echarts.js 2.8 MB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180251812518225183251842518525186251872518825189251902519125192251932519425195251962519725198251992520025201252022520325204252052520625207252082520925210252112521225213252142521525216252172521825219252202522125222252232522425225252262522725228252292523025231252322523325234252352523625237252382523925240252412524225243252442524525246252472524825249252502525125252252532525425255252562525725258252592526025261252622526325264252652526625267252682526925270252712527225273252742527525276252772527825279252802528125282252832528425285252862528725288252892529025291252922529325294252952529625297252982529925300253012530225303253042530525306253072530825309253102531125312253132531425315253162531725318253192532025321253222532325324253252532625327253282532925330253312533225333253342533525336253372533825339253402534125342253432534425345253462534725348253492535025351253522535325354253552535625357253582535925360253612536225363253642536525366253672536825369253702537125372253732537425375253762537725378253792538025381253822538325384253852538625387253882538925390253912539225393253942539525396253972539825399254002540125402254032540425405254062540725408254092541025411254122541325414254152541625417254182541925420254212542225423254242542525426254272542825429254302543125432254332543425435254362543725438254392544025441254422544325444254452544625447254482544925450254512545225453254542545525456254572545825459254602546125462254632546425465254662546725468254692547025471254722547325474254752547625477254782547925480254812548225483254842548525486254872548825489254902549125492254932549425495254962549725498254992550025501255022550325504255052550625507255082550925510255112551225513255142551525516255172551825519255202552125522255232552425525255262552725528255292553025531255322553325534255352553625537255382553925540255412554225543255442554525546255472554825549255502555125552255532555425555255562555725558255592556025561255622556325564255652556625567255682556925570255712557225573255742557525576255772557825579255802558125582255832558425585255862558725588255892559025591255922559325594255952559625597255982559925600256012560225603256042560525606256072560825609256102561125612256132561425615256162561725618256192562025621256222562325624256252562625627256282562925630256312563225633256342563525636256372563825639256402564125642256432564425645256462564725648256492565025651256522565325654256552565625657256582565925660256612566225663256642566525666256672566825669256702567125672256732567425675256762567725678256792568025681256822568325684256852568625687256882568925690256912569225693256942569525696256972569825699257002570125702257032570425705257062570725708257092571025711257122571325714257152571625717257182571925720257212572225723257242572525726257272572825729257302573125732257332573425735257362573725738257392574025741257422574325744257452574625747257482574925750257512575225753257542575525756257572575825759257602576125762257632576425765257662576725768257692577025771257722577325774257752577625777257782577925780257812578225783257842578525786257872578825789257902579125792257932579425795257962579725798257992580025801258022580325804258052580625807258082580925810258112581225813258142581525816258172581825819258202582125822258232582425825258262582725828258292583025831258322583325834258352583625837258382583925840258412584225843258442584525846258472584825849258502585125852258532585425855258562585725858258592586025861258622586325864258652586625867258682586925870258712587225873258742587525876258772587825879258802588125882258832588425885258862588725888258892589025891258922589325894258952589625897258982589925900259012590225903259042590525906259072590825909259102591125912259132591425915259162591725918259192592025921259222592325924259252592625927259282592925930259312593225933259342593525936259372593825939259402594125942259432594425945259462594725948259492595025951259522595325954259552595625957259582595925960259612596225963259642596525966259672596825969259702597125972259732597425975259762597725978259792598025981259822598325984259852598625987259882598925990259912599225993259942599525996259972599825999260002600126002260032600426005260062600726008260092601026011260122601326014260152601626017260182601926020260212602226023260242602526026260272602826029260302603126032260332603426035260362603726038260392604026041260422604326044260452604626047260482604926050260512605226053260542605526056260572605826059260602606126062260632606426065260662606726068260692607026071260722607326074260752607626077260782607926080260812608226083260842608526086260872608826089260902609126092260932609426095260962609726098260992610026101261022610326104261052610626107261082610926110261112611226113261142611526116261172611826119261202612126122261232612426125261262612726128261292613026131261322613326134261352613626137261382613926140261412614226143261442614526146261472614826149261502615126152261532615426155261562615726158261592616026161261622616326164261652616626167261682616926170261712617226173261742617526176261772617826179261802618126182261832618426185261862618726188261892619026191261922619326194261952619626197261982619926200262012620226203262042620526206262072620826209262102621126212262132621426215262162621726218262192622026221262222622326224262252622626227262282622926230262312623226233262342623526236262372623826239262402624126242262432624426245262462624726248262492625026251262522625326254262552625626257262582625926260262612626226263262642626526266262672626826269262702627126272262732627426275262762627726278262792628026281262822628326284262852628626287262882628926290262912629226293262942629526296262972629826299263002630126302263032630426305263062630726308263092631026311263122631326314263152631626317263182631926320263212632226323263242632526326263272632826329263302633126332263332633426335263362633726338263392634026341263422634326344263452634626347263482634926350263512635226353263542635526356263572635826359263602636126362263632636426365263662636726368263692637026371263722637326374263752637626377263782637926380263812638226383263842638526386263872638826389263902639126392263932639426395263962639726398263992640026401264022640326404264052640626407264082640926410264112641226413264142641526416264172641826419264202642126422264232642426425264262642726428264292643026431264322643326434264352643626437264382643926440264412644226443264442644526446264472644826449264502645126452264532645426455264562645726458264592646026461264622646326464264652646626467264682646926470264712647226473264742647526476264772647826479264802648126482264832648426485264862648726488264892649026491264922649326494264952649626497264982649926500265012650226503265042650526506265072650826509265102651126512265132651426515265162651726518265192652026521265222652326524265252652626527265282652926530265312653226533265342653526536265372653826539265402654126542265432654426545265462654726548265492655026551265522655326554265552655626557265582655926560265612656226563265642656526566265672656826569265702657126572265732657426575265762657726578265792658026581265822658326584265852658626587265882658926590265912659226593265942659526596265972659826599266002660126602266032660426605266062660726608266092661026611266122661326614266152661626617266182661926620266212662226623266242662526626266272662826629266302663126632266332663426635266362663726638266392664026641266422664326644266452664626647266482664926650266512665226653266542665526656266572665826659266602666126662266632666426665266662666726668266692667026671266722667326674266752667626677266782667926680266812668226683266842668526686266872668826689266902669126692266932669426695266962669726698266992670026701267022670326704267052670626707267082670926710267112671226713267142671526716267172671826719267202672126722267232672426725267262672726728267292673026731267322673326734267352673626737267382673926740267412674226743267442674526746267472674826749267502675126752267532675426755267562675726758267592676026761267622676326764267652676626767267682676926770267712677226773267742677526776267772677826779267802678126782267832678426785267862678726788267892679026791267922679326794267952679626797267982679926800268012680226803268042680526806268072680826809268102681126812268132681426815268162681726818268192682026821268222682326824268252682626827268282682926830268312683226833268342683526836268372683826839268402684126842268432684426845268462684726848268492685026851268522685326854268552685626857268582685926860268612686226863268642686526866268672686826869268702687126872268732687426875268762687726878268792688026881268822688326884268852688626887268882688926890268912689226893268942689526896268972689826899269002690126902269032690426905269062690726908269092691026911269122691326914269152691626917269182691926920269212692226923269242692526926269272692826929269302693126932269332693426935269362693726938269392694026941269422694326944269452694626947269482694926950269512695226953269542695526956269572695826959269602696126962269632696426965269662696726968269692697026971269722697326974269752697626977269782697926980269812698226983269842698526986269872698826989269902699126992269932699426995269962699726998269992700027001270022700327004270052700627007270082700927010270112701227013270142701527016270172701827019270202702127022270232702427025270262702727028270292703027031270322703327034270352703627037270382703927040270412704227043270442704527046270472704827049270502705127052270532705427055270562705727058270592706027061270622706327064270652706627067270682706927070270712707227073270742707527076270772707827079270802708127082270832708427085270862708727088270892709027091270922709327094270952709627097270982709927100271012710227103271042710527106271072710827109271102711127112271132711427115271162711727118271192712027121271222712327124271252712627127271282712927130271312713227133271342713527136271372713827139271402714127142271432714427145271462714727148271492715027151271522715327154271552715627157271582715927160271612716227163271642716527166271672716827169271702717127172271732717427175271762717727178271792718027181271822718327184271852718627187271882718927190271912719227193271942719527196271972719827199272002720127202272032720427205272062720727208272092721027211272122721327214272152721627217272182721927220272212722227223272242722527226272272722827229272302723127232272332723427235272362723727238272392724027241272422724327244272452724627247272482724927250272512725227253272542725527256272572725827259272602726127262272632726427265272662726727268272692727027271272722727327274272752727627277272782727927280272812728227283272842728527286272872728827289272902729127292272932729427295272962729727298272992730027301273022730327304273052730627307273082730927310273112731227313273142731527316273172731827319273202732127322273232732427325273262732727328273292733027331273322733327334273352733627337273382733927340273412734227343273442734527346273472734827349273502735127352273532735427355273562735727358273592736027361273622736327364273652736627367273682736927370273712737227373273742737527376273772737827379273802738127382273832738427385273862738727388273892739027391273922739327394273952739627397273982739927400274012740227403274042740527406274072740827409274102741127412274132741427415274162741727418274192742027421274222742327424274252742627427274282742927430274312743227433274342743527436274372743827439274402744127442274432744427445274462744727448274492745027451274522745327454274552745627457274582745927460274612746227463274642746527466274672746827469274702747127472274732747427475274762747727478274792748027481274822748327484274852748627487274882748927490274912749227493274942749527496274972749827499275002750127502275032750427505275062750727508275092751027511275122751327514275152751627517275182751927520275212752227523275242752527526275272752827529275302753127532275332753427535275362753727538275392754027541275422754327544275452754627547275482754927550275512755227553275542755527556275572755827559275602756127562275632756427565275662756727568275692757027571275722757327574275752757627577275782757927580275812758227583275842758527586275872758827589275902759127592275932759427595275962759727598275992760027601276022760327604276052760627607276082760927610276112761227613276142761527616276172761827619276202762127622276232762427625276262762727628276292763027631276322763327634276352763627637276382763927640276412764227643276442764527646276472764827649276502765127652276532765427655276562765727658276592766027661276622766327664276652766627667276682766927670276712767227673276742767527676276772767827679276802768127682276832768427685276862768727688276892769027691276922769327694276952769627697276982769927700277012770227703277042770527706277072770827709277102771127712277132771427715277162771727718277192772027721277222772327724277252772627727277282772927730277312773227733277342773527736277372773827739277402774127742277432774427745277462774727748277492775027751277522775327754277552775627757277582775927760277612776227763277642776527766277672776827769277702777127772277732777427775277762777727778277792778027781277822778327784277852778627787277882778927790277912779227793277942779527796277972779827799278002780127802278032780427805278062780727808278092781027811278122781327814278152781627817278182781927820278212782227823278242782527826278272782827829278302783127832278332783427835278362783727838278392784027841278422784327844278452784627847278482784927850278512785227853278542785527856278572785827859278602786127862278632786427865278662786727868278692787027871278722787327874278752787627877278782787927880278812788227883278842788527886278872788827889278902789127892278932789427895278962789727898278992790027901279022790327904279052790627907279082790927910279112791227913279142791527916279172791827919279202792127922279232792427925279262792727928279292793027931279322793327934279352793627937279382793927940279412794227943279442794527946279472794827949279502795127952279532795427955279562795727958279592796027961279622796327964279652796627967279682796927970279712797227973279742797527976279772797827979279802798127982279832798427985279862798727988279892799027991279922799327994279952799627997279982799928000280012800228003280042800528006280072800828009280102801128012280132801428015280162801728018280192802028021280222802328024280252802628027280282802928030280312803228033280342803528036280372803828039280402804128042280432804428045280462804728048280492805028051280522805328054280552805628057280582805928060280612806228063280642806528066280672806828069280702807128072280732807428075280762807728078280792808028081280822808328084280852808628087280882808928090280912809228093280942809528096280972809828099281002810128102281032810428105281062810728108281092811028111281122811328114281152811628117281182811928120281212812228123281242812528126281272812828129281302813128132281332813428135281362813728138281392814028141281422814328144281452814628147281482814928150281512815228153281542815528156281572815828159281602816128162281632816428165281662816728168281692817028171281722817328174281752817628177281782817928180281812818228183281842818528186281872818828189281902819128192281932819428195281962819728198281992820028201282022820328204282052820628207282082820928210282112821228213282142821528216282172821828219282202822128222282232822428225282262822728228282292823028231282322823328234282352823628237282382823928240282412824228243282442824528246282472824828249282502825128252282532825428255282562825728258282592826028261282622826328264282652826628267282682826928270282712827228273282742827528276282772827828279282802828128282282832828428285282862828728288282892829028291282922829328294282952829628297282982829928300283012830228303283042830528306283072830828309283102831128312283132831428315283162831728318283192832028321283222832328324283252832628327283282832928330283312833228333283342833528336283372833828339283402834128342283432834428345283462834728348283492835028351283522835328354283552835628357283582835928360283612836228363283642836528366283672836828369283702837128372283732837428375283762837728378283792838028381283822838328384283852838628387283882838928390283912839228393283942839528396283972839828399284002840128402284032840428405284062840728408284092841028411284122841328414284152841628417284182841928420284212842228423284242842528426284272842828429284302843128432284332843428435284362843728438284392844028441284422844328444284452844628447284482844928450284512845228453284542845528456284572845828459284602846128462284632846428465284662846728468284692847028471284722847328474284752847628477284782847928480284812848228483284842848528486284872848828489284902849128492284932849428495284962849728498284992850028501285022850328504285052850628507285082850928510285112851228513285142851528516285172851828519285202852128522285232852428525285262852728528285292853028531285322853328534285352853628537285382853928540285412854228543285442854528546285472854828549285502855128552285532855428555285562855728558285592856028561285622856328564285652856628567285682856928570285712857228573285742857528576285772857828579285802858128582285832858428585285862858728588285892859028591285922859328594285952859628597285982859928600286012860228603286042860528606286072860828609286102861128612286132861428615286162861728618286192862028621286222862328624286252862628627286282862928630286312863228633286342863528636286372863828639286402864128642286432864428645286462864728648286492865028651286522865328654286552865628657286582865928660286612866228663286642866528666286672866828669286702867128672286732867428675286762867728678286792868028681286822868328684286852868628687286882868928690286912869228693286942869528696286972869828699287002870128702287032870428705287062870728708287092871028711287122871328714287152871628717287182871928720287212872228723287242872528726287272872828729287302873128732287332873428735287362873728738287392874028741287422874328744287452874628747287482874928750287512875228753287542875528756287572875828759287602876128762287632876428765287662876728768287692877028771287722877328774287752877628777287782877928780287812878228783287842878528786287872878828789287902879128792287932879428795287962879728798287992880028801288022880328804288052880628807288082880928810288112881228813288142881528816288172881828819288202882128822288232882428825288262882728828288292883028831288322883328834288352883628837288382883928840288412884228843288442884528846288472884828849288502885128852288532885428855288562885728858288592886028861288622886328864288652886628867288682886928870288712887228873288742887528876288772887828879288802888128882288832888428885288862888728888288892889028891288922889328894288952889628897288982889928900289012890228903289042890528906289072890828909289102891128912289132891428915289162891728918289192892028921289222892328924289252892628927289282892928930289312893228933289342893528936289372893828939289402894128942289432894428945289462894728948289492895028951289522895328954289552895628957289582895928960289612896228963289642896528966289672896828969289702897128972289732897428975289762897728978289792898028981289822898328984289852898628987289882898928990289912899228993289942899528996289972899828999290002900129002290032900429005290062900729008290092901029011290122901329014290152901629017290182901929020290212902229023290242902529026290272902829029290302903129032290332903429035290362903729038290392904029041290422904329044290452904629047290482904929050290512905229053290542905529056290572905829059290602906129062290632906429065290662906729068290692907029071290722907329074290752907629077290782907929080290812908229083290842908529086290872908829089290902909129092290932909429095290962909729098290992910029101291022910329104291052910629107291082910929110291112911229113291142911529116291172911829119291202912129122291232912429125291262912729128291292913029131291322913329134291352913629137291382913929140291412914229143291442914529146291472914829149291502915129152291532915429155291562915729158291592916029161291622916329164291652916629167291682916929170291712917229173291742917529176291772917829179291802918129182291832918429185291862918729188291892919029191291922919329194291952919629197291982919929200292012920229203292042920529206292072920829209292102921129212292132921429215292162921729218292192922029221292222922329224292252922629227292282922929230292312923229233292342923529236292372923829239292402924129242292432924429245292462924729248292492925029251292522925329254292552925629257292582925929260292612926229263292642926529266292672926829269292702927129272292732927429275292762927729278292792928029281292822928329284292852928629287292882928929290292912929229293292942929529296292972929829299293002930129302293032930429305293062930729308293092931029311293122931329314293152931629317293182931929320293212932229323293242932529326293272932829329293302933129332293332933429335293362933729338293392934029341293422934329344293452934629347293482934929350293512935229353293542935529356293572935829359293602936129362293632936429365293662936729368293692937029371293722937329374293752937629377293782937929380293812938229383293842938529386293872938829389293902939129392293932939429395293962939729398293992940029401294022940329404294052940629407294082940929410294112941229413294142941529416294172941829419294202942129422294232942429425294262942729428294292943029431294322943329434294352943629437294382943929440294412944229443294442944529446294472944829449294502945129452294532945429455294562945729458294592946029461294622946329464294652946629467294682946929470294712947229473294742947529476294772947829479294802948129482294832948429485294862948729488294892949029491294922949329494294952949629497294982949929500295012950229503295042950529506295072950829509295102951129512295132951429515295162951729518295192952029521295222952329524295252952629527295282952929530295312953229533295342953529536295372953829539295402954129542295432954429545295462954729548295492955029551295522955329554295552955629557295582955929560295612956229563295642956529566295672956829569295702957129572295732957429575295762957729578295792958029581295822958329584295852958629587295882958929590295912959229593295942959529596295972959829599296002960129602296032960429605296062960729608296092961029611296122961329614296152961629617296182961929620296212962229623296242962529626296272962829629296302963129632296332963429635296362963729638296392964029641296422964329644296452964629647296482964929650296512965229653296542965529656296572965829659296602966129662296632966429665296662966729668296692967029671296722967329674296752967629677296782967929680296812968229683296842968529686296872968829689296902969129692296932969429695296962969729698296992970029701297022970329704297052970629707297082970929710297112971229713297142971529716297172971829719297202972129722297232972429725297262972729728297292973029731297322973329734297352973629737297382973929740297412974229743297442974529746297472974829749297502975129752297532975429755297562975729758297592976029761297622976329764297652976629767297682976929770297712977229773297742977529776297772977829779297802978129782297832978429785297862978729788297892979029791297922979329794297952979629797297982979929800298012980229803298042980529806298072980829809298102981129812298132981429815298162981729818298192982029821298222982329824298252982629827298282982929830298312983229833298342983529836298372983829839298402984129842298432984429845298462984729848298492985029851298522985329854298552985629857298582985929860298612986229863298642986529866298672986829869298702987129872298732987429875298762987729878298792988029881298822988329884298852988629887298882988929890298912989229893298942989529896298972989829899299002990129902299032990429905299062990729908299092991029911299122991329914299152991629917299182991929920299212992229923299242992529926299272992829929299302993129932299332993429935299362993729938299392994029941299422994329944299452994629947299482994929950299512995229953299542995529956299572995829959299602996129962299632996429965299662996729968299692997029971299722997329974299752997629977299782997929980299812998229983299842998529986299872998829989299902999129992299932999429995299962999729998299993000030001300023000330004300053000630007300083000930010300113001230013300143001530016300173001830019300203002130022300233002430025300263002730028300293003030031300323003330034300353003630037300383003930040300413004230043300443004530046300473004830049300503005130052300533005430055300563005730058300593006030061300623006330064300653006630067300683006930070300713007230073300743007530076300773007830079300803008130082300833008430085300863008730088300893009030091300923009330094300953009630097300983009930100301013010230103301043010530106301073010830109301103011130112301133011430115301163011730118301193012030121301223012330124301253012630127301283012930130301313013230133301343013530136301373013830139301403014130142301433014430145301463014730148301493015030151301523015330154301553015630157301583015930160301613016230163301643016530166301673016830169301703017130172301733017430175301763017730178301793018030181301823018330184301853018630187301883018930190301913019230193301943019530196301973019830199302003020130202302033020430205302063020730208302093021030211302123021330214302153021630217302183021930220302213022230223302243022530226302273022830229302303023130232302333023430235302363023730238302393024030241302423024330244302453024630247302483024930250302513025230253302543025530256302573025830259302603026130262302633026430265302663026730268302693027030271302723027330274302753027630277302783027930280302813028230283302843028530286302873028830289302903029130292302933029430295302963029730298302993030030301303023030330304303053030630307303083030930310303113031230313303143031530316303173031830319303203032130322303233032430325303263032730328303293033030331303323033330334303353033630337303383033930340303413034230343303443034530346303473034830349303503035130352303533035430355303563035730358303593036030361303623036330364303653036630367303683036930370303713037230373303743037530376303773037830379303803038130382303833038430385303863038730388303893039030391303923039330394303953039630397303983039930400304013040230403304043040530406304073040830409304103041130412304133041430415304163041730418304193042030421304223042330424304253042630427304283042930430304313043230433304343043530436304373043830439304403044130442304433044430445304463044730448304493045030451304523045330454304553045630457304583045930460304613046230463304643046530466304673046830469304703047130472304733047430475304763047730478304793048030481304823048330484304853048630487304883048930490304913049230493304943049530496304973049830499305003050130502305033050430505305063050730508305093051030511305123051330514305153051630517305183051930520305213052230523305243052530526305273052830529305303053130532305333053430535305363053730538305393054030541305423054330544305453054630547305483054930550305513055230553305543055530556305573055830559305603056130562305633056430565305663056730568305693057030571305723057330574305753057630577305783057930580305813058230583305843058530586305873058830589305903059130592305933059430595305963059730598305993060030601306023060330604306053060630607306083060930610306113061230613306143061530616306173061830619306203062130622306233062430625306263062730628306293063030631306323063330634306353063630637306383063930640306413064230643306443064530646306473064830649306503065130652306533065430655306563065730658306593066030661306623066330664306653066630667306683066930670306713067230673306743067530676306773067830679306803068130682306833068430685306863068730688306893069030691306923069330694306953069630697306983069930700307013070230703307043070530706307073070830709307103071130712307133071430715307163071730718307193072030721307223072330724307253072630727307283072930730307313073230733307343073530736307373073830739307403074130742307433074430745307463074730748307493075030751307523075330754307553075630757307583075930760307613076230763307643076530766307673076830769307703077130772307733077430775307763077730778307793078030781307823078330784307853078630787307883078930790307913079230793307943079530796307973079830799308003080130802308033080430805308063080730808308093081030811308123081330814308153081630817308183081930820308213082230823308243082530826308273082830829308303083130832308333083430835308363083730838308393084030841308423084330844308453084630847308483084930850308513085230853308543085530856308573085830859308603086130862308633086430865308663086730868308693087030871308723087330874308753087630877308783087930880308813088230883308843088530886308873088830889308903089130892308933089430895308963089730898308993090030901309023090330904309053090630907309083090930910309113091230913309143091530916309173091830919309203092130922309233092430925309263092730928309293093030931309323093330934309353093630937309383093930940309413094230943309443094530946309473094830949309503095130952309533095430955309563095730958309593096030961309623096330964309653096630967309683096930970309713097230973309743097530976309773097830979309803098130982309833098430985309863098730988309893099030991309923099330994309953099630997309983099931000310013100231003310043100531006310073100831009310103101131012310133101431015310163101731018310193102031021310223102331024310253102631027310283102931030310313103231033310343103531036310373103831039310403104131042310433104431045310463104731048310493105031051310523105331054310553105631057310583105931060310613106231063310643106531066310673106831069310703107131072310733107431075310763107731078310793108031081310823108331084310853108631087310883108931090310913109231093310943109531096310973109831099311003110131102311033110431105311063110731108311093111031111311123111331114311153111631117311183111931120311213112231123311243112531126311273112831129311303113131132311333113431135311363113731138311393114031141311423114331144311453114631147311483114931150311513115231153311543115531156311573115831159311603116131162311633116431165311663116731168311693117031171311723117331174311753117631177311783117931180311813118231183311843118531186311873118831189311903119131192311933119431195311963119731198311993120031201312023120331204312053120631207312083120931210312113121231213312143121531216312173121831219312203122131222312233122431225312263122731228312293123031231312323123331234312353123631237312383123931240312413124231243312443124531246312473124831249312503125131252312533125431255312563125731258312593126031261312623126331264312653126631267312683126931270312713127231273312743127531276312773127831279312803128131282312833128431285312863128731288312893129031291312923129331294312953129631297312983129931300313013130231303313043130531306313073130831309313103131131312313133131431315313163131731318313193132031321313223132331324313253132631327313283132931330313313133231333313343133531336313373133831339313403134131342313433134431345313463134731348313493135031351313523135331354313553135631357313583135931360313613136231363313643136531366313673136831369313703137131372313733137431375313763137731378313793138031381313823138331384313853138631387313883138931390313913139231393313943139531396313973139831399314003140131402314033140431405314063140731408314093141031411314123141331414314153141631417314183141931420314213142231423314243142531426314273142831429314303143131432314333143431435314363143731438314393144031441314423144331444314453144631447314483144931450314513145231453314543145531456314573145831459314603146131462314633146431465314663146731468314693147031471314723147331474314753147631477314783147931480314813148231483314843148531486314873148831489314903149131492314933149431495314963149731498314993150031501315023150331504315053150631507315083150931510315113151231513315143151531516315173151831519315203152131522315233152431525315263152731528315293153031531315323153331534315353153631537315383153931540315413154231543315443154531546315473154831549315503155131552315533155431555315563155731558315593156031561315623156331564315653156631567315683156931570315713157231573315743157531576315773157831579315803158131582315833158431585315863158731588315893159031591315923159331594315953159631597315983159931600316013160231603316043160531606316073160831609316103161131612316133161431615316163161731618316193162031621316223162331624316253162631627316283162931630316313163231633316343163531636316373163831639316403164131642316433164431645316463164731648316493165031651316523165331654316553165631657316583165931660316613166231663316643166531666316673166831669316703167131672316733167431675316763167731678316793168031681316823168331684316853168631687316883168931690316913169231693316943169531696316973169831699317003170131702317033170431705317063170731708317093171031711317123171331714317153171631717317183171931720317213172231723317243172531726317273172831729317303173131732317333173431735317363173731738317393174031741317423174331744317453174631747317483174931750317513175231753317543175531756317573175831759317603176131762317633176431765317663176731768317693177031771317723177331774317753177631777317783177931780317813178231783317843178531786317873178831789317903179131792317933179431795317963179731798317993180031801318023180331804318053180631807318083180931810318113181231813318143181531816318173181831819318203182131822318233182431825318263182731828318293183031831318323183331834318353183631837318383183931840318413184231843318443184531846318473184831849318503185131852318533185431855318563185731858318593186031861318623186331864318653186631867318683186931870318713187231873318743187531876318773187831879318803188131882318833188431885318863188731888318893189031891318923189331894318953189631897318983189931900319013190231903319043190531906319073190831909319103191131912319133191431915319163191731918319193192031921319223192331924319253192631927319283192931930319313193231933319343193531936319373193831939319403194131942319433194431945319463194731948319493195031951319523195331954319553195631957319583195931960319613196231963319643196531966319673196831969319703197131972319733197431975319763197731978319793198031981319823198331984319853198631987319883198931990319913199231993319943199531996319973199831999320003200132002320033200432005320063200732008320093201032011320123201332014320153201632017320183201932020320213202232023320243202532026320273202832029320303203132032320333203432035320363203732038320393204032041320423204332044320453204632047320483204932050320513205232053320543205532056320573205832059320603206132062320633206432065320663206732068320693207032071320723207332074320753207632077320783207932080320813208232083320843208532086320873208832089320903209132092320933209432095320963209732098320993210032101321023210332104321053210632107321083210932110321113211232113321143211532116321173211832119321203212132122321233212432125321263212732128321293213032131321323213332134321353213632137321383213932140321413214232143321443214532146321473214832149321503215132152321533215432155321563215732158321593216032161321623216332164321653216632167321683216932170321713217232173321743217532176321773217832179321803218132182321833218432185321863218732188321893219032191321923219332194321953219632197321983219932200322013220232203322043220532206322073220832209322103221132212322133221432215322163221732218322193222032221322223222332224322253222632227322283222932230322313223232233322343223532236322373223832239322403224132242322433224432245322463224732248322493225032251322523225332254322553225632257322583225932260322613226232263322643226532266322673226832269322703227132272322733227432275322763227732278322793228032281322823228332284322853228632287322883228932290322913229232293322943229532296322973229832299323003230132302323033230432305323063230732308323093231032311323123231332314323153231632317323183231932320323213232232323323243232532326323273232832329323303233132332323333233432335323363233732338323393234032341323423234332344323453234632347323483234932350323513235232353323543235532356323573235832359323603236132362323633236432365323663236732368323693237032371323723237332374323753237632377323783237932380323813238232383323843238532386323873238832389323903239132392323933239432395323963239732398323993240032401324023240332404324053240632407324083240932410324113241232413324143241532416324173241832419324203242132422324233242432425324263242732428324293243032431324323243332434324353243632437324383243932440324413244232443324443244532446324473244832449324503245132452324533245432455324563245732458324593246032461324623246332464324653246632467324683246932470324713247232473324743247532476324773247832479324803248132482324833248432485324863248732488324893249032491324923249332494324953249632497324983249932500325013250232503325043250532506325073250832509325103251132512325133251432515325163251732518325193252032521325223252332524325253252632527325283252932530325313253232533325343253532536325373253832539325403254132542325433254432545325463254732548325493255032551325523255332554325553255632557325583255932560325613256232563325643256532566325673256832569325703257132572325733257432575325763257732578325793258032581325823258332584325853258632587325883258932590325913259232593325943259532596325973259832599326003260132602326033260432605326063260732608326093261032611326123261332614326153261632617326183261932620326213262232623326243262532626326273262832629326303263132632326333263432635326363263732638326393264032641326423264332644326453264632647326483264932650326513265232653326543265532656326573265832659326603266132662326633266432665326663266732668326693267032671326723267332674326753267632677326783267932680326813268232683326843268532686326873268832689326903269132692326933269432695326963269732698326993270032701327023270332704327053270632707327083270932710327113271232713327143271532716327173271832719327203272132722327233272432725327263272732728327293273032731327323273332734327353273632737327383273932740327413274232743327443274532746327473274832749327503275132752327533275432755327563275732758327593276032761327623276332764327653276632767327683276932770327713277232773327743277532776327773277832779327803278132782327833278432785327863278732788327893279032791327923279332794327953279632797327983279932800328013280232803328043280532806328073280832809328103281132812328133281432815328163281732818328193282032821328223282332824328253282632827328283282932830328313283232833328343283532836328373283832839328403284132842328433284432845328463284732848328493285032851328523285332854328553285632857328583285932860328613286232863328643286532866328673286832869328703287132872328733287432875328763287732878328793288032881328823288332884328853288632887328883288932890328913289232893328943289532896328973289832899329003290132902329033290432905329063290732908329093291032911329123291332914329153291632917329183291932920329213292232923329243292532926329273292832929329303293132932329333293432935329363293732938329393294032941329423294332944329453294632947329483294932950329513295232953329543295532956329573295832959329603296132962329633296432965329663296732968329693297032971329723297332974329753297632977329783297932980329813298232983329843298532986329873298832989329903299132992329933299432995329963299732998329993300033001330023300333004330053300633007330083300933010330113301233013330143301533016330173301833019330203302133022330233302433025330263302733028330293303033031330323303333034330353303633037330383303933040330413304233043330443304533046330473304833049330503305133052330533305433055330563305733058330593306033061330623306333064330653306633067330683306933070330713307233073330743307533076330773307833079330803308133082330833308433085330863308733088330893309033091330923309333094330953309633097330983309933100331013310233103331043310533106331073310833109331103311133112331133311433115331163311733118331193312033121331223312333124331253312633127331283312933130331313313233133331343313533136331373313833139331403314133142331433314433145331463314733148331493315033151331523315333154331553315633157331583315933160331613316233163331643316533166331673316833169331703317133172331733317433175331763317733178331793318033181331823318333184331853318633187331883318933190331913319233193331943319533196331973319833199332003320133202332033320433205332063320733208332093321033211332123321333214332153321633217332183321933220332213322233223332243322533226332273322833229332303323133232332333323433235332363323733238332393324033241332423324333244332453324633247332483324933250332513325233253332543325533256332573325833259332603326133262332633326433265332663326733268332693327033271332723327333274332753327633277332783327933280332813328233283332843328533286332873328833289332903329133292332933329433295332963329733298332993330033301333023330333304333053330633307333083330933310333113331233313333143331533316333173331833319333203332133322333233332433325333263332733328333293333033331333323333333334333353333633337333383333933340333413334233343333443334533346333473334833349333503335133352333533335433355333563335733358333593336033361333623336333364333653336633367333683336933370333713337233373333743337533376333773337833379333803338133382333833338433385333863338733388333893339033391333923339333394333953339633397333983339933400334013340233403334043340533406334073340833409334103341133412334133341433415334163341733418334193342033421334223342333424334253342633427334283342933430334313343233433334343343533436334373343833439334403344133442334433344433445334463344733448334493345033451334523345333454334553345633457334583345933460334613346233463334643346533466334673346833469334703347133472334733347433475334763347733478334793348033481334823348333484334853348633487334883348933490334913349233493334943349533496334973349833499335003350133502335033350433505335063350733508335093351033511335123351333514335153351633517335183351933520335213352233523335243352533526335273352833529335303353133532335333353433535335363353733538335393354033541335423354333544335453354633547335483354933550335513355233553335543355533556335573355833559335603356133562335633356433565335663356733568335693357033571335723357333574335753357633577335783357933580335813358233583335843358533586335873358833589335903359133592335933359433595335963359733598335993360033601336023360333604336053360633607336083360933610336113361233613336143361533616336173361833619336203362133622336233362433625336263362733628336293363033631336323363333634336353363633637336383363933640336413364233643336443364533646336473364833649336503365133652336533365433655336563365733658336593366033661336623366333664336653366633667336683366933670336713367233673336743367533676336773367833679336803368133682336833368433685336863368733688336893369033691336923369333694336953369633697336983369933700337013370233703337043370533706337073370833709337103371133712337133371433715337163371733718337193372033721337223372333724337253372633727337283372933730337313373233733337343373533736337373373833739337403374133742337433374433745337463374733748337493375033751337523375333754337553375633757337583375933760337613376233763337643376533766337673376833769337703377133772337733377433775337763377733778337793378033781337823378333784337853378633787337883378933790337913379233793337943379533796337973379833799338003380133802338033380433805338063380733808338093381033811338123381333814338153381633817338183381933820338213382233823338243382533826338273382833829338303383133832338333383433835338363383733838338393384033841338423384333844338453384633847338483384933850338513385233853338543385533856338573385833859338603386133862338633386433865338663386733868338693387033871338723387333874338753387633877338783387933880338813388233883338843388533886338873388833889338903389133892338933389433895338963389733898338993390033901339023390333904339053390633907339083390933910339113391233913339143391533916339173391833919339203392133922339233392433925339263392733928339293393033931339323393333934339353393633937339383393933940339413394233943339443394533946339473394833949339503395133952339533395433955339563395733958339593396033961339623396333964339653396633967339683396933970339713397233973339743397533976339773397833979339803398133982339833398433985339863398733988339893399033991339923399333994339953399633997339983399934000340013400234003340043400534006340073400834009340103401134012340133401434015340163401734018340193402034021340223402334024340253402634027340283402934030340313403234033340343403534036340373403834039340403404134042340433404434045340463404734048340493405034051340523405334054340553405634057340583405934060340613406234063340643406534066340673406834069340703407134072340733407434075340763407734078340793408034081340823408334084340853408634087340883408934090340913409234093340943409534096340973409834099341003410134102341033410434105341063410734108341093411034111341123411334114341153411634117341183411934120341213412234123341243412534126341273412834129341303413134132341333413434135341363413734138341393414034141341423414334144341453414634147341483414934150341513415234153341543415534156341573415834159341603416134162341633416434165341663416734168341693417034171341723417334174341753417634177341783417934180341813418234183341843418534186341873418834189341903419134192341933419434195341963419734198341993420034201342023420334204342053420634207342083420934210342113421234213342143421534216342173421834219342203422134222342233422434225342263422734228342293423034231342323423334234342353423634237342383423934240342413424234243342443424534246342473424834249342503425134252342533425434255342563425734258342593426034261342623426334264342653426634267342683426934270342713427234273342743427534276342773427834279342803428134282342833428434285342863428734288342893429034291342923429334294342953429634297342983429934300343013430234303343043430534306343073430834309343103431134312343133431434315343163431734318343193432034321343223432334324343253432634327343283432934330343313433234333343343433534336343373433834339343403434134342343433434434345343463434734348343493435034351343523435334354343553435634357343583435934360343613436234363343643436534366343673436834369343703437134372343733437434375343763437734378343793438034381343823438334384343853438634387343883438934390343913439234393343943439534396343973439834399344003440134402344033440434405344063440734408344093441034411344123441334414344153441634417344183441934420344213442234423344243442534426344273442834429344303443134432344333443434435344363443734438344393444034441344423444334444344453444634447344483444934450344513445234453344543445534456344573445834459344603446134462344633446434465344663446734468344693447034471344723447334474344753447634477344783447934480344813448234483344843448534486344873448834489344903449134492344933449434495344963449734498344993450034501345023450334504345053450634507345083450934510345113451234513345143451534516345173451834519345203452134522345233452434525345263452734528345293453034531345323453334534345353453634537345383453934540345413454234543345443454534546345473454834549345503455134552345533455434555345563455734558345593456034561345623456334564345653456634567345683456934570345713457234573345743457534576345773457834579345803458134582345833458434585345863458734588345893459034591345923459334594345953459634597345983459934600346013460234603346043460534606346073460834609346103461134612346133461434615346163461734618346193462034621346223462334624346253462634627346283462934630346313463234633346343463534636346373463834639346403464134642346433464434645346463464734648346493465034651346523465334654346553465634657346583465934660346613466234663346643466534666346673466834669346703467134672346733467434675346763467734678346793468034681346823468334684346853468634687346883468934690346913469234693346943469534696346973469834699347003470134702347033470434705347063470734708347093471034711347123471334714347153471634717347183471934720347213472234723347243472534726347273472834729347303473134732347333473434735347363473734738347393474034741347423474334744347453474634747347483474934750347513475234753347543475534756347573475834759347603476134762347633476434765347663476734768347693477034771347723477334774347753477634777347783477934780347813478234783347843478534786347873478834789347903479134792347933479434795347963479734798347993480034801348023480334804348053480634807348083480934810348113481234813348143481534816348173481834819348203482134822348233482434825348263482734828348293483034831348323483334834348353483634837348383483934840348413484234843348443484534846348473484834849348503485134852348533485434855348563485734858348593486034861348623486334864348653486634867348683486934870348713487234873348743487534876348773487834879348803488134882348833488434885348863488734888348893489034891348923489334894348953489634897348983489934900349013490234903349043490534906349073490834909349103491134912349133491434915349163491734918349193492034921349223492334924349253492634927349283492934930349313493234933349343493534936349373493834939349403494134942349433494434945349463494734948349493495034951349523495334954349553495634957349583495934960349613496234963349643496534966349673496834969349703497134972349733497434975349763497734978349793498034981349823498334984349853498634987349883498934990349913499234993349943499534996349973499834999350003500135002350033500435005350063500735008350093501035011350123501335014350153501635017350183501935020350213502235023350243502535026350273502835029350303503135032350333503435035350363503735038350393504035041350423504335044350453504635047350483504935050350513505235053350543505535056350573505835059350603506135062350633506435065350663506735068350693507035071350723507335074350753507635077350783507935080350813508235083350843508535086350873508835089350903509135092350933509435095350963509735098350993510035101351023510335104351053510635107351083510935110351113511235113351143511535116351173511835119351203512135122351233512435125351263512735128351293513035131351323513335134351353513635137351383513935140351413514235143351443514535146351473514835149351503515135152351533515435155351563515735158351593516035161351623516335164351653516635167351683516935170351713517235173351743517535176351773517835179351803518135182351833518435185351863518735188351893519035191351923519335194351953519635197351983519935200352013520235203352043520535206352073520835209352103521135212352133521435215352163521735218352193522035221352223522335224352253522635227352283522935230352313523235233352343523535236352373523835239352403524135242352433524435245352463524735248352493525035251352523525335254352553525635257352583525935260352613526235263352643526535266352673526835269352703527135272352733527435275352763527735278352793528035281352823528335284352853528635287352883528935290352913529235293352943529535296352973529835299353003530135302353033530435305353063530735308353093531035311353123531335314353153531635317353183531935320353213532235323353243532535326353273532835329353303533135332353333533435335353363533735338353393534035341353423534335344353453534635347353483534935350353513535235353353543535535356353573535835359353603536135362353633536435365353663536735368353693537035371353723537335374353753537635377353783537935380353813538235383353843538535386353873538835389353903539135392353933539435395353963539735398353993540035401354023540335404354053540635407354083540935410354113541235413354143541535416354173541835419354203542135422354233542435425354263542735428354293543035431354323543335434354353543635437354383543935440354413544235443354443544535446354473544835449354503545135452354533545435455354563545735458354593546035461354623546335464354653546635467354683546935470354713547235473354743547535476354773547835479354803548135482354833548435485354863548735488354893549035491354923549335494354953549635497354983549935500355013550235503355043550535506355073550835509355103551135512355133551435515355163551735518355193552035521355223552335524355253552635527355283552935530355313553235533355343553535536355373553835539355403554135542355433554435545355463554735548355493555035551355523555335554355553555635557355583555935560355613556235563355643556535566355673556835569355703557135572355733557435575355763557735578355793558035581355823558335584355853558635587355883558935590355913559235593355943559535596355973559835599356003560135602356033560435605356063560735608356093561035611356123561335614356153561635617356183561935620356213562235623356243562535626356273562835629356303563135632356333563435635356363563735638356393564035641356423564335644356453564635647356483564935650356513565235653356543565535656356573565835659356603566135662356633566435665356663566735668356693567035671356723567335674356753567635677356783567935680356813568235683356843568535686356873568835689356903569135692356933569435695356963569735698356993570035701357023570335704357053570635707357083570935710357113571235713357143571535716357173571835719357203572135722357233572435725357263572735728357293573035731357323573335734357353573635737357383573935740357413574235743357443574535746357473574835749357503575135752357533575435755357563575735758357593576035761357623576335764357653576635767357683576935770357713577235773357743577535776357773577835779357803578135782357833578435785357863578735788357893579035791357923579335794357953579635797357983579935800358013580235803358043580535806358073580835809358103581135812358133581435815358163581735818358193582035821358223582335824358253582635827358283582935830358313583235833358343583535836358373583835839358403584135842358433584435845358463584735848358493585035851358523585335854358553585635857358583585935860358613586235863358643586535866358673586835869358703587135872358733587435875358763587735878358793588035881358823588335884358853588635887358883588935890358913589235893358943589535896358973589835899359003590135902359033590435905359063590735908359093591035911359123591335914359153591635917359183591935920359213592235923359243592535926359273592835929359303593135932359333593435935359363593735938359393594035941359423594335944359453594635947359483594935950359513595235953359543595535956359573595835959359603596135962359633596435965359663596735968359693597035971359723597335974359753597635977359783597935980359813598235983359843598535986359873598835989359903599135992359933599435995359963599735998359993600036001360023600336004360053600636007360083600936010360113601236013360143601536016360173601836019360203602136022360233602436025360263602736028360293603036031360323603336034360353603636037360383603936040360413604236043360443604536046360473604836049360503605136052360533605436055360563605736058360593606036061360623606336064360653606636067360683606936070360713607236073360743607536076360773607836079360803608136082360833608436085360863608736088360893609036091360923609336094360953609636097360983609936100361013610236103361043610536106361073610836109361103611136112361133611436115361163611736118361193612036121361223612336124361253612636127361283612936130361313613236133361343613536136361373613836139361403614136142361433614436145361463614736148361493615036151361523615336154361553615636157361583615936160361613616236163361643616536166361673616836169361703617136172361733617436175361763617736178361793618036181361823618336184361853618636187361883618936190361913619236193361943619536196361973619836199362003620136202362033620436205362063620736208362093621036211362123621336214362153621636217362183621936220362213622236223362243622536226362273622836229362303623136232362333623436235362363623736238362393624036241362423624336244362453624636247362483624936250362513625236253362543625536256362573625836259362603626136262362633626436265362663626736268362693627036271362723627336274362753627636277362783627936280362813628236283362843628536286362873628836289362903629136292362933629436295362963629736298362993630036301363023630336304363053630636307363083630936310363113631236313363143631536316363173631836319363203632136322363233632436325363263632736328363293633036331363323633336334363353633636337363383633936340363413634236343363443634536346363473634836349363503635136352363533635436355363563635736358363593636036361363623636336364363653636636367363683636936370363713637236373363743637536376363773637836379363803638136382363833638436385363863638736388363893639036391363923639336394363953639636397363983639936400364013640236403364043640536406364073640836409364103641136412364133641436415364163641736418364193642036421364223642336424364253642636427364283642936430364313643236433364343643536436364373643836439364403644136442364433644436445364463644736448364493645036451364523645336454364553645636457364583645936460364613646236463364643646536466364673646836469364703647136472364733647436475364763647736478364793648036481364823648336484364853648636487364883648936490364913649236493364943649536496364973649836499365003650136502365033650436505365063650736508365093651036511365123651336514365153651636517365183651936520365213652236523365243652536526365273652836529365303653136532365333653436535365363653736538365393654036541365423654336544365453654636547365483654936550365513655236553365543655536556365573655836559365603656136562365633656436565365663656736568365693657036571365723657336574365753657636577365783657936580365813658236583365843658536586365873658836589365903659136592365933659436595365963659736598365993660036601366023660336604366053660636607366083660936610366113661236613366143661536616366173661836619366203662136622366233662436625366263662736628366293663036631366323663336634366353663636637366383663936640366413664236643366443664536646366473664836649366503665136652366533665436655366563665736658366593666036661366623666336664366653666636667366683666936670366713667236673366743667536676366773667836679366803668136682366833668436685366863668736688366893669036691366923669336694366953669636697366983669936700367013670236703367043670536706367073670836709367103671136712367133671436715367163671736718367193672036721367223672336724367253672636727367283672936730367313673236733367343673536736367373673836739367403674136742367433674436745367463674736748367493675036751367523675336754367553675636757367583675936760367613676236763367643676536766367673676836769367703677136772367733677436775367763677736778367793678036781367823678336784367853678636787367883678936790367913679236793367943679536796367973679836799368003680136802368033680436805368063680736808368093681036811368123681336814368153681636817368183681936820368213682236823368243682536826368273682836829368303683136832368333683436835368363683736838368393684036841368423684336844368453684636847368483684936850368513685236853368543685536856368573685836859368603686136862368633686436865368663686736868368693687036871368723687336874368753687636877368783687936880368813688236883368843688536886368873688836889368903689136892368933689436895368963689736898368993690036901369023690336904369053690636907369083690936910369113691236913369143691536916369173691836919369203692136922369233692436925369263692736928369293693036931369323693336934369353693636937369383693936940369413694236943369443694536946369473694836949369503695136952369533695436955369563695736958369593696036961369623696336964369653696636967369683696936970369713697236973369743697536976369773697836979369803698136982369833698436985369863698736988369893699036991369923699336994369953699636997369983699937000370013700237003370043700537006370073700837009370103701137012370133701437015370163701737018370193702037021370223702337024370253702637027370283702937030370313703237033370343703537036370373703837039370403704137042370433704437045370463704737048370493705037051370523705337054370553705637057370583705937060370613706237063370643706537066370673706837069370703707137072370733707437075370763707737078370793708037081370823708337084370853708637087370883708937090370913709237093370943709537096370973709837099371003710137102371033710437105371063710737108371093711037111371123711337114371153711637117371183711937120371213712237123371243712537126371273712837129371303713137132371333713437135371363713737138371393714037141371423714337144371453714637147371483714937150371513715237153371543715537156371573715837159371603716137162371633716437165371663716737168371693717037171371723717337174371753717637177371783717937180371813718237183371843718537186371873718837189371903719137192371933719437195371963719737198371993720037201372023720337204372053720637207372083720937210372113721237213372143721537216372173721837219372203722137222372233722437225372263722737228372293723037231372323723337234372353723637237372383723937240372413724237243372443724537246372473724837249372503725137252372533725437255372563725737258372593726037261372623726337264372653726637267372683726937270372713727237273372743727537276372773727837279372803728137282372833728437285372863728737288372893729037291372923729337294372953729637297372983729937300373013730237303373043730537306373073730837309373103731137312373133731437315373163731737318373193732037321373223732337324373253732637327373283732937330373313733237333373343733537336373373733837339373403734137342373433734437345373463734737348373493735037351373523735337354373553735637357373583735937360373613736237363373643736537366373673736837369373703737137372373733737437375373763737737378373793738037381373823738337384373853738637387373883738937390373913739237393373943739537396373973739837399374003740137402374033740437405374063740737408374093741037411374123741337414374153741637417374183741937420374213742237423374243742537426374273742837429374303743137432374333743437435374363743737438374393744037441374423744337444374453744637447374483744937450374513745237453374543745537456374573745837459374603746137462374633746437465374663746737468374693747037471374723747337474374753747637477374783747937480374813748237483374843748537486374873748837489374903749137492374933749437495374963749737498374993750037501375023750337504375053750637507375083750937510375113751237513375143751537516375173751837519375203752137522375233752437525375263752737528375293753037531375323753337534375353753637537375383753937540375413754237543375443754537546375473754837549375503755137552375533755437555375563755737558375593756037561375623756337564375653756637567375683756937570375713757237573375743757537576375773757837579375803758137582375833758437585375863758737588375893759037591375923759337594375953759637597375983759937600376013760237603376043760537606376073760837609376103761137612376133761437615376163761737618376193762037621376223762337624376253762637627376283762937630376313763237633376343763537636376373763837639376403764137642376433764437645376463764737648376493765037651376523765337654376553765637657376583765937660376613766237663376643766537666376673766837669376703767137672376733767437675376763767737678376793768037681376823768337684376853768637687376883768937690376913769237693376943769537696376973769837699377003770137702377033770437705377063770737708377093771037711377123771337714377153771637717377183771937720377213772237723377243772537726377273772837729377303773137732377333773437735377363773737738377393774037741377423774337744377453774637747377483774937750377513775237753377543775537756377573775837759377603776137762377633776437765377663776737768377693777037771377723777337774377753777637777377783777937780377813778237783377843778537786377873778837789377903779137792377933779437795377963779737798377993780037801378023780337804378053780637807378083780937810378113781237813378143781537816378173781837819378203782137822378233782437825378263782737828378293783037831378323783337834378353783637837378383783937840378413784237843378443784537846378473784837849378503785137852378533785437855378563785737858378593786037861378623786337864378653786637867378683786937870378713787237873378743787537876378773787837879378803788137882378833788437885378863788737888378893789037891378923789337894378953789637897378983789937900379013790237903379043790537906379073790837909379103791137912379133791437915379163791737918379193792037921379223792337924379253792637927379283792937930379313793237933379343793537936379373793837939379403794137942379433794437945379463794737948379493795037951379523795337954379553795637957379583795937960379613796237963379643796537966379673796837969379703797137972379733797437975379763797737978379793798037981379823798337984379853798637987379883798937990379913799237993379943799537996379973799837999380003800138002380033800438005380063800738008380093801038011380123801338014380153801638017380183801938020380213802238023380243802538026380273802838029380303803138032380333803438035380363803738038380393804038041380423804338044380453804638047380483804938050380513805238053380543805538056380573805838059380603806138062380633806438065380663806738068380693807038071380723807338074380753807638077380783807938080380813808238083380843808538086380873808838089380903809138092380933809438095380963809738098380993810038101381023810338104381053810638107381083810938110381113811238113381143811538116381173811838119381203812138122381233812438125381263812738128381293813038131381323813338134381353813638137381383813938140381413814238143381443814538146381473814838149381503815138152381533815438155381563815738158381593816038161381623816338164381653816638167381683816938170381713817238173381743817538176381773817838179381803818138182381833818438185381863818738188381893819038191381923819338194381953819638197381983819938200382013820238203382043820538206382073820838209382103821138212382133821438215382163821738218382193822038221382223822338224382253822638227382283822938230382313823238233382343823538236382373823838239382403824138242382433824438245382463824738248382493825038251382523825338254382553825638257382583825938260382613826238263382643826538266382673826838269382703827138272382733827438275382763827738278382793828038281382823828338284382853828638287382883828938290382913829238293382943829538296382973829838299383003830138302383033830438305383063830738308383093831038311383123831338314383153831638317383183831938320383213832238323383243832538326383273832838329383303833138332383333833438335383363833738338383393834038341383423834338344383453834638347383483834938350383513835238353383543835538356383573835838359383603836138362383633836438365383663836738368383693837038371383723837338374383753837638377383783837938380383813838238383383843838538386383873838838389383903839138392383933839438395383963839738398383993840038401384023840338404384053840638407384083840938410384113841238413384143841538416384173841838419384203842138422384233842438425384263842738428384293843038431384323843338434384353843638437384383843938440384413844238443384443844538446384473844838449384503845138452384533845438455384563845738458384593846038461384623846338464384653846638467384683846938470384713847238473384743847538476384773847838479384803848138482384833848438485384863848738488384893849038491384923849338494384953849638497384983849938500385013850238503385043850538506385073850838509385103851138512385133851438515385163851738518385193852038521385223852338524385253852638527385283852938530385313853238533385343853538536385373853838539385403854138542385433854438545385463854738548385493855038551385523855338554385553855638557385583855938560385613856238563385643856538566385673856838569385703857138572385733857438575385763857738578385793858038581385823858338584385853858638587385883858938590385913859238593385943859538596385973859838599386003860138602386033860438605386063860738608386093861038611386123861338614386153861638617386183861938620386213862238623386243862538626386273862838629386303863138632386333863438635386363863738638386393864038641386423864338644386453864638647386483864938650386513865238653386543865538656386573865838659386603866138662386633866438665386663866738668386693867038671386723867338674386753867638677386783867938680386813868238683386843868538686386873868838689386903869138692386933869438695386963869738698386993870038701387023870338704387053870638707387083870938710387113871238713387143871538716387173871838719387203872138722387233872438725387263872738728387293873038731387323873338734387353873638737387383873938740387413874238743387443874538746387473874838749387503875138752387533875438755387563875738758387593876038761387623876338764387653876638767387683876938770387713877238773387743877538776387773877838779387803878138782387833878438785387863878738788387893879038791387923879338794387953879638797387983879938800388013880238803388043880538806388073880838809388103881138812388133881438815388163881738818388193882038821388223882338824388253882638827388283882938830388313883238833388343883538836388373883838839388403884138842388433884438845388463884738848388493885038851388523885338854388553885638857388583885938860388613886238863388643886538866388673886838869388703887138872388733887438875388763887738878388793888038881388823888338884388853888638887388883888938890388913889238893388943889538896388973889838899389003890138902389033890438905389063890738908389093891038911389123891338914389153891638917389183891938920389213892238923389243892538926389273892838929389303893138932389333893438935389363893738938389393894038941389423894338944389453894638947389483894938950389513895238953389543895538956389573895838959389603896138962389633896438965389663896738968389693897038971389723897338974389753897638977389783897938980389813898238983389843898538986389873898838989389903899138992389933899438995389963899738998389993900039001390023900339004390053900639007390083900939010390113901239013390143901539016390173901839019390203902139022390233902439025390263902739028390293903039031390323903339034390353903639037390383903939040390413904239043390443904539046390473904839049390503905139052390533905439055390563905739058390593906039061390623906339064390653906639067390683906939070390713907239073390743907539076390773907839079390803908139082390833908439085390863908739088390893909039091390923909339094390953909639097390983909939100391013910239103391043910539106391073910839109391103911139112391133911439115391163911739118391193912039121391223912339124391253912639127391283912939130391313913239133391343913539136391373913839139391403914139142391433914439145391463914739148391493915039151391523915339154391553915639157391583915939160391613916239163391643916539166391673916839169391703917139172391733917439175391763917739178391793918039181391823918339184391853918639187391883918939190391913919239193391943919539196391973919839199392003920139202392033920439205392063920739208392093921039211392123921339214392153921639217392183921939220392213922239223392243922539226392273922839229392303923139232392333923439235392363923739238392393924039241392423924339244392453924639247392483924939250392513925239253392543925539256392573925839259392603926139262392633926439265392663926739268392693927039271392723927339274392753927639277392783927939280392813928239283392843928539286392873928839289392903929139292392933929439295392963929739298392993930039301393023930339304393053930639307393083930939310393113931239313393143931539316393173931839319393203932139322393233932439325393263932739328393293933039331393323933339334393353933639337393383933939340393413934239343393443934539346393473934839349393503935139352393533935439355393563935739358393593936039361393623936339364393653936639367393683936939370393713937239373393743937539376393773937839379393803938139382393833938439385393863938739388393893939039391393923939339394393953939639397393983939939400394013940239403394043940539406394073940839409394103941139412394133941439415394163941739418394193942039421394223942339424394253942639427394283942939430394313943239433394343943539436394373943839439394403944139442394433944439445394463944739448394493945039451394523945339454394553945639457394583945939460394613946239463394643946539466394673946839469394703947139472394733947439475394763947739478394793948039481394823948339484394853948639487394883948939490394913949239493394943949539496394973949839499395003950139502395033950439505395063950739508395093951039511395123951339514395153951639517395183951939520395213952239523395243952539526395273952839529395303953139532395333953439535395363953739538395393954039541395423954339544395453954639547395483954939550395513955239553395543955539556395573955839559395603956139562395633956439565395663956739568395693957039571395723957339574395753957639577395783957939580395813958239583395843958539586395873958839589395903959139592395933959439595395963959739598395993960039601396023960339604396053960639607396083960939610396113961239613396143961539616396173961839619396203962139622396233962439625396263962739628396293963039631396323963339634396353963639637396383963939640396413964239643396443964539646396473964839649396503965139652396533965439655396563965739658396593966039661396623966339664396653966639667396683966939670396713967239673396743967539676396773967839679396803968139682396833968439685396863968739688396893969039691396923969339694396953969639697396983969939700397013970239703397043970539706397073970839709397103971139712397133971439715397163971739718397193972039721397223972339724397253972639727397283972939730397313973239733397343973539736397373973839739397403974139742397433974439745397463974739748397493975039751397523975339754397553975639757397583975939760397613976239763397643976539766397673976839769397703977139772397733977439775397763977739778397793978039781397823978339784397853978639787397883978939790397913979239793397943979539796397973979839799398003980139802398033980439805398063980739808398093981039811398123981339814398153981639817398183981939820398213982239823398243982539826398273982839829398303983139832398333983439835398363983739838398393984039841398423984339844398453984639847398483984939850398513985239853398543985539856398573985839859398603986139862398633986439865398663986739868398693987039871398723987339874398753987639877398783987939880398813988239883398843988539886398873988839889398903989139892398933989439895398963989739898398993990039901399023990339904399053990639907399083990939910399113991239913399143991539916399173991839919399203992139922399233992439925399263992739928399293993039931399323993339934399353993639937399383993939940399413994239943399443994539946399473994839949399503995139952399533995439955399563995739958399593996039961399623996339964399653996639967399683996939970399713997239973399743997539976399773997839979399803998139982399833998439985399863998739988399893999039991399923999339994399953999639997399983999940000400014000240003400044000540006400074000840009400104001140012400134001440015400164001740018400194002040021400224002340024400254002640027400284002940030400314003240033400344003540036400374003840039400404004140042400434004440045400464004740048400494005040051400524005340054400554005640057400584005940060400614006240063400644006540066400674006840069400704007140072400734007440075400764007740078400794008040081400824008340084400854008640087400884008940090400914009240093400944009540096400974009840099401004010140102401034010440105401064010740108401094011040111401124011340114401154011640117401184011940120401214012240123401244012540126401274012840129401304013140132401334013440135401364013740138401394014040141401424014340144401454014640147401484014940150401514015240153401544015540156401574015840159401604016140162401634016440165401664016740168401694017040171401724017340174401754017640177401784017940180401814018240183401844018540186401874018840189401904019140192401934019440195401964019740198401994020040201402024020340204402054020640207402084020940210402114021240213402144021540216402174021840219402204022140222402234022440225402264022740228402294023040231402324023340234402354023640237402384023940240402414024240243402444024540246402474024840249402504025140252402534025440255402564025740258402594026040261402624026340264402654026640267402684026940270402714027240273402744027540276402774027840279402804028140282402834028440285402864028740288402894029040291402924029340294402954029640297402984029940300403014030240303403044030540306403074030840309403104031140312403134031440315403164031740318403194032040321403224032340324403254032640327403284032940330403314033240333403344033540336403374033840339403404034140342403434034440345403464034740348403494035040351403524035340354403554035640357403584035940360403614036240363403644036540366403674036840369403704037140372403734037440375403764037740378403794038040381403824038340384403854038640387403884038940390403914039240393403944039540396403974039840399404004040140402404034040440405404064040740408404094041040411404124041340414404154041640417404184041940420404214042240423404244042540426404274042840429404304043140432404334043440435404364043740438404394044040441404424044340444404454044640447404484044940450404514045240453404544045540456404574045840459404604046140462404634046440465404664046740468404694047040471404724047340474404754047640477404784047940480404814048240483404844048540486404874048840489404904049140492404934049440495404964049740498404994050040501405024050340504405054050640507405084050940510405114051240513405144051540516405174051840519405204052140522405234052440525405264052740528405294053040531405324053340534405354053640537405384053940540405414054240543405444054540546405474054840549405504055140552405534055440555405564055740558405594056040561405624056340564405654056640567405684056940570405714057240573405744057540576405774057840579405804058140582405834058440585405864058740588405894059040591405924059340594405954059640597405984059940600406014060240603406044060540606406074060840609406104061140612406134061440615406164061740618406194062040621406224062340624406254062640627406284062940630406314063240633406344063540636406374063840639406404064140642406434064440645406464064740648406494065040651406524065340654406554065640657406584065940660406614066240663406644066540666406674066840669406704067140672406734067440675406764067740678406794068040681406824068340684406854068640687406884068940690406914069240693406944069540696406974069840699407004070140702407034070440705407064070740708407094071040711407124071340714407154071640717407184071940720407214072240723407244072540726407274072840729407304073140732407334073440735407364073740738407394074040741407424074340744407454074640747407484074940750407514075240753407544075540756407574075840759407604076140762407634076440765407664076740768407694077040771407724077340774407754077640777407784077940780407814078240783407844078540786407874078840789407904079140792407934079440795407964079740798407994080040801408024080340804408054080640807408084080940810408114081240813408144081540816408174081840819408204082140822408234082440825408264082740828408294083040831408324083340834408354083640837408384083940840408414084240843408444084540846408474084840849408504085140852408534085440855408564085740858408594086040861408624086340864408654086640867408684086940870408714087240873408744087540876408774087840879408804088140882408834088440885408864088740888408894089040891408924089340894408954089640897408984089940900409014090240903409044090540906409074090840909409104091140912409134091440915409164091740918409194092040921409224092340924409254092640927409284092940930409314093240933409344093540936409374093840939409404094140942409434094440945409464094740948409494095040951409524095340954409554095640957409584095940960409614096240963409644096540966409674096840969409704097140972409734097440975409764097740978409794098040981409824098340984409854098640987409884098940990409914099240993409944099540996409974099840999410004100141002410034100441005410064100741008410094101041011410124101341014410154101641017410184101941020410214102241023410244102541026410274102841029410304103141032410334103441035410364103741038410394104041041410424104341044410454104641047410484104941050410514105241053410544105541056410574105841059410604106141062410634106441065410664106741068410694107041071410724107341074410754107641077410784107941080410814108241083410844108541086410874108841089410904109141092410934109441095410964109741098410994110041101411024110341104411054110641107411084110941110411114111241113411144111541116411174111841119411204112141122411234112441125411264112741128411294113041131411324113341134411354113641137411384113941140411414114241143411444114541146411474114841149411504115141152411534115441155411564115741158411594116041161411624116341164411654116641167411684116941170411714117241173411744117541176411774117841179411804118141182411834118441185411864118741188411894119041191411924119341194411954119641197411984119941200412014120241203412044120541206412074120841209412104121141212412134121441215412164121741218412194122041221412224122341224412254122641227412284122941230412314123241233412344123541236412374123841239412404124141242412434124441245412464124741248412494125041251412524125341254412554125641257412584125941260412614126241263412644126541266412674126841269412704127141272412734127441275412764127741278412794128041281412824128341284412854128641287412884128941290412914129241293412944129541296412974129841299413004130141302413034130441305413064130741308413094131041311413124131341314413154131641317413184131941320413214132241323413244132541326413274132841329413304133141332413334133441335413364133741338413394134041341413424134341344413454134641347413484134941350413514135241353413544135541356413574135841359413604136141362413634136441365413664136741368413694137041371413724137341374413754137641377413784137941380413814138241383413844138541386413874138841389413904139141392413934139441395413964139741398413994140041401414024140341404414054140641407414084140941410414114141241413414144141541416414174141841419414204142141422414234142441425414264142741428414294143041431414324143341434414354143641437414384143941440414414144241443414444144541446414474144841449414504145141452414534145441455414564145741458414594146041461414624146341464414654146641467414684146941470414714147241473414744147541476414774147841479414804148141482414834148441485414864148741488414894149041491414924149341494414954149641497414984149941500415014150241503415044150541506415074150841509415104151141512415134151441515415164151741518415194152041521415224152341524415254152641527415284152941530415314153241533415344153541536415374153841539415404154141542415434154441545415464154741548415494155041551415524155341554415554155641557415584155941560415614156241563415644156541566415674156841569415704157141572415734157441575415764157741578415794158041581415824158341584415854158641587415884158941590415914159241593415944159541596415974159841599416004160141602416034160441605416064160741608416094161041611416124161341614416154161641617416184161941620416214162241623416244162541626416274162841629416304163141632416334163441635416364163741638416394164041641416424164341644416454164641647416484164941650416514165241653416544165541656416574165841659416604166141662416634166441665416664166741668416694167041671416724167341674416754167641677416784167941680416814168241683416844168541686416874168841689416904169141692416934169441695416964169741698416994170041701417024170341704417054170641707417084170941710417114171241713417144171541716417174171841719417204172141722417234172441725417264172741728417294173041731417324173341734417354173641737417384173941740417414174241743417444174541746417474174841749417504175141752417534175441755417564175741758417594176041761417624176341764417654176641767417684176941770417714177241773417744177541776417774177841779417804178141782417834178441785417864178741788417894179041791417924179341794417954179641797417984179941800418014180241803418044180541806418074180841809418104181141812418134181441815418164181741818418194182041821418224182341824418254182641827418284182941830418314183241833418344183541836418374183841839418404184141842418434184441845418464184741848418494185041851418524185341854418554185641857418584185941860418614186241863418644186541866418674186841869418704187141872418734187441875418764187741878418794188041881418824188341884418854188641887418884188941890418914189241893418944189541896418974189841899419004190141902419034190441905419064190741908419094191041911419124191341914419154191641917419184191941920419214192241923419244192541926419274192841929419304193141932419334193441935419364193741938419394194041941419424194341944419454194641947419484194941950419514195241953419544195541956419574195841959419604196141962419634196441965419664196741968419694197041971419724197341974419754197641977419784197941980419814198241983419844198541986419874198841989419904199141992419934199441995419964199741998419994200042001420024200342004420054200642007420084200942010420114201242013420144201542016420174201842019420204202142022420234202442025420264202742028420294203042031420324203342034420354203642037420384203942040420414204242043420444204542046420474204842049420504205142052420534205442055420564205742058420594206042061420624206342064420654206642067420684206942070420714207242073420744207542076420774207842079420804208142082420834208442085420864208742088420894209042091420924209342094420954209642097420984209942100421014210242103421044210542106421074210842109421104211142112421134211442115421164211742118421194212042121421224212342124421254212642127421284212942130421314213242133421344213542136421374213842139421404214142142421434214442145421464214742148421494215042151421524215342154421554215642157421584215942160421614216242163421644216542166421674216842169421704217142172421734217442175421764217742178421794218042181421824218342184421854218642187421884218942190421914219242193421944219542196421974219842199422004220142202422034220442205422064220742208422094221042211422124221342214422154221642217422184221942220422214222242223422244222542226422274222842229422304223142232422334223442235422364223742238422394224042241422424224342244422454224642247422484224942250422514225242253422544225542256422574225842259422604226142262422634226442265422664226742268422694227042271422724227342274422754227642277422784227942280422814228242283422844228542286422874228842289422904229142292422934229442295422964229742298422994230042301423024230342304423054230642307423084230942310423114231242313423144231542316423174231842319423204232142322423234232442325423264232742328423294233042331423324233342334423354233642337423384233942340423414234242343423444234542346423474234842349423504235142352423534235442355423564235742358423594236042361423624236342364423654236642367423684236942370423714237242373423744237542376423774237842379423804238142382423834238442385423864238742388423894239042391423924239342394423954239642397423984239942400424014240242403424044240542406424074240842409424104241142412424134241442415424164241742418424194242042421424224242342424424254242642427424284242942430424314243242433424344243542436424374243842439424404244142442424434244442445424464244742448424494245042451424524245342454424554245642457424584245942460424614246242463424644246542466424674246842469424704247142472424734247442475424764247742478424794248042481424824248342484424854248642487424884248942490424914249242493424944249542496424974249842499425004250142502425034250442505425064250742508425094251042511425124251342514425154251642517425184251942520425214252242523425244252542526425274252842529425304253142532425334253442535425364253742538425394254042541425424254342544425454254642547425484254942550425514255242553425544255542556425574255842559425604256142562425634256442565425664256742568425694257042571425724257342574425754257642577425784257942580425814258242583425844258542586425874258842589425904259142592425934259442595425964259742598425994260042601426024260342604426054260642607426084260942610426114261242613426144261542616426174261842619426204262142622426234262442625426264262742628426294263042631426324263342634426354263642637426384263942640426414264242643426444264542646426474264842649426504265142652426534265442655426564265742658426594266042661426624266342664426654266642667426684266942670426714267242673426744267542676426774267842679426804268142682426834268442685426864268742688426894269042691426924269342694426954269642697426984269942700427014270242703427044270542706427074270842709427104271142712427134271442715427164271742718427194272042721427224272342724427254272642727427284272942730427314273242733427344273542736427374273842739427404274142742427434274442745427464274742748427494275042751427524275342754427554275642757427584275942760427614276242763427644276542766427674276842769427704277142772427734277442775427764277742778427794278042781427824278342784427854278642787427884278942790427914279242793427944279542796427974279842799428004280142802428034280442805428064280742808428094281042811428124281342814428154281642817428184281942820428214282242823428244282542826428274282842829428304283142832428334283442835428364283742838428394284042841428424284342844428454284642847428484284942850428514285242853428544285542856428574285842859428604286142862428634286442865428664286742868428694287042871428724287342874428754287642877428784287942880428814288242883428844288542886428874288842889428904289142892428934289442895428964289742898428994290042901429024290342904429054290642907429084290942910429114291242913429144291542916429174291842919429204292142922429234292442925429264292742928429294293042931429324293342934429354293642937429384293942940429414294242943429444294542946429474294842949429504295142952429534295442955429564295742958429594296042961429624296342964429654296642967429684296942970429714297242973429744297542976429774297842979429804298142982429834298442985429864298742988429894299042991429924299342994429954299642997429984299943000430014300243003430044300543006430074300843009430104301143012430134301443015430164301743018430194302043021430224302343024430254302643027430284302943030430314303243033430344303543036430374303843039430404304143042430434304443045430464304743048430494305043051430524305343054430554305643057430584305943060430614306243063430644306543066430674306843069430704307143072430734307443075430764307743078430794308043081430824308343084430854308643087430884308943090430914309243093430944309543096430974309843099431004310143102431034310443105431064310743108431094311043111431124311343114431154311643117431184311943120431214312243123431244312543126431274312843129431304313143132431334313443135431364313743138431394314043141431424314343144431454314643147431484314943150431514315243153431544315543156431574315843159431604316143162431634316443165431664316743168431694317043171431724317343174431754317643177431784317943180431814318243183431844318543186431874318843189431904319143192431934319443195431964319743198431994320043201432024320343204432054320643207432084320943210432114321243213432144321543216432174321843219432204322143222432234322443225432264322743228432294323043231432324323343234432354323643237432384323943240432414324243243432444324543246432474324843249432504325143252432534325443255432564325743258432594326043261432624326343264432654326643267432684326943270432714327243273432744327543276432774327843279432804328143282432834328443285432864328743288432894329043291432924329343294432954329643297432984329943300433014330243303433044330543306433074330843309433104331143312433134331443315433164331743318433194332043321433224332343324433254332643327433284332943330433314333243333433344333543336433374333843339433404334143342433434334443345433464334743348433494335043351433524335343354433554335643357433584335943360433614336243363433644336543366433674336843369433704337143372433734337443375433764337743378433794338043381433824338343384433854338643387433884338943390433914339243393433944339543396433974339843399434004340143402434034340443405434064340743408434094341043411434124341343414434154341643417434184341943420434214342243423434244342543426434274342843429434304343143432434334343443435434364343743438434394344043441434424344343444434454344643447434484344943450434514345243453434544345543456434574345843459434604346143462434634346443465434664346743468434694347043471434724347343474434754347643477434784347943480434814348243483434844348543486434874348843489434904349143492434934349443495434964349743498434994350043501435024350343504435054350643507435084350943510435114351243513435144351543516435174351843519435204352143522435234352443525435264352743528435294353043531435324353343534435354353643537435384353943540435414354243543435444354543546435474354843549435504355143552435534355443555435564355743558435594356043561435624356343564435654356643567435684356943570435714357243573435744357543576435774357843579435804358143582435834358443585435864358743588435894359043591435924359343594435954359643597435984359943600436014360243603436044360543606436074360843609436104361143612436134361443615436164361743618436194362043621436224362343624436254362643627436284362943630436314363243633436344363543636436374363843639436404364143642436434364443645436464364743648436494365043651436524365343654436554365643657436584365943660436614366243663436644366543666436674366843669436704367143672436734367443675436764367743678436794368043681436824368343684436854368643687436884368943690436914369243693436944369543696436974369843699437004370143702437034370443705437064370743708437094371043711437124371343714437154371643717437184371943720437214372243723437244372543726437274372843729437304373143732437334373443735437364373743738437394374043741437424374343744437454374643747437484374943750437514375243753437544375543756437574375843759437604376143762437634376443765437664376743768437694377043771437724377343774437754377643777437784377943780437814378243783437844378543786437874378843789437904379143792437934379443795437964379743798437994380043801438024380343804438054380643807438084380943810438114381243813438144381543816438174381843819438204382143822438234382443825438264382743828438294383043831438324383343834438354383643837438384383943840438414384243843438444384543846438474384843849438504385143852438534385443855438564385743858438594386043861438624386343864438654386643867438684386943870438714387243873438744387543876438774387843879438804388143882438834388443885438864388743888438894389043891438924389343894438954389643897438984389943900439014390243903439044390543906439074390843909439104391143912439134391443915439164391743918439194392043921439224392343924439254392643927439284392943930439314393243933439344393543936439374393843939439404394143942439434394443945439464394743948439494395043951439524395343954439554395643957439584395943960439614396243963439644396543966439674396843969439704397143972439734397443975439764397743978439794398043981439824398343984439854398643987439884398943990439914399243993439944399543996439974399843999440004400144002440034400444005440064400744008440094401044011440124401344014440154401644017440184401944020440214402244023440244402544026440274402844029440304403144032440334403444035440364403744038440394404044041440424404344044440454404644047440484404944050440514405244053440544405544056440574405844059440604406144062440634406444065440664406744068440694407044071440724407344074440754407644077440784407944080440814408244083440844408544086440874408844089440904409144092440934409444095440964409744098440994410044101441024410344104441054410644107441084410944110441114411244113441144411544116441174411844119441204412144122441234412444125441264412744128441294413044131441324413344134441354413644137441384413944140441414414244143441444414544146441474414844149441504415144152441534415444155441564415744158441594416044161441624416344164441654416644167441684416944170441714417244173441744417544176441774417844179441804418144182441834418444185441864418744188441894419044191441924419344194441954419644197441984419944200442014420244203442044420544206442074420844209442104421144212442134421444215442164421744218442194422044221442224422344224442254422644227442284422944230442314423244233442344423544236442374423844239442404424144242442434424444245442464424744248442494425044251442524425344254442554425644257442584425944260442614426244263442644426544266442674426844269442704427144272442734427444275442764427744278442794428044281442824428344284442854428644287442884428944290442914429244293442944429544296442974429844299443004430144302443034430444305443064430744308443094431044311443124431344314443154431644317443184431944320443214432244323443244432544326443274432844329443304433144332443334433444335443364433744338443394434044341443424434344344443454434644347443484434944350443514435244353443544435544356443574435844359443604436144362443634436444365443664436744368443694437044371443724437344374443754437644377443784437944380443814438244383443844438544386443874438844389443904439144392443934439444395443964439744398443994440044401444024440344404444054440644407444084440944410444114441244413444144441544416444174441844419444204442144422444234442444425444264442744428444294443044431444324443344434444354443644437444384443944440444414444244443444444444544446444474444844449444504445144452444534445444455444564445744458444594446044461444624446344464444654446644467444684446944470444714447244473444744447544476444774447844479444804448144482444834448444485444864448744488444894449044491444924449344494444954449644497444984449944500445014450244503445044450544506445074450844509445104451144512445134451444515445164451744518445194452044521445224452344524445254452644527445284452944530445314453244533445344453544536445374453844539445404454144542445434454444545445464454744548445494455044551445524455344554445554455644557445584455944560445614456244563445644456544566445674456844569445704457144572445734457444575445764457744578445794458044581445824458344584445854458644587445884458944590445914459244593445944459544596445974459844599446004460144602446034460444605446064460744608446094461044611446124461344614446154461644617446184461944620446214462244623446244462544626446274462844629446304463144632446334463444635446364463744638446394464044641446424464344644446454464644647446484464944650446514465244653446544465544656446574465844659446604466144662446634466444665446664466744668446694467044671446724467344674446754467644677446784467944680446814468244683446844468544686446874468844689446904469144692446934469444695446964469744698446994470044701447024470344704447054470644707447084470944710447114471244713447144471544716447174471844719447204472144722447234472444725447264472744728447294473044731447324473344734447354473644737447384473944740447414474244743447444474544746447474474844749447504475144752447534475444755447564475744758447594476044761447624476344764447654476644767447684476944770447714477244773447744477544776447774477844779447804478144782447834478444785447864478744788447894479044791447924479344794447954479644797447984479944800448014480244803448044480544806448074480844809448104481144812448134481444815448164481744818448194482044821448224482344824448254482644827448284482944830448314483244833448344483544836448374483844839448404484144842448434484444845448464484744848448494485044851448524485344854448554485644857448584485944860448614486244863448644486544866448674486844869448704487144872448734487444875448764487744878448794488044881448824488344884448854488644887448884488944890448914489244893448944489544896448974489844899449004490144902449034490444905449064490744908449094491044911449124491344914449154491644917449184491944920449214492244923449244492544926449274492844929449304493144932449334493444935449364493744938449394494044941449424494344944449454494644947449484494944950449514495244953449544495544956449574495844959449604496144962449634496444965449664496744968449694497044971449724497344974449754497644977449784497944980449814498244983449844498544986449874498844989449904499144992449934499444995449964499744998449994500045001450024500345004450054500645007450084500945010450114501245013450144501545016450174501845019450204502145022450234502445025450264502745028450294503045031450324503345034450354503645037450384503945040450414504245043450444504545046450474504845049450504505145052450534505445055450564505745058450594506045061450624506345064450654506645067450684506945070450714507245073450744507545076450774507845079450804508145082450834508445085450864508745088450894509045091450924509345094450954509645097450984509945100451014510245103451044510545106451074510845109451104511145112451134511445115451164511745118451194512045121451224512345124451254512645127451284512945130451314513245133451344513545136451374513845139451404514145142451434514445145451464514745148451494515045151451524515345154451554515645157451584515945160451614516245163451644516545166451674516845169451704517145172451734517445175451764517745178451794518045181451824518345184451854518645187451884518945190451914519245193451944519545196451974519845199452004520145202452034520445205452064520745208452094521045211452124521345214452154521645217452184521945220452214522245223452244522545226452274522845229452304523145232452334523445235452364523745238452394524045241452424524345244452454524645247452484524945250452514525245253452544525545256452574525845259452604526145262452634526445265452664526745268452694527045271452724527345274452754527645277452784527945280452814528245283452844528545286452874528845289452904529145292452934529445295452964529745298452994530045301453024530345304453054530645307453084530945310453114531245313453144531545316453174531845319453204532145322453234532445325453264532745328453294533045331453324533345334453354533645337453384533945340453414534245343453444534545346453474534845349453504535145352453534535445355453564535745358453594536045361453624536345364453654536645367453684536945370453714537245373453744537545376453774537845379453804538145382453834538445385453864538745388453894539045391453924539345394453954539645397453984539945400454014540245403454044540545406454074540845409454104541145412454134541445415454164541745418454194542045421454224542345424454254542645427454284542945430454314543245433454344543545436454374543845439454404544145442454434544445445454464544745448454494545045451454524545345454454554545645457454584545945460454614546245463454644546545466454674546845469454704547145472454734547445475454764547745478454794548045481454824548345484454854548645487454884548945490454914549245493454944549545496454974549845499455004550145502455034550445505455064550745508455094551045511455124551345514455154551645517455184551945520455214552245523455244552545526455274552845529455304553145532455334553445535455364553745538455394554045541455424554345544455454554645547455484554945550455514555245553455544555545556455574555845559455604556145562455634556445565455664556745568455694557045571455724557345574455754557645577455784557945580455814558245583455844558545586455874558845589455904559145592455934559445595455964559745598455994560045601456024560345604456054560645607456084560945610456114561245613456144561545616456174561845619456204562145622456234562445625456264562745628456294563045631456324563345634456354563645637456384563945640456414564245643456444564545646456474564845649456504565145652456534565445655456564565745658456594566045661456624566345664456654566645667456684566945670456714567245673456744567545676456774567845679456804568145682456834568445685456864568745688456894569045691456924569345694456954569645697456984569945700457014570245703457044570545706457074570845709457104571145712457134571445715457164571745718457194572045721457224572345724457254572645727457284572945730457314573245733457344573545736457374573845739457404574145742457434574445745457464574745748457494575045751457524575345754457554575645757457584575945760457614576245763457644576545766457674576845769457704577145772457734577445775457764577745778457794578045781457824578345784457854578645787457884578945790457914579245793457944579545796457974579845799458004580145802458034580445805458064580745808458094581045811458124581345814458154581645817458184581945820458214582245823458244582545826458274582845829458304583145832458334583445835458364583745838458394584045841458424584345844458454584645847458484584945850458514585245853458544585545856458574585845859458604586145862458634586445865458664586745868458694587045871458724587345874458754587645877458784587945880458814588245883458844588545886458874588845889458904589145892458934589445895458964589745898458994590045901459024590345904459054590645907459084590945910459114591245913459144591545916459174591845919459204592145922459234592445925459264592745928459294593045931459324593345934459354593645937459384593945940459414594245943459444594545946459474594845949459504595145952459534595445955459564595745958459594596045961459624596345964459654596645967459684596945970459714597245973459744597545976459774597845979459804598145982459834598445985459864598745988459894599045991459924599345994459954599645997459984599946000460014600246003460044600546006460074600846009460104601146012460134601446015460164601746018460194602046021460224602346024460254602646027460284602946030460314603246033460344603546036460374603846039460404604146042460434604446045460464604746048460494605046051460524605346054460554605646057460584605946060460614606246063460644606546066460674606846069460704607146072460734607446075460764607746078460794608046081460824608346084460854608646087460884608946090460914609246093460944609546096460974609846099461004610146102461034610446105461064610746108461094611046111461124611346114461154611646117461184611946120461214612246123461244612546126461274612846129461304613146132461334613446135461364613746138461394614046141461424614346144461454614646147461484614946150461514615246153461544615546156461574615846159461604616146162461634616446165461664616746168461694617046171461724617346174461754617646177461784617946180461814618246183461844618546186461874618846189461904619146192461934619446195461964619746198461994620046201462024620346204462054620646207462084620946210462114621246213462144621546216462174621846219462204622146222462234622446225462264622746228462294623046231462324623346234462354623646237462384623946240462414624246243462444624546246462474624846249462504625146252462534625446255462564625746258462594626046261462624626346264462654626646267462684626946270462714627246273462744627546276462774627846279462804628146282462834628446285462864628746288462894629046291462924629346294462954629646297462984629946300463014630246303463044630546306463074630846309463104631146312463134631446315463164631746318463194632046321463224632346324463254632646327463284632946330463314633246333463344633546336463374633846339463404634146342463434634446345463464634746348463494635046351463524635346354463554635646357463584635946360463614636246363463644636546366463674636846369463704637146372463734637446375463764637746378463794638046381463824638346384463854638646387463884638946390463914639246393463944639546396463974639846399464004640146402464034640446405464064640746408464094641046411464124641346414464154641646417464184641946420464214642246423464244642546426464274642846429464304643146432464334643446435464364643746438464394644046441464424644346444464454644646447464484644946450464514645246453464544645546456464574645846459464604646146462464634646446465464664646746468464694647046471464724647346474464754647646477464784647946480464814648246483464844648546486464874648846489464904649146492464934649446495464964649746498464994650046501465024650346504465054650646507465084650946510465114651246513465144651546516465174651846519465204652146522465234652446525465264652746528465294653046531465324653346534465354653646537465384653946540465414654246543465444654546546465474654846549465504655146552465534655446555465564655746558465594656046561465624656346564465654656646567465684656946570465714657246573465744657546576465774657846579465804658146582465834658446585465864658746588465894659046591465924659346594465954659646597465984659946600466014660246603466044660546606466074660846609466104661146612466134661446615466164661746618466194662046621466224662346624466254662646627466284662946630466314663246633466344663546636466374663846639466404664146642466434664446645466464664746648466494665046651466524665346654466554665646657466584665946660466614666246663466644666546666466674666846669466704667146672466734667446675466764667746678466794668046681466824668346684466854668646687466884668946690466914669246693466944669546696466974669846699467004670146702467034670446705467064670746708467094671046711467124671346714467154671646717467184671946720467214672246723467244672546726467274672846729467304673146732467334673446735467364673746738467394674046741467424674346744467454674646747467484674946750467514675246753467544675546756467574675846759467604676146762467634676446765467664676746768467694677046771467724677346774467754677646777467784677946780467814678246783467844678546786467874678846789467904679146792467934679446795467964679746798467994680046801468024680346804468054680646807468084680946810468114681246813468144681546816468174681846819468204682146822468234682446825468264682746828468294683046831468324683346834468354683646837468384683946840468414684246843468444684546846468474684846849468504685146852468534685446855468564685746858468594686046861468624686346864468654686646867468684686946870468714687246873468744687546876468774687846879468804688146882468834688446885468864688746888468894689046891468924689346894468954689646897468984689946900469014690246903469044690546906469074690846909469104691146912469134691446915469164691746918469194692046921469224692346924469254692646927469284692946930469314693246933469344693546936469374693846939469404694146942469434694446945469464694746948469494695046951469524695346954469554695646957469584695946960469614696246963469644696546966469674696846969469704697146972469734697446975469764697746978469794698046981469824698346984469854698646987469884698946990469914699246993469944699546996469974699846999470004700147002470034700447005470064700747008470094701047011470124701347014470154701647017470184701947020470214702247023470244702547026470274702847029470304703147032470334703447035470364703747038470394704047041470424704347044470454704647047470484704947050470514705247053470544705547056470574705847059470604706147062470634706447065470664706747068470694707047071470724707347074470754707647077470784707947080470814708247083470844708547086470874708847089470904709147092470934709447095470964709747098470994710047101471024710347104471054710647107471084710947110471114711247113471144711547116471174711847119471204712147122471234712447125471264712747128471294713047131471324713347134471354713647137471384713947140471414714247143471444714547146471474714847149471504715147152471534715447155471564715747158471594716047161471624716347164471654716647167471684716947170471714717247173471744717547176471774717847179471804718147182471834718447185471864718747188471894719047191471924719347194471954719647197471984719947200472014720247203472044720547206472074720847209472104721147212472134721447215472164721747218472194722047221472224722347224472254722647227472284722947230472314723247233472344723547236472374723847239472404724147242472434724447245472464724747248472494725047251472524725347254472554725647257472584725947260472614726247263472644726547266472674726847269472704727147272472734727447275472764727747278472794728047281472824728347284472854728647287472884728947290472914729247293472944729547296472974729847299473004730147302473034730447305473064730747308473094731047311473124731347314473154731647317473184731947320473214732247323473244732547326473274732847329473304733147332473334733447335473364733747338473394734047341473424734347344473454734647347473484734947350473514735247353473544735547356473574735847359473604736147362473634736447365473664736747368473694737047371473724737347374473754737647377473784737947380473814738247383473844738547386473874738847389473904739147392473934739447395473964739747398473994740047401474024740347404474054740647407474084740947410474114741247413474144741547416474174741847419474204742147422474234742447425474264742747428474294743047431474324743347434474354743647437474384743947440474414744247443474444744547446474474744847449474504745147452474534745447455474564745747458474594746047461474624746347464474654746647467474684746947470474714747247473474744747547476474774747847479474804748147482474834748447485474864748747488474894749047491474924749347494474954749647497474984749947500475014750247503475044750547506475074750847509475104751147512475134751447515475164751747518475194752047521475224752347524475254752647527475284752947530475314753247533475344753547536475374753847539475404754147542475434754447545475464754747548475494755047551475524755347554475554755647557475584755947560475614756247563475644756547566475674756847569475704757147572475734757447575475764757747578475794758047581475824758347584475854758647587475884758947590475914759247593475944759547596475974759847599476004760147602476034760447605476064760747608476094761047611476124761347614476154761647617476184761947620476214762247623476244762547626476274762847629476304763147632476334763447635476364763747638476394764047641476424764347644476454764647647476484764947650476514765247653476544765547656476574765847659476604766147662476634766447665476664766747668476694767047671476724767347674476754767647677476784767947680476814768247683476844768547686476874768847689476904769147692476934769447695476964769747698476994770047701477024770347704477054770647707477084770947710477114771247713477144771547716477174771847719477204772147722477234772447725477264772747728477294773047731477324773347734477354773647737477384773947740477414774247743477444774547746477474774847749477504775147752477534775447755477564775747758477594776047761477624776347764477654776647767477684776947770477714777247773477744777547776477774777847779477804778147782477834778447785477864778747788477894779047791477924779347794477954779647797477984779947800478014780247803478044780547806478074780847809478104781147812478134781447815478164781747818478194782047821478224782347824478254782647827478284782947830478314783247833478344783547836478374783847839478404784147842478434784447845478464784747848478494785047851478524785347854478554785647857478584785947860478614786247863478644786547866478674786847869478704787147872478734787447875478764787747878478794788047881478824788347884478854788647887478884788947890478914789247893478944789547896478974789847899479004790147902479034790447905479064790747908479094791047911479124791347914479154791647917479184791947920479214792247923479244792547926479274792847929479304793147932479334793447935479364793747938479394794047941479424794347944479454794647947479484794947950479514795247953479544795547956479574795847959479604796147962479634796447965479664796747968479694797047971479724797347974479754797647977479784797947980479814798247983479844798547986479874798847989479904799147992479934799447995479964799747998479994800048001480024800348004480054800648007480084800948010480114801248013480144801548016480174801848019480204802148022480234802448025480264802748028480294803048031480324803348034480354803648037480384803948040480414804248043480444804548046480474804848049480504805148052480534805448055480564805748058480594806048061480624806348064480654806648067480684806948070480714807248073480744807548076480774807848079480804808148082480834808448085480864808748088480894809048091480924809348094480954809648097480984809948100481014810248103481044810548106481074810848109481104811148112481134811448115481164811748118481194812048121481224812348124481254812648127481284812948130481314813248133481344813548136481374813848139481404814148142481434814448145481464814748148481494815048151481524815348154481554815648157481584815948160481614816248163481644816548166481674816848169481704817148172481734817448175481764817748178481794818048181481824818348184481854818648187481884818948190481914819248193481944819548196481974819848199482004820148202482034820448205482064820748208482094821048211482124821348214482154821648217482184821948220482214822248223482244822548226482274822848229482304823148232482334823448235482364823748238482394824048241482424824348244482454824648247482484824948250482514825248253482544825548256482574825848259482604826148262482634826448265482664826748268482694827048271482724827348274482754827648277482784827948280482814828248283482844828548286482874828848289482904829148292482934829448295482964829748298482994830048301483024830348304483054830648307483084830948310483114831248313483144831548316483174831848319483204832148322483234832448325483264832748328483294833048331483324833348334483354833648337483384833948340483414834248343483444834548346483474834848349483504835148352483534835448355483564835748358483594836048361483624836348364483654836648367483684836948370483714837248373483744837548376483774837848379483804838148382483834838448385483864838748388483894839048391483924839348394483954839648397483984839948400484014840248403484044840548406484074840848409484104841148412484134841448415484164841748418484194842048421484224842348424484254842648427484284842948430484314843248433484344843548436484374843848439484404844148442484434844448445484464844748448484494845048451484524845348454484554845648457484584845948460484614846248463484644846548466484674846848469484704847148472484734847448475484764847748478484794848048481484824848348484484854848648487484884848948490484914849248493484944849548496484974849848499485004850148502485034850448505485064850748508485094851048511485124851348514485154851648517485184851948520485214852248523485244852548526485274852848529485304853148532485334853448535485364853748538485394854048541485424854348544485454854648547485484854948550485514855248553485544855548556485574855848559485604856148562485634856448565485664856748568485694857048571485724857348574485754857648577485784857948580485814858248583485844858548586485874858848589485904859148592485934859448595485964859748598485994860048601486024860348604486054860648607486084860948610486114861248613486144861548616486174861848619486204862148622486234862448625486264862748628486294863048631486324863348634486354863648637486384863948640486414864248643486444864548646486474864848649486504865148652486534865448655486564865748658486594866048661486624866348664486654866648667486684866948670486714867248673486744867548676486774867848679486804868148682486834868448685486864868748688486894869048691486924869348694486954869648697486984869948700487014870248703487044870548706487074870848709487104871148712487134871448715487164871748718487194872048721487224872348724487254872648727487284872948730487314873248733487344873548736487374873848739487404874148742487434874448745487464874748748487494875048751487524875348754487554875648757487584875948760487614876248763487644876548766487674876848769487704877148772487734877448775487764877748778487794878048781487824878348784487854878648787487884878948790487914879248793487944879548796487974879848799488004880148802488034880448805488064880748808488094881048811488124881348814488154881648817488184881948820488214882248823488244882548826488274882848829488304883148832488334883448835488364883748838488394884048841488424884348844488454884648847488484884948850488514885248853488544885548856488574885848859488604886148862488634886448865488664886748868488694887048871488724887348874488754887648877488784887948880488814888248883488844888548886488874888848889488904889148892488934889448895488964889748898488994890048901489024890348904489054890648907489084890948910489114891248913489144891548916489174891848919489204892148922489234892448925489264892748928489294893048931489324893348934489354893648937489384893948940489414894248943489444894548946489474894848949489504895148952489534895448955489564895748958489594896048961489624896348964489654896648967489684896948970489714897248973489744897548976489774897848979489804898148982489834898448985489864898748988489894899048991489924899348994489954899648997489984899949000490014900249003490044900549006490074900849009490104901149012490134901449015490164901749018490194902049021490224902349024490254902649027490284902949030490314903249033490344903549036490374903849039490404904149042490434904449045490464904749048490494905049051490524905349054490554905649057490584905949060490614906249063490644906549066490674906849069490704907149072490734907449075490764907749078490794908049081490824908349084490854908649087490884908949090490914909249093490944909549096490974909849099491004910149102491034910449105491064910749108491094911049111491124911349114491154911649117491184911949120491214912249123491244912549126491274912849129491304913149132491334913449135491364913749138491394914049141491424914349144491454914649147491484914949150491514915249153491544915549156491574915849159491604916149162491634916449165491664916749168491694917049171491724917349174491754917649177491784917949180491814918249183491844918549186491874918849189491904919149192491934919449195491964919749198491994920049201492024920349204492054920649207492084920949210492114921249213492144921549216492174921849219492204922149222492234922449225492264922749228492294923049231492324923349234492354923649237492384923949240492414924249243492444924549246492474924849249492504925149252492534925449255492564925749258492594926049261492624926349264492654926649267492684926949270492714927249273492744927549276492774927849279492804928149282492834928449285492864928749288492894929049291492924929349294492954929649297492984929949300493014930249303493044930549306493074930849309493104931149312493134931449315493164931749318493194932049321493224932349324493254932649327493284932949330493314933249333493344933549336493374933849339493404934149342493434934449345493464934749348493494935049351493524935349354493554935649357493584935949360493614936249363493644936549366493674936849369493704937149372493734937449375493764937749378493794938049381493824938349384493854938649387493884938949390493914939249393493944939549396493974939849399494004940149402494034940449405494064940749408494094941049411494124941349414494154941649417494184941949420494214942249423494244942549426494274942849429494304943149432494334943449435494364943749438494394944049441494424944349444494454944649447494484944949450494514945249453494544945549456494574945849459494604946149462494634946449465494664946749468494694947049471494724947349474494754947649477494784947949480494814948249483494844948549486494874948849489494904949149492494934949449495494964949749498494994950049501495024950349504495054950649507495084950949510495114951249513495144951549516495174951849519495204952149522495234952449525495264952749528495294953049531495324953349534495354953649537495384953949540495414954249543495444954549546495474954849549495504955149552495534955449555495564955749558495594956049561495624956349564495654956649567495684956949570495714957249573495744957549576495774957849579495804958149582495834958449585495864958749588495894959049591495924959349594495954959649597495984959949600496014960249603496044960549606496074960849609496104961149612496134961449615496164961749618496194962049621496224962349624496254962649627496284962949630496314963249633496344963549636496374963849639496404964149642496434964449645496464964749648496494965049651496524965349654496554965649657496584965949660496614966249663496644966549666496674966849669496704967149672496734967449675496764967749678496794968049681496824968349684496854968649687496884968949690496914969249693496944969549696496974969849699497004970149702497034970449705497064970749708497094971049711497124971349714497154971649717497184971949720497214972249723497244972549726497274972849729497304973149732497334973449735497364973749738497394974049741497424974349744497454974649747497484974949750497514975249753497544975549756497574975849759497604976149762497634976449765497664976749768497694977049771497724977349774497754977649777497784977949780497814978249783497844978549786497874978849789497904979149792497934979449795497964979749798497994980049801498024980349804498054980649807498084980949810498114981249813498144981549816498174981849819498204982149822498234982449825498264982749828498294983049831498324983349834498354983649837498384983949840498414984249843498444984549846498474984849849498504985149852498534985449855498564985749858498594986049861498624986349864498654986649867498684986949870498714987249873498744987549876498774987849879498804988149882498834988449885498864988749888498894989049891498924989349894498954989649897498984989949900499014990249903499044990549906499074990849909499104991149912499134991449915499164991749918499194992049921499224992349924499254992649927499284992949930499314993249933499344993549936499374993849939499404994149942499434994449945499464994749948499494995049951499524995349954499554995649957499584995949960499614996249963499644996549966499674996849969499704997149972499734997449975499764997749978499794998049981499824998349984499854998649987499884998949990499914999249993499944999549996499974999849999500005000150002500035000450005500065000750008500095001050011500125001350014500155001650017500185001950020500215002250023500245002550026500275002850029500305003150032500335003450035500365003750038500395004050041500425004350044500455004650047500485004950050500515005250053500545005550056500575005850059500605006150062500635006450065500665006750068500695007050071500725007350074500755007650077500785007950080500815008250083500845008550086500875008850089500905009150092500935009450095500965009750098500995010050101501025010350104501055010650107501085010950110501115011250113501145011550116501175011850119501205012150122501235012450125501265012750128501295013050131501325013350134501355013650137501385013950140501415014250143501445014550146501475014850149501505015150152501535015450155501565015750158501595016050161501625016350164501655016650167501685016950170501715017250173501745017550176501775017850179501805018150182501835018450185501865018750188501895019050191501925019350194501955019650197501985019950200502015020250203502045020550206502075020850209502105021150212502135021450215502165021750218502195022050221502225022350224502255022650227502285022950230502315023250233502345023550236502375023850239502405024150242502435024450245502465024750248502495025050251502525025350254502555025650257502585025950260502615026250263502645026550266502675026850269502705027150272502735027450275502765027750278502795028050281502825028350284502855028650287502885028950290502915029250293502945029550296502975029850299503005030150302503035030450305503065030750308503095031050311503125031350314503155031650317503185031950320503215032250323503245032550326503275032850329503305033150332503335033450335503365033750338503395034050341503425034350344503455034650347503485034950350503515035250353503545035550356503575035850359503605036150362503635036450365503665036750368503695037050371503725037350374503755037650377503785037950380503815038250383503845038550386503875038850389503905039150392503935039450395503965039750398503995040050401504025040350404504055040650407504085040950410504115041250413504145041550416504175041850419504205042150422504235042450425504265042750428504295043050431504325043350434504355043650437504385043950440504415044250443504445044550446504475044850449504505045150452504535045450455504565045750458504595046050461504625046350464504655046650467504685046950470504715047250473504745047550476504775047850479504805048150482504835048450485504865048750488504895049050491504925049350494504955049650497504985049950500505015050250503505045050550506505075050850509505105051150512505135051450515505165051750518505195052050521505225052350524505255052650527505285052950530505315053250533505345053550536505375053850539505405054150542505435054450545505465054750548505495055050551505525055350554505555055650557505585055950560505615056250563505645056550566505675056850569505705057150572505735057450575505765057750578505795058050581505825058350584505855058650587505885058950590505915059250593505945059550596505975059850599506005060150602506035060450605506065060750608506095061050611506125061350614506155061650617506185061950620506215062250623506245062550626506275062850629506305063150632506335063450635506365063750638506395064050641506425064350644506455064650647506485064950650506515065250653506545065550656506575065850659506605066150662506635066450665506665066750668506695067050671506725067350674506755067650677506785067950680506815068250683506845068550686506875068850689506905069150692506935069450695506965069750698506995070050701507025070350704507055070650707507085070950710507115071250713507145071550716507175071850719507205072150722507235072450725507265072750728507295073050731507325073350734507355073650737507385073950740507415074250743507445074550746507475074850749507505075150752507535075450755507565075750758507595076050761507625076350764507655076650767507685076950770507715077250773507745077550776507775077850779507805078150782507835078450785507865078750788507895079050791507925079350794507955079650797507985079950800508015080250803508045080550806508075080850809508105081150812508135081450815508165081750818508195082050821508225082350824508255082650827508285082950830508315083250833508345083550836508375083850839508405084150842508435084450845508465084750848508495085050851508525085350854508555085650857508585085950860508615086250863508645086550866508675086850869508705087150872508735087450875508765087750878508795088050881508825088350884508855088650887508885088950890508915089250893508945089550896508975089850899509005090150902509035090450905509065090750908509095091050911509125091350914509155091650917509185091950920509215092250923509245092550926509275092850929509305093150932509335093450935509365093750938509395094050941509425094350944509455094650947509485094950950509515095250953509545095550956509575095850959509605096150962509635096450965509665096750968509695097050971509725097350974509755097650977509785097950980509815098250983509845098550986509875098850989509905099150992509935099450995509965099750998509995100051001510025100351004510055100651007510085100951010510115101251013510145101551016510175101851019510205102151022510235102451025510265102751028510295103051031510325103351034510355103651037510385103951040510415104251043510445104551046510475104851049510505105151052510535105451055510565105751058510595106051061510625106351064510655106651067510685106951070510715107251073510745107551076510775107851079510805108151082510835108451085510865108751088510895109051091510925109351094510955109651097510985109951100511015110251103511045110551106511075110851109511105111151112511135111451115511165111751118511195112051121511225112351124511255112651127511285112951130511315113251133511345113551136511375113851139511405114151142511435114451145511465114751148511495115051151511525115351154511555115651157511585115951160511615116251163511645116551166511675116851169511705117151172511735117451175511765117751178511795118051181511825118351184511855118651187511885118951190511915119251193511945119551196511975119851199512005120151202512035120451205512065120751208512095121051211512125121351214512155121651217512185121951220512215122251223512245122551226512275122851229512305123151232512335123451235512365123751238512395124051241512425124351244512455124651247512485124951250512515125251253512545125551256512575125851259512605126151262512635126451265512665126751268512695127051271512725127351274512755127651277512785127951280512815128251283512845128551286512875128851289512905129151292512935129451295512965129751298512995130051301513025130351304513055130651307513085130951310513115131251313513145131551316513175131851319513205132151322513235132451325513265132751328513295133051331513325133351334513355133651337513385133951340513415134251343513445134551346513475134851349513505135151352513535135451355513565135751358513595136051361513625136351364513655136651367513685136951370513715137251373513745137551376513775137851379513805138151382513835138451385513865138751388513895139051391513925139351394513955139651397513985139951400514015140251403514045140551406514075140851409514105141151412514135141451415514165141751418514195142051421514225142351424514255142651427514285142951430514315143251433514345143551436514375143851439514405144151442514435144451445514465144751448514495145051451514525145351454514555145651457514585145951460514615146251463514645146551466514675146851469514705147151472514735147451475514765147751478514795148051481514825148351484514855148651487514885148951490514915149251493514945149551496514975149851499515005150151502515035150451505515065150751508515095151051511515125151351514515155151651517515185151951520515215152251523515245152551526515275152851529515305153151532515335153451535515365153751538515395154051541515425154351544515455154651547515485154951550515515155251553515545155551556515575155851559515605156151562515635156451565515665156751568515695157051571515725157351574515755157651577515785157951580515815158251583515845158551586515875158851589515905159151592515935159451595515965159751598515995160051601516025160351604516055160651607516085160951610516115161251613516145161551616516175161851619516205162151622516235162451625516265162751628516295163051631516325163351634516355163651637516385163951640516415164251643516445164551646516475164851649516505165151652516535165451655516565165751658516595166051661516625166351664516655166651667516685166951670516715167251673516745167551676516775167851679516805168151682516835168451685516865168751688516895169051691516925169351694516955169651697516985169951700517015170251703517045170551706517075170851709517105171151712517135171451715517165171751718517195172051721517225172351724517255172651727517285172951730517315173251733517345173551736517375173851739517405174151742517435174451745517465174751748517495175051751517525175351754517555175651757517585175951760517615176251763517645176551766517675176851769517705177151772517735177451775517765177751778517795178051781517825178351784517855178651787517885178951790517915179251793517945179551796517975179851799518005180151802518035180451805518065180751808518095181051811518125181351814518155181651817518185181951820518215182251823518245182551826518275182851829518305183151832518335183451835518365183751838518395184051841518425184351844518455184651847518485184951850518515185251853518545185551856518575185851859518605186151862518635186451865518665186751868518695187051871518725187351874518755187651877518785187951880518815188251883518845188551886518875188851889518905189151892518935189451895518965189751898518995190051901519025190351904519055190651907519085190951910519115191251913519145191551916519175191851919519205192151922519235192451925519265192751928519295193051931519325193351934519355193651937519385193951940519415194251943519445194551946519475194851949519505195151952519535195451955519565195751958519595196051961519625196351964519655196651967519685196951970519715197251973519745197551976519775197851979519805198151982519835198451985519865198751988519895199051991519925199351994519955199651997519985199952000520015200252003520045200552006520075200852009520105201152012520135201452015520165201752018520195202052021520225202352024520255202652027520285202952030520315203252033520345203552036520375203852039520405204152042520435204452045520465204752048520495205052051520525205352054520555205652057520585205952060520615206252063520645206552066520675206852069520705207152072520735207452075520765207752078520795208052081520825208352084520855208652087520885208952090520915209252093520945209552096520975209852099521005210152102521035210452105521065210752108521095211052111521125211352114521155211652117521185211952120521215212252123521245212552126521275212852129521305213152132521335213452135521365213752138521395214052141521425214352144521455214652147521485214952150521515215252153521545215552156521575215852159521605216152162521635216452165521665216752168521695217052171521725217352174521755217652177521785217952180521815218252183521845218552186521875218852189521905219152192521935219452195521965219752198521995220052201522025220352204522055220652207522085220952210522115221252213522145221552216522175221852219522205222152222522235222452225522265222752228522295223052231522325223352234522355223652237522385223952240522415224252243522445224552246522475224852249522505225152252522535225452255522565225752258522595226052261522625226352264522655226652267522685226952270522715227252273522745227552276522775227852279522805228152282522835228452285522865228752288522895229052291522925229352294522955229652297522985229952300523015230252303523045230552306523075230852309523105231152312523135231452315523165231752318523195232052321523225232352324523255232652327523285232952330523315233252333523345233552336523375233852339523405234152342523435234452345523465234752348523495235052351523525235352354523555235652357523585235952360523615236252363523645236552366523675236852369523705237152372523735237452375523765237752378523795238052381523825238352384523855238652387523885238952390523915239252393523945239552396523975239852399524005240152402524035240452405524065240752408524095241052411524125241352414524155241652417524185241952420524215242252423524245242552426524275242852429524305243152432524335243452435524365243752438524395244052441524425244352444524455244652447524485244952450524515245252453524545245552456524575245852459524605246152462524635246452465524665246752468524695247052471524725247352474524755247652477524785247952480524815248252483524845248552486524875248852489524905249152492524935249452495524965249752498524995250052501525025250352504525055250652507525085250952510525115251252513525145251552516525175251852519525205252152522525235252452525525265252752528525295253052531525325253352534525355253652537525385253952540525415254252543525445254552546525475254852549525505255152552525535255452555525565255752558525595256052561525625256352564525655256652567525685256952570525715257252573525745257552576525775257852579525805258152582525835258452585525865258752588525895259052591525925259352594525955259652597525985259952600526015260252603526045260552606526075260852609526105261152612526135261452615526165261752618526195262052621526225262352624526255262652627526285262952630526315263252633526345263552636526375263852639526405264152642526435264452645526465264752648526495265052651526525265352654526555265652657526585265952660526615266252663526645266552666526675266852669526705267152672526735267452675526765267752678526795268052681526825268352684526855268652687526885268952690526915269252693526945269552696526975269852699527005270152702527035270452705527065270752708527095271052711527125271352714527155271652717527185271952720527215272252723527245272552726527275272852729527305273152732527335273452735527365273752738527395274052741527425274352744527455274652747527485274952750527515275252753527545275552756527575275852759527605276152762527635276452765527665276752768527695277052771527725277352774527755277652777527785277952780527815278252783527845278552786527875278852789527905279152792527935279452795527965279752798527995280052801528025280352804528055280652807528085280952810528115281252813528145281552816528175281852819528205282152822528235282452825528265282752828528295283052831528325283352834528355283652837528385283952840528415284252843528445284552846528475284852849528505285152852528535285452855528565285752858528595286052861528625286352864528655286652867528685286952870528715287252873528745287552876528775287852879528805288152882528835288452885528865288752888528895289052891528925289352894528955289652897528985289952900529015290252903529045290552906529075290852909529105291152912529135291452915529165291752918529195292052921529225292352924529255292652927529285292952930529315293252933529345293552936529375293852939529405294152942529435294452945529465294752948529495295052951529525295352954529555295652957529585295952960529615296252963529645296552966529675296852969529705297152972529735297452975529765297752978529795298052981529825298352984529855298652987529885298952990529915299252993529945299552996529975299852999530005300153002530035300453005530065300753008530095301053011530125301353014530155301653017530185301953020530215302253023530245302553026530275302853029530305303153032530335303453035530365303753038530395304053041530425304353044530455304653047530485304953050530515305253053530545305553056530575305853059530605306153062530635306453065530665306753068530695307053071530725307353074530755307653077530785307953080530815308253083530845308553086530875308853089530905309153092530935309453095530965309753098530995310053101531025310353104531055310653107531085310953110531115311253113531145311553116531175311853119531205312153122531235312453125531265312753128531295313053131531325313353134531355313653137531385313953140531415314253143531445314553146531475314853149531505315153152531535315453155531565315753158531595316053161531625316353164531655316653167531685316953170531715317253173531745317553176531775317853179531805318153182531835318453185531865318753188531895319053191531925319353194531955319653197531985319953200532015320253203532045320553206532075320853209532105321153212532135321453215532165321753218532195322053221532225322353224532255322653227532285322953230532315323253233532345323553236532375323853239532405324153242532435324453245532465324753248532495325053251532525325353254532555325653257532585325953260532615326253263532645326553266532675326853269532705327153272532735327453275532765327753278532795328053281532825328353284532855328653287532885328953290532915329253293532945329553296532975329853299533005330153302533035330453305533065330753308533095331053311533125331353314533155331653317533185331953320533215332253323533245332553326533275332853329533305333153332533335333453335533365333753338533395334053341533425334353344533455334653347533485334953350533515335253353533545335553356533575335853359533605336153362533635336453365533665336753368533695337053371533725337353374533755337653377533785337953380533815338253383533845338553386533875338853389533905339153392533935339453395533965339753398533995340053401534025340353404534055340653407534085340953410534115341253413534145341553416534175341853419534205342153422534235342453425534265342753428534295343053431534325343353434534355343653437534385343953440534415344253443534445344553446534475344853449534505345153452534535345453455534565345753458534595346053461534625346353464534655346653467534685346953470534715347253473534745347553476534775347853479534805348153482534835348453485534865348753488534895349053491534925349353494534955349653497534985349953500535015350253503535045350553506535075350853509535105351153512535135351453515535165351753518535195352053521535225352353524535255352653527535285352953530535315353253533535345353553536535375353853539535405354153542535435354453545535465354753548535495355053551535525355353554535555355653557535585355953560535615356253563535645356553566535675356853569535705357153572535735357453575535765357753578535795358053581535825358353584535855358653587535885358953590535915359253593535945359553596535975359853599536005360153602536035360453605536065360753608536095361053611536125361353614536155361653617536185361953620536215362253623536245362553626536275362853629536305363153632536335363453635536365363753638536395364053641536425364353644536455364653647536485364953650536515365253653536545365553656536575365853659536605366153662536635366453665536665366753668536695367053671536725367353674536755367653677536785367953680536815368253683536845368553686536875368853689536905369153692536935369453695536965369753698536995370053701537025370353704537055370653707537085370953710537115371253713537145371553716537175371853719537205372153722537235372453725537265372753728537295373053731537325373353734537355373653737537385373953740537415374253743537445374553746537475374853749537505375153752537535375453755537565375753758537595376053761537625376353764537655376653767537685376953770537715377253773537745377553776537775377853779537805378153782537835378453785537865378753788537895379053791537925379353794537955379653797537985379953800538015380253803538045380553806538075380853809538105381153812538135381453815538165381753818538195382053821538225382353824538255382653827538285382953830538315383253833538345383553836538375383853839538405384153842538435384453845538465384753848538495385053851538525385353854538555385653857538585385953860538615386253863538645386553866538675386853869538705387153872538735387453875538765387753878538795388053881538825388353884538855388653887538885388953890538915389253893538945389553896538975389853899539005390153902539035390453905539065390753908539095391053911539125391353914539155391653917539185391953920539215392253923539245392553926539275392853929539305393153932539335393453935539365393753938539395394053941539425394353944539455394653947539485394953950539515395253953539545395553956539575395853959539605396153962539635396453965539665396753968539695397053971539725397353974539755397653977539785397953980539815398253983539845398553986539875398853989539905399153992539935399453995539965399753998539995400054001540025400354004540055400654007540085400954010540115401254013540145401554016540175401854019540205402154022540235402454025540265402754028540295403054031540325403354034540355403654037540385403954040540415404254043540445404554046540475404854049540505405154052540535405454055540565405754058540595406054061540625406354064540655406654067540685406954070540715407254073540745407554076540775407854079540805408154082540835408454085540865408754088540895409054091540925409354094540955409654097540985409954100541015410254103541045410554106541075410854109541105411154112541135411454115541165411754118541195412054121541225412354124541255412654127541285412954130541315413254133541345413554136541375413854139541405414154142541435414454145541465414754148541495415054151541525415354154541555415654157541585415954160541615416254163541645416554166541675416854169541705417154172541735417454175541765417754178541795418054181541825418354184541855418654187541885418954190541915419254193541945419554196541975419854199542005420154202542035420454205542065420754208542095421054211542125421354214542155421654217542185421954220542215422254223542245422554226542275422854229542305423154232542335423454235542365423754238542395424054241542425424354244542455424654247542485424954250542515425254253542545425554256542575425854259542605426154262542635426454265542665426754268542695427054271542725427354274542755427654277542785427954280542815428254283542845428554286542875428854289542905429154292542935429454295542965429754298542995430054301543025430354304543055430654307543085430954310543115431254313543145431554316543175431854319543205432154322543235432454325543265432754328543295433054331543325433354334543355433654337543385433954340543415434254343543445434554346543475434854349543505435154352543535435454355543565435754358543595436054361543625436354364543655436654367543685436954370543715437254373543745437554376543775437854379543805438154382543835438454385543865438754388543895439054391543925439354394543955439654397543985439954400544015440254403544045440554406544075440854409544105441154412544135441454415544165441754418544195442054421544225442354424544255442654427544285442954430544315443254433544345443554436544375443854439544405444154442544435444454445544465444754448544495445054451544525445354454544555445654457544585445954460544615446254463544645446554466544675446854469544705447154472544735447454475544765447754478544795448054481544825448354484544855448654487544885448954490544915449254493544945449554496544975449854499545005450154502545035450454505545065450754508545095451054511545125451354514545155451654517545185451954520545215452254523545245452554526545275452854529545305453154532545335453454535545365453754538545395454054541545425454354544545455454654547545485454954550545515455254553545545455554556545575455854559545605456154562545635456454565545665456754568545695457054571545725457354574545755457654577545785457954580545815458254583545845458554586545875458854589545905459154592545935459454595545965459754598545995460054601546025460354604546055460654607546085460954610546115461254613546145461554616546175461854619546205462154622546235462454625546265462754628546295463054631546325463354634546355463654637546385463954640546415464254643546445464554646546475464854649546505465154652546535465454655546565465754658546595466054661546625466354664546655466654667546685466954670546715467254673546745467554676546775467854679546805468154682546835468454685546865468754688546895469054691546925469354694546955469654697546985469954700547015470254703547045470554706547075470854709547105471154712547135471454715547165471754718547195472054721547225472354724547255472654727547285472954730547315473254733547345473554736547375473854739547405474154742547435474454745547465474754748547495475054751547525475354754547555475654757547585475954760547615476254763547645476554766547675476854769547705477154772547735477454775547765477754778547795478054781547825478354784547855478654787547885478954790547915479254793547945479554796547975479854799548005480154802548035480454805548065480754808548095481054811548125481354814548155481654817548185481954820548215482254823548245482554826548275482854829548305483154832548335483454835548365483754838548395484054841548425484354844548455484654847548485484954850548515485254853548545485554856548575485854859548605486154862548635486454865548665486754868548695487054871548725487354874548755487654877548785487954880548815488254883548845488554886548875488854889548905489154892548935489454895548965489754898548995490054901549025490354904549055490654907549085490954910549115491254913549145491554916549175491854919549205492154922549235492454925549265492754928549295493054931549325493354934549355493654937549385493954940549415494254943549445494554946549475494854949549505495154952549535495454955549565495754958549595496054961549625496354964549655496654967549685496954970549715497254973549745497554976549775497854979549805498154982549835498454985549865498754988549895499054991549925499354994549955499654997549985499955000550015500255003550045500555006550075500855009550105501155012550135501455015550165501755018550195502055021550225502355024550255502655027550285502955030550315503255033550345503555036550375503855039550405504155042550435504455045550465504755048550495505055051550525505355054550555505655057550585505955060550615506255063550645506555066550675506855069550705507155072550735507455075550765507755078550795508055081550825508355084550855508655087550885508955090550915509255093550945509555096550975509855099551005510155102551035510455105551065510755108551095511055111551125511355114551155511655117551185511955120551215512255123551245512555126551275512855129551305513155132551335513455135551365513755138551395514055141551425514355144551455514655147551485514955150551515515255153551545515555156551575515855159551605516155162551635516455165551665516755168551695517055171551725517355174551755517655177551785517955180551815518255183551845518555186551875518855189551905519155192551935519455195551965519755198551995520055201552025520355204552055520655207552085520955210552115521255213552145521555216552175521855219552205522155222552235522455225552265522755228552295523055231552325523355234552355523655237552385523955240552415524255243552445524555246552475524855249552505525155252552535525455255552565525755258552595526055261552625526355264552655526655267552685526955270552715527255273552745527555276552775527855279552805528155282552835528455285552865528755288552895529055291552925529355294552955529655297552985529955300553015530255303553045530555306553075530855309553105531155312553135531455315553165531755318553195532055321553225532355324553255532655327553285532955330553315533255333553345533555336553375533855339553405534155342553435534455345553465534755348553495535055351553525535355354553555535655357553585535955360553615536255363553645536555366553675536855369553705537155372553735537455375553765537755378553795538055381553825538355384553855538655387553885538955390553915539255393553945539555396553975539855399554005540155402554035540455405554065540755408554095541055411554125541355414554155541655417554185541955420554215542255423554245542555426554275542855429554305543155432554335543455435554365543755438554395544055441554425544355444554455544655447554485544955450554515545255453554545545555456554575545855459554605546155462554635546455465554665546755468554695547055471554725547355474554755547655477554785547955480554815548255483554845548555486554875548855489554905549155492554935549455495554965549755498554995550055501555025550355504555055550655507555085550955510555115551255513555145551555516555175551855519555205552155522555235552455525555265552755528555295553055531555325553355534555355553655537555385553955540555415554255543555445554555546555475554855549555505555155552555535555455555555565555755558555595556055561555625556355564555655556655567555685556955570555715557255573555745557555576555775557855579555805558155582555835558455585555865558755588555895559055591555925559355594555955559655597555985559955600556015560255603556045560555606556075560855609556105561155612556135561455615556165561755618556195562055621556225562355624556255562655627556285562955630556315563255633556345563555636556375563855639556405564155642556435564455645556465564755648556495565055651556525565355654556555565655657556585565955660556615566255663556645566555666556675566855669556705567155672556735567455675556765567755678556795568055681556825568355684556855568655687556885568955690556915569255693556945569555696556975569855699557005570155702557035570455705557065570755708557095571055711557125571355714557155571655717557185571955720557215572255723557245572555726557275572855729557305573155732557335573455735557365573755738557395574055741557425574355744557455574655747557485574955750557515575255753557545575555756557575575855759557605576155762557635576455765557665576755768557695577055771557725577355774557755577655777557785577955780557815578255783557845578555786557875578855789557905579155792557935579455795557965579755798557995580055801558025580355804558055580655807558085580955810558115581255813558145581555816558175581855819558205582155822558235582455825558265582755828558295583055831558325583355834558355583655837558385583955840558415584255843558445584555846558475584855849558505585155852558535585455855558565585755858558595586055861558625586355864558655586655867558685586955870558715587255873558745587555876558775587855879558805588155882558835588455885558865588755888558895589055891558925589355894558955589655897558985589955900559015590255903559045590555906559075590855909559105591155912559135591455915559165591755918559195592055921559225592355924559255592655927559285592955930559315593255933559345593555936559375593855939559405594155942559435594455945559465594755948559495595055951559525595355954559555595655957559585595955960559615596255963559645596555966559675596855969559705597155972559735597455975559765597755978559795598055981559825598355984559855598655987559885598955990559915599255993559945599555996559975599855999560005600156002560035600456005560065600756008560095601056011560125601356014560155601656017560185601956020560215602256023560245602556026560275602856029560305603156032560335603456035560365603756038560395604056041560425604356044560455604656047560485604956050560515605256053560545605556056560575605856059560605606156062560635606456065560665606756068560695607056071560725607356074560755607656077560785607956080560815608256083560845608556086560875608856089560905609156092560935609456095560965609756098560995610056101561025610356104561055610656107561085610956110561115611256113561145611556116561175611856119561205612156122561235612456125561265612756128561295613056131561325613356134561355613656137561385613956140561415614256143561445614556146561475614856149561505615156152561535615456155561565615756158561595616056161561625616356164561655616656167561685616956170561715617256173561745617556176561775617856179561805618156182561835618456185561865618756188561895619056191561925619356194561955619656197561985619956200562015620256203562045620556206562075620856209562105621156212562135621456215562165621756218562195622056221562225622356224562255622656227562285622956230562315623256233562345623556236562375623856239562405624156242562435624456245562465624756248562495625056251562525625356254562555625656257562585625956260562615626256263562645626556266562675626856269562705627156272562735627456275562765627756278562795628056281562825628356284562855628656287562885628956290562915629256293562945629556296562975629856299563005630156302563035630456305563065630756308563095631056311563125631356314563155631656317563185631956320563215632256323563245632556326563275632856329563305633156332563335633456335563365633756338563395634056341563425634356344563455634656347563485634956350563515635256353563545635556356563575635856359563605636156362563635636456365563665636756368563695637056371563725637356374563755637656377563785637956380563815638256383563845638556386563875638856389563905639156392563935639456395563965639756398563995640056401564025640356404564055640656407564085640956410564115641256413564145641556416564175641856419564205642156422564235642456425564265642756428564295643056431564325643356434564355643656437564385643956440564415644256443564445644556446564475644856449564505645156452564535645456455564565645756458564595646056461564625646356464564655646656467564685646956470564715647256473564745647556476564775647856479564805648156482564835648456485564865648756488564895649056491564925649356494564955649656497564985649956500565015650256503565045650556506565075650856509565105651156512565135651456515565165651756518565195652056521565225652356524565255652656527565285652956530565315653256533565345653556536565375653856539565405654156542565435654456545565465654756548565495655056551565525655356554565555655656557565585655956560565615656256563565645656556566565675656856569565705657156572565735657456575565765657756578565795658056581565825658356584565855658656587565885658956590565915659256593565945659556596565975659856599566005660156602566035660456605566065660756608566095661056611566125661356614566155661656617566185661956620566215662256623566245662556626566275662856629566305663156632566335663456635566365663756638566395664056641566425664356644566455664656647566485664956650566515665256653566545665556656566575665856659566605666156662566635666456665566665666756668566695667056671566725667356674566755667656677566785667956680566815668256683566845668556686566875668856689566905669156692566935669456695566965669756698566995670056701567025670356704567055670656707567085670956710567115671256713567145671556716567175671856719567205672156722567235672456725567265672756728567295673056731567325673356734567355673656737567385673956740567415674256743567445674556746567475674856749567505675156752567535675456755567565675756758567595676056761567625676356764567655676656767567685676956770567715677256773567745677556776567775677856779567805678156782567835678456785567865678756788567895679056791567925679356794567955679656797567985679956800568015680256803568045680556806568075680856809568105681156812568135681456815568165681756818568195682056821568225682356824568255682656827568285682956830568315683256833568345683556836568375683856839568405684156842568435684456845568465684756848568495685056851568525685356854568555685656857568585685956860568615686256863568645686556866568675686856869568705687156872568735687456875568765687756878568795688056881568825688356884568855688656887568885688956890568915689256893568945689556896568975689856899569005690156902569035690456905569065690756908569095691056911569125691356914569155691656917569185691956920569215692256923569245692556926569275692856929569305693156932569335693456935569365693756938569395694056941569425694356944569455694656947569485694956950569515695256953569545695556956569575695856959569605696156962569635696456965569665696756968569695697056971569725697356974569755697656977569785697956980569815698256983569845698556986569875698856989569905699156992569935699456995569965699756998569995700057001570025700357004570055700657007570085700957010570115701257013570145701557016570175701857019570205702157022570235702457025570265702757028570295703057031570325703357034570355703657037570385703957040570415704257043570445704557046570475704857049570505705157052570535705457055570565705757058570595706057061570625706357064570655706657067570685706957070570715707257073570745707557076570775707857079570805708157082570835708457085570865708757088570895709057091570925709357094570955709657097570985709957100571015710257103571045710557106571075710857109571105711157112571135711457115571165711757118571195712057121571225712357124571255712657127571285712957130571315713257133571345713557136571375713857139571405714157142571435714457145571465714757148571495715057151571525715357154571555715657157571585715957160571615716257163571645716557166571675716857169571705717157172571735717457175571765717757178571795718057181571825718357184571855718657187571885718957190571915719257193571945719557196571975719857199572005720157202572035720457205572065720757208572095721057211572125721357214572155721657217572185721957220572215722257223572245722557226572275722857229572305723157232572335723457235572365723757238572395724057241572425724357244572455724657247572485724957250572515725257253572545725557256572575725857259572605726157262572635726457265572665726757268572695727057271572725727357274572755727657277572785727957280572815728257283572845728557286572875728857289572905729157292572935729457295572965729757298572995730057301573025730357304573055730657307573085730957310573115731257313573145731557316573175731857319573205732157322573235732457325573265732757328573295733057331573325733357334573355733657337573385733957340573415734257343573445734557346573475734857349573505735157352573535735457355573565735757358573595736057361573625736357364573655736657367573685736957370573715737257373573745737557376573775737857379573805738157382573835738457385573865738757388573895739057391573925739357394573955739657397573985739957400574015740257403574045740557406574075740857409574105741157412574135741457415574165741757418574195742057421574225742357424574255742657427574285742957430574315743257433574345743557436574375743857439574405744157442574435744457445574465744757448574495745057451574525745357454574555745657457574585745957460574615746257463574645746557466574675746857469574705747157472574735747457475574765747757478574795748057481574825748357484574855748657487574885748957490574915749257493574945749557496574975749857499575005750157502575035750457505575065750757508575095751057511575125751357514575155751657517575185751957520575215752257523575245752557526575275752857529575305753157532575335753457535575365753757538575395754057541575425754357544575455754657547575485754957550575515755257553575545755557556575575755857559575605756157562575635756457565575665756757568575695757057571575725757357574575755757657577575785757957580575815758257583575845758557586575875758857589575905759157592575935759457595575965759757598575995760057601576025760357604576055760657607576085760957610576115761257613576145761557616576175761857619576205762157622576235762457625576265762757628576295763057631576325763357634576355763657637576385763957640576415764257643576445764557646576475764857649576505765157652576535765457655576565765757658576595766057661576625766357664576655766657667576685766957670576715767257673576745767557676576775767857679576805768157682576835768457685576865768757688576895769057691576925769357694576955769657697576985769957700577015770257703577045770557706577075770857709577105771157712577135771457715577165771757718577195772057721577225772357724577255772657727577285772957730577315773257733577345773557736577375773857739577405774157742577435774457745577465774757748577495775057751577525775357754577555775657757577585775957760577615776257763577645776557766577675776857769577705777157772577735777457775577765777757778577795778057781577825778357784577855778657787577885778957790577915779257793577945779557796577975779857799578005780157802578035780457805578065780757808578095781057811578125781357814578155781657817578185781957820578215782257823578245782557826578275782857829578305783157832578335783457835578365783757838578395784057841578425784357844578455784657847578485784957850578515785257853578545785557856578575785857859578605786157862578635786457865578665786757868578695787057871578725787357874578755787657877578785787957880578815788257883578845788557886578875788857889578905789157892578935789457895578965789757898578995790057901579025790357904579055790657907579085790957910579115791257913579145791557916579175791857919579205792157922579235792457925579265792757928579295793057931579325793357934579355793657937579385793957940579415794257943579445794557946579475794857949579505795157952579535795457955579565795757958579595796057961579625796357964579655796657967579685796957970579715797257973579745797557976579775797857979579805798157982579835798457985579865798757988579895799057991579925799357994579955799657997579985799958000580015800258003580045800558006580075800858009580105801158012580135801458015580165801758018580195802058021580225802358024580255802658027580285802958030580315803258033580345803558036580375803858039580405804158042580435804458045580465804758048580495805058051580525805358054580555805658057580585805958060580615806258063580645806558066580675806858069580705807158072580735807458075580765807758078580795808058081580825808358084580855808658087580885808958090580915809258093580945809558096580975809858099581005810158102581035810458105581065810758108581095811058111581125811358114581155811658117581185811958120581215812258123581245812558126581275812858129581305813158132581335813458135581365813758138581395814058141581425814358144581455814658147581485814958150581515815258153581545815558156581575815858159581605816158162581635816458165581665816758168581695817058171581725817358174581755817658177581785817958180581815818258183581845818558186581875818858189581905819158192581935819458195581965819758198581995820058201582025820358204582055820658207582085820958210582115821258213582145821558216582175821858219582205822158222582235822458225582265822758228582295823058231582325823358234582355823658237582385823958240582415824258243582445824558246582475824858249582505825158252582535825458255582565825758258582595826058261582625826358264582655826658267582685826958270582715827258273582745827558276582775827858279582805828158282582835828458285582865828758288582895829058291582925829358294582955829658297582985829958300583015830258303583045830558306583075830858309583105831158312583135831458315583165831758318583195832058321583225832358324583255832658327583285832958330583315833258333583345833558336583375833858339583405834158342583435834458345583465834758348583495835058351583525835358354583555835658357583585835958360583615836258363583645836558366583675836858369583705837158372583735837458375583765837758378583795838058381583825838358384583855838658387583885838958390583915839258393583945839558396583975839858399584005840158402584035840458405584065840758408584095841058411584125841358414584155841658417584185841958420584215842258423584245842558426584275842858429584305843158432584335843458435584365843758438584395844058441584425844358444584455844658447584485844958450584515845258453584545845558456584575845858459584605846158462584635846458465584665846758468584695847058471584725847358474584755847658477584785847958480584815848258483584845848558486584875848858489584905849158492584935849458495584965849758498584995850058501585025850358504585055850658507585085850958510585115851258513585145851558516585175851858519585205852158522585235852458525585265852758528585295853058531585325853358534585355853658537585385853958540585415854258543585445854558546585475854858549585505855158552585535855458555585565855758558585595856058561585625856358564585655856658567585685856958570585715857258573585745857558576585775857858579585805858158582585835858458585585865858758588585895859058591585925859358594585955859658597585985859958600586015860258603586045860558606586075860858609586105861158612586135861458615586165861758618586195862058621586225862358624586255862658627586285862958630586315863258633586345863558636586375863858639586405864158642586435864458645586465864758648586495865058651586525865358654586555865658657586585865958660586615866258663586645866558666586675866858669586705867158672586735867458675586765867758678586795868058681586825868358684586855868658687586885868958690586915869258693586945869558696586975869858699587005870158702587035870458705587065870758708587095871058711587125871358714587155871658717587185871958720587215872258723587245872558726587275872858729587305873158732587335873458735587365873758738587395874058741587425874358744587455874658747587485874958750587515875258753587545875558756587575875858759587605876158762587635876458765587665876758768587695877058771587725877358774587755877658777587785877958780587815878258783587845878558786587875878858789587905879158792587935879458795587965879758798587995880058801588025880358804588055880658807588085880958810588115881258813588145881558816588175881858819588205882158822588235882458825588265882758828588295883058831588325883358834588355883658837588385883958840588415884258843588445884558846588475884858849588505885158852588535885458855588565885758858588595886058861588625886358864588655886658867588685886958870588715887258873588745887558876588775887858879588805888158882588835888458885588865888758888588895889058891588925889358894588955889658897588985889958900589015890258903589045890558906589075890858909589105891158912589135891458915589165891758918589195892058921589225892358924589255892658927589285892958930589315893258933589345893558936589375893858939589405894158942589435894458945589465894758948589495895058951589525895358954589555895658957589585895958960589615896258963589645896558966589675896858969589705897158972589735897458975589765897758978589795898058981589825898358984589855898658987589885898958990589915899258993589945899558996589975899858999590005900159002590035900459005590065900759008590095901059011590125901359014590155901659017590185901959020590215902259023590245902559026590275902859029590305903159032590335903459035590365903759038590395904059041590425904359044590455904659047590485904959050590515905259053590545905559056590575905859059590605906159062590635906459065590665906759068590695907059071590725907359074590755907659077590785907959080590815908259083590845908559086590875908859089590905909159092590935909459095590965909759098590995910059101591025910359104591055910659107591085910959110591115911259113591145911559116591175911859119591205912159122591235912459125591265912759128591295913059131591325913359134591355913659137591385913959140591415914259143591445914559146591475914859149591505915159152591535915459155591565915759158591595916059161591625916359164591655916659167591685916959170591715917259173591745917559176591775917859179591805918159182591835918459185591865918759188591895919059191591925919359194591955919659197591985919959200592015920259203592045920559206592075920859209592105921159212592135921459215592165921759218592195922059221592225922359224592255922659227592285922959230592315923259233592345923559236592375923859239592405924159242592435924459245592465924759248592495925059251592525925359254592555925659257592585925959260592615926259263592645926559266592675926859269592705927159272592735927459275592765927759278592795928059281592825928359284592855928659287592885928959290592915929259293592945929559296592975929859299593005930159302593035930459305593065930759308593095931059311593125931359314593155931659317593185931959320593215932259323593245932559326593275932859329593305933159332593335933459335593365933759338593395934059341593425934359344593455934659347593485934959350593515935259353593545935559356593575935859359593605936159362593635936459365593665936759368593695937059371593725937359374593755937659377593785937959380593815938259383593845938559386593875938859389593905939159392593935939459395593965939759398593995940059401594025940359404594055940659407594085940959410594115941259413594145941559416594175941859419594205942159422594235942459425594265942759428594295943059431594325943359434594355943659437594385943959440594415944259443594445944559446594475944859449594505945159452594535945459455594565945759458594595946059461594625946359464594655946659467594685946959470594715947259473594745947559476594775947859479594805948159482594835948459485594865948759488594895949059491594925949359494594955949659497594985949959500595015950259503595045950559506595075950859509595105951159512595135951459515595165951759518595195952059521595225952359524595255952659527595285952959530595315953259533595345953559536595375953859539595405954159542595435954459545595465954759548595495955059551595525955359554595555955659557595585955959560595615956259563595645956559566595675956859569595705957159572595735957459575595765957759578595795958059581595825958359584595855958659587595885958959590595915959259593595945959559596595975959859599596005960159602596035960459605596065960759608596095961059611596125961359614596155961659617596185961959620596215962259623596245962559626596275962859629596305963159632596335963459635596365963759638596395964059641596425964359644596455964659647596485964959650596515965259653596545965559656596575965859659596605966159662596635966459665596665966759668596695967059671596725967359674596755967659677596785967959680596815968259683596845968559686596875968859689596905969159692596935969459695596965969759698596995970059701597025970359704597055970659707597085970959710597115971259713597145971559716597175971859719597205972159722597235972459725597265972759728597295973059731597325973359734597355973659737597385973959740597415974259743597445974559746597475974859749597505975159752597535975459755597565975759758597595976059761597625976359764597655976659767597685976959770597715977259773597745977559776597775977859779597805978159782597835978459785597865978759788597895979059791597925979359794597955979659797597985979959800598015980259803598045980559806598075980859809598105981159812598135981459815598165981759818598195982059821598225982359824598255982659827598285982959830598315983259833598345983559836598375983859839598405984159842598435984459845598465984759848598495985059851598525985359854598555985659857598585985959860598615986259863598645986559866598675986859869598705987159872598735987459875598765987759878598795988059881598825988359884598855988659887598885988959890598915989259893598945989559896598975989859899599005990159902599035990459905599065990759908599095991059911599125991359914599155991659917599185991959920599215992259923599245992559926599275992859929599305993159932599335993459935599365993759938599395994059941599425994359944599455994659947599485994959950599515995259953599545995559956599575995859959599605996159962599635996459965599665996759968599695997059971599725997359974599755997659977599785997959980599815998259983599845998559986599875998859989599905999159992599935999459995599965999759998599996000060001600026000360004600056000660007600086000960010600116001260013600146001560016600176001860019600206002160022600236002460025600266002760028600296003060031600326003360034600356003660037600386003960040600416004260043600446004560046600476004860049600506005160052600536005460055600566005760058600596006060061600626006360064600656006660067600686006960070600716007260073600746007560076600776007860079600806008160082600836008460085600866008760088600896009060091600926009360094600956009660097600986009960100601016010260103601046010560106601076010860109601106011160112601136011460115601166011760118601196012060121601226012360124601256012660127601286012960130601316013260133601346013560136601376013860139601406014160142601436014460145601466014760148601496015060151601526015360154601556015660157601586015960160601616016260163601646016560166601676016860169601706017160172601736017460175601766017760178601796018060181601826018360184601856018660187601886018960190601916019260193601946019560196601976019860199602006020160202602036020460205602066020760208602096021060211602126021360214602156021660217602186021960220602216022260223602246022560226602276022860229602306023160232602336023460235602366023760238602396024060241602426024360244602456024660247602486024960250602516025260253602546025560256602576025860259602606026160262602636026460265602666026760268602696027060271602726027360274602756027660277602786027960280602816028260283602846028560286602876028860289602906029160292602936029460295602966029760298602996030060301603026030360304603056030660307603086030960310603116031260313603146031560316603176031860319603206032160322603236032460325603266032760328603296033060331603326033360334603356033660337603386033960340603416034260343603446034560346603476034860349603506035160352603536035460355603566035760358603596036060361603626036360364603656036660367603686036960370603716037260373603746037560376603776037860379603806038160382603836038460385603866038760388603896039060391603926039360394603956039660397603986039960400604016040260403604046040560406604076040860409604106041160412604136041460415604166041760418604196042060421604226042360424604256042660427604286042960430604316043260433604346043560436604376043860439604406044160442604436044460445604466044760448604496045060451604526045360454604556045660457604586045960460604616046260463604646046560466604676046860469604706047160472604736047460475604766047760478604796048060481604826048360484604856048660487604886048960490604916049260493604946049560496604976049860499605006050160502605036050460505605066050760508605096051060511605126051360514605156051660517605186051960520605216052260523605246052560526605276052860529605306053160532605336053460535605366053760538605396054060541605426054360544605456054660547605486054960550605516055260553605546055560556605576055860559605606056160562605636056460565605666056760568605696057060571605726057360574605756057660577605786057960580605816058260583605846058560586605876058860589605906059160592605936059460595605966059760598605996060060601606026060360604606056060660607606086060960610606116061260613606146061560616606176061860619606206062160622606236062460625606266062760628606296063060631606326063360634606356063660637606386063960640606416064260643606446064560646606476064860649606506065160652606536065460655606566065760658606596066060661606626066360664606656066660667606686066960670606716067260673606746067560676606776067860679606806068160682606836068460685606866068760688606896069060691606926069360694606956069660697606986069960700607016070260703607046070560706607076070860709607106071160712607136071460715607166071760718607196072060721607226072360724607256072660727607286072960730607316073260733607346073560736607376073860739607406074160742607436074460745607466074760748607496075060751607526075360754607556075660757607586075960760607616076260763607646076560766607676076860769607706077160772607736077460775607766077760778607796078060781607826078360784607856078660787607886078960790607916079260793607946079560796607976079860799608006080160802608036080460805608066080760808608096081060811608126081360814608156081660817608186081960820608216082260823608246082560826608276082860829608306083160832608336083460835608366083760838608396084060841608426084360844608456084660847608486084960850608516085260853608546085560856608576085860859608606086160862608636086460865608666086760868608696087060871608726087360874608756087660877608786087960880608816088260883608846088560886608876088860889608906089160892608936089460895608966089760898608996090060901609026090360904609056090660907609086090960910609116091260913609146091560916609176091860919609206092160922609236092460925609266092760928609296093060931609326093360934609356093660937609386093960940609416094260943609446094560946609476094860949609506095160952609536095460955609566095760958609596096060961609626096360964609656096660967609686096960970609716097260973609746097560976609776097860979609806098160982609836098460985609866098760988609896099060991609926099360994609956099660997609986099961000610016100261003610046100561006610076100861009610106101161012610136101461015610166101761018610196102061021610226102361024610256102661027610286102961030610316103261033610346103561036610376103861039610406104161042610436104461045610466104761048610496105061051610526105361054610556105661057610586105961060610616106261063610646106561066610676106861069610706107161072610736107461075610766107761078610796108061081610826108361084610856108661087610886108961090610916109261093610946109561096610976109861099611006110161102611036110461105611066110761108611096111061111611126111361114611156111661117611186111961120611216112261123611246112561126611276112861129611306113161132611336113461135611366113761138611396114061141611426114361144611456114661147611486114961150611516115261153611546115561156611576115861159611606116161162611636116461165611666116761168611696117061171611726117361174611756117661177611786117961180611816118261183611846118561186611876118861189611906119161192611936119461195611966119761198611996120061201612026120361204612056120661207612086120961210612116121261213612146121561216612176121861219612206122161222612236122461225612266122761228612296123061231612326123361234612356123661237612386123961240612416124261243612446124561246612476124861249612506125161252612536125461255612566125761258612596126061261612626126361264612656126661267612686126961270612716127261273612746127561276612776127861279612806128161282612836128461285612866128761288612896129061291612926129361294612956129661297612986129961300613016130261303613046130561306613076130861309613106131161312613136131461315613166131761318613196132061321613226132361324613256132661327613286132961330613316133261333613346133561336613376133861339613406134161342613436134461345613466134761348613496135061351613526135361354613556135661357613586135961360613616136261363613646136561366613676136861369613706137161372613736137461375613766137761378613796138061381613826138361384613856138661387613886138961390613916139261393613946139561396613976139861399614006140161402614036140461405614066140761408614096141061411614126141361414614156141661417614186141961420614216142261423614246142561426614276142861429614306143161432614336143461435614366143761438614396144061441614426144361444614456144661447614486144961450614516145261453614546145561456614576145861459614606146161462614636146461465614666146761468614696147061471614726147361474614756147661477614786147961480614816148261483614846148561486614876148861489614906149161492614936149461495614966149761498614996150061501615026150361504615056150661507615086150961510615116151261513615146151561516615176151861519615206152161522615236152461525615266152761528615296153061531615326153361534615356153661537615386153961540615416154261543615446154561546615476154861549615506155161552615536155461555615566155761558615596156061561615626156361564615656156661567615686156961570615716157261573615746157561576615776157861579615806158161582615836158461585615866158761588615896159061591615926159361594615956159661597615986159961600616016160261603616046160561606616076160861609616106161161612616136161461615616166161761618616196162061621616226162361624616256162661627616286162961630616316163261633616346163561636616376163861639616406164161642616436164461645616466164761648616496165061651616526165361654616556165661657616586165961660616616166261663616646166561666616676166861669616706167161672616736167461675616766167761678616796168061681616826168361684616856168661687616886168961690616916169261693616946169561696616976169861699617006170161702617036170461705617066170761708617096171061711617126171361714617156171661717617186171961720617216172261723617246172561726617276172861729617306173161732617336173461735617366173761738617396174061741617426174361744617456174661747617486174961750617516175261753617546175561756617576175861759617606176161762617636176461765617666176761768617696177061771617726177361774617756177661777617786177961780617816178261783617846178561786617876178861789617906179161792617936179461795617966179761798617996180061801618026180361804618056180661807618086180961810618116181261813618146181561816618176181861819618206182161822618236182461825618266182761828618296183061831618326183361834618356183661837618386183961840618416184261843618446184561846618476184861849618506185161852618536185461855618566185761858618596186061861618626186361864618656186661867618686186961870618716187261873618746187561876618776187861879618806188161882618836188461885618866188761888618896189061891618926189361894618956189661897618986189961900619016190261903619046190561906619076190861909619106191161912619136191461915619166191761918619196192061921619226192361924619256192661927619286192961930619316193261933619346193561936619376193861939619406194161942619436194461945619466194761948619496195061951619526195361954619556195661957619586195961960619616196261963619646196561966619676196861969619706197161972619736197461975619766197761978619796198061981619826198361984619856198661987619886198961990619916199261993619946199561996619976199861999620006200162002620036200462005620066200762008620096201062011620126201362014620156201662017620186201962020620216202262023620246202562026620276202862029620306203162032620336203462035620366203762038620396204062041620426204362044620456204662047620486204962050620516205262053620546205562056620576205862059620606206162062620636206462065620666206762068620696207062071620726207362074620756207662077620786207962080620816208262083620846208562086620876208862089620906209162092620936209462095620966209762098620996210062101621026210362104621056210662107621086210962110621116211262113621146211562116621176211862119621206212162122621236212462125621266212762128621296213062131621326213362134621356213662137621386213962140621416214262143621446214562146621476214862149621506215162152621536215462155621566215762158621596216062161621626216362164621656216662167621686216962170621716217262173621746217562176621776217862179621806218162182621836218462185621866218762188621896219062191621926219362194621956219662197621986219962200622016220262203622046220562206622076220862209622106221162212622136221462215622166221762218622196222062221622226222362224622256222662227622286222962230622316223262233622346223562236622376223862239622406224162242622436224462245622466224762248622496225062251622526225362254622556225662257622586225962260622616226262263622646226562266622676226862269622706227162272622736227462275622766227762278622796228062281622826228362284622856228662287622886228962290622916229262293622946229562296622976229862299623006230162302623036230462305623066230762308623096231062311623126231362314623156231662317623186231962320623216232262323623246232562326623276232862329623306233162332623336233462335623366233762338623396234062341623426234362344623456234662347623486234962350623516235262353623546235562356623576235862359623606236162362623636236462365623666236762368623696237062371623726237362374623756237662377623786237962380623816238262383623846238562386623876238862389623906239162392623936239462395623966239762398623996240062401624026240362404624056240662407624086240962410624116241262413624146241562416624176241862419624206242162422624236242462425624266242762428624296243062431624326243362434624356243662437624386243962440624416244262443624446244562446624476244862449624506245162452624536245462455624566245762458624596246062461624626246362464624656246662467624686246962470624716247262473624746247562476624776247862479624806248162482624836248462485624866248762488624896249062491624926249362494624956249662497624986249962500625016250262503625046250562506625076250862509625106251162512625136251462515625166251762518625196252062521625226252362524625256252662527625286252962530625316253262533625346253562536625376253862539625406254162542625436254462545625466254762548625496255062551625526255362554625556255662557625586255962560625616256262563625646256562566625676256862569625706257162572625736257462575625766257762578625796258062581625826258362584625856258662587625886258962590625916259262593625946259562596625976259862599626006260162602626036260462605626066260762608626096261062611626126261362614626156261662617626186261962620626216262262623626246262562626626276262862629626306263162632626336263462635626366263762638626396264062641626426264362644626456264662647626486264962650626516265262653626546265562656626576265862659626606266162662626636266462665626666266762668626696267062671626726267362674626756267662677626786267962680626816268262683626846268562686626876268862689626906269162692626936269462695626966269762698626996270062701627026270362704627056270662707627086270962710627116271262713627146271562716627176271862719627206272162722627236272462725627266272762728627296273062731627326273362734627356273662737627386273962740627416274262743627446274562746627476274862749627506275162752627536275462755627566275762758627596276062761627626276362764627656276662767627686276962770627716277262773627746277562776627776277862779627806278162782627836278462785627866278762788627896279062791627926279362794627956279662797627986279962800628016280262803628046280562806628076280862809628106281162812628136281462815628166281762818628196282062821628226282362824628256282662827628286282962830628316283262833628346283562836628376283862839628406284162842628436284462845628466284762848628496285062851628526285362854628556285662857628586285962860628616286262863628646286562866628676286862869628706287162872628736287462875628766287762878628796288062881628826288362884628856288662887628886288962890628916289262893628946289562896628976289862899629006290162902629036290462905629066290762908629096291062911629126291362914629156291662917629186291962920629216292262923629246292562926629276292862929629306293162932629336293462935629366293762938629396294062941629426294362944629456294662947629486294962950629516295262953629546295562956629576295862959629606296162962629636296462965629666296762968629696297062971629726297362974629756297662977629786297962980629816298262983629846298562986629876298862989629906299162992629936299462995629966299762998629996300063001630026300363004630056300663007630086300963010630116301263013630146301563016630176301863019630206302163022630236302463025630266302763028630296303063031630326303363034630356303663037630386303963040630416304263043630446304563046630476304863049630506305163052630536305463055630566305763058630596306063061630626306363064630656306663067630686306963070630716307263073630746307563076630776307863079630806308163082630836308463085630866308763088630896309063091630926309363094630956309663097630986309963100631016310263103631046310563106631076310863109631106311163112631136311463115631166311763118631196312063121631226312363124631256312663127631286312963130631316313263133631346313563136631376313863139631406314163142631436314463145631466314763148631496315063151631526315363154631556315663157631586315963160631616316263163631646316563166631676316863169631706317163172631736317463175631766317763178631796318063181631826318363184631856318663187631886318963190631916319263193631946319563196631976319863199632006320163202632036320463205632066320763208632096321063211632126321363214632156321663217632186321963220632216322263223632246322563226632276322863229632306323163232632336323463235632366323763238632396324063241632426324363244632456324663247632486324963250632516325263253632546325563256632576325863259632606326163262632636326463265632666326763268632696327063271632726327363274632756327663277632786327963280632816328263283632846328563286632876328863289632906329163292632936329463295632966329763298632996330063301633026330363304633056330663307633086330963310633116331263313633146331563316633176331863319633206332163322633236332463325633266332763328633296333063331633326333363334633356333663337633386333963340633416334263343633446334563346633476334863349633506335163352633536335463355633566335763358633596336063361633626336363364633656336663367633686336963370633716337263373633746337563376633776337863379633806338163382633836338463385633866338763388633896339063391633926339363394633956339663397633986339963400634016340263403634046340563406634076340863409634106341163412634136341463415634166341763418634196342063421634226342363424634256342663427634286342963430634316343263433634346343563436634376343863439634406344163442634436344463445634466344763448634496345063451634526345363454634556345663457634586345963460634616346263463634646346563466634676346863469634706347163472634736347463475634766347763478634796348063481634826348363484634856348663487634886348963490634916349263493634946349563496634976349863499635006350163502635036350463505635066350763508635096351063511635126351363514635156351663517635186351963520635216352263523635246352563526635276352863529635306353163532635336353463535635366353763538635396354063541635426354363544635456354663547635486354963550635516355263553635546355563556635576355863559635606356163562635636356463565635666356763568635696357063571635726357363574635756357663577635786357963580635816358263583635846358563586635876358863589635906359163592635936359463595635966359763598635996360063601636026360363604636056360663607636086360963610636116361263613636146361563616636176361863619636206362163622636236362463625636266362763628636296363063631636326363363634636356363663637636386363963640636416364263643636446364563646636476364863649636506365163652636536365463655636566365763658636596366063661636626366363664636656366663667636686366963670636716367263673636746367563676636776367863679636806368163682636836368463685636866368763688636896369063691636926369363694636956369663697636986369963700637016370263703637046370563706637076370863709637106371163712637136371463715637166371763718637196372063721637226372363724637256372663727637286372963730637316373263733637346373563736637376373863739637406374163742637436374463745637466374763748637496375063751637526375363754637556375663757637586375963760637616376263763637646376563766637676376863769637706377163772637736377463775637766377763778637796378063781637826378363784637856378663787637886378963790637916379263793637946379563796637976379863799638006380163802638036380463805638066380763808638096381063811638126381363814638156381663817638186381963820638216382263823638246382563826638276382863829638306383163832638336383463835638366383763838638396384063841638426384363844638456384663847638486384963850638516385263853638546385563856638576385863859638606386163862638636386463865638666386763868638696387063871638726387363874638756387663877638786387963880638816388263883638846388563886638876388863889638906389163892638936389463895638966389763898638996390063901639026390363904639056390663907639086390963910639116391263913639146391563916639176391863919639206392163922639236392463925639266392763928639296393063931639326393363934639356393663937639386393963940639416394263943639446394563946639476394863949639506395163952639536395463955639566395763958639596396063961639626396363964639656396663967639686396963970639716397263973639746397563976639776397863979639806398163982639836398463985639866398763988639896399063991639926399363994639956399663997639986399964000640016400264003640046400564006640076400864009640106401164012640136401464015640166401764018640196402064021640226402364024640256402664027640286402964030640316403264033640346403564036640376403864039640406404164042640436404464045640466404764048640496405064051640526405364054640556405664057640586405964060640616406264063640646406564066640676406864069640706407164072640736407464075640766407764078640796408064081640826408364084640856408664087640886408964090640916409264093640946409564096640976409864099641006410164102641036410464105641066410764108641096411064111641126411364114641156411664117641186411964120641216412264123641246412564126641276412864129641306413164132641336413464135641366413764138641396414064141641426414364144641456414664147641486414964150641516415264153641546415564156641576415864159641606416164162641636416464165641666416764168641696417064171641726417364174641756417664177641786417964180641816418264183641846418564186641876418864189641906419164192641936419464195641966419764198641996420064201642026420364204642056420664207642086420964210642116421264213642146421564216642176421864219642206422164222642236422464225642266422764228642296423064231642326423364234642356423664237642386423964240642416424264243642446424564246642476424864249642506425164252642536425464255642566425764258642596426064261642626426364264642656426664267642686426964270642716427264273642746427564276642776427864279642806428164282642836428464285642866428764288642896429064291642926429364294642956429664297642986429964300643016430264303643046430564306643076430864309643106431164312643136431464315643166431764318643196432064321643226432364324643256432664327643286432964330643316433264333643346433564336643376433864339643406434164342643436434464345643466434764348643496435064351643526435364354643556435664357643586435964360643616436264363643646436564366643676436864369643706437164372643736437464375643766437764378643796438064381643826438364384643856438664387643886438964390643916439264393643946439564396643976439864399644006440164402644036440464405644066440764408644096441064411644126441364414644156441664417644186441964420644216442264423644246442564426644276442864429644306443164432644336443464435644366443764438644396444064441644426444364444644456444664447644486444964450644516445264453644546445564456644576445864459644606446164462644636446464465644666446764468644696447064471644726447364474644756447664477644786447964480644816448264483644846448564486644876448864489644906449164492644936449464495644966449764498644996450064501645026450364504645056450664507645086450964510645116451264513645146451564516645176451864519645206452164522645236452464525645266452764528645296453064531645326453364534645356453664537645386453964540645416454264543645446454564546645476454864549645506455164552645536455464555645566455764558645596456064561645626456364564645656456664567645686456964570645716457264573645746457564576645776457864579645806458164582645836458464585645866458764588645896459064591645926459364594645956459664597645986459964600646016460264603646046460564606646076460864609646106461164612646136461464615646166461764618646196462064621646226462364624646256462664627646286462964630646316463264633646346463564636646376463864639646406464164642646436464464645646466464764648646496465064651646526465364654646556465664657646586465964660646616466264663646646466564666646676466864669646706467164672646736467464675646766467764678646796468064681646826468364684646856468664687646886468964690646916469264693646946469564696646976469864699647006470164702647036470464705647066470764708647096471064711647126471364714647156471664717647186471964720647216472264723647246472564726647276472864729647306473164732647336473464735647366473764738647396474064741647426474364744647456474664747647486474964750647516475264753647546475564756647576475864759647606476164762647636476464765647666476764768647696477064771647726477364774647756477664777647786477964780647816478264783647846478564786647876478864789647906479164792647936479464795647966479764798647996480064801648026480364804648056480664807648086480964810648116481264813648146481564816648176481864819648206482164822648236482464825648266482764828648296483064831648326483364834648356483664837648386483964840648416484264843648446484564846648476484864849648506485164852648536485464855648566485764858648596486064861648626486364864648656486664867648686486964870648716487264873648746487564876648776487864879648806488164882648836488464885648866488764888648896489064891648926489364894648956489664897648986489964900649016490264903649046490564906649076490864909649106491164912649136491464915649166491764918649196492064921649226492364924649256492664927649286492964930649316493264933649346493564936649376493864939649406494164942649436494464945649466494764948649496495064951649526495364954649556495664957649586495964960649616496264963649646496564966649676496864969649706497164972649736497464975649766497764978649796498064981649826498364984649856498664987649886498964990649916499264993649946499564996649976499864999650006500165002650036500465005650066500765008650096501065011650126501365014650156501665017650186501965020650216502265023650246502565026650276502865029650306503165032650336503465035650366503765038650396504065041650426504365044650456504665047650486504965050650516505265053650546505565056650576505865059650606506165062650636506465065650666506765068650696507065071650726507365074650756507665077650786507965080650816508265083650846508565086650876508865089650906509165092650936509465095650966509765098650996510065101651026510365104651056510665107651086510965110651116511265113651146511565116651176511865119651206512165122651236512465125651266512765128651296513065131651326513365134651356513665137651386513965140651416514265143651446514565146651476514865149651506515165152651536515465155651566515765158651596516065161651626516365164651656516665167651686516965170651716517265173651746517565176651776517865179651806518165182651836518465185651866518765188651896519065191651926519365194651956519665197651986519965200652016520265203652046520565206652076520865209652106521165212652136521465215652166521765218652196522065221652226522365224652256522665227652286522965230652316523265233652346523565236652376523865239652406524165242652436524465245652466524765248652496525065251652526525365254652556525665257652586525965260652616526265263652646526565266652676526865269652706527165272652736527465275652766527765278652796528065281652826528365284652856528665287652886528965290652916529265293652946529565296652976529865299653006530165302653036530465305653066530765308653096531065311653126531365314653156531665317653186531965320653216532265323653246532565326653276532865329653306533165332653336533465335653366533765338653396534065341653426534365344653456534665347653486534965350653516535265353653546535565356653576535865359653606536165362653636536465365653666536765368653696537065371653726537365374653756537665377653786537965380653816538265383653846538565386653876538865389653906539165392653936539465395653966539765398653996540065401654026540365404654056540665407654086540965410654116541265413654146541565416654176541865419654206542165422654236542465425654266542765428654296543065431654326543365434654356543665437654386543965440654416544265443654446544565446654476544865449654506545165452654536545465455654566545765458654596546065461654626546365464654656546665467654686546965470654716547265473654746547565476654776547865479654806548165482654836548465485654866548765488654896549065491654926549365494654956549665497654986549965500655016550265503655046550565506655076550865509655106551165512655136551465515655166551765518655196552065521655226552365524655256552665527655286552965530655316553265533655346553565536655376553865539655406554165542655436554465545655466554765548655496555065551655526555365554655556555665557655586555965560655616556265563655646556565566655676556865569655706557165572655736557465575655766557765578655796558065581655826558365584655856558665587655886558965590655916559265593655946559565596655976559865599656006560165602656036560465605656066560765608656096561065611656126561365614656156561665617656186561965620656216562265623656246562565626656276562865629656306563165632656336563465635656366563765638656396564065641656426564365644656456564665647656486564965650656516565265653656546565565656656576565865659656606566165662656636566465665656666566765668656696567065671656726567365674656756567665677656786567965680656816568265683656846568565686656876568865689656906569165692656936569465695656966569765698656996570065701657026570365704657056570665707657086570965710657116571265713657146571565716657176571865719657206572165722657236572465725657266572765728657296573065731657326573365734657356573665737657386573965740657416574265743657446574565746657476574865749657506575165752657536575465755657566575765758657596576065761657626576365764657656576665767657686576965770657716577265773657746577565776657776577865779657806578165782657836578465785657866578765788657896579065791657926579365794657956579665797657986579965800658016580265803658046580565806658076580865809658106581165812658136581465815658166581765818658196582065821658226582365824658256582665827658286582965830658316583265833658346583565836658376583865839658406584165842658436584465845658466584765848658496585065851658526585365854658556585665857658586585965860658616586265863658646586565866658676586865869658706587165872658736587465875658766587765878658796588065881658826588365884658856588665887658886588965890658916589265893658946589565896658976589865899659006590165902659036590465905659066590765908659096591065911659126591365914659156591665917659186591965920659216592265923659246592565926659276592865929659306593165932659336593465935659366593765938659396594065941659426594365944659456594665947659486594965950659516595265953659546595565956659576595865959659606596165962659636596465965659666596765968659696597065971659726597365974659756597665977659786597965980659816598265983659846598565986659876598865989659906599165992659936599465995659966599765998659996600066001660026600366004660056600666007660086600966010660116601266013660146601566016660176601866019660206602166022660236602466025660266602766028660296603066031660326603366034660356603666037660386603966040660416604266043660446604566046660476604866049660506605166052660536605466055660566605766058660596606066061660626606366064660656606666067660686606966070660716607266073660746607566076660776607866079660806608166082660836608466085660866608766088660896609066091660926609366094660956609666097660986609966100661016610266103661046610566106661076610866109661106611166112661136611466115661166611766118661196612066121661226612366124661256612666127661286612966130661316613266133661346613566136661376613866139661406614166142661436614466145661466614766148661496615066151661526615366154661556615666157661586615966160661616616266163661646616566166661676616866169661706617166172661736617466175661766617766178661796618066181661826618366184661856618666187661886618966190661916619266193661946619566196661976619866199662006620166202662036620466205662066620766208662096621066211662126621366214662156621666217662186621966220662216622266223662246622566226662276622866229662306623166232662336623466235662366623766238662396624066241662426624366244662456624666247662486624966250662516625266253662546625566256662576625866259662606626166262662636626466265662666626766268662696627066271662726627366274662756627666277662786627966280662816628266283662846628566286662876628866289662906629166292662936629466295662966629766298662996630066301663026630366304663056630666307663086630966310663116631266313663146631566316663176631866319663206632166322663236632466325663266632766328663296633066331663326633366334663356633666337663386633966340663416634266343663446634566346663476634866349663506635166352663536635466355663566635766358663596636066361663626636366364663656636666367663686636966370663716637266373663746637566376663776637866379663806638166382663836638466385663866638766388663896639066391663926639366394663956639666397663986639966400664016640266403664046640566406664076640866409664106641166412664136641466415664166641766418664196642066421664226642366424664256642666427664286642966430664316643266433664346643566436664376643866439664406644166442664436644466445664466644766448664496645066451664526645366454664556645666457664586645966460664616646266463664646646566466664676646866469664706647166472664736647466475664766647766478664796648066481664826648366484664856648666487664886648966490664916649266493664946649566496664976649866499665006650166502665036650466505665066650766508665096651066511665126651366514665156651666517665186651966520665216652266523665246652566526665276652866529665306653166532665336653466535665366653766538665396654066541665426654366544665456654666547665486654966550665516655266553665546655566556665576655866559665606656166562665636656466565665666656766568665696657066571665726657366574665756657666577665786657966580665816658266583665846658566586665876658866589665906659166592665936659466595665966659766598665996660066601666026660366604666056660666607666086660966610666116661266613666146661566616666176661866619666206662166622666236662466625666266662766628666296663066631666326663366634666356663666637666386663966640666416664266643666446664566646666476664866649666506665166652666536665466655666566665766658666596666066661666626666366664666656666666667666686666966670666716667266673666746667566676666776667866679666806668166682666836668466685666866668766688666896669066691666926669366694666956669666697666986669966700667016670266703667046670566706667076670866709667106671166712667136671466715667166671766718667196672066721667226672366724667256672666727667286672966730667316673266733667346673566736667376673866739667406674166742667436674466745667466674766748667496675066751667526675366754667556675666757667586675966760667616676266763667646676566766667676676866769667706677166772667736677466775667766677766778667796678066781667826678366784667856678666787667886678966790667916679266793667946679566796667976679866799668006680166802668036680466805668066680766808668096681066811668126681366814668156681666817668186681966820668216682266823668246682566826668276682866829668306683166832668336683466835668366683766838668396684066841668426684366844668456684666847668486684966850668516685266853668546685566856668576685866859668606686166862668636686466865668666686766868668696687066871668726687366874668756687666877668786687966880668816688266883668846688566886668876688866889668906689166892668936689466895668966689766898668996690066901669026690366904669056690666907669086690966910669116691266913669146691566916669176691866919669206692166922669236692466925669266692766928669296693066931669326693366934669356693666937669386693966940669416694266943669446694566946669476694866949669506695166952669536695466955669566695766958669596696066961669626696366964669656696666967669686696966970669716697266973669746697566976669776697866979669806698166982669836698466985669866698766988669896699066991669926699366994669956699666997669986699967000670016700267003670046700567006670076700867009670106701167012670136701467015670166701767018670196702067021670226702367024670256702667027670286702967030670316703267033670346703567036670376703867039670406704167042670436704467045670466704767048670496705067051670526705367054670556705667057670586705967060670616706267063670646706567066670676706867069670706707167072670736707467075670766707767078670796708067081670826708367084670856708667087670886708967090670916709267093670946709567096670976709867099671006710167102671036710467105671066710767108671096711067111671126711367114671156711667117671186711967120671216712267123671246712567126671276712867129671306713167132671336713467135671366713767138671396714067141671426714367144671456714667147671486714967150671516715267153671546715567156671576715867159671606716167162671636716467165671666716767168671696717067171671726717367174671756717667177671786717967180671816718267183671846718567186671876718867189671906719167192671936719467195671966719767198671996720067201672026720367204672056720667207672086720967210672116721267213672146721567216672176721867219672206722167222672236722467225672266722767228672296723067231672326723367234672356723667237672386723967240672416724267243672446724567246672476724867249672506725167252672536725467255672566725767258672596726067261672626726367264672656726667267672686726967270672716727267273672746727567276672776727867279672806728167282672836728467285672866728767288672896729067291672926729367294672956729667297672986729967300673016730267303673046730567306673076730867309673106731167312673136731467315673166731767318673196732067321673226732367324673256732667327673286732967330673316733267333673346733567336673376733867339673406734167342673436734467345673466734767348673496735067351673526735367354673556735667357673586735967360673616736267363673646736567366673676736867369673706737167372673736737467375673766737767378673796738067381673826738367384673856738667387673886738967390673916739267393673946739567396673976739867399674006740167402674036740467405674066740767408674096741067411674126741367414674156741667417674186741967420674216742267423674246742567426674276742867429674306743167432674336743467435674366743767438674396744067441674426744367444674456744667447674486744967450674516745267453674546745567456674576745867459674606746167462674636746467465674666746767468674696747067471674726747367474674756747667477674786747967480674816748267483674846748567486674876748867489674906749167492674936749467495674966749767498674996750067501675026750367504675056750667507675086750967510675116751267513675146751567516675176751867519675206752167522675236752467525675266752767528675296753067531675326753367534675356753667537675386753967540675416754267543675446754567546675476754867549675506755167552675536755467555675566755767558675596756067561675626756367564675656756667567675686756967570675716757267573675746757567576675776757867579675806758167582675836758467585675866758767588675896759067591675926759367594675956759667597675986759967600676016760267603676046760567606676076760867609676106761167612676136761467615676166761767618676196762067621676226762367624676256762667627676286762967630676316763267633676346763567636676376763867639676406764167642676436764467645676466764767648676496765067651676526765367654676556765667657676586765967660676616766267663676646766567666676676766867669676706767167672676736767467675676766767767678676796768067681676826768367684676856768667687676886768967690676916769267693676946769567696676976769867699677006770167702677036770467705677066770767708677096771067711677126771367714677156771667717677186771967720677216772267723677246772567726677276772867729677306773167732677336773467735677366773767738677396774067741677426774367744677456774667747677486774967750677516775267753677546775567756677576775867759677606776167762677636776467765677666776767768677696777067771677726777367774677756777667777677786777967780677816778267783677846778567786677876778867789677906779167792677936779467795677966779767798677996780067801678026780367804678056780667807678086780967810678116781267813678146781567816678176781867819678206782167822678236782467825678266782767828678296783067831678326783367834678356783667837678386783967840678416784267843678446784567846678476784867849678506785167852678536785467855678566785767858678596786067861678626786367864678656786667867678686786967870678716787267873678746787567876678776787867879678806788167882678836788467885678866788767888678896789067891678926789367894678956789667897678986789967900679016790267903679046790567906679076790867909679106791167912679136791467915679166791767918679196792067921679226792367924679256792667927679286792967930679316793267933679346793567936679376793867939679406794167942679436794467945679466794767948679496795067951679526795367954679556795667957679586795967960679616796267963679646796567966679676796867969679706797167972679736797467975679766797767978679796798067981679826798367984679856798667987679886798967990679916799267993679946799567996679976799867999680006800168002680036800468005680066800768008680096801068011680126801368014680156801668017680186801968020680216802268023680246802568026680276802868029680306803168032680336803468035680366803768038680396804068041680426804368044680456804668047680486804968050680516805268053680546805568056680576805868059680606806168062680636806468065680666806768068680696807068071680726807368074680756807668077680786807968080680816808268083680846808568086680876808868089680906809168092680936809468095680966809768098680996810068101681026810368104681056810668107681086810968110681116811268113681146811568116681176811868119681206812168122681236812468125681266812768128681296813068131681326813368134681356813668137681386813968140681416814268143681446814568146681476814868149681506815168152681536815468155681566815768158681596816068161681626816368164681656816668167681686816968170681716817268173681746817568176681776817868179681806818168182681836818468185681866818768188681896819068191681926819368194681956819668197681986819968200682016820268203682046820568206682076820868209682106821168212682136821468215682166821768218682196822068221682226822368224682256822668227682286822968230682316823268233682346823568236682376823868239682406824168242682436824468245682466824768248682496825068251682526825368254682556825668257682586825968260682616826268263682646826568266682676826868269682706827168272682736827468275682766827768278682796828068281682826828368284682856828668287682886828968290682916829268293682946829568296682976829868299683006830168302683036830468305683066830768308683096831068311683126831368314683156831668317683186831968320683216832268323683246832568326683276832868329683306833168332683336833468335683366833768338683396834068341683426834368344683456834668347683486834968350683516835268353683546835568356683576835868359683606836168362683636836468365683666836768368683696837068371683726837368374683756837668377683786837968380683816838268383683846838568386683876838868389683906839168392683936839468395683966839768398683996840068401684026840368404684056840668407684086840968410684116841268413684146841568416684176841868419684206842168422684236842468425684266842768428684296843068431684326843368434684356843668437684386843968440684416844268443684446844568446684476844868449684506845168452684536845468455684566845768458684596846068461684626846368464684656846668467684686846968470684716847268473684746847568476684776847868479684806848168482684836848468485684866848768488684896849068491684926849368494684956849668497684986849968500685016850268503685046850568506685076850868509685106851168512685136851468515685166851768518685196852068521685226852368524685256852668527685286852968530685316853268533685346853568536685376853868539685406854168542685436854468545685466854768548685496855068551685526855368554685556855668557685586855968560685616856268563685646856568566685676856868569685706857168572685736857468575685766857768578685796858068581685826858368584685856858668587685886858968590685916859268593685946859568596685976859868599686006860168602686036860468605686066860768608686096861068611686126861368614686156861668617686186861968620686216862268623686246862568626686276862868629686306863168632686336863468635686366863768638686396864068641686426864368644686456864668647686486864968650686516865268653686546865568656686576865868659686606866168662686636866468665686666866768668686696867068671686726867368674686756867668677686786867968680686816868268683686846868568686686876868868689686906869168692686936869468695686966869768698686996870068701687026870368704687056870668707687086870968710687116871268713687146871568716687176871868719687206872168722687236872468725687266872768728687296873068731687326873368734687356873668737687386873968740687416874268743687446874568746687476874868749687506875168752687536875468755687566875768758687596876068761687626876368764687656876668767687686876968770687716877268773687746877568776687776877868779687806878168782687836878468785687866878768788687896879068791687926879368794687956879668797687986879968800688016880268803688046880568806688076880868809688106881168812688136881468815688166881768818688196882068821688226882368824688256882668827688286882968830688316883268833688346883568836688376883868839688406884168842688436884468845688466884768848688496885068851688526885368854688556885668857688586885968860688616886268863688646886568866688676886868869688706887168872688736887468875688766887768878688796888068881688826888368884688856888668887688886888968890688916889268893688946889568896688976889868899689006890168902689036890468905689066890768908689096891068911689126891368914689156891668917689186891968920689216892268923689246892568926689276892868929689306893168932689336893468935689366893768938689396894068941689426894368944689456894668947689486894968950689516895268953689546895568956689576895868959689606896168962689636896468965689666896768968689696897068971689726897368974689756897668977689786897968980689816898268983689846898568986689876898868989689906899168992689936899468995689966899768998689996900069001690026900369004690056900669007690086900969010690116901269013690146901569016690176901869019690206902169022690236902469025690266902769028690296903069031690326903369034690356903669037690386903969040690416904269043690446904569046690476904869049690506905169052690536905469055690566905769058690596906069061690626906369064690656906669067690686906969070690716907269073690746907569076690776907869079690806908169082690836908469085690866908769088690896909069091690926909369094690956909669097690986909969100691016910269103691046910569106691076910869109691106911169112691136911469115691166911769118691196912069121691226912369124691256912669127691286912969130691316913269133691346913569136691376913869139691406914169142691436914469145691466914769148691496915069151691526915369154691556915669157691586915969160691616916269163691646916569166691676916869169691706917169172691736917469175691766917769178691796918069181691826918369184691856918669187691886918969190691916919269193691946919569196691976919869199692006920169202692036920469205692066920769208692096921069211692126921369214692156921669217692186921969220692216922269223692246922569226692276922869229692306923169232692336923469235692366923769238692396924069241692426924369244692456924669247692486924969250692516925269253692546925569256692576925869259692606926169262692636926469265692666926769268692696927069271692726927369274692756927669277692786927969280692816928269283692846928569286692876928869289692906929169292692936929469295692966929769298692996930069301693026930369304693056930669307693086930969310693116931269313693146931569316693176931869319693206932169322693236932469325693266932769328693296933069331693326933369334693356933669337693386933969340693416934269343693446934569346693476934869349693506935169352693536935469355693566935769358693596936069361693626936369364693656936669367693686936969370693716937269373693746937569376693776937869379693806938169382693836938469385693866938769388693896939069391693926939369394693956939669397693986939969400694016940269403694046940569406694076940869409694106941169412694136941469415694166941769418694196942069421694226942369424694256942669427694286942969430694316943269433694346943569436694376943869439694406944169442694436944469445694466944769448694496945069451694526945369454694556945669457694586945969460694616946269463694646946569466694676946869469694706947169472694736947469475694766947769478694796948069481694826948369484694856948669487694886948969490694916949269493694946949569496694976949869499695006950169502695036950469505695066950769508695096951069511695126951369514695156951669517695186951969520695216952269523695246952569526695276952869529695306953169532695336953469535695366953769538695396954069541695426954369544695456954669547695486954969550695516955269553695546955569556695576955869559695606956169562695636956469565695666956769568695696957069571695726957369574695756957669577695786957969580695816958269583695846958569586695876958869589695906959169592695936959469595695966959769598695996960069601696026960369604696056960669607696086960969610696116961269613696146961569616696176961869619696206962169622696236962469625696266962769628696296963069631696326963369634696356963669637696386963969640696416964269643696446964569646696476964869649696506965169652696536965469655696566965769658696596966069661696626966369664696656966669667696686966969670696716967269673696746967569676696776967869679696806968169682696836968469685696866968769688696896969069691696926969369694696956969669697696986969969700697016970269703697046970569706697076970869709697106971169712697136971469715697166971769718697196972069721697226972369724697256972669727697286972969730697316973269733697346973569736697376973869739697406974169742697436974469745697466974769748697496975069751697526975369754697556975669757697586975969760697616976269763697646976569766697676976869769697706977169772697736977469775697766977769778697796978069781697826978369784697856978669787697886978969790697916979269793697946979569796697976979869799698006980169802698036980469805698066980769808698096981069811698126981369814698156981669817698186981969820698216982269823698246982569826698276982869829698306983169832698336983469835698366983769838698396984069841698426984369844698456984669847698486984969850698516985269853698546985569856698576985869859698606986169862698636986469865698666986769868698696987069871698726987369874698756987669877698786987969880698816988269883698846988569886698876988869889698906989169892698936989469895698966989769898698996990069901699026990369904699056990669907699086990969910699116991269913699146991569916699176991869919699206992169922699236992469925699266992769928699296993069931699326993369934699356993669937699386993969940699416994269943699446994569946699476994869949699506995169952699536995469955699566995769958699596996069961699626996369964699656996669967699686996969970699716997269973699746997569976699776997869979699806998169982699836998469985699866998769988699896999069991699926999369994699956999669997699986999970000700017000270003700047000570006700077000870009700107001170012700137001470015700167001770018700197002070021700227002370024700257002670027700287002970030700317003270033700347003570036700377003870039700407004170042700437004470045700467004770048700497005070051700527005370054700557005670057700587005970060700617006270063700647006570066700677006870069700707007170072700737007470075700767007770078700797008070081700827008370084700857008670087700887008970090700917009270093700947009570096700977009870099701007010170102701037010470105701067010770108701097011070111701127011370114701157011670117701187011970120701217012270123701247012570126701277012870129701307013170132701337013470135701367013770138701397014070141701427014370144701457014670147701487014970150701517015270153701547015570156701577015870159701607016170162701637016470165701667016770168701697017070171701727017370174701757017670177701787017970180701817018270183701847018570186701877018870189701907019170192701937019470195701967019770198701997020070201702027020370204702057020670207702087020970210702117021270213702147021570216702177021870219702207022170222702237022470225702267022770228702297023070231702327023370234702357023670237702387023970240702417024270243702447024570246702477024870249702507025170252702537025470255702567025770258702597026070261702627026370264702657026670267702687026970270702717027270273702747027570276702777027870279702807028170282702837028470285702867028770288702897029070291702927029370294702957029670297702987029970300703017030270303703047030570306703077030870309703107031170312703137031470315703167031770318703197032070321703227032370324703257032670327703287032970330703317033270333703347033570336703377033870339703407034170342703437034470345703467034770348703497035070351703527035370354703557035670357703587035970360703617036270363703647036570366703677036870369703707037170372703737037470375703767037770378703797038070381703827038370384703857038670387703887038970390703917039270393703947039570396703977039870399704007040170402704037040470405704067040770408704097041070411704127041370414704157041670417704187041970420704217042270423704247042570426704277042870429704307043170432704337043470435704367043770438704397044070441704427044370444704457044670447704487044970450704517045270453704547045570456704577045870459704607046170462704637046470465704667046770468704697047070471704727047370474704757047670477704787047970480704817048270483704847048570486704877048870489704907049170492704937049470495704967049770498704997050070501705027050370504705057050670507705087050970510705117051270513705147051570516705177051870519705207052170522705237052470525705267052770528705297053070531705327053370534705357053670537705387053970540705417054270543705447054570546705477054870549705507055170552705537055470555705567055770558705597056070561705627056370564705657056670567705687056970570705717057270573705747057570576705777057870579705807058170582705837058470585705867058770588705897059070591705927059370594705957059670597705987059970600706017060270603706047060570606706077060870609706107061170612706137061470615706167061770618706197062070621706227062370624706257062670627706287062970630706317063270633706347063570636706377063870639706407064170642706437064470645706467064770648706497065070651706527065370654706557065670657706587065970660706617066270663706647066570666706677066870669706707067170672706737067470675706767067770678706797068070681706827068370684706857068670687706887068970690706917069270693706947069570696706977069870699707007070170702707037070470705707067070770708707097071070711707127071370714707157071670717707187071970720707217072270723707247072570726707277072870729707307073170732707337073470735707367073770738707397074070741707427074370744707457074670747707487074970750707517075270753707547075570756707577075870759707607076170762707637076470765707667076770768707697077070771707727077370774707757077670777707787077970780707817078270783707847078570786707877078870789707907079170792707937079470795707967079770798707997080070801708027080370804708057080670807708087080970810708117081270813708147081570816708177081870819708207082170822708237082470825708267082770828708297083070831708327083370834708357083670837708387083970840708417084270843708447084570846708477084870849708507085170852708537085470855708567085770858708597086070861708627086370864708657086670867708687086970870708717087270873708747087570876708777087870879708807088170882708837088470885708867088770888708897089070891708927089370894708957089670897708987089970900709017090270903709047090570906709077090870909709107091170912709137091470915709167091770918709197092070921709227092370924709257092670927709287092970930709317093270933709347093570936709377093870939709407094170942709437094470945709467094770948709497095070951709527095370954709557095670957709587095970960709617096270963709647096570966709677096870969709707097170972709737097470975709767097770978709797098070981709827098370984709857098670987709887098970990709917099270993709947099570996709977099870999710007100171002710037100471005710067100771008710097101071011710127101371014710157101671017710187101971020710217102271023710247102571026710277102871029710307103171032710337103471035710367103771038710397104071041710427104371044710457104671047710487104971050710517105271053710547105571056710577105871059710607106171062710637106471065710667106771068710697107071071710727107371074710757107671077710787107971080710817108271083710847108571086710877108871089710907109171092710937109471095710967109771098710997110071101711027110371104711057110671107711087110971110711117111271113711147111571116711177111871119711207112171122711237112471125711267112771128711297113071131711327113371134711357113671137711387113971140711417114271143711447114571146711477114871149711507115171152711537115471155711567115771158711597116071161711627116371164711657116671167711687116971170711717117271173711747117571176711777117871179711807118171182711837118471185711867118771188711897119071191711927119371194711957119671197711987119971200712017120271203712047120571206712077120871209712107121171212712137121471215712167121771218712197122071221712227122371224712257122671227712287122971230712317123271233712347123571236712377123871239712407124171242712437124471245712467124771248712497125071251712527125371254712557125671257712587125971260712617126271263712647126571266712677126871269712707127171272712737127471275712767127771278712797128071281712827128371284712857128671287712887128971290712917129271293712947129571296712977129871299713007130171302713037130471305713067130771308713097131071311713127131371314713157131671317713187131971320713217132271323713247132571326713277132871329713307133171332713337133471335713367133771338713397134071341713427134371344713457134671347713487134971350713517135271353713547135571356713577135871359713607136171362713637136471365713667136771368713697137071371713727137371374713757137671377713787137971380713817138271383713847138571386713877138871389713907139171392713937139471395713967139771398713997140071401714027140371404714057140671407714087140971410714117141271413714147141571416714177141871419714207142171422714237142471425714267142771428714297143071431714327143371434714357143671437714387143971440714417144271443714447144571446714477144871449714507145171452714537145471455714567145771458714597146071461714627146371464714657146671467714687146971470714717147271473714747147571476714777147871479714807148171482714837148471485714867148771488714897149071491714927149371494714957149671497714987149971500715017150271503715047150571506715077150871509715107151171512715137151471515715167151771518715197152071521715227152371524715257152671527715287152971530715317153271533715347153571536715377153871539715407154171542715437154471545715467154771548715497155071551715527155371554715557155671557715587155971560715617156271563715647156571566715677156871569715707157171572715737157471575715767157771578715797158071581715827158371584715857158671587715887158971590715917159271593715947159571596715977159871599716007160171602716037160471605716067160771608716097161071611716127161371614716157161671617716187161971620716217162271623716247162571626716277162871629716307163171632716337163471635716367163771638716397164071641716427164371644716457164671647716487164971650716517165271653716547165571656716577165871659716607166171662716637166471665716667166771668716697167071671716727167371674716757167671677716787167971680716817168271683716847168571686716877168871689716907169171692716937169471695716967169771698716997170071701717027170371704717057170671707717087170971710717117171271713717147171571716717177171871719717207172171722717237172471725717267172771728717297173071731717327173371734717357173671737717387173971740717417174271743717447174571746717477174871749717507175171752717537175471755717567175771758717597176071761717627176371764717657176671767717687176971770717717177271773717747177571776717777177871779717807178171782717837178471785717867178771788717897179071791717927179371794717957179671797717987179971800718017180271803718047180571806718077180871809718107181171812718137181471815718167181771818718197182071821718227182371824718257182671827718287182971830718317183271833718347183571836718377183871839718407184171842718437184471845718467184771848718497185071851718527185371854718557185671857718587185971860718617186271863718647186571866718677186871869718707187171872718737187471875718767187771878718797188071881718827188371884718857188671887718887188971890718917189271893718947189571896718977189871899719007190171902719037190471905719067190771908719097191071911719127191371914719157191671917719187191971920719217192271923719247192571926719277192871929719307193171932719337193471935719367193771938719397194071941719427194371944719457194671947719487194971950719517195271953719547195571956719577195871959719607196171962719637196471965719667196771968719697197071971719727197371974719757197671977719787197971980719817198271983719847198571986719877198871989719907199171992719937199471995719967199771998719997200072001720027200372004720057200672007720087200972010720117201272013720147201572016720177201872019720207202172022720237202472025720267202772028720297203072031720327203372034720357203672037720387203972040720417204272043720447204572046720477204872049720507205172052720537205472055720567205772058720597206072061720627206372064720657206672067720687206972070720717207272073720747207572076720777207872079720807208172082720837208472085720867208772088720897209072091720927209372094720957209672097720987209972100721017210272103721047210572106721077210872109721107211172112721137211472115721167211772118721197212072121721227212372124721257212672127721287212972130721317213272133721347213572136721377213872139721407214172142721437214472145721467214772148721497215072151721527215372154721557215672157721587215972160721617216272163721647216572166721677216872169721707217172172721737217472175721767217772178721797218072181721827218372184721857218672187721887218972190721917219272193721947219572196721977219872199722007220172202722037220472205722067220772208722097221072211722127221372214722157221672217722187221972220722217222272223722247222572226722277222872229722307223172232722337223472235722367223772238722397224072241722427224372244722457224672247722487224972250722517225272253722547225572256722577225872259722607226172262722637226472265722667226772268722697227072271722727227372274722757227672277722787227972280722817228272283722847228572286722877228872289722907229172292722937229472295722967229772298722997230072301723027230372304723057230672307723087230972310723117231272313723147231572316723177231872319723207232172322723237232472325723267232772328723297233072331723327233372334723357233672337723387233972340723417234272343723447234572346723477234872349723507235172352723537235472355723567235772358723597236072361723627236372364723657236672367723687236972370723717237272373723747237572376723777237872379723807238172382723837238472385723867238772388723897239072391723927239372394723957239672397723987239972400724017240272403724047240572406724077240872409724107241172412724137241472415724167241772418724197242072421724227242372424724257242672427724287242972430724317243272433724347243572436724377243872439724407244172442724437244472445724467244772448724497245072451724527245372454724557245672457724587245972460724617246272463724647246572466724677246872469724707247172472724737247472475724767247772478724797248072481724827248372484724857248672487724887248972490724917249272493724947249572496724977249872499725007250172502725037250472505725067250772508725097251072511725127251372514725157251672517725187251972520725217252272523725247252572526725277252872529725307253172532725337253472535725367253772538725397254072541725427254372544725457254672547725487254972550725517255272553725547255572556725577255872559725607256172562725637256472565725667256772568725697257072571725727257372574725757257672577725787257972580725817258272583725847258572586725877258872589725907259172592725937259472595725967259772598725997260072601726027260372604726057260672607726087260972610726117261272613726147261572616726177261872619726207262172622726237262472625726267262772628726297263072631726327263372634726357263672637726387263972640726417264272643726447264572646726477264872649726507265172652726537265472655726567265772658726597266072661726627266372664726657266672667726687266972670726717267272673726747267572676726777267872679726807268172682726837268472685726867268772688726897269072691726927269372694726957269672697726987269972700727017270272703727047270572706727077270872709727107271172712727137271472715727167271772718727197272072721727227272372724727257272672727727287272972730727317273272733727347273572736727377273872739727407274172742727437274472745727467274772748727497275072751727527275372754727557275672757727587275972760727617276272763727647276572766727677276872769727707277172772727737277472775727767277772778727797278072781727827278372784727857278672787727887278972790727917279272793727947279572796727977279872799728007280172802728037280472805728067280772808728097281072811728127281372814728157281672817728187281972820728217282272823728247282572826728277282872829728307283172832728337283472835728367283772838728397284072841728427284372844728457284672847728487284972850728517285272853728547285572856728577285872859728607286172862728637286472865728667286772868728697287072871728727287372874728757287672877728787287972880728817288272883728847288572886728877288872889728907289172892728937289472895728967289772898728997290072901729027290372904729057290672907729087290972910729117291272913729147291572916729177291872919729207292172922729237292472925729267292772928729297293072931729327293372934729357293672937729387293972940729417294272943729447294572946729477294872949729507295172952729537295472955729567295772958729597296072961729627296372964729657296672967729687296972970729717297272973729747297572976729777297872979729807298172982729837298472985729867298772988729897299072991729927299372994729957299672997729987299973000730017300273003730047300573006730077300873009730107301173012730137301473015730167301773018730197302073021730227302373024730257302673027730287302973030730317303273033730347303573036730377303873039730407304173042730437304473045730467304773048730497305073051730527305373054730557305673057730587305973060730617306273063730647306573066730677306873069730707307173072730737307473075730767307773078730797308073081730827308373084730857308673087730887308973090730917309273093730947309573096730977309873099731007310173102731037310473105731067310773108731097311073111731127311373114731157311673117731187311973120731217312273123731247312573126731277312873129731307313173132731337313473135731367313773138731397314073141731427314373144731457314673147731487314973150731517315273153731547315573156731577315873159731607316173162731637316473165731667316773168731697317073171731727317373174731757317673177731787317973180731817318273183731847318573186731877318873189731907319173192731937319473195731967319773198731997320073201732027320373204732057320673207732087320973210732117321273213732147321573216732177321873219732207322173222732237322473225732267322773228732297323073231732327323373234732357323673237732387323973240732417324273243732447324573246732477324873249732507325173252732537325473255732567325773258732597326073261732627326373264732657326673267732687326973270732717327273273732747327573276732777327873279732807328173282732837328473285732867328773288732897329073291732927329373294732957329673297732987329973300733017330273303733047330573306733077330873309733107331173312733137331473315733167331773318733197332073321733227332373324733257332673327733287332973330733317333273333733347333573336733377333873339733407334173342733437334473345733467334773348733497335073351733527335373354733557335673357733587335973360733617336273363733647336573366733677336873369733707337173372733737337473375733767337773378733797338073381733827338373384733857338673387733887338973390733917339273393733947339573396733977339873399734007340173402734037340473405734067340773408734097341073411734127341373414734157341673417734187341973420734217342273423734247342573426734277342873429734307343173432734337343473435734367343773438734397344073441734427344373444734457344673447734487344973450734517345273453734547345573456734577345873459734607346173462734637346473465734667346773468734697347073471734727347373474734757347673477734787347973480734817348273483734847348573486734877348873489734907349173492734937349473495734967349773498734997350073501735027350373504735057350673507735087350973510735117351273513735147351573516735177351873519735207352173522735237352473525735267352773528735297353073531735327353373534735357353673537735387353973540735417354273543735447354573546735477354873549735507355173552735537355473555735567355773558735597356073561735627356373564735657356673567735687356973570735717357273573735747357573576735777357873579735807358173582735837358473585735867358773588735897359073591735927359373594735957359673597735987359973600736017360273603736047360573606736077360873609736107361173612736137361473615736167361773618736197362073621736227362373624736257362673627736287362973630736317363273633736347363573636736377363873639736407364173642736437364473645736467364773648736497365073651736527365373654736557365673657736587365973660736617366273663736647366573666736677366873669736707367173672736737367473675736767367773678736797368073681736827368373684736857368673687736887368973690736917369273693736947369573696736977369873699737007370173702737037370473705737067370773708737097371073711737127371373714737157371673717737187371973720737217372273723737247372573726737277372873729737307373173732737337373473735737367373773738737397374073741737427374373744737457374673747737487374973750737517375273753737547375573756737577375873759737607376173762737637376473765737667376773768737697377073771737727377373774737757377673777737787377973780737817378273783737847378573786737877378873789737907379173792737937379473795737967379773798737997380073801738027380373804738057380673807738087380973810738117381273813738147381573816738177381873819738207382173822738237382473825738267382773828738297383073831738327383373834738357383673837738387383973840738417384273843738447384573846738477384873849738507385173852738537385473855738567385773858738597386073861738627386373864738657386673867738687386973870738717387273873738747387573876738777387873879738807388173882738837388473885738867388773888738897389073891738927389373894738957389673897738987389973900739017390273903739047390573906739077390873909739107391173912739137391473915739167391773918739197392073921739227392373924739257392673927739287392973930739317393273933739347393573936739377393873939739407394173942739437394473945739467394773948739497395073951739527395373954739557395673957739587395973960739617396273963739647396573966739677396873969739707397173972739737397473975739767397773978739797398073981739827398373984739857398673987739887398973990739917399273993739947399573996739977399873999740007400174002740037400474005740067400774008740097401074011740127401374014740157401674017740187401974020740217402274023740247402574026740277402874029740307403174032740337403474035740367403774038740397404074041740427404374044740457404674047740487404974050740517405274053740547405574056740577405874059740607406174062740637406474065740667406774068740697407074071740727407374074740757407674077740787407974080740817408274083740847408574086740877408874089740907409174092740937409474095740967409774098740997410074101741027410374104741057410674107741087410974110741117411274113741147411574116741177411874119741207412174122741237412474125741267412774128741297413074131741327413374134741357413674137741387413974140741417414274143741447414574146741477414874149741507415174152741537415474155741567415774158741597416074161741627416374164741657416674167741687416974170741717417274173741747417574176741777417874179741807418174182741837418474185741867418774188741897419074191741927419374194741957419674197741987419974200742017420274203742047420574206742077420874209742107421174212742137421474215742167421774218742197422074221742227422374224742257422674227742287422974230742317423274233742347423574236742377423874239742407424174242742437424474245742467424774248742497425074251742527425374254742557425674257742587425974260742617426274263742647426574266742677426874269742707427174272742737427474275742767427774278742797428074281742827428374284742857428674287742887428974290742917429274293742947429574296742977429874299743007430174302743037430474305743067430774308743097431074311743127431374314743157431674317743187431974320743217432274323743247432574326743277432874329743307433174332743337433474335743367433774338743397434074341743427434374344743457434674347743487434974350743517435274353743547435574356743577435874359743607436174362743637436474365743667436774368743697437074371743727437374374743757437674377743787437974380743817438274383743847438574386743877438874389743907439174392743937439474395743967439774398743997440074401744027440374404744057440674407744087440974410744117441274413744147441574416744177441874419744207442174422744237442474425744267442774428744297443074431744327443374434744357443674437744387443974440744417444274443744447444574446744477444874449744507445174452744537445474455744567445774458744597446074461744627446374464744657446674467744687446974470744717447274473744747447574476744777447874479744807448174482744837448474485744867448774488744897449074491744927449374494744957449674497744987449974500745017450274503745047450574506745077450874509745107451174512745137451474515745167451774518745197452074521745227452374524745257452674527745287452974530745317453274533745347453574536745377453874539745407454174542745437454474545745467454774548745497455074551745527455374554745557455674557745587455974560745617456274563745647456574566745677456874569745707457174572745737457474575745767457774578745797458074581745827458374584745857458674587745887458974590745917459274593745947459574596745977459874599746007460174602746037460474605746067460774608746097461074611746127461374614746157461674617746187461974620746217462274623746247462574626746277462874629746307463174632746337463474635746367463774638746397464074641746427464374644746457464674647746487464974650746517465274653746547465574656746577465874659746607466174662746637466474665746667466774668746697467074671746727467374674746757467674677746787467974680746817468274683746847468574686746877468874689746907469174692746937469474695746967469774698746997470074701747027470374704747057470674707747087470974710747117471274713747147471574716747177471874719747207472174722747237472474725747267472774728747297473074731747327473374734747357473674737747387473974740747417474274743747447474574746747477474874749747507475174752747537475474755747567475774758747597476074761747627476374764747657476674767747687476974770747717477274773747747477574776747777477874779747807478174782747837478474785747867478774788747897479074791747927479374794747957479674797747987479974800748017480274803748047480574806748077480874809748107481174812748137481474815748167481774818748197482074821748227482374824748257482674827748287482974830748317483274833748347483574836748377483874839748407484174842748437484474845748467484774848748497485074851748527485374854748557485674857748587485974860748617486274863748647486574866748677486874869748707487174872748737487474875748767487774878748797488074881748827488374884748857488674887748887488974890748917489274893748947489574896748977489874899749007490174902749037490474905749067490774908749097491074911749127491374914749157491674917749187491974920749217492274923749247492574926749277492874929749307493174932749337493474935749367493774938749397494074941749427494374944749457494674947749487494974950749517495274953749547495574956749577495874959749607496174962749637496474965749667496774968749697497074971749727497374974749757497674977749787497974980749817498274983749847498574986749877498874989749907499174992749937499474995749967499774998749997500075001750027500375004750057500675007750087500975010750117501275013750147501575016750177501875019750207502175022750237502475025750267502775028750297503075031750327503375034750357503675037750387503975040750417504275043750447504575046750477504875049750507505175052750537505475055750567505775058750597506075061750627506375064750657506675067750687506975070750717507275073750747507575076750777507875079750807508175082750837508475085750867508775088750897509075091750927509375094750957509675097750987509975100751017510275103751047510575106751077510875109751107511175112751137511475115751167511775118751197512075121751227512375124751257512675127751287512975130751317513275133751347513575136751377513875139751407514175142751437514475145751467514775148751497515075151751527515375154751557515675157751587515975160751617516275163751647516575166751677516875169751707517175172751737517475175751767517775178751797518075181751827518375184751857518675187751887518975190751917519275193751947519575196751977519875199752007520175202752037520475205752067520775208752097521075211752127521375214752157521675217752187521975220752217522275223752247522575226752277522875229752307523175232752337523475235752367523775238752397524075241752427524375244752457524675247752487524975250752517525275253752547525575256752577525875259752607526175262752637526475265752667526775268752697527075271752727527375274752757527675277752787527975280752817528275283752847528575286752877528875289752907529175292752937529475295752967529775298752997530075301753027530375304753057530675307753087530975310753117531275313753147531575316753177531875319753207532175322753237532475325753267532775328753297533075331753327533375334753357533675337753387533975340753417534275343753447534575346753477534875349753507535175352753537535475355753567535775358753597536075361753627536375364753657536675367753687536975370753717537275373753747537575376753777537875379753807538175382753837538475385753867538775388753897539075391753927539375394753957539675397753987539975400754017540275403754047540575406754077540875409754107541175412754137541475415754167541775418754197542075421754227542375424754257542675427754287542975430754317543275433754347543575436754377543875439754407544175442754437544475445754467544775448754497545075451754527545375454754557545675457754587545975460754617546275463754647546575466754677546875469754707547175472754737547475475754767547775478754797548075481754827548375484754857548675487754887548975490754917549275493754947549575496754977549875499755007550175502755037550475505755067550775508755097551075511755127551375514755157551675517755187551975520755217552275523755247552575526755277552875529755307553175532755337553475535755367553775538755397554075541755427554375544755457554675547755487554975550755517555275553755547555575556755577555875559755607556175562755637556475565755667556775568755697557075571755727557375574755757557675577755787557975580755817558275583755847558575586755877558875589755907559175592755937559475595755967559775598755997560075601756027560375604756057560675607756087560975610756117561275613756147561575616756177561875619756207562175622756237562475625756267562775628756297563075631756327563375634756357563675637756387563975640756417564275643756447564575646756477564875649756507565175652756537565475655756567565775658756597566075661756627566375664756657566675667756687566975670756717567275673756747567575676756777567875679756807568175682756837568475685756867568775688756897569075691756927569375694756957569675697756987569975700757017570275703757047570575706757077570875709757107571175712757137571475715757167571775718757197572075721757227572375724757257572675727757287572975730757317573275733757347573575736757377573875739757407574175742757437574475745757467574775748757497575075751757527575375754757557575675757757587575975760757617576275763757647576575766757677576875769757707577175772757737577475775757767577775778757797578075781757827578375784757857578675787757887578975790757917579275793757947579575796757977579875799758007580175802758037580475805758067580775808758097581075811758127581375814758157581675817758187581975820758217582275823758247582575826758277582875829758307583175832758337583475835758367583775838758397584075841758427584375844758457584675847758487584975850758517585275853758547585575856758577585875859758607586175862758637586475865758667586775868758697587075871758727587375874758757587675877758787587975880758817588275883758847588575886758877588875889758907589175892758937589475895758967589775898758997590075901759027590375904759057590675907759087590975910759117591275913759147591575916759177591875919759207592175922759237592475925759267592775928759297593075931759327593375934759357593675937759387593975940759417594275943759447594575946759477594875949759507595175952759537595475955759567595775958759597596075961759627596375964759657596675967759687596975970759717597275973759747597575976759777597875979759807598175982759837598475985759867598775988759897599075991759927599375994759957599675997759987599976000760017600276003760047600576006760077600876009760107601176012760137601476015760167601776018760197602076021760227602376024760257602676027760287602976030760317603276033760347603576036760377603876039760407604176042760437604476045760467604776048760497605076051760527605376054760557605676057760587605976060760617606276063760647606576066760677606876069760707607176072760737607476075760767607776078760797608076081760827608376084760857608676087760887608976090760917609276093760947609576096760977609876099761007610176102761037610476105761067610776108761097611076111761127611376114761157611676117761187611976120761217612276123761247612576126761277612876129761307613176132761337613476135761367613776138761397614076141761427614376144761457614676147761487614976150761517615276153761547615576156761577615876159761607616176162761637616476165761667616776168761697617076171761727617376174761757617676177761787617976180761817618276183761847618576186761877618876189761907619176192761937619476195761967619776198761997620076201762027620376204762057620676207762087620976210762117621276213762147621576216762177621876219762207622176222762237622476225762267622776228762297623076231762327623376234762357623676237762387623976240762417624276243762447624576246762477624876249762507625176252762537625476255762567625776258762597626076261762627626376264762657626676267762687626976270762717627276273762747627576276762777627876279762807628176282762837628476285762867628776288762897629076291762927629376294762957629676297762987629976300763017630276303763047630576306763077630876309763107631176312763137631476315763167631776318763197632076321763227632376324763257632676327763287632976330763317633276333763347633576336763377633876339763407634176342763437634476345763467634776348763497635076351763527635376354763557635676357763587635976360763617636276363763647636576366763677636876369763707637176372763737637476375763767637776378763797638076381763827638376384763857638676387763887638976390763917639276393763947639576396763977639876399764007640176402764037640476405764067640776408764097641076411764127641376414764157641676417764187641976420764217642276423764247642576426764277642876429764307643176432764337643476435764367643776438764397644076441764427644376444764457644676447764487644976450764517645276453764547645576456764577645876459764607646176462764637646476465764667646776468764697647076471764727647376474764757647676477764787647976480764817648276483764847648576486764877648876489764907649176492764937649476495764967649776498764997650076501765027650376504765057650676507765087650976510765117651276513765147651576516765177651876519765207652176522765237652476525765267652776528765297653076531765327653376534765357653676537765387653976540765417654276543765447654576546765477654876549765507655176552765537655476555765567655776558765597656076561765627656376564765657656676567765687656976570765717657276573765747657576576765777657876579765807658176582765837658476585765867658776588765897659076591765927659376594765957659676597765987659976600766017660276603766047660576606766077660876609766107661176612766137661476615766167661776618766197662076621766227662376624766257662676627766287662976630766317663276633766347663576636766377663876639766407664176642766437664476645766467664776648766497665076651766527665376654766557665676657766587665976660766617666276663766647666576666766677666876669766707667176672766737667476675766767667776678766797668076681766827668376684766857668676687766887668976690766917669276693766947669576696766977669876699767007670176702767037670476705767067670776708767097671076711767127671376714767157671676717767187671976720767217672276723767247672576726767277672876729767307673176732767337673476735767367673776738767397674076741767427674376744767457674676747767487674976750767517675276753767547675576756767577675876759767607676176762767637676476765767667676776768767697677076771767727677376774767757677676777767787677976780767817678276783767847678576786767877678876789767907679176792767937679476795767967679776798767997680076801768027680376804768057680676807768087680976810768117681276813768147681576816768177681876819768207682176822768237682476825768267682776828768297683076831768327683376834768357683676837768387683976840768417684276843768447684576846768477684876849768507685176852768537685476855768567685776858768597686076861768627686376864768657686676867768687686976870768717687276873768747687576876768777687876879768807688176882768837688476885768867688776888768897689076891768927689376894768957689676897768987689976900769017690276903769047690576906769077690876909769107691176912769137691476915769167691776918769197692076921769227692376924769257692676927769287692976930769317693276933769347693576936769377693876939769407694176942769437694476945769467694776948769497695076951769527695376954769557695676957769587695976960769617696276963769647696576966769677696876969769707697176972769737697476975769767697776978769797698076981769827698376984769857698676987769887698976990769917699276993769947699576996769977699876999770007700177002770037700477005770067700777008770097701077011770127701377014770157701677017770187701977020770217702277023770247702577026770277702877029770307703177032770337703477035770367703777038770397704077041770427704377044770457704677047770487704977050770517705277053770547705577056770577705877059770607706177062770637706477065770667706777068770697707077071770727707377074770757707677077770787707977080770817708277083770847708577086770877708877089770907709177092770937709477095770967709777098770997710077101771027710377104771057710677107771087710977110771117711277113771147711577116771177711877119771207712177122771237712477125771267712777128771297713077131771327713377134771357713677137771387713977140771417714277143771447714577146771477714877149771507715177152771537715477155771567715777158771597716077161771627716377164771657716677167771687716977170771717717277173771747717577176771777717877179771807718177182771837718477185771867718777188771897719077191771927719377194771957719677197771987719977200772017720277203772047720577206772077720877209772107721177212772137721477215772167721777218772197722077221772227722377224772257722677227772287722977230772317723277233772347723577236772377723877239772407724177242772437724477245772467724777248772497725077251772527725377254772557725677257772587725977260772617726277263772647726577266772677726877269772707727177272772737727477275772767727777278772797728077281772827728377284772857728677287772887728977290772917729277293772947729577296772977729877299773007730177302773037730477305773067730777308773097731077311773127731377314773157731677317773187731977320773217732277323773247732577326773277732877329773307733177332773337733477335773367733777338773397734077341773427734377344773457734677347773487734977350773517735277353773547735577356773577735877359773607736177362773637736477365773667736777368773697737077371773727737377374773757737677377773787737977380773817738277383773847738577386773877738877389773907739177392773937739477395773967739777398773997740077401774027740377404774057740677407774087740977410774117741277413774147741577416774177741877419774207742177422774237742477425774267742777428774297743077431774327743377434774357743677437774387743977440774417744277443774447744577446774477744877449774507745177452774537745477455774567745777458774597746077461774627746377464774657746677467774687746977470774717747277473774747747577476774777747877479774807748177482774837748477485774867748777488774897749077491774927749377494774957749677497774987749977500775017750277503775047750577506775077750877509775107751177512775137751477515775167751777518775197752077521775227752377524775257752677527775287752977530775317753277533775347753577536775377753877539775407754177542775437754477545775467754777548775497755077551775527755377554775557755677557775587755977560775617756277563775647756577566775677756877569775707757177572775737757477575775767757777578775797758077581775827758377584775857758677587775887758977590775917759277593775947759577596775977759877599776007760177602776037760477605776067760777608776097761077611776127761377614776157761677617776187761977620776217762277623776247762577626776277762877629776307763177632776337763477635776367763777638776397764077641776427764377644776457764677647776487764977650776517765277653776547765577656776577765877659776607766177662776637766477665776667766777668776697767077671776727767377674776757767677677776787767977680776817768277683776847768577686776877768877689776907769177692776937769477695776967769777698776997770077701777027770377704777057770677707777087770977710777117771277713777147771577716777177771877719777207772177722777237772477725777267772777728777297773077731777327773377734777357773677737777387773977740777417774277743777447774577746777477774877749777507775177752777537775477755777567775777758777597776077761777627776377764777657776677767777687776977770777717777277773777747777577776777777777877779777807778177782777837778477785777867778777788777897779077791777927779377794777957779677797777987779977800778017780277803778047780577806778077780877809778107781177812778137781477815778167781777818778197782077821778227782377824778257782677827778287782977830778317783277833778347783577836778377783877839778407784177842778437784477845778467784777848778497785077851778527785377854778557785677857778587785977860778617786277863778647786577866778677786877869778707787177872778737787477875778767787777878778797788077881778827788377884778857788677887778887788977890778917789277893778947789577896778977789877899779007790177902779037790477905779067790777908779097791077911779127791377914779157791677917779187791977920779217792277923779247792577926779277792877929779307793177932779337793477935779367793777938779397794077941779427794377944779457794677947779487794977950779517795277953779547795577956779577795877959779607796177962779637796477965779667796777968779697797077971779727797377974779757797677977779787797977980779817798277983779847798577986779877798877989779907799177992779937799477995779967799777998779997800078001780027800378004780057800678007780087800978010780117801278013780147801578016780177801878019780207802178022780237802478025780267802778028780297803078031780327803378034780357803678037780387803978040780417804278043780447804578046780477804878049780507805178052780537805478055780567805778058780597806078061780627806378064780657806678067780687806978070780717807278073780747807578076780777807878079780807808178082780837808478085780867808778088780897809078091780927809378094780957809678097780987809978100781017810278103781047810578106781077810878109781107811178112781137811478115781167811778118781197812078121781227812378124781257812678127781287812978130781317813278133781347813578136781377813878139781407814178142781437814478145781467814778148781497815078151781527815378154781557815678157781587815978160781617816278163781647816578166781677816878169781707817178172781737817478175781767817778178781797818078181781827818378184781857818678187781887818978190781917819278193781947819578196781977819878199782007820178202782037820478205782067820778208782097821078211782127821378214782157821678217782187821978220782217822278223782247822578226782277822878229782307823178232782337823478235782367823778238782397824078241782427824378244782457824678247782487824978250782517825278253782547825578256782577825878259782607826178262782637826478265782667826778268782697827078271782727827378274782757827678277782787827978280782817828278283782847828578286782877828878289782907829178292782937829478295782967829778298782997830078301783027830378304783057830678307783087830978310783117831278313783147831578316783177831878319783207832178322783237832478325783267832778328783297833078331783327833378334783357833678337783387833978340783417834278343783447834578346783477834878349783507835178352783537835478355783567835778358783597836078361783627836378364783657836678367783687836978370783717837278373783747837578376783777837878379783807838178382783837838478385783867838778388783897839078391783927839378394783957839678397783987839978400784017840278403784047840578406784077840878409784107841178412784137841478415784167841778418784197842078421784227842378424784257842678427784287842978430784317843278433784347843578436784377843878439784407844178442784437844478445784467844778448784497845078451784527845378454784557845678457784587845978460784617846278463784647846578466784677846878469784707847178472784737847478475784767847778478784797848078481784827848378484784857848678487784887848978490784917849278493784947849578496784977849878499785007850178502785037850478505785067850778508785097851078511785127851378514785157851678517785187851978520785217852278523785247852578526785277852878529785307853178532785337853478535785367853778538785397854078541785427854378544785457854678547785487854978550785517855278553785547855578556785577855878559785607856178562785637856478565785667856778568785697857078571785727857378574785757857678577785787857978580785817858278583785847858578586785877858878589785907859178592785937859478595785967859778598785997860078601786027860378604786057860678607786087860978610786117861278613786147861578616786177861878619786207862178622786237862478625786267862778628786297863078631786327863378634786357863678637786387863978640786417864278643786447864578646786477864878649786507865178652786537865478655786567865778658786597866078661786627866378664786657866678667786687866978670786717867278673786747867578676786777867878679786807868178682786837868478685786867868778688786897869078691786927869378694786957869678697786987869978700787017870278703787047870578706787077870878709787107871178712787137871478715787167871778718787197872078721787227872378724787257872678727787287872978730787317873278733787347873578736787377873878739787407874178742787437874478745787467874778748787497875078751787527875378754787557875678757787587875978760787617876278763787647876578766787677876878769787707877178772787737877478775787767877778778787797878078781787827878378784787857878678787787887878978790787917879278793787947879578796787977879878799788007880178802788037880478805788067880778808788097881078811788127881378814788157881678817788187881978820788217882278823788247882578826788277882878829788307883178832788337883478835788367883778838788397884078841788427884378844788457884678847788487884978850788517885278853788547885578856788577885878859788607886178862788637886478865788667886778868788697887078871788727887378874788757887678877788787887978880788817888278883788847888578886788877888878889788907889178892788937889478895788967889778898788997890078901789027890378904789057890678907789087890978910789117891278913789147891578916789177891878919789207892178922789237892478925789267892778928789297893078931789327893378934789357893678937789387893978940789417894278943789447894578946789477894878949789507895178952789537895478955789567895778958789597896078961789627896378964789657896678967789687896978970789717897278973789747897578976789777897878979789807898178982789837898478985789867898778988789897899078991789927899378994789957899678997789987899979000790017900279003790047900579006790077900879009790107901179012790137901479015790167901779018790197902079021790227902379024790257902679027790287902979030790317903279033790347903579036790377903879039790407904179042790437904479045790467904779048790497905079051790527905379054790557905679057790587905979060790617906279063790647906579066790677906879069790707907179072790737907479075790767907779078790797908079081790827908379084790857908679087790887908979090790917909279093790947909579096790977909879099791007910179102791037910479105791067910779108791097911079111791127911379114791157911679117791187911979120791217912279123791247912579126791277912879129791307913179132791337913479135791367913779138791397914079141791427914379144791457914679147791487914979150791517915279153791547915579156791577915879159791607916179162791637916479165791667916779168791697917079171791727917379174791757917679177791787917979180791817918279183791847918579186791877918879189791907919179192791937919479195791967919779198791997920079201792027920379204792057920679207792087920979210792117921279213792147921579216792177921879219792207922179222792237922479225792267922779228792297923079231792327923379234792357923679237792387923979240792417924279243792447924579246792477924879249792507925179252792537925479255792567925779258792597926079261792627926379264792657926679267792687926979270792717927279273792747927579276792777927879279792807928179282792837928479285792867928779288792897929079291792927929379294792957929679297792987929979300793017930279303793047930579306793077930879309793107931179312793137931479315793167931779318793197932079321793227932379324793257932679327793287932979330793317933279333793347933579336793377933879339793407934179342793437934479345793467934779348793497935079351793527935379354793557935679357793587935979360793617936279363793647936579366793677936879369793707937179372793737937479375793767937779378793797938079381793827938379384793857938679387793887938979390793917939279393793947939579396793977939879399794007940179402794037940479405794067940779408794097941079411794127941379414794157941679417794187941979420794217942279423794247942579426794277942879429794307943179432794337943479435794367943779438794397944079441794427944379444794457944679447794487944979450794517945279453794547945579456794577945879459794607946179462794637946479465794667946779468794697947079471794727947379474794757947679477794787947979480794817948279483794847948579486794877948879489794907949179492794937949479495794967949779498794997950079501795027950379504795057950679507795087950979510795117951279513795147951579516795177951879519795207952179522795237952479525795267952779528795297953079531795327953379534795357953679537795387953979540795417954279543795447954579546795477954879549795507955179552795537955479555795567955779558795597956079561795627956379564795657956679567795687956979570795717957279573795747957579576795777957879579795807958179582795837958479585795867958779588795897959079591795927959379594795957959679597795987959979600796017960279603796047960579606796077960879609796107961179612796137961479615796167961779618796197962079621796227962379624796257962679627796287962979630796317963279633796347963579636796377963879639796407964179642796437964479645796467964779648796497965079651796527965379654796557965679657796587965979660796617966279663796647966579666796677966879669796707967179672796737967479675796767967779678796797968079681796827968379684796857968679687796887968979690796917969279693796947969579696796977969879699797007970179702797037970479705797067970779708797097971079711797127971379714797157971679717797187971979720797217972279723797247972579726797277972879729797307973179732797337973479735797367973779738797397974079741797427974379744797457974679747797487974979750797517975279753797547975579756797577975879759797607976179762797637976479765797667976779768797697977079771797727977379774797757977679777797787977979780797817978279783797847978579786797877978879789797907979179792797937979479795797967979779798797997980079801798027980379804798057980679807798087980979810798117981279813798147981579816798177981879819798207982179822798237982479825798267982779828798297983079831798327983379834798357983679837798387983979840798417984279843798447984579846798477984879849798507985179852798537985479855798567985779858798597986079861798627986379864798657986679867798687986979870798717987279873798747987579876798777987879879798807988179882798837988479885798867988779888798897989079891798927989379894798957989679897798987989979900799017990279903799047990579906799077990879909799107991179912799137991479915799167991779918799197992079921799227992379924799257992679927799287992979930799317993279933799347993579936799377993879939799407994179942799437994479945799467994779948799497995079951799527995379954799557995679957799587995979960799617996279963799647996579966799677996879969799707997179972799737997479975799767997779978799797998079981799827998379984799857998679987799887998979990799917999279993799947999579996799977999879999800008000180002800038000480005800068000780008800098001080011800128001380014800158001680017800188001980020800218002280023800248002580026800278002880029800308003180032800338003480035800368003780038800398004080041800428004380044800458004680047800488004980050800518005280053800548005580056800578005880059800608006180062800638006480065800668006780068800698007080071800728007380074800758007680077800788007980080800818008280083800848008580086800878008880089800908009180092800938009480095800968009780098800998010080101801028010380104801058010680107801088010980110801118011280113801148011580116801178011880119801208012180122801238012480125801268012780128801298013080131801328013380134801358013680137801388013980140801418014280143801448014580146801478014880149801508015180152801538015480155801568015780158801598016080161801628016380164801658016680167801688016980170801718017280173801748017580176801778017880179801808018180182801838018480185801868018780188801898019080191801928019380194801958019680197801988019980200802018020280203802048020580206802078020880209802108021180212802138021480215802168021780218802198022080221802228022380224802258022680227802288022980230802318023280233802348023580236802378023880239802408024180242802438024480245802468024780248802498025080251802528025380254802558025680257802588025980260802618026280263802648026580266802678026880269802708027180272802738027480275802768027780278802798028080281802828028380284802858028680287802888028980290802918029280293802948029580296802978029880299803008030180302803038030480305803068030780308803098031080311803128031380314803158031680317803188031980320803218032280323803248032580326803278032880329803308033180332803338033480335803368033780338803398034080341803428034380344803458034680347803488034980350803518035280353803548035580356803578035880359803608036180362803638036480365803668036780368803698037080371803728037380374803758037680377803788037980380803818038280383803848038580386803878038880389803908039180392803938039480395803968039780398803998040080401804028040380404804058040680407804088040980410804118041280413804148041580416804178041880419804208042180422804238042480425804268042780428804298043080431804328043380434804358043680437804388043980440804418044280443804448044580446804478044880449804508045180452804538045480455804568045780458804598046080461804628046380464804658046680467804688046980470804718047280473804748047580476804778047880479804808048180482804838048480485804868048780488804898049080491804928049380494804958049680497804988049980500805018050280503805048050580506805078050880509805108051180512805138051480515805168051780518805198052080521805228052380524805258052680527805288052980530805318053280533805348053580536805378053880539805408054180542805438054480545805468054780548805498055080551805528055380554805558055680557805588055980560805618056280563805648056580566805678056880569805708057180572805738057480575805768057780578805798058080581805828058380584805858058680587805888058980590805918059280593805948059580596805978059880599806008060180602806038060480605806068060780608806098061080611806128061380614806158061680617806188061980620806218062280623806248062580626806278062880629806308063180632806338063480635806368063780638806398064080641806428064380644806458064680647806488064980650806518065280653806548065580656806578065880659806608066180662806638066480665806668066780668806698067080671806728067380674806758067680677806788067980680806818068280683806848068580686806878068880689806908069180692806938069480695806968069780698806998070080701807028070380704807058070680707807088070980710807118071280713807148071580716807178071880719807208072180722807238072480725807268072780728807298073080731807328073380734807358073680737807388073980740807418074280743807448074580746807478074880749807508075180752807538075480755807568075780758807598076080761807628076380764807658076680767807688076980770807718077280773807748077580776807778077880779807808078180782807838078480785807868078780788807898079080791807928079380794807958079680797807988079980800808018080280803808048080580806808078080880809808108081180812808138081480815808168081780818808198082080821808228082380824808258082680827808288082980830808318083280833808348083580836808378083880839808408084180842808438084480845808468084780848808498085080851808528085380854808558085680857808588085980860808618086280863808648086580866808678086880869808708087180872808738087480875808768087780878808798088080881808828088380884808858088680887808888088980890808918089280893808948089580896808978089880899809008090180902809038090480905809068090780908809098091080911809128091380914809158091680917809188091980920809218092280923809248092580926809278092880929809308093180932809338093480935809368093780938809398094080941809428094380944809458094680947809488094980950809518095280953809548095580956809578095880959809608096180962809638096480965809668096780968809698097080971809728097380974809758097680977809788097980980809818098280983809848098580986809878098880989809908099180992809938099480995809968099780998809998100081001810028100381004810058100681007810088100981010810118101281013810148101581016810178101881019810208102181022810238102481025810268102781028810298103081031810328103381034810358103681037810388103981040810418104281043810448104581046810478104881049810508105181052810538105481055810568105781058810598106081061810628106381064810658106681067810688106981070810718107281073810748107581076810778107881079810808108181082810838108481085810868108781088810898109081091810928109381094810958109681097810988109981100811018110281103811048110581106811078110881109811108111181112811138111481115811168111781118811198112081121811228112381124811258112681127811288112981130811318113281133811348113581136811378113881139811408114181142811438114481145811468114781148811498115081151811528115381154811558115681157811588115981160811618116281163811648116581166811678116881169811708117181172811738117481175811768117781178811798118081181811828118381184811858118681187811888118981190811918119281193811948119581196811978119881199812008120181202812038120481205812068120781208812098121081211812128121381214812158121681217812188121981220812218122281223812248122581226812278122881229812308123181232812338123481235812368123781238812398124081241812428124381244812458124681247812488124981250812518125281253812548125581256812578125881259812608126181262812638126481265812668126781268812698127081271812728127381274812758127681277812788127981280812818128281283812848128581286812878128881289812908129181292812938129481295812968129781298812998130081301813028130381304813058130681307813088130981310813118131281313813148131581316813178131881319813208132181322813238132481325813268132781328813298133081331813328133381334813358133681337813388133981340813418134281343813448134581346813478134881349813508135181352813538135481355813568135781358813598136081361813628136381364813658136681367813688136981370813718137281373813748137581376813778137881379813808138181382813838138481385813868138781388813898139081391813928139381394813958139681397813988139981400814018140281403814048140581406814078140881409814108141181412814138141481415814168141781418814198142081421814228142381424814258142681427814288142981430814318143281433814348143581436814378143881439814408144181442814438144481445814468144781448814498145081451814528145381454814558145681457814588145981460814618146281463814648146581466814678146881469814708147181472814738147481475814768147781478814798148081481814828148381484814858148681487814888148981490814918149281493814948149581496814978149881499815008150181502815038150481505815068150781508815098151081511815128151381514815158151681517815188151981520815218152281523815248152581526815278152881529815308153181532815338153481535815368153781538815398154081541815428154381544815458154681547815488154981550815518155281553815548155581556815578155881559815608156181562815638156481565815668156781568815698157081571815728157381574815758157681577815788157981580815818158281583815848158581586815878158881589815908159181592815938159481595815968159781598815998160081601816028160381604816058160681607816088160981610816118161281613816148161581616816178161881619816208162181622816238162481625816268162781628816298163081631816328163381634816358163681637816388163981640816418164281643816448164581646816478164881649816508165181652816538165481655816568165781658816598166081661816628166381664816658166681667816688166981670816718167281673816748167581676816778167881679816808168181682816838168481685816868168781688816898169081691816928169381694816958169681697816988169981700817018170281703817048170581706817078170881709817108171181712817138171481715817168171781718817198172081721817228172381724817258172681727817288172981730817318173281733817348173581736817378173881739817408174181742817438174481745817468174781748817498175081751817528175381754817558175681757817588175981760817618176281763817648176581766817678176881769817708177181772817738177481775817768177781778817798178081781817828178381784817858178681787817888178981790817918179281793817948179581796817978179881799818008180181802818038180481805818068180781808818098181081811818128181381814818158181681817818188181981820818218182281823818248182581826818278182881829818308183181832818338183481835818368183781838818398184081841818428184381844818458184681847818488184981850818518185281853818548185581856818578185881859818608186181862818638186481865818668186781868818698187081871818728187381874818758187681877818788187981880818818188281883818848188581886818878188881889818908189181892818938189481895818968189781898818998190081901819028190381904819058190681907819088190981910819118191281913819148191581916819178191881919819208192181922819238192481925819268192781928819298193081931819328193381934819358193681937819388193981940819418194281943819448194581946819478194881949819508195181952819538195481955819568195781958819598196081961819628196381964819658196681967819688196981970819718197281973819748197581976819778197881979819808198181982819838198481985819868198781988819898199081991819928199381994819958199681997819988199982000820018200282003820048200582006820078200882009820108201182012820138201482015820168201782018820198202082021820228202382024820258202682027820288202982030820318203282033820348203582036820378203882039820408204182042820438204482045820468204782048820498205082051820528205382054820558205682057820588205982060820618206282063820648206582066820678206882069820708207182072820738207482075820768207782078820798208082081820828208382084820858208682087820888208982090820918209282093820948209582096820978209882099821008210182102821038210482105821068210782108821098211082111821128211382114821158211682117821188211982120821218212282123821248212582126821278212882129821308213182132821338213482135821368213782138821398214082141821428214382144821458214682147821488214982150821518215282153821548215582156821578215882159821608216182162821638216482165821668216782168821698217082171821728217382174821758217682177821788217982180821818218282183821848218582186821878218882189821908219182192821938219482195821968219782198821998220082201822028220382204822058220682207822088220982210822118221282213822148221582216822178221882219822208222182222822238222482225822268222782228822298223082231822328223382234822358223682237822388223982240822418224282243822448224582246822478224882249822508225182252822538225482255822568225782258822598226082261822628226382264822658226682267822688226982270822718227282273822748227582276822778227882279822808228182282822838228482285822868228782288822898229082291822928229382294822958229682297822988229982300823018230282303823048230582306823078230882309823108231182312823138231482315823168231782318823198232082321823228232382324823258232682327823288232982330823318233282333823348233582336823378233882339823408234182342823438234482345823468234782348823498235082351823528235382354823558235682357823588235982360823618236282363823648236582366823678236882369823708237182372823738237482375823768237782378823798238082381823828238382384823858238682387823888238982390823918239282393823948239582396823978239882399824008240182402824038240482405824068240782408824098241082411824128241382414824158241682417824188241982420824218242282423824248242582426824278242882429824308243182432824338243482435824368243782438824398244082441824428244382444824458244682447824488244982450824518245282453824548245582456824578245882459824608246182462824638246482465824668246782468824698247082471824728247382474824758247682477824788247982480824818248282483824848248582486824878248882489824908249182492824938249482495824968249782498824998250082501825028250382504825058250682507825088250982510825118251282513825148251582516825178251882519825208252182522825238252482525825268252782528825298253082531825328253382534825358253682537825388253982540825418254282543825448254582546825478254882549825508255182552825538255482555825568255782558825598256082561825628256382564825658256682567825688256982570825718257282573825748257582576825778257882579825808258182582825838258482585825868258782588825898259082591825928259382594825958259682597825988259982600826018260282603826048260582606826078260882609826108261182612826138261482615826168261782618826198262082621826228262382624826258262682627826288262982630826318263282633826348263582636826378263882639826408264182642826438264482645826468264782648826498265082651826528265382654826558265682657826588265982660826618266282663826648266582666826678266882669826708267182672826738267482675826768267782678826798268082681826828268382684826858268682687826888268982690826918269282693826948269582696826978269882699827008270182702827038270482705827068270782708827098271082711827128271382714827158271682717827188271982720827218272282723827248272582726827278272882729827308273182732827338273482735827368273782738827398274082741827428274382744827458274682747827488274982750827518275282753827548275582756827578275882759827608276182762827638276482765827668276782768827698277082771827728277382774827758277682777827788277982780827818278282783827848278582786827878278882789827908279182792827938279482795827968279782798827998280082801828028280382804828058280682807828088280982810828118281282813828148281582816828178281882819828208282182822828238282482825828268282782828828298283082831828328283382834828358283682837828388283982840828418284282843828448284582846828478284882849828508285182852828538285482855828568285782858828598286082861828628286382864828658286682867828688286982870828718287282873828748287582876828778287882879828808288182882828838288482885828868288782888828898289082891828928289382894828958289682897828988289982900829018290282903829048290582906829078290882909829108291182912829138291482915829168291782918829198292082921829228292382924829258292682927829288292982930829318293282933829348293582936829378293882939829408294182942829438294482945829468294782948829498295082951829528295382954829558295682957829588295982960829618296282963829648296582966829678296882969829708297182972829738297482975829768297782978829798298082981829828298382984829858298682987829888298982990829918299282993829948299582996829978299882999830008300183002830038300483005830068300783008830098301083011830128301383014830158301683017830188301983020830218302283023830248302583026830278302883029830308303183032830338303483035830368303783038830398304083041830428304383044830458304683047830488304983050830518305283053830548305583056830578305883059830608306183062830638306483065830668306783068830698307083071830728307383074830758307683077830788307983080830818308283083830848308583086830878308883089830908309183092830938309483095830968309783098830998310083101831028310383104831058310683107831088310983110831118311283113831148311583116831178311883119831208312183122831238312483125831268312783128831298313083131831328313383134831358313683137831388313983140831418314283143831448314583146831478314883149831508315183152831538315483155831568315783158831598316083161831628316383164831658316683167831688316983170831718317283173831748317583176831778317883179831808318183182831838318483185831868318783188831898319083191831928319383194831958319683197831988319983200832018320283203832048320583206832078320883209832108321183212832138321483215832168321783218832198322083221832228322383224832258322683227832288322983230832318323283233832348323583236832378323883239832408324183242832438324483245832468324783248832498325083251832528325383254832558325683257832588325983260832618326283263832648326583266832678326883269832708327183272832738327483275832768327783278832798328083281832828328383284832858328683287832888328983290832918329283293832948329583296832978329883299833008330183302833038330483305833068330783308833098331083311833128331383314833158331683317833188331983320833218332283323833248332583326833278332883329833308333183332833338333483335833368333783338833398334083341833428334383344833458334683347833488334983350833518335283353833548335583356833578335883359833608336183362833638336483365833668336783368833698337083371833728337383374833758337683377833788337983380833818338283383833848338583386833878338883389833908339183392833938339483395833968339783398833998340083401834028340383404834058340683407834088340983410834118341283413834148341583416834178341883419834208342183422834238342483425834268342783428834298343083431834328343383434834358343683437834388343983440834418344283443834448344583446834478344883449834508345183452834538345483455834568345783458834598346083461834628346383464834658346683467834688346983470834718347283473834748347583476834778347883479834808348183482834838348483485834868348783488834898349083491834928349383494834958349683497834988349983500835018350283503835048350583506835078350883509835108351183512835138351483515835168351783518835198352083521835228352383524835258352683527835288352983530835318353283533835348353583536835378353883539835408354183542835438354483545835468354783548835498355083551835528355383554835558355683557835588355983560835618356283563835648356583566835678356883569835708357183572835738357483575835768357783578835798358083581835828358383584835858358683587835888358983590835918359283593835948359583596835978359883599836008360183602836038360483605836068360783608836098361083611836128361383614836158361683617836188361983620836218362283623836248362583626836278362883629836308363183632836338363483635836368363783638836398364083641836428364383644836458364683647836488364983650836518365283653836548365583656836578365883659836608366183662836638366483665836668366783668836698367083671836728367383674836758367683677836788367983680836818368283683836848368583686836878368883689836908369183692836938369483695836968369783698836998370083701837028370383704837058370683707837088370983710837118371283713837148371583716837178371883719837208372183722837238372483725837268372783728837298373083731837328373383734837358373683737837388373983740837418374283743837448374583746837478374883749837508375183752837538375483755837568375783758837598376083761837628376383764837658376683767837688376983770837718377283773837748377583776837778377883779837808378183782837838378483785837868378783788837898379083791837928379383794837958379683797837988379983800838018380283803838048380583806838078380883809838108381183812838138381483815838168381783818838198382083821838228382383824838258382683827838288382983830838318383283833838348383583836838378383883839838408384183842838438384483845838468384783848838498385083851838528385383854838558385683857838588385983860838618386283863838648386583866838678386883869838708387183872838738387483875838768387783878838798388083881838828388383884838858388683887838888388983890838918389283893838948389583896838978389883899839008390183902839038390483905839068390783908839098391083911839128391383914839158391683917839188391983920839218392283923839248392583926839278392883929839308393183932839338393483935839368393783938839398394083941839428394383944839458394683947839488394983950839518395283953839548395583956839578395883959839608396183962839638396483965839668396783968839698397083971839728397383974839758397683977839788397983980839818398283983839848398583986839878398883989839908399183992839938399483995839968399783998839998400084001840028400384004840058400684007840088400984010840118401284013840148401584016840178401884019840208402184022840238402484025840268402784028840298403084031840328403384034840358403684037840388403984040840418404284043840448404584046840478404884049840508405184052840538405484055840568405784058840598406084061840628406384064840658406684067840688406984070840718407284073840748407584076840778407884079840808408184082840838408484085840868408784088840898409084091840928409384094840958409684097840988409984100841018410284103841048410584106841078410884109841108411184112841138411484115841168411784118841198412084121841228412384124841258412684127841288412984130841318413284133841348413584136841378413884139841408414184142841438414484145841468414784148841498415084151841528415384154841558415684157841588415984160841618416284163841648416584166841678416884169841708417184172841738417484175841768417784178841798418084181841828418384184841858418684187841888418984190841918419284193841948419584196841978419884199842008420184202842038420484205842068420784208842098421084211842128421384214842158421684217842188421984220842218422284223842248422584226842278422884229842308423184232842338423484235842368423784238842398424084241842428424384244842458424684247842488424984250842518425284253842548425584256842578425884259842608426184262842638426484265842668426784268842698427084271842728427384274842758427684277842788427984280842818428284283842848428584286842878428884289842908429184292842938429484295842968429784298842998430084301843028430384304843058430684307843088430984310843118431284313843148431584316843178431884319843208432184322843238432484325843268432784328843298433084331843328433384334843358433684337843388433984340843418434284343843448434584346843478434884349843508435184352843538435484355843568435784358843598436084361843628436384364843658436684367843688436984370843718437284373843748437584376843778437884379843808438184382843838438484385843868438784388843898439084391843928439384394843958439684397843988439984400844018440284403844048440584406844078440884409844108441184412844138441484415844168441784418844198442084421844228442384424844258442684427844288442984430844318443284433844348443584436844378443884439844408444184442844438444484445844468444784448844498445084451844528445384454844558445684457844588445984460844618446284463844648446584466844678446884469844708447184472844738447484475844768447784478844798448084481844828448384484844858448684487844888448984490844918449284493844948449584496844978449884499845008450184502845038450484505845068450784508845098451084511845128451384514845158451684517845188451984520845218452284523845248452584526845278452884529845308453184532845338453484535845368453784538845398454084541845428454384544845458454684547845488454984550845518455284553845548455584556845578455884559845608456184562845638456484565845668456784568845698457084571845728457384574845758457684577845788457984580845818458284583845848458584586845878458884589845908459184592845938459484595845968459784598845998460084601846028460384604846058460684607846088460984610846118461284613846148461584616846178461884619846208462184622846238462484625846268462784628846298463084631846328463384634846358463684637846388463984640846418464284643846448464584646846478464884649846508465184652846538465484655846568465784658846598466084661846628466384664846658466684667846688466984670846718467284673846748467584676846778467884679846808468184682846838468484685846868468784688846898469084691846928469384694846958469684697846988469984700847018470284703847048470584706847078470884709847108471184712847138471484715847168471784718847198472084721847228472384724847258472684727847288472984730847318473284733847348473584736847378473884739847408474184742847438474484745847468474784748847498475084751847528475384754847558475684757847588475984760847618476284763847648476584766847678476884769847708477184772847738477484775847768477784778847798478084781847828478384784847858478684787847888478984790847918479284793847948479584796847978479884799848008480184802848038480484805848068480784808848098481084811848128481384814848158481684817848188481984820848218482284823848248482584826848278482884829848308483184832848338483484835848368483784838848398484084841848428484384844848458484684847848488484984850848518485284853848548485584856848578485884859848608486184862848638486484865848668486784868848698487084871848728487384874848758487684877848788487984880848818488284883848848488584886848878488884889848908489184892848938489484895848968489784898848998490084901849028490384904849058490684907849088490984910849118491284913849148491584916849178491884919849208492184922849238492484925849268492784928849298493084931849328493384934849358493684937849388493984940849418494284943849448494584946849478494884949849508495184952849538495484955849568495784958849598496084961849628496384964849658496684967849688496984970849718497284973849748497584976849778497884979849808498184982849838498484985849868498784988849898499084991849928499384994849958499684997849988499985000850018500285003850048500585006850078500885009850108501185012850138501485015850168501785018850198502085021850228502385024850258502685027850288502985030850318503285033850348503585036850378503885039850408504185042850438504485045850468504785048850498505085051850528505385054850558505685057850588505985060850618506285063850648506585066850678506885069850708507185072850738507485075850768507785078850798508085081850828508385084850858508685087850888508985090850918509285093850948509585096850978509885099851008510185102851038510485105851068510785108851098511085111851128511385114851158511685117851188511985120851218512285123851248512585126851278512885129851308513185132851338513485135851368513785138851398514085141851428514385144851458514685147851488514985150851518515285153851548515585156851578515885159851608516185162851638516485165851668516785168851698517085171851728517385174851758517685177851788517985180851818518285183851848518585186851878518885189851908519185192851938519485195851968519785198851998520085201852028520385204852058520685207852088520985210852118521285213852148521585216852178521885219852208522185222852238522485225852268522785228852298523085231852328523385234852358523685237852388523985240852418524285243852448524585246852478524885249852508525185252852538525485255852568525785258852598526085261852628526385264852658526685267852688526985270852718527285273852748527585276852778527885279852808528185282852838528485285852868528785288852898529085291852928529385294852958529685297852988529985300853018530285303853048530585306853078530885309853108531185312853138531485315853168531785318853198532085321853228532385324853258532685327853288532985330853318533285333853348533585336853378533885339853408534185342853438534485345853468534785348853498535085351853528535385354853558535685357853588535985360853618536285363853648536585366853678536885369853708537185372853738537485375853768537785378853798538085381853828538385384853858538685387853888538985390853918539285393853948539585396853978539885399854008540185402854038540485405854068540785408854098541085411854128541385414854158541685417854188541985420854218542285423854248542585426854278542885429854308543185432854338543485435854368543785438854398544085441854428544385444854458544685447854488544985450854518545285453854548545585456854578545885459854608546185462854638546485465854668546785468854698547085471854728547385474854758547685477854788547985480854818548285483854848548585486854878548885489854908549185492854938549485495854968549785498854998550085501855028550385504855058550685507855088550985510855118551285513855148551585516855178551885519855208552185522855238552485525855268552785528855298553085531855328553385534855358553685537855388553985540855418554285543855448554585546855478554885549855508555185552855538555485555855568555785558855598556085561855628556385564855658556685567855688556985570855718557285573855748557585576855778557885579855808558185582855838558485585855868558785588855898559085591855928559385594855958559685597855988559985600856018560285603856048560585606856078560885609856108561185612856138561485615856168561785618856198562085621856228562385624856258562685627856288562985630856318563285633856348563585636856378563885639856408564185642856438564485645856468564785648856498565085651856528565385654856558565685657856588565985660856618566285663856648566585666856678566885669856708567185672856738567485675856768567785678856798568085681856828568385684856858568685687856888568985690856918569285693856948569585696856978569885699857008570185702857038570485705857068570785708857098571085711857128571385714857158571685717857188571985720857218572285723857248572585726857278572885729857308573185732857338573485735857368573785738857398574085741857428574385744857458574685747857488574985750857518575285753857548575585756857578575885759857608576185762857638576485765857668576785768857698577085771857728577385774857758577685777857788577985780857818578285783857848578585786857878578885789857908579185792857938579485795857968579785798857998580085801858028580385804858058580685807858088580985810858118581285813858148581585816858178581885819858208582185822858238582485825858268582785828858298583085831858328583385834858358583685837858388583985840858418584285843858448584585846858478584885849858508585185852858538585485855858568585785858858598586085861858628586385864858658586685867858688586985870858718587285873858748587585876858778587885879858808588185882858838588485885858868588785888858898589085891858928589385894858958589685897858988589985900859018590285903859048590585906859078590885909859108591185912859138591485915859168591785918859198592085921859228592385924859258592685927859288592985930859318593285933859348593585936859378593885939859408594185942859438594485945859468594785948859498595085951859528595385954859558595685957859588595985960859618596285963859648596585966859678596885969859708597185972859738597485975859768597785978859798598085981859828598385984859858598685987859888598985990859918599285993859948599585996859978599885999860008600186002860038600486005860068600786008860098601086011860128601386014860158601686017860188601986020860218602286023860248602586026860278602886029860308603186032860338603486035860368603786038860398604086041860428604386044860458604686047860488604986050860518605286053860548605586056860578605886059860608606186062860638606486065860668606786068860698607086071860728607386074860758607686077860788607986080860818608286083860848608586086860878608886089860908609186092860938609486095860968609786098860998610086101861028610386104861058610686107861088610986110861118611286113861148611586116861178611886119861208612186122861238612486125861268612786128861298613086131861328613386134861358613686137861388613986140861418614286143861448614586146861478614886149861508615186152861538615486155861568615786158861598616086161861628616386164861658616686167861688616986170861718617286173861748617586176861778617886179861808618186182861838618486185861868618786188861898619086191861928619386194861958619686197861988619986200862018620286203862048620586206862078620886209862108621186212862138621486215862168621786218862198622086221862228622386224862258622686227862288622986230862318623286233862348623586236862378623886239862408624186242862438624486245862468624786248862498625086251862528625386254862558625686257862588625986260862618626286263862648626586266862678626886269862708627186272862738627486275862768627786278862798628086281862828628386284862858628686287862888628986290862918629286293862948629586296862978629886299863008630186302863038630486305863068630786308863098631086311863128631386314863158631686317863188631986320863218632286323863248632586326863278632886329863308633186332863338633486335863368633786338863398634086341863428634386344863458634686347863488634986350863518635286353863548635586356863578635886359863608636186362863638636486365863668636786368863698637086371863728637386374863758637686377863788637986380863818638286383863848638586386863878638886389863908639186392863938639486395863968639786398863998640086401864028640386404864058640686407864088640986410864118641286413864148641586416864178641886419864208642186422864238642486425864268642786428864298643086431864328643386434864358643686437864388643986440864418644286443864448644586446864478644886449864508645186452864538645486455864568645786458864598646086461864628646386464864658646686467864688646986470864718647286473864748647586476864778647886479864808648186482864838648486485864868648786488864898649086491864928649386494864958649686497864988649986500865018650286503865048650586506865078650886509865108651186512865138651486515865168651786518865198652086521865228652386524865258652686527865288652986530865318653286533865348653586536865378653886539865408654186542865438654486545865468654786548865498655086551865528655386554865558655686557865588655986560865618656286563865648656586566865678656886569865708657186572865738657486575865768657786578865798658086581865828658386584865858658686587865888658986590865918659286593865948659586596865978659886599866008660186602866038660486605866068660786608866098661086611866128661386614866158661686617866188661986620866218662286623866248662586626866278662886629866308663186632866338663486635866368663786638866398664086641866428664386644866458664686647866488664986650866518665286653866548665586656866578665886659866608666186662866638666486665866668666786668866698667086671866728667386674866758667686677866788667986680866818668286683866848668586686866878668886689866908669186692866938669486695866968669786698866998670086701867028670386704867058670686707867088670986710867118671286713867148671586716867178671886719867208672186722867238672486725867268672786728867298673086731867328673386734867358673686737867388673986740867418674286743867448674586746867478674886749867508675186752867538675486755867568675786758867598676086761867628676386764867658676686767867688676986770867718677286773867748677586776867778677886779867808678186782867838678486785867868678786788867898679086791867928679386794867958679686797867988679986800868018680286803868048680586806868078680886809868108681186812868138681486815868168681786818868198682086821868228682386824868258682686827868288682986830868318683286833868348683586836868378683886839868408684186842868438684486845868468684786848868498685086851868528685386854868558685686857868588685986860868618686286863868648686586866868678686886869868708687186872868738687486875868768687786878868798688086881868828688386884868858688686887868888688986890868918689286893868948689586896868978689886899869008690186902869038690486905869068690786908869098691086911869128691386914869158691686917869188691986920869218692286923869248692586926869278692886929869308693186932869338693486935869368693786938869398694086941869428694386944869458694686947869488694986950869518695286953869548695586956869578695886959869608696186962869638696486965869668696786968869698697086971869728697386974869758697686977869788697986980869818698286983869848698586986869878698886989869908699186992869938699486995869968699786998869998700087001870028700387004870058700687007870088700987010870118701287013870148701587016870178701887019870208702187022870238702487025870268702787028870298703087031870328703387034870358703687037870388703987040870418704287043870448704587046870478704887049870508705187052870538705487055870568705787058870598706087061870628706387064870658706687067870688706987070870718707287073870748707587076870778707887079870808708187082870838708487085870868708787088870898709087091870928709387094870958709687097870988709987100871018710287103871048710587106871078710887109871108711187112871138711487115871168711787118871198712087121871228712387124871258712687127871288712987130871318713287133871348713587136871378713887139871408714187142871438714487145871468714787148871498715087151871528715387154871558715687157871588715987160871618716287163871648716587166871678716887169871708717187172871738717487175871768717787178871798718087181871828718387184871858718687187871888718987190871918719287193871948719587196871978719887199872008720187202872038720487205872068720787208872098721087211872128721387214872158721687217872188721987220872218722287223872248722587226872278722887229872308723187232872338723487235872368723787238872398724087241872428724387244872458724687247872488724987250872518725287253872548725587256872578725887259872608726187262872638726487265872668726787268872698727087271872728727387274872758727687277872788727987280872818728287283872848728587286872878728887289872908729187292872938729487295872968729787298872998730087301873028730387304873058730687307873088730987310873118731287313873148731587316873178731887319873208732187322873238732487325873268732787328873298733087331873328733387334873358733687337873388733987340873418734287343873448734587346873478734887349873508735187352873538735487355873568735787358873598736087361873628736387364873658736687367873688736987370873718737287373873748737587376873778737887379873808738187382873838738487385873868738787388873898739087391873928739387394873958739687397873988739987400874018740287403874048740587406874078740887409874108741187412874138741487415874168741787418874198742087421874228742387424874258742687427874288742987430874318743287433874348743587436874378743887439874408744187442874438744487445874468744787448874498745087451874528745387454874558745687457874588745987460874618746287463874648746587466874678746887469874708747187472874738747487475874768747787478874798748087481874828748387484874858748687487874888748987490874918749287493874948749587496874978749887499875008750187502875038750487505875068750787508875098751087511875128751387514875158751687517875188751987520875218752287523875248752587526875278752887529875308753187532875338753487535875368753787538875398754087541875428754387544875458754687547875488754987550875518755287553875548755587556875578755887559875608756187562875638756487565875668756787568875698757087571875728757387574875758757687577875788757987580875818758287583875848758587586875878758887589875908759187592875938759487595875968759787598875998760087601876028760387604876058760687607876088760987610876118761287613876148761587616876178761887619876208762187622876238762487625876268762787628876298763087631876328763387634876358763687637876388763987640876418764287643876448764587646876478764887649876508765187652876538765487655876568765787658876598766087661876628766387664876658766687667876688766987670876718767287673876748767587676876778767887679876808768187682876838768487685876868768787688876898769087691876928769387694876958769687697876988769987700877018770287703877048770587706877078770887709877108771187712877138771487715877168771787718877198772087721877228772387724877258772687727877288772987730877318773287733877348773587736877378773887739877408774187742877438774487745877468774787748877498775087751877528775387754877558775687757877588775987760877618776287763877648776587766877678776887769877708777187772877738777487775877768777787778877798778087781877828778387784877858778687787877888778987790877918779287793877948779587796877978779887799878008780187802878038780487805878068780787808878098781087811878128781387814878158781687817878188781987820878218782287823878248782587826878278782887829878308783187832878338783487835878368783787838878398784087841878428784387844878458784687847878488784987850878518785287853878548785587856878578785887859878608786187862878638786487865878668786787868878698787087871878728787387874878758787687877878788787987880878818788287883878848788587886878878788887889878908789187892878938789487895878968789787898878998790087901879028790387904879058790687907879088790987910879118791287913879148791587916879178791887919879208792187922879238792487925879268792787928879298793087931879328793387934879358793687937879388793987940879418794287943879448794587946879478794887949879508795187952879538795487955879568795787958879598796087961879628796387964879658796687967879688796987970879718797287973879748797587976879778797887979879808798187982879838798487985879868798787988879898799087991879928799387994879958799687997879988799988000880018800288003880048800588006880078800888009880108801188012880138801488015880168801788018880198802088021880228802388024880258802688027880288802988030880318803288033880348803588036880378803888039880408804188042880438804488045880468804788048880498805088051880528805388054880558805688057880588805988060880618806288063880648806588066880678806888069880708807188072880738807488075880768807788078880798808088081880828808388084880858808688087880888808988090880918809288093880948809588096880978809888099881008810188102881038810488105881068810788108881098811088111881128811388114881158811688117881188811988120881218812288123881248812588126881278812888129881308813188132881338813488135881368813788138881398814088141881428814388144881458814688147881488814988150881518815288153881548815588156881578815888159881608816188162881638816488165881668816788168881698817088171881728817388174881758817688177881788817988180881818818288183881848818588186881878818888189881908819188192881938819488195881968819788198881998820088201882028820388204882058820688207882088820988210882118821288213882148821588216882178821888219882208822188222882238822488225882268822788228882298823088231882328823388234882358823688237882388823988240882418824288243882448824588246882478824888249882508825188252882538825488255882568825788258882598826088261882628826388264882658826688267882688826988270882718827288273882748827588276882778827888279882808828188282882838828488285882868828788288882898829088291882928829388294882958829688297882988829988300883018830288303883048830588306883078830888309883108831188312883138831488315883168831788318883198832088321883228832388324883258832688327883288832988330883318833288333883348833588336883378833888339883408834188342883438834488345883468834788348883498835088351883528835388354883558835688357883588835988360883618836288363883648836588366883678836888369883708837188372883738837488375883768837788378883798838088381883828838388384883858838688387883888838988390883918839288393883948839588396883978839888399884008840188402884038840488405884068840788408884098841088411884128841388414884158841688417884188841988420884218842288423884248842588426884278842888429884308843188432884338843488435884368843788438884398844088441884428844388444884458844688447884488844988450884518845288453884548845588456884578845888459884608846188462884638846488465884668846788468884698847088471884728847388474884758847688477884788847988480884818848288483884848848588486884878848888489884908849188492884938849488495884968849788498884998850088501885028850388504885058850688507885088850988510885118851288513885148851588516885178851888519885208852188522885238852488525885268852788528885298853088531885328853388534885358853688537885388853988540885418854288543885448854588546885478854888549885508855188552885538855488555885568855788558885598856088561885628856388564885658856688567885688856988570885718857288573885748857588576885778857888579885808858188582885838858488585885868858788588885898859088591885928859388594885958859688597885988859988600886018860288603886048860588606886078860888609886108861188612886138861488615886168861788618886198862088621886228862388624886258862688627886288862988630886318863288633886348863588636886378863888639886408864188642886438864488645886468864788648886498865088651886528865388654886558865688657886588865988660886618866288663886648866588666886678866888669886708867188672886738867488675886768867788678886798868088681886828868388684886858868688687886888868988690886918869288693886948869588696886978869888699887008870188702887038870488705887068870788708887098871088711887128871388714887158871688717887188871988720887218872288723887248872588726887278872888729887308873188732887338873488735887368873788738887398874088741887428874388744887458874688747887488874988750887518875288753887548875588756887578875888759887608876188762887638876488765887668876788768887698877088771887728877388774887758877688777887788877988780887818878288783887848878588786887878878888789887908879188792887938879488795887968879788798887998880088801888028880388804888058880688807888088880988810888118881288813888148881588816888178881888819888208882188822888238882488825888268882788828888298883088831888328883388834888358883688837888388883988840888418884288843888448884588846888478884888849888508885188852888538885488855888568885788858888598886088861888628886388864888658886688867888688886988870888718887288873888748887588876888778887888879888808888188882888838888488885888868888788888888898889088891888928889388894888958889688897888988889988900889018890288903889048890588906889078890888909889108891188912889138891488915889168891788918889198892088921889228892388924889258892688927889288892988930889318893288933889348893588936889378893888939889408894188942889438894488945889468894788948889498895088951889528895388954889558895688957889588895988960889618896288963889648896588966889678896888969889708897188972889738897488975889768897788978889798898088981889828898388984889858898688987889888898988990889918899288993889948899588996889978899888999890008900189002890038900489005890068900789008890098901089011890128901389014890158901689017890188901989020890218902289023890248902589026890278902889029890308903189032890338903489035890368903789038890398904089041890428904389044890458904689047890488904989050890518905289053890548905589056890578905889059890608906189062890638906489065890668906789068890698907089071890728907389074890758907689077890788907989080890818908289083890848908589086890878908889089890908909189092890938909489095890968909789098890998910089101891028910389104891058910689107891088910989110891118911289113891148911589116891178911889119891208912189122891238912489125891268912789128891298913089131891328913389134891358913689137891388913989140891418914289143891448914589146891478914889149891508915189152891538915489155891568915789158891598916089161891628916389164891658916689167891688916989170891718917289173891748917589176891778917889179891808918189182891838918489185891868918789188891898919089191891928919389194891958919689197891988919989200892018920289203892048920589206892078920889209892108921189212892138921489215892168921789218892198922089221892228922389224892258922689227892288922989230892318923289233892348923589236892378923889239892408924189242892438924489245892468924789248892498925089251892528925389254892558925689257892588925989260892618926289263892648926589266892678926889269892708927189272892738927489275892768927789278892798928089281892828928389284892858928689287892888928989290892918929289293892948929589296892978929889299893008930189302893038930489305893068930789308893098931089311893128931389314893158931689317893188931989320893218932289323893248932589326893278932889329893308933189332893338933489335893368933789338893398934089341893428934389344893458934689347893488934989350893518935289353893548935589356893578935889359893608936189362893638936489365893668936789368893698937089371893728937389374893758937689377893788937989380893818938289383893848938589386893878938889389893908939189392893938939489395893968939789398893998940089401894028940389404894058940689407894088940989410894118941289413894148941589416894178941889419894208942189422894238942489425894268942789428894298943089431894328943389434894358943689437894388943989440894418944289443894448944589446894478944889449894508945189452894538945489455894568945789458894598946089461894628946389464894658946689467894688946989470894718947289473894748947589476894778947889479894808948189482894838948489485894868948789488894898949089491894928949389494894958949689497894988949989500895018950289503895048950589506895078950889509895108951189512895138951489515895168951789518895198952089521895228952389524895258952689527895288952989530895318953289533895348953589536895378953889539895408954189542895438954489545895468954789548895498955089551895528955389554895558955689557895588955989560895618956289563895648956589566895678956889569895708957189572895738957489575895768957789578895798958089581895828958389584895858958689587895888958989590895918959289593895948959589596895978959889599896008960189602896038960489605896068960789608896098961089611896128961389614896158961689617896188961989620896218962289623896248962589626896278962889629896308963189632896338963489635896368963789638896398964089641896428964389644896458964689647896488964989650896518965289653896548965589656896578965889659896608966189662896638966489665896668966789668896698967089671896728967389674896758967689677896788967989680896818968289683896848968589686896878968889689896908969189692896938969489695896968969789698896998970089701897028970389704897058970689707897088970989710897118971289713897148971589716897178971889719897208972189722897238972489725897268972789728897298973089731897328973389734897358973689737897388973989740897418974289743897448974589746897478974889749897508975189752897538975489755897568975789758897598976089761897628976389764897658976689767897688976989770897718977289773897748977589776897778977889779897808978189782897838978489785897868978789788897898979089791897928979389794897958979689797897988979989800898018980289803898048980589806898078980889809898108981189812898138981489815898168981789818898198982089821898228982389824898258982689827898288982989830898318983289833898348983589836898378983889839898408984189842898438984489845898468984789848898498985089851898528985389854898558985689857898588985989860898618986289863898648986589866898678986889869898708987189872898738987489875898768987789878898798988089881898828988389884898858988689887898888988989890898918989289893898948989589896898978989889899899008990189902899038990489905899068990789908899098991089911899128991389914899158991689917899188991989920899218992289923899248992589926899278992889929899308993189932899338993489935899368993789938899398994089941899428994389944899458994689947899488994989950899518995289953899548995589956899578995889959899608996189962899638996489965899668996789968899698997089971899728997389974899758997689977899788997989980899818998289983899848998589986899878998889989899908999189992899938999489995899968999789998899999000090001900029000390004900059000690007900089000990010900119001290013900149001590016900179001890019900209002190022900239002490025900269002790028900299003090031900329003390034900359003690037900389003990040900419004290043900449004590046900479004890049900509005190052900539005490055900569005790058900599006090061900629006390064900659006690067900689006990070900719007290073900749007590076900779007890079900809008190082900839008490085900869008790088900899009090091900929009390094900959009690097900989009990100901019010290103901049010590106901079010890109901109011190112901139011490115901169011790118901199012090121901229012390124901259012690127901289012990130901319013290133901349013590136901379013890139901409014190142901439014490145901469014790148901499015090151901529015390154901559015690157901589015990160901619016290163901649016590166901679016890169901709017190172901739017490175901769017790178901799018090181901829018390184901859018690187901889018990190901919019290193901949019590196901979019890199902009020190202902039020490205902069020790208902099021090211902129021390214902159021690217902189021990220902219022290223902249022590226902279022890229902309023190232902339023490235902369023790238902399024090241902429024390244902459024690247902489024990250902519025290253902549025590256902579025890259902609026190262902639026490265902669026790268902699027090271902729027390274902759027690277902789027990280902819028290283902849028590286902879028890289902909029190292902939029490295902969029790298902999030090301903029030390304903059030690307903089030990310903119031290313903149031590316903179031890319903209032190322903239032490325903269032790328903299033090331903329033390334903359033690337903389033990340903419034290343903449034590346903479034890349903509035190352903539035490355903569035790358903599036090361903629036390364903659036690367903689036990370903719037290373903749037590376903779037890379903809038190382903839038490385903869038790388903899039090391903929039390394903959039690397903989039990400904019040290403904049040590406904079040890409904109041190412904139041490415904169041790418904199042090421904229042390424904259042690427904289042990430904319043290433904349043590436904379043890439904409044190442904439044490445904469044790448904499045090451904529045390454904559045690457904589045990460904619046290463904649046590466904679046890469904709047190472904739047490475904769047790478904799048090481904829048390484904859048690487904889048990490904919049290493904949049590496904979049890499905009050190502905039050490505905069050790508905099051090511905129051390514905159051690517905189051990520905219052290523905249052590526905279052890529905309053190532905339053490535905369053790538905399054090541905429054390544905459054690547905489054990550905519055290553905549055590556905579055890559905609056190562905639056490565905669056790568905699057090571905729057390574905759057690577905789057990580905819058290583905849058590586905879058890589905909059190592905939059490595905969059790598905999060090601906029060390604906059060690607906089060990610906119061290613906149061590616906179061890619906209062190622906239062490625906269062790628906299063090631906329063390634906359063690637906389063990640906419064290643906449064590646906479064890649906509065190652906539065490655906569065790658906599066090661906629066390664906659066690667906689066990670906719067290673906749067590676906779067890679906809068190682906839068490685906869068790688906899069090691906929069390694906959069690697906989069990700907019070290703907049070590706907079070890709907109071190712907139071490715907169071790718907199072090721907229072390724907259072690727907289072990730907319073290733907349073590736907379073890739907409074190742907439074490745907469074790748907499075090751907529075390754907559075690757907589075990760907619076290763907649076590766907679076890769907709077190772907739077490775907769077790778907799078090781907829078390784907859078690787907889078990790907919079290793907949079590796907979079890799908009080190802908039080490805908069080790808908099081090811908129081390814908159081690817908189081990820908219082290823908249082590826908279082890829908309083190832908339083490835908369083790838908399084090841908429084390844908459084690847908489084990850908519085290853908549085590856908579085890859908609086190862908639086490865908669086790868908699087090871908729087390874908759087690877908789087990880908819088290883908849088590886908879088890889908909089190892908939089490895908969089790898908999090090901909029090390904909059090690907909089090990910909119091290913909149091590916909179091890919909209092190922909239092490925909269092790928909299093090931909329093390934909359093690937909389093990940909419094290943909449094590946909479094890949909509095190952909539095490955909569095790958909599096090961909629096390964909659096690967909689096990970909719097290973909749097590976909779097890979909809098190982909839098490985909869098790988909899099090991909929099390994909959099690997909989099991000910019100291003910049100591006910079100891009910109101191012910139101491015910169101791018910199102091021910229102391024910259102691027910289102991030910319103291033910349103591036910379103891039910409104191042910439104491045910469104791048910499105091051910529105391054910559105691057910589105991060910619106291063910649106591066910679106891069910709107191072910739107491075910769107791078910799108091081910829108391084910859108691087910889108991090910919109291093910949109591096910979109891099911009110191102911039110491105911069110791108911099111091111911129111391114911159111691117911189111991120911219112291123911249112591126911279112891129911309113191132911339113491135911369113791138911399114091141911429114391144911459114691147911489114991150911519115291153911549115591156911579115891159911609116191162911639116491165911669116791168911699117091171911729117391174911759117691177911789117991180911819118291183911849118591186911879118891189911909119191192911939119491195911969119791198911999120091201912029120391204912059120691207912089120991210912119121291213912149121591216912179121891219912209122191222912239122491225912269122791228912299123091231912329123391234912359123691237912389123991240912419124291243912449124591246912479124891249912509125191252912539125491255912569125791258912599126091261912629126391264912659126691267912689126991270912719127291273912749127591276912779127891279912809128191282912839128491285912869128791288912899129091291912929129391294912959129691297912989129991300913019130291303913049130591306913079130891309913109131191312913139131491315913169131791318913199132091321913229132391324913259132691327913289132991330913319133291333913349133591336913379133891339913409134191342913439134491345913469134791348913499135091351913529135391354913559135691357913589135991360913619136291363913649136591366913679136891369913709137191372913739137491375913769137791378913799138091381913829138391384913859138691387913889138991390913919139291393913949139591396913979139891399914009140191402914039140491405914069140791408914099141091411914129141391414914159141691417914189141991420914219142291423914249142591426914279142891429914309143191432914339143491435914369143791438914399144091441914429144391444914459144691447914489144991450914519145291453914549145591456914579145891459914609146191462914639146491465914669146791468914699147091471914729147391474914759147691477914789147991480914819148291483914849148591486914879148891489914909149191492914939149491495914969149791498914999150091501915029150391504915059150691507915089150991510915119151291513915149151591516915179151891519915209152191522915239152491525915269152791528915299153091531915329153391534915359153691537915389153991540915419154291543915449154591546915479154891549915509155191552915539155491555915569155791558915599156091561915629156391564915659156691567915689156991570915719157291573915749157591576915779157891579915809158191582915839158491585915869158791588915899159091591915929159391594915959159691597915989159991600916019160291603916049160591606916079160891609916109161191612916139161491615916169161791618916199162091621916229162391624916259162691627916289162991630916319163291633916349163591636916379163891639916409164191642916439164491645916469164791648916499165091651916529165391654916559165691657916589165991660916619166291663916649166591666916679166891669916709167191672916739167491675916769167791678916799168091681916829168391684916859168691687916889168991690916919169291693916949169591696916979169891699917009170191702917039170491705917069170791708917099171091711917129171391714917159171691717917189171991720917219172291723917249172591726917279172891729917309173191732917339173491735917369173791738917399174091741917429174391744917459174691747917489174991750917519175291753917549175591756917579175891759917609176191762917639176491765917669176791768917699177091771917729177391774917759177691777917789177991780917819178291783917849178591786917879178891789917909179191792917939179491795917969179791798917999180091801918029180391804918059180691807918089180991810918119181291813918149181591816918179181891819918209182191822918239182491825918269182791828918299183091831918329183391834918359183691837918389183991840918419184291843918449184591846918479184891849918509185191852918539185491855918569185791858918599186091861918629186391864918659186691867918689186991870918719187291873918749187591876918779187891879918809188191882918839188491885918869188791888918899189091891918929189391894918959189691897918989189991900919019190291903919049190591906919079190891909919109191191912919139191491915919169191791918919199192091921919229192391924919259192691927919289192991930919319193291933919349193591936919379193891939919409194191942919439194491945919469194791948919499195091951919529195391954919559195691957919589195991960919619196291963919649196591966919679196891969919709197191972919739197491975919769197791978919799198091981919829198391984919859198691987919889198991990919919199291993919949199591996919979199891999920009200192002920039200492005920069200792008920099201092011920129201392014920159201692017920189201992020920219202292023920249202592026920279202892029920309203192032920339203492035920369203792038920399204092041920429204392044920459204692047920489204992050920519205292053920549205592056920579205892059920609206192062920639206492065920669206792068920699207092071920729207392074920759207692077920789207992080920819208292083920849208592086920879208892089920909209192092920939209492095920969209792098920999210092101921029210392104921059210692107921089210992110921119211292113921149211592116921179211892119921209212192122921239212492125921269212792128921299213092131921329213392134921359213692137921389213992140921419214292143921449214592146921479214892149921509215192152921539215492155921569215792158921599216092161921629216392164921659216692167921689216992170921719217292173921749217592176921779217892179921809218192182921839218492185921869218792188921899219092191921929219392194921959219692197921989219992200922019220292203922049220592206922079220892209922109221192212922139221492215922169221792218922199222092221922229222392224922259222692227922289222992230922319223292233922349223592236922379223892239922409224192242922439224492245922469224792248922499225092251922529225392254922559225692257922589225992260922619226292263922649226592266922679226892269922709227192272922739227492275922769227792278922799228092281922829228392284922859228692287922889228992290922919229292293922949229592296922979229892299923009230192302923039230492305923069230792308923099231092311923129231392314923159231692317923189231992320923219232292323923249232592326923279232892329923309233192332923339233492335923369233792338923399234092341923429234392344923459234692347923489234992350923519235292353923549235592356923579235892359923609236192362923639236492365923669236792368923699237092371923729237392374923759237692377923789237992380923819238292383923849238592386923879238892389923909239192392923939239492395923969239792398923999240092401924029240392404924059240692407924089240992410924119241292413924149241592416924179241892419924209242192422924239242492425924269242792428924299243092431924329243392434924359243692437924389243992440924419244292443924449244592446924479244892449924509245192452924539245492455924569245792458924599246092461924629246392464924659246692467924689246992470924719247292473924749247592476924779247892479924809248192482924839248492485924869248792488924899249092491924929249392494924959249692497924989249992500925019250292503925049250592506925079250892509925109251192512925139251492515925169251792518925199252092521925229252392524925259252692527925289252992530925319253292533925349253592536925379253892539925409254192542925439254492545925469254792548925499255092551925529255392554925559255692557925589255992560925619256292563925649256592566925679256892569925709257192572925739257492575925769257792578925799258092581925829258392584925859258692587925889258992590925919259292593925949259592596925979259892599926009260192602926039260492605926069260792608926099261092611926129261392614926159261692617926189261992620926219262292623926249262592626926279262892629926309263192632926339263492635926369263792638926399264092641926429264392644926459264692647926489264992650926519265292653926549265592656926579265892659926609266192662926639266492665926669266792668926699267092671926729267392674926759267692677926789267992680926819268292683926849268592686926879268892689926909269192692926939269492695926969269792698926999270092701927029270392704927059270692707927089270992710927119271292713927149271592716927179271892719927209272192722927239272492725927269272792728927299273092731927329273392734927359273692737927389273992740927419274292743927449274592746927479274892749927509275192752927539275492755927569275792758927599276092761927629276392764927659276692767927689276992770927719277292773927749277592776927779277892779927809278192782927839278492785927869278792788927899279092791927929279392794927959279692797927989279992800928019280292803928049280592806928079280892809928109281192812928139281492815928169281792818928199282092821928229282392824928259282692827928289282992830928319283292833928349283592836928379283892839928409284192842928439284492845928469284792848928499285092851928529285392854928559285692857928589285992860928619286292863928649286592866928679286892869928709287192872928739287492875928769287792878928799288092881928829288392884928859288692887928889288992890928919289292893928949289592896928979289892899929009290192902929039290492905929069290792908929099291092911929129291392914929159291692917929189291992920929219292292923929249292592926929279292892929929309293192932929339293492935929369293792938929399294092941929429294392944929459294692947929489294992950929519295292953929549295592956929579295892959929609296192962929639296492965929669296792968929699297092971929729297392974929759297692977929789297992980929819298292983929849298592986929879298892989929909299192992929939299492995929969299792998929999300093001930029300393004930059300693007930089300993010930119301293013930149301593016930179301893019930209302193022930239302493025930269302793028930299303093031930329303393034930359303693037930389303993040930419304293043930449304593046930479304893049930509305193052930539305493055930569305793058930599306093061930629306393064930659306693067930689306993070930719307293073930749307593076930779307893079930809308193082930839308493085930869308793088930899309093091930929309393094930959309693097930989309993100931019310293103931049310593106931079310893109931109311193112931139311493115931169311793118931199312093121931229312393124931259312693127931289312993130931319313293133931349313593136931379313893139931409314193142931439314493145931469314793148931499315093151931529315393154931559315693157931589315993160931619316293163931649316593166931679316893169931709317193172931739317493175931769317793178931799318093181931829318393184931859318693187931889318993190931919319293193931949319593196931979319893199932009320193202932039320493205932069320793208932099321093211932129321393214932159321693217932189321993220932219322293223932249322593226932279322893229932309323193232932339323493235932369323793238932399324093241932429324393244932459324693247932489324993250932519325293253932549325593256932579325893259932609326193262932639326493265932669326793268932699327093271932729327393274932759327693277932789327993280932819328293283932849328593286932879328893289932909329193292932939329493295932969329793298932999330093301933029330393304933059330693307933089330993310933119331293313933149331593316933179331893319933209332193322933239332493325933269332793328933299333093331933329333393334933359333693337933389333993340933419334293343933449334593346933479334893349933509335193352933539335493355933569335793358933599336093361933629336393364933659336693367933689336993370933719337293373933749337593376933779337893379933809338193382933839338493385933869338793388933899339093391933929339393394933959339693397933989339993400934019340293403934049340593406934079340893409934109341193412934139341493415934169341793418934199342093421934229342393424934259342693427934289342993430934319343293433934349343593436934379343893439934409344193442934439344493445934469344793448934499345093451934529345393454934559345693457934589345993460934619346293463934649346593466934679346893469934709347193472934739347493475934769347793478934799348093481934829348393484934859348693487934889348993490934919349293493934949349593496934979349893499935009350193502935039350493505935069350793508935099351093511935129351393514935159351693517935189351993520935219352293523935249352593526935279352893529935309353193532935339353493535935369353793538935399354093541935429354393544935459354693547935489354993550935519355293553935549355593556935579355893559935609356193562935639356493565935669356793568935699357093571935729357393574935759357693577935789357993580935819358293583935849358593586935879358893589935909359193592935939359493595935969359793598935999360093601936029360393604936059360693607936089360993610936119361293613936149361593616936179361893619936209362193622936239362493625936269362793628936299363093631936329363393634936359363693637936389363993640936419364293643936449364593646936479364893649936509365193652936539365493655936569365793658936599366093661936629366393664936659366693667936689366993670936719367293673936749367593676936779367893679936809368193682936839368493685936869368793688936899369093691936929369393694936959369693697936989369993700937019370293703937049370593706937079370893709937109371193712937139371493715937169371793718937199372093721937229372393724937259372693727937289372993730937319373293733937349373593736937379373893739937409374193742937439374493745937469374793748937499375093751937529375393754937559375693757937589375993760937619376293763937649376593766937679376893769937709377193772937739377493775937769377793778937799378093781937829378393784937859378693787937889378993790937919379293793937949379593796937979379893799938009380193802938039380493805938069380793808938099381093811938129381393814938159381693817938189381993820938219382293823938249382593826938279382893829938309383193832938339383493835938369383793838938399384093841938429384393844938459384693847938489384993850938519385293853938549385593856938579385893859938609386193862938639386493865938669386793868938699387093871938729387393874938759387693877938789387993880938819388293883938849388593886938879388893889938909389193892938939389493895938969389793898938999390093901939029390393904939059390693907939089390993910939119391293913939149391593916939179391893919939209392193922939239392493925939269392793928939299393093931939329393393934939359393693937939389393993940939419394293943939449394593946939479394893949939509395193952939539395493955939569395793958939599396093961939629396393964939659396693967939689396993970939719397293973939749397593976939779397893979939809398193982939839398493985939869398793988939899399093991939929399393994939959399693997939989399994000940019400294003940049400594006940079400894009940109401194012940139401494015940169401794018940199402094021940229402394024940259402694027940289402994030940319403294033940349403594036940379403894039940409404194042940439404494045940469404794048940499405094051940529405394054940559405694057940589405994060940619406294063940649406594066940679406894069940709407194072940739407494075940769407794078940799408094081940829408394084940859408694087940889408994090940919409294093940949409594096940979409894099941009410194102941039410494105941069410794108941099411094111941129411394114941159411694117941189411994120941219412294123941249412594126941279412894129941309413194132941339413494135941369413794138941399414094141941429414394144941459414694147941489414994150941519415294153941549415594156941579415894159941609416194162941639416494165941669416794168941699417094171941729417394174941759417694177941789417994180941819418294183941849418594186941879418894189941909419194192941939419494195941969419794198941999420094201942029420394204942059420694207942089420994210942119421294213942149421594216942179421894219942209422194222942239422494225942269422794228942299423094231942329423394234942359423694237942389423994240942419424294243942449424594246942479424894249942509425194252942539425494255942569425794258942599426094261942629426394264942659426694267942689426994270942719427294273942749427594276942779427894279942809428194282942839428494285942869428794288942899429094291942929429394294942959429694297942989429994300943019430294303943049430594306943079430894309943109431194312943139431494315943169431794318943199432094321943229432394324943259432694327943289432994330943319433294333943349433594336943379433894339943409434194342943439434494345943469434794348943499435094351943529435394354943559435694357943589435994360943619436294363943649436594366943679436894369943709437194372943739437494375943769437794378943799438094381943829438394384943859438694387943889438994390943919439294393943949439594396943979439894399944009440194402944039440494405944069440794408944099441094411944129441394414944159441694417944189441994420944219442294423944249442594426944279442894429944309443194432944339443494435944369443794438944399444094441944429444394444944459444694447944489444994450944519445294453944549445594456944579445894459944609446194462944639446494465944669446794468944699447094471944729447394474944759447694477944789447994480944819448294483944849448594486944879448894489944909449194492944939449494495944969449794498944999450094501945029450394504945059450694507945089450994510945119451294513945149451594516945179451894519945209452194522945239452494525945269452794528945299453094531945329453394534945359453694537945389453994540945419454294543945449454594546945479454894549945509455194552945539455494555945569455794558945599456094561945629456394564945659456694567945689456994570945719457294573945749457594576945779457894579945809458194582945839458494585945869458794588945899459094591945929459394594945959459694597945989459994600946019460294603946049460594606946079460894609946109461194612946139461494615946169461794618946199462094621946229462394624946259462694627946289462994630946319463294633946349463594636946379463894639946409464194642946439464494645946469464794648946499465094651946529465394654946559465694657946589465994660946619466294663946649466594666946679466894669946709467194672946739467494675946769467794678946799468094681946829468394684946859468694687946889468994690946919469294693946949469594696946979469894699947009470194702947039470494705947069470794708947099471094711947129471394714947159471694717947189471994720947219472294723947249472594726947279472894729947309473194732947339473494735947369473794738947399474094741947429474394744947459474694747947489474994750947519475294753947549475594756947579475894759947609476194762947639476494765947669476794768947699477094771947729477394774947759477694777947789477994780947819478294783947849478594786947879478894789947909479194792947939479494795947969479794798947999480094801948029480394804948059480694807948089480994810948119481294813948149481594816948179481894819948209482194822948239482494825948269482794828948299483094831948329483394834948359483694837948389483994840948419484294843948449484594846948479484894849948509485194852948539485494855948569485794858948599486094861948629486394864948659486694867948689486994870948719487294873948749487594876948779487894879948809488194882948839488494885948869488794888948899489094891948929489394894948959489694897948989489994900949019490294903949049490594906
  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. * The algoritm is learnt from
  1448. * https://franklinta.com/2014/09/08/computing-css-matrix3d-transforms/
  1449. * And we made some optimization for matrix inversion.
  1450. * Other similar approaches:
  1451. * "cv::getPerspectiveTransform", "Direct Linear Transformation".
  1452. */
  1453. var LN2 = Math.log(2);
  1454. function determinant(rows, rank, rowStart, rowMask, colMask, detCache) {
  1455. var cacheKey = rowMask + '-' + colMask;
  1456. var fullRank = rows.length;
  1457. if (detCache.hasOwnProperty(cacheKey)) {
  1458. return detCache[cacheKey];
  1459. }
  1460. if (rank === 1) {
  1461. // In this case the colMask must be like: `11101111`. We can find the place of `0`.
  1462. var colStart = Math.round(Math.log(((1 << fullRank) - 1) & ~colMask) / LN2);
  1463. return rows[rowStart][colStart];
  1464. }
  1465. var subRowMask = rowMask | (1 << rowStart);
  1466. var subRowStart = rowStart + 1;
  1467. while (rowMask & (1 << subRowStart)) {
  1468. subRowStart++;
  1469. }
  1470. var sum = 0;
  1471. for (var j = 0, colLocalIdx = 0; j < fullRank; j++) {
  1472. var colTag = 1 << j;
  1473. if (!(colTag & colMask)) {
  1474. sum += (colLocalIdx % 2 ? -1 : 1) * rows[rowStart][j]
  1475. // det(subMatrix(0, j))
  1476. * determinant(rows, rank - 1, subRowStart, subRowMask, colMask | colTag, detCache);
  1477. colLocalIdx++;
  1478. }
  1479. }
  1480. detCache[cacheKey] = sum;
  1481. return sum;
  1482. }
  1483. /**
  1484. * Usage:
  1485. * ```js
  1486. * var transformer = buildTransformer(
  1487. * [10, 44, 100, 44, 100, 300, 10, 300],
  1488. * [50, 54, 130, 14, 140, 330, 14, 220]
  1489. * );
  1490. * var out = [];
  1491. * transformer && transformer([11, 33], out);
  1492. * ```
  1493. *
  1494. * Notice: `buildTransformer` may take more than 10ms in some Android device.
  1495. *
  1496. * @param {Array.<number>} src source four points, [x0, y0, x1, y1, x2, y2, x3, y3]
  1497. * @param {Array.<number>} dest destination four points, [x0, y0, x1, y1, x2, y2, x3, y3]
  1498. * @return {Function} transformer If fail, return null/undefined.
  1499. */
  1500. function buildTransformer(src, dest) {
  1501. var mA = [
  1502. [src[0], src[1], 1, 0, 0, 0, -dest[0] * src[0], -dest[0] * src[1]],
  1503. [0, 0, 0, src[0], src[1], 1, -dest[1] * src[0], -dest[1] * src[1]],
  1504. [src[2], src[3], 1, 0, 0, 0, -dest[2] * src[2], -dest[2] * src[3]],
  1505. [0, 0, 0, src[2], src[3], 1, -dest[3] * src[2], -dest[3] * src[3]],
  1506. [src[4], src[5], 1, 0, 0, 0, -dest[4] * src[4], -dest[4] * src[5]],
  1507. [0, 0, 0, src[4], src[5], 1, -dest[5] * src[4], -dest[5] * src[5]],
  1508. [src[6], src[7], 1, 0, 0, 0, -dest[6] * src[6], -dest[6] * src[7]],
  1509. [0, 0, 0, src[6], src[7], 1, -dest[7] * src[6], -dest[7] * src[7]]
  1510. ];
  1511. var detCache = {};
  1512. var det = determinant(mA, 8, 0, 0, 0, detCache);
  1513. if (det === 0) {
  1514. return;
  1515. }
  1516. // `invert(mA) * dest`, that is, `adj(mA) / det * dest`.
  1517. var vh = [];
  1518. for (var i = 0; i < 8; i++) {
  1519. for (var j = 0; j < 8; j++) {
  1520. vh[j] == null && (vh[j] = 0);
  1521. vh[j] += ((i + j) % 2 ? -1 : 1)
  1522. // det(subMatrix(i, j))
  1523. * determinant(mA, 7, i === 0 ? 1 : 0, 1 << i, 1 << j, detCache)
  1524. / det * dest[i];
  1525. }
  1526. }
  1527. return function (out, srcPointX, srcPointY) {
  1528. var pk = srcPointX * vh[6] + srcPointY * vh[7] + 1;
  1529. out[0] = (srcPointX * vh[0] + srcPointY * vh[1] + vh[2]) / pk;
  1530. out[1] = (srcPointX * vh[3] + srcPointY * vh[4] + vh[5]) / pk;
  1531. };
  1532. }
  1533. /**
  1534. * Utilities for mouse or touch events.
  1535. */
  1536. var isDomLevel2 = (typeof window !== 'undefined') && !!window.addEventListener;
  1537. var MOUSE_EVENT_REG = /^(?:mouse|pointer|contextmenu|drag|drop)|click/;
  1538. var EVENT_SAVED_PROP = '___zrEVENTSAVED';
  1539. var _calcOut = [];
  1540. /**
  1541. * Get the `zrX` and `zrY`, which are relative to the top-left of
  1542. * the input `el`.
  1543. * CSS transform (2D & 3D) is supported.
  1544. *
  1545. * The strategy to fetch the coords:
  1546. * + If `calculate` is not set as `true`, users of this method should
  1547. * ensure that `el` is the same or the same size & location as `e.target`.
  1548. * Otherwise the result coords are probably not expected. Because we
  1549. * firstly try to get coords from e.offsetX/e.offsetY.
  1550. * + If `calculate` is set as `true`, the input `el` can be any element
  1551. * and we force to calculate the coords based on `el`.
  1552. * + The input `el` should be positionable (not position:static).
  1553. *
  1554. * The force `calculate` can be used in case like:
  1555. * When mousemove event triggered on ec tooltip, `e.target` is not `el`(zr painter.dom).
  1556. *
  1557. * @param {HTMLElement} el DOM element.
  1558. * @param {Event} e Mouse event or touch event.
  1559. * @param {Object} out Get `out.zrX` and `out.zrY` as the result.
  1560. * @param {boolean} [calculate=false] Whether to force calculate
  1561. * the coordinates but not use ones provided by browser.
  1562. */
  1563. function clientToLocal(el, e, out, calculate) {
  1564. out = out || {};
  1565. // According to the W3C Working Draft, offsetX and offsetY should be relative
  1566. // to the padding edge of the target element. The only browser using this convention
  1567. // is IE. Webkit uses the border edge, Opera uses the content edge, and FireFox does
  1568. // not support the properties.
  1569. // (see http://www.jacklmoore.com/notes/mouse-position/)
  1570. // In zr painter.dom, padding edge equals to border edge.
  1571. if (calculate || !env$1.canvasSupported) {
  1572. calculateZrXY(el, e, out);
  1573. }
  1574. // Caution: In FireFox, layerX/layerY Mouse position relative to the closest positioned
  1575. // ancestor element, so we should make sure el is positioned (e.g., not position:static).
  1576. // BTW1, Webkit don't return the same results as FF in non-simple cases (like add
  1577. // zoom-factor, overflow / opacity layers, transforms ...)
  1578. // BTW2, (ev.offsetY || ev.pageY - $(ev.target).offset().top) is not correct in preserve-3d.
  1579. // <https://bugs.jquery.com/ticket/8523#comment:14>
  1580. // BTW3, In ff, offsetX/offsetY is always 0.
  1581. else if (env$1.browser.firefox && e.layerX != null && e.layerX !== e.offsetX) {
  1582. out.zrX = e.layerX;
  1583. out.zrY = e.layerY;
  1584. }
  1585. // For IE6+, chrome, safari, opera. (When will ff support offsetX?)
  1586. else if (e.offsetX != null) {
  1587. out.zrX = e.offsetX;
  1588. out.zrY = e.offsetY;
  1589. }
  1590. // For some other device, e.g., IOS safari.
  1591. else {
  1592. calculateZrXY(el, e, out);
  1593. }
  1594. return out;
  1595. }
  1596. function calculateZrXY(el, e, out) {
  1597. // BlackBerry 5, iOS 3 (original iPhone) don't have getBoundingRect.
  1598. if (el.getBoundingClientRect && env$1.domSupported) {
  1599. var ex = e.clientX;
  1600. var ey = e.clientY;
  1601. if (el.nodeName.toUpperCase() === 'CANVAS') {
  1602. // Original approach, which do not support CSS transform.
  1603. // marker can not be locationed in a canvas container
  1604. // (getBoundingClientRect is always 0). We do not support
  1605. // that input a pre-created canvas to zr while using css
  1606. // transform in iOS.
  1607. var box = el.getBoundingClientRect();
  1608. out.zrX = ex - box.left;
  1609. out.zrY = ey - box.top;
  1610. return;
  1611. }
  1612. else {
  1613. var saved = el[EVENT_SAVED_PROP] || (el[EVENT_SAVED_PROP] = {});
  1614. var transformer = preparePointerTransformer(prepareCoordMarkers(el, saved), saved);
  1615. if (transformer) {
  1616. transformer(_calcOut, ex, ey);
  1617. out.zrX = _calcOut[0];
  1618. out.zrY = _calcOut[1];
  1619. return;
  1620. }
  1621. }
  1622. }
  1623. out.zrX = out.zrY = 0;
  1624. }
  1625. function prepareCoordMarkers(el, saved) {
  1626. var markers = saved.markers;
  1627. if (markers) {
  1628. return markers;
  1629. }
  1630. markers = saved.markers = [];
  1631. var propLR = ['left', 'right'];
  1632. var propTB = ['top', 'bottom'];
  1633. for (var i = 0; i < 4; i++) {
  1634. var marker = document.createElement('div');
  1635. var stl = marker.style;
  1636. var idxLR = i % 2;
  1637. var idxTB = (i >> 1) % 2;
  1638. stl.cssText = [
  1639. 'position:absolute',
  1640. 'visibility: hidden',
  1641. 'padding: 0',
  1642. 'margin: 0',
  1643. 'border-width: 0',
  1644. 'width:0',
  1645. 'height:0',
  1646. // 'width: 5px',
  1647. // 'height: 5px',
  1648. propLR[idxLR] + ':0',
  1649. propTB[idxTB] + ':0',
  1650. propLR[1 - idxLR] + ':auto',
  1651. propTB[1 - idxTB] + ':auto',
  1652. ''
  1653. ].join('!important;');
  1654. el.appendChild(marker);
  1655. markers.push(marker);
  1656. }
  1657. return markers;
  1658. }
  1659. function preparePointerTransformer(markers, saved) {
  1660. var transformer = saved.transformer;
  1661. var oldSrcCoords = saved.srcCoords;
  1662. var useOld = true;
  1663. var srcCoords = [];
  1664. var destCoords = [];
  1665. for (var i = 0; i < 4; i++) {
  1666. var rect = markers[i].getBoundingClientRect();
  1667. var ii = 2 * i;
  1668. var x = rect.left;
  1669. var y = rect.top;
  1670. srcCoords.push(x, y);
  1671. useOld &= oldSrcCoords && x === oldSrcCoords[ii] && y === oldSrcCoords[ii + 1];
  1672. destCoords.push(markers[i].offsetLeft, markers[i].offsetTop);
  1673. }
  1674. // Cache to avoid time consuming of `buildTransformer`.
  1675. return useOld
  1676. ? transformer
  1677. : (
  1678. saved.srcCoords = srcCoords,
  1679. saved.transformer = buildTransformer(srcCoords, destCoords)
  1680. );
  1681. }
  1682. /**
  1683. * Normalize the coordinates of the input event.
  1684. *
  1685. * Get the `e.zrX` and `e.zrY`, which are relative to the top-left of
  1686. * the input `el`.
  1687. * Get `e.zrDelta` if using mouse wheel.
  1688. * Get `e.which`, see the comment inside this function.
  1689. *
  1690. * Do not calculate repeatly if `zrX` and `zrY` already exist.
  1691. *
  1692. * Notice: see comments in `clientToLocal`. check the relationship
  1693. * between the result coords and the parameters `el` and `calculate`.
  1694. *
  1695. * @param {HTMLElement} el DOM element.
  1696. * @param {Event} [e] Mouse event or touch event. For lagency IE,
  1697. * do not need to input it and `window.event` is used.
  1698. * @param {boolean} [calculate=false] Whether to force calculate
  1699. * the coordinates but not use ones provided by browser.
  1700. */
  1701. function normalizeEvent(el, e, calculate) {
  1702. e = e || window.event;
  1703. if (e.zrX != null) {
  1704. return e;
  1705. }
  1706. var eventType = e.type;
  1707. var isTouch = eventType && eventType.indexOf('touch') >= 0;
  1708. if (!isTouch) {
  1709. clientToLocal(el, e, e, calculate);
  1710. e.zrDelta = (e.wheelDelta) ? e.wheelDelta / 120 : -(e.detail || 0) / 3;
  1711. }
  1712. else {
  1713. var touch = eventType !== 'touchend'
  1714. ? e.targetTouches[0]
  1715. : e.changedTouches[0];
  1716. touch && clientToLocal(el, touch, e, calculate);
  1717. }
  1718. // Add which for click: 1 === left; 2 === middle; 3 === right; otherwise: 0;
  1719. // See jQuery: https://github.com/jquery/jquery/blob/master/src/event.js
  1720. // If e.which has been defined, it may be readonly,
  1721. // see: https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/which
  1722. var button = e.button;
  1723. if (e.which == null && button !== undefined && MOUSE_EVENT_REG.test(e.type)) {
  1724. e.which = (button & 1 ? 1 : (button & 2 ? 3 : (button & 4 ? 2 : 0)));
  1725. }
  1726. // [Caution]: `e.which` from browser is not always reliable. For example,
  1727. // when press left button and `mousemove (pointermove)` in Edge, the `e.which`
  1728. // is 65536 and the `e.button` is -1. But the `mouseup (pointerup)` and
  1729. // `mousedown (pointerdown)` is the same as Chrome does.
  1730. return e;
  1731. }
  1732. /**
  1733. * @param {HTMLElement} el
  1734. * @param {string} name
  1735. * @param {Function} handler
  1736. */
  1737. function addEventListener(el, name, handler) {
  1738. if (isDomLevel2) {
  1739. // Reproduct the console warning:
  1740. // [Violation] Added non-passive event listener to a scroll-blocking <some> event.
  1741. // Consider marking event handler as 'passive' to make the page more responsive.
  1742. // Just set console log level: verbose in chrome dev tool.
  1743. // then the warning log will be printed when addEventListener called.
  1744. // See https://github.com/WICG/EventListenerOptions/blob/gh-pages/explainer.md
  1745. // We have not yet found a neat way to using passive. Because in zrender the dom event
  1746. // listener delegate all of the upper events of element. Some of those events need
  1747. // to prevent default. For example, the feature `preventDefaultMouseMove` of echarts.
  1748. // Before passive can be adopted, these issues should be considered:
  1749. // (1) Whether and how a zrender user specifies an event listener passive. And by default,
  1750. // passive or not.
  1751. // (2) How to tread that some zrender event listener is passive, and some is not. If
  1752. // we use other way but not preventDefault of mousewheel and touchmove, browser
  1753. // compatibility should be handled.
  1754. // var opts = (env.passiveSupported && name === 'mousewheel')
  1755. // ? {passive: true}
  1756. // // By default, the third param of el.addEventListener is `capture: false`.
  1757. // : void 0;
  1758. // el.addEventListener(name, handler /* , opts */);
  1759. el.addEventListener(name, handler);
  1760. }
  1761. else {
  1762. el.attachEvent('on' + name, handler);
  1763. }
  1764. }
  1765. function removeEventListener(el, name, handler) {
  1766. if (isDomLevel2) {
  1767. el.removeEventListener(name, handler);
  1768. }
  1769. else {
  1770. el.detachEvent('on' + name, handler);
  1771. }
  1772. }
  1773. /**
  1774. * preventDefault and stopPropagation.
  1775. * Notice: do not use this method in zrender. It can only be
  1776. * used by upper applications if necessary.
  1777. *
  1778. * @param {Event} e A mouse or touch event.
  1779. */
  1780. var stop = isDomLevel2
  1781. ? function (e) {
  1782. e.preventDefault();
  1783. e.stopPropagation();
  1784. e.cancelBubble = true;
  1785. }
  1786. : function (e) {
  1787. e.returnValue = false;
  1788. e.cancelBubble = true;
  1789. };
  1790. /**
  1791. * This method only works for mouseup and mousedown. The functionality is restricted
  1792. * for fault tolerance, See the `e.which` compatibility above.
  1793. *
  1794. * @param {MouseEvent} e
  1795. * @return {boolean}
  1796. */
  1797. function isMiddleOrRightButtonOnMouseUpDown(e) {
  1798. return e.which === 2 || e.which === 3;
  1799. }
  1800. /**
  1801. * To be removed.
  1802. * @deprecated
  1803. */
  1804. /**
  1805. * Only implements needed gestures for mobile.
  1806. */
  1807. var GestureMgr = function () {
  1808. /**
  1809. * @private
  1810. * @type {Array.<Object>}
  1811. */
  1812. this._track = [];
  1813. };
  1814. GestureMgr.prototype = {
  1815. constructor: GestureMgr,
  1816. recognize: function (event, target, root) {
  1817. this._doTrack(event, target, root);
  1818. return this._recognize(event);
  1819. },
  1820. clear: function () {
  1821. this._track.length = 0;
  1822. return this;
  1823. },
  1824. _doTrack: function (event, target, root) {
  1825. var touches = event.touches;
  1826. if (!touches) {
  1827. return;
  1828. }
  1829. var trackItem = {
  1830. points: [],
  1831. touches: [],
  1832. target: target,
  1833. event: event
  1834. };
  1835. for (var i = 0, len = touches.length; i < len; i++) {
  1836. var touch = touches[i];
  1837. var pos = clientToLocal(root, touch, {});
  1838. trackItem.points.push([pos.zrX, pos.zrY]);
  1839. trackItem.touches.push(touch);
  1840. }
  1841. this._track.push(trackItem);
  1842. },
  1843. _recognize: function (event) {
  1844. for (var eventName in recognizers) {
  1845. if (recognizers.hasOwnProperty(eventName)) {
  1846. var gestureInfo = recognizers[eventName](this._track, event);
  1847. if (gestureInfo) {
  1848. return gestureInfo;
  1849. }
  1850. }
  1851. }
  1852. }
  1853. };
  1854. function dist$1(pointPair) {
  1855. var dx = pointPair[1][0] - pointPair[0][0];
  1856. var dy = pointPair[1][1] - pointPair[0][1];
  1857. return Math.sqrt(dx * dx + dy * dy);
  1858. }
  1859. function center(pointPair) {
  1860. return [
  1861. (pointPair[0][0] + pointPair[1][0]) / 2,
  1862. (pointPair[0][1] + pointPair[1][1]) / 2
  1863. ];
  1864. }
  1865. var recognizers = {
  1866. pinch: function (track, event) {
  1867. var trackLen = track.length;
  1868. if (!trackLen) {
  1869. return;
  1870. }
  1871. var pinchEnd = (track[trackLen - 1] || {}).points;
  1872. var pinchPre = (track[trackLen - 2] || {}).points || pinchEnd;
  1873. if (pinchPre
  1874. && pinchPre.length > 1
  1875. && pinchEnd
  1876. && pinchEnd.length > 1
  1877. ) {
  1878. var pinchScale = dist$1(pinchEnd) / dist$1(pinchPre);
  1879. !isFinite(pinchScale) && (pinchScale = 1);
  1880. event.pinchScale = pinchScale;
  1881. var pinchCenter = center(pinchEnd);
  1882. event.pinchX = pinchCenter[0];
  1883. event.pinchY = pinchCenter[1];
  1884. return {
  1885. type: 'pinch',
  1886. target: track[0].target,
  1887. event: event
  1888. };
  1889. }
  1890. }
  1891. // Only pinch currently.
  1892. };
  1893. var SILENT = 'silent';
  1894. function makeEventPacket(eveType, targetInfo, event) {
  1895. return {
  1896. type: eveType,
  1897. event: event,
  1898. // target can only be an element that is not silent.
  1899. target: targetInfo.target,
  1900. // topTarget can be a silent element.
  1901. topTarget: targetInfo.topTarget,
  1902. cancelBubble: false,
  1903. offsetX: event.zrX,
  1904. offsetY: event.zrY,
  1905. gestureEvent: event.gestureEvent,
  1906. pinchX: event.pinchX,
  1907. pinchY: event.pinchY,
  1908. pinchScale: event.pinchScale,
  1909. wheelDelta: event.zrDelta,
  1910. zrByTouch: event.zrByTouch,
  1911. which: event.which,
  1912. stop: stopEvent
  1913. };
  1914. }
  1915. function stopEvent(event) {
  1916. stop(this.event);
  1917. }
  1918. function EmptyProxy() {}
  1919. EmptyProxy.prototype.dispose = function () {};
  1920. var handlerNames = [
  1921. 'click', 'dblclick', 'mousewheel', 'mouseout',
  1922. 'mouseup', 'mousedown', 'mousemove', 'contextmenu'
  1923. ];
  1924. /**
  1925. * @alias module:zrender/Handler
  1926. * @constructor
  1927. * @extends module:zrender/mixin/Eventful
  1928. * @param {module:zrender/Storage} storage Storage instance.
  1929. * @param {module:zrender/Painter} painter Painter instance.
  1930. * @param {module:zrender/dom/HandlerProxy} proxy HandlerProxy instance.
  1931. * @param {HTMLElement} painterRoot painter.root (not painter.getViewportRoot()).
  1932. */
  1933. var Handler = function (storage, painter, proxy, painterRoot) {
  1934. Eventful.call(this);
  1935. this.storage = storage;
  1936. this.painter = painter;
  1937. this.painterRoot = painterRoot;
  1938. proxy = proxy || new EmptyProxy();
  1939. /**
  1940. * Proxy of event. can be Dom, WebGLSurface, etc.
  1941. */
  1942. this.proxy = null;
  1943. /**
  1944. * {target, topTarget, x, y}
  1945. * @private
  1946. * @type {Object}
  1947. */
  1948. this._hovered = {};
  1949. /**
  1950. * @private
  1951. * @type {Date}
  1952. */
  1953. this._lastTouchMoment;
  1954. /**
  1955. * @private
  1956. * @type {number}
  1957. */
  1958. this._lastX;
  1959. /**
  1960. * @private
  1961. * @type {number}
  1962. */
  1963. this._lastY;
  1964. /**
  1965. * @private
  1966. * @type {module:zrender/core/GestureMgr}
  1967. */
  1968. this._gestureMgr;
  1969. Draggable.call(this);
  1970. this.setHandlerProxy(proxy);
  1971. };
  1972. Handler.prototype = {
  1973. constructor: Handler,
  1974. setHandlerProxy: function (proxy) {
  1975. if (this.proxy) {
  1976. this.proxy.dispose();
  1977. }
  1978. if (proxy) {
  1979. each$1(handlerNames, function (name) {
  1980. proxy.on && proxy.on(name, this[name], this);
  1981. }, this);
  1982. // Attach handler
  1983. proxy.handler = this;
  1984. }
  1985. this.proxy = proxy;
  1986. },
  1987. mousemove: function (event) {
  1988. var x = event.zrX;
  1989. var y = event.zrY;
  1990. var lastHovered = this._hovered;
  1991. var lastHoveredTarget = lastHovered.target;
  1992. // If lastHoveredTarget is removed from zr (detected by '__zr') by some API call
  1993. // (like 'setOption' or 'dispatchAction') in event handlers, we should find
  1994. // lastHovered again here. Otherwise 'mouseout' can not be triggered normally.
  1995. // See #6198.
  1996. if (lastHoveredTarget && !lastHoveredTarget.__zr) {
  1997. lastHovered = this.findHover(lastHovered.x, lastHovered.y);
  1998. lastHoveredTarget = lastHovered.target;
  1999. }
  2000. var hovered = this._hovered = this.findHover(x, y);
  2001. var hoveredTarget = hovered.target;
  2002. var proxy = this.proxy;
  2003. proxy.setCursor && proxy.setCursor(hoveredTarget ? hoveredTarget.cursor : 'default');
  2004. // Mouse out on previous hovered element
  2005. if (lastHoveredTarget && hoveredTarget !== lastHoveredTarget) {
  2006. this.dispatchToElement(lastHovered, 'mouseout', event);
  2007. }
  2008. // Mouse moving on one element
  2009. this.dispatchToElement(hovered, 'mousemove', event);
  2010. // Mouse over on a new element
  2011. if (hoveredTarget && hoveredTarget !== lastHoveredTarget) {
  2012. this.dispatchToElement(hovered, 'mouseover', event);
  2013. }
  2014. },
  2015. mouseout: function (event) {
  2016. this.dispatchToElement(this._hovered, 'mouseout', event);
  2017. // There might be some doms created by upper layer application
  2018. // at the same level of painter.getViewportRoot() (e.g., tooltip
  2019. // dom created by echarts), where 'globalout' event should not
  2020. // be triggered when mouse enters these doms. (But 'mouseout'
  2021. // should be triggered at the original hovered element as usual).
  2022. var element = event.toElement || event.relatedTarget;
  2023. var innerDom;
  2024. do {
  2025. element = element && element.parentNode;
  2026. }
  2027. while (element && element.nodeType !== 9 && !(
  2028. innerDom = element === this.painterRoot
  2029. ));
  2030. !innerDom && this.trigger('globalout', {event: event});
  2031. },
  2032. /**
  2033. * Resize
  2034. */
  2035. resize: function (event) {
  2036. this._hovered = {};
  2037. },
  2038. /**
  2039. * Dispatch event
  2040. * @param {string} eventName
  2041. * @param {event=} eventArgs
  2042. */
  2043. dispatch: function (eventName, eventArgs) {
  2044. var handler = this[eventName];
  2045. handler && handler.call(this, eventArgs);
  2046. },
  2047. /**
  2048. * Dispose
  2049. */
  2050. dispose: function () {
  2051. this.proxy.dispose();
  2052. this.storage =
  2053. this.proxy =
  2054. this.painter = null;
  2055. },
  2056. /**
  2057. * 设置默认的cursor style
  2058. * @param {string} [cursorStyle='default'] 例如 crosshair
  2059. */
  2060. setCursorStyle: function (cursorStyle) {
  2061. var proxy = this.proxy;
  2062. proxy.setCursor && proxy.setCursor(cursorStyle);
  2063. },
  2064. /**
  2065. * 事件分发代理
  2066. *
  2067. * @private
  2068. * @param {Object} targetInfo {target, topTarget} 目标图形元素
  2069. * @param {string} eventName 事件名称
  2070. * @param {Object} event 事件对象
  2071. */
  2072. dispatchToElement: function (targetInfo, eventName, event) {
  2073. targetInfo = targetInfo || {};
  2074. var el = targetInfo.target;
  2075. if (el && el.silent) {
  2076. return;
  2077. }
  2078. var eventHandler = 'on' + eventName;
  2079. var eventPacket = makeEventPacket(eventName, targetInfo, event);
  2080. while (el) {
  2081. el[eventHandler]
  2082. && (eventPacket.cancelBubble = el[eventHandler].call(el, eventPacket));
  2083. el.trigger(eventName, eventPacket);
  2084. el = el.parent;
  2085. if (eventPacket.cancelBubble) {
  2086. break;
  2087. }
  2088. }
  2089. if (!eventPacket.cancelBubble) {
  2090. // 冒泡到顶级 zrender 对象
  2091. this.trigger(eventName, eventPacket);
  2092. // 分发事件到用户自定义层
  2093. // 用户有可能在全局 click 事件中 dispose,所以需要判断下 painter 是否存在
  2094. this.painter && this.painter.eachOtherLayer(function (layer) {
  2095. if (typeof (layer[eventHandler]) === 'function') {
  2096. layer[eventHandler].call(layer, eventPacket);
  2097. }
  2098. if (layer.trigger) {
  2099. layer.trigger(eventName, eventPacket);
  2100. }
  2101. });
  2102. }
  2103. },
  2104. /**
  2105. * @private
  2106. * @param {number} x
  2107. * @param {number} y
  2108. * @param {module:zrender/graphic/Displayable} exclude
  2109. * @return {model:zrender/Element}
  2110. * @method
  2111. */
  2112. findHover: function (x, y, exclude) {
  2113. var list = this.storage.getDisplayList();
  2114. var out = {x: x, y: y};
  2115. for (var i = list.length - 1; i >= 0; i--) {
  2116. var hoverCheckResult;
  2117. if (list[i] !== exclude
  2118. // getDisplayList may include ignored item in VML mode
  2119. && !list[i].ignore
  2120. && (hoverCheckResult = isHover(list[i], x, y))
  2121. ) {
  2122. !out.topTarget && (out.topTarget = list[i]);
  2123. if (hoverCheckResult !== SILENT) {
  2124. out.target = list[i];
  2125. break;
  2126. }
  2127. }
  2128. }
  2129. return out;
  2130. },
  2131. processGesture: function (event, stage) {
  2132. if (!this._gestureMgr) {
  2133. this._gestureMgr = new GestureMgr();
  2134. }
  2135. var gestureMgr = this._gestureMgr;
  2136. stage === 'start' && gestureMgr.clear();
  2137. var gestureInfo = gestureMgr.recognize(
  2138. event,
  2139. this.findHover(event.zrX, event.zrY, null).target,
  2140. this.proxy.dom
  2141. );
  2142. stage === 'end' && gestureMgr.clear();
  2143. // Do not do any preventDefault here. Upper application do that if necessary.
  2144. if (gestureInfo) {
  2145. var type = gestureInfo.type;
  2146. event.gestureEvent = type;
  2147. this.dispatchToElement({target: gestureInfo.target}, type, gestureInfo.event);
  2148. }
  2149. }
  2150. };
  2151. // Common handlers
  2152. each$1(['click', 'mousedown', 'mouseup', 'mousewheel', 'dblclick', 'contextmenu'], function (name) {
  2153. Handler.prototype[name] = function (event) {
  2154. // Find hover again to avoid click event is dispatched manually. Or click is triggered without mouseover
  2155. var hovered = this.findHover(event.zrX, event.zrY);
  2156. var hoveredTarget = hovered.target;
  2157. if (name === 'mousedown') {
  2158. this._downEl = hoveredTarget;
  2159. this._downPoint = [event.zrX, event.zrY];
  2160. // In case click triggered before mouseup
  2161. this._upEl = hoveredTarget;
  2162. }
  2163. else if (name === 'mouseup') {
  2164. this._upEl = hoveredTarget;
  2165. }
  2166. else if (name === 'click') {
  2167. if (this._downEl !== this._upEl
  2168. // Original click event is triggered on the whole canvas element,
  2169. // including the case that `mousedown` - `mousemove` - `mouseup`,
  2170. // which should be filtered, otherwise it will bring trouble to
  2171. // pan and zoom.
  2172. || !this._downPoint
  2173. // Arbitrary value
  2174. || dist(this._downPoint, [event.zrX, event.zrY]) > 4
  2175. ) {
  2176. return;
  2177. }
  2178. this._downPoint = null;
  2179. }
  2180. this.dispatchToElement(hovered, name, event);
  2181. };
  2182. });
  2183. function isHover(displayable, x, y) {
  2184. if (displayable[displayable.rectHover ? 'rectContain' : 'contain'](x, y)) {
  2185. var el = displayable;
  2186. var isSilent;
  2187. while (el) {
  2188. // If clipped by ancestor.
  2189. // FIXME: If clipPath has neither stroke nor fill,
  2190. // el.clipPath.contain(x, y) will always return false.
  2191. if (el.clipPath && !el.clipPath.contain(x, y)) {
  2192. return false;
  2193. }
  2194. if (el.silent) {
  2195. isSilent = true;
  2196. }
  2197. el = el.parent;
  2198. }
  2199. return isSilent ? SILENT : true;
  2200. }
  2201. return false;
  2202. }
  2203. mixin(Handler, Eventful);
  2204. mixin(Handler, Draggable);
  2205. /**
  2206. * 3x2矩阵操作类
  2207. * @exports zrender/tool/matrix
  2208. */
  2209. var ArrayCtor$1 = typeof Float32Array === 'undefined'
  2210. ? Array
  2211. : Float32Array;
  2212. /**
  2213. * Create a identity matrix.
  2214. * @return {Float32Array|Array.<number>}
  2215. */
  2216. function create$1() {
  2217. var out = new ArrayCtor$1(6);
  2218. identity(out);
  2219. return out;
  2220. }
  2221. /**
  2222. * 设置矩阵为单位矩阵
  2223. * @param {Float32Array|Array.<number>} out
  2224. */
  2225. function identity(out) {
  2226. out[0] = 1;
  2227. out[1] = 0;
  2228. out[2] = 0;
  2229. out[3] = 1;
  2230. out[4] = 0;
  2231. out[5] = 0;
  2232. return out;
  2233. }
  2234. /**
  2235. * 复制矩阵
  2236. * @param {Float32Array|Array.<number>} out
  2237. * @param {Float32Array|Array.<number>} m
  2238. */
  2239. function copy$1(out, m) {
  2240. out[0] = m[0];
  2241. out[1] = m[1];
  2242. out[2] = m[2];
  2243. out[3] = m[3];
  2244. out[4] = m[4];
  2245. out[5] = m[5];
  2246. return out;
  2247. }
  2248. /**
  2249. * 矩阵相乘
  2250. * @param {Float32Array|Array.<number>} out
  2251. * @param {Float32Array|Array.<number>} m1
  2252. * @param {Float32Array|Array.<number>} m2
  2253. */
  2254. function mul$1(out, m1, m2) {
  2255. // Consider matrix.mul(m, m2, m);
  2256. // where out is the same as m2.
  2257. // So use temp variable to escape error.
  2258. var out0 = m1[0] * m2[0] + m1[2] * m2[1];
  2259. var out1 = m1[1] * m2[0] + m1[3] * m2[1];
  2260. var out2 = m1[0] * m2[2] + m1[2] * m2[3];
  2261. var out3 = m1[1] * m2[2] + m1[3] * m2[3];
  2262. var out4 = m1[0] * m2[4] + m1[2] * m2[5] + m1[4];
  2263. var out5 = m1[1] * m2[4] + m1[3] * m2[5] + m1[5];
  2264. out[0] = out0;
  2265. out[1] = out1;
  2266. out[2] = out2;
  2267. out[3] = out3;
  2268. out[4] = out4;
  2269. out[5] = out5;
  2270. return out;
  2271. }
  2272. /**
  2273. * 平移变换
  2274. * @param {Float32Array|Array.<number>} out
  2275. * @param {Float32Array|Array.<number>} a
  2276. * @param {Float32Array|Array.<number>} v
  2277. */
  2278. function translate(out, a, v) {
  2279. out[0] = a[0];
  2280. out[1] = a[1];
  2281. out[2] = a[2];
  2282. out[3] = a[3];
  2283. out[4] = a[4] + v[0];
  2284. out[5] = a[5] + v[1];
  2285. return out;
  2286. }
  2287. /**
  2288. * 旋转变换
  2289. * @param {Float32Array|Array.<number>} out
  2290. * @param {Float32Array|Array.<number>} a
  2291. * @param {number} rad
  2292. */
  2293. function rotate(out, a, rad) {
  2294. var aa = a[0];
  2295. var ac = a[2];
  2296. var atx = a[4];
  2297. var ab = a[1];
  2298. var ad = a[3];
  2299. var aty = a[5];
  2300. var st = Math.sin(rad);
  2301. var ct = Math.cos(rad);
  2302. out[0] = aa * ct + ab * st;
  2303. out[1] = -aa * st + ab * ct;
  2304. out[2] = ac * ct + ad * st;
  2305. out[3] = -ac * st + ct * ad;
  2306. out[4] = ct * atx + st * aty;
  2307. out[5] = ct * aty - st * atx;
  2308. return out;
  2309. }
  2310. /**
  2311. * 缩放变换
  2312. * @param {Float32Array|Array.<number>} out
  2313. * @param {Float32Array|Array.<number>} a
  2314. * @param {Float32Array|Array.<number>} v
  2315. */
  2316. function scale$1(out, a, v) {
  2317. var vx = v[0];
  2318. var vy = v[1];
  2319. out[0] = a[0] * vx;
  2320. out[1] = a[1] * vy;
  2321. out[2] = a[2] * vx;
  2322. out[3] = a[3] * vy;
  2323. out[4] = a[4] * vx;
  2324. out[5] = a[5] * vy;
  2325. return out;
  2326. }
  2327. /**
  2328. * 求逆矩阵
  2329. * @param {Float32Array|Array.<number>} out
  2330. * @param {Float32Array|Array.<number>} a
  2331. */
  2332. function invert(out, a) {
  2333. var aa = a[0];
  2334. var ac = a[2];
  2335. var atx = a[4];
  2336. var ab = a[1];
  2337. var ad = a[3];
  2338. var aty = a[5];
  2339. var det = aa * ad - ab * ac;
  2340. if (!det) {
  2341. return null;
  2342. }
  2343. det = 1.0 / det;
  2344. out[0] = ad * det;
  2345. out[1] = -ab * det;
  2346. out[2] = -ac * det;
  2347. out[3] = aa * det;
  2348. out[4] = (ac * aty - ad * atx) * det;
  2349. out[5] = (ab * atx - aa * aty) * det;
  2350. return out;
  2351. }
  2352. /**
  2353. * Clone a new matrix.
  2354. * @param {Float32Array|Array.<number>} a
  2355. */
  2356. function clone$2(a) {
  2357. var b = create$1();
  2358. copy$1(b, a);
  2359. return b;
  2360. }
  2361. var matrix = (Object.freeze || Object)({
  2362. create: create$1,
  2363. identity: identity,
  2364. copy: copy$1,
  2365. mul: mul$1,
  2366. translate: translate,
  2367. rotate: rotate,
  2368. scale: scale$1,
  2369. invert: invert,
  2370. clone: clone$2
  2371. });
  2372. /**
  2373. * 提供变换扩展
  2374. * @module zrender/mixin/Transformable
  2375. * @author pissang (https://www.github.com/pissang)
  2376. */
  2377. var mIdentity = identity;
  2378. var EPSILON = 5e-5;
  2379. function isNotAroundZero(val) {
  2380. return val > EPSILON || val < -EPSILON;
  2381. }
  2382. /**
  2383. * @alias module:zrender/mixin/Transformable
  2384. * @constructor
  2385. */
  2386. var Transformable = function (opts) {
  2387. opts = opts || {};
  2388. // If there are no given position, rotation, scale
  2389. if (!opts.position) {
  2390. /**
  2391. * 平移
  2392. * @type {Array.<number>}
  2393. * @default [0, 0]
  2394. */
  2395. this.position = [0, 0];
  2396. }
  2397. if (opts.rotation == null) {
  2398. /**
  2399. * 旋转
  2400. * @type {Array.<number>}
  2401. * @default 0
  2402. */
  2403. this.rotation = 0;
  2404. }
  2405. if (!opts.scale) {
  2406. /**
  2407. * 缩放
  2408. * @type {Array.<number>}
  2409. * @default [1, 1]
  2410. */
  2411. this.scale = [1, 1];
  2412. }
  2413. /**
  2414. * 旋转和缩放的原点
  2415. * @type {Array.<number>}
  2416. * @default null
  2417. */
  2418. this.origin = this.origin || null;
  2419. };
  2420. var transformableProto = Transformable.prototype;
  2421. transformableProto.transform = null;
  2422. /**
  2423. * 判断是否需要有坐标变换
  2424. * 如果有坐标变换, 则从position, rotation, scale以及父节点的transform计算出自身的transform矩阵
  2425. */
  2426. transformableProto.needLocalTransform = function () {
  2427. return isNotAroundZero(this.rotation)
  2428. || isNotAroundZero(this.position[0])
  2429. || isNotAroundZero(this.position[1])
  2430. || isNotAroundZero(this.scale[0] - 1)
  2431. || isNotAroundZero(this.scale[1] - 1);
  2432. };
  2433. var scaleTmp = [];
  2434. transformableProto.updateTransform = function () {
  2435. var parent = this.parent;
  2436. var parentHasTransform = parent && parent.transform;
  2437. var needLocalTransform = this.needLocalTransform();
  2438. var m = this.transform;
  2439. if (!(needLocalTransform || parentHasTransform)) {
  2440. m && mIdentity(m);
  2441. return;
  2442. }
  2443. m = m || create$1();
  2444. if (needLocalTransform) {
  2445. this.getLocalTransform(m);
  2446. }
  2447. else {
  2448. mIdentity(m);
  2449. }
  2450. // 应用父节点变换
  2451. if (parentHasTransform) {
  2452. if (needLocalTransform) {
  2453. mul$1(m, parent.transform, m);
  2454. }
  2455. else {
  2456. copy$1(m, parent.transform);
  2457. }
  2458. }
  2459. // 保存这个变换矩阵
  2460. this.transform = m;
  2461. var globalScaleRatio = this.globalScaleRatio;
  2462. if (globalScaleRatio != null && globalScaleRatio !== 1) {
  2463. this.getGlobalScale(scaleTmp);
  2464. var relX = scaleTmp[0] < 0 ? -1 : 1;
  2465. var relY = scaleTmp[1] < 0 ? -1 : 1;
  2466. var sx = ((scaleTmp[0] - relX) * globalScaleRatio + relX) / scaleTmp[0] || 0;
  2467. var sy = ((scaleTmp[1] - relY) * globalScaleRatio + relY) / scaleTmp[1] || 0;
  2468. m[0] *= sx;
  2469. m[1] *= sx;
  2470. m[2] *= sy;
  2471. m[3] *= sy;
  2472. }
  2473. this.invTransform = this.invTransform || create$1();
  2474. invert(this.invTransform, m);
  2475. };
  2476. transformableProto.getLocalTransform = function (m) {
  2477. return Transformable.getLocalTransform(this, m);
  2478. };
  2479. /**
  2480. * 将自己的transform应用到context上
  2481. * @param {CanvasRenderingContext2D} ctx
  2482. */
  2483. transformableProto.setTransform = function (ctx) {
  2484. var m = this.transform;
  2485. var dpr = ctx.dpr || 1;
  2486. if (m) {
  2487. ctx.setTransform(dpr * m[0], dpr * m[1], dpr * m[2], dpr * m[3], dpr * m[4], dpr * m[5]);
  2488. }
  2489. else {
  2490. ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
  2491. }
  2492. };
  2493. transformableProto.restoreTransform = function (ctx) {
  2494. var dpr = ctx.dpr || 1;
  2495. ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
  2496. };
  2497. var tmpTransform = [];
  2498. var originTransform = create$1();
  2499. transformableProto.setLocalTransform = function (m) {
  2500. if (!m) {
  2501. // TODO return or set identity?
  2502. return;
  2503. }
  2504. var sx = m[0] * m[0] + m[1] * m[1];
  2505. var sy = m[2] * m[2] + m[3] * m[3];
  2506. var position = this.position;
  2507. var scale$$1 = this.scale;
  2508. if (isNotAroundZero(sx - 1)) {
  2509. sx = Math.sqrt(sx);
  2510. }
  2511. if (isNotAroundZero(sy - 1)) {
  2512. sy = Math.sqrt(sy);
  2513. }
  2514. if (m[0] < 0) {
  2515. sx = -sx;
  2516. }
  2517. if (m[3] < 0) {
  2518. sy = -sy;
  2519. }
  2520. position[0] = m[4];
  2521. position[1] = m[5];
  2522. scale$$1[0] = sx;
  2523. scale$$1[1] = sy;
  2524. this.rotation = Math.atan2(-m[1] / sy, m[0] / sx);
  2525. };
  2526. /**
  2527. * 分解`transform`矩阵到`position`, `rotation`, `scale`
  2528. */
  2529. transformableProto.decomposeTransform = function () {
  2530. if (!this.transform) {
  2531. return;
  2532. }
  2533. var parent = this.parent;
  2534. var m = this.transform;
  2535. if (parent && parent.transform) {
  2536. // Get local transform and decompose them to position, scale, rotation
  2537. mul$1(tmpTransform, parent.invTransform, m);
  2538. m = tmpTransform;
  2539. }
  2540. var origin = this.origin;
  2541. if (origin && (origin[0] || origin[1])) {
  2542. originTransform[4] = origin[0];
  2543. originTransform[5] = origin[1];
  2544. mul$1(tmpTransform, m, originTransform);
  2545. tmpTransform[4] -= origin[0];
  2546. tmpTransform[5] -= origin[1];
  2547. m = tmpTransform;
  2548. }
  2549. this.setLocalTransform(m);
  2550. };
  2551. /**
  2552. * Get global scale
  2553. * @return {Array.<number>}
  2554. */
  2555. transformableProto.getGlobalScale = function (out) {
  2556. var m = this.transform;
  2557. out = out || [];
  2558. if (!m) {
  2559. out[0] = 1;
  2560. out[1] = 1;
  2561. return out;
  2562. }
  2563. out[0] = Math.sqrt(m[0] * m[0] + m[1] * m[1]);
  2564. out[1] = Math.sqrt(m[2] * m[2] + m[3] * m[3]);
  2565. if (m[0] < 0) {
  2566. out[0] = -out[0];
  2567. }
  2568. if (m[3] < 0) {
  2569. out[1] = -out[1];
  2570. }
  2571. return out;
  2572. };
  2573. /**
  2574. * 变换坐标位置到 shape 的局部坐标空间
  2575. * @method
  2576. * @param {number} x
  2577. * @param {number} y
  2578. * @return {Array.<number>}
  2579. */
  2580. transformableProto.transformCoordToLocal = function (x, y) {
  2581. var v2 = [x, y];
  2582. var invTransform = this.invTransform;
  2583. if (invTransform) {
  2584. applyTransform(v2, v2, invTransform);
  2585. }
  2586. return v2;
  2587. };
  2588. /**
  2589. * 变换局部坐标位置到全局坐标空间
  2590. * @method
  2591. * @param {number} x
  2592. * @param {number} y
  2593. * @return {Array.<number>}
  2594. */
  2595. transformableProto.transformCoordToGlobal = function (x, y) {
  2596. var v2 = [x, y];
  2597. var transform = this.transform;
  2598. if (transform) {
  2599. applyTransform(v2, v2, transform);
  2600. }
  2601. return v2;
  2602. };
  2603. /**
  2604. * @static
  2605. * @param {Object} target
  2606. * @param {Array.<number>} target.origin
  2607. * @param {number} target.rotation
  2608. * @param {Array.<number>} target.position
  2609. * @param {Array.<number>} [m]
  2610. */
  2611. Transformable.getLocalTransform = function (target, m) {
  2612. m = m || [];
  2613. mIdentity(m);
  2614. var origin = target.origin;
  2615. var scale$$1 = target.scale || [1, 1];
  2616. var rotation = target.rotation || 0;
  2617. var position = target.position || [0, 0];
  2618. if (origin) {
  2619. // Translate to origin
  2620. m[4] -= origin[0];
  2621. m[5] -= origin[1];
  2622. }
  2623. scale$1(m, m, scale$$1);
  2624. if (rotation) {
  2625. rotate(m, m, rotation);
  2626. }
  2627. if (origin) {
  2628. // Translate back from origin
  2629. m[4] += origin[0];
  2630. m[5] += origin[1];
  2631. }
  2632. m[4] += position[0];
  2633. m[5] += position[1];
  2634. return m;
  2635. };
  2636. /**
  2637. * 缓动代码来自 https://github.com/sole/tween.js/blob/master/src/Tween.js
  2638. * @see http://sole.github.io/tween.js/examples/03_graphs.html
  2639. * @exports zrender/animation/easing
  2640. */
  2641. var easing = {
  2642. /**
  2643. * @param {number} k
  2644. * @return {number}
  2645. */
  2646. linear: function (k) {
  2647. return k;
  2648. },
  2649. /**
  2650. * @param {number} k
  2651. * @return {number}
  2652. */
  2653. quadraticIn: function (k) {
  2654. return k * k;
  2655. },
  2656. /**
  2657. * @param {number} k
  2658. * @return {number}
  2659. */
  2660. quadraticOut: function (k) {
  2661. return k * (2 - k);
  2662. },
  2663. /**
  2664. * @param {number} k
  2665. * @return {number}
  2666. */
  2667. quadraticInOut: function (k) {
  2668. if ((k *= 2) < 1) {
  2669. return 0.5 * k * k;
  2670. }
  2671. return -0.5 * (--k * (k - 2) - 1);
  2672. },
  2673. // 三次方的缓动(t^3)
  2674. /**
  2675. * @param {number} k
  2676. * @return {number}
  2677. */
  2678. cubicIn: function (k) {
  2679. return k * k * k;
  2680. },
  2681. /**
  2682. * @param {number} k
  2683. * @return {number}
  2684. */
  2685. cubicOut: function (k) {
  2686. return --k * k * k + 1;
  2687. },
  2688. /**
  2689. * @param {number} k
  2690. * @return {number}
  2691. */
  2692. cubicInOut: function (k) {
  2693. if ((k *= 2) < 1) {
  2694. return 0.5 * k * k * k;
  2695. }
  2696. return 0.5 * ((k -= 2) * k * k + 2);
  2697. },
  2698. // 四次方的缓动(t^4)
  2699. /**
  2700. * @param {number} k
  2701. * @return {number}
  2702. */
  2703. quarticIn: function (k) {
  2704. return k * k * k * k;
  2705. },
  2706. /**
  2707. * @param {number} k
  2708. * @return {number}
  2709. */
  2710. quarticOut: function (k) {
  2711. return 1 - (--k * k * k * k);
  2712. },
  2713. /**
  2714. * @param {number} k
  2715. * @return {number}
  2716. */
  2717. quarticInOut: function (k) {
  2718. if ((k *= 2) < 1) {
  2719. return 0.5 * k * k * k * k;
  2720. }
  2721. return -0.5 * ((k -= 2) * k * k * k - 2);
  2722. },
  2723. // 五次方的缓动(t^5)
  2724. /**
  2725. * @param {number} k
  2726. * @return {number}
  2727. */
  2728. quinticIn: function (k) {
  2729. return k * k * k * k * k;
  2730. },
  2731. /**
  2732. * @param {number} k
  2733. * @return {number}
  2734. */
  2735. quinticOut: function (k) {
  2736. return --k * k * k * k * k + 1;
  2737. },
  2738. /**
  2739. * @param {number} k
  2740. * @return {number}
  2741. */
  2742. quinticInOut: function (k) {
  2743. if ((k *= 2) < 1) {
  2744. return 0.5 * k * k * k * k * k;
  2745. }
  2746. return 0.5 * ((k -= 2) * k * k * k * k + 2);
  2747. },
  2748. // 正弦曲线的缓动(sin(t))
  2749. /**
  2750. * @param {number} k
  2751. * @return {number}
  2752. */
  2753. sinusoidalIn: function (k) {
  2754. return 1 - Math.cos(k * Math.PI / 2);
  2755. },
  2756. /**
  2757. * @param {number} k
  2758. * @return {number}
  2759. */
  2760. sinusoidalOut: function (k) {
  2761. return Math.sin(k * Math.PI / 2);
  2762. },
  2763. /**
  2764. * @param {number} k
  2765. * @return {number}
  2766. */
  2767. sinusoidalInOut: function (k) {
  2768. return 0.5 * (1 - Math.cos(Math.PI * k));
  2769. },
  2770. // 指数曲线的缓动(2^t)
  2771. /**
  2772. * @param {number} k
  2773. * @return {number}
  2774. */
  2775. exponentialIn: function (k) {
  2776. return k === 0 ? 0 : Math.pow(1024, k - 1);
  2777. },
  2778. /**
  2779. * @param {number} k
  2780. * @return {number}
  2781. */
  2782. exponentialOut: function (k) {
  2783. return k === 1 ? 1 : 1 - Math.pow(2, -10 * k);
  2784. },
  2785. /**
  2786. * @param {number} k
  2787. * @return {number}
  2788. */
  2789. exponentialInOut: function (k) {
  2790. if (k === 0) {
  2791. return 0;
  2792. }
  2793. if (k === 1) {
  2794. return 1;
  2795. }
  2796. if ((k *= 2) < 1) {
  2797. return 0.5 * Math.pow(1024, k - 1);
  2798. }
  2799. return 0.5 * (-Math.pow(2, -10 * (k - 1)) + 2);
  2800. },
  2801. // 圆形曲线的缓动(sqrt(1-t^2))
  2802. /**
  2803. * @param {number} k
  2804. * @return {number}
  2805. */
  2806. circularIn: function (k) {
  2807. return 1 - Math.sqrt(1 - k * k);
  2808. },
  2809. /**
  2810. * @param {number} k
  2811. * @return {number}
  2812. */
  2813. circularOut: function (k) {
  2814. return Math.sqrt(1 - (--k * k));
  2815. },
  2816. /**
  2817. * @param {number} k
  2818. * @return {number}
  2819. */
  2820. circularInOut: function (k) {
  2821. if ((k *= 2) < 1) {
  2822. return -0.5 * (Math.sqrt(1 - k * k) - 1);
  2823. }
  2824. return 0.5 * (Math.sqrt(1 - (k -= 2) * k) + 1);
  2825. },
  2826. // 创建类似于弹簧在停止前来回振荡的动画
  2827. /**
  2828. * @param {number} k
  2829. * @return {number}
  2830. */
  2831. elasticIn: function (k) {
  2832. var s;
  2833. var a = 0.1;
  2834. var p = 0.4;
  2835. if (k === 0) {
  2836. return 0;
  2837. }
  2838. if (k === 1) {
  2839. return 1;
  2840. }
  2841. if (!a || a < 1) {
  2842. a = 1;
  2843. s = p / 4;
  2844. }
  2845. else {
  2846. s = p * Math.asin(1 / a) / (2 * Math.PI);
  2847. }
  2848. return -(a * Math.pow(2, 10 * (k -= 1))
  2849. * Math.sin((k - s) * (2 * Math.PI) / p));
  2850. },
  2851. /**
  2852. * @param {number} k
  2853. * @return {number}
  2854. */
  2855. elasticOut: function (k) {
  2856. var s;
  2857. var a = 0.1;
  2858. var p = 0.4;
  2859. if (k === 0) {
  2860. return 0;
  2861. }
  2862. if (k === 1) {
  2863. return 1;
  2864. }
  2865. if (!a || a < 1) {
  2866. a = 1;
  2867. s = p / 4;
  2868. }
  2869. else {
  2870. s = p * Math.asin(1 / a) / (2 * Math.PI);
  2871. }
  2872. return (a * Math.pow(2, -10 * k)
  2873. * Math.sin((k - s) * (2 * Math.PI) / p) + 1);
  2874. },
  2875. /**
  2876. * @param {number} k
  2877. * @return {number}
  2878. */
  2879. elasticInOut: function (k) {
  2880. var s;
  2881. var a = 0.1;
  2882. var p = 0.4;
  2883. if (k === 0) {
  2884. return 0;
  2885. }
  2886. if (k === 1) {
  2887. return 1;
  2888. }
  2889. if (!a || a < 1) {
  2890. a = 1;
  2891. s = p / 4;
  2892. }
  2893. else {
  2894. s = p * Math.asin(1 / a) / (2 * Math.PI);
  2895. }
  2896. if ((k *= 2) < 1) {
  2897. return -0.5 * (a * Math.pow(2, 10 * (k -= 1))
  2898. * Math.sin((k - s) * (2 * Math.PI) / p));
  2899. }
  2900. return a * Math.pow(2, -10 * (k -= 1))
  2901. * Math.sin((k - s) * (2 * Math.PI) / p) * 0.5 + 1;
  2902. },
  2903. // 在某一动画开始沿指示的路径进行动画处理前稍稍收回该动画的移动
  2904. /**
  2905. * @param {number} k
  2906. * @return {number}
  2907. */
  2908. backIn: function (k) {
  2909. var s = 1.70158;
  2910. return k * k * ((s + 1) * k - s);
  2911. },
  2912. /**
  2913. * @param {number} k
  2914. * @return {number}
  2915. */
  2916. backOut: function (k) {
  2917. var s = 1.70158;
  2918. return --k * k * ((s + 1) * k + s) + 1;
  2919. },
  2920. /**
  2921. * @param {number} k
  2922. * @return {number}
  2923. */
  2924. backInOut: function (k) {
  2925. var s = 1.70158 * 1.525;
  2926. if ((k *= 2) < 1) {
  2927. return 0.5 * (k * k * ((s + 1) * k - s));
  2928. }
  2929. return 0.5 * ((k -= 2) * k * ((s + 1) * k + s) + 2);
  2930. },
  2931. // 创建弹跳效果
  2932. /**
  2933. * @param {number} k
  2934. * @return {number}
  2935. */
  2936. bounceIn: function (k) {
  2937. return 1 - easing.bounceOut(1 - k);
  2938. },
  2939. /**
  2940. * @param {number} k
  2941. * @return {number}
  2942. */
  2943. bounceOut: function (k) {
  2944. if (k < (1 / 2.75)) {
  2945. return 7.5625 * k * k;
  2946. }
  2947. else if (k < (2 / 2.75)) {
  2948. return 7.5625 * (k -= (1.5 / 2.75)) * k + 0.75;
  2949. }
  2950. else if (k < (2.5 / 2.75)) {
  2951. return 7.5625 * (k -= (2.25 / 2.75)) * k + 0.9375;
  2952. }
  2953. else {
  2954. return 7.5625 * (k -= (2.625 / 2.75)) * k + 0.984375;
  2955. }
  2956. },
  2957. /**
  2958. * @param {number} k
  2959. * @return {number}
  2960. */
  2961. bounceInOut: function (k) {
  2962. if (k < 0.5) {
  2963. return easing.bounceIn(k * 2) * 0.5;
  2964. }
  2965. return easing.bounceOut(k * 2 - 1) * 0.5 + 0.5;
  2966. }
  2967. };
  2968. /**
  2969. * 动画主控制器
  2970. * @config target 动画对象,可以是数组,如果是数组的话会批量分发onframe等事件
  2971. * @config life(1000) 动画时长
  2972. * @config delay(0) 动画延迟时间
  2973. * @config loop(true)
  2974. * @config gap(0) 循环的间隔时间
  2975. * @config onframe
  2976. * @config easing(optional)
  2977. * @config ondestroy(optional)
  2978. * @config onrestart(optional)
  2979. *
  2980. * TODO pause
  2981. */
  2982. function Clip(options) {
  2983. this._target = options.target;
  2984. // 生命周期
  2985. this._life = options.life || 1000;
  2986. // 延时
  2987. this._delay = options.delay || 0;
  2988. // 开始时间
  2989. // this._startTime = new Date().getTime() + this._delay;// 单位毫秒
  2990. this._initialized = false;
  2991. // 是否循环
  2992. this.loop = options.loop == null ? false : options.loop;
  2993. this.gap = options.gap || 0;
  2994. this.easing = options.easing || 'Linear';
  2995. this.onframe = options.onframe;
  2996. this.ondestroy = options.ondestroy;
  2997. this.onrestart = options.onrestart;
  2998. this._pausedTime = 0;
  2999. this._paused = false;
  3000. }
  3001. Clip.prototype = {
  3002. constructor: Clip,
  3003. step: function (globalTime, deltaTime) {
  3004. // Set startTime on first step, or _startTime may has milleseconds different between clips
  3005. // PENDING
  3006. if (!this._initialized) {
  3007. this._startTime = globalTime + this._delay;
  3008. this._initialized = true;
  3009. }
  3010. if (this._paused) {
  3011. this._pausedTime += deltaTime;
  3012. return;
  3013. }
  3014. var percent = (globalTime - this._startTime - this._pausedTime) / this._life;
  3015. // 还没开始
  3016. if (percent < 0) {
  3017. return;
  3018. }
  3019. percent = Math.min(percent, 1);
  3020. var easing$$1 = this.easing;
  3021. var easingFunc = typeof easing$$1 === 'string' ? easing[easing$$1] : easing$$1;
  3022. var schedule = typeof easingFunc === 'function'
  3023. ? easingFunc(percent)
  3024. : percent;
  3025. this.fire('frame', schedule);
  3026. // 结束
  3027. if (percent === 1) {
  3028. if (this.loop) {
  3029. this.restart(globalTime);
  3030. // 重新开始周期
  3031. // 抛出而不是直接调用事件直到 stage.update 后再统一调用这些事件
  3032. return 'restart';
  3033. }
  3034. // 动画完成将这个控制器标识为待删除
  3035. // 在Animation.update中进行批量删除
  3036. this._needsRemove = true;
  3037. return 'destroy';
  3038. }
  3039. return null;
  3040. },
  3041. restart: function (globalTime) {
  3042. var remainder = (globalTime - this._startTime - this._pausedTime) % this._life;
  3043. this._startTime = globalTime - remainder + this.gap;
  3044. this._pausedTime = 0;
  3045. this._needsRemove = false;
  3046. },
  3047. fire: function (eventType, arg) {
  3048. eventType = 'on' + eventType;
  3049. if (this[eventType]) {
  3050. this[eventType](this._target, arg);
  3051. }
  3052. },
  3053. pause: function () {
  3054. this._paused = true;
  3055. },
  3056. resume: function () {
  3057. this._paused = false;
  3058. }
  3059. };
  3060. // Simple LRU cache use doubly linked list
  3061. // @module zrender/core/LRU
  3062. /**
  3063. * Simple double linked list. Compared with array, it has O(1) remove operation.
  3064. * @constructor
  3065. */
  3066. var LinkedList = function () {
  3067. /**
  3068. * @type {module:zrender/core/LRU~Entry}
  3069. */
  3070. this.head = null;
  3071. /**
  3072. * @type {module:zrender/core/LRU~Entry}
  3073. */
  3074. this.tail = null;
  3075. this._len = 0;
  3076. };
  3077. var linkedListProto = LinkedList.prototype;
  3078. /**
  3079. * Insert a new value at the tail
  3080. * @param {} val
  3081. * @return {module:zrender/core/LRU~Entry}
  3082. */
  3083. linkedListProto.insert = function (val) {
  3084. var entry = new Entry(val);
  3085. this.insertEntry(entry);
  3086. return entry;
  3087. };
  3088. /**
  3089. * Insert an entry at the tail
  3090. * @param {module:zrender/core/LRU~Entry} entry
  3091. */
  3092. linkedListProto.insertEntry = function (entry) {
  3093. if (!this.head) {
  3094. this.head = this.tail = entry;
  3095. }
  3096. else {
  3097. this.tail.next = entry;
  3098. entry.prev = this.tail;
  3099. entry.next = null;
  3100. this.tail = entry;
  3101. }
  3102. this._len++;
  3103. };
  3104. /**
  3105. * Remove entry.
  3106. * @param {module:zrender/core/LRU~Entry} entry
  3107. */
  3108. linkedListProto.remove = function (entry) {
  3109. var prev = entry.prev;
  3110. var next = entry.next;
  3111. if (prev) {
  3112. prev.next = next;
  3113. }
  3114. else {
  3115. // Is head
  3116. this.head = next;
  3117. }
  3118. if (next) {
  3119. next.prev = prev;
  3120. }
  3121. else {
  3122. // Is tail
  3123. this.tail = prev;
  3124. }
  3125. entry.next = entry.prev = null;
  3126. this._len--;
  3127. };
  3128. /**
  3129. * @return {number}
  3130. */
  3131. linkedListProto.len = function () {
  3132. return this._len;
  3133. };
  3134. /**
  3135. * Clear list
  3136. */
  3137. linkedListProto.clear = function () {
  3138. this.head = this.tail = null;
  3139. this._len = 0;
  3140. };
  3141. /**
  3142. * @constructor
  3143. * @param {} val
  3144. */
  3145. var Entry = function (val) {
  3146. /**
  3147. * @type {}
  3148. */
  3149. this.value = val;
  3150. /**
  3151. * @type {module:zrender/core/LRU~Entry}
  3152. */
  3153. this.next;
  3154. /**
  3155. * @type {module:zrender/core/LRU~Entry}
  3156. */
  3157. this.prev;
  3158. };
  3159. /**
  3160. * LRU Cache
  3161. * @constructor
  3162. * @alias module:zrender/core/LRU
  3163. */
  3164. var LRU = function (maxSize) {
  3165. this._list = new LinkedList();
  3166. this._map = {};
  3167. this._maxSize = maxSize || 10;
  3168. this._lastRemovedEntry = null;
  3169. };
  3170. var LRUProto = LRU.prototype;
  3171. /**
  3172. * @param {string} key
  3173. * @param {} value
  3174. * @return {} Removed value
  3175. */
  3176. LRUProto.put = function (key, value) {
  3177. var list = this._list;
  3178. var map = this._map;
  3179. var removed = null;
  3180. if (map[key] == null) {
  3181. var len = list.len();
  3182. // Reuse last removed entry
  3183. var entry = this._lastRemovedEntry;
  3184. if (len >= this._maxSize && len > 0) {
  3185. // Remove the least recently used
  3186. var leastUsedEntry = list.head;
  3187. list.remove(leastUsedEntry);
  3188. delete map[leastUsedEntry.key];
  3189. removed = leastUsedEntry.value;
  3190. this._lastRemovedEntry = leastUsedEntry;
  3191. }
  3192. if (entry) {
  3193. entry.value = value;
  3194. }
  3195. else {
  3196. entry = new Entry(value);
  3197. }
  3198. entry.key = key;
  3199. list.insertEntry(entry);
  3200. map[key] = entry;
  3201. }
  3202. return removed;
  3203. };
  3204. /**
  3205. * @param {string} key
  3206. * @return {}
  3207. */
  3208. LRUProto.get = function (key) {
  3209. var entry = this._map[key];
  3210. var list = this._list;
  3211. if (entry != null) {
  3212. // Put the latest used entry in the tail
  3213. if (entry !== list.tail) {
  3214. list.remove(entry);
  3215. list.insertEntry(entry);
  3216. }
  3217. return entry.value;
  3218. }
  3219. };
  3220. /**
  3221. * Clear the cache
  3222. */
  3223. LRUProto.clear = function () {
  3224. this._list.clear();
  3225. this._map = {};
  3226. };
  3227. var kCSSColorTable = {
  3228. 'transparent': [0, 0, 0, 0], 'aliceblue': [240, 248, 255, 1],
  3229. 'antiquewhite': [250, 235, 215, 1], 'aqua': [0, 255, 255, 1],
  3230. 'aquamarine': [127, 255, 212, 1], 'azure': [240, 255, 255, 1],
  3231. 'beige': [245, 245, 220, 1], 'bisque': [255, 228, 196, 1],
  3232. 'black': [0, 0, 0, 1], 'blanchedalmond': [255, 235, 205, 1],
  3233. 'blue': [0, 0, 255, 1], 'blueviolet': [138, 43, 226, 1],
  3234. 'brown': [165, 42, 42, 1], 'burlywood': [222, 184, 135, 1],
  3235. 'cadetblue': [95, 158, 160, 1], 'chartreuse': [127, 255, 0, 1],
  3236. 'chocolate': [210, 105, 30, 1], 'coral': [255, 127, 80, 1],
  3237. 'cornflowerblue': [100, 149, 237, 1], 'cornsilk': [255, 248, 220, 1],
  3238. 'crimson': [220, 20, 60, 1], 'cyan': [0, 255, 255, 1],
  3239. 'darkblue': [0, 0, 139, 1], 'darkcyan': [0, 139, 139, 1],
  3240. 'darkgoldenrod': [184, 134, 11, 1], 'darkgray': [169, 169, 169, 1],
  3241. 'darkgreen': [0, 100, 0, 1], 'darkgrey': [169, 169, 169, 1],
  3242. 'darkkhaki': [189, 183, 107, 1], 'darkmagenta': [139, 0, 139, 1],
  3243. 'darkolivegreen': [85, 107, 47, 1], 'darkorange': [255, 140, 0, 1],
  3244. 'darkorchid': [153, 50, 204, 1], 'darkred': [139, 0, 0, 1],
  3245. 'darksalmon': [233, 150, 122, 1], 'darkseagreen': [143, 188, 143, 1],
  3246. 'darkslateblue': [72, 61, 139, 1], 'darkslategray': [47, 79, 79, 1],
  3247. 'darkslategrey': [47, 79, 79, 1], 'darkturquoise': [0, 206, 209, 1],
  3248. 'darkviolet': [148, 0, 211, 1], 'deeppink': [255, 20, 147, 1],
  3249. 'deepskyblue': [0, 191, 255, 1], 'dimgray': [105, 105, 105, 1],
  3250. 'dimgrey': [105, 105, 105, 1], 'dodgerblue': [30, 144, 255, 1],
  3251. 'firebrick': [178, 34, 34, 1], 'floralwhite': [255, 250, 240, 1],
  3252. 'forestgreen': [34, 139, 34, 1], 'fuchsia': [255, 0, 255, 1],
  3253. 'gainsboro': [220, 220, 220, 1], 'ghostwhite': [248, 248, 255, 1],
  3254. 'gold': [255, 215, 0, 1], 'goldenrod': [218, 165, 32, 1],
  3255. 'gray': [128, 128, 128, 1], 'green': [0, 128, 0, 1],
  3256. 'greenyellow': [173, 255, 47, 1], 'grey': [128, 128, 128, 1],
  3257. 'honeydew': [240, 255, 240, 1], 'hotpink': [255, 105, 180, 1],
  3258. 'indianred': [205, 92, 92, 1], 'indigo': [75, 0, 130, 1],
  3259. 'ivory': [255, 255, 240, 1], 'khaki': [240, 230, 140, 1],
  3260. 'lavender': [230, 230, 250, 1], 'lavenderblush': [255, 240, 245, 1],
  3261. 'lawngreen': [124, 252, 0, 1], 'lemonchiffon': [255, 250, 205, 1],
  3262. 'lightblue': [173, 216, 230, 1], 'lightcoral': [240, 128, 128, 1],
  3263. 'lightcyan': [224, 255, 255, 1], 'lightgoldenrodyellow': [250, 250, 210, 1],
  3264. 'lightgray': [211, 211, 211, 1], 'lightgreen': [144, 238, 144, 1],
  3265. 'lightgrey': [211, 211, 211, 1], 'lightpink': [255, 182, 193, 1],
  3266. 'lightsalmon': [255, 160, 122, 1], 'lightseagreen': [32, 178, 170, 1],
  3267. 'lightskyblue': [135, 206, 250, 1], 'lightslategray': [119, 136, 153, 1],
  3268. 'lightslategrey': [119, 136, 153, 1], 'lightsteelblue': [176, 196, 222, 1],
  3269. 'lightyellow': [255, 255, 224, 1], 'lime': [0, 255, 0, 1],
  3270. 'limegreen': [50, 205, 50, 1], 'linen': [250, 240, 230, 1],
  3271. 'magenta': [255, 0, 255, 1], 'maroon': [128, 0, 0, 1],
  3272. 'mediumaquamarine': [102, 205, 170, 1], 'mediumblue': [0, 0, 205, 1],
  3273. 'mediumorchid': [186, 85, 211, 1], 'mediumpurple': [147, 112, 219, 1],
  3274. 'mediumseagreen': [60, 179, 113, 1], 'mediumslateblue': [123, 104, 238, 1],
  3275. 'mediumspringgreen': [0, 250, 154, 1], 'mediumturquoise': [72, 209, 204, 1],
  3276. 'mediumvioletred': [199, 21, 133, 1], 'midnightblue': [25, 25, 112, 1],
  3277. 'mintcream': [245, 255, 250, 1], 'mistyrose': [255, 228, 225, 1],
  3278. 'moccasin': [255, 228, 181, 1], 'navajowhite': [255, 222, 173, 1],
  3279. 'navy': [0, 0, 128, 1], 'oldlace': [253, 245, 230, 1],
  3280. 'olive': [128, 128, 0, 1], 'olivedrab': [107, 142, 35, 1],
  3281. 'orange': [255, 165, 0, 1], 'orangered': [255, 69, 0, 1],
  3282. 'orchid': [218, 112, 214, 1], 'palegoldenrod': [238, 232, 170, 1],
  3283. 'palegreen': [152, 251, 152, 1], 'paleturquoise': [175, 238, 238, 1],
  3284. 'palevioletred': [219, 112, 147, 1], 'papayawhip': [255, 239, 213, 1],
  3285. 'peachpuff': [255, 218, 185, 1], 'peru': [205, 133, 63, 1],
  3286. 'pink': [255, 192, 203, 1], 'plum': [221, 160, 221, 1],
  3287. 'powderblue': [176, 224, 230, 1], 'purple': [128, 0, 128, 1],
  3288. 'red': [255, 0, 0, 1], 'rosybrown': [188, 143, 143, 1],
  3289. 'royalblue': [65, 105, 225, 1], 'saddlebrown': [139, 69, 19, 1],
  3290. 'salmon': [250, 128, 114, 1], 'sandybrown': [244, 164, 96, 1],
  3291. 'seagreen': [46, 139, 87, 1], 'seashell': [255, 245, 238, 1],
  3292. 'sienna': [160, 82, 45, 1], 'silver': [192, 192, 192, 1],
  3293. 'skyblue': [135, 206, 235, 1], 'slateblue': [106, 90, 205, 1],
  3294. 'slategray': [112, 128, 144, 1], 'slategrey': [112, 128, 144, 1],
  3295. 'snow': [255, 250, 250, 1], 'springgreen': [0, 255, 127, 1],
  3296. 'steelblue': [70, 130, 180, 1], 'tan': [210, 180, 140, 1],
  3297. 'teal': [0, 128, 128, 1], 'thistle': [216, 191, 216, 1],
  3298. 'tomato': [255, 99, 71, 1], 'turquoise': [64, 224, 208, 1],
  3299. 'violet': [238, 130, 238, 1], 'wheat': [245, 222, 179, 1],
  3300. 'white': [255, 255, 255, 1], 'whitesmoke': [245, 245, 245, 1],
  3301. 'yellow': [255, 255, 0, 1], 'yellowgreen': [154, 205, 50, 1]
  3302. };
  3303. function clampCssByte(i) { // Clamp to integer 0 .. 255.
  3304. i = Math.round(i); // Seems to be what Chrome does (vs truncation).
  3305. return i < 0 ? 0 : i > 255 ? 255 : i;
  3306. }
  3307. function clampCssAngle(i) { // Clamp to integer 0 .. 360.
  3308. i = Math.round(i); // Seems to be what Chrome does (vs truncation).
  3309. return i < 0 ? 0 : i > 360 ? 360 : i;
  3310. }
  3311. function clampCssFloat(f) { // Clamp to float 0.0 .. 1.0.
  3312. return f < 0 ? 0 : f > 1 ? 1 : f;
  3313. }
  3314. function parseCssInt(str) { // int or percentage.
  3315. if (str.length && str.charAt(str.length - 1) === '%') {
  3316. return clampCssByte(parseFloat(str) / 100 * 255);
  3317. }
  3318. return clampCssByte(parseInt(str, 10));
  3319. }
  3320. function parseCssFloat(str) { // float or percentage.
  3321. if (str.length && str.charAt(str.length - 1) === '%') {
  3322. return clampCssFloat(parseFloat(str) / 100);
  3323. }
  3324. return clampCssFloat(parseFloat(str));
  3325. }
  3326. function cssHueToRgb(m1, m2, h) {
  3327. if (h < 0) {
  3328. h += 1;
  3329. }
  3330. else if (h > 1) {
  3331. h -= 1;
  3332. }
  3333. if (h * 6 < 1) {
  3334. return m1 + (m2 - m1) * h * 6;
  3335. }
  3336. if (h * 2 < 1) {
  3337. return m2;
  3338. }
  3339. if (h * 3 < 2) {
  3340. return m1 + (m2 - m1) * (2 / 3 - h) * 6;
  3341. }
  3342. return m1;
  3343. }
  3344. function lerpNumber(a, b, p) {
  3345. return a + (b - a) * p;
  3346. }
  3347. function setRgba(out, r, g, b, a) {
  3348. out[0] = r; out[1] = g; out[2] = b; out[3] = a;
  3349. return out;
  3350. }
  3351. function copyRgba(out, a) {
  3352. out[0] = a[0]; out[1] = a[1]; out[2] = a[2]; out[3] = a[3];
  3353. return out;
  3354. }
  3355. var colorCache = new LRU(20);
  3356. var lastRemovedArr = null;
  3357. function putToCache(colorStr, rgbaArr) {
  3358. // Reuse removed array
  3359. if (lastRemovedArr) {
  3360. copyRgba(lastRemovedArr, rgbaArr);
  3361. }
  3362. lastRemovedArr = colorCache.put(colorStr, lastRemovedArr || (rgbaArr.slice()));
  3363. }
  3364. /**
  3365. * @param {string} colorStr
  3366. * @param {Array.<number>} out
  3367. * @return {Array.<number>}
  3368. * @memberOf module:zrender/util/color
  3369. */
  3370. function parse(colorStr, rgbaArr) {
  3371. if (!colorStr) {
  3372. return;
  3373. }
  3374. rgbaArr = rgbaArr || [];
  3375. var cached = colorCache.get(colorStr);
  3376. if (cached) {
  3377. return copyRgba(rgbaArr, cached);
  3378. }
  3379. // colorStr may be not string
  3380. colorStr = colorStr + '';
  3381. // Remove all whitespace, not compliant, but should just be more accepting.
  3382. var str = colorStr.replace(/ /g, '').toLowerCase();
  3383. // Color keywords (and transparent) lookup.
  3384. if (str in kCSSColorTable) {
  3385. copyRgba(rgbaArr, kCSSColorTable[str]);
  3386. putToCache(colorStr, rgbaArr);
  3387. return rgbaArr;
  3388. }
  3389. // #abc and #abc123 syntax.
  3390. if (str.charAt(0) === '#') {
  3391. if (str.length === 4) {
  3392. var iv = parseInt(str.substr(1), 16); // TODO(deanm): Stricter parsing.
  3393. if (!(iv >= 0 && iv <= 0xfff)) {
  3394. setRgba(rgbaArr, 0, 0, 0, 1);
  3395. return; // Covers NaN.
  3396. }
  3397. setRgba(rgbaArr,
  3398. ((iv & 0xf00) >> 4) | ((iv & 0xf00) >> 8),
  3399. (iv & 0xf0) | ((iv & 0xf0) >> 4),
  3400. (iv & 0xf) | ((iv & 0xf) << 4),
  3401. 1
  3402. );
  3403. putToCache(colorStr, rgbaArr);
  3404. return rgbaArr;
  3405. }
  3406. else if (str.length === 7) {
  3407. var iv = parseInt(str.substr(1), 16); // TODO(deanm): Stricter parsing.
  3408. if (!(iv >= 0 && iv <= 0xffffff)) {
  3409. setRgba(rgbaArr, 0, 0, 0, 1);
  3410. return; // Covers NaN.
  3411. }
  3412. setRgba(rgbaArr,
  3413. (iv & 0xff0000) >> 16,
  3414. (iv & 0xff00) >> 8,
  3415. iv & 0xff,
  3416. 1
  3417. );
  3418. putToCache(colorStr, rgbaArr);
  3419. return rgbaArr;
  3420. }
  3421. return;
  3422. }
  3423. var op = str.indexOf('(');
  3424. var ep = str.indexOf(')');
  3425. if (op !== -1 && ep + 1 === str.length) {
  3426. var fname = str.substr(0, op);
  3427. var params = str.substr(op + 1, ep - (op + 1)).split(',');
  3428. var alpha = 1; // To allow case fallthrough.
  3429. switch (fname) {
  3430. case 'rgba':
  3431. if (params.length !== 4) {
  3432. setRgba(rgbaArr, 0, 0, 0, 1);
  3433. return;
  3434. }
  3435. alpha = parseCssFloat(params.pop()); // jshint ignore:line
  3436. // Fall through.
  3437. case 'rgb':
  3438. if (params.length !== 3) {
  3439. setRgba(rgbaArr, 0, 0, 0, 1);
  3440. return;
  3441. }
  3442. setRgba(rgbaArr,
  3443. parseCssInt(params[0]),
  3444. parseCssInt(params[1]),
  3445. parseCssInt(params[2]),
  3446. alpha
  3447. );
  3448. putToCache(colorStr, rgbaArr);
  3449. return rgbaArr;
  3450. case 'hsla':
  3451. if (params.length !== 4) {
  3452. setRgba(rgbaArr, 0, 0, 0, 1);
  3453. return;
  3454. }
  3455. params[3] = parseCssFloat(params[3]);
  3456. hsla2rgba(params, rgbaArr);
  3457. putToCache(colorStr, rgbaArr);
  3458. return rgbaArr;
  3459. case 'hsl':
  3460. if (params.length !== 3) {
  3461. setRgba(rgbaArr, 0, 0, 0, 1);
  3462. return;
  3463. }
  3464. hsla2rgba(params, rgbaArr);
  3465. putToCache(colorStr, rgbaArr);
  3466. return rgbaArr;
  3467. default:
  3468. return;
  3469. }
  3470. }
  3471. setRgba(rgbaArr, 0, 0, 0, 1);
  3472. return;
  3473. }
  3474. /**
  3475. * @param {Array.<number>} hsla
  3476. * @param {Array.<number>} rgba
  3477. * @return {Array.<number>} rgba
  3478. */
  3479. function hsla2rgba(hsla, rgba) {
  3480. var h = (((parseFloat(hsla[0]) % 360) + 360) % 360) / 360; // 0 .. 1
  3481. // NOTE(deanm): According to the CSS spec s/l should only be
  3482. // percentages, but we don't bother and let float or percentage.
  3483. var s = parseCssFloat(hsla[1]);
  3484. var l = parseCssFloat(hsla[2]);
  3485. var m2 = l <= 0.5 ? l * (s + 1) : l + s - l * s;
  3486. var m1 = l * 2 - m2;
  3487. rgba = rgba || [];
  3488. setRgba(rgba,
  3489. clampCssByte(cssHueToRgb(m1, m2, h + 1 / 3) * 255),
  3490. clampCssByte(cssHueToRgb(m1, m2, h) * 255),
  3491. clampCssByte(cssHueToRgb(m1, m2, h - 1 / 3) * 255),
  3492. 1
  3493. );
  3494. if (hsla.length === 4) {
  3495. rgba[3] = hsla[3];
  3496. }
  3497. return rgba;
  3498. }
  3499. /**
  3500. * @param {Array.<number>} rgba
  3501. * @return {Array.<number>} hsla
  3502. */
  3503. function rgba2hsla(rgba) {
  3504. if (!rgba) {
  3505. return;
  3506. }
  3507. // RGB from 0 to 255
  3508. var R = rgba[0] / 255;
  3509. var G = rgba[1] / 255;
  3510. var B = rgba[2] / 255;
  3511. var vMin = Math.min(R, G, B); // Min. value of RGB
  3512. var vMax = Math.max(R, G, B); // Max. value of RGB
  3513. var delta = vMax - vMin; // Delta RGB value
  3514. var L = (vMax + vMin) / 2;
  3515. var H;
  3516. var S;
  3517. // HSL results from 0 to 1
  3518. if (delta === 0) {
  3519. H = 0;
  3520. S = 0;
  3521. }
  3522. else {
  3523. if (L < 0.5) {
  3524. S = delta / (vMax + vMin);
  3525. }
  3526. else {
  3527. S = delta / (2 - vMax - vMin);
  3528. }
  3529. var deltaR = (((vMax - R) / 6) + (delta / 2)) / delta;
  3530. var deltaG = (((vMax - G) / 6) + (delta / 2)) / delta;
  3531. var deltaB = (((vMax - B) / 6) + (delta / 2)) / delta;
  3532. if (R === vMax) {
  3533. H = deltaB - deltaG;
  3534. }
  3535. else if (G === vMax) {
  3536. H = (1 / 3) + deltaR - deltaB;
  3537. }
  3538. else if (B === vMax) {
  3539. H = (2 / 3) + deltaG - deltaR;
  3540. }
  3541. if (H < 0) {
  3542. H += 1;
  3543. }
  3544. if (H > 1) {
  3545. H -= 1;
  3546. }
  3547. }
  3548. var hsla = [H * 360, S, L];
  3549. if (rgba[3] != null) {
  3550. hsla.push(rgba[3]);
  3551. }
  3552. return hsla;
  3553. }
  3554. /**
  3555. * @param {string} color
  3556. * @param {number} level
  3557. * @return {string}
  3558. * @memberOf module:zrender/util/color
  3559. */
  3560. function lift(color, level) {
  3561. var colorArr = parse(color);
  3562. if (colorArr) {
  3563. for (var i = 0; i < 3; i++) {
  3564. if (level < 0) {
  3565. colorArr[i] = colorArr[i] * (1 - level) | 0;
  3566. }
  3567. else {
  3568. colorArr[i] = ((255 - colorArr[i]) * level + colorArr[i]) | 0;
  3569. }
  3570. if (colorArr[i] > 255) {
  3571. colorArr[i] = 255;
  3572. }
  3573. else if (color[i] < 0) {
  3574. colorArr[i] = 0;
  3575. }
  3576. }
  3577. return stringify(colorArr, colorArr.length === 4 ? 'rgba' : 'rgb');
  3578. }
  3579. }
  3580. /**
  3581. * @param {string} color
  3582. * @return {string}
  3583. * @memberOf module:zrender/util/color
  3584. */
  3585. function toHex(color) {
  3586. var colorArr = parse(color);
  3587. if (colorArr) {
  3588. return ((1 << 24) + (colorArr[0] << 16) + (colorArr[1] << 8) + (+colorArr[2])).toString(16).slice(1);
  3589. }
  3590. }
  3591. /**
  3592. * Map value to color. Faster than lerp methods because color is represented by rgba array.
  3593. * @param {number} normalizedValue A float between 0 and 1.
  3594. * @param {Array.<Array.<number>>} colors List of rgba color array
  3595. * @param {Array.<number>} [out] Mapped gba color array
  3596. * @return {Array.<number>} will be null/undefined if input illegal.
  3597. */
  3598. function fastLerp(normalizedValue, colors, out) {
  3599. if (!(colors && colors.length)
  3600. || !(normalizedValue >= 0 && normalizedValue <= 1)
  3601. ) {
  3602. return;
  3603. }
  3604. out = out || [];
  3605. var value = normalizedValue * (colors.length - 1);
  3606. var leftIndex = Math.floor(value);
  3607. var rightIndex = Math.ceil(value);
  3608. var leftColor = colors[leftIndex];
  3609. var rightColor = colors[rightIndex];
  3610. var dv = value - leftIndex;
  3611. out[0] = clampCssByte(lerpNumber(leftColor[0], rightColor[0], dv));
  3612. out[1] = clampCssByte(lerpNumber(leftColor[1], rightColor[1], dv));
  3613. out[2] = clampCssByte(lerpNumber(leftColor[2], rightColor[2], dv));
  3614. out[3] = clampCssFloat(lerpNumber(leftColor[3], rightColor[3], dv));
  3615. return out;
  3616. }
  3617. /**
  3618. * @deprecated
  3619. */
  3620. var fastMapToColor = fastLerp;
  3621. /**
  3622. * @param {number} normalizedValue A float between 0 and 1.
  3623. * @param {Array.<string>} colors Color list.
  3624. * @param {boolean=} fullOutput Default false.
  3625. * @return {(string|Object)} Result color. If fullOutput,
  3626. * return {color: ..., leftIndex: ..., rightIndex: ..., value: ...},
  3627. * @memberOf module:zrender/util/color
  3628. */
  3629. function lerp$1(normalizedValue, colors, fullOutput) {
  3630. if (!(colors && colors.length)
  3631. || !(normalizedValue >= 0 && normalizedValue <= 1)
  3632. ) {
  3633. return;
  3634. }
  3635. var value = normalizedValue * (colors.length - 1);
  3636. var leftIndex = Math.floor(value);
  3637. var rightIndex = Math.ceil(value);
  3638. var leftColor = parse(colors[leftIndex]);
  3639. var rightColor = parse(colors[rightIndex]);
  3640. var dv = value - leftIndex;
  3641. var color = stringify(
  3642. [
  3643. clampCssByte(lerpNumber(leftColor[0], rightColor[0], dv)),
  3644. clampCssByte(lerpNumber(leftColor[1], rightColor[1], dv)),
  3645. clampCssByte(lerpNumber(leftColor[2], rightColor[2], dv)),
  3646. clampCssFloat(lerpNumber(leftColor[3], rightColor[3], dv))
  3647. ],
  3648. 'rgba'
  3649. );
  3650. return fullOutput
  3651. ? {
  3652. color: color,
  3653. leftIndex: leftIndex,
  3654. rightIndex: rightIndex,
  3655. value: value
  3656. }
  3657. : color;
  3658. }
  3659. /**
  3660. * @deprecated
  3661. */
  3662. var mapToColor = lerp$1;
  3663. /**
  3664. * @param {string} color
  3665. * @param {number=} h 0 ~ 360, ignore when null.
  3666. * @param {number=} s 0 ~ 1, ignore when null.
  3667. * @param {number=} l 0 ~ 1, ignore when null.
  3668. * @return {string} Color string in rgba format.
  3669. * @memberOf module:zrender/util/color
  3670. */
  3671. function modifyHSL(color, h, s, l) {
  3672. color = parse(color);
  3673. if (color) {
  3674. color = rgba2hsla(color);
  3675. h != null && (color[0] = clampCssAngle(h));
  3676. s != null && (color[1] = parseCssFloat(s));
  3677. l != null && (color[2] = parseCssFloat(l));
  3678. return stringify(hsla2rgba(color), 'rgba');
  3679. }
  3680. }
  3681. /**
  3682. * @param {string} color
  3683. * @param {number=} alpha 0 ~ 1
  3684. * @return {string} Color string in rgba format.
  3685. * @memberOf module:zrender/util/color
  3686. */
  3687. function modifyAlpha(color, alpha) {
  3688. color = parse(color);
  3689. if (color && alpha != null) {
  3690. color[3] = clampCssFloat(alpha);
  3691. return stringify(color, 'rgba');
  3692. }
  3693. }
  3694. /**
  3695. * @param {Array.<number>} arrColor like [12,33,44,0.4]
  3696. * @param {string} type 'rgba', 'hsva', ...
  3697. * @return {string} Result color. (If input illegal, return undefined).
  3698. */
  3699. function stringify(arrColor, type) {
  3700. if (!arrColor || !arrColor.length) {
  3701. return;
  3702. }
  3703. var colorStr = arrColor[0] + ',' + arrColor[1] + ',' + arrColor[2];
  3704. if (type === 'rgba' || type === 'hsva' || type === 'hsla') {
  3705. colorStr += ',' + arrColor[3];
  3706. }
  3707. return type + '(' + colorStr + ')';
  3708. }
  3709. var color = (Object.freeze || Object)({
  3710. parse: parse,
  3711. lift: lift,
  3712. toHex: toHex,
  3713. fastLerp: fastLerp,
  3714. fastMapToColor: fastMapToColor,
  3715. lerp: lerp$1,
  3716. mapToColor: mapToColor,
  3717. modifyHSL: modifyHSL,
  3718. modifyAlpha: modifyAlpha,
  3719. stringify: stringify
  3720. });
  3721. /**
  3722. * @module echarts/animation/Animator
  3723. */
  3724. var arraySlice = Array.prototype.slice;
  3725. function defaultGetter(target, key) {
  3726. return target[key];
  3727. }
  3728. function defaultSetter(target, key, value) {
  3729. target[key] = value;
  3730. }
  3731. /**
  3732. * @param {number} p0
  3733. * @param {number} p1
  3734. * @param {number} percent
  3735. * @return {number}
  3736. */
  3737. function interpolateNumber(p0, p1, percent) {
  3738. return (p1 - p0) * percent + p0;
  3739. }
  3740. /**
  3741. * @param {string} p0
  3742. * @param {string} p1
  3743. * @param {number} percent
  3744. * @return {string}
  3745. */
  3746. function interpolateString(p0, p1, percent) {
  3747. return percent > 0.5 ? p1 : p0;
  3748. }
  3749. /**
  3750. * @param {Array} p0
  3751. * @param {Array} p1
  3752. * @param {number} percent
  3753. * @param {Array} out
  3754. * @param {number} arrDim
  3755. */
  3756. function interpolateArray(p0, p1, percent, out, arrDim) {
  3757. var len = p0.length;
  3758. if (arrDim === 1) {
  3759. for (var i = 0; i < len; i++) {
  3760. out[i] = interpolateNumber(p0[i], p1[i], percent);
  3761. }
  3762. }
  3763. else {
  3764. var len2 = len && p0[0].length;
  3765. for (var i = 0; i < len; i++) {
  3766. for (var j = 0; j < len2; j++) {
  3767. out[i][j] = interpolateNumber(
  3768. p0[i][j], p1[i][j], percent
  3769. );
  3770. }
  3771. }
  3772. }
  3773. }
  3774. // arr0 is source array, arr1 is target array.
  3775. // Do some preprocess to avoid error happened when interpolating from arr0 to arr1
  3776. function fillArr(arr0, arr1, arrDim) {
  3777. var arr0Len = arr0.length;
  3778. var arr1Len = arr1.length;
  3779. if (arr0Len !== arr1Len) {
  3780. // FIXME Not work for TypedArray
  3781. var isPreviousLarger = arr0Len > arr1Len;
  3782. if (isPreviousLarger) {
  3783. // Cut the previous
  3784. arr0.length = arr1Len;
  3785. }
  3786. else {
  3787. // Fill the previous
  3788. for (var i = arr0Len; i < arr1Len; i++) {
  3789. arr0.push(
  3790. arrDim === 1 ? arr1[i] : arraySlice.call(arr1[i])
  3791. );
  3792. }
  3793. }
  3794. }
  3795. // Handling NaN value
  3796. var len2 = arr0[0] && arr0[0].length;
  3797. for (var i = 0; i < arr0.length; i++) {
  3798. if (arrDim === 1) {
  3799. if (isNaN(arr0[i])) {
  3800. arr0[i] = arr1[i];
  3801. }
  3802. }
  3803. else {
  3804. for (var j = 0; j < len2; j++) {
  3805. if (isNaN(arr0[i][j])) {
  3806. arr0[i][j] = arr1[i][j];
  3807. }
  3808. }
  3809. }
  3810. }
  3811. }
  3812. /**
  3813. * @param {Array} arr0
  3814. * @param {Array} arr1
  3815. * @param {number} arrDim
  3816. * @return {boolean}
  3817. */
  3818. function isArraySame(arr0, arr1, arrDim) {
  3819. if (arr0 === arr1) {
  3820. return true;
  3821. }
  3822. var len = arr0.length;
  3823. if (len !== arr1.length) {
  3824. return false;
  3825. }
  3826. if (arrDim === 1) {
  3827. for (var i = 0; i < len; i++) {
  3828. if (arr0[i] !== arr1[i]) {
  3829. return false;
  3830. }
  3831. }
  3832. }
  3833. else {
  3834. var len2 = arr0[0].length;
  3835. for (var i = 0; i < len; i++) {
  3836. for (var j = 0; j < len2; j++) {
  3837. if (arr0[i][j] !== arr1[i][j]) {
  3838. return false;
  3839. }
  3840. }
  3841. }
  3842. }
  3843. return true;
  3844. }
  3845. /**
  3846. * Catmull Rom interpolate array
  3847. * @param {Array} p0
  3848. * @param {Array} p1
  3849. * @param {Array} p2
  3850. * @param {Array} p3
  3851. * @param {number} t
  3852. * @param {number} t2
  3853. * @param {number} t3
  3854. * @param {Array} out
  3855. * @param {number} arrDim
  3856. */
  3857. function catmullRomInterpolateArray(
  3858. p0, p1, p2, p3, t, t2, t3, out, arrDim
  3859. ) {
  3860. var len = p0.length;
  3861. if (arrDim === 1) {
  3862. for (var i = 0; i < len; i++) {
  3863. out[i] = catmullRomInterpolate(
  3864. p0[i], p1[i], p2[i], p3[i], t, t2, t3
  3865. );
  3866. }
  3867. }
  3868. else {
  3869. var len2 = p0[0].length;
  3870. for (var i = 0; i < len; i++) {
  3871. for (var j = 0; j < len2; j++) {
  3872. out[i][j] = catmullRomInterpolate(
  3873. p0[i][j], p1[i][j], p2[i][j], p3[i][j],
  3874. t, t2, t3
  3875. );
  3876. }
  3877. }
  3878. }
  3879. }
  3880. /**
  3881. * Catmull Rom interpolate number
  3882. * @param {number} p0
  3883. * @param {number} p1
  3884. * @param {number} p2
  3885. * @param {number} p3
  3886. * @param {number} t
  3887. * @param {number} t2
  3888. * @param {number} t3
  3889. * @return {number}
  3890. */
  3891. function catmullRomInterpolate(p0, p1, p2, p3, t, t2, t3) {
  3892. var v0 = (p2 - p0) * 0.5;
  3893. var v1 = (p3 - p1) * 0.5;
  3894. return (2 * (p1 - p2) + v0 + v1) * t3
  3895. + (-3 * (p1 - p2) - 2 * v0 - v1) * t2
  3896. + v0 * t + p1;
  3897. }
  3898. function cloneValue(value) {
  3899. if (isArrayLike(value)) {
  3900. var len = value.length;
  3901. if (isArrayLike(value[0])) {
  3902. var ret = [];
  3903. for (var i = 0; i < len; i++) {
  3904. ret.push(arraySlice.call(value[i]));
  3905. }
  3906. return ret;
  3907. }
  3908. return arraySlice.call(value);
  3909. }
  3910. return value;
  3911. }
  3912. function rgba2String(rgba) {
  3913. rgba[0] = Math.floor(rgba[0]);
  3914. rgba[1] = Math.floor(rgba[1]);
  3915. rgba[2] = Math.floor(rgba[2]);
  3916. return 'rgba(' + rgba.join(',') + ')';
  3917. }
  3918. function getArrayDim(keyframes) {
  3919. var lastValue = keyframes[keyframes.length - 1].value;
  3920. return isArrayLike(lastValue && lastValue[0]) ? 2 : 1;
  3921. }
  3922. function createTrackClip(animator, easing, oneTrackDone, keyframes, propName, forceAnimate) {
  3923. var getter = animator._getter;
  3924. var setter = animator._setter;
  3925. var useSpline = easing === 'spline';
  3926. var trackLen = keyframes.length;
  3927. if (!trackLen) {
  3928. return;
  3929. }
  3930. // Guess data type
  3931. var firstVal = keyframes[0].value;
  3932. var isValueArray = isArrayLike(firstVal);
  3933. var isValueColor = false;
  3934. var isValueString = false;
  3935. // For vertices morphing
  3936. var arrDim = isValueArray ? getArrayDim(keyframes) : 0;
  3937. var trackMaxTime;
  3938. // Sort keyframe as ascending
  3939. keyframes.sort(function (a, b) {
  3940. return a.time - b.time;
  3941. });
  3942. trackMaxTime = keyframes[trackLen - 1].time;
  3943. // Percents of each keyframe
  3944. var kfPercents = [];
  3945. // Value of each keyframe
  3946. var kfValues = [];
  3947. var prevValue = keyframes[0].value;
  3948. var isAllValueEqual = true;
  3949. for (var i = 0; i < trackLen; i++) {
  3950. kfPercents.push(keyframes[i].time / trackMaxTime);
  3951. // Assume value is a color when it is a string
  3952. var value = keyframes[i].value;
  3953. // Check if value is equal, deep check if value is array
  3954. if (!((isValueArray && isArraySame(value, prevValue, arrDim))
  3955. || (!isValueArray && value === prevValue))) {
  3956. isAllValueEqual = false;
  3957. }
  3958. prevValue = value;
  3959. // Try converting a string to a color array
  3960. if (typeof value === 'string') {
  3961. var colorArray = parse(value);
  3962. if (colorArray) {
  3963. value = colorArray;
  3964. isValueColor = true;
  3965. }
  3966. else {
  3967. isValueString = true;
  3968. }
  3969. }
  3970. kfValues.push(value);
  3971. }
  3972. if (!forceAnimate && isAllValueEqual) {
  3973. return;
  3974. }
  3975. var lastValue = kfValues[trackLen - 1];
  3976. // Polyfill array and NaN value
  3977. for (var i = 0; i < trackLen - 1; i++) {
  3978. if (isValueArray) {
  3979. fillArr(kfValues[i], lastValue, arrDim);
  3980. }
  3981. else {
  3982. if (isNaN(kfValues[i]) && !isNaN(lastValue) && !isValueString && !isValueColor) {
  3983. kfValues[i] = lastValue;
  3984. }
  3985. }
  3986. }
  3987. isValueArray && fillArr(getter(animator._target, propName), lastValue, arrDim);
  3988. // Cache the key of last frame to speed up when
  3989. // animation playback is sequency
  3990. var lastFrame = 0;
  3991. var lastFramePercent = 0;
  3992. var start;
  3993. var w;
  3994. var p0;
  3995. var p1;
  3996. var p2;
  3997. var p3;
  3998. if (isValueColor) {
  3999. var rgba = [0, 0, 0, 0];
  4000. }
  4001. var onframe = function (target, percent) {
  4002. // Find the range keyframes
  4003. // kf1-----kf2---------current--------kf3
  4004. // find kf2 and kf3 and do interpolation
  4005. var frame;
  4006. // In the easing function like elasticOut, percent may less than 0
  4007. if (percent < 0) {
  4008. frame = 0;
  4009. }
  4010. else if (percent < lastFramePercent) {
  4011. // Start from next key
  4012. // PENDING start from lastFrame ?
  4013. start = Math.min(lastFrame + 1, trackLen - 1);
  4014. for (frame = start; frame >= 0; frame--) {
  4015. if (kfPercents[frame] <= percent) {
  4016. break;
  4017. }
  4018. }
  4019. // PENDING really need to do this ?
  4020. frame = Math.min(frame, trackLen - 2);
  4021. }
  4022. else {
  4023. for (frame = lastFrame; frame < trackLen; frame++) {
  4024. if (kfPercents[frame] > percent) {
  4025. break;
  4026. }
  4027. }
  4028. frame = Math.min(frame - 1, trackLen - 2);
  4029. }
  4030. lastFrame = frame;
  4031. lastFramePercent = percent;
  4032. var range = (kfPercents[frame + 1] - kfPercents[frame]);
  4033. if (range === 0) {
  4034. return;
  4035. }
  4036. else {
  4037. w = (percent - kfPercents[frame]) / range;
  4038. }
  4039. if (useSpline) {
  4040. p1 = kfValues[frame];
  4041. p0 = kfValues[frame === 0 ? frame : frame - 1];
  4042. p2 = kfValues[frame > trackLen - 2 ? trackLen - 1 : frame + 1];
  4043. p3 = kfValues[frame > trackLen - 3 ? trackLen - 1 : frame + 2];
  4044. if (isValueArray) {
  4045. catmullRomInterpolateArray(
  4046. p0, p1, p2, p3, w, w * w, w * w * w,
  4047. getter(target, propName),
  4048. arrDim
  4049. );
  4050. }
  4051. else {
  4052. var value;
  4053. if (isValueColor) {
  4054. value = catmullRomInterpolateArray(
  4055. p0, p1, p2, p3, w, w * w, w * w * w,
  4056. rgba, 1
  4057. );
  4058. value = rgba2String(rgba);
  4059. }
  4060. else if (isValueString) {
  4061. // String is step(0.5)
  4062. return interpolateString(p1, p2, w);
  4063. }
  4064. else {
  4065. value = catmullRomInterpolate(
  4066. p0, p1, p2, p3, w, w * w, w * w * w
  4067. );
  4068. }
  4069. setter(
  4070. target,
  4071. propName,
  4072. value
  4073. );
  4074. }
  4075. }
  4076. else {
  4077. if (isValueArray) {
  4078. interpolateArray(
  4079. kfValues[frame], kfValues[frame + 1], w,
  4080. getter(target, propName),
  4081. arrDim
  4082. );
  4083. }
  4084. else {
  4085. var value;
  4086. if (isValueColor) {
  4087. interpolateArray(
  4088. kfValues[frame], kfValues[frame + 1], w,
  4089. rgba, 1
  4090. );
  4091. value = rgba2String(rgba);
  4092. }
  4093. else if (isValueString) {
  4094. // String is step(0.5)
  4095. return interpolateString(kfValues[frame], kfValues[frame + 1], w);
  4096. }
  4097. else {
  4098. value = interpolateNumber(kfValues[frame], kfValues[frame + 1], w);
  4099. }
  4100. setter(
  4101. target,
  4102. propName,
  4103. value
  4104. );
  4105. }
  4106. }
  4107. };
  4108. var clip = new Clip({
  4109. target: animator._target,
  4110. life: trackMaxTime,
  4111. loop: animator._loop,
  4112. delay: animator._delay,
  4113. onframe: onframe,
  4114. ondestroy: oneTrackDone
  4115. });
  4116. if (easing && easing !== 'spline') {
  4117. clip.easing = easing;
  4118. }
  4119. return clip;
  4120. }
  4121. /**
  4122. * @alias module:zrender/animation/Animator
  4123. * @constructor
  4124. * @param {Object} target
  4125. * @param {boolean} loop
  4126. * @param {Function} getter
  4127. * @param {Function} setter
  4128. */
  4129. var Animator = function (target, loop, getter, setter) {
  4130. this._tracks = {};
  4131. this._target = target;
  4132. this._loop = loop || false;
  4133. this._getter = getter || defaultGetter;
  4134. this._setter = setter || defaultSetter;
  4135. this._clipCount = 0;
  4136. this._delay = 0;
  4137. this._doneList = [];
  4138. this._onframeList = [];
  4139. this._clipList = [];
  4140. };
  4141. Animator.prototype = {
  4142. /**
  4143. * 设置动画关键帧
  4144. * @param {number} time 关键帧时间,单位是ms
  4145. * @param {Object} props 关键帧的属性值,key-value表示
  4146. * @return {module:zrender/animation/Animator}
  4147. */
  4148. when: function (time /* ms */, props) {
  4149. var tracks = this._tracks;
  4150. for (var propName in props) {
  4151. if (!props.hasOwnProperty(propName)) {
  4152. continue;
  4153. }
  4154. if (!tracks[propName]) {
  4155. tracks[propName] = [];
  4156. // Invalid value
  4157. var value = this._getter(this._target, propName);
  4158. if (value == null) {
  4159. // zrLog('Invalid property ' + propName);
  4160. continue;
  4161. }
  4162. // If time is 0
  4163. // Then props is given initialize value
  4164. // Else
  4165. // Initialize value from current prop value
  4166. if (time !== 0) {
  4167. tracks[propName].push({
  4168. time: 0,
  4169. value: cloneValue(value)
  4170. });
  4171. }
  4172. }
  4173. tracks[propName].push({
  4174. time: time,
  4175. value: props[propName]
  4176. });
  4177. }
  4178. return this;
  4179. },
  4180. /**
  4181. * 添加动画每一帧的回调函数
  4182. * @param {Function} callback
  4183. * @return {module:zrender/animation/Animator}
  4184. */
  4185. during: function (callback) {
  4186. this._onframeList.push(callback);
  4187. return this;
  4188. },
  4189. pause: function () {
  4190. for (var i = 0; i < this._clipList.length; i++) {
  4191. this._clipList[i].pause();
  4192. }
  4193. this._paused = true;
  4194. },
  4195. resume: function () {
  4196. for (var i = 0; i < this._clipList.length; i++) {
  4197. this._clipList[i].resume();
  4198. }
  4199. this._paused = false;
  4200. },
  4201. isPaused: function () {
  4202. return !!this._paused;
  4203. },
  4204. _doneCallback: function () {
  4205. // Clear all tracks
  4206. this._tracks = {};
  4207. // Clear all clips
  4208. this._clipList.length = 0;
  4209. var doneList = this._doneList;
  4210. var len = doneList.length;
  4211. for (var i = 0; i < len; i++) {
  4212. doneList[i].call(this);
  4213. }
  4214. },
  4215. /**
  4216. * 开始执行动画
  4217. * @param {string|Function} [easing]
  4218. * 动画缓动函数,详见{@link module:zrender/animation/easing}
  4219. * @param {boolean} forceAnimate
  4220. * @return {module:zrender/animation/Animator}
  4221. */
  4222. start: function (easing, forceAnimate) {
  4223. var self = this;
  4224. var clipCount = 0;
  4225. var oneTrackDone = function () {
  4226. clipCount--;
  4227. if (!clipCount) {
  4228. self._doneCallback();
  4229. }
  4230. };
  4231. var lastClip;
  4232. for (var propName in this._tracks) {
  4233. if (!this._tracks.hasOwnProperty(propName)) {
  4234. continue;
  4235. }
  4236. var clip = createTrackClip(
  4237. this, easing, oneTrackDone,
  4238. this._tracks[propName], propName, forceAnimate
  4239. );
  4240. if (clip) {
  4241. this._clipList.push(clip);
  4242. clipCount++;
  4243. // If start after added to animation
  4244. if (this.animation) {
  4245. this.animation.addClip(clip);
  4246. }
  4247. lastClip = clip;
  4248. }
  4249. }
  4250. // Add during callback on the last clip
  4251. if (lastClip) {
  4252. var oldOnFrame = lastClip.onframe;
  4253. lastClip.onframe = function (target, percent) {
  4254. oldOnFrame(target, percent);
  4255. for (var i = 0; i < self._onframeList.length; i++) {
  4256. self._onframeList[i](target, percent);
  4257. }
  4258. };
  4259. }
  4260. // This optimization will help the case that in the upper application
  4261. // the view may be refreshed frequently, where animation will be
  4262. // called repeatly but nothing changed.
  4263. if (!clipCount) {
  4264. this._doneCallback();
  4265. }
  4266. return this;
  4267. },
  4268. /**
  4269. * 停止动画
  4270. * @param {boolean} forwardToLast If move to last frame before stop
  4271. */
  4272. stop: function (forwardToLast) {
  4273. var clipList = this._clipList;
  4274. var animation = this.animation;
  4275. for (var i = 0; i < clipList.length; i++) {
  4276. var clip = clipList[i];
  4277. if (forwardToLast) {
  4278. // Move to last frame before stop
  4279. clip.onframe(this._target, 1);
  4280. }
  4281. animation && animation.removeClip(clip);
  4282. }
  4283. clipList.length = 0;
  4284. },
  4285. /**
  4286. * 设置动画延迟开始的时间
  4287. * @param {number} time 单位ms
  4288. * @return {module:zrender/animation/Animator}
  4289. */
  4290. delay: function (time) {
  4291. this._delay = time;
  4292. return this;
  4293. },
  4294. /**
  4295. * 添加动画结束的回调
  4296. * @param {Function} cb
  4297. * @return {module:zrender/animation/Animator}
  4298. */
  4299. done: function (cb) {
  4300. if (cb) {
  4301. this._doneList.push(cb);
  4302. }
  4303. return this;
  4304. },
  4305. /**
  4306. * @return {Array.<module:zrender/animation/Clip>}
  4307. */
  4308. getClips: function () {
  4309. return this._clipList;
  4310. }
  4311. };
  4312. var dpr = 1;
  4313. // If in browser environment
  4314. if (typeof window !== 'undefined') {
  4315. dpr = Math.max(window.devicePixelRatio || 1, 1);
  4316. }
  4317. /**
  4318. * config默认配置项
  4319. * @exports zrender/config
  4320. * @author Kener (@Kener-林峰, kener.linfeng@gmail.com)
  4321. */
  4322. /**
  4323. * debug日志选项:catchBrushException为true下有效
  4324. * 0 : 不生成debug数据,发布用
  4325. * 1 : 异常抛出,调试用
  4326. * 2 : 控制台输出,调试用
  4327. */
  4328. var debugMode = 0;
  4329. // retina 屏幕优化
  4330. var devicePixelRatio = dpr;
  4331. var log = function () {
  4332. };
  4333. if (debugMode === 1) {
  4334. log = function () {
  4335. for (var k in arguments) {
  4336. throw new Error(arguments[k]);
  4337. }
  4338. };
  4339. }
  4340. else if (debugMode > 1) {
  4341. log = function () {
  4342. for (var k in arguments) {
  4343. console.log(arguments[k]);
  4344. }
  4345. };
  4346. }
  4347. var zrLog = log;
  4348. /**
  4349. * @alias modue:zrender/mixin/Animatable
  4350. * @constructor
  4351. */
  4352. var Animatable = function () {
  4353. /**
  4354. * @type {Array.<module:zrender/animation/Animator>}
  4355. * @readOnly
  4356. */
  4357. this.animators = [];
  4358. };
  4359. Animatable.prototype = {
  4360. constructor: Animatable,
  4361. /**
  4362. * 动画
  4363. *
  4364. * @param {string} path The path to fetch value from object, like 'a.b.c'.
  4365. * @param {boolean} [loop] Whether to loop animation.
  4366. * @return {module:zrender/animation/Animator}
  4367. * @example:
  4368. * el.animate('style', false)
  4369. * .when(1000, {x: 10} )
  4370. * .done(function(){ // Animation done })
  4371. * .start()
  4372. */
  4373. animate: function (path, loop) {
  4374. var target;
  4375. var animatingShape = false;
  4376. var el = this;
  4377. var zr = this.__zr;
  4378. if (path) {
  4379. var pathSplitted = path.split('.');
  4380. var prop = el;
  4381. // If animating shape
  4382. animatingShape = pathSplitted[0] === 'shape';
  4383. for (var i = 0, l = pathSplitted.length; i < l; i++) {
  4384. if (!prop) {
  4385. continue;
  4386. }
  4387. prop = prop[pathSplitted[i]];
  4388. }
  4389. if (prop) {
  4390. target = prop;
  4391. }
  4392. }
  4393. else {
  4394. target = el;
  4395. }
  4396. if (!target) {
  4397. zrLog(
  4398. 'Property "'
  4399. + path
  4400. + '" is not existed in element '
  4401. + el.id
  4402. );
  4403. return;
  4404. }
  4405. var animators = el.animators;
  4406. var animator = new Animator(target, loop);
  4407. animator.during(function (target) {
  4408. el.dirty(animatingShape);
  4409. })
  4410. .done(function () {
  4411. // FIXME Animator will not be removed if use `Animator#stop` to stop animation
  4412. animators.splice(indexOf(animators, animator), 1);
  4413. });
  4414. animators.push(animator);
  4415. // If animate after added to the zrender
  4416. if (zr) {
  4417. zr.animation.addAnimator(animator);
  4418. }
  4419. return animator;
  4420. },
  4421. /**
  4422. * 停止动画
  4423. * @param {boolean} forwardToLast If move to last frame before stop
  4424. */
  4425. stopAnimation: function (forwardToLast) {
  4426. var animators = this.animators;
  4427. var len = animators.length;
  4428. for (var i = 0; i < len; i++) {
  4429. animators[i].stop(forwardToLast);
  4430. }
  4431. animators.length = 0;
  4432. return this;
  4433. },
  4434. /**
  4435. * Caution: this method will stop previous animation.
  4436. * So do not use this method to one element twice before
  4437. * animation starts, unless you know what you are doing.
  4438. * @param {Object} target
  4439. * @param {number} [time=500] Time in ms
  4440. * @param {string} [easing='linear']
  4441. * @param {number} [delay=0]
  4442. * @param {Function} [callback]
  4443. * @param {Function} [forceAnimate] Prevent stop animation and callback
  4444. * immediently when target values are the same as current values.
  4445. *
  4446. * @example
  4447. * // Animate position
  4448. * el.animateTo({
  4449. * position: [10, 10]
  4450. * }, function () { // done })
  4451. *
  4452. * // Animate shape, style and position in 100ms, delayed 100ms, with cubicOut easing
  4453. * el.animateTo({
  4454. * shape: {
  4455. * width: 500
  4456. * },
  4457. * style: {
  4458. * fill: 'red'
  4459. * }
  4460. * position: [10, 10]
  4461. * }, 100, 100, 'cubicOut', function () { // done })
  4462. */
  4463. // TODO Return animation key
  4464. animateTo: function (target, time, delay, easing, callback, forceAnimate) {
  4465. animateTo(this, target, time, delay, easing, callback, forceAnimate);
  4466. },
  4467. /**
  4468. * Animate from the target state to current state.
  4469. * The params and the return value are the same as `this.animateTo`.
  4470. */
  4471. animateFrom: function (target, time, delay, easing, callback, forceAnimate) {
  4472. animateTo(this, target, time, delay, easing, callback, forceAnimate, true);
  4473. }
  4474. };
  4475. function animateTo(animatable, target, time, delay, easing, callback, forceAnimate, reverse) {
  4476. // animateTo(target, time, easing, callback);
  4477. if (isString(delay)) {
  4478. callback = easing;
  4479. easing = delay;
  4480. delay = 0;
  4481. }
  4482. // animateTo(target, time, delay, callback);
  4483. else if (isFunction$1(easing)) {
  4484. callback = easing;
  4485. easing = 'linear';
  4486. delay = 0;
  4487. }
  4488. // animateTo(target, time, callback);
  4489. else if (isFunction$1(delay)) {
  4490. callback = delay;
  4491. delay = 0;
  4492. }
  4493. // animateTo(target, callback)
  4494. else if (isFunction$1(time)) {
  4495. callback = time;
  4496. time = 500;
  4497. }
  4498. // animateTo(target)
  4499. else if (!time) {
  4500. time = 500;
  4501. }
  4502. // Stop all previous animations
  4503. animatable.stopAnimation();
  4504. animateToShallow(animatable, '', animatable, target, time, delay, reverse);
  4505. // Animators may be removed immediately after start
  4506. // if there is nothing to animate
  4507. var animators = animatable.animators.slice();
  4508. var count = animators.length;
  4509. function done() {
  4510. count--;
  4511. if (!count) {
  4512. callback && callback();
  4513. }
  4514. }
  4515. // No animators. This should be checked before animators[i].start(),
  4516. // because 'done' may be executed immediately if no need to animate.
  4517. if (!count) {
  4518. callback && callback();
  4519. }
  4520. // Start after all animators created
  4521. // Incase any animator is done immediately when all animation properties are not changed
  4522. for (var i = 0; i < animators.length; i++) {
  4523. animators[i]
  4524. .done(done)
  4525. .start(easing, forceAnimate);
  4526. }
  4527. }
  4528. /**
  4529. * @param {string} path=''
  4530. * @param {Object} source=animatable
  4531. * @param {Object} target
  4532. * @param {number} [time=500]
  4533. * @param {number} [delay=0]
  4534. * @param {boolean} [reverse] If `true`, animate
  4535. * from the `target` to current state.
  4536. *
  4537. * @example
  4538. * // Animate position
  4539. * el._animateToShallow({
  4540. * position: [10, 10]
  4541. * })
  4542. *
  4543. * // Animate shape, style and position in 100ms, delayed 100ms
  4544. * el._animateToShallow({
  4545. * shape: {
  4546. * width: 500
  4547. * },
  4548. * style: {
  4549. * fill: 'red'
  4550. * }
  4551. * position: [10, 10]
  4552. * }, 100, 100)
  4553. */
  4554. function animateToShallow(animatable, path, source, target, time, delay, reverse) {
  4555. var objShallow = {};
  4556. var propertyCount = 0;
  4557. for (var name in target) {
  4558. if (!target.hasOwnProperty(name)) {
  4559. continue;
  4560. }
  4561. if (source[name] != null) {
  4562. if (isObject$1(target[name]) && !isArrayLike(target[name])) {
  4563. animateToShallow(
  4564. animatable,
  4565. path ? path + '.' + name : name,
  4566. source[name],
  4567. target[name],
  4568. time,
  4569. delay,
  4570. reverse
  4571. );
  4572. }
  4573. else {
  4574. if (reverse) {
  4575. objShallow[name] = source[name];
  4576. setAttrByPath(animatable, path, name, target[name]);
  4577. }
  4578. else {
  4579. objShallow[name] = target[name];
  4580. }
  4581. propertyCount++;
  4582. }
  4583. }
  4584. else if (target[name] != null && !reverse) {
  4585. setAttrByPath(animatable, path, name, target[name]);
  4586. }
  4587. }
  4588. if (propertyCount > 0) {
  4589. animatable.animate(path, false)
  4590. .when(time == null ? 500 : time, objShallow)
  4591. .delay(delay || 0);
  4592. }
  4593. }
  4594. function setAttrByPath(el, path, name, value) {
  4595. // Attr directly if not has property
  4596. // FIXME, if some property not needed for element ?
  4597. if (!path) {
  4598. el.attr(name, value);
  4599. }
  4600. else {
  4601. // Only support set shape or style
  4602. var props = {};
  4603. props[path] = {};
  4604. props[path][name] = value;
  4605. el.attr(props);
  4606. }
  4607. }
  4608. /**
  4609. * @alias module:zrender/Element
  4610. * @constructor
  4611. * @extends {module:zrender/mixin/Animatable}
  4612. * @extends {module:zrender/mixin/Transformable}
  4613. * @extends {module:zrender/mixin/Eventful}
  4614. */
  4615. var Element = function (opts) { // jshint ignore:line
  4616. Transformable.call(this, opts);
  4617. Eventful.call(this, opts);
  4618. Animatable.call(this, opts);
  4619. /**
  4620. * 画布元素ID
  4621. * @type {string}
  4622. */
  4623. this.id = opts.id || guid();
  4624. };
  4625. Element.prototype = {
  4626. /**
  4627. * 元素类型
  4628. * Element type
  4629. * @type {string}
  4630. */
  4631. type: 'element',
  4632. /**
  4633. * 元素名字
  4634. * Element name
  4635. * @type {string}
  4636. */
  4637. name: '',
  4638. /**
  4639. * ZRender 实例对象,会在 element 添加到 zrender 实例中后自动赋值
  4640. * ZRender instance will be assigned when element is associated with zrender
  4641. * @name module:/zrender/Element#__zr
  4642. * @type {module:zrender/ZRender}
  4643. */
  4644. __zr: null,
  4645. /**
  4646. * 图形是否忽略,为true时忽略图形的绘制以及事件触发
  4647. * If ignore drawing and events of the element object
  4648. * @name module:/zrender/Element#ignore
  4649. * @type {boolean}
  4650. * @default false
  4651. */
  4652. ignore: false,
  4653. /**
  4654. * 用于裁剪的路径(shape),所有 Group 内的路径在绘制时都会被这个路径裁剪
  4655. * 该路径会继承被裁减对象的变换
  4656. * @type {module:zrender/graphic/Path}
  4657. * @see http://www.w3.org/TR/2dcontext/#clipping-region
  4658. * @readOnly
  4659. */
  4660. clipPath: null,
  4661. /**
  4662. * 是否是 Group
  4663. * @type {boolean}
  4664. */
  4665. isGroup: false,
  4666. /**
  4667. * Drift element
  4668. * @param {number} dx dx on the global space
  4669. * @param {number} dy dy on the global space
  4670. */
  4671. drift: function (dx, dy) {
  4672. switch (this.draggable) {
  4673. case 'horizontal':
  4674. dy = 0;
  4675. break;
  4676. case 'vertical':
  4677. dx = 0;
  4678. break;
  4679. }
  4680. var m = this.transform;
  4681. if (!m) {
  4682. m = this.transform = [1, 0, 0, 1, 0, 0];
  4683. }
  4684. m[4] += dx;
  4685. m[5] += dy;
  4686. this.decomposeTransform();
  4687. this.dirty(false);
  4688. },
  4689. /**
  4690. * Hook before update
  4691. */
  4692. beforeUpdate: function () {},
  4693. /**
  4694. * Hook after update
  4695. */
  4696. afterUpdate: function () {},
  4697. /**
  4698. * Update each frame
  4699. */
  4700. update: function () {
  4701. this.updateTransform();
  4702. },
  4703. /**
  4704. * @param {Function} cb
  4705. * @param {} context
  4706. */
  4707. traverse: function (cb, context) {},
  4708. /**
  4709. * @protected
  4710. */
  4711. attrKV: function (key, value) {
  4712. if (key === 'position' || key === 'scale' || key === 'origin') {
  4713. // Copy the array
  4714. if (value) {
  4715. var target = this[key];
  4716. if (!target) {
  4717. target = this[key] = [];
  4718. }
  4719. target[0] = value[0];
  4720. target[1] = value[1];
  4721. }
  4722. }
  4723. else {
  4724. this[key] = value;
  4725. }
  4726. },
  4727. /**
  4728. * Hide the element
  4729. */
  4730. hide: function () {
  4731. this.ignore = true;
  4732. this.__zr && this.__zr.refresh();
  4733. },
  4734. /**
  4735. * Show the element
  4736. */
  4737. show: function () {
  4738. this.ignore = false;
  4739. this.__zr && this.__zr.refresh();
  4740. },
  4741. /**
  4742. * @param {string|Object} key
  4743. * @param {*} value
  4744. */
  4745. attr: function (key, value) {
  4746. if (typeof key === 'string') {
  4747. this.attrKV(key, value);
  4748. }
  4749. else if (isObject$1(key)) {
  4750. for (var name in key) {
  4751. if (key.hasOwnProperty(name)) {
  4752. this.attrKV(name, key[name]);
  4753. }
  4754. }
  4755. }
  4756. this.dirty(false);
  4757. return this;
  4758. },
  4759. /**
  4760. * @param {module:zrender/graphic/Path} clipPath
  4761. */
  4762. setClipPath: function (clipPath) {
  4763. var zr = this.__zr;
  4764. if (zr) {
  4765. clipPath.addSelfToZr(zr);
  4766. }
  4767. // Remove previous clip path
  4768. if (this.clipPath && this.clipPath !== clipPath) {
  4769. this.removeClipPath();
  4770. }
  4771. this.clipPath = clipPath;
  4772. clipPath.__zr = zr;
  4773. clipPath.__clipTarget = this;
  4774. this.dirty(false);
  4775. },
  4776. /**
  4777. */
  4778. removeClipPath: function () {
  4779. var clipPath = this.clipPath;
  4780. if (clipPath) {
  4781. if (clipPath.__zr) {
  4782. clipPath.removeSelfFromZr(clipPath.__zr);
  4783. }
  4784. clipPath.__zr = null;
  4785. clipPath.__clipTarget = null;
  4786. this.clipPath = null;
  4787. this.dirty(false);
  4788. }
  4789. },
  4790. /**
  4791. * Add self from zrender instance.
  4792. * Not recursively because it will be invoked when element added to storage.
  4793. * @param {module:zrender/ZRender} zr
  4794. */
  4795. addSelfToZr: function (zr) {
  4796. this.__zr = zr;
  4797. // 添加动画
  4798. var animators = this.animators;
  4799. if (animators) {
  4800. for (var i = 0; i < animators.length; i++) {
  4801. zr.animation.addAnimator(animators[i]);
  4802. }
  4803. }
  4804. if (this.clipPath) {
  4805. this.clipPath.addSelfToZr(zr);
  4806. }
  4807. },
  4808. /**
  4809. * Remove self from zrender instance.
  4810. * Not recursively because it will be invoked when element added to storage.
  4811. * @param {module:zrender/ZRender} zr
  4812. */
  4813. removeSelfFromZr: function (zr) {
  4814. this.__zr = null;
  4815. // 移除动画
  4816. var animators = this.animators;
  4817. if (animators) {
  4818. for (var i = 0; i < animators.length; i++) {
  4819. zr.animation.removeAnimator(animators[i]);
  4820. }
  4821. }
  4822. if (this.clipPath) {
  4823. this.clipPath.removeSelfFromZr(zr);
  4824. }
  4825. }
  4826. };
  4827. mixin(Element, Animatable);
  4828. mixin(Element, Transformable);
  4829. mixin(Element, Eventful);
  4830. /**
  4831. * @module echarts/core/BoundingRect
  4832. */
  4833. var v2ApplyTransform = applyTransform;
  4834. var mathMin = Math.min;
  4835. var mathMax = Math.max;
  4836. /**
  4837. * @alias module:echarts/core/BoundingRect
  4838. */
  4839. function BoundingRect(x, y, width, height) {
  4840. if (width < 0) {
  4841. x = x + width;
  4842. width = -width;
  4843. }
  4844. if (height < 0) {
  4845. y = y + height;
  4846. height = -height;
  4847. }
  4848. /**
  4849. * @type {number}
  4850. */
  4851. this.x = x;
  4852. /**
  4853. * @type {number}
  4854. */
  4855. this.y = y;
  4856. /**
  4857. * @type {number}
  4858. */
  4859. this.width = width;
  4860. /**
  4861. * @type {number}
  4862. */
  4863. this.height = height;
  4864. }
  4865. BoundingRect.prototype = {
  4866. constructor: BoundingRect,
  4867. /**
  4868. * @param {module:echarts/core/BoundingRect} other
  4869. */
  4870. union: function (other) {
  4871. var x = mathMin(other.x, this.x);
  4872. var y = mathMin(other.y, this.y);
  4873. this.width = mathMax(
  4874. other.x + other.width,
  4875. this.x + this.width
  4876. ) - x;
  4877. this.height = mathMax(
  4878. other.y + other.height,
  4879. this.y + this.height
  4880. ) - y;
  4881. this.x = x;
  4882. this.y = y;
  4883. },
  4884. /**
  4885. * @param {Array.<number>} m
  4886. * @methods
  4887. */
  4888. applyTransform: (function () {
  4889. var lt = [];
  4890. var rb = [];
  4891. var lb = [];
  4892. var rt = [];
  4893. return function (m) {
  4894. // In case usage like this
  4895. // el.getBoundingRect().applyTransform(el.transform)
  4896. // And element has no transform
  4897. if (!m) {
  4898. return;
  4899. }
  4900. lt[0] = lb[0] = this.x;
  4901. lt[1] = rt[1] = this.y;
  4902. rb[0] = rt[0] = this.x + this.width;
  4903. rb[1] = lb[1] = this.y + this.height;
  4904. v2ApplyTransform(lt, lt, m);
  4905. v2ApplyTransform(rb, rb, m);
  4906. v2ApplyTransform(lb, lb, m);
  4907. v2ApplyTransform(rt, rt, m);
  4908. this.x = mathMin(lt[0], rb[0], lb[0], rt[0]);
  4909. this.y = mathMin(lt[1], rb[1], lb[1], rt[1]);
  4910. var maxX = mathMax(lt[0], rb[0], lb[0], rt[0]);
  4911. var maxY = mathMax(lt[1], rb[1], lb[1], rt[1]);
  4912. this.width = maxX - this.x;
  4913. this.height = maxY - this.y;
  4914. };
  4915. })(),
  4916. /**
  4917. * Calculate matrix of transforming from self to target rect
  4918. * @param {module:zrender/core/BoundingRect} b
  4919. * @return {Array.<number>}
  4920. */
  4921. calculateTransform: function (b) {
  4922. var a = this;
  4923. var sx = b.width / a.width;
  4924. var sy = b.height / a.height;
  4925. var m = create$1();
  4926. // 矩阵右乘
  4927. translate(m, m, [-a.x, -a.y]);
  4928. scale$1(m, m, [sx, sy]);
  4929. translate(m, m, [b.x, b.y]);
  4930. return m;
  4931. },
  4932. /**
  4933. * @param {(module:echarts/core/BoundingRect|Object)} b
  4934. * @return {boolean}
  4935. */
  4936. intersect: function (b) {
  4937. if (!b) {
  4938. return false;
  4939. }
  4940. if (!(b instanceof BoundingRect)) {
  4941. // Normalize negative width/height.
  4942. b = BoundingRect.create(b);
  4943. }
  4944. var a = this;
  4945. var ax0 = a.x;
  4946. var ax1 = a.x + a.width;
  4947. var ay0 = a.y;
  4948. var ay1 = a.y + a.height;
  4949. var bx0 = b.x;
  4950. var bx1 = b.x + b.width;
  4951. var by0 = b.y;
  4952. var by1 = b.y + b.height;
  4953. return !(ax1 < bx0 || bx1 < ax0 || ay1 < by0 || by1 < ay0);
  4954. },
  4955. contain: function (x, y) {
  4956. var rect = this;
  4957. return x >= rect.x
  4958. && x <= (rect.x + rect.width)
  4959. && y >= rect.y
  4960. && y <= (rect.y + rect.height);
  4961. },
  4962. /**
  4963. * @return {module:echarts/core/BoundingRect}
  4964. */
  4965. clone: function () {
  4966. return new BoundingRect(this.x, this.y, this.width, this.height);
  4967. },
  4968. /**
  4969. * Copy from another rect
  4970. */
  4971. copy: function (other) {
  4972. this.x = other.x;
  4973. this.y = other.y;
  4974. this.width = other.width;
  4975. this.height = other.height;
  4976. },
  4977. plain: function () {
  4978. return {
  4979. x: this.x,
  4980. y: this.y,
  4981. width: this.width,
  4982. height: this.height
  4983. };
  4984. }
  4985. };
  4986. /**
  4987. * @param {Object|module:zrender/core/BoundingRect} rect
  4988. * @param {number} rect.x
  4989. * @param {number} rect.y
  4990. * @param {number} rect.width
  4991. * @param {number} rect.height
  4992. * @return {module:zrender/core/BoundingRect}
  4993. */
  4994. BoundingRect.create = function (rect) {
  4995. return new BoundingRect(rect.x, rect.y, rect.width, rect.height);
  4996. };
  4997. /**
  4998. * Group是一个容器,可以插入子节点,Group的变换也会被应用到子节点上
  4999. * @module zrender/graphic/Group
  5000. * @example
  5001. * var Group = require('zrender/container/Group');
  5002. * var Circle = require('zrender/graphic/shape/Circle');
  5003. * var g = new Group();
  5004. * g.position[0] = 100;
  5005. * g.position[1] = 100;
  5006. * g.add(new Circle({
  5007. * style: {
  5008. * x: 100,
  5009. * y: 100,
  5010. * r: 20,
  5011. * }
  5012. * }));
  5013. * zr.add(g);
  5014. */
  5015. /**
  5016. * @alias module:zrender/graphic/Group
  5017. * @constructor
  5018. * @extends module:zrender/mixin/Transformable
  5019. * @extends module:zrender/mixin/Eventful
  5020. */
  5021. var Group = function (opts) {
  5022. opts = opts || {};
  5023. Element.call(this, opts);
  5024. for (var key in opts) {
  5025. if (opts.hasOwnProperty(key)) {
  5026. this[key] = opts[key];
  5027. }
  5028. }
  5029. this._children = [];
  5030. this.__storage = null;
  5031. this.__dirty = true;
  5032. };
  5033. Group.prototype = {
  5034. constructor: Group,
  5035. isGroup: true,
  5036. /**
  5037. * @type {string}
  5038. */
  5039. type: 'group',
  5040. /**
  5041. * 所有子孙元素是否响应鼠标事件
  5042. * @name module:/zrender/container/Group#silent
  5043. * @type {boolean}
  5044. * @default false
  5045. */
  5046. silent: false,
  5047. /**
  5048. * @return {Array.<module:zrender/Element>}
  5049. */
  5050. children: function () {
  5051. return this._children.slice();
  5052. },
  5053. /**
  5054. * 获取指定 index 的儿子节点
  5055. * @param {number} idx
  5056. * @return {module:zrender/Element}
  5057. */
  5058. childAt: function (idx) {
  5059. return this._children[idx];
  5060. },
  5061. /**
  5062. * 获取指定名字的儿子节点
  5063. * @param {string} name
  5064. * @return {module:zrender/Element}
  5065. */
  5066. childOfName: function (name) {
  5067. var children = this._children;
  5068. for (var i = 0; i < children.length; i++) {
  5069. if (children[i].name === name) {
  5070. return children[i];
  5071. }
  5072. }
  5073. },
  5074. /**
  5075. * @return {number}
  5076. */
  5077. childCount: function () {
  5078. return this._children.length;
  5079. },
  5080. /**
  5081. * 添加子节点到最后
  5082. * @param {module:zrender/Element} child
  5083. */
  5084. add: function (child) {
  5085. if (child && child !== this && child.parent !== this) {
  5086. this._children.push(child);
  5087. this._doAdd(child);
  5088. }
  5089. return this;
  5090. },
  5091. /**
  5092. * 添加子节点在 nextSibling 之前
  5093. * @param {module:zrender/Element} child
  5094. * @param {module:zrender/Element} nextSibling
  5095. */
  5096. addBefore: function (child, nextSibling) {
  5097. if (child && child !== this && child.parent !== this
  5098. && nextSibling && nextSibling.parent === this) {
  5099. var children = this._children;
  5100. var idx = children.indexOf(nextSibling);
  5101. if (idx >= 0) {
  5102. children.splice(idx, 0, child);
  5103. this._doAdd(child);
  5104. }
  5105. }
  5106. return this;
  5107. },
  5108. _doAdd: function (child) {
  5109. if (child.parent) {
  5110. child.parent.remove(child);
  5111. }
  5112. child.parent = this;
  5113. var storage = this.__storage;
  5114. var zr = this.__zr;
  5115. if (storage && storage !== child.__storage) {
  5116. storage.addToStorage(child);
  5117. if (child instanceof Group) {
  5118. child.addChildrenToStorage(storage);
  5119. }
  5120. }
  5121. zr && zr.refresh();
  5122. },
  5123. /**
  5124. * 移除子节点
  5125. * @param {module:zrender/Element} child
  5126. */
  5127. remove: function (child) {
  5128. var zr = this.__zr;
  5129. var storage = this.__storage;
  5130. var children = this._children;
  5131. var idx = indexOf(children, child);
  5132. if (idx < 0) {
  5133. return this;
  5134. }
  5135. children.splice(idx, 1);
  5136. child.parent = null;
  5137. if (storage) {
  5138. storage.delFromStorage(child);
  5139. if (child instanceof Group) {
  5140. child.delChildrenFromStorage(storage);
  5141. }
  5142. }
  5143. zr && zr.refresh();
  5144. return this;
  5145. },
  5146. /**
  5147. * 移除所有子节点
  5148. */
  5149. removeAll: function () {
  5150. var children = this._children;
  5151. var storage = this.__storage;
  5152. var child;
  5153. var i;
  5154. for (i = 0; i < children.length; i++) {
  5155. child = children[i];
  5156. if (storage) {
  5157. storage.delFromStorage(child);
  5158. if (child instanceof Group) {
  5159. child.delChildrenFromStorage(storage);
  5160. }
  5161. }
  5162. child.parent = null;
  5163. }
  5164. children.length = 0;
  5165. return this;
  5166. },
  5167. /**
  5168. * 遍历所有子节点
  5169. * @param {Function} cb
  5170. * @param {} context
  5171. */
  5172. eachChild: function (cb, context) {
  5173. var children = this._children;
  5174. for (var i = 0; i < children.length; i++) {
  5175. var child = children[i];
  5176. cb.call(context, child, i);
  5177. }
  5178. return this;
  5179. },
  5180. /**
  5181. * 深度优先遍历所有子孙节点
  5182. * @param {Function} cb
  5183. * @param {} context
  5184. */
  5185. traverse: function (cb, context) {
  5186. for (var i = 0; i < this._children.length; i++) {
  5187. var child = this._children[i];
  5188. cb.call(context, child);
  5189. if (child.type === 'group') {
  5190. child.traverse(cb, context);
  5191. }
  5192. }
  5193. return this;
  5194. },
  5195. addChildrenToStorage: function (storage) {
  5196. for (var i = 0; i < this._children.length; i++) {
  5197. var child = this._children[i];
  5198. storage.addToStorage(child);
  5199. if (child instanceof Group) {
  5200. child.addChildrenToStorage(storage);
  5201. }
  5202. }
  5203. },
  5204. delChildrenFromStorage: function (storage) {
  5205. for (var i = 0; i < this._children.length; i++) {
  5206. var child = this._children[i];
  5207. storage.delFromStorage(child);
  5208. if (child instanceof Group) {
  5209. child.delChildrenFromStorage(storage);
  5210. }
  5211. }
  5212. },
  5213. dirty: function () {
  5214. this.__dirty = true;
  5215. this.__zr && this.__zr.refresh();
  5216. return this;
  5217. },
  5218. /**
  5219. * @return {module:zrender/core/BoundingRect}
  5220. */
  5221. getBoundingRect: function (includeChildren) {
  5222. // TODO Caching
  5223. var rect = null;
  5224. var tmpRect = new BoundingRect(0, 0, 0, 0);
  5225. var children = includeChildren || this._children;
  5226. var tmpMat = [];
  5227. for (var i = 0; i < children.length; i++) {
  5228. var child = children[i];
  5229. if (child.ignore || child.invisible) {
  5230. continue;
  5231. }
  5232. var childRect = child.getBoundingRect();
  5233. var transform = child.getLocalTransform(tmpMat);
  5234. // TODO
  5235. // The boundingRect cacluated by transforming original
  5236. // rect may be bigger than the actual bundingRect when rotation
  5237. // is used. (Consider a circle rotated aginst its center, where
  5238. // the actual boundingRect should be the same as that not be
  5239. // rotated.) But we can not find better approach to calculate
  5240. // actual boundingRect yet, considering performance.
  5241. if (transform) {
  5242. tmpRect.copy(childRect);
  5243. tmpRect.applyTransform(transform);
  5244. rect = rect || tmpRect.clone();
  5245. rect.union(tmpRect);
  5246. }
  5247. else {
  5248. rect = rect || childRect.clone();
  5249. rect.union(childRect);
  5250. }
  5251. }
  5252. return rect || tmpRect;
  5253. }
  5254. };
  5255. inherits(Group, Element);
  5256. // https://github.com/mziccard/node-timsort
  5257. var DEFAULT_MIN_MERGE = 32;
  5258. var DEFAULT_MIN_GALLOPING = 7;
  5259. function minRunLength(n) {
  5260. var r = 0;
  5261. while (n >= DEFAULT_MIN_MERGE) {
  5262. r |= n & 1;
  5263. n >>= 1;
  5264. }
  5265. return n + r;
  5266. }
  5267. function makeAscendingRun(array, lo, hi, compare) {
  5268. var runHi = lo + 1;
  5269. if (runHi === hi) {
  5270. return 1;
  5271. }
  5272. if (compare(array[runHi++], array[lo]) < 0) {
  5273. while (runHi < hi && compare(array[runHi], array[runHi - 1]) < 0) {
  5274. runHi++;
  5275. }
  5276. reverseRun(array, lo, runHi);
  5277. }
  5278. else {
  5279. while (runHi < hi && compare(array[runHi], array[runHi - 1]) >= 0) {
  5280. runHi++;
  5281. }
  5282. }
  5283. return runHi - lo;
  5284. }
  5285. function reverseRun(array, lo, hi) {
  5286. hi--;
  5287. while (lo < hi) {
  5288. var t = array[lo];
  5289. array[lo++] = array[hi];
  5290. array[hi--] = t;
  5291. }
  5292. }
  5293. function binaryInsertionSort(array, lo, hi, start, compare) {
  5294. if (start === lo) {
  5295. start++;
  5296. }
  5297. for (; start < hi; start++) {
  5298. var pivot = array[start];
  5299. var left = lo;
  5300. var right = start;
  5301. var mid;
  5302. while (left < right) {
  5303. mid = left + right >>> 1;
  5304. if (compare(pivot, array[mid]) < 0) {
  5305. right = mid;
  5306. }
  5307. else {
  5308. left = mid + 1;
  5309. }
  5310. }
  5311. var n = start - left;
  5312. switch (n) {
  5313. case 3:
  5314. array[left + 3] = array[left + 2];
  5315. case 2:
  5316. array[left + 2] = array[left + 1];
  5317. case 1:
  5318. array[left + 1] = array[left];
  5319. break;
  5320. default:
  5321. while (n > 0) {
  5322. array[left + n] = array[left + n - 1];
  5323. n--;
  5324. }
  5325. }
  5326. array[left] = pivot;
  5327. }
  5328. }
  5329. function gallopLeft(value, array, start, length, hint, compare) {
  5330. var lastOffset = 0;
  5331. var maxOffset = 0;
  5332. var offset = 1;
  5333. if (compare(value, array[start + hint]) > 0) {
  5334. maxOffset = length - hint;
  5335. while (offset < maxOffset && compare(value, array[start + hint + offset]) > 0) {
  5336. lastOffset = offset;
  5337. offset = (offset << 1) + 1;
  5338. if (offset <= 0) {
  5339. offset = maxOffset;
  5340. }
  5341. }
  5342. if (offset > maxOffset) {
  5343. offset = maxOffset;
  5344. }
  5345. lastOffset += hint;
  5346. offset += hint;
  5347. }
  5348. else {
  5349. maxOffset = hint + 1;
  5350. while (offset < maxOffset && compare(value, array[start + hint - offset]) <= 0) {
  5351. lastOffset = offset;
  5352. offset = (offset << 1) + 1;
  5353. if (offset <= 0) {
  5354. offset = maxOffset;
  5355. }
  5356. }
  5357. if (offset > maxOffset) {
  5358. offset = maxOffset;
  5359. }
  5360. var tmp = lastOffset;
  5361. lastOffset = hint - offset;
  5362. offset = hint - tmp;
  5363. }
  5364. lastOffset++;
  5365. while (lastOffset < offset) {
  5366. var m = lastOffset + (offset - lastOffset >>> 1);
  5367. if (compare(value, array[start + m]) > 0) {
  5368. lastOffset = m + 1;
  5369. }
  5370. else {
  5371. offset = m;
  5372. }
  5373. }
  5374. return offset;
  5375. }
  5376. function gallopRight(value, array, start, length, hint, compare) {
  5377. var lastOffset = 0;
  5378. var maxOffset = 0;
  5379. var offset = 1;
  5380. if (compare(value, array[start + hint]) < 0) {
  5381. maxOffset = hint + 1;
  5382. while (offset < maxOffset && compare(value, array[start + hint - offset]) < 0) {
  5383. lastOffset = offset;
  5384. offset = (offset << 1) + 1;
  5385. if (offset <= 0) {
  5386. offset = maxOffset;
  5387. }
  5388. }
  5389. if (offset > maxOffset) {
  5390. offset = maxOffset;
  5391. }
  5392. var tmp = lastOffset;
  5393. lastOffset = hint - offset;
  5394. offset = hint - tmp;
  5395. }
  5396. else {
  5397. maxOffset = length - hint;
  5398. while (offset < maxOffset && compare(value, array[start + hint + offset]) >= 0) {
  5399. lastOffset = offset;
  5400. offset = (offset << 1) + 1;
  5401. if (offset <= 0) {
  5402. offset = maxOffset;
  5403. }
  5404. }
  5405. if (offset > maxOffset) {
  5406. offset = maxOffset;
  5407. }
  5408. lastOffset += hint;
  5409. offset += hint;
  5410. }
  5411. lastOffset++;
  5412. while (lastOffset < offset) {
  5413. var m = lastOffset + (offset - lastOffset >>> 1);
  5414. if (compare(value, array[start + m]) < 0) {
  5415. offset = m;
  5416. }
  5417. else {
  5418. lastOffset = m + 1;
  5419. }
  5420. }
  5421. return offset;
  5422. }
  5423. function TimSort(array, compare) {
  5424. var minGallop = DEFAULT_MIN_GALLOPING;
  5425. var runStart;
  5426. var runLength;
  5427. var stackSize = 0;
  5428. var tmp = [];
  5429. runStart = [];
  5430. runLength = [];
  5431. function pushRun(_runStart, _runLength) {
  5432. runStart[stackSize] = _runStart;
  5433. runLength[stackSize] = _runLength;
  5434. stackSize += 1;
  5435. }
  5436. function mergeRuns() {
  5437. while (stackSize > 1) {
  5438. var n = stackSize - 2;
  5439. if (n >= 1 && runLength[n - 1] <= runLength[n] + runLength[n + 1] || n >= 2 && runLength[n - 2] <= runLength[n] + runLength[n - 1]) {
  5440. if (runLength[n - 1] < runLength[n + 1]) {
  5441. n--;
  5442. }
  5443. }
  5444. else if (runLength[n] > runLength[n + 1]) {
  5445. break;
  5446. }
  5447. mergeAt(n);
  5448. }
  5449. }
  5450. function forceMergeRuns() {
  5451. while (stackSize > 1) {
  5452. var n = stackSize - 2;
  5453. if (n > 0 && runLength[n - 1] < runLength[n + 1]) {
  5454. n--;
  5455. }
  5456. mergeAt(n);
  5457. }
  5458. }
  5459. function mergeAt(i) {
  5460. var start1 = runStart[i];
  5461. var length1 = runLength[i];
  5462. var start2 = runStart[i + 1];
  5463. var length2 = runLength[i + 1];
  5464. runLength[i] = length1 + length2;
  5465. if (i === stackSize - 3) {
  5466. runStart[i + 1] = runStart[i + 2];
  5467. runLength[i + 1] = runLength[i + 2];
  5468. }
  5469. stackSize--;
  5470. var k = gallopRight(array[start2], array, start1, length1, 0, compare);
  5471. start1 += k;
  5472. length1 -= k;
  5473. if (length1 === 0) {
  5474. return;
  5475. }
  5476. length2 = gallopLeft(array[start1 + length1 - 1], array, start2, length2, length2 - 1, compare);
  5477. if (length2 === 0) {
  5478. return;
  5479. }
  5480. if (length1 <= length2) {
  5481. mergeLow(start1, length1, start2, length2);
  5482. }
  5483. else {
  5484. mergeHigh(start1, length1, start2, length2);
  5485. }
  5486. }
  5487. function mergeLow(start1, length1, start2, length2) {
  5488. var i = 0;
  5489. for (i = 0; i < length1; i++) {
  5490. tmp[i] = array[start1 + i];
  5491. }
  5492. var cursor1 = 0;
  5493. var cursor2 = start2;
  5494. var dest = start1;
  5495. array[dest++] = array[cursor2++];
  5496. if (--length2 === 0) {
  5497. for (i = 0; i < length1; i++) {
  5498. array[dest + i] = tmp[cursor1 + i];
  5499. }
  5500. return;
  5501. }
  5502. if (length1 === 1) {
  5503. for (i = 0; i < length2; i++) {
  5504. array[dest + i] = array[cursor2 + i];
  5505. }
  5506. array[dest + length2] = tmp[cursor1];
  5507. return;
  5508. }
  5509. var _minGallop = minGallop;
  5510. var count1, count2, exit;
  5511. while (1) {
  5512. count1 = 0;
  5513. count2 = 0;
  5514. exit = false;
  5515. do {
  5516. if (compare(array[cursor2], tmp[cursor1]) < 0) {
  5517. array[dest++] = array[cursor2++];
  5518. count2++;
  5519. count1 = 0;
  5520. if (--length2 === 0) {
  5521. exit = true;
  5522. break;
  5523. }
  5524. }
  5525. else {
  5526. array[dest++] = tmp[cursor1++];
  5527. count1++;
  5528. count2 = 0;
  5529. if (--length1 === 1) {
  5530. exit = true;
  5531. break;
  5532. }
  5533. }
  5534. } while ((count1 | count2) < _minGallop);
  5535. if (exit) {
  5536. break;
  5537. }
  5538. do {
  5539. count1 = gallopRight(array[cursor2], tmp, cursor1, length1, 0, compare);
  5540. if (count1 !== 0) {
  5541. for (i = 0; i < count1; i++) {
  5542. array[dest + i] = tmp[cursor1 + i];
  5543. }
  5544. dest += count1;
  5545. cursor1 += count1;
  5546. length1 -= count1;
  5547. if (length1 <= 1) {
  5548. exit = true;
  5549. break;
  5550. }
  5551. }
  5552. array[dest++] = array[cursor2++];
  5553. if (--length2 === 0) {
  5554. exit = true;
  5555. break;
  5556. }
  5557. count2 = gallopLeft(tmp[cursor1], array, cursor2, length2, 0, compare);
  5558. if (count2 !== 0) {
  5559. for (i = 0; i < count2; i++) {
  5560. array[dest + i] = array[cursor2 + i];
  5561. }
  5562. dest += count2;
  5563. cursor2 += count2;
  5564. length2 -= count2;
  5565. if (length2 === 0) {
  5566. exit = true;
  5567. break;
  5568. }
  5569. }
  5570. array[dest++] = tmp[cursor1++];
  5571. if (--length1 === 1) {
  5572. exit = true;
  5573. break;
  5574. }
  5575. _minGallop--;
  5576. } while (count1 >= DEFAULT_MIN_GALLOPING || count2 >= DEFAULT_MIN_GALLOPING);
  5577. if (exit) {
  5578. break;
  5579. }
  5580. if (_minGallop < 0) {
  5581. _minGallop = 0;
  5582. }
  5583. _minGallop += 2;
  5584. }
  5585. minGallop = _minGallop;
  5586. minGallop < 1 && (minGallop = 1);
  5587. if (length1 === 1) {
  5588. for (i = 0; i < length2; i++) {
  5589. array[dest + i] = array[cursor2 + i];
  5590. }
  5591. array[dest + length2] = tmp[cursor1];
  5592. }
  5593. else if (length1 === 0) {
  5594. throw new Error();
  5595. // throw new Error('mergeLow preconditions were not respected');
  5596. }
  5597. else {
  5598. for (i = 0; i < length1; i++) {
  5599. array[dest + i] = tmp[cursor1 + i];
  5600. }
  5601. }
  5602. }
  5603. function mergeHigh(start1, length1, start2, length2) {
  5604. var i = 0;
  5605. for (i = 0; i < length2; i++) {
  5606. tmp[i] = array[start2 + i];
  5607. }
  5608. var cursor1 = start1 + length1 - 1;
  5609. var cursor2 = length2 - 1;
  5610. var dest = start2 + length2 - 1;
  5611. var customCursor = 0;
  5612. var customDest = 0;
  5613. array[dest--] = array[cursor1--];
  5614. if (--length1 === 0) {
  5615. customCursor = dest - (length2 - 1);
  5616. for (i = 0; i < length2; i++) {
  5617. array[customCursor + i] = tmp[i];
  5618. }
  5619. return;
  5620. }
  5621. if (length2 === 1) {
  5622. dest -= length1;
  5623. cursor1 -= length1;
  5624. customDest = dest + 1;
  5625. customCursor = cursor1 + 1;
  5626. for (i = length1 - 1; i >= 0; i--) {
  5627. array[customDest + i] = array[customCursor + i];
  5628. }
  5629. array[dest] = tmp[cursor2];
  5630. return;
  5631. }
  5632. var _minGallop = minGallop;
  5633. while (true) {
  5634. var count1 = 0;
  5635. var count2 = 0;
  5636. var exit = false;
  5637. do {
  5638. if (compare(tmp[cursor2], array[cursor1]) < 0) {
  5639. array[dest--] = array[cursor1--];
  5640. count1++;
  5641. count2 = 0;
  5642. if (--length1 === 0) {
  5643. exit = true;
  5644. break;
  5645. }
  5646. }
  5647. else {
  5648. array[dest--] = tmp[cursor2--];
  5649. count2++;
  5650. count1 = 0;
  5651. if (--length2 === 1) {
  5652. exit = true;
  5653. break;
  5654. }
  5655. }
  5656. } while ((count1 | count2) < _minGallop);
  5657. if (exit) {
  5658. break;
  5659. }
  5660. do {
  5661. count1 = length1 - gallopRight(tmp[cursor2], array, start1, length1, length1 - 1, compare);
  5662. if (count1 !== 0) {
  5663. dest -= count1;
  5664. cursor1 -= count1;
  5665. length1 -= count1;
  5666. customDest = dest + 1;
  5667. customCursor = cursor1 + 1;
  5668. for (i = count1 - 1; i >= 0; i--) {
  5669. array[customDest + i] = array[customCursor + i];
  5670. }
  5671. if (length1 === 0) {
  5672. exit = true;
  5673. break;
  5674. }
  5675. }
  5676. array[dest--] = tmp[cursor2--];
  5677. if (--length2 === 1) {
  5678. exit = true;
  5679. break;
  5680. }
  5681. count2 = length2 - gallopLeft(array[cursor1], tmp, 0, length2, length2 - 1, compare);
  5682. if (count2 !== 0) {
  5683. dest -= count2;
  5684. cursor2 -= count2;
  5685. length2 -= count2;
  5686. customDest = dest + 1;
  5687. customCursor = cursor2 + 1;
  5688. for (i = 0; i < count2; i++) {
  5689. array[customDest + i] = tmp[customCursor + i];
  5690. }
  5691. if (length2 <= 1) {
  5692. exit = true;
  5693. break;
  5694. }
  5695. }
  5696. array[dest--] = array[cursor1--];
  5697. if (--length1 === 0) {
  5698. exit = true;
  5699. break;
  5700. }
  5701. _minGallop--;
  5702. } while (count1 >= DEFAULT_MIN_GALLOPING || count2 >= DEFAULT_MIN_GALLOPING);
  5703. if (exit) {
  5704. break;
  5705. }
  5706. if (_minGallop < 0) {
  5707. _minGallop = 0;
  5708. }
  5709. _minGallop += 2;
  5710. }
  5711. minGallop = _minGallop;
  5712. if (minGallop < 1) {
  5713. minGallop = 1;
  5714. }
  5715. if (length2 === 1) {
  5716. dest -= length1;
  5717. cursor1 -= length1;
  5718. customDest = dest + 1;
  5719. customCursor = cursor1 + 1;
  5720. for (i = length1 - 1; i >= 0; i--) {
  5721. array[customDest + i] = array[customCursor + i];
  5722. }
  5723. array[dest] = tmp[cursor2];
  5724. }
  5725. else if (length2 === 0) {
  5726. throw new Error();
  5727. // throw new Error('mergeHigh preconditions were not respected');
  5728. }
  5729. else {
  5730. customCursor = dest - (length2 - 1);
  5731. for (i = 0; i < length2; i++) {
  5732. array[customCursor + i] = tmp[i];
  5733. }
  5734. }
  5735. }
  5736. this.mergeRuns = mergeRuns;
  5737. this.forceMergeRuns = forceMergeRuns;
  5738. this.pushRun = pushRun;
  5739. }
  5740. function sort(array, compare, lo, hi) {
  5741. if (!lo) {
  5742. lo = 0;
  5743. }
  5744. if (!hi) {
  5745. hi = array.length;
  5746. }
  5747. var remaining = hi - lo;
  5748. if (remaining < 2) {
  5749. return;
  5750. }
  5751. var runLength = 0;
  5752. if (remaining < DEFAULT_MIN_MERGE) {
  5753. runLength = makeAscendingRun(array, lo, hi, compare);
  5754. binaryInsertionSort(array, lo, hi, lo + runLength, compare);
  5755. return;
  5756. }
  5757. var ts = new TimSort(array, compare);
  5758. var minRun = minRunLength(remaining);
  5759. do {
  5760. runLength = makeAscendingRun(array, lo, hi, compare);
  5761. if (runLength < minRun) {
  5762. var force = remaining;
  5763. if (force > minRun) {
  5764. force = minRun;
  5765. }
  5766. binaryInsertionSort(array, lo, lo + force, lo + runLength, compare);
  5767. runLength = force;
  5768. }
  5769. ts.pushRun(lo, runLength);
  5770. ts.mergeRuns();
  5771. remaining -= runLength;
  5772. lo += runLength;
  5773. } while (remaining !== 0);
  5774. ts.forceMergeRuns();
  5775. }
  5776. // Use timsort because in most case elements are partially sorted
  5777. // https://jsfiddle.net/pissang/jr4x7mdm/8/
  5778. function shapeCompareFunc(a, b) {
  5779. if (a.zlevel === b.zlevel) {
  5780. if (a.z === b.z) {
  5781. // if (a.z2 === b.z2) {
  5782. // // FIXME Slow has renderidx compare
  5783. // // http://stackoverflow.com/questions/20883421/sorting-in-javascript-should-every-compare-function-have-a-return-0-statement
  5784. // // https://github.com/v8/v8/blob/47cce544a31ed5577ffe2963f67acb4144ee0232/src/js/array.js#L1012
  5785. // return a.__renderidx - b.__renderidx;
  5786. // }
  5787. return a.z2 - b.z2;
  5788. }
  5789. return a.z - b.z;
  5790. }
  5791. return a.zlevel - b.zlevel;
  5792. }
  5793. /**
  5794. * 内容仓库 (M)
  5795. * @alias module:zrender/Storage
  5796. * @constructor
  5797. */
  5798. var Storage = function () { // jshint ignore:line
  5799. this._roots = [];
  5800. this._displayList = [];
  5801. this._displayListLen = 0;
  5802. };
  5803. Storage.prototype = {
  5804. constructor: Storage,
  5805. /**
  5806. * @param {Function} cb
  5807. *
  5808. */
  5809. traverse: function (cb, context) {
  5810. for (var i = 0; i < this._roots.length; i++) {
  5811. this._roots[i].traverse(cb, context);
  5812. }
  5813. },
  5814. /**
  5815. * 返回所有图形的绘制队列
  5816. * @param {boolean} [update=false] 是否在返回前更新该数组
  5817. * @param {boolean} [includeIgnore=false] 是否包含 ignore 的数组, 在 update 为 true 的时候有效
  5818. *
  5819. * 详见{@link module:zrender/graphic/Displayable.prototype.updateDisplayList}
  5820. * @return {Array.<module:zrender/graphic/Displayable>}
  5821. */
  5822. getDisplayList: function (update, includeIgnore) {
  5823. includeIgnore = includeIgnore || false;
  5824. if (update) {
  5825. this.updateDisplayList(includeIgnore);
  5826. }
  5827. return this._displayList;
  5828. },
  5829. /**
  5830. * 更新图形的绘制队列。
  5831. * 每次绘制前都会调用,该方法会先深度优先遍历整个树,更新所有Group和Shape的变换并且把所有可见的Shape保存到数组中,
  5832. * 最后根据绘制的优先级(zlevel > z > 插入顺序)排序得到绘制队列
  5833. * @param {boolean} [includeIgnore=false] 是否包含 ignore 的数组
  5834. */
  5835. updateDisplayList: function (includeIgnore) {
  5836. this._displayListLen = 0;
  5837. var roots = this._roots;
  5838. var displayList = this._displayList;
  5839. for (var i = 0, len = roots.length; i < len; i++) {
  5840. this._updateAndAddDisplayable(roots[i], null, includeIgnore);
  5841. }
  5842. displayList.length = this._displayListLen;
  5843. env$1.canvasSupported && sort(displayList, shapeCompareFunc);
  5844. },
  5845. _updateAndAddDisplayable: function (el, clipPaths, includeIgnore) {
  5846. if (el.ignore && !includeIgnore) {
  5847. return;
  5848. }
  5849. el.beforeUpdate();
  5850. if (el.__dirty) {
  5851. el.update();
  5852. }
  5853. el.afterUpdate();
  5854. var userSetClipPath = el.clipPath;
  5855. if (userSetClipPath) {
  5856. // FIXME 效率影响
  5857. if (clipPaths) {
  5858. clipPaths = clipPaths.slice();
  5859. }
  5860. else {
  5861. clipPaths = [];
  5862. }
  5863. var currentClipPath = userSetClipPath;
  5864. var parentClipPath = el;
  5865. // Recursively add clip path
  5866. while (currentClipPath) {
  5867. // clipPath 的变换是基于使用这个 clipPath 的元素
  5868. currentClipPath.parent = parentClipPath;
  5869. currentClipPath.updateTransform();
  5870. clipPaths.push(currentClipPath);
  5871. parentClipPath = currentClipPath;
  5872. currentClipPath = currentClipPath.clipPath;
  5873. }
  5874. }
  5875. if (el.isGroup) {
  5876. var children = el._children;
  5877. for (var i = 0; i < children.length; i++) {
  5878. var child = children[i];
  5879. // Force to mark as dirty if group is dirty
  5880. // FIXME __dirtyPath ?
  5881. if (el.__dirty) {
  5882. child.__dirty = true;
  5883. }
  5884. this._updateAndAddDisplayable(child, clipPaths, includeIgnore);
  5885. }
  5886. // Mark group clean here
  5887. el.__dirty = false;
  5888. }
  5889. else {
  5890. el.__clipPaths = clipPaths;
  5891. this._displayList[this._displayListLen++] = el;
  5892. }
  5893. },
  5894. /**
  5895. * 添加图形(Shape)或者组(Group)到根节点
  5896. * @param {module:zrender/Element} el
  5897. */
  5898. addRoot: function (el) {
  5899. if (el.__storage === this) {
  5900. return;
  5901. }
  5902. if (el instanceof Group) {
  5903. el.addChildrenToStorage(this);
  5904. }
  5905. this.addToStorage(el);
  5906. this._roots.push(el);
  5907. },
  5908. /**
  5909. * 删除指定的图形(Shape)或者组(Group)
  5910. * @param {string|Array.<string>} [el] 如果为空清空整个Storage
  5911. */
  5912. delRoot: function (el) {
  5913. if (el == null) {
  5914. // 不指定el清空
  5915. for (var i = 0; i < this._roots.length; i++) {
  5916. var root = this._roots[i];
  5917. if (root instanceof Group) {
  5918. root.delChildrenFromStorage(this);
  5919. }
  5920. }
  5921. this._roots = [];
  5922. this._displayList = [];
  5923. this._displayListLen = 0;
  5924. return;
  5925. }
  5926. if (el instanceof Array) {
  5927. for (var i = 0, l = el.length; i < l; i++) {
  5928. this.delRoot(el[i]);
  5929. }
  5930. return;
  5931. }
  5932. var idx = indexOf(this._roots, el);
  5933. if (idx >= 0) {
  5934. this.delFromStorage(el);
  5935. this._roots.splice(idx, 1);
  5936. if (el instanceof Group) {
  5937. el.delChildrenFromStorage(this);
  5938. }
  5939. }
  5940. },
  5941. addToStorage: function (el) {
  5942. if (el) {
  5943. el.__storage = this;
  5944. el.dirty(false);
  5945. }
  5946. return this;
  5947. },
  5948. delFromStorage: function (el) {
  5949. if (el) {
  5950. el.__storage = null;
  5951. }
  5952. return this;
  5953. },
  5954. /**
  5955. * 清空并且释放Storage
  5956. */
  5957. dispose: function () {
  5958. this._renderList =
  5959. this._roots = null;
  5960. },
  5961. displayableSortFunc: shapeCompareFunc
  5962. };
  5963. var SHADOW_PROPS = {
  5964. 'shadowBlur': 1,
  5965. 'shadowOffsetX': 1,
  5966. 'shadowOffsetY': 1,
  5967. 'textShadowBlur': 1,
  5968. 'textShadowOffsetX': 1,
  5969. 'textShadowOffsetY': 1,
  5970. 'textBoxShadowBlur': 1,
  5971. 'textBoxShadowOffsetX': 1,
  5972. 'textBoxShadowOffsetY': 1
  5973. };
  5974. var fixShadow = function (ctx, propName, value) {
  5975. if (SHADOW_PROPS.hasOwnProperty(propName)) {
  5976. return value *= ctx.dpr;
  5977. }
  5978. return value;
  5979. };
  5980. var ContextCachedBy = {
  5981. NONE: 0,
  5982. STYLE_BIND: 1,
  5983. PLAIN_TEXT: 2
  5984. };
  5985. // Avoid confused with 0/false.
  5986. var WILL_BE_RESTORED = 9;
  5987. var STYLE_COMMON_PROPS = [
  5988. ['shadowBlur', 0], ['shadowOffsetX', 0], ['shadowOffsetY', 0], ['shadowColor', '#000'],
  5989. ['lineCap', 'butt'], ['lineJoin', 'miter'], ['miterLimit', 10]
  5990. ];
  5991. // var SHADOW_PROPS = STYLE_COMMON_PROPS.slice(0, 4);
  5992. // var LINE_PROPS = STYLE_COMMON_PROPS.slice(4);
  5993. var Style = function (opts) {
  5994. this.extendFrom(opts, false);
  5995. };
  5996. function createLinearGradient(ctx, obj, rect) {
  5997. var x = obj.x == null ? 0 : obj.x;
  5998. var x2 = obj.x2 == null ? 1 : obj.x2;
  5999. var y = obj.y == null ? 0 : obj.y;
  6000. var y2 = obj.y2 == null ? 0 : obj.y2;
  6001. if (!obj.global) {
  6002. x = x * rect.width + rect.x;
  6003. x2 = x2 * rect.width + rect.x;
  6004. y = y * rect.height + rect.y;
  6005. y2 = y2 * rect.height + rect.y;
  6006. }
  6007. // Fix NaN when rect is Infinity
  6008. x = isNaN(x) ? 0 : x;
  6009. x2 = isNaN(x2) ? 1 : x2;
  6010. y = isNaN(y) ? 0 : y;
  6011. y2 = isNaN(y2) ? 0 : y2;
  6012. var canvasGradient = ctx.createLinearGradient(x, y, x2, y2);
  6013. return canvasGradient;
  6014. }
  6015. function createRadialGradient(ctx, obj, rect) {
  6016. var width = rect.width;
  6017. var height = rect.height;
  6018. var min = Math.min(width, height);
  6019. var x = obj.x == null ? 0.5 : obj.x;
  6020. var y = obj.y == null ? 0.5 : obj.y;
  6021. var r = obj.r == null ? 0.5 : obj.r;
  6022. if (!obj.global) {
  6023. x = x * width + rect.x;
  6024. y = y * height + rect.y;
  6025. r = r * min;
  6026. }
  6027. var canvasGradient = ctx.createRadialGradient(x, y, 0, x, y, r);
  6028. return canvasGradient;
  6029. }
  6030. Style.prototype = {
  6031. constructor: Style,
  6032. /**
  6033. * @type {string}
  6034. */
  6035. fill: '#000',
  6036. /**
  6037. * @type {string}
  6038. */
  6039. stroke: null,
  6040. /**
  6041. * @type {number}
  6042. */
  6043. opacity: 1,
  6044. /**
  6045. * @type {number}
  6046. */
  6047. fillOpacity: null,
  6048. /**
  6049. * @type {number}
  6050. */
  6051. strokeOpacity: null,
  6052. /**
  6053. * `true` is not supported.
  6054. * `false`/`null`/`undefined` are the same.
  6055. * `false` is used to remove lineDash in some
  6056. * case that `null`/`undefined` can not be set.
  6057. * (e.g., emphasis.lineStyle in echarts)
  6058. * @type {Array.<number>|boolean}
  6059. */
  6060. lineDash: null,
  6061. /**
  6062. * @type {number}
  6063. */
  6064. lineDashOffset: 0,
  6065. /**
  6066. * @type {number}
  6067. */
  6068. shadowBlur: 0,
  6069. /**
  6070. * @type {number}
  6071. */
  6072. shadowOffsetX: 0,
  6073. /**
  6074. * @type {number}
  6075. */
  6076. shadowOffsetY: 0,
  6077. /**
  6078. * @type {number}
  6079. */
  6080. lineWidth: 1,
  6081. /**
  6082. * If stroke ignore scale
  6083. * @type {Boolean}
  6084. */
  6085. strokeNoScale: false,
  6086. // Bounding rect text configuration
  6087. // Not affected by element transform
  6088. /**
  6089. * @type {string}
  6090. */
  6091. text: null,
  6092. /**
  6093. * If `fontSize` or `fontFamily` exists, `font` will be reset by
  6094. * `fontSize`, `fontStyle`, `fontWeight`, `fontFamily`.
  6095. * So do not visit it directly in upper application (like echarts),
  6096. * but use `contain/text#makeFont` instead.
  6097. * @type {string}
  6098. */
  6099. font: null,
  6100. /**
  6101. * The same as font. Use font please.
  6102. * @deprecated
  6103. * @type {string}
  6104. */
  6105. textFont: null,
  6106. /**
  6107. * It helps merging respectively, rather than parsing an entire font string.
  6108. * @type {string}
  6109. */
  6110. fontStyle: null,
  6111. /**
  6112. * It helps merging respectively, rather than parsing an entire font string.
  6113. * @type {string}
  6114. */
  6115. fontWeight: null,
  6116. /**
  6117. * It helps merging respectively, rather than parsing an entire font string.
  6118. * Should be 12 but not '12px'.
  6119. * @type {number}
  6120. */
  6121. fontSize: null,
  6122. /**
  6123. * It helps merging respectively, rather than parsing an entire font string.
  6124. * @type {string}
  6125. */
  6126. fontFamily: null,
  6127. /**
  6128. * Reserved for special functinality, like 'hr'.
  6129. * @type {string}
  6130. */
  6131. textTag: null,
  6132. /**
  6133. * @type {string}
  6134. */
  6135. textFill: '#000',
  6136. /**
  6137. * @type {string}
  6138. */
  6139. textStroke: null,
  6140. /**
  6141. * @type {number}
  6142. */
  6143. textWidth: null,
  6144. /**
  6145. * Only for textBackground.
  6146. * @type {number}
  6147. */
  6148. textHeight: null,
  6149. /**
  6150. * textStroke may be set as some color as a default
  6151. * value in upper applicaion, where the default value
  6152. * of textStrokeWidth should be 0 to make sure that
  6153. * user can choose to do not use text stroke.
  6154. * @type {number}
  6155. */
  6156. textStrokeWidth: 0,
  6157. /**
  6158. * @type {number}
  6159. */
  6160. textLineHeight: null,
  6161. /**
  6162. * 'inside', 'left', 'right', 'top', 'bottom'
  6163. * [x, y]
  6164. * Based on x, y of rect.
  6165. * @type {string|Array.<number>}
  6166. * @default 'inside'
  6167. */
  6168. textPosition: 'inside',
  6169. /**
  6170. * If not specified, use the boundingRect of a `displayable`.
  6171. * @type {Object}
  6172. */
  6173. textRect: null,
  6174. /**
  6175. * [x, y]
  6176. * @type {Array.<number>}
  6177. */
  6178. textOffset: null,
  6179. /**
  6180. * @type {string}
  6181. */
  6182. textAlign: null,
  6183. /**
  6184. * @type {string}
  6185. */
  6186. textVerticalAlign: null,
  6187. /**
  6188. * @type {number}
  6189. */
  6190. textDistance: 5,
  6191. /**
  6192. * @type {string}
  6193. */
  6194. textShadowColor: 'transparent',
  6195. /**
  6196. * @type {number}
  6197. */
  6198. textShadowBlur: 0,
  6199. /**
  6200. * @type {number}
  6201. */
  6202. textShadowOffsetX: 0,
  6203. /**
  6204. * @type {number}
  6205. */
  6206. textShadowOffsetY: 0,
  6207. /**
  6208. * @type {string}
  6209. */
  6210. textBoxShadowColor: 'transparent',
  6211. /**
  6212. * @type {number}
  6213. */
  6214. textBoxShadowBlur: 0,
  6215. /**
  6216. * @type {number}
  6217. */
  6218. textBoxShadowOffsetX: 0,
  6219. /**
  6220. * @type {number}
  6221. */
  6222. textBoxShadowOffsetY: 0,
  6223. /**
  6224. * Whether transform text.
  6225. * Only useful in Path and Image element
  6226. * @type {boolean}
  6227. */
  6228. transformText: false,
  6229. /**
  6230. * Text rotate around position of Path or Image
  6231. * Only useful in Path and Image element and transformText is false.
  6232. */
  6233. textRotation: 0,
  6234. /**
  6235. * Text origin of text rotation, like [10, 40].
  6236. * Based on x, y of rect.
  6237. * Useful in label rotation of circular symbol.
  6238. * By default, this origin is textPosition.
  6239. * Can be 'center'.
  6240. * @type {string|Array.<number>}
  6241. */
  6242. textOrigin: null,
  6243. /**
  6244. * @type {string}
  6245. */
  6246. textBackgroundColor: null,
  6247. /**
  6248. * @type {string}
  6249. */
  6250. textBorderColor: null,
  6251. /**
  6252. * @type {number}
  6253. */
  6254. textBorderWidth: 0,
  6255. /**
  6256. * @type {number}
  6257. */
  6258. textBorderRadius: 0,
  6259. /**
  6260. * Can be `2` or `[2, 4]` or `[2, 3, 4, 5]`
  6261. * @type {number|Array.<number>}
  6262. */
  6263. textPadding: null,
  6264. /**
  6265. * Text styles for rich text.
  6266. * @type {Object}
  6267. */
  6268. rich: null,
  6269. /**
  6270. * {outerWidth, outerHeight, ellipsis, placeholder}
  6271. * @type {Object}
  6272. */
  6273. truncate: null,
  6274. /**
  6275. * https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/globalCompositeOperation
  6276. * @type {string}
  6277. */
  6278. blend: null,
  6279. /**
  6280. * @param {CanvasRenderingContext2D} ctx
  6281. */
  6282. bind: function (ctx, el, prevEl) {
  6283. var style = this;
  6284. var prevStyle = prevEl && prevEl.style;
  6285. // If no prevStyle, it means first draw.
  6286. // Only apply cache if the last time cachced by this function.
  6287. var notCheckCache = !prevStyle || ctx.__attrCachedBy !== ContextCachedBy.STYLE_BIND;
  6288. ctx.__attrCachedBy = ContextCachedBy.STYLE_BIND;
  6289. for (var i = 0; i < STYLE_COMMON_PROPS.length; i++) {
  6290. var prop = STYLE_COMMON_PROPS[i];
  6291. var styleName = prop[0];
  6292. if (notCheckCache || style[styleName] !== prevStyle[styleName]) {
  6293. // FIXME Invalid property value will cause style leak from previous element.
  6294. ctx[styleName] =
  6295. fixShadow(ctx, styleName, style[styleName] || prop[1]);
  6296. }
  6297. }
  6298. if ((notCheckCache || style.fill !== prevStyle.fill)) {
  6299. ctx.fillStyle = style.fill;
  6300. }
  6301. if ((notCheckCache || style.stroke !== prevStyle.stroke)) {
  6302. ctx.strokeStyle = style.stroke;
  6303. }
  6304. if ((notCheckCache || style.opacity !== prevStyle.opacity)) {
  6305. ctx.globalAlpha = style.opacity == null ? 1 : style.opacity;
  6306. }
  6307. if ((notCheckCache || style.blend !== prevStyle.blend)) {
  6308. ctx.globalCompositeOperation = style.blend || 'source-over';
  6309. }
  6310. if (this.hasStroke()) {
  6311. var lineWidth = style.lineWidth;
  6312. ctx.lineWidth = lineWidth / (
  6313. (this.strokeNoScale && el && el.getLineScale) ? el.getLineScale() : 1
  6314. );
  6315. }
  6316. },
  6317. hasFill: function () {
  6318. var fill = this.fill;
  6319. return fill != null && fill !== 'none';
  6320. },
  6321. hasStroke: function () {
  6322. var stroke = this.stroke;
  6323. return stroke != null && stroke !== 'none' && this.lineWidth > 0;
  6324. },
  6325. /**
  6326. * Extend from other style
  6327. * @param {zrender/graphic/Style} otherStyle
  6328. * @param {boolean} overwrite true: overwrirte any way.
  6329. * false: overwrite only when !target.hasOwnProperty
  6330. * others: overwrite when property is not null/undefined.
  6331. */
  6332. extendFrom: function (otherStyle, overwrite) {
  6333. if (otherStyle) {
  6334. for (var name in otherStyle) {
  6335. if (otherStyle.hasOwnProperty(name)
  6336. && (overwrite === true
  6337. || (
  6338. overwrite === false
  6339. ? !this.hasOwnProperty(name)
  6340. : otherStyle[name] != null
  6341. )
  6342. )
  6343. ) {
  6344. this[name] = otherStyle[name];
  6345. }
  6346. }
  6347. }
  6348. },
  6349. /**
  6350. * Batch setting style with a given object
  6351. * @param {Object|string} obj
  6352. * @param {*} [obj]
  6353. */
  6354. set: function (obj, value) {
  6355. if (typeof obj === 'string') {
  6356. this[obj] = value;
  6357. }
  6358. else {
  6359. this.extendFrom(obj, true);
  6360. }
  6361. },
  6362. /**
  6363. * Clone
  6364. * @return {zrender/graphic/Style} [description]
  6365. */
  6366. clone: function () {
  6367. var newStyle = new this.constructor();
  6368. newStyle.extendFrom(this, true);
  6369. return newStyle;
  6370. },
  6371. getGradient: function (ctx, obj, rect) {
  6372. var method = obj.type === 'radial' ? createRadialGradient : createLinearGradient;
  6373. var canvasGradient = method(ctx, obj, rect);
  6374. var colorStops = obj.colorStops;
  6375. for (var i = 0; i < colorStops.length; i++) {
  6376. canvasGradient.addColorStop(
  6377. colorStops[i].offset, colorStops[i].color
  6378. );
  6379. }
  6380. return canvasGradient;
  6381. }
  6382. };
  6383. var styleProto = Style.prototype;
  6384. for (var i = 0; i < STYLE_COMMON_PROPS.length; i++) {
  6385. var prop = STYLE_COMMON_PROPS[i];
  6386. if (!(prop[0] in styleProto)) {
  6387. styleProto[prop[0]] = prop[1];
  6388. }
  6389. }
  6390. // Provide for others
  6391. Style.getGradient = styleProto.getGradient;
  6392. var Pattern = function (image, repeat) {
  6393. // Should do nothing more in this constructor. Because gradient can be
  6394. // declard by `color: {image: ...}`, where this constructor will not be called.
  6395. this.image = image;
  6396. this.repeat = repeat;
  6397. // Can be cloned
  6398. this.type = 'pattern';
  6399. };
  6400. Pattern.prototype.getCanvasPattern = function (ctx) {
  6401. return ctx.createPattern(this.image, this.repeat || 'repeat');
  6402. };
  6403. /**
  6404. * @module zrender/Layer
  6405. * @author pissang(https://www.github.com/pissang)
  6406. */
  6407. function returnFalse() {
  6408. return false;
  6409. }
  6410. /**
  6411. * 创建dom
  6412. *
  6413. * @inner
  6414. * @param {string} id dom id 待用
  6415. * @param {Painter} painter painter instance
  6416. * @param {number} number
  6417. */
  6418. function createDom(id, painter, dpr) {
  6419. var newDom = createCanvas();
  6420. var width = painter.getWidth();
  6421. var height = painter.getHeight();
  6422. var newDomStyle = newDom.style;
  6423. if (newDomStyle) { // In node or some other non-browser environment
  6424. newDomStyle.position = 'absolute';
  6425. newDomStyle.left = 0;
  6426. newDomStyle.top = 0;
  6427. newDomStyle.width = width + 'px';
  6428. newDomStyle.height = height + 'px';
  6429. newDom.setAttribute('data-zr-dom-id', id);
  6430. }
  6431. newDom.width = width * dpr;
  6432. newDom.height = height * dpr;
  6433. return newDom;
  6434. }
  6435. /**
  6436. * @alias module:zrender/Layer
  6437. * @constructor
  6438. * @extends module:zrender/mixin/Transformable
  6439. * @param {string} id
  6440. * @param {module:zrender/Painter} painter
  6441. * @param {number} [dpr]
  6442. */
  6443. var Layer = function (id, painter, dpr) {
  6444. var dom;
  6445. dpr = dpr || devicePixelRatio;
  6446. if (typeof id === 'string') {
  6447. dom = createDom(id, painter, dpr);
  6448. }
  6449. // Not using isDom because in node it will return false
  6450. else if (isObject$1(id)) {
  6451. dom = id;
  6452. id = dom.id;
  6453. }
  6454. this.id = id;
  6455. this.dom = dom;
  6456. var domStyle = dom.style;
  6457. if (domStyle) { // Not in node
  6458. dom.onselectstart = returnFalse; // 避免页面选中的尴尬
  6459. domStyle['-webkit-user-select'] = 'none';
  6460. domStyle['user-select'] = 'none';
  6461. domStyle['-webkit-touch-callout'] = 'none';
  6462. domStyle['-webkit-tap-highlight-color'] = 'rgba(0,0,0,0)';
  6463. domStyle['padding'] = 0;
  6464. domStyle['margin'] = 0;
  6465. domStyle['border-width'] = 0;
  6466. }
  6467. this.domBack = null;
  6468. this.ctxBack = null;
  6469. this.painter = painter;
  6470. this.config = null;
  6471. // Configs
  6472. /**
  6473. * 每次清空画布的颜色
  6474. * @type {string}
  6475. * @default 0
  6476. */
  6477. this.clearColor = 0;
  6478. /**
  6479. * 是否开启动态模糊
  6480. * @type {boolean}
  6481. * @default false
  6482. */
  6483. this.motionBlur = false;
  6484. /**
  6485. * 在开启动态模糊的时候使用,与上一帧混合的alpha值,值越大尾迹越明显
  6486. * @type {number}
  6487. * @default 0.7
  6488. */
  6489. this.lastFrameAlpha = 0.7;
  6490. /**
  6491. * Layer dpr
  6492. * @type {number}
  6493. */
  6494. this.dpr = dpr;
  6495. };
  6496. Layer.prototype = {
  6497. constructor: Layer,
  6498. __dirty: true,
  6499. __used: false,
  6500. __drawIndex: 0,
  6501. __startIndex: 0,
  6502. __endIndex: 0,
  6503. incremental: false,
  6504. getElementCount: function () {
  6505. return this.__endIndex - this.__startIndex;
  6506. },
  6507. initContext: function () {
  6508. this.ctx = this.dom.getContext('2d');
  6509. this.ctx.dpr = this.dpr;
  6510. },
  6511. createBackBuffer: function () {
  6512. var dpr = this.dpr;
  6513. this.domBack = createDom('back-' + this.id, this.painter, dpr);
  6514. this.ctxBack = this.domBack.getContext('2d');
  6515. if (dpr !== 1) {
  6516. this.ctxBack.scale(dpr, dpr);
  6517. }
  6518. },
  6519. /**
  6520. * @param {number} width
  6521. * @param {number} height
  6522. */
  6523. resize: function (width, height) {
  6524. var dpr = this.dpr;
  6525. var dom = this.dom;
  6526. var domStyle = dom.style;
  6527. var domBack = this.domBack;
  6528. if (domStyle) {
  6529. domStyle.width = width + 'px';
  6530. domStyle.height = height + 'px';
  6531. }
  6532. dom.width = width * dpr;
  6533. dom.height = height * dpr;
  6534. if (domBack) {
  6535. domBack.width = width * dpr;
  6536. domBack.height = height * dpr;
  6537. if (dpr !== 1) {
  6538. this.ctxBack.scale(dpr, dpr);
  6539. }
  6540. }
  6541. },
  6542. /**
  6543. * 清空该层画布
  6544. * @param {boolean} [clearAll]=false Clear all with out motion blur
  6545. * @param {Color} [clearColor]
  6546. */
  6547. clear: function (clearAll, clearColor) {
  6548. var dom = this.dom;
  6549. var ctx = this.ctx;
  6550. var width = dom.width;
  6551. var height = dom.height;
  6552. var clearColor = clearColor || this.clearColor;
  6553. var haveMotionBLur = this.motionBlur && !clearAll;
  6554. var lastFrameAlpha = this.lastFrameAlpha;
  6555. var dpr = this.dpr;
  6556. if (haveMotionBLur) {
  6557. if (!this.domBack) {
  6558. this.createBackBuffer();
  6559. }
  6560. this.ctxBack.globalCompositeOperation = 'copy';
  6561. this.ctxBack.drawImage(
  6562. dom, 0, 0,
  6563. width / dpr,
  6564. height / dpr
  6565. );
  6566. }
  6567. ctx.clearRect(0, 0, width, height);
  6568. if (clearColor && clearColor !== 'transparent') {
  6569. var clearColorGradientOrPattern;
  6570. // Gradient
  6571. if (clearColor.colorStops) {
  6572. // Cache canvas gradient
  6573. clearColorGradientOrPattern = clearColor.__canvasGradient || Style.getGradient(ctx, clearColor, {
  6574. x: 0,
  6575. y: 0,
  6576. width: width,
  6577. height: height
  6578. });
  6579. clearColor.__canvasGradient = clearColorGradientOrPattern;
  6580. }
  6581. // Pattern
  6582. else if (clearColor.image) {
  6583. clearColorGradientOrPattern = Pattern.prototype.getCanvasPattern.call(clearColor, ctx);
  6584. }
  6585. ctx.save();
  6586. ctx.fillStyle = clearColorGradientOrPattern || clearColor;
  6587. ctx.fillRect(0, 0, width, height);
  6588. ctx.restore();
  6589. }
  6590. if (haveMotionBLur) {
  6591. var domBack = this.domBack;
  6592. ctx.save();
  6593. ctx.globalAlpha = lastFrameAlpha;
  6594. ctx.drawImage(domBack, 0, 0, width, height);
  6595. ctx.restore();
  6596. }
  6597. }
  6598. };
  6599. var requestAnimationFrame = (
  6600. typeof window !== 'undefined'
  6601. && (
  6602. (window.requestAnimationFrame && window.requestAnimationFrame.bind(window))
  6603. // https://github.com/ecomfe/zrender/issues/189#issuecomment-224919809
  6604. || (window.msRequestAnimationFrame && window.msRequestAnimationFrame.bind(window))
  6605. || window.mozRequestAnimationFrame
  6606. || window.webkitRequestAnimationFrame
  6607. )
  6608. ) || function (func) {
  6609. setTimeout(func, 16);
  6610. };
  6611. var globalImageCache = new LRU(50);
  6612. /**
  6613. * @param {string|HTMLImageElement|HTMLCanvasElement|Canvas} newImageOrSrc
  6614. * @return {HTMLImageElement|HTMLCanvasElement|Canvas} image
  6615. */
  6616. function findExistImage(newImageOrSrc) {
  6617. if (typeof newImageOrSrc === 'string') {
  6618. var cachedImgObj = globalImageCache.get(newImageOrSrc);
  6619. return cachedImgObj && cachedImgObj.image;
  6620. }
  6621. else {
  6622. return newImageOrSrc;
  6623. }
  6624. }
  6625. /**
  6626. * Caution: User should cache loaded images, but not just count on LRU.
  6627. * Consider if required images more than LRU size, will dead loop occur?
  6628. *
  6629. * @param {string|HTMLImageElement|HTMLCanvasElement|Canvas} newImageOrSrc
  6630. * @param {HTMLImageElement|HTMLCanvasElement|Canvas} image Existent image.
  6631. * @param {module:zrender/Element} [hostEl] For calling `dirty`.
  6632. * @param {Function} [cb] params: (image, cbPayload)
  6633. * @param {Object} [cbPayload] Payload on cb calling.
  6634. * @return {HTMLImageElement|HTMLCanvasElement|Canvas} image
  6635. */
  6636. function createOrUpdateImage(newImageOrSrc, image, hostEl, cb, cbPayload) {
  6637. if (!newImageOrSrc) {
  6638. return image;
  6639. }
  6640. else if (typeof newImageOrSrc === 'string') {
  6641. // Image should not be loaded repeatly.
  6642. if ((image && image.__zrImageSrc === newImageOrSrc) || !hostEl) {
  6643. return image;
  6644. }
  6645. // Only when there is no existent image or existent image src
  6646. // is different, this method is responsible for load.
  6647. var cachedImgObj = globalImageCache.get(newImageOrSrc);
  6648. var pendingWrap = {hostEl: hostEl, cb: cb, cbPayload: cbPayload};
  6649. if (cachedImgObj) {
  6650. image = cachedImgObj.image;
  6651. !isImageReady(image) && cachedImgObj.pending.push(pendingWrap);
  6652. }
  6653. else {
  6654. image = new Image();
  6655. image.onload = image.onerror = imageOnLoad;
  6656. globalImageCache.put(
  6657. newImageOrSrc,
  6658. image.__cachedImgObj = {
  6659. image: image,
  6660. pending: [pendingWrap]
  6661. }
  6662. );
  6663. image.src = image.__zrImageSrc = newImageOrSrc;
  6664. }
  6665. return image;
  6666. }
  6667. // newImageOrSrc is an HTMLImageElement or HTMLCanvasElement or Canvas
  6668. else {
  6669. return newImageOrSrc;
  6670. }
  6671. }
  6672. function imageOnLoad() {
  6673. var cachedImgObj = this.__cachedImgObj;
  6674. this.onload = this.onerror = this.__cachedImgObj = null;
  6675. for (var i = 0; i < cachedImgObj.pending.length; i++) {
  6676. var pendingWrap = cachedImgObj.pending[i];
  6677. var cb = pendingWrap.cb;
  6678. cb && cb(this, pendingWrap.cbPayload);
  6679. pendingWrap.hostEl.dirty();
  6680. }
  6681. cachedImgObj.pending.length = 0;
  6682. }
  6683. function isImageReady(image) {
  6684. return image && image.width && image.height;
  6685. }
  6686. var textWidthCache = {};
  6687. var textWidthCacheCounter = 0;
  6688. var TEXT_CACHE_MAX = 5000;
  6689. var STYLE_REG = /\{([a-zA-Z0-9_]+)\|([^}]*)\}/g;
  6690. var DEFAULT_FONT$1 = '12px sans-serif';
  6691. // Avoid assign to an exported variable, for transforming to cjs.
  6692. var methods$1 = {};
  6693. function $override$1(name, fn) {
  6694. methods$1[name] = fn;
  6695. }
  6696. /**
  6697. * @public
  6698. * @param {string} text
  6699. * @param {string} font
  6700. * @return {number} width
  6701. */
  6702. function getWidth(text, font) {
  6703. font = font || DEFAULT_FONT$1;
  6704. var key = text + ':' + font;
  6705. if (textWidthCache[key]) {
  6706. return textWidthCache[key];
  6707. }
  6708. var textLines = (text + '').split('\n');
  6709. var width = 0;
  6710. for (var i = 0, l = textLines.length; i < l; i++) {
  6711. // textContain.measureText may be overrided in SVG or VML
  6712. width = Math.max(measureText(textLines[i], font).width, width);
  6713. }
  6714. if (textWidthCacheCounter > TEXT_CACHE_MAX) {
  6715. textWidthCacheCounter = 0;
  6716. textWidthCache = {};
  6717. }
  6718. textWidthCacheCounter++;
  6719. textWidthCache[key] = width;
  6720. return width;
  6721. }
  6722. /**
  6723. * @public
  6724. * @param {string} text
  6725. * @param {string} font
  6726. * @param {string} [textAlign='left']
  6727. * @param {string} [textVerticalAlign='top']
  6728. * @param {Array.<number>} [textPadding]
  6729. * @param {Object} [rich]
  6730. * @param {Object} [truncate]
  6731. * @return {Object} {x, y, width, height, lineHeight}
  6732. */
  6733. function getBoundingRect(text, font, textAlign, textVerticalAlign, textPadding, textLineHeight, rich, truncate) {
  6734. return rich
  6735. ? getRichTextRect(text, font, textAlign, textVerticalAlign, textPadding, textLineHeight, rich, truncate)
  6736. : getPlainTextRect(text, font, textAlign, textVerticalAlign, textPadding, textLineHeight, truncate);
  6737. }
  6738. function getPlainTextRect(text, font, textAlign, textVerticalAlign, textPadding, textLineHeight, truncate) {
  6739. var contentBlock = parsePlainText(text, font, textPadding, textLineHeight, truncate);
  6740. var outerWidth = getWidth(text, font);
  6741. if (textPadding) {
  6742. outerWidth += textPadding[1] + textPadding[3];
  6743. }
  6744. var outerHeight = contentBlock.outerHeight;
  6745. var x = adjustTextX(0, outerWidth, textAlign);
  6746. var y = adjustTextY(0, outerHeight, textVerticalAlign);
  6747. var rect = new BoundingRect(x, y, outerWidth, outerHeight);
  6748. rect.lineHeight = contentBlock.lineHeight;
  6749. return rect;
  6750. }
  6751. function getRichTextRect(text, font, textAlign, textVerticalAlign, textPadding, textLineHeight, rich, truncate) {
  6752. var contentBlock = parseRichText(text, {
  6753. rich: rich,
  6754. truncate: truncate,
  6755. font: font,
  6756. textAlign: textAlign,
  6757. textPadding: textPadding,
  6758. textLineHeight: textLineHeight
  6759. });
  6760. var outerWidth = contentBlock.outerWidth;
  6761. var outerHeight = contentBlock.outerHeight;
  6762. var x = adjustTextX(0, outerWidth, textAlign);
  6763. var y = adjustTextY(0, outerHeight, textVerticalAlign);
  6764. return new BoundingRect(x, y, outerWidth, outerHeight);
  6765. }
  6766. /**
  6767. * @public
  6768. * @param {number} x
  6769. * @param {number} width
  6770. * @param {string} [textAlign='left']
  6771. * @return {number} Adjusted x.
  6772. */
  6773. function adjustTextX(x, width, textAlign) {
  6774. // FIXME Right to left language
  6775. if (textAlign === 'right') {
  6776. x -= width;
  6777. }
  6778. else if (textAlign === 'center') {
  6779. x -= width / 2;
  6780. }
  6781. return x;
  6782. }
  6783. /**
  6784. * @public
  6785. * @param {number} y
  6786. * @param {number} height
  6787. * @param {string} [textVerticalAlign='top']
  6788. * @return {number} Adjusted y.
  6789. */
  6790. function adjustTextY(y, height, textVerticalAlign) {
  6791. if (textVerticalAlign === 'middle') {
  6792. y -= height / 2;
  6793. }
  6794. else if (textVerticalAlign === 'bottom') {
  6795. y -= height;
  6796. }
  6797. return y;
  6798. }
  6799. /**
  6800. * Follow same interface to `Displayable.prototype.calculateTextPosition`.
  6801. * @public
  6802. * @param {Obejct} [out] Prepared out object. If not input, auto created in the method.
  6803. * @param {module:zrender/graphic/Style} style where `textPosition` and `textDistance` are visited.
  6804. * @param {Object} rect {x, y, width, height} Rect of the host elment, according to which the text positioned.
  6805. * @return {Object} The input `out`. Set: {x, y, textAlign, textVerticalAlign}
  6806. */
  6807. function calculateTextPosition(out, style, rect) {
  6808. var textPosition = style.textPosition;
  6809. var distance = style.textDistance;
  6810. var x = rect.x;
  6811. var y = rect.y;
  6812. var height = rect.height;
  6813. var width = rect.width;
  6814. var halfHeight = height / 2;
  6815. var textAlign = 'left';
  6816. var textVerticalAlign = 'top';
  6817. switch (textPosition) {
  6818. case 'left':
  6819. x -= distance;
  6820. y += halfHeight;
  6821. textAlign = 'right';
  6822. textVerticalAlign = 'middle';
  6823. break;
  6824. case 'right':
  6825. x += distance + width;
  6826. y += halfHeight;
  6827. textVerticalAlign = 'middle';
  6828. break;
  6829. case 'top':
  6830. x += width / 2;
  6831. y -= distance;
  6832. textAlign = 'center';
  6833. textVerticalAlign = 'bottom';
  6834. break;
  6835. case 'bottom':
  6836. x += width / 2;
  6837. y += height + distance;
  6838. textAlign = 'center';
  6839. break;
  6840. case 'inside':
  6841. x += width / 2;
  6842. y += halfHeight;
  6843. textAlign = 'center';
  6844. textVerticalAlign = 'middle';
  6845. break;
  6846. case 'insideLeft':
  6847. x += distance;
  6848. y += halfHeight;
  6849. textVerticalAlign = 'middle';
  6850. break;
  6851. case 'insideRight':
  6852. x += width - distance;
  6853. y += halfHeight;
  6854. textAlign = 'right';
  6855. textVerticalAlign = 'middle';
  6856. break;
  6857. case 'insideTop':
  6858. x += width / 2;
  6859. y += distance;
  6860. textAlign = 'center';
  6861. break;
  6862. case 'insideBottom':
  6863. x += width / 2;
  6864. y += height - distance;
  6865. textAlign = 'center';
  6866. textVerticalAlign = 'bottom';
  6867. break;
  6868. case 'insideTopLeft':
  6869. x += distance;
  6870. y += distance;
  6871. break;
  6872. case 'insideTopRight':
  6873. x += width - distance;
  6874. y += distance;
  6875. textAlign = 'right';
  6876. break;
  6877. case 'insideBottomLeft':
  6878. x += distance;
  6879. y += height - distance;
  6880. textVerticalAlign = 'bottom';
  6881. break;
  6882. case 'insideBottomRight':
  6883. x += width - distance;
  6884. y += height - distance;
  6885. textAlign = 'right';
  6886. textVerticalAlign = 'bottom';
  6887. break;
  6888. }
  6889. out = out || {};
  6890. out.x = x;
  6891. out.y = y;
  6892. out.textAlign = textAlign;
  6893. out.textVerticalAlign = textVerticalAlign;
  6894. return out;
  6895. }
  6896. /**
  6897. * To be removed. But still do not remove in case that some one has imported it.
  6898. * @deprecated
  6899. * @public
  6900. * @param {stirng} textPosition
  6901. * @param {Object} rect {x, y, width, height}
  6902. * @param {number} distance
  6903. * @return {Object} {x, y, textAlign, textVerticalAlign}
  6904. */
  6905. /**
  6906. * Show ellipsis if overflow.
  6907. *
  6908. * @public
  6909. * @param {string} text
  6910. * @param {string} containerWidth
  6911. * @param {string} font
  6912. * @param {number} [ellipsis='...']
  6913. * @param {Object} [options]
  6914. * @param {number} [options.maxIterations=3]
  6915. * @param {number} [options.minChar=0] If truncate result are less
  6916. * then minChar, ellipsis will not show, which is
  6917. * better for user hint in some cases.
  6918. * @param {number} [options.placeholder=''] When all truncated, use the placeholder.
  6919. * @return {string}
  6920. */
  6921. function truncateText(text, containerWidth, font, ellipsis, options) {
  6922. if (!containerWidth) {
  6923. return '';
  6924. }
  6925. var textLines = (text + '').split('\n');
  6926. options = prepareTruncateOptions(containerWidth, font, ellipsis, options);
  6927. // FIXME
  6928. // It is not appropriate that every line has '...' when truncate multiple lines.
  6929. for (var i = 0, len = textLines.length; i < len; i++) {
  6930. textLines[i] = truncateSingleLine(textLines[i], options);
  6931. }
  6932. return textLines.join('\n');
  6933. }
  6934. function prepareTruncateOptions(containerWidth, font, ellipsis, options) {
  6935. options = extend({}, options);
  6936. options.font = font;
  6937. var ellipsis = retrieve2(ellipsis, '...');
  6938. options.maxIterations = retrieve2(options.maxIterations, 2);
  6939. var minChar = options.minChar = retrieve2(options.minChar, 0);
  6940. // FIXME
  6941. // Other languages?
  6942. options.cnCharWidth = getWidth('国', font);
  6943. // FIXME
  6944. // Consider proportional font?
  6945. var ascCharWidth = options.ascCharWidth = getWidth('a', font);
  6946. options.placeholder = retrieve2(options.placeholder, '');
  6947. // Example 1: minChar: 3, text: 'asdfzxcv', truncate result: 'asdf', but not: 'a...'.
  6948. // Example 2: minChar: 3, text: '维度', truncate result: '维', but not: '...'.
  6949. var contentWidth = containerWidth = Math.max(0, containerWidth - 1); // Reserve some gap.
  6950. for (var i = 0; i < minChar && contentWidth >= ascCharWidth; i++) {
  6951. contentWidth -= ascCharWidth;
  6952. }
  6953. var ellipsisWidth = getWidth(ellipsis, font);
  6954. if (ellipsisWidth > contentWidth) {
  6955. ellipsis = '';
  6956. ellipsisWidth = 0;
  6957. }
  6958. contentWidth = containerWidth - ellipsisWidth;
  6959. options.ellipsis = ellipsis;
  6960. options.ellipsisWidth = ellipsisWidth;
  6961. options.contentWidth = contentWidth;
  6962. options.containerWidth = containerWidth;
  6963. return options;
  6964. }
  6965. function truncateSingleLine(textLine, options) {
  6966. var containerWidth = options.containerWidth;
  6967. var font = options.font;
  6968. var contentWidth = options.contentWidth;
  6969. if (!containerWidth) {
  6970. return '';
  6971. }
  6972. var lineWidth = getWidth(textLine, font);
  6973. if (lineWidth <= containerWidth) {
  6974. return textLine;
  6975. }
  6976. for (var j = 0; ; j++) {
  6977. if (lineWidth <= contentWidth || j >= options.maxIterations) {
  6978. textLine += options.ellipsis;
  6979. break;
  6980. }
  6981. var subLength = j === 0
  6982. ? estimateLength(textLine, contentWidth, options.ascCharWidth, options.cnCharWidth)
  6983. : lineWidth > 0
  6984. ? Math.floor(textLine.length * contentWidth / lineWidth)
  6985. : 0;
  6986. textLine = textLine.substr(0, subLength);
  6987. lineWidth = getWidth(textLine, font);
  6988. }
  6989. if (textLine === '') {
  6990. textLine = options.placeholder;
  6991. }
  6992. return textLine;
  6993. }
  6994. function estimateLength(text, contentWidth, ascCharWidth, cnCharWidth) {
  6995. var width = 0;
  6996. var i = 0;
  6997. for (var len = text.length; i < len && width < contentWidth; i++) {
  6998. var charCode = text.charCodeAt(i);
  6999. width += (0 <= charCode && charCode <= 127) ? ascCharWidth : cnCharWidth;
  7000. }
  7001. return i;
  7002. }
  7003. /**
  7004. * @public
  7005. * @param {string} font
  7006. * @return {number} line height
  7007. */
  7008. function getLineHeight(font) {
  7009. // FIXME A rough approach.
  7010. return getWidth('国', font);
  7011. }
  7012. /**
  7013. * @public
  7014. * @param {string} text
  7015. * @param {string} font
  7016. * @return {Object} width
  7017. */
  7018. function measureText(text, font) {
  7019. return methods$1.measureText(text, font);
  7020. }
  7021. // Avoid assign to an exported variable, for transforming to cjs.
  7022. methods$1.measureText = function (text, font) {
  7023. var ctx = getContext();
  7024. ctx.font = font || DEFAULT_FONT$1;
  7025. return ctx.measureText(text);
  7026. };
  7027. /**
  7028. * @public
  7029. * @param {string} text
  7030. * @param {string} font
  7031. * @param {Object} [truncate]
  7032. * @return {Object} block: {lineHeight, lines, height, outerHeight}
  7033. * Notice: for performance, do not calculate outerWidth util needed.
  7034. */
  7035. function parsePlainText(text, font, padding, textLineHeight, truncate) {
  7036. text != null && (text += '');
  7037. var lineHeight = retrieve2(textLineHeight, getLineHeight(font));
  7038. var lines = text ? text.split('\n') : [];
  7039. var height = lines.length * lineHeight;
  7040. var outerHeight = height;
  7041. if (padding) {
  7042. outerHeight += padding[0] + padding[2];
  7043. }
  7044. if (text && truncate) {
  7045. var truncOuterHeight = truncate.outerHeight;
  7046. var truncOuterWidth = truncate.outerWidth;
  7047. if (truncOuterHeight != null && outerHeight > truncOuterHeight) {
  7048. text = '';
  7049. lines = [];
  7050. }
  7051. else if (truncOuterWidth != null) {
  7052. var options = prepareTruncateOptions(
  7053. truncOuterWidth - (padding ? padding[1] + padding[3] : 0),
  7054. font,
  7055. truncate.ellipsis,
  7056. {minChar: truncate.minChar, placeholder: truncate.placeholder}
  7057. );
  7058. // FIXME
  7059. // It is not appropriate that every line has '...' when truncate multiple lines.
  7060. for (var i = 0, len = lines.length; i < len; i++) {
  7061. lines[i] = truncateSingleLine(lines[i], options);
  7062. }
  7063. }
  7064. }
  7065. return {
  7066. lines: lines,
  7067. height: height,
  7068. outerHeight: outerHeight,
  7069. lineHeight: lineHeight
  7070. };
  7071. }
  7072. /**
  7073. * For example: 'some text {a|some text}other text{b|some text}xxx{c|}xxx'
  7074. * Also consider 'bbbb{a|xxx\nzzz}xxxx\naaaa'.
  7075. *
  7076. * @public
  7077. * @param {string} text
  7078. * @param {Object} style
  7079. * @return {Object} block
  7080. * {
  7081. * width,
  7082. * height,
  7083. * lines: [{
  7084. * lineHeight,
  7085. * width,
  7086. * tokens: [[{
  7087. * styleName,
  7088. * text,
  7089. * width, // include textPadding
  7090. * height, // include textPadding
  7091. * textWidth, // pure text width
  7092. * textHeight, // pure text height
  7093. * lineHeihgt,
  7094. * font,
  7095. * textAlign,
  7096. * textVerticalAlign
  7097. * }], [...], ...]
  7098. * }, ...]
  7099. * }
  7100. * If styleName is undefined, it is plain text.
  7101. */
  7102. function parseRichText(text, style) {
  7103. var contentBlock = {lines: [], width: 0, height: 0};
  7104. text != null && (text += '');
  7105. if (!text) {
  7106. return contentBlock;
  7107. }
  7108. var lastIndex = STYLE_REG.lastIndex = 0;
  7109. var result;
  7110. while ((result = STYLE_REG.exec(text)) != null) {
  7111. var matchedIndex = result.index;
  7112. if (matchedIndex > lastIndex) {
  7113. pushTokens(contentBlock, text.substring(lastIndex, matchedIndex));
  7114. }
  7115. pushTokens(contentBlock, result[2], result[1]);
  7116. lastIndex = STYLE_REG.lastIndex;
  7117. }
  7118. if (lastIndex < text.length) {
  7119. pushTokens(contentBlock, text.substring(lastIndex, text.length));
  7120. }
  7121. var lines = contentBlock.lines;
  7122. var contentHeight = 0;
  7123. var contentWidth = 0;
  7124. // For `textWidth: 100%`
  7125. var pendingList = [];
  7126. var stlPadding = style.textPadding;
  7127. var truncate = style.truncate;
  7128. var truncateWidth = truncate && truncate.outerWidth;
  7129. var truncateHeight = truncate && truncate.outerHeight;
  7130. if (stlPadding) {
  7131. truncateWidth != null && (truncateWidth -= stlPadding[1] + stlPadding[3]);
  7132. truncateHeight != null && (truncateHeight -= stlPadding[0] + stlPadding[2]);
  7133. }
  7134. // Calculate layout info of tokens.
  7135. for (var i = 0; i < lines.length; i++) {
  7136. var line = lines[i];
  7137. var lineHeight = 0;
  7138. var lineWidth = 0;
  7139. for (var j = 0; j < line.tokens.length; j++) {
  7140. var token = line.tokens[j];
  7141. var tokenStyle = token.styleName && style.rich[token.styleName] || {};
  7142. // textPadding should not inherit from style.
  7143. var textPadding = token.textPadding = tokenStyle.textPadding;
  7144. // textFont has been asigned to font by `normalizeStyle`.
  7145. var font = token.font = tokenStyle.font || style.font;
  7146. // textHeight can be used when textVerticalAlign is specified in token.
  7147. var tokenHeight = token.textHeight = retrieve2(
  7148. // textHeight should not be inherited, consider it can be specified
  7149. // as box height of the block.
  7150. tokenStyle.textHeight, getLineHeight(font)
  7151. );
  7152. textPadding && (tokenHeight += textPadding[0] + textPadding[2]);
  7153. token.height = tokenHeight;
  7154. token.lineHeight = retrieve3(
  7155. tokenStyle.textLineHeight, style.textLineHeight, tokenHeight
  7156. );
  7157. token.textAlign = tokenStyle && tokenStyle.textAlign || style.textAlign;
  7158. token.textVerticalAlign = tokenStyle && tokenStyle.textVerticalAlign || 'middle';
  7159. if (truncateHeight != null && contentHeight + token.lineHeight > truncateHeight) {
  7160. return {lines: [], width: 0, height: 0};
  7161. }
  7162. token.textWidth = getWidth(token.text, font);
  7163. var tokenWidth = tokenStyle.textWidth;
  7164. var tokenWidthNotSpecified = tokenWidth == null || tokenWidth === 'auto';
  7165. // Percent width, can be `100%`, can be used in drawing separate
  7166. // line when box width is needed to be auto.
  7167. if (typeof tokenWidth === 'string' && tokenWidth.charAt(tokenWidth.length - 1) === '%') {
  7168. token.percentWidth = tokenWidth;
  7169. pendingList.push(token);
  7170. tokenWidth = 0;
  7171. // Do not truncate in this case, because there is no user case
  7172. // and it is too complicated.
  7173. }
  7174. else {
  7175. if (tokenWidthNotSpecified) {
  7176. tokenWidth = token.textWidth;
  7177. // FIXME: If image is not loaded and textWidth is not specified, calling
  7178. // `getBoundingRect()` will not get correct result.
  7179. var textBackgroundColor = tokenStyle.textBackgroundColor;
  7180. var bgImg = textBackgroundColor && textBackgroundColor.image;
  7181. // Use cases:
  7182. // (1) If image is not loaded, it will be loaded at render phase and call
  7183. // `dirty()` and `textBackgroundColor.image` will be replaced with the loaded
  7184. // image, and then the right size will be calculated here at the next tick.
  7185. // See `graphic/helper/text.js`.
  7186. // (2) If image loaded, and `textBackgroundColor.image` is image src string,
  7187. // use `imageHelper.findExistImage` to find cached image.
  7188. // `imageHelper.findExistImage` will always be called here before
  7189. // `imageHelper.createOrUpdateImage` in `graphic/helper/text.js#renderRichText`
  7190. // which ensures that image will not be rendered before correct size calcualted.
  7191. if (bgImg) {
  7192. bgImg = findExistImage(bgImg);
  7193. if (isImageReady(bgImg)) {
  7194. tokenWidth = Math.max(tokenWidth, bgImg.width * tokenHeight / bgImg.height);
  7195. }
  7196. }
  7197. }
  7198. var paddingW = textPadding ? textPadding[1] + textPadding[3] : 0;
  7199. tokenWidth += paddingW;
  7200. var remianTruncWidth = truncateWidth != null ? truncateWidth - lineWidth : null;
  7201. if (remianTruncWidth != null && remianTruncWidth < tokenWidth) {
  7202. if (!tokenWidthNotSpecified || remianTruncWidth < paddingW) {
  7203. token.text = '';
  7204. token.textWidth = tokenWidth = 0;
  7205. }
  7206. else {
  7207. token.text = truncateText(
  7208. token.text, remianTruncWidth - paddingW, font, truncate.ellipsis,
  7209. {minChar: truncate.minChar}
  7210. );
  7211. token.textWidth = getWidth(token.text, font);
  7212. tokenWidth = token.textWidth + paddingW;
  7213. }
  7214. }
  7215. }
  7216. lineWidth += (token.width = tokenWidth);
  7217. tokenStyle && (lineHeight = Math.max(lineHeight, token.lineHeight));
  7218. }
  7219. line.width = lineWidth;
  7220. line.lineHeight = lineHeight;
  7221. contentHeight += lineHeight;
  7222. contentWidth = Math.max(contentWidth, lineWidth);
  7223. }
  7224. contentBlock.outerWidth = contentBlock.width = retrieve2(style.textWidth, contentWidth);
  7225. contentBlock.outerHeight = contentBlock.height = retrieve2(style.textHeight, contentHeight);
  7226. if (stlPadding) {
  7227. contentBlock.outerWidth += stlPadding[1] + stlPadding[3];
  7228. contentBlock.outerHeight += stlPadding[0] + stlPadding[2];
  7229. }
  7230. for (var i = 0; i < pendingList.length; i++) {
  7231. var token = pendingList[i];
  7232. var percentWidth = token.percentWidth;
  7233. // Should not base on outerWidth, because token can not be placed out of padding.
  7234. token.width = parseInt(percentWidth, 10) / 100 * contentWidth;
  7235. }
  7236. return contentBlock;
  7237. }
  7238. function pushTokens(block, str, styleName) {
  7239. var isEmptyStr = str === '';
  7240. var strs = str.split('\n');
  7241. var lines = block.lines;
  7242. for (var i = 0; i < strs.length; i++) {
  7243. var text = strs[i];
  7244. var token = {
  7245. styleName: styleName,
  7246. text: text,
  7247. isLineHolder: !text && !isEmptyStr
  7248. };
  7249. // The first token should be appended to the last line.
  7250. if (!i) {
  7251. var tokens = (lines[lines.length - 1] || (lines[0] = {tokens: []})).tokens;
  7252. // Consider cases:
  7253. // (1) ''.split('\n') => ['', '\n', ''], the '' at the first item
  7254. // (which is a placeholder) should be replaced by new token.
  7255. // (2) A image backage, where token likes {a|}.
  7256. // (3) A redundant '' will affect textAlign in line.
  7257. // (4) tokens with the same tplName should not be merged, because
  7258. // they should be displayed in different box (with border and padding).
  7259. var tokensLen = tokens.length;
  7260. (tokensLen === 1 && tokens[0].isLineHolder)
  7261. ? (tokens[0] = token)
  7262. // Consider text is '', only insert when it is the "lineHolder" or
  7263. // "emptyStr". Otherwise a redundant '' will affect textAlign in line.
  7264. : ((text || !tokensLen || isEmptyStr) && tokens.push(token));
  7265. }
  7266. // Other tokens always start a new line.
  7267. else {
  7268. // If there is '', insert it as a placeholder.
  7269. lines.push({tokens: [token]});
  7270. }
  7271. }
  7272. }
  7273. function makeFont(style) {
  7274. // FIXME in node-canvas fontWeight is before fontStyle
  7275. // Use `fontSize` `fontFamily` to check whether font properties are defined.
  7276. var font = (style.fontSize || style.fontFamily) && [
  7277. style.fontStyle,
  7278. style.fontWeight,
  7279. (style.fontSize || 12) + 'px',
  7280. // If font properties are defined, `fontFamily` should not be ignored.
  7281. style.fontFamily || 'sans-serif'
  7282. ].join(' ');
  7283. return font && trim(font) || style.textFont || style.font;
  7284. }
  7285. /**
  7286. * @param {Object} ctx
  7287. * @param {Object} shape
  7288. * @param {number} shape.x
  7289. * @param {number} shape.y
  7290. * @param {number} shape.width
  7291. * @param {number} shape.height
  7292. * @param {number} shape.r
  7293. */
  7294. function buildPath(ctx, shape) {
  7295. var x = shape.x;
  7296. var y = shape.y;
  7297. var width = shape.width;
  7298. var height = shape.height;
  7299. var r = shape.r;
  7300. var r1;
  7301. var r2;
  7302. var r3;
  7303. var r4;
  7304. // Convert width and height to positive for better borderRadius
  7305. if (width < 0) {
  7306. x = x + width;
  7307. width = -width;
  7308. }
  7309. if (height < 0) {
  7310. y = y + height;
  7311. height = -height;
  7312. }
  7313. if (typeof r === 'number') {
  7314. r1 = r2 = r3 = r4 = r;
  7315. }
  7316. else if (r instanceof Array) {
  7317. if (r.length === 1) {
  7318. r1 = r2 = r3 = r4 = r[0];
  7319. }
  7320. else if (r.length === 2) {
  7321. r1 = r3 = r[0];
  7322. r2 = r4 = r[1];
  7323. }
  7324. else if (r.length === 3) {
  7325. r1 = r[0];
  7326. r2 = r4 = r[1];
  7327. r3 = r[2];
  7328. }
  7329. else {
  7330. r1 = r[0];
  7331. r2 = r[1];
  7332. r3 = r[2];
  7333. r4 = r[3];
  7334. }
  7335. }
  7336. else {
  7337. r1 = r2 = r3 = r4 = 0;
  7338. }
  7339. var total;
  7340. if (r1 + r2 > width) {
  7341. total = r1 + r2;
  7342. r1 *= width / total;
  7343. r2 *= width / total;
  7344. }
  7345. if (r3 + r4 > width) {
  7346. total = r3 + r4;
  7347. r3 *= width / total;
  7348. r4 *= width / total;
  7349. }
  7350. if (r2 + r3 > height) {
  7351. total = r2 + r3;
  7352. r2 *= height / total;
  7353. r3 *= height / total;
  7354. }
  7355. if (r1 + r4 > height) {
  7356. total = r1 + r4;
  7357. r1 *= height / total;
  7358. r4 *= height / total;
  7359. }
  7360. ctx.moveTo(x + r1, y);
  7361. ctx.lineTo(x + width - r2, y);
  7362. r2 !== 0 && ctx.arc(x + width - r2, y + r2, r2, -Math.PI / 2, 0);
  7363. ctx.lineTo(x + width, y + height - r3);
  7364. r3 !== 0 && ctx.arc(x + width - r3, y + height - r3, r3, 0, Math.PI / 2);
  7365. ctx.lineTo(x + r4, y + height);
  7366. r4 !== 0 && ctx.arc(x + r4, y + height - r4, r4, Math.PI / 2, Math.PI);
  7367. ctx.lineTo(x, y + r1);
  7368. r1 !== 0 && ctx.arc(x + r1, y + r1, r1, Math.PI, Math.PI * 1.5);
  7369. }
  7370. var DEFAULT_FONT = DEFAULT_FONT$1;
  7371. // TODO: Have not support 'start', 'end' yet.
  7372. var VALID_TEXT_ALIGN = {left: 1, right: 1, center: 1};
  7373. var VALID_TEXT_VERTICAL_ALIGN = {top: 1, bottom: 1, middle: 1};
  7374. // Different from `STYLE_COMMON_PROPS` of `graphic/Style`,
  7375. // the default value of shadowColor is `'transparent'`.
  7376. var SHADOW_STYLE_COMMON_PROPS = [
  7377. ['textShadowBlur', 'shadowBlur', 0],
  7378. ['textShadowOffsetX', 'shadowOffsetX', 0],
  7379. ['textShadowOffsetY', 'shadowOffsetY', 0],
  7380. ['textShadowColor', 'shadowColor', 'transparent']
  7381. ];
  7382. var _tmpTextPositionResult = {};
  7383. var _tmpBoxPositionResult = {};
  7384. /**
  7385. * @param {module:zrender/graphic/Style} style
  7386. * @return {module:zrender/graphic/Style} The input style.
  7387. */
  7388. function normalizeTextStyle(style) {
  7389. normalizeStyle(style);
  7390. each$1(style.rich, normalizeStyle);
  7391. return style;
  7392. }
  7393. function normalizeStyle(style) {
  7394. if (style) {
  7395. style.font = makeFont(style);
  7396. var textAlign = style.textAlign;
  7397. textAlign === 'middle' && (textAlign = 'center');
  7398. style.textAlign = (
  7399. textAlign == null || VALID_TEXT_ALIGN[textAlign]
  7400. ) ? textAlign : 'left';
  7401. // Compatible with textBaseline.
  7402. var textVerticalAlign = style.textVerticalAlign || style.textBaseline;
  7403. textVerticalAlign === 'center' && (textVerticalAlign = 'middle');
  7404. style.textVerticalAlign = (
  7405. textVerticalAlign == null || VALID_TEXT_VERTICAL_ALIGN[textVerticalAlign]
  7406. ) ? textVerticalAlign : 'top';
  7407. var textPadding = style.textPadding;
  7408. if (textPadding) {
  7409. style.textPadding = normalizeCssArray(style.textPadding);
  7410. }
  7411. }
  7412. }
  7413. /**
  7414. * @param {CanvasRenderingContext2D} ctx
  7415. * @param {string} text
  7416. * @param {module:zrender/graphic/Style} style
  7417. * @param {Object|boolean} [rect] {x, y, width, height}
  7418. * If set false, rect text is not used.
  7419. * @param {Element|module:zrender/graphic/helper/constant.WILL_BE_RESTORED} [prevEl] For ctx prop cache.
  7420. */
  7421. function renderText(hostEl, ctx, text, style, rect, prevEl) {
  7422. style.rich
  7423. ? renderRichText(hostEl, ctx, text, style, rect, prevEl)
  7424. : renderPlainText(hostEl, ctx, text, style, rect, prevEl);
  7425. }
  7426. // Avoid setting to ctx according to prevEl if possible for
  7427. // performance in scenarios of large amount text.
  7428. function renderPlainText(hostEl, ctx, text, style, rect, prevEl) {
  7429. 'use strict';
  7430. var needDrawBg = needDrawBackground(style);
  7431. var prevStyle;
  7432. var checkCache = false;
  7433. var cachedByMe = ctx.__attrCachedBy === ContextCachedBy.PLAIN_TEXT;
  7434. // Only take and check cache for `Text` el, but not RectText.
  7435. if (prevEl !== WILL_BE_RESTORED) {
  7436. if (prevEl) {
  7437. prevStyle = prevEl.style;
  7438. checkCache = !needDrawBg && cachedByMe && prevStyle;
  7439. }
  7440. // Prevent from using cache in `Style::bind`, because of the case:
  7441. // ctx property is modified by other properties than `Style::bind`
  7442. // used, and Style::bind is called next.
  7443. ctx.__attrCachedBy = needDrawBg ? ContextCachedBy.NONE : ContextCachedBy.PLAIN_TEXT;
  7444. }
  7445. // Since this will be restored, prevent from using these props to check cache in the next
  7446. // entering of this method. But do not need to clear other cache like `Style::bind`.
  7447. else if (cachedByMe) {
  7448. ctx.__attrCachedBy = ContextCachedBy.NONE;
  7449. }
  7450. var styleFont = style.font || DEFAULT_FONT;
  7451. // PENDING
  7452. // Only `Text` el set `font` and keep it (`RectText` will restore). So theoretically
  7453. // we can make font cache on ctx, which can cache for text el that are discontinuous.
  7454. // But layer save/restore needed to be considered.
  7455. // if (styleFont !== ctx.__fontCache) {
  7456. // ctx.font = styleFont;
  7457. // if (prevEl !== WILL_BE_RESTORED) {
  7458. // ctx.__fontCache = styleFont;
  7459. // }
  7460. // }
  7461. if (!checkCache || styleFont !== (prevStyle.font || DEFAULT_FONT)) {
  7462. ctx.font = styleFont;
  7463. }
  7464. // Use the final font from context-2d, because the final
  7465. // font might not be the style.font when it is illegal.
  7466. // But get `ctx.font` might be time consuming.
  7467. var computedFont = hostEl.__computedFont;
  7468. if (hostEl.__styleFont !== styleFont) {
  7469. hostEl.__styleFont = styleFont;
  7470. computedFont = hostEl.__computedFont = ctx.font;
  7471. }
  7472. var textPadding = style.textPadding;
  7473. var textLineHeight = style.textLineHeight;
  7474. var contentBlock = hostEl.__textCotentBlock;
  7475. if (!contentBlock || hostEl.__dirtyText) {
  7476. contentBlock = hostEl.__textCotentBlock = parsePlainText(
  7477. text, computedFont, textPadding, textLineHeight, style.truncate
  7478. );
  7479. }
  7480. var outerHeight = contentBlock.outerHeight;
  7481. var textLines = contentBlock.lines;
  7482. var lineHeight = contentBlock.lineHeight;
  7483. var boxPos = getBoxPosition(_tmpBoxPositionResult, hostEl, style, rect);
  7484. var baseX = boxPos.baseX;
  7485. var baseY = boxPos.baseY;
  7486. var textAlign = boxPos.textAlign || 'left';
  7487. var textVerticalAlign = boxPos.textVerticalAlign;
  7488. // Origin of textRotation should be the base point of text drawing.
  7489. applyTextRotation(ctx, style, rect, baseX, baseY);
  7490. var boxY = adjustTextY(baseY, outerHeight, textVerticalAlign);
  7491. var textX = baseX;
  7492. var textY = boxY;
  7493. if (needDrawBg || textPadding) {
  7494. // Consider performance, do not call getTextWidth util necessary.
  7495. var textWidth = getWidth(text, computedFont);
  7496. var outerWidth = textWidth;
  7497. textPadding && (outerWidth += textPadding[1] + textPadding[3]);
  7498. var boxX = adjustTextX(baseX, outerWidth, textAlign);
  7499. needDrawBg && drawBackground(hostEl, ctx, style, boxX, boxY, outerWidth, outerHeight);
  7500. if (textPadding) {
  7501. textX = getTextXForPadding(baseX, textAlign, textPadding);
  7502. textY += textPadding[0];
  7503. }
  7504. }
  7505. // Always set textAlign and textBase line, because it is difficute to calculate
  7506. // textAlign from prevEl, and we dont sure whether textAlign will be reset if
  7507. // font set happened.
  7508. ctx.textAlign = textAlign;
  7509. // Force baseline to be "middle". Otherwise, if using "top", the
  7510. // text will offset downward a little bit in font "Microsoft YaHei".
  7511. ctx.textBaseline = 'middle';
  7512. // Set text opacity
  7513. ctx.globalAlpha = style.opacity || 1;
  7514. // Always set shadowBlur and shadowOffset to avoid leak from displayable.
  7515. for (var i = 0; i < SHADOW_STYLE_COMMON_PROPS.length; i++) {
  7516. var propItem = SHADOW_STYLE_COMMON_PROPS[i];
  7517. var styleProp = propItem[0];
  7518. var ctxProp = propItem[1];
  7519. var val = style[styleProp];
  7520. if (!checkCache || val !== prevStyle[styleProp]) {
  7521. ctx[ctxProp] = fixShadow(ctx, ctxProp, val || propItem[2]);
  7522. }
  7523. }
  7524. // `textBaseline` is set as 'middle'.
  7525. textY += lineHeight / 2;
  7526. var textStrokeWidth = style.textStrokeWidth;
  7527. var textStrokeWidthPrev = checkCache ? prevStyle.textStrokeWidth : null;
  7528. var strokeWidthChanged = !checkCache || textStrokeWidth !== textStrokeWidthPrev;
  7529. var strokeChanged = !checkCache || strokeWidthChanged || style.textStroke !== prevStyle.textStroke;
  7530. var textStroke = getStroke(style.textStroke, textStrokeWidth);
  7531. var textFill = getFill(style.textFill);
  7532. if (textStroke) {
  7533. if (strokeWidthChanged) {
  7534. ctx.lineWidth = textStrokeWidth;
  7535. }
  7536. if (strokeChanged) {
  7537. ctx.strokeStyle = textStroke;
  7538. }
  7539. }
  7540. if (textFill) {
  7541. if (!checkCache || style.textFill !== prevStyle.textFill) {
  7542. ctx.fillStyle = textFill;
  7543. }
  7544. }
  7545. // Optimize simply, in most cases only one line exists.
  7546. if (textLines.length === 1) {
  7547. // Fill after stroke so the outline will not cover the main part.
  7548. textStroke && ctx.strokeText(textLines[0], textX, textY);
  7549. textFill && ctx.fillText(textLines[0], textX, textY);
  7550. }
  7551. else {
  7552. for (var i = 0; i < textLines.length; i++) {
  7553. // Fill after stroke so the outline will not cover the main part.
  7554. textStroke && ctx.strokeText(textLines[i], textX, textY);
  7555. textFill && ctx.fillText(textLines[i], textX, textY);
  7556. textY += lineHeight;
  7557. }
  7558. }
  7559. }
  7560. function renderRichText(hostEl, ctx, text, style, rect, prevEl) {
  7561. // Do not do cache for rich text because of the complexity.
  7562. // But `RectText` this will be restored, do not need to clear other cache like `Style::bind`.
  7563. if (prevEl !== WILL_BE_RESTORED) {
  7564. ctx.__attrCachedBy = ContextCachedBy.NONE;
  7565. }
  7566. var contentBlock = hostEl.__textCotentBlock;
  7567. if (!contentBlock || hostEl.__dirtyText) {
  7568. contentBlock = hostEl.__textCotentBlock = parseRichText(text, style);
  7569. }
  7570. drawRichText(hostEl, ctx, contentBlock, style, rect);
  7571. }
  7572. function drawRichText(hostEl, ctx, contentBlock, style, rect) {
  7573. var contentWidth = contentBlock.width;
  7574. var outerWidth = contentBlock.outerWidth;
  7575. var outerHeight = contentBlock.outerHeight;
  7576. var textPadding = style.textPadding;
  7577. var boxPos = getBoxPosition(_tmpBoxPositionResult, hostEl, style, rect);
  7578. var baseX = boxPos.baseX;
  7579. var baseY = boxPos.baseY;
  7580. var textAlign = boxPos.textAlign;
  7581. var textVerticalAlign = boxPos.textVerticalAlign;
  7582. // Origin of textRotation should be the base point of text drawing.
  7583. applyTextRotation(ctx, style, rect, baseX, baseY);
  7584. var boxX = adjustTextX(baseX, outerWidth, textAlign);
  7585. var boxY = adjustTextY(baseY, outerHeight, textVerticalAlign);
  7586. var xLeft = boxX;
  7587. var lineTop = boxY;
  7588. if (textPadding) {
  7589. xLeft += textPadding[3];
  7590. lineTop += textPadding[0];
  7591. }
  7592. var xRight = xLeft + contentWidth;
  7593. needDrawBackground(style) && drawBackground(
  7594. hostEl, ctx, style, boxX, boxY, outerWidth, outerHeight
  7595. );
  7596. for (var i = 0; i < contentBlock.lines.length; i++) {
  7597. var line = contentBlock.lines[i];
  7598. var tokens = line.tokens;
  7599. var tokenCount = tokens.length;
  7600. var lineHeight = line.lineHeight;
  7601. var usedWidth = line.width;
  7602. var leftIndex = 0;
  7603. var lineXLeft = xLeft;
  7604. var lineXRight = xRight;
  7605. var rightIndex = tokenCount - 1;
  7606. var token;
  7607. while (
  7608. leftIndex < tokenCount
  7609. && (token = tokens[leftIndex], !token.textAlign || token.textAlign === 'left')
  7610. ) {
  7611. placeToken(hostEl, ctx, token, style, lineHeight, lineTop, lineXLeft, 'left');
  7612. usedWidth -= token.width;
  7613. lineXLeft += token.width;
  7614. leftIndex++;
  7615. }
  7616. while (
  7617. rightIndex >= 0
  7618. && (token = tokens[rightIndex], token.textAlign === 'right')
  7619. ) {
  7620. placeToken(hostEl, ctx, token, style, lineHeight, lineTop, lineXRight, 'right');
  7621. usedWidth -= token.width;
  7622. lineXRight -= token.width;
  7623. rightIndex--;
  7624. }
  7625. // The other tokens are placed as textAlign 'center' if there is enough space.
  7626. lineXLeft += (contentWidth - (lineXLeft - xLeft) - (xRight - lineXRight) - usedWidth) / 2;
  7627. while (leftIndex <= rightIndex) {
  7628. token = tokens[leftIndex];
  7629. // Consider width specified by user, use 'center' rather than 'left'.
  7630. placeToken(hostEl, ctx, token, style, lineHeight, lineTop, lineXLeft + token.width / 2, 'center');
  7631. lineXLeft += token.width;
  7632. leftIndex++;
  7633. }
  7634. lineTop += lineHeight;
  7635. }
  7636. }
  7637. function applyTextRotation(ctx, style, rect, x, y) {
  7638. // textRotation only apply in RectText.
  7639. if (rect && style.textRotation) {
  7640. var origin = style.textOrigin;
  7641. if (origin === 'center') {
  7642. x = rect.width / 2 + rect.x;
  7643. y = rect.height / 2 + rect.y;
  7644. }
  7645. else if (origin) {
  7646. x = origin[0] + rect.x;
  7647. y = origin[1] + rect.y;
  7648. }
  7649. ctx.translate(x, y);
  7650. // Positive: anticlockwise
  7651. ctx.rotate(-style.textRotation);
  7652. ctx.translate(-x, -y);
  7653. }
  7654. }
  7655. function placeToken(hostEl, ctx, token, style, lineHeight, lineTop, x, textAlign) {
  7656. var tokenStyle = style.rich[token.styleName] || {};
  7657. tokenStyle.text = token.text;
  7658. // 'ctx.textBaseline' is always set as 'middle', for sake of
  7659. // the bias of "Microsoft YaHei".
  7660. var textVerticalAlign = token.textVerticalAlign;
  7661. var y = lineTop + lineHeight / 2;
  7662. if (textVerticalAlign === 'top') {
  7663. y = lineTop + token.height / 2;
  7664. }
  7665. else if (textVerticalAlign === 'bottom') {
  7666. y = lineTop + lineHeight - token.height / 2;
  7667. }
  7668. !token.isLineHolder && needDrawBackground(tokenStyle) && drawBackground(
  7669. hostEl,
  7670. ctx,
  7671. tokenStyle,
  7672. textAlign === 'right'
  7673. ? x - token.width
  7674. : textAlign === 'center'
  7675. ? x - token.width / 2
  7676. : x,
  7677. y - token.height / 2,
  7678. token.width,
  7679. token.height
  7680. );
  7681. var textPadding = token.textPadding;
  7682. if (textPadding) {
  7683. x = getTextXForPadding(x, textAlign, textPadding);
  7684. y -= token.height / 2 - textPadding[2] - token.textHeight / 2;
  7685. }
  7686. setCtx(ctx, 'shadowBlur', retrieve3(tokenStyle.textShadowBlur, style.textShadowBlur, 0));
  7687. setCtx(ctx, 'shadowColor', tokenStyle.textShadowColor || style.textShadowColor || 'transparent');
  7688. setCtx(ctx, 'shadowOffsetX', retrieve3(tokenStyle.textShadowOffsetX, style.textShadowOffsetX, 0));
  7689. setCtx(ctx, 'shadowOffsetY', retrieve3(tokenStyle.textShadowOffsetY, style.textShadowOffsetY, 0));
  7690. setCtx(ctx, 'textAlign', textAlign);
  7691. // Force baseline to be "middle". Otherwise, if using "top", the
  7692. // text will offset downward a little bit in font "Microsoft YaHei".
  7693. setCtx(ctx, 'textBaseline', 'middle');
  7694. setCtx(ctx, 'font', token.font || DEFAULT_FONT);
  7695. var textStroke = getStroke(tokenStyle.textStroke || style.textStroke, textStrokeWidth);
  7696. var textFill = getFill(tokenStyle.textFill || style.textFill);
  7697. var textStrokeWidth = retrieve2(tokenStyle.textStrokeWidth, style.textStrokeWidth);
  7698. // Fill after stroke so the outline will not cover the main part.
  7699. if (textStroke) {
  7700. setCtx(ctx, 'lineWidth', textStrokeWidth);
  7701. setCtx(ctx, 'strokeStyle', textStroke);
  7702. ctx.strokeText(token.text, x, y);
  7703. }
  7704. if (textFill) {
  7705. setCtx(ctx, 'fillStyle', textFill);
  7706. ctx.fillText(token.text, x, y);
  7707. }
  7708. }
  7709. function needDrawBackground(style) {
  7710. return !!(
  7711. style.textBackgroundColor
  7712. || (style.textBorderWidth && style.textBorderColor)
  7713. );
  7714. }
  7715. // style: {textBackgroundColor, textBorderWidth, textBorderColor, textBorderRadius, text}
  7716. // shape: {x, y, width, height}
  7717. function drawBackground(hostEl, ctx, style, x, y, width, height) {
  7718. var textBackgroundColor = style.textBackgroundColor;
  7719. var textBorderWidth = style.textBorderWidth;
  7720. var textBorderColor = style.textBorderColor;
  7721. var isPlainBg = isString(textBackgroundColor);
  7722. setCtx(ctx, 'shadowBlur', style.textBoxShadowBlur || 0);
  7723. setCtx(ctx, 'shadowColor', style.textBoxShadowColor || 'transparent');
  7724. setCtx(ctx, 'shadowOffsetX', style.textBoxShadowOffsetX || 0);
  7725. setCtx(ctx, 'shadowOffsetY', style.textBoxShadowOffsetY || 0);
  7726. if (isPlainBg || (textBorderWidth && textBorderColor)) {
  7727. ctx.beginPath();
  7728. var textBorderRadius = style.textBorderRadius;
  7729. if (!textBorderRadius) {
  7730. ctx.rect(x, y, width, height);
  7731. }
  7732. else {
  7733. buildPath(ctx, {
  7734. x: x, y: y, width: width, height: height, r: textBorderRadius
  7735. });
  7736. }
  7737. ctx.closePath();
  7738. }
  7739. if (isPlainBg) {
  7740. setCtx(ctx, 'fillStyle', textBackgroundColor);
  7741. if (style.fillOpacity != null) {
  7742. var originalGlobalAlpha = ctx.globalAlpha;
  7743. ctx.globalAlpha = style.fillOpacity * style.opacity;
  7744. ctx.fill();
  7745. ctx.globalAlpha = originalGlobalAlpha;
  7746. }
  7747. else {
  7748. ctx.fill();
  7749. }
  7750. }
  7751. else if (isObject$1(textBackgroundColor)) {
  7752. var image = textBackgroundColor.image;
  7753. image = createOrUpdateImage(
  7754. image, null, hostEl, onBgImageLoaded, textBackgroundColor
  7755. );
  7756. if (image && isImageReady(image)) {
  7757. ctx.drawImage(image, x, y, width, height);
  7758. }
  7759. }
  7760. if (textBorderWidth && textBorderColor) {
  7761. setCtx(ctx, 'lineWidth', textBorderWidth);
  7762. setCtx(ctx, 'strokeStyle', textBorderColor);
  7763. if (style.strokeOpacity != null) {
  7764. var originalGlobalAlpha = ctx.globalAlpha;
  7765. ctx.globalAlpha = style.strokeOpacity * style.opacity;
  7766. ctx.stroke();
  7767. ctx.globalAlpha = originalGlobalAlpha;
  7768. }
  7769. else {
  7770. ctx.stroke();
  7771. }
  7772. }
  7773. }
  7774. function onBgImageLoaded(image, textBackgroundColor) {
  7775. // Replace image, so that `contain/text.js#parseRichText`
  7776. // will get correct result in next tick.
  7777. textBackgroundColor.image = image;
  7778. }
  7779. function getBoxPosition(out, hostEl, style, rect) {
  7780. var baseX = style.x || 0;
  7781. var baseY = style.y || 0;
  7782. var textAlign = style.textAlign;
  7783. var textVerticalAlign = style.textVerticalAlign;
  7784. // Text position represented by coord
  7785. if (rect) {
  7786. var textPosition = style.textPosition;
  7787. if (textPosition instanceof Array) {
  7788. // Percent
  7789. baseX = rect.x + parsePercent(textPosition[0], rect.width);
  7790. baseY = rect.y + parsePercent(textPosition[1], rect.height);
  7791. }
  7792. else {
  7793. var res = (hostEl && hostEl.calculateTextPosition)
  7794. ? hostEl.calculateTextPosition(_tmpTextPositionResult, style, rect)
  7795. : calculateTextPosition(_tmpTextPositionResult, style, rect);
  7796. baseX = res.x;
  7797. baseY = res.y;
  7798. // Default align and baseline when has textPosition
  7799. textAlign = textAlign || res.textAlign;
  7800. textVerticalAlign = textVerticalAlign || res.textVerticalAlign;
  7801. }
  7802. // textOffset is only support in RectText, otherwise
  7803. // we have to adjust boundingRect for textOffset.
  7804. var textOffset = style.textOffset;
  7805. if (textOffset) {
  7806. baseX += textOffset[0];
  7807. baseY += textOffset[1];
  7808. }
  7809. }
  7810. out = out || {};
  7811. out.baseX = baseX;
  7812. out.baseY = baseY;
  7813. out.textAlign = textAlign;
  7814. out.textVerticalAlign = textVerticalAlign;
  7815. return out;
  7816. }
  7817. function setCtx(ctx, prop, value) {
  7818. ctx[prop] = fixShadow(ctx, prop, value);
  7819. return ctx[prop];
  7820. }
  7821. /**
  7822. * @param {string} [stroke] If specified, do not check style.textStroke.
  7823. * @param {string} [lineWidth] If specified, do not check style.textStroke.
  7824. * @param {number} style
  7825. */
  7826. function getStroke(stroke, lineWidth) {
  7827. return (stroke == null || lineWidth <= 0 || stroke === 'transparent' || stroke === 'none')
  7828. ? null
  7829. // TODO pattern and gradient?
  7830. : (stroke.image || stroke.colorStops)
  7831. ? '#000'
  7832. : stroke;
  7833. }
  7834. function getFill(fill) {
  7835. return (fill == null || fill === 'none')
  7836. ? null
  7837. // TODO pattern and gradient?
  7838. : (fill.image || fill.colorStops)
  7839. ? '#000'
  7840. : fill;
  7841. }
  7842. function parsePercent(value, maxValue) {
  7843. if (typeof value === 'string') {
  7844. if (value.lastIndexOf('%') >= 0) {
  7845. return parseFloat(value) / 100 * maxValue;
  7846. }
  7847. return parseFloat(value);
  7848. }
  7849. return value;
  7850. }
  7851. function getTextXForPadding(x, textAlign, textPadding) {
  7852. return textAlign === 'right'
  7853. ? (x - textPadding[1])
  7854. : textAlign === 'center'
  7855. ? (x + textPadding[3] / 2 - textPadding[1] / 2)
  7856. : (x + textPadding[3]);
  7857. }
  7858. /**
  7859. * @param {string} text
  7860. * @param {module:zrender/Style} style
  7861. * @return {boolean}
  7862. */
  7863. function needDrawText(text, style) {
  7864. return text != null
  7865. && (text
  7866. || style.textBackgroundColor
  7867. || (style.textBorderWidth && style.textBorderColor)
  7868. || style.textPadding
  7869. );
  7870. }
  7871. /**
  7872. * Mixin for drawing text in a element bounding rect
  7873. * @module zrender/mixin/RectText
  7874. */
  7875. var tmpRect$1 = new BoundingRect();
  7876. var RectText = function () {};
  7877. RectText.prototype = {
  7878. constructor: RectText,
  7879. /**
  7880. * Draw text in a rect with specified position.
  7881. * @param {CanvasRenderingContext2D} ctx
  7882. * @param {Object} rect Displayable rect
  7883. */
  7884. drawRectText: function (ctx, rect) {
  7885. var style = this.style;
  7886. rect = style.textRect || rect;
  7887. // Optimize, avoid normalize every time.
  7888. this.__dirty && normalizeTextStyle(style, true);
  7889. var text = style.text;
  7890. // Convert to string
  7891. text != null && (text += '');
  7892. if (!needDrawText(text, style)) {
  7893. return;
  7894. }
  7895. // FIXME
  7896. // Do not provide prevEl to `textHelper.renderText` for ctx prop cache,
  7897. // but use `ctx.save()` and `ctx.restore()`. Because the cache for rect
  7898. // text propably break the cache for its host elements.
  7899. ctx.save();
  7900. // Transform rect to view space
  7901. var transform = this.transform;
  7902. if (!style.transformText) {
  7903. if (transform) {
  7904. tmpRect$1.copy(rect);
  7905. tmpRect$1.applyTransform(transform);
  7906. rect = tmpRect$1;
  7907. }
  7908. }
  7909. else {
  7910. this.setTransform(ctx);
  7911. }
  7912. // transformText and textRotation can not be used at the same time.
  7913. renderText(this, ctx, text, style, rect, WILL_BE_RESTORED);
  7914. ctx.restore();
  7915. }
  7916. };
  7917. /**
  7918. * 可绘制的图形基类
  7919. * Base class of all displayable graphic objects
  7920. * @module zrender/graphic/Displayable
  7921. */
  7922. /**
  7923. * @alias module:zrender/graphic/Displayable
  7924. * @extends module:zrender/Element
  7925. * @extends module:zrender/graphic/mixin/RectText
  7926. */
  7927. function Displayable(opts) {
  7928. opts = opts || {};
  7929. Element.call(this, opts);
  7930. // Extend properties
  7931. for (var name in opts) {
  7932. if (
  7933. opts.hasOwnProperty(name)
  7934. && name !== 'style'
  7935. ) {
  7936. this[name] = opts[name];
  7937. }
  7938. }
  7939. /**
  7940. * @type {module:zrender/graphic/Style}
  7941. */
  7942. this.style = new Style(opts.style, this);
  7943. this._rect = null;
  7944. // Shapes for cascade clipping.
  7945. // Can only be `null`/`undefined` or an non-empty array, MUST NOT be an empty array.
  7946. // because it is easy to only using null to check whether clipPaths changed.
  7947. this.__clipPaths = null;
  7948. // FIXME Stateful must be mixined after style is setted
  7949. // Stateful.call(this, opts);
  7950. }
  7951. Displayable.prototype = {
  7952. constructor: Displayable,
  7953. type: 'displayable',
  7954. /**
  7955. * Displayable 是否为脏,Painter 中会根据该标记判断是否需要是否需要重新绘制
  7956. * Dirty flag. From which painter will determine if this displayable object needs brush
  7957. * @name module:zrender/graphic/Displayable#__dirty
  7958. * @type {boolean}
  7959. */
  7960. __dirty: true,
  7961. /**
  7962. * 图形是否可见,为true时不绘制图形,但是仍能触发鼠标事件
  7963. * If ignore drawing of the displayable object. Mouse event will still be triggered
  7964. * @name module:/zrender/graphic/Displayable#invisible
  7965. * @type {boolean}
  7966. * @default false
  7967. */
  7968. invisible: false,
  7969. /**
  7970. * @name module:/zrender/graphic/Displayable#z
  7971. * @type {number}
  7972. * @default 0
  7973. */
  7974. z: 0,
  7975. /**
  7976. * @name module:/zrender/graphic/Displayable#z
  7977. * @type {number}
  7978. * @default 0
  7979. */
  7980. z2: 0,
  7981. /**
  7982. * z层level,决定绘画在哪层canvas中
  7983. * @name module:/zrender/graphic/Displayable#zlevel
  7984. * @type {number}
  7985. * @default 0
  7986. */
  7987. zlevel: 0,
  7988. /**
  7989. * 是否可拖拽
  7990. * @name module:/zrender/graphic/Displayable#draggable
  7991. * @type {boolean}
  7992. * @default false
  7993. */
  7994. draggable: false,
  7995. /**
  7996. * 是否正在拖拽
  7997. * @name module:/zrender/graphic/Displayable#draggable
  7998. * @type {boolean}
  7999. * @default false
  8000. */
  8001. dragging: false,
  8002. /**
  8003. * 是否相应鼠标事件
  8004. * @name module:/zrender/graphic/Displayable#silent
  8005. * @type {boolean}
  8006. * @default false
  8007. */
  8008. silent: false,
  8009. /**
  8010. * If enable culling
  8011. * @type {boolean}
  8012. * @default false
  8013. */
  8014. culling: false,
  8015. /**
  8016. * Mouse cursor when hovered
  8017. * @name module:/zrender/graphic/Displayable#cursor
  8018. * @type {string}
  8019. */
  8020. cursor: 'pointer',
  8021. /**
  8022. * If hover area is bounding rect
  8023. * @name module:/zrender/graphic/Displayable#rectHover
  8024. * @type {string}
  8025. */
  8026. rectHover: false,
  8027. /**
  8028. * Render the element progressively when the value >= 0,
  8029. * usefull for large data.
  8030. * @type {boolean}
  8031. */
  8032. progressive: false,
  8033. /**
  8034. * @type {boolean}
  8035. */
  8036. incremental: false,
  8037. /**
  8038. * Scale ratio for global scale.
  8039. * @type {boolean}
  8040. */
  8041. globalScaleRatio: 1,
  8042. beforeBrush: function (ctx) {},
  8043. afterBrush: function (ctx) {},
  8044. /**
  8045. * 图形绘制方法
  8046. * @param {CanvasRenderingContext2D} ctx
  8047. */
  8048. // Interface
  8049. brush: function (ctx, prevEl) {},
  8050. /**
  8051. * 获取最小包围盒
  8052. * @return {module:zrender/core/BoundingRect}
  8053. */
  8054. // Interface
  8055. getBoundingRect: function () {},
  8056. /**
  8057. * 判断坐标 x, y 是否在图形上
  8058. * If displayable element contain coord x, y
  8059. * @param {number} x
  8060. * @param {number} y
  8061. * @return {boolean}
  8062. */
  8063. contain: function (x, y) {
  8064. return this.rectContain(x, y);
  8065. },
  8066. /**
  8067. * @param {Function} cb
  8068. * @param {} context
  8069. */
  8070. traverse: function (cb, context) {
  8071. cb.call(context, this);
  8072. },
  8073. /**
  8074. * 判断坐标 x, y 是否在图形的包围盒上
  8075. * If bounding rect of element contain coord x, y
  8076. * @param {number} x
  8077. * @param {number} y
  8078. * @return {boolean}
  8079. */
  8080. rectContain: function (x, y) {
  8081. var coord = this.transformCoordToLocal(x, y);
  8082. var rect = this.getBoundingRect();
  8083. return rect.contain(coord[0], coord[1]);
  8084. },
  8085. /**
  8086. * 标记图形元素为脏,并且在下一帧重绘
  8087. * Mark displayable element dirty and refresh next frame
  8088. */
  8089. dirty: function () {
  8090. this.__dirty = this.__dirtyText = true;
  8091. this._rect = null;
  8092. this.__zr && this.__zr.refresh();
  8093. },
  8094. /**
  8095. * 图形是否会触发事件
  8096. * If displayable object binded any event
  8097. * @return {boolean}
  8098. */
  8099. // TODO, 通过 bind 绑定的事件
  8100. // isSilent: function () {
  8101. // return !(
  8102. // this.hoverable || this.draggable
  8103. // || this.onmousemove || this.onmouseover || this.onmouseout
  8104. // || this.onmousedown || this.onmouseup || this.onclick
  8105. // || this.ondragenter || this.ondragover || this.ondragleave
  8106. // || this.ondrop
  8107. // );
  8108. // },
  8109. /**
  8110. * Alias for animate('style')
  8111. * @param {boolean} loop
  8112. */
  8113. animateStyle: function (loop) {
  8114. return this.animate('style', loop);
  8115. },
  8116. attrKV: function (key, value) {
  8117. if (key !== 'style') {
  8118. Element.prototype.attrKV.call(this, key, value);
  8119. }
  8120. else {
  8121. this.style.set(value);
  8122. }
  8123. },
  8124. /**
  8125. * @param {Object|string} key
  8126. * @param {*} value
  8127. */
  8128. setStyle: function (key, value) {
  8129. this.style.set(key, value);
  8130. this.dirty(false);
  8131. return this;
  8132. },
  8133. /**
  8134. * Use given style object
  8135. * @param {Object} obj
  8136. */
  8137. useStyle: function (obj) {
  8138. this.style = new Style(obj, this);
  8139. this.dirty(false);
  8140. return this;
  8141. },
  8142. /**
  8143. * The string value of `textPosition` needs to be calculated to a real postion.
  8144. * For example, `'inside'` is calculated to `[rect.width/2, rect.height/2]`
  8145. * by default. See `contain/text.js#calculateTextPosition` for more details.
  8146. * But some coutom shapes like "pin", "flag" have center that is not exactly
  8147. * `[width/2, height/2]`. So we provide this hook to customize the calculation
  8148. * for those shapes. It will be called if the `style.textPosition` is a string.
  8149. * @param {Obejct} [out] Prepared out object. If not provided, this method should
  8150. * be responsible for creating one.
  8151. * @param {module:zrender/graphic/Style} style
  8152. * @param {Object} rect {x, y, width, height}
  8153. * @return {Obejct} out The same as the input out.
  8154. * {
  8155. * x: number. mandatory.
  8156. * y: number. mandatory.
  8157. * textAlign: string. optional. use style.textAlign by default.
  8158. * textVerticalAlign: string. optional. use style.textVerticalAlign by default.
  8159. * }
  8160. */
  8161. calculateTextPosition: null
  8162. };
  8163. inherits(Displayable, Element);
  8164. mixin(Displayable, RectText);
  8165. /**
  8166. * @alias zrender/graphic/Image
  8167. * @extends module:zrender/graphic/Displayable
  8168. * @constructor
  8169. * @param {Object} opts
  8170. */
  8171. function ZImage(opts) {
  8172. Displayable.call(this, opts);
  8173. }
  8174. ZImage.prototype = {
  8175. constructor: ZImage,
  8176. type: 'image',
  8177. brush: function (ctx, prevEl) {
  8178. var style = this.style;
  8179. var src = style.image;
  8180. // Must bind each time
  8181. style.bind(ctx, this, prevEl);
  8182. var image = this._image = createOrUpdateImage(
  8183. src,
  8184. this._image,
  8185. this,
  8186. this.onload
  8187. );
  8188. if (!image || !isImageReady(image)) {
  8189. return;
  8190. }
  8191. // 图片已经加载完成
  8192. // if (image.nodeName.toUpperCase() == 'IMG') {
  8193. // if (!image.complete) {
  8194. // return;
  8195. // }
  8196. // }
  8197. // Else is canvas
  8198. var x = style.x || 0;
  8199. var y = style.y || 0;
  8200. var width = style.width;
  8201. var height = style.height;
  8202. var aspect = image.width / image.height;
  8203. if (width == null && height != null) {
  8204. // Keep image/height ratio
  8205. width = height * aspect;
  8206. }
  8207. else if (height == null && width != null) {
  8208. height = width / aspect;
  8209. }
  8210. else if (width == null && height == null) {
  8211. width = image.width;
  8212. height = image.height;
  8213. }
  8214. // 设置transform
  8215. this.setTransform(ctx);
  8216. if (style.sWidth && style.sHeight) {
  8217. var sx = style.sx || 0;
  8218. var sy = style.sy || 0;
  8219. ctx.drawImage(
  8220. image,
  8221. sx, sy, style.sWidth, style.sHeight,
  8222. x, y, width, height
  8223. );
  8224. }
  8225. else if (style.sx && style.sy) {
  8226. var sx = style.sx;
  8227. var sy = style.sy;
  8228. var sWidth = width - sx;
  8229. var sHeight = height - sy;
  8230. ctx.drawImage(
  8231. image,
  8232. sx, sy, sWidth, sHeight,
  8233. x, y, width, height
  8234. );
  8235. }
  8236. else {
  8237. ctx.drawImage(image, x, y, width, height);
  8238. }
  8239. // Draw rect text
  8240. if (style.text != null) {
  8241. // Only restore transform when needs draw text.
  8242. this.restoreTransform(ctx);
  8243. this.drawRectText(ctx, this.getBoundingRect());
  8244. }
  8245. },
  8246. getBoundingRect: function () {
  8247. var style = this.style;
  8248. if (!this._rect) {
  8249. this._rect = new BoundingRect(
  8250. style.x || 0, style.y || 0, style.width || 0, style.height || 0
  8251. );
  8252. }
  8253. return this._rect;
  8254. }
  8255. };
  8256. inherits(ZImage, Displayable);
  8257. var HOVER_LAYER_ZLEVEL = 1e5;
  8258. var CANVAS_ZLEVEL = 314159;
  8259. var EL_AFTER_INCREMENTAL_INC = 0.01;
  8260. var INCREMENTAL_INC = 0.001;
  8261. function parseInt10(val) {
  8262. return parseInt(val, 10);
  8263. }
  8264. function isLayerValid(layer) {
  8265. if (!layer) {
  8266. return false;
  8267. }
  8268. if (layer.__builtin__) {
  8269. return true;
  8270. }
  8271. if (typeof (layer.resize) !== 'function'
  8272. || typeof (layer.refresh) !== 'function'
  8273. ) {
  8274. return false;
  8275. }
  8276. return true;
  8277. }
  8278. var tmpRect = new BoundingRect(0, 0, 0, 0);
  8279. var viewRect = new BoundingRect(0, 0, 0, 0);
  8280. function isDisplayableCulled(el, width, height) {
  8281. tmpRect.copy(el.getBoundingRect());
  8282. if (el.transform) {
  8283. tmpRect.applyTransform(el.transform);
  8284. }
  8285. viewRect.width = width;
  8286. viewRect.height = height;
  8287. return !tmpRect.intersect(viewRect);
  8288. }
  8289. function isClipPathChanged(clipPaths, prevClipPaths) {
  8290. // displayable.__clipPaths can only be `null`/`undefined` or an non-empty array.
  8291. if (clipPaths === prevClipPaths) {
  8292. return false;
  8293. }
  8294. if (!clipPaths || !prevClipPaths || (clipPaths.length !== prevClipPaths.length)) {
  8295. return true;
  8296. }
  8297. for (var i = 0; i < clipPaths.length; i++) {
  8298. if (clipPaths[i] !== prevClipPaths[i]) {
  8299. return true;
  8300. }
  8301. }
  8302. return false;
  8303. }
  8304. function doClip(clipPaths, ctx) {
  8305. for (var i = 0; i < clipPaths.length; i++) {
  8306. var clipPath = clipPaths[i];
  8307. clipPath.setTransform(ctx);
  8308. ctx.beginPath();
  8309. clipPath.buildPath(ctx, clipPath.shape);
  8310. ctx.clip();
  8311. // Transform back
  8312. clipPath.restoreTransform(ctx);
  8313. }
  8314. }
  8315. function createRoot(width, height) {
  8316. var domRoot = document.createElement('div');
  8317. // domRoot.onselectstart = returnFalse; // 避免页面选中的尴尬
  8318. domRoot.style.cssText = [
  8319. 'position:relative',
  8320. 'overflow:hidden',
  8321. 'width:' + width + 'px',
  8322. 'height:' + height + 'px',
  8323. 'padding:0',
  8324. 'margin:0',
  8325. 'border-width:0'
  8326. ].join(';') + ';';
  8327. return domRoot;
  8328. }
  8329. /**
  8330. * @alias module:zrender/Painter
  8331. * @constructor
  8332. * @param {HTMLElement} root 绘图容器
  8333. * @param {module:zrender/Storage} storage
  8334. * @param {Object} opts
  8335. */
  8336. var Painter = function (root, storage, opts) {
  8337. this.type = 'canvas';
  8338. // In node environment using node-canvas
  8339. var singleCanvas = !root.nodeName // In node ?
  8340. || root.nodeName.toUpperCase() === 'CANVAS';
  8341. this._opts = opts = extend({}, opts || {});
  8342. /**
  8343. * @type {number}
  8344. */
  8345. this.dpr = opts.devicePixelRatio || devicePixelRatio;
  8346. /**
  8347. * @type {boolean}
  8348. * @private
  8349. */
  8350. this._singleCanvas = singleCanvas;
  8351. /**
  8352. * 绘图容器
  8353. * @type {HTMLElement}
  8354. */
  8355. this.root = root;
  8356. var rootStyle = root.style;
  8357. if (rootStyle) {
  8358. rootStyle['-webkit-tap-highlight-color'] = 'transparent';
  8359. rootStyle['-webkit-user-select'] =
  8360. rootStyle['user-select'] =
  8361. rootStyle['-webkit-touch-callout'] = 'none';
  8362. root.innerHTML = '';
  8363. }
  8364. /**
  8365. * @type {module:zrender/Storage}
  8366. */
  8367. this.storage = storage;
  8368. /**
  8369. * @type {Array.<number>}
  8370. * @private
  8371. */
  8372. var zlevelList = this._zlevelList = [];
  8373. /**
  8374. * @type {Object.<string, module:zrender/Layer>}
  8375. * @private
  8376. */
  8377. var layers = this._layers = {};
  8378. /**
  8379. * @type {Object.<string, Object>}
  8380. * @private
  8381. */
  8382. this._layerConfig = {};
  8383. /**
  8384. * zrender will do compositing when root is a canvas and have multiple zlevels.
  8385. */
  8386. this._needsManuallyCompositing = false;
  8387. if (!singleCanvas) {
  8388. this._width = this._getSize(0);
  8389. this._height = this._getSize(1);
  8390. var domRoot = this._domRoot = createRoot(
  8391. this._width, this._height
  8392. );
  8393. root.appendChild(domRoot);
  8394. }
  8395. else {
  8396. var width = root.width;
  8397. var height = root.height;
  8398. if (opts.width != null) {
  8399. width = opts.width;
  8400. }
  8401. if (opts.height != null) {
  8402. height = opts.height;
  8403. }
  8404. this.dpr = opts.devicePixelRatio || 1;
  8405. // Use canvas width and height directly
  8406. root.width = width * this.dpr;
  8407. root.height = height * this.dpr;
  8408. this._width = width;
  8409. this._height = height;
  8410. // Create layer if only one given canvas
  8411. // Device can be specified to create a high dpi image.
  8412. var mainLayer = new Layer(root, this, this.dpr);
  8413. mainLayer.__builtin__ = true;
  8414. mainLayer.initContext();
  8415. // FIXME Use canvas width and height
  8416. // mainLayer.resize(width, height);
  8417. layers[CANVAS_ZLEVEL] = mainLayer;
  8418. mainLayer.zlevel = CANVAS_ZLEVEL;
  8419. // Not use common zlevel.
  8420. zlevelList.push(CANVAS_ZLEVEL);
  8421. this._domRoot = root;
  8422. }
  8423. /**
  8424. * @type {module:zrender/Layer}
  8425. * @private
  8426. */
  8427. this._hoverlayer = null;
  8428. this._hoverElements = [];
  8429. };
  8430. Painter.prototype = {
  8431. constructor: Painter,
  8432. getType: function () {
  8433. return 'canvas';
  8434. },
  8435. /**
  8436. * If painter use a single canvas
  8437. * @return {boolean}
  8438. */
  8439. isSingleCanvas: function () {
  8440. return this._singleCanvas;
  8441. },
  8442. /**
  8443. * @return {HTMLDivElement}
  8444. */
  8445. getViewportRoot: function () {
  8446. return this._domRoot;
  8447. },
  8448. getViewportRootOffset: function () {
  8449. var viewportRoot = this.getViewportRoot();
  8450. if (viewportRoot) {
  8451. return {
  8452. offsetLeft: viewportRoot.offsetLeft || 0,
  8453. offsetTop: viewportRoot.offsetTop || 0
  8454. };
  8455. }
  8456. },
  8457. /**
  8458. * 刷新
  8459. * @param {boolean} [paintAll=false] 强制绘制所有displayable
  8460. */
  8461. refresh: function (paintAll) {
  8462. var list = this.storage.getDisplayList(true);
  8463. var zlevelList = this._zlevelList;
  8464. this._redrawId = Math.random();
  8465. this._paintList(list, paintAll, this._redrawId);
  8466. // Paint custum layers
  8467. for (var i = 0; i < zlevelList.length; i++) {
  8468. var z = zlevelList[i];
  8469. var layer = this._layers[z];
  8470. if (!layer.__builtin__ && layer.refresh) {
  8471. var clearColor = i === 0 ? this._backgroundColor : null;
  8472. layer.refresh(clearColor);
  8473. }
  8474. }
  8475. this.refreshHover();
  8476. return this;
  8477. },
  8478. addHover: function (el, hoverStyle) {
  8479. if (el.__hoverMir) {
  8480. return;
  8481. }
  8482. var elMirror = new el.constructor({
  8483. style: el.style,
  8484. shape: el.shape,
  8485. z: el.z,
  8486. z2: el.z2,
  8487. silent: el.silent
  8488. });
  8489. elMirror.__from = el;
  8490. el.__hoverMir = elMirror;
  8491. hoverStyle && elMirror.setStyle(hoverStyle);
  8492. this._hoverElements.push(elMirror);
  8493. return elMirror;
  8494. },
  8495. removeHover: function (el) {
  8496. var elMirror = el.__hoverMir;
  8497. var hoverElements = this._hoverElements;
  8498. var idx = indexOf(hoverElements, elMirror);
  8499. if (idx >= 0) {
  8500. hoverElements.splice(idx, 1);
  8501. }
  8502. el.__hoverMir = null;
  8503. },
  8504. clearHover: function (el) {
  8505. var hoverElements = this._hoverElements;
  8506. for (var i = 0; i < hoverElements.length; i++) {
  8507. var from = hoverElements[i].__from;
  8508. if (from) {
  8509. from.__hoverMir = null;
  8510. }
  8511. }
  8512. hoverElements.length = 0;
  8513. },
  8514. refreshHover: function () {
  8515. var hoverElements = this._hoverElements;
  8516. var len = hoverElements.length;
  8517. var hoverLayer = this._hoverlayer;
  8518. hoverLayer && hoverLayer.clear();
  8519. if (!len) {
  8520. return;
  8521. }
  8522. sort(hoverElements, this.storage.displayableSortFunc);
  8523. // Use a extream large zlevel
  8524. // FIXME?
  8525. if (!hoverLayer) {
  8526. hoverLayer = this._hoverlayer = this.getLayer(HOVER_LAYER_ZLEVEL);
  8527. }
  8528. var scope = {};
  8529. hoverLayer.ctx.save();
  8530. for (var i = 0; i < len;) {
  8531. var el = hoverElements[i];
  8532. var originalEl = el.__from;
  8533. // Original el is removed
  8534. // PENDING
  8535. if (!(originalEl && originalEl.__zr)) {
  8536. hoverElements.splice(i, 1);
  8537. originalEl.__hoverMir = null;
  8538. len--;
  8539. continue;
  8540. }
  8541. i++;
  8542. // Use transform
  8543. // FIXME style and shape ?
  8544. if (!originalEl.invisible) {
  8545. el.transform = originalEl.transform;
  8546. el.invTransform = originalEl.invTransform;
  8547. el.__clipPaths = originalEl.__clipPaths;
  8548. // el.
  8549. this._doPaintEl(el, hoverLayer, true, scope);
  8550. }
  8551. }
  8552. hoverLayer.ctx.restore();
  8553. },
  8554. getHoverLayer: function () {
  8555. return this.getLayer(HOVER_LAYER_ZLEVEL);
  8556. },
  8557. _paintList: function (list, paintAll, redrawId) {
  8558. if (this._redrawId !== redrawId) {
  8559. return;
  8560. }
  8561. paintAll = paintAll || false;
  8562. this._updateLayerStatus(list);
  8563. var finished = this._doPaintList(list, paintAll);
  8564. if (this._needsManuallyCompositing) {
  8565. this._compositeManually();
  8566. }
  8567. if (!finished) {
  8568. var self = this;
  8569. requestAnimationFrame(function () {
  8570. self._paintList(list, paintAll, redrawId);
  8571. });
  8572. }
  8573. },
  8574. _compositeManually: function () {
  8575. var ctx = this.getLayer(CANVAS_ZLEVEL).ctx;
  8576. var width = this._domRoot.width;
  8577. var height = this._domRoot.height;
  8578. ctx.clearRect(0, 0, width, height);
  8579. // PENDING, If only builtin layer?
  8580. this.eachBuiltinLayer(function (layer) {
  8581. if (layer.virtual) {
  8582. ctx.drawImage(layer.dom, 0, 0, width, height);
  8583. }
  8584. });
  8585. },
  8586. _doPaintList: function (list, paintAll) {
  8587. var layerList = [];
  8588. for (var zi = 0; zi < this._zlevelList.length; zi++) {
  8589. var zlevel = this._zlevelList[zi];
  8590. var layer = this._layers[zlevel];
  8591. if (layer.__builtin__
  8592. && layer !== this._hoverlayer
  8593. && (layer.__dirty || paintAll)
  8594. ) {
  8595. layerList.push(layer);
  8596. }
  8597. }
  8598. var finished = true;
  8599. for (var k = 0; k < layerList.length; k++) {
  8600. var layer = layerList[k];
  8601. var ctx = layer.ctx;
  8602. var scope = {};
  8603. ctx.save();
  8604. var start = paintAll ? layer.__startIndex : layer.__drawIndex;
  8605. var useTimer = !paintAll && layer.incremental && Date.now;
  8606. var startTime = useTimer && Date.now();
  8607. var clearColor = layer.zlevel === this._zlevelList[0]
  8608. ? this._backgroundColor : null;
  8609. // All elements in this layer are cleared.
  8610. if (layer.__startIndex === layer.__endIndex) {
  8611. layer.clear(false, clearColor);
  8612. }
  8613. else if (start === layer.__startIndex) {
  8614. var firstEl = list[start];
  8615. if (!firstEl.incremental || !firstEl.notClear || paintAll) {
  8616. layer.clear(false, clearColor);
  8617. }
  8618. }
  8619. if (start === -1) {
  8620. console.error('For some unknown reason. drawIndex is -1');
  8621. start = layer.__startIndex;
  8622. }
  8623. for (var i = start; i < layer.__endIndex; i++) {
  8624. var el = list[i];
  8625. this._doPaintEl(el, layer, paintAll, scope);
  8626. el.__dirty = el.__dirtyText = false;
  8627. if (useTimer) {
  8628. // Date.now can be executed in 13,025,305 ops/second.
  8629. var dTime = Date.now() - startTime;
  8630. // Give 15 millisecond to draw.
  8631. // The rest elements will be drawn in the next frame.
  8632. if (dTime > 15) {
  8633. break;
  8634. }
  8635. }
  8636. }
  8637. layer.__drawIndex = i;
  8638. if (layer.__drawIndex < layer.__endIndex) {
  8639. finished = false;
  8640. }
  8641. if (scope.prevElClipPaths) {
  8642. // Needs restore the state. If last drawn element is in the clipping area.
  8643. ctx.restore();
  8644. }
  8645. ctx.restore();
  8646. }
  8647. if (env$1.wxa) {
  8648. // Flush for weixin application
  8649. each$1(this._layers, function (layer) {
  8650. if (layer && layer.ctx && layer.ctx.draw) {
  8651. layer.ctx.draw();
  8652. }
  8653. });
  8654. }
  8655. return finished;
  8656. },
  8657. _doPaintEl: function (el, currentLayer, forcePaint, scope) {
  8658. var ctx = currentLayer.ctx;
  8659. var m = el.transform;
  8660. if (
  8661. (currentLayer.__dirty || forcePaint)
  8662. // Ignore invisible element
  8663. && !el.invisible
  8664. // Ignore transparent element
  8665. && el.style.opacity !== 0
  8666. // Ignore scale 0 element, in some environment like node-canvas
  8667. // Draw a scale 0 element can cause all following draw wrong
  8668. // And setTransform with scale 0 will cause set back transform failed.
  8669. && !(m && !m[0] && !m[3])
  8670. // Ignore culled element
  8671. && !(el.culling && isDisplayableCulled(el, this._width, this._height))
  8672. ) {
  8673. var clipPaths = el.__clipPaths;
  8674. var prevElClipPaths = scope.prevElClipPaths;
  8675. // Optimize when clipping on group with several elements
  8676. if (!prevElClipPaths || isClipPathChanged(clipPaths, prevElClipPaths)) {
  8677. // If has previous clipping state, restore from it
  8678. if (prevElClipPaths) {
  8679. ctx.restore();
  8680. scope.prevElClipPaths = null;
  8681. // Reset prevEl since context has been restored
  8682. scope.prevEl = null;
  8683. }
  8684. // New clipping state
  8685. if (clipPaths) {
  8686. ctx.save();
  8687. doClip(clipPaths, ctx);
  8688. scope.prevElClipPaths = clipPaths;
  8689. }
  8690. }
  8691. el.beforeBrush && el.beforeBrush(ctx);
  8692. el.brush(ctx, scope.prevEl || null);
  8693. scope.prevEl = el;
  8694. el.afterBrush && el.afterBrush(ctx);
  8695. }
  8696. },
  8697. /**
  8698. * 获取 zlevel 所在层,如果不存在则会创建一个新的层
  8699. * @param {number} zlevel
  8700. * @param {boolean} virtual Virtual layer will not be inserted into dom.
  8701. * @return {module:zrender/Layer}
  8702. */
  8703. getLayer: function (zlevel, virtual) {
  8704. if (this._singleCanvas && !this._needsManuallyCompositing) {
  8705. zlevel = CANVAS_ZLEVEL;
  8706. }
  8707. var layer = this._layers[zlevel];
  8708. if (!layer) {
  8709. // Create a new layer
  8710. layer = new Layer('zr_' + zlevel, this, this.dpr);
  8711. layer.zlevel = zlevel;
  8712. layer.__builtin__ = true;
  8713. if (this._layerConfig[zlevel]) {
  8714. merge(layer, this._layerConfig[zlevel], true);
  8715. }
  8716. if (virtual) {
  8717. layer.virtual = virtual;
  8718. }
  8719. this.insertLayer(zlevel, layer);
  8720. // Context is created after dom inserted to document
  8721. // Or excanvas will get 0px clientWidth and clientHeight
  8722. layer.initContext();
  8723. }
  8724. return layer;
  8725. },
  8726. insertLayer: function (zlevel, layer) {
  8727. var layersMap = this._layers;
  8728. var zlevelList = this._zlevelList;
  8729. var len = zlevelList.length;
  8730. var prevLayer = null;
  8731. var i = -1;
  8732. var domRoot = this._domRoot;
  8733. if (layersMap[zlevel]) {
  8734. zrLog('ZLevel ' + zlevel + ' has been used already');
  8735. return;
  8736. }
  8737. // Check if is a valid layer
  8738. if (!isLayerValid(layer)) {
  8739. zrLog('Layer of zlevel ' + zlevel + ' is not valid');
  8740. return;
  8741. }
  8742. if (len > 0 && zlevel > zlevelList[0]) {
  8743. for (i = 0; i < len - 1; i++) {
  8744. if (
  8745. zlevelList[i] < zlevel
  8746. && zlevelList[i + 1] > zlevel
  8747. ) {
  8748. break;
  8749. }
  8750. }
  8751. prevLayer = layersMap[zlevelList[i]];
  8752. }
  8753. zlevelList.splice(i + 1, 0, zlevel);
  8754. layersMap[zlevel] = layer;
  8755. // Vitual layer will not directly show on the screen.
  8756. // (It can be a WebGL layer and assigned to a ZImage element)
  8757. // But it still under management of zrender.
  8758. if (!layer.virtual) {
  8759. if (prevLayer) {
  8760. var prevDom = prevLayer.dom;
  8761. if (prevDom.nextSibling) {
  8762. domRoot.insertBefore(
  8763. layer.dom,
  8764. prevDom.nextSibling
  8765. );
  8766. }
  8767. else {
  8768. domRoot.appendChild(layer.dom);
  8769. }
  8770. }
  8771. else {
  8772. if (domRoot.firstChild) {
  8773. domRoot.insertBefore(layer.dom, domRoot.firstChild);
  8774. }
  8775. else {
  8776. domRoot.appendChild(layer.dom);
  8777. }
  8778. }
  8779. }
  8780. },
  8781. // Iterate each layer
  8782. eachLayer: function (cb, context) {
  8783. var zlevelList = this._zlevelList;
  8784. var z;
  8785. var i;
  8786. for (i = 0; i < zlevelList.length; i++) {
  8787. z = zlevelList[i];
  8788. cb.call(context, this._layers[z], z);
  8789. }
  8790. },
  8791. // Iterate each buildin layer
  8792. eachBuiltinLayer: function (cb, context) {
  8793. var zlevelList = this._zlevelList;
  8794. var layer;
  8795. var z;
  8796. var i;
  8797. for (i = 0; i < zlevelList.length; i++) {
  8798. z = zlevelList[i];
  8799. layer = this._layers[z];
  8800. if (layer.__builtin__) {
  8801. cb.call(context, layer, z);
  8802. }
  8803. }
  8804. },
  8805. // Iterate each other layer except buildin layer
  8806. eachOtherLayer: function (cb, context) {
  8807. var zlevelList = this._zlevelList;
  8808. var layer;
  8809. var z;
  8810. var i;
  8811. for (i = 0; i < zlevelList.length; i++) {
  8812. z = zlevelList[i];
  8813. layer = this._layers[z];
  8814. if (!layer.__builtin__) {
  8815. cb.call(context, layer, z);
  8816. }
  8817. }
  8818. },
  8819. /**
  8820. * 获取所有已创建的层
  8821. * @param {Array.<module:zrender/Layer>} [prevLayer]
  8822. */
  8823. getLayers: function () {
  8824. return this._layers;
  8825. },
  8826. _updateLayerStatus: function (list) {
  8827. this.eachBuiltinLayer(function (layer, z) {
  8828. layer.__dirty = layer.__used = false;
  8829. });
  8830. function updatePrevLayer(idx) {
  8831. if (prevLayer) {
  8832. if (prevLayer.__endIndex !== idx) {
  8833. prevLayer.__dirty = true;
  8834. }
  8835. prevLayer.__endIndex = idx;
  8836. }
  8837. }
  8838. if (this._singleCanvas) {
  8839. for (var i = 1; i < list.length; i++) {
  8840. var el = list[i];
  8841. if (el.zlevel !== list[i - 1].zlevel || el.incremental) {
  8842. this._needsManuallyCompositing = true;
  8843. break;
  8844. }
  8845. }
  8846. }
  8847. var prevLayer = null;
  8848. var incrementalLayerCount = 0;
  8849. for (var i = 0; i < list.length; i++) {
  8850. var el = list[i];
  8851. var zlevel = el.zlevel;
  8852. var layer;
  8853. // PENDING If change one incremental element style ?
  8854. // TODO Where there are non-incremental elements between incremental elements.
  8855. if (el.incremental) {
  8856. layer = this.getLayer(zlevel + INCREMENTAL_INC, this._needsManuallyCompositing);
  8857. layer.incremental = true;
  8858. incrementalLayerCount = 1;
  8859. }
  8860. else {
  8861. layer = this.getLayer(zlevel + (incrementalLayerCount > 0 ? EL_AFTER_INCREMENTAL_INC : 0), this._needsManuallyCompositing);
  8862. }
  8863. if (!layer.__builtin__) {
  8864. zrLog('ZLevel ' + zlevel + ' has been used by unkown layer ' + layer.id);
  8865. }
  8866. if (layer !== prevLayer) {
  8867. layer.__used = true;
  8868. if (layer.__startIndex !== i) {
  8869. layer.__dirty = true;
  8870. }
  8871. layer.__startIndex = i;
  8872. if (!layer.incremental) {
  8873. layer.__drawIndex = i;
  8874. }
  8875. else {
  8876. // Mark layer draw index needs to update.
  8877. layer.__drawIndex = -1;
  8878. }
  8879. updatePrevLayer(i);
  8880. prevLayer = layer;
  8881. }
  8882. if (el.__dirty) {
  8883. layer.__dirty = true;
  8884. if (layer.incremental && layer.__drawIndex < 0) {
  8885. // Start draw from the first dirty element.
  8886. layer.__drawIndex = i;
  8887. }
  8888. }
  8889. }
  8890. updatePrevLayer(i);
  8891. this.eachBuiltinLayer(function (layer, z) {
  8892. // Used in last frame but not in this frame. Needs clear
  8893. if (!layer.__used && layer.getElementCount() > 0) {
  8894. layer.__dirty = true;
  8895. layer.__startIndex = layer.__endIndex = layer.__drawIndex = 0;
  8896. }
  8897. // For incremental layer. In case start index changed and no elements are dirty.
  8898. if (layer.__dirty && layer.__drawIndex < 0) {
  8899. layer.__drawIndex = layer.__startIndex;
  8900. }
  8901. });
  8902. },
  8903. /**
  8904. * 清除hover层外所有内容
  8905. */
  8906. clear: function () {
  8907. this.eachBuiltinLayer(this._clearLayer);
  8908. return this;
  8909. },
  8910. _clearLayer: function (layer) {
  8911. layer.clear();
  8912. },
  8913. setBackgroundColor: function (backgroundColor) {
  8914. this._backgroundColor = backgroundColor;
  8915. },
  8916. /**
  8917. * 修改指定zlevel的绘制参数
  8918. *
  8919. * @param {string} zlevel
  8920. * @param {Object} config 配置对象
  8921. * @param {string} [config.clearColor=0] 每次清空画布的颜色
  8922. * @param {string} [config.motionBlur=false] 是否开启动态模糊
  8923. * @param {number} [config.lastFrameAlpha=0.7]
  8924. * 在开启动态模糊的时候使用,与上一帧混合的alpha值,值越大尾迹越明显
  8925. */
  8926. configLayer: function (zlevel, config) {
  8927. if (config) {
  8928. var layerConfig = this._layerConfig;
  8929. if (!layerConfig[zlevel]) {
  8930. layerConfig[zlevel] = config;
  8931. }
  8932. else {
  8933. merge(layerConfig[zlevel], config, true);
  8934. }
  8935. for (var i = 0; i < this._zlevelList.length; i++) {
  8936. var _zlevel = this._zlevelList[i];
  8937. if (_zlevel === zlevel || _zlevel === zlevel + EL_AFTER_INCREMENTAL_INC) {
  8938. var layer = this._layers[_zlevel];
  8939. merge(layer, layerConfig[zlevel], true);
  8940. }
  8941. }
  8942. }
  8943. },
  8944. /**
  8945. * 删除指定层
  8946. * @param {number} zlevel 层所在的zlevel
  8947. */
  8948. delLayer: function (zlevel) {
  8949. var layers = this._layers;
  8950. var zlevelList = this._zlevelList;
  8951. var layer = layers[zlevel];
  8952. if (!layer) {
  8953. return;
  8954. }
  8955. layer.dom.parentNode.removeChild(layer.dom);
  8956. delete layers[zlevel];
  8957. zlevelList.splice(indexOf(zlevelList, zlevel), 1);
  8958. },
  8959. /**
  8960. * 区域大小变化后重绘
  8961. */
  8962. resize: function (width, height) {
  8963. if (!this._domRoot.style) { // Maybe in node or worker
  8964. if (width == null || height == null) {
  8965. return;
  8966. }
  8967. this._width = width;
  8968. this._height = height;
  8969. this.getLayer(CANVAS_ZLEVEL).resize(width, height);
  8970. }
  8971. else {
  8972. var domRoot = this._domRoot;
  8973. // FIXME Why ?
  8974. domRoot.style.display = 'none';
  8975. // Save input w/h
  8976. var opts = this._opts;
  8977. width != null && (opts.width = width);
  8978. height != null && (opts.height = height);
  8979. width = this._getSize(0);
  8980. height = this._getSize(1);
  8981. domRoot.style.display = '';
  8982. // 优化没有实际改变的resize
  8983. if (this._width !== width || height !== this._height) {
  8984. domRoot.style.width = width + 'px';
  8985. domRoot.style.height = height + 'px';
  8986. for (var id in this._layers) {
  8987. if (this._layers.hasOwnProperty(id)) {
  8988. this._layers[id].resize(width, height);
  8989. }
  8990. }
  8991. each$1(this._progressiveLayers, function (layer) {
  8992. layer.resize(width, height);
  8993. });
  8994. this.refresh(true);
  8995. }
  8996. this._width = width;
  8997. this._height = height;
  8998. }
  8999. return this;
  9000. },
  9001. /**
  9002. * 清除单独的一个层
  9003. * @param {number} zlevel
  9004. */
  9005. clearLayer: function (zlevel) {
  9006. var layer = this._layers[zlevel];
  9007. if (layer) {
  9008. layer.clear();
  9009. }
  9010. },
  9011. /**
  9012. * 释放
  9013. */
  9014. dispose: function () {
  9015. this.root.innerHTML = '';
  9016. this.root =
  9017. this.storage =
  9018. this._domRoot =
  9019. this._layers = null;
  9020. },
  9021. /**
  9022. * Get canvas which has all thing rendered
  9023. * @param {Object} opts
  9024. * @param {string} [opts.backgroundColor]
  9025. * @param {number} [opts.pixelRatio]
  9026. */
  9027. getRenderedCanvas: function (opts) {
  9028. opts = opts || {};
  9029. if (this._singleCanvas && !this._compositeManually) {
  9030. return this._layers[CANVAS_ZLEVEL].dom;
  9031. }
  9032. var imageLayer = new Layer('image', this, opts.pixelRatio || this.dpr);
  9033. imageLayer.initContext();
  9034. imageLayer.clear(false, opts.backgroundColor || this._backgroundColor);
  9035. if (opts.pixelRatio <= this.dpr) {
  9036. this.refresh();
  9037. var width = imageLayer.dom.width;
  9038. var height = imageLayer.dom.height;
  9039. var ctx = imageLayer.ctx;
  9040. this.eachLayer(function (layer) {
  9041. if (layer.__builtin__) {
  9042. ctx.drawImage(layer.dom, 0, 0, width, height);
  9043. }
  9044. else if (layer.renderToCanvas) {
  9045. imageLayer.ctx.save();
  9046. layer.renderToCanvas(imageLayer.ctx);
  9047. imageLayer.ctx.restore();
  9048. }
  9049. });
  9050. }
  9051. else {
  9052. // PENDING, echarts-gl and incremental rendering.
  9053. var scope = {};
  9054. var displayList = this.storage.getDisplayList(true);
  9055. for (var i = 0; i < displayList.length; i++) {
  9056. var el = displayList[i];
  9057. this._doPaintEl(el, imageLayer, true, scope);
  9058. }
  9059. }
  9060. return imageLayer.dom;
  9061. },
  9062. /**
  9063. * 获取绘图区域宽度
  9064. */
  9065. getWidth: function () {
  9066. return this._width;
  9067. },
  9068. /**
  9069. * 获取绘图区域高度
  9070. */
  9071. getHeight: function () {
  9072. return this._height;
  9073. },
  9074. _getSize: function (whIdx) {
  9075. var opts = this._opts;
  9076. var wh = ['width', 'height'][whIdx];
  9077. var cwh = ['clientWidth', 'clientHeight'][whIdx];
  9078. var plt = ['paddingLeft', 'paddingTop'][whIdx];
  9079. var prb = ['paddingRight', 'paddingBottom'][whIdx];
  9080. if (opts[wh] != null && opts[wh] !== 'auto') {
  9081. return parseFloat(opts[wh]);
  9082. }
  9083. var root = this.root;
  9084. // IE8 does not support getComputedStyle, but it use VML.
  9085. var stl = document.defaultView.getComputedStyle(root);
  9086. return (
  9087. (root[cwh] || parseInt10(stl[wh]) || parseInt10(root.style[wh]))
  9088. - (parseInt10(stl[plt]) || 0)
  9089. - (parseInt10(stl[prb]) || 0)
  9090. ) | 0;
  9091. },
  9092. pathToImage: function (path, dpr) {
  9093. dpr = dpr || this.dpr;
  9094. var canvas = document.createElement('canvas');
  9095. var ctx = canvas.getContext('2d');
  9096. var rect = path.getBoundingRect();
  9097. var style = path.style;
  9098. var shadowBlurSize = style.shadowBlur * dpr;
  9099. var shadowOffsetX = style.shadowOffsetX * dpr;
  9100. var shadowOffsetY = style.shadowOffsetY * dpr;
  9101. var lineWidth = style.hasStroke() ? style.lineWidth : 0;
  9102. var leftMargin = Math.max(lineWidth / 2, -shadowOffsetX + shadowBlurSize);
  9103. var rightMargin = Math.max(lineWidth / 2, shadowOffsetX + shadowBlurSize);
  9104. var topMargin = Math.max(lineWidth / 2, -shadowOffsetY + shadowBlurSize);
  9105. var bottomMargin = Math.max(lineWidth / 2, shadowOffsetY + shadowBlurSize);
  9106. var width = rect.width + leftMargin + rightMargin;
  9107. var height = rect.height + topMargin + bottomMargin;
  9108. canvas.width = width * dpr;
  9109. canvas.height = height * dpr;
  9110. ctx.scale(dpr, dpr);
  9111. ctx.clearRect(0, 0, width, height);
  9112. ctx.dpr = dpr;
  9113. var pathTransform = {
  9114. position: path.position,
  9115. rotation: path.rotation,
  9116. scale: path.scale
  9117. };
  9118. path.position = [leftMargin - rect.x, topMargin - rect.y];
  9119. path.rotation = 0;
  9120. path.scale = [1, 1];
  9121. path.updateTransform();
  9122. if (path) {
  9123. path.brush(ctx);
  9124. }
  9125. var ImageShape = ZImage;
  9126. var imgShape = new ImageShape({
  9127. style: {
  9128. x: 0,
  9129. y: 0,
  9130. image: canvas
  9131. }
  9132. });
  9133. if (pathTransform.position != null) {
  9134. imgShape.position = path.position = pathTransform.position;
  9135. }
  9136. if (pathTransform.rotation != null) {
  9137. imgShape.rotation = path.rotation = pathTransform.rotation;
  9138. }
  9139. if (pathTransform.scale != null) {
  9140. imgShape.scale = path.scale = pathTransform.scale;
  9141. }
  9142. return imgShape;
  9143. }
  9144. };
  9145. /**
  9146. * 动画主类, 调度和管理所有动画控制器
  9147. *
  9148. * @module zrender/animation/Animation
  9149. * @author pissang(https://github.com/pissang)
  9150. */
  9151. // TODO Additive animation
  9152. // http://iosoteric.com/additive-animations-animatewithduration-in-ios-8/
  9153. // https://developer.apple.com/videos/wwdc2014/#236
  9154. /**
  9155. * @typedef {Object} IZRenderStage
  9156. * @property {Function} update
  9157. */
  9158. /**
  9159. * @alias module:zrender/animation/Animation
  9160. * @constructor
  9161. * @param {Object} [options]
  9162. * @param {Function} [options.onframe]
  9163. * @param {IZRenderStage} [options.stage]
  9164. * @example
  9165. * var animation = new Animation();
  9166. * var obj = {
  9167. * x: 100,
  9168. * y: 100
  9169. * };
  9170. * animation.animate(node.position)
  9171. * .when(1000, {
  9172. * x: 500,
  9173. * y: 500
  9174. * })
  9175. * .when(2000, {
  9176. * x: 100,
  9177. * y: 100
  9178. * })
  9179. * .start('spline');
  9180. */
  9181. var Animation = function (options) {
  9182. options = options || {};
  9183. this.stage = options.stage || {};
  9184. this.onframe = options.onframe || function () {};
  9185. // private properties
  9186. this._clips = [];
  9187. this._running = false;
  9188. this._time;
  9189. this._pausedTime;
  9190. this._pauseStart;
  9191. this._paused = false;
  9192. Eventful.call(this);
  9193. };
  9194. Animation.prototype = {
  9195. constructor: Animation,
  9196. /**
  9197. * 添加 clip
  9198. * @param {module:zrender/animation/Clip} clip
  9199. */
  9200. addClip: function (clip) {
  9201. this._clips.push(clip);
  9202. },
  9203. /**
  9204. * 添加 animator
  9205. * @param {module:zrender/animation/Animator} animator
  9206. */
  9207. addAnimator: function (animator) {
  9208. animator.animation = this;
  9209. var clips = animator.getClips();
  9210. for (var i = 0; i < clips.length; i++) {
  9211. this.addClip(clips[i]);
  9212. }
  9213. },
  9214. /**
  9215. * 删除动画片段
  9216. * @param {module:zrender/animation/Clip} clip
  9217. */
  9218. removeClip: function (clip) {
  9219. var idx = indexOf(this._clips, clip);
  9220. if (idx >= 0) {
  9221. this._clips.splice(idx, 1);
  9222. }
  9223. },
  9224. /**
  9225. * 删除动画片段
  9226. * @param {module:zrender/animation/Animator} animator
  9227. */
  9228. removeAnimator: function (animator) {
  9229. var clips = animator.getClips();
  9230. for (var i = 0; i < clips.length; i++) {
  9231. this.removeClip(clips[i]);
  9232. }
  9233. animator.animation = null;
  9234. },
  9235. _update: function () {
  9236. var time = new Date().getTime() - this._pausedTime;
  9237. var delta = time - this._time;
  9238. var clips = this._clips;
  9239. var len = clips.length;
  9240. var deferredEvents = [];
  9241. var deferredClips = [];
  9242. for (var i = 0; i < len; i++) {
  9243. var clip = clips[i];
  9244. var e = clip.step(time, delta);
  9245. // Throw out the events need to be called after
  9246. // stage.update, like destroy
  9247. if (e) {
  9248. deferredEvents.push(e);
  9249. deferredClips.push(clip);
  9250. }
  9251. }
  9252. // Remove the finished clip
  9253. for (var i = 0; i < len;) {
  9254. if (clips[i]._needsRemove) {
  9255. clips[i] = clips[len - 1];
  9256. clips.pop();
  9257. len--;
  9258. }
  9259. else {
  9260. i++;
  9261. }
  9262. }
  9263. len = deferredEvents.length;
  9264. for (var i = 0; i < len; i++) {
  9265. deferredClips[i].fire(deferredEvents[i]);
  9266. }
  9267. this._time = time;
  9268. this.onframe(delta);
  9269. // 'frame' should be triggered before stage, because upper application
  9270. // depends on the sequence (e.g., echarts-stream and finish
  9271. // event judge)
  9272. this.trigger('frame', delta);
  9273. if (this.stage.update) {
  9274. this.stage.update();
  9275. }
  9276. },
  9277. _startLoop: function () {
  9278. var self = this;
  9279. this._running = true;
  9280. function step() {
  9281. if (self._running) {
  9282. requestAnimationFrame(step);
  9283. !self._paused && self._update();
  9284. }
  9285. }
  9286. requestAnimationFrame(step);
  9287. },
  9288. /**
  9289. * Start animation.
  9290. */
  9291. start: function () {
  9292. this._time = new Date().getTime();
  9293. this._pausedTime = 0;
  9294. this._startLoop();
  9295. },
  9296. /**
  9297. * Stop animation.
  9298. */
  9299. stop: function () {
  9300. this._running = false;
  9301. },
  9302. /**
  9303. * Pause animation.
  9304. */
  9305. pause: function () {
  9306. if (!this._paused) {
  9307. this._pauseStart = new Date().getTime();
  9308. this._paused = true;
  9309. }
  9310. },
  9311. /**
  9312. * Resume animation.
  9313. */
  9314. resume: function () {
  9315. if (this._paused) {
  9316. this._pausedTime += (new Date().getTime()) - this._pauseStart;
  9317. this._paused = false;
  9318. }
  9319. },
  9320. /**
  9321. * Clear animation.
  9322. */
  9323. clear: function () {
  9324. this._clips = [];
  9325. },
  9326. /**
  9327. * Whether animation finished.
  9328. */
  9329. isFinished: function () {
  9330. return !this._clips.length;
  9331. },
  9332. /**
  9333. * Creat animator for a target, whose props can be animated.
  9334. *
  9335. * @param {Object} target
  9336. * @param {Object} options
  9337. * @param {boolean} [options.loop=false] Whether loop animation.
  9338. * @param {Function} [options.getter=null] Get value from target.
  9339. * @param {Function} [options.setter=null] Set value to target.
  9340. * @return {module:zrender/animation/Animation~Animator}
  9341. */
  9342. // TODO Gap
  9343. animate: function (target, options) {
  9344. options = options || {};
  9345. var animator = new Animator(
  9346. target,
  9347. options.loop,
  9348. options.getter,
  9349. options.setter
  9350. );
  9351. this.addAnimator(animator);
  9352. return animator;
  9353. }
  9354. };
  9355. mixin(Animation, Eventful);
  9356. var TOUCH_CLICK_DELAY = 300;
  9357. var mouseHandlerNames = [
  9358. 'click', 'dblclick', 'mousewheel', 'mouseout',
  9359. 'mouseup', 'mousedown', 'mousemove', 'contextmenu'
  9360. ];
  9361. var touchHandlerNames = [
  9362. 'touchstart', 'touchend', 'touchmove'
  9363. ];
  9364. var pointerEventNames = {
  9365. pointerdown: 1, pointerup: 1, pointermove: 1, pointerout: 1
  9366. };
  9367. var pointerHandlerNames = map(mouseHandlerNames, function (name) {
  9368. var nm = name.replace('mouse', 'pointer');
  9369. return pointerEventNames[nm] ? nm : name;
  9370. });
  9371. function eventNameFix(name) {
  9372. return (name === 'mousewheel' && env$1.browser.firefox) ? 'DOMMouseScroll' : name;
  9373. }
  9374. // function onMSGestureChange(proxy, event) {
  9375. // if (event.translationX || event.translationY) {
  9376. // // mousemove is carried by MSGesture to reduce the sensitivity.
  9377. // proxy.handler.dispatchToElement(event.target, 'mousemove', event);
  9378. // }
  9379. // if (event.scale !== 1) {
  9380. // event.pinchX = event.offsetX;
  9381. // event.pinchY = event.offsetY;
  9382. // event.pinchScale = event.scale;
  9383. // proxy.handler.dispatchToElement(event.target, 'pinch', event);
  9384. // }
  9385. // }
  9386. /**
  9387. * Prevent mouse event from being dispatched after Touch Events action
  9388. * @see <https://github.com/deltakosh/handjs/blob/master/src/hand.base.js>
  9389. * 1. Mobile browsers dispatch mouse events 300ms after touchend.
  9390. * 2. Chrome for Android dispatch mousedown for long-touch about 650ms
  9391. * Result: Blocking Mouse Events for 700ms.
  9392. */
  9393. function setTouchTimer(instance) {
  9394. instance._touching = true;
  9395. clearTimeout(instance._touchTimer);
  9396. instance._touchTimer = setTimeout(function () {
  9397. instance._touching = false;
  9398. }, 700);
  9399. }
  9400. var domHandlers = {
  9401. /**
  9402. * Mouse move handler
  9403. * @inner
  9404. * @param {Event} event
  9405. */
  9406. mousemove: function (event) {
  9407. event = normalizeEvent(this.dom, event);
  9408. this.trigger('mousemove', event);
  9409. },
  9410. /**
  9411. * Mouse out handler
  9412. * @inner
  9413. * @param {Event} event
  9414. */
  9415. mouseout: function (event) {
  9416. event = normalizeEvent(this.dom, event);
  9417. var element = event.toElement || event.relatedTarget;
  9418. if (element !== this.dom) {
  9419. while (element && element.nodeType !== 9) {
  9420. // 忽略包含在root中的dom引起的mouseOut
  9421. if (element === this.dom) {
  9422. return;
  9423. }
  9424. element = element.parentNode;
  9425. }
  9426. }
  9427. this.trigger('mouseout', event);
  9428. },
  9429. /**
  9430. * Touch开始响应函数
  9431. * @inner
  9432. * @param {Event} event
  9433. */
  9434. touchstart: function (event) {
  9435. // Default mouse behaviour should not be disabled here.
  9436. // For example, page may needs to be slided.
  9437. event = normalizeEvent(this.dom, event);
  9438. // Mark touch, which is useful in distinguish touch and
  9439. // mouse event in upper applicatoin.
  9440. event.zrByTouch = true;
  9441. this._lastTouchMoment = new Date();
  9442. this.handler.processGesture(this, event, 'start');
  9443. // In touch device, trigger `mousemove`(`mouseover`) should
  9444. // be triggered, and must before `mousedown` triggered.
  9445. domHandlers.mousemove.call(this, event);
  9446. domHandlers.mousedown.call(this, event);
  9447. setTouchTimer(this);
  9448. },
  9449. /**
  9450. * Touch移动响应函数
  9451. * @inner
  9452. * @param {Event} event
  9453. */
  9454. touchmove: function (event) {
  9455. event = normalizeEvent(this.dom, event);
  9456. // Mark touch, which is useful in distinguish touch and
  9457. // mouse event in upper applicatoin.
  9458. event.zrByTouch = true;
  9459. this.handler.processGesture(this, event, 'change');
  9460. // Mouse move should always be triggered no matter whether
  9461. // there is gestrue event, because mouse move and pinch may
  9462. // be used at the same time.
  9463. domHandlers.mousemove.call(this, event);
  9464. setTouchTimer(this);
  9465. },
  9466. /**
  9467. * Touch结束响应函数
  9468. * @inner
  9469. * @param {Event} event
  9470. */
  9471. touchend: function (event) {
  9472. event = normalizeEvent(this.dom, event);
  9473. // Mark touch, which is useful in distinguish touch and
  9474. // mouse event in upper applicatoin.
  9475. event.zrByTouch = true;
  9476. this.handler.processGesture(this, event, 'end');
  9477. domHandlers.mouseup.call(this, event);
  9478. // Do not trigger `mouseout` here, in spite of `mousemove`(`mouseover`) is
  9479. // triggered in `touchstart`. This seems to be illogical, but by this mechanism,
  9480. // we can conveniently implement "hover style" in both PC and touch device just
  9481. // by listening to `mouseover` to add "hover style" and listening to `mouseout`
  9482. // to remove "hover style" on an element, without any additional code for
  9483. // compatibility. (`mouseout` will not be triggered in `touchend`, so "hover
  9484. // style" will remain for user view)
  9485. // click event should always be triggered no matter whether
  9486. // there is gestrue event. System click can not be prevented.
  9487. if (+new Date() - this._lastTouchMoment < TOUCH_CLICK_DELAY) {
  9488. domHandlers.click.call(this, event);
  9489. }
  9490. setTouchTimer(this);
  9491. },
  9492. pointerdown: function (event) {
  9493. domHandlers.mousedown.call(this, event);
  9494. // if (useMSGuesture(this, event)) {
  9495. // this._msGesture.addPointer(event.pointerId);
  9496. // }
  9497. },
  9498. pointermove: function (event) {
  9499. // FIXME
  9500. // pointermove is so sensitive that it always triggered when
  9501. // tap(click) on touch screen, which affect some judgement in
  9502. // upper application. So, we dont support mousemove on MS touch
  9503. // device yet.
  9504. if (!isPointerFromTouch(event)) {
  9505. domHandlers.mousemove.call(this, event);
  9506. }
  9507. },
  9508. pointerup: function (event) {
  9509. domHandlers.mouseup.call(this, event);
  9510. },
  9511. pointerout: function (event) {
  9512. // pointerout will be triggered when tap on touch screen
  9513. // (IE11+/Edge on MS Surface) after click event triggered,
  9514. // which is inconsistent with the mousout behavior we defined
  9515. // in touchend. So we unify them.
  9516. // (check domHandlers.touchend for detailed explanation)
  9517. if (!isPointerFromTouch(event)) {
  9518. domHandlers.mouseout.call(this, event);
  9519. }
  9520. }
  9521. };
  9522. function isPointerFromTouch(event) {
  9523. var pointerType = event.pointerType;
  9524. return pointerType === 'pen' || pointerType === 'touch';
  9525. }
  9526. // function useMSGuesture(handlerProxy, event) {
  9527. // return isPointerFromTouch(event) && !!handlerProxy._msGesture;
  9528. // }
  9529. // Common handlers
  9530. each$1(['click', 'mousedown', 'mouseup', 'mousewheel', 'dblclick', 'contextmenu'], function (name) {
  9531. domHandlers[name] = function (event) {
  9532. event = normalizeEvent(this.dom, event);
  9533. this.trigger(name, event);
  9534. };
  9535. });
  9536. /**
  9537. * 为控制类实例初始化dom 事件处理函数
  9538. *
  9539. * @inner
  9540. * @param {module:zrender/Handler} instance 控制类实例
  9541. */
  9542. function initDomHandler(instance) {
  9543. each$1(touchHandlerNames, function (name) {
  9544. instance._handlers[name] = bind(domHandlers[name], instance);
  9545. });
  9546. each$1(pointerHandlerNames, function (name) {
  9547. instance._handlers[name] = bind(domHandlers[name], instance);
  9548. });
  9549. each$1(mouseHandlerNames, function (name) {
  9550. instance._handlers[name] = makeMouseHandler(domHandlers[name], instance);
  9551. });
  9552. function makeMouseHandler(fn, instance) {
  9553. return function () {
  9554. if (instance._touching) {
  9555. return;
  9556. }
  9557. return fn.apply(instance, arguments);
  9558. };
  9559. }
  9560. }
  9561. function HandlerDomProxy(dom) {
  9562. Eventful.call(this);
  9563. this.dom = dom;
  9564. /**
  9565. * @private
  9566. * @type {boolean}
  9567. */
  9568. this._touching = false;
  9569. /**
  9570. * @private
  9571. * @type {number}
  9572. */
  9573. this._touchTimer;
  9574. this._handlers = {};
  9575. initDomHandler(this);
  9576. if (env$1.pointerEventsSupported) { // Only IE11+/Edge
  9577. // 1. On devices that both enable touch and mouse (e.g., MS Surface and lenovo X240),
  9578. // IE11+/Edge do not trigger touch event, but trigger pointer event and mouse event
  9579. // at the same time.
  9580. // 2. On MS Surface, it probablely only trigger mousedown but no mouseup when tap on
  9581. // screen, which do not occurs in pointer event.
  9582. // So we use pointer event to both detect touch gesture and mouse behavior.
  9583. mountHandlers(pointerHandlerNames, this);
  9584. // FIXME
  9585. // Note: MS Gesture require CSS touch-action set. But touch-action is not reliable,
  9586. // which does not prevent defuault behavior occasionally (which may cause view port
  9587. // zoomed in but use can not zoom it back). And event.preventDefault() does not work.
  9588. // So we have to not to use MSGesture and not to support touchmove and pinch on MS
  9589. // touch screen. And we only support click behavior on MS touch screen now.
  9590. // MS Gesture Event is only supported on IE11+/Edge and on Windows 8+.
  9591. // We dont support touch on IE on win7.
  9592. // See <https://msdn.microsoft.com/en-us/library/dn433243(v=vs.85).aspx>
  9593. // if (typeof MSGesture === 'function') {
  9594. // (this._msGesture = new MSGesture()).target = dom; // jshint ignore:line
  9595. // dom.addEventListener('MSGestureChange', onMSGestureChange);
  9596. // }
  9597. }
  9598. else {
  9599. if (env$1.touchEventsSupported) {
  9600. mountHandlers(touchHandlerNames, this);
  9601. // Handler of 'mouseout' event is needed in touch mode, which will be mounted below.
  9602. // addEventListener(root, 'mouseout', this._mouseoutHandler);
  9603. }
  9604. // 1. Considering some devices that both enable touch and mouse event (like on MS Surface
  9605. // and lenovo X240, @see #2350), we make mouse event be always listened, otherwise
  9606. // mouse event can not be handle in those devices.
  9607. // 2. On MS Surface, Chrome will trigger both touch event and mouse event. How to prevent
  9608. // mouseevent after touch event triggered, see `setTouchTimer`.
  9609. mountHandlers(mouseHandlerNames, this);
  9610. }
  9611. function mountHandlers(handlerNames, instance) {
  9612. each$1(handlerNames, function (name) {
  9613. addEventListener(dom, eventNameFix(name), instance._handlers[name]);
  9614. }, instance);
  9615. }
  9616. }
  9617. var handlerDomProxyProto = HandlerDomProxy.prototype;
  9618. handlerDomProxyProto.dispose = function () {
  9619. var handlerNames = mouseHandlerNames.concat(touchHandlerNames);
  9620. for (var i = 0; i < handlerNames.length; i++) {
  9621. var name = handlerNames[i];
  9622. removeEventListener(this.dom, eventNameFix(name), this._handlers[name]);
  9623. }
  9624. };
  9625. handlerDomProxyProto.setCursor = function (cursorStyle) {
  9626. this.dom.style && (this.dom.style.cursor = cursorStyle || 'default');
  9627. };
  9628. mixin(HandlerDomProxy, Eventful);
  9629. /*!
  9630. * ZRender, a high performance 2d drawing library.
  9631. *
  9632. * Copyright (c) 2013, Baidu Inc.
  9633. * All rights reserved.
  9634. *
  9635. * LICENSE
  9636. * https://github.com/ecomfe/zrender/blob/master/LICENSE.txt
  9637. */
  9638. var useVML = !env$1.canvasSupported;
  9639. var painterCtors = {
  9640. canvas: Painter
  9641. };
  9642. var instances$1 = {}; // ZRender实例map索引
  9643. /**
  9644. * @type {string}
  9645. */
  9646. var version$1 = '4.1.0';
  9647. /**
  9648. * Initializing a zrender instance
  9649. * @param {HTMLElement} dom
  9650. * @param {Object} [opts]
  9651. * @param {string} [opts.renderer='canvas'] 'canvas' or 'svg'
  9652. * @param {number} [opts.devicePixelRatio]
  9653. * @param {number|string} [opts.width] Can be 'auto' (the same as null/undefined)
  9654. * @param {number|string} [opts.height] Can be 'auto' (the same as null/undefined)
  9655. * @return {module:zrender/ZRender}
  9656. */
  9657. function init$1(dom, opts) {
  9658. var zr = new ZRender(guid(), dom, opts);
  9659. instances$1[zr.id] = zr;
  9660. return zr;
  9661. }
  9662. /**
  9663. * Dispose zrender instance
  9664. * @param {module:zrender/ZRender} zr
  9665. */
  9666. function dispose$1(zr) {
  9667. if (zr) {
  9668. zr.dispose();
  9669. }
  9670. else {
  9671. for (var key in instances$1) {
  9672. if (instances$1.hasOwnProperty(key)) {
  9673. instances$1[key].dispose();
  9674. }
  9675. }
  9676. instances$1 = {};
  9677. }
  9678. return this;
  9679. }
  9680. /**
  9681. * Get zrender instance by id
  9682. * @param {string} id zrender instance id
  9683. * @return {module:zrender/ZRender}
  9684. */
  9685. function getInstance(id) {
  9686. return instances$1[id];
  9687. }
  9688. function registerPainter(name, Ctor) {
  9689. painterCtors[name] = Ctor;
  9690. }
  9691. function delInstance(id) {
  9692. delete instances$1[id];
  9693. }
  9694. /**
  9695. * @module zrender/ZRender
  9696. */
  9697. /**
  9698. * @constructor
  9699. * @alias module:zrender/ZRender
  9700. * @param {string} id
  9701. * @param {HTMLElement} dom
  9702. * @param {Object} opts
  9703. * @param {string} [opts.renderer='canvas'] 'canvas' or 'svg'
  9704. * @param {number} [opts.devicePixelRatio]
  9705. * @param {number} [opts.width] Can be 'auto' (the same as null/undefined)
  9706. * @param {number} [opts.height] Can be 'auto' (the same as null/undefined)
  9707. */
  9708. var ZRender = function (id, dom, opts) {
  9709. opts = opts || {};
  9710. /**
  9711. * @type {HTMLDomElement}
  9712. */
  9713. this.dom = dom;
  9714. /**
  9715. * @type {string}
  9716. */
  9717. this.id = id;
  9718. var self = this;
  9719. var storage = new Storage();
  9720. var rendererType = opts.renderer;
  9721. // TODO WebGL
  9722. if (useVML) {
  9723. if (!painterCtors.vml) {
  9724. throw new Error('You need to require \'zrender/vml/vml\' to support IE8');
  9725. }
  9726. rendererType = 'vml';
  9727. }
  9728. else if (!rendererType || !painterCtors[rendererType]) {
  9729. rendererType = 'canvas';
  9730. }
  9731. var painter = new painterCtors[rendererType](dom, storage, opts, id);
  9732. this.storage = storage;
  9733. this.painter = painter;
  9734. var handerProxy = (!env$1.node && !env$1.worker) ? new HandlerDomProxy(painter.getViewportRoot()) : null;
  9735. this.handler = new Handler(storage, painter, handerProxy, painter.root);
  9736. /**
  9737. * @type {module:zrender/animation/Animation}
  9738. */
  9739. this.animation = new Animation({
  9740. stage: {
  9741. update: bind(this.flush, this)
  9742. }
  9743. });
  9744. this.animation.start();
  9745. /**
  9746. * @type {boolean}
  9747. * @private
  9748. */
  9749. this._needsRefresh;
  9750. // 修改 storage.delFromStorage, 每次删除元素之前删除动画
  9751. // FIXME 有点ugly
  9752. var oldDelFromStorage = storage.delFromStorage;
  9753. var oldAddToStorage = storage.addToStorage;
  9754. storage.delFromStorage = function (el) {
  9755. oldDelFromStorage.call(storage, el);
  9756. el && el.removeSelfFromZr(self);
  9757. };
  9758. storage.addToStorage = function (el) {
  9759. oldAddToStorage.call(storage, el);
  9760. el.addSelfToZr(self);
  9761. };
  9762. };
  9763. ZRender.prototype = {
  9764. constructor: ZRender,
  9765. /**
  9766. * 获取实例唯一标识
  9767. * @return {string}
  9768. */
  9769. getId: function () {
  9770. return this.id;
  9771. },
  9772. /**
  9773. * 添加元素
  9774. * @param {module:zrender/Element} el
  9775. */
  9776. add: function (el) {
  9777. this.storage.addRoot(el);
  9778. this._needsRefresh = true;
  9779. },
  9780. /**
  9781. * 删除元素
  9782. * @param {module:zrender/Element} el
  9783. */
  9784. remove: function (el) {
  9785. this.storage.delRoot(el);
  9786. this._needsRefresh = true;
  9787. },
  9788. /**
  9789. * Change configuration of layer
  9790. * @param {string} zLevel
  9791. * @param {Object} config
  9792. * @param {string} [config.clearColor=0] Clear color
  9793. * @param {string} [config.motionBlur=false] If enable motion blur
  9794. * @param {number} [config.lastFrameAlpha=0.7] Motion blur factor. Larger value cause longer trailer
  9795. */
  9796. configLayer: function (zLevel, config) {
  9797. if (this.painter.configLayer) {
  9798. this.painter.configLayer(zLevel, config);
  9799. }
  9800. this._needsRefresh = true;
  9801. },
  9802. /**
  9803. * Set background color
  9804. * @param {string} backgroundColor
  9805. */
  9806. setBackgroundColor: function (backgroundColor) {
  9807. if (this.painter.setBackgroundColor) {
  9808. this.painter.setBackgroundColor(backgroundColor);
  9809. }
  9810. this._needsRefresh = true;
  9811. },
  9812. /**
  9813. * Repaint the canvas immediately
  9814. */
  9815. refreshImmediately: function () {
  9816. // var start = new Date();
  9817. // Clear needsRefresh ahead to avoid something wrong happens in refresh
  9818. // Or it will cause zrender refreshes again and again.
  9819. this._needsRefresh = this._needsRefreshHover = false;
  9820. this.painter.refresh();
  9821. // Avoid trigger zr.refresh in Element#beforeUpdate hook
  9822. this._needsRefresh = this._needsRefreshHover = false;
  9823. // var end = new Date();
  9824. // var log = document.getElementById('log');
  9825. // if (log) {
  9826. // log.innerHTML = log.innerHTML + '<br>' + (end - start);
  9827. // }
  9828. },
  9829. /**
  9830. * Mark and repaint the canvas in the next frame of browser
  9831. */
  9832. refresh: function () {
  9833. this._needsRefresh = true;
  9834. },
  9835. /**
  9836. * Perform all refresh
  9837. */
  9838. flush: function () {
  9839. var triggerRendered;
  9840. if (this._needsRefresh) {
  9841. triggerRendered = true;
  9842. this.refreshImmediately();
  9843. }
  9844. if (this._needsRefreshHover) {
  9845. triggerRendered = true;
  9846. this.refreshHoverImmediately();
  9847. }
  9848. triggerRendered && this.trigger('rendered');
  9849. },
  9850. /**
  9851. * Add element to hover layer
  9852. * @param {module:zrender/Element} el
  9853. * @param {Object} style
  9854. */
  9855. addHover: function (el, style) {
  9856. if (this.painter.addHover) {
  9857. var elMirror = this.painter.addHover(el, style);
  9858. this.refreshHover();
  9859. return elMirror;
  9860. }
  9861. },
  9862. /**
  9863. * Add element from hover layer
  9864. * @param {module:zrender/Element} el
  9865. */
  9866. removeHover: function (el) {
  9867. if (this.painter.removeHover) {
  9868. this.painter.removeHover(el);
  9869. this.refreshHover();
  9870. }
  9871. },
  9872. /**
  9873. * Clear all hover elements in hover layer
  9874. * @param {module:zrender/Element} el
  9875. */
  9876. clearHover: function () {
  9877. if (this.painter.clearHover) {
  9878. this.painter.clearHover();
  9879. this.refreshHover();
  9880. }
  9881. },
  9882. /**
  9883. * Refresh hover in next frame
  9884. */
  9885. refreshHover: function () {
  9886. this._needsRefreshHover = true;
  9887. },
  9888. /**
  9889. * Refresh hover immediately
  9890. */
  9891. refreshHoverImmediately: function () {
  9892. this._needsRefreshHover = false;
  9893. this.painter.refreshHover && this.painter.refreshHover();
  9894. },
  9895. /**
  9896. * Resize the canvas.
  9897. * Should be invoked when container size is changed
  9898. * @param {Object} [opts]
  9899. * @param {number|string} [opts.width] Can be 'auto' (the same as null/undefined)
  9900. * @param {number|string} [opts.height] Can be 'auto' (the same as null/undefined)
  9901. */
  9902. resize: function (opts) {
  9903. opts = opts || {};
  9904. this.painter.resize(opts.width, opts.height);
  9905. this.handler.resize();
  9906. },
  9907. /**
  9908. * Stop and clear all animation immediately
  9909. */
  9910. clearAnimation: function () {
  9911. this.animation.clear();
  9912. },
  9913. /**
  9914. * Get container width
  9915. */
  9916. getWidth: function () {
  9917. return this.painter.getWidth();
  9918. },
  9919. /**
  9920. * Get container height
  9921. */
  9922. getHeight: function () {
  9923. return this.painter.getHeight();
  9924. },
  9925. /**
  9926. * Export the canvas as Base64 URL
  9927. * @param {string} type
  9928. * @param {string} [backgroundColor='#fff']
  9929. * @return {string} Base64 URL
  9930. */
  9931. // toDataURL: function(type, backgroundColor) {
  9932. // return this.painter.getRenderedCanvas({
  9933. // backgroundColor: backgroundColor
  9934. // }).toDataURL(type);
  9935. // },
  9936. /**
  9937. * Converting a path to image.
  9938. * It has much better performance of drawing image rather than drawing a vector path.
  9939. * @param {module:zrender/graphic/Path} e
  9940. * @param {number} width
  9941. * @param {number} height
  9942. */
  9943. pathToImage: function (e, dpr) {
  9944. return this.painter.pathToImage(e, dpr);
  9945. },
  9946. /**
  9947. * Set default cursor
  9948. * @param {string} [cursorStyle='default'] 例如 crosshair
  9949. */
  9950. setCursorStyle: function (cursorStyle) {
  9951. this.handler.setCursorStyle(cursorStyle);
  9952. },
  9953. /**
  9954. * Find hovered element
  9955. * @param {number} x
  9956. * @param {number} y
  9957. * @return {Object} {target, topTarget}
  9958. */
  9959. findHover: function (x, y) {
  9960. return this.handler.findHover(x, y);
  9961. },
  9962. /**
  9963. * Bind event
  9964. *
  9965. * @param {string} eventName Event name
  9966. * @param {Function} eventHandler Handler function
  9967. * @param {Object} [context] Context object
  9968. */
  9969. on: function (eventName, eventHandler, context) {
  9970. this.handler.on(eventName, eventHandler, context);
  9971. },
  9972. /**
  9973. * Unbind event
  9974. * @param {string} eventName Event name
  9975. * @param {Function} [eventHandler] Handler function
  9976. */
  9977. off: function (eventName, eventHandler) {
  9978. this.handler.off(eventName, eventHandler);
  9979. },
  9980. /**
  9981. * Trigger event manually
  9982. *
  9983. * @param {string} eventName Event name
  9984. * @param {event=} event Event object
  9985. */
  9986. trigger: function (eventName, event) {
  9987. this.handler.trigger(eventName, event);
  9988. },
  9989. /**
  9990. * Clear all objects and the canvas.
  9991. */
  9992. clear: function () {
  9993. this.storage.delRoot();
  9994. this.painter.clear();
  9995. },
  9996. /**
  9997. * Dispose self.
  9998. */
  9999. dispose: function () {
  10000. this.animation.stop();
  10001. this.clear();
  10002. this.storage.dispose();
  10003. this.painter.dispose();
  10004. this.handler.dispose();
  10005. this.animation =
  10006. this.storage =
  10007. this.painter =
  10008. this.handler = null;
  10009. delInstance(this.id);
  10010. }
  10011. };
  10012. var zrender = (Object.freeze || Object)({
  10013. version: version$1,
  10014. init: init$1,
  10015. dispose: dispose$1,
  10016. getInstance: getInstance,
  10017. registerPainter: registerPainter
  10018. });
  10019. /*
  10020. * Licensed to the Apache Software Foundation (ASF) under one
  10021. * or more contributor license agreements. See the NOTICE file
  10022. * distributed with this work for additional information
  10023. * regarding copyright ownership. The ASF licenses this file
  10024. * to you under the Apache License, Version 2.0 (the
  10025. * "License"); you may not use this file except in compliance
  10026. * with the License. You may obtain a copy of the License at
  10027. *
  10028. * http://www.apache.org/licenses/LICENSE-2.0
  10029. *
  10030. * Unless required by applicable law or agreed to in writing,
  10031. * software distributed under the License is distributed on an
  10032. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  10033. * KIND, either express or implied. See the License for the
  10034. * specific language governing permissions and limitations
  10035. * under the License.
  10036. */
  10037. var each$2 = each$1;
  10038. var isObject$2 = isObject$1;
  10039. var isArray$1 = isArray;
  10040. /**
  10041. * Make the name displayable. But we should
  10042. * make sure it is not duplicated with user
  10043. * specified name, so use '\0';
  10044. */
  10045. var DUMMY_COMPONENT_NAME_PREFIX = 'series\0';
  10046. /**
  10047. * If value is not array, then translate it to array.
  10048. * @param {*} value
  10049. * @return {Array} [value] or value
  10050. */
  10051. function normalizeToArray(value) {
  10052. return value instanceof Array
  10053. ? value
  10054. : value == null
  10055. ? []
  10056. : [value];
  10057. }
  10058. /**
  10059. * Sync default option between normal and emphasis like `position` and `show`
  10060. * In case some one will write code like
  10061. * label: {
  10062. * show: false,
  10063. * position: 'outside',
  10064. * fontSize: 18
  10065. * },
  10066. * emphasis: {
  10067. * label: { show: true }
  10068. * }
  10069. * @param {Object} opt
  10070. * @param {string} key
  10071. * @param {Array.<string>} subOpts
  10072. */
  10073. function defaultEmphasis(opt, key, subOpts) {
  10074. // Caution: performance sensitive.
  10075. if (opt) {
  10076. opt[key] = opt[key] || {};
  10077. opt.emphasis = opt.emphasis || {};
  10078. opt.emphasis[key] = opt.emphasis[key] || {};
  10079. // Default emphasis option from normal
  10080. for (var i = 0, len = subOpts.length; i < len; i++) {
  10081. var subOptName = subOpts[i];
  10082. if (!opt.emphasis[key].hasOwnProperty(subOptName)
  10083. && opt[key].hasOwnProperty(subOptName)
  10084. ) {
  10085. opt.emphasis[key][subOptName] = opt[key][subOptName];
  10086. }
  10087. }
  10088. }
  10089. }
  10090. var TEXT_STYLE_OPTIONS = [
  10091. 'fontStyle', 'fontWeight', 'fontSize', 'fontFamily',
  10092. 'rich', 'tag', 'color', 'textBorderColor', 'textBorderWidth',
  10093. 'width', 'height', 'lineHeight', 'align', 'verticalAlign', 'baseline',
  10094. 'shadowColor', 'shadowBlur', 'shadowOffsetX', 'shadowOffsetY',
  10095. 'textShadowColor', 'textShadowBlur', 'textShadowOffsetX', 'textShadowOffsetY',
  10096. 'backgroundColor', 'borderColor', 'borderWidth', 'borderRadius', 'padding'
  10097. ];
  10098. // modelUtil.LABEL_OPTIONS = modelUtil.TEXT_STYLE_OPTIONS.concat([
  10099. // 'position', 'offset', 'rotate', 'origin', 'show', 'distance', 'formatter',
  10100. // 'fontStyle', 'fontWeight', 'fontSize', 'fontFamily',
  10101. // // FIXME: deprecated, check and remove it.
  10102. // 'textStyle'
  10103. // ]);
  10104. /**
  10105. * The method do not ensure performance.
  10106. * data could be [12, 2323, {value: 223}, [1221, 23], {value: [2, 23]}]
  10107. * This helper method retieves value from data.
  10108. * @param {string|number|Date|Array|Object} dataItem
  10109. * @return {number|string|Date|Array.<number|string|Date>}
  10110. */
  10111. function getDataItemValue(dataItem) {
  10112. return (isObject$2(dataItem) && !isArray$1(dataItem) && !(dataItem instanceof Date))
  10113. ? dataItem.value : dataItem;
  10114. }
  10115. /**
  10116. * data could be [12, 2323, {value: 223}, [1221, 23], {value: [2, 23]}]
  10117. * This helper method determine if dataItem has extra option besides value
  10118. * @param {string|number|Date|Array|Object} dataItem
  10119. */
  10120. function isDataItemOption(dataItem) {
  10121. return isObject$2(dataItem)
  10122. && !(dataItem instanceof Array);
  10123. // // markLine data can be array
  10124. // && !(dataItem[0] && isObject(dataItem[0]) && !(dataItem[0] instanceof Array));
  10125. }
  10126. /**
  10127. * Mapping to exists for merge.
  10128. *
  10129. * @public
  10130. * @param {Array.<Object>|Array.<module:echarts/model/Component>} exists
  10131. * @param {Object|Array.<Object>} newCptOptions
  10132. * @return {Array.<Object>} Result, like [{exist: ..., option: ...}, {}],
  10133. * index of which is the same as exists.
  10134. */
  10135. function mappingToExists(exists, newCptOptions) {
  10136. // Mapping by the order by original option (but not order of
  10137. // new option) in merge mode. Because we should ensure
  10138. // some specified index (like xAxisIndex) is consistent with
  10139. // original option, which is easy to understand, espatially in
  10140. // media query. And in most case, merge option is used to
  10141. // update partial option but not be expected to change order.
  10142. newCptOptions = (newCptOptions || []).slice();
  10143. var result = map(exists || [], function (obj, index) {
  10144. return {exist: obj};
  10145. });
  10146. // Mapping by id or name if specified.
  10147. each$2(newCptOptions, function (cptOption, index) {
  10148. if (!isObject$2(cptOption)) {
  10149. return;
  10150. }
  10151. // id has highest priority.
  10152. for (var i = 0; i < result.length; i++) {
  10153. if (!result[i].option // Consider name: two map to one.
  10154. && cptOption.id != null
  10155. && result[i].exist.id === cptOption.id + ''
  10156. ) {
  10157. result[i].option = cptOption;
  10158. newCptOptions[index] = null;
  10159. return;
  10160. }
  10161. }
  10162. for (var i = 0; i < result.length; i++) {
  10163. var exist = result[i].exist;
  10164. if (!result[i].option // Consider name: two map to one.
  10165. // Can not match when both ids exist but different.
  10166. && (exist.id == null || cptOption.id == null)
  10167. && cptOption.name != null
  10168. && !isIdInner(cptOption)
  10169. && !isIdInner(exist)
  10170. && exist.name === cptOption.name + ''
  10171. ) {
  10172. result[i].option = cptOption;
  10173. newCptOptions[index] = null;
  10174. return;
  10175. }
  10176. }
  10177. });
  10178. // Otherwise mapping by index.
  10179. each$2(newCptOptions, function (cptOption, index) {
  10180. if (!isObject$2(cptOption)) {
  10181. return;
  10182. }
  10183. var i = 0;
  10184. for (; i < result.length; i++) {
  10185. var exist = result[i].exist;
  10186. if (!result[i].option
  10187. // Existing model that already has id should be able to
  10188. // mapped to (because after mapping performed model may
  10189. // be assigned with a id, whish should not affect next
  10190. // mapping), except those has inner id.
  10191. && !isIdInner(exist)
  10192. // Caution:
  10193. // Do not overwrite id. But name can be overwritten,
  10194. // because axis use name as 'show label text'.
  10195. // 'exist' always has id and name and we dont
  10196. // need to check it.
  10197. && cptOption.id == null
  10198. ) {
  10199. result[i].option = cptOption;
  10200. break;
  10201. }
  10202. }
  10203. if (i >= result.length) {
  10204. result.push({option: cptOption});
  10205. }
  10206. });
  10207. return result;
  10208. }
  10209. /**
  10210. * Make id and name for mapping result (result of mappingToExists)
  10211. * into `keyInfo` field.
  10212. *
  10213. * @public
  10214. * @param {Array.<Object>} Result, like [{exist: ..., option: ...}, {}],
  10215. * which order is the same as exists.
  10216. * @return {Array.<Object>} The input.
  10217. */
  10218. function makeIdAndName(mapResult) {
  10219. // We use this id to hash component models and view instances
  10220. // in echarts. id can be specified by user, or auto generated.
  10221. // The id generation rule ensures new view instance are able
  10222. // to mapped to old instance when setOption are called in
  10223. // no-merge mode. So we generate model id by name and plus
  10224. // type in view id.
  10225. // name can be duplicated among components, which is convenient
  10226. // to specify multi components (like series) by one name.
  10227. // Ensure that each id is distinct.
  10228. var idMap = createHashMap();
  10229. each$2(mapResult, function (item, index) {
  10230. var existCpt = item.exist;
  10231. existCpt && idMap.set(existCpt.id, item);
  10232. });
  10233. each$2(mapResult, function (item, index) {
  10234. var opt = item.option;
  10235. assert$1(
  10236. !opt || opt.id == null || !idMap.get(opt.id) || idMap.get(opt.id) === item,
  10237. 'id duplicates: ' + (opt && opt.id)
  10238. );
  10239. opt && opt.id != null && idMap.set(opt.id, item);
  10240. !item.keyInfo && (item.keyInfo = {});
  10241. });
  10242. // Make name and id.
  10243. each$2(mapResult, function (item, index) {
  10244. var existCpt = item.exist;
  10245. var opt = item.option;
  10246. var keyInfo = item.keyInfo;
  10247. if (!isObject$2(opt)) {
  10248. return;
  10249. }
  10250. // name can be overwitten. Consider case: axis.name = '20km'.
  10251. // But id generated by name will not be changed, which affect
  10252. // only in that case: setOption with 'not merge mode' and view
  10253. // instance will be recreated, which can be accepted.
  10254. keyInfo.name = opt.name != null
  10255. ? opt.name + ''
  10256. : existCpt
  10257. ? existCpt.name
  10258. // Avoid diffferent series has the same name,
  10259. // because name may be used like in color pallet.
  10260. : DUMMY_COMPONENT_NAME_PREFIX + index;
  10261. if (existCpt) {
  10262. keyInfo.id = existCpt.id;
  10263. }
  10264. else if (opt.id != null) {
  10265. keyInfo.id = opt.id + '';
  10266. }
  10267. else {
  10268. // Consider this situatoin:
  10269. // optionA: [{name: 'a'}, {name: 'a'}, {..}]
  10270. // optionB [{..}, {name: 'a'}, {name: 'a'}]
  10271. // Series with the same name between optionA and optionB
  10272. // should be mapped.
  10273. var idNum = 0;
  10274. do {
  10275. keyInfo.id = '\0' + keyInfo.name + '\0' + idNum++;
  10276. }
  10277. while (idMap.get(keyInfo.id));
  10278. }
  10279. idMap.set(keyInfo.id, item);
  10280. });
  10281. }
  10282. function isNameSpecified(componentModel) {
  10283. var name = componentModel.name;
  10284. // Is specified when `indexOf` get -1 or > 0.
  10285. return !!(name && name.indexOf(DUMMY_COMPONENT_NAME_PREFIX));
  10286. }
  10287. /**
  10288. * @public
  10289. * @param {Object} cptOption
  10290. * @return {boolean}
  10291. */
  10292. function isIdInner(cptOption) {
  10293. return isObject$2(cptOption)
  10294. && cptOption.id
  10295. && (cptOption.id + '').indexOf('\0_ec_\0') === 0;
  10296. }
  10297. /**
  10298. * A helper for removing duplicate items between batchA and batchB,
  10299. * and in themselves, and categorize by series.
  10300. *
  10301. * @param {Array.<Object>} batchA Like: [{seriesId: 2, dataIndex: [32, 4, 5]}, ...]
  10302. * @param {Array.<Object>} batchB Like: [{seriesId: 2, dataIndex: [32, 4, 5]}, ...]
  10303. * @return {Array.<Array.<Object>, Array.<Object>>} result: [resultBatchA, resultBatchB]
  10304. */
  10305. function compressBatches(batchA, batchB) {
  10306. var mapA = {};
  10307. var mapB = {};
  10308. makeMap(batchA || [], mapA);
  10309. makeMap(batchB || [], mapB, mapA);
  10310. return [mapToArray(mapA), mapToArray(mapB)];
  10311. function makeMap(sourceBatch, map$$1, otherMap) {
  10312. for (var i = 0, len = sourceBatch.length; i < len; i++) {
  10313. var seriesId = sourceBatch[i].seriesId;
  10314. var dataIndices = normalizeToArray(sourceBatch[i].dataIndex);
  10315. var otherDataIndices = otherMap && otherMap[seriesId];
  10316. for (var j = 0, lenj = dataIndices.length; j < lenj; j++) {
  10317. var dataIndex = dataIndices[j];
  10318. if (otherDataIndices && otherDataIndices[dataIndex]) {
  10319. otherDataIndices[dataIndex] = null;
  10320. }
  10321. else {
  10322. (map$$1[seriesId] || (map$$1[seriesId] = {}))[dataIndex] = 1;
  10323. }
  10324. }
  10325. }
  10326. }
  10327. function mapToArray(map$$1, isData) {
  10328. var result = [];
  10329. for (var i in map$$1) {
  10330. if (map$$1.hasOwnProperty(i) && map$$1[i] != null) {
  10331. if (isData) {
  10332. result.push(+i);
  10333. }
  10334. else {
  10335. var dataIndices = mapToArray(map$$1[i], true);
  10336. dataIndices.length && result.push({seriesId: i, dataIndex: dataIndices});
  10337. }
  10338. }
  10339. }
  10340. return result;
  10341. }
  10342. }
  10343. /**
  10344. * @param {module:echarts/data/List} data
  10345. * @param {Object} payload Contains dataIndex (means rawIndex) / dataIndexInside / name
  10346. * each of which can be Array or primary type.
  10347. * @return {number|Array.<number>} dataIndex If not found, return undefined/null.
  10348. */
  10349. function queryDataIndex(data, payload) {
  10350. if (payload.dataIndexInside != null) {
  10351. return payload.dataIndexInside;
  10352. }
  10353. else if (payload.dataIndex != null) {
  10354. return isArray(payload.dataIndex)
  10355. ? map(payload.dataIndex, function (value) {
  10356. return data.indexOfRawIndex(value);
  10357. })
  10358. : data.indexOfRawIndex(payload.dataIndex);
  10359. }
  10360. else if (payload.name != null) {
  10361. return isArray(payload.name)
  10362. ? map(payload.name, function (value) {
  10363. return data.indexOfName(value);
  10364. })
  10365. : data.indexOfName(payload.name);
  10366. }
  10367. }
  10368. /**
  10369. * Enable property storage to any host object.
  10370. * Notice: Serialization is not supported.
  10371. *
  10372. * For example:
  10373. * var inner = zrUitl.makeInner();
  10374. *
  10375. * function some1(hostObj) {
  10376. * inner(hostObj).someProperty = 1212;
  10377. * ...
  10378. * }
  10379. * function some2() {
  10380. * var fields = inner(this);
  10381. * fields.someProperty1 = 1212;
  10382. * fields.someProperty2 = 'xx';
  10383. * ...
  10384. * }
  10385. *
  10386. * @return {Function}
  10387. */
  10388. function makeInner() {
  10389. // Consider different scope by es module import.
  10390. var key = '__\0ec_inner_' + innerUniqueIndex++ + '_' + Math.random().toFixed(5);
  10391. return function (hostObj) {
  10392. return hostObj[key] || (hostObj[key] = {});
  10393. };
  10394. }
  10395. var innerUniqueIndex = 0;
  10396. /**
  10397. * @param {module:echarts/model/Global} ecModel
  10398. * @param {string|Object} finder
  10399. * If string, e.g., 'geo', means {geoIndex: 0}.
  10400. * If Object, could contain some of these properties below:
  10401. * {
  10402. * seriesIndex, seriesId, seriesName,
  10403. * geoIndex, geoId, geoName,
  10404. * bmapIndex, bmapId, bmapName,
  10405. * xAxisIndex, xAxisId, xAxisName,
  10406. * yAxisIndex, yAxisId, yAxisName,
  10407. * gridIndex, gridId, gridName,
  10408. * ... (can be extended)
  10409. * }
  10410. * Each properties can be number|string|Array.<number>|Array.<string>
  10411. * For example, a finder could be
  10412. * {
  10413. * seriesIndex: 3,
  10414. * geoId: ['aa', 'cc'],
  10415. * gridName: ['xx', 'rr']
  10416. * }
  10417. * xxxIndex can be set as 'all' (means all xxx) or 'none' (means not specify)
  10418. * If nothing or null/undefined specified, return nothing.
  10419. * @param {Object} [opt]
  10420. * @param {string} [opt.defaultMainType]
  10421. * @param {Array.<string>} [opt.includeMainTypes]
  10422. * @return {Object} result like:
  10423. * {
  10424. * seriesModels: [seriesModel1, seriesModel2],
  10425. * seriesModel: seriesModel1, // The first model
  10426. * geoModels: [geoModel1, geoModel2],
  10427. * geoModel: geoModel1, // The first model
  10428. * ...
  10429. * }
  10430. */
  10431. function parseFinder(ecModel, finder, opt) {
  10432. if (isString(finder)) {
  10433. var obj = {};
  10434. obj[finder + 'Index'] = 0;
  10435. finder = obj;
  10436. }
  10437. var defaultMainType = opt && opt.defaultMainType;
  10438. if (defaultMainType
  10439. && !has(finder, defaultMainType + 'Index')
  10440. && !has(finder, defaultMainType + 'Id')
  10441. && !has(finder, defaultMainType + 'Name')
  10442. ) {
  10443. finder[defaultMainType + 'Index'] = 0;
  10444. }
  10445. var result = {};
  10446. each$2(finder, function (value, key) {
  10447. var value = finder[key];
  10448. // Exclude 'dataIndex' and other illgal keys.
  10449. if (key === 'dataIndex' || key === 'dataIndexInside') {
  10450. result[key] = value;
  10451. return;
  10452. }
  10453. var parsedKey = key.match(/^(\w+)(Index|Id|Name)$/) || [];
  10454. var mainType = parsedKey[1];
  10455. var queryType = (parsedKey[2] || '').toLowerCase();
  10456. if (!mainType
  10457. || !queryType
  10458. || value == null
  10459. || (queryType === 'index' && value === 'none')
  10460. || (opt && opt.includeMainTypes && indexOf(opt.includeMainTypes, mainType) < 0)
  10461. ) {
  10462. return;
  10463. }
  10464. var queryParam = {mainType: mainType};
  10465. if (queryType !== 'index' || value !== 'all') {
  10466. queryParam[queryType] = value;
  10467. }
  10468. var models = ecModel.queryComponents(queryParam);
  10469. result[mainType + 'Models'] = models;
  10470. result[mainType + 'Model'] = models[0];
  10471. });
  10472. return result;
  10473. }
  10474. function has(obj, prop) {
  10475. return obj && obj.hasOwnProperty(prop);
  10476. }
  10477. function setAttribute(dom, key, value) {
  10478. dom.setAttribute
  10479. ? dom.setAttribute(key, value)
  10480. : (dom[key] = value);
  10481. }
  10482. function getAttribute(dom, key) {
  10483. return dom.getAttribute
  10484. ? dom.getAttribute(key)
  10485. : dom[key];
  10486. }
  10487. function getTooltipRenderMode(renderModeOption) {
  10488. if (renderModeOption === 'auto') {
  10489. // Using html when `document` exists, use richText otherwise
  10490. return env$1.domSupported ? 'html' : 'richText';
  10491. }
  10492. else {
  10493. return renderModeOption || 'html';
  10494. }
  10495. }
  10496. /**
  10497. * Group a list by key.
  10498. *
  10499. * @param {Array} array
  10500. * @param {Function} getKey
  10501. * param {*} Array item
  10502. * return {string} key
  10503. * @return {Object} Result
  10504. * {Array}: keys,
  10505. * {module:zrender/core/util/HashMap} buckets: {key -> Array}
  10506. */
  10507. function groupData(array, getKey) {
  10508. var buckets = createHashMap();
  10509. var keys = [];
  10510. each$1(array, function (item) {
  10511. var key = getKey(item);
  10512. (buckets.get(key)
  10513. || (keys.push(key), buckets.set(key, []))
  10514. ).push(item);
  10515. });
  10516. return {keys: keys, buckets: buckets};
  10517. }
  10518. /*
  10519. * Licensed to the Apache Software Foundation (ASF) under one
  10520. * or more contributor license agreements. See the NOTICE file
  10521. * distributed with this work for additional information
  10522. * regarding copyright ownership. The ASF licenses this file
  10523. * to you under the Apache License, Version 2.0 (the
  10524. * "License"); you may not use this file except in compliance
  10525. * with the License. You may obtain a copy of the License at
  10526. *
  10527. * http://www.apache.org/licenses/LICENSE-2.0
  10528. *
  10529. * Unless required by applicable law or agreed to in writing,
  10530. * software distributed under the License is distributed on an
  10531. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  10532. * KIND, either express or implied. See the License for the
  10533. * specific language governing permissions and limitations
  10534. * under the License.
  10535. */
  10536. var TYPE_DELIMITER = '.';
  10537. var IS_CONTAINER = '___EC__COMPONENT__CONTAINER___';
  10538. /**
  10539. * Notice, parseClassType('') should returns {main: '', sub: ''}
  10540. * @public
  10541. */
  10542. function parseClassType$1(componentType) {
  10543. var ret = {main: '', sub: ''};
  10544. if (componentType) {
  10545. componentType = componentType.split(TYPE_DELIMITER);
  10546. ret.main = componentType[0] || '';
  10547. ret.sub = componentType[1] || '';
  10548. }
  10549. return ret;
  10550. }
  10551. /**
  10552. * @public
  10553. */
  10554. function checkClassType(componentType) {
  10555. assert$1(
  10556. /^[a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)?$/.test(componentType),
  10557. 'componentType "' + componentType + '" illegal'
  10558. );
  10559. }
  10560. /**
  10561. * @public
  10562. */
  10563. function enableClassExtend(RootClass, mandatoryMethods) {
  10564. RootClass.$constructor = RootClass;
  10565. RootClass.extend = function (proto) {
  10566. if (__DEV__) {
  10567. each$1(mandatoryMethods, function (method) {
  10568. if (!proto[method]) {
  10569. console.warn(
  10570. 'Method `' + method + '` should be implemented'
  10571. + (proto.type ? ' in ' + proto.type : '') + '.'
  10572. );
  10573. }
  10574. });
  10575. }
  10576. var superClass = this;
  10577. var ExtendedClass = function () {
  10578. if (!proto.$constructor) {
  10579. superClass.apply(this, arguments);
  10580. }
  10581. else {
  10582. proto.$constructor.apply(this, arguments);
  10583. }
  10584. };
  10585. extend(ExtendedClass.prototype, proto);
  10586. ExtendedClass.extend = this.extend;
  10587. ExtendedClass.superCall = superCall;
  10588. ExtendedClass.superApply = superApply;
  10589. inherits(ExtendedClass, this);
  10590. ExtendedClass.superClass = superClass;
  10591. return ExtendedClass;
  10592. };
  10593. }
  10594. var classBase = 0;
  10595. /**
  10596. * Can not use instanceof, consider different scope by
  10597. * cross domain or es module import in ec extensions.
  10598. * Mount a method "isInstance()" to Clz.
  10599. */
  10600. function enableClassCheck(Clz) {
  10601. var classAttr = ['__\0is_clz', classBase++, Math.random().toFixed(3)].join('_');
  10602. Clz.prototype[classAttr] = true;
  10603. if (__DEV__) {
  10604. assert$1(!Clz.isInstance, 'The method "is" can not be defined.');
  10605. }
  10606. Clz.isInstance = function (obj) {
  10607. return !!(obj && obj[classAttr]);
  10608. };
  10609. }
  10610. // superCall should have class info, which can not be fetch from 'this'.
  10611. // Consider this case:
  10612. // class A has method f,
  10613. // class B inherits class A, overrides method f, f call superApply('f'),
  10614. // class C inherits class B, do not overrides method f,
  10615. // then when method of class C is called, dead loop occured.
  10616. function superCall(context, methodName) {
  10617. var args = slice(arguments, 2);
  10618. return this.superClass.prototype[methodName].apply(context, args);
  10619. }
  10620. function superApply(context, methodName, args) {
  10621. return this.superClass.prototype[methodName].apply(context, args);
  10622. }
  10623. /**
  10624. * @param {Object} entity
  10625. * @param {Object} options
  10626. * @param {boolean} [options.registerWhenExtend]
  10627. * @public
  10628. */
  10629. function enableClassManagement(entity, options) {
  10630. options = options || {};
  10631. /**
  10632. * Component model classes
  10633. * key: componentType,
  10634. * value:
  10635. * componentClass, when componentType is 'xxx'
  10636. * or Object.<subKey, componentClass>, when componentType is 'xxx.yy'
  10637. * @type {Object}
  10638. */
  10639. var storage = {};
  10640. entity.registerClass = function (Clazz, componentType) {
  10641. if (componentType) {
  10642. checkClassType(componentType);
  10643. componentType = parseClassType$1(componentType);
  10644. if (!componentType.sub) {
  10645. if (__DEV__) {
  10646. if (storage[componentType.main]) {
  10647. console.warn(componentType.main + ' exists.');
  10648. }
  10649. }
  10650. storage[componentType.main] = Clazz;
  10651. }
  10652. else if (componentType.sub !== IS_CONTAINER) {
  10653. var container = makeContainer(componentType);
  10654. container[componentType.sub] = Clazz;
  10655. }
  10656. }
  10657. return Clazz;
  10658. };
  10659. entity.getClass = function (componentMainType, subType, throwWhenNotFound) {
  10660. var Clazz = storage[componentMainType];
  10661. if (Clazz && Clazz[IS_CONTAINER]) {
  10662. Clazz = subType ? Clazz[subType] : null;
  10663. }
  10664. if (throwWhenNotFound && !Clazz) {
  10665. throw new Error(
  10666. !subType
  10667. ? componentMainType + '.' + 'type should be specified.'
  10668. : 'Component ' + componentMainType + '.' + (subType || '') + ' not exists. Load it first.'
  10669. );
  10670. }
  10671. return Clazz;
  10672. };
  10673. entity.getClassesByMainType = function (componentType) {
  10674. componentType = parseClassType$1(componentType);
  10675. var result = [];
  10676. var obj = storage[componentType.main];
  10677. if (obj && obj[IS_CONTAINER]) {
  10678. each$1(obj, function (o, type) {
  10679. type !== IS_CONTAINER && result.push(o);
  10680. });
  10681. }
  10682. else {
  10683. result.push(obj);
  10684. }
  10685. return result;
  10686. };
  10687. entity.hasClass = function (componentType) {
  10688. // Just consider componentType.main.
  10689. componentType = parseClassType$1(componentType);
  10690. return !!storage[componentType.main];
  10691. };
  10692. /**
  10693. * @return {Array.<string>} Like ['aa', 'bb'], but can not be ['aa.xx']
  10694. */
  10695. entity.getAllClassMainTypes = function () {
  10696. var types = [];
  10697. each$1(storage, function (obj, type) {
  10698. types.push(type);
  10699. });
  10700. return types;
  10701. };
  10702. /**
  10703. * If a main type is container and has sub types
  10704. * @param {string} mainType
  10705. * @return {boolean}
  10706. */
  10707. entity.hasSubTypes = function (componentType) {
  10708. componentType = parseClassType$1(componentType);
  10709. var obj = storage[componentType.main];
  10710. return obj && obj[IS_CONTAINER];
  10711. };
  10712. entity.parseClassType = parseClassType$1;
  10713. function makeContainer(componentType) {
  10714. var container = storage[componentType.main];
  10715. if (!container || !container[IS_CONTAINER]) {
  10716. container = storage[componentType.main] = {};
  10717. container[IS_CONTAINER] = true;
  10718. }
  10719. return container;
  10720. }
  10721. if (options.registerWhenExtend) {
  10722. var originalExtend = entity.extend;
  10723. if (originalExtend) {
  10724. entity.extend = function (proto) {
  10725. var ExtendedClass = originalExtend.call(this, proto);
  10726. return entity.registerClass(ExtendedClass, proto.type);
  10727. };
  10728. }
  10729. }
  10730. return entity;
  10731. }
  10732. /**
  10733. * @param {string|Array.<string>} properties
  10734. */
  10735. /*
  10736. * Licensed to the Apache Software Foundation (ASF) under one
  10737. * or more contributor license agreements. See the NOTICE file
  10738. * distributed with this work for additional information
  10739. * regarding copyright ownership. The ASF licenses this file
  10740. * to you under the Apache License, Version 2.0 (the
  10741. * "License"); you may not use this file except in compliance
  10742. * with the License. You may obtain a copy of the License at
  10743. *
  10744. * http://www.apache.org/licenses/LICENSE-2.0
  10745. *
  10746. * Unless required by applicable law or agreed to in writing,
  10747. * software distributed under the License is distributed on an
  10748. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  10749. * KIND, either express or implied. See the License for the
  10750. * specific language governing permissions and limitations
  10751. * under the License.
  10752. */
  10753. // TODO Parse shadow style
  10754. // TODO Only shallow path support
  10755. var makeStyleMapper = function (properties) {
  10756. // Normalize
  10757. for (var i = 0; i < properties.length; i++) {
  10758. if (!properties[i][1]) {
  10759. properties[i][1] = properties[i][0];
  10760. }
  10761. }
  10762. return function (model, excludes, includes) {
  10763. var style = {};
  10764. for (var i = 0; i < properties.length; i++) {
  10765. var propName = properties[i][1];
  10766. if ((excludes && indexOf(excludes, propName) >= 0)
  10767. || (includes && indexOf(includes, propName) < 0)
  10768. ) {
  10769. continue;
  10770. }
  10771. var val = model.getShallow(propName);
  10772. if (val != null) {
  10773. style[properties[i][0]] = val;
  10774. }
  10775. }
  10776. return style;
  10777. };
  10778. };
  10779. /*
  10780. * Licensed to the Apache Software Foundation (ASF) under one
  10781. * or more contributor license agreements. See the NOTICE file
  10782. * distributed with this work for additional information
  10783. * regarding copyright ownership. The ASF licenses this file
  10784. * to you under the Apache License, Version 2.0 (the
  10785. * "License"); you may not use this file except in compliance
  10786. * with the License. You may obtain a copy of the License at
  10787. *
  10788. * http://www.apache.org/licenses/LICENSE-2.0
  10789. *
  10790. * Unless required by applicable law or agreed to in writing,
  10791. * software distributed under the License is distributed on an
  10792. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  10793. * KIND, either express or implied. See the License for the
  10794. * specific language governing permissions and limitations
  10795. * under the License.
  10796. */
  10797. var getLineStyle = makeStyleMapper(
  10798. [
  10799. ['lineWidth', 'width'],
  10800. ['stroke', 'color'],
  10801. ['opacity'],
  10802. ['shadowBlur'],
  10803. ['shadowOffsetX'],
  10804. ['shadowOffsetY'],
  10805. ['shadowColor']
  10806. ]
  10807. );
  10808. var lineStyleMixin = {
  10809. getLineStyle: function (excludes) {
  10810. var style = getLineStyle(this, excludes);
  10811. // Always set lineDash whether dashed, otherwise we can not
  10812. // erase the previous style when assigning to el.style.
  10813. style.lineDash = this.getLineDash(style.lineWidth);
  10814. return style;
  10815. },
  10816. getLineDash: function (lineWidth) {
  10817. if (lineWidth == null) {
  10818. lineWidth = 1;
  10819. }
  10820. var lineType = this.get('type');
  10821. var dotSize = Math.max(lineWidth, 2);
  10822. var dashSize = lineWidth * 4;
  10823. return (lineType === 'solid' || lineType == null)
  10824. // Use `false` but not `null` for the solid line here, because `null` might be
  10825. // ignored when assigning to `el.style`. e.g., when setting `lineStyle.type` as
  10826. // `'dashed'` and `emphasis.lineStyle.type` as `'solid'` in graph series, the
  10827. // `lineDash` gotten form the latter one is not able to erase that from the former
  10828. // one if using `null` here according to the emhpsis strategy in `util/graphic.js`.
  10829. ? false
  10830. : lineType === 'dashed'
  10831. ? [dashSize, dashSize]
  10832. : [dotSize, dotSize];
  10833. }
  10834. };
  10835. /*
  10836. * Licensed to the Apache Software Foundation (ASF) under one
  10837. * or more contributor license agreements. See the NOTICE file
  10838. * distributed with this work for additional information
  10839. * regarding copyright ownership. The ASF licenses this file
  10840. * to you under the Apache License, Version 2.0 (the
  10841. * "License"); you may not use this file except in compliance
  10842. * with the License. You may obtain a copy of the License at
  10843. *
  10844. * http://www.apache.org/licenses/LICENSE-2.0
  10845. *
  10846. * Unless required by applicable law or agreed to in writing,
  10847. * software distributed under the License is distributed on an
  10848. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  10849. * KIND, either express or implied. See the License for the
  10850. * specific language governing permissions and limitations
  10851. * under the License.
  10852. */
  10853. var getAreaStyle = makeStyleMapper(
  10854. [
  10855. ['fill', 'color'],
  10856. ['shadowBlur'],
  10857. ['shadowOffsetX'],
  10858. ['shadowOffsetY'],
  10859. ['opacity'],
  10860. ['shadowColor']
  10861. ]
  10862. );
  10863. var areaStyleMixin = {
  10864. getAreaStyle: function (excludes, includes) {
  10865. return getAreaStyle(this, excludes, includes);
  10866. }
  10867. };
  10868. /**
  10869. * 曲线辅助模块
  10870. * @module zrender/core/curve
  10871. * @author pissang(https://www.github.com/pissang)
  10872. */
  10873. var mathPow = Math.pow;
  10874. var mathSqrt$2 = Math.sqrt;
  10875. var EPSILON$1 = 1e-8;
  10876. var EPSILON_NUMERIC = 1e-4;
  10877. var THREE_SQRT = mathSqrt$2(3);
  10878. var ONE_THIRD = 1 / 3;
  10879. // 临时变量
  10880. var _v0 = create();
  10881. var _v1 = create();
  10882. var _v2 = create();
  10883. function isAroundZero(val) {
  10884. return val > -EPSILON$1 && val < EPSILON$1;
  10885. }
  10886. function isNotAroundZero$1(val) {
  10887. return val > EPSILON$1 || val < -EPSILON$1;
  10888. }
  10889. /**
  10890. * 计算三次贝塞尔值
  10891. * @memberOf module:zrender/core/curve
  10892. * @param {number} p0
  10893. * @param {number} p1
  10894. * @param {number} p2
  10895. * @param {number} p3
  10896. * @param {number} t
  10897. * @return {number}
  10898. */
  10899. function cubicAt(p0, p1, p2, p3, t) {
  10900. var onet = 1 - t;
  10901. return onet * onet * (onet * p0 + 3 * t * p1)
  10902. + t * t * (t * p3 + 3 * onet * p2);
  10903. }
  10904. /**
  10905. * 计算三次贝塞尔导数值
  10906. * @memberOf module:zrender/core/curve
  10907. * @param {number} p0
  10908. * @param {number} p1
  10909. * @param {number} p2
  10910. * @param {number} p3
  10911. * @param {number} t
  10912. * @return {number}
  10913. */
  10914. function cubicDerivativeAt(p0, p1, p2, p3, t) {
  10915. var onet = 1 - t;
  10916. return 3 * (
  10917. ((p1 - p0) * onet + 2 * (p2 - p1) * t) * onet
  10918. + (p3 - p2) * t * t
  10919. );
  10920. }
  10921. /**
  10922. * 计算三次贝塞尔方程根,使用盛金公式
  10923. * @memberOf module:zrender/core/curve
  10924. * @param {number} p0
  10925. * @param {number} p1
  10926. * @param {number} p2
  10927. * @param {number} p3
  10928. * @param {number} val
  10929. * @param {Array.<number>} roots
  10930. * @return {number} 有效根数目
  10931. */
  10932. function cubicRootAt(p0, p1, p2, p3, val, roots) {
  10933. // Evaluate roots of cubic functions
  10934. var a = p3 + 3 * (p1 - p2) - p0;
  10935. var b = 3 * (p2 - p1 * 2 + p0);
  10936. var c = 3 * (p1 - p0);
  10937. var d = p0 - val;
  10938. var A = b * b - 3 * a * c;
  10939. var B = b * c - 9 * a * d;
  10940. var C = c * c - 3 * b * d;
  10941. var n = 0;
  10942. if (isAroundZero(A) && isAroundZero(B)) {
  10943. if (isAroundZero(b)) {
  10944. roots[0] = 0;
  10945. }
  10946. else {
  10947. var t1 = -c / b; //t1, t2, t3, b is not zero
  10948. if (t1 >= 0 && t1 <= 1) {
  10949. roots[n++] = t1;
  10950. }
  10951. }
  10952. }
  10953. else {
  10954. var disc = B * B - 4 * A * C;
  10955. if (isAroundZero(disc)) {
  10956. var K = B / A;
  10957. var t1 = -b / a + K; // t1, a is not zero
  10958. var t2 = -K / 2; // t2, t3
  10959. if (t1 >= 0 && t1 <= 1) {
  10960. roots[n++] = t1;
  10961. }
  10962. if (t2 >= 0 && t2 <= 1) {
  10963. roots[n++] = t2;
  10964. }
  10965. }
  10966. else if (disc > 0) {
  10967. var discSqrt = mathSqrt$2(disc);
  10968. var Y1 = A * b + 1.5 * a * (-B + discSqrt);
  10969. var Y2 = A * b + 1.5 * a * (-B - discSqrt);
  10970. if (Y1 < 0) {
  10971. Y1 = -mathPow(-Y1, ONE_THIRD);
  10972. }
  10973. else {
  10974. Y1 = mathPow(Y1, ONE_THIRD);
  10975. }
  10976. if (Y2 < 0) {
  10977. Y2 = -mathPow(-Y2, ONE_THIRD);
  10978. }
  10979. else {
  10980. Y2 = mathPow(Y2, ONE_THIRD);
  10981. }
  10982. var t1 = (-b - (Y1 + Y2)) / (3 * a);
  10983. if (t1 >= 0 && t1 <= 1) {
  10984. roots[n++] = t1;
  10985. }
  10986. }
  10987. else {
  10988. var T = (2 * A * b - 3 * a * B) / (2 * mathSqrt$2(A * A * A));
  10989. var theta = Math.acos(T) / 3;
  10990. var ASqrt = mathSqrt$2(A);
  10991. var tmp = Math.cos(theta);
  10992. var t1 = (-b - 2 * ASqrt * tmp) / (3 * a);
  10993. var t2 = (-b + ASqrt * (tmp + THREE_SQRT * Math.sin(theta))) / (3 * a);
  10994. var t3 = (-b + ASqrt * (tmp - THREE_SQRT * Math.sin(theta))) / (3 * a);
  10995. if (t1 >= 0 && t1 <= 1) {
  10996. roots[n++] = t1;
  10997. }
  10998. if (t2 >= 0 && t2 <= 1) {
  10999. roots[n++] = t2;
  11000. }
  11001. if (t3 >= 0 && t3 <= 1) {
  11002. roots[n++] = t3;
  11003. }
  11004. }
  11005. }
  11006. return n;
  11007. }
  11008. /**
  11009. * 计算三次贝塞尔方程极限值的位置
  11010. * @memberOf module:zrender/core/curve
  11011. * @param {number} p0
  11012. * @param {number} p1
  11013. * @param {number} p2
  11014. * @param {number} p3
  11015. * @param {Array.<number>} extrema
  11016. * @return {number} 有效数目
  11017. */
  11018. function cubicExtrema(p0, p1, p2, p3, extrema) {
  11019. var b = 6 * p2 - 12 * p1 + 6 * p0;
  11020. var a = 9 * p1 + 3 * p3 - 3 * p0 - 9 * p2;
  11021. var c = 3 * p1 - 3 * p0;
  11022. var n = 0;
  11023. if (isAroundZero(a)) {
  11024. if (isNotAroundZero$1(b)) {
  11025. var t1 = -c / b;
  11026. if (t1 >= 0 && t1 <= 1) {
  11027. extrema[n++] = t1;
  11028. }
  11029. }
  11030. }
  11031. else {
  11032. var disc = b * b - 4 * a * c;
  11033. if (isAroundZero(disc)) {
  11034. extrema[0] = -b / (2 * a);
  11035. }
  11036. else if (disc > 0) {
  11037. var discSqrt = mathSqrt$2(disc);
  11038. var t1 = (-b + discSqrt) / (2 * a);
  11039. var t2 = (-b - discSqrt) / (2 * a);
  11040. if (t1 >= 0 && t1 <= 1) {
  11041. extrema[n++] = t1;
  11042. }
  11043. if (t2 >= 0 && t2 <= 1) {
  11044. extrema[n++] = t2;
  11045. }
  11046. }
  11047. }
  11048. return n;
  11049. }
  11050. /**
  11051. * 细分三次贝塞尔曲线
  11052. * @memberOf module:zrender/core/curve
  11053. * @param {number} p0
  11054. * @param {number} p1
  11055. * @param {number} p2
  11056. * @param {number} p3
  11057. * @param {number} t
  11058. * @param {Array.<number>} out
  11059. */
  11060. function cubicSubdivide(p0, p1, p2, p3, t, out) {
  11061. var p01 = (p1 - p0) * t + p0;
  11062. var p12 = (p2 - p1) * t + p1;
  11063. var p23 = (p3 - p2) * t + p2;
  11064. var p012 = (p12 - p01) * t + p01;
  11065. var p123 = (p23 - p12) * t + p12;
  11066. var p0123 = (p123 - p012) * t + p012;
  11067. // Seg0
  11068. out[0] = p0;
  11069. out[1] = p01;
  11070. out[2] = p012;
  11071. out[3] = p0123;
  11072. // Seg1
  11073. out[4] = p0123;
  11074. out[5] = p123;
  11075. out[6] = p23;
  11076. out[7] = p3;
  11077. }
  11078. /**
  11079. * 投射点到三次贝塞尔曲线上,返回投射距离。
  11080. * 投射点有可能会有一个或者多个,这里只返回其中距离最短的一个。
  11081. * @param {number} x0
  11082. * @param {number} y0
  11083. * @param {number} x1
  11084. * @param {number} y1
  11085. * @param {number} x2
  11086. * @param {number} y2
  11087. * @param {number} x3
  11088. * @param {number} y3
  11089. * @param {number} x
  11090. * @param {number} y
  11091. * @param {Array.<number>} [out] 投射点
  11092. * @return {number}
  11093. */
  11094. function cubicProjectPoint(
  11095. x0, y0, x1, y1, x2, y2, x3, y3,
  11096. x, y, out
  11097. ) {
  11098. // http://pomax.github.io/bezierinfo/#projections
  11099. var t;
  11100. var interval = 0.005;
  11101. var d = Infinity;
  11102. var prev;
  11103. var next;
  11104. var d1;
  11105. var d2;
  11106. _v0[0] = x;
  11107. _v0[1] = y;
  11108. // 先粗略估计一下可能的最小距离的 t 值
  11109. // PENDING
  11110. for (var _t = 0; _t < 1; _t += 0.05) {
  11111. _v1[0] = cubicAt(x0, x1, x2, x3, _t);
  11112. _v1[1] = cubicAt(y0, y1, y2, y3, _t);
  11113. d1 = distSquare(_v0, _v1);
  11114. if (d1 < d) {
  11115. t = _t;
  11116. d = d1;
  11117. }
  11118. }
  11119. d = Infinity;
  11120. // At most 32 iteration
  11121. for (var i = 0; i < 32; i++) {
  11122. if (interval < EPSILON_NUMERIC) {
  11123. break;
  11124. }
  11125. prev = t - interval;
  11126. next = t + interval;
  11127. // t - interval
  11128. _v1[0] = cubicAt(x0, x1, x2, x3, prev);
  11129. _v1[1] = cubicAt(y0, y1, y2, y3, prev);
  11130. d1 = distSquare(_v1, _v0);
  11131. if (prev >= 0 && d1 < d) {
  11132. t = prev;
  11133. d = d1;
  11134. }
  11135. else {
  11136. // t + interval
  11137. _v2[0] = cubicAt(x0, x1, x2, x3, next);
  11138. _v2[1] = cubicAt(y0, y1, y2, y3, next);
  11139. d2 = distSquare(_v2, _v0);
  11140. if (next <= 1 && d2 < d) {
  11141. t = next;
  11142. d = d2;
  11143. }
  11144. else {
  11145. interval *= 0.5;
  11146. }
  11147. }
  11148. }
  11149. // t
  11150. if (out) {
  11151. out[0] = cubicAt(x0, x1, x2, x3, t);
  11152. out[1] = cubicAt(y0, y1, y2, y3, t);
  11153. }
  11154. // console.log(interval, i);
  11155. return mathSqrt$2(d);
  11156. }
  11157. /**
  11158. * 计算二次方贝塞尔值
  11159. * @param {number} p0
  11160. * @param {number} p1
  11161. * @param {number} p2
  11162. * @param {number} t
  11163. * @return {number}
  11164. */
  11165. function quadraticAt(p0, p1, p2, t) {
  11166. var onet = 1 - t;
  11167. return onet * (onet * p0 + 2 * t * p1) + t * t * p2;
  11168. }
  11169. /**
  11170. * 计算二次方贝塞尔导数值
  11171. * @param {number} p0
  11172. * @param {number} p1
  11173. * @param {number} p2
  11174. * @param {number} t
  11175. * @return {number}
  11176. */
  11177. function quadraticDerivativeAt(p0, p1, p2, t) {
  11178. return 2 * ((1 - t) * (p1 - p0) + t * (p2 - p1));
  11179. }
  11180. /**
  11181. * 计算二次方贝塞尔方程根
  11182. * @param {number} p0
  11183. * @param {number} p1
  11184. * @param {number} p2
  11185. * @param {number} t
  11186. * @param {Array.<number>} roots
  11187. * @return {number} 有效根数目
  11188. */
  11189. function quadraticRootAt(p0, p1, p2, val, roots) {
  11190. var a = p0 - 2 * p1 + p2;
  11191. var b = 2 * (p1 - p0);
  11192. var c = p0 - val;
  11193. var n = 0;
  11194. if (isAroundZero(a)) {
  11195. if (isNotAroundZero$1(b)) {
  11196. var t1 = -c / b;
  11197. if (t1 >= 0 && t1 <= 1) {
  11198. roots[n++] = t1;
  11199. }
  11200. }
  11201. }
  11202. else {
  11203. var disc = b * b - 4 * a * c;
  11204. if (isAroundZero(disc)) {
  11205. var t1 = -b / (2 * a);
  11206. if (t1 >= 0 && t1 <= 1) {
  11207. roots[n++] = t1;
  11208. }
  11209. }
  11210. else if (disc > 0) {
  11211. var discSqrt = mathSqrt$2(disc);
  11212. var t1 = (-b + discSqrt) / (2 * a);
  11213. var t2 = (-b - discSqrt) / (2 * a);
  11214. if (t1 >= 0 && t1 <= 1) {
  11215. roots[n++] = t1;
  11216. }
  11217. if (t2 >= 0 && t2 <= 1) {
  11218. roots[n++] = t2;
  11219. }
  11220. }
  11221. }
  11222. return n;
  11223. }
  11224. /**
  11225. * 计算二次贝塞尔方程极限值
  11226. * @memberOf module:zrender/core/curve
  11227. * @param {number} p0
  11228. * @param {number} p1
  11229. * @param {number} p2
  11230. * @return {number}
  11231. */
  11232. function quadraticExtremum(p0, p1, p2) {
  11233. var divider = p0 + p2 - 2 * p1;
  11234. if (divider === 0) {
  11235. // p1 is center of p0 and p2
  11236. return 0.5;
  11237. }
  11238. else {
  11239. return (p0 - p1) / divider;
  11240. }
  11241. }
  11242. /**
  11243. * 细分二次贝塞尔曲线
  11244. * @memberOf module:zrender/core/curve
  11245. * @param {number} p0
  11246. * @param {number} p1
  11247. * @param {number} p2
  11248. * @param {number} t
  11249. * @param {Array.<number>} out
  11250. */
  11251. function quadraticSubdivide(p0, p1, p2, t, out) {
  11252. var p01 = (p1 - p0) * t + p0;
  11253. var p12 = (p2 - p1) * t + p1;
  11254. var p012 = (p12 - p01) * t + p01;
  11255. // Seg0
  11256. out[0] = p0;
  11257. out[1] = p01;
  11258. out[2] = p012;
  11259. // Seg1
  11260. out[3] = p012;
  11261. out[4] = p12;
  11262. out[5] = p2;
  11263. }
  11264. /**
  11265. * 投射点到二次贝塞尔曲线上,返回投射距离。
  11266. * 投射点有可能会有一个或者多个,这里只返回其中距离最短的一个。
  11267. * @param {number} x0
  11268. * @param {number} y0
  11269. * @param {number} x1
  11270. * @param {number} y1
  11271. * @param {number} x2
  11272. * @param {number} y2
  11273. * @param {number} x
  11274. * @param {number} y
  11275. * @param {Array.<number>} out 投射点
  11276. * @return {number}
  11277. */
  11278. function quadraticProjectPoint(
  11279. x0, y0, x1, y1, x2, y2,
  11280. x, y, out
  11281. ) {
  11282. // http://pomax.github.io/bezierinfo/#projections
  11283. var t;
  11284. var interval = 0.005;
  11285. var d = Infinity;
  11286. _v0[0] = x;
  11287. _v0[1] = y;
  11288. // 先粗略估计一下可能的最小距离的 t 值
  11289. // PENDING
  11290. for (var _t = 0; _t < 1; _t += 0.05) {
  11291. _v1[0] = quadraticAt(x0, x1, x2, _t);
  11292. _v1[1] = quadraticAt(y0, y1, y2, _t);
  11293. var d1 = distSquare(_v0, _v1);
  11294. if (d1 < d) {
  11295. t = _t;
  11296. d = d1;
  11297. }
  11298. }
  11299. d = Infinity;
  11300. // At most 32 iteration
  11301. for (var i = 0; i < 32; i++) {
  11302. if (interval < EPSILON_NUMERIC) {
  11303. break;
  11304. }
  11305. var prev = t - interval;
  11306. var next = t + interval;
  11307. // t - interval
  11308. _v1[0] = quadraticAt(x0, x1, x2, prev);
  11309. _v1[1] = quadraticAt(y0, y1, y2, prev);
  11310. var d1 = distSquare(_v1, _v0);
  11311. if (prev >= 0 && d1 < d) {
  11312. t = prev;
  11313. d = d1;
  11314. }
  11315. else {
  11316. // t + interval
  11317. _v2[0] = quadraticAt(x0, x1, x2, next);
  11318. _v2[1] = quadraticAt(y0, y1, y2, next);
  11319. var d2 = distSquare(_v2, _v0);
  11320. if (next <= 1 && d2 < d) {
  11321. t = next;
  11322. d = d2;
  11323. }
  11324. else {
  11325. interval *= 0.5;
  11326. }
  11327. }
  11328. }
  11329. // t
  11330. if (out) {
  11331. out[0] = quadraticAt(x0, x1, x2, t);
  11332. out[1] = quadraticAt(y0, y1, y2, t);
  11333. }
  11334. // console.log(interval, i);
  11335. return mathSqrt$2(d);
  11336. }
  11337. /**
  11338. * @author Yi Shen(https://github.com/pissang)
  11339. */
  11340. var mathMin$3 = Math.min;
  11341. var mathMax$3 = Math.max;
  11342. var mathSin$2 = Math.sin;
  11343. var mathCos$2 = Math.cos;
  11344. var PI2 = Math.PI * 2;
  11345. var start = create();
  11346. var end = create();
  11347. var extremity = create();
  11348. /**
  11349. * 从顶点数组中计算出最小包围盒,写入`min`和`max`中
  11350. * @module zrender/core/bbox
  11351. * @param {Array<Object>} points 顶点数组
  11352. * @param {number} min
  11353. * @param {number} max
  11354. */
  11355. function fromPoints(points, min$$1, max$$1) {
  11356. if (points.length === 0) {
  11357. return;
  11358. }
  11359. var p = points[0];
  11360. var left = p[0];
  11361. var right = p[0];
  11362. var top = p[1];
  11363. var bottom = p[1];
  11364. var i;
  11365. for (i = 1; i < points.length; i++) {
  11366. p = points[i];
  11367. left = mathMin$3(left, p[0]);
  11368. right = mathMax$3(right, p[0]);
  11369. top = mathMin$3(top, p[1]);
  11370. bottom = mathMax$3(bottom, p[1]);
  11371. }
  11372. min$$1[0] = left;
  11373. min$$1[1] = top;
  11374. max$$1[0] = right;
  11375. max$$1[1] = bottom;
  11376. }
  11377. /**
  11378. * @memberOf module:zrender/core/bbox
  11379. * @param {number} x0
  11380. * @param {number} y0
  11381. * @param {number} x1
  11382. * @param {number} y1
  11383. * @param {Array.<number>} min
  11384. * @param {Array.<number>} max
  11385. */
  11386. function fromLine(x0, y0, x1, y1, min$$1, max$$1) {
  11387. min$$1[0] = mathMin$3(x0, x1);
  11388. min$$1[1] = mathMin$3(y0, y1);
  11389. max$$1[0] = mathMax$3(x0, x1);
  11390. max$$1[1] = mathMax$3(y0, y1);
  11391. }
  11392. var xDim = [];
  11393. var yDim = [];
  11394. /**
  11395. * 从三阶贝塞尔曲线(p0, p1, p2, p3)中计算出最小包围盒,写入`min`和`max`中
  11396. * @memberOf module:zrender/core/bbox
  11397. * @param {number} x0
  11398. * @param {number} y0
  11399. * @param {number} x1
  11400. * @param {number} y1
  11401. * @param {number} x2
  11402. * @param {number} y2
  11403. * @param {number} x3
  11404. * @param {number} y3
  11405. * @param {Array.<number>} min
  11406. * @param {Array.<number>} max
  11407. */
  11408. function fromCubic(
  11409. x0, y0, x1, y1, x2, y2, x3, y3, min$$1, max$$1
  11410. ) {
  11411. var cubicExtrema$$1 = cubicExtrema;
  11412. var cubicAt$$1 = cubicAt;
  11413. var i;
  11414. var n = cubicExtrema$$1(x0, x1, x2, x3, xDim);
  11415. min$$1[0] = Infinity;
  11416. min$$1[1] = Infinity;
  11417. max$$1[0] = -Infinity;
  11418. max$$1[1] = -Infinity;
  11419. for (i = 0; i < n; i++) {
  11420. var x = cubicAt$$1(x0, x1, x2, x3, xDim[i]);
  11421. min$$1[0] = mathMin$3(x, min$$1[0]);
  11422. max$$1[0] = mathMax$3(x, max$$1[0]);
  11423. }
  11424. n = cubicExtrema$$1(y0, y1, y2, y3, yDim);
  11425. for (i = 0; i < n; i++) {
  11426. var y = cubicAt$$1(y0, y1, y2, y3, yDim[i]);
  11427. min$$1[1] = mathMin$3(y, min$$1[1]);
  11428. max$$1[1] = mathMax$3(y, max$$1[1]);
  11429. }
  11430. min$$1[0] = mathMin$3(x0, min$$1[0]);
  11431. max$$1[0] = mathMax$3(x0, max$$1[0]);
  11432. min$$1[0] = mathMin$3(x3, min$$1[0]);
  11433. max$$1[0] = mathMax$3(x3, max$$1[0]);
  11434. min$$1[1] = mathMin$3(y0, min$$1[1]);
  11435. max$$1[1] = mathMax$3(y0, max$$1[1]);
  11436. min$$1[1] = mathMin$3(y3, min$$1[1]);
  11437. max$$1[1] = mathMax$3(y3, max$$1[1]);
  11438. }
  11439. /**
  11440. * 从二阶贝塞尔曲线(p0, p1, p2)中计算出最小包围盒,写入`min`和`max`中
  11441. * @memberOf module:zrender/core/bbox
  11442. * @param {number} x0
  11443. * @param {number} y0
  11444. * @param {number} x1
  11445. * @param {number} y1
  11446. * @param {number} x2
  11447. * @param {number} y2
  11448. * @param {Array.<number>} min
  11449. * @param {Array.<number>} max
  11450. */
  11451. function fromQuadratic(x0, y0, x1, y1, x2, y2, min$$1, max$$1) {
  11452. var quadraticExtremum$$1 = quadraticExtremum;
  11453. var quadraticAt$$1 = quadraticAt;
  11454. // Find extremities, where derivative in x dim or y dim is zero
  11455. var tx =
  11456. mathMax$3(
  11457. mathMin$3(quadraticExtremum$$1(x0, x1, x2), 1), 0
  11458. );
  11459. var ty =
  11460. mathMax$3(
  11461. mathMin$3(quadraticExtremum$$1(y0, y1, y2), 1), 0
  11462. );
  11463. var x = quadraticAt$$1(x0, x1, x2, tx);
  11464. var y = quadraticAt$$1(y0, y1, y2, ty);
  11465. min$$1[0] = mathMin$3(x0, x2, x);
  11466. min$$1[1] = mathMin$3(y0, y2, y);
  11467. max$$1[0] = mathMax$3(x0, x2, x);
  11468. max$$1[1] = mathMax$3(y0, y2, y);
  11469. }
  11470. /**
  11471. * 从圆弧中计算出最小包围盒,写入`min`和`max`中
  11472. * @method
  11473. * @memberOf module:zrender/core/bbox
  11474. * @param {number} x
  11475. * @param {number} y
  11476. * @param {number} rx
  11477. * @param {number} ry
  11478. * @param {number} startAngle
  11479. * @param {number} endAngle
  11480. * @param {number} anticlockwise
  11481. * @param {Array.<number>} min
  11482. * @param {Array.<number>} max
  11483. */
  11484. function fromArc(
  11485. x, y, rx, ry, startAngle, endAngle, anticlockwise, min$$1, max$$1
  11486. ) {
  11487. var vec2Min = min;
  11488. var vec2Max = max;
  11489. var diff = Math.abs(startAngle - endAngle);
  11490. if (diff % PI2 < 1e-4 && diff > 1e-4) {
  11491. // Is a circle
  11492. min$$1[0] = x - rx;
  11493. min$$1[1] = y - ry;
  11494. max$$1[0] = x + rx;
  11495. max$$1[1] = y + ry;
  11496. return;
  11497. }
  11498. start[0] = mathCos$2(startAngle) * rx + x;
  11499. start[1] = mathSin$2(startAngle) * ry + y;
  11500. end[0] = mathCos$2(endAngle) * rx + x;
  11501. end[1] = mathSin$2(endAngle) * ry + y;
  11502. vec2Min(min$$1, start, end);
  11503. vec2Max(max$$1, start, end);
  11504. // Thresh to [0, Math.PI * 2]
  11505. startAngle = startAngle % (PI2);
  11506. if (startAngle < 0) {
  11507. startAngle = startAngle + PI2;
  11508. }
  11509. endAngle = endAngle % (PI2);
  11510. if (endAngle < 0) {
  11511. endAngle = endAngle + PI2;
  11512. }
  11513. if (startAngle > endAngle && !anticlockwise) {
  11514. endAngle += PI2;
  11515. }
  11516. else if (startAngle < endAngle && anticlockwise) {
  11517. startAngle += PI2;
  11518. }
  11519. if (anticlockwise) {
  11520. var tmp = endAngle;
  11521. endAngle = startAngle;
  11522. startAngle = tmp;
  11523. }
  11524. // var number = 0;
  11525. // var step = (anticlockwise ? -Math.PI : Math.PI) / 2;
  11526. for (var angle = 0; angle < endAngle; angle += Math.PI / 2) {
  11527. if (angle > startAngle) {
  11528. extremity[0] = mathCos$2(angle) * rx + x;
  11529. extremity[1] = mathSin$2(angle) * ry + y;
  11530. vec2Min(min$$1, extremity, min$$1);
  11531. vec2Max(max$$1, extremity, max$$1);
  11532. }
  11533. }
  11534. }
  11535. /**
  11536. * Path 代理,可以在`buildPath`中用于替代`ctx`, 会保存每个path操作的命令到pathCommands属性中
  11537. * 可以用于 isInsidePath 判断以及获取boundingRect
  11538. *
  11539. * @module zrender/core/PathProxy
  11540. * @author Yi Shen (http://www.github.com/pissang)
  11541. */
  11542. // TODO getTotalLength, getPointAtLength
  11543. var CMD = {
  11544. M: 1,
  11545. L: 2,
  11546. C: 3,
  11547. Q: 4,
  11548. A: 5,
  11549. Z: 6,
  11550. // Rect
  11551. R: 7
  11552. };
  11553. // var CMD_MEM_SIZE = {
  11554. // M: 3,
  11555. // L: 3,
  11556. // C: 7,
  11557. // Q: 5,
  11558. // A: 9,
  11559. // R: 5,
  11560. // Z: 1
  11561. // };
  11562. var min$1 = [];
  11563. var max$1 = [];
  11564. var min2 = [];
  11565. var max2 = [];
  11566. var mathMin$2 = Math.min;
  11567. var mathMax$2 = Math.max;
  11568. var mathCos$1 = Math.cos;
  11569. var mathSin$1 = Math.sin;
  11570. var mathSqrt$1 = Math.sqrt;
  11571. var mathAbs = Math.abs;
  11572. var hasTypedArray = typeof Float32Array !== 'undefined';
  11573. /**
  11574. * @alias module:zrender/core/PathProxy
  11575. * @constructor
  11576. */
  11577. var PathProxy = function (notSaveData) {
  11578. this._saveData = !(notSaveData || false);
  11579. if (this._saveData) {
  11580. /**
  11581. * Path data. Stored as flat array
  11582. * @type {Array.<Object>}
  11583. */
  11584. this.data = [];
  11585. }
  11586. this._ctx = null;
  11587. };
  11588. /**
  11589. * 快速计算Path包围盒(并不是最小包围盒)
  11590. * @return {Object}
  11591. */
  11592. PathProxy.prototype = {
  11593. constructor: PathProxy,
  11594. _xi: 0,
  11595. _yi: 0,
  11596. _x0: 0,
  11597. _y0: 0,
  11598. // Unit x, Unit y. Provide for avoiding drawing that too short line segment
  11599. _ux: 0,
  11600. _uy: 0,
  11601. _len: 0,
  11602. _lineDash: null,
  11603. _dashOffset: 0,
  11604. _dashIdx: 0,
  11605. _dashSum: 0,
  11606. /**
  11607. * @readOnly
  11608. */
  11609. setScale: function (sx, sy, segmentIgnoreThreshold) {
  11610. // Compat. Previously there is no segmentIgnoreThreshold.
  11611. segmentIgnoreThreshold = segmentIgnoreThreshold || 0;
  11612. this._ux = mathAbs(segmentIgnoreThreshold / devicePixelRatio / sx) || 0;
  11613. this._uy = mathAbs(segmentIgnoreThreshold / devicePixelRatio / sy) || 0;
  11614. },
  11615. getContext: function () {
  11616. return this._ctx;
  11617. },
  11618. /**
  11619. * @param {CanvasRenderingContext2D} ctx
  11620. * @return {module:zrender/core/PathProxy}
  11621. */
  11622. beginPath: function (ctx) {
  11623. this._ctx = ctx;
  11624. ctx && ctx.beginPath();
  11625. ctx && (this.dpr = ctx.dpr);
  11626. // Reset
  11627. if (this._saveData) {
  11628. this._len = 0;
  11629. }
  11630. if (this._lineDash) {
  11631. this._lineDash = null;
  11632. this._dashOffset = 0;
  11633. }
  11634. return this;
  11635. },
  11636. /**
  11637. * @param {number} x
  11638. * @param {number} y
  11639. * @return {module:zrender/core/PathProxy}
  11640. */
  11641. moveTo: function (x, y) {
  11642. this.addData(CMD.M, x, y);
  11643. this._ctx && this._ctx.moveTo(x, y);
  11644. // x0, y0, xi, yi 是记录在 _dashedXXXXTo 方法中使用
  11645. // xi, yi 记录当前点, x0, y0 在 closePath 的时候回到起始点。
  11646. // 有可能在 beginPath 之后直接调用 lineTo,这时候 x0, y0 需要
  11647. // 在 lineTo 方法中记录,这里先不考虑这种情况,dashed line 也只在 IE10- 中不支持
  11648. this._x0 = x;
  11649. this._y0 = y;
  11650. this._xi = x;
  11651. this._yi = y;
  11652. return this;
  11653. },
  11654. /**
  11655. * @param {number} x
  11656. * @param {number} y
  11657. * @return {module:zrender/core/PathProxy}
  11658. */
  11659. lineTo: function (x, y) {
  11660. var exceedUnit = mathAbs(x - this._xi) > this._ux
  11661. || mathAbs(y - this._yi) > this._uy
  11662. // Force draw the first segment
  11663. || this._len < 5;
  11664. this.addData(CMD.L, x, y);
  11665. if (this._ctx && exceedUnit) {
  11666. this._needsDash() ? this._dashedLineTo(x, y)
  11667. : this._ctx.lineTo(x, y);
  11668. }
  11669. if (exceedUnit) {
  11670. this._xi = x;
  11671. this._yi = y;
  11672. }
  11673. return this;
  11674. },
  11675. /**
  11676. * @param {number} x1
  11677. * @param {number} y1
  11678. * @param {number} x2
  11679. * @param {number} y2
  11680. * @param {number} x3
  11681. * @param {number} y3
  11682. * @return {module:zrender/core/PathProxy}
  11683. */
  11684. bezierCurveTo: function (x1, y1, x2, y2, x3, y3) {
  11685. this.addData(CMD.C, x1, y1, x2, y2, x3, y3);
  11686. if (this._ctx) {
  11687. this._needsDash() ? this._dashedBezierTo(x1, y1, x2, y2, x3, y3)
  11688. : this._ctx.bezierCurveTo(x1, y1, x2, y2, x3, y3);
  11689. }
  11690. this._xi = x3;
  11691. this._yi = y3;
  11692. return this;
  11693. },
  11694. /**
  11695. * @param {number} x1
  11696. * @param {number} y1
  11697. * @param {number} x2
  11698. * @param {number} y2
  11699. * @return {module:zrender/core/PathProxy}
  11700. */
  11701. quadraticCurveTo: function (x1, y1, x2, y2) {
  11702. this.addData(CMD.Q, x1, y1, x2, y2);
  11703. if (this._ctx) {
  11704. this._needsDash() ? this._dashedQuadraticTo(x1, y1, x2, y2)
  11705. : this._ctx.quadraticCurveTo(x1, y1, x2, y2);
  11706. }
  11707. this._xi = x2;
  11708. this._yi = y2;
  11709. return this;
  11710. },
  11711. /**
  11712. * @param {number} cx
  11713. * @param {number} cy
  11714. * @param {number} r
  11715. * @param {number} startAngle
  11716. * @param {number} endAngle
  11717. * @param {boolean} anticlockwise
  11718. * @return {module:zrender/core/PathProxy}
  11719. */
  11720. arc: function (cx, cy, r, startAngle, endAngle, anticlockwise) {
  11721. this.addData(
  11722. CMD.A, cx, cy, r, r, startAngle, endAngle - startAngle, 0, anticlockwise ? 0 : 1
  11723. );
  11724. this._ctx && this._ctx.arc(cx, cy, r, startAngle, endAngle, anticlockwise);
  11725. this._xi = mathCos$1(endAngle) * r + cx;
  11726. this._yi = mathSin$1(endAngle) * r + cy;
  11727. return this;
  11728. },
  11729. // TODO
  11730. arcTo: function (x1, y1, x2, y2, radius) {
  11731. if (this._ctx) {
  11732. this._ctx.arcTo(x1, y1, x2, y2, radius);
  11733. }
  11734. return this;
  11735. },
  11736. // TODO
  11737. rect: function (x, y, w, h) {
  11738. this._ctx && this._ctx.rect(x, y, w, h);
  11739. this.addData(CMD.R, x, y, w, h);
  11740. return this;
  11741. },
  11742. /**
  11743. * @return {module:zrender/core/PathProxy}
  11744. */
  11745. closePath: function () {
  11746. this.addData(CMD.Z);
  11747. var ctx = this._ctx;
  11748. var x0 = this._x0;
  11749. var y0 = this._y0;
  11750. if (ctx) {
  11751. this._needsDash() && this._dashedLineTo(x0, y0);
  11752. ctx.closePath();
  11753. }
  11754. this._xi = x0;
  11755. this._yi = y0;
  11756. return this;
  11757. },
  11758. /**
  11759. * Context 从外部传入,因为有可能是 rebuildPath 完之后再 fill。
  11760. * stroke 同样
  11761. * @param {CanvasRenderingContext2D} ctx
  11762. * @return {module:zrender/core/PathProxy}
  11763. */
  11764. fill: function (ctx) {
  11765. ctx && ctx.fill();
  11766. this.toStatic();
  11767. },
  11768. /**
  11769. * @param {CanvasRenderingContext2D} ctx
  11770. * @return {module:zrender/core/PathProxy}
  11771. */
  11772. stroke: function (ctx) {
  11773. ctx && ctx.stroke();
  11774. this.toStatic();
  11775. },
  11776. /**
  11777. * 必须在其它绘制命令前调用
  11778. * Must be invoked before all other path drawing methods
  11779. * @return {module:zrender/core/PathProxy}
  11780. */
  11781. setLineDash: function (lineDash) {
  11782. if (lineDash instanceof Array) {
  11783. this._lineDash = lineDash;
  11784. this._dashIdx = 0;
  11785. var lineDashSum = 0;
  11786. for (var i = 0; i < lineDash.length; i++) {
  11787. lineDashSum += lineDash[i];
  11788. }
  11789. this._dashSum = lineDashSum;
  11790. }
  11791. return this;
  11792. },
  11793. /**
  11794. * 必须在其它绘制命令前调用
  11795. * Must be invoked before all other path drawing methods
  11796. * @return {module:zrender/core/PathProxy}
  11797. */
  11798. setLineDashOffset: function (offset) {
  11799. this._dashOffset = offset;
  11800. return this;
  11801. },
  11802. /**
  11803. *
  11804. * @return {boolean}
  11805. */
  11806. len: function () {
  11807. return this._len;
  11808. },
  11809. /**
  11810. * 直接设置 Path 数据
  11811. */
  11812. setData: function (data) {
  11813. var len$$1 = data.length;
  11814. if (!(this.data && this.data.length === len$$1) && hasTypedArray) {
  11815. this.data = new Float32Array(len$$1);
  11816. }
  11817. for (var i = 0; i < len$$1; i++) {
  11818. this.data[i] = data[i];
  11819. }
  11820. this._len = len$$1;
  11821. },
  11822. /**
  11823. * 添加子路径
  11824. * @param {module:zrender/core/PathProxy|Array.<module:zrender/core/PathProxy>} path
  11825. */
  11826. appendPath: function (path) {
  11827. if (!(path instanceof Array)) {
  11828. path = [path];
  11829. }
  11830. var len$$1 = path.length;
  11831. var appendSize = 0;
  11832. var offset = this._len;
  11833. for (var i = 0; i < len$$1; i++) {
  11834. appendSize += path[i].len();
  11835. }
  11836. if (hasTypedArray && (this.data instanceof Float32Array)) {
  11837. this.data = new Float32Array(offset + appendSize);
  11838. }
  11839. for (var i = 0; i < len$$1; i++) {
  11840. var appendPathData = path[i].data;
  11841. for (var k = 0; k < appendPathData.length; k++) {
  11842. this.data[offset++] = appendPathData[k];
  11843. }
  11844. }
  11845. this._len = offset;
  11846. },
  11847. /**
  11848. * 填充 Path 数据。
  11849. * 尽量复用而不申明新的数组。大部分图形重绘的指令数据长度都是不变的。
  11850. */
  11851. addData: function (cmd) {
  11852. if (!this._saveData) {
  11853. return;
  11854. }
  11855. var data = this.data;
  11856. if (this._len + arguments.length > data.length) {
  11857. // 因为之前的数组已经转换成静态的 Float32Array
  11858. // 所以不够用时需要扩展一个新的动态数组
  11859. this._expandData();
  11860. data = this.data;
  11861. }
  11862. for (var i = 0; i < arguments.length; i++) {
  11863. data[this._len++] = arguments[i];
  11864. }
  11865. this._prevCmd = cmd;
  11866. },
  11867. _expandData: function () {
  11868. // Only if data is Float32Array
  11869. if (!(this.data instanceof Array)) {
  11870. var newData = [];
  11871. for (var i = 0; i < this._len; i++) {
  11872. newData[i] = this.data[i];
  11873. }
  11874. this.data = newData;
  11875. }
  11876. },
  11877. /**
  11878. * If needs js implemented dashed line
  11879. * @return {boolean}
  11880. * @private
  11881. */
  11882. _needsDash: function () {
  11883. return this._lineDash;
  11884. },
  11885. _dashedLineTo: function (x1, y1) {
  11886. var dashSum = this._dashSum;
  11887. var offset = this._dashOffset;
  11888. var lineDash = this._lineDash;
  11889. var ctx = this._ctx;
  11890. var x0 = this._xi;
  11891. var y0 = this._yi;
  11892. var dx = x1 - x0;
  11893. var dy = y1 - y0;
  11894. var dist$$1 = mathSqrt$1(dx * dx + dy * dy);
  11895. var x = x0;
  11896. var y = y0;
  11897. var dash;
  11898. var nDash = lineDash.length;
  11899. var idx;
  11900. dx /= dist$$1;
  11901. dy /= dist$$1;
  11902. if (offset < 0) {
  11903. // Convert to positive offset
  11904. offset = dashSum + offset;
  11905. }
  11906. offset %= dashSum;
  11907. x -= offset * dx;
  11908. y -= offset * dy;
  11909. while ((dx > 0 && x <= x1) || (dx < 0 && x >= x1)
  11910. || (dx === 0 && ((dy > 0 && y <= y1) || (dy < 0 && y >= y1)))) {
  11911. idx = this._dashIdx;
  11912. dash = lineDash[idx];
  11913. x += dx * dash;
  11914. y += dy * dash;
  11915. this._dashIdx = (idx + 1) % nDash;
  11916. // Skip positive offset
  11917. if ((dx > 0 && x < x0) || (dx < 0 && x > x0) || (dy > 0 && y < y0) || (dy < 0 && y > y0)) {
  11918. continue;
  11919. }
  11920. ctx[idx % 2 ? 'moveTo' : 'lineTo'](
  11921. dx >= 0 ? mathMin$2(x, x1) : mathMax$2(x, x1),
  11922. dy >= 0 ? mathMin$2(y, y1) : mathMax$2(y, y1)
  11923. );
  11924. }
  11925. // Offset for next lineTo
  11926. dx = x - x1;
  11927. dy = y - y1;
  11928. this._dashOffset = -mathSqrt$1(dx * dx + dy * dy);
  11929. },
  11930. // Not accurate dashed line to
  11931. _dashedBezierTo: function (x1, y1, x2, y2, x3, y3) {
  11932. var dashSum = this._dashSum;
  11933. var offset = this._dashOffset;
  11934. var lineDash = this._lineDash;
  11935. var ctx = this._ctx;
  11936. var x0 = this._xi;
  11937. var y0 = this._yi;
  11938. var t;
  11939. var dx;
  11940. var dy;
  11941. var cubicAt$$1 = cubicAt;
  11942. var bezierLen = 0;
  11943. var idx = this._dashIdx;
  11944. var nDash = lineDash.length;
  11945. var x;
  11946. var y;
  11947. var tmpLen = 0;
  11948. if (offset < 0) {
  11949. // Convert to positive offset
  11950. offset = dashSum + offset;
  11951. }
  11952. offset %= dashSum;
  11953. // Bezier approx length
  11954. for (t = 0; t < 1; t += 0.1) {
  11955. dx = cubicAt$$1(x0, x1, x2, x3, t + 0.1)
  11956. - cubicAt$$1(x0, x1, x2, x3, t);
  11957. dy = cubicAt$$1(y0, y1, y2, y3, t + 0.1)
  11958. - cubicAt$$1(y0, y1, y2, y3, t);
  11959. bezierLen += mathSqrt$1(dx * dx + dy * dy);
  11960. }
  11961. // Find idx after add offset
  11962. for (; idx < nDash; idx++) {
  11963. tmpLen += lineDash[idx];
  11964. if (tmpLen > offset) {
  11965. break;
  11966. }
  11967. }
  11968. t = (tmpLen - offset) / bezierLen;
  11969. while (t <= 1) {
  11970. x = cubicAt$$1(x0, x1, x2, x3, t);
  11971. y = cubicAt$$1(y0, y1, y2, y3, t);
  11972. // Use line to approximate dashed bezier
  11973. // Bad result if dash is long
  11974. idx % 2 ? ctx.moveTo(x, y)
  11975. : ctx.lineTo(x, y);
  11976. t += lineDash[idx] / bezierLen;
  11977. idx = (idx + 1) % nDash;
  11978. }
  11979. // Finish the last segment and calculate the new offset
  11980. (idx % 2 !== 0) && ctx.lineTo(x3, y3);
  11981. dx = x3 - x;
  11982. dy = y3 - y;
  11983. this._dashOffset = -mathSqrt$1(dx * dx + dy * dy);
  11984. },
  11985. _dashedQuadraticTo: function (x1, y1, x2, y2) {
  11986. // Convert quadratic to cubic using degree elevation
  11987. var x3 = x2;
  11988. var y3 = y2;
  11989. x2 = (x2 + 2 * x1) / 3;
  11990. y2 = (y2 + 2 * y1) / 3;
  11991. x1 = (this._xi + 2 * x1) / 3;
  11992. y1 = (this._yi + 2 * y1) / 3;
  11993. this._dashedBezierTo(x1, y1, x2, y2, x3, y3);
  11994. },
  11995. /**
  11996. * 转成静态的 Float32Array 减少堆内存占用
  11997. * Convert dynamic array to static Float32Array
  11998. */
  11999. toStatic: function () {
  12000. var data = this.data;
  12001. if (data instanceof Array) {
  12002. data.length = this._len;
  12003. if (hasTypedArray) {
  12004. this.data = new Float32Array(data);
  12005. }
  12006. }
  12007. },
  12008. /**
  12009. * @return {module:zrender/core/BoundingRect}
  12010. */
  12011. getBoundingRect: function () {
  12012. min$1[0] = min$1[1] = min2[0] = min2[1] = Number.MAX_VALUE;
  12013. max$1[0] = max$1[1] = max2[0] = max2[1] = -Number.MAX_VALUE;
  12014. var data = this.data;
  12015. var xi = 0;
  12016. var yi = 0;
  12017. var x0 = 0;
  12018. var y0 = 0;
  12019. for (var i = 0; i < data.length;) {
  12020. var cmd = data[i++];
  12021. if (i === 1) {
  12022. // 如果第一个命令是 L, C, Q
  12023. // 则 previous point 同绘制命令的第一个 point
  12024. //
  12025. // 第一个命令为 Arc 的情况下会在后面特殊处理
  12026. xi = data[i];
  12027. yi = data[i + 1];
  12028. x0 = xi;
  12029. y0 = yi;
  12030. }
  12031. switch (cmd) {
  12032. case CMD.M:
  12033. // moveTo 命令重新创建一个新的 subpath, 并且更新新的起点
  12034. // 在 closePath 的时候使用
  12035. x0 = data[i++];
  12036. y0 = data[i++];
  12037. xi = x0;
  12038. yi = y0;
  12039. min2[0] = x0;
  12040. min2[1] = y0;
  12041. max2[0] = x0;
  12042. max2[1] = y0;
  12043. break;
  12044. case CMD.L:
  12045. fromLine(xi, yi, data[i], data[i + 1], min2, max2);
  12046. xi = data[i++];
  12047. yi = data[i++];
  12048. break;
  12049. case CMD.C:
  12050. fromCubic(
  12051. xi, yi, data[i++], data[i++], data[i++], data[i++], data[i], data[i + 1],
  12052. min2, max2
  12053. );
  12054. xi = data[i++];
  12055. yi = data[i++];
  12056. break;
  12057. case CMD.Q:
  12058. fromQuadratic(
  12059. xi, yi, data[i++], data[i++], data[i], data[i + 1],
  12060. min2, max2
  12061. );
  12062. xi = data[i++];
  12063. yi = data[i++];
  12064. break;
  12065. case CMD.A:
  12066. // TODO Arc 判断的开销比较大
  12067. var cx = data[i++];
  12068. var cy = data[i++];
  12069. var rx = data[i++];
  12070. var ry = data[i++];
  12071. var startAngle = data[i++];
  12072. var endAngle = data[i++] + startAngle;
  12073. // TODO Arc 旋转
  12074. i += 1;
  12075. var anticlockwise = 1 - data[i++];
  12076. if (i === 1) {
  12077. // 直接使用 arc 命令
  12078. // 第一个命令起点还未定义
  12079. x0 = mathCos$1(startAngle) * rx + cx;
  12080. y0 = mathSin$1(startAngle) * ry + cy;
  12081. }
  12082. fromArc(
  12083. cx, cy, rx, ry, startAngle, endAngle,
  12084. anticlockwise, min2, max2
  12085. );
  12086. xi = mathCos$1(endAngle) * rx + cx;
  12087. yi = mathSin$1(endAngle) * ry + cy;
  12088. break;
  12089. case CMD.R:
  12090. x0 = xi = data[i++];
  12091. y0 = yi = data[i++];
  12092. var width = data[i++];
  12093. var height = data[i++];
  12094. // Use fromLine
  12095. fromLine(x0, y0, x0 + width, y0 + height, min2, max2);
  12096. break;
  12097. case CMD.Z:
  12098. xi = x0;
  12099. yi = y0;
  12100. break;
  12101. }
  12102. // Union
  12103. min(min$1, min$1, min2);
  12104. max(max$1, max$1, max2);
  12105. }
  12106. // No data
  12107. if (i === 0) {
  12108. min$1[0] = min$1[1] = max$1[0] = max$1[1] = 0;
  12109. }
  12110. return new BoundingRect(
  12111. min$1[0], min$1[1], max$1[0] - min$1[0], max$1[1] - min$1[1]
  12112. );
  12113. },
  12114. /**
  12115. * Rebuild path from current data
  12116. * Rebuild path will not consider javascript implemented line dash.
  12117. * @param {CanvasRenderingContext2D} ctx
  12118. */
  12119. rebuildPath: function (ctx) {
  12120. var d = this.data;
  12121. var x0, y0;
  12122. var xi, yi;
  12123. var x, y;
  12124. var ux = this._ux;
  12125. var uy = this._uy;
  12126. var len$$1 = this._len;
  12127. for (var i = 0; i < len$$1;) {
  12128. var cmd = d[i++];
  12129. if (i === 1) {
  12130. // 如果第一个命令是 L, C, Q
  12131. // 则 previous point 同绘制命令的第一个 point
  12132. //
  12133. // 第一个命令为 Arc 的情况下会在后面特殊处理
  12134. xi = d[i];
  12135. yi = d[i + 1];
  12136. x0 = xi;
  12137. y0 = yi;
  12138. }
  12139. switch (cmd) {
  12140. case CMD.M:
  12141. x0 = xi = d[i++];
  12142. y0 = yi = d[i++];
  12143. ctx.moveTo(xi, yi);
  12144. break;
  12145. case CMD.L:
  12146. x = d[i++];
  12147. y = d[i++];
  12148. // Not draw too small seg between
  12149. if (mathAbs(x - xi) > ux || mathAbs(y - yi) > uy || i === len$$1 - 1) {
  12150. ctx.lineTo(x, y);
  12151. xi = x;
  12152. yi = y;
  12153. }
  12154. break;
  12155. case CMD.C:
  12156. ctx.bezierCurveTo(
  12157. d[i++], d[i++], d[i++], d[i++], d[i++], d[i++]
  12158. );
  12159. xi = d[i - 2];
  12160. yi = d[i - 1];
  12161. break;
  12162. case CMD.Q:
  12163. ctx.quadraticCurveTo(d[i++], d[i++], d[i++], d[i++]);
  12164. xi = d[i - 2];
  12165. yi = d[i - 1];
  12166. break;
  12167. case CMD.A:
  12168. var cx = d[i++];
  12169. var cy = d[i++];
  12170. var rx = d[i++];
  12171. var ry = d[i++];
  12172. var theta = d[i++];
  12173. var dTheta = d[i++];
  12174. var psi = d[i++];
  12175. var fs = d[i++];
  12176. var r = (rx > ry) ? rx : ry;
  12177. var scaleX = (rx > ry) ? 1 : rx / ry;
  12178. var scaleY = (rx > ry) ? ry / rx : 1;
  12179. var isEllipse = Math.abs(rx - ry) > 1e-3;
  12180. var endAngle = theta + dTheta;
  12181. if (isEllipse) {
  12182. ctx.translate(cx, cy);
  12183. ctx.rotate(psi);
  12184. ctx.scale(scaleX, scaleY);
  12185. ctx.arc(0, 0, r, theta, endAngle, 1 - fs);
  12186. ctx.scale(1 / scaleX, 1 / scaleY);
  12187. ctx.rotate(-psi);
  12188. ctx.translate(-cx, -cy);
  12189. }
  12190. else {
  12191. ctx.arc(cx, cy, r, theta, endAngle, 1 - fs);
  12192. }
  12193. if (i === 1) {
  12194. // 直接使用 arc 命令
  12195. // 第一个命令起点还未定义
  12196. x0 = mathCos$1(theta) * rx + cx;
  12197. y0 = mathSin$1(theta) * ry + cy;
  12198. }
  12199. xi = mathCos$1(endAngle) * rx + cx;
  12200. yi = mathSin$1(endAngle) * ry + cy;
  12201. break;
  12202. case CMD.R:
  12203. x0 = xi = d[i];
  12204. y0 = yi = d[i + 1];
  12205. ctx.rect(d[i++], d[i++], d[i++], d[i++]);
  12206. break;
  12207. case CMD.Z:
  12208. ctx.closePath();
  12209. xi = x0;
  12210. yi = y0;
  12211. }
  12212. }
  12213. }
  12214. };
  12215. PathProxy.CMD = CMD;
  12216. /**
  12217. * 线段包含判断
  12218. * @param {number} x0
  12219. * @param {number} y0
  12220. * @param {number} x1
  12221. * @param {number} y1
  12222. * @param {number} lineWidth
  12223. * @param {number} x
  12224. * @param {number} y
  12225. * @return {boolean}
  12226. */
  12227. function containStroke$1(x0, y0, x1, y1, lineWidth, x, y) {
  12228. if (lineWidth === 0) {
  12229. return false;
  12230. }
  12231. var _l = lineWidth;
  12232. var _a = 0;
  12233. var _b = x0;
  12234. // Quick reject
  12235. if (
  12236. (y > y0 + _l && y > y1 + _l)
  12237. || (y < y0 - _l && y < y1 - _l)
  12238. || (x > x0 + _l && x > x1 + _l)
  12239. || (x < x0 - _l && x < x1 - _l)
  12240. ) {
  12241. return false;
  12242. }
  12243. if (x0 !== x1) {
  12244. _a = (y0 - y1) / (x0 - x1);
  12245. _b = (x0 * y1 - x1 * y0) / (x0 - x1);
  12246. }
  12247. else {
  12248. return Math.abs(x - x0) <= _l / 2;
  12249. }
  12250. var tmp = _a * x - y + _b;
  12251. var _s = tmp * tmp / (_a * _a + 1);
  12252. return _s <= _l / 2 * _l / 2;
  12253. }
  12254. /**
  12255. * 三次贝塞尔曲线描边包含判断
  12256. * @param {number} x0
  12257. * @param {number} y0
  12258. * @param {number} x1
  12259. * @param {number} y1
  12260. * @param {number} x2
  12261. * @param {number} y2
  12262. * @param {number} x3
  12263. * @param {number} y3
  12264. * @param {number} lineWidth
  12265. * @param {number} x
  12266. * @param {number} y
  12267. * @return {boolean}
  12268. */
  12269. function containStroke$2(x0, y0, x1, y1, x2, y2, x3, y3, lineWidth, x, y) {
  12270. if (lineWidth === 0) {
  12271. return false;
  12272. }
  12273. var _l = lineWidth;
  12274. // Quick reject
  12275. if (
  12276. (y > y0 + _l && y > y1 + _l && y > y2 + _l && y > y3 + _l)
  12277. || (y < y0 - _l && y < y1 - _l && y < y2 - _l && y < y3 - _l)
  12278. || (x > x0 + _l && x > x1 + _l && x > x2 + _l && x > x3 + _l)
  12279. || (x < x0 - _l && x < x1 - _l && x < x2 - _l && x < x3 - _l)
  12280. ) {
  12281. return false;
  12282. }
  12283. var d = cubicProjectPoint(
  12284. x0, y0, x1, y1, x2, y2, x3, y3,
  12285. x, y, null
  12286. );
  12287. return d <= _l / 2;
  12288. }
  12289. /**
  12290. * 二次贝塞尔曲线描边包含判断
  12291. * @param {number} x0
  12292. * @param {number} y0
  12293. * @param {number} x1
  12294. * @param {number} y1
  12295. * @param {number} x2
  12296. * @param {number} y2
  12297. * @param {number} lineWidth
  12298. * @param {number} x
  12299. * @param {number} y
  12300. * @return {boolean}
  12301. */
  12302. function containStroke$3(x0, y0, x1, y1, x2, y2, lineWidth, x, y) {
  12303. if (lineWidth === 0) {
  12304. return false;
  12305. }
  12306. var _l = lineWidth;
  12307. // Quick reject
  12308. if (
  12309. (y > y0 + _l && y > y1 + _l && y > y2 + _l)
  12310. || (y < y0 - _l && y < y1 - _l && y < y2 - _l)
  12311. || (x > x0 + _l && x > x1 + _l && x > x2 + _l)
  12312. || (x < x0 - _l && x < x1 - _l && x < x2 - _l)
  12313. ) {
  12314. return false;
  12315. }
  12316. var d = quadraticProjectPoint(
  12317. x0, y0, x1, y1, x2, y2,
  12318. x, y, null
  12319. );
  12320. return d <= _l / 2;
  12321. }
  12322. var PI2$3 = Math.PI * 2;
  12323. function normalizeRadian(angle) {
  12324. angle %= PI2$3;
  12325. if (angle < 0) {
  12326. angle += PI2$3;
  12327. }
  12328. return angle;
  12329. }
  12330. var PI2$2 = Math.PI * 2;
  12331. /**
  12332. * 圆弧描边包含判断
  12333. * @param {number} cx
  12334. * @param {number} cy
  12335. * @param {number} r
  12336. * @param {number} startAngle
  12337. * @param {number} endAngle
  12338. * @param {boolean} anticlockwise
  12339. * @param {number} lineWidth
  12340. * @param {number} x
  12341. * @param {number} y
  12342. * @return {Boolean}
  12343. */
  12344. function containStroke$4(
  12345. cx, cy, r, startAngle, endAngle, anticlockwise,
  12346. lineWidth, x, y
  12347. ) {
  12348. if (lineWidth === 0) {
  12349. return false;
  12350. }
  12351. var _l = lineWidth;
  12352. x -= cx;
  12353. y -= cy;
  12354. var d = Math.sqrt(x * x + y * y);
  12355. if ((d - _l > r) || (d + _l < r)) {
  12356. return false;
  12357. }
  12358. if (Math.abs(startAngle - endAngle) % PI2$2 < 1e-4) {
  12359. // Is a circle
  12360. return true;
  12361. }
  12362. if (anticlockwise) {
  12363. var tmp = startAngle;
  12364. startAngle = normalizeRadian(endAngle);
  12365. endAngle = normalizeRadian(tmp);
  12366. }
  12367. else {
  12368. startAngle = normalizeRadian(startAngle);
  12369. endAngle = normalizeRadian(endAngle);
  12370. }
  12371. if (startAngle > endAngle) {
  12372. endAngle += PI2$2;
  12373. }
  12374. var angle = Math.atan2(y, x);
  12375. if (angle < 0) {
  12376. angle += PI2$2;
  12377. }
  12378. return (angle >= startAngle && angle <= endAngle)
  12379. || (angle + PI2$2 >= startAngle && angle + PI2$2 <= endAngle);
  12380. }
  12381. function windingLine(x0, y0, x1, y1, x, y) {
  12382. if ((y > y0 && y > y1) || (y < y0 && y < y1)) {
  12383. return 0;
  12384. }
  12385. // Ignore horizontal line
  12386. if (y1 === y0) {
  12387. return 0;
  12388. }
  12389. var dir = y1 < y0 ? 1 : -1;
  12390. var t = (y - y0) / (y1 - y0);
  12391. // Avoid winding error when intersection point is the connect point of two line of polygon
  12392. if (t === 1 || t === 0) {
  12393. dir = y1 < y0 ? 0.5 : -0.5;
  12394. }
  12395. var x_ = t * (x1 - x0) + x0;
  12396. // If (x, y) on the line, considered as "contain".
  12397. return x_ === x ? Infinity : x_ > x ? dir : 0;
  12398. }
  12399. var CMD$1 = PathProxy.CMD;
  12400. var PI2$1 = Math.PI * 2;
  12401. var EPSILON$2 = 1e-4;
  12402. function isAroundEqual(a, b) {
  12403. return Math.abs(a - b) < EPSILON$2;
  12404. }
  12405. // 临时数组
  12406. var roots = [-1, -1, -1];
  12407. var extrema = [-1, -1];
  12408. function swapExtrema() {
  12409. var tmp = extrema[0];
  12410. extrema[0] = extrema[1];
  12411. extrema[1] = tmp;
  12412. }
  12413. function windingCubic(x0, y0, x1, y1, x2, y2, x3, y3, x, y) {
  12414. // Quick reject
  12415. if (
  12416. (y > y0 && y > y1 && y > y2 && y > y3)
  12417. || (y < y0 && y < y1 && y < y2 && y < y3)
  12418. ) {
  12419. return 0;
  12420. }
  12421. var nRoots = cubicRootAt(y0, y1, y2, y3, y, roots);
  12422. if (nRoots === 0) {
  12423. return 0;
  12424. }
  12425. else {
  12426. var w = 0;
  12427. var nExtrema = -1;
  12428. var y0_;
  12429. var y1_;
  12430. for (var i = 0; i < nRoots; i++) {
  12431. var t = roots[i];
  12432. // Avoid winding error when intersection point is the connect point of two line of polygon
  12433. var unit = (t === 0 || t === 1) ? 0.5 : 1;
  12434. var x_ = cubicAt(x0, x1, x2, x3, t);
  12435. if (x_ < x) { // Quick reject
  12436. continue;
  12437. }
  12438. if (nExtrema < 0) {
  12439. nExtrema = cubicExtrema(y0, y1, y2, y3, extrema);
  12440. if (extrema[1] < extrema[0] && nExtrema > 1) {
  12441. swapExtrema();
  12442. }
  12443. y0_ = cubicAt(y0, y1, y2, y3, extrema[0]);
  12444. if (nExtrema > 1) {
  12445. y1_ = cubicAt(y0, y1, y2, y3, extrema[1]);
  12446. }
  12447. }
  12448. if (nExtrema === 2) {
  12449. // 分成三段单调函数
  12450. if (t < extrema[0]) {
  12451. w += y0_ < y0 ? unit : -unit;
  12452. }
  12453. else if (t < extrema[1]) {
  12454. w += y1_ < y0_ ? unit : -unit;
  12455. }
  12456. else {
  12457. w += y3 < y1_ ? unit : -unit;
  12458. }
  12459. }
  12460. else {
  12461. // 分成两段单调函数
  12462. if (t < extrema[0]) {
  12463. w += y0_ < y0 ? unit : -unit;
  12464. }
  12465. else {
  12466. w += y3 < y0_ ? unit : -unit;
  12467. }
  12468. }
  12469. }
  12470. return w;
  12471. }
  12472. }
  12473. function windingQuadratic(x0, y0, x1, y1, x2, y2, x, y) {
  12474. // Quick reject
  12475. if (
  12476. (y > y0 && y > y1 && y > y2)
  12477. || (y < y0 && y < y1 && y < y2)
  12478. ) {
  12479. return 0;
  12480. }
  12481. var nRoots = quadraticRootAt(y0, y1, y2, y, roots);
  12482. if (nRoots === 0) {
  12483. return 0;
  12484. }
  12485. else {
  12486. var t = quadraticExtremum(y0, y1, y2);
  12487. if (t >= 0 && t <= 1) {
  12488. var w = 0;
  12489. var y_ = quadraticAt(y0, y1, y2, t);
  12490. for (var i = 0; i < nRoots; i++) {
  12491. // Remove one endpoint.
  12492. var unit = (roots[i] === 0 || roots[i] === 1) ? 0.5 : 1;
  12493. var x_ = quadraticAt(x0, x1, x2, roots[i]);
  12494. if (x_ < x) { // Quick reject
  12495. continue;
  12496. }
  12497. if (roots[i] < t) {
  12498. w += y_ < y0 ? unit : -unit;
  12499. }
  12500. else {
  12501. w += y2 < y_ ? unit : -unit;
  12502. }
  12503. }
  12504. return w;
  12505. }
  12506. else {
  12507. // Remove one endpoint.
  12508. var unit = (roots[0] === 0 || roots[0] === 1) ? 0.5 : 1;
  12509. var x_ = quadraticAt(x0, x1, x2, roots[0]);
  12510. if (x_ < x) { // Quick reject
  12511. return 0;
  12512. }
  12513. return y2 < y0 ? unit : -unit;
  12514. }
  12515. }
  12516. }
  12517. // TODO
  12518. // Arc 旋转
  12519. function windingArc(
  12520. cx, cy, r, startAngle, endAngle, anticlockwise, x, y
  12521. ) {
  12522. y -= cy;
  12523. if (y > r || y < -r) {
  12524. return 0;
  12525. }
  12526. var tmp = Math.sqrt(r * r - y * y);
  12527. roots[0] = -tmp;
  12528. roots[1] = tmp;
  12529. var diff = Math.abs(startAngle - endAngle);
  12530. if (diff < 1e-4) {
  12531. return 0;
  12532. }
  12533. if (diff % PI2$1 < 1e-4) {
  12534. // Is a circle
  12535. startAngle = 0;
  12536. endAngle = PI2$1;
  12537. var dir = anticlockwise ? 1 : -1;
  12538. if (x >= roots[0] + cx && x <= roots[1] + cx) {
  12539. return dir;
  12540. }
  12541. else {
  12542. return 0;
  12543. }
  12544. }
  12545. if (anticlockwise) {
  12546. var tmp = startAngle;
  12547. startAngle = normalizeRadian(endAngle);
  12548. endAngle = normalizeRadian(tmp);
  12549. }
  12550. else {
  12551. startAngle = normalizeRadian(startAngle);
  12552. endAngle = normalizeRadian(endAngle);
  12553. }
  12554. if (startAngle > endAngle) {
  12555. endAngle += PI2$1;
  12556. }
  12557. var w = 0;
  12558. for (var i = 0; i < 2; i++) {
  12559. var x_ = roots[i];
  12560. if (x_ + cx > x) {
  12561. var angle = Math.atan2(y, x_);
  12562. var dir = anticlockwise ? 1 : -1;
  12563. if (angle < 0) {
  12564. angle = PI2$1 + angle;
  12565. }
  12566. if (
  12567. (angle >= startAngle && angle <= endAngle)
  12568. || (angle + PI2$1 >= startAngle && angle + PI2$1 <= endAngle)
  12569. ) {
  12570. if (angle > Math.PI / 2 && angle < Math.PI * 1.5) {
  12571. dir = -dir;
  12572. }
  12573. w += dir;
  12574. }
  12575. }
  12576. }
  12577. return w;
  12578. }
  12579. function containPath(data, lineWidth, isStroke, x, y) {
  12580. var w = 0;
  12581. var xi = 0;
  12582. var yi = 0;
  12583. var x0 = 0;
  12584. var y0 = 0;
  12585. for (var i = 0; i < data.length;) {
  12586. var cmd = data[i++];
  12587. // Begin a new subpath
  12588. if (cmd === CMD$1.M && i > 1) {
  12589. // Close previous subpath
  12590. if (!isStroke) {
  12591. w += windingLine(xi, yi, x0, y0, x, y);
  12592. }
  12593. // 如果被任何一个 subpath 包含
  12594. // if (w !== 0) {
  12595. // return true;
  12596. // }
  12597. }
  12598. if (i === 1) {
  12599. // 如果第一个命令是 L, C, Q
  12600. // 则 previous point 同绘制命令的第一个 point
  12601. //
  12602. // 第一个命令为 Arc 的情况下会在后面特殊处理
  12603. xi = data[i];
  12604. yi = data[i + 1];
  12605. x0 = xi;
  12606. y0 = yi;
  12607. }
  12608. switch (cmd) {
  12609. case CMD$1.M:
  12610. // moveTo 命令重新创建一个新的 subpath, 并且更新新的起点
  12611. // 在 closePath 的时候使用
  12612. x0 = data[i++];
  12613. y0 = data[i++];
  12614. xi = x0;
  12615. yi = y0;
  12616. break;
  12617. case CMD$1.L:
  12618. if (isStroke) {
  12619. if (containStroke$1(xi, yi, data[i], data[i + 1], lineWidth, x, y)) {
  12620. return true;
  12621. }
  12622. }
  12623. else {
  12624. // NOTE 在第一个命令为 L, C, Q 的时候会计算出 NaN
  12625. w += windingLine(xi, yi, data[i], data[i + 1], x, y) || 0;
  12626. }
  12627. xi = data[i++];
  12628. yi = data[i++];
  12629. break;
  12630. case CMD$1.C:
  12631. if (isStroke) {
  12632. if (containStroke$2(xi, yi,
  12633. data[i++], data[i++], data[i++], data[i++], data[i], data[i + 1],
  12634. lineWidth, x, y
  12635. )) {
  12636. return true;
  12637. }
  12638. }
  12639. else {
  12640. w += windingCubic(
  12641. xi, yi,
  12642. data[i++], data[i++], data[i++], data[i++], data[i], data[i + 1],
  12643. x, y
  12644. ) || 0;
  12645. }
  12646. xi = data[i++];
  12647. yi = data[i++];
  12648. break;
  12649. case CMD$1.Q:
  12650. if (isStroke) {
  12651. if (containStroke$3(xi, yi,
  12652. data[i++], data[i++], data[i], data[i + 1],
  12653. lineWidth, x, y
  12654. )) {
  12655. return true;
  12656. }
  12657. }
  12658. else {
  12659. w += windingQuadratic(
  12660. xi, yi,
  12661. data[i++], data[i++], data[i], data[i + 1],
  12662. x, y
  12663. ) || 0;
  12664. }
  12665. xi = data[i++];
  12666. yi = data[i++];
  12667. break;
  12668. case CMD$1.A:
  12669. // TODO Arc 判断的开销比较大
  12670. var cx = data[i++];
  12671. var cy = data[i++];
  12672. var rx = data[i++];
  12673. var ry = data[i++];
  12674. var theta = data[i++];
  12675. var dTheta = data[i++];
  12676. // TODO Arc 旋转
  12677. i += 1;
  12678. var anticlockwise = 1 - data[i++];
  12679. var x1 = Math.cos(theta) * rx + cx;
  12680. var y1 = Math.sin(theta) * ry + cy;
  12681. // 不是直接使用 arc 命令
  12682. if (i > 1) {
  12683. w += windingLine(xi, yi, x1, y1, x, y);
  12684. }
  12685. else {
  12686. // 第一个命令起点还未定义
  12687. x0 = x1;
  12688. y0 = y1;
  12689. }
  12690. // zr 使用scale来模拟椭圆, 这里也对x做一定的缩放
  12691. var _x = (x - cx) * ry / rx + cx;
  12692. if (isStroke) {
  12693. if (containStroke$4(
  12694. cx, cy, ry, theta, theta + dTheta, anticlockwise,
  12695. lineWidth, _x, y
  12696. )) {
  12697. return true;
  12698. }
  12699. }
  12700. else {
  12701. w += windingArc(
  12702. cx, cy, ry, theta, theta + dTheta, anticlockwise,
  12703. _x, y
  12704. );
  12705. }
  12706. xi = Math.cos(theta + dTheta) * rx + cx;
  12707. yi = Math.sin(theta + dTheta) * ry + cy;
  12708. break;
  12709. case CMD$1.R:
  12710. x0 = xi = data[i++];
  12711. y0 = yi = data[i++];
  12712. var width = data[i++];
  12713. var height = data[i++];
  12714. var x1 = x0 + width;
  12715. var y1 = y0 + height;
  12716. if (isStroke) {
  12717. if (containStroke$1(x0, y0, x1, y0, lineWidth, x, y)
  12718. || containStroke$1(x1, y0, x1, y1, lineWidth, x, y)
  12719. || containStroke$1(x1, y1, x0, y1, lineWidth, x, y)
  12720. || containStroke$1(x0, y1, x0, y0, lineWidth, x, y)
  12721. ) {
  12722. return true;
  12723. }
  12724. }
  12725. else {
  12726. // FIXME Clockwise ?
  12727. w += windingLine(x1, y0, x1, y1, x, y);
  12728. w += windingLine(x0, y1, x0, y0, x, y);
  12729. }
  12730. break;
  12731. case CMD$1.Z:
  12732. if (isStroke) {
  12733. if (containStroke$1(
  12734. xi, yi, x0, y0, lineWidth, x, y
  12735. )) {
  12736. return true;
  12737. }
  12738. }
  12739. else {
  12740. // Close a subpath
  12741. w += windingLine(xi, yi, x0, y0, x, y);
  12742. // 如果被任何一个 subpath 包含
  12743. // FIXME subpaths may overlap
  12744. // if (w !== 0) {
  12745. // return true;
  12746. // }
  12747. }
  12748. xi = x0;
  12749. yi = y0;
  12750. break;
  12751. }
  12752. }
  12753. if (!isStroke && !isAroundEqual(yi, y0)) {
  12754. w += windingLine(xi, yi, x0, y0, x, y) || 0;
  12755. }
  12756. return w !== 0;
  12757. }
  12758. function contain(pathData, x, y) {
  12759. return containPath(pathData, 0, false, x, y);
  12760. }
  12761. function containStroke(pathData, lineWidth, x, y) {
  12762. return containPath(pathData, lineWidth, true, x, y);
  12763. }
  12764. var getCanvasPattern = Pattern.prototype.getCanvasPattern;
  12765. var abs = Math.abs;
  12766. var pathProxyForDraw = new PathProxy(true);
  12767. /**
  12768. * @alias module:zrender/graphic/Path
  12769. * @extends module:zrender/graphic/Displayable
  12770. * @constructor
  12771. * @param {Object} opts
  12772. */
  12773. function Path(opts) {
  12774. Displayable.call(this, opts);
  12775. /**
  12776. * @type {module:zrender/core/PathProxy}
  12777. * @readOnly
  12778. */
  12779. this.path = null;
  12780. }
  12781. Path.prototype = {
  12782. constructor: Path,
  12783. type: 'path',
  12784. __dirtyPath: true,
  12785. strokeContainThreshold: 5,
  12786. // This item default to be false. But in map series in echarts,
  12787. // in order to improve performance, it should be set to true,
  12788. // so the shorty segment won't draw.
  12789. segmentIgnoreThreshold: 0,
  12790. /**
  12791. * See `module:zrender/src/graphic/helper/subPixelOptimize`.
  12792. * @type {boolean}
  12793. */
  12794. subPixelOptimize: false,
  12795. brush: function (ctx, prevEl) {
  12796. var style = this.style;
  12797. var path = this.path || pathProxyForDraw;
  12798. var hasStroke = style.hasStroke();
  12799. var hasFill = style.hasFill();
  12800. var fill = style.fill;
  12801. var stroke = style.stroke;
  12802. var hasFillGradient = hasFill && !!(fill.colorStops);
  12803. var hasStrokeGradient = hasStroke && !!(stroke.colorStops);
  12804. var hasFillPattern = hasFill && !!(fill.image);
  12805. var hasStrokePattern = hasStroke && !!(stroke.image);
  12806. style.bind(ctx, this, prevEl);
  12807. this.setTransform(ctx);
  12808. if (this.__dirty) {
  12809. var rect;
  12810. // Update gradient because bounding rect may changed
  12811. if (hasFillGradient) {
  12812. rect = rect || this.getBoundingRect();
  12813. this._fillGradient = style.getGradient(ctx, fill, rect);
  12814. }
  12815. if (hasStrokeGradient) {
  12816. rect = rect || this.getBoundingRect();
  12817. this._strokeGradient = style.getGradient(ctx, stroke, rect);
  12818. }
  12819. }
  12820. // Use the gradient or pattern
  12821. if (hasFillGradient) {
  12822. // PENDING If may have affect the state
  12823. ctx.fillStyle = this._fillGradient;
  12824. }
  12825. else if (hasFillPattern) {
  12826. ctx.fillStyle = getCanvasPattern.call(fill, ctx);
  12827. }
  12828. if (hasStrokeGradient) {
  12829. ctx.strokeStyle = this._strokeGradient;
  12830. }
  12831. else if (hasStrokePattern) {
  12832. ctx.strokeStyle = getCanvasPattern.call(stroke, ctx);
  12833. }
  12834. var lineDash = style.lineDash;
  12835. var lineDashOffset = style.lineDashOffset;
  12836. var ctxLineDash = !!ctx.setLineDash;
  12837. // Update path sx, sy
  12838. var scale = this.getGlobalScale();
  12839. path.setScale(scale[0], scale[1], this.segmentIgnoreThreshold);
  12840. // Proxy context
  12841. // Rebuild path in following 2 cases
  12842. // 1. Path is dirty
  12843. // 2. Path needs javascript implemented lineDash stroking.
  12844. // In this case, lineDash information will not be saved in PathProxy
  12845. if (this.__dirtyPath
  12846. || (lineDash && !ctxLineDash && hasStroke)
  12847. ) {
  12848. path.beginPath(ctx);
  12849. // Setting line dash before build path
  12850. if (lineDash && !ctxLineDash) {
  12851. path.setLineDash(lineDash);
  12852. path.setLineDashOffset(lineDashOffset);
  12853. }
  12854. this.buildPath(path, this.shape, false);
  12855. // Clear path dirty flag
  12856. if (this.path) {
  12857. this.__dirtyPath = false;
  12858. }
  12859. }
  12860. else {
  12861. // Replay path building
  12862. ctx.beginPath();
  12863. this.path.rebuildPath(ctx);
  12864. }
  12865. if (hasFill) {
  12866. if (style.fillOpacity != null) {
  12867. var originalGlobalAlpha = ctx.globalAlpha;
  12868. ctx.globalAlpha = style.fillOpacity * style.opacity;
  12869. path.fill(ctx);
  12870. ctx.globalAlpha = originalGlobalAlpha;
  12871. }
  12872. else {
  12873. path.fill(ctx);
  12874. }
  12875. }
  12876. if (lineDash && ctxLineDash) {
  12877. ctx.setLineDash(lineDash);
  12878. ctx.lineDashOffset = lineDashOffset;
  12879. }
  12880. if (hasStroke) {
  12881. if (style.strokeOpacity != null) {
  12882. var originalGlobalAlpha = ctx.globalAlpha;
  12883. ctx.globalAlpha = style.strokeOpacity * style.opacity;
  12884. path.stroke(ctx);
  12885. ctx.globalAlpha = originalGlobalAlpha;
  12886. }
  12887. else {
  12888. path.stroke(ctx);
  12889. }
  12890. }
  12891. if (lineDash && ctxLineDash) {
  12892. // PENDING
  12893. // Remove lineDash
  12894. ctx.setLineDash([]);
  12895. }
  12896. // Draw rect text
  12897. if (style.text != null) {
  12898. // Only restore transform when needs draw text.
  12899. this.restoreTransform(ctx);
  12900. this.drawRectText(ctx, this.getBoundingRect());
  12901. }
  12902. },
  12903. // When bundling path, some shape may decide if use moveTo to begin a new subpath or closePath
  12904. // Like in circle
  12905. buildPath: function (ctx, shapeCfg, inBundle) {},
  12906. createPathProxy: function () {
  12907. this.path = new PathProxy();
  12908. },
  12909. getBoundingRect: function () {
  12910. var rect = this._rect;
  12911. var style = this.style;
  12912. var needsUpdateRect = !rect;
  12913. if (needsUpdateRect) {
  12914. var path = this.path;
  12915. if (!path) {
  12916. // Create path on demand.
  12917. path = this.path = new PathProxy();
  12918. }
  12919. if (this.__dirtyPath) {
  12920. path.beginPath();
  12921. this.buildPath(path, this.shape, false);
  12922. }
  12923. rect = path.getBoundingRect();
  12924. }
  12925. this._rect = rect;
  12926. if (style.hasStroke()) {
  12927. // Needs update rect with stroke lineWidth when
  12928. // 1. Element changes scale or lineWidth
  12929. // 2. Shape is changed
  12930. var rectWithStroke = this._rectWithStroke || (this._rectWithStroke = rect.clone());
  12931. if (this.__dirty || needsUpdateRect) {
  12932. rectWithStroke.copy(rect);
  12933. // FIXME Must after updateTransform
  12934. var w = style.lineWidth;
  12935. // PENDING, Min line width is needed when line is horizontal or vertical
  12936. var lineScale = style.strokeNoScale ? this.getLineScale() : 1;
  12937. // Only add extra hover lineWidth when there are no fill
  12938. if (!style.hasFill()) {
  12939. w = Math.max(w, this.strokeContainThreshold || 4);
  12940. }
  12941. // Consider line width
  12942. // Line scale can't be 0;
  12943. if (lineScale > 1e-10) {
  12944. rectWithStroke.width += w / lineScale;
  12945. rectWithStroke.height += w / lineScale;
  12946. rectWithStroke.x -= w / lineScale / 2;
  12947. rectWithStroke.y -= w / lineScale / 2;
  12948. }
  12949. }
  12950. // Return rect with stroke
  12951. return rectWithStroke;
  12952. }
  12953. return rect;
  12954. },
  12955. contain: function (x, y) {
  12956. var localPos = this.transformCoordToLocal(x, y);
  12957. var rect = this.getBoundingRect();
  12958. var style = this.style;
  12959. x = localPos[0];
  12960. y = localPos[1];
  12961. if (rect.contain(x, y)) {
  12962. var pathData = this.path.data;
  12963. if (style.hasStroke()) {
  12964. var lineWidth = style.lineWidth;
  12965. var lineScale = style.strokeNoScale ? this.getLineScale() : 1;
  12966. // Line scale can't be 0;
  12967. if (lineScale > 1e-10) {
  12968. // Only add extra hover lineWidth when there are no fill
  12969. if (!style.hasFill()) {
  12970. lineWidth = Math.max(lineWidth, this.strokeContainThreshold);
  12971. }
  12972. if (containStroke(
  12973. pathData, lineWidth / lineScale, x, y
  12974. )) {
  12975. return true;
  12976. }
  12977. }
  12978. }
  12979. if (style.hasFill()) {
  12980. return contain(pathData, x, y);
  12981. }
  12982. }
  12983. return false;
  12984. },
  12985. /**
  12986. * @param {boolean} dirtyPath
  12987. */
  12988. dirty: function (dirtyPath) {
  12989. if (dirtyPath == null) {
  12990. dirtyPath = true;
  12991. }
  12992. // Only mark dirty, not mark clean
  12993. if (dirtyPath) {
  12994. this.__dirtyPath = dirtyPath;
  12995. this._rect = null;
  12996. }
  12997. this.__dirty = this.__dirtyText = true;
  12998. this.__zr && this.__zr.refresh();
  12999. // Used as a clipping path
  13000. if (this.__clipTarget) {
  13001. this.__clipTarget.dirty();
  13002. }
  13003. },
  13004. /**
  13005. * Alias for animate('shape')
  13006. * @param {boolean} loop
  13007. */
  13008. animateShape: function (loop) {
  13009. return this.animate('shape', loop);
  13010. },
  13011. // Overwrite attrKV
  13012. attrKV: function (key, value) {
  13013. // FIXME
  13014. if (key === 'shape') {
  13015. this.setShape(value);
  13016. this.__dirtyPath = true;
  13017. this._rect = null;
  13018. }
  13019. else {
  13020. Displayable.prototype.attrKV.call(this, key, value);
  13021. }
  13022. },
  13023. /**
  13024. * @param {Object|string} key
  13025. * @param {*} value
  13026. */
  13027. setShape: function (key, value) {
  13028. var shape = this.shape;
  13029. // Path from string may not have shape
  13030. if (shape) {
  13031. if (isObject$1(key)) {
  13032. for (var name in key) {
  13033. if (key.hasOwnProperty(name)) {
  13034. shape[name] = key[name];
  13035. }
  13036. }
  13037. }
  13038. else {
  13039. shape[key] = value;
  13040. }
  13041. this.dirty(true);
  13042. }
  13043. return this;
  13044. },
  13045. getLineScale: function () {
  13046. var m = this.transform;
  13047. // Get the line scale.
  13048. // Determinant of `m` means how much the area is enlarged by the
  13049. // transformation. So its square root can be used as a scale factor
  13050. // for width.
  13051. return m && abs(m[0] - 1) > 1e-10 && abs(m[3] - 1) > 1e-10
  13052. ? Math.sqrt(abs(m[0] * m[3] - m[2] * m[1]))
  13053. : 1;
  13054. }
  13055. };
  13056. /**
  13057. * 扩展一个 Path element, 比如星形,圆等。
  13058. * Extend a path element
  13059. * @param {Object} props
  13060. * @param {string} props.type Path type
  13061. * @param {Function} props.init Initialize
  13062. * @param {Function} props.buildPath Overwrite buildPath method
  13063. * @param {Object} [props.style] Extended default style config
  13064. * @param {Object} [props.shape] Extended default shape config
  13065. */
  13066. Path.extend = function (defaults$$1) {
  13067. var Sub = function (opts) {
  13068. Path.call(this, opts);
  13069. if (defaults$$1.style) {
  13070. // Extend default style
  13071. this.style.extendFrom(defaults$$1.style, false);
  13072. }
  13073. // Extend default shape
  13074. var defaultShape = defaults$$1.shape;
  13075. if (defaultShape) {
  13076. this.shape = this.shape || {};
  13077. var thisShape = this.shape;
  13078. for (var name in defaultShape) {
  13079. if (
  13080. !thisShape.hasOwnProperty(name)
  13081. && defaultShape.hasOwnProperty(name)
  13082. ) {
  13083. thisShape[name] = defaultShape[name];
  13084. }
  13085. }
  13086. }
  13087. defaults$$1.init && defaults$$1.init.call(this, opts);
  13088. };
  13089. inherits(Sub, Path);
  13090. // FIXME 不能 extend position, rotation 等引用对象
  13091. for (var name in defaults$$1) {
  13092. // Extending prototype values and methods
  13093. if (name !== 'style' && name !== 'shape') {
  13094. Sub.prototype[name] = defaults$$1[name];
  13095. }
  13096. }
  13097. return Sub;
  13098. };
  13099. inherits(Path, Displayable);
  13100. var CMD$2 = PathProxy.CMD;
  13101. var points = [[], [], []];
  13102. var mathSqrt$3 = Math.sqrt;
  13103. var mathAtan2 = Math.atan2;
  13104. var transformPath = function (path, m) {
  13105. var data = path.data;
  13106. var cmd;
  13107. var nPoint;
  13108. var i;
  13109. var j;
  13110. var k;
  13111. var p;
  13112. var M = CMD$2.M;
  13113. var C = CMD$2.C;
  13114. var L = CMD$2.L;
  13115. var R = CMD$2.R;
  13116. var A = CMD$2.A;
  13117. var Q = CMD$2.Q;
  13118. for (i = 0, j = 0; i < data.length;) {
  13119. cmd = data[i++];
  13120. j = i;
  13121. nPoint = 0;
  13122. switch (cmd) {
  13123. case M:
  13124. nPoint = 1;
  13125. break;
  13126. case L:
  13127. nPoint = 1;
  13128. break;
  13129. case C:
  13130. nPoint = 3;
  13131. break;
  13132. case Q:
  13133. nPoint = 2;
  13134. break;
  13135. case A:
  13136. var x = m[4];
  13137. var y = m[5];
  13138. var sx = mathSqrt$3(m[0] * m[0] + m[1] * m[1]);
  13139. var sy = mathSqrt$3(m[2] * m[2] + m[3] * m[3]);
  13140. var angle = mathAtan2(-m[1] / sy, m[0] / sx);
  13141. // cx
  13142. data[i] *= sx;
  13143. data[i++] += x;
  13144. // cy
  13145. data[i] *= sy;
  13146. data[i++] += y;
  13147. // Scale rx and ry
  13148. // FIXME Assume psi is 0 here
  13149. data[i++] *= sx;
  13150. data[i++] *= sy;
  13151. // Start angle
  13152. data[i++] += angle;
  13153. // end angle
  13154. data[i++] += angle;
  13155. // FIXME psi
  13156. i += 2;
  13157. j = i;
  13158. break;
  13159. case R:
  13160. // x0, y0
  13161. p[0] = data[i++];
  13162. p[1] = data[i++];
  13163. applyTransform(p, p, m);
  13164. data[j++] = p[0];
  13165. data[j++] = p[1];
  13166. // x1, y1
  13167. p[0] += data[i++];
  13168. p[1] += data[i++];
  13169. applyTransform(p, p, m);
  13170. data[j++] = p[0];
  13171. data[j++] = p[1];
  13172. }
  13173. for (k = 0; k < nPoint; k++) {
  13174. var p = points[k];
  13175. p[0] = data[i++];
  13176. p[1] = data[i++];
  13177. applyTransform(p, p, m);
  13178. // Write back
  13179. data[j++] = p[0];
  13180. data[j++] = p[1];
  13181. }
  13182. }
  13183. };
  13184. // command chars
  13185. // var cc = [
  13186. // 'm', 'M', 'l', 'L', 'v', 'V', 'h', 'H', 'z', 'Z',
  13187. // 'c', 'C', 'q', 'Q', 't', 'T', 's', 'S', 'a', 'A'
  13188. // ];
  13189. var mathSqrt = Math.sqrt;
  13190. var mathSin = Math.sin;
  13191. var mathCos = Math.cos;
  13192. var PI = Math.PI;
  13193. var vMag = function (v) {
  13194. return Math.sqrt(v[0] * v[0] + v[1] * v[1]);
  13195. };
  13196. var vRatio = function (u, v) {
  13197. return (u[0] * v[0] + u[1] * v[1]) / (vMag(u) * vMag(v));
  13198. };
  13199. var vAngle = function (u, v) {
  13200. return (u[0] * v[1] < u[1] * v[0] ? -1 : 1)
  13201. * Math.acos(vRatio(u, v));
  13202. };
  13203. function processArc(x1, y1, x2, y2, fa, fs, rx, ry, psiDeg, cmd, path) {
  13204. var psi = psiDeg * (PI / 180.0);
  13205. var xp = mathCos(psi) * (x1 - x2) / 2.0
  13206. + mathSin(psi) * (y1 - y2) / 2.0;
  13207. var yp = -1 * mathSin(psi) * (x1 - x2) / 2.0
  13208. + mathCos(psi) * (y1 - y2) / 2.0;
  13209. var lambda = (xp * xp) / (rx * rx) + (yp * yp) / (ry * ry);
  13210. if (lambda > 1) {
  13211. rx *= mathSqrt(lambda);
  13212. ry *= mathSqrt(lambda);
  13213. }
  13214. var f = (fa === fs ? -1 : 1)
  13215. * mathSqrt((((rx * rx) * (ry * ry))
  13216. - ((rx * rx) * (yp * yp))
  13217. - ((ry * ry) * (xp * xp))) / ((rx * rx) * (yp * yp)
  13218. + (ry * ry) * (xp * xp))
  13219. ) || 0;
  13220. var cxp = f * rx * yp / ry;
  13221. var cyp = f * -ry * xp / rx;
  13222. var cx = (x1 + x2) / 2.0
  13223. + mathCos(psi) * cxp
  13224. - mathSin(psi) * cyp;
  13225. var cy = (y1 + y2) / 2.0
  13226. + mathSin(psi) * cxp
  13227. + mathCos(psi) * cyp;
  13228. var theta = vAngle([ 1, 0 ], [ (xp - cxp) / rx, (yp - cyp) / ry ]);
  13229. var u = [ (xp - cxp) / rx, (yp - cyp) / ry ];
  13230. var v = [ (-1 * xp - cxp) / rx, (-1 * yp - cyp) / ry ];
  13231. var dTheta = vAngle(u, v);
  13232. if (vRatio(u, v) <= -1) {
  13233. dTheta = PI;
  13234. }
  13235. if (vRatio(u, v) >= 1) {
  13236. dTheta = 0;
  13237. }
  13238. if (fs === 0 && dTheta > 0) {
  13239. dTheta = dTheta - 2 * PI;
  13240. }
  13241. if (fs === 1 && dTheta < 0) {
  13242. dTheta = dTheta + 2 * PI;
  13243. }
  13244. path.addData(cmd, cx, cy, rx, ry, theta, dTheta, psi, fs);
  13245. }
  13246. var commandReg = /([mlvhzcqtsa])([^mlvhzcqtsa]*)/ig;
  13247. // Consider case:
  13248. // (1) delimiter can be comma or space, where continuous commas
  13249. // or spaces should be seen as one comma.
  13250. // (2) value can be like:
  13251. // '2e-4', 'l.5.9' (ignore 0), 'M-10-10', 'l-2.43e-1,34.9983',
  13252. // 'l-.5E1,54', '121-23-44-11' (no delimiter)
  13253. var numberReg = /-?([0-9]*\.)?[0-9]+([eE]-?[0-9]+)?/g;
  13254. // var valueSplitReg = /[\s,]+/;
  13255. function createPathProxyFromString(data) {
  13256. if (!data) {
  13257. return new PathProxy();
  13258. }
  13259. // var data = data.replace(/-/g, ' -')
  13260. // .replace(/ /g, ' ')
  13261. // .replace(/ /g, ',')
  13262. // .replace(/,,/g, ',');
  13263. // var n;
  13264. // create pipes so that we can split the data
  13265. // for (n = 0; n < cc.length; n++) {
  13266. // cs = cs.replace(new RegExp(cc[n], 'g'), '|' + cc[n]);
  13267. // }
  13268. // data = data.replace(/-/g, ',-');
  13269. // create array
  13270. // var arr = cs.split('|');
  13271. // init context point
  13272. var cpx = 0;
  13273. var cpy = 0;
  13274. var subpathX = cpx;
  13275. var subpathY = cpy;
  13276. var prevCmd;
  13277. var path = new PathProxy();
  13278. var CMD = PathProxy.CMD;
  13279. // commandReg.lastIndex = 0;
  13280. // var cmdResult;
  13281. // while ((cmdResult = commandReg.exec(data)) != null) {
  13282. // var cmdStr = cmdResult[1];
  13283. // var cmdContent = cmdResult[2];
  13284. var cmdList = data.match(commandReg);
  13285. for (var l = 0; l < cmdList.length; l++) {
  13286. var cmdText = cmdList[l];
  13287. var cmdStr = cmdText.charAt(0);
  13288. var cmd;
  13289. // String#split is faster a little bit than String#replace or RegExp#exec.
  13290. // var p = cmdContent.split(valueSplitReg);
  13291. // var pLen = 0;
  13292. // for (var i = 0; i < p.length; i++) {
  13293. // // '' and other invalid str => NaN
  13294. // var val = parseFloat(p[i]);
  13295. // !isNaN(val) && (p[pLen++] = val);
  13296. // }
  13297. var p = cmdText.match(numberReg) || [];
  13298. var pLen = p.length;
  13299. for (var i = 0; i < pLen; i++) {
  13300. p[i] = parseFloat(p[i]);
  13301. }
  13302. var off = 0;
  13303. while (off < pLen) {
  13304. var ctlPtx;
  13305. var ctlPty;
  13306. var rx;
  13307. var ry;
  13308. var psi;
  13309. var fa;
  13310. var fs;
  13311. var x1 = cpx;
  13312. var y1 = cpy;
  13313. // convert l, H, h, V, and v to L
  13314. switch (cmdStr) {
  13315. case 'l':
  13316. cpx += p[off++];
  13317. cpy += p[off++];
  13318. cmd = CMD.L;
  13319. path.addData(cmd, cpx, cpy);
  13320. break;
  13321. case 'L':
  13322. cpx = p[off++];
  13323. cpy = p[off++];
  13324. cmd = CMD.L;
  13325. path.addData(cmd, cpx, cpy);
  13326. break;
  13327. case 'm':
  13328. cpx += p[off++];
  13329. cpy += p[off++];
  13330. cmd = CMD.M;
  13331. path.addData(cmd, cpx, cpy);
  13332. subpathX = cpx;
  13333. subpathY = cpy;
  13334. cmdStr = 'l';
  13335. break;
  13336. case 'M':
  13337. cpx = p[off++];
  13338. cpy = p[off++];
  13339. cmd = CMD.M;
  13340. path.addData(cmd, cpx, cpy);
  13341. subpathX = cpx;
  13342. subpathY = cpy;
  13343. cmdStr = 'L';
  13344. break;
  13345. case 'h':
  13346. cpx += p[off++];
  13347. cmd = CMD.L;
  13348. path.addData(cmd, cpx, cpy);
  13349. break;
  13350. case 'H':
  13351. cpx = p[off++];
  13352. cmd = CMD.L;
  13353. path.addData(cmd, cpx, cpy);
  13354. break;
  13355. case 'v':
  13356. cpy += p[off++];
  13357. cmd = CMD.L;
  13358. path.addData(cmd, cpx, cpy);
  13359. break;
  13360. case 'V':
  13361. cpy = p[off++];
  13362. cmd = CMD.L;
  13363. path.addData(cmd, cpx, cpy);
  13364. break;
  13365. case 'C':
  13366. cmd = CMD.C;
  13367. path.addData(
  13368. cmd, p[off++], p[off++], p[off++], p[off++], p[off++], p[off++]
  13369. );
  13370. cpx = p[off - 2];
  13371. cpy = p[off - 1];
  13372. break;
  13373. case 'c':
  13374. cmd = CMD.C;
  13375. path.addData(
  13376. cmd,
  13377. p[off++] + cpx, p[off++] + cpy,
  13378. p[off++] + cpx, p[off++] + cpy,
  13379. p[off++] + cpx, p[off++] + cpy
  13380. );
  13381. cpx += p[off - 2];
  13382. cpy += p[off - 1];
  13383. break;
  13384. case 'S':
  13385. ctlPtx = cpx;
  13386. ctlPty = cpy;
  13387. var len = path.len();
  13388. var pathData = path.data;
  13389. if (prevCmd === CMD.C) {
  13390. ctlPtx += cpx - pathData[len - 4];
  13391. ctlPty += cpy - pathData[len - 3];
  13392. }
  13393. cmd = CMD.C;
  13394. x1 = p[off++];
  13395. y1 = p[off++];
  13396. cpx = p[off++];
  13397. cpy = p[off++];
  13398. path.addData(cmd, ctlPtx, ctlPty, x1, y1, cpx, cpy);
  13399. break;
  13400. case 's':
  13401. ctlPtx = cpx;
  13402. ctlPty = cpy;
  13403. var len = path.len();
  13404. var pathData = path.data;
  13405. if (prevCmd === CMD.C) {
  13406. ctlPtx += cpx - pathData[len - 4];
  13407. ctlPty += cpy - pathData[len - 3];
  13408. }
  13409. cmd = CMD.C;
  13410. x1 = cpx + p[off++];
  13411. y1 = cpy + p[off++];
  13412. cpx += p[off++];
  13413. cpy += p[off++];
  13414. path.addData(cmd, ctlPtx, ctlPty, x1, y1, cpx, cpy);
  13415. break;
  13416. case 'Q':
  13417. x1 = p[off++];
  13418. y1 = p[off++];
  13419. cpx = p[off++];
  13420. cpy = p[off++];
  13421. cmd = CMD.Q;
  13422. path.addData(cmd, x1, y1, cpx, cpy);
  13423. break;
  13424. case 'q':
  13425. x1 = p[off++] + cpx;
  13426. y1 = p[off++] + cpy;
  13427. cpx += p[off++];
  13428. cpy += p[off++];
  13429. cmd = CMD.Q;
  13430. path.addData(cmd, x1, y1, cpx, cpy);
  13431. break;
  13432. case 'T':
  13433. ctlPtx = cpx;
  13434. ctlPty = cpy;
  13435. var len = path.len();
  13436. var pathData = path.data;
  13437. if (prevCmd === CMD.Q) {
  13438. ctlPtx += cpx - pathData[len - 4];
  13439. ctlPty += cpy - pathData[len - 3];
  13440. }
  13441. cpx = p[off++];
  13442. cpy = p[off++];
  13443. cmd = CMD.Q;
  13444. path.addData(cmd, ctlPtx, ctlPty, cpx, cpy);
  13445. break;
  13446. case 't':
  13447. ctlPtx = cpx;
  13448. ctlPty = cpy;
  13449. var len = path.len();
  13450. var pathData = path.data;
  13451. if (prevCmd === CMD.Q) {
  13452. ctlPtx += cpx - pathData[len - 4];
  13453. ctlPty += cpy - pathData[len - 3];
  13454. }
  13455. cpx += p[off++];
  13456. cpy += p[off++];
  13457. cmd = CMD.Q;
  13458. path.addData(cmd, ctlPtx, ctlPty, cpx, cpy);
  13459. break;
  13460. case 'A':
  13461. rx = p[off++];
  13462. ry = p[off++];
  13463. psi = p[off++];
  13464. fa = p[off++];
  13465. fs = p[off++];
  13466. x1 = cpx, y1 = cpy;
  13467. cpx = p[off++];
  13468. cpy = p[off++];
  13469. cmd = CMD.A;
  13470. processArc(
  13471. x1, y1, cpx, cpy, fa, fs, rx, ry, psi, cmd, path
  13472. );
  13473. break;
  13474. case 'a':
  13475. rx = p[off++];
  13476. ry = p[off++];
  13477. psi = p[off++];
  13478. fa = p[off++];
  13479. fs = p[off++];
  13480. x1 = cpx, y1 = cpy;
  13481. cpx += p[off++];
  13482. cpy += p[off++];
  13483. cmd = CMD.A;
  13484. processArc(
  13485. x1, y1, cpx, cpy, fa, fs, rx, ry, psi, cmd, path
  13486. );
  13487. break;
  13488. }
  13489. }
  13490. if (cmdStr === 'z' || cmdStr === 'Z') {
  13491. cmd = CMD.Z;
  13492. path.addData(cmd);
  13493. // z may be in the middle of the path.
  13494. cpx = subpathX;
  13495. cpy = subpathY;
  13496. }
  13497. prevCmd = cmd;
  13498. }
  13499. path.toStatic();
  13500. return path;
  13501. }
  13502. // TODO Optimize double memory cost problem
  13503. function createPathOptions(str, opts) {
  13504. var pathProxy = createPathProxyFromString(str);
  13505. opts = opts || {};
  13506. opts.buildPath = function (path) {
  13507. if (path.setData) {
  13508. path.setData(pathProxy.data);
  13509. // Svg and vml renderer don't have context
  13510. var ctx = path.getContext();
  13511. if (ctx) {
  13512. path.rebuildPath(ctx);
  13513. }
  13514. }
  13515. else {
  13516. var ctx = path;
  13517. pathProxy.rebuildPath(ctx);
  13518. }
  13519. };
  13520. opts.applyTransform = function (m) {
  13521. transformPath(pathProxy, m);
  13522. this.dirty(true);
  13523. };
  13524. return opts;
  13525. }
  13526. /**
  13527. * Create a Path object from path string data
  13528. * http://www.w3.org/TR/SVG/paths.html#PathData
  13529. * @param {Object} opts Other options
  13530. */
  13531. function createFromString(str, opts) {
  13532. return new Path(createPathOptions(str, opts));
  13533. }
  13534. /**
  13535. * Create a Path class from path string data
  13536. * @param {string} str
  13537. * @param {Object} opts Other options
  13538. */
  13539. function extendFromString(str, opts) {
  13540. return Path.extend(createPathOptions(str, opts));
  13541. }
  13542. /**
  13543. * Merge multiple paths
  13544. */
  13545. // TODO Apply transform
  13546. // TODO stroke dash
  13547. // TODO Optimize double memory cost problem
  13548. function mergePath$1(pathEls, opts) {
  13549. var pathList = [];
  13550. var len = pathEls.length;
  13551. for (var i = 0; i < len; i++) {
  13552. var pathEl = pathEls[i];
  13553. if (!pathEl.path) {
  13554. pathEl.createPathProxy();
  13555. }
  13556. if (pathEl.__dirtyPath) {
  13557. pathEl.buildPath(pathEl.path, pathEl.shape, true);
  13558. }
  13559. pathList.push(pathEl.path);
  13560. }
  13561. var pathBundle = new Path(opts);
  13562. // Need path proxy.
  13563. pathBundle.createPathProxy();
  13564. pathBundle.buildPath = function (path) {
  13565. path.appendPath(pathList);
  13566. // Svg and vml renderer don't have context
  13567. var ctx = path.getContext();
  13568. if (ctx) {
  13569. path.rebuildPath(ctx);
  13570. }
  13571. };
  13572. return pathBundle;
  13573. }
  13574. /**
  13575. * @alias zrender/graphic/Text
  13576. * @extends module:zrender/graphic/Displayable
  13577. * @constructor
  13578. * @param {Object} opts
  13579. */
  13580. var Text = function (opts) { // jshint ignore:line
  13581. Displayable.call(this, opts);
  13582. };
  13583. Text.prototype = {
  13584. constructor: Text,
  13585. type: 'text',
  13586. brush: function (ctx, prevEl) {
  13587. var style = this.style;
  13588. // Optimize, avoid normalize every time.
  13589. this.__dirty && normalizeTextStyle(style, true);
  13590. // Use props with prefix 'text'.
  13591. style.fill = style.stroke = style.shadowBlur = style.shadowColor =
  13592. style.shadowOffsetX = style.shadowOffsetY = null;
  13593. var text = style.text;
  13594. // Convert to string
  13595. text != null && (text += '');
  13596. // Do not apply style.bind in Text node. Because the real bind job
  13597. // is in textHelper.renderText, and performance of text render should
  13598. // be considered.
  13599. // style.bind(ctx, this, prevEl);
  13600. if (!needDrawText(text, style)) {
  13601. // The current el.style is not applied
  13602. // and should not be used as cache.
  13603. ctx.__attrCachedBy = ContextCachedBy.NONE;
  13604. return;
  13605. }
  13606. this.setTransform(ctx);
  13607. renderText(this, ctx, text, style, null, prevEl);
  13608. this.restoreTransform(ctx);
  13609. },
  13610. getBoundingRect: function () {
  13611. var style = this.style;
  13612. // Optimize, avoid normalize every time.
  13613. this.__dirty && normalizeTextStyle(style, true);
  13614. if (!this._rect) {
  13615. var text = style.text;
  13616. text != null ? (text += '') : (text = '');
  13617. var rect = getBoundingRect(
  13618. style.text + '',
  13619. style.font,
  13620. style.textAlign,
  13621. style.textVerticalAlign,
  13622. style.textPadding,
  13623. style.textLineHeight,
  13624. style.rich
  13625. );
  13626. rect.x += style.x || 0;
  13627. rect.y += style.y || 0;
  13628. if (getStroke(style.textStroke, style.textStrokeWidth)) {
  13629. var w = style.textStrokeWidth;
  13630. rect.x -= w / 2;
  13631. rect.y -= w / 2;
  13632. rect.width += w;
  13633. rect.height += w;
  13634. }
  13635. this._rect = rect;
  13636. }
  13637. return this._rect;
  13638. }
  13639. };
  13640. inherits(Text, Displayable);
  13641. /**
  13642. * 圆形
  13643. * @module zrender/shape/Circle
  13644. */
  13645. var Circle = Path.extend({
  13646. type: 'circle',
  13647. shape: {
  13648. cx: 0,
  13649. cy: 0,
  13650. r: 0
  13651. },
  13652. buildPath: function (ctx, shape, inBundle) {
  13653. // Better stroking in ShapeBundle
  13654. // Always do it may have performence issue ( fill may be 2x more cost)
  13655. if (inBundle) {
  13656. ctx.moveTo(shape.cx + shape.r, shape.cy);
  13657. }
  13658. // else {
  13659. // if (ctx.allocate && !ctx.data.length) {
  13660. // ctx.allocate(ctx.CMD_MEM_SIZE.A);
  13661. // }
  13662. // }
  13663. // Better stroking in ShapeBundle
  13664. // ctx.moveTo(shape.cx + shape.r, shape.cy);
  13665. ctx.arc(shape.cx, shape.cy, shape.r, 0, Math.PI * 2, true);
  13666. }
  13667. });
  13668. // Fix weird bug in some version of IE11 (like 11.0.9600.178**),
  13669. // where exception "unexpected call to method or property access"
  13670. // might be thrown when calling ctx.fill or ctx.stroke after a path
  13671. // whose area size is zero is drawn and ctx.clip() is called and
  13672. // shadowBlur is set. See #4572, #3112, #5777.
  13673. // (e.g.,
  13674. // ctx.moveTo(10, 10);
  13675. // ctx.lineTo(20, 10);
  13676. // ctx.closePath();
  13677. // ctx.clip();
  13678. // ctx.shadowBlur = 10;
  13679. // ...
  13680. // ctx.fill();
  13681. // )
  13682. var shadowTemp = [
  13683. ['shadowBlur', 0],
  13684. ['shadowColor', '#000'],
  13685. ['shadowOffsetX', 0],
  13686. ['shadowOffsetY', 0]
  13687. ];
  13688. var fixClipWithShadow = function (orignalBrush) {
  13689. // version string can be: '11.0'
  13690. return (env$1.browser.ie && env$1.browser.version >= 11)
  13691. ? function () {
  13692. var clipPaths = this.__clipPaths;
  13693. var style = this.style;
  13694. var modified;
  13695. if (clipPaths) {
  13696. for (var i = 0; i < clipPaths.length; i++) {
  13697. var clipPath = clipPaths[i];
  13698. var shape = clipPath && clipPath.shape;
  13699. var type = clipPath && clipPath.type;
  13700. if (shape && (
  13701. (type === 'sector' && shape.startAngle === shape.endAngle)
  13702. || (type === 'rect' && (!shape.width || !shape.height))
  13703. )) {
  13704. for (var j = 0; j < shadowTemp.length; j++) {
  13705. // It is save to put shadowTemp static, because shadowTemp
  13706. // will be all modified each item brush called.
  13707. shadowTemp[j][2] = style[shadowTemp[j][0]];
  13708. style[shadowTemp[j][0]] = shadowTemp[j][1];
  13709. }
  13710. modified = true;
  13711. break;
  13712. }
  13713. }
  13714. }
  13715. orignalBrush.apply(this, arguments);
  13716. if (modified) {
  13717. for (var j = 0; j < shadowTemp.length; j++) {
  13718. style[shadowTemp[j][0]] = shadowTemp[j][2];
  13719. }
  13720. }
  13721. }
  13722. : orignalBrush;
  13723. };
  13724. /**
  13725. * 扇形
  13726. * @module zrender/graphic/shape/Sector
  13727. */
  13728. var Sector = Path.extend({
  13729. type: 'sector',
  13730. shape: {
  13731. cx: 0,
  13732. cy: 0,
  13733. r0: 0,
  13734. r: 0,
  13735. startAngle: 0,
  13736. endAngle: Math.PI * 2,
  13737. clockwise: true
  13738. },
  13739. brush: fixClipWithShadow(Path.prototype.brush),
  13740. buildPath: function (ctx, shape) {
  13741. var x = shape.cx;
  13742. var y = shape.cy;
  13743. var r0 = Math.max(shape.r0 || 0, 0);
  13744. var r = Math.max(shape.r, 0);
  13745. var startAngle = shape.startAngle;
  13746. var endAngle = shape.endAngle;
  13747. var clockwise = shape.clockwise;
  13748. var unitX = Math.cos(startAngle);
  13749. var unitY = Math.sin(startAngle);
  13750. ctx.moveTo(unitX * r0 + x, unitY * r0 + y);
  13751. ctx.lineTo(unitX * r + x, unitY * r + y);
  13752. ctx.arc(x, y, r, startAngle, endAngle, !clockwise);
  13753. ctx.lineTo(
  13754. Math.cos(endAngle) * r0 + x,
  13755. Math.sin(endAngle) * r0 + y
  13756. );
  13757. if (r0 !== 0) {
  13758. ctx.arc(x, y, r0, endAngle, startAngle, clockwise);
  13759. }
  13760. ctx.closePath();
  13761. }
  13762. });
  13763. /**
  13764. * 圆环
  13765. * @module zrender/graphic/shape/Ring
  13766. */
  13767. var Ring = Path.extend({
  13768. type: 'ring',
  13769. shape: {
  13770. cx: 0,
  13771. cy: 0,
  13772. r: 0,
  13773. r0: 0
  13774. },
  13775. buildPath: function (ctx, shape) {
  13776. var x = shape.cx;
  13777. var y = shape.cy;
  13778. var PI2 = Math.PI * 2;
  13779. ctx.moveTo(x + shape.r, y);
  13780. ctx.arc(x, y, shape.r, 0, PI2, false);
  13781. ctx.moveTo(x + shape.r0, y);
  13782. ctx.arc(x, y, shape.r0, 0, PI2, true);
  13783. }
  13784. });
  13785. /**
  13786. * Catmull-Rom spline 插值折线
  13787. * @module zrender/shape/util/smoothSpline
  13788. * @author pissang (https://www.github.com/pissang)
  13789. * Kener (@Kener-林峰, kener.linfeng@gmail.com)
  13790. * errorrik (errorrik@gmail.com)
  13791. */
  13792. /**
  13793. * @inner
  13794. */
  13795. function interpolate(p0, p1, p2, p3, t, t2, t3) {
  13796. var v0 = (p2 - p0) * 0.5;
  13797. var v1 = (p3 - p1) * 0.5;
  13798. return (2 * (p1 - p2) + v0 + v1) * t3
  13799. + (-3 * (p1 - p2) - 2 * v0 - v1) * t2
  13800. + v0 * t + p1;
  13801. }
  13802. /**
  13803. * @alias module:zrender/shape/util/smoothSpline
  13804. * @param {Array} points 线段顶点数组
  13805. * @param {boolean} isLoop
  13806. * @return {Array}
  13807. */
  13808. var smoothSpline = function (points, isLoop) {
  13809. var len$$1 = points.length;
  13810. var ret = [];
  13811. var distance$$1 = 0;
  13812. for (var i = 1; i < len$$1; i++) {
  13813. distance$$1 += distance(points[i - 1], points[i]);
  13814. }
  13815. var segs = distance$$1 / 2;
  13816. segs = segs < len$$1 ? len$$1 : segs;
  13817. for (var i = 0; i < segs; i++) {
  13818. var pos = i / (segs - 1) * (isLoop ? len$$1 : len$$1 - 1);
  13819. var idx = Math.floor(pos);
  13820. var w = pos - idx;
  13821. var p0;
  13822. var p1 = points[idx % len$$1];
  13823. var p2;
  13824. var p3;
  13825. if (!isLoop) {
  13826. p0 = points[idx === 0 ? idx : idx - 1];
  13827. p2 = points[idx > len$$1 - 2 ? len$$1 - 1 : idx + 1];
  13828. p3 = points[idx > len$$1 - 3 ? len$$1 - 1 : idx + 2];
  13829. }
  13830. else {
  13831. p0 = points[(idx - 1 + len$$1) % len$$1];
  13832. p2 = points[(idx + 1) % len$$1];
  13833. p3 = points[(idx + 2) % len$$1];
  13834. }
  13835. var w2 = w * w;
  13836. var w3 = w * w2;
  13837. ret.push([
  13838. interpolate(p0[0], p1[0], p2[0], p3[0], w, w2, w3),
  13839. interpolate(p0[1], p1[1], p2[1], p3[1], w, w2, w3)
  13840. ]);
  13841. }
  13842. return ret;
  13843. };
  13844. /**
  13845. * 贝塞尔平滑曲线
  13846. * @module zrender/shape/util/smoothBezier
  13847. * @author pissang (https://www.github.com/pissang)
  13848. * Kener (@Kener-林峰, kener.linfeng@gmail.com)
  13849. * errorrik (errorrik@gmail.com)
  13850. */
  13851. /**
  13852. * 贝塞尔平滑曲线
  13853. * @alias module:zrender/shape/util/smoothBezier
  13854. * @param {Array} points 线段顶点数组
  13855. * @param {number} smooth 平滑等级, 0-1
  13856. * @param {boolean} isLoop
  13857. * @param {Array} constraint 将计算出来的控制点约束在一个包围盒内
  13858. * 比如 [[0, 0], [100, 100]], 这个包围盒会与
  13859. * 整个折线的包围盒做一个并集用来约束控制点。
  13860. * @param {Array} 计算出来的控制点数组
  13861. */
  13862. var smoothBezier = function (points, smooth, isLoop, constraint) {
  13863. var cps = [];
  13864. var v = [];
  13865. var v1 = [];
  13866. var v2 = [];
  13867. var prevPoint;
  13868. var nextPoint;
  13869. var min$$1;
  13870. var max$$1;
  13871. if (constraint) {
  13872. min$$1 = [Infinity, Infinity];
  13873. max$$1 = [-Infinity, -Infinity];
  13874. for (var i = 0, len$$1 = points.length; i < len$$1; i++) {
  13875. min(min$$1, min$$1, points[i]);
  13876. max(max$$1, max$$1, points[i]);
  13877. }
  13878. // 与指定的包围盒做并集
  13879. min(min$$1, min$$1, constraint[0]);
  13880. max(max$$1, max$$1, constraint[1]);
  13881. }
  13882. for (var i = 0, len$$1 = points.length; i < len$$1; i++) {
  13883. var point = points[i];
  13884. if (isLoop) {
  13885. prevPoint = points[i ? i - 1 : len$$1 - 1];
  13886. nextPoint = points[(i + 1) % len$$1];
  13887. }
  13888. else {
  13889. if (i === 0 || i === len$$1 - 1) {
  13890. cps.push(clone$1(points[i]));
  13891. continue;
  13892. }
  13893. else {
  13894. prevPoint = points[i - 1];
  13895. nextPoint = points[i + 1];
  13896. }
  13897. }
  13898. sub(v, nextPoint, prevPoint);
  13899. // use degree to scale the handle length
  13900. scale(v, v, smooth);
  13901. var d0 = distance(point, prevPoint);
  13902. var d1 = distance(point, nextPoint);
  13903. var sum = d0 + d1;
  13904. if (sum !== 0) {
  13905. d0 /= sum;
  13906. d1 /= sum;
  13907. }
  13908. scale(v1, v, -d0);
  13909. scale(v2, v, d1);
  13910. var cp0 = add([], point, v1);
  13911. var cp1 = add([], point, v2);
  13912. if (constraint) {
  13913. max(cp0, cp0, min$$1);
  13914. min(cp0, cp0, max$$1);
  13915. max(cp1, cp1, min$$1);
  13916. min(cp1, cp1, max$$1);
  13917. }
  13918. cps.push(cp0);
  13919. cps.push(cp1);
  13920. }
  13921. if (isLoop) {
  13922. cps.push(cps.shift());
  13923. }
  13924. return cps;
  13925. };
  13926. function buildPath$1(ctx, shape, closePath) {
  13927. var points = shape.points;
  13928. var smooth = shape.smooth;
  13929. if (points && points.length >= 2) {
  13930. if (smooth && smooth !== 'spline') {
  13931. var controlPoints = smoothBezier(
  13932. points, smooth, closePath, shape.smoothConstraint
  13933. );
  13934. ctx.moveTo(points[0][0], points[0][1]);
  13935. var len = points.length;
  13936. for (var i = 0; i < (closePath ? len : len - 1); i++) {
  13937. var cp1 = controlPoints[i * 2];
  13938. var cp2 = controlPoints[i * 2 + 1];
  13939. var p = points[(i + 1) % len];
  13940. ctx.bezierCurveTo(
  13941. cp1[0], cp1[1], cp2[0], cp2[1], p[0], p[1]
  13942. );
  13943. }
  13944. }
  13945. else {
  13946. if (smooth === 'spline') {
  13947. points = smoothSpline(points, closePath);
  13948. }
  13949. ctx.moveTo(points[0][0], points[0][1]);
  13950. for (var i = 1, l = points.length; i < l; i++) {
  13951. ctx.lineTo(points[i][0], points[i][1]);
  13952. }
  13953. }
  13954. closePath && ctx.closePath();
  13955. }
  13956. }
  13957. /**
  13958. * 多边形
  13959. * @module zrender/shape/Polygon
  13960. */
  13961. var Polygon = Path.extend({
  13962. type: 'polygon',
  13963. shape: {
  13964. points: null,
  13965. smooth: false,
  13966. smoothConstraint: null
  13967. },
  13968. buildPath: function (ctx, shape) {
  13969. buildPath$1(ctx, shape, true);
  13970. }
  13971. });
  13972. /**
  13973. * @module zrender/graphic/shape/Polyline
  13974. */
  13975. var Polyline = Path.extend({
  13976. type: 'polyline',
  13977. shape: {
  13978. points: null,
  13979. smooth: false,
  13980. smoothConstraint: null
  13981. },
  13982. style: {
  13983. stroke: '#000',
  13984. fill: null
  13985. },
  13986. buildPath: function (ctx, shape) {
  13987. buildPath$1(ctx, shape, false);
  13988. }
  13989. });
  13990. /**
  13991. * Sub-pixel optimize for canvas rendering, prevent from blur
  13992. * when rendering a thin vertical/horizontal line.
  13993. */
  13994. var round = Math.round;
  13995. /**
  13996. * Sub pixel optimize line for canvas
  13997. *
  13998. * @param {Object} outputShape The modification will be performed on `outputShape`.
  13999. * `outputShape` and `inputShape` can be the same object.
  14000. * `outputShape` object can be used repeatly, because all of
  14001. * the `x1`, `x2`, `y1`, `y2` will be assigned in this method.
  14002. * @param {Object} [inputShape]
  14003. * @param {number} [inputShape.x1]
  14004. * @param {number} [inputShape.y1]
  14005. * @param {number} [inputShape.x2]
  14006. * @param {number} [inputShape.y2]
  14007. * @param {Object} [style]
  14008. * @param {number} [style.lineWidth]
  14009. */
  14010. function subPixelOptimizeLine$1(outputShape, inputShape, style) {
  14011. var lineWidth = style && style.lineWidth;
  14012. if (!inputShape || !lineWidth) {
  14013. return;
  14014. }
  14015. var x1 = inputShape.x1;
  14016. var x2 = inputShape.x2;
  14017. var y1 = inputShape.y1;
  14018. var y2 = inputShape.y2;
  14019. if (round(x1 * 2) === round(x2 * 2)) {
  14020. outputShape.x1 = outputShape.x2 = subPixelOptimize$1(x1, lineWidth, true);
  14021. }
  14022. else {
  14023. outputShape.x1 = x1;
  14024. outputShape.x2 = x2;
  14025. }
  14026. if (round(y1 * 2) === round(y2 * 2)) {
  14027. outputShape.y1 = outputShape.y2 = subPixelOptimize$1(y1, lineWidth, true);
  14028. }
  14029. else {
  14030. outputShape.y1 = y1;
  14031. outputShape.y2 = y2;
  14032. }
  14033. }
  14034. /**
  14035. * Sub pixel optimize rect for canvas
  14036. *
  14037. * @param {Object} outputShape The modification will be performed on `outputShape`.
  14038. * `outputShape` and `inputShape` can be the same object.
  14039. * `outputShape` object can be used repeatly, because all of
  14040. * the `x`, `y`, `width`, `height` will be assigned in this method.
  14041. * @param {Object} [inputShape]
  14042. * @param {number} [inputShape.x]
  14043. * @param {number} [inputShape.y]
  14044. * @param {number} [inputShape.width]
  14045. * @param {number} [inputShape.height]
  14046. * @param {Object} [style]
  14047. * @param {number} [style.lineWidth]
  14048. */
  14049. function subPixelOptimizeRect$1(outputShape, inputShape, style) {
  14050. var lineWidth = style && style.lineWidth;
  14051. if (!inputShape || !lineWidth) {
  14052. return;
  14053. }
  14054. var originX = inputShape.x;
  14055. var originY = inputShape.y;
  14056. var originWidth = inputShape.width;
  14057. var originHeight = inputShape.height;
  14058. outputShape.x = subPixelOptimize$1(originX, lineWidth, true);
  14059. outputShape.y = subPixelOptimize$1(originY, lineWidth, true);
  14060. outputShape.width = Math.max(
  14061. subPixelOptimize$1(originX + originWidth, lineWidth, false) - outputShape.x,
  14062. originWidth === 0 ? 0 : 1
  14063. );
  14064. outputShape.height = Math.max(
  14065. subPixelOptimize$1(originY + originHeight, lineWidth, false) - outputShape.y,
  14066. originHeight === 0 ? 0 : 1
  14067. );
  14068. }
  14069. /**
  14070. * Sub pixel optimize for canvas
  14071. *
  14072. * @param {number} position Coordinate, such as x, y
  14073. * @param {number} lineWidth Should be nonnegative integer.
  14074. * @param {boolean=} positiveOrNegative Default false (negative).
  14075. * @return {number} Optimized position.
  14076. */
  14077. function subPixelOptimize$1(position, lineWidth, positiveOrNegative) {
  14078. // Assure that (position + lineWidth / 2) is near integer edge,
  14079. // otherwise line will be fuzzy in canvas.
  14080. var doubledPosition = round(position * 2);
  14081. return (doubledPosition + round(lineWidth)) % 2 === 0
  14082. ? doubledPosition / 2
  14083. : (doubledPosition + (positiveOrNegative ? 1 : -1)) / 2;
  14084. }
  14085. /**
  14086. * 矩形
  14087. * @module zrender/graphic/shape/Rect
  14088. */
  14089. // Avoid create repeatly.
  14090. var subPixelOptimizeOutputShape = {};
  14091. var Rect = Path.extend({
  14092. type: 'rect',
  14093. shape: {
  14094. // 左上、右上、右下、左下角的半径依次为r1、r2、r3、r4
  14095. // r缩写为1 相当于 [1, 1, 1, 1]
  14096. // r缩写为[1] 相当于 [1, 1, 1, 1]
  14097. // r缩写为[1, 2] 相当于 [1, 2, 1, 2]
  14098. // r缩写为[1, 2, 3] 相当于 [1, 2, 3, 2]
  14099. r: 0,
  14100. x: 0,
  14101. y: 0,
  14102. width: 0,
  14103. height: 0
  14104. },
  14105. buildPath: function (ctx, shape) {
  14106. var x;
  14107. var y;
  14108. var width;
  14109. var height;
  14110. if (this.subPixelOptimize) {
  14111. subPixelOptimizeRect$1(subPixelOptimizeOutputShape, shape, this.style);
  14112. x = subPixelOptimizeOutputShape.x;
  14113. y = subPixelOptimizeOutputShape.y;
  14114. width = subPixelOptimizeOutputShape.width;
  14115. height = subPixelOptimizeOutputShape.height;
  14116. subPixelOptimizeOutputShape.r = shape.r;
  14117. shape = subPixelOptimizeOutputShape;
  14118. }
  14119. else {
  14120. x = shape.x;
  14121. y = shape.y;
  14122. width = shape.width;
  14123. height = shape.height;
  14124. }
  14125. if (!shape.r) {
  14126. ctx.rect(x, y, width, height);
  14127. }
  14128. else {
  14129. buildPath(ctx, shape);
  14130. }
  14131. ctx.closePath();
  14132. return;
  14133. }
  14134. });
  14135. /**
  14136. * 直线
  14137. * @module zrender/graphic/shape/Line
  14138. */
  14139. // Avoid create repeatly.
  14140. var subPixelOptimizeOutputShape$1 = {};
  14141. var Line = Path.extend({
  14142. type: 'line',
  14143. shape: {
  14144. // Start point
  14145. x1: 0,
  14146. y1: 0,
  14147. // End point
  14148. x2: 0,
  14149. y2: 0,
  14150. percent: 1
  14151. },
  14152. style: {
  14153. stroke: '#000',
  14154. fill: null
  14155. },
  14156. buildPath: function (ctx, shape) {
  14157. var x1;
  14158. var y1;
  14159. var x2;
  14160. var y2;
  14161. if (this.subPixelOptimize) {
  14162. subPixelOptimizeLine$1(subPixelOptimizeOutputShape$1, shape, this.style);
  14163. x1 = subPixelOptimizeOutputShape$1.x1;
  14164. y1 = subPixelOptimizeOutputShape$1.y1;
  14165. x2 = subPixelOptimizeOutputShape$1.x2;
  14166. y2 = subPixelOptimizeOutputShape$1.y2;
  14167. }
  14168. else {
  14169. x1 = shape.x1;
  14170. y1 = shape.y1;
  14171. x2 = shape.x2;
  14172. y2 = shape.y2;
  14173. }
  14174. var percent = shape.percent;
  14175. if (percent === 0) {
  14176. return;
  14177. }
  14178. ctx.moveTo(x1, y1);
  14179. if (percent < 1) {
  14180. x2 = x1 * (1 - percent) + x2 * percent;
  14181. y2 = y1 * (1 - percent) + y2 * percent;
  14182. }
  14183. ctx.lineTo(x2, y2);
  14184. },
  14185. /**
  14186. * Get point at percent
  14187. * @param {number} percent
  14188. * @return {Array.<number>}
  14189. */
  14190. pointAt: function (p) {
  14191. var shape = this.shape;
  14192. return [
  14193. shape.x1 * (1 - p) + shape.x2 * p,
  14194. shape.y1 * (1 - p) + shape.y2 * p
  14195. ];
  14196. }
  14197. });
  14198. /**
  14199. * 贝塞尔曲线
  14200. * @module zrender/shape/BezierCurve
  14201. */
  14202. var out = [];
  14203. function someVectorAt(shape, t, isTangent) {
  14204. var cpx2 = shape.cpx2;
  14205. var cpy2 = shape.cpy2;
  14206. if (cpx2 === null || cpy2 === null) {
  14207. return [
  14208. (isTangent ? cubicDerivativeAt : cubicAt)(shape.x1, shape.cpx1, shape.cpx2, shape.x2, t),
  14209. (isTangent ? cubicDerivativeAt : cubicAt)(shape.y1, shape.cpy1, shape.cpy2, shape.y2, t)
  14210. ];
  14211. }
  14212. else {
  14213. return [
  14214. (isTangent ? quadraticDerivativeAt : quadraticAt)(shape.x1, shape.cpx1, shape.x2, t),
  14215. (isTangent ? quadraticDerivativeAt : quadraticAt)(shape.y1, shape.cpy1, shape.y2, t)
  14216. ];
  14217. }
  14218. }
  14219. var BezierCurve = Path.extend({
  14220. type: 'bezier-curve',
  14221. shape: {
  14222. x1: 0,
  14223. y1: 0,
  14224. x2: 0,
  14225. y2: 0,
  14226. cpx1: 0,
  14227. cpy1: 0,
  14228. // cpx2: 0,
  14229. // cpy2: 0
  14230. // Curve show percent, for animating
  14231. percent: 1
  14232. },
  14233. style: {
  14234. stroke: '#000',
  14235. fill: null
  14236. },
  14237. buildPath: function (ctx, shape) {
  14238. var x1 = shape.x1;
  14239. var y1 = shape.y1;
  14240. var x2 = shape.x2;
  14241. var y2 = shape.y2;
  14242. var cpx1 = shape.cpx1;
  14243. var cpy1 = shape.cpy1;
  14244. var cpx2 = shape.cpx2;
  14245. var cpy2 = shape.cpy2;
  14246. var percent = shape.percent;
  14247. if (percent === 0) {
  14248. return;
  14249. }
  14250. ctx.moveTo(x1, y1);
  14251. if (cpx2 == null || cpy2 == null) {
  14252. if (percent < 1) {
  14253. quadraticSubdivide(
  14254. x1, cpx1, x2, percent, out
  14255. );
  14256. cpx1 = out[1];
  14257. x2 = out[2];
  14258. quadraticSubdivide(
  14259. y1, cpy1, y2, percent, out
  14260. );
  14261. cpy1 = out[1];
  14262. y2 = out[2];
  14263. }
  14264. ctx.quadraticCurveTo(
  14265. cpx1, cpy1,
  14266. x2, y2
  14267. );
  14268. }
  14269. else {
  14270. if (percent < 1) {
  14271. cubicSubdivide(
  14272. x1, cpx1, cpx2, x2, percent, out
  14273. );
  14274. cpx1 = out[1];
  14275. cpx2 = out[2];
  14276. x2 = out[3];
  14277. cubicSubdivide(
  14278. y1, cpy1, cpy2, y2, percent, out
  14279. );
  14280. cpy1 = out[1];
  14281. cpy2 = out[2];
  14282. y2 = out[3];
  14283. }
  14284. ctx.bezierCurveTo(
  14285. cpx1, cpy1,
  14286. cpx2, cpy2,
  14287. x2, y2
  14288. );
  14289. }
  14290. },
  14291. /**
  14292. * Get point at percent
  14293. * @param {number} t
  14294. * @return {Array.<number>}
  14295. */
  14296. pointAt: function (t) {
  14297. return someVectorAt(this.shape, t, false);
  14298. },
  14299. /**
  14300. * Get tangent at percent
  14301. * @param {number} t
  14302. * @return {Array.<number>}
  14303. */
  14304. tangentAt: function (t) {
  14305. var p = someVectorAt(this.shape, t, true);
  14306. return normalize(p, p);
  14307. }
  14308. });
  14309. /**
  14310. * 圆弧
  14311. * @module zrender/graphic/shape/Arc
  14312. */
  14313. var Arc = Path.extend({
  14314. type: 'arc',
  14315. shape: {
  14316. cx: 0,
  14317. cy: 0,
  14318. r: 0,
  14319. startAngle: 0,
  14320. endAngle: Math.PI * 2,
  14321. clockwise: true
  14322. },
  14323. style: {
  14324. stroke: '#000',
  14325. fill: null
  14326. },
  14327. buildPath: function (ctx, shape) {
  14328. var x = shape.cx;
  14329. var y = shape.cy;
  14330. var r = Math.max(shape.r, 0);
  14331. var startAngle = shape.startAngle;
  14332. var endAngle = shape.endAngle;
  14333. var clockwise = shape.clockwise;
  14334. var unitX = Math.cos(startAngle);
  14335. var unitY = Math.sin(startAngle);
  14336. ctx.moveTo(unitX * r + x, unitY * r + y);
  14337. ctx.arc(x, y, r, startAngle, endAngle, !clockwise);
  14338. }
  14339. });
  14340. // CompoundPath to improve performance
  14341. var CompoundPath = Path.extend({
  14342. type: 'compound',
  14343. shape: {
  14344. paths: null
  14345. },
  14346. _updatePathDirty: function () {
  14347. var dirtyPath = this.__dirtyPath;
  14348. var paths = this.shape.paths;
  14349. for (var i = 0; i < paths.length; i++) {
  14350. // Mark as dirty if any subpath is dirty
  14351. dirtyPath = dirtyPath || paths[i].__dirtyPath;
  14352. }
  14353. this.__dirtyPath = dirtyPath;
  14354. this.__dirty = this.__dirty || dirtyPath;
  14355. },
  14356. beforeBrush: function () {
  14357. this._updatePathDirty();
  14358. var paths = this.shape.paths || [];
  14359. var scale = this.getGlobalScale();
  14360. // Update path scale
  14361. for (var i = 0; i < paths.length; i++) {
  14362. if (!paths[i].path) {
  14363. paths[i].createPathProxy();
  14364. }
  14365. paths[i].path.setScale(scale[0], scale[1], paths[i].segmentIgnoreThreshold);
  14366. }
  14367. },
  14368. buildPath: function (ctx, shape) {
  14369. var paths = shape.paths || [];
  14370. for (var i = 0; i < paths.length; i++) {
  14371. paths[i].buildPath(ctx, paths[i].shape, true);
  14372. }
  14373. },
  14374. afterBrush: function () {
  14375. var paths = this.shape.paths || [];
  14376. for (var i = 0; i < paths.length; i++) {
  14377. paths[i].__dirtyPath = false;
  14378. }
  14379. },
  14380. getBoundingRect: function () {
  14381. this._updatePathDirty();
  14382. return Path.prototype.getBoundingRect.call(this);
  14383. }
  14384. });
  14385. /**
  14386. * @param {Array.<Object>} colorStops
  14387. */
  14388. var Gradient = function (colorStops) {
  14389. this.colorStops = colorStops || [];
  14390. };
  14391. Gradient.prototype = {
  14392. constructor: Gradient,
  14393. addColorStop: function (offset, color) {
  14394. this.colorStops.push({
  14395. offset: offset,
  14396. color: color
  14397. });
  14398. }
  14399. };
  14400. /**
  14401. * x, y, x2, y2 are all percent from 0 to 1
  14402. * @param {number} [x=0]
  14403. * @param {number} [y=0]
  14404. * @param {number} [x2=1]
  14405. * @param {number} [y2=0]
  14406. * @param {Array.<Object>} colorStops
  14407. * @param {boolean} [globalCoord=false]
  14408. */
  14409. var LinearGradient = function (x, y, x2, y2, colorStops, globalCoord) {
  14410. // Should do nothing more in this constructor. Because gradient can be
  14411. // declard by `color: {type: 'linear', colorStops: ...}`, where
  14412. // this constructor will not be called.
  14413. this.x = x == null ? 0 : x;
  14414. this.y = y == null ? 0 : y;
  14415. this.x2 = x2 == null ? 1 : x2;
  14416. this.y2 = y2 == null ? 0 : y2;
  14417. // Can be cloned
  14418. this.type = 'linear';
  14419. // If use global coord
  14420. this.global = globalCoord || false;
  14421. Gradient.call(this, colorStops);
  14422. };
  14423. LinearGradient.prototype = {
  14424. constructor: LinearGradient
  14425. };
  14426. inherits(LinearGradient, Gradient);
  14427. /**
  14428. * x, y, r are all percent from 0 to 1
  14429. * @param {number} [x=0.5]
  14430. * @param {number} [y=0.5]
  14431. * @param {number} [r=0.5]
  14432. * @param {Array.<Object>} [colorStops]
  14433. * @param {boolean} [globalCoord=false]
  14434. */
  14435. var RadialGradient = function (x, y, r, colorStops, globalCoord) {
  14436. // Should do nothing more in this constructor. Because gradient can be
  14437. // declard by `color: {type: 'radial', colorStops: ...}`, where
  14438. // this constructor will not be called.
  14439. this.x = x == null ? 0.5 : x;
  14440. this.y = y == null ? 0.5 : y;
  14441. this.r = r == null ? 0.5 : r;
  14442. // Can be cloned
  14443. this.type = 'radial';
  14444. // If use global coord
  14445. this.global = globalCoord || false;
  14446. Gradient.call(this, colorStops);
  14447. };
  14448. RadialGradient.prototype = {
  14449. constructor: RadialGradient
  14450. };
  14451. inherits(RadialGradient, Gradient);
  14452. /**
  14453. * Displayable for incremental rendering. It will be rendered in a separate layer
  14454. * IncrementalDisplay have two main methods. `clearDisplayables` and `addDisplayables`
  14455. * addDisplayables will render the added displayables incremetally.
  14456. *
  14457. * It use a not clearFlag to tell the painter don't clear the layer if it's the first element.
  14458. */
  14459. // TODO Style override ?
  14460. function IncrementalDisplayble(opts) {
  14461. Displayable.call(this, opts);
  14462. this._displayables = [];
  14463. this._temporaryDisplayables = [];
  14464. this._cursor = 0;
  14465. this.notClear = true;
  14466. }
  14467. IncrementalDisplayble.prototype.incremental = true;
  14468. IncrementalDisplayble.prototype.clearDisplaybles = function () {
  14469. this._displayables = [];
  14470. this._temporaryDisplayables = [];
  14471. this._cursor = 0;
  14472. this.dirty();
  14473. this.notClear = false;
  14474. };
  14475. IncrementalDisplayble.prototype.addDisplayable = function (displayable, notPersistent) {
  14476. if (notPersistent) {
  14477. this._temporaryDisplayables.push(displayable);
  14478. }
  14479. else {
  14480. this._displayables.push(displayable);
  14481. }
  14482. this.dirty();
  14483. };
  14484. IncrementalDisplayble.prototype.addDisplayables = function (displayables, notPersistent) {
  14485. notPersistent = notPersistent || false;
  14486. for (var i = 0; i < displayables.length; i++) {
  14487. this.addDisplayable(displayables[i], notPersistent);
  14488. }
  14489. };
  14490. IncrementalDisplayble.prototype.eachPendingDisplayable = function (cb) {
  14491. for (var i = this._cursor; i < this._displayables.length; i++) {
  14492. cb && cb(this._displayables[i]);
  14493. }
  14494. for (var i = 0; i < this._temporaryDisplayables.length; i++) {
  14495. cb && cb(this._temporaryDisplayables[i]);
  14496. }
  14497. };
  14498. IncrementalDisplayble.prototype.update = function () {
  14499. this.updateTransform();
  14500. for (var i = this._cursor; i < this._displayables.length; i++) {
  14501. var displayable = this._displayables[i];
  14502. // PENDING
  14503. displayable.parent = this;
  14504. displayable.update();
  14505. displayable.parent = null;
  14506. }
  14507. for (var i = 0; i < this._temporaryDisplayables.length; i++) {
  14508. var displayable = this._temporaryDisplayables[i];
  14509. // PENDING
  14510. displayable.parent = this;
  14511. displayable.update();
  14512. displayable.parent = null;
  14513. }
  14514. };
  14515. IncrementalDisplayble.prototype.brush = function (ctx, prevEl) {
  14516. // Render persistant displayables.
  14517. for (var i = this._cursor; i < this._displayables.length; i++) {
  14518. var displayable = this._displayables[i];
  14519. displayable.beforeBrush && displayable.beforeBrush(ctx);
  14520. displayable.brush(ctx, i === this._cursor ? null : this._displayables[i - 1]);
  14521. displayable.afterBrush && displayable.afterBrush(ctx);
  14522. }
  14523. this._cursor = i;
  14524. // Render temporary displayables.
  14525. for (var i = 0; i < this._temporaryDisplayables.length; i++) {
  14526. var displayable = this._temporaryDisplayables[i];
  14527. displayable.beforeBrush && displayable.beforeBrush(ctx);
  14528. displayable.brush(ctx, i === 0 ? null : this._temporaryDisplayables[i - 1]);
  14529. displayable.afterBrush && displayable.afterBrush(ctx);
  14530. }
  14531. this._temporaryDisplayables = [];
  14532. this.notClear = true;
  14533. };
  14534. var m = [];
  14535. IncrementalDisplayble.prototype.getBoundingRect = function () {
  14536. if (!this._rect) {
  14537. var rect = new BoundingRect(Infinity, Infinity, -Infinity, -Infinity);
  14538. for (var i = 0; i < this._displayables.length; i++) {
  14539. var displayable = this._displayables[i];
  14540. var childRect = displayable.getBoundingRect().clone();
  14541. if (displayable.needLocalTransform()) {
  14542. childRect.applyTransform(displayable.getLocalTransform(m));
  14543. }
  14544. rect.union(childRect);
  14545. }
  14546. this._rect = rect;
  14547. }
  14548. return this._rect;
  14549. };
  14550. IncrementalDisplayble.prototype.contain = function (x, y) {
  14551. var localPos = this.transformCoordToLocal(x, y);
  14552. var rect = this.getBoundingRect();
  14553. if (rect.contain(localPos[0], localPos[1])) {
  14554. for (var i = 0; i < this._displayables.length; i++) {
  14555. var displayable = this._displayables[i];
  14556. if (displayable.contain(x, y)) {
  14557. return true;
  14558. }
  14559. }
  14560. }
  14561. return false;
  14562. };
  14563. inherits(IncrementalDisplayble, Displayable);
  14564. /*
  14565. * Licensed to the Apache Software Foundation (ASF) under one
  14566. * or more contributor license agreements. See the NOTICE file
  14567. * distributed with this work for additional information
  14568. * regarding copyright ownership. The ASF licenses this file
  14569. * to you under the Apache License, Version 2.0 (the
  14570. * "License"); you may not use this file except in compliance
  14571. * with the License. You may obtain a copy of the License at
  14572. *
  14573. * http://www.apache.org/licenses/LICENSE-2.0
  14574. *
  14575. * Unless required by applicable law or agreed to in writing,
  14576. * software distributed under the License is distributed on an
  14577. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  14578. * KIND, either express or implied. See the License for the
  14579. * specific language governing permissions and limitations
  14580. * under the License.
  14581. */
  14582. var mathMax$1 = Math.max;
  14583. var mathMin$1 = Math.min;
  14584. var EMPTY_OBJ = {};
  14585. var Z2_EMPHASIS_LIFT = 1;
  14586. // key: label model property nane, value: style property name.
  14587. var CACHED_LABEL_STYLE_PROPERTIES = {
  14588. color: 'textFill',
  14589. textBorderColor: 'textStroke',
  14590. textBorderWidth: 'textStrokeWidth'
  14591. };
  14592. var EMPHASIS = 'emphasis';
  14593. var NORMAL = 'normal';
  14594. // Reserve 0 as default.
  14595. var _highlightNextDigit = 1;
  14596. var _highlightKeyMap = {};
  14597. /**
  14598. * Extend shape with parameters
  14599. */
  14600. function extendShape(opts) {
  14601. return Path.extend(opts);
  14602. }
  14603. /**
  14604. * Extend path
  14605. */
  14606. function extendPath(pathData, opts) {
  14607. return extendFromString(pathData, opts);
  14608. }
  14609. /**
  14610. * Create a path element from path data string
  14611. * @param {string} pathData
  14612. * @param {Object} opts
  14613. * @param {module:zrender/core/BoundingRect} rect
  14614. * @param {string} [layout=cover] 'center' or 'cover'
  14615. */
  14616. function makePath(pathData, opts, rect, layout) {
  14617. var path = createFromString(pathData, opts);
  14618. if (rect) {
  14619. if (layout === 'center') {
  14620. rect = centerGraphic(rect, path.getBoundingRect());
  14621. }
  14622. resizePath(path, rect);
  14623. }
  14624. return path;
  14625. }
  14626. /**
  14627. * Create a image element from image url
  14628. * @param {string} imageUrl image url
  14629. * @param {Object} opts options
  14630. * @param {module:zrender/core/BoundingRect} rect constrain rect
  14631. * @param {string} [layout=cover] 'center' or 'cover'
  14632. */
  14633. function makeImage(imageUrl, rect, layout) {
  14634. var path = new ZImage({
  14635. style: {
  14636. image: imageUrl,
  14637. x: rect.x,
  14638. y: rect.y,
  14639. width: rect.width,
  14640. height: rect.height
  14641. },
  14642. onload: function (img) {
  14643. if (layout === 'center') {
  14644. var boundingRect = {
  14645. width: img.width,
  14646. height: img.height
  14647. };
  14648. path.setStyle(centerGraphic(rect, boundingRect));
  14649. }
  14650. }
  14651. });
  14652. return path;
  14653. }
  14654. /**
  14655. * Get position of centered element in bounding box.
  14656. *
  14657. * @param {Object} rect element local bounding box
  14658. * @param {Object} boundingRect constraint bounding box
  14659. * @return {Object} element position containing x, y, width, and height
  14660. */
  14661. function centerGraphic(rect, boundingRect) {
  14662. // Set rect to center, keep width / height ratio.
  14663. var aspect = boundingRect.width / boundingRect.height;
  14664. var width = rect.height * aspect;
  14665. var height;
  14666. if (width <= rect.width) {
  14667. height = rect.height;
  14668. }
  14669. else {
  14670. width = rect.width;
  14671. height = width / aspect;
  14672. }
  14673. var cx = rect.x + rect.width / 2;
  14674. var cy = rect.y + rect.height / 2;
  14675. return {
  14676. x: cx - width / 2,
  14677. y: cy - height / 2,
  14678. width: width,
  14679. height: height
  14680. };
  14681. }
  14682. var mergePath = mergePath$1;
  14683. /**
  14684. * Resize a path to fit the rect
  14685. * @param {module:zrender/graphic/Path} path
  14686. * @param {Object} rect
  14687. */
  14688. function resizePath(path, rect) {
  14689. if (!path.applyTransform) {
  14690. return;
  14691. }
  14692. var pathRect = path.getBoundingRect();
  14693. var m = pathRect.calculateTransform(rect);
  14694. path.applyTransform(m);
  14695. }
  14696. /**
  14697. * Sub pixel optimize line for canvas
  14698. *
  14699. * @param {Object} param
  14700. * @param {Object} [param.shape]
  14701. * @param {number} [param.shape.x1]
  14702. * @param {number} [param.shape.y1]
  14703. * @param {number} [param.shape.x2]
  14704. * @param {number} [param.shape.y2]
  14705. * @param {Object} [param.style]
  14706. * @param {number} [param.style.lineWidth]
  14707. * @return {Object} Modified param
  14708. */
  14709. function subPixelOptimizeLine(param) {
  14710. subPixelOptimizeLine$1(param.shape, param.shape, param.style);
  14711. return param;
  14712. }
  14713. /**
  14714. * Sub pixel optimize rect for canvas
  14715. *
  14716. * @param {Object} param
  14717. * @param {Object} [param.shape]
  14718. * @param {number} [param.shape.x]
  14719. * @param {number} [param.shape.y]
  14720. * @param {number} [param.shape.width]
  14721. * @param {number} [param.shape.height]
  14722. * @param {Object} [param.style]
  14723. * @param {number} [param.style.lineWidth]
  14724. * @return {Object} Modified param
  14725. */
  14726. function subPixelOptimizeRect(param) {
  14727. subPixelOptimizeRect$1(param.shape, param.shape, param.style);
  14728. return param;
  14729. }
  14730. /**
  14731. * Sub pixel optimize for canvas
  14732. *
  14733. * @param {number} position Coordinate, such as x, y
  14734. * @param {number} lineWidth Should be nonnegative integer.
  14735. * @param {boolean=} positiveOrNegative Default false (negative).
  14736. * @return {number} Optimized position.
  14737. */
  14738. var subPixelOptimize = subPixelOptimize$1;
  14739. function hasFillOrStroke(fillOrStroke) {
  14740. return fillOrStroke != null && fillOrStroke !== 'none';
  14741. }
  14742. // Most lifted color are duplicated.
  14743. var liftedColorMap = createHashMap();
  14744. var liftedColorCount = 0;
  14745. function liftColor(color) {
  14746. if (typeof color !== 'string') {
  14747. return color;
  14748. }
  14749. var liftedColor = liftedColorMap.get(color);
  14750. if (!liftedColor) {
  14751. liftedColor = lift(color, -0.1);
  14752. if (liftedColorCount < 10000) {
  14753. liftedColorMap.set(color, liftedColor);
  14754. liftedColorCount++;
  14755. }
  14756. }
  14757. return liftedColor;
  14758. }
  14759. function cacheElementStl(el) {
  14760. if (!el.__hoverStlDirty) {
  14761. return;
  14762. }
  14763. el.__hoverStlDirty = false;
  14764. var hoverStyle = el.__hoverStl;
  14765. if (!hoverStyle) {
  14766. el.__cachedNormalStl = el.__cachedNormalZ2 = null;
  14767. return;
  14768. }
  14769. var normalStyle = el.__cachedNormalStl = {};
  14770. el.__cachedNormalZ2 = el.z2;
  14771. var elStyle = el.style;
  14772. for (var name in hoverStyle) {
  14773. // See comment in `singleEnterEmphasis`.
  14774. if (hoverStyle[name] != null) {
  14775. normalStyle[name] = elStyle[name];
  14776. }
  14777. }
  14778. // Always cache fill and stroke to normalStyle for lifting color.
  14779. normalStyle.fill = elStyle.fill;
  14780. normalStyle.stroke = elStyle.stroke;
  14781. }
  14782. function singleEnterEmphasis(el) {
  14783. var hoverStl = el.__hoverStl;
  14784. if (!hoverStl || el.__highlighted) {
  14785. return;
  14786. }
  14787. var useHoverLayer = el.useHoverLayer;
  14788. el.__highlighted = useHoverLayer ? 'layer' : 'plain';
  14789. var zr = el.__zr;
  14790. if (el.isGroup || (!zr && useHoverLayer)) {
  14791. return;
  14792. }
  14793. var elTarget = el;
  14794. var targetStyle = el.style;
  14795. if (useHoverLayer) {
  14796. elTarget = zr.addHover(el);
  14797. targetStyle = elTarget.style;
  14798. }
  14799. rollbackDefaultTextStyle(targetStyle);
  14800. if (!useHoverLayer) {
  14801. cacheElementStl(elTarget);
  14802. }
  14803. // styles can be:
  14804. // {
  14805. // label: {
  14806. // show: false,
  14807. // position: 'outside',
  14808. // fontSize: 18
  14809. // },
  14810. // emphasis: {
  14811. // label: {
  14812. // show: true
  14813. // }
  14814. // }
  14815. // },
  14816. // where properties of `emphasis` may not appear in `normal`. We previously use
  14817. // module:echarts/util/model#defaultEmphasis to merge `normal` to `emphasis`.
  14818. // But consider rich text and setOption in merge mode, it is impossible to cover
  14819. // all properties in merge. So we use merge mode when setting style here.
  14820. // But we choose the merge strategy that only properties that is not `null/undefined`.
  14821. // Because when making a textStyle (espacially rich text), it is not easy to distinguish
  14822. // `hasOwnProperty` and `null/undefined` in code, so we trade them as the same for simplicity.
  14823. // But this strategy brings a trouble that `null/undefined` can not be used to remove
  14824. // style any more in `emphasis`. Users can both set properties directly on normal and
  14825. // emphasis to avoid this issue, or we might support `'none'` for this case if required.
  14826. targetStyle.extendFrom(hoverStl);
  14827. setDefaultHoverFillStroke(targetStyle, hoverStl, 'fill');
  14828. setDefaultHoverFillStroke(targetStyle, hoverStl, 'stroke');
  14829. applyDefaultTextStyle(targetStyle);
  14830. if (!useHoverLayer) {
  14831. el.dirty(false);
  14832. el.z2 += Z2_EMPHASIS_LIFT;
  14833. }
  14834. }
  14835. function setDefaultHoverFillStroke(targetStyle, hoverStyle, prop) {
  14836. if (!hasFillOrStroke(hoverStyle[prop]) && hasFillOrStroke(targetStyle[prop])) {
  14837. targetStyle[prop] = liftColor(targetStyle[prop]);
  14838. }
  14839. }
  14840. function singleEnterNormal(el) {
  14841. var highlighted = el.__highlighted;
  14842. if (!highlighted) {
  14843. return;
  14844. }
  14845. el.__highlighted = false;
  14846. if (el.isGroup) {
  14847. return;
  14848. }
  14849. if (highlighted === 'layer') {
  14850. el.__zr && el.__zr.removeHover(el);
  14851. }
  14852. else {
  14853. var style = el.style;
  14854. var normalStl = el.__cachedNormalStl;
  14855. if (normalStl) {
  14856. rollbackDefaultTextStyle(style);
  14857. el.setStyle(normalStl);
  14858. applyDefaultTextStyle(style);
  14859. }
  14860. // `__cachedNormalZ2` will not be reset if calling `setElementHoverStyle`
  14861. // when `el` is on emphasis state. So here by comparing with 1, we try
  14862. // hard to make the bug case rare.
  14863. var normalZ2 = el.__cachedNormalZ2;
  14864. if (normalZ2 != null && el.z2 - normalZ2 === Z2_EMPHASIS_LIFT) {
  14865. el.z2 = normalZ2;
  14866. }
  14867. }
  14868. }
  14869. function traverseUpdate(el, updater, commonParam) {
  14870. // If root is group, also enter updater for `highDownOnUpdate`.
  14871. var fromState = NORMAL;
  14872. var toState = NORMAL;
  14873. var trigger;
  14874. // See the rule of `highDownOnUpdate` on `graphic.setAsHighDownDispatcher`.
  14875. el.__highlighted && (fromState = EMPHASIS, trigger = true);
  14876. updater(el, commonParam);
  14877. el.__highlighted && (toState = EMPHASIS, trigger = true);
  14878. el.isGroup && el.traverse(function (child) {
  14879. !child.isGroup && updater(child, commonParam);
  14880. });
  14881. trigger && el.__highDownOnUpdate && el.__highDownOnUpdate(fromState, toState);
  14882. }
  14883. /**
  14884. * Set hover style (namely "emphasis style") of element, based on the current
  14885. * style of the given `el`.
  14886. * This method should be called after all of the normal styles have been adopted
  14887. * to the `el`. See the reason on `setHoverStyle`.
  14888. *
  14889. * @param {module:zrender/Element} el Should not be `zrender/container/Group`.
  14890. * @param {Object} [el.hoverStyle] Can be set on el or its descendants,
  14891. * e.g., `el.hoverStyle = ...; graphic.setHoverStyle(el); `.
  14892. * Often used when item group has a label element and it's hoverStyle is different.
  14893. * @param {Object|boolean} [hoverStl] The specified hover style.
  14894. * If set as `false`, disable the hover style.
  14895. * Similarly, The `el.hoverStyle` can alse be set
  14896. * as `false` to disable the hover style.
  14897. * Otherwise, use the default hover style if not provided.
  14898. */
  14899. function setElementHoverStyle(el, hoverStl) {
  14900. // For performance consideration, it might be better to make the "hover style" only the
  14901. // difference properties from the "normal style", but not a entire copy of all styles.
  14902. hoverStl = el.__hoverStl = hoverStl !== false && (el.hoverStyle || hoverStl || {});
  14903. el.__hoverStlDirty = true;
  14904. // FIXME
  14905. // It is not completely right to save "normal"/"emphasis" flag on elements.
  14906. // It probably should be saved on `data` of series. Consider the cases:
  14907. // (1) A highlighted elements are moved out of the view port and re-enter
  14908. // again by dataZoom.
  14909. // (2) call `setOption` and replace elements totally when they are highlighted.
  14910. if (el.__highlighted) {
  14911. // Consider the case:
  14912. // The styles of a highlighted `el` is being updated. The new "emphasis style"
  14913. // should be adapted to the `el`. Notice here new "normal styles" should have
  14914. // been set outside and the cached "normal style" is out of date.
  14915. el.__cachedNormalStl = null;
  14916. // Do not clear `__cachedNormalZ2` here, because setting `z2` is not a constraint
  14917. // of this method. In most cases, `z2` is not set and hover style should be able
  14918. // to rollback. Of course, that would bring bug, but only in a rare case, see
  14919. // `doSingleLeaveHover` for details.
  14920. singleEnterNormal(el);
  14921. singleEnterEmphasis(el);
  14922. }
  14923. }
  14924. function onElementMouseOver(e) {
  14925. !shouldSilent(this, e)
  14926. // "emphasis" event highlight has higher priority than mouse highlight.
  14927. && !this.__highByOuter
  14928. && traverseUpdate(this, singleEnterEmphasis);
  14929. }
  14930. function onElementMouseOut(e) {
  14931. !shouldSilent(this, e)
  14932. // "emphasis" event highlight has higher priority than mouse highlight.
  14933. && !this.__highByOuter
  14934. && traverseUpdate(this, singleEnterNormal);
  14935. }
  14936. function onElementEmphasisEvent(highlightDigit) {
  14937. this.__highByOuter |= 1 << (highlightDigit || 0);
  14938. traverseUpdate(this, singleEnterEmphasis);
  14939. }
  14940. function onElementNormalEvent(highlightDigit) {
  14941. !(this.__highByOuter &= ~(1 << (highlightDigit || 0)))
  14942. && traverseUpdate(this, singleEnterNormal);
  14943. }
  14944. function shouldSilent(el, e) {
  14945. return el.__highDownSilentOnTouch && e.zrByTouch;
  14946. }
  14947. /**
  14948. * Set hover style (namely "emphasis style") of element,
  14949. * based on the current style of the given `el`.
  14950. *
  14951. * (1)
  14952. * **CONSTRAINTS** for this method:
  14953. * <A> This method MUST be called after all of the normal styles having been adopted
  14954. * to the `el`.
  14955. * <B> The input `hoverStyle` (that is, "emphasis style") MUST be the subset of the
  14956. * "normal style" having been set to the el.
  14957. * <C> `color` MUST be one of the "normal styles" (because color might be lifted as
  14958. * a default hover style).
  14959. *
  14960. * The reason: this method treat the current style of the `el` as the "normal style"
  14961. * and cache them when enter/update the "emphasis style". Consider the case: the `el`
  14962. * is in "emphasis" state and `setOption`/`dispatchAction` trigger the style updating
  14963. * logic, where the el should shift from the original emphasis style to the new
  14964. * "emphasis style" and should be able to "downplay" back to the new "normal style".
  14965. *
  14966. * Indeed, it is error-prone to make a interface has so many constraints, but I have
  14967. * not found a better solution yet to fit the backward compatibility, performance and
  14968. * the current programming style.
  14969. *
  14970. * (2)
  14971. * Call the method for a "root" element once. Do not call it for each descendants.
  14972. * If the descendants elemenets of a group has itself hover style different from the
  14973. * root group, we can simply mount the style on `el.hoverStyle` for them, but should
  14974. * not call this method for them.
  14975. *
  14976. * (3) These input parameters can be set directly on `el`:
  14977. *
  14978. * @param {module:zrender/Element} el
  14979. * @param {Object} [el.hoverStyle] See `graphic.setElementHoverStyle`.
  14980. * @param {boolean} [el.highDownSilentOnTouch=false] See `graphic.setAsHighDownDispatcher`.
  14981. * @param {Function} [el.highDownOnUpdate] See `graphic.setAsHighDownDispatcher`.
  14982. * @param {Object|boolean} [hoverStyle] See `graphic.setElementHoverStyle`.
  14983. */
  14984. function setHoverStyle(el, hoverStyle) {
  14985. setAsHighDownDispatcher(el, true);
  14986. traverseUpdate(el, setElementHoverStyle, hoverStyle);
  14987. }
  14988. /**
  14989. * @param {module:zrender/Element} el
  14990. * @param {Function} [el.highDownOnUpdate] Called when state updated.
  14991. * Since `setHoverStyle` has the constraint that it must be called after
  14992. * all of the normal style updated, `highDownOnUpdate` is not needed to
  14993. * trigger if both `fromState` and `toState` is 'normal', and needed to
  14994. * trigger if both `fromState` and `toState` is 'emphasis', which enables
  14995. * to sync outside style settings to "emphasis" state.
  14996. * @this {string} This dispatcher `el`.
  14997. * @param {string} fromState Can be "normal" or "emphasis".
  14998. * `fromState` might equal to `toState`,
  14999. * for example, when this method is called when `el` is
  15000. * on "emphasis" state.
  15001. * @param {string} toState Can be "normal" or "emphasis".
  15002. *
  15003. * FIXME
  15004. * CAUTION: Do not expose `highDownOnUpdate` outside echarts.
  15005. * Because it is not a complete solution. The update
  15006. * listener should not have been mount in element,
  15007. * and the normal/emphasis state should not have
  15008. * mantained on elements.
  15009. *
  15010. * @param {boolean} [el.highDownSilentOnTouch=false]
  15011. * In touch device, mouseover event will be trigger on touchstart event
  15012. * (see module:zrender/dom/HandlerProxy). By this mechanism, we can
  15013. * conveniently use hoverStyle when tap on touch screen without additional
  15014. * code for compatibility.
  15015. * But if the chart/component has select feature, which usually also use
  15016. * hoverStyle, there might be conflict between 'select-highlight' and
  15017. * 'hover-highlight' especially when roam is enabled (see geo for example).
  15018. * In this case, `highDownSilentOnTouch` should be used to disable
  15019. * hover-highlight on touch device.
  15020. * @param {boolean} [asDispatcher=true] If `false`, do not set as "highDownDispatcher".
  15021. */
  15022. function setAsHighDownDispatcher(el, asDispatcher) {
  15023. var disable = asDispatcher === false;
  15024. // Make `highDownSilentOnTouch` and `highDownOnUpdate` only work after
  15025. // `setAsHighDownDispatcher` called. Avoid it is modified by user unexpectedly.
  15026. el.__highDownSilentOnTouch = el.highDownSilentOnTouch;
  15027. el.__highDownOnUpdate = el.highDownOnUpdate;
  15028. // Simple optimize, since this method might be
  15029. // called for each elements of a group in some cases.
  15030. if (!disable || el.__highDownDispatcher) {
  15031. var method = disable ? 'off' : 'on';
  15032. // Duplicated function will be auto-ignored, see Eventful.js.
  15033. el[method]('mouseover', onElementMouseOver)[method]('mouseout', onElementMouseOut);
  15034. // Emphasis, normal can be triggered manually by API or other components like hover link.
  15035. el[method]('emphasis', onElementEmphasisEvent)[method]('normal', onElementNormalEvent);
  15036. // Also keep previous record.
  15037. el.__highByOuter = el.__highByOuter || 0;
  15038. el.__highDownDispatcher = !disable;
  15039. }
  15040. }
  15041. /**
  15042. * @param {module:zrender/src/Element} el
  15043. * @return {boolean}
  15044. */
  15045. function isHighDownDispatcher(el) {
  15046. return !!(el && el.__highDownDispatcher);
  15047. }
  15048. /**
  15049. * Support hightlight/downplay record on each elements.
  15050. * For the case: hover highlight/downplay (legend, visualMap, ...) and
  15051. * user triggerred hightlight/downplay should not conflict.
  15052. * Only all of the highlightDigit cleared, return to normal.
  15053. * @param {string} highlightKey
  15054. * @return {number} highlightDigit
  15055. */
  15056. function getHighlightDigit(highlightKey) {
  15057. var highlightDigit = _highlightKeyMap[highlightKey];
  15058. if (highlightDigit == null && _highlightNextDigit <= 32) {
  15059. highlightDigit = _highlightKeyMap[highlightKey] = _highlightNextDigit++;
  15060. }
  15061. return highlightDigit;
  15062. }
  15063. /**
  15064. * See more info in `setTextStyleCommon`.
  15065. * @param {Object|module:zrender/graphic/Style} normalStyle
  15066. * @param {Object} emphasisStyle
  15067. * @param {module:echarts/model/Model} normalModel
  15068. * @param {module:echarts/model/Model} emphasisModel
  15069. * @param {Object} opt Check `opt` of `setTextStyleCommon` to find other props.
  15070. * @param {string|Function} [opt.defaultText]
  15071. * @param {module:echarts/model/Model} [opt.labelFetcher] Fetch text by
  15072. * `opt.labelFetcher.getFormattedLabel(opt.labelDataIndex, 'normal'/'emphasis', null, opt.labelDimIndex)`
  15073. * @param {module:echarts/model/Model} [opt.labelDataIndex] Fetch text by
  15074. * `opt.textFetcher.getFormattedLabel(opt.labelDataIndex, 'normal'/'emphasis', null, opt.labelDimIndex)`
  15075. * @param {module:echarts/model/Model} [opt.labelDimIndex] Fetch text by
  15076. * `opt.textFetcher.getFormattedLabel(opt.labelDataIndex, 'normal'/'emphasis', null, opt.labelDimIndex)`
  15077. * @param {Object} [normalSpecified]
  15078. * @param {Object} [emphasisSpecified]
  15079. */
  15080. function setLabelStyle(
  15081. normalStyle, emphasisStyle,
  15082. normalModel, emphasisModel,
  15083. opt,
  15084. normalSpecified, emphasisSpecified
  15085. ) {
  15086. opt = opt || EMPTY_OBJ;
  15087. var labelFetcher = opt.labelFetcher;
  15088. var labelDataIndex = opt.labelDataIndex;
  15089. var labelDimIndex = opt.labelDimIndex;
  15090. // This scenario, `label.normal.show = true; label.emphasis.show = false`,
  15091. // is not supported util someone requests.
  15092. var showNormal = normalModel.getShallow('show');
  15093. var showEmphasis = emphasisModel.getShallow('show');
  15094. // Consider performance, only fetch label when necessary.
  15095. // If `normal.show` is `false` and `emphasis.show` is `true` and `emphasis.formatter` is not set,
  15096. // label should be displayed, where text is fetched by `normal.formatter` or `opt.defaultText`.
  15097. var baseText;
  15098. if (showNormal || showEmphasis) {
  15099. if (labelFetcher) {
  15100. baseText = labelFetcher.getFormattedLabel(labelDataIndex, 'normal', null, labelDimIndex);
  15101. }
  15102. if (baseText == null) {
  15103. baseText = isFunction$1(opt.defaultText) ? opt.defaultText(labelDataIndex, opt) : opt.defaultText;
  15104. }
  15105. }
  15106. var normalStyleText = showNormal ? baseText : null;
  15107. var emphasisStyleText = showEmphasis
  15108. ? retrieve2(
  15109. labelFetcher
  15110. ? labelFetcher.getFormattedLabel(labelDataIndex, 'emphasis', null, labelDimIndex)
  15111. : null,
  15112. baseText
  15113. )
  15114. : null;
  15115. // Optimize: If style.text is null, text will not be drawn.
  15116. if (normalStyleText != null || emphasisStyleText != null) {
  15117. // Always set `textStyle` even if `normalStyle.text` is null, because default
  15118. // values have to be set on `normalStyle`.
  15119. // If we set default values on `emphasisStyle`, consider case:
  15120. // Firstly, `setOption(... label: {normal: {text: null}, emphasis: {show: true}} ...);`
  15121. // Secondly, `setOption(... label: {noraml: {show: true, text: 'abc', color: 'red'} ...);`
  15122. // Then the 'red' will not work on emphasis.
  15123. setTextStyle(normalStyle, normalModel, normalSpecified, opt);
  15124. setTextStyle(emphasisStyle, emphasisModel, emphasisSpecified, opt, true);
  15125. }
  15126. normalStyle.text = normalStyleText;
  15127. emphasisStyle.text = emphasisStyleText;
  15128. }
  15129. /**
  15130. * Modify label style manually.
  15131. * Only works after `setLabelStyle` and `setElementHoverStyle` called.
  15132. *
  15133. * @param {module:zrender/src/Element} el
  15134. * @param {Object} [normalStyleProps] optional
  15135. * @param {Object} [emphasisStyleProps] optional
  15136. */
  15137. function modifyLabelStyle(el, normalStyleProps, emphasisStyleProps) {
  15138. var elStyle = el.style;
  15139. if (normalStyleProps) {
  15140. rollbackDefaultTextStyle(elStyle);
  15141. el.setStyle(normalStyleProps);
  15142. applyDefaultTextStyle(elStyle);
  15143. }
  15144. elStyle = el.__hoverStl;
  15145. if (emphasisStyleProps && elStyle) {
  15146. rollbackDefaultTextStyle(elStyle);
  15147. extend(elStyle, emphasisStyleProps);
  15148. applyDefaultTextStyle(elStyle);
  15149. }
  15150. }
  15151. /**
  15152. * Set basic textStyle properties.
  15153. * See more info in `setTextStyleCommon`.
  15154. * @param {Object|module:zrender/graphic/Style} textStyle
  15155. * @param {module:echarts/model/Model} model
  15156. * @param {Object} [specifiedTextStyle] Can be overrided by settings in model.
  15157. * @param {Object} [opt] See `opt` of `setTextStyleCommon`.
  15158. * @param {boolean} [isEmphasis]
  15159. */
  15160. function setTextStyle(
  15161. textStyle, textStyleModel, specifiedTextStyle, opt, isEmphasis
  15162. ) {
  15163. setTextStyleCommon(textStyle, textStyleModel, opt, isEmphasis);
  15164. specifiedTextStyle && extend(textStyle, specifiedTextStyle);
  15165. // textStyle.host && textStyle.host.dirty && textStyle.host.dirty(false);
  15166. return textStyle;
  15167. }
  15168. /**
  15169. * Set text option in the style.
  15170. * See more info in `setTextStyleCommon`.
  15171. * @deprecated
  15172. * @param {Object} textStyle
  15173. * @param {module:echarts/model/Model} labelModel
  15174. * @param {string|boolean} defaultColor Default text color.
  15175. * If set as false, it will be processed as a emphasis style.
  15176. */
  15177. function setText(textStyle, labelModel, defaultColor) {
  15178. var opt = {isRectText: true};
  15179. var isEmphasis;
  15180. if (defaultColor === false) {
  15181. isEmphasis = true;
  15182. }
  15183. else {
  15184. // Support setting color as 'auto' to get visual color.
  15185. opt.autoColor = defaultColor;
  15186. }
  15187. setTextStyleCommon(textStyle, labelModel, opt, isEmphasis);
  15188. // textStyle.host && textStyle.host.dirty && textStyle.host.dirty(false);
  15189. }
  15190. /**
  15191. * The uniform entry of set text style, that is, retrieve style definitions
  15192. * from `model` and set to `textStyle` object.
  15193. *
  15194. * Never in merge mode, but in overwrite mode, that is, all of the text style
  15195. * properties will be set. (Consider the states of normal and emphasis and
  15196. * default value can be adopted, merge would make the logic too complicated
  15197. * to manage.)
  15198. *
  15199. * The `textStyle` object can either be a plain object or an instance of
  15200. * `zrender/src/graphic/Style`, and either be the style of normal or emphasis.
  15201. * After this mothod called, the `textStyle` object can then be used in
  15202. * `el.setStyle(textStyle)` or `el.hoverStyle = textStyle`.
  15203. *
  15204. * Default value will be adopted and `insideRollbackOpt` will be created.
  15205. * See `applyDefaultTextStyle` `rollbackDefaultTextStyle` for more details.
  15206. *
  15207. * opt: {
  15208. * disableBox: boolean, Whether diable drawing box of block (outer most).
  15209. * isRectText: boolean,
  15210. * autoColor: string, specify a color when color is 'auto',
  15211. * for textFill, textStroke, textBackgroundColor, and textBorderColor.
  15212. * If autoColor specified, it is used as default textFill.
  15213. * useInsideStyle:
  15214. * `true`: Use inside style (textFill, textStroke, textStrokeWidth)
  15215. * if `textFill` is not specified.
  15216. * `false`: Do not use inside style.
  15217. * `null/undefined`: use inside style if `isRectText` is true and
  15218. * `textFill` is not specified and textPosition contains `'inside'`.
  15219. * forceRich: boolean
  15220. * }
  15221. */
  15222. function setTextStyleCommon(textStyle, textStyleModel, opt, isEmphasis) {
  15223. // Consider there will be abnormal when merge hover style to normal style if given default value.
  15224. opt = opt || EMPTY_OBJ;
  15225. if (opt.isRectText) {
  15226. var textPosition = textStyleModel.getShallow('position')
  15227. || (isEmphasis ? null : 'inside');
  15228. // 'outside' is not a valid zr textPostion value, but used
  15229. // in bar series, and magric type should be considered.
  15230. textPosition === 'outside' && (textPosition = 'top');
  15231. textStyle.textPosition = textPosition;
  15232. textStyle.textOffset = textStyleModel.getShallow('offset');
  15233. var labelRotate = textStyleModel.getShallow('rotate');
  15234. labelRotate != null && (labelRotate *= Math.PI / 180);
  15235. textStyle.textRotation = labelRotate;
  15236. textStyle.textDistance = retrieve2(
  15237. textStyleModel.getShallow('distance'), isEmphasis ? null : 5
  15238. );
  15239. }
  15240. var ecModel = textStyleModel.ecModel;
  15241. var globalTextStyle = ecModel && ecModel.option.textStyle;
  15242. // Consider case:
  15243. // {
  15244. // data: [{
  15245. // value: 12,
  15246. // label: {
  15247. // rich: {
  15248. // // no 'a' here but using parent 'a'.
  15249. // }
  15250. // }
  15251. // }],
  15252. // rich: {
  15253. // a: { ... }
  15254. // }
  15255. // }
  15256. var richItemNames = getRichItemNames(textStyleModel);
  15257. var richResult;
  15258. if (richItemNames) {
  15259. richResult = {};
  15260. for (var name in richItemNames) {
  15261. if (richItemNames.hasOwnProperty(name)) {
  15262. // Cascade is supported in rich.
  15263. var richTextStyle = textStyleModel.getModel(['rich', name]);
  15264. // In rich, never `disableBox`.
  15265. // FIXME: consider `label: {formatter: '{a|xx}', color: 'blue', rich: {a: {}}}`,
  15266. // the default color `'blue'` will not be adopted if no color declared in `rich`.
  15267. // That might confuses users. So probably we should put `textStyleModel` as the
  15268. // root ancestor of the `richTextStyle`. But that would be a break change.
  15269. setTokenTextStyle(richResult[name] = {}, richTextStyle, globalTextStyle, opt, isEmphasis);
  15270. }
  15271. }
  15272. }
  15273. textStyle.rich = richResult;
  15274. setTokenTextStyle(textStyle, textStyleModel, globalTextStyle, opt, isEmphasis, true);
  15275. if (opt.forceRich && !opt.textStyle) {
  15276. opt.textStyle = {};
  15277. }
  15278. return textStyle;
  15279. }
  15280. // Consider case:
  15281. // {
  15282. // data: [{
  15283. // value: 12,
  15284. // label: {
  15285. // rich: {
  15286. // // no 'a' here but using parent 'a'.
  15287. // }
  15288. // }
  15289. // }],
  15290. // rich: {
  15291. // a: { ... }
  15292. // }
  15293. // }
  15294. function getRichItemNames(textStyleModel) {
  15295. // Use object to remove duplicated names.
  15296. var richItemNameMap;
  15297. while (textStyleModel && textStyleModel !== textStyleModel.ecModel) {
  15298. var rich = (textStyleModel.option || EMPTY_OBJ).rich;
  15299. if (rich) {
  15300. richItemNameMap = richItemNameMap || {};
  15301. for (var name in rich) {
  15302. if (rich.hasOwnProperty(name)) {
  15303. richItemNameMap[name] = 1;
  15304. }
  15305. }
  15306. }
  15307. textStyleModel = textStyleModel.parentModel;
  15308. }
  15309. return richItemNameMap;
  15310. }
  15311. function setTokenTextStyle(textStyle, textStyleModel, globalTextStyle, opt, isEmphasis, isBlock) {
  15312. // In merge mode, default value should not be given.
  15313. globalTextStyle = !isEmphasis && globalTextStyle || EMPTY_OBJ;
  15314. textStyle.textFill = getAutoColor(textStyleModel.getShallow('color'), opt)
  15315. || globalTextStyle.color;
  15316. textStyle.textStroke = getAutoColor(textStyleModel.getShallow('textBorderColor'), opt)
  15317. || globalTextStyle.textBorderColor;
  15318. textStyle.textStrokeWidth = retrieve2(
  15319. textStyleModel.getShallow('textBorderWidth'),
  15320. globalTextStyle.textBorderWidth
  15321. );
  15322. if (!isEmphasis) {
  15323. if (isBlock) {
  15324. textStyle.insideRollbackOpt = opt;
  15325. applyDefaultTextStyle(textStyle);
  15326. }
  15327. // Set default finally.
  15328. if (textStyle.textFill == null) {
  15329. textStyle.textFill = opt.autoColor;
  15330. }
  15331. }
  15332. // Do not use `getFont` here, because merge should be supported, where
  15333. // part of these properties may be changed in emphasis style, and the
  15334. // others should remain their original value got from normal style.
  15335. textStyle.fontStyle = textStyleModel.getShallow('fontStyle') || globalTextStyle.fontStyle;
  15336. textStyle.fontWeight = textStyleModel.getShallow('fontWeight') || globalTextStyle.fontWeight;
  15337. textStyle.fontSize = textStyleModel.getShallow('fontSize') || globalTextStyle.fontSize;
  15338. textStyle.fontFamily = textStyleModel.getShallow('fontFamily') || globalTextStyle.fontFamily;
  15339. textStyle.textAlign = textStyleModel.getShallow('align');
  15340. textStyle.textVerticalAlign = textStyleModel.getShallow('verticalAlign')
  15341. || textStyleModel.getShallow('baseline');
  15342. textStyle.textLineHeight = textStyleModel.getShallow('lineHeight');
  15343. textStyle.textWidth = textStyleModel.getShallow('width');
  15344. textStyle.textHeight = textStyleModel.getShallow('height');
  15345. textStyle.textTag = textStyleModel.getShallow('tag');
  15346. if (!isBlock || !opt.disableBox) {
  15347. textStyle.textBackgroundColor = getAutoColor(textStyleModel.getShallow('backgroundColor'), opt);
  15348. textStyle.textPadding = textStyleModel.getShallow('padding');
  15349. textStyle.textBorderColor = getAutoColor(textStyleModel.getShallow('borderColor'), opt);
  15350. textStyle.textBorderWidth = textStyleModel.getShallow('borderWidth');
  15351. textStyle.textBorderRadius = textStyleModel.getShallow('borderRadius');
  15352. textStyle.textBoxShadowColor = textStyleModel.getShallow('shadowColor');
  15353. textStyle.textBoxShadowBlur = textStyleModel.getShallow('shadowBlur');
  15354. textStyle.textBoxShadowOffsetX = textStyleModel.getShallow('shadowOffsetX');
  15355. textStyle.textBoxShadowOffsetY = textStyleModel.getShallow('shadowOffsetY');
  15356. }
  15357. textStyle.textShadowColor = textStyleModel.getShallow('textShadowColor')
  15358. || globalTextStyle.textShadowColor;
  15359. textStyle.textShadowBlur = textStyleModel.getShallow('textShadowBlur')
  15360. || globalTextStyle.textShadowBlur;
  15361. textStyle.textShadowOffsetX = textStyleModel.getShallow('textShadowOffsetX')
  15362. || globalTextStyle.textShadowOffsetX;
  15363. textStyle.textShadowOffsetY = textStyleModel.getShallow('textShadowOffsetY')
  15364. || globalTextStyle.textShadowOffsetY;
  15365. }
  15366. function getAutoColor(color, opt) {
  15367. return color !== 'auto' ? color : (opt && opt.autoColor) ? opt.autoColor : null;
  15368. }
  15369. /**
  15370. * Give some default value to the input `textStyle` object, based on the current settings
  15371. * in this `textStyle` object.
  15372. *
  15373. * The Scenario:
  15374. * when text position is `inside` and `textFill` is not specified, we show
  15375. * text border by default for better view. But it should be considered that text position
  15376. * might be changed when hovering or being emphasis, where the `insideRollback` is used to
  15377. * restore the style.
  15378. *
  15379. * Usage (& NOTICE):
  15380. * When a style object (eithor plain object or instance of `zrender/src/graphic/Style`) is
  15381. * about to be modified on its text related properties, `rollbackDefaultTextStyle` should
  15382. * be called before the modification and `applyDefaultTextStyle` should be called after that.
  15383. * (For the case that all of the text related properties is reset, like `setTextStyleCommon`
  15384. * does, `rollbackDefaultTextStyle` is not needed to be called).
  15385. */
  15386. function applyDefaultTextStyle(textStyle) {
  15387. var textPosition = textStyle.textPosition;
  15388. var opt = textStyle.insideRollbackOpt;
  15389. var insideRollback;
  15390. if (opt && textStyle.textFill == null) {
  15391. var autoColor = opt.autoColor;
  15392. var isRectText = opt.isRectText;
  15393. var useInsideStyle = opt.useInsideStyle;
  15394. var useInsideStyleCache = useInsideStyle !== false
  15395. && (useInsideStyle === true
  15396. || (isRectText
  15397. && textPosition
  15398. // textPosition can be [10, 30]
  15399. && typeof textPosition === 'string'
  15400. && textPosition.indexOf('inside') >= 0
  15401. )
  15402. );
  15403. var useAutoColorCache = !useInsideStyleCache && autoColor != null;
  15404. // All of the props declared in `CACHED_LABEL_STYLE_PROPERTIES` are to be cached.
  15405. if (useInsideStyleCache || useAutoColorCache) {
  15406. insideRollback = {
  15407. textFill: textStyle.textFill,
  15408. textStroke: textStyle.textStroke,
  15409. textStrokeWidth: textStyle.textStrokeWidth
  15410. };
  15411. }
  15412. if (useInsideStyleCache) {
  15413. textStyle.textFill = '#fff';
  15414. // Consider text with #fff overflow its container.
  15415. if (textStyle.textStroke == null) {
  15416. textStyle.textStroke = autoColor;
  15417. textStyle.textStrokeWidth == null && (textStyle.textStrokeWidth = 2);
  15418. }
  15419. }
  15420. if (useAutoColorCache) {
  15421. textStyle.textFill = autoColor;
  15422. }
  15423. }
  15424. // Always set `insideRollback`, so that the previous one can be cleared.
  15425. textStyle.insideRollback = insideRollback;
  15426. }
  15427. /**
  15428. * Consider the case: in a scatter,
  15429. * label: {
  15430. * normal: {position: 'inside'},
  15431. * emphasis: {position: 'top'}
  15432. * }
  15433. * In the normal state, the `textFill` will be set as '#fff' for pretty view (see
  15434. * `applyDefaultTextStyle`), but when switching to emphasis state, the `textFill`
  15435. * should be retured to 'autoColor', but not keep '#fff'.
  15436. */
  15437. function rollbackDefaultTextStyle(style) {
  15438. var insideRollback = style.insideRollback;
  15439. if (insideRollback) {
  15440. // Reset all of the props in `CACHED_LABEL_STYLE_PROPERTIES`.
  15441. style.textFill = insideRollback.textFill;
  15442. style.textStroke = insideRollback.textStroke;
  15443. style.textStrokeWidth = insideRollback.textStrokeWidth;
  15444. style.insideRollback = null;
  15445. }
  15446. }
  15447. function getFont(opt, ecModel) {
  15448. // ecModel or default text style model.
  15449. var gTextStyleModel = ecModel || ecModel.getModel('textStyle');
  15450. return trim([
  15451. // FIXME in node-canvas fontWeight is before fontStyle
  15452. opt.fontStyle || gTextStyleModel && gTextStyleModel.getShallow('fontStyle') || '',
  15453. opt.fontWeight || gTextStyleModel && gTextStyleModel.getShallow('fontWeight') || '',
  15454. (opt.fontSize || gTextStyleModel && gTextStyleModel.getShallow('fontSize') || 12) + 'px',
  15455. opt.fontFamily || gTextStyleModel && gTextStyleModel.getShallow('fontFamily') || 'sans-serif'
  15456. ].join(' '));
  15457. }
  15458. function animateOrSetProps(isUpdate, el, props, animatableModel, dataIndex, cb) {
  15459. if (typeof dataIndex === 'function') {
  15460. cb = dataIndex;
  15461. dataIndex = null;
  15462. }
  15463. // Do not check 'animation' property directly here. Consider this case:
  15464. // animation model is an `itemModel`, whose does not have `isAnimationEnabled`
  15465. // but its parent model (`seriesModel`) does.
  15466. var animationEnabled = animatableModel && animatableModel.isAnimationEnabled();
  15467. if (animationEnabled) {
  15468. var postfix = isUpdate ? 'Update' : '';
  15469. var duration = animatableModel.getShallow('animationDuration' + postfix);
  15470. var animationEasing = animatableModel.getShallow('animationEasing' + postfix);
  15471. var animationDelay = animatableModel.getShallow('animationDelay' + postfix);
  15472. if (typeof animationDelay === 'function') {
  15473. animationDelay = animationDelay(
  15474. dataIndex,
  15475. animatableModel.getAnimationDelayParams
  15476. ? animatableModel.getAnimationDelayParams(el, dataIndex)
  15477. : null
  15478. );
  15479. }
  15480. if (typeof duration === 'function') {
  15481. duration = duration(dataIndex);
  15482. }
  15483. duration > 0
  15484. ? el.animateTo(props, duration, animationDelay || 0, animationEasing, cb, !!cb)
  15485. : (el.stopAnimation(), el.attr(props), cb && cb());
  15486. }
  15487. else {
  15488. el.stopAnimation();
  15489. el.attr(props);
  15490. cb && cb();
  15491. }
  15492. }
  15493. /**
  15494. * Update graphic element properties with or without animation according to the
  15495. * configuration in series.
  15496. *
  15497. * Caution: this method will stop previous animation.
  15498. * So if do not use this method to one element twice before
  15499. * animation starts, unless you know what you are doing.
  15500. *
  15501. * @param {module:zrender/Element} el
  15502. * @param {Object} props
  15503. * @param {module:echarts/model/Model} [animatableModel]
  15504. * @param {number} [dataIndex]
  15505. * @param {Function} [cb]
  15506. * @example
  15507. * graphic.updateProps(el, {
  15508. * position: [100, 100]
  15509. * }, seriesModel, dataIndex, function () { console.log('Animation done!'); });
  15510. * // Or
  15511. * graphic.updateProps(el, {
  15512. * position: [100, 100]
  15513. * }, seriesModel, function () { console.log('Animation done!'); });
  15514. */
  15515. function updateProps(el, props, animatableModel, dataIndex, cb) {
  15516. animateOrSetProps(true, el, props, animatableModel, dataIndex, cb);
  15517. }
  15518. /**
  15519. * Init graphic element properties with or without animation according to the
  15520. * configuration in series.
  15521. *
  15522. * Caution: this method will stop previous animation.
  15523. * So if do not use this method to one element twice before
  15524. * animation starts, unless you know what you are doing.
  15525. *
  15526. * @param {module:zrender/Element} el
  15527. * @param {Object} props
  15528. * @param {module:echarts/model/Model} [animatableModel]
  15529. * @param {number} [dataIndex]
  15530. * @param {Function} cb
  15531. */
  15532. function initProps(el, props, animatableModel, dataIndex, cb) {
  15533. animateOrSetProps(false, el, props, animatableModel, dataIndex, cb);
  15534. }
  15535. /**
  15536. * Get transform matrix of target (param target),
  15537. * in coordinate of its ancestor (param ancestor)
  15538. *
  15539. * @param {module:zrender/mixin/Transformable} target
  15540. * @param {module:zrender/mixin/Transformable} [ancestor]
  15541. */
  15542. function getTransform(target, ancestor) {
  15543. var mat = identity([]);
  15544. while (target && target !== ancestor) {
  15545. mul$1(mat, target.getLocalTransform(), mat);
  15546. target = target.parent;
  15547. }
  15548. return mat;
  15549. }
  15550. /**
  15551. * Apply transform to an vertex.
  15552. * @param {Array.<number>} target [x, y]
  15553. * @param {Array.<number>|TypedArray.<number>|Object} transform Can be:
  15554. * + Transform matrix: like [1, 0, 0, 1, 0, 0]
  15555. * + {position, rotation, scale}, the same as `zrender/Transformable`.
  15556. * @param {boolean=} invert Whether use invert matrix.
  15557. * @return {Array.<number>} [x, y]
  15558. */
  15559. function applyTransform$1(target, transform, invert$$1) {
  15560. if (transform && !isArrayLike(transform)) {
  15561. transform = Transformable.getLocalTransform(transform);
  15562. }
  15563. if (invert$$1) {
  15564. transform = invert([], transform);
  15565. }
  15566. return applyTransform([], target, transform);
  15567. }
  15568. /**
  15569. * @param {string} direction 'left' 'right' 'top' 'bottom'
  15570. * @param {Array.<number>} transform Transform matrix: like [1, 0, 0, 1, 0, 0]
  15571. * @param {boolean=} invert Whether use invert matrix.
  15572. * @return {string} Transformed direction. 'left' 'right' 'top' 'bottom'
  15573. */
  15574. function transformDirection(direction, transform, invert$$1) {
  15575. // Pick a base, ensure that transform result will not be (0, 0).
  15576. var hBase = (transform[4] === 0 || transform[5] === 0 || transform[0] === 0)
  15577. ? 1 : Math.abs(2 * transform[4] / transform[0]);
  15578. var vBase = (transform[4] === 0 || transform[5] === 0 || transform[2] === 0)
  15579. ? 1 : Math.abs(2 * transform[4] / transform[2]);
  15580. var vertex = [
  15581. direction === 'left' ? -hBase : direction === 'right' ? hBase : 0,
  15582. direction === 'top' ? -vBase : direction === 'bottom' ? vBase : 0
  15583. ];
  15584. vertex = applyTransform$1(vertex, transform, invert$$1);
  15585. return Math.abs(vertex[0]) > Math.abs(vertex[1])
  15586. ? (vertex[0] > 0 ? 'right' : 'left')
  15587. : (vertex[1] > 0 ? 'bottom' : 'top');
  15588. }
  15589. /**
  15590. * Apply group transition animation from g1 to g2.
  15591. * If no animatableModel, no animation.
  15592. */
  15593. function groupTransition(g1, g2, animatableModel, cb) {
  15594. if (!g1 || !g2) {
  15595. return;
  15596. }
  15597. function getElMap(g) {
  15598. var elMap = {};
  15599. g.traverse(function (el) {
  15600. if (!el.isGroup && el.anid) {
  15601. elMap[el.anid] = el;
  15602. }
  15603. });
  15604. return elMap;
  15605. }
  15606. function getAnimatableProps(el) {
  15607. var obj = {
  15608. position: clone$1(el.position),
  15609. rotation: el.rotation
  15610. };
  15611. if (el.shape) {
  15612. obj.shape = extend({}, el.shape);
  15613. }
  15614. return obj;
  15615. }
  15616. var elMap1 = getElMap(g1);
  15617. g2.traverse(function (el) {
  15618. if (!el.isGroup && el.anid) {
  15619. var oldEl = elMap1[el.anid];
  15620. if (oldEl) {
  15621. var newProp = getAnimatableProps(el);
  15622. el.attr(getAnimatableProps(oldEl));
  15623. updateProps(el, newProp, animatableModel, el.dataIndex);
  15624. }
  15625. // else {
  15626. // if (el.previousProps) {
  15627. // graphic.updateProps
  15628. // }
  15629. // }
  15630. }
  15631. });
  15632. }
  15633. /**
  15634. * @param {Array.<Array.<number>>} points Like: [[23, 44], [53, 66], ...]
  15635. * @param {Object} rect {x, y, width, height}
  15636. * @return {Array.<Array.<number>>} A new clipped points.
  15637. */
  15638. function clipPointsByRect(points, rect) {
  15639. // FIXME: this way migth be incorrect when grpahic clipped by a corner.
  15640. // and when element have border.
  15641. return map(points, function (point) {
  15642. var x = point[0];
  15643. x = mathMax$1(x, rect.x);
  15644. x = mathMin$1(x, rect.x + rect.width);
  15645. var y = point[1];
  15646. y = mathMax$1(y, rect.y);
  15647. y = mathMin$1(y, rect.y + rect.height);
  15648. return [x, y];
  15649. });
  15650. }
  15651. /**
  15652. * @param {Object} targetRect {x, y, width, height}
  15653. * @param {Object} rect {x, y, width, height}
  15654. * @return {Object} A new clipped rect. If rect size are negative, return undefined.
  15655. */
  15656. function clipRectByRect(targetRect, rect) {
  15657. var x = mathMax$1(targetRect.x, rect.x);
  15658. var x2 = mathMin$1(targetRect.x + targetRect.width, rect.x + rect.width);
  15659. var y = mathMax$1(targetRect.y, rect.y);
  15660. var y2 = mathMin$1(targetRect.y + targetRect.height, rect.y + rect.height);
  15661. // If the total rect is cliped, nothing, including the border,
  15662. // should be painted. So return undefined.
  15663. if (x2 >= x && y2 >= y) {
  15664. return {
  15665. x: x,
  15666. y: y,
  15667. width: x2 - x,
  15668. height: y2 - y
  15669. };
  15670. }
  15671. }
  15672. /**
  15673. * @param {string} iconStr Support 'image://' or 'path://' or direct svg path.
  15674. * @param {Object} [opt] Properties of `module:zrender/Element`, except `style`.
  15675. * @param {Object} [rect] {x, y, width, height}
  15676. * @return {module:zrender/Element} Icon path or image element.
  15677. */
  15678. function createIcon(iconStr, opt, rect) {
  15679. opt = extend({rectHover: true}, opt);
  15680. var style = opt.style = {strokeNoScale: true};
  15681. rect = rect || {x: -1, y: -1, width: 2, height: 2};
  15682. if (iconStr) {
  15683. return iconStr.indexOf('image://') === 0
  15684. ? (
  15685. style.image = iconStr.slice(8),
  15686. defaults(style, rect),
  15687. new ZImage(opt)
  15688. )
  15689. : (
  15690. makePath(
  15691. iconStr.replace('path://', ''),
  15692. opt,
  15693. rect,
  15694. 'center'
  15695. )
  15696. );
  15697. }
  15698. }
  15699. /**
  15700. * Return `true` if the given line (line `a`) and the given polygon
  15701. * are intersect.
  15702. * Note that we do not count colinear as intersect here because no
  15703. * requirement for that. We could do that if required in future.
  15704. *
  15705. * @param {number} a1x
  15706. * @param {number} a1y
  15707. * @param {number} a2x
  15708. * @param {number} a2y
  15709. * @param {Array.<Array.<number>>} points Points of the polygon.
  15710. * @return {boolean}
  15711. */
  15712. function linePolygonIntersect(a1x, a1y, a2x, a2y, points) {
  15713. for (var i = 0, p2 = points[points.length - 1]; i < points.length; i++) {
  15714. var p = points[i];
  15715. if (lineLineIntersect(a1x, a1y, a2x, a2y, p[0], p[1], p2[0], p2[1])) {
  15716. return true;
  15717. }
  15718. p2 = p;
  15719. }
  15720. }
  15721. /**
  15722. * Return `true` if the given two lines (line `a` and line `b`)
  15723. * are intersect.
  15724. * Note that we do not count colinear as intersect here because no
  15725. * requirement for that. We could do that if required in future.
  15726. *
  15727. * @param {number} a1x
  15728. * @param {number} a1y
  15729. * @param {number} a2x
  15730. * @param {number} a2y
  15731. * @param {number} b1x
  15732. * @param {number} b1y
  15733. * @param {number} b2x
  15734. * @param {number} b2y
  15735. * @return {boolean}
  15736. */
  15737. function lineLineIntersect(a1x, a1y, a2x, a2y, b1x, b1y, b2x, b2y) {
  15738. // let `vec_m` to be `vec_a2 - vec_a1` and `vec_n` to be `vec_b2 - vec_b1`.
  15739. var mx = a2x - a1x;
  15740. var my = a2y - a1y;
  15741. var nx = b2x - b1x;
  15742. var ny = b2y - b1y;
  15743. // `vec_m` and `vec_n` are parallel iff
  15744. // exising `k` such that `vec_m = k · vec_n`, equivalent to `vec_m X vec_n = 0`.
  15745. var nmCrossProduct = crossProduct2d(nx, ny, mx, my);
  15746. if (nearZero(nmCrossProduct)) {
  15747. return false;
  15748. }
  15749. // `vec_m` and `vec_n` are intersect iff
  15750. // existing `p` and `q` in [0, 1] such that `vec_a1 + p * vec_m = vec_b1 + q * vec_n`,
  15751. // such that `q = ((vec_a1 - vec_b1) X vec_m) / (vec_n X vec_m)`
  15752. // and `p = ((vec_a1 - vec_b1) X vec_n) / (vec_n X vec_m)`.
  15753. var b1a1x = a1x - b1x;
  15754. var b1a1y = a1y - b1y;
  15755. var q = crossProduct2d(b1a1x, b1a1y, mx, my) / nmCrossProduct;
  15756. if (q < 0 || q > 1) {
  15757. return false;
  15758. }
  15759. var p = crossProduct2d(b1a1x, b1a1y, nx, ny) / nmCrossProduct;
  15760. if (p < 0 || p > 1) {
  15761. return false;
  15762. }
  15763. return true;
  15764. }
  15765. /**
  15766. * Cross product of 2-dimension vector.
  15767. */
  15768. function crossProduct2d(x1, y1, x2, y2) {
  15769. return x1 * y2 - x2 * y1;
  15770. }
  15771. function nearZero(val) {
  15772. return val <= (1e-6) && val >= -(1e-6);
  15773. }
  15774. var graphic = (Object.freeze || Object)({
  15775. Z2_EMPHASIS_LIFT: Z2_EMPHASIS_LIFT,
  15776. CACHED_LABEL_STYLE_PROPERTIES: CACHED_LABEL_STYLE_PROPERTIES,
  15777. extendShape: extendShape,
  15778. extendPath: extendPath,
  15779. makePath: makePath,
  15780. makeImage: makeImage,
  15781. mergePath: mergePath,
  15782. resizePath: resizePath,
  15783. subPixelOptimizeLine: subPixelOptimizeLine,
  15784. subPixelOptimizeRect: subPixelOptimizeRect,
  15785. subPixelOptimize: subPixelOptimize,
  15786. setElementHoverStyle: setElementHoverStyle,
  15787. setHoverStyle: setHoverStyle,
  15788. setAsHighDownDispatcher: setAsHighDownDispatcher,
  15789. isHighDownDispatcher: isHighDownDispatcher,
  15790. getHighlightDigit: getHighlightDigit,
  15791. setLabelStyle: setLabelStyle,
  15792. modifyLabelStyle: modifyLabelStyle,
  15793. setTextStyle: setTextStyle,
  15794. setText: setText,
  15795. getFont: getFont,
  15796. updateProps: updateProps,
  15797. initProps: initProps,
  15798. getTransform: getTransform,
  15799. applyTransform: applyTransform$1,
  15800. transformDirection: transformDirection,
  15801. groupTransition: groupTransition,
  15802. clipPointsByRect: clipPointsByRect,
  15803. clipRectByRect: clipRectByRect,
  15804. createIcon: createIcon,
  15805. linePolygonIntersect: linePolygonIntersect,
  15806. lineLineIntersect: lineLineIntersect,
  15807. Group: Group,
  15808. Image: ZImage,
  15809. Text: Text,
  15810. Circle: Circle,
  15811. Sector: Sector,
  15812. Ring: Ring,
  15813. Polygon: Polygon,
  15814. Polyline: Polyline,
  15815. Rect: Rect,
  15816. Line: Line,
  15817. BezierCurve: BezierCurve,
  15818. Arc: Arc,
  15819. IncrementalDisplayable: IncrementalDisplayble,
  15820. CompoundPath: CompoundPath,
  15821. LinearGradient: LinearGradient,
  15822. RadialGradient: RadialGradient,
  15823. BoundingRect: BoundingRect
  15824. });
  15825. /*
  15826. * Licensed to the Apache Software Foundation (ASF) under one
  15827. * or more contributor license agreements. See the NOTICE file
  15828. * distributed with this work for additional information
  15829. * regarding copyright ownership. The ASF licenses this file
  15830. * to you under the Apache License, Version 2.0 (the
  15831. * "License"); you may not use this file except in compliance
  15832. * with the License. You may obtain a copy of the License at
  15833. *
  15834. * http://www.apache.org/licenses/LICENSE-2.0
  15835. *
  15836. * Unless required by applicable law or agreed to in writing,
  15837. * software distributed under the License is distributed on an
  15838. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15839. * KIND, either express or implied. See the License for the
  15840. * specific language governing permissions and limitations
  15841. * under the License.
  15842. */
  15843. var PATH_COLOR = ['textStyle', 'color'];
  15844. var textStyleMixin = {
  15845. /**
  15846. * Get color property or get color from option.textStyle.color
  15847. * @param {boolean} [isEmphasis]
  15848. * @return {string}
  15849. */
  15850. getTextColor: function (isEmphasis) {
  15851. var ecModel = this.ecModel;
  15852. return this.getShallow('color')
  15853. || (
  15854. (!isEmphasis && ecModel) ? ecModel.get(PATH_COLOR) : null
  15855. );
  15856. },
  15857. /**
  15858. * Create font string from fontStyle, fontWeight, fontSize, fontFamily
  15859. * @return {string}
  15860. */
  15861. getFont: function () {
  15862. return getFont({
  15863. fontStyle: this.getShallow('fontStyle'),
  15864. fontWeight: this.getShallow('fontWeight'),
  15865. fontSize: this.getShallow('fontSize'),
  15866. fontFamily: this.getShallow('fontFamily')
  15867. }, this.ecModel);
  15868. },
  15869. getTextRect: function (text) {
  15870. return getBoundingRect(
  15871. text,
  15872. this.getFont(),
  15873. this.getShallow('align'),
  15874. this.getShallow('verticalAlign') || this.getShallow('baseline'),
  15875. this.getShallow('padding'),
  15876. this.getShallow('lineHeight'),
  15877. this.getShallow('rich'),
  15878. this.getShallow('truncateText')
  15879. );
  15880. }
  15881. };
  15882. /*
  15883. * Licensed to the Apache Software Foundation (ASF) under one
  15884. * or more contributor license agreements. See the NOTICE file
  15885. * distributed with this work for additional information
  15886. * regarding copyright ownership. The ASF licenses this file
  15887. * to you under the Apache License, Version 2.0 (the
  15888. * "License"); you may not use this file except in compliance
  15889. * with the License. You may obtain a copy of the License at
  15890. *
  15891. * http://www.apache.org/licenses/LICENSE-2.0
  15892. *
  15893. * Unless required by applicable law or agreed to in writing,
  15894. * software distributed under the License is distributed on an
  15895. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15896. * KIND, either express or implied. See the License for the
  15897. * specific language governing permissions and limitations
  15898. * under the License.
  15899. */
  15900. var getItemStyle = makeStyleMapper(
  15901. [
  15902. ['fill', 'color'],
  15903. ['stroke', 'borderColor'],
  15904. ['lineWidth', 'borderWidth'],
  15905. ['opacity'],
  15906. ['shadowBlur'],
  15907. ['shadowOffsetX'],
  15908. ['shadowOffsetY'],
  15909. ['shadowColor'],
  15910. ['textPosition'],
  15911. ['textAlign']
  15912. ]
  15913. );
  15914. var itemStyleMixin = {
  15915. getItemStyle: function (excludes, includes) {
  15916. var style = getItemStyle(this, excludes, includes);
  15917. var lineDash = this.getBorderLineDash();
  15918. lineDash && (style.lineDash = lineDash);
  15919. return style;
  15920. },
  15921. getBorderLineDash: function () {
  15922. var lineType = this.get('borderType');
  15923. return (lineType === 'solid' || lineType == null) ? null
  15924. : (lineType === 'dashed' ? [5, 5] : [1, 1]);
  15925. }
  15926. };
  15927. /*
  15928. * Licensed to the Apache Software Foundation (ASF) under one
  15929. * or more contributor license agreements. See the NOTICE file
  15930. * distributed with this work for additional information
  15931. * regarding copyright ownership. The ASF licenses this file
  15932. * to you under the Apache License, Version 2.0 (the
  15933. * "License"); you may not use this file except in compliance
  15934. * with the License. You may obtain a copy of the License at
  15935. *
  15936. * http://www.apache.org/licenses/LICENSE-2.0
  15937. *
  15938. * Unless required by applicable law or agreed to in writing,
  15939. * software distributed under the License is distributed on an
  15940. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15941. * KIND, either express or implied. See the License for the
  15942. * specific language governing permissions and limitations
  15943. * under the License.
  15944. */
  15945. /**
  15946. * @module echarts/model/Model
  15947. */
  15948. var mixin$1 = mixin;
  15949. var inner = makeInner();
  15950. /**
  15951. * @alias module:echarts/model/Model
  15952. * @constructor
  15953. * @param {Object} [option]
  15954. * @param {module:echarts/model/Model} [parentModel]
  15955. * @param {module:echarts/model/Global} [ecModel]
  15956. */
  15957. function Model(option, parentModel, ecModel) {
  15958. /**
  15959. * @type {module:echarts/model/Model}
  15960. * @readOnly
  15961. */
  15962. this.parentModel = parentModel;
  15963. /**
  15964. * @type {module:echarts/model/Global}
  15965. * @readOnly
  15966. */
  15967. this.ecModel = ecModel;
  15968. /**
  15969. * @type {Object}
  15970. * @protected
  15971. */
  15972. this.option = option;
  15973. // Simple optimization
  15974. // if (this.init) {
  15975. // if (arguments.length <= 4) {
  15976. // this.init(option, parentModel, ecModel, extraOpt);
  15977. // }
  15978. // else {
  15979. // this.init.apply(this, arguments);
  15980. // }
  15981. // }
  15982. }
  15983. Model.prototype = {
  15984. constructor: Model,
  15985. /**
  15986. * Model 的初始化函数
  15987. * @param {Object} option
  15988. */
  15989. init: null,
  15990. /**
  15991. * 从新的 Option merge
  15992. */
  15993. mergeOption: function (option) {
  15994. merge(this.option, option, true);
  15995. },
  15996. /**
  15997. * @param {string|Array.<string>} path
  15998. * @param {boolean} [ignoreParent=false]
  15999. * @return {*}
  16000. */
  16001. get: function (path, ignoreParent) {
  16002. if (path == null) {
  16003. return this.option;
  16004. }
  16005. return doGet(
  16006. this.option,
  16007. this.parsePath(path),
  16008. !ignoreParent && getParent(this, path)
  16009. );
  16010. },
  16011. /**
  16012. * @param {string} key
  16013. * @param {boolean} [ignoreParent=false]
  16014. * @return {*}
  16015. */
  16016. getShallow: function (key, ignoreParent) {
  16017. var option = this.option;
  16018. var val = option == null ? option : option[key];
  16019. var parentModel = !ignoreParent && getParent(this, key);
  16020. if (val == null && parentModel) {
  16021. val = parentModel.getShallow(key);
  16022. }
  16023. return val;
  16024. },
  16025. /**
  16026. * @param {string|Array.<string>} [path]
  16027. * @param {module:echarts/model/Model} [parentModel]
  16028. * @return {module:echarts/model/Model}
  16029. */
  16030. getModel: function (path, parentModel) {
  16031. var obj = path == null
  16032. ? this.option
  16033. : doGet(this.option, path = this.parsePath(path));
  16034. var thisParentModel;
  16035. parentModel = parentModel || (
  16036. (thisParentModel = getParent(this, path))
  16037. && thisParentModel.getModel(path)
  16038. );
  16039. return new Model(obj, parentModel, this.ecModel);
  16040. },
  16041. /**
  16042. * If model has option
  16043. */
  16044. isEmpty: function () {
  16045. return this.option == null;
  16046. },
  16047. restoreData: function () {},
  16048. // Pending
  16049. clone: function () {
  16050. var Ctor = this.constructor;
  16051. return new Ctor(clone(this.option));
  16052. },
  16053. setReadOnly: function (properties) {
  16054. // clazzUtil.setReadOnly(this, properties);
  16055. },
  16056. // If path is null/undefined, return null/undefined.
  16057. parsePath: function (path) {
  16058. if (typeof path === 'string') {
  16059. path = path.split('.');
  16060. }
  16061. return path;
  16062. },
  16063. /**
  16064. * @param {Function} getParentMethod
  16065. * param {Array.<string>|string} path
  16066. * return {module:echarts/model/Model}
  16067. */
  16068. customizeGetParent: function (getParentMethod) {
  16069. inner(this).getParent = getParentMethod;
  16070. },
  16071. isAnimationEnabled: function () {
  16072. if (!env$1.node) {
  16073. if (this.option.animation != null) {
  16074. return !!this.option.animation;
  16075. }
  16076. else if (this.parentModel) {
  16077. return this.parentModel.isAnimationEnabled();
  16078. }
  16079. }
  16080. }
  16081. };
  16082. function doGet(obj, pathArr, parentModel) {
  16083. for (var i = 0; i < pathArr.length; i++) {
  16084. // Ignore empty
  16085. if (!pathArr[i]) {
  16086. continue;
  16087. }
  16088. // obj could be number/string/... (like 0)
  16089. obj = (obj && typeof obj === 'object') ? obj[pathArr[i]] : null;
  16090. if (obj == null) {
  16091. break;
  16092. }
  16093. }
  16094. if (obj == null && parentModel) {
  16095. obj = parentModel.get(pathArr);
  16096. }
  16097. return obj;
  16098. }
  16099. // `path` can be null/undefined
  16100. function getParent(model, path) {
  16101. var getParentMethod = inner(model).getParent;
  16102. return getParentMethod ? getParentMethod.call(model, path) : model.parentModel;
  16103. }
  16104. // Enable Model.extend.
  16105. enableClassExtend(Model);
  16106. enableClassCheck(Model);
  16107. mixin$1(Model, lineStyleMixin);
  16108. mixin$1(Model, areaStyleMixin);
  16109. mixin$1(Model, textStyleMixin);
  16110. mixin$1(Model, itemStyleMixin);
  16111. /*
  16112. * Licensed to the Apache Software Foundation (ASF) under one
  16113. * or more contributor license agreements. See the NOTICE file
  16114. * distributed with this work for additional information
  16115. * regarding copyright ownership. The ASF licenses this file
  16116. * to you under the Apache License, Version 2.0 (the
  16117. * "License"); you may not use this file except in compliance
  16118. * with the License. You may obtain a copy of the License at
  16119. *
  16120. * http://www.apache.org/licenses/LICENSE-2.0
  16121. *
  16122. * Unless required by applicable law or agreed to in writing,
  16123. * software distributed under the License is distributed on an
  16124. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16125. * KIND, either express or implied. See the License for the
  16126. * specific language governing permissions and limitations
  16127. * under the License.
  16128. */
  16129. var base = 0;
  16130. /**
  16131. * @public
  16132. * @param {string} type
  16133. * @return {string}
  16134. */
  16135. function getUID(type) {
  16136. // Considering the case of crossing js context,
  16137. // use Math.random to make id as unique as possible.
  16138. return [(type || ''), base++, Math.random().toFixed(5)].join('_');
  16139. }
  16140. /**
  16141. * @inner
  16142. */
  16143. function enableSubTypeDefaulter(entity) {
  16144. var subTypeDefaulters = {};
  16145. entity.registerSubTypeDefaulter = function (componentType, defaulter) {
  16146. componentType = parseClassType$1(componentType);
  16147. subTypeDefaulters[componentType.main] = defaulter;
  16148. };
  16149. entity.determineSubType = function (componentType, option) {
  16150. var type = option.type;
  16151. if (!type) {
  16152. var componentTypeMain = parseClassType$1(componentType).main;
  16153. if (entity.hasSubTypes(componentType) && subTypeDefaulters[componentTypeMain]) {
  16154. type = subTypeDefaulters[componentTypeMain](option);
  16155. }
  16156. }
  16157. return type;
  16158. };
  16159. return entity;
  16160. }
  16161. /**
  16162. * Topological travel on Activity Network (Activity On Vertices).
  16163. * Dependencies is defined in Model.prototype.dependencies, like ['xAxis', 'yAxis'].
  16164. *
  16165. * If 'xAxis' or 'yAxis' is absent in componentTypeList, just ignore it in topology.
  16166. *
  16167. * If there is circle dependencey, Error will be thrown.
  16168. *
  16169. */
  16170. function enableTopologicalTravel(entity, dependencyGetter) {
  16171. /**
  16172. * @public
  16173. * @param {Array.<string>} targetNameList Target Component type list.
  16174. * Can be ['aa', 'bb', 'aa.xx']
  16175. * @param {Array.<string>} fullNameList By which we can build dependency graph.
  16176. * @param {Function} callback Params: componentType, dependencies.
  16177. * @param {Object} context Scope of callback.
  16178. */
  16179. entity.topologicalTravel = function (targetNameList, fullNameList, callback, context) {
  16180. if (!targetNameList.length) {
  16181. return;
  16182. }
  16183. var result = makeDepndencyGraph(fullNameList);
  16184. var graph = result.graph;
  16185. var stack = result.noEntryList;
  16186. var targetNameSet = {};
  16187. each$1(targetNameList, function (name) {
  16188. targetNameSet[name] = true;
  16189. });
  16190. while (stack.length) {
  16191. var currComponentType = stack.pop();
  16192. var currVertex = graph[currComponentType];
  16193. var isInTargetNameSet = !!targetNameSet[currComponentType];
  16194. if (isInTargetNameSet) {
  16195. callback.call(context, currComponentType, currVertex.originalDeps.slice());
  16196. delete targetNameSet[currComponentType];
  16197. }
  16198. each$1(
  16199. currVertex.successor,
  16200. isInTargetNameSet ? removeEdgeAndAdd : removeEdge
  16201. );
  16202. }
  16203. each$1(targetNameSet, function () {
  16204. throw new Error('Circle dependency may exists');
  16205. });
  16206. function removeEdge(succComponentType) {
  16207. graph[succComponentType].entryCount--;
  16208. if (graph[succComponentType].entryCount === 0) {
  16209. stack.push(succComponentType);
  16210. }
  16211. }
  16212. // Consider this case: legend depends on series, and we call
  16213. // chart.setOption({series: [...]}), where only series is in option.
  16214. // If we do not have 'removeEdgeAndAdd', legendModel.mergeOption will
  16215. // not be called, but only sereis.mergeOption is called. Thus legend
  16216. // have no chance to update its local record about series (like which
  16217. // name of series is available in legend).
  16218. function removeEdgeAndAdd(succComponentType) {
  16219. targetNameSet[succComponentType] = true;
  16220. removeEdge(succComponentType);
  16221. }
  16222. };
  16223. /**
  16224. * DepndencyGraph: {Object}
  16225. * key: conponentType,
  16226. * value: {
  16227. * successor: [conponentTypes...],
  16228. * originalDeps: [conponentTypes...],
  16229. * entryCount: {number}
  16230. * }
  16231. */
  16232. function makeDepndencyGraph(fullNameList) {
  16233. var graph = {};
  16234. var noEntryList = [];
  16235. each$1(fullNameList, function (name) {
  16236. var thisItem = createDependencyGraphItem(graph, name);
  16237. var originalDeps = thisItem.originalDeps = dependencyGetter(name);
  16238. var availableDeps = getAvailableDependencies(originalDeps, fullNameList);
  16239. thisItem.entryCount = availableDeps.length;
  16240. if (thisItem.entryCount === 0) {
  16241. noEntryList.push(name);
  16242. }
  16243. each$1(availableDeps, function (dependentName) {
  16244. if (indexOf(thisItem.predecessor, dependentName) < 0) {
  16245. thisItem.predecessor.push(dependentName);
  16246. }
  16247. var thatItem = createDependencyGraphItem(graph, dependentName);
  16248. if (indexOf(thatItem.successor, dependentName) < 0) {
  16249. thatItem.successor.push(name);
  16250. }
  16251. });
  16252. });
  16253. return {graph: graph, noEntryList: noEntryList};
  16254. }
  16255. function createDependencyGraphItem(graph, name) {
  16256. if (!graph[name]) {
  16257. graph[name] = {predecessor: [], successor: []};
  16258. }
  16259. return graph[name];
  16260. }
  16261. function getAvailableDependencies(originalDeps, fullNameList) {
  16262. var availableDeps = [];
  16263. each$1(originalDeps, function (dep) {
  16264. indexOf(fullNameList, dep) >= 0 && availableDeps.push(dep);
  16265. });
  16266. return availableDeps;
  16267. }
  16268. }
  16269. /*
  16270. * Licensed to the Apache Software Foundation (ASF) under one
  16271. * or more contributor license agreements. See the NOTICE file
  16272. * distributed with this work for additional information
  16273. * regarding copyright ownership. The ASF licenses this file
  16274. * to you under the Apache License, Version 2.0 (the
  16275. * "License"); you may not use this file except in compliance
  16276. * with the License. You may obtain a copy of the License at
  16277. *
  16278. * http://www.apache.org/licenses/LICENSE-2.0
  16279. *
  16280. * Unless required by applicable law or agreed to in writing,
  16281. * software distributed under the License is distributed on an
  16282. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16283. * KIND, either express or implied. See the License for the
  16284. * specific language governing permissions and limitations
  16285. * under the License.
  16286. */
  16287. /*
  16288. * A third-party license is embeded for some of the code in this file:
  16289. * The method "quantile" was copied from "d3.js".
  16290. * (See more details in the comment of the method below.)
  16291. * The use of the source code of this file is also subject to the terms
  16292. * and consitions of the license of "d3.js" (BSD-3Clause, see
  16293. * </licenses/LICENSE-d3>).
  16294. */
  16295. var RADIAN_EPSILON = 1e-4;
  16296. function _trim(str) {
  16297. return str.replace(/^\s+/, '').replace(/\s+$/, '');
  16298. }
  16299. /**
  16300. * Linear mapping a value from domain to range
  16301. * @memberOf module:echarts/util/number
  16302. * @param {(number|Array.<number>)} val
  16303. * @param {Array.<number>} domain Domain extent domain[0] can be bigger than domain[1]
  16304. * @param {Array.<number>} range Range extent range[0] can be bigger than range[1]
  16305. * @param {boolean} clamp
  16306. * @return {(number|Array.<number>}
  16307. */
  16308. function linearMap(val, domain, range, clamp) {
  16309. var subDomain = domain[1] - domain[0];
  16310. var subRange = range[1] - range[0];
  16311. if (subDomain === 0) {
  16312. return subRange === 0
  16313. ? range[0]
  16314. : (range[0] + range[1]) / 2;
  16315. }
  16316. // Avoid accuracy problem in edge, such as
  16317. // 146.39 - 62.83 === 83.55999999999999.
  16318. // See echarts/test/ut/spec/util/number.js#linearMap#accuracyError
  16319. // It is a little verbose for efficiency considering this method
  16320. // is a hotspot.
  16321. if (clamp) {
  16322. if (subDomain > 0) {
  16323. if (val <= domain[0]) {
  16324. return range[0];
  16325. }
  16326. else if (val >= domain[1]) {
  16327. return range[1];
  16328. }
  16329. }
  16330. else {
  16331. if (val >= domain[0]) {
  16332. return range[0];
  16333. }
  16334. else if (val <= domain[1]) {
  16335. return range[1];
  16336. }
  16337. }
  16338. }
  16339. else {
  16340. if (val === domain[0]) {
  16341. return range[0];
  16342. }
  16343. if (val === domain[1]) {
  16344. return range[1];
  16345. }
  16346. }
  16347. return (val - domain[0]) / subDomain * subRange + range[0];
  16348. }
  16349. /**
  16350. * Convert a percent string to absolute number.
  16351. * Returns NaN if percent is not a valid string or number
  16352. * @memberOf module:echarts/util/number
  16353. * @param {string|number} percent
  16354. * @param {number} all
  16355. * @return {number}
  16356. */
  16357. function parsePercent$1(percent, all) {
  16358. switch (percent) {
  16359. case 'center':
  16360. case 'middle':
  16361. percent = '50%';
  16362. break;
  16363. case 'left':
  16364. case 'top':
  16365. percent = '0%';
  16366. break;
  16367. case 'right':
  16368. case 'bottom':
  16369. percent = '100%';
  16370. break;
  16371. }
  16372. if (typeof percent === 'string') {
  16373. if (_trim(percent).match(/%$/)) {
  16374. return parseFloat(percent) / 100 * all;
  16375. }
  16376. return parseFloat(percent);
  16377. }
  16378. return percent == null ? NaN : +percent;
  16379. }
  16380. /**
  16381. * (1) Fix rounding error of float numbers.
  16382. * (2) Support return string to avoid scientific notation like '3.5e-7'.
  16383. *
  16384. * @param {number} x
  16385. * @param {number} [precision]
  16386. * @param {boolean} [returnStr]
  16387. * @return {number|string}
  16388. */
  16389. function round$1(x, precision, returnStr) {
  16390. if (precision == null) {
  16391. precision = 10;
  16392. }
  16393. // Avoid range error
  16394. precision = Math.min(Math.max(0, precision), 20);
  16395. x = (+x).toFixed(precision);
  16396. return returnStr ? x : +x;
  16397. }
  16398. /**
  16399. * asc sort arr.
  16400. * The input arr will be modified.
  16401. *
  16402. * @param {Array} arr
  16403. * @return {Array} The input arr.
  16404. */
  16405. function asc(arr) {
  16406. arr.sort(function (a, b) {
  16407. return a - b;
  16408. });
  16409. return arr;
  16410. }
  16411. /**
  16412. * Get precision
  16413. * @param {number} val
  16414. */
  16415. function getPrecision(val) {
  16416. val = +val;
  16417. if (isNaN(val)) {
  16418. return 0;
  16419. }
  16420. // It is much faster than methods converting number to string as follows
  16421. // var tmp = val.toString();
  16422. // return tmp.length - 1 - tmp.indexOf('.');
  16423. // especially when precision is low
  16424. var e = 1;
  16425. var count = 0;
  16426. while (Math.round(val * e) / e !== val) {
  16427. e *= 10;
  16428. count++;
  16429. }
  16430. return count;
  16431. }
  16432. /**
  16433. * @param {string|number} val
  16434. * @return {number}
  16435. */
  16436. function getPrecisionSafe(val) {
  16437. var str = val.toString();
  16438. // Consider scientific notation: '3.4e-12' '3.4e+12'
  16439. var eIndex = str.indexOf('e');
  16440. if (eIndex > 0) {
  16441. var precision = +str.slice(eIndex + 1);
  16442. return precision < 0 ? -precision : 0;
  16443. }
  16444. else {
  16445. var dotIndex = str.indexOf('.');
  16446. return dotIndex < 0 ? 0 : str.length - 1 - dotIndex;
  16447. }
  16448. }
  16449. /**
  16450. * Minimal dicernible data precisioin according to a single pixel.
  16451. *
  16452. * @param {Array.<number>} dataExtent
  16453. * @param {Array.<number>} pixelExtent
  16454. * @return {number} precision
  16455. */
  16456. function getPixelPrecision(dataExtent, pixelExtent) {
  16457. var log = Math.log;
  16458. var LN10 = Math.LN10;
  16459. var dataQuantity = Math.floor(log(dataExtent[1] - dataExtent[0]) / LN10);
  16460. var sizeQuantity = Math.round(log(Math.abs(pixelExtent[1] - pixelExtent[0])) / LN10);
  16461. // toFixed() digits argument must be between 0 and 20.
  16462. var precision = Math.min(Math.max(-dataQuantity + sizeQuantity, 0), 20);
  16463. return !isFinite(precision) ? 20 : precision;
  16464. }
  16465. /**
  16466. * Get a data of given precision, assuring the sum of percentages
  16467. * in valueList is 1.
  16468. * The largest remainer method is used.
  16469. * https://en.wikipedia.org/wiki/Largest_remainder_method
  16470. *
  16471. * @param {Array.<number>} valueList a list of all data
  16472. * @param {number} idx index of the data to be processed in valueList
  16473. * @param {number} precision integer number showing digits of precision
  16474. * @return {number} percent ranging from 0 to 100
  16475. */
  16476. function getPercentWithPrecision(valueList, idx, precision) {
  16477. if (!valueList[idx]) {
  16478. return 0;
  16479. }
  16480. var sum = reduce(valueList, function (acc, val) {
  16481. return acc + (isNaN(val) ? 0 : val);
  16482. }, 0);
  16483. if (sum === 0) {
  16484. return 0;
  16485. }
  16486. var digits = Math.pow(10, precision);
  16487. var votesPerQuota = map(valueList, function (val) {
  16488. return (isNaN(val) ? 0 : val) / sum * digits * 100;
  16489. });
  16490. var targetSeats = digits * 100;
  16491. var seats = map(votesPerQuota, function (votes) {
  16492. // Assign automatic seats.
  16493. return Math.floor(votes);
  16494. });
  16495. var currentSum = reduce(seats, function (acc, val) {
  16496. return acc + val;
  16497. }, 0);
  16498. var remainder = map(votesPerQuota, function (votes, idx) {
  16499. return votes - seats[idx];
  16500. });
  16501. // Has remainding votes.
  16502. while (currentSum < targetSeats) {
  16503. // Find next largest remainder.
  16504. var max = Number.NEGATIVE_INFINITY;
  16505. var maxId = null;
  16506. for (var i = 0, len = remainder.length; i < len; ++i) {
  16507. if (remainder[i] > max) {
  16508. max = remainder[i];
  16509. maxId = i;
  16510. }
  16511. }
  16512. // Add a vote to max remainder.
  16513. ++seats[maxId];
  16514. remainder[maxId] = 0;
  16515. ++currentSum;
  16516. }
  16517. return seats[idx] / digits;
  16518. }
  16519. // Number.MAX_SAFE_INTEGER, ie do not support.
  16520. var MAX_SAFE_INTEGER = 9007199254740991;
  16521. /**
  16522. * To 0 - 2 * PI, considering negative radian.
  16523. * @param {number} radian
  16524. * @return {number}
  16525. */
  16526. function remRadian(radian) {
  16527. var pi2 = Math.PI * 2;
  16528. return (radian % pi2 + pi2) % pi2;
  16529. }
  16530. /**
  16531. * @param {type} radian
  16532. * @return {boolean}
  16533. */
  16534. function isRadianAroundZero(val) {
  16535. return val > -RADIAN_EPSILON && val < RADIAN_EPSILON;
  16536. }
  16537. /* eslint-disable */
  16538. 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
  16539. /* eslint-enable */
  16540. /**
  16541. * @param {string|Date|number} value These values can be accepted:
  16542. * + An instance of Date, represent a time in its own time zone.
  16543. * + Or string in a subset of ISO 8601, only including:
  16544. * + only year, month, date: '2012-03', '2012-03-01', '2012-03-01 05', '2012-03-01 05:06',
  16545. * + separated with T or space: '2012-03-01T12:22:33.123', '2012-03-01 12:22:33.123',
  16546. * + time zone: '2012-03-01T12:22:33Z', '2012-03-01T12:22:33+8000', '2012-03-01T12:22:33-05:00',
  16547. * all of which will be treated as local time if time zone is not specified
  16548. * (see <https://momentjs.com/>).
  16549. * + Or other string format, including (all of which will be treated as loacal time):
  16550. * '2012', '2012-3-1', '2012/3/1', '2012/03/01',
  16551. * '2009/6/12 2:00', '2009/6/12 2:05:08', '2009/6/12 2:05:08.123'
  16552. * + a timestamp, which represent a time in UTC.
  16553. * @return {Date} date
  16554. */
  16555. function parseDate(value) {
  16556. if (value instanceof Date) {
  16557. return value;
  16558. }
  16559. else if (typeof value === 'string') {
  16560. // Different browsers parse date in different way, so we parse it manually.
  16561. // Some other issues:
  16562. // new Date('1970-01-01') is UTC,
  16563. // new Date('1970/01/01') and new Date('1970-1-01') is local.
  16564. // See issue #3623
  16565. var match = TIME_REG.exec(value);
  16566. if (!match) {
  16567. // return Invalid Date.
  16568. return new Date(NaN);
  16569. }
  16570. // Use local time when no timezone offset specifed.
  16571. if (!match[8]) {
  16572. // match[n] can only be string or undefined.
  16573. // But take care of '12' + 1 => '121'.
  16574. return new Date(
  16575. +match[1],
  16576. +(match[2] || 1) - 1,
  16577. +match[3] || 1,
  16578. +match[4] || 0,
  16579. +(match[5] || 0),
  16580. +match[6] || 0,
  16581. +match[7] || 0
  16582. );
  16583. }
  16584. // Timezoneoffset of Javascript Date has considered DST (Daylight Saving Time,
  16585. // https://tc39.github.io/ecma262/#sec-daylight-saving-time-adjustment).
  16586. // For example, system timezone is set as "Time Zone: America/Toronto",
  16587. // then these code will get different result:
  16588. // `new Date(1478411999999).getTimezoneOffset(); // get 240`
  16589. // `new Date(1478412000000).getTimezoneOffset(); // get 300`
  16590. // So we should not use `new Date`, but use `Date.UTC`.
  16591. else {
  16592. var hour = +match[4] || 0;
  16593. if (match[8].toUpperCase() !== 'Z') {
  16594. hour -= match[8].slice(0, 3);
  16595. }
  16596. return new Date(Date.UTC(
  16597. +match[1],
  16598. +(match[2] || 1) - 1,
  16599. +match[3] || 1,
  16600. hour,
  16601. +(match[5] || 0),
  16602. +match[6] || 0,
  16603. +match[7] || 0
  16604. ));
  16605. }
  16606. }
  16607. else if (value == null) {
  16608. return new Date(NaN);
  16609. }
  16610. return new Date(Math.round(value));
  16611. }
  16612. /**
  16613. * Quantity of a number. e.g. 0.1, 1, 10, 100
  16614. *
  16615. * @param {number} val
  16616. * @return {number}
  16617. */
  16618. function quantity(val) {
  16619. return Math.pow(10, quantityExponent(val));
  16620. }
  16621. function quantityExponent(val) {
  16622. return Math.floor(Math.log(val) / Math.LN10);
  16623. }
  16624. /**
  16625. * find a “nice” number approximately equal to x. Round the number if round = true,
  16626. * take ceiling if round = false. The primary observation is that the “nicest”
  16627. * numbers in decimal are 1, 2, and 5, and all power-of-ten multiples of these numbers.
  16628. *
  16629. * See "Nice Numbers for Graph Labels" of Graphic Gems.
  16630. *
  16631. * @param {number} val Non-negative value.
  16632. * @param {boolean} round
  16633. * @return {number}
  16634. */
  16635. function nice(val, round) {
  16636. var exponent = quantityExponent(val);
  16637. var exp10 = Math.pow(10, exponent);
  16638. var f = val / exp10; // 1 <= f < 10
  16639. var nf;
  16640. if (round) {
  16641. if (f < 1.5) {
  16642. nf = 1;
  16643. }
  16644. else if (f < 2.5) {
  16645. nf = 2;
  16646. }
  16647. else if (f < 4) {
  16648. nf = 3;
  16649. }
  16650. else if (f < 7) {
  16651. nf = 5;
  16652. }
  16653. else {
  16654. nf = 10;
  16655. }
  16656. }
  16657. else {
  16658. if (f < 1) {
  16659. nf = 1;
  16660. }
  16661. else if (f < 2) {
  16662. nf = 2;
  16663. }
  16664. else if (f < 3) {
  16665. nf = 3;
  16666. }
  16667. else if (f < 5) {
  16668. nf = 5;
  16669. }
  16670. else {
  16671. nf = 10;
  16672. }
  16673. }
  16674. val = nf * exp10;
  16675. // Fix 3 * 0.1 === 0.30000000000000004 issue (see IEEE 754).
  16676. // 20 is the uppper bound of toFixed.
  16677. return exponent >= -20 ? +val.toFixed(exponent < 0 ? -exponent : 0) : val;
  16678. }
  16679. /**
  16680. * This code was copied from "d3.js"
  16681. * <https://github.com/d3/d3/blob/9cc9a875e636a1dcf36cc1e07bdf77e1ad6e2c74/src/arrays/quantile.js>.
  16682. * See the license statement at the head of this file.
  16683. * @param {Array.<number>} ascArr
  16684. */
  16685. function quantile(ascArr, p) {
  16686. var H = (ascArr.length - 1) * p + 1;
  16687. var h = Math.floor(H);
  16688. var v = +ascArr[h - 1];
  16689. var e = H - h;
  16690. return e ? v + e * (ascArr[h] - v) : v;
  16691. }
  16692. /**
  16693. * Order intervals asc, and split them when overlap.
  16694. * expect(numberUtil.reformIntervals([
  16695. * {interval: [18, 62], close: [1, 1]},
  16696. * {interval: [-Infinity, -70], close: [0, 0]},
  16697. * {interval: [-70, -26], close: [1, 1]},
  16698. * {interval: [-26, 18], close: [1, 1]},
  16699. * {interval: [62, 150], close: [1, 1]},
  16700. * {interval: [106, 150], close: [1, 1]},
  16701. * {interval: [150, Infinity], close: [0, 0]}
  16702. * ])).toEqual([
  16703. * {interval: [-Infinity, -70], close: [0, 0]},
  16704. * {interval: [-70, -26], close: [1, 1]},
  16705. * {interval: [-26, 18], close: [0, 1]},
  16706. * {interval: [18, 62], close: [0, 1]},
  16707. * {interval: [62, 150], close: [0, 1]},
  16708. * {interval: [150, Infinity], close: [0, 0]}
  16709. * ]);
  16710. * @param {Array.<Object>} list, where `close` mean open or close
  16711. * of the interval, and Infinity can be used.
  16712. * @return {Array.<Object>} The origin list, which has been reformed.
  16713. */
  16714. function reformIntervals(list) {
  16715. list.sort(function (a, b) {
  16716. return littleThan(a, b, 0) ? -1 : 1;
  16717. });
  16718. var curr = -Infinity;
  16719. var currClose = 1;
  16720. for (var i = 0; i < list.length;) {
  16721. var interval = list[i].interval;
  16722. var close = list[i].close;
  16723. for (var lg = 0; lg < 2; lg++) {
  16724. if (interval[lg] <= curr) {
  16725. interval[lg] = curr;
  16726. close[lg] = !lg ? 1 - currClose : 1;
  16727. }
  16728. curr = interval[lg];
  16729. currClose = close[lg];
  16730. }
  16731. if (interval[0] === interval[1] && close[0] * close[1] !== 1) {
  16732. list.splice(i, 1);
  16733. }
  16734. else {
  16735. i++;
  16736. }
  16737. }
  16738. return list;
  16739. function littleThan(a, b, lg) {
  16740. return a.interval[lg] < b.interval[lg]
  16741. || (
  16742. a.interval[lg] === b.interval[lg]
  16743. && (
  16744. (a.close[lg] - b.close[lg] === (!lg ? 1 : -1))
  16745. || (!lg && littleThan(a, b, 1))
  16746. )
  16747. );
  16748. }
  16749. }
  16750. /**
  16751. * parseFloat NaNs numeric-cast false positives (null|true|false|"")
  16752. * ...but misinterprets leading-number strings, particularly hex literals ("0x...")
  16753. * subtraction forces infinities to NaN
  16754. *
  16755. * @param {*} v
  16756. * @return {boolean}
  16757. */
  16758. function isNumeric(v) {
  16759. return v - parseFloat(v) >= 0;
  16760. }
  16761. var number = (Object.freeze || Object)({
  16762. linearMap: linearMap,
  16763. parsePercent: parsePercent$1,
  16764. round: round$1,
  16765. asc: asc,
  16766. getPrecision: getPrecision,
  16767. getPrecisionSafe: getPrecisionSafe,
  16768. getPixelPrecision: getPixelPrecision,
  16769. getPercentWithPrecision: getPercentWithPrecision,
  16770. MAX_SAFE_INTEGER: MAX_SAFE_INTEGER,
  16771. remRadian: remRadian,
  16772. isRadianAroundZero: isRadianAroundZero,
  16773. parseDate: parseDate,
  16774. quantity: quantity,
  16775. nice: nice,
  16776. quantile: quantile,
  16777. reformIntervals: reformIntervals,
  16778. isNumeric: isNumeric
  16779. });
  16780. /*
  16781. * Licensed to the Apache Software Foundation (ASF) under one
  16782. * or more contributor license agreements. See the NOTICE file
  16783. * distributed with this work for additional information
  16784. * regarding copyright ownership. The ASF licenses this file
  16785. * to you under the Apache License, Version 2.0 (the
  16786. * "License"); you may not use this file except in compliance
  16787. * with the License. You may obtain a copy of the License at
  16788. *
  16789. * http://www.apache.org/licenses/LICENSE-2.0
  16790. *
  16791. * Unless required by applicable law or agreed to in writing,
  16792. * software distributed under the License is distributed on an
  16793. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16794. * KIND, either express or implied. See the License for the
  16795. * specific language governing permissions and limitations
  16796. * under the License.
  16797. */
  16798. // import Text from 'zrender/src/graphic/Text';
  16799. /**
  16800. * 每三位默认加,格式化
  16801. * @param {string|number} x
  16802. * @return {string}
  16803. */
  16804. function addCommas(x) {
  16805. if (isNaN(x)) {
  16806. return '-';
  16807. }
  16808. x = (x + '').split('.');
  16809. return x[0].replace(/(\d{1,3})(?=(?:\d{3})+(?!\d))/g, '$1,')
  16810. + (x.length > 1 ? ('.' + x[1]) : '');
  16811. }
  16812. /**
  16813. * @param {string} str
  16814. * @param {boolean} [upperCaseFirst=false]
  16815. * @return {string} str
  16816. */
  16817. function toCamelCase(str, upperCaseFirst) {
  16818. str = (str || '').toLowerCase().replace(/-(.)/g, function (match, group1) {
  16819. return group1.toUpperCase();
  16820. });
  16821. if (upperCaseFirst && str) {
  16822. str = str.charAt(0).toUpperCase() + str.slice(1);
  16823. }
  16824. return str;
  16825. }
  16826. var normalizeCssArray$1 = normalizeCssArray;
  16827. var replaceReg = /([&<>"'])/g;
  16828. var replaceMap = {
  16829. '&': '&amp;',
  16830. '<': '&lt;',
  16831. '>': '&gt;',
  16832. '"': '&quot;',
  16833. '\'': '&#39;'
  16834. };
  16835. function encodeHTML(source) {
  16836. return source == null
  16837. ? ''
  16838. : (source + '').replace(replaceReg, function (str, c) {
  16839. return replaceMap[c];
  16840. });
  16841. }
  16842. var TPL_VAR_ALIAS = ['a', 'b', 'c', 'd', 'e', 'f', 'g'];
  16843. var wrapVar = function (varName, seriesIdx) {
  16844. return '{' + varName + (seriesIdx == null ? '' : seriesIdx) + '}';
  16845. };
  16846. /**
  16847. * Template formatter
  16848. * @param {string} tpl
  16849. * @param {Array.<Object>|Object} paramsList
  16850. * @param {boolean} [encode=false]
  16851. * @return {string}
  16852. */
  16853. function formatTpl(tpl, paramsList, encode) {
  16854. if (!isArray(paramsList)) {
  16855. paramsList = [paramsList];
  16856. }
  16857. var seriesLen = paramsList.length;
  16858. if (!seriesLen) {
  16859. return '';
  16860. }
  16861. var $vars = paramsList[0].$vars || [];
  16862. for (var i = 0; i < $vars.length; i++) {
  16863. var alias = TPL_VAR_ALIAS[i];
  16864. tpl = tpl.replace(wrapVar(alias), wrapVar(alias, 0));
  16865. }
  16866. for (var seriesIdx = 0; seriesIdx < seriesLen; seriesIdx++) {
  16867. for (var k = 0; k < $vars.length; k++) {
  16868. var val = paramsList[seriesIdx][$vars[k]];
  16869. tpl = tpl.replace(
  16870. wrapVar(TPL_VAR_ALIAS[k], seriesIdx),
  16871. encode ? encodeHTML(val) : val
  16872. );
  16873. }
  16874. }
  16875. return tpl;
  16876. }
  16877. /**
  16878. * simple Template formatter
  16879. *
  16880. * @param {string} tpl
  16881. * @param {Object} param
  16882. * @param {boolean} [encode=false]
  16883. * @return {string}
  16884. */
  16885. function formatTplSimple(tpl, param, encode) {
  16886. each$1(param, function (value, key) {
  16887. tpl = tpl.replace(
  16888. '{' + key + '}',
  16889. encode ? encodeHTML(value) : value
  16890. );
  16891. });
  16892. return tpl;
  16893. }
  16894. /**
  16895. * @param {Object|string} [opt] If string, means color.
  16896. * @param {string} [opt.color]
  16897. * @param {string} [opt.extraCssText]
  16898. * @param {string} [opt.type='item'] 'item' or 'subItem'
  16899. * @param {string} [opt.renderMode='html'] render mode of tooltip, 'html' or 'richText'
  16900. * @param {string} [opt.markerId='X'] id name for marker. If only one marker is in a rich text, this can be omitted.
  16901. * @return {string}
  16902. */
  16903. function getTooltipMarker(opt, extraCssText) {
  16904. opt = isString(opt) ? {color: opt, extraCssText: extraCssText} : (opt || {});
  16905. var color = opt.color;
  16906. var type = opt.type;
  16907. var extraCssText = opt.extraCssText;
  16908. var renderMode = opt.renderMode || 'html';
  16909. var markerId = opt.markerId || 'X';
  16910. if (!color) {
  16911. return '';
  16912. }
  16913. if (renderMode === 'html') {
  16914. return type === 'subItem'
  16915. ? '<span style="display:inline-block;vertical-align:middle;margin-right:8px;margin-left:3px;'
  16916. + 'border-radius:4px;width:4px;height:4px;background-color:'
  16917. + encodeHTML(color) + ';' + (extraCssText || '') + '"></span>'
  16918. : '<span style="display:inline-block;margin-right:5px;'
  16919. + 'border-radius:10px;width:10px;height:10px;background-color:'
  16920. + encodeHTML(color) + ';' + (extraCssText || '') + '"></span>';
  16921. }
  16922. else {
  16923. // Space for rich element marker
  16924. return {
  16925. renderMode: renderMode,
  16926. content: '{marker' + markerId + '|} ',
  16927. style: {
  16928. color: color
  16929. }
  16930. };
  16931. }
  16932. }
  16933. function pad(str, len) {
  16934. str += '';
  16935. return '0000'.substr(0, len - str.length) + str;
  16936. }
  16937. /**
  16938. * ISO Date format
  16939. * @param {string} tpl
  16940. * @param {number} value
  16941. * @param {boolean} [isUTC=false] Default in local time.
  16942. * see `module:echarts/scale/Time`
  16943. * and `module:echarts/util/number#parseDate`.
  16944. * @inner
  16945. */
  16946. function formatTime(tpl, value, isUTC) {
  16947. if (tpl === 'week'
  16948. || tpl === 'month'
  16949. || tpl === 'quarter'
  16950. || tpl === 'half-year'
  16951. || tpl === 'year'
  16952. ) {
  16953. tpl = 'MM-dd\nyyyy';
  16954. }
  16955. var date = parseDate(value);
  16956. var utc = isUTC ? 'UTC' : '';
  16957. var y = date['get' + utc + 'FullYear']();
  16958. var M = date['get' + utc + 'Month']() + 1;
  16959. var d = date['get' + utc + 'Date']();
  16960. var h = date['get' + utc + 'Hours']();
  16961. var m = date['get' + utc + 'Minutes']();
  16962. var s = date['get' + utc + 'Seconds']();
  16963. var S = date['get' + utc + 'Milliseconds']();
  16964. tpl = tpl.replace('MM', pad(M, 2))
  16965. .replace('M', M)
  16966. .replace('yyyy', y)
  16967. .replace('yy', y % 100)
  16968. .replace('dd', pad(d, 2))
  16969. .replace('d', d)
  16970. .replace('hh', pad(h, 2))
  16971. .replace('h', h)
  16972. .replace('mm', pad(m, 2))
  16973. .replace('m', m)
  16974. .replace('ss', pad(s, 2))
  16975. .replace('s', s)
  16976. .replace('SSS', pad(S, 3));
  16977. return tpl;
  16978. }
  16979. /**
  16980. * Capital first
  16981. * @param {string} str
  16982. * @return {string}
  16983. */
  16984. function capitalFirst(str) {
  16985. return str ? str.charAt(0).toUpperCase() + str.substr(1) : str;
  16986. }
  16987. var truncateText$1 = truncateText;
  16988. /**
  16989. * @public
  16990. * @param {Object} opt
  16991. * @param {string} opt.text
  16992. * @param {string} opt.font
  16993. * @param {string} [opt.textAlign='left']
  16994. * @param {string} [opt.textVerticalAlign='top']
  16995. * @param {Array.<number>} [opt.textPadding]
  16996. * @param {number} [opt.textLineHeight]
  16997. * @param {Object} [opt.rich]
  16998. * @param {Object} [opt.truncate]
  16999. * @return {Object} {x, y, width, height, lineHeight}
  17000. */
  17001. function getTextBoundingRect(opt) {
  17002. return getBoundingRect(
  17003. opt.text,
  17004. opt.font,
  17005. opt.textAlign,
  17006. opt.textVerticalAlign,
  17007. opt.textPadding,
  17008. opt.textLineHeight,
  17009. opt.rich,
  17010. opt.truncate
  17011. );
  17012. }
  17013. /**
  17014. * @deprecated
  17015. * the `textLineHeight` was added later.
  17016. * For backward compatiblility, put it as the last parameter.
  17017. * But deprecated this interface. Please use `getTextBoundingRect` instead.
  17018. */
  17019. function getTextRect(
  17020. text, font, textAlign, textVerticalAlign, textPadding, rich, truncate, textLineHeight
  17021. ) {
  17022. return getBoundingRect(
  17023. text, font, textAlign, textVerticalAlign, textPadding, textLineHeight, rich, truncate
  17024. );
  17025. }
  17026. var format = (Object.freeze || Object)({
  17027. addCommas: addCommas,
  17028. toCamelCase: toCamelCase,
  17029. normalizeCssArray: normalizeCssArray$1,
  17030. encodeHTML: encodeHTML,
  17031. formatTpl: formatTpl,
  17032. formatTplSimple: formatTplSimple,
  17033. getTooltipMarker: getTooltipMarker,
  17034. formatTime: formatTime,
  17035. capitalFirst: capitalFirst,
  17036. truncateText: truncateText$1,
  17037. getTextBoundingRect: getTextBoundingRect,
  17038. getTextRect: getTextRect
  17039. });
  17040. /*
  17041. * Licensed to the Apache Software Foundation (ASF) under one
  17042. * or more contributor license agreements. See the NOTICE file
  17043. * distributed with this work for additional information
  17044. * regarding copyright ownership. The ASF licenses this file
  17045. * to you under the Apache License, Version 2.0 (the
  17046. * "License"); you may not use this file except in compliance
  17047. * with the License. You may obtain a copy of the License at
  17048. *
  17049. * http://www.apache.org/licenses/LICENSE-2.0
  17050. *
  17051. * Unless required by applicable law or agreed to in writing,
  17052. * software distributed under the License is distributed on an
  17053. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  17054. * KIND, either express or implied. See the License for the
  17055. * specific language governing permissions and limitations
  17056. * under the License.
  17057. */
  17058. // Layout helpers for each component positioning
  17059. var each$3 = each$1;
  17060. /**
  17061. * @public
  17062. */
  17063. var LOCATION_PARAMS = [
  17064. 'left', 'right', 'top', 'bottom', 'width', 'height'
  17065. ];
  17066. /**
  17067. * @public
  17068. */
  17069. var HV_NAMES = [
  17070. ['width', 'left', 'right'],
  17071. ['height', 'top', 'bottom']
  17072. ];
  17073. function boxLayout(orient, group, gap, maxWidth, maxHeight) {
  17074. var x = 0;
  17075. var y = 0;
  17076. if (maxWidth == null) {
  17077. maxWidth = Infinity;
  17078. }
  17079. if (maxHeight == null) {
  17080. maxHeight = Infinity;
  17081. }
  17082. var currentLineMaxSize = 0;
  17083. group.eachChild(function (child, idx) {
  17084. var position = child.position;
  17085. var rect = child.getBoundingRect();
  17086. var nextChild = group.childAt(idx + 1);
  17087. var nextChildRect = nextChild && nextChild.getBoundingRect();
  17088. var nextX;
  17089. var nextY;
  17090. if (orient === 'horizontal') {
  17091. var moveX = rect.width + (nextChildRect ? (-nextChildRect.x + rect.x) : 0);
  17092. nextX = x + moveX;
  17093. // Wrap when width exceeds maxWidth or meet a `newline` group
  17094. // FIXME compare before adding gap?
  17095. if (nextX > maxWidth || child.newline) {
  17096. x = 0;
  17097. nextX = moveX;
  17098. y += currentLineMaxSize + gap;
  17099. currentLineMaxSize = rect.height;
  17100. }
  17101. else {
  17102. // FIXME: consider rect.y is not `0`?
  17103. currentLineMaxSize = Math.max(currentLineMaxSize, rect.height);
  17104. }
  17105. }
  17106. else {
  17107. var moveY = rect.height + (nextChildRect ? (-nextChildRect.y + rect.y) : 0);
  17108. nextY = y + moveY;
  17109. // Wrap when width exceeds maxHeight or meet a `newline` group
  17110. if (nextY > maxHeight || child.newline) {
  17111. x += currentLineMaxSize + gap;
  17112. y = 0;
  17113. nextY = moveY;
  17114. currentLineMaxSize = rect.width;
  17115. }
  17116. else {
  17117. currentLineMaxSize = Math.max(currentLineMaxSize, rect.width);
  17118. }
  17119. }
  17120. if (child.newline) {
  17121. return;
  17122. }
  17123. position[0] = x;
  17124. position[1] = y;
  17125. orient === 'horizontal'
  17126. ? (x = nextX + gap)
  17127. : (y = nextY + gap);
  17128. });
  17129. }
  17130. /**
  17131. * VBox or HBox layouting
  17132. * @param {string} orient
  17133. * @param {module:zrender/container/Group} group
  17134. * @param {number} gap
  17135. * @param {number} [width=Infinity]
  17136. * @param {number} [height=Infinity]
  17137. */
  17138. var box = boxLayout;
  17139. /**
  17140. * VBox layouting
  17141. * @param {module:zrender/container/Group} group
  17142. * @param {number} gap
  17143. * @param {number} [width=Infinity]
  17144. * @param {number} [height=Infinity]
  17145. */
  17146. var vbox = curry(boxLayout, 'vertical');
  17147. /**
  17148. * HBox layouting
  17149. * @param {module:zrender/container/Group} group
  17150. * @param {number} gap
  17151. * @param {number} [width=Infinity]
  17152. * @param {number} [height=Infinity]
  17153. */
  17154. var hbox = curry(boxLayout, 'horizontal');
  17155. /**
  17156. * If x or x2 is not specified or 'center' 'left' 'right',
  17157. * the width would be as long as possible.
  17158. * If y or y2 is not specified or 'middle' 'top' 'bottom',
  17159. * the height would be as long as possible.
  17160. *
  17161. * @param {Object} positionInfo
  17162. * @param {number|string} [positionInfo.x]
  17163. * @param {number|string} [positionInfo.y]
  17164. * @param {number|string} [positionInfo.x2]
  17165. * @param {number|string} [positionInfo.y2]
  17166. * @param {Object} containerRect {width, height}
  17167. * @param {string|number} margin
  17168. * @return {Object} {width, height}
  17169. */
  17170. function getAvailableSize(positionInfo, containerRect, margin) {
  17171. var containerWidth = containerRect.width;
  17172. var containerHeight = containerRect.height;
  17173. var x = parsePercent$1(positionInfo.x, containerWidth);
  17174. var y = parsePercent$1(positionInfo.y, containerHeight);
  17175. var x2 = parsePercent$1(positionInfo.x2, containerWidth);
  17176. var y2 = parsePercent$1(positionInfo.y2, containerHeight);
  17177. (isNaN(x) || isNaN(parseFloat(positionInfo.x))) && (x = 0);
  17178. (isNaN(x2) || isNaN(parseFloat(positionInfo.x2))) && (x2 = containerWidth);
  17179. (isNaN(y) || isNaN(parseFloat(positionInfo.y))) && (y = 0);
  17180. (isNaN(y2) || isNaN(parseFloat(positionInfo.y2))) && (y2 = containerHeight);
  17181. margin = normalizeCssArray$1(margin || 0);
  17182. return {
  17183. width: Math.max(x2 - x - margin[1] - margin[3], 0),
  17184. height: Math.max(y2 - y - margin[0] - margin[2], 0)
  17185. };
  17186. }
  17187. /**
  17188. * Parse position info.
  17189. *
  17190. * @param {Object} positionInfo
  17191. * @param {number|string} [positionInfo.left]
  17192. * @param {number|string} [positionInfo.top]
  17193. * @param {number|string} [positionInfo.right]
  17194. * @param {number|string} [positionInfo.bottom]
  17195. * @param {number|string} [positionInfo.width]
  17196. * @param {number|string} [positionInfo.height]
  17197. * @param {number|string} [positionInfo.aspect] Aspect is width / height
  17198. * @param {Object} containerRect
  17199. * @param {string|number} [margin]
  17200. *
  17201. * @return {module:zrender/core/BoundingRect}
  17202. */
  17203. function getLayoutRect(
  17204. positionInfo, containerRect, margin
  17205. ) {
  17206. margin = normalizeCssArray$1(margin || 0);
  17207. var containerWidth = containerRect.width;
  17208. var containerHeight = containerRect.height;
  17209. var left = parsePercent$1(positionInfo.left, containerWidth);
  17210. var top = parsePercent$1(positionInfo.top, containerHeight);
  17211. var right = parsePercent$1(positionInfo.right, containerWidth);
  17212. var bottom = parsePercent$1(positionInfo.bottom, containerHeight);
  17213. var width = parsePercent$1(positionInfo.width, containerWidth);
  17214. var height = parsePercent$1(positionInfo.height, containerHeight);
  17215. var verticalMargin = margin[2] + margin[0];
  17216. var horizontalMargin = margin[1] + margin[3];
  17217. var aspect = positionInfo.aspect;
  17218. // If width is not specified, calculate width from left and right
  17219. if (isNaN(width)) {
  17220. width = containerWidth - right - horizontalMargin - left;
  17221. }
  17222. if (isNaN(height)) {
  17223. height = containerHeight - bottom - verticalMargin - top;
  17224. }
  17225. if (aspect != null) {
  17226. // If width and height are not given
  17227. // 1. Graph should not exceeds the container
  17228. // 2. Aspect must be keeped
  17229. // 3. Graph should take the space as more as possible
  17230. // FIXME
  17231. // Margin is not considered, because there is no case that both
  17232. // using margin and aspect so far.
  17233. if (isNaN(width) && isNaN(height)) {
  17234. if (aspect > containerWidth / containerHeight) {
  17235. width = containerWidth * 0.8;
  17236. }
  17237. else {
  17238. height = containerHeight * 0.8;
  17239. }
  17240. }
  17241. // Calculate width or height with given aspect
  17242. if (isNaN(width)) {
  17243. width = aspect * height;
  17244. }
  17245. if (isNaN(height)) {
  17246. height = width / aspect;
  17247. }
  17248. }
  17249. // If left is not specified, calculate left from right and width
  17250. if (isNaN(left)) {
  17251. left = containerWidth - right - width - horizontalMargin;
  17252. }
  17253. if (isNaN(top)) {
  17254. top = containerHeight - bottom - height - verticalMargin;
  17255. }
  17256. // Align left and top
  17257. switch (positionInfo.left || positionInfo.right) {
  17258. case 'center':
  17259. left = containerWidth / 2 - width / 2 - margin[3];
  17260. break;
  17261. case 'right':
  17262. left = containerWidth - width - horizontalMargin;
  17263. break;
  17264. }
  17265. switch (positionInfo.top || positionInfo.bottom) {
  17266. case 'middle':
  17267. case 'center':
  17268. top = containerHeight / 2 - height / 2 - margin[0];
  17269. break;
  17270. case 'bottom':
  17271. top = containerHeight - height - verticalMargin;
  17272. break;
  17273. }
  17274. // If something is wrong and left, top, width, height are calculated as NaN
  17275. left = left || 0;
  17276. top = top || 0;
  17277. if (isNaN(width)) {
  17278. // Width may be NaN if only one value is given except width
  17279. width = containerWidth - horizontalMargin - left - (right || 0);
  17280. }
  17281. if (isNaN(height)) {
  17282. // Height may be NaN if only one value is given except height
  17283. height = containerHeight - verticalMargin - top - (bottom || 0);
  17284. }
  17285. var rect = new BoundingRect(left + margin[3], top + margin[0], width, height);
  17286. rect.margin = margin;
  17287. return rect;
  17288. }
  17289. /**
  17290. * Position a zr element in viewport
  17291. * Group position is specified by either
  17292. * {left, top}, {right, bottom}
  17293. * If all properties exists, right and bottom will be igonred.
  17294. *
  17295. * Logic:
  17296. * 1. Scale (against origin point in parent coord)
  17297. * 2. Rotate (against origin point in parent coord)
  17298. * 3. Traslate (with el.position by this method)
  17299. * So this method only fixes the last step 'Traslate', which does not affect
  17300. * scaling and rotating.
  17301. *
  17302. * If be called repeatly with the same input el, the same result will be gotten.
  17303. *
  17304. * @param {module:zrender/Element} el Should have `getBoundingRect` method.
  17305. * @param {Object} positionInfo
  17306. * @param {number|string} [positionInfo.left]
  17307. * @param {number|string} [positionInfo.top]
  17308. * @param {number|string} [positionInfo.right]
  17309. * @param {number|string} [positionInfo.bottom]
  17310. * @param {number|string} [positionInfo.width] Only for opt.boundingModel: 'raw'
  17311. * @param {number|string} [positionInfo.height] Only for opt.boundingModel: 'raw'
  17312. * @param {Object} containerRect
  17313. * @param {string|number} margin
  17314. * @param {Object} [opt]
  17315. * @param {Array.<number>} [opt.hv=[1,1]] Only horizontal or only vertical.
  17316. * @param {Array.<number>} [opt.boundingMode='all']
  17317. * Specify how to calculate boundingRect when locating.
  17318. * 'all': Position the boundingRect that is transformed and uioned
  17319. * both itself and its descendants.
  17320. * This mode simplies confine the elements in the bounding
  17321. * of their container (e.g., using 'right: 0').
  17322. * 'raw': Position the boundingRect that is not transformed and only itself.
  17323. * This mode is useful when you want a element can overflow its
  17324. * container. (Consider a rotated circle needs to be located in a corner.)
  17325. * In this mode positionInfo.width/height can only be number.
  17326. */
  17327. function positionElement(el, positionInfo, containerRect, margin, opt) {
  17328. var h = !opt || !opt.hv || opt.hv[0];
  17329. var v = !opt || !opt.hv || opt.hv[1];
  17330. var boundingMode = opt && opt.boundingMode || 'all';
  17331. if (!h && !v) {
  17332. return;
  17333. }
  17334. var rect;
  17335. if (boundingMode === 'raw') {
  17336. rect = el.type === 'group'
  17337. ? new BoundingRect(0, 0, +positionInfo.width || 0, +positionInfo.height || 0)
  17338. : el.getBoundingRect();
  17339. }
  17340. else {
  17341. rect = el.getBoundingRect();
  17342. if (el.needLocalTransform()) {
  17343. var transform = el.getLocalTransform();
  17344. // Notice: raw rect may be inner object of el,
  17345. // which should not be modified.
  17346. rect = rect.clone();
  17347. rect.applyTransform(transform);
  17348. }
  17349. }
  17350. // The real width and height can not be specified but calculated by the given el.
  17351. positionInfo = getLayoutRect(
  17352. defaults(
  17353. {width: rect.width, height: rect.height},
  17354. positionInfo
  17355. ),
  17356. containerRect,
  17357. margin
  17358. );
  17359. // Because 'tranlate' is the last step in transform
  17360. // (see zrender/core/Transformable#getLocalTransform),
  17361. // we can just only modify el.position to get final result.
  17362. var elPos = el.position;
  17363. var dx = h ? positionInfo.x - rect.x : 0;
  17364. var dy = v ? positionInfo.y - rect.y : 0;
  17365. el.attr('position', boundingMode === 'raw' ? [dx, dy] : [elPos[0] + dx, elPos[1] + dy]);
  17366. }
  17367. /**
  17368. * @param {Object} option Contains some of the properties in HV_NAMES.
  17369. * @param {number} hvIdx 0: horizontal; 1: vertical.
  17370. */
  17371. function sizeCalculable(option, hvIdx) {
  17372. return option[HV_NAMES[hvIdx][0]] != null
  17373. || (option[HV_NAMES[hvIdx][1]] != null && option[HV_NAMES[hvIdx][2]] != null);
  17374. }
  17375. /**
  17376. * Consider Case:
  17377. * When defulat option has {left: 0, width: 100}, and we set {right: 0}
  17378. * through setOption or media query, using normal zrUtil.merge will cause
  17379. * {right: 0} does not take effect.
  17380. *
  17381. * @example
  17382. * ComponentModel.extend({
  17383. * init: function () {
  17384. * ...
  17385. * var inputPositionParams = layout.getLayoutParams(option);
  17386. * this.mergeOption(inputPositionParams);
  17387. * },
  17388. * mergeOption: function (newOption) {
  17389. * newOption && zrUtil.merge(thisOption, newOption, true);
  17390. * layout.mergeLayoutParam(thisOption, newOption);
  17391. * }
  17392. * });
  17393. *
  17394. * @param {Object} targetOption
  17395. * @param {Object} newOption
  17396. * @param {Object|string} [opt]
  17397. * @param {boolean|Array.<boolean>} [opt.ignoreSize=false] Used for the components
  17398. * that width (or height) should not be calculated by left and right (or top and bottom).
  17399. */
  17400. function mergeLayoutParam(targetOption, newOption, opt) {
  17401. !isObject$1(opt) && (opt = {});
  17402. var ignoreSize = opt.ignoreSize;
  17403. !isArray(ignoreSize) && (ignoreSize = [ignoreSize, ignoreSize]);
  17404. var hResult = merge$$1(HV_NAMES[0], 0);
  17405. var vResult = merge$$1(HV_NAMES[1], 1);
  17406. copy(HV_NAMES[0], targetOption, hResult);
  17407. copy(HV_NAMES[1], targetOption, vResult);
  17408. function merge$$1(names, hvIdx) {
  17409. var newParams = {};
  17410. var newValueCount = 0;
  17411. var merged = {};
  17412. var mergedValueCount = 0;
  17413. var enoughParamNumber = 2;
  17414. each$3(names, function (name) {
  17415. merged[name] = targetOption[name];
  17416. });
  17417. each$3(names, function (name) {
  17418. // Consider case: newOption.width is null, which is
  17419. // set by user for removing width setting.
  17420. hasProp(newOption, name) && (newParams[name] = merged[name] = newOption[name]);
  17421. hasValue(newParams, name) && newValueCount++;
  17422. hasValue(merged, name) && mergedValueCount++;
  17423. });
  17424. if (ignoreSize[hvIdx]) {
  17425. // Only one of left/right is premitted to exist.
  17426. if (hasValue(newOption, names[1])) {
  17427. merged[names[2]] = null;
  17428. }
  17429. else if (hasValue(newOption, names[2])) {
  17430. merged[names[1]] = null;
  17431. }
  17432. return merged;
  17433. }
  17434. // Case: newOption: {width: ..., right: ...},
  17435. // or targetOption: {right: ...} and newOption: {width: ...},
  17436. // There is no conflict when merged only has params count
  17437. // little than enoughParamNumber.
  17438. if (mergedValueCount === enoughParamNumber || !newValueCount) {
  17439. return merged;
  17440. }
  17441. // Case: newOption: {width: ..., right: ...},
  17442. // Than we can make sure user only want those two, and ignore
  17443. // all origin params in targetOption.
  17444. else if (newValueCount >= enoughParamNumber) {
  17445. return newParams;
  17446. }
  17447. else {
  17448. // Chose another param from targetOption by priority.
  17449. for (var i = 0; i < names.length; i++) {
  17450. var name = names[i];
  17451. if (!hasProp(newParams, name) && hasProp(targetOption, name)) {
  17452. newParams[name] = targetOption[name];
  17453. break;
  17454. }
  17455. }
  17456. return newParams;
  17457. }
  17458. }
  17459. function hasProp(obj, name) {
  17460. return obj.hasOwnProperty(name);
  17461. }
  17462. function hasValue(obj, name) {
  17463. return obj[name] != null && obj[name] !== 'auto';
  17464. }
  17465. function copy(names, target, source) {
  17466. each$3(names, function (name) {
  17467. target[name] = source[name];
  17468. });
  17469. }
  17470. }
  17471. /**
  17472. * Retrieve 'left', 'right', 'top', 'bottom', 'width', 'height' from object.
  17473. * @param {Object} source
  17474. * @return {Object} Result contains those props.
  17475. */
  17476. function getLayoutParams(source) {
  17477. return copyLayoutParams({}, source);
  17478. }
  17479. /**
  17480. * Retrieve 'left', 'right', 'top', 'bottom', 'width', 'height' from object.
  17481. * @param {Object} source
  17482. * @return {Object} Result contains those props.
  17483. */
  17484. function copyLayoutParams(target, source) {
  17485. source && target && each$3(LOCATION_PARAMS, function (name) {
  17486. source.hasOwnProperty(name) && (target[name] = source[name]);
  17487. });
  17488. return target;
  17489. }
  17490. /*
  17491. * Licensed to the Apache Software Foundation (ASF) under one
  17492. * or more contributor license agreements. See the NOTICE file
  17493. * distributed with this work for additional information
  17494. * regarding copyright ownership. The ASF licenses this file
  17495. * to you under the Apache License, Version 2.0 (the
  17496. * "License"); you may not use this file except in compliance
  17497. * with the License. You may obtain a copy of the License at
  17498. *
  17499. * http://www.apache.org/licenses/LICENSE-2.0
  17500. *
  17501. * Unless required by applicable law or agreed to in writing,
  17502. * software distributed under the License is distributed on an
  17503. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  17504. * KIND, either express or implied. See the License for the
  17505. * specific language governing permissions and limitations
  17506. * under the License.
  17507. */
  17508. var boxLayoutMixin = {
  17509. getBoxLayoutParams: function () {
  17510. return {
  17511. left: this.get('left'),
  17512. top: this.get('top'),
  17513. right: this.get('right'),
  17514. bottom: this.get('bottom'),
  17515. width: this.get('width'),
  17516. height: this.get('height')
  17517. };
  17518. }
  17519. };
  17520. /*
  17521. * Licensed to the Apache Software Foundation (ASF) under one
  17522. * or more contributor license agreements. See the NOTICE file
  17523. * distributed with this work for additional information
  17524. * regarding copyright ownership. The ASF licenses this file
  17525. * to you under the Apache License, Version 2.0 (the
  17526. * "License"); you may not use this file except in compliance
  17527. * with the License. You may obtain a copy of the License at
  17528. *
  17529. * http://www.apache.org/licenses/LICENSE-2.0
  17530. *
  17531. * Unless required by applicable law or agreed to in writing,
  17532. * software distributed under the License is distributed on an
  17533. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  17534. * KIND, either express or implied. See the License for the
  17535. * specific language governing permissions and limitations
  17536. * under the License.
  17537. */
  17538. /**
  17539. * Component model
  17540. *
  17541. * @module echarts/model/Component
  17542. */
  17543. var inner$1 = makeInner();
  17544. /**
  17545. * @alias module:echarts/model/Component
  17546. * @constructor
  17547. * @param {Object} option
  17548. * @param {module:echarts/model/Model} parentModel
  17549. * @param {module:echarts/model/Model} ecModel
  17550. */
  17551. var ComponentModel = Model.extend({
  17552. type: 'component',
  17553. /**
  17554. * @readOnly
  17555. * @type {string}
  17556. */
  17557. id: '',
  17558. /**
  17559. * Because simplified concept is probably better, series.name (or component.name)
  17560. * has been having too many resposibilities:
  17561. * (1) Generating id (which requires name in option should not be modified).
  17562. * (2) As an index to mapping series when merging option or calling API (a name
  17563. * can refer to more then one components, which is convinient is some case).
  17564. * (3) Display.
  17565. * @readOnly
  17566. */
  17567. name: '',
  17568. /**
  17569. * @readOnly
  17570. * @type {string}
  17571. */
  17572. mainType: '',
  17573. /**
  17574. * @readOnly
  17575. * @type {string}
  17576. */
  17577. subType: '',
  17578. /**
  17579. * @readOnly
  17580. * @type {number}
  17581. */
  17582. componentIndex: 0,
  17583. /**
  17584. * @type {Object}
  17585. * @protected
  17586. */
  17587. defaultOption: null,
  17588. /**
  17589. * @type {module:echarts/model/Global}
  17590. * @readOnly
  17591. */
  17592. ecModel: null,
  17593. /**
  17594. * key: componentType
  17595. * value: Component model list, can not be null.
  17596. * @type {Object.<string, Array.<module:echarts/model/Model>>}
  17597. * @readOnly
  17598. */
  17599. dependentModels: [],
  17600. /**
  17601. * @type {string}
  17602. * @readOnly
  17603. */
  17604. uid: null,
  17605. /**
  17606. * Support merge layout params.
  17607. * Only support 'box' now (left/right/top/bottom/width/height).
  17608. * @type {string|Object} Object can be {ignoreSize: true}
  17609. * @readOnly
  17610. */
  17611. layoutMode: null,
  17612. $constructor: function (option, parentModel, ecModel, extraOpt) {
  17613. Model.call(this, option, parentModel, ecModel, extraOpt);
  17614. this.uid = getUID('ec_cpt_model');
  17615. },
  17616. init: function (option, parentModel, ecModel, extraOpt) {
  17617. this.mergeDefaultAndTheme(option, ecModel);
  17618. },
  17619. mergeDefaultAndTheme: function (option, ecModel) {
  17620. var layoutMode = this.layoutMode;
  17621. var inputPositionParams = layoutMode
  17622. ? getLayoutParams(option) : {};
  17623. var themeModel = ecModel.getTheme();
  17624. merge(option, themeModel.get(this.mainType));
  17625. merge(option, this.getDefaultOption());
  17626. if (layoutMode) {
  17627. mergeLayoutParam(option, inputPositionParams, layoutMode);
  17628. }
  17629. },
  17630. mergeOption: function (option, extraOpt) {
  17631. merge(this.option, option, true);
  17632. var layoutMode = this.layoutMode;
  17633. if (layoutMode) {
  17634. mergeLayoutParam(this.option, option, layoutMode);
  17635. }
  17636. },
  17637. // Hooker after init or mergeOption
  17638. optionUpdated: function (newCptOption, isInit) {},
  17639. getDefaultOption: function () {
  17640. var fields = inner$1(this);
  17641. if (!fields.defaultOption) {
  17642. var optList = [];
  17643. var Class = this.constructor;
  17644. while (Class) {
  17645. var opt = Class.prototype.defaultOption;
  17646. opt && optList.push(opt);
  17647. Class = Class.superClass;
  17648. }
  17649. var defaultOption = {};
  17650. for (var i = optList.length - 1; i >= 0; i--) {
  17651. defaultOption = merge(defaultOption, optList[i], true);
  17652. }
  17653. fields.defaultOption = defaultOption;
  17654. }
  17655. return fields.defaultOption;
  17656. },
  17657. getReferringComponents: function (mainType) {
  17658. return this.ecModel.queryComponents({
  17659. mainType: mainType,
  17660. index: this.get(mainType + 'Index', true),
  17661. id: this.get(mainType + 'Id', true)
  17662. });
  17663. }
  17664. });
  17665. // Reset ComponentModel.extend, add preConstruct.
  17666. // clazzUtil.enableClassExtend(
  17667. // ComponentModel,
  17668. // function (option, parentModel, ecModel, extraOpt) {
  17669. // // Set dependentModels, componentIndex, name, id, mainType, subType.
  17670. // zrUtil.extend(this, extraOpt);
  17671. // this.uid = componentUtil.getUID('componentModel');
  17672. // // this.setReadOnly([
  17673. // // 'type', 'id', 'uid', 'name', 'mainType', 'subType',
  17674. // // 'dependentModels', 'componentIndex'
  17675. // // ]);
  17676. // }
  17677. // );
  17678. // Add capability of registerClass, getClass, hasClass, registerSubTypeDefaulter and so on.
  17679. enableClassManagement(
  17680. ComponentModel, {registerWhenExtend: true}
  17681. );
  17682. enableSubTypeDefaulter(ComponentModel);
  17683. // Add capability of ComponentModel.topologicalTravel.
  17684. enableTopologicalTravel(ComponentModel, getDependencies);
  17685. function getDependencies(componentType) {
  17686. var deps = [];
  17687. each$1(ComponentModel.getClassesByMainType(componentType), function (Clazz) {
  17688. deps = deps.concat(Clazz.prototype.dependencies || []);
  17689. });
  17690. // Ensure main type.
  17691. deps = map(deps, function (type) {
  17692. return parseClassType$1(type).main;
  17693. });
  17694. // Hack dataset for convenience.
  17695. if (componentType !== 'dataset' && indexOf(deps, 'dataset') <= 0) {
  17696. deps.unshift('dataset');
  17697. }
  17698. return deps;
  17699. }
  17700. mixin(ComponentModel, boxLayoutMixin);
  17701. /*
  17702. * Licensed to the Apache Software Foundation (ASF) under one
  17703. * or more contributor license agreements. See the NOTICE file
  17704. * distributed with this work for additional information
  17705. * regarding copyright ownership. The ASF licenses this file
  17706. * to you under the Apache License, Version 2.0 (the
  17707. * "License"); you may not use this file except in compliance
  17708. * with the License. You may obtain a copy of the License at
  17709. *
  17710. * http://www.apache.org/licenses/LICENSE-2.0
  17711. *
  17712. * Unless required by applicable law or agreed to in writing,
  17713. * software distributed under the License is distributed on an
  17714. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  17715. * KIND, either express or implied. See the License for the
  17716. * specific language governing permissions and limitations
  17717. * under the License.
  17718. */
  17719. var platform = '';
  17720. // Navigator not exists in node
  17721. if (typeof navigator !== 'undefined') {
  17722. platform = navigator.platform || '';
  17723. }
  17724. var globalDefault = {
  17725. // backgroundColor: 'rgba(0,0,0,0)',
  17726. // https://dribbble.com/shots/1065960-Infographic-Pie-chart-visualization
  17727. // color: ['#5793f3', '#d14a61', '#fd9c35', '#675bba', '#fec42c', '#dd4444', '#d4df5a', '#cd4870'],
  17728. // Light colors:
  17729. // color: ['#bcd3bb', '#e88f70', '#edc1a5', '#9dc5c8', '#e1e8c8', '#7b7c68', '#e5b5b5', '#f0b489', '#928ea8', '#bda29a'],
  17730. // color: ['#cc5664', '#9bd6ec', '#ea946e', '#8acaaa', '#f1ec64', '#ee8686', '#a48dc1', '#5da6bc', '#b9dcae'],
  17731. // Dark colors:
  17732. color: [
  17733. '#c23531', '#2f4554', '#61a0a8', '#d48265', '#91c7ae', '#749f83',
  17734. '#ca8622', '#bda29a', '#6e7074', '#546570', '#c4ccd3'
  17735. ],
  17736. gradientColor: ['#f6efa6', '#d88273', '#bf444c'],
  17737. // If xAxis and yAxis declared, grid is created by default.
  17738. // grid: {},
  17739. textStyle: {
  17740. // color: '#000',
  17741. // decoration: 'none',
  17742. // PENDING
  17743. fontFamily: platform.match(/^Win/) ? 'Microsoft YaHei' : 'sans-serif',
  17744. // fontFamily: 'Arial, Verdana, sans-serif',
  17745. fontSize: 12,
  17746. fontStyle: 'normal',
  17747. fontWeight: 'normal'
  17748. },
  17749. // http://blogs.adobe.com/webplatform/2014/02/24/using-blend-modes-in-html-canvas/
  17750. // https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/globalCompositeOperation
  17751. // Default is source-over
  17752. blendMode: null,
  17753. animation: 'auto',
  17754. animationDuration: 1000,
  17755. animationDurationUpdate: 300,
  17756. animationEasing: 'exponentialOut',
  17757. animationEasingUpdate: 'cubicOut',
  17758. animationThreshold: 2000,
  17759. // Configuration for progressive/incremental rendering
  17760. progressiveThreshold: 3000,
  17761. progressive: 400,
  17762. // Threshold of if use single hover layer to optimize.
  17763. // It is recommended that `hoverLayerThreshold` is equivalent to or less than
  17764. // `progressiveThreshold`, otherwise hover will cause restart of progressive,
  17765. // which is unexpected.
  17766. // see example <echarts/test/heatmap-large.html>.
  17767. hoverLayerThreshold: 3000,
  17768. // See: module:echarts/scale/Time
  17769. useUTC: false
  17770. };
  17771. /*
  17772. * Licensed to the Apache Software Foundation (ASF) under one
  17773. * or more contributor license agreements. See the NOTICE file
  17774. * distributed with this work for additional information
  17775. * regarding copyright ownership. The ASF licenses this file
  17776. * to you under the Apache License, Version 2.0 (the
  17777. * "License"); you may not use this file except in compliance
  17778. * with the License. You may obtain a copy of the License at
  17779. *
  17780. * http://www.apache.org/licenses/LICENSE-2.0
  17781. *
  17782. * Unless required by applicable law or agreed to in writing,
  17783. * software distributed under the License is distributed on an
  17784. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  17785. * KIND, either express or implied. See the License for the
  17786. * specific language governing permissions and limitations
  17787. * under the License.
  17788. */
  17789. var inner$2 = makeInner();
  17790. function getNearestColorPalette(colors, requestColorNum) {
  17791. var paletteNum = colors.length;
  17792. // TODO colors must be in order
  17793. for (var i = 0; i < paletteNum; i++) {
  17794. if (colors[i].length > requestColorNum) {
  17795. return colors[i];
  17796. }
  17797. }
  17798. return colors[paletteNum - 1];
  17799. }
  17800. var colorPaletteMixin = {
  17801. clearColorPalette: function () {
  17802. inner$2(this).colorIdx = 0;
  17803. inner$2(this).colorNameMap = {};
  17804. },
  17805. /**
  17806. * @param {string} name MUST NOT be null/undefined. Otherwise call this function
  17807. * twise with the same parameters will get different result.
  17808. * @param {Object} [scope=this]
  17809. * @param {Object} [requestColorNum]
  17810. * @return {string} color string.
  17811. */
  17812. getColorFromPalette: function (name, scope, requestColorNum) {
  17813. scope = scope || this;
  17814. var scopeFields = inner$2(scope);
  17815. var colorIdx = scopeFields.colorIdx || 0;
  17816. var colorNameMap = scopeFields.colorNameMap = scopeFields.colorNameMap || {};
  17817. // Use `hasOwnProperty` to avoid conflict with Object.prototype.
  17818. if (colorNameMap.hasOwnProperty(name)) {
  17819. return colorNameMap[name];
  17820. }
  17821. var defaultColorPalette = normalizeToArray(this.get('color', true));
  17822. var layeredColorPalette = this.get('colorLayer', true);
  17823. var colorPalette = ((requestColorNum == null || !layeredColorPalette)
  17824. ? defaultColorPalette : getNearestColorPalette(layeredColorPalette, requestColorNum));
  17825. // In case can't find in layered color palette.
  17826. colorPalette = colorPalette || defaultColorPalette;
  17827. if (!colorPalette || !colorPalette.length) {
  17828. return;
  17829. }
  17830. var color = colorPalette[colorIdx];
  17831. if (name) {
  17832. colorNameMap[name] = color;
  17833. }
  17834. scopeFields.colorIdx = (colorIdx + 1) % colorPalette.length;
  17835. return color;
  17836. }
  17837. };
  17838. /*
  17839. * Licensed to the Apache Software Foundation (ASF) under one
  17840. * or more contributor license agreements. See the NOTICE file
  17841. * distributed with this work for additional information
  17842. * regarding copyright ownership. The ASF licenses this file
  17843. * to you under the Apache License, Version 2.0 (the
  17844. * "License"); you may not use this file except in compliance
  17845. * with the License. You may obtain a copy of the License at
  17846. *
  17847. * http://www.apache.org/licenses/LICENSE-2.0
  17848. *
  17849. * Unless required by applicable law or agreed to in writing,
  17850. * software distributed under the License is distributed on an
  17851. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  17852. * KIND, either express or implied. See the License for the
  17853. * specific language governing permissions and limitations
  17854. * under the License.
  17855. */
  17856. /**
  17857. * Helper for model references.
  17858. * There are many manners to refer axis/coordSys.
  17859. */
  17860. // TODO
  17861. // merge relevant logic to this file?
  17862. // check: "modelHelper" of tooltip and "BrushTargetManager".
  17863. /**
  17864. * @return {Object} For example:
  17865. * {
  17866. * coordSysName: 'cartesian2d',
  17867. * coordSysDims: ['x', 'y', ...],
  17868. * axisMap: HashMap({
  17869. * x: xAxisModel,
  17870. * y: yAxisModel
  17871. * }),
  17872. * categoryAxisMap: HashMap({
  17873. * x: xAxisModel,
  17874. * y: undefined
  17875. * }),
  17876. * // It also indicate that whether there is category axis.
  17877. * firstCategoryDimIndex: 1,
  17878. * // To replace user specified encode.
  17879. * }
  17880. */
  17881. function getCoordSysDefineBySeries(seriesModel) {
  17882. var coordSysName = seriesModel.get('coordinateSystem');
  17883. var result = {
  17884. coordSysName: coordSysName,
  17885. coordSysDims: [],
  17886. axisMap: createHashMap(),
  17887. categoryAxisMap: createHashMap()
  17888. };
  17889. var fetch = fetchers[coordSysName];
  17890. if (fetch) {
  17891. fetch(seriesModel, result, result.axisMap, result.categoryAxisMap);
  17892. return result;
  17893. }
  17894. }
  17895. var fetchers = {
  17896. cartesian2d: function (seriesModel, result, axisMap, categoryAxisMap) {
  17897. var xAxisModel = seriesModel.getReferringComponents('xAxis')[0];
  17898. var yAxisModel = seriesModel.getReferringComponents('yAxis')[0];
  17899. if (__DEV__) {
  17900. if (!xAxisModel) {
  17901. throw new Error('xAxis "' + retrieve(
  17902. seriesModel.get('xAxisIndex'),
  17903. seriesModel.get('xAxisId'),
  17904. 0
  17905. ) + '" not found');
  17906. }
  17907. if (!yAxisModel) {
  17908. throw new Error('yAxis "' + retrieve(
  17909. seriesModel.get('xAxisIndex'),
  17910. seriesModel.get('yAxisId'),
  17911. 0
  17912. ) + '" not found');
  17913. }
  17914. }
  17915. result.coordSysDims = ['x', 'y'];
  17916. axisMap.set('x', xAxisModel);
  17917. axisMap.set('y', yAxisModel);
  17918. if (isCategory(xAxisModel)) {
  17919. categoryAxisMap.set('x', xAxisModel);
  17920. result.firstCategoryDimIndex = 0;
  17921. }
  17922. if (isCategory(yAxisModel)) {
  17923. categoryAxisMap.set('y', yAxisModel);
  17924. result.firstCategoryDimIndex = 1;
  17925. }
  17926. },
  17927. singleAxis: function (seriesModel, result, axisMap, categoryAxisMap) {
  17928. var singleAxisModel = seriesModel.getReferringComponents('singleAxis')[0];
  17929. if (__DEV__) {
  17930. if (!singleAxisModel) {
  17931. throw new Error('singleAxis should be specified.');
  17932. }
  17933. }
  17934. result.coordSysDims = ['single'];
  17935. axisMap.set('single', singleAxisModel);
  17936. if (isCategory(singleAxisModel)) {
  17937. categoryAxisMap.set('single', singleAxisModel);
  17938. result.firstCategoryDimIndex = 0;
  17939. }
  17940. },
  17941. polar: function (seriesModel, result, axisMap, categoryAxisMap) {
  17942. var polarModel = seriesModel.getReferringComponents('polar')[0];
  17943. var radiusAxisModel = polarModel.findAxisModel('radiusAxis');
  17944. var angleAxisModel = polarModel.findAxisModel('angleAxis');
  17945. if (__DEV__) {
  17946. if (!angleAxisModel) {
  17947. throw new Error('angleAxis option not found');
  17948. }
  17949. if (!radiusAxisModel) {
  17950. throw new Error('radiusAxis option not found');
  17951. }
  17952. }
  17953. result.coordSysDims = ['radius', 'angle'];
  17954. axisMap.set('radius', radiusAxisModel);
  17955. axisMap.set('angle', angleAxisModel);
  17956. if (isCategory(radiusAxisModel)) {
  17957. categoryAxisMap.set('radius', radiusAxisModel);
  17958. result.firstCategoryDimIndex = 0;
  17959. }
  17960. if (isCategory(angleAxisModel)) {
  17961. categoryAxisMap.set('angle', angleAxisModel);
  17962. result.firstCategoryDimIndex = 1;
  17963. }
  17964. },
  17965. geo: function (seriesModel, result, axisMap, categoryAxisMap) {
  17966. result.coordSysDims = ['lng', 'lat'];
  17967. },
  17968. parallel: function (seriesModel, result, axisMap, categoryAxisMap) {
  17969. var ecModel = seriesModel.ecModel;
  17970. var parallelModel = ecModel.getComponent(
  17971. 'parallel', seriesModel.get('parallelIndex')
  17972. );
  17973. var coordSysDims = result.coordSysDims = parallelModel.dimensions.slice();
  17974. each$1(parallelModel.parallelAxisIndex, function (axisIndex, index) {
  17975. var axisModel = ecModel.getComponent('parallelAxis', axisIndex);
  17976. var axisDim = coordSysDims[index];
  17977. axisMap.set(axisDim, axisModel);
  17978. if (isCategory(axisModel) && result.firstCategoryDimIndex == null) {
  17979. categoryAxisMap.set(axisDim, axisModel);
  17980. result.firstCategoryDimIndex = index;
  17981. }
  17982. });
  17983. }
  17984. };
  17985. function isCategory(axisModel) {
  17986. return axisModel.get('type') === 'category';
  17987. }
  17988. /*
  17989. * Licensed to the Apache Software Foundation (ASF) under one
  17990. * or more contributor license agreements. See the NOTICE file
  17991. * distributed with this work for additional information
  17992. * regarding copyright ownership. The ASF licenses this file
  17993. * to you under the Apache License, Version 2.0 (the
  17994. * "License"); you may not use this file except in compliance
  17995. * with the License. You may obtain a copy of the License at
  17996. *
  17997. * http://www.apache.org/licenses/LICENSE-2.0
  17998. *
  17999. * Unless required by applicable law or agreed to in writing,
  18000. * software distributed under the License is distributed on an
  18001. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  18002. * KIND, either express or implied. See the License for the
  18003. * specific language governing permissions and limitations
  18004. * under the License.
  18005. */
  18006. // Avoid typo.
  18007. var SOURCE_FORMAT_ORIGINAL = 'original';
  18008. var SOURCE_FORMAT_ARRAY_ROWS = 'arrayRows';
  18009. var SOURCE_FORMAT_OBJECT_ROWS = 'objectRows';
  18010. var SOURCE_FORMAT_KEYED_COLUMNS = 'keyedColumns';
  18011. var SOURCE_FORMAT_UNKNOWN = 'unknown';
  18012. // ??? CHANGE A NAME
  18013. var SOURCE_FORMAT_TYPED_ARRAY = 'typedArray';
  18014. var SERIES_LAYOUT_BY_COLUMN = 'column';
  18015. var SERIES_LAYOUT_BY_ROW = 'row';
  18016. /*
  18017. * Licensed to the Apache Software Foundation (ASF) under one
  18018. * or more contributor license agreements. See the NOTICE file
  18019. * distributed with this work for additional information
  18020. * regarding copyright ownership. The ASF licenses this file
  18021. * to you under the Apache License, Version 2.0 (the
  18022. * "License"); you may not use this file except in compliance
  18023. * with the License. You may obtain a copy of the License at
  18024. *
  18025. * http://www.apache.org/licenses/LICENSE-2.0
  18026. *
  18027. * Unless required by applicable law or agreed to in writing,
  18028. * software distributed under the License is distributed on an
  18029. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  18030. * KIND, either express or implied. See the License for the
  18031. * specific language governing permissions and limitations
  18032. * under the License.
  18033. */
  18034. /**
  18035. * [sourceFormat]
  18036. *
  18037. * + "original":
  18038. * This format is only used in series.data, where
  18039. * itemStyle can be specified in data item.
  18040. *
  18041. * + "arrayRows":
  18042. * [
  18043. * ['product', 'score', 'amount'],
  18044. * ['Matcha Latte', 89.3, 95.8],
  18045. * ['Milk Tea', 92.1, 89.4],
  18046. * ['Cheese Cocoa', 94.4, 91.2],
  18047. * ['Walnut Brownie', 85.4, 76.9]
  18048. * ]
  18049. *
  18050. * + "objectRows":
  18051. * [
  18052. * {product: 'Matcha Latte', score: 89.3, amount: 95.8},
  18053. * {product: 'Milk Tea', score: 92.1, amount: 89.4},
  18054. * {product: 'Cheese Cocoa', score: 94.4, amount: 91.2},
  18055. * {product: 'Walnut Brownie', score: 85.4, amount: 76.9}
  18056. * ]
  18057. *
  18058. * + "keyedColumns":
  18059. * {
  18060. * 'product': ['Matcha Latte', 'Milk Tea', 'Cheese Cocoa', 'Walnut Brownie'],
  18061. * 'count': [823, 235, 1042, 988],
  18062. * 'score': [95.8, 81.4, 91.2, 76.9]
  18063. * }
  18064. *
  18065. * + "typedArray"
  18066. *
  18067. * + "unknown"
  18068. */
  18069. /**
  18070. * @constructor
  18071. * @param {Object} fields
  18072. * @param {string} fields.sourceFormat
  18073. * @param {Array|Object} fields.fromDataset
  18074. * @param {Array|Object} [fields.data]
  18075. * @param {string} [seriesLayoutBy='column']
  18076. * @param {Array.<Object|string>} [dimensionsDefine]
  18077. * @param {Objet|HashMap} [encodeDefine]
  18078. * @param {number} [startIndex=0]
  18079. * @param {number} [dimensionsDetectCount]
  18080. */
  18081. function Source(fields) {
  18082. /**
  18083. * @type {boolean}
  18084. */
  18085. this.fromDataset = fields.fromDataset;
  18086. /**
  18087. * Not null/undefined.
  18088. * @type {Array|Object}
  18089. */
  18090. this.data = fields.data || (
  18091. fields.sourceFormat === SOURCE_FORMAT_KEYED_COLUMNS ? {} : []
  18092. );
  18093. /**
  18094. * See also "detectSourceFormat".
  18095. * Not null/undefined.
  18096. * @type {string}
  18097. */
  18098. this.sourceFormat = fields.sourceFormat || SOURCE_FORMAT_UNKNOWN;
  18099. /**
  18100. * 'row' or 'column'
  18101. * Not null/undefined.
  18102. * @type {string} seriesLayoutBy
  18103. */
  18104. this.seriesLayoutBy = fields.seriesLayoutBy || SERIES_LAYOUT_BY_COLUMN;
  18105. /**
  18106. * dimensions definition in option.
  18107. * can be null/undefined.
  18108. * @type {Array.<Object|string>}
  18109. */
  18110. this.dimensionsDefine = fields.dimensionsDefine;
  18111. /**
  18112. * encode definition in option.
  18113. * can be null/undefined.
  18114. * @type {Objet|HashMap}
  18115. */
  18116. this.encodeDefine = fields.encodeDefine && createHashMap(fields.encodeDefine);
  18117. /**
  18118. * Not null/undefined, uint.
  18119. * @type {number}
  18120. */
  18121. this.startIndex = fields.startIndex || 0;
  18122. /**
  18123. * Can be null/undefined (when unknown), uint.
  18124. * @type {number}
  18125. */
  18126. this.dimensionsDetectCount = fields.dimensionsDetectCount;
  18127. }
  18128. /**
  18129. * Wrap original series data for some compatibility cases.
  18130. */
  18131. Source.seriesDataToSource = function (data) {
  18132. return new Source({
  18133. data: data,
  18134. sourceFormat: isTypedArray(data)
  18135. ? SOURCE_FORMAT_TYPED_ARRAY
  18136. : SOURCE_FORMAT_ORIGINAL,
  18137. fromDataset: false
  18138. });
  18139. };
  18140. enableClassCheck(Source);
  18141. /*
  18142. * Licensed to the Apache Software Foundation (ASF) under one
  18143. * or more contributor license agreements. See the NOTICE file
  18144. * distributed with this work for additional information
  18145. * regarding copyright ownership. The ASF licenses this file
  18146. * to you under the Apache License, Version 2.0 (the
  18147. * "License"); you may not use this file except in compliance
  18148. * with the License. You may obtain a copy of the License at
  18149. *
  18150. * http://www.apache.org/licenses/LICENSE-2.0
  18151. *
  18152. * Unless required by applicable law or agreed to in writing,
  18153. * software distributed under the License is distributed on an
  18154. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  18155. * KIND, either express or implied. See the License for the
  18156. * specific language governing permissions and limitations
  18157. * under the License.
  18158. */
  18159. var inner$3 = makeInner();
  18160. /**
  18161. * @see {module:echarts/data/Source}
  18162. * @param {module:echarts/component/dataset/DatasetModel} datasetModel
  18163. * @return {string} sourceFormat
  18164. */
  18165. function detectSourceFormat(datasetModel) {
  18166. var data = datasetModel.option.source;
  18167. var sourceFormat = SOURCE_FORMAT_UNKNOWN;
  18168. if (isTypedArray(data)) {
  18169. sourceFormat = SOURCE_FORMAT_TYPED_ARRAY;
  18170. }
  18171. else if (isArray(data)) {
  18172. // FIXME Whether tolerate null in top level array?
  18173. if (data.length === 0) {
  18174. sourceFormat = SOURCE_FORMAT_ARRAY_ROWS;
  18175. }
  18176. for (var i = 0, len = data.length; i < len; i++) {
  18177. var item = data[i];
  18178. if (item == null) {
  18179. continue;
  18180. }
  18181. else if (isArray(item)) {
  18182. sourceFormat = SOURCE_FORMAT_ARRAY_ROWS;
  18183. break;
  18184. }
  18185. else if (isObject$1(item)) {
  18186. sourceFormat = SOURCE_FORMAT_OBJECT_ROWS;
  18187. break;
  18188. }
  18189. }
  18190. }
  18191. else if (isObject$1(data)) {
  18192. for (var key in data) {
  18193. if (data.hasOwnProperty(key) && isArrayLike(data[key])) {
  18194. sourceFormat = SOURCE_FORMAT_KEYED_COLUMNS;
  18195. break;
  18196. }
  18197. }
  18198. }
  18199. else if (data != null) {
  18200. throw new Error('Invalid data');
  18201. }
  18202. inner$3(datasetModel).sourceFormat = sourceFormat;
  18203. }
  18204. /**
  18205. * [Scenarios]:
  18206. * (1) Provide source data directly:
  18207. * series: {
  18208. * encode: {...},
  18209. * dimensions: [...]
  18210. * seriesLayoutBy: 'row',
  18211. * data: [[...]]
  18212. * }
  18213. * (2) Refer to datasetModel.
  18214. * series: [{
  18215. * encode: {...}
  18216. * // Ignore datasetIndex means `datasetIndex: 0`
  18217. * // and the dimensions defination in dataset is used
  18218. * }, {
  18219. * encode: {...},
  18220. * seriesLayoutBy: 'column',
  18221. * datasetIndex: 1
  18222. * }]
  18223. *
  18224. * Get data from series itself or datset.
  18225. * @return {module:echarts/data/Source} source
  18226. */
  18227. function getSource(seriesModel) {
  18228. return inner$3(seriesModel).source;
  18229. }
  18230. /**
  18231. * MUST be called before mergeOption of all series.
  18232. * @param {module:echarts/model/Global} ecModel
  18233. */
  18234. function resetSourceDefaulter(ecModel) {
  18235. // `datasetMap` is used to make default encode.
  18236. inner$3(ecModel).datasetMap = createHashMap();
  18237. }
  18238. /**
  18239. * [Caution]:
  18240. * MUST be called after series option merged and
  18241. * before "series.getInitailData()" called.
  18242. *
  18243. * [The rule of making default encode]:
  18244. * Category axis (if exists) alway map to the first dimension.
  18245. * Each other axis occupies a subsequent dimension.
  18246. *
  18247. * [Why make default encode]:
  18248. * Simplify the typing of encode in option, avoiding the case like that:
  18249. * series: [{encode: {x: 0, y: 1}}, {encode: {x: 0, y: 2}}, {encode: {x: 0, y: 3}}],
  18250. * where the "y" have to be manually typed as "1, 2, 3, ...".
  18251. *
  18252. * @param {module:echarts/model/Series} seriesModel
  18253. */
  18254. function prepareSource(seriesModel) {
  18255. var seriesOption = seriesModel.option;
  18256. var data = seriesOption.data;
  18257. var sourceFormat = isTypedArray(data)
  18258. ? SOURCE_FORMAT_TYPED_ARRAY : SOURCE_FORMAT_ORIGINAL;
  18259. var fromDataset = false;
  18260. var seriesLayoutBy = seriesOption.seriesLayoutBy;
  18261. var sourceHeader = seriesOption.sourceHeader;
  18262. var dimensionsDefine = seriesOption.dimensions;
  18263. var datasetModel = getDatasetModel(seriesModel);
  18264. if (datasetModel) {
  18265. var datasetOption = datasetModel.option;
  18266. data = datasetOption.source;
  18267. sourceFormat = inner$3(datasetModel).sourceFormat;
  18268. fromDataset = true;
  18269. // These settings from series has higher priority.
  18270. seriesLayoutBy = seriesLayoutBy || datasetOption.seriesLayoutBy;
  18271. sourceHeader == null && (sourceHeader = datasetOption.sourceHeader);
  18272. dimensionsDefine = dimensionsDefine || datasetOption.dimensions;
  18273. }
  18274. var completeResult = completeBySourceData(
  18275. data, sourceFormat, seriesLayoutBy, sourceHeader, dimensionsDefine
  18276. );
  18277. // Note: dataset option does not have `encode`.
  18278. var encodeDefine = seriesOption.encode;
  18279. if (!encodeDefine && datasetModel) {
  18280. encodeDefine = makeDefaultEncode(
  18281. seriesModel, datasetModel, data, sourceFormat, seriesLayoutBy, completeResult
  18282. );
  18283. }
  18284. inner$3(seriesModel).source = new Source({
  18285. data: data,
  18286. fromDataset: fromDataset,
  18287. seriesLayoutBy: seriesLayoutBy,
  18288. sourceFormat: sourceFormat,
  18289. dimensionsDefine: completeResult.dimensionsDefine,
  18290. startIndex: completeResult.startIndex,
  18291. dimensionsDetectCount: completeResult.dimensionsDetectCount,
  18292. encodeDefine: encodeDefine
  18293. });
  18294. }
  18295. // return {startIndex, dimensionsDefine, dimensionsCount}
  18296. function completeBySourceData(data, sourceFormat, seriesLayoutBy, sourceHeader, dimensionsDefine) {
  18297. if (!data) {
  18298. return {dimensionsDefine: normalizeDimensionsDefine(dimensionsDefine)};
  18299. }
  18300. var dimensionsDetectCount;
  18301. var startIndex;
  18302. var findPotentialName;
  18303. if (sourceFormat === SOURCE_FORMAT_ARRAY_ROWS) {
  18304. // Rule: Most of the first line are string: it is header.
  18305. // Caution: consider a line with 5 string and 1 number,
  18306. // it still can not be sure it is a head, because the
  18307. // 5 string may be 5 values of category columns.
  18308. if (sourceHeader === 'auto' || sourceHeader == null) {
  18309. arrayRowsTravelFirst(function (val) {
  18310. // '-' is regarded as null/undefined.
  18311. if (val != null && val !== '-') {
  18312. if (isString(val)) {
  18313. startIndex == null && (startIndex = 1);
  18314. }
  18315. else {
  18316. startIndex = 0;
  18317. }
  18318. }
  18319. // 10 is an experience number, avoid long loop.
  18320. }, seriesLayoutBy, data, 10);
  18321. }
  18322. else {
  18323. startIndex = sourceHeader ? 1 : 0;
  18324. }
  18325. if (!dimensionsDefine && startIndex === 1) {
  18326. dimensionsDefine = [];
  18327. arrayRowsTravelFirst(function (val, index) {
  18328. dimensionsDefine[index] = val != null ? val : '';
  18329. }, seriesLayoutBy, data);
  18330. }
  18331. dimensionsDetectCount = dimensionsDefine
  18332. ? dimensionsDefine.length
  18333. : seriesLayoutBy === SERIES_LAYOUT_BY_ROW
  18334. ? data.length
  18335. : data[0]
  18336. ? data[0].length
  18337. : null;
  18338. }
  18339. else if (sourceFormat === SOURCE_FORMAT_OBJECT_ROWS) {
  18340. if (!dimensionsDefine) {
  18341. dimensionsDefine = objectRowsCollectDimensions(data);
  18342. findPotentialName = true;
  18343. }
  18344. }
  18345. else if (sourceFormat === SOURCE_FORMAT_KEYED_COLUMNS) {
  18346. if (!dimensionsDefine) {
  18347. dimensionsDefine = [];
  18348. findPotentialName = true;
  18349. each$1(data, function (colArr, key) {
  18350. dimensionsDefine.push(key);
  18351. });
  18352. }
  18353. }
  18354. else if (sourceFormat === SOURCE_FORMAT_ORIGINAL) {
  18355. var value0 = getDataItemValue(data[0]);
  18356. dimensionsDetectCount = isArray(value0) && value0.length || 1;
  18357. }
  18358. else if (sourceFormat === SOURCE_FORMAT_TYPED_ARRAY) {
  18359. if (__DEV__) {
  18360. assert$1(!!dimensionsDefine, 'dimensions must be given if data is TypedArray.');
  18361. }
  18362. }
  18363. var potentialNameDimIndex;
  18364. if (findPotentialName) {
  18365. each$1(dimensionsDefine, function (dim, idx) {
  18366. if ((isObject$1(dim) ? dim.name : dim) === 'name') {
  18367. potentialNameDimIndex = idx;
  18368. }
  18369. });
  18370. }
  18371. return {
  18372. startIndex: startIndex,
  18373. dimensionsDefine: normalizeDimensionsDefine(dimensionsDefine),
  18374. dimensionsDetectCount: dimensionsDetectCount,
  18375. potentialNameDimIndex: potentialNameDimIndex
  18376. // TODO: potentialIdDimIdx
  18377. };
  18378. }
  18379. // Consider dimensions defined like ['A', 'price', 'B', 'price', 'C', 'price'],
  18380. // which is reasonable. But dimension name is duplicated.
  18381. // Returns undefined or an array contains only object without null/undefiend or string.
  18382. function normalizeDimensionsDefine(dimensionsDefine) {
  18383. if (!dimensionsDefine) {
  18384. // The meaning of null/undefined is different from empty array.
  18385. return;
  18386. }
  18387. var nameMap = createHashMap();
  18388. return map(dimensionsDefine, function (item, index) {
  18389. item = extend({}, isObject$1(item) ? item : {name: item});
  18390. // User can set null in dimensions.
  18391. // We dont auto specify name, othewise a given name may
  18392. // cause it be refered unexpectedly.
  18393. if (item.name == null) {
  18394. return item;
  18395. }
  18396. // Also consider number form like 2012.
  18397. item.name += '';
  18398. // User may also specify displayName.
  18399. // displayName will always exists except user not
  18400. // specified or dim name is not specified or detected.
  18401. // (A auto generated dim name will not be used as
  18402. // displayName).
  18403. if (item.displayName == null) {
  18404. item.displayName = item.name;
  18405. }
  18406. var exist = nameMap.get(item.name);
  18407. if (!exist) {
  18408. nameMap.set(item.name, {count: 1});
  18409. }
  18410. else {
  18411. item.name += '-' + exist.count++;
  18412. }
  18413. return item;
  18414. });
  18415. }
  18416. function arrayRowsTravelFirst(cb, seriesLayoutBy, data, maxLoop) {
  18417. maxLoop == null && (maxLoop = Infinity);
  18418. if (seriesLayoutBy === SERIES_LAYOUT_BY_ROW) {
  18419. for (var i = 0; i < data.length && i < maxLoop; i++) {
  18420. cb(data[i] ? data[i][0] : null, i);
  18421. }
  18422. }
  18423. else {
  18424. var value0 = data[0] || [];
  18425. for (var i = 0; i < value0.length && i < maxLoop; i++) {
  18426. cb(value0[i], i);
  18427. }
  18428. }
  18429. }
  18430. function objectRowsCollectDimensions(data) {
  18431. var firstIndex = 0;
  18432. var obj;
  18433. while (firstIndex < data.length && !(obj = data[firstIndex++])) {} // jshint ignore: line
  18434. if (obj) {
  18435. var dimensions = [];
  18436. each$1(obj, function (value, key) {
  18437. dimensions.push(key);
  18438. });
  18439. return dimensions;
  18440. }
  18441. }
  18442. // ??? TODO merge to completedimensions, where also has
  18443. // default encode making logic. And the default rule
  18444. // should depends on series? consider 'map'.
  18445. function makeDefaultEncode(
  18446. seriesModel, datasetModel, data, sourceFormat, seriesLayoutBy, completeResult
  18447. ) {
  18448. var coordSysDefine = getCoordSysDefineBySeries(seriesModel);
  18449. var encode = {};
  18450. // var encodeTooltip = [];
  18451. // var encodeLabel = [];
  18452. var encodeItemName = [];
  18453. var encodeSeriesName = [];
  18454. var seriesType = seriesModel.subType;
  18455. // ??? TODO refactor: provide by series itself.
  18456. // Consider the case: 'map' series is based on geo coordSys,
  18457. // 'graph', 'heatmap' can be based on cartesian. But can not
  18458. // give default rule simply here.
  18459. var nSeriesMap = createHashMap(['pie', 'map', 'funnel']);
  18460. var cSeriesMap = createHashMap([
  18461. 'line', 'bar', 'pictorialBar', 'scatter', 'effectScatter', 'candlestick', 'boxplot'
  18462. ]);
  18463. // Usually in this case series will use the first data
  18464. // dimension as the "value" dimension, or other default
  18465. // processes respectively.
  18466. if (coordSysDefine && cSeriesMap.get(seriesType) != null) {
  18467. var ecModel = seriesModel.ecModel;
  18468. var datasetMap = inner$3(ecModel).datasetMap;
  18469. var key = datasetModel.uid + '_' + seriesLayoutBy;
  18470. var datasetRecord = datasetMap.get(key)
  18471. || datasetMap.set(key, {categoryWayDim: 1, valueWayDim: 0});
  18472. // TODO
  18473. // Auto detect first time axis and do arrangement.
  18474. each$1(coordSysDefine.coordSysDims, function (coordDim) {
  18475. // In value way.
  18476. if (coordSysDefine.firstCategoryDimIndex == null) {
  18477. var dataDim = datasetRecord.valueWayDim++;
  18478. encode[coordDim] = dataDim;
  18479. // ??? TODO give a better default series name rule?
  18480. // especially when encode x y specified.
  18481. // consider: when mutiple series share one dimension
  18482. // category axis, series name should better use
  18483. // the other dimsion name. On the other hand, use
  18484. // both dimensions name.
  18485. encodeSeriesName.push(dataDim);
  18486. // encodeTooltip.push(dataDim);
  18487. // encodeLabel.push(dataDim);
  18488. }
  18489. // In category way, category axis.
  18490. else if (coordSysDefine.categoryAxisMap.get(coordDim)) {
  18491. encode[coordDim] = 0;
  18492. encodeItemName.push(0);
  18493. }
  18494. // In category way, non-category axis.
  18495. else {
  18496. var dataDim = datasetRecord.categoryWayDim++;
  18497. encode[coordDim] = dataDim;
  18498. // encodeTooltip.push(dataDim);
  18499. // encodeLabel.push(dataDim);
  18500. encodeSeriesName.push(dataDim);
  18501. }
  18502. });
  18503. }
  18504. // Do not make a complex rule! Hard to code maintain and not necessary.
  18505. // ??? TODO refactor: provide by series itself.
  18506. // [{name: ..., value: ...}, ...] like:
  18507. else if (nSeriesMap.get(seriesType) != null) {
  18508. // Find the first not ordinal. (5 is an experience value)
  18509. var firstNotOrdinal;
  18510. for (var i = 0; i < 5 && firstNotOrdinal == null; i++) {
  18511. if (!doGuessOrdinal(
  18512. data, sourceFormat, seriesLayoutBy,
  18513. completeResult.dimensionsDefine, completeResult.startIndex, i
  18514. )) {
  18515. firstNotOrdinal = i;
  18516. }
  18517. }
  18518. if (firstNotOrdinal != null) {
  18519. encode.value = firstNotOrdinal;
  18520. var nameDimIndex = completeResult.potentialNameDimIndex
  18521. || Math.max(firstNotOrdinal - 1, 0);
  18522. // By default, label use itemName in charts.
  18523. // So we dont set encodeLabel here.
  18524. encodeSeriesName.push(nameDimIndex);
  18525. encodeItemName.push(nameDimIndex);
  18526. // encodeTooltip.push(firstNotOrdinal);
  18527. }
  18528. }
  18529. // encodeTooltip.length && (encode.tooltip = encodeTooltip);
  18530. // encodeLabel.length && (encode.label = encodeLabel);
  18531. encodeItemName.length && (encode.itemName = encodeItemName);
  18532. encodeSeriesName.length && (encode.seriesName = encodeSeriesName);
  18533. return encode;
  18534. }
  18535. /**
  18536. * If return null/undefined, indicate that should not use datasetModel.
  18537. */
  18538. function getDatasetModel(seriesModel) {
  18539. var option = seriesModel.option;
  18540. // Caution: consider the scenario:
  18541. // A dataset is declared and a series is not expected to use the dataset,
  18542. // and at the beginning `setOption({series: { noData })` (just prepare other
  18543. // option but no data), then `setOption({series: {data: [...]}); In this case,
  18544. // the user should set an empty array to avoid that dataset is used by default.
  18545. var thisData = option.data;
  18546. if (!thisData) {
  18547. return seriesModel.ecModel.getComponent('dataset', option.datasetIndex || 0);
  18548. }
  18549. }
  18550. /**
  18551. * The rule should not be complex, otherwise user might not
  18552. * be able to known where the data is wrong.
  18553. * The code is ugly, but how to make it neat?
  18554. *
  18555. * @param {module:echars/data/Source} source
  18556. * @param {number} dimIndex
  18557. * @return {boolean} Whether ordinal.
  18558. */
  18559. function guessOrdinal(source, dimIndex) {
  18560. return doGuessOrdinal(
  18561. source.data,
  18562. source.sourceFormat,
  18563. source.seriesLayoutBy,
  18564. source.dimensionsDefine,
  18565. source.startIndex,
  18566. dimIndex
  18567. );
  18568. }
  18569. // dimIndex may be overflow source data.
  18570. function doGuessOrdinal(
  18571. data, sourceFormat, seriesLayoutBy, dimensionsDefine, startIndex, dimIndex
  18572. ) {
  18573. var result;
  18574. // Experience value.
  18575. var maxLoop = 5;
  18576. if (isTypedArray(data)) {
  18577. return false;
  18578. }
  18579. // When sourceType is 'objectRows' or 'keyedColumns', dimensionsDefine
  18580. // always exists in source.
  18581. var dimName;
  18582. if (dimensionsDefine) {
  18583. dimName = dimensionsDefine[dimIndex];
  18584. dimName = isObject$1(dimName) ? dimName.name : dimName;
  18585. }
  18586. if (sourceFormat === SOURCE_FORMAT_ARRAY_ROWS) {
  18587. if (seriesLayoutBy === SERIES_LAYOUT_BY_ROW) {
  18588. var sample = data[dimIndex];
  18589. for (var i = 0; i < (sample || []).length && i < maxLoop; i++) {
  18590. if ((result = detectValue(sample[startIndex + i])) != null) {
  18591. return result;
  18592. }
  18593. }
  18594. }
  18595. else {
  18596. for (var i = 0; i < data.length && i < maxLoop; i++) {
  18597. var row = data[startIndex + i];
  18598. if (row && (result = detectValue(row[dimIndex])) != null) {
  18599. return result;
  18600. }
  18601. }
  18602. }
  18603. }
  18604. else if (sourceFormat === SOURCE_FORMAT_OBJECT_ROWS) {
  18605. if (!dimName) {
  18606. return;
  18607. }
  18608. for (var i = 0; i < data.length && i < maxLoop; i++) {
  18609. var item = data[i];
  18610. if (item && (result = detectValue(item[dimName])) != null) {
  18611. return result;
  18612. }
  18613. }
  18614. }
  18615. else if (sourceFormat === SOURCE_FORMAT_KEYED_COLUMNS) {
  18616. if (!dimName) {
  18617. return;
  18618. }
  18619. var sample = data[dimName];
  18620. if (!sample || isTypedArray(sample)) {
  18621. return false;
  18622. }
  18623. for (var i = 0; i < sample.length && i < maxLoop; i++) {
  18624. if ((result = detectValue(sample[i])) != null) {
  18625. return result;
  18626. }
  18627. }
  18628. }
  18629. else if (sourceFormat === SOURCE_FORMAT_ORIGINAL) {
  18630. for (var i = 0; i < data.length && i < maxLoop; i++) {
  18631. var item = data[i];
  18632. var val = getDataItemValue(item);
  18633. if (!isArray(val)) {
  18634. return false;
  18635. }
  18636. if ((result = detectValue(val[dimIndex])) != null) {
  18637. return result;
  18638. }
  18639. }
  18640. }
  18641. function detectValue(val) {
  18642. // Consider usage convenience, '1', '2' will be treated as "number".
  18643. // `isFinit('')` get `true`.
  18644. if (val != null && isFinite(val) && val !== '') {
  18645. return false;
  18646. }
  18647. else if (isString(val) && val !== '-') {
  18648. return true;
  18649. }
  18650. }
  18651. return false;
  18652. }
  18653. /*
  18654. * Licensed to the Apache Software Foundation (ASF) under one
  18655. * or more contributor license agreements. See the NOTICE file
  18656. * distributed with this work for additional information
  18657. * regarding copyright ownership. The ASF licenses this file
  18658. * to you under the Apache License, Version 2.0 (the
  18659. * "License"); you may not use this file except in compliance
  18660. * with the License. You may obtain a copy of the License at
  18661. *
  18662. * http://www.apache.org/licenses/LICENSE-2.0
  18663. *
  18664. * Unless required by applicable law or agreed to in writing,
  18665. * software distributed under the License is distributed on an
  18666. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  18667. * KIND, either express or implied. See the License for the
  18668. * specific language governing permissions and limitations
  18669. * under the License.
  18670. */
  18671. /**
  18672. * ECharts global model
  18673. *
  18674. * @module {echarts/model/Global}
  18675. */
  18676. /**
  18677. * Caution: If the mechanism should be changed some day, these cases
  18678. * should be considered:
  18679. *
  18680. * (1) In `merge option` mode, if using the same option to call `setOption`
  18681. * many times, the result should be the same (try our best to ensure that).
  18682. * (2) In `merge option` mode, if a component has no id/name specified, it
  18683. * will be merged by index, and the result sequence of the components is
  18684. * consistent to the original sequence.
  18685. * (3) `reset` feature (in toolbox). Find detailed info in comments about
  18686. * `mergeOption` in module:echarts/model/OptionManager.
  18687. */
  18688. var OPTION_INNER_KEY = '\0_ec_inner';
  18689. /**
  18690. * @alias module:echarts/model/Global
  18691. *
  18692. * @param {Object} option
  18693. * @param {module:echarts/model/Model} parentModel
  18694. * @param {Object} theme
  18695. */
  18696. var GlobalModel = Model.extend({
  18697. init: function (option, parentModel, theme, optionManager) {
  18698. theme = theme || {};
  18699. this.option = null; // Mark as not initialized.
  18700. /**
  18701. * @type {module:echarts/model/Model}
  18702. * @private
  18703. */
  18704. this._theme = new Model(theme);
  18705. /**
  18706. * @type {module:echarts/model/OptionManager}
  18707. */
  18708. this._optionManager = optionManager;
  18709. },
  18710. setOption: function (option, optionPreprocessorFuncs) {
  18711. assert$1(
  18712. !(OPTION_INNER_KEY in option),
  18713. 'please use chart.getOption()'
  18714. );
  18715. this._optionManager.setOption(option, optionPreprocessorFuncs);
  18716. this.resetOption(null);
  18717. },
  18718. /**
  18719. * @param {string} type null/undefined: reset all.
  18720. * 'recreate': force recreate all.
  18721. * 'timeline': only reset timeline option
  18722. * 'media': only reset media query option
  18723. * @return {boolean} Whether option changed.
  18724. */
  18725. resetOption: function (type) {
  18726. var optionChanged = false;
  18727. var optionManager = this._optionManager;
  18728. if (!type || type === 'recreate') {
  18729. var baseOption = optionManager.mountOption(type === 'recreate');
  18730. if (!this.option || type === 'recreate') {
  18731. initBase.call(this, baseOption);
  18732. }
  18733. else {
  18734. this.restoreData();
  18735. this.mergeOption(baseOption);
  18736. }
  18737. optionChanged = true;
  18738. }
  18739. if (type === 'timeline' || type === 'media') {
  18740. this.restoreData();
  18741. }
  18742. if (!type || type === 'recreate' || type === 'timeline') {
  18743. var timelineOption = optionManager.getTimelineOption(this);
  18744. timelineOption && (this.mergeOption(timelineOption), optionChanged = true);
  18745. }
  18746. if (!type || type === 'recreate' || type === 'media') {
  18747. var mediaOptions = optionManager.getMediaOption(this, this._api);
  18748. if (mediaOptions.length) {
  18749. each$1(mediaOptions, function (mediaOption) {
  18750. this.mergeOption(mediaOption, optionChanged = true);
  18751. }, this);
  18752. }
  18753. }
  18754. return optionChanged;
  18755. },
  18756. /**
  18757. * @protected
  18758. */
  18759. mergeOption: function (newOption) {
  18760. var option = this.option;
  18761. var componentsMap = this._componentsMap;
  18762. var newCptTypes = [];
  18763. resetSourceDefaulter(this);
  18764. // If no component class, merge directly.
  18765. // For example: color, animaiton options, etc.
  18766. each$1(newOption, function (componentOption, mainType) {
  18767. if (componentOption == null) {
  18768. return;
  18769. }
  18770. if (!ComponentModel.hasClass(mainType)) {
  18771. // globalSettingTask.dirty();
  18772. option[mainType] = option[mainType] == null
  18773. ? clone(componentOption)
  18774. : merge(option[mainType], componentOption, true);
  18775. }
  18776. else if (mainType) {
  18777. newCptTypes.push(mainType);
  18778. }
  18779. });
  18780. ComponentModel.topologicalTravel(
  18781. newCptTypes, ComponentModel.getAllClassMainTypes(), visitComponent, this
  18782. );
  18783. function visitComponent(mainType, dependencies) {
  18784. var newCptOptionList = normalizeToArray(newOption[mainType]);
  18785. var mapResult = mappingToExists(
  18786. componentsMap.get(mainType), newCptOptionList
  18787. );
  18788. makeIdAndName(mapResult);
  18789. // Set mainType and complete subType.
  18790. each$1(mapResult, function (item, index) {
  18791. var opt = item.option;
  18792. if (isObject$1(opt)) {
  18793. item.keyInfo.mainType = mainType;
  18794. item.keyInfo.subType = determineSubType(mainType, opt, item.exist);
  18795. }
  18796. });
  18797. var dependentModels = getComponentsByTypes(
  18798. componentsMap, dependencies
  18799. );
  18800. option[mainType] = [];
  18801. componentsMap.set(mainType, []);
  18802. each$1(mapResult, function (resultItem, index) {
  18803. var componentModel = resultItem.exist;
  18804. var newCptOption = resultItem.option;
  18805. assert$1(
  18806. isObject$1(newCptOption) || componentModel,
  18807. 'Empty component definition'
  18808. );
  18809. // Consider where is no new option and should be merged using {},
  18810. // see removeEdgeAndAdd in topologicalTravel and
  18811. // ComponentModel.getAllClassMainTypes.
  18812. if (!newCptOption) {
  18813. componentModel.mergeOption({}, this);
  18814. componentModel.optionUpdated({}, false);
  18815. }
  18816. else {
  18817. var ComponentModelClass = ComponentModel.getClass(
  18818. mainType, resultItem.keyInfo.subType, true
  18819. );
  18820. if (componentModel && componentModel instanceof ComponentModelClass) {
  18821. componentModel.name = resultItem.keyInfo.name;
  18822. // componentModel.settingTask && componentModel.settingTask.dirty();
  18823. componentModel.mergeOption(newCptOption, this);
  18824. componentModel.optionUpdated(newCptOption, false);
  18825. }
  18826. else {
  18827. // PENDING Global as parent ?
  18828. var extraOpt = extend(
  18829. {
  18830. dependentModels: dependentModels,
  18831. componentIndex: index
  18832. },
  18833. resultItem.keyInfo
  18834. );
  18835. componentModel = new ComponentModelClass(
  18836. newCptOption, this, this, extraOpt
  18837. );
  18838. extend(componentModel, extraOpt);
  18839. componentModel.init(newCptOption, this, this, extraOpt);
  18840. // Call optionUpdated after init.
  18841. // newCptOption has been used as componentModel.option
  18842. // and may be merged with theme and default, so pass null
  18843. // to avoid confusion.
  18844. componentModel.optionUpdated(null, true);
  18845. }
  18846. }
  18847. componentsMap.get(mainType)[index] = componentModel;
  18848. option[mainType][index] = componentModel.option;
  18849. }, this);
  18850. // Backup series for filtering.
  18851. if (mainType === 'series') {
  18852. createSeriesIndices(this, componentsMap.get('series'));
  18853. }
  18854. }
  18855. this._seriesIndicesMap = createHashMap(
  18856. this._seriesIndices = this._seriesIndices || []
  18857. );
  18858. },
  18859. /**
  18860. * Get option for output (cloned option and inner info removed)
  18861. * @public
  18862. * @return {Object}
  18863. */
  18864. getOption: function () {
  18865. var option = clone(this.option);
  18866. each$1(option, function (opts, mainType) {
  18867. if (ComponentModel.hasClass(mainType)) {
  18868. var opts = normalizeToArray(opts);
  18869. for (var i = opts.length - 1; i >= 0; i--) {
  18870. // Remove options with inner id.
  18871. if (isIdInner(opts[i])) {
  18872. opts.splice(i, 1);
  18873. }
  18874. }
  18875. option[mainType] = opts;
  18876. }
  18877. });
  18878. delete option[OPTION_INNER_KEY];
  18879. return option;
  18880. },
  18881. /**
  18882. * @return {module:echarts/model/Model}
  18883. */
  18884. getTheme: function () {
  18885. return this._theme;
  18886. },
  18887. /**
  18888. * @param {string} mainType
  18889. * @param {number} [idx=0]
  18890. * @return {module:echarts/model/Component}
  18891. */
  18892. getComponent: function (mainType, idx) {
  18893. var list = this._componentsMap.get(mainType);
  18894. if (list) {
  18895. return list[idx || 0];
  18896. }
  18897. },
  18898. /**
  18899. * If none of index and id and name used, return all components with mainType.
  18900. * @param {Object} condition
  18901. * @param {string} condition.mainType
  18902. * @param {string} [condition.subType] If ignore, only query by mainType
  18903. * @param {number|Array.<number>} [condition.index] Either input index or id or name.
  18904. * @param {string|Array.<string>} [condition.id] Either input index or id or name.
  18905. * @param {string|Array.<string>} [condition.name] Either input index or id or name.
  18906. * @return {Array.<module:echarts/model/Component>}
  18907. */
  18908. queryComponents: function (condition) {
  18909. var mainType = condition.mainType;
  18910. if (!mainType) {
  18911. return [];
  18912. }
  18913. var index = condition.index;
  18914. var id = condition.id;
  18915. var name = condition.name;
  18916. var cpts = this._componentsMap.get(mainType);
  18917. if (!cpts || !cpts.length) {
  18918. return [];
  18919. }
  18920. var result;
  18921. if (index != null) {
  18922. if (!isArray(index)) {
  18923. index = [index];
  18924. }
  18925. result = filter(map(index, function (idx) {
  18926. return cpts[idx];
  18927. }), function (val) {
  18928. return !!val;
  18929. });
  18930. }
  18931. else if (id != null) {
  18932. var isIdArray = isArray(id);
  18933. result = filter(cpts, function (cpt) {
  18934. return (isIdArray && indexOf(id, cpt.id) >= 0)
  18935. || (!isIdArray && cpt.id === id);
  18936. });
  18937. }
  18938. else if (name != null) {
  18939. var isNameArray = isArray(name);
  18940. result = filter(cpts, function (cpt) {
  18941. return (isNameArray && indexOf(name, cpt.name) >= 0)
  18942. || (!isNameArray && cpt.name === name);
  18943. });
  18944. }
  18945. else {
  18946. // Return all components with mainType
  18947. result = cpts.slice();
  18948. }
  18949. return filterBySubType(result, condition);
  18950. },
  18951. /**
  18952. * The interface is different from queryComponents,
  18953. * which is convenient for inner usage.
  18954. *
  18955. * @usage
  18956. * var result = findComponents(
  18957. * {mainType: 'dataZoom', query: {dataZoomId: 'abc'}}
  18958. * );
  18959. * var result = findComponents(
  18960. * {mainType: 'series', subType: 'pie', query: {seriesName: 'uio'}}
  18961. * );
  18962. * var result = findComponents(
  18963. * {mainType: 'series'},
  18964. * function (model, index) {...}
  18965. * );
  18966. * // result like [component0, componnet1, ...]
  18967. *
  18968. * @param {Object} condition
  18969. * @param {string} condition.mainType Mandatory.
  18970. * @param {string} [condition.subType] Optional.
  18971. * @param {Object} [condition.query] like {xxxIndex, xxxId, xxxName},
  18972. * where xxx is mainType.
  18973. * If query attribute is null/undefined or has no index/id/name,
  18974. * do not filtering by query conditions, which is convenient for
  18975. * no-payload situations or when target of action is global.
  18976. * @param {Function} [condition.filter] parameter: component, return boolean.
  18977. * @return {Array.<module:echarts/model/Component>}
  18978. */
  18979. findComponents: function (condition) {
  18980. var query = condition.query;
  18981. var mainType = condition.mainType;
  18982. var queryCond = getQueryCond(query);
  18983. var result = queryCond
  18984. ? this.queryComponents(queryCond)
  18985. : this._componentsMap.get(mainType);
  18986. return doFilter(filterBySubType(result, condition));
  18987. function getQueryCond(q) {
  18988. var indexAttr = mainType + 'Index';
  18989. var idAttr = mainType + 'Id';
  18990. var nameAttr = mainType + 'Name';
  18991. return q && (
  18992. q[indexAttr] != null
  18993. || q[idAttr] != null
  18994. || q[nameAttr] != null
  18995. )
  18996. ? {
  18997. mainType: mainType,
  18998. // subType will be filtered finally.
  18999. index: q[indexAttr],
  19000. id: q[idAttr],
  19001. name: q[nameAttr]
  19002. }
  19003. : null;
  19004. }
  19005. function doFilter(res) {
  19006. return condition.filter
  19007. ? filter(res, condition.filter)
  19008. : res;
  19009. }
  19010. },
  19011. /**
  19012. * @usage
  19013. * eachComponent('legend', function (legendModel, index) {
  19014. * ...
  19015. * });
  19016. * eachComponent(function (componentType, model, index) {
  19017. * // componentType does not include subType
  19018. * // (componentType is 'xxx' but not 'xxx.aa')
  19019. * });
  19020. * eachComponent(
  19021. * {mainType: 'dataZoom', query: {dataZoomId: 'abc'}},
  19022. * function (model, index) {...}
  19023. * );
  19024. * eachComponent(
  19025. * {mainType: 'series', subType: 'pie', query: {seriesName: 'uio'}},
  19026. * function (model, index) {...}
  19027. * );
  19028. *
  19029. * @param {string|Object=} mainType When mainType is object, the definition
  19030. * is the same as the method 'findComponents'.
  19031. * @param {Function} cb
  19032. * @param {*} context
  19033. */
  19034. eachComponent: function (mainType, cb, context) {
  19035. var componentsMap = this._componentsMap;
  19036. if (typeof mainType === 'function') {
  19037. context = cb;
  19038. cb = mainType;
  19039. componentsMap.each(function (components, componentType) {
  19040. each$1(components, function (component, index) {
  19041. cb.call(context, componentType, component, index);
  19042. });
  19043. });
  19044. }
  19045. else if (isString(mainType)) {
  19046. each$1(componentsMap.get(mainType), cb, context);
  19047. }
  19048. else if (isObject$1(mainType)) {
  19049. var queryResult = this.findComponents(mainType);
  19050. each$1(queryResult, cb, context);
  19051. }
  19052. },
  19053. /**
  19054. * @param {string} name
  19055. * @return {Array.<module:echarts/model/Series>}
  19056. */
  19057. getSeriesByName: function (name) {
  19058. var series = this._componentsMap.get('series');
  19059. return filter(series, function (oneSeries) {
  19060. return oneSeries.name === name;
  19061. });
  19062. },
  19063. /**
  19064. * @param {number} seriesIndex
  19065. * @return {module:echarts/model/Series}
  19066. */
  19067. getSeriesByIndex: function (seriesIndex) {
  19068. return this._componentsMap.get('series')[seriesIndex];
  19069. },
  19070. /**
  19071. * Get series list before filtered by type.
  19072. * FIXME: rename to getRawSeriesByType?
  19073. *
  19074. * @param {string} subType
  19075. * @return {Array.<module:echarts/model/Series>}
  19076. */
  19077. getSeriesByType: function (subType) {
  19078. var series = this._componentsMap.get('series');
  19079. return filter(series, function (oneSeries) {
  19080. return oneSeries.subType === subType;
  19081. });
  19082. },
  19083. /**
  19084. * @return {Array.<module:echarts/model/Series>}
  19085. */
  19086. getSeries: function () {
  19087. return this._componentsMap.get('series').slice();
  19088. },
  19089. /**
  19090. * @return {number}
  19091. */
  19092. getSeriesCount: function () {
  19093. return this._componentsMap.get('series').length;
  19094. },
  19095. /**
  19096. * After filtering, series may be different
  19097. * frome raw series.
  19098. *
  19099. * @param {Function} cb
  19100. * @param {*} context
  19101. */
  19102. eachSeries: function (cb, context) {
  19103. assertSeriesInitialized(this);
  19104. each$1(this._seriesIndices, function (rawSeriesIndex) {
  19105. var series = this._componentsMap.get('series')[rawSeriesIndex];
  19106. cb.call(context, series, rawSeriesIndex);
  19107. }, this);
  19108. },
  19109. /**
  19110. * Iterate raw series before filtered.
  19111. *
  19112. * @param {Function} cb
  19113. * @param {*} context
  19114. */
  19115. eachRawSeries: function (cb, context) {
  19116. each$1(this._componentsMap.get('series'), cb, context);
  19117. },
  19118. /**
  19119. * After filtering, series may be different.
  19120. * frome raw series.
  19121. *
  19122. * @param {string} subType.
  19123. * @param {Function} cb
  19124. * @param {*} context
  19125. */
  19126. eachSeriesByType: function (subType, cb, context) {
  19127. assertSeriesInitialized(this);
  19128. each$1(this._seriesIndices, function (rawSeriesIndex) {
  19129. var series = this._componentsMap.get('series')[rawSeriesIndex];
  19130. if (series.subType === subType) {
  19131. cb.call(context, series, rawSeriesIndex);
  19132. }
  19133. }, this);
  19134. },
  19135. /**
  19136. * Iterate raw series before filtered of given type.
  19137. *
  19138. * @parma {string} subType
  19139. * @param {Function} cb
  19140. * @param {*} context
  19141. */
  19142. eachRawSeriesByType: function (subType, cb, context) {
  19143. return each$1(this.getSeriesByType(subType), cb, context);
  19144. },
  19145. /**
  19146. * @param {module:echarts/model/Series} seriesModel
  19147. */
  19148. isSeriesFiltered: function (seriesModel) {
  19149. assertSeriesInitialized(this);
  19150. return this._seriesIndicesMap.get(seriesModel.componentIndex) == null;
  19151. },
  19152. /**
  19153. * @return {Array.<number>}
  19154. */
  19155. getCurrentSeriesIndices: function () {
  19156. return (this._seriesIndices || []).slice();
  19157. },
  19158. /**
  19159. * @param {Function} cb
  19160. * @param {*} context
  19161. */
  19162. filterSeries: function (cb, context) {
  19163. assertSeriesInitialized(this);
  19164. var filteredSeries = filter(
  19165. this._componentsMap.get('series'), cb, context
  19166. );
  19167. createSeriesIndices(this, filteredSeries);
  19168. },
  19169. restoreData: function (payload) {
  19170. var componentsMap = this._componentsMap;
  19171. createSeriesIndices(this, componentsMap.get('series'));
  19172. var componentTypes = [];
  19173. componentsMap.each(function (components, componentType) {
  19174. componentTypes.push(componentType);
  19175. });
  19176. ComponentModel.topologicalTravel(
  19177. componentTypes,
  19178. ComponentModel.getAllClassMainTypes(),
  19179. function (componentType, dependencies) {
  19180. each$1(componentsMap.get(componentType), function (component) {
  19181. (componentType !== 'series' || !isNotTargetSeries(component, payload))
  19182. && component.restoreData();
  19183. });
  19184. }
  19185. );
  19186. }
  19187. });
  19188. function isNotTargetSeries(seriesModel, payload) {
  19189. if (payload) {
  19190. var index = payload.seiresIndex;
  19191. var id = payload.seriesId;
  19192. var name = payload.seriesName;
  19193. return (index != null && seriesModel.componentIndex !== index)
  19194. || (id != null && seriesModel.id !== id)
  19195. || (name != null && seriesModel.name !== name);
  19196. }
  19197. }
  19198. /**
  19199. * @inner
  19200. */
  19201. function mergeTheme(option, theme) {
  19202. // PENDING
  19203. // NOT use `colorLayer` in theme if option has `color`
  19204. var notMergeColorLayer = option.color && !option.colorLayer;
  19205. each$1(theme, function (themeItem, name) {
  19206. if (name === 'colorLayer' && notMergeColorLayer) {
  19207. return;
  19208. }
  19209. // 如果有 component model 则把具体的 merge 逻辑交给该 model 处理
  19210. if (!ComponentModel.hasClass(name)) {
  19211. if (typeof themeItem === 'object') {
  19212. option[name] = !option[name]
  19213. ? clone(themeItem)
  19214. : merge(option[name], themeItem, false);
  19215. }
  19216. else {
  19217. if (option[name] == null) {
  19218. option[name] = themeItem;
  19219. }
  19220. }
  19221. }
  19222. });
  19223. }
  19224. function initBase(baseOption) {
  19225. baseOption = baseOption;
  19226. // Using OPTION_INNER_KEY to mark that this option can not be used outside,
  19227. // i.e. `chart.setOption(chart.getModel().option);` is forbiden.
  19228. this.option = {};
  19229. this.option[OPTION_INNER_KEY] = 1;
  19230. /**
  19231. * Init with series: [], in case of calling findSeries method
  19232. * before series initialized.
  19233. * @type {Object.<string, Array.<module:echarts/model/Model>>}
  19234. * @private
  19235. */
  19236. this._componentsMap = createHashMap({series: []});
  19237. /**
  19238. * Mapping between filtered series list and raw series list.
  19239. * key: filtered series indices, value: raw series indices.
  19240. * @type {Array.<nubmer>}
  19241. * @private
  19242. */
  19243. this._seriesIndices;
  19244. this._seriesIndicesMap;
  19245. mergeTheme(baseOption, this._theme.option);
  19246. // TODO Needs clone when merging to the unexisted property
  19247. merge(baseOption, globalDefault, false);
  19248. this.mergeOption(baseOption);
  19249. }
  19250. /**
  19251. * @inner
  19252. * @param {Array.<string>|string} types model types
  19253. * @return {Object} key: {string} type, value: {Array.<Object>} models
  19254. */
  19255. function getComponentsByTypes(componentsMap, types) {
  19256. if (!isArray(types)) {
  19257. types = types ? [types] : [];
  19258. }
  19259. var ret = {};
  19260. each$1(types, function (type) {
  19261. ret[type] = (componentsMap.get(type) || []).slice();
  19262. });
  19263. return ret;
  19264. }
  19265. /**
  19266. * @inner
  19267. */
  19268. function determineSubType(mainType, newCptOption, existComponent) {
  19269. var subType = newCptOption.type
  19270. ? newCptOption.type
  19271. : existComponent
  19272. ? existComponent.subType
  19273. // Use determineSubType only when there is no existComponent.
  19274. : ComponentModel.determineSubType(mainType, newCptOption);
  19275. // tooltip, markline, markpoint may always has no subType
  19276. return subType;
  19277. }
  19278. /**
  19279. * @inner
  19280. */
  19281. function createSeriesIndices(ecModel, seriesModels) {
  19282. ecModel._seriesIndicesMap = createHashMap(
  19283. ecModel._seriesIndices = map(seriesModels, function (series) {
  19284. return series.componentIndex;
  19285. }) || []
  19286. );
  19287. }
  19288. /**
  19289. * @inner
  19290. */
  19291. function filterBySubType(components, condition) {
  19292. // Using hasOwnProperty for restrict. Consider
  19293. // subType is undefined in user payload.
  19294. return condition.hasOwnProperty('subType')
  19295. ? filter(components, function (cpt) {
  19296. return cpt.subType === condition.subType;
  19297. })
  19298. : components;
  19299. }
  19300. /**
  19301. * @inner
  19302. */
  19303. function assertSeriesInitialized(ecModel) {
  19304. // Components that use _seriesIndices should depends on series component,
  19305. // which make sure that their initialization is after series.
  19306. if (__DEV__) {
  19307. if (!ecModel._seriesIndices) {
  19308. throw new Error('Option should contains series.');
  19309. }
  19310. }
  19311. }
  19312. mixin(GlobalModel, colorPaletteMixin);
  19313. /*
  19314. * Licensed to the Apache Software Foundation (ASF) under one
  19315. * or more contributor license agreements. See the NOTICE file
  19316. * distributed with this work for additional information
  19317. * regarding copyright ownership. The ASF licenses this file
  19318. * to you under the Apache License, Version 2.0 (the
  19319. * "License"); you may not use this file except in compliance
  19320. * with the License. You may obtain a copy of the License at
  19321. *
  19322. * http://www.apache.org/licenses/LICENSE-2.0
  19323. *
  19324. * Unless required by applicable law or agreed to in writing,
  19325. * software distributed under the License is distributed on an
  19326. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  19327. * KIND, either express or implied. See the License for the
  19328. * specific language governing permissions and limitations
  19329. * under the License.
  19330. */
  19331. var echartsAPIList = [
  19332. 'getDom', 'getZr', 'getWidth', 'getHeight', 'getDevicePixelRatio', 'dispatchAction', 'isDisposed',
  19333. 'on', 'off', 'getDataURL', 'getConnectedDataURL', 'getModel', 'getOption',
  19334. 'getViewOfComponentModel', 'getViewOfSeriesModel'
  19335. ];
  19336. // And `getCoordinateSystems` and `getComponentByElement` will be injected in echarts.js
  19337. function ExtensionAPI(chartInstance) {
  19338. each$1(echartsAPIList, function (name) {
  19339. this[name] = bind(chartInstance[name], chartInstance);
  19340. }, this);
  19341. }
  19342. /*
  19343. * Licensed to the Apache Software Foundation (ASF) under one
  19344. * or more contributor license agreements. See the NOTICE file
  19345. * distributed with this work for additional information
  19346. * regarding copyright ownership. The ASF licenses this file
  19347. * to you under the Apache License, Version 2.0 (the
  19348. * "License"); you may not use this file except in compliance
  19349. * with the License. You may obtain a copy of the License at
  19350. *
  19351. * http://www.apache.org/licenses/LICENSE-2.0
  19352. *
  19353. * Unless required by applicable law or agreed to in writing,
  19354. * software distributed under the License is distributed on an
  19355. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  19356. * KIND, either express or implied. See the License for the
  19357. * specific language governing permissions and limitations
  19358. * under the License.
  19359. */
  19360. var coordinateSystemCreators = {};
  19361. function CoordinateSystemManager() {
  19362. this._coordinateSystems = [];
  19363. }
  19364. CoordinateSystemManager.prototype = {
  19365. constructor: CoordinateSystemManager,
  19366. create: function (ecModel, api) {
  19367. var coordinateSystems = [];
  19368. each$1(coordinateSystemCreators, function (creater, type) {
  19369. var list = creater.create(ecModel, api);
  19370. coordinateSystems = coordinateSystems.concat(list || []);
  19371. });
  19372. this._coordinateSystems = coordinateSystems;
  19373. },
  19374. update: function (ecModel, api) {
  19375. each$1(this._coordinateSystems, function (coordSys) {
  19376. coordSys.update && coordSys.update(ecModel, api);
  19377. });
  19378. },
  19379. getCoordinateSystems: function () {
  19380. return this._coordinateSystems.slice();
  19381. }
  19382. };
  19383. CoordinateSystemManager.register = function (type, coordinateSystemCreator) {
  19384. coordinateSystemCreators[type] = coordinateSystemCreator;
  19385. };
  19386. CoordinateSystemManager.get = function (type) {
  19387. return coordinateSystemCreators[type];
  19388. };
  19389. /*
  19390. * Licensed to the Apache Software Foundation (ASF) under one
  19391. * or more contributor license agreements. See the NOTICE file
  19392. * distributed with this work for additional information
  19393. * regarding copyright ownership. The ASF licenses this file
  19394. * to you under the Apache License, Version 2.0 (the
  19395. * "License"); you may not use this file except in compliance
  19396. * with the License. You may obtain a copy of the License at
  19397. *
  19398. * http://www.apache.org/licenses/LICENSE-2.0
  19399. *
  19400. * Unless required by applicable law or agreed to in writing,
  19401. * software distributed under the License is distributed on an
  19402. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  19403. * KIND, either express or implied. See the License for the
  19404. * specific language governing permissions and limitations
  19405. * under the License.
  19406. */
  19407. /**
  19408. * ECharts option manager
  19409. *
  19410. * @module {echarts/model/OptionManager}
  19411. */
  19412. var each$4 = each$1;
  19413. var clone$3 = clone;
  19414. var map$1 = map;
  19415. var merge$1 = merge;
  19416. var QUERY_REG = /^(min|max)?(.+)$/;
  19417. /**
  19418. * TERM EXPLANATIONS:
  19419. *
  19420. * [option]:
  19421. *
  19422. * An object that contains definitions of components. For example:
  19423. * var option = {
  19424. * title: {...},
  19425. * legend: {...},
  19426. * visualMap: {...},
  19427. * series: [
  19428. * {data: [...]},
  19429. * {data: [...]},
  19430. * ...
  19431. * ]
  19432. * };
  19433. *
  19434. * [rawOption]:
  19435. *
  19436. * An object input to echarts.setOption. 'rawOption' may be an
  19437. * 'option', or may be an object contains multi-options. For example:
  19438. * var option = {
  19439. * baseOption: {
  19440. * title: {...},
  19441. * legend: {...},
  19442. * series: [
  19443. * {data: [...]},
  19444. * {data: [...]},
  19445. * ...
  19446. * ]
  19447. * },
  19448. * timeline: {...},
  19449. * options: [
  19450. * {title: {...}, series: {data: [...]}},
  19451. * {title: {...}, series: {data: [...]}},
  19452. * ...
  19453. * ],
  19454. * media: [
  19455. * {
  19456. * query: {maxWidth: 320},
  19457. * option: {series: {x: 20}, visualMap: {show: false}}
  19458. * },
  19459. * {
  19460. * query: {minWidth: 320, maxWidth: 720},
  19461. * option: {series: {x: 500}, visualMap: {show: true}}
  19462. * },
  19463. * {
  19464. * option: {series: {x: 1200}, visualMap: {show: true}}
  19465. * }
  19466. * ]
  19467. * };
  19468. *
  19469. * @alias module:echarts/model/OptionManager
  19470. * @param {module:echarts/ExtensionAPI} api
  19471. */
  19472. function OptionManager(api) {
  19473. /**
  19474. * @private
  19475. * @type {module:echarts/ExtensionAPI}
  19476. */
  19477. this._api = api;
  19478. /**
  19479. * @private
  19480. * @type {Array.<number>}
  19481. */
  19482. this._timelineOptions = [];
  19483. /**
  19484. * @private
  19485. * @type {Array.<Object>}
  19486. */
  19487. this._mediaList = [];
  19488. /**
  19489. * @private
  19490. * @type {Object}
  19491. */
  19492. this._mediaDefault;
  19493. /**
  19494. * -1, means default.
  19495. * empty means no media.
  19496. * @private
  19497. * @type {Array.<number>}
  19498. */
  19499. this._currentMediaIndices = [];
  19500. /**
  19501. * @private
  19502. * @type {Object}
  19503. */
  19504. this._optionBackup;
  19505. /**
  19506. * @private
  19507. * @type {Object}
  19508. */
  19509. this._newBaseOption;
  19510. }
  19511. // timeline.notMerge is not supported in ec3. Firstly there is rearly
  19512. // case that notMerge is needed. Secondly supporting 'notMerge' requires
  19513. // rawOption cloned and backuped when timeline changed, which does no
  19514. // good to performance. What's more, that both timeline and setOption
  19515. // method supply 'notMerge' brings complex and some problems.
  19516. // Consider this case:
  19517. // (step1) chart.setOption({timeline: {notMerge: false}, ...}, false);
  19518. // (step2) chart.setOption({timeline: {notMerge: true}, ...}, false);
  19519. OptionManager.prototype = {
  19520. constructor: OptionManager,
  19521. /**
  19522. * @public
  19523. * @param {Object} rawOption Raw option.
  19524. * @param {module:echarts/model/Global} ecModel
  19525. * @param {Array.<Function>} optionPreprocessorFuncs
  19526. * @return {Object} Init option
  19527. */
  19528. setOption: function (rawOption, optionPreprocessorFuncs) {
  19529. if (rawOption) {
  19530. // That set dat primitive is dangerous if user reuse the data when setOption again.
  19531. each$1(normalizeToArray(rawOption.series), function (series) {
  19532. series && series.data && isTypedArray(series.data) && setAsPrimitive(series.data);
  19533. });
  19534. }
  19535. // Caution: some series modify option data, if do not clone,
  19536. // it should ensure that the repeat modify correctly
  19537. // (create a new object when modify itself).
  19538. rawOption = clone$3(rawOption);
  19539. // FIXME
  19540. // 如果 timeline options 或者 media 中设置了某个属性,而baseOption中没有设置,则进行警告。
  19541. var oldOptionBackup = this._optionBackup;
  19542. var newParsedOption = parseRawOption.call(
  19543. this, rawOption, optionPreprocessorFuncs, !oldOptionBackup
  19544. );
  19545. this._newBaseOption = newParsedOption.baseOption;
  19546. // For setOption at second time (using merge mode);
  19547. if (oldOptionBackup) {
  19548. // Only baseOption can be merged.
  19549. mergeOption(oldOptionBackup.baseOption, newParsedOption.baseOption);
  19550. // For simplicity, timeline options and media options do not support merge,
  19551. // that is, if you `setOption` twice and both has timeline options, the latter
  19552. // timeline opitons will not be merged to the formers, but just substitude them.
  19553. if (newParsedOption.timelineOptions.length) {
  19554. oldOptionBackup.timelineOptions = newParsedOption.timelineOptions;
  19555. }
  19556. if (newParsedOption.mediaList.length) {
  19557. oldOptionBackup.mediaList = newParsedOption.mediaList;
  19558. }
  19559. if (newParsedOption.mediaDefault) {
  19560. oldOptionBackup.mediaDefault = newParsedOption.mediaDefault;
  19561. }
  19562. }
  19563. else {
  19564. this._optionBackup = newParsedOption;
  19565. }
  19566. },
  19567. /**
  19568. * @param {boolean} isRecreate
  19569. * @return {Object}
  19570. */
  19571. mountOption: function (isRecreate) {
  19572. var optionBackup = this._optionBackup;
  19573. // TODO
  19574. // 如果没有reset功能则不clone。
  19575. this._timelineOptions = map$1(optionBackup.timelineOptions, clone$3);
  19576. this._mediaList = map$1(optionBackup.mediaList, clone$3);
  19577. this._mediaDefault = clone$3(optionBackup.mediaDefault);
  19578. this._currentMediaIndices = [];
  19579. return clone$3(isRecreate
  19580. // this._optionBackup.baseOption, which is created at the first `setOption`
  19581. // called, and is merged into every new option by inner method `mergeOption`
  19582. // each time `setOption` called, can be only used in `isRecreate`, because
  19583. // its reliability is under suspicion. In other cases option merge is
  19584. // performed by `model.mergeOption`.
  19585. ? optionBackup.baseOption : this._newBaseOption
  19586. );
  19587. },
  19588. /**
  19589. * @param {module:echarts/model/Global} ecModel
  19590. * @return {Object}
  19591. */
  19592. getTimelineOption: function (ecModel) {
  19593. var option;
  19594. var timelineOptions = this._timelineOptions;
  19595. if (timelineOptions.length) {
  19596. // getTimelineOption can only be called after ecModel inited,
  19597. // so we can get currentIndex from timelineModel.
  19598. var timelineModel = ecModel.getComponent('timeline');
  19599. if (timelineModel) {
  19600. option = clone$3(
  19601. timelineOptions[timelineModel.getCurrentIndex()],
  19602. true
  19603. );
  19604. }
  19605. }
  19606. return option;
  19607. },
  19608. /**
  19609. * @param {module:echarts/model/Global} ecModel
  19610. * @return {Array.<Object>}
  19611. */
  19612. getMediaOption: function (ecModel) {
  19613. var ecWidth = this._api.getWidth();
  19614. var ecHeight = this._api.getHeight();
  19615. var mediaList = this._mediaList;
  19616. var mediaDefault = this._mediaDefault;
  19617. var indices = [];
  19618. var result = [];
  19619. // No media defined.
  19620. if (!mediaList.length && !mediaDefault) {
  19621. return result;
  19622. }
  19623. // Multi media may be applied, the latter defined media has higher priority.
  19624. for (var i = 0, len = mediaList.length; i < len; i++) {
  19625. if (applyMediaQuery(mediaList[i].query, ecWidth, ecHeight)) {
  19626. indices.push(i);
  19627. }
  19628. }
  19629. // FIXME
  19630. // 是否mediaDefault应该强制用户设置,否则可能修改不能回归。
  19631. if (!indices.length && mediaDefault) {
  19632. indices = [-1];
  19633. }
  19634. if (indices.length && !indicesEquals(indices, this._currentMediaIndices)) {
  19635. result = map$1(indices, function (index) {
  19636. return clone$3(
  19637. index === -1 ? mediaDefault.option : mediaList[index].option
  19638. );
  19639. });
  19640. }
  19641. // Otherwise return nothing.
  19642. this._currentMediaIndices = indices;
  19643. return result;
  19644. }
  19645. };
  19646. function parseRawOption(rawOption, optionPreprocessorFuncs, isNew) {
  19647. var timelineOptions = [];
  19648. var mediaList = [];
  19649. var mediaDefault;
  19650. var baseOption;
  19651. // Compatible with ec2.
  19652. var timelineOpt = rawOption.timeline;
  19653. if (rawOption.baseOption) {
  19654. baseOption = rawOption.baseOption;
  19655. }
  19656. // For timeline
  19657. if (timelineOpt || rawOption.options) {
  19658. baseOption = baseOption || {};
  19659. timelineOptions = (rawOption.options || []).slice();
  19660. }
  19661. // For media query
  19662. if (rawOption.media) {
  19663. baseOption = baseOption || {};
  19664. var media = rawOption.media;
  19665. each$4(media, function (singleMedia) {
  19666. if (singleMedia && singleMedia.option) {
  19667. if (singleMedia.query) {
  19668. mediaList.push(singleMedia);
  19669. }
  19670. else if (!mediaDefault) {
  19671. // Use the first media default.
  19672. mediaDefault = singleMedia;
  19673. }
  19674. }
  19675. });
  19676. }
  19677. // For normal option
  19678. if (!baseOption) {
  19679. baseOption = rawOption;
  19680. }
  19681. // Set timelineOpt to baseOption in ec3,
  19682. // which is convenient for merge option.
  19683. if (!baseOption.timeline) {
  19684. baseOption.timeline = timelineOpt;
  19685. }
  19686. // Preprocess.
  19687. each$4([baseOption].concat(timelineOptions)
  19688. .concat(map(mediaList, function (media) {
  19689. return media.option;
  19690. })),
  19691. function (option) {
  19692. each$4(optionPreprocessorFuncs, function (preProcess) {
  19693. preProcess(option, isNew);
  19694. });
  19695. }
  19696. );
  19697. return {
  19698. baseOption: baseOption,
  19699. timelineOptions: timelineOptions,
  19700. mediaDefault: mediaDefault,
  19701. mediaList: mediaList
  19702. };
  19703. }
  19704. /**
  19705. * @see <http://www.w3.org/TR/css3-mediaqueries/#media1>
  19706. * Support: width, height, aspectRatio
  19707. * Can use max or min as prefix.
  19708. */
  19709. function applyMediaQuery(query, ecWidth, ecHeight) {
  19710. var realMap = {
  19711. width: ecWidth,
  19712. height: ecHeight,
  19713. aspectratio: ecWidth / ecHeight // lowser case for convenientce.
  19714. };
  19715. var applicatable = true;
  19716. each$1(query, function (value, attr) {
  19717. var matched = attr.match(QUERY_REG);
  19718. if (!matched || !matched[1] || !matched[2]) {
  19719. return;
  19720. }
  19721. var operator = matched[1];
  19722. var realAttr = matched[2].toLowerCase();
  19723. if (!compare(realMap[realAttr], value, operator)) {
  19724. applicatable = false;
  19725. }
  19726. });
  19727. return applicatable;
  19728. }
  19729. function compare(real, expect, operator) {
  19730. if (operator === 'min') {
  19731. return real >= expect;
  19732. }
  19733. else if (operator === 'max') {
  19734. return real <= expect;
  19735. }
  19736. else { // Equals
  19737. return real === expect;
  19738. }
  19739. }
  19740. function indicesEquals(indices1, indices2) {
  19741. // indices is always order by asc and has only finite number.
  19742. return indices1.join(',') === indices2.join(',');
  19743. }
  19744. /**
  19745. * Consider case:
  19746. * `chart.setOption(opt1);`
  19747. * Then user do some interaction like dataZoom, dataView changing.
  19748. * `chart.setOption(opt2);`
  19749. * Then user press 'reset button' in toolbox.
  19750. *
  19751. * After doing that all of the interaction effects should be reset, the
  19752. * chart should be the same as the result of invoke
  19753. * `chart.setOption(opt1); chart.setOption(opt2);`.
  19754. *
  19755. * Although it is not able ensure that
  19756. * `chart.setOption(opt1); chart.setOption(opt2);` is equivalents to
  19757. * `chart.setOption(merge(opt1, opt2));` exactly,
  19758. * this might be the only simple way to implement that feature.
  19759. *
  19760. * MEMO: We've considered some other approaches:
  19761. * 1. Each model handle its self restoration but not uniform treatment.
  19762. * (Too complex in logic and error-prone)
  19763. * 2. Use a shadow ecModel. (Performace expensive)
  19764. */
  19765. function mergeOption(oldOption, newOption) {
  19766. newOption = newOption || {};
  19767. each$4(newOption, function (newCptOpt, mainType) {
  19768. if (newCptOpt == null) {
  19769. return;
  19770. }
  19771. var oldCptOpt = oldOption[mainType];
  19772. if (!ComponentModel.hasClass(mainType)) {
  19773. oldOption[mainType] = merge$1(oldCptOpt, newCptOpt, true);
  19774. }
  19775. else {
  19776. newCptOpt = normalizeToArray(newCptOpt);
  19777. oldCptOpt = normalizeToArray(oldCptOpt);
  19778. var mapResult = mappingToExists(oldCptOpt, newCptOpt);
  19779. oldOption[mainType] = map$1(mapResult, function (item) {
  19780. return (item.option && item.exist)
  19781. ? merge$1(item.exist, item.option, true)
  19782. : (item.exist || item.option);
  19783. });
  19784. }
  19785. });
  19786. }
  19787. /*
  19788. * Licensed to the Apache Software Foundation (ASF) under one
  19789. * or more contributor license agreements. See the NOTICE file
  19790. * distributed with this work for additional information
  19791. * regarding copyright ownership. The ASF licenses this file
  19792. * to you under the Apache License, Version 2.0 (the
  19793. * "License"); you may not use this file except in compliance
  19794. * with the License. You may obtain a copy of the License at
  19795. *
  19796. * http://www.apache.org/licenses/LICENSE-2.0
  19797. *
  19798. * Unless required by applicable law or agreed to in writing,
  19799. * software distributed under the License is distributed on an
  19800. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  19801. * KIND, either express or implied. See the License for the
  19802. * specific language governing permissions and limitations
  19803. * under the License.
  19804. */
  19805. var each$5 = each$1;
  19806. var isObject$3 = isObject$1;
  19807. var POSSIBLE_STYLES = [
  19808. 'areaStyle', 'lineStyle', 'nodeStyle', 'linkStyle',
  19809. 'chordStyle', 'label', 'labelLine'
  19810. ];
  19811. function compatEC2ItemStyle(opt) {
  19812. var itemStyleOpt = opt && opt.itemStyle;
  19813. if (!itemStyleOpt) {
  19814. return;
  19815. }
  19816. for (var i = 0, len = POSSIBLE_STYLES.length; i < len; i++) {
  19817. var styleName = POSSIBLE_STYLES[i];
  19818. var normalItemStyleOpt = itemStyleOpt.normal;
  19819. var emphasisItemStyleOpt = itemStyleOpt.emphasis;
  19820. if (normalItemStyleOpt && normalItemStyleOpt[styleName]) {
  19821. opt[styleName] = opt[styleName] || {};
  19822. if (!opt[styleName].normal) {
  19823. opt[styleName].normal = normalItemStyleOpt[styleName];
  19824. }
  19825. else {
  19826. merge(opt[styleName].normal, normalItemStyleOpt[styleName]);
  19827. }
  19828. normalItemStyleOpt[styleName] = null;
  19829. }
  19830. if (emphasisItemStyleOpt && emphasisItemStyleOpt[styleName]) {
  19831. opt[styleName] = opt[styleName] || {};
  19832. if (!opt[styleName].emphasis) {
  19833. opt[styleName].emphasis = emphasisItemStyleOpt[styleName];
  19834. }
  19835. else {
  19836. merge(opt[styleName].emphasis, emphasisItemStyleOpt[styleName]);
  19837. }
  19838. emphasisItemStyleOpt[styleName] = null;
  19839. }
  19840. }
  19841. }
  19842. function convertNormalEmphasis(opt, optType, useExtend) {
  19843. if (opt && opt[optType] && (opt[optType].normal || opt[optType].emphasis)) {
  19844. var normalOpt = opt[optType].normal;
  19845. var emphasisOpt = opt[optType].emphasis;
  19846. if (normalOpt) {
  19847. // Timeline controlStyle has other properties besides normal and emphasis
  19848. if (useExtend) {
  19849. opt[optType].normal = opt[optType].emphasis = null;
  19850. defaults(opt[optType], normalOpt);
  19851. }
  19852. else {
  19853. opt[optType] = normalOpt;
  19854. }
  19855. }
  19856. if (emphasisOpt) {
  19857. opt.emphasis = opt.emphasis || {};
  19858. opt.emphasis[optType] = emphasisOpt;
  19859. }
  19860. }
  19861. }
  19862. function removeEC3NormalStatus(opt) {
  19863. convertNormalEmphasis(opt, 'itemStyle');
  19864. convertNormalEmphasis(opt, 'lineStyle');
  19865. convertNormalEmphasis(opt, 'areaStyle');
  19866. convertNormalEmphasis(opt, 'label');
  19867. convertNormalEmphasis(opt, 'labelLine');
  19868. // treemap
  19869. convertNormalEmphasis(opt, 'upperLabel');
  19870. // graph
  19871. convertNormalEmphasis(opt, 'edgeLabel');
  19872. }
  19873. function compatTextStyle(opt, propName) {
  19874. // Check whether is not object (string\null\undefined ...)
  19875. var labelOptSingle = isObject$3(opt) && opt[propName];
  19876. var textStyle = isObject$3(labelOptSingle) && labelOptSingle.textStyle;
  19877. if (textStyle) {
  19878. for (var i = 0, len = TEXT_STYLE_OPTIONS.length; i < len; i++) {
  19879. var propName = TEXT_STYLE_OPTIONS[i];
  19880. if (textStyle.hasOwnProperty(propName)) {
  19881. labelOptSingle[propName] = textStyle[propName];
  19882. }
  19883. }
  19884. }
  19885. }
  19886. function compatEC3CommonStyles(opt) {
  19887. if (opt) {
  19888. removeEC3NormalStatus(opt);
  19889. compatTextStyle(opt, 'label');
  19890. opt.emphasis && compatTextStyle(opt.emphasis, 'label');
  19891. }
  19892. }
  19893. function processSeries(seriesOpt) {
  19894. if (!isObject$3(seriesOpt)) {
  19895. return;
  19896. }
  19897. compatEC2ItemStyle(seriesOpt);
  19898. removeEC3NormalStatus(seriesOpt);
  19899. compatTextStyle(seriesOpt, 'label');
  19900. // treemap
  19901. compatTextStyle(seriesOpt, 'upperLabel');
  19902. // graph
  19903. compatTextStyle(seriesOpt, 'edgeLabel');
  19904. if (seriesOpt.emphasis) {
  19905. compatTextStyle(seriesOpt.emphasis, 'label');
  19906. // treemap
  19907. compatTextStyle(seriesOpt.emphasis, 'upperLabel');
  19908. // graph
  19909. compatTextStyle(seriesOpt.emphasis, 'edgeLabel');
  19910. }
  19911. var markPoint = seriesOpt.markPoint;
  19912. if (markPoint) {
  19913. compatEC2ItemStyle(markPoint);
  19914. compatEC3CommonStyles(markPoint);
  19915. }
  19916. var markLine = seriesOpt.markLine;
  19917. if (markLine) {
  19918. compatEC2ItemStyle(markLine);
  19919. compatEC3CommonStyles(markLine);
  19920. }
  19921. var markArea = seriesOpt.markArea;
  19922. if (markArea) {
  19923. compatEC3CommonStyles(markArea);
  19924. }
  19925. var data = seriesOpt.data;
  19926. // Break with ec3: if `setOption` again, there may be no `type` in option,
  19927. // then the backward compat based on option type will not be performed.
  19928. if (seriesOpt.type === 'graph') {
  19929. data = data || seriesOpt.nodes;
  19930. var edgeData = seriesOpt.links || seriesOpt.edges;
  19931. if (edgeData && !isTypedArray(edgeData)) {
  19932. for (var i = 0; i < edgeData.length; i++) {
  19933. compatEC3CommonStyles(edgeData[i]);
  19934. }
  19935. }
  19936. each$1(seriesOpt.categories, function (opt) {
  19937. removeEC3NormalStatus(opt);
  19938. });
  19939. }
  19940. if (data && !isTypedArray(data)) {
  19941. for (var i = 0; i < data.length; i++) {
  19942. compatEC3CommonStyles(data[i]);
  19943. }
  19944. }
  19945. // mark point data
  19946. var markPoint = seriesOpt.markPoint;
  19947. if (markPoint && markPoint.data) {
  19948. var mpData = markPoint.data;
  19949. for (var i = 0; i < mpData.length; i++) {
  19950. compatEC3CommonStyles(mpData[i]);
  19951. }
  19952. }
  19953. // mark line data
  19954. var markLine = seriesOpt.markLine;
  19955. if (markLine && markLine.data) {
  19956. var mlData = markLine.data;
  19957. for (var i = 0; i < mlData.length; i++) {
  19958. if (isArray(mlData[i])) {
  19959. compatEC3CommonStyles(mlData[i][0]);
  19960. compatEC3CommonStyles(mlData[i][1]);
  19961. }
  19962. else {
  19963. compatEC3CommonStyles(mlData[i]);
  19964. }
  19965. }
  19966. }
  19967. // Series
  19968. if (seriesOpt.type === 'gauge') {
  19969. compatTextStyle(seriesOpt, 'axisLabel');
  19970. compatTextStyle(seriesOpt, 'title');
  19971. compatTextStyle(seriesOpt, 'detail');
  19972. }
  19973. else if (seriesOpt.type === 'treemap') {
  19974. convertNormalEmphasis(seriesOpt.breadcrumb, 'itemStyle');
  19975. each$1(seriesOpt.levels, function (opt) {
  19976. removeEC3NormalStatus(opt);
  19977. });
  19978. }
  19979. else if (seriesOpt.type === 'tree') {
  19980. removeEC3NormalStatus(seriesOpt.leaves);
  19981. }
  19982. // sunburst starts from ec4, so it does not need to compat levels.
  19983. }
  19984. function toArr(o) {
  19985. return isArray(o) ? o : o ? [o] : [];
  19986. }
  19987. function toObj(o) {
  19988. return (isArray(o) ? o[0] : o) || {};
  19989. }
  19990. var compatStyle = function (option, isTheme) {
  19991. each$5(toArr(option.series), function (seriesOpt) {
  19992. isObject$3(seriesOpt) && processSeries(seriesOpt);
  19993. });
  19994. var axes = ['xAxis', 'yAxis', 'radiusAxis', 'angleAxis', 'singleAxis', 'parallelAxis', 'radar'];
  19995. isTheme && axes.push('valueAxis', 'categoryAxis', 'logAxis', 'timeAxis');
  19996. each$5(
  19997. axes,
  19998. function (axisName) {
  19999. each$5(toArr(option[axisName]), function (axisOpt) {
  20000. if (axisOpt) {
  20001. compatTextStyle(axisOpt, 'axisLabel');
  20002. compatTextStyle(axisOpt.axisPointer, 'label');
  20003. }
  20004. });
  20005. }
  20006. );
  20007. each$5(toArr(option.parallel), function (parallelOpt) {
  20008. var parallelAxisDefault = parallelOpt && parallelOpt.parallelAxisDefault;
  20009. compatTextStyle(parallelAxisDefault, 'axisLabel');
  20010. compatTextStyle(parallelAxisDefault && parallelAxisDefault.axisPointer, 'label');
  20011. });
  20012. each$5(toArr(option.calendar), function (calendarOpt) {
  20013. convertNormalEmphasis(calendarOpt, 'itemStyle');
  20014. compatTextStyle(calendarOpt, 'dayLabel');
  20015. compatTextStyle(calendarOpt, 'monthLabel');
  20016. compatTextStyle(calendarOpt, 'yearLabel');
  20017. });
  20018. // radar.name.textStyle
  20019. each$5(toArr(option.radar), function (radarOpt) {
  20020. compatTextStyle(radarOpt, 'name');
  20021. });
  20022. each$5(toArr(option.geo), function (geoOpt) {
  20023. if (isObject$3(geoOpt)) {
  20024. compatEC3CommonStyles(geoOpt);
  20025. each$5(toArr(geoOpt.regions), function (regionObj) {
  20026. compatEC3CommonStyles(regionObj);
  20027. });
  20028. }
  20029. });
  20030. each$5(toArr(option.timeline), function (timelineOpt) {
  20031. compatEC3CommonStyles(timelineOpt);
  20032. convertNormalEmphasis(timelineOpt, 'label');
  20033. convertNormalEmphasis(timelineOpt, 'itemStyle');
  20034. convertNormalEmphasis(timelineOpt, 'controlStyle', true);
  20035. var data = timelineOpt.data;
  20036. isArray(data) && each$1(data, function (item) {
  20037. if (isObject$1(item)) {
  20038. convertNormalEmphasis(item, 'label');
  20039. convertNormalEmphasis(item, 'itemStyle');
  20040. }
  20041. });
  20042. });
  20043. each$5(toArr(option.toolbox), function (toolboxOpt) {
  20044. convertNormalEmphasis(toolboxOpt, 'iconStyle');
  20045. each$5(toolboxOpt.feature, function (featureOpt) {
  20046. convertNormalEmphasis(featureOpt, 'iconStyle');
  20047. });
  20048. });
  20049. compatTextStyle(toObj(option.axisPointer), 'label');
  20050. compatTextStyle(toObj(option.tooltip).axisPointer, 'label');
  20051. };
  20052. /*
  20053. * Licensed to the Apache Software Foundation (ASF) under one
  20054. * or more contributor license agreements. See the NOTICE file
  20055. * distributed with this work for additional information
  20056. * regarding copyright ownership. The ASF licenses this file
  20057. * to you under the Apache License, Version 2.0 (the
  20058. * "License"); you may not use this file except in compliance
  20059. * with the License. You may obtain a copy of the License at
  20060. *
  20061. * http://www.apache.org/licenses/LICENSE-2.0
  20062. *
  20063. * Unless required by applicable law or agreed to in writing,
  20064. * software distributed under the License is distributed on an
  20065. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  20066. * KIND, either express or implied. See the License for the
  20067. * specific language governing permissions and limitations
  20068. * under the License.
  20069. */
  20070. // Compatitable with 2.0
  20071. function get(opt, path) {
  20072. path = path.split(',');
  20073. var obj = opt;
  20074. for (var i = 0; i < path.length; i++) {
  20075. obj = obj && obj[path[i]];
  20076. if (obj == null) {
  20077. break;
  20078. }
  20079. }
  20080. return obj;
  20081. }
  20082. function set$1(opt, path, val, overwrite) {
  20083. path = path.split(',');
  20084. var obj = opt;
  20085. var key;
  20086. for (var i = 0; i < path.length - 1; i++) {
  20087. key = path[i];
  20088. if (obj[key] == null) {
  20089. obj[key] = {};
  20090. }
  20091. obj = obj[key];
  20092. }
  20093. if (overwrite || obj[path[i]] == null) {
  20094. obj[path[i]] = val;
  20095. }
  20096. }
  20097. function compatLayoutProperties(option) {
  20098. each$1(LAYOUT_PROPERTIES, function (prop) {
  20099. if (prop[0] in option && !(prop[1] in option)) {
  20100. option[prop[1]] = option[prop[0]];
  20101. }
  20102. });
  20103. }
  20104. var LAYOUT_PROPERTIES = [
  20105. ['x', 'left'], ['y', 'top'], ['x2', 'right'], ['y2', 'bottom']
  20106. ];
  20107. var COMPATITABLE_COMPONENTS = [
  20108. 'grid', 'geo', 'parallel', 'legend', 'toolbox', 'title', 'visualMap', 'dataZoom', 'timeline'
  20109. ];
  20110. var backwardCompat = function (option, isTheme) {
  20111. compatStyle(option, isTheme);
  20112. // Make sure series array for model initialization.
  20113. option.series = normalizeToArray(option.series);
  20114. each$1(option.series, function (seriesOpt) {
  20115. if (!isObject$1(seriesOpt)) {
  20116. return;
  20117. }
  20118. var seriesType = seriesOpt.type;
  20119. if (seriesType === 'pie' || seriesType === 'gauge') {
  20120. if (seriesOpt.clockWise != null) {
  20121. seriesOpt.clockwise = seriesOpt.clockWise;
  20122. }
  20123. }
  20124. if (seriesType === 'gauge') {
  20125. var pointerColor = get(seriesOpt, 'pointer.color');
  20126. pointerColor != null
  20127. && set$1(seriesOpt, 'itemStyle.color', pointerColor);
  20128. }
  20129. compatLayoutProperties(seriesOpt);
  20130. });
  20131. // dataRange has changed to visualMap
  20132. if (option.dataRange) {
  20133. option.visualMap = option.dataRange;
  20134. }
  20135. each$1(COMPATITABLE_COMPONENTS, function (componentName) {
  20136. var options = option[componentName];
  20137. if (options) {
  20138. if (!isArray(options)) {
  20139. options = [options];
  20140. }
  20141. each$1(options, function (option) {
  20142. compatLayoutProperties(option);
  20143. });
  20144. }
  20145. });
  20146. };
  20147. /*
  20148. * Licensed to the Apache Software Foundation (ASF) under one
  20149. * or more contributor license agreements. See the NOTICE file
  20150. * distributed with this work for additional information
  20151. * regarding copyright ownership. The ASF licenses this file
  20152. * to you under the Apache License, Version 2.0 (the
  20153. * "License"); you may not use this file except in compliance
  20154. * with the License. You may obtain a copy of the License at
  20155. *
  20156. * http://www.apache.org/licenses/LICENSE-2.0
  20157. *
  20158. * Unless required by applicable law or agreed to in writing,
  20159. * software distributed under the License is distributed on an
  20160. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  20161. * KIND, either express or implied. See the License for the
  20162. * specific language governing permissions and limitations
  20163. * under the License.
  20164. */
  20165. // (1) [Caution]: the logic is correct based on the premises:
  20166. // data processing stage is blocked in stream.
  20167. // See <module:echarts/stream/Scheduler#performDataProcessorTasks>
  20168. // (2) Only register once when import repeatly.
  20169. // Should be executed before after series filtered and before stack calculation.
  20170. var dataStack = function (ecModel) {
  20171. var stackInfoMap = createHashMap();
  20172. ecModel.eachSeries(function (seriesModel) {
  20173. var stack = seriesModel.get('stack');
  20174. // Compatibal: when `stack` is set as '', do not stack.
  20175. if (stack) {
  20176. var stackInfoList = stackInfoMap.get(stack) || stackInfoMap.set(stack, []);
  20177. var data = seriesModel.getData();
  20178. var stackInfo = {
  20179. // Used for calculate axis extent automatically.
  20180. stackResultDimension: data.getCalculationInfo('stackResultDimension'),
  20181. stackedOverDimension: data.getCalculationInfo('stackedOverDimension'),
  20182. stackedDimension: data.getCalculationInfo('stackedDimension'),
  20183. stackedByDimension: data.getCalculationInfo('stackedByDimension'),
  20184. isStackedByIndex: data.getCalculationInfo('isStackedByIndex'),
  20185. data: data,
  20186. seriesModel: seriesModel
  20187. };
  20188. // If stacked on axis that do not support data stack.
  20189. if (!stackInfo.stackedDimension
  20190. || !(stackInfo.isStackedByIndex || stackInfo.stackedByDimension)
  20191. ) {
  20192. return;
  20193. }
  20194. stackInfoList.length && data.setCalculationInfo(
  20195. 'stackedOnSeries', stackInfoList[stackInfoList.length - 1].seriesModel
  20196. );
  20197. stackInfoList.push(stackInfo);
  20198. }
  20199. });
  20200. stackInfoMap.each(calculateStack);
  20201. };
  20202. function calculateStack(stackInfoList) {
  20203. each$1(stackInfoList, function (targetStackInfo, idxInStack) {
  20204. var resultVal = [];
  20205. var resultNaN = [NaN, NaN];
  20206. var dims = [targetStackInfo.stackResultDimension, targetStackInfo.stackedOverDimension];
  20207. var targetData = targetStackInfo.data;
  20208. var isStackedByIndex = targetStackInfo.isStackedByIndex;
  20209. // Should not write on raw data, because stack series model list changes
  20210. // depending on legend selection.
  20211. var newData = targetData.map(dims, function (v0, v1, dataIndex) {
  20212. var sum = targetData.get(targetStackInfo.stackedDimension, dataIndex);
  20213. // Consider `connectNulls` of line area, if value is NaN, stackedOver
  20214. // should also be NaN, to draw a appropriate belt area.
  20215. if (isNaN(sum)) {
  20216. return resultNaN;
  20217. }
  20218. var byValue;
  20219. var stackedDataRawIndex;
  20220. if (isStackedByIndex) {
  20221. stackedDataRawIndex = targetData.getRawIndex(dataIndex);
  20222. }
  20223. else {
  20224. byValue = targetData.get(targetStackInfo.stackedByDimension, dataIndex);
  20225. }
  20226. // If stackOver is NaN, chart view will render point on value start.
  20227. var stackedOver = NaN;
  20228. for (var j = idxInStack - 1; j >= 0; j--) {
  20229. var stackInfo = stackInfoList[j];
  20230. // Has been optimized by inverted indices on `stackedByDimension`.
  20231. if (!isStackedByIndex) {
  20232. stackedDataRawIndex = stackInfo.data.rawIndexOf(stackInfo.stackedByDimension, byValue);
  20233. }
  20234. if (stackedDataRawIndex >= 0) {
  20235. var val = stackInfo.data.getByRawIndex(stackInfo.stackResultDimension, stackedDataRawIndex);
  20236. // Considering positive stack, negative stack and empty data
  20237. if ((sum >= 0 && val > 0) // Positive stack
  20238. || (sum <= 0 && val < 0) // Negative stack
  20239. ) {
  20240. sum += val;
  20241. stackedOver = val;
  20242. break;
  20243. }
  20244. }
  20245. }
  20246. resultVal[0] = sum;
  20247. resultVal[1] = stackedOver;
  20248. return resultVal;
  20249. });
  20250. targetData.hostModel.setData(newData);
  20251. // Update for consequent calculation
  20252. targetStackInfo.data = newData;
  20253. });
  20254. }
  20255. /*
  20256. * Licensed to the Apache Software Foundation (ASF) under one
  20257. * or more contributor license agreements. See the NOTICE file
  20258. * distributed with this work for additional information
  20259. * regarding copyright ownership. The ASF licenses this file
  20260. * to you under the Apache License, Version 2.0 (the
  20261. * "License"); you may not use this file except in compliance
  20262. * with the License. You may obtain a copy of the License at
  20263. *
  20264. * http://www.apache.org/licenses/LICENSE-2.0
  20265. *
  20266. * Unless required by applicable law or agreed to in writing,
  20267. * software distributed under the License is distributed on an
  20268. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  20269. * KIND, either express or implied. See the License for the
  20270. * specific language governing permissions and limitations
  20271. * under the License.
  20272. */
  20273. // TODO
  20274. // ??? refactor? check the outer usage of data provider.
  20275. // merge with defaultDimValueGetter?
  20276. /**
  20277. * If normal array used, mutable chunk size is supported.
  20278. * If typed array used, chunk size must be fixed.
  20279. */
  20280. function DefaultDataProvider(source, dimSize) {
  20281. if (!Source.isInstance(source)) {
  20282. source = Source.seriesDataToSource(source);
  20283. }
  20284. this._source = source;
  20285. var data = this._data = source.data;
  20286. var sourceFormat = source.sourceFormat;
  20287. // Typed array. TODO IE10+?
  20288. if (sourceFormat === SOURCE_FORMAT_TYPED_ARRAY) {
  20289. if (__DEV__) {
  20290. if (dimSize == null) {
  20291. throw new Error('Typed array data must specify dimension size');
  20292. }
  20293. }
  20294. this._offset = 0;
  20295. this._dimSize = dimSize;
  20296. this._data = data;
  20297. }
  20298. var methods = providerMethods[
  20299. sourceFormat === SOURCE_FORMAT_ARRAY_ROWS
  20300. ? sourceFormat + '_' + source.seriesLayoutBy
  20301. : sourceFormat
  20302. ];
  20303. if (__DEV__) {
  20304. assert$1(methods, 'Invalide sourceFormat: ' + sourceFormat);
  20305. }
  20306. extend(this, methods);
  20307. }
  20308. var providerProto = DefaultDataProvider.prototype;
  20309. // If data is pure without style configuration
  20310. providerProto.pure = false;
  20311. // If data is persistent and will not be released after use.
  20312. providerProto.persistent = true;
  20313. // ???! FIXME legacy data provider do not has method getSource
  20314. providerProto.getSource = function () {
  20315. return this._source;
  20316. };
  20317. var providerMethods = {
  20318. 'arrayRows_column': {
  20319. pure: true,
  20320. count: function () {
  20321. return Math.max(0, this._data.length - this._source.startIndex);
  20322. },
  20323. getItem: function (idx) {
  20324. return this._data[idx + this._source.startIndex];
  20325. },
  20326. appendData: appendDataSimply
  20327. },
  20328. 'arrayRows_row': {
  20329. pure: true,
  20330. count: function () {
  20331. var row = this._data[0];
  20332. return row ? Math.max(0, row.length - this._source.startIndex) : 0;
  20333. },
  20334. getItem: function (idx) {
  20335. idx += this._source.startIndex;
  20336. var item = [];
  20337. var data = this._data;
  20338. for (var i = 0; i < data.length; i++) {
  20339. var row = data[i];
  20340. item.push(row ? row[idx] : null);
  20341. }
  20342. return item;
  20343. },
  20344. appendData: function () {
  20345. throw new Error('Do not support appendData when set seriesLayoutBy: "row".');
  20346. }
  20347. },
  20348. 'objectRows': {
  20349. pure: true,
  20350. count: countSimply,
  20351. getItem: getItemSimply,
  20352. appendData: appendDataSimply
  20353. },
  20354. 'keyedColumns': {
  20355. pure: true,
  20356. count: function () {
  20357. var dimName = this._source.dimensionsDefine[0].name;
  20358. var col = this._data[dimName];
  20359. return col ? col.length : 0;
  20360. },
  20361. getItem: function (idx) {
  20362. var item = [];
  20363. var dims = this._source.dimensionsDefine;
  20364. for (var i = 0; i < dims.length; i++) {
  20365. var col = this._data[dims[i].name];
  20366. item.push(col ? col[idx] : null);
  20367. }
  20368. return item;
  20369. },
  20370. appendData: function (newData) {
  20371. var data = this._data;
  20372. each$1(newData, function (newCol, key) {
  20373. var oldCol = data[key] || (data[key] = []);
  20374. for (var i = 0; i < (newCol || []).length; i++) {
  20375. oldCol.push(newCol[i]);
  20376. }
  20377. });
  20378. }
  20379. },
  20380. 'original': {
  20381. count: countSimply,
  20382. getItem: getItemSimply,
  20383. appendData: appendDataSimply
  20384. },
  20385. 'typedArray': {
  20386. persistent: false,
  20387. pure: true,
  20388. count: function () {
  20389. return this._data ? (this._data.length / this._dimSize) : 0;
  20390. },
  20391. getItem: function (idx, out) {
  20392. idx = idx - this._offset;
  20393. out = out || [];
  20394. var offset = this._dimSize * idx;
  20395. for (var i = 0; i < this._dimSize; i++) {
  20396. out[i] = this._data[offset + i];
  20397. }
  20398. return out;
  20399. },
  20400. appendData: function (newData) {
  20401. if (__DEV__) {
  20402. assert$1(
  20403. isTypedArray(newData),
  20404. 'Added data must be TypedArray if data in initialization is TypedArray'
  20405. );
  20406. }
  20407. this._data = newData;
  20408. },
  20409. // Clean self if data is already used.
  20410. clean: function () {
  20411. // PENDING
  20412. this._offset += this.count();
  20413. this._data = null;
  20414. }
  20415. }
  20416. };
  20417. function countSimply() {
  20418. return this._data.length;
  20419. }
  20420. function getItemSimply(idx) {
  20421. return this._data[idx];
  20422. }
  20423. function appendDataSimply(newData) {
  20424. for (var i = 0; i < newData.length; i++) {
  20425. this._data.push(newData[i]);
  20426. }
  20427. }
  20428. var rawValueGetters = {
  20429. arrayRows: getRawValueSimply,
  20430. objectRows: function (dataItem, dataIndex, dimIndex, dimName) {
  20431. return dimIndex != null ? dataItem[dimName] : dataItem;
  20432. },
  20433. keyedColumns: getRawValueSimply,
  20434. original: function (dataItem, dataIndex, dimIndex, dimName) {
  20435. // FIXME
  20436. // In some case (markpoint in geo (geo-map.html)), dataItem
  20437. // is {coord: [...]}
  20438. var value = getDataItemValue(dataItem);
  20439. return (dimIndex == null || !(value instanceof Array))
  20440. ? value
  20441. : value[dimIndex];
  20442. },
  20443. typedArray: getRawValueSimply
  20444. };
  20445. function getRawValueSimply(dataItem, dataIndex, dimIndex, dimName) {
  20446. return dimIndex != null ? dataItem[dimIndex] : dataItem;
  20447. }
  20448. var defaultDimValueGetters = {
  20449. arrayRows: getDimValueSimply,
  20450. objectRows: function (dataItem, dimName, dataIndex, dimIndex) {
  20451. return converDataValue(dataItem[dimName], this._dimensionInfos[dimName]);
  20452. },
  20453. keyedColumns: getDimValueSimply,
  20454. original: function (dataItem, dimName, dataIndex, dimIndex) {
  20455. // Performance sensitive, do not use modelUtil.getDataItemValue.
  20456. // If dataItem is an plain object with no value field, the var `value`
  20457. // will be assigned with the object, but it will be tread correctly
  20458. // in the `convertDataValue`.
  20459. var value = dataItem && (dataItem.value == null ? dataItem : dataItem.value);
  20460. // If any dataItem is like { value: 10 }
  20461. if (!this._rawData.pure && isDataItemOption(dataItem)) {
  20462. this.hasItemOption = true;
  20463. }
  20464. return converDataValue(
  20465. (value instanceof Array)
  20466. ? value[dimIndex]
  20467. // If value is a single number or something else not array.
  20468. : value,
  20469. this._dimensionInfos[dimName]
  20470. );
  20471. },
  20472. typedArray: function (dataItem, dimName, dataIndex, dimIndex) {
  20473. return dataItem[dimIndex];
  20474. }
  20475. };
  20476. function getDimValueSimply(dataItem, dimName, dataIndex, dimIndex) {
  20477. return converDataValue(dataItem[dimIndex], this._dimensionInfos[dimName]);
  20478. }
  20479. /**
  20480. * This helper method convert value in data.
  20481. * @param {string|number|Date} value
  20482. * @param {Object|string} [dimInfo] If string (like 'x'), dimType defaults 'number'.
  20483. * If "dimInfo.ordinalParseAndSave", ordinal value can be parsed.
  20484. */
  20485. function converDataValue(value, dimInfo) {
  20486. // Performance sensitive.
  20487. var dimType = dimInfo && dimInfo.type;
  20488. if (dimType === 'ordinal') {
  20489. // If given value is a category string
  20490. var ordinalMeta = dimInfo && dimInfo.ordinalMeta;
  20491. return ordinalMeta
  20492. ? ordinalMeta.parseAndCollect(value)
  20493. : value;
  20494. }
  20495. if (dimType === 'time'
  20496. // spead up when using timestamp
  20497. && typeof value !== 'number'
  20498. && value != null
  20499. && value !== '-'
  20500. ) {
  20501. value = +parseDate(value);
  20502. }
  20503. // dimType defaults 'number'.
  20504. // If dimType is not ordinal and value is null or undefined or NaN or '-',
  20505. // parse to NaN.
  20506. return (value == null || value === '')
  20507. ? NaN
  20508. // If string (like '-'), using '+' parse to NaN
  20509. // If object, also parse to NaN
  20510. : +value;
  20511. }
  20512. // ??? FIXME can these logic be more neat: getRawValue, getRawDataItem,
  20513. // Consider persistent.
  20514. // Caution: why use raw value to display on label or tooltip?
  20515. // A reason is to avoid format. For example time value we do not know
  20516. // how to format is expected. More over, if stack is used, calculated
  20517. // value may be 0.91000000001, which have brings trouble to display.
  20518. // TODO: consider how to treat null/undefined/NaN when display?
  20519. /**
  20520. * @param {module:echarts/data/List} data
  20521. * @param {number} dataIndex
  20522. * @param {string|number} [dim] dimName or dimIndex
  20523. * @return {Array.<number>|string|number} can be null/undefined.
  20524. */
  20525. function retrieveRawValue(data, dataIndex, dim) {
  20526. if (!data) {
  20527. return;
  20528. }
  20529. // Consider data may be not persistent.
  20530. var dataItem = data.getRawDataItem(dataIndex);
  20531. if (dataItem == null) {
  20532. return;
  20533. }
  20534. var sourceFormat = data.getProvider().getSource().sourceFormat;
  20535. var dimName;
  20536. var dimIndex;
  20537. var dimInfo = data.getDimensionInfo(dim);
  20538. if (dimInfo) {
  20539. dimName = dimInfo.name;
  20540. dimIndex = dimInfo.index;
  20541. }
  20542. return rawValueGetters[sourceFormat](dataItem, dataIndex, dimIndex, dimName);
  20543. }
  20544. /**
  20545. * Compatible with some cases (in pie, map) like:
  20546. * data: [{name: 'xx', value: 5, selected: true}, ...]
  20547. * where only sourceFormat is 'original' and 'objectRows' supported.
  20548. *
  20549. * ??? TODO
  20550. * Supported detail options in data item when using 'arrayRows'.
  20551. *
  20552. * @param {module:echarts/data/List} data
  20553. * @param {number} dataIndex
  20554. * @param {string} attr like 'selected'
  20555. */
  20556. function retrieveRawAttr(data, dataIndex, attr) {
  20557. if (!data) {
  20558. return;
  20559. }
  20560. var sourceFormat = data.getProvider().getSource().sourceFormat;
  20561. if (sourceFormat !== SOURCE_FORMAT_ORIGINAL
  20562. && sourceFormat !== SOURCE_FORMAT_OBJECT_ROWS
  20563. ) {
  20564. return;
  20565. }
  20566. var dataItem = data.getRawDataItem(dataIndex);
  20567. if (sourceFormat === SOURCE_FORMAT_ORIGINAL && !isObject$1(dataItem)) {
  20568. dataItem = null;
  20569. }
  20570. if (dataItem) {
  20571. return dataItem[attr];
  20572. }
  20573. }
  20574. /*
  20575. * Licensed to the Apache Software Foundation (ASF) under one
  20576. * or more contributor license agreements. See the NOTICE file
  20577. * distributed with this work for additional information
  20578. * regarding copyright ownership. The ASF licenses this file
  20579. * to you under the Apache License, Version 2.0 (the
  20580. * "License"); you may not use this file except in compliance
  20581. * with the License. You may obtain a copy of the License at
  20582. *
  20583. * http://www.apache.org/licenses/LICENSE-2.0
  20584. *
  20585. * Unless required by applicable law or agreed to in writing,
  20586. * software distributed under the License is distributed on an
  20587. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  20588. * KIND, either express or implied. See the License for the
  20589. * specific language governing permissions and limitations
  20590. * under the License.
  20591. */
  20592. var DIMENSION_LABEL_REG = /\{@(.+?)\}/g;
  20593. // PENDING A little ugly
  20594. var dataFormatMixin = {
  20595. /**
  20596. * Get params for formatter
  20597. * @param {number} dataIndex
  20598. * @param {string} [dataType]
  20599. * @return {Object}
  20600. */
  20601. getDataParams: function (dataIndex, dataType) {
  20602. var data = this.getData(dataType);
  20603. var rawValue = this.getRawValue(dataIndex, dataType);
  20604. var rawDataIndex = data.getRawIndex(dataIndex);
  20605. var name = data.getName(dataIndex);
  20606. var itemOpt = data.getRawDataItem(dataIndex);
  20607. var color = data.getItemVisual(dataIndex, 'color');
  20608. var tooltipModel = this.ecModel.getComponent('tooltip');
  20609. var renderModeOption = tooltipModel && tooltipModel.get('renderMode');
  20610. var renderMode = getTooltipRenderMode(renderModeOption);
  20611. var mainType = this.mainType;
  20612. var isSeries = mainType === 'series';
  20613. var userOutput = data.userOutput;
  20614. return {
  20615. componentType: mainType,
  20616. componentSubType: this.subType,
  20617. componentIndex: this.componentIndex,
  20618. seriesType: isSeries ? this.subType : null,
  20619. seriesIndex: this.seriesIndex,
  20620. seriesId: isSeries ? this.id : null,
  20621. seriesName: isSeries ? this.name : null,
  20622. name: name,
  20623. dataIndex: rawDataIndex,
  20624. data: itemOpt,
  20625. dataType: dataType,
  20626. value: rawValue,
  20627. color: color,
  20628. dimensionNames: userOutput ? userOutput.dimensionNames : null,
  20629. encode: userOutput ? userOutput.encode : null,
  20630. marker: getTooltipMarker({
  20631. color: color,
  20632. renderMode: renderMode
  20633. }),
  20634. // Param name list for mapping `a`, `b`, `c`, `d`, `e`
  20635. $vars: ['seriesName', 'name', 'value']
  20636. };
  20637. },
  20638. /**
  20639. * Format label
  20640. * @param {number} dataIndex
  20641. * @param {string} [status='normal'] 'normal' or 'emphasis'
  20642. * @param {string} [dataType]
  20643. * @param {number} [dimIndex] Only used in some chart that
  20644. * use formatter in different dimensions, like radar.
  20645. * @param {string} [labelProp='label']
  20646. * @return {string} If not formatter, return null/undefined
  20647. */
  20648. getFormattedLabel: function (dataIndex, status, dataType, dimIndex, labelProp) {
  20649. status = status || 'normal';
  20650. var data = this.getData(dataType);
  20651. var itemModel = data.getItemModel(dataIndex);
  20652. var params = this.getDataParams(dataIndex, dataType);
  20653. if (dimIndex != null && (params.value instanceof Array)) {
  20654. params.value = params.value[dimIndex];
  20655. }
  20656. var formatter = itemModel.get(
  20657. status === 'normal'
  20658. ? [labelProp || 'label', 'formatter']
  20659. : [status, labelProp || 'label', 'formatter']
  20660. );
  20661. if (typeof formatter === 'function') {
  20662. params.status = status;
  20663. params.dimensionIndex = dimIndex;
  20664. return formatter(params);
  20665. }
  20666. else if (typeof formatter === 'string') {
  20667. var str = formatTpl(formatter, params);
  20668. // Support 'aaa{@[3]}bbb{@product}ccc'.
  20669. // Do not support '}' in dim name util have to.
  20670. return str.replace(DIMENSION_LABEL_REG, function (origin, dim) {
  20671. var len = dim.length;
  20672. if (dim.charAt(0) === '[' && dim.charAt(len - 1) === ']') {
  20673. dim = +dim.slice(1, len - 1); // Also: '[]' => 0
  20674. }
  20675. return retrieveRawValue(data, dataIndex, dim);
  20676. });
  20677. }
  20678. },
  20679. /**
  20680. * Get raw value in option
  20681. * @param {number} idx
  20682. * @param {string} [dataType]
  20683. * @return {Array|number|string}
  20684. */
  20685. getRawValue: function (idx, dataType) {
  20686. return retrieveRawValue(this.getData(dataType), idx);
  20687. },
  20688. /**
  20689. * Should be implemented.
  20690. * @param {number} dataIndex
  20691. * @param {boolean} [multipleSeries=false]
  20692. * @param {number} [dataType]
  20693. * @return {string} tooltip string
  20694. */
  20695. formatTooltip: function () {
  20696. // Empty function
  20697. }
  20698. };
  20699. /*
  20700. * Licensed to the Apache Software Foundation (ASF) under one
  20701. * or more contributor license agreements. See the NOTICE file
  20702. * distributed with this work for additional information
  20703. * regarding copyright ownership. The ASF licenses this file
  20704. * to you under the Apache License, Version 2.0 (the
  20705. * "License"); you may not use this file except in compliance
  20706. * with the License. You may obtain a copy of the License at
  20707. *
  20708. * http://www.apache.org/licenses/LICENSE-2.0
  20709. *
  20710. * Unless required by applicable law or agreed to in writing,
  20711. * software distributed under the License is distributed on an
  20712. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  20713. * KIND, either express or implied. See the License for the
  20714. * specific language governing permissions and limitations
  20715. * under the License.
  20716. */
  20717. /**
  20718. * @param {Object} define
  20719. * @return See the return of `createTask`.
  20720. */
  20721. function createTask(define) {
  20722. return new Task(define);
  20723. }
  20724. /**
  20725. * @constructor
  20726. * @param {Object} define
  20727. * @param {Function} define.reset Custom reset
  20728. * @param {Function} [define.plan] Returns 'reset' indicate reset immediately.
  20729. * @param {Function} [define.count] count is used to determin data task.
  20730. * @param {Function} [define.onDirty] count is used to determin data task.
  20731. */
  20732. function Task(define) {
  20733. define = define || {};
  20734. this._reset = define.reset;
  20735. this._plan = define.plan;
  20736. this._count = define.count;
  20737. this._onDirty = define.onDirty;
  20738. this._dirty = true;
  20739. // Context must be specified implicitly, to
  20740. // avoid miss update context when model changed.
  20741. this.context;
  20742. }
  20743. var taskProto = Task.prototype;
  20744. /**
  20745. * @param {Object} performArgs
  20746. * @param {number} [performArgs.step] Specified step.
  20747. * @param {number} [performArgs.skip] Skip customer perform call.
  20748. * @param {number} [performArgs.modBy] Sampling window size.
  20749. * @param {number} [performArgs.modDataCount] Sampling count.
  20750. */
  20751. taskProto.perform = function (performArgs) {
  20752. var upTask = this._upstream;
  20753. var skip = performArgs && performArgs.skip;
  20754. // TODO some refactor.
  20755. // Pull data. Must pull data each time, because context.data
  20756. // may be updated by Series.setData.
  20757. if (this._dirty && upTask) {
  20758. var context = this.context;
  20759. context.data = context.outputData = upTask.context.outputData;
  20760. }
  20761. if (this.__pipeline) {
  20762. this.__pipeline.currentTask = this;
  20763. }
  20764. var planResult;
  20765. if (this._plan && !skip) {
  20766. planResult = this._plan(this.context);
  20767. }
  20768. // Support sharding by mod, which changes the render sequence and makes the rendered graphic
  20769. // elements uniformed distributed when progress, especially when moving or zooming.
  20770. var lastModBy = normalizeModBy(this._modBy);
  20771. var lastModDataCount = this._modDataCount || 0;
  20772. var modBy = normalizeModBy(performArgs && performArgs.modBy);
  20773. var modDataCount = performArgs && performArgs.modDataCount || 0;
  20774. if (lastModBy !== modBy || lastModDataCount !== modDataCount) {
  20775. planResult = 'reset';
  20776. }
  20777. function normalizeModBy(val) {
  20778. !(val >= 1) && (val = 1); // jshint ignore:line
  20779. return val;
  20780. }
  20781. var forceFirstProgress;
  20782. if (this._dirty || planResult === 'reset') {
  20783. this._dirty = false;
  20784. forceFirstProgress = reset(this, skip);
  20785. }
  20786. this._modBy = modBy;
  20787. this._modDataCount = modDataCount;
  20788. var step = performArgs && performArgs.step;
  20789. if (upTask) {
  20790. if (__DEV__) {
  20791. assert$1(upTask._outputDueEnd != null);
  20792. }
  20793. this._dueEnd = upTask._outputDueEnd;
  20794. }
  20795. // DataTask or overallTask
  20796. else {
  20797. if (__DEV__) {
  20798. assert$1(!this._progress || this._count);
  20799. }
  20800. this._dueEnd = this._count ? this._count(this.context) : Infinity;
  20801. }
  20802. // Note: Stubs, that its host overall task let it has progress, has progress.
  20803. // If no progress, pass index from upstream to downstream each time plan called.
  20804. if (this._progress) {
  20805. var start = this._dueIndex;
  20806. var end = Math.min(
  20807. step != null ? this._dueIndex + step : Infinity,
  20808. this._dueEnd
  20809. );
  20810. if (!skip && (forceFirstProgress || start < end)) {
  20811. var progress = this._progress;
  20812. if (isArray(progress)) {
  20813. for (var i = 0; i < progress.length; i++) {
  20814. doProgress(this, progress[i], start, end, modBy, modDataCount);
  20815. }
  20816. }
  20817. else {
  20818. doProgress(this, progress, start, end, modBy, modDataCount);
  20819. }
  20820. }
  20821. this._dueIndex = end;
  20822. // If no `outputDueEnd`, assume that output data and
  20823. // input data is the same, so use `dueIndex` as `outputDueEnd`.
  20824. var outputDueEnd = this._settedOutputEnd != null
  20825. ? this._settedOutputEnd : end;
  20826. if (__DEV__) {
  20827. // ??? Can not rollback.
  20828. assert$1(outputDueEnd >= this._outputDueEnd);
  20829. }
  20830. this._outputDueEnd = outputDueEnd;
  20831. }
  20832. else {
  20833. // (1) Some overall task has no progress.
  20834. // (2) Stubs, that its host overall task do not let it has progress, has no progress.
  20835. // This should always be performed so it can be passed to downstream.
  20836. this._dueIndex = this._outputDueEnd = this._settedOutputEnd != null
  20837. ? this._settedOutputEnd : this._dueEnd;
  20838. }
  20839. return this.unfinished();
  20840. };
  20841. var iterator = (function () {
  20842. var end;
  20843. var current;
  20844. var modBy;
  20845. var modDataCount;
  20846. var winCount;
  20847. var it = {
  20848. reset: function (s, e, sStep, sCount) {
  20849. current = s;
  20850. end = e;
  20851. modBy = sStep;
  20852. modDataCount = sCount;
  20853. winCount = Math.ceil(modDataCount / modBy);
  20854. it.next = (modBy > 1 && modDataCount > 0) ? modNext : sequentialNext;
  20855. }
  20856. };
  20857. return it;
  20858. function sequentialNext() {
  20859. return current < end ? current++ : null;
  20860. }
  20861. function modNext() {
  20862. var dataIndex = (current % winCount) * modBy + Math.ceil(current / winCount);
  20863. var result = current >= end
  20864. ? null
  20865. : dataIndex < modDataCount
  20866. ? dataIndex
  20867. // If modDataCount is smaller than data.count() (consider `appendData` case),
  20868. // Use normal linear rendering mode.
  20869. : current;
  20870. current++;
  20871. return result;
  20872. }
  20873. })();
  20874. taskProto.dirty = function () {
  20875. this._dirty = true;
  20876. this._onDirty && this._onDirty(this.context);
  20877. };
  20878. function doProgress(taskIns, progress, start, end, modBy, modDataCount) {
  20879. iterator.reset(start, end, modBy, modDataCount);
  20880. taskIns._callingProgress = progress;
  20881. taskIns._callingProgress({
  20882. start: start, end: end, count: end - start, next: iterator.next
  20883. }, taskIns.context);
  20884. }
  20885. function reset(taskIns, skip) {
  20886. taskIns._dueIndex = taskIns._outputDueEnd = taskIns._dueEnd = 0;
  20887. taskIns._settedOutputEnd = null;
  20888. var progress;
  20889. var forceFirstProgress;
  20890. if (!skip && taskIns._reset) {
  20891. progress = taskIns._reset(taskIns.context);
  20892. if (progress && progress.progress) {
  20893. forceFirstProgress = progress.forceFirstProgress;
  20894. progress = progress.progress;
  20895. }
  20896. // To simplify no progress checking, array must has item.
  20897. if (isArray(progress) && !progress.length) {
  20898. progress = null;
  20899. }
  20900. }
  20901. taskIns._progress = progress;
  20902. taskIns._modBy = taskIns._modDataCount = null;
  20903. var downstream = taskIns._downstream;
  20904. downstream && downstream.dirty();
  20905. return forceFirstProgress;
  20906. }
  20907. /**
  20908. * @return {boolean}
  20909. */
  20910. taskProto.unfinished = function () {
  20911. return this._progress && this._dueIndex < this._dueEnd;
  20912. };
  20913. /**
  20914. * @param {Object} downTask The downstream task.
  20915. * @return {Object} The downstream task.
  20916. */
  20917. taskProto.pipe = function (downTask) {
  20918. if (__DEV__) {
  20919. assert$1(downTask && !downTask._disposed && downTask !== this);
  20920. }
  20921. // If already downstream, do not dirty downTask.
  20922. if (this._downstream !== downTask || this._dirty) {
  20923. this._downstream = downTask;
  20924. downTask._upstream = this;
  20925. downTask.dirty();
  20926. }
  20927. };
  20928. taskProto.dispose = function () {
  20929. if (this._disposed) {
  20930. return;
  20931. }
  20932. this._upstream && (this._upstream._downstream = null);
  20933. this._downstream && (this._downstream._upstream = null);
  20934. this._dirty = false;
  20935. this._disposed = true;
  20936. };
  20937. taskProto.getUpstream = function () {
  20938. return this._upstream;
  20939. };
  20940. taskProto.getDownstream = function () {
  20941. return this._downstream;
  20942. };
  20943. taskProto.setOutputEnd = function (end) {
  20944. // This only happend in dataTask, dataZoom, map, currently.
  20945. // where dataZoom do not set end each time, but only set
  20946. // when reset. So we should record the setted end, in case
  20947. // that the stub of dataZoom perform again and earse the
  20948. // setted end by upstream.
  20949. this._outputDueEnd = this._settedOutputEnd = end;
  20950. };
  20951. ///////////////////////////////////////////////////////////
  20952. // For stream debug (Should be commented out after used!)
  20953. // Usage: printTask(this, 'begin');
  20954. // Usage: printTask(this, null, {someExtraProp});
  20955. // function printTask(task, prefix, extra) {
  20956. // window.ecTaskUID == null && (window.ecTaskUID = 0);
  20957. // task.uidDebug == null && (task.uidDebug = `task_${window.ecTaskUID++}`);
  20958. // task.agent && task.agent.uidDebug == null && (task.agent.uidDebug = `task_${window.ecTaskUID++}`);
  20959. // var props = [];
  20960. // if (task.__pipeline) {
  20961. // var val = `${task.__idxInPipeline}/${task.__pipeline.tail.__idxInPipeline} ${task.agent ? '(stub)' : ''}`;
  20962. // props.push({text: 'idx', value: val});
  20963. // } else {
  20964. // var stubCount = 0;
  20965. // task.agentStubMap.each(() => stubCount++);
  20966. // props.push({text: 'idx', value: `overall (stubs: ${stubCount})`});
  20967. // }
  20968. // props.push({text: 'uid', value: task.uidDebug});
  20969. // if (task.__pipeline) {
  20970. // props.push({text: 'pid', value: task.__pipeline.id});
  20971. // task.agent && props.push(
  20972. // {text: 'stubFor', value: task.agent.uidDebug}
  20973. // );
  20974. // }
  20975. // props.push(
  20976. // {text: 'dirty', value: task._dirty},
  20977. // {text: 'dueIndex', value: task._dueIndex},
  20978. // {text: 'dueEnd', value: task._dueEnd},
  20979. // {text: 'outputDueEnd', value: task._outputDueEnd}
  20980. // );
  20981. // if (extra) {
  20982. // Object.keys(extra).forEach(key => {
  20983. // props.push({text: key, value: extra[key]});
  20984. // });
  20985. // }
  20986. // var args = ['color: blue'];
  20987. // var msg = `%c[${prefix || 'T'}] %c` + props.map(item => (
  20988. // args.push('color: black', 'color: red'),
  20989. // `${item.text}: %c${item.value}`
  20990. // )).join('%c, ');
  20991. // console.log.apply(console, [msg].concat(args));
  20992. // // console.log(this);
  20993. // }
  20994. /*
  20995. * Licensed to the Apache Software Foundation (ASF) under one
  20996. * or more contributor license agreements. See the NOTICE file
  20997. * distributed with this work for additional information
  20998. * regarding copyright ownership. The ASF licenses this file
  20999. * to you under the Apache License, Version 2.0 (the
  21000. * "License"); you may not use this file except in compliance
  21001. * with the License. You may obtain a copy of the License at
  21002. *
  21003. * http://www.apache.org/licenses/LICENSE-2.0
  21004. *
  21005. * Unless required by applicable law or agreed to in writing,
  21006. * software distributed under the License is distributed on an
  21007. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  21008. * KIND, either express or implied. See the License for the
  21009. * specific language governing permissions and limitations
  21010. * under the License.
  21011. */
  21012. var inner$4 = makeInner();
  21013. var SeriesModel = ComponentModel.extend({
  21014. type: 'series.__base__',
  21015. /**
  21016. * @readOnly
  21017. */
  21018. seriesIndex: 0,
  21019. // coodinateSystem will be injected in the echarts/CoordinateSystem
  21020. coordinateSystem: null,
  21021. /**
  21022. * @type {Object}
  21023. * @protected
  21024. */
  21025. defaultOption: null,
  21026. /**
  21027. * Data provided for legend
  21028. * @type {Function}
  21029. */
  21030. // PENDING
  21031. legendDataProvider: null,
  21032. /**
  21033. * Access path of color for visual
  21034. */
  21035. visualColorAccessPath: 'itemStyle.color',
  21036. /**
  21037. * Support merge layout params.
  21038. * Only support 'box' now (left/right/top/bottom/width/height).
  21039. * @type {string|Object} Object can be {ignoreSize: true}
  21040. * @readOnly
  21041. */
  21042. layoutMode: null,
  21043. init: function (option, parentModel, ecModel, extraOpt) {
  21044. /**
  21045. * @type {number}
  21046. * @readOnly
  21047. */
  21048. this.seriesIndex = this.componentIndex;
  21049. this.dataTask = createTask({
  21050. count: dataTaskCount,
  21051. reset: dataTaskReset
  21052. });
  21053. this.dataTask.context = {model: this};
  21054. this.mergeDefaultAndTheme(option, ecModel);
  21055. prepareSource(this);
  21056. var data = this.getInitialData(option, ecModel);
  21057. wrapData(data, this);
  21058. this.dataTask.context.data = data;
  21059. if (__DEV__) {
  21060. assert$1(data, 'getInitialData returned invalid data.');
  21061. }
  21062. /**
  21063. * @type {module:echarts/data/List|module:echarts/data/Tree|module:echarts/data/Graph}
  21064. * @private
  21065. */
  21066. inner$4(this).dataBeforeProcessed = data;
  21067. // If we reverse the order (make data firstly, and then make
  21068. // dataBeforeProcessed by cloneShallow), cloneShallow will
  21069. // cause data.graph.data !== data when using
  21070. // module:echarts/data/Graph or module:echarts/data/Tree.
  21071. // See module:echarts/data/helper/linkList
  21072. // Theoretically, it is unreasonable to call `seriesModel.getData()` in the model
  21073. // init or merge stage, because the data can be restored. So we do not `restoreData`
  21074. // and `setData` here, which forbids calling `seriesModel.getData()` in this stage.
  21075. // Call `seriesModel.getRawData()` instead.
  21076. // this.restoreData();
  21077. autoSeriesName(this);
  21078. },
  21079. /**
  21080. * Util for merge default and theme to option
  21081. * @param {Object} option
  21082. * @param {module:echarts/model/Global} ecModel
  21083. */
  21084. mergeDefaultAndTheme: function (option, ecModel) {
  21085. var layoutMode = this.layoutMode;
  21086. var inputPositionParams = layoutMode
  21087. ? getLayoutParams(option) : {};
  21088. // Backward compat: using subType on theme.
  21089. // But if name duplicate between series subType
  21090. // (for example: parallel) add component mainType,
  21091. // add suffix 'Series'.
  21092. var themeSubType = this.subType;
  21093. if (ComponentModel.hasClass(themeSubType)) {
  21094. themeSubType += 'Series';
  21095. }
  21096. merge(
  21097. option,
  21098. ecModel.getTheme().get(this.subType)
  21099. );
  21100. merge(option, this.getDefaultOption());
  21101. // Default label emphasis `show`
  21102. defaultEmphasis(option, 'label', ['show']);
  21103. this.fillDataTextStyle(option.data);
  21104. if (layoutMode) {
  21105. mergeLayoutParam(option, inputPositionParams, layoutMode);
  21106. }
  21107. },
  21108. mergeOption: function (newSeriesOption, ecModel) {
  21109. // this.settingTask.dirty();
  21110. newSeriesOption = merge(this.option, newSeriesOption, true);
  21111. this.fillDataTextStyle(newSeriesOption.data);
  21112. var layoutMode = this.layoutMode;
  21113. if (layoutMode) {
  21114. mergeLayoutParam(this.option, newSeriesOption, layoutMode);
  21115. }
  21116. prepareSource(this);
  21117. var data = this.getInitialData(newSeriesOption, ecModel);
  21118. wrapData(data, this);
  21119. this.dataTask.dirty();
  21120. this.dataTask.context.data = data;
  21121. inner$4(this).dataBeforeProcessed = data;
  21122. autoSeriesName(this);
  21123. },
  21124. fillDataTextStyle: function (data) {
  21125. // Default data label emphasis `show`
  21126. // FIXME Tree structure data ?
  21127. // FIXME Performance ?
  21128. if (data && !isTypedArray(data)) {
  21129. var props = ['show'];
  21130. for (var i = 0; i < data.length; i++) {
  21131. if (data[i] && data[i].label) {
  21132. defaultEmphasis(data[i], 'label', props);
  21133. }
  21134. }
  21135. }
  21136. },
  21137. /**
  21138. * Init a data structure from data related option in series
  21139. * Must be overwritten
  21140. */
  21141. getInitialData: function () {},
  21142. /**
  21143. * Append data to list
  21144. * @param {Object} params
  21145. * @param {Array|TypedArray} params.data
  21146. */
  21147. appendData: function (params) {
  21148. // FIXME ???
  21149. // (1) If data from dataset, forbidden append.
  21150. // (2) support append data of dataset.
  21151. var data = this.getRawData();
  21152. data.appendData(params.data);
  21153. },
  21154. /**
  21155. * Consider some method like `filter`, `map` need make new data,
  21156. * We should make sure that `seriesModel.getData()` get correct
  21157. * data in the stream procedure. So we fetch data from upstream
  21158. * each time `task.perform` called.
  21159. * @param {string} [dataType]
  21160. * @return {module:echarts/data/List}
  21161. */
  21162. getData: function (dataType) {
  21163. var task = getCurrentTask(this);
  21164. if (task) {
  21165. var data = task.context.data;
  21166. return dataType == null ? data : data.getLinkedData(dataType);
  21167. }
  21168. else {
  21169. // When series is not alive (that may happen when click toolbox
  21170. // restore or setOption with not merge mode), series data may
  21171. // be still need to judge animation or something when graphic
  21172. // elements want to know whether fade out.
  21173. return inner$4(this).data;
  21174. }
  21175. },
  21176. /**
  21177. * @param {module:echarts/data/List} data
  21178. */
  21179. setData: function (data) {
  21180. var task = getCurrentTask(this);
  21181. if (task) {
  21182. var context = task.context;
  21183. // Consider case: filter, data sample.
  21184. if (context.data !== data && task.modifyOutputEnd) {
  21185. task.setOutputEnd(data.count());
  21186. }
  21187. context.outputData = data;
  21188. // Caution: setData should update context.data,
  21189. // Because getData may be called multiply in a
  21190. // single stage and expect to get the data just
  21191. // set. (For example, AxisProxy, x y both call
  21192. // getData and setDate sequentially).
  21193. // So the context.data should be fetched from
  21194. // upstream each time when a stage starts to be
  21195. // performed.
  21196. if (task !== this.dataTask) {
  21197. context.data = data;
  21198. }
  21199. }
  21200. inner$4(this).data = data;
  21201. },
  21202. /**
  21203. * @see {module:echarts/data/helper/sourceHelper#getSource}
  21204. * @return {module:echarts/data/Source} source
  21205. */
  21206. getSource: function () {
  21207. return getSource(this);
  21208. },
  21209. /**
  21210. * Get data before processed
  21211. * @return {module:echarts/data/List}
  21212. */
  21213. getRawData: function () {
  21214. return inner$4(this).dataBeforeProcessed;
  21215. },
  21216. /**
  21217. * Get base axis if has coordinate system and has axis.
  21218. * By default use coordSys.getBaseAxis();
  21219. * Can be overrided for some chart.
  21220. * @return {type} description
  21221. */
  21222. getBaseAxis: function () {
  21223. var coordSys = this.coordinateSystem;
  21224. return coordSys && coordSys.getBaseAxis && coordSys.getBaseAxis();
  21225. },
  21226. // FIXME
  21227. /**
  21228. * Default tooltip formatter
  21229. *
  21230. * @param {number} dataIndex
  21231. * @param {boolean} [multipleSeries=false]
  21232. * @param {number} [dataType]
  21233. * @param {string} [renderMode='html'] valid values: 'html' and 'richText'.
  21234. * 'html' is used for rendering tooltip in extra DOM form, and the result
  21235. * string is used as DOM HTML content.
  21236. * 'richText' is used for rendering tooltip in rich text form, for those where
  21237. * DOM operation is not supported.
  21238. * @return {Object} formatted tooltip with `html` and `markers`
  21239. */
  21240. formatTooltip: function (dataIndex, multipleSeries, dataType, renderMode) {
  21241. var series = this;
  21242. renderMode = renderMode || 'html';
  21243. var newLine = renderMode === 'html' ? '<br/>' : '\n';
  21244. var isRichText = renderMode === 'richText';
  21245. var markers = {};
  21246. var markerId = 0;
  21247. function formatArrayValue(value) {
  21248. // ??? TODO refactor these logic.
  21249. // check: category-no-encode-has-axis-data in dataset.html
  21250. var vertially = reduce(value, function (vertially, val, idx) {
  21251. var dimItem = data.getDimensionInfo(idx);
  21252. return vertially |= dimItem && dimItem.tooltip !== false && dimItem.displayName != null;
  21253. }, 0);
  21254. var result = [];
  21255. tooltipDims.length
  21256. ? each$1(tooltipDims, function (dim) {
  21257. setEachItem(retrieveRawValue(data, dataIndex, dim), dim);
  21258. })
  21259. // By default, all dims is used on tooltip.
  21260. : each$1(value, setEachItem);
  21261. function setEachItem(val, dim) {
  21262. var dimInfo = data.getDimensionInfo(dim);
  21263. // If `dimInfo.tooltip` is not set, show tooltip.
  21264. if (!dimInfo || dimInfo.otherDims.tooltip === false) {
  21265. return;
  21266. }
  21267. var dimType = dimInfo.type;
  21268. var markName = 'sub' + series.seriesIndex + 'at' + markerId;
  21269. var dimHead = getTooltipMarker({
  21270. color: color,
  21271. type: 'subItem',
  21272. renderMode: renderMode,
  21273. markerId: markName
  21274. });
  21275. var dimHeadStr = typeof dimHead === 'string' ? dimHead : dimHead.content;
  21276. var valStr = (vertially
  21277. ? dimHeadStr + encodeHTML(dimInfo.displayName || '-') + ': '
  21278. : ''
  21279. )
  21280. // FIXME should not format time for raw data?
  21281. + encodeHTML(dimType === 'ordinal'
  21282. ? val + ''
  21283. : dimType === 'time'
  21284. ? (multipleSeries ? '' : formatTime('yyyy/MM/dd hh:mm:ss', val))
  21285. : addCommas(val)
  21286. );
  21287. valStr && result.push(valStr);
  21288. if (isRichText) {
  21289. markers[markName] = color;
  21290. ++markerId;
  21291. }
  21292. }
  21293. var newLine = vertially ? (isRichText ? '\n' : '<br/>') : '';
  21294. var content = newLine + result.join(newLine || ', ');
  21295. return {
  21296. renderMode: renderMode,
  21297. content: content,
  21298. style: markers
  21299. };
  21300. }
  21301. function formatSingleValue(val) {
  21302. // return encodeHTML(addCommas(val));
  21303. return {
  21304. renderMode: renderMode,
  21305. content: encodeHTML(addCommas(val)),
  21306. style: markers
  21307. };
  21308. }
  21309. var data = this.getData();
  21310. var tooltipDims = data.mapDimension('defaultedTooltip', true);
  21311. var tooltipDimLen = tooltipDims.length;
  21312. var value = this.getRawValue(dataIndex);
  21313. var isValueArr = isArray(value);
  21314. var color = data.getItemVisual(dataIndex, 'color');
  21315. if (isObject$1(color) && color.colorStops) {
  21316. color = (color.colorStops[0] || {}).color;
  21317. }
  21318. color = color || 'transparent';
  21319. // Complicated rule for pretty tooltip.
  21320. var formattedValue = (tooltipDimLen > 1 || (isValueArr && !tooltipDimLen))
  21321. ? formatArrayValue(value)
  21322. : tooltipDimLen
  21323. ? formatSingleValue(retrieveRawValue(data, dataIndex, tooltipDims[0]))
  21324. : formatSingleValue(isValueArr ? value[0] : value);
  21325. var content = formattedValue.content;
  21326. var markName = series.seriesIndex + 'at' + markerId;
  21327. var colorEl = getTooltipMarker({
  21328. color: color,
  21329. type: 'item',
  21330. renderMode: renderMode,
  21331. markerId: markName
  21332. });
  21333. markers[markName] = color;
  21334. ++markerId;
  21335. var name = data.getName(dataIndex);
  21336. var seriesName = this.name;
  21337. if (!isNameSpecified(this)) {
  21338. seriesName = '';
  21339. }
  21340. seriesName = seriesName
  21341. ? encodeHTML(seriesName) + (!multipleSeries ? newLine : ': ')
  21342. : '';
  21343. var colorStr = typeof colorEl === 'string' ? colorEl : colorEl.content;
  21344. var html = !multipleSeries
  21345. ? seriesName + colorStr
  21346. + (name
  21347. ? encodeHTML(name) + ': ' + content
  21348. : content
  21349. )
  21350. : colorStr + seriesName + content;
  21351. return {
  21352. html: html,
  21353. markers: markers
  21354. };
  21355. },
  21356. /**
  21357. * @return {boolean}
  21358. */
  21359. isAnimationEnabled: function () {
  21360. if (env$1.node) {
  21361. return false;
  21362. }
  21363. var animationEnabled = this.getShallow('animation');
  21364. if (animationEnabled) {
  21365. if (this.getData().count() > this.getShallow('animationThreshold')) {
  21366. animationEnabled = false;
  21367. }
  21368. }
  21369. return animationEnabled;
  21370. },
  21371. restoreData: function () {
  21372. this.dataTask.dirty();
  21373. },
  21374. getColorFromPalette: function (name, scope, requestColorNum) {
  21375. var ecModel = this.ecModel;
  21376. // PENDING
  21377. var color = colorPaletteMixin.getColorFromPalette.call(this, name, scope, requestColorNum);
  21378. if (!color) {
  21379. color = ecModel.getColorFromPalette(name, scope, requestColorNum);
  21380. }
  21381. return color;
  21382. },
  21383. /**
  21384. * Use `data.mapDimension(coordDim, true)` instead.
  21385. * @deprecated
  21386. */
  21387. coordDimToDataDim: function (coordDim) {
  21388. return this.getRawData().mapDimension(coordDim, true);
  21389. },
  21390. /**
  21391. * Get progressive rendering count each step
  21392. * @return {number}
  21393. */
  21394. getProgressive: function () {
  21395. return this.get('progressive');
  21396. },
  21397. /**
  21398. * Get progressive rendering count each step
  21399. * @return {number}
  21400. */
  21401. getProgressiveThreshold: function () {
  21402. return this.get('progressiveThreshold');
  21403. },
  21404. /**
  21405. * Get data indices for show tooltip content. See tooltip.
  21406. * @abstract
  21407. * @param {Array.<string>|string} dim
  21408. * @param {Array.<number>} value
  21409. * @param {module:echarts/coord/single/SingleAxis} baseAxis
  21410. * @return {Object} {dataIndices, nestestValue}.
  21411. */
  21412. getAxisTooltipData: null,
  21413. /**
  21414. * See tooltip.
  21415. * @abstract
  21416. * @param {number} dataIndex
  21417. * @return {Array.<number>} Point of tooltip. null/undefined can be returned.
  21418. */
  21419. getTooltipPosition: null,
  21420. /**
  21421. * @see {module:echarts/stream/Scheduler}
  21422. */
  21423. pipeTask: null,
  21424. /**
  21425. * Convinient for override in extended class.
  21426. * @protected
  21427. * @type {Function}
  21428. */
  21429. preventIncremental: null,
  21430. /**
  21431. * @public
  21432. * @readOnly
  21433. * @type {Object}
  21434. */
  21435. pipelineContext: null
  21436. });
  21437. mixin(SeriesModel, dataFormatMixin);
  21438. mixin(SeriesModel, colorPaletteMixin);
  21439. /**
  21440. * MUST be called after `prepareSource` called
  21441. * Here we need to make auto series, especially for auto legend. But we
  21442. * do not modify series.name in option to avoid side effects.
  21443. */
  21444. function autoSeriesName(seriesModel) {
  21445. // User specified name has higher priority, otherwise it may cause
  21446. // series can not be queried unexpectedly.
  21447. var name = seriesModel.name;
  21448. if (!isNameSpecified(seriesModel)) {
  21449. seriesModel.name = getSeriesAutoName(seriesModel) || name;
  21450. }
  21451. }
  21452. function getSeriesAutoName(seriesModel) {
  21453. var data = seriesModel.getRawData();
  21454. var dataDims = data.mapDimension('seriesName', true);
  21455. var nameArr = [];
  21456. each$1(dataDims, function (dataDim) {
  21457. var dimInfo = data.getDimensionInfo(dataDim);
  21458. dimInfo.displayName && nameArr.push(dimInfo.displayName);
  21459. });
  21460. return nameArr.join(' ');
  21461. }
  21462. function dataTaskCount(context) {
  21463. return context.model.getRawData().count();
  21464. }
  21465. function dataTaskReset(context) {
  21466. var seriesModel = context.model;
  21467. seriesModel.setData(seriesModel.getRawData().cloneShallow());
  21468. return dataTaskProgress;
  21469. }
  21470. function dataTaskProgress(param, context) {
  21471. // Avoid repead cloneShallow when data just created in reset.
  21472. if (param.end > context.outputData.count()) {
  21473. context.model.getRawData().cloneShallow(context.outputData);
  21474. }
  21475. }
  21476. // TODO refactor
  21477. function wrapData(data, seriesModel) {
  21478. each$1(data.CHANGABLE_METHODS, function (methodName) {
  21479. data.wrapMethod(methodName, curry(onDataSelfChange, seriesModel));
  21480. });
  21481. }
  21482. function onDataSelfChange(seriesModel) {
  21483. var task = getCurrentTask(seriesModel);
  21484. if (task) {
  21485. // Consider case: filter, selectRange
  21486. task.setOutputEnd(this.count());
  21487. }
  21488. }
  21489. function getCurrentTask(seriesModel) {
  21490. var scheduler = (seriesModel.ecModel || {}).scheduler;
  21491. var pipeline = scheduler && scheduler.getPipeline(seriesModel.uid);
  21492. if (pipeline) {
  21493. // When pipline finished, the currrentTask keep the last
  21494. // task (renderTask).
  21495. var task = pipeline.currentTask;
  21496. if (task) {
  21497. var agentStubMap = task.agentStubMap;
  21498. if (agentStubMap) {
  21499. task = agentStubMap.get(seriesModel.uid);
  21500. }
  21501. }
  21502. return task;
  21503. }
  21504. }
  21505. /*
  21506. * Licensed to the Apache Software Foundation (ASF) under one
  21507. * or more contributor license agreements. See the NOTICE file
  21508. * distributed with this work for additional information
  21509. * regarding copyright ownership. The ASF licenses this file
  21510. * to you under the Apache License, Version 2.0 (the
  21511. * "License"); you may not use this file except in compliance
  21512. * with the License. You may obtain a copy of the License at
  21513. *
  21514. * http://www.apache.org/licenses/LICENSE-2.0
  21515. *
  21516. * Unless required by applicable law or agreed to in writing,
  21517. * software distributed under the License is distributed on an
  21518. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  21519. * KIND, either express or implied. See the License for the
  21520. * specific language governing permissions and limitations
  21521. * under the License.
  21522. */
  21523. var Component$1 = function () {
  21524. /**
  21525. * @type {module:zrender/container/Group}
  21526. * @readOnly
  21527. */
  21528. this.group = new Group();
  21529. /**
  21530. * @type {string}
  21531. * @readOnly
  21532. */
  21533. this.uid = getUID('viewComponent');
  21534. };
  21535. Component$1.prototype = {
  21536. constructor: Component$1,
  21537. init: function (ecModel, api) {},
  21538. render: function (componentModel, ecModel, api, payload) {},
  21539. dispose: function () {},
  21540. /**
  21541. * @param {string} eventType
  21542. * @param {Object} query
  21543. * @param {module:zrender/Element} targetEl
  21544. * @param {Object} packedEvent
  21545. * @return {boolen} Pass only when return `true`.
  21546. */
  21547. filterForExposedEvent: null
  21548. };
  21549. var componentProto = Component$1.prototype;
  21550. componentProto.updateView
  21551. = componentProto.updateLayout
  21552. = componentProto.updateVisual
  21553. = function (seriesModel, ecModel, api, payload) {
  21554. // Do nothing;
  21555. };
  21556. // Enable Component.extend.
  21557. enableClassExtend(Component$1);
  21558. // Enable capability of registerClass, getClass, hasClass, registerSubTypeDefaulter and so on.
  21559. enableClassManagement(Component$1, {registerWhenExtend: true});
  21560. /*
  21561. * Licensed to the Apache Software Foundation (ASF) under one
  21562. * or more contributor license agreements. See the NOTICE file
  21563. * distributed with this work for additional information
  21564. * regarding copyright ownership. The ASF licenses this file
  21565. * to you under the Apache License, Version 2.0 (the
  21566. * "License"); you may not use this file except in compliance
  21567. * with the License. You may obtain a copy of the License at
  21568. *
  21569. * http://www.apache.org/licenses/LICENSE-2.0
  21570. *
  21571. * Unless required by applicable law or agreed to in writing,
  21572. * software distributed under the License is distributed on an
  21573. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  21574. * KIND, either express or implied. See the License for the
  21575. * specific language governing permissions and limitations
  21576. * under the License.
  21577. */
  21578. /**
  21579. * @return {string} If large mode changed, return string 'reset';
  21580. */
  21581. var createRenderPlanner = function () {
  21582. var inner = makeInner();
  21583. return function (seriesModel) {
  21584. var fields = inner(seriesModel);
  21585. var pipelineContext = seriesModel.pipelineContext;
  21586. var originalLarge = fields.large;
  21587. var originalProgressive = fields.progressiveRender;
  21588. var large = fields.large = pipelineContext.large;
  21589. var progressive = fields.progressiveRender = pipelineContext.progressiveRender;
  21590. return !!((originalLarge ^ large) || (originalProgressive ^ progressive)) && 'reset';
  21591. };
  21592. };
  21593. /*
  21594. * Licensed to the Apache Software Foundation (ASF) under one
  21595. * or more contributor license agreements. See the NOTICE file
  21596. * distributed with this work for additional information
  21597. * regarding copyright ownership. The ASF licenses this file
  21598. * to you under the Apache License, Version 2.0 (the
  21599. * "License"); you may not use this file except in compliance
  21600. * with the License. You may obtain a copy of the License at
  21601. *
  21602. * http://www.apache.org/licenses/LICENSE-2.0
  21603. *
  21604. * Unless required by applicable law or agreed to in writing,
  21605. * software distributed under the License is distributed on an
  21606. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  21607. * KIND, either express or implied. See the License for the
  21608. * specific language governing permissions and limitations
  21609. * under the License.
  21610. */
  21611. var inner$5 = makeInner();
  21612. var renderPlanner = createRenderPlanner();
  21613. function Chart() {
  21614. /**
  21615. * @type {module:zrender/container/Group}
  21616. * @readOnly
  21617. */
  21618. this.group = new Group();
  21619. /**
  21620. * @type {string}
  21621. * @readOnly
  21622. */
  21623. this.uid = getUID('viewChart');
  21624. this.renderTask = createTask({
  21625. plan: renderTaskPlan,
  21626. reset: renderTaskReset
  21627. });
  21628. this.renderTask.context = {view: this};
  21629. }
  21630. Chart.prototype = {
  21631. type: 'chart',
  21632. /**
  21633. * Init the chart.
  21634. * @param {module:echarts/model/Global} ecModel
  21635. * @param {module:echarts/ExtensionAPI} api
  21636. */
  21637. init: function (ecModel, api) {},
  21638. /**
  21639. * Render the chart.
  21640. * @param {module:echarts/model/Series} seriesModel
  21641. * @param {module:echarts/model/Global} ecModel
  21642. * @param {module:echarts/ExtensionAPI} api
  21643. * @param {Object} payload
  21644. */
  21645. render: function (seriesModel, ecModel, api, payload) {},
  21646. /**
  21647. * Highlight series or specified data item.
  21648. * @param {module:echarts/model/Series} seriesModel
  21649. * @param {module:echarts/model/Global} ecModel
  21650. * @param {module:echarts/ExtensionAPI} api
  21651. * @param {Object} payload
  21652. */
  21653. highlight: function (seriesModel, ecModel, api, payload) {
  21654. toggleHighlight(seriesModel.getData(), payload, 'emphasis');
  21655. },
  21656. /**
  21657. * Downplay series or specified data item.
  21658. * @param {module:echarts/model/Series} seriesModel
  21659. * @param {module:echarts/model/Global} ecModel
  21660. * @param {module:echarts/ExtensionAPI} api
  21661. * @param {Object} payload
  21662. */
  21663. downplay: function (seriesModel, ecModel, api, payload) {
  21664. toggleHighlight(seriesModel.getData(), payload, 'normal');
  21665. },
  21666. /**
  21667. * Remove self.
  21668. * @param {module:echarts/model/Global} ecModel
  21669. * @param {module:echarts/ExtensionAPI} api
  21670. */
  21671. remove: function (ecModel, api) {
  21672. this.group.removeAll();
  21673. },
  21674. /**
  21675. * Dispose self.
  21676. * @param {module:echarts/model/Global} ecModel
  21677. * @param {module:echarts/ExtensionAPI} api
  21678. */
  21679. dispose: function () {},
  21680. /**
  21681. * Rendering preparation in progressive mode.
  21682. * @param {module:echarts/model/Series} seriesModel
  21683. * @param {module:echarts/model/Global} ecModel
  21684. * @param {module:echarts/ExtensionAPI} api
  21685. * @param {Object} payload
  21686. */
  21687. incrementalPrepareRender: null,
  21688. /**
  21689. * Render in progressive mode.
  21690. * @param {Object} params See taskParams in `stream/task.js`
  21691. * @param {module:echarts/model/Series} seriesModel
  21692. * @param {module:echarts/model/Global} ecModel
  21693. * @param {module:echarts/ExtensionAPI} api
  21694. * @param {Object} payload
  21695. */
  21696. incrementalRender: null,
  21697. /**
  21698. * Update transform directly.
  21699. * @param {module:echarts/model/Series} seriesModel
  21700. * @param {module:echarts/model/Global} ecModel
  21701. * @param {module:echarts/ExtensionAPI} api
  21702. * @param {Object} payload
  21703. * @return {Object} {update: true}
  21704. */
  21705. updateTransform: null,
  21706. /**
  21707. * The view contains the given point.
  21708. * @interface
  21709. * @param {Array.<number>} point
  21710. * @return {boolean}
  21711. */
  21712. // containPoint: function () {}
  21713. /**
  21714. * @param {string} eventType
  21715. * @param {Object} query
  21716. * @param {module:zrender/Element} targetEl
  21717. * @param {Object} packedEvent
  21718. * @return {boolen} Pass only when return `true`.
  21719. */
  21720. filterForExposedEvent: null
  21721. };
  21722. var chartProto = Chart.prototype;
  21723. chartProto.updateView =
  21724. chartProto.updateLayout =
  21725. chartProto.updateVisual =
  21726. function (seriesModel, ecModel, api, payload) {
  21727. this.render(seriesModel, ecModel, api, payload);
  21728. };
  21729. /**
  21730. * Set state of single element
  21731. * @param {module:zrender/Element} el
  21732. * @param {string} state 'normal'|'emphasis'
  21733. * @param {number} highlightDigit
  21734. */
  21735. function elSetState(el, state, highlightDigit) {
  21736. if (el) {
  21737. el.trigger(state, highlightDigit);
  21738. if (el.isGroup
  21739. // Simple optimize.
  21740. && !isHighDownDispatcher(el)
  21741. ) {
  21742. for (var i = 0, len = el.childCount(); i < len; i++) {
  21743. elSetState(el.childAt(i), state, highlightDigit);
  21744. }
  21745. }
  21746. }
  21747. }
  21748. /**
  21749. * @param {module:echarts/data/List} data
  21750. * @param {Object} payload
  21751. * @param {string} state 'normal'|'emphasis'
  21752. */
  21753. function toggleHighlight(data, payload, state) {
  21754. var dataIndex = queryDataIndex(data, payload);
  21755. var highlightDigit = (payload && payload.highlightKey != null)
  21756. ? getHighlightDigit(payload.highlightKey)
  21757. : null;
  21758. if (dataIndex != null) {
  21759. each$1(normalizeToArray(dataIndex), function (dataIdx) {
  21760. elSetState(data.getItemGraphicEl(dataIdx), state, highlightDigit);
  21761. });
  21762. }
  21763. else {
  21764. data.eachItemGraphicEl(function (el) {
  21765. elSetState(el, state, highlightDigit);
  21766. });
  21767. }
  21768. }
  21769. // Enable Chart.extend.
  21770. enableClassExtend(Chart, ['dispose']);
  21771. // Add capability of registerClass, getClass, hasClass, registerSubTypeDefaulter and so on.
  21772. enableClassManagement(Chart, {registerWhenExtend: true});
  21773. Chart.markUpdateMethod = function (payload, methodName) {
  21774. inner$5(payload).updateMethod = methodName;
  21775. };
  21776. function renderTaskPlan(context) {
  21777. return renderPlanner(context.model);
  21778. }
  21779. function renderTaskReset(context) {
  21780. var seriesModel = context.model;
  21781. var ecModel = context.ecModel;
  21782. var api = context.api;
  21783. var payload = context.payload;
  21784. // ???! remove updateView updateVisual
  21785. var progressiveRender = seriesModel.pipelineContext.progressiveRender;
  21786. var view = context.view;
  21787. var updateMethod = payload && inner$5(payload).updateMethod;
  21788. var methodName = progressiveRender
  21789. ? 'incrementalPrepareRender'
  21790. : (updateMethod && view[updateMethod])
  21791. ? updateMethod
  21792. // `appendData` is also supported when data amount
  21793. // is less than progressive threshold.
  21794. : 'render';
  21795. if (methodName !== 'render') {
  21796. view[methodName](seriesModel, ecModel, api, payload);
  21797. }
  21798. return progressMethodMap[methodName];
  21799. }
  21800. var progressMethodMap = {
  21801. incrementalPrepareRender: {
  21802. progress: function (params, context) {
  21803. context.view.incrementalRender(
  21804. params, context.model, context.ecModel, context.api, context.payload
  21805. );
  21806. }
  21807. },
  21808. render: {
  21809. // Put view.render in `progress` to support appendData. But in this case
  21810. // view.render should not be called in reset, otherwise it will be called
  21811. // twise. Use `forceFirstProgress` to make sure that view.render is called
  21812. // in any cases.
  21813. forceFirstProgress: true,
  21814. progress: function (params, context) {
  21815. context.view.render(
  21816. context.model, context.ecModel, context.api, context.payload
  21817. );
  21818. }
  21819. }
  21820. };
  21821. /*
  21822. * Licensed to the Apache Software Foundation (ASF) under one
  21823. * or more contributor license agreements. See the NOTICE file
  21824. * distributed with this work for additional information
  21825. * regarding copyright ownership. The ASF licenses this file
  21826. * to you under the Apache License, Version 2.0 (the
  21827. * "License"); you may not use this file except in compliance
  21828. * with the License. You may obtain a copy of the License at
  21829. *
  21830. * http://www.apache.org/licenses/LICENSE-2.0
  21831. *
  21832. * Unless required by applicable law or agreed to in writing,
  21833. * software distributed under the License is distributed on an
  21834. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  21835. * KIND, either express or implied. See the License for the
  21836. * specific language governing permissions and limitations
  21837. * under the License.
  21838. */
  21839. var ORIGIN_METHOD = '\0__throttleOriginMethod';
  21840. var RATE = '\0__throttleRate';
  21841. var THROTTLE_TYPE = '\0__throttleType';
  21842. /**
  21843. * @public
  21844. * @param {(Function)} fn
  21845. * @param {number} [delay=0] Unit: ms.
  21846. * @param {boolean} [debounce=false]
  21847. * true: If call interval less than `delay`, only the last call works.
  21848. * false: If call interval less than `delay, call works on fixed rate.
  21849. * @return {(Function)} throttled fn.
  21850. */
  21851. function throttle(fn, delay, debounce) {
  21852. var currCall;
  21853. var lastCall = 0;
  21854. var lastExec = 0;
  21855. var timer = null;
  21856. var diff;
  21857. var scope;
  21858. var args;
  21859. var debounceNextCall;
  21860. delay = delay || 0;
  21861. function exec() {
  21862. lastExec = (new Date()).getTime();
  21863. timer = null;
  21864. fn.apply(scope, args || []);
  21865. }
  21866. var cb = function () {
  21867. currCall = (new Date()).getTime();
  21868. scope = this;
  21869. args = arguments;
  21870. var thisDelay = debounceNextCall || delay;
  21871. var thisDebounce = debounceNextCall || debounce;
  21872. debounceNextCall = null;
  21873. diff = currCall - (thisDebounce ? lastCall : lastExec) - thisDelay;
  21874. clearTimeout(timer);
  21875. // Here we should make sure that: the `exec` SHOULD NOT be called later
  21876. // than a new call of `cb`, that is, preserving the command order. Consider
  21877. // calculating "scale rate" when roaming as an example. When a call of `cb`
  21878. // happens, either the `exec` is called dierectly, or the call is delayed.
  21879. // But the delayed call should never be later than next call of `cb`. Under
  21880. // this assurance, we can simply update view state each time `dispatchAction`
  21881. // triggered by user roaming, but not need to add extra code to avoid the
  21882. // state being "rolled-back".
  21883. if (thisDebounce) {
  21884. timer = setTimeout(exec, thisDelay);
  21885. }
  21886. else {
  21887. if (diff >= 0) {
  21888. exec();
  21889. }
  21890. else {
  21891. timer = setTimeout(exec, -diff);
  21892. }
  21893. }
  21894. lastCall = currCall;
  21895. };
  21896. /**
  21897. * Clear throttle.
  21898. * @public
  21899. */
  21900. cb.clear = function () {
  21901. if (timer) {
  21902. clearTimeout(timer);
  21903. timer = null;
  21904. }
  21905. };
  21906. /**
  21907. * Enable debounce once.
  21908. */
  21909. cb.debounceNextCall = function (debounceDelay) {
  21910. debounceNextCall = debounceDelay;
  21911. };
  21912. return cb;
  21913. }
  21914. /**
  21915. * Create throttle method or update throttle rate.
  21916. *
  21917. * @example
  21918. * ComponentView.prototype.render = function () {
  21919. * ...
  21920. * throttle.createOrUpdate(
  21921. * this,
  21922. * '_dispatchAction',
  21923. * this.model.get('throttle'),
  21924. * 'fixRate'
  21925. * );
  21926. * };
  21927. * ComponentView.prototype.remove = function () {
  21928. * throttle.clear(this, '_dispatchAction');
  21929. * };
  21930. * ComponentView.prototype.dispose = function () {
  21931. * throttle.clear(this, '_dispatchAction');
  21932. * };
  21933. *
  21934. * @public
  21935. * @param {Object} obj
  21936. * @param {string} fnAttr
  21937. * @param {number} [rate]
  21938. * @param {string} [throttleType='fixRate'] 'fixRate' or 'debounce'
  21939. * @return {Function} throttled function.
  21940. */
  21941. function createOrUpdate(obj, fnAttr, rate, throttleType) {
  21942. var fn = obj[fnAttr];
  21943. if (!fn) {
  21944. return;
  21945. }
  21946. var originFn = fn[ORIGIN_METHOD] || fn;
  21947. var lastThrottleType = fn[THROTTLE_TYPE];
  21948. var lastRate = fn[RATE];
  21949. if (lastRate !== rate || lastThrottleType !== throttleType) {
  21950. if (rate == null || !throttleType) {
  21951. return (obj[fnAttr] = originFn);
  21952. }
  21953. fn = obj[fnAttr] = throttle(
  21954. originFn, rate, throttleType === 'debounce'
  21955. );
  21956. fn[ORIGIN_METHOD] = originFn;
  21957. fn[THROTTLE_TYPE] = throttleType;
  21958. fn[RATE] = rate;
  21959. }
  21960. return fn;
  21961. }
  21962. /**
  21963. * Clear throttle. Example see throttle.createOrUpdate.
  21964. *
  21965. * @public
  21966. * @param {Object} obj
  21967. * @param {string} fnAttr
  21968. */
  21969. function clear(obj, fnAttr) {
  21970. var fn = obj[fnAttr];
  21971. if (fn && fn[ORIGIN_METHOD]) {
  21972. obj[fnAttr] = fn[ORIGIN_METHOD];
  21973. }
  21974. }
  21975. /*
  21976. * Licensed to the Apache Software Foundation (ASF) under one
  21977. * or more contributor license agreements. See the NOTICE file
  21978. * distributed with this work for additional information
  21979. * regarding copyright ownership. The ASF licenses this file
  21980. * to you under the Apache License, Version 2.0 (the
  21981. * "License"); you may not use this file except in compliance
  21982. * with the License. You may obtain a copy of the License at
  21983. *
  21984. * http://www.apache.org/licenses/LICENSE-2.0
  21985. *
  21986. * Unless required by applicable law or agreed to in writing,
  21987. * software distributed under the License is distributed on an
  21988. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  21989. * KIND, either express or implied. See the License for the
  21990. * specific language governing permissions and limitations
  21991. * under the License.
  21992. */
  21993. var seriesColor = {
  21994. createOnAllSeries: true,
  21995. performRawSeries: true,
  21996. reset: function (seriesModel, ecModel) {
  21997. var data = seriesModel.getData();
  21998. var colorAccessPath = (seriesModel.visualColorAccessPath || 'itemStyle.color').split('.');
  21999. var color = seriesModel.get(colorAccessPath) // Set in itemStyle
  22000. || seriesModel.getColorFromPalette(
  22001. // TODO series count changed.
  22002. seriesModel.name, null, ecModel.getSeriesCount()
  22003. ); // Default color
  22004. // FIXME Set color function or use the platte color
  22005. data.setVisual('color', color);
  22006. // Only visible series has each data be visual encoded
  22007. if (!ecModel.isSeriesFiltered(seriesModel)) {
  22008. if (typeof color === 'function' && !(color instanceof Gradient)) {
  22009. data.each(function (idx) {
  22010. data.setItemVisual(
  22011. idx, 'color', color(seriesModel.getDataParams(idx))
  22012. );
  22013. });
  22014. }
  22015. // itemStyle in each data item
  22016. var dataEach = function (data, idx) {
  22017. var itemModel = data.getItemModel(idx);
  22018. var color = itemModel.get(colorAccessPath, true);
  22019. if (color != null) {
  22020. data.setItemVisual(idx, 'color', color);
  22021. }
  22022. };
  22023. return { dataEach: data.hasItemOption ? dataEach : null };
  22024. }
  22025. }
  22026. };
  22027. /*
  22028. * Licensed to the Apache Software Foundation (ASF) under one
  22029. * or more contributor license agreements. See the NOTICE file
  22030. * distributed with this work for additional information
  22031. * regarding copyright ownership. The ASF licenses this file
  22032. * to you under the Apache License, Version 2.0 (the
  22033. * "License"); you may not use this file except in compliance
  22034. * with the License. You may obtain a copy of the License at
  22035. *
  22036. * http://www.apache.org/licenses/LICENSE-2.0
  22037. *
  22038. * Unless required by applicable law or agreed to in writing,
  22039. * software distributed under the License is distributed on an
  22040. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  22041. * KIND, either express or implied. See the License for the
  22042. * specific language governing permissions and limitations
  22043. * under the License.
  22044. */
  22045. var lang = {
  22046. toolbox: {
  22047. brush: {
  22048. title: {
  22049. rect: '矩形选择',
  22050. polygon: '圈选',
  22051. lineX: '横向选择',
  22052. lineY: '纵向选择',
  22053. keep: '保持选择',
  22054. clear: '清除选择'
  22055. }
  22056. },
  22057. dataView: {
  22058. title: '数据视图',
  22059. lang: ['数据视图', '关闭', '刷新']
  22060. },
  22061. dataZoom: {
  22062. title: {
  22063. zoom: '区域缩放',
  22064. back: '区域缩放还原'
  22065. }
  22066. },
  22067. magicType: {
  22068. title: {
  22069. line: '切换为折线图',
  22070. bar: '切换为柱状图',
  22071. stack: '切换为堆叠',
  22072. tiled: '切换为平铺'
  22073. }
  22074. },
  22075. restore: {
  22076. title: '还原'
  22077. },
  22078. saveAsImage: {
  22079. title: '保存为图片',
  22080. lang: ['右键另存为图片']
  22081. }
  22082. },
  22083. series: {
  22084. typeNames: {
  22085. pie: '饼图',
  22086. bar: '柱状图',
  22087. line: '折线图',
  22088. scatter: '散点图',
  22089. effectScatter: '涟漪散点图',
  22090. radar: '雷达图',
  22091. tree: '树图',
  22092. treemap: '矩形树图',
  22093. boxplot: '箱型图',
  22094. candlestick: 'K线图',
  22095. k: 'K线图',
  22096. heatmap: '热力图',
  22097. map: '地图',
  22098. parallel: '平行坐标图',
  22099. lines: '线图',
  22100. graph: '关系图',
  22101. sankey: '桑基图',
  22102. funnel: '漏斗图',
  22103. gauge: '仪表盘图',
  22104. pictorialBar: '象形柱图',
  22105. themeRiver: '主题河流图',
  22106. sunburst: '旭日图'
  22107. }
  22108. },
  22109. aria: {
  22110. general: {
  22111. withTitle: '这是一个关于“{title}”的图表。',
  22112. withoutTitle: '这是一个图表,'
  22113. },
  22114. series: {
  22115. single: {
  22116. prefix: '',
  22117. withName: '图表类型是{seriesType},表示{seriesName}。',
  22118. withoutName: '图表类型是{seriesType}。'
  22119. },
  22120. multiple: {
  22121. prefix: '它由{seriesCount}个图表系列组成。',
  22122. withName: '第{seriesId}个系列是一个表示{seriesName}的{seriesType},',
  22123. withoutName: '第{seriesId}个系列是一个{seriesType},',
  22124. separator: {
  22125. middle: ';',
  22126. end: '。'
  22127. }
  22128. }
  22129. },
  22130. data: {
  22131. allData: '其数据是——',
  22132. partialData: '其中,前{displayCnt}项是——',
  22133. withName: '{name}的数据是{value}',
  22134. withoutName: '{value}',
  22135. separator: {
  22136. middle: ',',
  22137. end: ''
  22138. }
  22139. }
  22140. }
  22141. };
  22142. /*
  22143. * Licensed to the Apache Software Foundation (ASF) under one
  22144. * or more contributor license agreements. See the NOTICE file
  22145. * distributed with this work for additional information
  22146. * regarding copyright ownership. The ASF licenses this file
  22147. * to you under the Apache License, Version 2.0 (the
  22148. * "License"); you may not use this file except in compliance
  22149. * with the License. You may obtain a copy of the License at
  22150. *
  22151. * http://www.apache.org/licenses/LICENSE-2.0
  22152. *
  22153. * Unless required by applicable law or agreed to in writing,
  22154. * software distributed under the License is distributed on an
  22155. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  22156. * KIND, either express or implied. See the License for the
  22157. * specific language governing permissions and limitations
  22158. * under the License.
  22159. */
  22160. var aria = function (dom, ecModel) {
  22161. var ariaModel = ecModel.getModel('aria');
  22162. if (!ariaModel.get('show')) {
  22163. return;
  22164. }
  22165. else if (ariaModel.get('description')) {
  22166. dom.setAttribute('aria-label', ariaModel.get('description'));
  22167. return;
  22168. }
  22169. var seriesCnt = 0;
  22170. ecModel.eachSeries(function (seriesModel, idx) {
  22171. ++seriesCnt;
  22172. }, this);
  22173. var maxDataCnt = ariaModel.get('data.maxCount') || 10;
  22174. var maxSeriesCnt = ariaModel.get('series.maxCount') || 10;
  22175. var displaySeriesCnt = Math.min(seriesCnt, maxSeriesCnt);
  22176. var ariaLabel;
  22177. if (seriesCnt < 1) {
  22178. // No series, no aria label
  22179. return;
  22180. }
  22181. else {
  22182. var title = getTitle();
  22183. if (title) {
  22184. ariaLabel = replace(getConfig('general.withTitle'), {
  22185. title: title
  22186. });
  22187. }
  22188. else {
  22189. ariaLabel = getConfig('general.withoutTitle');
  22190. }
  22191. var seriesLabels = [];
  22192. var prefix = seriesCnt > 1
  22193. ? 'series.multiple.prefix'
  22194. : 'series.single.prefix';
  22195. ariaLabel += replace(getConfig(prefix), { seriesCount: seriesCnt });
  22196. ecModel.eachSeries(function (seriesModel, idx) {
  22197. if (idx < displaySeriesCnt) {
  22198. var seriesLabel;
  22199. var seriesName = seriesModel.get('name');
  22200. var seriesTpl = 'series.'
  22201. + (seriesCnt > 1 ? 'multiple' : 'single') + '.';
  22202. seriesLabel = getConfig(seriesName
  22203. ? seriesTpl + 'withName'
  22204. : seriesTpl + 'withoutName');
  22205. seriesLabel = replace(seriesLabel, {
  22206. seriesId: seriesModel.seriesIndex,
  22207. seriesName: seriesModel.get('name'),
  22208. seriesType: getSeriesTypeName(seriesModel.subType)
  22209. });
  22210. var data = seriesModel.getData();
  22211. window.data = data;
  22212. if (data.count() > maxDataCnt) {
  22213. // Show part of data
  22214. seriesLabel += replace(getConfig('data.partialData'), {
  22215. displayCnt: maxDataCnt
  22216. });
  22217. }
  22218. else {
  22219. seriesLabel += getConfig('data.allData');
  22220. }
  22221. var dataLabels = [];
  22222. for (var i = 0; i < data.count(); i++) {
  22223. if (i < maxDataCnt) {
  22224. var name = data.getName(i);
  22225. var value = retrieveRawValue(data, i);
  22226. dataLabels.push(
  22227. replace(
  22228. name
  22229. ? getConfig('data.withName')
  22230. : getConfig('data.withoutName'),
  22231. {
  22232. name: name,
  22233. value: value
  22234. }
  22235. )
  22236. );
  22237. }
  22238. }
  22239. seriesLabel += dataLabels
  22240. .join(getConfig('data.separator.middle'))
  22241. + getConfig('data.separator.end');
  22242. seriesLabels.push(seriesLabel);
  22243. }
  22244. });
  22245. ariaLabel += seriesLabels
  22246. .join(getConfig('series.multiple.separator.middle'))
  22247. + getConfig('series.multiple.separator.end');
  22248. dom.setAttribute('aria-label', ariaLabel);
  22249. }
  22250. function replace(str, keyValues) {
  22251. if (typeof str !== 'string') {
  22252. return str;
  22253. }
  22254. var result = str;
  22255. each$1(keyValues, function (value, key) {
  22256. result = result.replace(
  22257. new RegExp('\\{\\s*' + key + '\\s*\\}', 'g'),
  22258. value
  22259. );
  22260. });
  22261. return result;
  22262. }
  22263. function getConfig(path) {
  22264. var userConfig = ariaModel.get(path);
  22265. if (userConfig == null) {
  22266. var pathArr = path.split('.');
  22267. var result = lang.aria;
  22268. for (var i = 0; i < pathArr.length; ++i) {
  22269. result = result[pathArr[i]];
  22270. }
  22271. return result;
  22272. }
  22273. else {
  22274. return userConfig;
  22275. }
  22276. }
  22277. function getTitle() {
  22278. var title = ecModel.getModel('title').option;
  22279. if (title && title.length) {
  22280. title = title[0];
  22281. }
  22282. return title && title.text;
  22283. }
  22284. function getSeriesTypeName(type) {
  22285. return lang.series.typeNames[type] || '自定义图';
  22286. }
  22287. };
  22288. /*
  22289. * Licensed to the Apache Software Foundation (ASF) under one
  22290. * or more contributor license agreements. See the NOTICE file
  22291. * distributed with this work for additional information
  22292. * regarding copyright ownership. The ASF licenses this file
  22293. * to you under the Apache License, Version 2.0 (the
  22294. * "License"); you may not use this file except in compliance
  22295. * with the License. You may obtain a copy of the License at
  22296. *
  22297. * http://www.apache.org/licenses/LICENSE-2.0
  22298. *
  22299. * Unless required by applicable law or agreed to in writing,
  22300. * software distributed under the License is distributed on an
  22301. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  22302. * KIND, either express or implied. See the License for the
  22303. * specific language governing permissions and limitations
  22304. * under the License.
  22305. */
  22306. var PI$1 = Math.PI;
  22307. /**
  22308. * @param {module:echarts/ExtensionAPI} api
  22309. * @param {Object} [opts]
  22310. * @param {string} [opts.text]
  22311. * @param {string} [opts.color]
  22312. * @param {string} [opts.textColor]
  22313. * @return {module:zrender/Element}
  22314. */
  22315. var loadingDefault = function (api, opts) {
  22316. opts = opts || {};
  22317. defaults(opts, {
  22318. text: 'loading',
  22319. color: '#c23531',
  22320. textColor: '#000',
  22321. maskColor: 'rgba(255, 255, 255, 0.8)',
  22322. zlevel: 0
  22323. });
  22324. var mask = new Rect({
  22325. style: {
  22326. fill: opts.maskColor
  22327. },
  22328. zlevel: opts.zlevel,
  22329. z: 10000
  22330. });
  22331. var arc = new Arc({
  22332. shape: {
  22333. startAngle: -PI$1 / 2,
  22334. endAngle: -PI$1 / 2 + 0.1,
  22335. r: 10
  22336. },
  22337. style: {
  22338. stroke: opts.color,
  22339. lineCap: 'round',
  22340. lineWidth: 5
  22341. },
  22342. zlevel: opts.zlevel,
  22343. z: 10001
  22344. });
  22345. var labelRect = new Rect({
  22346. style: {
  22347. fill: 'none',
  22348. text: opts.text,
  22349. textPosition: 'right',
  22350. textDistance: 10,
  22351. textFill: opts.textColor
  22352. },
  22353. zlevel: opts.zlevel,
  22354. z: 10001
  22355. });
  22356. arc.animateShape(true)
  22357. .when(1000, {
  22358. endAngle: PI$1 * 3 / 2
  22359. })
  22360. .start('circularInOut');
  22361. arc.animateShape(true)
  22362. .when(1000, {
  22363. startAngle: PI$1 * 3 / 2
  22364. })
  22365. .delay(300)
  22366. .start('circularInOut');
  22367. var group = new Group();
  22368. group.add(arc);
  22369. group.add(labelRect);
  22370. group.add(mask);
  22371. // Inject resize
  22372. group.resize = function () {
  22373. var cx = api.getWidth() / 2;
  22374. var cy = api.getHeight() / 2;
  22375. arc.setShape({
  22376. cx: cx,
  22377. cy: cy
  22378. });
  22379. var r = arc.shape.r;
  22380. labelRect.setShape({
  22381. x: cx - r,
  22382. y: cy - r,
  22383. width: r * 2,
  22384. height: r * 2
  22385. });
  22386. mask.setShape({
  22387. x: 0,
  22388. y: 0,
  22389. width: api.getWidth(),
  22390. height: api.getHeight()
  22391. });
  22392. };
  22393. group.resize();
  22394. return group;
  22395. };
  22396. /*
  22397. * Licensed to the Apache Software Foundation (ASF) under one
  22398. * or more contributor license agreements. See the NOTICE file
  22399. * distributed with this work for additional information
  22400. * regarding copyright ownership. The ASF licenses this file
  22401. * to you under the Apache License, Version 2.0 (the
  22402. * "License"); you may not use this file except in compliance
  22403. * with the License. You may obtain a copy of the License at
  22404. *
  22405. * http://www.apache.org/licenses/LICENSE-2.0
  22406. *
  22407. * Unless required by applicable law or agreed to in writing,
  22408. * software distributed under the License is distributed on an
  22409. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  22410. * KIND, either express or implied. See the License for the
  22411. * specific language governing permissions and limitations
  22412. * under the License.
  22413. */
  22414. /**
  22415. * @module echarts/stream/Scheduler
  22416. */
  22417. /**
  22418. * @constructor
  22419. */
  22420. function Scheduler(ecInstance, api, dataProcessorHandlers, visualHandlers) {
  22421. this.ecInstance = ecInstance;
  22422. this.api = api;
  22423. this.unfinished;
  22424. // Fix current processors in case that in some rear cases that
  22425. // processors might be registered after echarts instance created.
  22426. // Register processors incrementally for a echarts instance is
  22427. // not supported by this stream architecture.
  22428. var dataProcessorHandlers = this._dataProcessorHandlers = dataProcessorHandlers.slice();
  22429. var visualHandlers = this._visualHandlers = visualHandlers.slice();
  22430. this._allHandlers = dataProcessorHandlers.concat(visualHandlers);
  22431. /**
  22432. * @private
  22433. * @type {
  22434. * [handlerUID: string]: {
  22435. * seriesTaskMap?: {
  22436. * [seriesUID: string]: Task
  22437. * },
  22438. * overallTask?: Task
  22439. * }
  22440. * }
  22441. */
  22442. this._stageTaskMap = createHashMap();
  22443. }
  22444. var proto = Scheduler.prototype;
  22445. /**
  22446. * @param {module:echarts/model/Global} ecModel
  22447. * @param {Object} payload
  22448. */
  22449. proto.restoreData = function (ecModel, payload) {
  22450. // TODO: Only restroe needed series and components, but not all components.
  22451. // Currently `restoreData` of all of the series and component will be called.
  22452. // But some independent components like `title`, `legend`, `graphic`, `toolbox`,
  22453. // `tooltip`, `axisPointer`, etc, do not need series refresh when `setOption`,
  22454. // and some components like coordinate system, axes, dataZoom, visualMap only
  22455. // need their target series refresh.
  22456. // (1) If we are implementing this feature some day, we should consider these cases:
  22457. // if a data processor depends on a component (e.g., dataZoomProcessor depends
  22458. // on the settings of `dataZoom`), it should be re-performed if the component
  22459. // is modified by `setOption`.
  22460. // (2) If a processor depends on sevral series, speicified by its `getTargetSeries`,
  22461. // it should be re-performed when the result array of `getTargetSeries` changed.
  22462. // We use `dependencies` to cover these issues.
  22463. // (3) How to update target series when coordinate system related components modified.
  22464. // TODO: simply the dirty mechanism? Check whether only the case here can set tasks dirty,
  22465. // and this case all of the tasks will be set as dirty.
  22466. ecModel.restoreData(payload);
  22467. // Theoretically an overall task not only depends on each of its target series, but also
  22468. // depends on all of the series.
  22469. // The overall task is not in pipeline, and `ecModel.restoreData` only set pipeline tasks
  22470. // dirty. If `getTargetSeries` of an overall task returns nothing, we should also ensure
  22471. // that the overall task is set as dirty and to be performed, otherwise it probably cause
  22472. // state chaos. So we have to set dirty of all of the overall tasks manually, otherwise it
  22473. // probably cause state chaos (consider `dataZoomProcessor`).
  22474. this._stageTaskMap.each(function (taskRecord) {
  22475. var overallTask = taskRecord.overallTask;
  22476. overallTask && overallTask.dirty();
  22477. });
  22478. };
  22479. // If seriesModel provided, incremental threshold is check by series data.
  22480. proto.getPerformArgs = function (task, isBlock) {
  22481. // For overall task
  22482. if (!task.__pipeline) {
  22483. return;
  22484. }
  22485. var pipeline = this._pipelineMap.get(task.__pipeline.id);
  22486. var pCtx = pipeline.context;
  22487. var incremental = !isBlock
  22488. && pipeline.progressiveEnabled
  22489. && (!pCtx || pCtx.progressiveRender)
  22490. && task.__idxInPipeline > pipeline.blockIndex;
  22491. var step = incremental ? pipeline.step : null;
  22492. var modDataCount = pCtx && pCtx.modDataCount;
  22493. var modBy = modDataCount != null ? Math.ceil(modDataCount / step) : null;
  22494. return {step: step, modBy: modBy, modDataCount: modDataCount};
  22495. };
  22496. proto.getPipeline = function (pipelineId) {
  22497. return this._pipelineMap.get(pipelineId);
  22498. };
  22499. /**
  22500. * Current, progressive rendering starts from visual and layout.
  22501. * Always detect render mode in the same stage, avoiding that incorrect
  22502. * detection caused by data filtering.
  22503. * Caution:
  22504. * `updateStreamModes` use `seriesModel.getData()`.
  22505. */
  22506. proto.updateStreamModes = function (seriesModel, view) {
  22507. var pipeline = this._pipelineMap.get(seriesModel.uid);
  22508. var data = seriesModel.getData();
  22509. var dataLen = data.count();
  22510. // `progressiveRender` means that can render progressively in each
  22511. // animation frame. Note that some types of series do not provide
  22512. // `view.incrementalPrepareRender` but support `chart.appendData`. We
  22513. // use the term `incremental` but not `progressive` to describe the
  22514. // case that `chart.appendData`.
  22515. var progressiveRender = pipeline.progressiveEnabled
  22516. && view.incrementalPrepareRender
  22517. && dataLen >= pipeline.threshold;
  22518. var large = seriesModel.get('large') && dataLen >= seriesModel.get('largeThreshold');
  22519. // TODO: modDataCount should not updated if `appendData`, otherwise cause whole repaint.
  22520. // see `test/candlestick-large3.html`
  22521. var modDataCount = seriesModel.get('progressiveChunkMode') === 'mod' ? dataLen : null;
  22522. seriesModel.pipelineContext = pipeline.context = {
  22523. progressiveRender: progressiveRender,
  22524. modDataCount: modDataCount,
  22525. large: large
  22526. };
  22527. };
  22528. proto.restorePipelines = function (ecModel) {
  22529. var scheduler = this;
  22530. var pipelineMap = scheduler._pipelineMap = createHashMap();
  22531. ecModel.eachSeries(function (seriesModel) {
  22532. var progressive = seriesModel.getProgressive();
  22533. var pipelineId = seriesModel.uid;
  22534. pipelineMap.set(pipelineId, {
  22535. id: pipelineId,
  22536. head: null,
  22537. tail: null,
  22538. threshold: seriesModel.getProgressiveThreshold(),
  22539. progressiveEnabled: progressive
  22540. && !(seriesModel.preventIncremental && seriesModel.preventIncremental()),
  22541. blockIndex: -1,
  22542. step: Math.round(progressive || 700),
  22543. count: 0
  22544. });
  22545. pipe(scheduler, seriesModel, seriesModel.dataTask);
  22546. });
  22547. };
  22548. proto.prepareStageTasks = function () {
  22549. var stageTaskMap = this._stageTaskMap;
  22550. var ecModel = this.ecInstance.getModel();
  22551. var api = this.api;
  22552. each$1(this._allHandlers, function (handler) {
  22553. var record = stageTaskMap.get(handler.uid) || stageTaskMap.set(handler.uid, []);
  22554. handler.reset && createSeriesStageTask(this, handler, record, ecModel, api);
  22555. handler.overallReset && createOverallStageTask(this, handler, record, ecModel, api);
  22556. }, this);
  22557. };
  22558. proto.prepareView = function (view, model, ecModel, api) {
  22559. var renderTask = view.renderTask;
  22560. var context = renderTask.context;
  22561. context.model = model;
  22562. context.ecModel = ecModel;
  22563. context.api = api;
  22564. renderTask.__block = !view.incrementalPrepareRender;
  22565. pipe(this, model, renderTask);
  22566. };
  22567. proto.performDataProcessorTasks = function (ecModel, payload) {
  22568. // If we do not use `block` here, it should be considered when to update modes.
  22569. performStageTasks(this, this._dataProcessorHandlers, ecModel, payload, {block: true});
  22570. };
  22571. // opt
  22572. // opt.visualType: 'visual' or 'layout'
  22573. // opt.setDirty
  22574. proto.performVisualTasks = function (ecModel, payload, opt) {
  22575. performStageTasks(this, this._visualHandlers, ecModel, payload, opt);
  22576. };
  22577. function performStageTasks(scheduler, stageHandlers, ecModel, payload, opt) {
  22578. opt = opt || {};
  22579. var unfinished;
  22580. each$1(stageHandlers, function (stageHandler, idx) {
  22581. if (opt.visualType && opt.visualType !== stageHandler.visualType) {
  22582. return;
  22583. }
  22584. var stageHandlerRecord = scheduler._stageTaskMap.get(stageHandler.uid);
  22585. var seriesTaskMap = stageHandlerRecord.seriesTaskMap;
  22586. var overallTask = stageHandlerRecord.overallTask;
  22587. if (overallTask) {
  22588. var overallNeedDirty;
  22589. var agentStubMap = overallTask.agentStubMap;
  22590. agentStubMap.each(function (stub) {
  22591. if (needSetDirty(opt, stub)) {
  22592. stub.dirty();
  22593. overallNeedDirty = true;
  22594. }
  22595. });
  22596. overallNeedDirty && overallTask.dirty();
  22597. updatePayload(overallTask, payload);
  22598. var performArgs = scheduler.getPerformArgs(overallTask, opt.block);
  22599. // Execute stubs firstly, which may set the overall task dirty,
  22600. // then execute the overall task. And stub will call seriesModel.setData,
  22601. // which ensures that in the overallTask seriesModel.getData() will not
  22602. // return incorrect data.
  22603. agentStubMap.each(function (stub) {
  22604. stub.perform(performArgs);
  22605. });
  22606. unfinished |= overallTask.perform(performArgs);
  22607. }
  22608. else if (seriesTaskMap) {
  22609. seriesTaskMap.each(function (task, pipelineId) {
  22610. if (needSetDirty(opt, task)) {
  22611. task.dirty();
  22612. }
  22613. var performArgs = scheduler.getPerformArgs(task, opt.block);
  22614. performArgs.skip = !stageHandler.performRawSeries
  22615. && ecModel.isSeriesFiltered(task.context.model);
  22616. updatePayload(task, payload);
  22617. unfinished |= task.perform(performArgs);
  22618. });
  22619. }
  22620. });
  22621. function needSetDirty(opt, task) {
  22622. return opt.setDirty && (!opt.dirtyMap || opt.dirtyMap.get(task.__pipeline.id));
  22623. }
  22624. scheduler.unfinished |= unfinished;
  22625. }
  22626. proto.performSeriesTasks = function (ecModel) {
  22627. var unfinished;
  22628. ecModel.eachSeries(function (seriesModel) {
  22629. // Progress to the end for dataInit and dataRestore.
  22630. unfinished |= seriesModel.dataTask.perform();
  22631. });
  22632. this.unfinished |= unfinished;
  22633. };
  22634. proto.plan = function () {
  22635. // Travel pipelines, check block.
  22636. this._pipelineMap.each(function (pipeline) {
  22637. var task = pipeline.tail;
  22638. do {
  22639. if (task.__block) {
  22640. pipeline.blockIndex = task.__idxInPipeline;
  22641. break;
  22642. }
  22643. task = task.getUpstream();
  22644. }
  22645. while (task);
  22646. });
  22647. };
  22648. var updatePayload = proto.updatePayload = function (task, payload) {
  22649. payload !== 'remain' && (task.context.payload = payload);
  22650. };
  22651. function createSeriesStageTask(scheduler, stageHandler, stageHandlerRecord, ecModel, api) {
  22652. var seriesTaskMap = stageHandlerRecord.seriesTaskMap
  22653. || (stageHandlerRecord.seriesTaskMap = createHashMap());
  22654. var seriesType = stageHandler.seriesType;
  22655. var getTargetSeries = stageHandler.getTargetSeries;
  22656. // If a stageHandler should cover all series, `createOnAllSeries` should be declared mandatorily,
  22657. // to avoid some typo or abuse. Otherwise if an extension do not specify a `seriesType`,
  22658. // it works but it may cause other irrelevant charts blocked.
  22659. if (stageHandler.createOnAllSeries) {
  22660. ecModel.eachRawSeries(create);
  22661. }
  22662. else if (seriesType) {
  22663. ecModel.eachRawSeriesByType(seriesType, create);
  22664. }
  22665. else if (getTargetSeries) {
  22666. getTargetSeries(ecModel, api).each(create);
  22667. }
  22668. function create(seriesModel) {
  22669. var pipelineId = seriesModel.uid;
  22670. // Init tasks for each seriesModel only once.
  22671. // Reuse original task instance.
  22672. var task = seriesTaskMap.get(pipelineId)
  22673. || seriesTaskMap.set(pipelineId, createTask({
  22674. plan: seriesTaskPlan,
  22675. reset: seriesTaskReset,
  22676. count: seriesTaskCount
  22677. }));
  22678. task.context = {
  22679. model: seriesModel,
  22680. ecModel: ecModel,
  22681. api: api,
  22682. useClearVisual: stageHandler.isVisual && !stageHandler.isLayout,
  22683. plan: stageHandler.plan,
  22684. reset: stageHandler.reset,
  22685. scheduler: scheduler
  22686. };
  22687. pipe(scheduler, seriesModel, task);
  22688. }
  22689. // Clear unused series tasks.
  22690. var pipelineMap = scheduler._pipelineMap;
  22691. seriesTaskMap.each(function (task, pipelineId) {
  22692. if (!pipelineMap.get(pipelineId)) {
  22693. task.dispose();
  22694. seriesTaskMap.removeKey(pipelineId);
  22695. }
  22696. });
  22697. }
  22698. function createOverallStageTask(scheduler, stageHandler, stageHandlerRecord, ecModel, api) {
  22699. var overallTask = stageHandlerRecord.overallTask = stageHandlerRecord.overallTask
  22700. // For overall task, the function only be called on reset stage.
  22701. || createTask({reset: overallTaskReset});
  22702. overallTask.context = {
  22703. ecModel: ecModel,
  22704. api: api,
  22705. overallReset: stageHandler.overallReset,
  22706. scheduler: scheduler
  22707. };
  22708. // Reuse orignal stubs.
  22709. var agentStubMap = overallTask.agentStubMap = overallTask.agentStubMap || createHashMap();
  22710. var seriesType = stageHandler.seriesType;
  22711. var getTargetSeries = stageHandler.getTargetSeries;
  22712. var overallProgress = true;
  22713. var modifyOutputEnd = stageHandler.modifyOutputEnd;
  22714. // An overall task with seriesType detected or has `getTargetSeries`, we add
  22715. // stub in each pipelines, it will set the overall task dirty when the pipeline
  22716. // progress. Moreover, to avoid call the overall task each frame (too frequent),
  22717. // we set the pipeline block.
  22718. if (seriesType) {
  22719. ecModel.eachRawSeriesByType(seriesType, createStub);
  22720. }
  22721. else if (getTargetSeries) {
  22722. getTargetSeries(ecModel, api).each(createStub);
  22723. }
  22724. // Otherwise, (usually it is legancy case), the overall task will only be
  22725. // executed when upstream dirty. Otherwise the progressive rendering of all
  22726. // pipelines will be disabled unexpectedly. But it still needs stubs to receive
  22727. // dirty info from upsteam.
  22728. else {
  22729. overallProgress = false;
  22730. each$1(ecModel.getSeries(), createStub);
  22731. }
  22732. function createStub(seriesModel) {
  22733. var pipelineId = seriesModel.uid;
  22734. var stub = agentStubMap.get(pipelineId);
  22735. if (!stub) {
  22736. stub = agentStubMap.set(pipelineId, createTask(
  22737. {reset: stubReset, onDirty: stubOnDirty}
  22738. ));
  22739. // When the result of `getTargetSeries` changed, the overallTask
  22740. // should be set as dirty and re-performed.
  22741. overallTask.dirty();
  22742. }
  22743. stub.context = {
  22744. model: seriesModel,
  22745. overallProgress: overallProgress,
  22746. modifyOutputEnd: modifyOutputEnd
  22747. };
  22748. stub.agent = overallTask;
  22749. stub.__block = overallProgress;
  22750. pipe(scheduler, seriesModel, stub);
  22751. }
  22752. // Clear unused stubs.
  22753. var pipelineMap = scheduler._pipelineMap;
  22754. agentStubMap.each(function (stub, pipelineId) {
  22755. if (!pipelineMap.get(pipelineId)) {
  22756. stub.dispose();
  22757. // When the result of `getTargetSeries` changed, the overallTask
  22758. // should be set as dirty and re-performed.
  22759. overallTask.dirty();
  22760. agentStubMap.removeKey(pipelineId);
  22761. }
  22762. });
  22763. }
  22764. function overallTaskReset(context) {
  22765. context.overallReset(
  22766. context.ecModel, context.api, context.payload
  22767. );
  22768. }
  22769. function stubReset(context, upstreamContext) {
  22770. return context.overallProgress && stubProgress;
  22771. }
  22772. function stubProgress() {
  22773. this.agent.dirty();
  22774. this.getDownstream().dirty();
  22775. }
  22776. function stubOnDirty() {
  22777. this.agent && this.agent.dirty();
  22778. }
  22779. function seriesTaskPlan(context) {
  22780. return context.plan && context.plan(
  22781. context.model, context.ecModel, context.api, context.payload
  22782. );
  22783. }
  22784. function seriesTaskReset(context) {
  22785. if (context.useClearVisual) {
  22786. context.data.clearAllVisual();
  22787. }
  22788. var resetDefines = context.resetDefines = normalizeToArray(context.reset(
  22789. context.model, context.ecModel, context.api, context.payload
  22790. ));
  22791. return resetDefines.length > 1
  22792. ? map(resetDefines, function (v, idx) {
  22793. return makeSeriesTaskProgress(idx);
  22794. })
  22795. : singleSeriesTaskProgress;
  22796. }
  22797. var singleSeriesTaskProgress = makeSeriesTaskProgress(0);
  22798. function makeSeriesTaskProgress(resetDefineIdx) {
  22799. return function (params, context) {
  22800. var data = context.data;
  22801. var resetDefine = context.resetDefines[resetDefineIdx];
  22802. if (resetDefine && resetDefine.dataEach) {
  22803. for (var i = params.start; i < params.end; i++) {
  22804. resetDefine.dataEach(data, i);
  22805. }
  22806. }
  22807. else if (resetDefine && resetDefine.progress) {
  22808. resetDefine.progress(params, data);
  22809. }
  22810. };
  22811. }
  22812. function seriesTaskCount(context) {
  22813. return context.data.count();
  22814. }
  22815. function pipe(scheduler, seriesModel, task) {
  22816. var pipelineId = seriesModel.uid;
  22817. var pipeline = scheduler._pipelineMap.get(pipelineId);
  22818. !pipeline.head && (pipeline.head = task);
  22819. pipeline.tail && pipeline.tail.pipe(task);
  22820. pipeline.tail = task;
  22821. task.__idxInPipeline = pipeline.count++;
  22822. task.__pipeline = pipeline;
  22823. }
  22824. Scheduler.wrapStageHandler = function (stageHandler, visualType) {
  22825. if (isFunction$1(stageHandler)) {
  22826. stageHandler = {
  22827. overallReset: stageHandler,
  22828. seriesType: detectSeriseType(stageHandler)
  22829. };
  22830. }
  22831. stageHandler.uid = getUID('stageHandler');
  22832. visualType && (stageHandler.visualType = visualType);
  22833. return stageHandler;
  22834. };
  22835. /**
  22836. * Only some legacy stage handlers (usually in echarts extensions) are pure function.
  22837. * To ensure that they can work normally, they should work in block mode, that is,
  22838. * they should not be started util the previous tasks finished. So they cause the
  22839. * progressive rendering disabled. We try to detect the series type, to narrow down
  22840. * the block range to only the series type they concern, but not all series.
  22841. */
  22842. function detectSeriseType(legacyFunc) {
  22843. seriesType = null;
  22844. try {
  22845. // Assume there is no async when calling `eachSeriesByType`.
  22846. legacyFunc(ecModelMock, apiMock);
  22847. }
  22848. catch (e) {
  22849. }
  22850. return seriesType;
  22851. }
  22852. var ecModelMock = {};
  22853. var apiMock = {};
  22854. var seriesType;
  22855. mockMethods(ecModelMock, GlobalModel);
  22856. mockMethods(apiMock, ExtensionAPI);
  22857. ecModelMock.eachSeriesByType = ecModelMock.eachRawSeriesByType = function (type) {
  22858. seriesType = type;
  22859. };
  22860. ecModelMock.eachComponent = function (cond) {
  22861. if (cond.mainType === 'series' && cond.subType) {
  22862. seriesType = cond.subType;
  22863. }
  22864. };
  22865. function mockMethods(target, Clz) {
  22866. /* eslint-disable */
  22867. for (var name in Clz.prototype) {
  22868. // Do not use hasOwnProperty
  22869. target[name] = noop;
  22870. }
  22871. /* eslint-enable */
  22872. }
  22873. /*
  22874. * Licensed to the Apache Software Foundation (ASF) under one
  22875. * or more contributor license agreements. See the NOTICE file
  22876. * distributed with this work for additional information
  22877. * regarding copyright ownership. The ASF licenses this file
  22878. * to you under the Apache License, Version 2.0 (the
  22879. * "License"); you may not use this file except in compliance
  22880. * with the License. You may obtain a copy of the License at
  22881. *
  22882. * http://www.apache.org/licenses/LICENSE-2.0
  22883. *
  22884. * Unless required by applicable law or agreed to in writing,
  22885. * software distributed under the License is distributed on an
  22886. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  22887. * KIND, either express or implied. See the License for the
  22888. * specific language governing permissions and limitations
  22889. * under the License.
  22890. */
  22891. var colorAll = [
  22892. '#37A2DA', '#32C5E9', '#67E0E3', '#9FE6B8', '#FFDB5C', '#ff9f7f',
  22893. '#fb7293', '#E062AE', '#E690D1', '#e7bcf3', '#9d96f5', '#8378EA', '#96BFFF'
  22894. ];
  22895. var lightTheme = {
  22896. color: colorAll,
  22897. colorLayer: [
  22898. ['#37A2DA', '#ffd85c', '#fd7b5f'],
  22899. ['#37A2DA', '#67E0E3', '#FFDB5C', '#ff9f7f', '#E062AE', '#9d96f5'],
  22900. ['#37A2DA', '#32C5E9', '#9FE6B8', '#FFDB5C', '#ff9f7f', '#fb7293', '#e7bcf3', '#8378EA', '#96BFFF'],
  22901. colorAll
  22902. ]
  22903. };
  22904. /*
  22905. * Licensed to the Apache Software Foundation (ASF) under one
  22906. * or more contributor license agreements. See the NOTICE file
  22907. * distributed with this work for additional information
  22908. * regarding copyright ownership. The ASF licenses this file
  22909. * to you under the Apache License, Version 2.0 (the
  22910. * "License"); you may not use this file except in compliance
  22911. * with the License. You may obtain a copy of the License at
  22912. *
  22913. * http://www.apache.org/licenses/LICENSE-2.0
  22914. *
  22915. * Unless required by applicable law or agreed to in writing,
  22916. * software distributed under the License is distributed on an
  22917. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  22918. * KIND, either express or implied. See the License for the
  22919. * specific language governing permissions and limitations
  22920. * under the License.
  22921. */
  22922. var contrastColor = '#eee';
  22923. var axisCommon = function () {
  22924. return {
  22925. axisLine: {
  22926. lineStyle: {
  22927. color: contrastColor
  22928. }
  22929. },
  22930. axisTick: {
  22931. lineStyle: {
  22932. color: contrastColor
  22933. }
  22934. },
  22935. axisLabel: {
  22936. textStyle: {
  22937. color: contrastColor
  22938. }
  22939. },
  22940. splitLine: {
  22941. lineStyle: {
  22942. type: 'dashed',
  22943. color: '#aaa'
  22944. }
  22945. },
  22946. splitArea: {
  22947. areaStyle: {
  22948. color: contrastColor
  22949. }
  22950. }
  22951. };
  22952. };
  22953. var colorPalette = [
  22954. '#dd6b66', '#759aa0', '#e69d87', '#8dc1a9', '#ea7e53',
  22955. '#eedd78', '#73a373', '#73b9bc', '#7289ab', '#91ca8c', '#f49f42'
  22956. ];
  22957. var theme = {
  22958. color: colorPalette,
  22959. backgroundColor: '#333',
  22960. tooltip: {
  22961. axisPointer: {
  22962. lineStyle: {
  22963. color: contrastColor
  22964. },
  22965. crossStyle: {
  22966. color: contrastColor
  22967. }
  22968. }
  22969. },
  22970. legend: {
  22971. textStyle: {
  22972. color: contrastColor
  22973. }
  22974. },
  22975. textStyle: {
  22976. color: contrastColor
  22977. },
  22978. title: {
  22979. textStyle: {
  22980. color: contrastColor
  22981. }
  22982. },
  22983. toolbox: {
  22984. iconStyle: {
  22985. normal: {
  22986. borderColor: contrastColor
  22987. }
  22988. }
  22989. },
  22990. dataZoom: {
  22991. textStyle: {
  22992. color: contrastColor
  22993. }
  22994. },
  22995. visualMap: {
  22996. textStyle: {
  22997. color: contrastColor
  22998. }
  22999. },
  23000. timeline: {
  23001. lineStyle: {
  23002. color: contrastColor
  23003. },
  23004. itemStyle: {
  23005. normal: {
  23006. color: colorPalette[1]
  23007. }
  23008. },
  23009. label: {
  23010. normal: {
  23011. textStyle: {
  23012. color: contrastColor
  23013. }
  23014. }
  23015. },
  23016. controlStyle: {
  23017. normal: {
  23018. color: contrastColor,
  23019. borderColor: contrastColor
  23020. }
  23021. }
  23022. },
  23023. timeAxis: axisCommon(),
  23024. logAxis: axisCommon(),
  23025. valueAxis: axisCommon(),
  23026. categoryAxis: axisCommon(),
  23027. line: {
  23028. symbol: 'circle'
  23029. },
  23030. graph: {
  23031. color: colorPalette
  23032. },
  23033. gauge: {
  23034. title: {
  23035. textStyle: {
  23036. color: contrastColor
  23037. }
  23038. }
  23039. },
  23040. candlestick: {
  23041. itemStyle: {
  23042. normal: {
  23043. color: '#FD1050',
  23044. color0: '#0CF49B',
  23045. borderColor: '#FD1050',
  23046. borderColor0: '#0CF49B'
  23047. }
  23048. }
  23049. }
  23050. };
  23051. theme.categoryAxis.splitLine.show = false;
  23052. /*
  23053. * Licensed to the Apache Software Foundation (ASF) under one
  23054. * or more contributor license agreements. See the NOTICE file
  23055. * distributed with this work for additional information
  23056. * regarding copyright ownership. The ASF licenses this file
  23057. * to you under the Apache License, Version 2.0 (the
  23058. * "License"); you may not use this file except in compliance
  23059. * with the License. You may obtain a copy of the License at
  23060. *
  23061. * http://www.apache.org/licenses/LICENSE-2.0
  23062. *
  23063. * Unless required by applicable law or agreed to in writing,
  23064. * software distributed under the License is distributed on an
  23065. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  23066. * KIND, either express or implied. See the License for the
  23067. * specific language governing permissions and limitations
  23068. * under the License.
  23069. */
  23070. /**
  23071. * This module is imported by echarts directly.
  23072. *
  23073. * Notice:
  23074. * Always keep this file exists for backward compatibility.
  23075. * Because before 4.1.0, dataset is an optional component,
  23076. * some users may import this module manually.
  23077. */
  23078. ComponentModel.extend({
  23079. type: 'dataset',
  23080. /**
  23081. * @protected
  23082. */
  23083. defaultOption: {
  23084. // 'row', 'column'
  23085. seriesLayoutBy: SERIES_LAYOUT_BY_COLUMN,
  23086. // null/'auto': auto detect header, see "module:echarts/data/helper/sourceHelper"
  23087. sourceHeader: null,
  23088. dimensions: null,
  23089. source: null
  23090. },
  23091. optionUpdated: function () {
  23092. detectSourceFormat(this);
  23093. }
  23094. });
  23095. Component$1.extend({
  23096. type: 'dataset'
  23097. });
  23098. /**
  23099. * 椭圆形状
  23100. * @module zrender/graphic/shape/Ellipse
  23101. */
  23102. var Ellipse = Path.extend({
  23103. type: 'ellipse',
  23104. shape: {
  23105. cx: 0, cy: 0,
  23106. rx: 0, ry: 0
  23107. },
  23108. buildPath: function (ctx, shape) {
  23109. var k = 0.5522848;
  23110. var x = shape.cx;
  23111. var y = shape.cy;
  23112. var a = shape.rx;
  23113. var b = shape.ry;
  23114. var ox = a * k; // 水平控制点偏移量
  23115. var oy = b * k; // 垂直控制点偏移量
  23116. // 从椭圆的左端点开始顺时针绘制四条三次贝塞尔曲线
  23117. ctx.moveTo(x - a, y);
  23118. ctx.bezierCurveTo(x - a, y - oy, x - ox, y - b, x, y - b);
  23119. ctx.bezierCurveTo(x + ox, y - b, x + a, y - oy, x + a, y);
  23120. ctx.bezierCurveTo(x + a, y + oy, x + ox, y + b, x, y + b);
  23121. ctx.bezierCurveTo(x - ox, y + b, x - a, y + oy, x - a, y);
  23122. ctx.closePath();
  23123. }
  23124. });
  23125. // import RadialGradient from '../graphic/RadialGradient';
  23126. // import Pattern from '../graphic/Pattern';
  23127. // import * as vector from '../core/vector';
  23128. // Most of the values can be separated by comma and/or white space.
  23129. var DILIMITER_REG = /[\s,]+/;
  23130. /**
  23131. * For big svg string, this method might be time consuming.
  23132. *
  23133. * @param {string} svg xml string
  23134. * @return {Object} xml root.
  23135. */
  23136. function parseXML(svg) {
  23137. if (isString(svg)) {
  23138. var parser = new DOMParser();
  23139. svg = parser.parseFromString(svg, 'text/xml');
  23140. }
  23141. // Document node. If using $.get, doc node may be input.
  23142. if (svg.nodeType === 9) {
  23143. svg = svg.firstChild;
  23144. }
  23145. // nodeName of <!DOCTYPE svg> is also 'svg'.
  23146. while (svg.nodeName.toLowerCase() !== 'svg' || svg.nodeType !== 1) {
  23147. svg = svg.nextSibling;
  23148. }
  23149. return svg;
  23150. }
  23151. function SVGParser() {
  23152. this._defs = {};
  23153. this._root = null;
  23154. this._isDefine = false;
  23155. this._isText = false;
  23156. }
  23157. SVGParser.prototype.parse = function (xml, opt) {
  23158. opt = opt || {};
  23159. var svg = parseXML(xml);
  23160. if (!svg) {
  23161. throw new Error('Illegal svg');
  23162. }
  23163. var root = new Group();
  23164. this._root = root;
  23165. // parse view port
  23166. var viewBox = svg.getAttribute('viewBox') || '';
  23167. // If width/height not specified, means "100%" of `opt.width/height`.
  23168. // TODO: Other percent value not supported yet.
  23169. var width = parseFloat(svg.getAttribute('width') || opt.width);
  23170. var height = parseFloat(svg.getAttribute('height') || opt.height);
  23171. // If width/height not specified, set as null for output.
  23172. isNaN(width) && (width = null);
  23173. isNaN(height) && (height = null);
  23174. // Apply inline style on svg element.
  23175. parseAttributes(svg, root, null, true);
  23176. var child = svg.firstChild;
  23177. while (child) {
  23178. this._parseNode(child, root);
  23179. child = child.nextSibling;
  23180. }
  23181. var viewBoxRect;
  23182. var viewBoxTransform;
  23183. if (viewBox) {
  23184. var viewBoxArr = trim(viewBox).split(DILIMITER_REG);
  23185. // Some invalid case like viewBox: 'none'.
  23186. if (viewBoxArr.length >= 4) {
  23187. viewBoxRect = {
  23188. x: parseFloat(viewBoxArr[0] || 0),
  23189. y: parseFloat(viewBoxArr[1] || 0),
  23190. width: parseFloat(viewBoxArr[2]),
  23191. height: parseFloat(viewBoxArr[3])
  23192. };
  23193. }
  23194. }
  23195. if (viewBoxRect && width != null && height != null) {
  23196. viewBoxTransform = makeViewBoxTransform(viewBoxRect, width, height);
  23197. if (!opt.ignoreViewBox) {
  23198. // If set transform on the output group, it probably bring trouble when
  23199. // some users only intend to show the clipped content inside the viewBox,
  23200. // but not intend to transform the output group. So we keep the output
  23201. // group no transform. If the user intend to use the viewBox as a
  23202. // camera, just set `opt.ignoreViewBox` as `true` and set transfrom
  23203. // manually according to the viewBox info in the output of this method.
  23204. var elRoot = root;
  23205. root = new Group();
  23206. root.add(elRoot);
  23207. elRoot.scale = viewBoxTransform.scale.slice();
  23208. elRoot.position = viewBoxTransform.position.slice();
  23209. }
  23210. }
  23211. // Some shapes might be overflow the viewport, which should be
  23212. // clipped despite whether the viewBox is used, as the SVG does.
  23213. if (!opt.ignoreRootClip && width != null && height != null) {
  23214. root.setClipPath(new Rect({
  23215. shape: {x: 0, y: 0, width: width, height: height}
  23216. }));
  23217. }
  23218. // Set width/height on group just for output the viewport size.
  23219. return {
  23220. root: root,
  23221. width: width,
  23222. height: height,
  23223. viewBoxRect: viewBoxRect,
  23224. viewBoxTransform: viewBoxTransform
  23225. };
  23226. };
  23227. SVGParser.prototype._parseNode = function (xmlNode, parentGroup) {
  23228. var nodeName = xmlNode.nodeName.toLowerCase();
  23229. // TODO
  23230. // support <style>...</style> in svg, where nodeName is 'style',
  23231. // CSS classes is defined globally wherever the style tags are declared.
  23232. if (nodeName === 'defs') {
  23233. // define flag
  23234. this._isDefine = true;
  23235. }
  23236. else if (nodeName === 'text') {
  23237. this._isText = true;
  23238. }
  23239. var el;
  23240. if (this._isDefine) {
  23241. var parser = defineParsers[nodeName];
  23242. if (parser) {
  23243. var def = parser.call(this, xmlNode);
  23244. var id = xmlNode.getAttribute('id');
  23245. if (id) {
  23246. this._defs[id] = def;
  23247. }
  23248. }
  23249. }
  23250. else {
  23251. var parser = nodeParsers[nodeName];
  23252. if (parser) {
  23253. el = parser.call(this, xmlNode, parentGroup);
  23254. parentGroup.add(el);
  23255. }
  23256. }
  23257. var child = xmlNode.firstChild;
  23258. while (child) {
  23259. if (child.nodeType === 1) {
  23260. this._parseNode(child, el);
  23261. }
  23262. // Is text
  23263. if (child.nodeType === 3 && this._isText) {
  23264. this._parseText(child, el);
  23265. }
  23266. child = child.nextSibling;
  23267. }
  23268. // Quit define
  23269. if (nodeName === 'defs') {
  23270. this._isDefine = false;
  23271. }
  23272. else if (nodeName === 'text') {
  23273. this._isText = false;
  23274. }
  23275. };
  23276. SVGParser.prototype._parseText = function (xmlNode, parentGroup) {
  23277. if (xmlNode.nodeType === 1) {
  23278. var dx = xmlNode.getAttribute('dx') || 0;
  23279. var dy = xmlNode.getAttribute('dy') || 0;
  23280. this._textX += parseFloat(dx);
  23281. this._textY += parseFloat(dy);
  23282. }
  23283. var text = new Text({
  23284. style: {
  23285. text: xmlNode.textContent,
  23286. transformText: true
  23287. },
  23288. position: [this._textX || 0, this._textY || 0]
  23289. });
  23290. inheritStyle(parentGroup, text);
  23291. parseAttributes(xmlNode, text, this._defs);
  23292. var fontSize = text.style.fontSize;
  23293. if (fontSize && fontSize < 9) {
  23294. // PENDING
  23295. text.style.fontSize = 9;
  23296. text.scale = text.scale || [1, 1];
  23297. text.scale[0] *= fontSize / 9;
  23298. text.scale[1] *= fontSize / 9;
  23299. }
  23300. var rect = text.getBoundingRect();
  23301. this._textX += rect.width;
  23302. parentGroup.add(text);
  23303. return text;
  23304. };
  23305. var nodeParsers = {
  23306. 'g': function (xmlNode, parentGroup) {
  23307. var g = new Group();
  23308. inheritStyle(parentGroup, g);
  23309. parseAttributes(xmlNode, g, this._defs);
  23310. return g;
  23311. },
  23312. 'rect': function (xmlNode, parentGroup) {
  23313. var rect = new Rect();
  23314. inheritStyle(parentGroup, rect);
  23315. parseAttributes(xmlNode, rect, this._defs);
  23316. rect.setShape({
  23317. x: parseFloat(xmlNode.getAttribute('x') || 0),
  23318. y: parseFloat(xmlNode.getAttribute('y') || 0),
  23319. width: parseFloat(xmlNode.getAttribute('width') || 0),
  23320. height: parseFloat(xmlNode.getAttribute('height') || 0)
  23321. });
  23322. // console.log(xmlNode.getAttribute('transform'));
  23323. // console.log(rect.transform);
  23324. return rect;
  23325. },
  23326. 'circle': function (xmlNode, parentGroup) {
  23327. var circle = new Circle();
  23328. inheritStyle(parentGroup, circle);
  23329. parseAttributes(xmlNode, circle, this._defs);
  23330. circle.setShape({
  23331. cx: parseFloat(xmlNode.getAttribute('cx') || 0),
  23332. cy: parseFloat(xmlNode.getAttribute('cy') || 0),
  23333. r: parseFloat(xmlNode.getAttribute('r') || 0)
  23334. });
  23335. return circle;
  23336. },
  23337. 'line': function (xmlNode, parentGroup) {
  23338. var line = new Line();
  23339. inheritStyle(parentGroup, line);
  23340. parseAttributes(xmlNode, line, this._defs);
  23341. line.setShape({
  23342. x1: parseFloat(xmlNode.getAttribute('x1') || 0),
  23343. y1: parseFloat(xmlNode.getAttribute('y1') || 0),
  23344. x2: parseFloat(xmlNode.getAttribute('x2') || 0),
  23345. y2: parseFloat(xmlNode.getAttribute('y2') || 0)
  23346. });
  23347. return line;
  23348. },
  23349. 'ellipse': function (xmlNode, parentGroup) {
  23350. var ellipse = new Ellipse();
  23351. inheritStyle(parentGroup, ellipse);
  23352. parseAttributes(xmlNode, ellipse, this._defs);
  23353. ellipse.setShape({
  23354. cx: parseFloat(xmlNode.getAttribute('cx') || 0),
  23355. cy: parseFloat(xmlNode.getAttribute('cy') || 0),
  23356. rx: parseFloat(xmlNode.getAttribute('rx') || 0),
  23357. ry: parseFloat(xmlNode.getAttribute('ry') || 0)
  23358. });
  23359. return ellipse;
  23360. },
  23361. 'polygon': function (xmlNode, parentGroup) {
  23362. var points = xmlNode.getAttribute('points');
  23363. if (points) {
  23364. points = parsePoints(points);
  23365. }
  23366. var polygon = new Polygon({
  23367. shape: {
  23368. points: points || []
  23369. }
  23370. });
  23371. inheritStyle(parentGroup, polygon);
  23372. parseAttributes(xmlNode, polygon, this._defs);
  23373. return polygon;
  23374. },
  23375. 'polyline': function (xmlNode, parentGroup) {
  23376. var path = new Path();
  23377. inheritStyle(parentGroup, path);
  23378. parseAttributes(xmlNode, path, this._defs);
  23379. var points = xmlNode.getAttribute('points');
  23380. if (points) {
  23381. points = parsePoints(points);
  23382. }
  23383. var polyline = new Polyline({
  23384. shape: {
  23385. points: points || []
  23386. }
  23387. });
  23388. return polyline;
  23389. },
  23390. 'image': function (xmlNode, parentGroup) {
  23391. var img = new ZImage();
  23392. inheritStyle(parentGroup, img);
  23393. parseAttributes(xmlNode, img, this._defs);
  23394. img.setStyle({
  23395. image: xmlNode.getAttribute('xlink:href'),
  23396. x: xmlNode.getAttribute('x'),
  23397. y: xmlNode.getAttribute('y'),
  23398. width: xmlNode.getAttribute('width'),
  23399. height: xmlNode.getAttribute('height')
  23400. });
  23401. return img;
  23402. },
  23403. 'text': function (xmlNode, parentGroup) {
  23404. var x = xmlNode.getAttribute('x') || 0;
  23405. var y = xmlNode.getAttribute('y') || 0;
  23406. var dx = xmlNode.getAttribute('dx') || 0;
  23407. var dy = xmlNode.getAttribute('dy') || 0;
  23408. this._textX = parseFloat(x) + parseFloat(dx);
  23409. this._textY = parseFloat(y) + parseFloat(dy);
  23410. var g = new Group();
  23411. inheritStyle(parentGroup, g);
  23412. parseAttributes(xmlNode, g, this._defs);
  23413. return g;
  23414. },
  23415. 'tspan': function (xmlNode, parentGroup) {
  23416. var x = xmlNode.getAttribute('x');
  23417. var y = xmlNode.getAttribute('y');
  23418. if (x != null) {
  23419. // new offset x
  23420. this._textX = parseFloat(x);
  23421. }
  23422. if (y != null) {
  23423. // new offset y
  23424. this._textY = parseFloat(y);
  23425. }
  23426. var dx = xmlNode.getAttribute('dx') || 0;
  23427. var dy = xmlNode.getAttribute('dy') || 0;
  23428. var g = new Group();
  23429. inheritStyle(parentGroup, g);
  23430. parseAttributes(xmlNode, g, this._defs);
  23431. this._textX += dx;
  23432. this._textY += dy;
  23433. return g;
  23434. },
  23435. 'path': function (xmlNode, parentGroup) {
  23436. // TODO svg fill rule
  23437. // https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/fill-rule
  23438. // path.style.globalCompositeOperation = 'xor';
  23439. var d = xmlNode.getAttribute('d') || '';
  23440. // Performance sensitive.
  23441. var path = createFromString(d);
  23442. inheritStyle(parentGroup, path);
  23443. parseAttributes(xmlNode, path, this._defs);
  23444. return path;
  23445. }
  23446. };
  23447. var defineParsers = {
  23448. 'lineargradient': function (xmlNode) {
  23449. var x1 = parseInt(xmlNode.getAttribute('x1') || 0, 10);
  23450. var y1 = parseInt(xmlNode.getAttribute('y1') || 0, 10);
  23451. var x2 = parseInt(xmlNode.getAttribute('x2') || 10, 10);
  23452. var y2 = parseInt(xmlNode.getAttribute('y2') || 0, 10);
  23453. var gradient = new LinearGradient(x1, y1, x2, y2);
  23454. _parseGradientColorStops(xmlNode, gradient);
  23455. return gradient;
  23456. },
  23457. 'radialgradient': function (xmlNode) {
  23458. }
  23459. };
  23460. function _parseGradientColorStops(xmlNode, gradient) {
  23461. var stop = xmlNode.firstChild;
  23462. while (stop) {
  23463. if (stop.nodeType === 1) {
  23464. var offset = stop.getAttribute('offset');
  23465. if (offset.indexOf('%') > 0) { // percentage
  23466. offset = parseInt(offset, 10) / 100;
  23467. }
  23468. else if (offset) { // number from 0 to 1
  23469. offset = parseFloat(offset);
  23470. }
  23471. else {
  23472. offset = 0;
  23473. }
  23474. var stopColor = stop.getAttribute('stop-color') || '#000000';
  23475. gradient.addColorStop(offset, stopColor);
  23476. }
  23477. stop = stop.nextSibling;
  23478. }
  23479. }
  23480. function inheritStyle(parent, child) {
  23481. if (parent && parent.__inheritedStyle) {
  23482. if (!child.__inheritedStyle) {
  23483. child.__inheritedStyle = {};
  23484. }
  23485. defaults(child.__inheritedStyle, parent.__inheritedStyle);
  23486. }
  23487. }
  23488. function parsePoints(pointsString) {
  23489. var list = trim(pointsString).split(DILIMITER_REG);
  23490. var points = [];
  23491. for (var i = 0; i < list.length; i += 2) {
  23492. var x = parseFloat(list[i]);
  23493. var y = parseFloat(list[i + 1]);
  23494. points.push([x, y]);
  23495. }
  23496. return points;
  23497. }
  23498. var attributesMap = {
  23499. 'fill': 'fill',
  23500. 'stroke': 'stroke',
  23501. 'stroke-width': 'lineWidth',
  23502. 'opacity': 'opacity',
  23503. 'fill-opacity': 'fillOpacity',
  23504. 'stroke-opacity': 'strokeOpacity',
  23505. 'stroke-dasharray': 'lineDash',
  23506. 'stroke-dashoffset': 'lineDashOffset',
  23507. 'stroke-linecap': 'lineCap',
  23508. 'stroke-linejoin': 'lineJoin',
  23509. 'stroke-miterlimit': 'miterLimit',
  23510. 'font-family': 'fontFamily',
  23511. 'font-size': 'fontSize',
  23512. 'font-style': 'fontStyle',
  23513. 'font-weight': 'fontWeight',
  23514. 'text-align': 'textAlign',
  23515. 'alignment-baseline': 'textBaseline'
  23516. };
  23517. function parseAttributes(xmlNode, el, defs, onlyInlineStyle) {
  23518. var zrStyle = el.__inheritedStyle || {};
  23519. var isTextEl = el.type === 'text';
  23520. // TODO Shadow
  23521. if (xmlNode.nodeType === 1) {
  23522. parseTransformAttribute(xmlNode, el);
  23523. extend(zrStyle, parseStyleAttribute(xmlNode));
  23524. if (!onlyInlineStyle) {
  23525. for (var svgAttrName in attributesMap) {
  23526. if (attributesMap.hasOwnProperty(svgAttrName)) {
  23527. var attrValue = xmlNode.getAttribute(svgAttrName);
  23528. if (attrValue != null) {
  23529. zrStyle[attributesMap[svgAttrName]] = attrValue;
  23530. }
  23531. }
  23532. }
  23533. }
  23534. }
  23535. var elFillProp = isTextEl ? 'textFill' : 'fill';
  23536. var elStrokeProp = isTextEl ? 'textStroke' : 'stroke';
  23537. el.style = el.style || new Style();
  23538. var elStyle = el.style;
  23539. zrStyle.fill != null && elStyle.set(elFillProp, getPaint(zrStyle.fill, defs));
  23540. zrStyle.stroke != null && elStyle.set(elStrokeProp, getPaint(zrStyle.stroke, defs));
  23541. each$1([
  23542. 'lineWidth', 'opacity', 'fillOpacity', 'strokeOpacity', 'miterLimit', 'fontSize'
  23543. ], function (propName) {
  23544. var elPropName = (propName === 'lineWidth' && isTextEl) ? 'textStrokeWidth' : propName;
  23545. zrStyle[propName] != null && elStyle.set(elPropName, parseFloat(zrStyle[propName]));
  23546. });
  23547. if (!zrStyle.textBaseline || zrStyle.textBaseline === 'auto') {
  23548. zrStyle.textBaseline = 'alphabetic';
  23549. }
  23550. if (zrStyle.textBaseline === 'alphabetic') {
  23551. zrStyle.textBaseline = 'bottom';
  23552. }
  23553. if (zrStyle.textAlign === 'start') {
  23554. zrStyle.textAlign = 'left';
  23555. }
  23556. if (zrStyle.textAlign === 'end') {
  23557. zrStyle.textAlign = 'right';
  23558. }
  23559. each$1(['lineDashOffset', 'lineCap', 'lineJoin',
  23560. 'fontWeight', 'fontFamily', 'fontStyle', 'textAlign', 'textBaseline'
  23561. ], function (propName) {
  23562. zrStyle[propName] != null && elStyle.set(propName, zrStyle[propName]);
  23563. });
  23564. if (zrStyle.lineDash) {
  23565. el.style.lineDash = trim(zrStyle.lineDash).split(DILIMITER_REG);
  23566. }
  23567. if (elStyle[elStrokeProp] && elStyle[elStrokeProp] !== 'none') {
  23568. // enable stroke
  23569. el[elStrokeProp] = true;
  23570. }
  23571. el.__inheritedStyle = zrStyle;
  23572. }
  23573. var urlRegex = /url\(\s*#(.*?)\)/;
  23574. function getPaint(str, defs) {
  23575. // if (str === 'none') {
  23576. // return;
  23577. // }
  23578. var urlMatch = defs && str && str.match(urlRegex);
  23579. if (urlMatch) {
  23580. var url = trim(urlMatch[1]);
  23581. var def = defs[url];
  23582. return def;
  23583. }
  23584. return str;
  23585. }
  23586. var transformRegex = /(translate|scale|rotate|skewX|skewY|matrix)\(([\-\s0-9\.e,]*)\)/g;
  23587. function parseTransformAttribute(xmlNode, node) {
  23588. var transform = xmlNode.getAttribute('transform');
  23589. if (transform) {
  23590. transform = transform.replace(/,/g, ' ');
  23591. var m = null;
  23592. var transformOps = [];
  23593. transform.replace(transformRegex, function (str, type, value) {
  23594. transformOps.push(type, value);
  23595. });
  23596. for (var i = transformOps.length - 1; i > 0; i -= 2) {
  23597. var value = transformOps[i];
  23598. var type = transformOps[i - 1];
  23599. m = m || create$1();
  23600. switch (type) {
  23601. case 'translate':
  23602. value = trim(value).split(DILIMITER_REG);
  23603. translate(m, m, [parseFloat(value[0]), parseFloat(value[1] || 0)]);
  23604. break;
  23605. case 'scale':
  23606. value = trim(value).split(DILIMITER_REG);
  23607. scale$1(m, m, [parseFloat(value[0]), parseFloat(value[1] || value[0])]);
  23608. break;
  23609. case 'rotate':
  23610. value = trim(value).split(DILIMITER_REG);
  23611. rotate(m, m, parseFloat(value[0]));
  23612. break;
  23613. case 'skew':
  23614. value = trim(value).split(DILIMITER_REG);
  23615. console.warn('Skew transform is not supported yet');
  23616. break;
  23617. case 'matrix':
  23618. var value = trim(value).split(DILIMITER_REG);
  23619. m[0] = parseFloat(value[0]);
  23620. m[1] = parseFloat(value[1]);
  23621. m[2] = parseFloat(value[2]);
  23622. m[3] = parseFloat(value[3]);
  23623. m[4] = parseFloat(value[4]);
  23624. m[5] = parseFloat(value[5]);
  23625. break;
  23626. }
  23627. }
  23628. node.setLocalTransform(m);
  23629. }
  23630. }
  23631. // Value may contain space.
  23632. var styleRegex = /([^\s:;]+)\s*:\s*([^:;]+)/g;
  23633. function parseStyleAttribute(xmlNode) {
  23634. var style = xmlNode.getAttribute('style');
  23635. var result = {};
  23636. if (!style) {
  23637. return result;
  23638. }
  23639. var styleList = {};
  23640. styleRegex.lastIndex = 0;
  23641. var styleRegResult;
  23642. while ((styleRegResult = styleRegex.exec(style)) != null) {
  23643. styleList[styleRegResult[1]] = styleRegResult[2];
  23644. }
  23645. for (var svgAttrName in attributesMap) {
  23646. if (attributesMap.hasOwnProperty(svgAttrName) && styleList[svgAttrName] != null) {
  23647. result[attributesMap[svgAttrName]] = styleList[svgAttrName];
  23648. }
  23649. }
  23650. return result;
  23651. }
  23652. /**
  23653. * @param {Array.<number>} viewBoxRect
  23654. * @param {number} width
  23655. * @param {number} height
  23656. * @return {Object} {scale, position}
  23657. */
  23658. function makeViewBoxTransform(viewBoxRect, width, height) {
  23659. var scaleX = width / viewBoxRect.width;
  23660. var scaleY = height / viewBoxRect.height;
  23661. var scale = Math.min(scaleX, scaleY);
  23662. // preserveAspectRatio 'xMidYMid'
  23663. var viewBoxScale = [scale, scale];
  23664. var viewBoxPosition = [
  23665. -(viewBoxRect.x + viewBoxRect.width / 2) * scale + width / 2,
  23666. -(viewBoxRect.y + viewBoxRect.height / 2) * scale + height / 2
  23667. ];
  23668. return {
  23669. scale: viewBoxScale,
  23670. position: viewBoxPosition
  23671. };
  23672. }
  23673. /**
  23674. * @param {string|XMLElement} xml
  23675. * @param {Object} [opt]
  23676. * @param {number} [opt.width] Default width if svg width not specified or is a percent value.
  23677. * @param {number} [opt.height] Default height if svg height not specified or is a percent value.
  23678. * @param {boolean} [opt.ignoreViewBox]
  23679. * @param {boolean} [opt.ignoreRootClip]
  23680. * @return {Object} result:
  23681. * {
  23682. * root: Group, The root of the the result tree of zrender shapes,
  23683. * width: number, the viewport width of the SVG,
  23684. * height: number, the viewport height of the SVG,
  23685. * viewBoxRect: {x, y, width, height}, the declared viewBox rect of the SVG, if exists,
  23686. * viewBoxTransform: the {scale, position} calculated by viewBox and viewport, is exists.
  23687. * }
  23688. */
  23689. function parseSVG(xml, opt) {
  23690. var parser = new SVGParser();
  23691. return parser.parse(xml, opt);
  23692. }
  23693. /*
  23694. * Licensed to the Apache Software Foundation (ASF) under one
  23695. * or more contributor license agreements. See the NOTICE file
  23696. * distributed with this work for additional information
  23697. * regarding copyright ownership. The ASF licenses this file
  23698. * to you under the Apache License, Version 2.0 (the
  23699. * "License"); you may not use this file except in compliance
  23700. * with the License. You may obtain a copy of the License at
  23701. *
  23702. * http://www.apache.org/licenses/LICENSE-2.0
  23703. *
  23704. * Unless required by applicable law or agreed to in writing,
  23705. * software distributed under the License is distributed on an
  23706. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  23707. * KIND, either express or implied. See the License for the
  23708. * specific language governing permissions and limitations
  23709. * under the License.
  23710. */
  23711. var storage = createHashMap();
  23712. // For minimize the code size of common echarts package,
  23713. // do not put too much logic in this module.
  23714. var mapDataStorage = {
  23715. // The format of record: see `echarts.registerMap`.
  23716. // Compatible with previous `echarts.registerMap`.
  23717. registerMap: function (mapName, rawGeoJson, rawSpecialAreas) {
  23718. var records;
  23719. if (isArray(rawGeoJson)) {
  23720. records = rawGeoJson;
  23721. }
  23722. else if (rawGeoJson.svg) {
  23723. records = [{
  23724. type: 'svg',
  23725. source: rawGeoJson.svg,
  23726. specialAreas: rawGeoJson.specialAreas
  23727. }];
  23728. }
  23729. else {
  23730. // Backward compatibility.
  23731. if (rawGeoJson.geoJson && !rawGeoJson.features) {
  23732. rawSpecialAreas = rawGeoJson.specialAreas;
  23733. rawGeoJson = rawGeoJson.geoJson;
  23734. }
  23735. records = [{
  23736. type: 'geoJSON',
  23737. source: rawGeoJson,
  23738. specialAreas: rawSpecialAreas
  23739. }];
  23740. }
  23741. each$1(records, function (record) {
  23742. var type = record.type;
  23743. type === 'geoJson' && (type = record.type = 'geoJSON');
  23744. var parse = parsers[type];
  23745. if (__DEV__) {
  23746. assert$1(parse, 'Illegal map type: ' + type);
  23747. }
  23748. parse(record);
  23749. });
  23750. return storage.set(mapName, records);
  23751. },
  23752. retrieveMap: function (mapName) {
  23753. return storage.get(mapName);
  23754. }
  23755. };
  23756. var parsers = {
  23757. geoJSON: function (record) {
  23758. var source = record.source;
  23759. record.geoJSON = !isString(source)
  23760. ? source
  23761. : (typeof JSON !== 'undefined' && JSON.parse)
  23762. ? JSON.parse(source)
  23763. : (new Function('return (' + source + ');'))();
  23764. },
  23765. // Only perform parse to XML object here, which might be time
  23766. // consiming for large SVG.
  23767. // Although convert XML to zrender element is also time consiming,
  23768. // if we do it here, the clone of zrender elements has to be
  23769. // required. So we do it once for each geo instance, util real
  23770. // performance issues call for optimizing it.
  23771. svg: function (record) {
  23772. record.svgXML = parseXML(record.source);
  23773. }
  23774. };
  23775. /*
  23776. * Licensed to the Apache Software Foundation (ASF) under one
  23777. * or more contributor license agreements. See the NOTICE file
  23778. * distributed with this work for additional information
  23779. * regarding copyright ownership. The ASF licenses this file
  23780. * to you under the Apache License, Version 2.0 (the
  23781. * "License"); you may not use this file except in compliance
  23782. * with the License. You may obtain a copy of the License at
  23783. *
  23784. * http://www.apache.org/licenses/LICENSE-2.0
  23785. *
  23786. * Unless required by applicable law or agreed to in writing,
  23787. * software distributed under the License is distributed on an
  23788. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  23789. * KIND, either express or implied. See the License for the
  23790. * specific language governing permissions and limitations
  23791. * under the License.
  23792. */
  23793. var assert = assert$1;
  23794. var each = each$1;
  23795. var isFunction = isFunction$1;
  23796. var isObject = isObject$1;
  23797. var parseClassType = ComponentModel.parseClassType;
  23798. var version = '4.3.0';
  23799. var dependencies = {
  23800. zrender: '4.1.0'
  23801. };
  23802. var TEST_FRAME_REMAIN_TIME = 1;
  23803. var PRIORITY_PROCESSOR_FILTER = 1000;
  23804. var PRIORITY_PROCESSOR_STATISTIC = 5000;
  23805. var PRIORITY_VISUAL_LAYOUT = 1000;
  23806. var PRIORITY_VISUAL_PROGRESSIVE_LAYOUT = 1100;
  23807. var PRIORITY_VISUAL_GLOBAL = 2000;
  23808. var PRIORITY_VISUAL_CHART = 3000;
  23809. var PRIORITY_VISUAL_POST_CHART_LAYOUT = 3500;
  23810. var PRIORITY_VISUAL_COMPONENT = 4000;
  23811. // FIXME
  23812. // necessary?
  23813. var PRIORITY_VISUAL_BRUSH = 5000;
  23814. var PRIORITY = {
  23815. PROCESSOR: {
  23816. FILTER: PRIORITY_PROCESSOR_FILTER,
  23817. STATISTIC: PRIORITY_PROCESSOR_STATISTIC
  23818. },
  23819. VISUAL: {
  23820. LAYOUT: PRIORITY_VISUAL_LAYOUT,
  23821. PROGRESSIVE_LAYOUT: PRIORITY_VISUAL_PROGRESSIVE_LAYOUT,
  23822. GLOBAL: PRIORITY_VISUAL_GLOBAL,
  23823. CHART: PRIORITY_VISUAL_CHART,
  23824. POST_CHART_LAYOUT: PRIORITY_VISUAL_POST_CHART_LAYOUT,
  23825. COMPONENT: PRIORITY_VISUAL_COMPONENT,
  23826. BRUSH: PRIORITY_VISUAL_BRUSH
  23827. }
  23828. };
  23829. // Main process have three entries: `setOption`, `dispatchAction` and `resize`,
  23830. // where they must not be invoked nestedly, except the only case: invoke
  23831. // dispatchAction with updateMethod "none" in main process.
  23832. // This flag is used to carry out this rule.
  23833. // All events will be triggered out side main process (i.e. when !this[IN_MAIN_PROCESS]).
  23834. var IN_MAIN_PROCESS = '__flagInMainProcess';
  23835. var OPTION_UPDATED = '__optionUpdated';
  23836. var ACTION_REG = /^[a-zA-Z0-9_]+$/;
  23837. function createRegisterEventWithLowercaseName(method) {
  23838. return function (eventName, handler, context) {
  23839. // Event name is all lowercase
  23840. eventName = eventName && eventName.toLowerCase();
  23841. Eventful.prototype[method].call(this, eventName, handler, context);
  23842. };
  23843. }
  23844. /**
  23845. * @module echarts~MessageCenter
  23846. */
  23847. function MessageCenter() {
  23848. Eventful.call(this);
  23849. }
  23850. MessageCenter.prototype.on = createRegisterEventWithLowercaseName('on');
  23851. MessageCenter.prototype.off = createRegisterEventWithLowercaseName('off');
  23852. MessageCenter.prototype.one = createRegisterEventWithLowercaseName('one');
  23853. mixin(MessageCenter, Eventful);
  23854. /**
  23855. * @module echarts~ECharts
  23856. */
  23857. function ECharts(dom, theme$$1, opts) {
  23858. opts = opts || {};
  23859. // Get theme by name
  23860. if (typeof theme$$1 === 'string') {
  23861. theme$$1 = themeStorage[theme$$1];
  23862. }
  23863. /**
  23864. * @type {string}
  23865. */
  23866. this.id;
  23867. /**
  23868. * Group id
  23869. * @type {string}
  23870. */
  23871. this.group;
  23872. /**
  23873. * @type {HTMLElement}
  23874. * @private
  23875. */
  23876. this._dom = dom;
  23877. var defaultRenderer = 'canvas';
  23878. if (__DEV__) {
  23879. defaultRenderer = (
  23880. typeof window === 'undefined' ? global : window
  23881. ).__ECHARTS__DEFAULT__RENDERER__ || defaultRenderer;
  23882. }
  23883. /**
  23884. * @type {module:zrender/ZRender}
  23885. * @private
  23886. */
  23887. var zr = this._zr = init$1(dom, {
  23888. renderer: opts.renderer || defaultRenderer,
  23889. devicePixelRatio: opts.devicePixelRatio,
  23890. width: opts.width,
  23891. height: opts.height
  23892. });
  23893. /**
  23894. * Expect 60 fps.
  23895. * @type {Function}
  23896. * @private
  23897. */
  23898. this._throttledZrFlush = throttle(bind(zr.flush, zr), 17);
  23899. var theme$$1 = clone(theme$$1);
  23900. theme$$1 && backwardCompat(theme$$1, true);
  23901. /**
  23902. * @type {Object}
  23903. * @private
  23904. */
  23905. this._theme = theme$$1;
  23906. /**
  23907. * @type {Array.<module:echarts/view/Chart>}
  23908. * @private
  23909. */
  23910. this._chartsViews = [];
  23911. /**
  23912. * @type {Object.<string, module:echarts/view/Chart>}
  23913. * @private
  23914. */
  23915. this._chartsMap = {};
  23916. /**
  23917. * @type {Array.<module:echarts/view/Component>}
  23918. * @private
  23919. */
  23920. this._componentsViews = [];
  23921. /**
  23922. * @type {Object.<string, module:echarts/view/Component>}
  23923. * @private
  23924. */
  23925. this._componentsMap = {};
  23926. /**
  23927. * @type {module:echarts/CoordinateSystem}
  23928. * @private
  23929. */
  23930. this._coordSysMgr = new CoordinateSystemManager();
  23931. /**
  23932. * @type {module:echarts/ExtensionAPI}
  23933. * @private
  23934. */
  23935. var api = this._api = createExtensionAPI(this);
  23936. // Sort on demand
  23937. function prioritySortFunc(a, b) {
  23938. return a.__prio - b.__prio;
  23939. }
  23940. sort(visualFuncs, prioritySortFunc);
  23941. sort(dataProcessorFuncs, prioritySortFunc);
  23942. /**
  23943. * @type {module:echarts/stream/Scheduler}
  23944. */
  23945. this._scheduler = new Scheduler(this, api, dataProcessorFuncs, visualFuncs);
  23946. Eventful.call(this, this._ecEventProcessor = new EventProcessor());
  23947. /**
  23948. * @type {module:echarts~MessageCenter}
  23949. * @private
  23950. */
  23951. this._messageCenter = new MessageCenter();
  23952. // Init mouse events
  23953. this._initEvents();
  23954. // In case some people write `window.onresize = chart.resize`
  23955. this.resize = bind(this.resize, this);
  23956. // Can't dispatch action during rendering procedure
  23957. this._pendingActions = [];
  23958. zr.animation.on('frame', this._onframe, this);
  23959. bindRenderedEvent(zr, this);
  23960. // ECharts instance can be used as value.
  23961. setAsPrimitive(this);
  23962. }
  23963. var echartsProto = ECharts.prototype;
  23964. echartsProto._onframe = function () {
  23965. if (this._disposed) {
  23966. return;
  23967. }
  23968. var scheduler = this._scheduler;
  23969. // Lazy update
  23970. if (this[OPTION_UPDATED]) {
  23971. var silent = this[OPTION_UPDATED].silent;
  23972. this[IN_MAIN_PROCESS] = true;
  23973. prepare(this);
  23974. updateMethods.update.call(this);
  23975. this[IN_MAIN_PROCESS] = false;
  23976. this[OPTION_UPDATED] = false;
  23977. flushPendingActions.call(this, silent);
  23978. triggerUpdatedEvent.call(this, silent);
  23979. }
  23980. // Avoid do both lazy update and progress in one frame.
  23981. else if (scheduler.unfinished) {
  23982. // Stream progress.
  23983. var remainTime = TEST_FRAME_REMAIN_TIME;
  23984. var ecModel = this._model;
  23985. var api = this._api;
  23986. scheduler.unfinished = false;
  23987. do {
  23988. var startTime = +new Date();
  23989. scheduler.performSeriesTasks(ecModel);
  23990. // Currently dataProcessorFuncs do not check threshold.
  23991. scheduler.performDataProcessorTasks(ecModel);
  23992. updateStreamModes(this, ecModel);
  23993. // Do not update coordinate system here. Because that coord system update in
  23994. // each frame is not a good user experience. So we follow the rule that
  23995. // the extent of the coordinate system is determin in the first frame (the
  23996. // frame is executed immedietely after task reset.
  23997. // this._coordSysMgr.update(ecModel, api);
  23998. // console.log('--- ec frame visual ---', remainTime);
  23999. scheduler.performVisualTasks(ecModel);
  24000. renderSeries(this, this._model, api, 'remain');
  24001. remainTime -= (+new Date() - startTime);
  24002. }
  24003. while (remainTime > 0 && scheduler.unfinished);
  24004. // Call flush explicitly for trigger finished event.
  24005. if (!scheduler.unfinished) {
  24006. this._zr.flush();
  24007. }
  24008. // Else, zr flushing be ensue within the same frame,
  24009. // because zr flushing is after onframe event.
  24010. }
  24011. };
  24012. /**
  24013. * @return {HTMLElement}
  24014. */
  24015. echartsProto.getDom = function () {
  24016. return this._dom;
  24017. };
  24018. /**
  24019. * @return {module:zrender~ZRender}
  24020. */
  24021. echartsProto.getZr = function () {
  24022. return this._zr;
  24023. };
  24024. /**
  24025. * Usage:
  24026. * chart.setOption(option, notMerge, lazyUpdate);
  24027. * chart.setOption(option, {
  24028. * notMerge: ...,
  24029. * lazyUpdate: ...,
  24030. * silent: ...
  24031. * });
  24032. *
  24033. * @param {Object} option
  24034. * @param {Object|boolean} [opts] opts or notMerge.
  24035. * @param {boolean} [opts.notMerge=false]
  24036. * @param {boolean} [opts.lazyUpdate=false] Useful when setOption frequently.
  24037. */
  24038. echartsProto.setOption = function (option, notMerge, lazyUpdate) {
  24039. if (__DEV__) {
  24040. assert(!this[IN_MAIN_PROCESS], '`setOption` should not be called during main process.');
  24041. }
  24042. var silent;
  24043. if (isObject(notMerge)) {
  24044. lazyUpdate = notMerge.lazyUpdate;
  24045. silent = notMerge.silent;
  24046. notMerge = notMerge.notMerge;
  24047. }
  24048. this[IN_MAIN_PROCESS] = true;
  24049. if (!this._model || notMerge) {
  24050. var optionManager = new OptionManager(this._api);
  24051. var theme$$1 = this._theme;
  24052. var ecModel = this._model = new GlobalModel();
  24053. ecModel.scheduler = this._scheduler;
  24054. ecModel.init(null, null, theme$$1, optionManager);
  24055. }
  24056. this._model.setOption(option, optionPreprocessorFuncs);
  24057. if (lazyUpdate) {
  24058. this[OPTION_UPDATED] = {silent: silent};
  24059. this[IN_MAIN_PROCESS] = false;
  24060. }
  24061. else {
  24062. prepare(this);
  24063. updateMethods.update.call(this);
  24064. // Ensure zr refresh sychronously, and then pixel in canvas can be
  24065. // fetched after `setOption`.
  24066. this._zr.flush();
  24067. this[OPTION_UPDATED] = false;
  24068. this[IN_MAIN_PROCESS] = false;
  24069. flushPendingActions.call(this, silent);
  24070. triggerUpdatedEvent.call(this, silent);
  24071. }
  24072. };
  24073. /**
  24074. * @DEPRECATED
  24075. */
  24076. echartsProto.setTheme = function () {
  24077. console.error('ECharts#setTheme() is DEPRECATED in ECharts 3.0');
  24078. };
  24079. /**
  24080. * @return {module:echarts/model/Global}
  24081. */
  24082. echartsProto.getModel = function () {
  24083. return this._model;
  24084. };
  24085. /**
  24086. * @return {Object}
  24087. */
  24088. echartsProto.getOption = function () {
  24089. return this._model && this._model.getOption();
  24090. };
  24091. /**
  24092. * @return {number}
  24093. */
  24094. echartsProto.getWidth = function () {
  24095. return this._zr.getWidth();
  24096. };
  24097. /**
  24098. * @return {number}
  24099. */
  24100. echartsProto.getHeight = function () {
  24101. return this._zr.getHeight();
  24102. };
  24103. /**
  24104. * @return {number}
  24105. */
  24106. echartsProto.getDevicePixelRatio = function () {
  24107. return this._zr.painter.dpr || window.devicePixelRatio || 1;
  24108. };
  24109. /**
  24110. * Get canvas which has all thing rendered
  24111. * @param {Object} opts
  24112. * @param {string} [opts.backgroundColor]
  24113. * @return {string}
  24114. */
  24115. echartsProto.getRenderedCanvas = function (opts) {
  24116. if (!env$1.canvasSupported) {
  24117. return;
  24118. }
  24119. opts = opts || {};
  24120. opts.pixelRatio = opts.pixelRatio || 1;
  24121. opts.backgroundColor = opts.backgroundColor
  24122. || this._model.get('backgroundColor');
  24123. var zr = this._zr;
  24124. // var list = zr.storage.getDisplayList();
  24125. // Stop animations
  24126. // Never works before in init animation, so remove it.
  24127. // zrUtil.each(list, function (el) {
  24128. // el.stopAnimation(true);
  24129. // });
  24130. return zr.painter.getRenderedCanvas(opts);
  24131. };
  24132. /**
  24133. * Get svg data url
  24134. * @return {string}
  24135. */
  24136. echartsProto.getSvgDataUrl = function () {
  24137. if (!env$1.svgSupported) {
  24138. return;
  24139. }
  24140. var zr = this._zr;
  24141. var list = zr.storage.getDisplayList();
  24142. // Stop animations
  24143. each$1(list, function (el) {
  24144. el.stopAnimation(true);
  24145. });
  24146. return zr.painter.pathToDataUrl();
  24147. };
  24148. /**
  24149. * @return {string}
  24150. * @param {Object} opts
  24151. * @param {string} [opts.type='png']
  24152. * @param {string} [opts.pixelRatio=1]
  24153. * @param {string} [opts.backgroundColor]
  24154. * @param {string} [opts.excludeComponents]
  24155. */
  24156. echartsProto.getDataURL = function (opts) {
  24157. opts = opts || {};
  24158. var excludeComponents = opts.excludeComponents;
  24159. var ecModel = this._model;
  24160. var excludesComponentViews = [];
  24161. var self = this;
  24162. each(excludeComponents, function (componentType) {
  24163. ecModel.eachComponent({
  24164. mainType: componentType
  24165. }, function (component) {
  24166. var view = self._componentsMap[component.__viewId];
  24167. if (!view.group.ignore) {
  24168. excludesComponentViews.push(view);
  24169. view.group.ignore = true;
  24170. }
  24171. });
  24172. });
  24173. var url = this._zr.painter.getType() === 'svg'
  24174. ? this.getSvgDataUrl()
  24175. : this.getRenderedCanvas(opts).toDataURL(
  24176. 'image/' + (opts && opts.type || 'png')
  24177. );
  24178. each(excludesComponentViews, function (view) {
  24179. view.group.ignore = false;
  24180. });
  24181. return url;
  24182. };
  24183. /**
  24184. * @return {string}
  24185. * @param {Object} opts
  24186. * @param {string} [opts.type='png']
  24187. * @param {string} [opts.pixelRatio=1]
  24188. * @param {string} [opts.backgroundColor]
  24189. */
  24190. echartsProto.getConnectedDataURL = function (opts) {
  24191. if (!env$1.canvasSupported) {
  24192. return;
  24193. }
  24194. var groupId = this.group;
  24195. var mathMin = Math.min;
  24196. var mathMax = Math.max;
  24197. var MAX_NUMBER = Infinity;
  24198. if (connectedGroups[groupId]) {
  24199. var left = MAX_NUMBER;
  24200. var top = MAX_NUMBER;
  24201. var right = -MAX_NUMBER;
  24202. var bottom = -MAX_NUMBER;
  24203. var canvasList = [];
  24204. var dpr = (opts && opts.pixelRatio) || 1;
  24205. each$1(instances, function (chart, id) {
  24206. if (chart.group === groupId) {
  24207. var canvas = chart.getRenderedCanvas(
  24208. clone(opts)
  24209. );
  24210. var boundingRect = chart.getDom().getBoundingClientRect();
  24211. left = mathMin(boundingRect.left, left);
  24212. top = mathMin(boundingRect.top, top);
  24213. right = mathMax(boundingRect.right, right);
  24214. bottom = mathMax(boundingRect.bottom, bottom);
  24215. canvasList.push({
  24216. dom: canvas,
  24217. left: boundingRect.left,
  24218. top: boundingRect.top
  24219. });
  24220. }
  24221. });
  24222. left *= dpr;
  24223. top *= dpr;
  24224. right *= dpr;
  24225. bottom *= dpr;
  24226. var width = right - left;
  24227. var height = bottom - top;
  24228. var targetCanvas = createCanvas();
  24229. targetCanvas.width = width;
  24230. targetCanvas.height = height;
  24231. var zr = init$1(targetCanvas);
  24232. // Background between the charts
  24233. if (opts.connectedBackgroundColor) {
  24234. zr.add(new Rect({
  24235. shape: {
  24236. x: 0,
  24237. y: 0,
  24238. width: width,
  24239. height: height
  24240. },
  24241. style: {
  24242. fill: opts.connectedBackgroundColor
  24243. }
  24244. }));
  24245. }
  24246. each(canvasList, function (item) {
  24247. var img = new ZImage({
  24248. style: {
  24249. x: item.left * dpr - left,
  24250. y: item.top * dpr - top,
  24251. image: item.dom
  24252. }
  24253. });
  24254. zr.add(img);
  24255. });
  24256. zr.refreshImmediately();
  24257. return targetCanvas.toDataURL('image/' + (opts && opts.type || 'png'));
  24258. }
  24259. else {
  24260. return this.getDataURL(opts);
  24261. }
  24262. };
  24263. /**
  24264. * Convert from logical coordinate system to pixel coordinate system.
  24265. * See CoordinateSystem#convertToPixel.
  24266. * @param {string|Object} finder
  24267. * If string, e.g., 'geo', means {geoIndex: 0}.
  24268. * If Object, could contain some of these properties below:
  24269. * {
  24270. * seriesIndex / seriesId / seriesName,
  24271. * geoIndex / geoId, geoName,
  24272. * bmapIndex / bmapId / bmapName,
  24273. * xAxisIndex / xAxisId / xAxisName,
  24274. * yAxisIndex / yAxisId / yAxisName,
  24275. * gridIndex / gridId / gridName,
  24276. * ... (can be extended)
  24277. * }
  24278. * @param {Array|number} value
  24279. * @return {Array|number} result
  24280. */
  24281. echartsProto.convertToPixel = curry(doConvertPixel, 'convertToPixel');
  24282. /**
  24283. * Convert from pixel coordinate system to logical coordinate system.
  24284. * See CoordinateSystem#convertFromPixel.
  24285. * @param {string|Object} finder
  24286. * If string, e.g., 'geo', means {geoIndex: 0}.
  24287. * If Object, could contain some of these properties below:
  24288. * {
  24289. * seriesIndex / seriesId / seriesName,
  24290. * geoIndex / geoId / geoName,
  24291. * bmapIndex / bmapId / bmapName,
  24292. * xAxisIndex / xAxisId / xAxisName,
  24293. * yAxisIndex / yAxisId / yAxisName
  24294. * gridIndex / gridId / gridName,
  24295. * ... (can be extended)
  24296. * }
  24297. * @param {Array|number} value
  24298. * @return {Array|number} result
  24299. */
  24300. echartsProto.convertFromPixel = curry(doConvertPixel, 'convertFromPixel');
  24301. function doConvertPixel(methodName, finder, value) {
  24302. var ecModel = this._model;
  24303. var coordSysList = this._coordSysMgr.getCoordinateSystems();
  24304. var result;
  24305. finder = parseFinder(ecModel, finder);
  24306. for (var i = 0; i < coordSysList.length; i++) {
  24307. var coordSys = coordSysList[i];
  24308. if (coordSys[methodName]
  24309. && (result = coordSys[methodName](ecModel, finder, value)) != null
  24310. ) {
  24311. return result;
  24312. }
  24313. }
  24314. if (__DEV__) {
  24315. console.warn(
  24316. 'No coordinate system that supports ' + methodName + ' found by the given finder.'
  24317. );
  24318. }
  24319. }
  24320. /**
  24321. * Is the specified coordinate systems or components contain the given pixel point.
  24322. * @param {string|Object} finder
  24323. * If string, e.g., 'geo', means {geoIndex: 0}.
  24324. * If Object, could contain some of these properties below:
  24325. * {
  24326. * seriesIndex / seriesId / seriesName,
  24327. * geoIndex / geoId / geoName,
  24328. * bmapIndex / bmapId / bmapName,
  24329. * xAxisIndex / xAxisId / xAxisName,
  24330. * yAxisIndex / yAxisId / yAxisName,
  24331. * gridIndex / gridId / gridName,
  24332. * ... (can be extended)
  24333. * }
  24334. * @param {Array|number} value
  24335. * @return {boolean} result
  24336. */
  24337. echartsProto.containPixel = function (finder, value) {
  24338. var ecModel = this._model;
  24339. var result;
  24340. finder = parseFinder(ecModel, finder);
  24341. each$1(finder, function (models, key) {
  24342. key.indexOf('Models') >= 0 && each$1(models, function (model) {
  24343. var coordSys = model.coordinateSystem;
  24344. if (coordSys && coordSys.containPoint) {
  24345. result |= !!coordSys.containPoint(value);
  24346. }
  24347. else if (key === 'seriesModels') {
  24348. var view = this._chartsMap[model.__viewId];
  24349. if (view && view.containPoint) {
  24350. result |= view.containPoint(value, model);
  24351. }
  24352. else {
  24353. if (__DEV__) {
  24354. console.warn(key + ': ' + (view
  24355. ? 'The found component do not support containPoint.'
  24356. : 'No view mapping to the found component.'
  24357. ));
  24358. }
  24359. }
  24360. }
  24361. else {
  24362. if (__DEV__) {
  24363. console.warn(key + ': containPoint is not supported');
  24364. }
  24365. }
  24366. }, this);
  24367. }, this);
  24368. return !!result;
  24369. };
  24370. /**
  24371. * Get visual from series or data.
  24372. * @param {string|Object} finder
  24373. * If string, e.g., 'series', means {seriesIndex: 0}.
  24374. * If Object, could contain some of these properties below:
  24375. * {
  24376. * seriesIndex / seriesId / seriesName,
  24377. * dataIndex / dataIndexInside
  24378. * }
  24379. * If dataIndex is not specified, series visual will be fetched,
  24380. * but not data item visual.
  24381. * If all of seriesIndex, seriesId, seriesName are not specified,
  24382. * visual will be fetched from first series.
  24383. * @param {string} visualType 'color', 'symbol', 'symbolSize'
  24384. */
  24385. echartsProto.getVisual = function (finder, visualType) {
  24386. var ecModel = this._model;
  24387. finder = parseFinder(ecModel, finder, {defaultMainType: 'series'});
  24388. var seriesModel = finder.seriesModel;
  24389. if (__DEV__) {
  24390. if (!seriesModel) {
  24391. console.warn('There is no specified seires model');
  24392. }
  24393. }
  24394. var data = seriesModel.getData();
  24395. var dataIndexInside = finder.hasOwnProperty('dataIndexInside')
  24396. ? finder.dataIndexInside
  24397. : finder.hasOwnProperty('dataIndex')
  24398. ? data.indexOfRawIndex(finder.dataIndex)
  24399. : null;
  24400. return dataIndexInside != null
  24401. ? data.getItemVisual(dataIndexInside, visualType)
  24402. : data.getVisual(visualType);
  24403. };
  24404. /**
  24405. * Get view of corresponding component model
  24406. * @param {module:echarts/model/Component} componentModel
  24407. * @return {module:echarts/view/Component}
  24408. */
  24409. echartsProto.getViewOfComponentModel = function (componentModel) {
  24410. return this._componentsMap[componentModel.__viewId];
  24411. };
  24412. /**
  24413. * Get view of corresponding series model
  24414. * @param {module:echarts/model/Series} seriesModel
  24415. * @return {module:echarts/view/Chart}
  24416. */
  24417. echartsProto.getViewOfSeriesModel = function (seriesModel) {
  24418. return this._chartsMap[seriesModel.__viewId];
  24419. };
  24420. var updateMethods = {
  24421. prepareAndUpdate: function (payload) {
  24422. prepare(this);
  24423. updateMethods.update.call(this, payload);
  24424. },
  24425. /**
  24426. * @param {Object} payload
  24427. * @private
  24428. */
  24429. update: function (payload) {
  24430. // console.profile && console.profile('update');
  24431. var ecModel = this._model;
  24432. var api = this._api;
  24433. var zr = this._zr;
  24434. var coordSysMgr = this._coordSysMgr;
  24435. var scheduler = this._scheduler;
  24436. // update before setOption
  24437. if (!ecModel) {
  24438. return;
  24439. }
  24440. scheduler.restoreData(ecModel, payload);
  24441. scheduler.performSeriesTasks(ecModel);
  24442. // TODO
  24443. // Save total ecModel here for undo/redo (after restoring data and before processing data).
  24444. // Undo (restoration of total ecModel) can be carried out in 'action' or outside API call.
  24445. // Create new coordinate system each update
  24446. // In LineView may save the old coordinate system and use it to get the orignal point
  24447. coordSysMgr.create(ecModel, api);
  24448. scheduler.performDataProcessorTasks(ecModel, payload);
  24449. // Current stream render is not supported in data process. So we can update
  24450. // stream modes after data processing, where the filtered data is used to
  24451. // deteming whether use progressive rendering.
  24452. updateStreamModes(this, ecModel);
  24453. // We update stream modes before coordinate system updated, then the modes info
  24454. // can be fetched when coord sys updating (consider the barGrid extent fix). But
  24455. // the drawback is the full coord info can not be fetched. Fortunately this full
  24456. // coord is not requied in stream mode updater currently.
  24457. coordSysMgr.update(ecModel, api);
  24458. clearColorPalette(ecModel);
  24459. scheduler.performVisualTasks(ecModel, payload);
  24460. render(this, ecModel, api, payload);
  24461. // Set background
  24462. var backgroundColor = ecModel.get('backgroundColor') || 'transparent';
  24463. // In IE8
  24464. if (!env$1.canvasSupported) {
  24465. var colorArr = parse(backgroundColor);
  24466. backgroundColor = stringify(colorArr, 'rgb');
  24467. if (colorArr[3] === 0) {
  24468. backgroundColor = 'transparent';
  24469. }
  24470. }
  24471. else {
  24472. zr.setBackgroundColor(backgroundColor);
  24473. }
  24474. performPostUpdateFuncs(ecModel, api);
  24475. // console.profile && console.profileEnd('update');
  24476. },
  24477. /**
  24478. * @param {Object} payload
  24479. * @private
  24480. */
  24481. updateTransform: function (payload) {
  24482. var ecModel = this._model;
  24483. var ecIns = this;
  24484. var api = this._api;
  24485. // update before setOption
  24486. if (!ecModel) {
  24487. return;
  24488. }
  24489. // ChartView.markUpdateMethod(payload, 'updateTransform');
  24490. var componentDirtyList = [];
  24491. ecModel.eachComponent(function (componentType, componentModel) {
  24492. var componentView = ecIns.getViewOfComponentModel(componentModel);
  24493. if (componentView && componentView.__alive) {
  24494. if (componentView.updateTransform) {
  24495. var result = componentView.updateTransform(componentModel, ecModel, api, payload);
  24496. result && result.update && componentDirtyList.push(componentView);
  24497. }
  24498. else {
  24499. componentDirtyList.push(componentView);
  24500. }
  24501. }
  24502. });
  24503. var seriesDirtyMap = createHashMap();
  24504. ecModel.eachSeries(function (seriesModel) {
  24505. var chartView = ecIns._chartsMap[seriesModel.__viewId];
  24506. if (chartView.updateTransform) {
  24507. var result = chartView.updateTransform(seriesModel, ecModel, api, payload);
  24508. result && result.update && seriesDirtyMap.set(seriesModel.uid, 1);
  24509. }
  24510. else {
  24511. seriesDirtyMap.set(seriesModel.uid, 1);
  24512. }
  24513. });
  24514. clearColorPalette(ecModel);
  24515. // Keep pipe to the exist pipeline because it depends on the render task of the full pipeline.
  24516. // this._scheduler.performVisualTasks(ecModel, payload, 'layout', true);
  24517. this._scheduler.performVisualTasks(
  24518. ecModel, payload, {setDirty: true, dirtyMap: seriesDirtyMap}
  24519. );
  24520. // Currently, not call render of components. Geo render cost a lot.
  24521. // renderComponents(ecIns, ecModel, api, payload, componentDirtyList);
  24522. renderSeries(ecIns, ecModel, api, payload, seriesDirtyMap);
  24523. performPostUpdateFuncs(ecModel, this._api);
  24524. },
  24525. /**
  24526. * @param {Object} payload
  24527. * @private
  24528. */
  24529. updateView: function (payload) {
  24530. var ecModel = this._model;
  24531. // update before setOption
  24532. if (!ecModel) {
  24533. return;
  24534. }
  24535. Chart.markUpdateMethod(payload, 'updateView');
  24536. clearColorPalette(ecModel);
  24537. // Keep pipe to the exist pipeline because it depends on the render task of the full pipeline.
  24538. this._scheduler.performVisualTasks(ecModel, payload, {setDirty: true});
  24539. render(this, this._model, this._api, payload);
  24540. performPostUpdateFuncs(ecModel, this._api);
  24541. },
  24542. /**
  24543. * @param {Object} payload
  24544. * @private
  24545. */
  24546. updateVisual: function (payload) {
  24547. updateMethods.update.call(this, payload);
  24548. // var ecModel = this._model;
  24549. // // update before setOption
  24550. // if (!ecModel) {
  24551. // return;
  24552. // }
  24553. // ChartView.markUpdateMethod(payload, 'updateVisual');
  24554. // clearColorPalette(ecModel);
  24555. // // Keep pipe to the exist pipeline because it depends on the render task of the full pipeline.
  24556. // this._scheduler.performVisualTasks(ecModel, payload, {visualType: 'visual', setDirty: true});
  24557. // render(this, this._model, this._api, payload);
  24558. // performPostUpdateFuncs(ecModel, this._api);
  24559. },
  24560. /**
  24561. * @param {Object} payload
  24562. * @private
  24563. */
  24564. updateLayout: function (payload) {
  24565. updateMethods.update.call(this, payload);
  24566. // var ecModel = this._model;
  24567. // // update before setOption
  24568. // if (!ecModel) {
  24569. // return;
  24570. // }
  24571. // ChartView.markUpdateMethod(payload, 'updateLayout');
  24572. // // Keep pipe to the exist pipeline because it depends on the render task of the full pipeline.
  24573. // // this._scheduler.performVisualTasks(ecModel, payload, 'layout', true);
  24574. // this._scheduler.performVisualTasks(ecModel, payload, {setDirty: true});
  24575. // render(this, this._model, this._api, payload);
  24576. // performPostUpdateFuncs(ecModel, this._api);
  24577. }
  24578. };
  24579. function prepare(ecIns) {
  24580. var ecModel = ecIns._model;
  24581. var scheduler = ecIns._scheduler;
  24582. scheduler.restorePipelines(ecModel);
  24583. scheduler.prepareStageTasks();
  24584. prepareView(ecIns, 'component', ecModel, scheduler);
  24585. prepareView(ecIns, 'chart', ecModel, scheduler);
  24586. scheduler.plan();
  24587. }
  24588. /**
  24589. * @private
  24590. */
  24591. function updateDirectly(ecIns, method, payload, mainType, subType) {
  24592. var ecModel = ecIns._model;
  24593. // broadcast
  24594. if (!mainType) {
  24595. // FIXME
  24596. // Chart will not be update directly here, except set dirty.
  24597. // But there is no such scenario now.
  24598. each(ecIns._componentsViews.concat(ecIns._chartsViews), callView);
  24599. return;
  24600. }
  24601. var query = {};
  24602. query[mainType + 'Id'] = payload[mainType + 'Id'];
  24603. query[mainType + 'Index'] = payload[mainType + 'Index'];
  24604. query[mainType + 'Name'] = payload[mainType + 'Name'];
  24605. var condition = {mainType: mainType, query: query};
  24606. subType && (condition.subType = subType); // subType may be '' by parseClassType;
  24607. var excludeSeriesId = payload.excludeSeriesId;
  24608. if (excludeSeriesId != null) {
  24609. excludeSeriesId = createHashMap(normalizeToArray(excludeSeriesId));
  24610. }
  24611. // If dispatchAction before setOption, do nothing.
  24612. ecModel && ecModel.eachComponent(condition, function (model) {
  24613. if (!excludeSeriesId || excludeSeriesId.get(model.id) == null) {
  24614. callView(ecIns[
  24615. mainType === 'series' ? '_chartsMap' : '_componentsMap'
  24616. ][model.__viewId]);
  24617. }
  24618. }, ecIns);
  24619. function callView(view) {
  24620. view && view.__alive && view[method] && view[method](
  24621. view.__model, ecModel, ecIns._api, payload
  24622. );
  24623. }
  24624. }
  24625. /**
  24626. * Resize the chart
  24627. * @param {Object} opts
  24628. * @param {number} [opts.width] Can be 'auto' (the same as null/undefined)
  24629. * @param {number} [opts.height] Can be 'auto' (the same as null/undefined)
  24630. * @param {boolean} [opts.silent=false]
  24631. */
  24632. echartsProto.resize = function (opts) {
  24633. if (__DEV__) {
  24634. assert(!this[IN_MAIN_PROCESS], '`resize` should not be called during main process.');
  24635. }
  24636. this._zr.resize(opts);
  24637. var ecModel = this._model;
  24638. // Resize loading effect
  24639. this._loadingFX && this._loadingFX.resize();
  24640. if (!ecModel) {
  24641. return;
  24642. }
  24643. var optionChanged = ecModel.resetOption('media');
  24644. var silent = opts && opts.silent;
  24645. this[IN_MAIN_PROCESS] = true;
  24646. optionChanged && prepare(this);
  24647. updateMethods.update.call(this);
  24648. this[IN_MAIN_PROCESS] = false;
  24649. flushPendingActions.call(this, silent);
  24650. triggerUpdatedEvent.call(this, silent);
  24651. };
  24652. function updateStreamModes(ecIns, ecModel) {
  24653. var chartsMap = ecIns._chartsMap;
  24654. var scheduler = ecIns._scheduler;
  24655. ecModel.eachSeries(function (seriesModel) {
  24656. scheduler.updateStreamModes(seriesModel, chartsMap[seriesModel.__viewId]);
  24657. });
  24658. }
  24659. /**
  24660. * Show loading effect
  24661. * @param {string} [name='default']
  24662. * @param {Object} [cfg]
  24663. */
  24664. echartsProto.showLoading = function (name, cfg) {
  24665. if (isObject(name)) {
  24666. cfg = name;
  24667. name = '';
  24668. }
  24669. name = name || 'default';
  24670. this.hideLoading();
  24671. if (!loadingEffects[name]) {
  24672. if (__DEV__) {
  24673. console.warn('Loading effects ' + name + ' not exists.');
  24674. }
  24675. return;
  24676. }
  24677. var el = loadingEffects[name](this._api, cfg);
  24678. var zr = this._zr;
  24679. this._loadingFX = el;
  24680. zr.add(el);
  24681. };
  24682. /**
  24683. * Hide loading effect
  24684. */
  24685. echartsProto.hideLoading = function () {
  24686. this._loadingFX && this._zr.remove(this._loadingFX);
  24687. this._loadingFX = null;
  24688. };
  24689. /**
  24690. * @param {Object} eventObj
  24691. * @return {Object}
  24692. */
  24693. echartsProto.makeActionFromEvent = function (eventObj) {
  24694. var payload = extend({}, eventObj);
  24695. payload.type = eventActionMap[eventObj.type];
  24696. return payload;
  24697. };
  24698. /**
  24699. * @pubilc
  24700. * @param {Object} payload
  24701. * @param {string} [payload.type] Action type
  24702. * @param {Object|boolean} [opt] If pass boolean, means opt.silent
  24703. * @param {boolean} [opt.silent=false] Whether trigger events.
  24704. * @param {boolean} [opt.flush=undefined]
  24705. * true: Flush immediately, and then pixel in canvas can be fetched
  24706. * immediately. Caution: it might affect performance.
  24707. * false: Not not flush.
  24708. * undefined: Auto decide whether perform flush.
  24709. */
  24710. echartsProto.dispatchAction = function (payload, opt) {
  24711. if (!isObject(opt)) {
  24712. opt = {silent: !!opt};
  24713. }
  24714. if (!actions[payload.type]) {
  24715. return;
  24716. }
  24717. // Avoid dispatch action before setOption. Especially in `connect`.
  24718. if (!this._model) {
  24719. return;
  24720. }
  24721. // May dispatchAction in rendering procedure
  24722. if (this[IN_MAIN_PROCESS]) {
  24723. this._pendingActions.push(payload);
  24724. return;
  24725. }
  24726. doDispatchAction.call(this, payload, opt.silent);
  24727. if (opt.flush) {
  24728. this._zr.flush(true);
  24729. }
  24730. else if (opt.flush !== false && env$1.browser.weChat) {
  24731. // In WeChat embeded browser, `requestAnimationFrame` and `setInterval`
  24732. // hang when sliding page (on touch event), which cause that zr does not
  24733. // refresh util user interaction finished, which is not expected.
  24734. // But `dispatchAction` may be called too frequently when pan on touch
  24735. // screen, which impacts performance if do not throttle them.
  24736. this._throttledZrFlush();
  24737. }
  24738. flushPendingActions.call(this, opt.silent);
  24739. triggerUpdatedEvent.call(this, opt.silent);
  24740. };
  24741. function doDispatchAction(payload, silent) {
  24742. var payloadType = payload.type;
  24743. var escapeConnect = payload.escapeConnect;
  24744. var actionWrap = actions[payloadType];
  24745. var actionInfo = actionWrap.actionInfo;
  24746. var cptType = (actionInfo.update || 'update').split(':');
  24747. var updateMethod = cptType.pop();
  24748. cptType = cptType[0] != null && parseClassType(cptType[0]);
  24749. this[IN_MAIN_PROCESS] = true;
  24750. var payloads = [payload];
  24751. var batched = false;
  24752. // Batch action
  24753. if (payload.batch) {
  24754. batched = true;
  24755. payloads = map(payload.batch, function (item) {
  24756. item = defaults(extend({}, item), payload);
  24757. item.batch = null;
  24758. return item;
  24759. });
  24760. }
  24761. var eventObjBatch = [];
  24762. var eventObj;
  24763. var isHighDown = payloadType === 'highlight' || payloadType === 'downplay';
  24764. each(payloads, function (batchItem) {
  24765. // Action can specify the event by return it.
  24766. eventObj = actionWrap.action(batchItem, this._model, this._api);
  24767. // Emit event outside
  24768. eventObj = eventObj || extend({}, batchItem);
  24769. // Convert type to eventType
  24770. eventObj.type = actionInfo.event || eventObj.type;
  24771. eventObjBatch.push(eventObj);
  24772. // light update does not perform data process, layout and visual.
  24773. if (isHighDown) {
  24774. // method, payload, mainType, subType
  24775. updateDirectly(this, updateMethod, batchItem, 'series');
  24776. }
  24777. else if (cptType) {
  24778. updateDirectly(this, updateMethod, batchItem, cptType.main, cptType.sub);
  24779. }
  24780. }, this);
  24781. if (updateMethod !== 'none' && !isHighDown && !cptType) {
  24782. // Still dirty
  24783. if (this[OPTION_UPDATED]) {
  24784. // FIXME Pass payload ?
  24785. prepare(this);
  24786. updateMethods.update.call(this, payload);
  24787. this[OPTION_UPDATED] = false;
  24788. }
  24789. else {
  24790. updateMethods[updateMethod].call(this, payload);
  24791. }
  24792. }
  24793. // Follow the rule of action batch
  24794. if (batched) {
  24795. eventObj = {
  24796. type: actionInfo.event || payloadType,
  24797. escapeConnect: escapeConnect,
  24798. batch: eventObjBatch
  24799. };
  24800. }
  24801. else {
  24802. eventObj = eventObjBatch[0];
  24803. }
  24804. this[IN_MAIN_PROCESS] = false;
  24805. !silent && this._messageCenter.trigger(eventObj.type, eventObj);
  24806. }
  24807. function flushPendingActions(silent) {
  24808. var pendingActions = this._pendingActions;
  24809. while (pendingActions.length) {
  24810. var payload = pendingActions.shift();
  24811. doDispatchAction.call(this, payload, silent);
  24812. }
  24813. }
  24814. function triggerUpdatedEvent(silent) {
  24815. !silent && this.trigger('updated');
  24816. }
  24817. /**
  24818. * Event `rendered` is triggered when zr
  24819. * rendered. It is useful for realtime
  24820. * snapshot (reflect animation).
  24821. *
  24822. * Event `finished` is triggered when:
  24823. * (1) zrender rendering finished.
  24824. * (2) initial animation finished.
  24825. * (3) progressive rendering finished.
  24826. * (4) no pending action.
  24827. * (5) no delayed setOption needs to be processed.
  24828. */
  24829. function bindRenderedEvent(zr, ecIns) {
  24830. zr.on('rendered', function () {
  24831. ecIns.trigger('rendered');
  24832. // The `finished` event should not be triggered repeatly,
  24833. // so it should only be triggered when rendering indeed happend
  24834. // in zrender. (Consider the case that dipatchAction is keep
  24835. // triggering when mouse move).
  24836. if (
  24837. // Although zr is dirty if initial animation is not finished
  24838. // and this checking is called on frame, we also check
  24839. // animation finished for robustness.
  24840. zr.animation.isFinished()
  24841. && !ecIns[OPTION_UPDATED]
  24842. && !ecIns._scheduler.unfinished
  24843. && !ecIns._pendingActions.length
  24844. ) {
  24845. ecIns.trigger('finished');
  24846. }
  24847. });
  24848. }
  24849. /**
  24850. * @param {Object} params
  24851. * @param {number} params.seriesIndex
  24852. * @param {Array|TypedArray} params.data
  24853. */
  24854. echartsProto.appendData = function (params) {
  24855. var seriesIndex = params.seriesIndex;
  24856. var ecModel = this.getModel();
  24857. var seriesModel = ecModel.getSeriesByIndex(seriesIndex);
  24858. if (__DEV__) {
  24859. assert(params.data && seriesModel);
  24860. }
  24861. seriesModel.appendData(params);
  24862. // Note: `appendData` does not support that update extent of coordinate
  24863. // system, util some scenario require that. In the expected usage of
  24864. // `appendData`, the initial extent of coordinate system should better
  24865. // be fixed by axis `min`/`max` setting or initial data, otherwise if
  24866. // the extent changed while `appendData`, the location of the painted
  24867. // graphic elements have to be changed, which make the usage of
  24868. // `appendData` meaningless.
  24869. this._scheduler.unfinished = true;
  24870. };
  24871. /**
  24872. * Register event
  24873. * @method
  24874. */
  24875. echartsProto.on = createRegisterEventWithLowercaseName('on');
  24876. echartsProto.off = createRegisterEventWithLowercaseName('off');
  24877. echartsProto.one = createRegisterEventWithLowercaseName('one');
  24878. /**
  24879. * Prepare view instances of charts and components
  24880. * @param {module:echarts/model/Global} ecModel
  24881. * @private
  24882. */
  24883. function prepareView(ecIns, type, ecModel, scheduler) {
  24884. var isComponent = type === 'component';
  24885. var viewList = isComponent ? ecIns._componentsViews : ecIns._chartsViews;
  24886. var viewMap = isComponent ? ecIns._componentsMap : ecIns._chartsMap;
  24887. var zr = ecIns._zr;
  24888. var api = ecIns._api;
  24889. for (var i = 0; i < viewList.length; i++) {
  24890. viewList[i].__alive = false;
  24891. }
  24892. isComponent
  24893. ? ecModel.eachComponent(function (componentType, model) {
  24894. componentType !== 'series' && doPrepare(model);
  24895. })
  24896. : ecModel.eachSeries(doPrepare);
  24897. function doPrepare(model) {
  24898. // Consider: id same and type changed.
  24899. var viewId = '_ec_' + model.id + '_' + model.type;
  24900. var view = viewMap[viewId];
  24901. if (!view) {
  24902. var classType = parseClassType(model.type);
  24903. var Clazz = isComponent
  24904. ? Component$1.getClass(classType.main, classType.sub)
  24905. : Chart.getClass(classType.sub);
  24906. if (__DEV__) {
  24907. assert(Clazz, classType.sub + ' does not exist.');
  24908. }
  24909. view = new Clazz();
  24910. view.init(ecModel, api);
  24911. viewMap[viewId] = view;
  24912. viewList.push(view);
  24913. zr.add(view.group);
  24914. }
  24915. model.__viewId = view.__id = viewId;
  24916. view.__alive = true;
  24917. view.__model = model;
  24918. view.group.__ecComponentInfo = {
  24919. mainType: model.mainType,
  24920. index: model.componentIndex
  24921. };
  24922. !isComponent && scheduler.prepareView(view, model, ecModel, api);
  24923. }
  24924. for (var i = 0; i < viewList.length;) {
  24925. var view = viewList[i];
  24926. if (!view.__alive) {
  24927. !isComponent && view.renderTask.dispose();
  24928. zr.remove(view.group);
  24929. view.dispose(ecModel, api);
  24930. viewList.splice(i, 1);
  24931. delete viewMap[view.__id];
  24932. view.__id = view.group.__ecComponentInfo = null;
  24933. }
  24934. else {
  24935. i++;
  24936. }
  24937. }
  24938. }
  24939. // /**
  24940. // * Encode visual infomation from data after data processing
  24941. // *
  24942. // * @param {module:echarts/model/Global} ecModel
  24943. // * @param {object} layout
  24944. // * @param {boolean} [layoutFilter] `true`: only layout,
  24945. // * `false`: only not layout,
  24946. // * `null`/`undefined`: all.
  24947. // * @param {string} taskBaseTag
  24948. // * @private
  24949. // */
  24950. // function startVisualEncoding(ecIns, ecModel, api, payload, layoutFilter) {
  24951. // each(visualFuncs, function (visual, index) {
  24952. // var isLayout = visual.isLayout;
  24953. // if (layoutFilter == null
  24954. // || (layoutFilter === false && !isLayout)
  24955. // || (layoutFilter === true && isLayout)
  24956. // ) {
  24957. // visual.func(ecModel, api, payload);
  24958. // }
  24959. // });
  24960. // }
  24961. function clearColorPalette(ecModel) {
  24962. ecModel.clearColorPalette();
  24963. ecModel.eachSeries(function (seriesModel) {
  24964. seriesModel.clearColorPalette();
  24965. });
  24966. }
  24967. function render(ecIns, ecModel, api, payload) {
  24968. renderComponents(ecIns, ecModel, api, payload);
  24969. each(ecIns._chartsViews, function (chart) {
  24970. chart.__alive = false;
  24971. });
  24972. renderSeries(ecIns, ecModel, api, payload);
  24973. // Remove groups of unrendered charts
  24974. each(ecIns._chartsViews, function (chart) {
  24975. if (!chart.__alive) {
  24976. chart.remove(ecModel, api);
  24977. }
  24978. });
  24979. }
  24980. function renderComponents(ecIns, ecModel, api, payload, dirtyList) {
  24981. each(dirtyList || ecIns._componentsViews, function (componentView) {
  24982. var componentModel = componentView.__model;
  24983. componentView.render(componentModel, ecModel, api, payload);
  24984. updateZ(componentModel, componentView);
  24985. });
  24986. }
  24987. /**
  24988. * Render each chart and component
  24989. * @private
  24990. */
  24991. function renderSeries(ecIns, ecModel, api, payload, dirtyMap) {
  24992. // Render all charts
  24993. var scheduler = ecIns._scheduler;
  24994. var unfinished;
  24995. ecModel.eachSeries(function (seriesModel) {
  24996. var chartView = ecIns._chartsMap[seriesModel.__viewId];
  24997. chartView.__alive = true;
  24998. var renderTask = chartView.renderTask;
  24999. scheduler.updatePayload(renderTask, payload);
  25000. if (dirtyMap && dirtyMap.get(seriesModel.uid)) {
  25001. renderTask.dirty();
  25002. }
  25003. unfinished |= renderTask.perform(scheduler.getPerformArgs(renderTask));
  25004. chartView.group.silent = !!seriesModel.get('silent');
  25005. updateZ(seriesModel, chartView);
  25006. updateBlend(seriesModel, chartView);
  25007. });
  25008. scheduler.unfinished |= unfinished;
  25009. // If use hover layer
  25010. updateHoverLayerStatus(ecIns, ecModel);
  25011. // Add aria
  25012. aria(ecIns._zr.dom, ecModel);
  25013. }
  25014. function performPostUpdateFuncs(ecModel, api) {
  25015. each(postUpdateFuncs, function (func) {
  25016. func(ecModel, api);
  25017. });
  25018. }
  25019. var MOUSE_EVENT_NAMES = [
  25020. 'click', 'dblclick', 'mouseover', 'mouseout', 'mousemove',
  25021. 'mousedown', 'mouseup', 'globalout', 'contextmenu'
  25022. ];
  25023. /**
  25024. * @private
  25025. */
  25026. echartsProto._initEvents = function () {
  25027. each(MOUSE_EVENT_NAMES, function (eveName) {
  25028. var handler = function (e) {
  25029. var ecModel = this.getModel();
  25030. var el = e.target;
  25031. var params;
  25032. var isGlobalOut = eveName === 'globalout';
  25033. // no e.target when 'globalout'.
  25034. if (isGlobalOut) {
  25035. params = {};
  25036. }
  25037. else if (el && el.dataIndex != null) {
  25038. var dataModel = el.dataModel || ecModel.getSeriesByIndex(el.seriesIndex);
  25039. params = dataModel && dataModel.getDataParams(el.dataIndex, el.dataType, el) || {};
  25040. }
  25041. // If element has custom eventData of components
  25042. else if (el && el.eventData) {
  25043. params = extend({}, el.eventData);
  25044. }
  25045. // Contract: if params prepared in mouse event,
  25046. // these properties must be specified:
  25047. // {
  25048. // componentType: string (component main type)
  25049. // componentIndex: number
  25050. // }
  25051. // Otherwise event query can not work.
  25052. if (params) {
  25053. var componentType = params.componentType;
  25054. var componentIndex = params.componentIndex;
  25055. // Special handling for historic reason: when trigger by
  25056. // markLine/markPoint/markArea, the componentType is
  25057. // 'markLine'/'markPoint'/'markArea', but we should better
  25058. // enable them to be queried by seriesIndex, since their
  25059. // option is set in each series.
  25060. if (componentType === 'markLine'
  25061. || componentType === 'markPoint'
  25062. || componentType === 'markArea'
  25063. ) {
  25064. componentType = 'series';
  25065. componentIndex = params.seriesIndex;
  25066. }
  25067. var model = componentType && componentIndex != null
  25068. && ecModel.getComponent(componentType, componentIndex);
  25069. var view = model && this[
  25070. model.mainType === 'series' ? '_chartsMap' : '_componentsMap'
  25071. ][model.__viewId];
  25072. if (__DEV__) {
  25073. // `event.componentType` and `event[componentTpype + 'Index']` must not
  25074. // be missed, otherwise there is no way to distinguish source component.
  25075. // See `dataFormat.getDataParams`.
  25076. if (!isGlobalOut && !(model && view)) {
  25077. console.warn('model or view can not be found by params');
  25078. }
  25079. }
  25080. params.event = e;
  25081. params.type = eveName;
  25082. this._ecEventProcessor.eventInfo = {
  25083. targetEl: el,
  25084. packedEvent: params,
  25085. model: model,
  25086. view: view
  25087. };
  25088. this.trigger(eveName, params);
  25089. }
  25090. };
  25091. // Consider that some component (like tooltip, brush, ...)
  25092. // register zr event handler, but user event handler might
  25093. // do anything, such as call `setOption` or `dispatchAction`,
  25094. // which probably update any of the content and probably
  25095. // cause problem if it is called previous other inner handlers.
  25096. handler.zrEventfulCallAtLast = true;
  25097. this._zr.on(eveName, handler, this);
  25098. }, this);
  25099. each(eventActionMap, function (actionType, eventType) {
  25100. this._messageCenter.on(eventType, function (event) {
  25101. this.trigger(eventType, event);
  25102. }, this);
  25103. }, this);
  25104. };
  25105. /**
  25106. * @return {boolean}
  25107. */
  25108. echartsProto.isDisposed = function () {
  25109. return this._disposed;
  25110. };
  25111. /**
  25112. * Clear
  25113. */
  25114. echartsProto.clear = function () {
  25115. this.setOption({ series: [] }, true);
  25116. };
  25117. /**
  25118. * Dispose instance
  25119. */
  25120. echartsProto.dispose = function () {
  25121. if (this._disposed) {
  25122. if (__DEV__) {
  25123. console.warn('Instance ' + this.id + ' has been disposed');
  25124. }
  25125. return;
  25126. }
  25127. this._disposed = true;
  25128. setAttribute(this.getDom(), DOM_ATTRIBUTE_KEY, '');
  25129. var api = this._api;
  25130. var ecModel = this._model;
  25131. each(this._componentsViews, function (component) {
  25132. component.dispose(ecModel, api);
  25133. });
  25134. each(this._chartsViews, function (chart) {
  25135. chart.dispose(ecModel, api);
  25136. });
  25137. // Dispose after all views disposed
  25138. this._zr.dispose();
  25139. delete instances[this.id];
  25140. };
  25141. mixin(ECharts, Eventful);
  25142. function updateHoverLayerStatus(ecIns, ecModel) {
  25143. var zr = ecIns._zr;
  25144. var storage = zr.storage;
  25145. var elCount = 0;
  25146. storage.traverse(function (el) {
  25147. elCount++;
  25148. });
  25149. if (elCount > ecModel.get('hoverLayerThreshold') && !env$1.node) {
  25150. ecModel.eachSeries(function (seriesModel) {
  25151. if (seriesModel.preventUsingHoverLayer) {
  25152. return;
  25153. }
  25154. var chartView = ecIns._chartsMap[seriesModel.__viewId];
  25155. if (chartView.__alive) {
  25156. chartView.group.traverse(function (el) {
  25157. // Don't switch back.
  25158. el.useHoverLayer = true;
  25159. });
  25160. }
  25161. });
  25162. }
  25163. }
  25164. /**
  25165. * Update chart progressive and blend.
  25166. * @param {module:echarts/model/Series|module:echarts/model/Component} model
  25167. * @param {module:echarts/view/Component|module:echarts/view/Chart} view
  25168. */
  25169. function updateBlend(seriesModel, chartView) {
  25170. var blendMode = seriesModel.get('blendMode') || null;
  25171. if (__DEV__) {
  25172. if (!env$1.canvasSupported && blendMode && blendMode !== 'source-over') {
  25173. console.warn('Only canvas support blendMode');
  25174. }
  25175. }
  25176. chartView.group.traverse(function (el) {
  25177. // FIXME marker and other components
  25178. if (!el.isGroup) {
  25179. // Only set if blendMode is changed. In case element is incremental and don't wan't to rerender.
  25180. if (el.style.blend !== blendMode) {
  25181. el.setStyle('blend', blendMode);
  25182. }
  25183. }
  25184. if (el.eachPendingDisplayable) {
  25185. el.eachPendingDisplayable(function (displayable) {
  25186. displayable.setStyle('blend', blendMode);
  25187. });
  25188. }
  25189. });
  25190. }
  25191. /**
  25192. * @param {module:echarts/model/Series|module:echarts/model/Component} model
  25193. * @param {module:echarts/view/Component|module:echarts/view/Chart} view
  25194. */
  25195. function updateZ(model, view) {
  25196. var z = model.get('z');
  25197. var zlevel = model.get('zlevel');
  25198. // Set z and zlevel
  25199. view.group.traverse(function (el) {
  25200. if (el.type !== 'group') {
  25201. z != null && (el.z = z);
  25202. zlevel != null && (el.zlevel = zlevel);
  25203. }
  25204. });
  25205. }
  25206. function createExtensionAPI(ecInstance) {
  25207. var coordSysMgr = ecInstance._coordSysMgr;
  25208. return extend(new ExtensionAPI(ecInstance), {
  25209. // Inject methods
  25210. getCoordinateSystems: bind(
  25211. coordSysMgr.getCoordinateSystems, coordSysMgr
  25212. ),
  25213. getComponentByElement: function (el) {
  25214. while (el) {
  25215. var modelInfo = el.__ecComponentInfo;
  25216. if (modelInfo != null) {
  25217. return ecInstance._model.getComponent(modelInfo.mainType, modelInfo.index);
  25218. }
  25219. el = el.parent;
  25220. }
  25221. }
  25222. });
  25223. }
  25224. /**
  25225. * @class
  25226. * Usage of query:
  25227. * `chart.on('click', query, handler);`
  25228. * The `query` can be:
  25229. * + The component type query string, only `mainType` or `mainType.subType`,
  25230. * like: 'xAxis', 'series', 'xAxis.category' or 'series.line'.
  25231. * + The component query object, like:
  25232. * `{seriesIndex: 2}`, `{seriesName: 'xx'}`, `{seriesId: 'some'}`,
  25233. * `{xAxisIndex: 2}`, `{xAxisName: 'xx'}`, `{xAxisId: 'some'}`.
  25234. * + The data query object, like:
  25235. * `{dataIndex: 123}`, `{dataType: 'link'}`, `{name: 'some'}`.
  25236. * + The other query object (cmponent customized query), like:
  25237. * `{element: 'some'}` (only available in custom series).
  25238. *
  25239. * Caveat: If a prop in the `query` object is `null/undefined`, it is the
  25240. * same as there is no such prop in the `query` object.
  25241. */
  25242. function EventProcessor() {
  25243. // These info required: targetEl, packedEvent, model, view
  25244. this.eventInfo;
  25245. }
  25246. EventProcessor.prototype = {
  25247. constructor: EventProcessor,
  25248. normalizeQuery: function (query) {
  25249. var cptQuery = {};
  25250. var dataQuery = {};
  25251. var otherQuery = {};
  25252. // `query` is `mainType` or `mainType.subType` of component.
  25253. if (isString(query)) {
  25254. var condCptType = parseClassType(query);
  25255. // `.main` and `.sub` may be ''.
  25256. cptQuery.mainType = condCptType.main || null;
  25257. cptQuery.subType = condCptType.sub || null;
  25258. }
  25259. // `query` is an object, convert to {mainType, index, name, id}.
  25260. else {
  25261. // `xxxIndex`, `xxxName`, `xxxId`, `name`, `dataIndex`, `dataType` is reserved,
  25262. // can not be used in `compomentModel.filterForExposedEvent`.
  25263. var suffixes = ['Index', 'Name', 'Id'];
  25264. var dataKeys = {name: 1, dataIndex: 1, dataType: 1};
  25265. each$1(query, function (val, key) {
  25266. var reserved = false;
  25267. for (var i = 0; i < suffixes.length; i++) {
  25268. var propSuffix = suffixes[i];
  25269. var suffixPos = key.lastIndexOf(propSuffix);
  25270. if (suffixPos > 0 && suffixPos === key.length - propSuffix.length) {
  25271. var mainType = key.slice(0, suffixPos);
  25272. // Consider `dataIndex`.
  25273. if (mainType !== 'data') {
  25274. cptQuery.mainType = mainType;
  25275. cptQuery[propSuffix.toLowerCase()] = val;
  25276. reserved = true;
  25277. }
  25278. }
  25279. }
  25280. if (dataKeys.hasOwnProperty(key)) {
  25281. dataQuery[key] = val;
  25282. reserved = true;
  25283. }
  25284. if (!reserved) {
  25285. otherQuery[key] = val;
  25286. }
  25287. });
  25288. }
  25289. return {
  25290. cptQuery: cptQuery,
  25291. dataQuery: dataQuery,
  25292. otherQuery: otherQuery
  25293. };
  25294. },
  25295. filter: function (eventType, query, args) {
  25296. // They should be assigned before each trigger call.
  25297. var eventInfo = this.eventInfo;
  25298. if (!eventInfo) {
  25299. return true;
  25300. }
  25301. var targetEl = eventInfo.targetEl;
  25302. var packedEvent = eventInfo.packedEvent;
  25303. var model = eventInfo.model;
  25304. var view = eventInfo.view;
  25305. // For event like 'globalout'.
  25306. if (!model || !view) {
  25307. return true;
  25308. }
  25309. var cptQuery = query.cptQuery;
  25310. var dataQuery = query.dataQuery;
  25311. return check(cptQuery, model, 'mainType')
  25312. && check(cptQuery, model, 'subType')
  25313. && check(cptQuery, model, 'index', 'componentIndex')
  25314. && check(cptQuery, model, 'name')
  25315. && check(cptQuery, model, 'id')
  25316. && check(dataQuery, packedEvent, 'name')
  25317. && check(dataQuery, packedEvent, 'dataIndex')
  25318. && check(dataQuery, packedEvent, 'dataType')
  25319. && (!view.filterForExposedEvent || view.filterForExposedEvent(
  25320. eventType, query.otherQuery, targetEl, packedEvent
  25321. ));
  25322. function check(query, host, prop, propOnHost) {
  25323. return query[prop] == null || host[propOnHost || prop] === query[prop];
  25324. }
  25325. },
  25326. afterTrigger: function () {
  25327. // Make sure the eventInfo wont be used in next trigger.
  25328. this.eventInfo = null;
  25329. }
  25330. };
  25331. /**
  25332. * @type {Object} key: actionType.
  25333. * @inner
  25334. */
  25335. var actions = {};
  25336. /**
  25337. * Map eventType to actionType
  25338. * @type {Object}
  25339. */
  25340. var eventActionMap = {};
  25341. /**
  25342. * Data processor functions of each stage
  25343. * @type {Array.<Object.<string, Function>>}
  25344. * @inner
  25345. */
  25346. var dataProcessorFuncs = [];
  25347. /**
  25348. * @type {Array.<Function>}
  25349. * @inner
  25350. */
  25351. var optionPreprocessorFuncs = [];
  25352. /**
  25353. * @type {Array.<Function>}
  25354. * @inner
  25355. */
  25356. var postUpdateFuncs = [];
  25357. /**
  25358. * Visual encoding functions of each stage
  25359. * @type {Array.<Object.<string, Function>>}
  25360. */
  25361. var visualFuncs = [];
  25362. /**
  25363. * Theme storage
  25364. * @type {Object.<key, Object>}
  25365. */
  25366. var themeStorage = {};
  25367. /**
  25368. * Loading effects
  25369. */
  25370. var loadingEffects = {};
  25371. var instances = {};
  25372. var connectedGroups = {};
  25373. var idBase = new Date() - 0;
  25374. var groupIdBase = new Date() - 0;
  25375. var DOM_ATTRIBUTE_KEY = '_echarts_instance_';
  25376. function enableConnect(chart) {
  25377. var STATUS_PENDING = 0;
  25378. var STATUS_UPDATING = 1;
  25379. var STATUS_UPDATED = 2;
  25380. var STATUS_KEY = '__connectUpdateStatus';
  25381. function updateConnectedChartsStatus(charts, status) {
  25382. for (var i = 0; i < charts.length; i++) {
  25383. var otherChart = charts[i];
  25384. otherChart[STATUS_KEY] = status;
  25385. }
  25386. }
  25387. each(eventActionMap, function (actionType, eventType) {
  25388. chart._messageCenter.on(eventType, function (event) {
  25389. if (connectedGroups[chart.group] && chart[STATUS_KEY] !== STATUS_PENDING) {
  25390. if (event && event.escapeConnect) {
  25391. return;
  25392. }
  25393. var action = chart.makeActionFromEvent(event);
  25394. var otherCharts = [];
  25395. each(instances, function (otherChart) {
  25396. if (otherChart !== chart && otherChart.group === chart.group) {
  25397. otherCharts.push(otherChart);
  25398. }
  25399. });
  25400. updateConnectedChartsStatus(otherCharts, STATUS_PENDING);
  25401. each(otherCharts, function (otherChart) {
  25402. if (otherChart[STATUS_KEY] !== STATUS_UPDATING) {
  25403. otherChart.dispatchAction(action);
  25404. }
  25405. });
  25406. updateConnectedChartsStatus(otherCharts, STATUS_UPDATED);
  25407. }
  25408. });
  25409. });
  25410. }
  25411. /**
  25412. * @param {HTMLElement} dom
  25413. * @param {Object} [theme]
  25414. * @param {Object} opts
  25415. * @param {number} [opts.devicePixelRatio] Use window.devicePixelRatio by default
  25416. * @param {string} [opts.renderer] Can choose 'canvas' or 'svg' to render the chart.
  25417. * @param {number} [opts.width] Use clientWidth of the input `dom` by default.
  25418. * Can be 'auto' (the same as null/undefined)
  25419. * @param {number} [opts.height] Use clientHeight of the input `dom` by default.
  25420. * Can be 'auto' (the same as null/undefined)
  25421. */
  25422. function init(dom, theme$$1, opts) {
  25423. if (__DEV__) {
  25424. // Check version
  25425. if ((version$1.replace('.', '') - 0) < (dependencies.zrender.replace('.', '') - 0)) {
  25426. throw new Error(
  25427. 'zrender/src ' + version$1
  25428. + ' is too old for ECharts ' + version
  25429. + '. Current version need ZRender '
  25430. + dependencies.zrender + '+'
  25431. );
  25432. }
  25433. if (!dom) {
  25434. throw new Error('Initialize failed: invalid dom.');
  25435. }
  25436. }
  25437. var existInstance = getInstanceByDom(dom);
  25438. if (existInstance) {
  25439. if (__DEV__) {
  25440. console.warn('There is a chart instance already initialized on the dom.');
  25441. }
  25442. return existInstance;
  25443. }
  25444. if (__DEV__) {
  25445. if (isDom(dom)
  25446. && dom.nodeName.toUpperCase() !== 'CANVAS'
  25447. && (
  25448. (!dom.clientWidth && (!opts || opts.width == null))
  25449. || (!dom.clientHeight && (!opts || opts.height == null))
  25450. )
  25451. ) {
  25452. console.warn('Can\'t get DOM width or height. Please check '
  25453. + 'dom.clientWidth and dom.clientHeight. They should not be 0.'
  25454. + 'For example, you may need to call this in the callback '
  25455. + 'of window.onload.');
  25456. }
  25457. }
  25458. var chart = new ECharts(dom, theme$$1, opts);
  25459. chart.id = 'ec_' + idBase++;
  25460. instances[chart.id] = chart;
  25461. setAttribute(dom, DOM_ATTRIBUTE_KEY, chart.id);
  25462. enableConnect(chart);
  25463. return chart;
  25464. }
  25465. /**
  25466. * @return {string|Array.<module:echarts~ECharts>} groupId
  25467. */
  25468. function connect(groupId) {
  25469. // Is array of charts
  25470. if (isArray(groupId)) {
  25471. var charts = groupId;
  25472. groupId = null;
  25473. // If any chart has group
  25474. each(charts, function (chart) {
  25475. if (chart.group != null) {
  25476. groupId = chart.group;
  25477. }
  25478. });
  25479. groupId = groupId || ('g_' + groupIdBase++);
  25480. each(charts, function (chart) {
  25481. chart.group = groupId;
  25482. });
  25483. }
  25484. connectedGroups[groupId] = true;
  25485. return groupId;
  25486. }
  25487. /**
  25488. * @DEPRECATED
  25489. * @return {string} groupId
  25490. */
  25491. function disConnect(groupId) {
  25492. connectedGroups[groupId] = false;
  25493. }
  25494. /**
  25495. * @return {string} groupId
  25496. */
  25497. var disconnect = disConnect;
  25498. /**
  25499. * Dispose a chart instance
  25500. * @param {module:echarts~ECharts|HTMLDomElement|string} chart
  25501. */
  25502. function dispose(chart) {
  25503. if (typeof chart === 'string') {
  25504. chart = instances[chart];
  25505. }
  25506. else if (!(chart instanceof ECharts)) {
  25507. // Try to treat as dom
  25508. chart = getInstanceByDom(chart);
  25509. }
  25510. if ((chart instanceof ECharts) && !chart.isDisposed()) {
  25511. chart.dispose();
  25512. }
  25513. }
  25514. /**
  25515. * @param {HTMLElement} dom
  25516. * @return {echarts~ECharts}
  25517. */
  25518. function getInstanceByDom(dom) {
  25519. return instances[getAttribute(dom, DOM_ATTRIBUTE_KEY)];
  25520. }
  25521. /**
  25522. * @param {string} key
  25523. * @return {echarts~ECharts}
  25524. */
  25525. function getInstanceById(key) {
  25526. return instances[key];
  25527. }
  25528. /**
  25529. * Register theme
  25530. */
  25531. function registerTheme(name, theme$$1) {
  25532. themeStorage[name] = theme$$1;
  25533. }
  25534. /**
  25535. * Register option preprocessor
  25536. * @param {Function} preprocessorFunc
  25537. */
  25538. function registerPreprocessor(preprocessorFunc) {
  25539. optionPreprocessorFuncs.push(preprocessorFunc);
  25540. }
  25541. /**
  25542. * @param {number} [priority=1000]
  25543. * @param {Object|Function} processor
  25544. */
  25545. function registerProcessor(priority, processor) {
  25546. normalizeRegister(dataProcessorFuncs, priority, processor, PRIORITY_PROCESSOR_FILTER);
  25547. }
  25548. /**
  25549. * Register postUpdater
  25550. * @param {Function} postUpdateFunc
  25551. */
  25552. function registerPostUpdate(postUpdateFunc) {
  25553. postUpdateFuncs.push(postUpdateFunc);
  25554. }
  25555. /**
  25556. * Usage:
  25557. * registerAction('someAction', 'someEvent', function () { ... });
  25558. * registerAction('someAction', function () { ... });
  25559. * registerAction(
  25560. * {type: 'someAction', event: 'someEvent', update: 'updateView'},
  25561. * function () { ... }
  25562. * );
  25563. *
  25564. * @param {(string|Object)} actionInfo
  25565. * @param {string} actionInfo.type
  25566. * @param {string} [actionInfo.event]
  25567. * @param {string} [actionInfo.update]
  25568. * @param {string} [eventName]
  25569. * @param {Function} action
  25570. */
  25571. function registerAction(actionInfo, eventName, action) {
  25572. if (typeof eventName === 'function') {
  25573. action = eventName;
  25574. eventName = '';
  25575. }
  25576. var actionType = isObject(actionInfo)
  25577. ? actionInfo.type
  25578. : ([actionInfo, actionInfo = {
  25579. event: eventName
  25580. }][0]);
  25581. // Event name is all lowercase
  25582. actionInfo.event = (actionInfo.event || actionType).toLowerCase();
  25583. eventName = actionInfo.event;
  25584. // Validate action type and event name.
  25585. assert(ACTION_REG.test(actionType) && ACTION_REG.test(eventName));
  25586. if (!actions[actionType]) {
  25587. actions[actionType] = {action: action, actionInfo: actionInfo};
  25588. }
  25589. eventActionMap[eventName] = actionType;
  25590. }
  25591. /**
  25592. * @param {string} type
  25593. * @param {*} CoordinateSystem
  25594. */
  25595. function registerCoordinateSystem(type, CoordinateSystem$$1) {
  25596. CoordinateSystemManager.register(type, CoordinateSystem$$1);
  25597. }
  25598. /**
  25599. * Get dimensions of specified coordinate system.
  25600. * @param {string} type
  25601. * @return {Array.<string|Object>}
  25602. */
  25603. function getCoordinateSystemDimensions(type) {
  25604. var coordSysCreator = CoordinateSystemManager.get(type);
  25605. if (coordSysCreator) {
  25606. return coordSysCreator.getDimensionsInfo
  25607. ? coordSysCreator.getDimensionsInfo()
  25608. : coordSysCreator.dimensions.slice();
  25609. }
  25610. }
  25611. /**
  25612. * Layout is a special stage of visual encoding
  25613. * Most visual encoding like color are common for different chart
  25614. * But each chart has it's own layout algorithm
  25615. *
  25616. * @param {number} [priority=1000]
  25617. * @param {Function} layoutTask
  25618. */
  25619. function registerLayout(priority, layoutTask) {
  25620. normalizeRegister(visualFuncs, priority, layoutTask, PRIORITY_VISUAL_LAYOUT, 'layout');
  25621. }
  25622. /**
  25623. * @param {number} [priority=3000]
  25624. * @param {module:echarts/stream/Task} visualTask
  25625. */
  25626. function registerVisual(priority, visualTask) {
  25627. normalizeRegister(visualFuncs, priority, visualTask, PRIORITY_VISUAL_CHART, 'visual');
  25628. }
  25629. /**
  25630. * @param {Object|Function} fn: {seriesType, createOnAllSeries, performRawSeries, reset}
  25631. */
  25632. function normalizeRegister(targetList, priority, fn, defaultPriority, visualType) {
  25633. if (isFunction(priority) || isObject(priority)) {
  25634. fn = priority;
  25635. priority = defaultPriority;
  25636. }
  25637. if (__DEV__) {
  25638. if (isNaN(priority) || priority == null) {
  25639. throw new Error('Illegal priority');
  25640. }
  25641. // Check duplicate
  25642. each(targetList, function (wrap) {
  25643. assert(wrap.__raw !== fn);
  25644. });
  25645. }
  25646. var stageHandler = Scheduler.wrapStageHandler(fn, visualType);
  25647. stageHandler.__prio = priority;
  25648. stageHandler.__raw = fn;
  25649. targetList.push(stageHandler);
  25650. return stageHandler;
  25651. }
  25652. /**
  25653. * @param {string} name
  25654. */
  25655. function registerLoading(name, loadingFx) {
  25656. loadingEffects[name] = loadingFx;
  25657. }
  25658. /**
  25659. * @param {Object} opts
  25660. * @param {string} [superClass]
  25661. */
  25662. function extendComponentModel(opts/*, superClass*/) {
  25663. // var Clazz = ComponentModel;
  25664. // if (superClass) {
  25665. // var classType = parseClassType(superClass);
  25666. // Clazz = ComponentModel.getClass(classType.main, classType.sub, true);
  25667. // }
  25668. return ComponentModel.extend(opts);
  25669. }
  25670. /**
  25671. * @param {Object} opts
  25672. * @param {string} [superClass]
  25673. */
  25674. function extendComponentView(opts/*, superClass*/) {
  25675. // var Clazz = ComponentView;
  25676. // if (superClass) {
  25677. // var classType = parseClassType(superClass);
  25678. // Clazz = ComponentView.getClass(classType.main, classType.sub, true);
  25679. // }
  25680. return Component$1.extend(opts);
  25681. }
  25682. /**
  25683. * @param {Object} opts
  25684. * @param {string} [superClass]
  25685. */
  25686. function extendSeriesModel(opts/*, superClass*/) {
  25687. // var Clazz = SeriesModel;
  25688. // if (superClass) {
  25689. // superClass = 'series.' + superClass.replace('series.', '');
  25690. // var classType = parseClassType(superClass);
  25691. // Clazz = ComponentModel.getClass(classType.main, classType.sub, true);
  25692. // }
  25693. return SeriesModel.extend(opts);
  25694. }
  25695. /**
  25696. * @param {Object} opts
  25697. * @param {string} [superClass]
  25698. */
  25699. function extendChartView(opts/*, superClass*/) {
  25700. // var Clazz = ChartView;
  25701. // if (superClass) {
  25702. // superClass = superClass.replace('series.', '');
  25703. // var classType = parseClassType(superClass);
  25704. // Clazz = ChartView.getClass(classType.main, true);
  25705. // }
  25706. return Chart.extend(opts);
  25707. }
  25708. /**
  25709. * ZRender need a canvas context to do measureText.
  25710. * But in node environment canvas may be created by node-canvas.
  25711. * So we need to specify how to create a canvas instead of using document.createElement('canvas')
  25712. *
  25713. * Be careful of using it in the browser.
  25714. *
  25715. * @param {Function} creator
  25716. * @example
  25717. * var Canvas = require('canvas');
  25718. * var echarts = require('echarts');
  25719. * echarts.setCanvasCreator(function () {
  25720. * // Small size is enough.
  25721. * return new Canvas(32, 32);
  25722. * });
  25723. */
  25724. function setCanvasCreator(creator) {
  25725. $override('createCanvas', creator);
  25726. }
  25727. /**
  25728. * @param {string} mapName
  25729. * @param {Array.<Object>|Object|string} geoJson
  25730. * @param {Object} [specialAreas]
  25731. *
  25732. * @example GeoJSON
  25733. * $.get('USA.json', function (geoJson) {
  25734. * echarts.registerMap('USA', geoJson);
  25735. * // Or
  25736. * echarts.registerMap('USA', {
  25737. * geoJson: geoJson,
  25738. * specialAreas: {}
  25739. * })
  25740. * });
  25741. *
  25742. * $.get('airport.svg', function (svg) {
  25743. * echarts.registerMap('airport', {
  25744. * svg: svg
  25745. * }
  25746. * });
  25747. *
  25748. * echarts.registerMap('eu', [
  25749. * {svg: eu-topographic.svg},
  25750. * {geoJSON: eu.json}
  25751. * ])
  25752. */
  25753. function registerMap(mapName, geoJson, specialAreas) {
  25754. mapDataStorage.registerMap(mapName, geoJson, specialAreas);
  25755. }
  25756. /**
  25757. * @param {string} mapName
  25758. * @return {Object}
  25759. */
  25760. function getMap(mapName) {
  25761. // For backward compatibility, only return the first one.
  25762. var records = mapDataStorage.retrieveMap(mapName);
  25763. return records && records[0] && {
  25764. geoJson: records[0].geoJSON,
  25765. specialAreas: records[0].specialAreas
  25766. };
  25767. }
  25768. registerVisual(PRIORITY_VISUAL_GLOBAL, seriesColor);
  25769. registerPreprocessor(backwardCompat);
  25770. registerProcessor(PRIORITY_PROCESSOR_STATISTIC, dataStack);
  25771. registerLoading('default', loadingDefault);
  25772. // Default actions
  25773. registerAction({
  25774. type: 'highlight',
  25775. event: 'highlight',
  25776. update: 'highlight'
  25777. }, noop);
  25778. registerAction({
  25779. type: 'downplay',
  25780. event: 'downplay',
  25781. update: 'downplay'
  25782. }, noop);
  25783. // Default theme
  25784. registerTheme('light', lightTheme);
  25785. registerTheme('dark', theme);
  25786. // For backward compatibility, where the namespace `dataTool` will
  25787. // be mounted on `echarts` is the extension `dataTool` is imported.
  25788. var dataTool = {};
  25789. /*
  25790. * Licensed to the Apache Software Foundation (ASF) under one
  25791. * or more contributor license agreements. See the NOTICE file
  25792. * distributed with this work for additional information
  25793. * regarding copyright ownership. The ASF licenses this file
  25794. * to you under the Apache License, Version 2.0 (the
  25795. * "License"); you may not use this file except in compliance
  25796. * with the License. You may obtain a copy of the License at
  25797. *
  25798. * http://www.apache.org/licenses/LICENSE-2.0
  25799. *
  25800. * Unless required by applicable law or agreed to in writing,
  25801. * software distributed under the License is distributed on an
  25802. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  25803. * KIND, either express or implied. See the License for the
  25804. * specific language governing permissions and limitations
  25805. * under the License.
  25806. */
  25807. function defaultKeyGetter(item) {
  25808. return item;
  25809. }
  25810. /**
  25811. * @param {Array} oldArr
  25812. * @param {Array} newArr
  25813. * @param {Function} oldKeyGetter
  25814. * @param {Function} newKeyGetter
  25815. * @param {Object} [context] Can be visited by this.context in callback.
  25816. */
  25817. function DataDiffer(oldArr, newArr, oldKeyGetter, newKeyGetter, context) {
  25818. this._old = oldArr;
  25819. this._new = newArr;
  25820. this._oldKeyGetter = oldKeyGetter || defaultKeyGetter;
  25821. this._newKeyGetter = newKeyGetter || defaultKeyGetter;
  25822. this.context = context;
  25823. }
  25824. DataDiffer.prototype = {
  25825. constructor: DataDiffer,
  25826. /**
  25827. * Callback function when add a data
  25828. */
  25829. add: function (func) {
  25830. this._add = func;
  25831. return this;
  25832. },
  25833. /**
  25834. * Callback function when update a data
  25835. */
  25836. update: function (func) {
  25837. this._update = func;
  25838. return this;
  25839. },
  25840. /**
  25841. * Callback function when remove a data
  25842. */
  25843. remove: function (func) {
  25844. this._remove = func;
  25845. return this;
  25846. },
  25847. execute: function () {
  25848. var oldArr = this._old;
  25849. var newArr = this._new;
  25850. var oldDataIndexMap = {};
  25851. var newDataIndexMap = {};
  25852. var oldDataKeyArr = [];
  25853. var newDataKeyArr = [];
  25854. var i;
  25855. initIndexMap(oldArr, oldDataIndexMap, oldDataKeyArr, '_oldKeyGetter', this);
  25856. initIndexMap(newArr, newDataIndexMap, newDataKeyArr, '_newKeyGetter', this);
  25857. // Travel by inverted order to make sure order consistency
  25858. // when duplicate keys exists (consider newDataIndex.pop() below).
  25859. // For performance consideration, these code below do not look neat.
  25860. for (i = 0; i < oldArr.length; i++) {
  25861. var key = oldDataKeyArr[i];
  25862. var idx = newDataIndexMap[key];
  25863. // idx can never be empty array here. see 'set null' logic below.
  25864. if (idx != null) {
  25865. // Consider there is duplicate key (for example, use dataItem.name as key).
  25866. // We should make sure every item in newArr and oldArr can be visited.
  25867. var len = idx.length;
  25868. if (len) {
  25869. len === 1 && (newDataIndexMap[key] = null);
  25870. idx = idx.unshift();
  25871. }
  25872. else {
  25873. newDataIndexMap[key] = null;
  25874. }
  25875. this._update && this._update(idx, i);
  25876. }
  25877. else {
  25878. this._remove && this._remove(i);
  25879. }
  25880. }
  25881. for (var i = 0; i < newDataKeyArr.length; i++) {
  25882. var key = newDataKeyArr[i];
  25883. if (newDataIndexMap.hasOwnProperty(key)) {
  25884. var idx = newDataIndexMap[key];
  25885. if (idx == null) {
  25886. continue;
  25887. }
  25888. // idx can never be empty array here. see 'set null' logic above.
  25889. if (!idx.length) {
  25890. this._add && this._add(idx);
  25891. }
  25892. else {
  25893. for (var j = 0, len = idx.length; j < len; j++) {
  25894. this._add && this._add(idx[j]);
  25895. }
  25896. }
  25897. }
  25898. }
  25899. }
  25900. };
  25901. function initIndexMap(arr, map, keyArr, keyGetterName, dataDiffer) {
  25902. for (var i = 0; i < arr.length; i++) {
  25903. // Add prefix to avoid conflict with Object.prototype.
  25904. var key = '_ec_' + dataDiffer[keyGetterName](arr[i], i);
  25905. var existence = map[key];
  25906. if (existence == null) {
  25907. keyArr.push(key);
  25908. map[key] = i;
  25909. }
  25910. else {
  25911. if (!existence.length) {
  25912. map[key] = existence = [existence];
  25913. }
  25914. existence.push(i);
  25915. }
  25916. }
  25917. }
  25918. /*
  25919. * Licensed to the Apache Software Foundation (ASF) under one
  25920. * or more contributor license agreements. See the NOTICE file
  25921. * distributed with this work for additional information
  25922. * regarding copyright ownership. The ASF licenses this file
  25923. * to you under the Apache License, Version 2.0 (the
  25924. * "License"); you may not use this file except in compliance
  25925. * with the License. You may obtain a copy of the License at
  25926. *
  25927. * http://www.apache.org/licenses/LICENSE-2.0
  25928. *
  25929. * Unless required by applicable law or agreed to in writing,
  25930. * software distributed under the License is distributed on an
  25931. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  25932. * KIND, either express or implied. See the License for the
  25933. * specific language governing permissions and limitations
  25934. * under the License.
  25935. */
  25936. var OTHER_DIMENSIONS = createHashMap([
  25937. 'tooltip', 'label', 'itemName', 'itemId', 'seriesName'
  25938. ]);
  25939. function summarizeDimensions(data) {
  25940. var summary = {};
  25941. var encode = summary.encode = {};
  25942. var notExtraCoordDimMap = createHashMap();
  25943. var defaultedLabel = [];
  25944. var defaultedTooltip = [];
  25945. // See the comment of `List.js#userOutput`.
  25946. var userOutput = summary.userOutput = {
  25947. dimensionNames: data.dimensions.slice(),
  25948. encode: {}
  25949. };
  25950. each$1(data.dimensions, function (dimName) {
  25951. var dimItem = data.getDimensionInfo(dimName);
  25952. var coordDim = dimItem.coordDim;
  25953. if (coordDim) {
  25954. if (__DEV__) {
  25955. assert$1(OTHER_DIMENSIONS.get(coordDim) == null);
  25956. }
  25957. var coordDimIndex = dimItem.coordDimIndex;
  25958. getOrCreateEncodeArr(encode, coordDim)[coordDimIndex] = dimName;
  25959. if (!dimItem.isExtraCoord) {
  25960. notExtraCoordDimMap.set(coordDim, 1);
  25961. // Use the last coord dim (and label friendly) as default label,
  25962. // because when dataset is used, it is hard to guess which dimension
  25963. // can be value dimension. If both show x, y on label is not look good,
  25964. // and conventionally y axis is focused more.
  25965. if (mayLabelDimType(dimItem.type)) {
  25966. defaultedLabel[0] = dimName;
  25967. }
  25968. // User output encode do not contain generated coords.
  25969. // And it only has index. User can use index to retrieve value from the raw item array.
  25970. getOrCreateEncodeArr(userOutput.encode, coordDim)[coordDimIndex] = dimItem.index;
  25971. }
  25972. if (dimItem.defaultTooltip) {
  25973. defaultedTooltip.push(dimName);
  25974. }
  25975. }
  25976. OTHER_DIMENSIONS.each(function (v, otherDim) {
  25977. var encodeArr = getOrCreateEncodeArr(encode, otherDim);
  25978. var dimIndex = dimItem.otherDims[otherDim];
  25979. if (dimIndex != null && dimIndex !== false) {
  25980. encodeArr[dimIndex] = dimItem.name;
  25981. }
  25982. });
  25983. });
  25984. var dataDimsOnCoord = [];
  25985. var encodeFirstDimNotExtra = {};
  25986. notExtraCoordDimMap.each(function (v, coordDim) {
  25987. var dimArr = encode[coordDim];
  25988. // ??? FIXME extra coord should not be set in dataDimsOnCoord.
  25989. // But should fix the case that radar axes: simplify the logic
  25990. // of `completeDimension`, remove `extraPrefix`.
  25991. encodeFirstDimNotExtra[coordDim] = dimArr[0];
  25992. // Not necessary to remove duplicate, because a data
  25993. // dim canot on more than one coordDim.
  25994. dataDimsOnCoord = dataDimsOnCoord.concat(dimArr);
  25995. });
  25996. summary.dataDimsOnCoord = dataDimsOnCoord;
  25997. summary.encodeFirstDimNotExtra = encodeFirstDimNotExtra;
  25998. var encodeLabel = encode.label;
  25999. // FIXME `encode.label` is not recommanded, because formatter can not be set
  26000. // in this way. Use label.formatter instead. May be remove this approach someday.
  26001. if (encodeLabel && encodeLabel.length) {
  26002. defaultedLabel = encodeLabel.slice();
  26003. }
  26004. var encodeTooltip = encode.tooltip;
  26005. if (encodeTooltip && encodeTooltip.length) {
  26006. defaultedTooltip = encodeTooltip.slice();
  26007. }
  26008. else if (!defaultedTooltip.length) {
  26009. defaultedTooltip = defaultedLabel.slice();
  26010. }
  26011. encode.defaultedLabel = defaultedLabel;
  26012. encode.defaultedTooltip = defaultedTooltip;
  26013. return summary;
  26014. }
  26015. function getOrCreateEncodeArr(encode, dim) {
  26016. if (!encode.hasOwnProperty(dim)) {
  26017. encode[dim] = [];
  26018. }
  26019. return encode[dim];
  26020. }
  26021. function getDimensionTypeByAxis(axisType) {
  26022. return axisType === 'category'
  26023. ? 'ordinal'
  26024. : axisType === 'time'
  26025. ? 'time'
  26026. : 'float';
  26027. }
  26028. function mayLabelDimType(dimType) {
  26029. // In most cases, ordinal and time do not suitable for label.
  26030. // Ordinal info can be displayed on axis. Time is too long.
  26031. return !(dimType === 'ordinal' || dimType === 'time');
  26032. }
  26033. // function findTheLastDimMayLabel(data) {
  26034. // // Get last value dim
  26035. // var dimensions = data.dimensions.slice();
  26036. // var valueType;
  26037. // var valueDim;
  26038. // while (dimensions.length && (
  26039. // valueDim = dimensions.pop(),
  26040. // valueType = data.getDimensionInfo(valueDim).type,
  26041. // valueType === 'ordinal' || valueType === 'time'
  26042. // )) {} // jshint ignore:line
  26043. // return valueDim;
  26044. // }
  26045. /*
  26046. * Licensed to the Apache Software Foundation (ASF) under one
  26047. * or more contributor license agreements. See the NOTICE file
  26048. * distributed with this work for additional information
  26049. * regarding copyright ownership. The ASF licenses this file
  26050. * to you under the Apache License, Version 2.0 (the
  26051. * "License"); you may not use this file except in compliance
  26052. * with the License. You may obtain a copy of the License at
  26053. *
  26054. * http://www.apache.org/licenses/LICENSE-2.0
  26055. *
  26056. * Unless required by applicable law or agreed to in writing,
  26057. * software distributed under the License is distributed on an
  26058. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  26059. * KIND, either express or implied. See the License for the
  26060. * specific language governing permissions and limitations
  26061. * under the License.
  26062. */
  26063. /* global Float64Array, Int32Array, Uint32Array, Uint16Array */
  26064. /**
  26065. * List for data storage
  26066. * @module echarts/data/List
  26067. */
  26068. var isObject$4 = isObject$1;
  26069. var UNDEFINED = 'undefined';
  26070. var INDEX_NOT_FOUND = -1;
  26071. // Use prefix to avoid index to be the same as otherIdList[idx],
  26072. // which will cause weird udpate animation.
  26073. var ID_PREFIX = 'e\0\0';
  26074. var dataCtors = {
  26075. 'float': typeof Float64Array === UNDEFINED
  26076. ? Array : Float64Array,
  26077. 'int': typeof Int32Array === UNDEFINED
  26078. ? Array : Int32Array,
  26079. // Ordinal data type can be string or int
  26080. 'ordinal': Array,
  26081. 'number': Array,
  26082. 'time': Array
  26083. };
  26084. // Caution: MUST not use `new CtorUint32Array(arr, 0, len)`, because the Ctor of array is
  26085. // different from the Ctor of typed array.
  26086. var CtorUint32Array = typeof Uint32Array === UNDEFINED ? Array : Uint32Array;
  26087. var CtorInt32Array = typeof Int32Array === UNDEFINED ? Array : Int32Array;
  26088. var CtorUint16Array = typeof Uint16Array === UNDEFINED ? Array : Uint16Array;
  26089. function getIndicesCtor(list) {
  26090. // The possible max value in this._indicies is always this._rawCount despite of filtering.
  26091. return list._rawCount > 65535 ? CtorUint32Array : CtorUint16Array;
  26092. }
  26093. function cloneChunk(originalChunk) {
  26094. var Ctor = originalChunk.constructor;
  26095. // Only shallow clone is enough when Array.
  26096. return Ctor === Array ? originalChunk.slice() : new Ctor(originalChunk);
  26097. }
  26098. var TRANSFERABLE_PROPERTIES = [
  26099. 'hasItemOption', '_nameList', '_idList', '_invertedIndicesMap',
  26100. '_rawData', '_chunkSize', '_chunkCount', '_dimValueGetter',
  26101. '_count', '_rawCount', '_nameDimIdx', '_idDimIdx'
  26102. ];
  26103. var CLONE_PROPERTIES = [
  26104. '_extent', '_approximateExtent', '_rawExtent'
  26105. ];
  26106. function transferProperties(target, source) {
  26107. each$1(TRANSFERABLE_PROPERTIES.concat(source.__wrappedMethods || []), function (propName) {
  26108. if (source.hasOwnProperty(propName)) {
  26109. target[propName] = source[propName];
  26110. }
  26111. });
  26112. target.__wrappedMethods = source.__wrappedMethods;
  26113. each$1(CLONE_PROPERTIES, function (propName) {
  26114. target[propName] = clone(source[propName]);
  26115. });
  26116. target._calculationInfo = extend(source._calculationInfo);
  26117. }
  26118. /**
  26119. * @constructor
  26120. * @alias module:echarts/data/List
  26121. *
  26122. * @param {Array.<string|Object>} dimensions
  26123. * For example, ['someDimName', {name: 'someDimName', type: 'someDimType'}, ...].
  26124. * Dimensions should be concrete names like x, y, z, lng, lat, angle, radius
  26125. * Spetial fields: {
  26126. * ordinalMeta: <module:echarts/data/OrdinalMeta>
  26127. * createInvertedIndices: <boolean>
  26128. * }
  26129. * @param {module:echarts/model/Model} hostModel
  26130. */
  26131. var List = function (dimensions, hostModel) {
  26132. dimensions = dimensions || ['x', 'y'];
  26133. var dimensionInfos = {};
  26134. var dimensionNames = [];
  26135. var invertedIndicesMap = {};
  26136. for (var i = 0; i < dimensions.length; i++) {
  26137. // Use the original dimensions[i], where other flag props may exists.
  26138. var dimensionInfo = dimensions[i];
  26139. if (isString(dimensionInfo)) {
  26140. dimensionInfo = {name: dimensionInfo};
  26141. }
  26142. var dimensionName = dimensionInfo.name;
  26143. dimensionInfo.type = dimensionInfo.type || 'float';
  26144. if (!dimensionInfo.coordDim) {
  26145. dimensionInfo.coordDim = dimensionName;
  26146. dimensionInfo.coordDimIndex = 0;
  26147. }
  26148. dimensionInfo.otherDims = dimensionInfo.otherDims || {};
  26149. dimensionNames.push(dimensionName);
  26150. dimensionInfos[dimensionName] = dimensionInfo;
  26151. dimensionInfo.index = i;
  26152. if (dimensionInfo.createInvertedIndices) {
  26153. invertedIndicesMap[dimensionName] = [];
  26154. }
  26155. }
  26156. /**
  26157. * @readOnly
  26158. * @type {Array.<string>}
  26159. */
  26160. this.dimensions = dimensionNames;
  26161. /**
  26162. * Infomation of each data dimension, like data type.
  26163. * @type {Object}
  26164. */
  26165. this._dimensionInfos = dimensionInfos;
  26166. /**
  26167. * @type {module:echarts/model/Model}
  26168. */
  26169. this.hostModel = hostModel;
  26170. /**
  26171. * @type {module:echarts/model/Model}
  26172. */
  26173. this.dataType;
  26174. /**
  26175. * Indices stores the indices of data subset after filtered.
  26176. * This data subset will be used in chart.
  26177. * @type {Array.<number>}
  26178. * @readOnly
  26179. */
  26180. this._indices = null;
  26181. this._count = 0;
  26182. this._rawCount = 0;
  26183. /**
  26184. * Data storage
  26185. * @type {Object.<key, Array.<TypedArray|Array>>}
  26186. * @private
  26187. */
  26188. this._storage = {};
  26189. /**
  26190. * @type {Array.<string>}
  26191. */
  26192. this._nameList = [];
  26193. /**
  26194. * @type {Array.<string>}
  26195. */
  26196. this._idList = [];
  26197. /**
  26198. * Models of data option is stored sparse for optimizing memory cost
  26199. * @type {Array.<module:echarts/model/Model>}
  26200. * @private
  26201. */
  26202. this._optionModels = [];
  26203. /**
  26204. * Global visual properties after visual coding
  26205. * @type {Object}
  26206. * @private
  26207. */
  26208. this._visual = {};
  26209. /**
  26210. * Globel layout properties.
  26211. * @type {Object}
  26212. * @private
  26213. */
  26214. this._layout = {};
  26215. /**
  26216. * Item visual properties after visual coding
  26217. * @type {Array.<Object>}
  26218. * @private
  26219. */
  26220. this._itemVisuals = [];
  26221. /**
  26222. * Key: visual type, Value: boolean
  26223. * @type {Object}
  26224. * @readOnly
  26225. */
  26226. this.hasItemVisual = {};
  26227. /**
  26228. * Item layout properties after layout
  26229. * @type {Array.<Object>}
  26230. * @private
  26231. */
  26232. this._itemLayouts = [];
  26233. /**
  26234. * Graphic elemnents
  26235. * @type {Array.<module:zrender/Element>}
  26236. * @private
  26237. */
  26238. this._graphicEls = [];
  26239. /**
  26240. * Max size of each chunk.
  26241. * @type {number}
  26242. * @private
  26243. */
  26244. this._chunkSize = 1e5;
  26245. /**
  26246. * @type {number}
  26247. * @private
  26248. */
  26249. this._chunkCount = 0;
  26250. /**
  26251. * @type {Array.<Array|Object>}
  26252. * @private
  26253. */
  26254. this._rawData;
  26255. /**
  26256. * Raw extent will not be cloned, but only transfered.
  26257. * It will not be calculated util needed.
  26258. * key: dim,
  26259. * value: {end: number, extent: Array.<number>}
  26260. * @type {Object}
  26261. * @private
  26262. */
  26263. this._rawExtent = {};
  26264. /**
  26265. * @type {Object}
  26266. * @private
  26267. */
  26268. this._extent = {};
  26269. /**
  26270. * key: dim
  26271. * value: extent
  26272. * @type {Object}
  26273. * @private
  26274. */
  26275. this._approximateExtent = {};
  26276. /**
  26277. * Cache summary info for fast visit. See "dimensionHelper".
  26278. * @type {Object}
  26279. * @private
  26280. */
  26281. this._dimensionsSummary = summarizeDimensions(this);
  26282. /**
  26283. * @type {Object.<Array|TypedArray>}
  26284. * @private
  26285. */
  26286. this._invertedIndicesMap = invertedIndicesMap;
  26287. /**
  26288. * @type {Object}
  26289. * @private
  26290. */
  26291. this._calculationInfo = {};
  26292. /**
  26293. * User output info of this data.
  26294. * DO NOT use it in other places!
  26295. *
  26296. * When preparing user params for user callbacks, we have
  26297. * to clone these inner data structures to prevent users
  26298. * from modifying them to effect built-in logic. And for
  26299. * performance consideration we make this `userOutput` to
  26300. * avoid clone them too many times.
  26301. *
  26302. * @type {Object}
  26303. * @readOnly
  26304. */
  26305. this.userOutput = this._dimensionsSummary.userOutput;
  26306. };
  26307. var listProto = List.prototype;
  26308. listProto.type = 'list';
  26309. /**
  26310. * If each data item has it's own option
  26311. * @type {boolean}
  26312. */
  26313. listProto.hasItemOption = true;
  26314. /**
  26315. * The meanings of the input parameter `dim`:
  26316. *
  26317. * + If dim is a number (e.g., `1`), it means the index of the dimension.
  26318. * For example, `getDimension(0)` will return 'x' or 'lng' or 'radius'.
  26319. * + If dim is a number-like string (e.g., `"1"`):
  26320. * + If there is the same concrete dim name defined in `this.dimensions`, it means that concrete name.
  26321. * + If not, it will be converted to a number, which means the index of the dimension.
  26322. * (why? because of the backward compatbility. We have been tolerating number-like string in
  26323. * dimension setting, although now it seems that it is not a good idea.)
  26324. * For example, `visualMap[i].dimension: "1"` is the same meaning as `visualMap[i].dimension: 1`,
  26325. * if no dimension name is defined as `"1"`.
  26326. * + If dim is a not-number-like string, it means the concrete dim name.
  26327. * For example, it can be be default name `"x"`, `"y"`, `"z"`, `"lng"`, `"lat"`, `"angle"`, `"radius"`,
  26328. * or customized in `dimensions` property of option like `"age"`.
  26329. *
  26330. * Get dimension name
  26331. * @param {string|number} dim See above.
  26332. * @return {string} Concrete dim name.
  26333. */
  26334. listProto.getDimension = function (dim) {
  26335. if (typeof dim === 'number'
  26336. // If being a number-like string but not being defined a dimension name.
  26337. || (!isNaN(dim) && !this._dimensionInfos.hasOwnProperty(dim))
  26338. ) {
  26339. dim = this.dimensions[dim];
  26340. }
  26341. return dim;
  26342. };
  26343. /**
  26344. * Get type and calculation info of particular dimension
  26345. * @param {string|number} dim
  26346. * Dimension can be concrete names like x, y, z, lng, lat, angle, radius
  26347. * Or a ordinal number. For example getDimensionInfo(0) will return 'x' or 'lng' or 'radius'
  26348. */
  26349. listProto.getDimensionInfo = function (dim) {
  26350. // Do not clone, because there may be categories in dimInfo.
  26351. return this._dimensionInfos[this.getDimension(dim)];
  26352. };
  26353. /**
  26354. * @return {Array.<string>} concrete dimension name list on coord.
  26355. */
  26356. listProto.getDimensionsOnCoord = function () {
  26357. return this._dimensionsSummary.dataDimsOnCoord.slice();
  26358. };
  26359. /**
  26360. * @param {string} coordDim
  26361. * @param {number} [idx] A coordDim may map to more than one data dim.
  26362. * If idx is `true`, return a array of all mapped dims.
  26363. * If idx is not specified, return the first dim not extra.
  26364. * @return {string|Array.<string>} concrete data dim.
  26365. * If idx is number, and not found, return null/undefined.
  26366. * If idx is `true`, and not found, return empty array (always return array).
  26367. */
  26368. listProto.mapDimension = function (coordDim, idx) {
  26369. var dimensionsSummary = this._dimensionsSummary;
  26370. if (idx == null) {
  26371. return dimensionsSummary.encodeFirstDimNotExtra[coordDim];
  26372. }
  26373. var dims = dimensionsSummary.encode[coordDim];
  26374. return idx === true
  26375. // always return array if idx is `true`
  26376. ? (dims || []).slice()
  26377. : (dims && dims[idx]);
  26378. };
  26379. /**
  26380. * Initialize from data
  26381. * @param {Array.<Object|number|Array>} data source or data or data provider.
  26382. * @param {Array.<string>} [nameLIst] The name of a datum is used on data diff and
  26383. * defualt label/tooltip.
  26384. * A name can be specified in encode.itemName,
  26385. * or dataItem.name (only for series option data),
  26386. * or provided in nameList from outside.
  26387. * @param {Function} [dimValueGetter] (dataItem, dimName, dataIndex, dimIndex) => number
  26388. */
  26389. listProto.initData = function (data, nameList, dimValueGetter) {
  26390. var notProvider = Source.isInstance(data) || isArrayLike(data);
  26391. if (notProvider) {
  26392. data = new DefaultDataProvider(data, this.dimensions.length);
  26393. }
  26394. if (__DEV__) {
  26395. if (!notProvider && (typeof data.getItem !== 'function' || typeof data.count !== 'function')) {
  26396. throw new Error('Inavlid data provider.');
  26397. }
  26398. }
  26399. this._rawData = data;
  26400. // Clear
  26401. this._storage = {};
  26402. this._indices = null;
  26403. this._nameList = nameList || [];
  26404. this._idList = [];
  26405. this._nameRepeatCount = {};
  26406. if (!dimValueGetter) {
  26407. this.hasItemOption = false;
  26408. }
  26409. /**
  26410. * @readOnly
  26411. */
  26412. this.defaultDimValueGetter = defaultDimValueGetters[
  26413. this._rawData.getSource().sourceFormat
  26414. ];
  26415. // Default dim value getter
  26416. this._dimValueGetter = dimValueGetter = dimValueGetter
  26417. || this.defaultDimValueGetter;
  26418. this._dimValueGetterArrayRows = defaultDimValueGetters.arrayRows;
  26419. // Reset raw extent.
  26420. this._rawExtent = {};
  26421. this._initDataFromProvider(0, data.count());
  26422. // If data has no item option.
  26423. if (data.pure) {
  26424. this.hasItemOption = false;
  26425. }
  26426. };
  26427. listProto.getProvider = function () {
  26428. return this._rawData;
  26429. };
  26430. /**
  26431. * Caution: Can be only called on raw data (before `this._indices` created).
  26432. */
  26433. listProto.appendData = function (data) {
  26434. if (__DEV__) {
  26435. assert$1(!this._indices, 'appendData can only be called on raw data.');
  26436. }
  26437. var rawData = this._rawData;
  26438. var start = this.count();
  26439. rawData.appendData(data);
  26440. var end = rawData.count();
  26441. if (!rawData.persistent) {
  26442. end += start;
  26443. }
  26444. this._initDataFromProvider(start, end);
  26445. };
  26446. /**
  26447. * Caution: Can be only called on raw data (before `this._indices` created).
  26448. * This method does not modify `rawData` (`dataProvider`), but only
  26449. * add values to storage.
  26450. *
  26451. * The final count will be increased by `Math.max(values.length, names.length)`.
  26452. *
  26453. * @param {Array.<Array.<*>>} values That is the SourceType: 'arrayRows', like
  26454. * [
  26455. * [12, 33, 44],
  26456. * [NaN, 43, 1],
  26457. * ['-', 'asdf', 0]
  26458. * ]
  26459. * Each item is exaclty cooresponding to a dimension.
  26460. * @param {Array.<string>} [names]
  26461. */
  26462. listProto.appendValues = function (values, names) {
  26463. var chunkSize = this._chunkSize;
  26464. var storage = this._storage;
  26465. var dimensions = this.dimensions;
  26466. var dimLen = dimensions.length;
  26467. var rawExtent = this._rawExtent;
  26468. var start = this.count();
  26469. var end = start + Math.max(values.length, names ? names.length : 0);
  26470. var originalChunkCount = this._chunkCount;
  26471. for (var i = 0; i < dimLen; i++) {
  26472. var dim = dimensions[i];
  26473. if (!rawExtent[dim]) {
  26474. rawExtent[dim] = getInitialExtent();
  26475. }
  26476. if (!storage[dim]) {
  26477. storage[dim] = [];
  26478. }
  26479. prepareChunks(storage, this._dimensionInfos[dim], chunkSize, originalChunkCount, end);
  26480. this._chunkCount = storage[dim].length;
  26481. }
  26482. var emptyDataItem = new Array(dimLen);
  26483. for (var idx = start; idx < end; idx++) {
  26484. var sourceIdx = idx - start;
  26485. var chunkIndex = Math.floor(idx / chunkSize);
  26486. var chunkOffset = idx % chunkSize;
  26487. // Store the data by dimensions
  26488. for (var k = 0; k < dimLen; k++) {
  26489. var dim = dimensions[k];
  26490. var val = this._dimValueGetterArrayRows(
  26491. values[sourceIdx] || emptyDataItem, dim, sourceIdx, k
  26492. );
  26493. storage[dim][chunkIndex][chunkOffset] = val;
  26494. var dimRawExtent = rawExtent[dim];
  26495. val < dimRawExtent[0] && (dimRawExtent[0] = val);
  26496. val > dimRawExtent[1] && (dimRawExtent[1] = val);
  26497. }
  26498. if (names) {
  26499. this._nameList[idx] = names[sourceIdx];
  26500. }
  26501. }
  26502. this._rawCount = this._count = end;
  26503. // Reset data extent
  26504. this._extent = {};
  26505. prepareInvertedIndex(this);
  26506. };
  26507. listProto._initDataFromProvider = function (start, end) {
  26508. // Optimize.
  26509. if (start >= end) {
  26510. return;
  26511. }
  26512. var chunkSize = this._chunkSize;
  26513. var rawData = this._rawData;
  26514. var storage = this._storage;
  26515. var dimensions = this.dimensions;
  26516. var dimLen = dimensions.length;
  26517. var dimensionInfoMap = this._dimensionInfos;
  26518. var nameList = this._nameList;
  26519. var idList = this._idList;
  26520. var rawExtent = this._rawExtent;
  26521. var nameRepeatCount = this._nameRepeatCount = {};
  26522. var nameDimIdx;
  26523. var originalChunkCount = this._chunkCount;
  26524. for (var i = 0; i < dimLen; i++) {
  26525. var dim = dimensions[i];
  26526. if (!rawExtent[dim]) {
  26527. rawExtent[dim] = getInitialExtent();
  26528. }
  26529. var dimInfo = dimensionInfoMap[dim];
  26530. if (dimInfo.otherDims.itemName === 0) {
  26531. nameDimIdx = this._nameDimIdx = i;
  26532. }
  26533. if (dimInfo.otherDims.itemId === 0) {
  26534. this._idDimIdx = i;
  26535. }
  26536. if (!storage[dim]) {
  26537. storage[dim] = [];
  26538. }
  26539. prepareChunks(storage, dimInfo, chunkSize, originalChunkCount, end);
  26540. this._chunkCount = storage[dim].length;
  26541. }
  26542. var dataItem = new Array(dimLen);
  26543. for (var idx = start; idx < end; idx++) {
  26544. // NOTICE: Try not to write things into dataItem
  26545. dataItem = rawData.getItem(idx, dataItem);
  26546. // Each data item is value
  26547. // [1, 2]
  26548. // 2
  26549. // Bar chart, line chart which uses category axis
  26550. // only gives the 'y' value. 'x' value is the indices of category
  26551. // Use a tempValue to normalize the value to be a (x, y) value
  26552. var chunkIndex = Math.floor(idx / chunkSize);
  26553. var chunkOffset = idx % chunkSize;
  26554. // Store the data by dimensions
  26555. for (var k = 0; k < dimLen; k++) {
  26556. var dim = dimensions[k];
  26557. var dimStorage = storage[dim][chunkIndex];
  26558. // PENDING NULL is empty or zero
  26559. var val = this._dimValueGetter(dataItem, dim, idx, k);
  26560. dimStorage[chunkOffset] = val;
  26561. var dimRawExtent = rawExtent[dim];
  26562. val < dimRawExtent[0] && (dimRawExtent[0] = val);
  26563. val > dimRawExtent[1] && (dimRawExtent[1] = val);
  26564. }
  26565. // ??? FIXME not check by pure but sourceFormat?
  26566. // TODO refactor these logic.
  26567. if (!rawData.pure) {
  26568. var name = nameList[idx];
  26569. if (dataItem && name == null) {
  26570. // If dataItem is {name: ...}, it has highest priority.
  26571. // That is appropriate for many common cases.
  26572. if (dataItem.name != null) {
  26573. // There is no other place to persistent dataItem.name,
  26574. // so save it to nameList.
  26575. nameList[idx] = name = dataItem.name;
  26576. }
  26577. else if (nameDimIdx != null) {
  26578. var nameDim = dimensions[nameDimIdx];
  26579. var nameDimChunk = storage[nameDim][chunkIndex];
  26580. if (nameDimChunk) {
  26581. name = nameDimChunk[chunkOffset];
  26582. var ordinalMeta = dimensionInfoMap[nameDim].ordinalMeta;
  26583. if (ordinalMeta && ordinalMeta.categories.length) {
  26584. name = ordinalMeta.categories[name];
  26585. }
  26586. }
  26587. }
  26588. }
  26589. // Try using the id in option
  26590. // id or name is used on dynamical data, mapping old and new items.
  26591. var id = dataItem == null ? null : dataItem.id;
  26592. if (id == null && name != null) {
  26593. // Use name as id and add counter to avoid same name
  26594. nameRepeatCount[name] = nameRepeatCount[name] || 0;
  26595. id = name;
  26596. if (nameRepeatCount[name] > 0) {
  26597. id += '__ec__' + nameRepeatCount[name];
  26598. }
  26599. nameRepeatCount[name]++;
  26600. }
  26601. id != null && (idList[idx] = id);
  26602. }
  26603. }
  26604. if (!rawData.persistent && rawData.clean) {
  26605. // Clean unused data if data source is typed array.
  26606. rawData.clean();
  26607. }
  26608. this._rawCount = this._count = end;
  26609. // Reset data extent
  26610. this._extent = {};
  26611. prepareInvertedIndex(this);
  26612. };
  26613. function prepareChunks(storage, dimInfo, chunkSize, chunkCount, end) {
  26614. var DataCtor = dataCtors[dimInfo.type];
  26615. var lastChunkIndex = chunkCount - 1;
  26616. var dim = dimInfo.name;
  26617. var resizeChunkArray = storage[dim][lastChunkIndex];
  26618. if (resizeChunkArray && resizeChunkArray.length < chunkSize) {
  26619. var newStore = new DataCtor(Math.min(end - lastChunkIndex * chunkSize, chunkSize));
  26620. // The cost of the copy is probably inconsiderable
  26621. // within the initial chunkSize.
  26622. for (var j = 0; j < resizeChunkArray.length; j++) {
  26623. newStore[j] = resizeChunkArray[j];
  26624. }
  26625. storage[dim][lastChunkIndex] = newStore;
  26626. }
  26627. // Create new chunks.
  26628. for (var k = chunkCount * chunkSize; k < end; k += chunkSize) {
  26629. storage[dim].push(new DataCtor(Math.min(end - k, chunkSize)));
  26630. }
  26631. }
  26632. function prepareInvertedIndex(list) {
  26633. var invertedIndicesMap = list._invertedIndicesMap;
  26634. each$1(invertedIndicesMap, function (invertedIndices, dim) {
  26635. var dimInfo = list._dimensionInfos[dim];
  26636. // Currently, only dimensions that has ordinalMeta can create inverted indices.
  26637. var ordinalMeta = dimInfo.ordinalMeta;
  26638. if (ordinalMeta) {
  26639. invertedIndices = invertedIndicesMap[dim] = new CtorInt32Array(
  26640. ordinalMeta.categories.length
  26641. );
  26642. // The default value of TypedArray is 0. To avoid miss
  26643. // mapping to 0, we should set it as INDEX_NOT_FOUND.
  26644. for (var i = 0; i < invertedIndices.length; i++) {
  26645. invertedIndices[i] = INDEX_NOT_FOUND;
  26646. }
  26647. for (var i = 0; i < list._count; i++) {
  26648. // Only support the case that all values are distinct.
  26649. invertedIndices[list.get(dim, i)] = i;
  26650. }
  26651. }
  26652. });
  26653. }
  26654. function getRawValueFromStore(list, dimIndex, rawIndex) {
  26655. var val;
  26656. if (dimIndex != null) {
  26657. var chunkSize = list._chunkSize;
  26658. var chunkIndex = Math.floor(rawIndex / chunkSize);
  26659. var chunkOffset = rawIndex % chunkSize;
  26660. var dim = list.dimensions[dimIndex];
  26661. var chunk = list._storage[dim][chunkIndex];
  26662. if (chunk) {
  26663. val = chunk[chunkOffset];
  26664. var ordinalMeta = list._dimensionInfos[dim].ordinalMeta;
  26665. if (ordinalMeta && ordinalMeta.categories.length) {
  26666. val = ordinalMeta.categories[val];
  26667. }
  26668. }
  26669. }
  26670. return val;
  26671. }
  26672. /**
  26673. * @return {number}
  26674. */
  26675. listProto.count = function () {
  26676. return this._count;
  26677. };
  26678. listProto.getIndices = function () {
  26679. var newIndices;
  26680. var indices = this._indices;
  26681. if (indices) {
  26682. var Ctor = indices.constructor;
  26683. var thisCount = this._count;
  26684. // `new Array(a, b, c)` is different from `new Uint32Array(a, b, c)`.
  26685. if (Ctor === Array) {
  26686. newIndices = new Ctor(thisCount);
  26687. for (var i = 0; i < thisCount; i++) {
  26688. newIndices[i] = indices[i];
  26689. }
  26690. }
  26691. else {
  26692. newIndices = new Ctor(indices.buffer, 0, thisCount);
  26693. }
  26694. }
  26695. else {
  26696. var Ctor = getIndicesCtor(this);
  26697. var newIndices = new Ctor(this.count());
  26698. for (var i = 0; i < newIndices.length; i++) {
  26699. newIndices[i] = i;
  26700. }
  26701. }
  26702. return newIndices;
  26703. };
  26704. /**
  26705. * Get value. Return NaN if idx is out of range.
  26706. * @param {string} dim Dim must be concrete name.
  26707. * @param {number} idx
  26708. * @param {boolean} stack
  26709. * @return {number}
  26710. */
  26711. listProto.get = function (dim, idx /*, stack */) {
  26712. if (!(idx >= 0 && idx < this._count)) {
  26713. return NaN;
  26714. }
  26715. var storage = this._storage;
  26716. if (!storage[dim]) {
  26717. // TODO Warn ?
  26718. return NaN;
  26719. }
  26720. idx = this.getRawIndex(idx);
  26721. var chunkIndex = Math.floor(idx / this._chunkSize);
  26722. var chunkOffset = idx % this._chunkSize;
  26723. var chunkStore = storage[dim][chunkIndex];
  26724. var value = chunkStore[chunkOffset];
  26725. // FIXME ordinal data type is not stackable
  26726. // if (stack) {
  26727. // var dimensionInfo = this._dimensionInfos[dim];
  26728. // if (dimensionInfo && dimensionInfo.stackable) {
  26729. // var stackedOn = this.stackedOn;
  26730. // while (stackedOn) {
  26731. // // Get no stacked data of stacked on
  26732. // var stackedValue = stackedOn.get(dim, idx);
  26733. // // Considering positive stack, negative stack and empty data
  26734. // if ((value >= 0 && stackedValue > 0) // Positive stack
  26735. // || (value <= 0 && stackedValue < 0) // Negative stack
  26736. // ) {
  26737. // value += stackedValue;
  26738. // }
  26739. // stackedOn = stackedOn.stackedOn;
  26740. // }
  26741. // }
  26742. // }
  26743. return value;
  26744. };
  26745. /**
  26746. * @param {string} dim concrete dim
  26747. * @param {number} rawIndex
  26748. * @return {number|string}
  26749. */
  26750. listProto.getByRawIndex = function (dim, rawIdx) {
  26751. if (!(rawIdx >= 0 && rawIdx < this._rawCount)) {
  26752. return NaN;
  26753. }
  26754. var dimStore = this._storage[dim];
  26755. if (!dimStore) {
  26756. // TODO Warn ?
  26757. return NaN;
  26758. }
  26759. var chunkIndex = Math.floor(rawIdx / this._chunkSize);
  26760. var chunkOffset = rawIdx % this._chunkSize;
  26761. var chunkStore = dimStore[chunkIndex];
  26762. return chunkStore[chunkOffset];
  26763. };
  26764. /**
  26765. * FIXME Use `get` on chrome maybe slow(in filterSelf and selectRange).
  26766. * Hack a much simpler _getFast
  26767. * @private
  26768. */
  26769. listProto._getFast = function (dim, rawIdx) {
  26770. var chunkIndex = Math.floor(rawIdx / this._chunkSize);
  26771. var chunkOffset = rawIdx % this._chunkSize;
  26772. var chunkStore = this._storage[dim][chunkIndex];
  26773. return chunkStore[chunkOffset];
  26774. };
  26775. /**
  26776. * Get value for multi dimensions.
  26777. * @param {Array.<string>} [dimensions] If ignored, using all dimensions.
  26778. * @param {number} idx
  26779. * @return {number}
  26780. */
  26781. listProto.getValues = function (dimensions, idx /*, stack */) {
  26782. var values = [];
  26783. if (!isArray(dimensions)) {
  26784. // stack = idx;
  26785. idx = dimensions;
  26786. dimensions = this.dimensions;
  26787. }
  26788. for (var i = 0, len = dimensions.length; i < len; i++) {
  26789. values.push(this.get(dimensions[i], idx /*, stack */));
  26790. }
  26791. return values;
  26792. };
  26793. /**
  26794. * If value is NaN. Inlcuding '-'
  26795. * Only check the coord dimensions.
  26796. * @param {string} dim
  26797. * @param {number} idx
  26798. * @return {number}
  26799. */
  26800. listProto.hasValue = function (idx) {
  26801. var dataDimsOnCoord = this._dimensionsSummary.dataDimsOnCoord;
  26802. for (var i = 0, len = dataDimsOnCoord.length; i < len; i++) {
  26803. // Ordinal type originally can be string or number.
  26804. // But when an ordinal type is used on coord, it can
  26805. // not be string but only number. So we can also use isNaN.
  26806. if (isNaN(this.get(dataDimsOnCoord[i], idx))) {
  26807. return false;
  26808. }
  26809. }
  26810. return true;
  26811. };
  26812. /**
  26813. * Get extent of data in one dimension
  26814. * @param {string} dim
  26815. * @param {boolean} stack
  26816. */
  26817. listProto.getDataExtent = function (dim /*, stack */) {
  26818. // Make sure use concrete dim as cache name.
  26819. dim = this.getDimension(dim);
  26820. var dimData = this._storage[dim];
  26821. var initialExtent = getInitialExtent();
  26822. // stack = !!((stack || false) && this.getCalculationInfo(dim));
  26823. if (!dimData) {
  26824. return initialExtent;
  26825. }
  26826. // Make more strict checkings to ensure hitting cache.
  26827. var currEnd = this.count();
  26828. // var cacheName = [dim, !!stack].join('_');
  26829. // var cacheName = dim;
  26830. // Consider the most cases when using data zoom, `getDataExtent`
  26831. // happened before filtering. We cache raw extent, which is not
  26832. // necessary to be cleared and recalculated when restore data.
  26833. var useRaw = !this._indices; // && !stack;
  26834. var dimExtent;
  26835. if (useRaw) {
  26836. return this._rawExtent[dim].slice();
  26837. }
  26838. dimExtent = this._extent[dim];
  26839. if (dimExtent) {
  26840. return dimExtent.slice();
  26841. }
  26842. dimExtent = initialExtent;
  26843. var min = dimExtent[0];
  26844. var max = dimExtent[1];
  26845. for (var i = 0; i < currEnd; i++) {
  26846. // var value = stack ? this.get(dim, i, true) : this._getFast(dim, this.getRawIndex(i));
  26847. var value = this._getFast(dim, this.getRawIndex(i));
  26848. value < min && (min = value);
  26849. value > max && (max = value);
  26850. }
  26851. dimExtent = [min, max];
  26852. this._extent[dim] = dimExtent;
  26853. return dimExtent;
  26854. };
  26855. /**
  26856. * Optimize for the scenario that data is filtered by a given extent.
  26857. * Consider that if data amount is more than hundreds of thousand,
  26858. * extent calculation will cost more than 10ms and the cache will
  26859. * be erased because of the filtering.
  26860. */
  26861. listProto.getApproximateExtent = function (dim /*, stack */) {
  26862. dim = this.getDimension(dim);
  26863. return this._approximateExtent[dim] || this.getDataExtent(dim /*, stack */);
  26864. };
  26865. listProto.setApproximateExtent = function (extent, dim /*, stack */) {
  26866. dim = this.getDimension(dim);
  26867. this._approximateExtent[dim] = extent.slice();
  26868. };
  26869. /**
  26870. * @param {string} key
  26871. * @return {*}
  26872. */
  26873. listProto.getCalculationInfo = function (key) {
  26874. return this._calculationInfo[key];
  26875. };
  26876. /**
  26877. * @param {string|Object} key or k-v object
  26878. * @param {*} [value]
  26879. */
  26880. listProto.setCalculationInfo = function (key, value) {
  26881. isObject$4(key)
  26882. ? extend(this._calculationInfo, key)
  26883. : (this._calculationInfo[key] = value);
  26884. };
  26885. /**
  26886. * Get sum of data in one dimension
  26887. * @param {string} dim
  26888. */
  26889. listProto.getSum = function (dim /*, stack */) {
  26890. var dimData = this._storage[dim];
  26891. var sum = 0;
  26892. if (dimData) {
  26893. for (var i = 0, len = this.count(); i < len; i++) {
  26894. var value = this.get(dim, i /*, stack */);
  26895. if (!isNaN(value)) {
  26896. sum += value;
  26897. }
  26898. }
  26899. }
  26900. return sum;
  26901. };
  26902. /**
  26903. * Get median of data in one dimension
  26904. * @param {string} dim
  26905. */
  26906. listProto.getMedian = function (dim /*, stack */) {
  26907. var dimDataArray = [];
  26908. // map all data of one dimension
  26909. this.each(dim, function (val, idx) {
  26910. if (!isNaN(val)) {
  26911. dimDataArray.push(val);
  26912. }
  26913. });
  26914. // TODO
  26915. // Use quick select?
  26916. // immutability & sort
  26917. var sortedDimDataArray = [].concat(dimDataArray).sort(function (a, b) {
  26918. return a - b;
  26919. });
  26920. var len = this.count();
  26921. // calculate median
  26922. return len === 0
  26923. ? 0
  26924. : len % 2 === 1
  26925. ? sortedDimDataArray[(len - 1) / 2]
  26926. : (sortedDimDataArray[len / 2] + sortedDimDataArray[len / 2 - 1]) / 2;
  26927. };
  26928. // /**
  26929. // * Retreive the index with given value
  26930. // * @param {string} dim Concrete dimension.
  26931. // * @param {number} value
  26932. // * @return {number}
  26933. // */
  26934. // Currently incorrect: should return dataIndex but not rawIndex.
  26935. // Do not fix it until this method is to be used somewhere.
  26936. // FIXME Precision of float value
  26937. // listProto.indexOf = function (dim, value) {
  26938. // var storage = this._storage;
  26939. // var dimData = storage[dim];
  26940. // var chunkSize = this._chunkSize;
  26941. // if (dimData) {
  26942. // for (var i = 0, len = this.count(); i < len; i++) {
  26943. // var chunkIndex = Math.floor(i / chunkSize);
  26944. // var chunkOffset = i % chunkSize;
  26945. // if (dimData[chunkIndex][chunkOffset] === value) {
  26946. // return i;
  26947. // }
  26948. // }
  26949. // }
  26950. // return -1;
  26951. // };
  26952. /**
  26953. * Only support the dimension which inverted index created.
  26954. * Do not support other cases until required.
  26955. * @param {string} concrete dim
  26956. * @param {number|string} value
  26957. * @return {number} rawIndex
  26958. */
  26959. listProto.rawIndexOf = function (dim, value) {
  26960. var invertedIndices = dim && this._invertedIndicesMap[dim];
  26961. if (__DEV__) {
  26962. if (!invertedIndices) {
  26963. throw new Error('Do not supported yet');
  26964. }
  26965. }
  26966. var rawIndex = invertedIndices[value];
  26967. if (rawIndex == null || isNaN(rawIndex)) {
  26968. return INDEX_NOT_FOUND;
  26969. }
  26970. return rawIndex;
  26971. };
  26972. /**
  26973. * Retreive the index with given name
  26974. * @param {number} idx
  26975. * @param {number} name
  26976. * @return {number}
  26977. */
  26978. listProto.indexOfName = function (name) {
  26979. for (var i = 0, len = this.count(); i < len; i++) {
  26980. if (this.getName(i) === name) {
  26981. return i;
  26982. }
  26983. }
  26984. return -1;
  26985. };
  26986. /**
  26987. * Retreive the index with given raw data index
  26988. * @param {number} idx
  26989. * @param {number} name
  26990. * @return {number}
  26991. */
  26992. listProto.indexOfRawIndex = function (rawIndex) {
  26993. if (!this._indices) {
  26994. return rawIndex;
  26995. }
  26996. if (rawIndex >= this._rawCount || rawIndex < 0) {
  26997. return -1;
  26998. }
  26999. // Indices are ascending
  27000. var indices = this._indices;
  27001. // If rawIndex === dataIndex
  27002. var rawDataIndex = indices[rawIndex];
  27003. if (rawDataIndex != null && rawDataIndex < this._count && rawDataIndex === rawIndex) {
  27004. return rawIndex;
  27005. }
  27006. var left = 0;
  27007. var right = this._count - 1;
  27008. while (left <= right) {
  27009. var mid = (left + right) / 2 | 0;
  27010. if (indices[mid] < rawIndex) {
  27011. left = mid + 1;
  27012. }
  27013. else if (indices[mid] > rawIndex) {
  27014. right = mid - 1;
  27015. }
  27016. else {
  27017. return mid;
  27018. }
  27019. }
  27020. return -1;
  27021. };
  27022. /**
  27023. * Retreive the index of nearest value
  27024. * @param {string} dim
  27025. * @param {number} value
  27026. * @param {number} [maxDistance=Infinity]
  27027. * @return {Array.<number>} Considere multiple points has the same value.
  27028. */
  27029. listProto.indicesOfNearest = function (dim, value, maxDistance) {
  27030. var storage = this._storage;
  27031. var dimData = storage[dim];
  27032. var nearestIndices = [];
  27033. if (!dimData) {
  27034. return nearestIndices;
  27035. }
  27036. if (maxDistance == null) {
  27037. maxDistance = Infinity;
  27038. }
  27039. var minDist = Number.MAX_VALUE;
  27040. var minDiff = -1;
  27041. for (var i = 0, len = this.count(); i < len; i++) {
  27042. var diff = value - this.get(dim, i /*, stack */);
  27043. var dist = Math.abs(diff);
  27044. if (diff <= maxDistance && dist <= minDist) {
  27045. // For the case of two data are same on xAxis, which has sequence data.
  27046. // Show the nearest index
  27047. // https://github.com/ecomfe/echarts/issues/2869
  27048. if (dist < minDist || (diff >= 0 && minDiff < 0)) {
  27049. minDist = dist;
  27050. minDiff = diff;
  27051. nearestIndices.length = 0;
  27052. }
  27053. nearestIndices.push(i);
  27054. }
  27055. }
  27056. return nearestIndices;
  27057. };
  27058. /**
  27059. * Get raw data index
  27060. * @param {number} idx
  27061. * @return {number}
  27062. */
  27063. listProto.getRawIndex = getRawIndexWithoutIndices;
  27064. function getRawIndexWithoutIndices(idx) {
  27065. return idx;
  27066. }
  27067. function getRawIndexWithIndices(idx) {
  27068. if (idx < this._count && idx >= 0) {
  27069. return this._indices[idx];
  27070. }
  27071. return -1;
  27072. }
  27073. /**
  27074. * Get raw data item
  27075. * @param {number} idx
  27076. * @return {number}
  27077. */
  27078. listProto.getRawDataItem = function (idx) {
  27079. if (!this._rawData.persistent) {
  27080. var val = [];
  27081. for (var i = 0; i < this.dimensions.length; i++) {
  27082. var dim = this.dimensions[i];
  27083. val.push(this.get(dim, idx));
  27084. }
  27085. return val;
  27086. }
  27087. else {
  27088. return this._rawData.getItem(this.getRawIndex(idx));
  27089. }
  27090. };
  27091. /**
  27092. * @param {number} idx
  27093. * @param {boolean} [notDefaultIdx=false]
  27094. * @return {string}
  27095. */
  27096. listProto.getName = function (idx) {
  27097. var rawIndex = this.getRawIndex(idx);
  27098. return this._nameList[rawIndex]
  27099. || getRawValueFromStore(this, this._nameDimIdx, rawIndex)
  27100. || '';
  27101. };
  27102. /**
  27103. * @param {number} idx
  27104. * @param {boolean} [notDefaultIdx=false]
  27105. * @return {string}
  27106. */
  27107. listProto.getId = function (idx) {
  27108. return getId(this, this.getRawIndex(idx));
  27109. };
  27110. function getId(list, rawIndex) {
  27111. var id = list._idList[rawIndex];
  27112. if (id == null) {
  27113. id = getRawValueFromStore(list, list._idDimIdx, rawIndex);
  27114. }
  27115. if (id == null) {
  27116. // FIXME Check the usage in graph, should not use prefix.
  27117. id = ID_PREFIX + rawIndex;
  27118. }
  27119. return id;
  27120. }
  27121. function normalizeDimensions(dimensions) {
  27122. if (!isArray(dimensions)) {
  27123. dimensions = [dimensions];
  27124. }
  27125. return dimensions;
  27126. }
  27127. function validateDimensions(list, dims) {
  27128. for (var i = 0; i < dims.length; i++) {
  27129. // stroage may be empty when no data, so use
  27130. // dimensionInfos to check.
  27131. if (!list._dimensionInfos[dims[i]]) {
  27132. console.error('Unkown dimension ' + dims[i]);
  27133. }
  27134. }
  27135. }
  27136. /**
  27137. * Data iteration
  27138. * @param {string|Array.<string>}
  27139. * @param {Function} cb
  27140. * @param {*} [context=this]
  27141. *
  27142. * @example
  27143. * list.each('x', function (x, idx) {});
  27144. * list.each(['x', 'y'], function (x, y, idx) {});
  27145. * list.each(function (idx) {})
  27146. */
  27147. listProto.each = function (dims, cb, context, contextCompat) {
  27148. 'use strict';
  27149. if (!this._count) {
  27150. return;
  27151. }
  27152. if (typeof dims === 'function') {
  27153. contextCompat = context;
  27154. context = cb;
  27155. cb = dims;
  27156. dims = [];
  27157. }
  27158. // contextCompat just for compat echarts3
  27159. context = context || contextCompat || this;
  27160. dims = map(normalizeDimensions(dims), this.getDimension, this);
  27161. if (__DEV__) {
  27162. validateDimensions(this, dims);
  27163. }
  27164. var dimSize = dims.length;
  27165. for (var i = 0; i < this.count(); i++) {
  27166. // Simple optimization
  27167. switch (dimSize) {
  27168. case 0:
  27169. cb.call(context, i);
  27170. break;
  27171. case 1:
  27172. cb.call(context, this.get(dims[0], i), i);
  27173. break;
  27174. case 2:
  27175. cb.call(context, this.get(dims[0], i), this.get(dims[1], i), i);
  27176. break;
  27177. default:
  27178. var k = 0;
  27179. var value = [];
  27180. for (; k < dimSize; k++) {
  27181. value[k] = this.get(dims[k], i);
  27182. }
  27183. // Index
  27184. value[k] = i;
  27185. cb.apply(context, value);
  27186. }
  27187. }
  27188. };
  27189. /**
  27190. * Data filter
  27191. * @param {string|Array.<string>}
  27192. * @param {Function} cb
  27193. * @param {*} [context=this]
  27194. */
  27195. listProto.filterSelf = function (dimensions, cb, context, contextCompat) {
  27196. 'use strict';
  27197. if (!this._count) {
  27198. return;
  27199. }
  27200. if (typeof dimensions === 'function') {
  27201. contextCompat = context;
  27202. context = cb;
  27203. cb = dimensions;
  27204. dimensions = [];
  27205. }
  27206. // contextCompat just for compat echarts3
  27207. context = context || contextCompat || this;
  27208. dimensions = map(
  27209. normalizeDimensions(dimensions), this.getDimension, this
  27210. );
  27211. if (__DEV__) {
  27212. validateDimensions(this, dimensions);
  27213. }
  27214. var count = this.count();
  27215. var Ctor = getIndicesCtor(this);
  27216. var newIndices = new Ctor(count);
  27217. var value = [];
  27218. var dimSize = dimensions.length;
  27219. var offset = 0;
  27220. var dim0 = dimensions[0];
  27221. for (var i = 0; i < count; i++) {
  27222. var keep;
  27223. var rawIdx = this.getRawIndex(i);
  27224. // Simple optimization
  27225. if (dimSize === 0) {
  27226. keep = cb.call(context, i);
  27227. }
  27228. else if (dimSize === 1) {
  27229. var val = this._getFast(dim0, rawIdx);
  27230. keep = cb.call(context, val, i);
  27231. }
  27232. else {
  27233. for (var k = 0; k < dimSize; k++) {
  27234. value[k] = this._getFast(dim0, rawIdx);
  27235. }
  27236. value[k] = i;
  27237. keep = cb.apply(context, value);
  27238. }
  27239. if (keep) {
  27240. newIndices[offset++] = rawIdx;
  27241. }
  27242. }
  27243. // Set indices after filtered.
  27244. if (offset < count) {
  27245. this._indices = newIndices;
  27246. }
  27247. this._count = offset;
  27248. // Reset data extent
  27249. this._extent = {};
  27250. this.getRawIndex = this._indices ? getRawIndexWithIndices : getRawIndexWithoutIndices;
  27251. return this;
  27252. };
  27253. /**
  27254. * Select data in range. (For optimization of filter)
  27255. * (Manually inline code, support 5 million data filtering in data zoom.)
  27256. */
  27257. listProto.selectRange = function (range) {
  27258. 'use strict';
  27259. if (!this._count) {
  27260. return;
  27261. }
  27262. var dimensions = [];
  27263. for (var dim in range) {
  27264. if (range.hasOwnProperty(dim)) {
  27265. dimensions.push(dim);
  27266. }
  27267. }
  27268. if (__DEV__) {
  27269. validateDimensions(this, dimensions);
  27270. }
  27271. var dimSize = dimensions.length;
  27272. if (!dimSize) {
  27273. return;
  27274. }
  27275. var originalCount = this.count();
  27276. var Ctor = getIndicesCtor(this);
  27277. var newIndices = new Ctor(originalCount);
  27278. var offset = 0;
  27279. var dim0 = dimensions[0];
  27280. var min = range[dim0][0];
  27281. var max = range[dim0][1];
  27282. var quickFinished = false;
  27283. if (!this._indices) {
  27284. // Extreme optimization for common case. About 2x faster in chrome.
  27285. var idx = 0;
  27286. if (dimSize === 1) {
  27287. var dimStorage = this._storage[dimensions[0]];
  27288. for (var k = 0; k < this._chunkCount; k++) {
  27289. var chunkStorage = dimStorage[k];
  27290. var len = Math.min(this._count - k * this._chunkSize, this._chunkSize);
  27291. for (var i = 0; i < len; i++) {
  27292. var val = chunkStorage[i];
  27293. // NaN will not be filtered. Consider the case, in line chart, empty
  27294. // value indicates the line should be broken. But for the case like
  27295. // scatter plot, a data item with empty value will not be rendered,
  27296. // but the axis extent may be effected if some other dim of the data
  27297. // item has value. Fortunately it is not a significant negative effect.
  27298. if (
  27299. (val >= min && val <= max) || isNaN(val)
  27300. ) {
  27301. newIndices[offset++] = idx;
  27302. }
  27303. idx++;
  27304. }
  27305. }
  27306. quickFinished = true;
  27307. }
  27308. else if (dimSize === 2) {
  27309. var dimStorage = this._storage[dim0];
  27310. var dimStorage2 = this._storage[dimensions[1]];
  27311. var min2 = range[dimensions[1]][0];
  27312. var max2 = range[dimensions[1]][1];
  27313. for (var k = 0; k < this._chunkCount; k++) {
  27314. var chunkStorage = dimStorage[k];
  27315. var chunkStorage2 = dimStorage2[k];
  27316. var len = Math.min(this._count - k * this._chunkSize, this._chunkSize);
  27317. for (var i = 0; i < len; i++) {
  27318. var val = chunkStorage[i];
  27319. var val2 = chunkStorage2[i];
  27320. // Do not filter NaN, see comment above.
  27321. if ((
  27322. (val >= min && val <= max) || isNaN(val)
  27323. )
  27324. && (
  27325. (val2 >= min2 && val2 <= max2) || isNaN(val2)
  27326. )
  27327. ) {
  27328. newIndices[offset++] = idx;
  27329. }
  27330. idx++;
  27331. }
  27332. }
  27333. quickFinished = true;
  27334. }
  27335. }
  27336. if (!quickFinished) {
  27337. if (dimSize === 1) {
  27338. for (var i = 0; i < originalCount; i++) {
  27339. var rawIndex = this.getRawIndex(i);
  27340. var val = this._getFast(dim0, rawIndex);
  27341. // Do not filter NaN, see comment above.
  27342. if (
  27343. (val >= min && val <= max) || isNaN(val)
  27344. ) {
  27345. newIndices[offset++] = rawIndex;
  27346. }
  27347. }
  27348. }
  27349. else {
  27350. for (var i = 0; i < originalCount; i++) {
  27351. var keep = true;
  27352. var rawIndex = this.getRawIndex(i);
  27353. for (var k = 0; k < dimSize; k++) {
  27354. var dimk = dimensions[k];
  27355. var val = this._getFast(dim, rawIndex);
  27356. // Do not filter NaN, see comment above.
  27357. if (val < range[dimk][0] || val > range[dimk][1]) {
  27358. keep = false;
  27359. }
  27360. }
  27361. if (keep) {
  27362. newIndices[offset++] = this.getRawIndex(i);
  27363. }
  27364. }
  27365. }
  27366. }
  27367. // Set indices after filtered.
  27368. if (offset < originalCount) {
  27369. this._indices = newIndices;
  27370. }
  27371. this._count = offset;
  27372. // Reset data extent
  27373. this._extent = {};
  27374. this.getRawIndex = this._indices ? getRawIndexWithIndices : getRawIndexWithoutIndices;
  27375. return this;
  27376. };
  27377. /**
  27378. * Data mapping to a plain array
  27379. * @param {string|Array.<string>} [dimensions]
  27380. * @param {Function} cb
  27381. * @param {*} [context=this]
  27382. * @return {Array}
  27383. */
  27384. listProto.mapArray = function (dimensions, cb, context, contextCompat) {
  27385. 'use strict';
  27386. if (typeof dimensions === 'function') {
  27387. contextCompat = context;
  27388. context = cb;
  27389. cb = dimensions;
  27390. dimensions = [];
  27391. }
  27392. // contextCompat just for compat echarts3
  27393. context = context || contextCompat || this;
  27394. var result = [];
  27395. this.each(dimensions, function () {
  27396. result.push(cb && cb.apply(this, arguments));
  27397. }, context);
  27398. return result;
  27399. };
  27400. // Data in excludeDimensions is copied, otherwise transfered.
  27401. function cloneListForMapAndSample(original, excludeDimensions) {
  27402. var allDimensions = original.dimensions;
  27403. var list = new List(
  27404. map(allDimensions, original.getDimensionInfo, original),
  27405. original.hostModel
  27406. );
  27407. // FIXME If needs stackedOn, value may already been stacked
  27408. transferProperties(list, original);
  27409. var storage = list._storage = {};
  27410. var originalStorage = original._storage;
  27411. // Init storage
  27412. for (var i = 0; i < allDimensions.length; i++) {
  27413. var dim = allDimensions[i];
  27414. if (originalStorage[dim]) {
  27415. // Notice that we do not reset invertedIndicesMap here, becuase
  27416. // there is no scenario of mapping or sampling ordinal dimension.
  27417. if (indexOf(excludeDimensions, dim) >= 0) {
  27418. storage[dim] = cloneDimStore(originalStorage[dim]);
  27419. list._rawExtent[dim] = getInitialExtent();
  27420. list._extent[dim] = null;
  27421. }
  27422. else {
  27423. // Direct reference for other dimensions
  27424. storage[dim] = originalStorage[dim];
  27425. }
  27426. }
  27427. }
  27428. return list;
  27429. }
  27430. function cloneDimStore(originalDimStore) {
  27431. var newDimStore = new Array(originalDimStore.length);
  27432. for (var j = 0; j < originalDimStore.length; j++) {
  27433. newDimStore[j] = cloneChunk(originalDimStore[j]);
  27434. }
  27435. return newDimStore;
  27436. }
  27437. function getInitialExtent() {
  27438. return [Infinity, -Infinity];
  27439. }
  27440. /**
  27441. * Data mapping to a new List with given dimensions
  27442. * @param {string|Array.<string>} dimensions
  27443. * @param {Function} cb
  27444. * @param {*} [context=this]
  27445. * @return {Array}
  27446. */
  27447. listProto.map = function (dimensions, cb, context, contextCompat) {
  27448. 'use strict';
  27449. // contextCompat just for compat echarts3
  27450. context = context || contextCompat || this;
  27451. dimensions = map(
  27452. normalizeDimensions(dimensions), this.getDimension, this
  27453. );
  27454. if (__DEV__) {
  27455. validateDimensions(this, dimensions);
  27456. }
  27457. var list = cloneListForMapAndSample(this, dimensions);
  27458. // Following properties are all immutable.
  27459. // So we can reference to the same value
  27460. list._indices = this._indices;
  27461. list.getRawIndex = list._indices ? getRawIndexWithIndices : getRawIndexWithoutIndices;
  27462. var storage = list._storage;
  27463. var tmpRetValue = [];
  27464. var chunkSize = this._chunkSize;
  27465. var dimSize = dimensions.length;
  27466. var dataCount = this.count();
  27467. var values = [];
  27468. var rawExtent = list._rawExtent;
  27469. for (var dataIndex = 0; dataIndex < dataCount; dataIndex++) {
  27470. for (var dimIndex = 0; dimIndex < dimSize; dimIndex++) {
  27471. values[dimIndex] = this.get(dimensions[dimIndex], dataIndex /*, stack */);
  27472. }
  27473. values[dimSize] = dataIndex;
  27474. var retValue = cb && cb.apply(context, values);
  27475. if (retValue != null) {
  27476. // a number or string (in oridinal dimension)?
  27477. if (typeof retValue !== 'object') {
  27478. tmpRetValue[0] = retValue;
  27479. retValue = tmpRetValue;
  27480. }
  27481. var rawIndex = this.getRawIndex(dataIndex);
  27482. var chunkIndex = Math.floor(rawIndex / chunkSize);
  27483. var chunkOffset = rawIndex % chunkSize;
  27484. for (var i = 0; i < retValue.length; i++) {
  27485. var dim = dimensions[i];
  27486. var val = retValue[i];
  27487. var rawExtentOnDim = rawExtent[dim];
  27488. var dimStore = storage[dim];
  27489. if (dimStore) {
  27490. dimStore[chunkIndex][chunkOffset] = val;
  27491. }
  27492. if (val < rawExtentOnDim[0]) {
  27493. rawExtentOnDim[0] = val;
  27494. }
  27495. if (val > rawExtentOnDim[1]) {
  27496. rawExtentOnDim[1] = val;
  27497. }
  27498. }
  27499. }
  27500. }
  27501. return list;
  27502. };
  27503. /**
  27504. * Large data down sampling on given dimension
  27505. * @param {string} dimension
  27506. * @param {number} rate
  27507. * @param {Function} sampleValue
  27508. * @param {Function} sampleIndex Sample index for name and id
  27509. */
  27510. listProto.downSample = function (dimension, rate, sampleValue, sampleIndex) {
  27511. var list = cloneListForMapAndSample(this, [dimension]);
  27512. var targetStorage = list._storage;
  27513. var frameValues = [];
  27514. var frameSize = Math.floor(1 / rate);
  27515. var dimStore = targetStorage[dimension];
  27516. var len = this.count();
  27517. var chunkSize = this._chunkSize;
  27518. var rawExtentOnDim = list._rawExtent[dimension];
  27519. var newIndices = new (getIndicesCtor(this))(len);
  27520. var offset = 0;
  27521. for (var i = 0; i < len; i += frameSize) {
  27522. // Last frame
  27523. if (frameSize > len - i) {
  27524. frameSize = len - i;
  27525. frameValues.length = frameSize;
  27526. }
  27527. for (var k = 0; k < frameSize; k++) {
  27528. var dataIdx = this.getRawIndex(i + k);
  27529. var originalChunkIndex = Math.floor(dataIdx / chunkSize);
  27530. var originalChunkOffset = dataIdx % chunkSize;
  27531. frameValues[k] = dimStore[originalChunkIndex][originalChunkOffset];
  27532. }
  27533. var value = sampleValue(frameValues);
  27534. var sampleFrameIdx = this.getRawIndex(
  27535. Math.min(i + sampleIndex(frameValues, value) || 0, len - 1)
  27536. );
  27537. var sampleChunkIndex = Math.floor(sampleFrameIdx / chunkSize);
  27538. var sampleChunkOffset = sampleFrameIdx % chunkSize;
  27539. // Only write value on the filtered data
  27540. dimStore[sampleChunkIndex][sampleChunkOffset] = value;
  27541. if (value < rawExtentOnDim[0]) {
  27542. rawExtentOnDim[0] = value;
  27543. }
  27544. if (value > rawExtentOnDim[1]) {
  27545. rawExtentOnDim[1] = value;
  27546. }
  27547. newIndices[offset++] = sampleFrameIdx;
  27548. }
  27549. list._count = offset;
  27550. list._indices = newIndices;
  27551. list.getRawIndex = getRawIndexWithIndices;
  27552. return list;
  27553. };
  27554. /**
  27555. * Get model of one data item.
  27556. *
  27557. * @param {number} idx
  27558. */
  27559. // FIXME Model proxy ?
  27560. listProto.getItemModel = function (idx) {
  27561. var hostModel = this.hostModel;
  27562. return new Model(this.getRawDataItem(idx), hostModel, hostModel && hostModel.ecModel);
  27563. };
  27564. /**
  27565. * Create a data differ
  27566. * @param {module:echarts/data/List} otherList
  27567. * @return {module:echarts/data/DataDiffer}
  27568. */
  27569. listProto.diff = function (otherList) {
  27570. var thisList = this;
  27571. return new DataDiffer(
  27572. otherList ? otherList.getIndices() : [],
  27573. this.getIndices(),
  27574. function (idx) {
  27575. return getId(otherList, idx);
  27576. },
  27577. function (idx) {
  27578. return getId(thisList, idx);
  27579. }
  27580. );
  27581. };
  27582. /**
  27583. * Get visual property.
  27584. * @param {string} key
  27585. */
  27586. listProto.getVisual = function (key) {
  27587. var visual = this._visual;
  27588. return visual && visual[key];
  27589. };
  27590. /**
  27591. * Set visual property
  27592. * @param {string|Object} key
  27593. * @param {*} [value]
  27594. *
  27595. * @example
  27596. * setVisual('color', color);
  27597. * setVisual({
  27598. * 'color': color
  27599. * });
  27600. */
  27601. listProto.setVisual = function (key, val) {
  27602. if (isObject$4(key)) {
  27603. for (var name in key) {
  27604. if (key.hasOwnProperty(name)) {
  27605. this.setVisual(name, key[name]);
  27606. }
  27607. }
  27608. return;
  27609. }
  27610. this._visual = this._visual || {};
  27611. this._visual[key] = val;
  27612. };
  27613. /**
  27614. * Set layout property.
  27615. * @param {string|Object} key
  27616. * @param {*} [val]
  27617. */
  27618. listProto.setLayout = function (key, val) {
  27619. if (isObject$4(key)) {
  27620. for (var name in key) {
  27621. if (key.hasOwnProperty(name)) {
  27622. this.setLayout(name, key[name]);
  27623. }
  27624. }
  27625. return;
  27626. }
  27627. this._layout[key] = val;
  27628. };
  27629. /**
  27630. * Get layout property.
  27631. * @param {string} key.
  27632. * @return {*}
  27633. */
  27634. listProto.getLayout = function (key) {
  27635. return this._layout[key];
  27636. };
  27637. /**
  27638. * Get layout of single data item
  27639. * @param {number} idx
  27640. */
  27641. listProto.getItemLayout = function (idx) {
  27642. return this._itemLayouts[idx];
  27643. };
  27644. /**
  27645. * Set layout of single data item
  27646. * @param {number} idx
  27647. * @param {Object} layout
  27648. * @param {boolean=} [merge=false]
  27649. */
  27650. listProto.setItemLayout = function (idx, layout, merge$$1) {
  27651. this._itemLayouts[idx] = merge$$1
  27652. ? extend(this._itemLayouts[idx] || {}, layout)
  27653. : layout;
  27654. };
  27655. /**
  27656. * Clear all layout of single data item
  27657. */
  27658. listProto.clearItemLayouts = function () {
  27659. this._itemLayouts.length = 0;
  27660. };
  27661. /**
  27662. * Get visual property of single data item
  27663. * @param {number} idx
  27664. * @param {string} key
  27665. * @param {boolean} [ignoreParent=false]
  27666. */
  27667. listProto.getItemVisual = function (idx, key, ignoreParent) {
  27668. var itemVisual = this._itemVisuals[idx];
  27669. var val = itemVisual && itemVisual[key];
  27670. if (val == null && !ignoreParent) {
  27671. // Use global visual property
  27672. return this.getVisual(key);
  27673. }
  27674. return val;
  27675. };
  27676. /**
  27677. * Set visual property of single data item
  27678. *
  27679. * @param {number} idx
  27680. * @param {string|Object} key
  27681. * @param {*} [value]
  27682. *
  27683. * @example
  27684. * setItemVisual(0, 'color', color);
  27685. * setItemVisual(0, {
  27686. * 'color': color
  27687. * });
  27688. */
  27689. listProto.setItemVisual = function (idx, key, value) {
  27690. var itemVisual = this._itemVisuals[idx] || {};
  27691. var hasItemVisual = this.hasItemVisual;
  27692. this._itemVisuals[idx] = itemVisual;
  27693. if (isObject$4(key)) {
  27694. for (var name in key) {
  27695. if (key.hasOwnProperty(name)) {
  27696. itemVisual[name] = key[name];
  27697. hasItemVisual[name] = true;
  27698. }
  27699. }
  27700. return;
  27701. }
  27702. itemVisual[key] = value;
  27703. hasItemVisual[key] = true;
  27704. };
  27705. /**
  27706. * Clear itemVisuals and list visual.
  27707. */
  27708. listProto.clearAllVisual = function () {
  27709. this._visual = {};
  27710. this._itemVisuals = [];
  27711. this.hasItemVisual = {};
  27712. };
  27713. var setItemDataAndSeriesIndex = function (child) {
  27714. child.seriesIndex = this.seriesIndex;
  27715. child.dataIndex = this.dataIndex;
  27716. child.dataType = this.dataType;
  27717. };
  27718. /**
  27719. * Set graphic element relative to data. It can be set as null
  27720. * @param {number} idx
  27721. * @param {module:zrender/Element} [el]
  27722. */
  27723. listProto.setItemGraphicEl = function (idx, el) {
  27724. var hostModel = this.hostModel;
  27725. if (el) {
  27726. // Add data index and series index for indexing the data by element
  27727. // Useful in tooltip
  27728. el.dataIndex = idx;
  27729. el.dataType = this.dataType;
  27730. el.seriesIndex = hostModel && hostModel.seriesIndex;
  27731. if (el.type === 'group') {
  27732. el.traverse(setItemDataAndSeriesIndex, el);
  27733. }
  27734. }
  27735. this._graphicEls[idx] = el;
  27736. };
  27737. /**
  27738. * @param {number} idx
  27739. * @return {module:zrender/Element}
  27740. */
  27741. listProto.getItemGraphicEl = function (idx) {
  27742. return this._graphicEls[idx];
  27743. };
  27744. /**
  27745. * @param {Function} cb
  27746. * @param {*} context
  27747. */
  27748. listProto.eachItemGraphicEl = function (cb, context) {
  27749. each$1(this._graphicEls, function (el, idx) {
  27750. if (el) {
  27751. cb && cb.call(context, el, idx);
  27752. }
  27753. });
  27754. };
  27755. /**
  27756. * Shallow clone a new list except visual and layout properties, and graph elements.
  27757. * New list only change the indices.
  27758. */
  27759. listProto.cloneShallow = function (list) {
  27760. if (!list) {
  27761. var dimensionInfoList = map(this.dimensions, this.getDimensionInfo, this);
  27762. list = new List(dimensionInfoList, this.hostModel);
  27763. }
  27764. // FIXME
  27765. list._storage = this._storage;
  27766. transferProperties(list, this);
  27767. // Clone will not change the data extent and indices
  27768. if (this._indices) {
  27769. var Ctor = this._indices.constructor;
  27770. list._indices = new Ctor(this._indices);
  27771. }
  27772. else {
  27773. list._indices = null;
  27774. }
  27775. list.getRawIndex = list._indices ? getRawIndexWithIndices : getRawIndexWithoutIndices;
  27776. return list;
  27777. };
  27778. /**
  27779. * Wrap some method to add more feature
  27780. * @param {string} methodName
  27781. * @param {Function} injectFunction
  27782. */
  27783. listProto.wrapMethod = function (methodName, injectFunction) {
  27784. var originalMethod = this[methodName];
  27785. if (typeof originalMethod !== 'function') {
  27786. return;
  27787. }
  27788. this.__wrappedMethods = this.__wrappedMethods || [];
  27789. this.__wrappedMethods.push(methodName);
  27790. this[methodName] = function () {
  27791. var res = originalMethod.apply(this, arguments);
  27792. return injectFunction.apply(this, [res].concat(slice(arguments)));
  27793. };
  27794. };
  27795. // Methods that create a new list based on this list should be listed here.
  27796. // Notice that those method should `RETURN` the new list.
  27797. listProto.TRANSFERABLE_METHODS = ['cloneShallow', 'downSample', 'map'];
  27798. // Methods that change indices of this list should be listed here.
  27799. listProto.CHANGABLE_METHODS = ['filterSelf', 'selectRange'];
  27800. /*
  27801. * Licensed to the Apache Software Foundation (ASF) under one
  27802. * or more contributor license agreements. See the NOTICE file
  27803. * distributed with this work for additional information
  27804. * regarding copyright ownership. The ASF licenses this file
  27805. * to you under the Apache License, Version 2.0 (the
  27806. * "License"); you may not use this file except in compliance
  27807. * with the License. You may obtain a copy of the License at
  27808. *
  27809. * http://www.apache.org/licenses/LICENSE-2.0
  27810. *
  27811. * Unless required by applicable law or agreed to in writing,
  27812. * software distributed under the License is distributed on an
  27813. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  27814. * KIND, either express or implied. See the License for the
  27815. * specific language governing permissions and limitations
  27816. * under the License.
  27817. */
  27818. /**
  27819. * @deprecated
  27820. * Use `echarts/data/helper/createDimensions` instead.
  27821. */
  27822. /**
  27823. * @see {module:echarts/test/ut/spec/data/completeDimensions}
  27824. *
  27825. * Complete the dimensions array, by user defined `dimension` and `encode`,
  27826. * and guessing from the data structure.
  27827. * If no 'value' dimension specified, the first no-named dimension will be
  27828. * named as 'value'.
  27829. *
  27830. * @param {Array.<string>} sysDims Necessary dimensions, like ['x', 'y'], which
  27831. * provides not only dim template, but also default order.
  27832. * properties: 'name', 'type', 'displayName'.
  27833. * `name` of each item provides default coord name.
  27834. * [{dimsDef: [string|Object, ...]}, ...] dimsDef of sysDim item provides default dim name, and
  27835. * provide dims count that the sysDim required.
  27836. * [{ordinalMeta}] can be specified.
  27837. * @param {module:echarts/data/Source|Array|Object} source or data (for compatibal with pervious)
  27838. * @param {Object} [opt]
  27839. * @param {Array.<Object|string>} [opt.dimsDef] option.series.dimensions User defined dimensions
  27840. * For example: ['asdf', {name, type}, ...].
  27841. * @param {Object|HashMap} [opt.encodeDef] option.series.encode {x: 2, y: [3, 1], tooltip: [1, 2], label: 3}
  27842. * @param {string} [opt.generateCoord] Generate coord dim with the given name.
  27843. * If not specified, extra dim names will be:
  27844. * 'value', 'value0', 'value1', ...
  27845. * @param {number} [opt.generateCoordCount] By default, the generated dim name is `generateCoord`.
  27846. * If `generateCoordCount` specified, the generated dim names will be:
  27847. * `generateCoord` + 0, `generateCoord` + 1, ...
  27848. * can be Infinity, indicate that use all of the remain columns.
  27849. * @param {number} [opt.dimCount] If not specified, guess by the first data item.
  27850. * @param {number} [opt.encodeDefaulter] If not specified, auto find the next available data dim.
  27851. * @return {Array.<Object>} [{
  27852. * name: string mandatory,
  27853. * displayName: string, the origin name in dimsDef, see source helper.
  27854. * If displayName given, the tooltip will displayed vertically.
  27855. * coordDim: string mandatory,
  27856. * coordDimIndex: number mandatory,
  27857. * type: string optional,
  27858. * otherDims: { never null/undefined
  27859. * tooltip: number optional,
  27860. * label: number optional,
  27861. * itemName: number optional,
  27862. * seriesName: number optional,
  27863. * },
  27864. * isExtraCoord: boolean true if coord is generated
  27865. * (not specified in encode and not series specified)
  27866. * other props ...
  27867. * }]
  27868. */
  27869. function completeDimensions(sysDims, source, opt) {
  27870. if (!Source.isInstance(source)) {
  27871. source = Source.seriesDataToSource(source);
  27872. }
  27873. opt = opt || {};
  27874. sysDims = (sysDims || []).slice();
  27875. var dimsDef = (opt.dimsDef || []).slice();
  27876. var encodeDef = createHashMap(opt.encodeDef);
  27877. var dataDimNameMap = createHashMap();
  27878. var coordDimNameMap = createHashMap();
  27879. // var valueCandidate;
  27880. var result = [];
  27881. var dimCount = getDimCount(source, sysDims, dimsDef, opt.dimCount);
  27882. // Apply user defined dims (`name` and `type`) and init result.
  27883. for (var i = 0; i < dimCount; i++) {
  27884. var dimDefItem = dimsDef[i] = extend(
  27885. {}, isObject$1(dimsDef[i]) ? dimsDef[i] : {name: dimsDef[i]}
  27886. );
  27887. var userDimName = dimDefItem.name;
  27888. var resultItem = result[i] = {otherDims: {}};
  27889. // Name will be applied later for avoiding duplication.
  27890. if (userDimName != null && dataDimNameMap.get(userDimName) == null) {
  27891. // Only if `series.dimensions` is defined in option
  27892. // displayName, will be set, and dimension will be diplayed vertically in
  27893. // tooltip by default.
  27894. resultItem.name = resultItem.displayName = userDimName;
  27895. dataDimNameMap.set(userDimName, i);
  27896. }
  27897. dimDefItem.type != null && (resultItem.type = dimDefItem.type);
  27898. dimDefItem.displayName != null && (resultItem.displayName = dimDefItem.displayName);
  27899. }
  27900. // Set `coordDim` and `coordDimIndex` by `encodeDef` and normalize `encodeDef`.
  27901. encodeDef.each(function (dataDims, coordDim) {
  27902. dataDims = normalizeToArray(dataDims).slice();
  27903. // Note: It is allowed that `dataDims.length` is `0`, e.g., options is
  27904. // `{encode: {x: -1, y: 1}}`. Should not filter anything in
  27905. // this case.
  27906. if (dataDims.length === 1 && !isString(dataDims[0]) && dataDims[0] < 0) {
  27907. encodeDef.set(coordDim, false);
  27908. return;
  27909. }
  27910. var validDataDims = encodeDef.set(coordDim, []);
  27911. each$1(dataDims, function (resultDimIdx, idx) {
  27912. // The input resultDimIdx can be dim name or index.
  27913. isString(resultDimIdx) && (resultDimIdx = dataDimNameMap.get(resultDimIdx));
  27914. if (resultDimIdx != null && resultDimIdx < dimCount) {
  27915. validDataDims[idx] = resultDimIdx;
  27916. applyDim(result[resultDimIdx], coordDim, idx);
  27917. }
  27918. });
  27919. });
  27920. // Apply templetes and default order from `sysDims`.
  27921. var availDimIdx = 0;
  27922. each$1(sysDims, function (sysDimItem, sysDimIndex) {
  27923. var coordDim;
  27924. var sysDimItem;
  27925. var sysDimItemDimsDef;
  27926. var sysDimItemOtherDims;
  27927. if (isString(sysDimItem)) {
  27928. coordDim = sysDimItem;
  27929. sysDimItem = {};
  27930. }
  27931. else {
  27932. coordDim = sysDimItem.name;
  27933. var ordinalMeta = sysDimItem.ordinalMeta;
  27934. sysDimItem.ordinalMeta = null;
  27935. sysDimItem = clone(sysDimItem);
  27936. sysDimItem.ordinalMeta = ordinalMeta;
  27937. // `coordDimIndex` should not be set directly.
  27938. sysDimItemDimsDef = sysDimItem.dimsDef;
  27939. sysDimItemOtherDims = sysDimItem.otherDims;
  27940. sysDimItem.name = sysDimItem.coordDim = sysDimItem.coordDimIndex
  27941. = sysDimItem.dimsDef = sysDimItem.otherDims = null;
  27942. }
  27943. var dataDims = encodeDef.get(coordDim);
  27944. // negative resultDimIdx means no need to mapping.
  27945. if (dataDims === false) {
  27946. return;
  27947. }
  27948. var dataDims = normalizeToArray(dataDims);
  27949. // dimensions provides default dim sequences.
  27950. if (!dataDims.length) {
  27951. for (var i = 0; i < (sysDimItemDimsDef && sysDimItemDimsDef.length || 1); i++) {
  27952. while (availDimIdx < result.length && result[availDimIdx].coordDim != null) {
  27953. availDimIdx++;
  27954. }
  27955. availDimIdx < result.length && dataDims.push(availDimIdx++);
  27956. }
  27957. }
  27958. // Apply templates.
  27959. each$1(dataDims, function (resultDimIdx, coordDimIndex) {
  27960. var resultItem = result[resultDimIdx];
  27961. applyDim(defaults(resultItem, sysDimItem), coordDim, coordDimIndex);
  27962. if (resultItem.name == null && sysDimItemDimsDef) {
  27963. var sysDimItemDimsDefItem = sysDimItemDimsDef[coordDimIndex];
  27964. !isObject$1(sysDimItemDimsDefItem) && (sysDimItemDimsDefItem = {name: sysDimItemDimsDefItem});
  27965. resultItem.name = resultItem.displayName = sysDimItemDimsDefItem.name;
  27966. resultItem.defaultTooltip = sysDimItemDimsDefItem.defaultTooltip;
  27967. }
  27968. // FIXME refactor, currently only used in case: {otherDims: {tooltip: false}}
  27969. sysDimItemOtherDims && defaults(resultItem.otherDims, sysDimItemOtherDims);
  27970. });
  27971. });
  27972. function applyDim(resultItem, coordDim, coordDimIndex) {
  27973. if (OTHER_DIMENSIONS.get(coordDim) != null) {
  27974. resultItem.otherDims[coordDim] = coordDimIndex;
  27975. }
  27976. else {
  27977. resultItem.coordDim = coordDim;
  27978. resultItem.coordDimIndex = coordDimIndex;
  27979. coordDimNameMap.set(coordDim, true);
  27980. }
  27981. }
  27982. // Make sure the first extra dim is 'value'.
  27983. var generateCoord = opt.generateCoord;
  27984. var generateCoordCount = opt.generateCoordCount;
  27985. var fromZero = generateCoordCount != null;
  27986. generateCoordCount = generateCoord ? (generateCoordCount || 1) : 0;
  27987. var extra = generateCoord || 'value';
  27988. // Set dim `name` and other `coordDim` and other props.
  27989. for (var resultDimIdx = 0; resultDimIdx < dimCount; resultDimIdx++) {
  27990. var resultItem = result[resultDimIdx] = result[resultDimIdx] || {};
  27991. var coordDim = resultItem.coordDim;
  27992. if (coordDim == null) {
  27993. resultItem.coordDim = genName(
  27994. extra, coordDimNameMap, fromZero
  27995. );
  27996. resultItem.coordDimIndex = 0;
  27997. if (!generateCoord || generateCoordCount <= 0) {
  27998. resultItem.isExtraCoord = true;
  27999. }
  28000. generateCoordCount--;
  28001. }
  28002. resultItem.name == null && (resultItem.name = genName(
  28003. resultItem.coordDim,
  28004. dataDimNameMap
  28005. ));
  28006. if (resultItem.type == null && guessOrdinal(source, resultDimIdx, resultItem.name)) {
  28007. resultItem.type = 'ordinal';
  28008. }
  28009. }
  28010. return result;
  28011. }
  28012. // ??? TODO
  28013. // Originally detect dimCount by data[0]. Should we
  28014. // optimize it to only by sysDims and dimensions and encode.
  28015. // So only necessary dims will be initialized.
  28016. // But
  28017. // (1) custom series should be considered. where other dims
  28018. // may be visited.
  28019. // (2) sometimes user need to calcualte bubble size or use visualMap
  28020. // on other dimensions besides coordSys needed.
  28021. // So, dims that is not used by system, should be shared in storage?
  28022. function getDimCount(source, sysDims, dimsDef, optDimCount) {
  28023. // Note that the result dimCount should not small than columns count
  28024. // of data, otherwise `dataDimNameMap` checking will be incorrect.
  28025. var dimCount = Math.max(
  28026. source.dimensionsDetectCount || 1,
  28027. sysDims.length,
  28028. dimsDef.length,
  28029. optDimCount || 0
  28030. );
  28031. each$1(sysDims, function (sysDimItem) {
  28032. var sysDimItemDimsDef = sysDimItem.dimsDef;
  28033. sysDimItemDimsDef && (dimCount = Math.max(dimCount, sysDimItemDimsDef.length));
  28034. });
  28035. return dimCount;
  28036. }
  28037. function genName(name, map$$1, fromZero) {
  28038. if (fromZero || map$$1.get(name) != null) {
  28039. var i = 0;
  28040. while (map$$1.get(name + i) != null) {
  28041. i++;
  28042. }
  28043. name += i;
  28044. }
  28045. map$$1.set(name, true);
  28046. return name;
  28047. }
  28048. /*
  28049. * Licensed to the Apache Software Foundation (ASF) under one
  28050. * or more contributor license agreements. See the NOTICE file
  28051. * distributed with this work for additional information
  28052. * regarding copyright ownership. The ASF licenses this file
  28053. * to you under the Apache License, Version 2.0 (the
  28054. * "License"); you may not use this file except in compliance
  28055. * with the License. You may obtain a copy of the License at
  28056. *
  28057. * http://www.apache.org/licenses/LICENSE-2.0
  28058. *
  28059. * Unless required by applicable law or agreed to in writing,
  28060. * software distributed under the License is distributed on an
  28061. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  28062. * KIND, either express or implied. See the License for the
  28063. * specific language governing permissions and limitations
  28064. * under the License.
  28065. */
  28066. /**
  28067. * Substitute `completeDimensions`.
  28068. * `completeDimensions` is to be deprecated.
  28069. */
  28070. /**
  28071. * @param {module:echarts/data/Source|module:echarts/data/List} source or data.
  28072. * @param {Object|Array} [opt]
  28073. * @param {Array.<string|Object>} [opt.coordDimensions=[]]
  28074. * @param {number} [opt.dimensionsCount]
  28075. * @param {string} [opt.generateCoord]
  28076. * @param {string} [opt.generateCoordCount]
  28077. * @param {Array.<string|Object>} [opt.dimensionsDefine=source.dimensionsDefine] Overwrite source define.
  28078. * @param {Object|HashMap} [opt.encodeDefine=source.encodeDefine] Overwrite source define.
  28079. * @return {Array.<Object>} dimensionsInfo
  28080. */
  28081. var createDimensions = function (source, opt) {
  28082. opt = opt || {};
  28083. return completeDimensions(opt.coordDimensions || [], source, {
  28084. dimsDef: opt.dimensionsDefine || source.dimensionsDefine,
  28085. encodeDef: opt.encodeDefine || source.encodeDefine,
  28086. dimCount: opt.dimensionsCount,
  28087. generateCoord: opt.generateCoord,
  28088. generateCoordCount: opt.generateCoordCount
  28089. });
  28090. };
  28091. /*
  28092. * Licensed to the Apache Software Foundation (ASF) under one
  28093. * or more contributor license agreements. See the NOTICE file
  28094. * distributed with this work for additional information
  28095. * regarding copyright ownership. The ASF licenses this file
  28096. * to you under the Apache License, Version 2.0 (the
  28097. * "License"); you may not use this file except in compliance
  28098. * with the License. You may obtain a copy of the License at
  28099. *
  28100. * http://www.apache.org/licenses/LICENSE-2.0
  28101. *
  28102. * Unless required by applicable law or agreed to in writing,
  28103. * software distributed under the License is distributed on an
  28104. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  28105. * KIND, either express or implied. See the License for the
  28106. * specific language governing permissions and limitations
  28107. * under the License.
  28108. */
  28109. /**
  28110. * Note that it is too complicated to support 3d stack by value
  28111. * (have to create two-dimension inverted index), so in 3d case
  28112. * we just support that stacked by index.
  28113. *
  28114. * @param {module:echarts/model/Series} seriesModel
  28115. * @param {Array.<string|Object>} dimensionInfoList The same as the input of <module:echarts/data/List>.
  28116. * The input dimensionInfoList will be modified.
  28117. * @param {Object} [opt]
  28118. * @param {boolean} [opt.stackedCoordDimension=''] Specify a coord dimension if needed.
  28119. * @param {boolean} [opt.byIndex=false]
  28120. * @return {Object} calculationInfo
  28121. * {
  28122. * stackedDimension: string
  28123. * stackedByDimension: string
  28124. * isStackedByIndex: boolean
  28125. * stackedOverDimension: string
  28126. * stackResultDimension: string
  28127. * }
  28128. */
  28129. function enableDataStack(seriesModel, dimensionInfoList, opt) {
  28130. opt = opt || {};
  28131. var byIndex = opt.byIndex;
  28132. var stackedCoordDimension = opt.stackedCoordDimension;
  28133. // Compatibal: when `stack` is set as '', do not stack.
  28134. var mayStack = !!(seriesModel && seriesModel.get('stack'));
  28135. var stackedByDimInfo;
  28136. var stackedDimInfo;
  28137. var stackResultDimension;
  28138. var stackedOverDimension;
  28139. each$1(dimensionInfoList, function (dimensionInfo, index) {
  28140. if (isString(dimensionInfo)) {
  28141. dimensionInfoList[index] = dimensionInfo = {name: dimensionInfo};
  28142. }
  28143. if (mayStack && !dimensionInfo.isExtraCoord) {
  28144. // Find the first ordinal dimension as the stackedByDimInfo.
  28145. if (!byIndex && !stackedByDimInfo && dimensionInfo.ordinalMeta) {
  28146. stackedByDimInfo = dimensionInfo;
  28147. }
  28148. // Find the first stackable dimension as the stackedDimInfo.
  28149. if (!stackedDimInfo
  28150. && dimensionInfo.type !== 'ordinal'
  28151. && dimensionInfo.type !== 'time'
  28152. && (!stackedCoordDimension || stackedCoordDimension === dimensionInfo.coordDim)
  28153. ) {
  28154. stackedDimInfo = dimensionInfo;
  28155. }
  28156. }
  28157. });
  28158. if (stackedDimInfo && !byIndex && !stackedByDimInfo) {
  28159. // Compatible with previous design, value axis (time axis) only stack by index.
  28160. // It may make sense if the user provides elaborately constructed data.
  28161. byIndex = true;
  28162. }
  28163. // Add stack dimension, they can be both calculated by coordinate system in `unionExtent`.
  28164. // That put stack logic in List is for using conveniently in echarts extensions, but it
  28165. // might not be a good way.
  28166. if (stackedDimInfo) {
  28167. // Use a weird name that not duplicated with other names.
  28168. stackResultDimension = '__\0ecstackresult';
  28169. stackedOverDimension = '__\0ecstackedover';
  28170. // Create inverted index to fast query index by value.
  28171. if (stackedByDimInfo) {
  28172. stackedByDimInfo.createInvertedIndices = true;
  28173. }
  28174. var stackedDimCoordDim = stackedDimInfo.coordDim;
  28175. var stackedDimType = stackedDimInfo.type;
  28176. var stackedDimCoordIndex = 0;
  28177. each$1(dimensionInfoList, function (dimensionInfo) {
  28178. if (dimensionInfo.coordDim === stackedDimCoordDim) {
  28179. stackedDimCoordIndex++;
  28180. }
  28181. });
  28182. dimensionInfoList.push({
  28183. name: stackResultDimension,
  28184. coordDim: stackedDimCoordDim,
  28185. coordDimIndex: stackedDimCoordIndex,
  28186. type: stackedDimType,
  28187. isExtraCoord: true,
  28188. isCalculationCoord: true
  28189. });
  28190. stackedDimCoordIndex++;
  28191. dimensionInfoList.push({
  28192. name: stackedOverDimension,
  28193. // This dimension contains stack base (generally, 0), so do not set it as
  28194. // `stackedDimCoordDim` to avoid extent calculation, consider log scale.
  28195. coordDim: stackedOverDimension,
  28196. coordDimIndex: stackedDimCoordIndex,
  28197. type: stackedDimType,
  28198. isExtraCoord: true,
  28199. isCalculationCoord: true
  28200. });
  28201. }
  28202. return {
  28203. stackedDimension: stackedDimInfo && stackedDimInfo.name,
  28204. stackedByDimension: stackedByDimInfo && stackedByDimInfo.name,
  28205. isStackedByIndex: byIndex,
  28206. stackedOverDimension: stackedOverDimension,
  28207. stackResultDimension: stackResultDimension
  28208. };
  28209. }
  28210. /**
  28211. * @param {module:echarts/data/List} data
  28212. * @param {string} stackedDim
  28213. */
  28214. function isDimensionStacked(data, stackedDim /*, stackedByDim*/) {
  28215. // Each single series only maps to one pair of axis. So we do not need to
  28216. // check stackByDim, whatever stacked by a dimension or stacked by index.
  28217. return !!stackedDim && stackedDim === data.getCalculationInfo('stackedDimension');
  28218. // && (
  28219. // stackedByDim != null
  28220. // ? stackedByDim === data.getCalculationInfo('stackedByDimension')
  28221. // : data.getCalculationInfo('isStackedByIndex')
  28222. // );
  28223. }
  28224. /**
  28225. * @param {module:echarts/data/List} data
  28226. * @param {string} targetDim
  28227. * @param {string} [stackedByDim] If not input this parameter, check whether
  28228. * stacked by index.
  28229. * @return {string} dimension
  28230. */
  28231. function getStackedDimension(data, targetDim) {
  28232. return isDimensionStacked(data, targetDim)
  28233. ? data.getCalculationInfo('stackResultDimension')
  28234. : targetDim;
  28235. }
  28236. /*
  28237. * Licensed to the Apache Software Foundation (ASF) under one
  28238. * or more contributor license agreements. See the NOTICE file
  28239. * distributed with this work for additional information
  28240. * regarding copyright ownership. The ASF licenses this file
  28241. * to you under the Apache License, Version 2.0 (the
  28242. * "License"); you may not use this file except in compliance
  28243. * with the License. You may obtain a copy of the License at
  28244. *
  28245. * http://www.apache.org/licenses/LICENSE-2.0
  28246. *
  28247. * Unless required by applicable law or agreed to in writing,
  28248. * software distributed under the License is distributed on an
  28249. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  28250. * KIND, either express or implied. See the License for the
  28251. * specific language governing permissions and limitations
  28252. * under the License.
  28253. */
  28254. /**
  28255. * @param {module:echarts/data/Source|Array} source Or raw data.
  28256. * @param {module:echarts/model/Series} seriesModel
  28257. * @param {Object} [opt]
  28258. * @param {string} [opt.generateCoord]
  28259. */
  28260. function createListFromArray(source, seriesModel, opt) {
  28261. opt = opt || {};
  28262. if (!Source.isInstance(source)) {
  28263. source = Source.seriesDataToSource(source);
  28264. }
  28265. var coordSysName = seriesModel.get('coordinateSystem');
  28266. var registeredCoordSys = CoordinateSystemManager.get(coordSysName);
  28267. var coordSysDefine = getCoordSysDefineBySeries(seriesModel);
  28268. var coordSysDimDefs;
  28269. if (coordSysDefine) {
  28270. coordSysDimDefs = map(coordSysDefine.coordSysDims, function (dim) {
  28271. var dimInfo = {name: dim};
  28272. var axisModel = coordSysDefine.axisMap.get(dim);
  28273. if (axisModel) {
  28274. var axisType = axisModel.get('type');
  28275. dimInfo.type = getDimensionTypeByAxis(axisType);
  28276. // dimInfo.stackable = isStackable(axisType);
  28277. }
  28278. return dimInfo;
  28279. });
  28280. }
  28281. if (!coordSysDimDefs) {
  28282. // Get dimensions from registered coordinate system
  28283. coordSysDimDefs = (registeredCoordSys && (
  28284. registeredCoordSys.getDimensionsInfo
  28285. ? registeredCoordSys.getDimensionsInfo()
  28286. : registeredCoordSys.dimensions.slice()
  28287. )) || ['x', 'y'];
  28288. }
  28289. var dimInfoList = createDimensions(source, {
  28290. coordDimensions: coordSysDimDefs,
  28291. generateCoord: opt.generateCoord
  28292. });
  28293. var firstCategoryDimIndex;
  28294. var hasNameEncode;
  28295. coordSysDefine && each$1(dimInfoList, function (dimInfo, dimIndex) {
  28296. var coordDim = dimInfo.coordDim;
  28297. var categoryAxisModel = coordSysDefine.categoryAxisMap.get(coordDim);
  28298. if (categoryAxisModel) {
  28299. if (firstCategoryDimIndex == null) {
  28300. firstCategoryDimIndex = dimIndex;
  28301. }
  28302. dimInfo.ordinalMeta = categoryAxisModel.getOrdinalMeta();
  28303. }
  28304. if (dimInfo.otherDims.itemName != null) {
  28305. hasNameEncode = true;
  28306. }
  28307. });
  28308. if (!hasNameEncode && firstCategoryDimIndex != null) {
  28309. dimInfoList[firstCategoryDimIndex].otherDims.itemName = 0;
  28310. }
  28311. var stackCalculationInfo = enableDataStack(seriesModel, dimInfoList);
  28312. var list = new List(dimInfoList, seriesModel);
  28313. list.setCalculationInfo(stackCalculationInfo);
  28314. var dimValueGetter = (firstCategoryDimIndex != null && isNeedCompleteOrdinalData(source))
  28315. ? function (itemOpt, dimName, dataIndex, dimIndex) {
  28316. // Use dataIndex as ordinal value in categoryAxis
  28317. return dimIndex === firstCategoryDimIndex
  28318. ? dataIndex
  28319. : this.defaultDimValueGetter(itemOpt, dimName, dataIndex, dimIndex);
  28320. }
  28321. : null;
  28322. list.hasItemOption = false;
  28323. list.initData(source, null, dimValueGetter);
  28324. return list;
  28325. }
  28326. function isNeedCompleteOrdinalData(source) {
  28327. if (source.sourceFormat === SOURCE_FORMAT_ORIGINAL) {
  28328. var sampleItem = firstDataNotNull(source.data || []);
  28329. return sampleItem != null
  28330. && !isArray(getDataItemValue(sampleItem));
  28331. }
  28332. }
  28333. function firstDataNotNull(data) {
  28334. var i = 0;
  28335. while (i < data.length && data[i] == null) {
  28336. i++;
  28337. }
  28338. return data[i];
  28339. }
  28340. /*
  28341. * Licensed to the Apache Software Foundation (ASF) under one
  28342. * or more contributor license agreements. See the NOTICE file
  28343. * distributed with this work for additional information
  28344. * regarding copyright ownership. The ASF licenses this file
  28345. * to you under the Apache License, Version 2.0 (the
  28346. * "License"); you may not use this file except in compliance
  28347. * with the License. You may obtain a copy of the License at
  28348. *
  28349. * http://www.apache.org/licenses/LICENSE-2.0
  28350. *
  28351. * Unless required by applicable law or agreed to in writing,
  28352. * software distributed under the License is distributed on an
  28353. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  28354. * KIND, either express or implied. See the License for the
  28355. * specific language governing permissions and limitations
  28356. * under the License.
  28357. */
  28358. /**
  28359. * // Scale class management
  28360. * @module echarts/scale/Scale
  28361. */
  28362. /**
  28363. * @param {Object} [setting]
  28364. */
  28365. function Scale(setting) {
  28366. this._setting = setting || {};
  28367. /**
  28368. * Extent
  28369. * @type {Array.<number>}
  28370. * @protected
  28371. */
  28372. this._extent = [Infinity, -Infinity];
  28373. /**
  28374. * Step is calculated in adjustExtent
  28375. * @type {Array.<number>}
  28376. * @protected
  28377. */
  28378. this._interval = 0;
  28379. this.init && this.init.apply(this, arguments);
  28380. }
  28381. /**
  28382. * Parse input val to valid inner number.
  28383. * @param {*} val
  28384. * @return {number}
  28385. */
  28386. Scale.prototype.parse = function (val) {
  28387. // Notice: This would be a trap here, If the implementation
  28388. // of this method depends on extent, and this method is used
  28389. // before extent set (like in dataZoom), it would be wrong.
  28390. // Nevertheless, parse does not depend on extent generally.
  28391. return val;
  28392. };
  28393. Scale.prototype.getSetting = function (name) {
  28394. return this._setting[name];
  28395. };
  28396. Scale.prototype.contain = function (val) {
  28397. var extent = this._extent;
  28398. return val >= extent[0] && val <= extent[1];
  28399. };
  28400. /**
  28401. * Normalize value to linear [0, 1], return 0.5 if extent span is 0
  28402. * @param {number} val
  28403. * @return {number}
  28404. */
  28405. Scale.prototype.normalize = function (val) {
  28406. var extent = this._extent;
  28407. if (extent[1] === extent[0]) {
  28408. return 0.5;
  28409. }
  28410. return (val - extent[0]) / (extent[1] - extent[0]);
  28411. };
  28412. /**
  28413. * Scale normalized value
  28414. * @param {number} val
  28415. * @return {number}
  28416. */
  28417. Scale.prototype.scale = function (val) {
  28418. var extent = this._extent;
  28419. return val * (extent[1] - extent[0]) + extent[0];
  28420. };
  28421. /**
  28422. * Set extent from data
  28423. * @param {Array.<number>} other
  28424. */
  28425. Scale.prototype.unionExtent = function (other) {
  28426. var extent = this._extent;
  28427. other[0] < extent[0] && (extent[0] = other[0]);
  28428. other[1] > extent[1] && (extent[1] = other[1]);
  28429. // not setExtent because in log axis it may transformed to power
  28430. // this.setExtent(extent[0], extent[1]);
  28431. };
  28432. /**
  28433. * Set extent from data
  28434. * @param {module:echarts/data/List} data
  28435. * @param {string} dim
  28436. */
  28437. Scale.prototype.unionExtentFromData = function (data, dim) {
  28438. this.unionExtent(data.getApproximateExtent(dim));
  28439. };
  28440. /**
  28441. * Get extent
  28442. * @return {Array.<number>}
  28443. */
  28444. Scale.prototype.getExtent = function () {
  28445. return this._extent.slice();
  28446. };
  28447. /**
  28448. * Set extent
  28449. * @param {number} start
  28450. * @param {number} end
  28451. */
  28452. Scale.prototype.setExtent = function (start, end) {
  28453. var thisExtent = this._extent;
  28454. if (!isNaN(start)) {
  28455. thisExtent[0] = start;
  28456. }
  28457. if (!isNaN(end)) {
  28458. thisExtent[1] = end;
  28459. }
  28460. };
  28461. /**
  28462. * When axis extent depends on data and no data exists,
  28463. * axis ticks should not be drawn, which is named 'blank'.
  28464. */
  28465. Scale.prototype.isBlank = function () {
  28466. return this._isBlank;
  28467. },
  28468. /**
  28469. * When axis extent depends on data and no data exists,
  28470. * axis ticks should not be drawn, which is named 'blank'.
  28471. */
  28472. Scale.prototype.setBlank = function (isBlank) {
  28473. this._isBlank = isBlank;
  28474. };
  28475. /**
  28476. * @abstract
  28477. * @param {*} tick
  28478. * @return {string} label of the tick.
  28479. */
  28480. Scale.prototype.getLabel = null;
  28481. enableClassExtend(Scale);
  28482. enableClassManagement(Scale, {
  28483. registerWhenExtend: true
  28484. });
  28485. /*
  28486. * Licensed to the Apache Software Foundation (ASF) under one
  28487. * or more contributor license agreements. See the NOTICE file
  28488. * distributed with this work for additional information
  28489. * regarding copyright ownership. The ASF licenses this file
  28490. * to you under the Apache License, Version 2.0 (the
  28491. * "License"); you may not use this file except in compliance
  28492. * with the License. You may obtain a copy of the License at
  28493. *
  28494. * http://www.apache.org/licenses/LICENSE-2.0
  28495. *
  28496. * Unless required by applicable law or agreed to in writing,
  28497. * software distributed under the License is distributed on an
  28498. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  28499. * KIND, either express or implied. See the License for the
  28500. * specific language governing permissions and limitations
  28501. * under the License.
  28502. */
  28503. /**
  28504. * @constructor
  28505. * @param {Object} [opt]
  28506. * @param {Object} [opt.categories=[]]
  28507. * @param {Object} [opt.needCollect=false]
  28508. * @param {Object} [opt.deduplication=false]
  28509. */
  28510. function OrdinalMeta(opt) {
  28511. /**
  28512. * @readOnly
  28513. * @type {Array.<string>}
  28514. */
  28515. this.categories = opt.categories || [];
  28516. /**
  28517. * @private
  28518. * @type {boolean}
  28519. */
  28520. this._needCollect = opt.needCollect;
  28521. /**
  28522. * @private
  28523. * @type {boolean}
  28524. */
  28525. this._deduplication = opt.deduplication;
  28526. /**
  28527. * @private
  28528. * @type {boolean}
  28529. */
  28530. this._map;
  28531. }
  28532. /**
  28533. * @param {module:echarts/model/Model} axisModel
  28534. * @return {module:echarts/data/OrdinalMeta}
  28535. */
  28536. OrdinalMeta.createByAxisModel = function (axisModel) {
  28537. var option = axisModel.option;
  28538. var data = option.data;
  28539. var categories = data && map(data, getName);
  28540. return new OrdinalMeta({
  28541. categories: categories,
  28542. needCollect: !categories,
  28543. // deduplication is default in axis.
  28544. deduplication: option.dedplication !== false
  28545. });
  28546. };
  28547. var proto$1 = OrdinalMeta.prototype;
  28548. /**
  28549. * @param {string} category
  28550. * @return {number} ordinal
  28551. */
  28552. proto$1.getOrdinal = function (category) {
  28553. return getOrCreateMap(this).get(category);
  28554. };
  28555. /**
  28556. * @param {*} category
  28557. * @return {number} The ordinal. If not found, return NaN.
  28558. */
  28559. proto$1.parseAndCollect = function (category) {
  28560. var index;
  28561. var needCollect = this._needCollect;
  28562. // The value of category dim can be the index of the given category set.
  28563. // This feature is only supported when !needCollect, because we should
  28564. // consider a common case: a value is 2017, which is a number but is
  28565. // expected to be tread as a category. This case usually happen in dataset,
  28566. // where it happent to be no need of the index feature.
  28567. if (typeof category !== 'string' && !needCollect) {
  28568. return category;
  28569. }
  28570. // Optimize for the scenario:
  28571. // category is ['2012-01-01', '2012-01-02', ...], where the input
  28572. // data has been ensured not duplicate and is large data.
  28573. // Notice, if a dataset dimension provide categroies, usually echarts
  28574. // should remove duplication except user tell echarts dont do that
  28575. // (set axis.deduplication = false), because echarts do not know whether
  28576. // the values in the category dimension has duplication (consider the
  28577. // parallel-aqi example)
  28578. if (needCollect && !this._deduplication) {
  28579. index = this.categories.length;
  28580. this.categories[index] = category;
  28581. return index;
  28582. }
  28583. var map$$1 = getOrCreateMap(this);
  28584. index = map$$1.get(category);
  28585. if (index == null) {
  28586. if (needCollect) {
  28587. index = this.categories.length;
  28588. this.categories[index] = category;
  28589. map$$1.set(category, index);
  28590. }
  28591. else {
  28592. index = NaN;
  28593. }
  28594. }
  28595. return index;
  28596. };
  28597. // Consider big data, do not create map until needed.
  28598. function getOrCreateMap(ordinalMeta) {
  28599. return ordinalMeta._map || (
  28600. ordinalMeta._map = createHashMap(ordinalMeta.categories)
  28601. );
  28602. }
  28603. function getName(obj) {
  28604. if (isObject$1(obj) && obj.value != null) {
  28605. return obj.value;
  28606. }
  28607. else {
  28608. return obj + '';
  28609. }
  28610. }
  28611. /*
  28612. * Licensed to the Apache Software Foundation (ASF) under one
  28613. * or more contributor license agreements. See the NOTICE file
  28614. * distributed with this work for additional information
  28615. * regarding copyright ownership. The ASF licenses this file
  28616. * to you under the Apache License, Version 2.0 (the
  28617. * "License"); you may not use this file except in compliance
  28618. * with the License. You may obtain a copy of the License at
  28619. *
  28620. * http://www.apache.org/licenses/LICENSE-2.0
  28621. *
  28622. * Unless required by applicable law or agreed to in writing,
  28623. * software distributed under the License is distributed on an
  28624. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  28625. * KIND, either express or implied. See the License for the
  28626. * specific language governing permissions and limitations
  28627. * under the License.
  28628. */
  28629. /**
  28630. * Linear continuous scale
  28631. * @module echarts/coord/scale/Ordinal
  28632. *
  28633. * http://en.wikipedia.org/wiki/Level_of_measurement
  28634. */
  28635. // FIXME only one data
  28636. var scaleProto = Scale.prototype;
  28637. var OrdinalScale = Scale.extend({
  28638. type: 'ordinal',
  28639. /**
  28640. * @param {module:echarts/data/OrdianlMeta|Array.<string>} ordinalMeta
  28641. */
  28642. init: function (ordinalMeta, extent) {
  28643. // Caution: Should not use instanceof, consider ec-extensions using
  28644. // import approach to get OrdinalMeta class.
  28645. if (!ordinalMeta || isArray(ordinalMeta)) {
  28646. ordinalMeta = new OrdinalMeta({categories: ordinalMeta});
  28647. }
  28648. this._ordinalMeta = ordinalMeta;
  28649. this._extent = extent || [0, ordinalMeta.categories.length - 1];
  28650. },
  28651. parse: function (val) {
  28652. return typeof val === 'string'
  28653. ? this._ordinalMeta.getOrdinal(val)
  28654. // val might be float.
  28655. : Math.round(val);
  28656. },
  28657. contain: function (rank) {
  28658. rank = this.parse(rank);
  28659. return scaleProto.contain.call(this, rank)
  28660. && this._ordinalMeta.categories[rank] != null;
  28661. },
  28662. /**
  28663. * Normalize given rank or name to linear [0, 1]
  28664. * @param {number|string} [val]
  28665. * @return {number}
  28666. */
  28667. normalize: function (val) {
  28668. return scaleProto.normalize.call(this, this.parse(val));
  28669. },
  28670. scale: function (val) {
  28671. return Math.round(scaleProto.scale.call(this, val));
  28672. },
  28673. /**
  28674. * @return {Array}
  28675. */
  28676. getTicks: function () {
  28677. var ticks = [];
  28678. var extent = this._extent;
  28679. var rank = extent[0];
  28680. while (rank <= extent[1]) {
  28681. ticks.push(rank);
  28682. rank++;
  28683. }
  28684. return ticks;
  28685. },
  28686. /**
  28687. * Get item on rank n
  28688. * @param {number} n
  28689. * @return {string}
  28690. */
  28691. getLabel: function (n) {
  28692. if (!this.isBlank()) {
  28693. // Note that if no data, ordinalMeta.categories is an empty array.
  28694. return this._ordinalMeta.categories[n];
  28695. }
  28696. },
  28697. /**
  28698. * @return {number}
  28699. */
  28700. count: function () {
  28701. return this._extent[1] - this._extent[0] + 1;
  28702. },
  28703. /**
  28704. * @override
  28705. */
  28706. unionExtentFromData: function (data, dim) {
  28707. this.unionExtent(data.getApproximateExtent(dim));
  28708. },
  28709. getOrdinalMeta: function () {
  28710. return this._ordinalMeta;
  28711. },
  28712. niceTicks: noop,
  28713. niceExtent: noop
  28714. });
  28715. /**
  28716. * @return {module:echarts/scale/Time}
  28717. */
  28718. OrdinalScale.create = function () {
  28719. return new OrdinalScale();
  28720. };
  28721. /*
  28722. * Licensed to the Apache Software Foundation (ASF) under one
  28723. * or more contributor license agreements. See the NOTICE file
  28724. * distributed with this work for additional information
  28725. * regarding copyright ownership. The ASF licenses this file
  28726. * to you under the Apache License, Version 2.0 (the
  28727. * "License"); you may not use this file except in compliance
  28728. * with the License. You may obtain a copy of the License at
  28729. *
  28730. * http://www.apache.org/licenses/LICENSE-2.0
  28731. *
  28732. * Unless required by applicable law or agreed to in writing,
  28733. * software distributed under the License is distributed on an
  28734. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  28735. * KIND, either express or implied. See the License for the
  28736. * specific language governing permissions and limitations
  28737. * under the License.
  28738. */
  28739. /**
  28740. * For testable.
  28741. */
  28742. var roundNumber$1 = round$1;
  28743. /**
  28744. * @param {Array.<number>} extent Both extent[0] and extent[1] should be valid number.
  28745. * Should be extent[0] < extent[1].
  28746. * @param {number} splitNumber splitNumber should be >= 1.
  28747. * @param {number} [minInterval]
  28748. * @param {number} [maxInterval]
  28749. * @return {Object} {interval, intervalPrecision, niceTickExtent}
  28750. */
  28751. function intervalScaleNiceTicks(extent, splitNumber, minInterval, maxInterval) {
  28752. var result = {};
  28753. var span = extent[1] - extent[0];
  28754. var interval = result.interval = nice(span / splitNumber, true);
  28755. if (minInterval != null && interval < minInterval) {
  28756. interval = result.interval = minInterval;
  28757. }
  28758. if (maxInterval != null && interval > maxInterval) {
  28759. interval = result.interval = maxInterval;
  28760. }
  28761. // Tow more digital for tick.
  28762. var precision = result.intervalPrecision = getIntervalPrecision(interval);
  28763. // Niced extent inside original extent
  28764. var niceTickExtent = result.niceTickExtent = [
  28765. roundNumber$1(Math.ceil(extent[0] / interval) * interval, precision),
  28766. roundNumber$1(Math.floor(extent[1] / interval) * interval, precision)
  28767. ];
  28768. fixExtent(niceTickExtent, extent);
  28769. return result;
  28770. }
  28771. /**
  28772. * @param {number} interval
  28773. * @return {number} interval precision
  28774. */
  28775. function getIntervalPrecision(interval) {
  28776. // Tow more digital for tick.
  28777. return getPrecisionSafe(interval) + 2;
  28778. }
  28779. function clamp(niceTickExtent, idx, extent) {
  28780. niceTickExtent[idx] = Math.max(Math.min(niceTickExtent[idx], extent[1]), extent[0]);
  28781. }
  28782. // In some cases (e.g., splitNumber is 1), niceTickExtent may be out of extent.
  28783. function fixExtent(niceTickExtent, extent) {
  28784. !isFinite(niceTickExtent[0]) && (niceTickExtent[0] = extent[0]);
  28785. !isFinite(niceTickExtent[1]) && (niceTickExtent[1] = extent[1]);
  28786. clamp(niceTickExtent, 0, extent);
  28787. clamp(niceTickExtent, 1, extent);
  28788. if (niceTickExtent[0] > niceTickExtent[1]) {
  28789. niceTickExtent[0] = niceTickExtent[1];
  28790. }
  28791. }
  28792. function intervalScaleGetTicks(interval, extent, niceTickExtent, intervalPrecision) {
  28793. var ticks = [];
  28794. // If interval is 0, return [];
  28795. if (!interval) {
  28796. return ticks;
  28797. }
  28798. // Consider this case: using dataZoom toolbox, zoom and zoom.
  28799. var safeLimit = 10000;
  28800. if (extent[0] < niceTickExtent[0]) {
  28801. ticks.push(extent[0]);
  28802. }
  28803. var tick = niceTickExtent[0];
  28804. while (tick <= niceTickExtent[1]) {
  28805. ticks.push(tick);
  28806. // Avoid rounding error
  28807. tick = roundNumber$1(tick + interval, intervalPrecision);
  28808. if (tick === ticks[ticks.length - 1]) {
  28809. // Consider out of safe float point, e.g.,
  28810. // -3711126.9907707 + 2e-10 === -3711126.9907707
  28811. break;
  28812. }
  28813. if (ticks.length > safeLimit) {
  28814. return [];
  28815. }
  28816. }
  28817. // Consider this case: the last item of ticks is smaller
  28818. // than niceTickExtent[1] and niceTickExtent[1] === extent[1].
  28819. if (extent[1] > (ticks.length ? ticks[ticks.length - 1] : niceTickExtent[1])) {
  28820. ticks.push(extent[1]);
  28821. }
  28822. return ticks;
  28823. }
  28824. /*
  28825. * Licensed to the Apache Software Foundation (ASF) under one
  28826. * or more contributor license agreements. See the NOTICE file
  28827. * distributed with this work for additional information
  28828. * regarding copyright ownership. The ASF licenses this file
  28829. * to you under the Apache License, Version 2.0 (the
  28830. * "License"); you may not use this file except in compliance
  28831. * with the License. You may obtain a copy of the License at
  28832. *
  28833. * http://www.apache.org/licenses/LICENSE-2.0
  28834. *
  28835. * Unless required by applicable law or agreed to in writing,
  28836. * software distributed under the License is distributed on an
  28837. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  28838. * KIND, either express or implied. See the License for the
  28839. * specific language governing permissions and limitations
  28840. * under the License.
  28841. */
  28842. /**
  28843. * Interval scale
  28844. * @module echarts/scale/Interval
  28845. */
  28846. var roundNumber = round$1;
  28847. /**
  28848. * @alias module:echarts/coord/scale/Interval
  28849. * @constructor
  28850. */
  28851. var IntervalScale = Scale.extend({
  28852. type: 'interval',
  28853. _interval: 0,
  28854. _intervalPrecision: 2,
  28855. setExtent: function (start, end) {
  28856. var thisExtent = this._extent;
  28857. //start,end may be a Number like '25',so...
  28858. if (!isNaN(start)) {
  28859. thisExtent[0] = parseFloat(start);
  28860. }
  28861. if (!isNaN(end)) {
  28862. thisExtent[1] = parseFloat(end);
  28863. }
  28864. },
  28865. unionExtent: function (other) {
  28866. var extent = this._extent;
  28867. other[0] < extent[0] && (extent[0] = other[0]);
  28868. other[1] > extent[1] && (extent[1] = other[1]);
  28869. // unionExtent may called by it's sub classes
  28870. IntervalScale.prototype.setExtent.call(this, extent[0], extent[1]);
  28871. },
  28872. /**
  28873. * Get interval
  28874. */
  28875. getInterval: function () {
  28876. return this._interval;
  28877. },
  28878. /**
  28879. * Set interval
  28880. */
  28881. setInterval: function (interval) {
  28882. this._interval = interval;
  28883. // Dropped auto calculated niceExtent and use user setted extent
  28884. // We assume user wan't to set both interval, min, max to get a better result
  28885. this._niceExtent = this._extent.slice();
  28886. this._intervalPrecision = getIntervalPrecision(interval);
  28887. },
  28888. /**
  28889. * @return {Array.<number>}
  28890. */
  28891. getTicks: function () {
  28892. return intervalScaleGetTicks(
  28893. this._interval, this._extent, this._niceExtent, this._intervalPrecision
  28894. );
  28895. },
  28896. /**
  28897. * @param {number} data
  28898. * @param {Object} [opt]
  28899. * @param {number|string} [opt.precision] If 'auto', use nice presision.
  28900. * @param {boolean} [opt.pad] returns 1.50 but not 1.5 if precision is 2.
  28901. * @return {string}
  28902. */
  28903. getLabel: function (data, opt) {
  28904. if (data == null) {
  28905. return '';
  28906. }
  28907. var precision = opt && opt.precision;
  28908. if (precision == null) {
  28909. precision = getPrecisionSafe(data) || 0;
  28910. }
  28911. else if (precision === 'auto') {
  28912. // Should be more precise then tick.
  28913. precision = this._intervalPrecision;
  28914. }
  28915. // (1) If `precision` is set, 12.005 should be display as '12.00500'.
  28916. // (2) Use roundNumber (toFixed) to avoid scientific notation like '3.5e-7'.
  28917. data = roundNumber(data, precision, true);
  28918. return addCommas(data);
  28919. },
  28920. /**
  28921. * Update interval and extent of intervals for nice ticks
  28922. *
  28923. * @param {number} [splitNumber = 5] Desired number of ticks
  28924. * @param {number} [minInterval]
  28925. * @param {number} [maxInterval]
  28926. */
  28927. niceTicks: function (splitNumber, minInterval, maxInterval) {
  28928. splitNumber = splitNumber || 5;
  28929. var extent = this._extent;
  28930. var span = extent[1] - extent[0];
  28931. if (!isFinite(span)) {
  28932. return;
  28933. }
  28934. // User may set axis min 0 and data are all negative
  28935. // FIXME If it needs to reverse ?
  28936. if (span < 0) {
  28937. span = -span;
  28938. extent.reverse();
  28939. }
  28940. var result = intervalScaleNiceTicks(
  28941. extent, splitNumber, minInterval, maxInterval
  28942. );
  28943. this._intervalPrecision = result.intervalPrecision;
  28944. this._interval = result.interval;
  28945. this._niceExtent = result.niceTickExtent;
  28946. },
  28947. /**
  28948. * Nice extent.
  28949. * @param {Object} opt
  28950. * @param {number} [opt.splitNumber = 5] Given approx tick number
  28951. * @param {boolean} [opt.fixMin=false]
  28952. * @param {boolean} [opt.fixMax=false]
  28953. * @param {boolean} [opt.minInterval]
  28954. * @param {boolean} [opt.maxInterval]
  28955. */
  28956. niceExtent: function (opt) {
  28957. var extent = this._extent;
  28958. // If extent start and end are same, expand them
  28959. if (extent[0] === extent[1]) {
  28960. if (extent[0] !== 0) {
  28961. // Expand extent
  28962. var expandSize = extent[0];
  28963. // In the fowllowing case
  28964. // Axis has been fixed max 100
  28965. // Plus data are all 100 and axis extent are [100, 100].
  28966. // Extend to the both side will cause expanded max is larger than fixed max.
  28967. // So only expand to the smaller side.
  28968. if (!opt.fixMax) {
  28969. extent[1] += expandSize / 2;
  28970. extent[0] -= expandSize / 2;
  28971. }
  28972. else {
  28973. extent[0] -= expandSize / 2;
  28974. }
  28975. }
  28976. else {
  28977. extent[1] = 1;
  28978. }
  28979. }
  28980. var span = extent[1] - extent[0];
  28981. // If there are no data and extent are [Infinity, -Infinity]
  28982. if (!isFinite(span)) {
  28983. extent[0] = 0;
  28984. extent[1] = 1;
  28985. }
  28986. this.niceTicks(opt.splitNumber, opt.minInterval, opt.maxInterval);
  28987. // var extent = this._extent;
  28988. var interval = this._interval;
  28989. if (!opt.fixMin) {
  28990. extent[0] = roundNumber(Math.floor(extent[0] / interval) * interval);
  28991. }
  28992. if (!opt.fixMax) {
  28993. extent[1] = roundNumber(Math.ceil(extent[1] / interval) * interval);
  28994. }
  28995. }
  28996. });
  28997. /**
  28998. * @return {module:echarts/scale/Time}
  28999. */
  29000. IntervalScale.create = function () {
  29001. return new IntervalScale();
  29002. };
  29003. /*
  29004. * Licensed to the Apache Software Foundation (ASF) under one
  29005. * or more contributor license agreements. See the NOTICE file
  29006. * distributed with this work for additional information
  29007. * regarding copyright ownership. The ASF licenses this file
  29008. * to you under the Apache License, Version 2.0 (the
  29009. * "License"); you may not use this file except in compliance
  29010. * with the License. You may obtain a copy of the License at
  29011. *
  29012. * http://www.apache.org/licenses/LICENSE-2.0
  29013. *
  29014. * Unless required by applicable law or agreed to in writing,
  29015. * software distributed under the License is distributed on an
  29016. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  29017. * KIND, either express or implied. See the License for the
  29018. * specific language governing permissions and limitations
  29019. * under the License.
  29020. */
  29021. /* global Float32Array */
  29022. var STACK_PREFIX = '__ec_stack_';
  29023. var LARGE_BAR_MIN_WIDTH = 0.5;
  29024. var LargeArr = typeof Float32Array !== 'undefined' ? Float32Array : Array;
  29025. function getSeriesStackId(seriesModel) {
  29026. return seriesModel.get('stack') || STACK_PREFIX + seriesModel.seriesIndex;
  29027. }
  29028. function getAxisKey(axis) {
  29029. return axis.dim + axis.index;
  29030. }
  29031. /**
  29032. * @param {Object} opt
  29033. * @param {module:echarts/coord/Axis} opt.axis Only support category axis currently.
  29034. * @param {number} opt.count Positive interger.
  29035. * @param {number} [opt.barWidth]
  29036. * @param {number} [opt.barMaxWidth]
  29037. * @param {number} [opt.barGap]
  29038. * @param {number} [opt.barCategoryGap]
  29039. * @return {Object} {width, offset, offsetCenter} If axis.type is not 'category', return undefined.
  29040. */
  29041. function getLayoutOnAxis(opt) {
  29042. var params = [];
  29043. var baseAxis = opt.axis;
  29044. var axisKey = 'axis0';
  29045. if (baseAxis.type !== 'category') {
  29046. return;
  29047. }
  29048. var bandWidth = baseAxis.getBandWidth();
  29049. for (var i = 0; i < opt.count || 0; i++) {
  29050. params.push(defaults({
  29051. bandWidth: bandWidth,
  29052. axisKey: axisKey,
  29053. stackId: STACK_PREFIX + i
  29054. }, opt));
  29055. }
  29056. var widthAndOffsets = doCalBarWidthAndOffset(params);
  29057. var result = [];
  29058. for (var i = 0; i < opt.count; i++) {
  29059. var item = widthAndOffsets[axisKey][STACK_PREFIX + i];
  29060. item.offsetCenter = item.offset + item.width / 2;
  29061. result.push(item);
  29062. }
  29063. return result;
  29064. }
  29065. function prepareLayoutBarSeries(seriesType, ecModel) {
  29066. var seriesModels = [];
  29067. ecModel.eachSeriesByType(seriesType, function (seriesModel) {
  29068. // Check series coordinate, do layout for cartesian2d only
  29069. if (isOnCartesian(seriesModel) && !isInLargeMode(seriesModel)) {
  29070. seriesModels.push(seriesModel);
  29071. }
  29072. });
  29073. return seriesModels;
  29074. }
  29075. function makeColumnLayout(barSeries) {
  29076. var seriesInfoList = [];
  29077. each$1(barSeries, function (seriesModel) {
  29078. var data = seriesModel.getData();
  29079. var cartesian = seriesModel.coordinateSystem;
  29080. var baseAxis = cartesian.getBaseAxis();
  29081. var axisExtent = baseAxis.getExtent();
  29082. var bandWidth = baseAxis.type === 'category'
  29083. ? baseAxis.getBandWidth()
  29084. : (Math.abs(axisExtent[1] - axisExtent[0]) / data.count());
  29085. var barWidth = parsePercent$1(
  29086. seriesModel.get('barWidth'), bandWidth
  29087. );
  29088. var barMaxWidth = parsePercent$1(
  29089. seriesModel.get('barMaxWidth'), bandWidth
  29090. );
  29091. var barGap = seriesModel.get('barGap');
  29092. var barCategoryGap = seriesModel.get('barCategoryGap');
  29093. seriesInfoList.push({
  29094. bandWidth: bandWidth,
  29095. barWidth: barWidth,
  29096. barMaxWidth: barMaxWidth,
  29097. barGap: barGap,
  29098. barCategoryGap: barCategoryGap,
  29099. axisKey: getAxisKey(baseAxis),
  29100. stackId: getSeriesStackId(seriesModel)
  29101. });
  29102. });
  29103. return doCalBarWidthAndOffset(seriesInfoList);
  29104. }
  29105. function doCalBarWidthAndOffset(seriesInfoList) {
  29106. // Columns info on each category axis. Key is cartesian name
  29107. var columnsMap = {};
  29108. each$1(seriesInfoList, function (seriesInfo, idx) {
  29109. var axisKey = seriesInfo.axisKey;
  29110. var bandWidth = seriesInfo.bandWidth;
  29111. var columnsOnAxis = columnsMap[axisKey] || {
  29112. bandWidth: bandWidth,
  29113. remainedWidth: bandWidth,
  29114. autoWidthCount: 0,
  29115. categoryGap: '20%',
  29116. gap: '30%',
  29117. stacks: {}
  29118. };
  29119. var stacks = columnsOnAxis.stacks;
  29120. columnsMap[axisKey] = columnsOnAxis;
  29121. var stackId = seriesInfo.stackId;
  29122. if (!stacks[stackId]) {
  29123. columnsOnAxis.autoWidthCount++;
  29124. }
  29125. stacks[stackId] = stacks[stackId] || {
  29126. width: 0,
  29127. maxWidth: 0
  29128. };
  29129. // Caution: In a single coordinate system, these barGrid attributes
  29130. // will be shared by series. Consider that they have default values,
  29131. // only the attributes set on the last series will work.
  29132. // Do not change this fact unless there will be a break change.
  29133. // TODO
  29134. var barWidth = seriesInfo.barWidth;
  29135. if (barWidth && !stacks[stackId].width) {
  29136. // See #6312, do not restrict width.
  29137. stacks[stackId].width = barWidth;
  29138. barWidth = Math.min(columnsOnAxis.remainedWidth, barWidth);
  29139. columnsOnAxis.remainedWidth -= barWidth;
  29140. }
  29141. var barMaxWidth = seriesInfo.barMaxWidth;
  29142. barMaxWidth && (stacks[stackId].maxWidth = barMaxWidth);
  29143. var barGap = seriesInfo.barGap;
  29144. (barGap != null) && (columnsOnAxis.gap = barGap);
  29145. var barCategoryGap = seriesInfo.barCategoryGap;
  29146. (barCategoryGap != null) && (columnsOnAxis.categoryGap = barCategoryGap);
  29147. });
  29148. var result = {};
  29149. each$1(columnsMap, function (columnsOnAxis, coordSysName) {
  29150. result[coordSysName] = {};
  29151. var stacks = columnsOnAxis.stacks;
  29152. var bandWidth = columnsOnAxis.bandWidth;
  29153. var categoryGap = parsePercent$1(columnsOnAxis.categoryGap, bandWidth);
  29154. var barGapPercent = parsePercent$1(columnsOnAxis.gap, 1);
  29155. var remainedWidth = columnsOnAxis.remainedWidth;
  29156. var autoWidthCount = columnsOnAxis.autoWidthCount;
  29157. var autoWidth = (remainedWidth - categoryGap)
  29158. / (autoWidthCount + (autoWidthCount - 1) * barGapPercent);
  29159. autoWidth = Math.max(autoWidth, 0);
  29160. // Find if any auto calculated bar exceeded maxBarWidth
  29161. each$1(stacks, function (column, stack) {
  29162. var maxWidth = column.maxWidth;
  29163. if (maxWidth && maxWidth < autoWidth) {
  29164. maxWidth = Math.min(maxWidth, remainedWidth);
  29165. if (column.width) {
  29166. maxWidth = Math.min(maxWidth, column.width);
  29167. }
  29168. remainedWidth -= maxWidth;
  29169. column.width = maxWidth;
  29170. autoWidthCount--;
  29171. }
  29172. });
  29173. // Recalculate width again
  29174. autoWidth = (remainedWidth - categoryGap)
  29175. / (autoWidthCount + (autoWidthCount - 1) * barGapPercent);
  29176. autoWidth = Math.max(autoWidth, 0);
  29177. var widthSum = 0;
  29178. var lastColumn;
  29179. each$1(stacks, function (column, idx) {
  29180. if (!column.width) {
  29181. column.width = autoWidth;
  29182. }
  29183. lastColumn = column;
  29184. widthSum += column.width * (1 + barGapPercent);
  29185. });
  29186. if (lastColumn) {
  29187. widthSum -= lastColumn.width * barGapPercent;
  29188. }
  29189. var offset = -widthSum / 2;
  29190. each$1(stacks, function (column, stackId) {
  29191. result[coordSysName][stackId] = result[coordSysName][stackId] || {
  29192. offset: offset,
  29193. width: column.width
  29194. };
  29195. offset += column.width * (1 + barGapPercent);
  29196. });
  29197. });
  29198. return result;
  29199. }
  29200. /**
  29201. * @param {Object} barWidthAndOffset The result of makeColumnLayout
  29202. * @param {module:echarts/coord/Axis} axis
  29203. * @param {module:echarts/model/Series} [seriesModel] If not provided, return all.
  29204. * @return {Object} {stackId: {offset, width}} or {offset, width} if seriesModel provided.
  29205. */
  29206. function retrieveColumnLayout(barWidthAndOffset, axis, seriesModel) {
  29207. if (barWidthAndOffset && axis) {
  29208. var result = barWidthAndOffset[getAxisKey(axis)];
  29209. if (result != null && seriesModel != null) {
  29210. result = result[getSeriesStackId(seriesModel)];
  29211. }
  29212. return result;
  29213. }
  29214. }
  29215. /**
  29216. * @param {string} seriesType
  29217. * @param {module:echarts/model/Global} ecModel
  29218. */
  29219. function layout(seriesType, ecModel) {
  29220. var seriesModels = prepareLayoutBarSeries(seriesType, ecModel);
  29221. var barWidthAndOffset = makeColumnLayout(seriesModels);
  29222. var lastStackCoords = {};
  29223. each$1(seriesModels, function (seriesModel) {
  29224. var data = seriesModel.getData();
  29225. var cartesian = seriesModel.coordinateSystem;
  29226. var baseAxis = cartesian.getBaseAxis();
  29227. var stackId = getSeriesStackId(seriesModel);
  29228. var columnLayoutInfo = barWidthAndOffset[getAxisKey(baseAxis)][stackId];
  29229. var columnOffset = columnLayoutInfo.offset;
  29230. var columnWidth = columnLayoutInfo.width;
  29231. var valueAxis = cartesian.getOtherAxis(baseAxis);
  29232. var barMinHeight = seriesModel.get('barMinHeight') || 0;
  29233. lastStackCoords[stackId] = lastStackCoords[stackId] || [];
  29234. data.setLayout({
  29235. offset: columnOffset,
  29236. size: columnWidth
  29237. });
  29238. var valueDim = data.mapDimension(valueAxis.dim);
  29239. var baseDim = data.mapDimension(baseAxis.dim);
  29240. var stacked = isDimensionStacked(data, valueDim /*, baseDim*/);
  29241. var isValueAxisH = valueAxis.isHorizontal();
  29242. var valueAxisStart = getValueAxisStart(baseAxis, valueAxis, stacked);
  29243. for (var idx = 0, len = data.count(); idx < len; idx++) {
  29244. var value = data.get(valueDim, idx);
  29245. var baseValue = data.get(baseDim, idx);
  29246. // If dataZoom in filteMode: 'empty', the baseValue can be set as NaN in "axisProxy".
  29247. if (isNaN(value) || isNaN(baseValue)) {
  29248. continue;
  29249. }
  29250. var sign = value >= 0 ? 'p' : 'n';
  29251. var baseCoord = valueAxisStart;
  29252. // Because of the barMinHeight, we can not use the value in
  29253. // stackResultDimension directly.
  29254. if (stacked) {
  29255. // Only ordinal axis can be stacked.
  29256. if (!lastStackCoords[stackId][baseValue]) {
  29257. lastStackCoords[stackId][baseValue] = {
  29258. p: valueAxisStart, // Positive stack
  29259. n: valueAxisStart // Negative stack
  29260. };
  29261. }
  29262. // Should also consider #4243
  29263. baseCoord = lastStackCoords[stackId][baseValue][sign];
  29264. }
  29265. var x;
  29266. var y;
  29267. var width;
  29268. var height;
  29269. if (isValueAxisH) {
  29270. var coord = cartesian.dataToPoint([value, baseValue]);
  29271. x = baseCoord;
  29272. y = coord[1] + columnOffset;
  29273. width = coord[0] - valueAxisStart;
  29274. height = columnWidth;
  29275. if (Math.abs(width) < barMinHeight) {
  29276. width = (width < 0 ? -1 : 1) * barMinHeight;
  29277. }
  29278. stacked && (lastStackCoords[stackId][baseValue][sign] += width);
  29279. }
  29280. else {
  29281. var coord = cartesian.dataToPoint([baseValue, value]);
  29282. x = coord[0] + columnOffset;
  29283. y = baseCoord;
  29284. width = columnWidth;
  29285. height = coord[1] - valueAxisStart;
  29286. if (Math.abs(height) < barMinHeight) {
  29287. // Include zero to has a positive bar
  29288. height = (height <= 0 ? -1 : 1) * barMinHeight;
  29289. }
  29290. stacked && (lastStackCoords[stackId][baseValue][sign] += height);
  29291. }
  29292. data.setItemLayout(idx, {
  29293. x: x,
  29294. y: y,
  29295. width: width,
  29296. height: height
  29297. });
  29298. }
  29299. }, this);
  29300. }
  29301. // TODO: Do not support stack in large mode yet.
  29302. var largeLayout = {
  29303. seriesType: 'bar',
  29304. plan: createRenderPlanner(),
  29305. reset: function (seriesModel) {
  29306. if (!isOnCartesian(seriesModel) || !isInLargeMode(seriesModel)) {
  29307. return;
  29308. }
  29309. var data = seriesModel.getData();
  29310. var cartesian = seriesModel.coordinateSystem;
  29311. var baseAxis = cartesian.getBaseAxis();
  29312. var valueAxis = cartesian.getOtherAxis(baseAxis);
  29313. var valueDim = data.mapDimension(valueAxis.dim);
  29314. var baseDim = data.mapDimension(baseAxis.dim);
  29315. var valueAxisHorizontal = valueAxis.isHorizontal();
  29316. var valueDimIdx = valueAxisHorizontal ? 0 : 1;
  29317. var barWidth = retrieveColumnLayout(
  29318. makeColumnLayout([seriesModel]), baseAxis, seriesModel
  29319. ).width;
  29320. if (!(barWidth > LARGE_BAR_MIN_WIDTH)) { // jshint ignore:line
  29321. barWidth = LARGE_BAR_MIN_WIDTH;
  29322. }
  29323. return {progress: progress};
  29324. function progress(params, data) {
  29325. var count = params.count;
  29326. var largePoints = new LargeArr(count * 2);
  29327. var largeDataIndices = new LargeArr(count);
  29328. var dataIndex;
  29329. var coord = [];
  29330. var valuePair = [];
  29331. var pointsOffset = 0;
  29332. var idxOffset = 0;
  29333. while ((dataIndex = params.next()) != null) {
  29334. valuePair[valueDimIdx] = data.get(valueDim, dataIndex);
  29335. valuePair[1 - valueDimIdx] = data.get(baseDim, dataIndex);
  29336. coord = cartesian.dataToPoint(valuePair, null, coord);
  29337. // Data index might not be in order, depends on `progressiveChunkMode`.
  29338. largePoints[pointsOffset++] = coord[0];
  29339. largePoints[pointsOffset++] = coord[1];
  29340. largeDataIndices[idxOffset++] = dataIndex;
  29341. }
  29342. data.setLayout({
  29343. largePoints: largePoints,
  29344. largeDataIndices: largeDataIndices,
  29345. barWidth: barWidth,
  29346. valueAxisStart: getValueAxisStart(baseAxis, valueAxis, false),
  29347. valueAxisHorizontal: valueAxisHorizontal
  29348. });
  29349. }
  29350. }
  29351. };
  29352. function isOnCartesian(seriesModel) {
  29353. return seriesModel.coordinateSystem && seriesModel.coordinateSystem.type === 'cartesian2d';
  29354. }
  29355. function isInLargeMode(seriesModel) {
  29356. return seriesModel.pipelineContext && seriesModel.pipelineContext.large;
  29357. }
  29358. // See cases in `test/bar-start.html` and `#7412`, `#8747`.
  29359. function getValueAxisStart(baseAxis, valueAxis, stacked) {
  29360. var extent = valueAxis.getGlobalExtent();
  29361. var min;
  29362. var max;
  29363. if (extent[0] > extent[1]) {
  29364. min = extent[1];
  29365. max = extent[0];
  29366. }
  29367. else {
  29368. min = extent[0];
  29369. max = extent[1];
  29370. }
  29371. var valueStart = valueAxis.toGlobalCoord(valueAxis.dataToCoord(0));
  29372. valueStart < min && (valueStart = min);
  29373. valueStart > max && (valueStart = max);
  29374. return valueStart;
  29375. }
  29376. /*
  29377. * Licensed to the Apache Software Foundation (ASF) under one
  29378. * or more contributor license agreements. See the NOTICE file
  29379. * distributed with this work for additional information
  29380. * regarding copyright ownership. The ASF licenses this file
  29381. * to you under the Apache License, Version 2.0 (the
  29382. * "License"); you may not use this file except in compliance
  29383. * with the License. You may obtain a copy of the License at
  29384. *
  29385. * http://www.apache.org/licenses/LICENSE-2.0
  29386. *
  29387. * Unless required by applicable law or agreed to in writing,
  29388. * software distributed under the License is distributed on an
  29389. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  29390. * KIND, either express or implied. See the License for the
  29391. * specific language governing permissions and limitations
  29392. * under the License.
  29393. */
  29394. /*
  29395. * A third-party license is embeded for some of the code in this file:
  29396. * The "scaleLevels" was originally copied from "d3.js" with some
  29397. * modifications made for this project.
  29398. * (See more details in the comment on the definition of "scaleLevels" below.)
  29399. * The use of the source code of this file is also subject to the terms
  29400. * and consitions of the license of "d3.js" (BSD-3Clause, see
  29401. * </licenses/LICENSE-d3>).
  29402. */
  29403. // [About UTC and local time zone]:
  29404. // In most cases, `number.parseDate` will treat input data string as local time
  29405. // (except time zone is specified in time string). And `format.formateTime` returns
  29406. // local time by default. option.useUTC is false by default. This design have
  29407. // concidered these common case:
  29408. // (1) Time that is persistent in server is in UTC, but it is needed to be diplayed
  29409. // in local time by default.
  29410. // (2) By default, the input data string (e.g., '2011-01-02') should be displayed
  29411. // as its original time, without any time difference.
  29412. var intervalScaleProto = IntervalScale.prototype;
  29413. var mathCeil = Math.ceil;
  29414. var mathFloor = Math.floor;
  29415. var ONE_SECOND = 1000;
  29416. var ONE_MINUTE = ONE_SECOND * 60;
  29417. var ONE_HOUR = ONE_MINUTE * 60;
  29418. var ONE_DAY = ONE_HOUR * 24;
  29419. // FIXME 公用?
  29420. var bisect = function (a, x, lo, hi) {
  29421. while (lo < hi) {
  29422. var mid = lo + hi >>> 1;
  29423. if (a[mid][1] < x) {
  29424. lo = mid + 1;
  29425. }
  29426. else {
  29427. hi = mid;
  29428. }
  29429. }
  29430. return lo;
  29431. };
  29432. /**
  29433. * @alias module:echarts/coord/scale/Time
  29434. * @constructor
  29435. */
  29436. var TimeScale = IntervalScale.extend({
  29437. type: 'time',
  29438. /**
  29439. * @override
  29440. */
  29441. getLabel: function (val) {
  29442. var stepLvl = this._stepLvl;
  29443. var date = new Date(val);
  29444. return formatTime(stepLvl[0], date, this.getSetting('useUTC'));
  29445. },
  29446. /**
  29447. * @override
  29448. */
  29449. niceExtent: function (opt) {
  29450. var extent = this._extent;
  29451. // If extent start and end are same, expand them
  29452. if (extent[0] === extent[1]) {
  29453. // Expand extent
  29454. extent[0] -= ONE_DAY;
  29455. extent[1] += ONE_DAY;
  29456. }
  29457. // If there are no data and extent are [Infinity, -Infinity]
  29458. if (extent[1] === -Infinity && extent[0] === Infinity) {
  29459. var d = new Date();
  29460. extent[1] = +new Date(d.getFullYear(), d.getMonth(), d.getDate());
  29461. extent[0] = extent[1] - ONE_DAY;
  29462. }
  29463. this.niceTicks(opt.splitNumber, opt.minInterval, opt.maxInterval);
  29464. // var extent = this._extent;
  29465. var interval = this._interval;
  29466. if (!opt.fixMin) {
  29467. extent[0] = round$1(mathFloor(extent[0] / interval) * interval);
  29468. }
  29469. if (!opt.fixMax) {
  29470. extent[1] = round$1(mathCeil(extent[1] / interval) * interval);
  29471. }
  29472. },
  29473. /**
  29474. * @override
  29475. */
  29476. niceTicks: function (approxTickNum, minInterval, maxInterval) {
  29477. approxTickNum = approxTickNum || 10;
  29478. var extent = this._extent;
  29479. var span = extent[1] - extent[0];
  29480. var approxInterval = span / approxTickNum;
  29481. if (minInterval != null && approxInterval < minInterval) {
  29482. approxInterval = minInterval;
  29483. }
  29484. if (maxInterval != null && approxInterval > maxInterval) {
  29485. approxInterval = maxInterval;
  29486. }
  29487. var scaleLevelsLen = scaleLevels.length;
  29488. var idx = bisect(scaleLevels, approxInterval, 0, scaleLevelsLen);
  29489. var level = scaleLevels[Math.min(idx, scaleLevelsLen - 1)];
  29490. var interval = level[1];
  29491. // Same with interval scale if span is much larger than 1 year
  29492. if (level[0] === 'year') {
  29493. var yearSpan = span / interval;
  29494. // From "Nice Numbers for Graph Labels" of Graphic Gems
  29495. // var niceYearSpan = numberUtil.nice(yearSpan, false);
  29496. var yearStep = nice(yearSpan / approxTickNum, true);
  29497. interval *= yearStep;
  29498. }
  29499. var timezoneOffset = this.getSetting('useUTC')
  29500. ? 0 : (new Date(+extent[0] || +extent[1])).getTimezoneOffset() * 60 * 1000;
  29501. var niceExtent = [
  29502. Math.round(mathCeil((extent[0] - timezoneOffset) / interval) * interval + timezoneOffset),
  29503. Math.round(mathFloor((extent[1] - timezoneOffset) / interval) * interval + timezoneOffset)
  29504. ];
  29505. fixExtent(niceExtent, extent);
  29506. this._stepLvl = level;
  29507. // Interval will be used in getTicks
  29508. this._interval = interval;
  29509. this._niceExtent = niceExtent;
  29510. },
  29511. parse: function (val) {
  29512. // val might be float.
  29513. return +parseDate(val);
  29514. }
  29515. });
  29516. each$1(['contain', 'normalize'], function (methodName) {
  29517. TimeScale.prototype[methodName] = function (val) {
  29518. return intervalScaleProto[methodName].call(this, this.parse(val));
  29519. };
  29520. });
  29521. /**
  29522. * This implementation was originally copied from "d3.js"
  29523. * <https://github.com/d3/d3/blob/b516d77fb8566b576088e73410437494717ada26/src/time/scale.js>
  29524. * with some modifications made for this program.
  29525. * See the license statement at the head of this file.
  29526. */
  29527. var scaleLevels = [
  29528. // Format interval
  29529. ['hh:mm:ss', ONE_SECOND], // 1s
  29530. ['hh:mm:ss', ONE_SECOND * 5], // 5s
  29531. ['hh:mm:ss', ONE_SECOND * 10], // 10s
  29532. ['hh:mm:ss', ONE_SECOND * 15], // 15s
  29533. ['hh:mm:ss', ONE_SECOND * 30], // 30s
  29534. ['hh:mm\nMM-dd', ONE_MINUTE], // 1m
  29535. ['hh:mm\nMM-dd', ONE_MINUTE * 5], // 5m
  29536. ['hh:mm\nMM-dd', ONE_MINUTE * 10], // 10m
  29537. ['hh:mm\nMM-dd', ONE_MINUTE * 15], // 15m
  29538. ['hh:mm\nMM-dd', ONE_MINUTE * 30], // 30m
  29539. ['hh:mm\nMM-dd', ONE_HOUR], // 1h
  29540. ['hh:mm\nMM-dd', ONE_HOUR * 2], // 2h
  29541. ['hh:mm\nMM-dd', ONE_HOUR * 6], // 6h
  29542. ['hh:mm\nMM-dd', ONE_HOUR * 12], // 12h
  29543. ['MM-dd\nyyyy', ONE_DAY], // 1d
  29544. ['MM-dd\nyyyy', ONE_DAY * 2], // 2d
  29545. ['MM-dd\nyyyy', ONE_DAY * 3], // 3d
  29546. ['MM-dd\nyyyy', ONE_DAY * 4], // 4d
  29547. ['MM-dd\nyyyy', ONE_DAY * 5], // 5d
  29548. ['MM-dd\nyyyy', ONE_DAY * 6], // 6d
  29549. ['week', ONE_DAY * 7], // 7d
  29550. ['MM-dd\nyyyy', ONE_DAY * 10], // 10d
  29551. ['week', ONE_DAY * 14], // 2w
  29552. ['week', ONE_DAY * 21], // 3w
  29553. ['month', ONE_DAY * 31], // 1M
  29554. ['week', ONE_DAY * 42], // 6w
  29555. ['month', ONE_DAY * 62], // 2M
  29556. ['week', ONE_DAY * 70], // 10w
  29557. ['quarter', ONE_DAY * 95], // 3M
  29558. ['month', ONE_DAY * 31 * 4], // 4M
  29559. ['month', ONE_DAY * 31 * 5], // 5M
  29560. ['half-year', ONE_DAY * 380 / 2], // 6M
  29561. ['month', ONE_DAY * 31 * 8], // 8M
  29562. ['month', ONE_DAY * 31 * 10], // 10M
  29563. ['year', ONE_DAY * 380] // 1Y
  29564. ];
  29565. /**
  29566. * @param {module:echarts/model/Model}
  29567. * @return {module:echarts/scale/Time}
  29568. */
  29569. TimeScale.create = function (model) {
  29570. return new TimeScale({useUTC: model.ecModel.get('useUTC')});
  29571. };
  29572. /*
  29573. * Licensed to the Apache Software Foundation (ASF) under one
  29574. * or more contributor license agreements. See the NOTICE file
  29575. * distributed with this work for additional information
  29576. * regarding copyright ownership. The ASF licenses this file
  29577. * to you under the Apache License, Version 2.0 (the
  29578. * "License"); you may not use this file except in compliance
  29579. * with the License. You may obtain a copy of the License at
  29580. *
  29581. * http://www.apache.org/licenses/LICENSE-2.0
  29582. *
  29583. * Unless required by applicable law or agreed to in writing,
  29584. * software distributed under the License is distributed on an
  29585. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  29586. * KIND, either express or implied. See the License for the
  29587. * specific language governing permissions and limitations
  29588. * under the License.
  29589. */
  29590. /**
  29591. * Log scale
  29592. * @module echarts/scale/Log
  29593. */
  29594. // Use some method of IntervalScale
  29595. var scaleProto$1 = Scale.prototype;
  29596. var intervalScaleProto$1 = IntervalScale.prototype;
  29597. var getPrecisionSafe$1 = getPrecisionSafe;
  29598. var roundingErrorFix = round$1;
  29599. var mathFloor$1 = Math.floor;
  29600. var mathCeil$1 = Math.ceil;
  29601. var mathPow$1 = Math.pow;
  29602. var mathLog = Math.log;
  29603. var LogScale = Scale.extend({
  29604. type: 'log',
  29605. base: 10,
  29606. $constructor: function () {
  29607. Scale.apply(this, arguments);
  29608. this._originalScale = new IntervalScale();
  29609. },
  29610. /**
  29611. * @return {Array.<number>}
  29612. */
  29613. getTicks: function () {
  29614. var originalScale = this._originalScale;
  29615. var extent = this._extent;
  29616. var originalExtent = originalScale.getExtent();
  29617. return map(intervalScaleProto$1.getTicks.call(this), function (val) {
  29618. var powVal = round$1(mathPow$1(this.base, val));
  29619. // Fix #4158
  29620. powVal = (val === extent[0] && originalScale.__fixMin)
  29621. ? fixRoundingError(powVal, originalExtent[0])
  29622. : powVal;
  29623. powVal = (val === extent[1] && originalScale.__fixMax)
  29624. ? fixRoundingError(powVal, originalExtent[1])
  29625. : powVal;
  29626. return powVal;
  29627. }, this);
  29628. },
  29629. /**
  29630. * @param {number} val
  29631. * @return {string}
  29632. */
  29633. getLabel: intervalScaleProto$1.getLabel,
  29634. /**
  29635. * @param {number} val
  29636. * @return {number}
  29637. */
  29638. scale: function (val) {
  29639. val = scaleProto$1.scale.call(this, val);
  29640. return mathPow$1(this.base, val);
  29641. },
  29642. /**
  29643. * @param {number} start
  29644. * @param {number} end
  29645. */
  29646. setExtent: function (start, end) {
  29647. var base = this.base;
  29648. start = mathLog(start) / mathLog(base);
  29649. end = mathLog(end) / mathLog(base);
  29650. intervalScaleProto$1.setExtent.call(this, start, end);
  29651. },
  29652. /**
  29653. * @return {number} end
  29654. */
  29655. getExtent: function () {
  29656. var base = this.base;
  29657. var extent = scaleProto$1.getExtent.call(this);
  29658. extent[0] = mathPow$1(base, extent[0]);
  29659. extent[1] = mathPow$1(base, extent[1]);
  29660. // Fix #4158
  29661. var originalScale = this._originalScale;
  29662. var originalExtent = originalScale.getExtent();
  29663. originalScale.__fixMin && (extent[0] = fixRoundingError(extent[0], originalExtent[0]));
  29664. originalScale.__fixMax && (extent[1] = fixRoundingError(extent[1], originalExtent[1]));
  29665. return extent;
  29666. },
  29667. /**
  29668. * @param {Array.<number>} extent
  29669. */
  29670. unionExtent: function (extent) {
  29671. this._originalScale.unionExtent(extent);
  29672. var base = this.base;
  29673. extent[0] = mathLog(extent[0]) / mathLog(base);
  29674. extent[1] = mathLog(extent[1]) / mathLog(base);
  29675. scaleProto$1.unionExtent.call(this, extent);
  29676. },
  29677. /**
  29678. * @override
  29679. */
  29680. unionExtentFromData: function (data, dim) {
  29681. // TODO
  29682. // filter value that <= 0
  29683. this.unionExtent(data.getApproximateExtent(dim));
  29684. },
  29685. /**
  29686. * Update interval and extent of intervals for nice ticks
  29687. * @param {number} [approxTickNum = 10] Given approx tick number
  29688. */
  29689. niceTicks: function (approxTickNum) {
  29690. approxTickNum = approxTickNum || 10;
  29691. var extent = this._extent;
  29692. var span = extent[1] - extent[0];
  29693. if (span === Infinity || span <= 0) {
  29694. return;
  29695. }
  29696. var interval = quantity(span);
  29697. var err = approxTickNum / span * interval;
  29698. // Filter ticks to get closer to the desired count.
  29699. if (err <= 0.5) {
  29700. interval *= 10;
  29701. }
  29702. // Interval should be integer
  29703. while (!isNaN(interval) && Math.abs(interval) < 1 && Math.abs(interval) > 0) {
  29704. interval *= 10;
  29705. }
  29706. var niceExtent = [
  29707. round$1(mathCeil$1(extent[0] / interval) * interval),
  29708. round$1(mathFloor$1(extent[1] / interval) * interval)
  29709. ];
  29710. this._interval = interval;
  29711. this._niceExtent = niceExtent;
  29712. },
  29713. /**
  29714. * Nice extent.
  29715. * @override
  29716. */
  29717. niceExtent: function (opt) {
  29718. intervalScaleProto$1.niceExtent.call(this, opt);
  29719. var originalScale = this._originalScale;
  29720. originalScale.__fixMin = opt.fixMin;
  29721. originalScale.__fixMax = opt.fixMax;
  29722. }
  29723. });
  29724. each$1(['contain', 'normalize'], function (methodName) {
  29725. LogScale.prototype[methodName] = function (val) {
  29726. val = mathLog(val) / mathLog(this.base);
  29727. return scaleProto$1[methodName].call(this, val);
  29728. };
  29729. });
  29730. LogScale.create = function () {
  29731. return new LogScale();
  29732. };
  29733. function fixRoundingError(val, originalVal) {
  29734. return roundingErrorFix(val, getPrecisionSafe$1(originalVal));
  29735. }
  29736. /*
  29737. * Licensed to the Apache Software Foundation (ASF) under one
  29738. * or more contributor license agreements. See the NOTICE file
  29739. * distributed with this work for additional information
  29740. * regarding copyright ownership. The ASF licenses this file
  29741. * to you under the Apache License, Version 2.0 (the
  29742. * "License"); you may not use this file except in compliance
  29743. * with the License. You may obtain a copy of the License at
  29744. *
  29745. * http://www.apache.org/licenses/LICENSE-2.0
  29746. *
  29747. * Unless required by applicable law or agreed to in writing,
  29748. * software distributed under the License is distributed on an
  29749. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  29750. * KIND, either express or implied. See the License for the
  29751. * specific language governing permissions and limitations
  29752. * under the License.
  29753. */
  29754. /**
  29755. * Get axis scale extent before niced.
  29756. * Item of returned array can only be number (including Infinity and NaN).
  29757. */
  29758. function getScaleExtent(scale, model) {
  29759. var scaleType = scale.type;
  29760. var min = model.getMin();
  29761. var max = model.getMax();
  29762. var fixMin = min != null;
  29763. var fixMax = max != null;
  29764. var originalExtent = scale.getExtent();
  29765. var axisDataLen;
  29766. var boundaryGap;
  29767. var span;
  29768. if (scaleType === 'ordinal') {
  29769. axisDataLen = model.getCategories().length;
  29770. }
  29771. else {
  29772. boundaryGap = model.get('boundaryGap');
  29773. if (!isArray(boundaryGap)) {
  29774. boundaryGap = [boundaryGap || 0, boundaryGap || 0];
  29775. }
  29776. if (typeof boundaryGap[0] === 'boolean') {
  29777. if (__DEV__) {
  29778. console.warn('Boolean type for boundaryGap is only '
  29779. + 'allowed for ordinal axis. Please use string in '
  29780. + 'percentage instead, e.g., "20%". Currently, '
  29781. + 'boundaryGap is set to be 0.');
  29782. }
  29783. boundaryGap = [0, 0];
  29784. }
  29785. boundaryGap[0] = parsePercent$1(boundaryGap[0], 1);
  29786. boundaryGap[1] = parsePercent$1(boundaryGap[1], 1);
  29787. span = (originalExtent[1] - originalExtent[0])
  29788. || Math.abs(originalExtent[0]);
  29789. }
  29790. // Notice: When min/max is not set (that is, when there are null/undefined,
  29791. // which is the most common case), these cases should be ensured:
  29792. // (1) For 'ordinal', show all axis.data.
  29793. // (2) For others:
  29794. // + `boundaryGap` is applied (if min/max set, boundaryGap is
  29795. // disabled).
  29796. // + If `needCrossZero`, min/max should be zero, otherwise, min/max should
  29797. // be the result that originalExtent enlarged by boundaryGap.
  29798. // (3) If no data, it should be ensured that `scale.setBlank` is set.
  29799. // FIXME
  29800. // (1) When min/max is 'dataMin' or 'dataMax', should boundaryGap be able to used?
  29801. // (2) When `needCrossZero` and all data is positive/negative, should it be ensured
  29802. // that the results processed by boundaryGap are positive/negative?
  29803. if (min == null) {
  29804. min = scaleType === 'ordinal'
  29805. ? (axisDataLen ? 0 : NaN)
  29806. : originalExtent[0] - boundaryGap[0] * span;
  29807. }
  29808. if (max == null) {
  29809. max = scaleType === 'ordinal'
  29810. ? (axisDataLen ? axisDataLen - 1 : NaN)
  29811. : originalExtent[1] + boundaryGap[1] * span;
  29812. }
  29813. if (min === 'dataMin') {
  29814. min = originalExtent[0];
  29815. }
  29816. else if (typeof min === 'function') {
  29817. min = min({
  29818. min: originalExtent[0],
  29819. max: originalExtent[1]
  29820. });
  29821. }
  29822. if (max === 'dataMax') {
  29823. max = originalExtent[1];
  29824. }
  29825. else if (typeof max === 'function') {
  29826. max = max({
  29827. min: originalExtent[0],
  29828. max: originalExtent[1]
  29829. });
  29830. }
  29831. (min == null || !isFinite(min)) && (min = NaN);
  29832. (max == null || !isFinite(max)) && (max = NaN);
  29833. scale.setBlank(
  29834. eqNaN(min)
  29835. || eqNaN(max)
  29836. || (scaleType === 'ordinal' && !scale.getOrdinalMeta().categories.length)
  29837. );
  29838. // Evaluate if axis needs cross zero
  29839. if (model.getNeedCrossZero()) {
  29840. // Axis is over zero and min is not set
  29841. if (min > 0 && max > 0 && !fixMin) {
  29842. min = 0;
  29843. }
  29844. // Axis is under zero and max is not set
  29845. if (min < 0 && max < 0 && !fixMax) {
  29846. max = 0;
  29847. }
  29848. }
  29849. // If bars are placed on a base axis of type time or interval account for axis boundary overflow and current axis
  29850. // is base axis
  29851. // FIXME
  29852. // (1) Consider support value axis, where below zero and axis `onZero` should be handled properly.
  29853. // (2) Refactor the logic with `barGrid`. Is it not need to `makeBarWidthAndOffsetInfo` twice with different extent?
  29854. // Should not depend on series type `bar`?
  29855. // (3) Fix that might overlap when using dataZoom.
  29856. // (4) Consider other chart types using `barGrid`?
  29857. // See #6728, #4862, `test/bar-overflow-time-plot.html`
  29858. var ecModel = model.ecModel;
  29859. if (ecModel && (scaleType === 'time' /*|| scaleType === 'interval' */)) {
  29860. var barSeriesModels = prepareLayoutBarSeries('bar', ecModel);
  29861. var isBaseAxisAndHasBarSeries;
  29862. each$1(barSeriesModels, function (seriesModel) {
  29863. isBaseAxisAndHasBarSeries |= seriesModel.getBaseAxis() === model.axis;
  29864. });
  29865. if (isBaseAxisAndHasBarSeries) {
  29866. // Calculate placement of bars on axis
  29867. var barWidthAndOffset = makeColumnLayout(barSeriesModels);
  29868. // Adjust axis min and max to account for overflow
  29869. var adjustedScale = adjustScaleForOverflow(min, max, model, barWidthAndOffset);
  29870. min = adjustedScale.min;
  29871. max = adjustedScale.max;
  29872. }
  29873. }
  29874. return [min, max];
  29875. }
  29876. function adjustScaleForOverflow(min, max, model, barWidthAndOffset) {
  29877. // Get Axis Length
  29878. var axisExtent = model.axis.getExtent();
  29879. var axisLength = axisExtent[1] - axisExtent[0];
  29880. // Get bars on current base axis and calculate min and max overflow
  29881. var barsOnCurrentAxis = retrieveColumnLayout(barWidthAndOffset, model.axis);
  29882. if (barsOnCurrentAxis === undefined) {
  29883. return {min: min, max: max};
  29884. }
  29885. var minOverflow = Infinity;
  29886. each$1(barsOnCurrentAxis, function (item) {
  29887. minOverflow = Math.min(item.offset, minOverflow);
  29888. });
  29889. var maxOverflow = -Infinity;
  29890. each$1(barsOnCurrentAxis, function (item) {
  29891. maxOverflow = Math.max(item.offset + item.width, maxOverflow);
  29892. });
  29893. minOverflow = Math.abs(minOverflow);
  29894. maxOverflow = Math.abs(maxOverflow);
  29895. var totalOverFlow = minOverflow + maxOverflow;
  29896. // Calulate required buffer based on old range and overflow
  29897. var oldRange = max - min;
  29898. var oldRangePercentOfNew = (1 - (minOverflow + maxOverflow) / axisLength);
  29899. var overflowBuffer = ((oldRange / oldRangePercentOfNew) - oldRange);
  29900. max += overflowBuffer * (maxOverflow / totalOverFlow);
  29901. min -= overflowBuffer * (minOverflow / totalOverFlow);
  29902. return {min: min, max: max};
  29903. }
  29904. function niceScaleExtent(scale, model) {
  29905. var extent = getScaleExtent(scale, model);
  29906. var fixMin = model.getMin() != null;
  29907. var fixMax = model.getMax() != null;
  29908. var splitNumber = model.get('splitNumber');
  29909. if (scale.type === 'log') {
  29910. scale.base = model.get('logBase');
  29911. }
  29912. var scaleType = scale.type;
  29913. scale.setExtent(extent[0], extent[1]);
  29914. scale.niceExtent({
  29915. splitNumber: splitNumber,
  29916. fixMin: fixMin,
  29917. fixMax: fixMax,
  29918. minInterval: (scaleType === 'interval' || scaleType === 'time')
  29919. ? model.get('minInterval') : null,
  29920. maxInterval: (scaleType === 'interval' || scaleType === 'time')
  29921. ? model.get('maxInterval') : null
  29922. });
  29923. // If some one specified the min, max. And the default calculated interval
  29924. // is not good enough. He can specify the interval. It is often appeared
  29925. // in angle axis with angle 0 - 360. Interval calculated in interval scale is hard
  29926. // to be 60.
  29927. // FIXME
  29928. var interval = model.get('interval');
  29929. if (interval != null) {
  29930. scale.setInterval && scale.setInterval(interval);
  29931. }
  29932. }
  29933. /**
  29934. * @param {module:echarts/model/Model} model
  29935. * @param {string} [axisType] Default retrieve from model.type
  29936. * @return {module:echarts/scale/*}
  29937. */
  29938. function createScaleByModel(model, axisType) {
  29939. axisType = axisType || model.get('type');
  29940. if (axisType) {
  29941. switch (axisType) {
  29942. // Buildin scale
  29943. case 'category':
  29944. return new OrdinalScale(
  29945. model.getOrdinalMeta
  29946. ? model.getOrdinalMeta()
  29947. : model.getCategories(),
  29948. [Infinity, -Infinity]
  29949. );
  29950. case 'value':
  29951. return new IntervalScale();
  29952. // Extended scale, like time and log
  29953. default:
  29954. return (Scale.getClass(axisType) || IntervalScale).create(model);
  29955. }
  29956. }
  29957. }
  29958. /**
  29959. * Check if the axis corss 0
  29960. */
  29961. function ifAxisCrossZero(axis) {
  29962. var dataExtent = axis.scale.getExtent();
  29963. var min = dataExtent[0];
  29964. var max = dataExtent[1];
  29965. return !((min > 0 && max > 0) || (min < 0 && max < 0));
  29966. }
  29967. /**
  29968. * @param {module:echarts/coord/Axis} axis
  29969. * @return {Function} Label formatter function.
  29970. * param: {number} tickValue,
  29971. * param: {number} idx, the index in all ticks.
  29972. * If category axis, this param is not requied.
  29973. * return: {string} label string.
  29974. */
  29975. function makeLabelFormatter(axis) {
  29976. var labelFormatter = axis.getLabelModel().get('formatter');
  29977. var categoryTickStart = axis.type === 'category' ? axis.scale.getExtent()[0] : null;
  29978. if (typeof labelFormatter === 'string') {
  29979. labelFormatter = (function (tpl) {
  29980. return function (val) {
  29981. // For category axis, get raw value; for numeric axis,
  29982. // get foramtted label like '1,333,444'.
  29983. val = axis.scale.getLabel(val);
  29984. return tpl.replace('{value}', val != null ? val : '');
  29985. };
  29986. })(labelFormatter);
  29987. // Consider empty array
  29988. return labelFormatter;
  29989. }
  29990. else if (typeof labelFormatter === 'function') {
  29991. return function (tickValue, idx) {
  29992. // The original intention of `idx` is "the index of the tick in all ticks".
  29993. // But the previous implementation of category axis do not consider the
  29994. // `axisLabel.interval`, which cause that, for example, the `interval` is
  29995. // `1`, then the ticks "name5", "name7", "name9" are displayed, where the
  29996. // corresponding `idx` are `0`, `2`, `4`, but not `0`, `1`, `2`. So we keep
  29997. // the definition here for back compatibility.
  29998. if (categoryTickStart != null) {
  29999. idx = tickValue - categoryTickStart;
  30000. }
  30001. return labelFormatter(getAxisRawValue(axis, tickValue), idx);
  30002. };
  30003. }
  30004. else {
  30005. return function (tick) {
  30006. return axis.scale.getLabel(tick);
  30007. };
  30008. }
  30009. }
  30010. function getAxisRawValue(axis, value) {
  30011. // In category axis with data zoom, tick is not the original
  30012. // index of axis.data. So tick should not be exposed to user
  30013. // in category axis.
  30014. return axis.type === 'category' ? axis.scale.getLabel(value) : value;
  30015. }
  30016. /**
  30017. * @param {module:echarts/coord/Axis} axis
  30018. * @return {module:zrender/core/BoundingRect} Be null/undefined if no labels.
  30019. */
  30020. function estimateLabelUnionRect(axis) {
  30021. var axisModel = axis.model;
  30022. var scale = axis.scale;
  30023. if (!axisModel.get('axisLabel.show') || scale.isBlank()) {
  30024. return;
  30025. }
  30026. var isCategory = axis.type === 'category';
  30027. var realNumberScaleTicks;
  30028. var tickCount;
  30029. var categoryScaleExtent = scale.getExtent();
  30030. // Optimize for large category data, avoid call `getTicks()`.
  30031. if (isCategory) {
  30032. tickCount = scale.count();
  30033. }
  30034. else {
  30035. realNumberScaleTicks = scale.getTicks();
  30036. tickCount = realNumberScaleTicks.length;
  30037. }
  30038. var axisLabelModel = axis.getLabelModel();
  30039. var labelFormatter = makeLabelFormatter(axis);
  30040. var rect;
  30041. var step = 1;
  30042. // Simple optimization for large amount of labels
  30043. if (tickCount > 40) {
  30044. step = Math.ceil(tickCount / 40);
  30045. }
  30046. for (var i = 0; i < tickCount; i += step) {
  30047. var tickValue = realNumberScaleTicks ? realNumberScaleTicks[i] : categoryScaleExtent[0] + i;
  30048. var label = labelFormatter(tickValue);
  30049. var unrotatedSingleRect = axisLabelModel.getTextRect(label);
  30050. var singleRect = rotateTextRect(unrotatedSingleRect, axisLabelModel.get('rotate') || 0);
  30051. rect ? rect.union(singleRect) : (rect = singleRect);
  30052. }
  30053. return rect;
  30054. }
  30055. function rotateTextRect(textRect, rotate) {
  30056. var rotateRadians = rotate * Math.PI / 180;
  30057. var boundingBox = textRect.plain();
  30058. var beforeWidth = boundingBox.width;
  30059. var beforeHeight = boundingBox.height;
  30060. var afterWidth = beforeWidth * Math.cos(rotateRadians) + beforeHeight * Math.sin(rotateRadians);
  30061. var afterHeight = beforeWidth * Math.sin(rotateRadians) + beforeHeight * Math.cos(rotateRadians);
  30062. var rotatedRect = new BoundingRect(boundingBox.x, boundingBox.y, afterWidth, afterHeight);
  30063. return rotatedRect;
  30064. }
  30065. /**
  30066. * @param {module:echarts/src/model/Model} model axisLabelModel or axisTickModel
  30067. * @return {number|String} Can be null|'auto'|number|function
  30068. */
  30069. function getOptionCategoryInterval(model) {
  30070. var interval = model.get('interval');
  30071. return interval == null ? 'auto' : interval;
  30072. }
  30073. /**
  30074. * Set `categoryInterval` as 0 implicitly indicates that
  30075. * show all labels reguardless of overlap.
  30076. * @param {Object} axis axisModel.axis
  30077. * @return {boolean}
  30078. */
  30079. function shouldShowAllLabels(axis) {
  30080. return axis.type === 'category'
  30081. && getOptionCategoryInterval(axis.getLabelModel()) === 0;
  30082. }
  30083. /*
  30084. * Licensed to the Apache Software Foundation (ASF) under one
  30085. * or more contributor license agreements. See the NOTICE file
  30086. * distributed with this work for additional information
  30087. * regarding copyright ownership. The ASF licenses this file
  30088. * to you under the Apache License, Version 2.0 (the
  30089. * "License"); you may not use this file except in compliance
  30090. * with the License. You may obtain a copy of the License at
  30091. *
  30092. * http://www.apache.org/licenses/LICENSE-2.0
  30093. *
  30094. * Unless required by applicable law or agreed to in writing,
  30095. * software distributed under the License is distributed on an
  30096. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  30097. * KIND, either express or implied. See the License for the
  30098. * specific language governing permissions and limitations
  30099. * under the License.
  30100. */
  30101. // import * as axisHelper from './axisHelper';
  30102. var axisModelCommonMixin = {
  30103. /**
  30104. * @param {boolean} origin
  30105. * @return {number|string} min value or 'dataMin' or null/undefined (means auto) or NaN
  30106. */
  30107. getMin: function (origin) {
  30108. var option = this.option;
  30109. var min = (!origin && option.rangeStart != null)
  30110. ? option.rangeStart : option.min;
  30111. if (this.axis
  30112. && min != null
  30113. && min !== 'dataMin'
  30114. && typeof min !== 'function'
  30115. && !eqNaN(min)
  30116. ) {
  30117. min = this.axis.scale.parse(min);
  30118. }
  30119. return min;
  30120. },
  30121. /**
  30122. * @param {boolean} origin
  30123. * @return {number|string} max value or 'dataMax' or null/undefined (means auto) or NaN
  30124. */
  30125. getMax: function (origin) {
  30126. var option = this.option;
  30127. var max = (!origin && option.rangeEnd != null)
  30128. ? option.rangeEnd : option.max;
  30129. if (this.axis
  30130. && max != null
  30131. && max !== 'dataMax'
  30132. && typeof max !== 'function'
  30133. && !eqNaN(max)
  30134. ) {
  30135. max = this.axis.scale.parse(max);
  30136. }
  30137. return max;
  30138. },
  30139. /**
  30140. * @return {boolean}
  30141. */
  30142. getNeedCrossZero: function () {
  30143. var option = this.option;
  30144. return (option.rangeStart != null || option.rangeEnd != null)
  30145. ? false : !option.scale;
  30146. },
  30147. /**
  30148. * Should be implemented by each axis model if necessary.
  30149. * @return {module:echarts/model/Component} coordinate system model
  30150. */
  30151. getCoordSysModel: noop,
  30152. /**
  30153. * @param {number} rangeStart Can only be finite number or null/undefined or NaN.
  30154. * @param {number} rangeEnd Can only be finite number or null/undefined or NaN.
  30155. */
  30156. setRange: function (rangeStart, rangeEnd) {
  30157. this.option.rangeStart = rangeStart;
  30158. this.option.rangeEnd = rangeEnd;
  30159. },
  30160. /**
  30161. * Reset range
  30162. */
  30163. resetRange: function () {
  30164. // rangeStart and rangeEnd is readonly.
  30165. this.option.rangeStart = this.option.rangeEnd = null;
  30166. }
  30167. };
  30168. /*
  30169. * Licensed to the Apache Software Foundation (ASF) under one
  30170. * or more contributor license agreements. See the NOTICE file
  30171. * distributed with this work for additional information
  30172. * regarding copyright ownership. The ASF licenses this file
  30173. * to you under the Apache License, Version 2.0 (the
  30174. * "License"); you may not use this file except in compliance
  30175. * with the License. You may obtain a copy of the License at
  30176. *
  30177. * http://www.apache.org/licenses/LICENSE-2.0
  30178. *
  30179. * Unless required by applicable law or agreed to in writing,
  30180. * software distributed under the License is distributed on an
  30181. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  30182. * KIND, either express or implied. See the License for the
  30183. * specific language governing permissions and limitations
  30184. * under the License.
  30185. */
  30186. // Symbol factory
  30187. /**
  30188. * Triangle shape
  30189. * @inner
  30190. */
  30191. var Triangle = extendShape({
  30192. type: 'triangle',
  30193. shape: {
  30194. cx: 0,
  30195. cy: 0,
  30196. width: 0,
  30197. height: 0
  30198. },
  30199. buildPath: function (path, shape) {
  30200. var cx = shape.cx;
  30201. var cy = shape.cy;
  30202. var width = shape.width / 2;
  30203. var height = shape.height / 2;
  30204. path.moveTo(cx, cy - height);
  30205. path.lineTo(cx + width, cy + height);
  30206. path.lineTo(cx - width, cy + height);
  30207. path.closePath();
  30208. }
  30209. });
  30210. /**
  30211. * Diamond shape
  30212. * @inner
  30213. */
  30214. var Diamond = extendShape({
  30215. type: 'diamond',
  30216. shape: {
  30217. cx: 0,
  30218. cy: 0,
  30219. width: 0,
  30220. height: 0
  30221. },
  30222. buildPath: function (path, shape) {
  30223. var cx = shape.cx;
  30224. var cy = shape.cy;
  30225. var width = shape.width / 2;
  30226. var height = shape.height / 2;
  30227. path.moveTo(cx, cy - height);
  30228. path.lineTo(cx + width, cy);
  30229. path.lineTo(cx, cy + height);
  30230. path.lineTo(cx - width, cy);
  30231. path.closePath();
  30232. }
  30233. });
  30234. /**
  30235. * Pin shape
  30236. * @inner
  30237. */
  30238. var Pin = extendShape({
  30239. type: 'pin',
  30240. shape: {
  30241. // x, y on the cusp
  30242. x: 0,
  30243. y: 0,
  30244. width: 0,
  30245. height: 0
  30246. },
  30247. buildPath: function (path, shape) {
  30248. var x = shape.x;
  30249. var y = shape.y;
  30250. var w = shape.width / 5 * 3;
  30251. // Height must be larger than width
  30252. var h = Math.max(w, shape.height);
  30253. var r = w / 2;
  30254. // Dist on y with tangent point and circle center
  30255. var dy = r * r / (h - r);
  30256. var cy = y - h + r + dy;
  30257. var angle = Math.asin(dy / r);
  30258. // Dist on x with tangent point and circle center
  30259. var dx = Math.cos(angle) * r;
  30260. var tanX = Math.sin(angle);
  30261. var tanY = Math.cos(angle);
  30262. var cpLen = r * 0.6;
  30263. var cpLen2 = r * 0.7;
  30264. path.moveTo(x - dx, cy + dy);
  30265. path.arc(
  30266. x, cy, r,
  30267. Math.PI - angle,
  30268. Math.PI * 2 + angle
  30269. );
  30270. path.bezierCurveTo(
  30271. x + dx - tanX * cpLen, cy + dy + tanY * cpLen,
  30272. x, y - cpLen2,
  30273. x, y
  30274. );
  30275. path.bezierCurveTo(
  30276. x, y - cpLen2,
  30277. x - dx + tanX * cpLen, cy + dy + tanY * cpLen,
  30278. x - dx, cy + dy
  30279. );
  30280. path.closePath();
  30281. }
  30282. });
  30283. /**
  30284. * Arrow shape
  30285. * @inner
  30286. */
  30287. var Arrow = extendShape({
  30288. type: 'arrow',
  30289. shape: {
  30290. x: 0,
  30291. y: 0,
  30292. width: 0,
  30293. height: 0
  30294. },
  30295. buildPath: function (ctx, shape) {
  30296. var height = shape.height;
  30297. var width = shape.width;
  30298. var x = shape.x;
  30299. var y = shape.y;
  30300. var dx = width / 3 * 2;
  30301. ctx.moveTo(x, y);
  30302. ctx.lineTo(x + dx, y + height);
  30303. ctx.lineTo(x, y + height / 4 * 3);
  30304. ctx.lineTo(x - dx, y + height);
  30305. ctx.lineTo(x, y);
  30306. ctx.closePath();
  30307. }
  30308. });
  30309. /**
  30310. * Map of path contructors
  30311. * @type {Object.<string, module:zrender/graphic/Path>}
  30312. */
  30313. var symbolCtors = {
  30314. line: Line,
  30315. rect: Rect,
  30316. roundRect: Rect,
  30317. square: Rect,
  30318. circle: Circle,
  30319. diamond: Diamond,
  30320. pin: Pin,
  30321. arrow: Arrow,
  30322. triangle: Triangle
  30323. };
  30324. var symbolShapeMakers = {
  30325. line: function (x, y, w, h, shape) {
  30326. // FIXME
  30327. shape.x1 = x;
  30328. shape.y1 = y + h / 2;
  30329. shape.x2 = x + w;
  30330. shape.y2 = y + h / 2;
  30331. },
  30332. rect: function (x, y, w, h, shape) {
  30333. shape.x = x;
  30334. shape.y = y;
  30335. shape.width = w;
  30336. shape.height = h;
  30337. },
  30338. roundRect: function (x, y, w, h, shape) {
  30339. shape.x = x;
  30340. shape.y = y;
  30341. shape.width = w;
  30342. shape.height = h;
  30343. shape.r = Math.min(w, h) / 4;
  30344. },
  30345. square: function (x, y, w, h, shape) {
  30346. var size = Math.min(w, h);
  30347. shape.x = x;
  30348. shape.y = y;
  30349. shape.width = size;
  30350. shape.height = size;
  30351. },
  30352. circle: function (x, y, w, h, shape) {
  30353. // Put circle in the center of square
  30354. shape.cx = x + w / 2;
  30355. shape.cy = y + h / 2;
  30356. shape.r = Math.min(w, h) / 2;
  30357. },
  30358. diamond: function (x, y, w, h, shape) {
  30359. shape.cx = x + w / 2;
  30360. shape.cy = y + h / 2;
  30361. shape.width = w;
  30362. shape.height = h;
  30363. },
  30364. pin: function (x, y, w, h, shape) {
  30365. shape.x = x + w / 2;
  30366. shape.y = y + h / 2;
  30367. shape.width = w;
  30368. shape.height = h;
  30369. },
  30370. arrow: function (x, y, w, h, shape) {
  30371. shape.x = x + w / 2;
  30372. shape.y = y + h / 2;
  30373. shape.width = w;
  30374. shape.height = h;
  30375. },
  30376. triangle: function (x, y, w, h, shape) {
  30377. shape.cx = x + w / 2;
  30378. shape.cy = y + h / 2;
  30379. shape.width = w;
  30380. shape.height = h;
  30381. }
  30382. };
  30383. var symbolBuildProxies = {};
  30384. each$1(symbolCtors, function (Ctor, name) {
  30385. symbolBuildProxies[name] = new Ctor();
  30386. });
  30387. var SymbolClz = extendShape({
  30388. type: 'symbol',
  30389. shape: {
  30390. symbolType: '',
  30391. x: 0,
  30392. y: 0,
  30393. width: 0,
  30394. height: 0
  30395. },
  30396. calculateTextPosition: function (out, style, rect) {
  30397. var res = calculateTextPosition(out, style, rect);
  30398. var shape = this.shape;
  30399. if (shape && shape.symbolType === 'pin' && style.textPosition === 'inside') {
  30400. res.y = rect.y + rect.height * 0.4;
  30401. }
  30402. return res;
  30403. },
  30404. buildPath: function (ctx, shape, inBundle) {
  30405. var symbolType = shape.symbolType;
  30406. if (symbolType !== 'none') {
  30407. var proxySymbol = symbolBuildProxies[symbolType];
  30408. if (!proxySymbol) {
  30409. // Default rect
  30410. symbolType = 'rect';
  30411. proxySymbol = symbolBuildProxies[symbolType];
  30412. }
  30413. symbolShapeMakers[symbolType](
  30414. shape.x, shape.y, shape.width, shape.height, proxySymbol.shape
  30415. );
  30416. proxySymbol.buildPath(ctx, proxySymbol.shape, inBundle);
  30417. }
  30418. }
  30419. });
  30420. // Provide setColor helper method to avoid determine if set the fill or stroke outside
  30421. function symbolPathSetColor(color, innerColor) {
  30422. if (this.type !== 'image') {
  30423. var symbolStyle = this.style;
  30424. var symbolShape = this.shape;
  30425. if (symbolShape && symbolShape.symbolType === 'line') {
  30426. symbolStyle.stroke = color;
  30427. }
  30428. else if (this.__isEmptyBrush) {
  30429. symbolStyle.stroke = color;
  30430. symbolStyle.fill = innerColor || '#fff';
  30431. }
  30432. else {
  30433. // FIXME 判断图形默认是填充还是描边,使用 onlyStroke ?
  30434. symbolStyle.fill && (symbolStyle.fill = color);
  30435. symbolStyle.stroke && (symbolStyle.stroke = color);
  30436. }
  30437. this.dirty(false);
  30438. }
  30439. }
  30440. /**
  30441. * Create a symbol element with given symbol configuration: shape, x, y, width, height, color
  30442. * @param {string} symbolType
  30443. * @param {number} x
  30444. * @param {number} y
  30445. * @param {number} w
  30446. * @param {number} h
  30447. * @param {string} color
  30448. * @param {boolean} [keepAspect=false] whether to keep the ratio of w/h,
  30449. * for path and image only.
  30450. */
  30451. function createSymbol(symbolType, x, y, w, h, color, keepAspect) {
  30452. // TODO Support image object, DynamicImage.
  30453. var isEmpty = symbolType.indexOf('empty') === 0;
  30454. if (isEmpty) {
  30455. symbolType = symbolType.substr(5, 1).toLowerCase() + symbolType.substr(6);
  30456. }
  30457. var symbolPath;
  30458. if (symbolType.indexOf('image://') === 0) {
  30459. symbolPath = makeImage(
  30460. symbolType.slice(8),
  30461. new BoundingRect(x, y, w, h),
  30462. keepAspect ? 'center' : 'cover'
  30463. );
  30464. }
  30465. else if (symbolType.indexOf('path://') === 0) {
  30466. symbolPath = makePath(
  30467. symbolType.slice(7),
  30468. {},
  30469. new BoundingRect(x, y, w, h),
  30470. keepAspect ? 'center' : 'cover'
  30471. );
  30472. }
  30473. else {
  30474. symbolPath = new SymbolClz({
  30475. shape: {
  30476. symbolType: symbolType,
  30477. x: x,
  30478. y: y,
  30479. width: w,
  30480. height: h
  30481. }
  30482. });
  30483. }
  30484. symbolPath.__isEmptyBrush = isEmpty;
  30485. symbolPath.setColor = symbolPathSetColor;
  30486. symbolPath.setColor(color);
  30487. return symbolPath;
  30488. }
  30489. /*
  30490. * Licensed to the Apache Software Foundation (ASF) under one
  30491. * or more contributor license agreements. See the NOTICE file
  30492. * distributed with this work for additional information
  30493. * regarding copyright ownership. The ASF licenses this file
  30494. * to you under the Apache License, Version 2.0 (the
  30495. * "License"); you may not use this file except in compliance
  30496. * with the License. You may obtain a copy of the License at
  30497. *
  30498. * http://www.apache.org/licenses/LICENSE-2.0
  30499. *
  30500. * Unless required by applicable law or agreed to in writing,
  30501. * software distributed under the License is distributed on an
  30502. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  30503. * KIND, either express or implied. See the License for the
  30504. * specific language governing permissions and limitations
  30505. * under the License.
  30506. */
  30507. // import createGraphFromNodeEdge from './chart/helper/createGraphFromNodeEdge';
  30508. /**
  30509. * Create a muti dimension List structure from seriesModel.
  30510. * @param {module:echarts/model/Model} seriesModel
  30511. * @return {module:echarts/data/List} list
  30512. */
  30513. function createList(seriesModel) {
  30514. return createListFromArray(seriesModel.getSource(), seriesModel);
  30515. }
  30516. var dataStack$1 = {
  30517. isDimensionStacked: isDimensionStacked,
  30518. enableDataStack: enableDataStack,
  30519. getStackedDimension: getStackedDimension
  30520. };
  30521. /**
  30522. * Create scale
  30523. * @param {Array.<number>} dataExtent
  30524. * @param {Object|module:echarts/Model} option
  30525. */
  30526. function createScale(dataExtent, option) {
  30527. var axisModel = option;
  30528. if (!Model.isInstance(option)) {
  30529. axisModel = new Model(option);
  30530. mixin(axisModel, axisModelCommonMixin);
  30531. }
  30532. var scale = createScaleByModel(axisModel);
  30533. scale.setExtent(dataExtent[0], dataExtent[1]);
  30534. niceScaleExtent(scale, axisModel);
  30535. return scale;
  30536. }
  30537. /**
  30538. * Mixin common methods to axis model,
  30539. *
  30540. * Inlcude methods
  30541. * `getFormattedLabels() => Array.<string>`
  30542. * `getCategories() => Array.<string>`
  30543. * `getMin(origin: boolean) => number`
  30544. * `getMax(origin: boolean) => number`
  30545. * `getNeedCrossZero() => boolean`
  30546. * `setRange(start: number, end: number)`
  30547. * `resetRange()`
  30548. */
  30549. function mixinAxisModelCommonMethods(Model$$1) {
  30550. mixin(Model$$1, axisModelCommonMixin);
  30551. }
  30552. var helper = (Object.freeze || Object)({
  30553. createList: createList,
  30554. getLayoutRect: getLayoutRect,
  30555. dataStack: dataStack$1,
  30556. createScale: createScale,
  30557. mixinAxisModelCommonMethods: mixinAxisModelCommonMethods,
  30558. completeDimensions: completeDimensions,
  30559. createDimensions: createDimensions,
  30560. createSymbol: createSymbol
  30561. });
  30562. var EPSILON$3 = 1e-8;
  30563. function isAroundEqual$1(a, b) {
  30564. return Math.abs(a - b) < EPSILON$3;
  30565. }
  30566. function contain$1(points, x, y) {
  30567. var w = 0;
  30568. var p = points[0];
  30569. if (!p) {
  30570. return false;
  30571. }
  30572. for (var i = 1; i < points.length; i++) {
  30573. var p2 = points[i];
  30574. w += windingLine(p[0], p[1], p2[0], p2[1], x, y);
  30575. p = p2;
  30576. }
  30577. // Close polygon
  30578. var p0 = points[0];
  30579. if (!isAroundEqual$1(p[0], p0[0]) || !isAroundEqual$1(p[1], p0[1])) {
  30580. w += windingLine(p[0], p[1], p0[0], p0[1], x, y);
  30581. }
  30582. return w !== 0;
  30583. }
  30584. /*
  30585. * Licensed to the Apache Software Foundation (ASF) under one
  30586. * or more contributor license agreements. See the NOTICE file
  30587. * distributed with this work for additional information
  30588. * regarding copyright ownership. The ASF licenses this file
  30589. * to you under the Apache License, Version 2.0 (the
  30590. * "License"); you may not use this file except in compliance
  30591. * with the License. You may obtain a copy of the License at
  30592. *
  30593. * http://www.apache.org/licenses/LICENSE-2.0
  30594. *
  30595. * Unless required by applicable law or agreed to in writing,
  30596. * software distributed under the License is distributed on an
  30597. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  30598. * KIND, either express or implied. See the License for the
  30599. * specific language governing permissions and limitations
  30600. * under the License.
  30601. */
  30602. /**
  30603. * @module echarts/coord/geo/Region
  30604. */
  30605. /**
  30606. * @param {string|Region} name
  30607. * @param {Array} geometries
  30608. * @param {Array.<number>} cp
  30609. */
  30610. function Region(name, geometries, cp) {
  30611. /**
  30612. * @type {string}
  30613. * @readOnly
  30614. */
  30615. this.name = name;
  30616. /**
  30617. * @type {Array.<Array>}
  30618. * @readOnly
  30619. */
  30620. this.geometries = geometries;
  30621. if (!cp) {
  30622. var rect = this.getBoundingRect();
  30623. cp = [
  30624. rect.x + rect.width / 2,
  30625. rect.y + rect.height / 2
  30626. ];
  30627. }
  30628. else {
  30629. cp = [cp[0], cp[1]];
  30630. }
  30631. /**
  30632. * @type {Array.<number>}
  30633. */
  30634. this.center = cp;
  30635. }
  30636. Region.prototype = {
  30637. constructor: Region,
  30638. properties: null,
  30639. /**
  30640. * @return {module:zrender/core/BoundingRect}
  30641. */
  30642. getBoundingRect: function () {
  30643. var rect = this._rect;
  30644. if (rect) {
  30645. return rect;
  30646. }
  30647. var MAX_NUMBER = Number.MAX_VALUE;
  30648. var min$$1 = [MAX_NUMBER, MAX_NUMBER];
  30649. var max$$1 = [-MAX_NUMBER, -MAX_NUMBER];
  30650. var min2 = [];
  30651. var max2 = [];
  30652. var geometries = this.geometries;
  30653. for (var i = 0; i < geometries.length; i++) {
  30654. // Only support polygon
  30655. if (geometries[i].type !== 'polygon') {
  30656. continue;
  30657. }
  30658. // Doesn't consider hole
  30659. var exterior = geometries[i].exterior;
  30660. fromPoints(exterior, min2, max2);
  30661. min(min$$1, min$$1, min2);
  30662. max(max$$1, max$$1, max2);
  30663. }
  30664. // No data
  30665. if (i === 0) {
  30666. min$$1[0] = min$$1[1] = max$$1[0] = max$$1[1] = 0;
  30667. }
  30668. return (this._rect = new BoundingRect(
  30669. min$$1[0], min$$1[1], max$$1[0] - min$$1[0], max$$1[1] - min$$1[1]
  30670. ));
  30671. },
  30672. /**
  30673. * @param {<Array.<number>} coord
  30674. * @return {boolean}
  30675. */
  30676. contain: function (coord) {
  30677. var rect = this.getBoundingRect();
  30678. var geometries = this.geometries;
  30679. if (!rect.contain(coord[0], coord[1])) {
  30680. return false;
  30681. }
  30682. loopGeo: for (var i = 0, len$$1 = geometries.length; i < len$$1; i++) {
  30683. // Only support polygon.
  30684. if (geometries[i].type !== 'polygon') {
  30685. continue;
  30686. }
  30687. var exterior = geometries[i].exterior;
  30688. var interiors = geometries[i].interiors;
  30689. if (contain$1(exterior, coord[0], coord[1])) {
  30690. // Not in the region if point is in the hole.
  30691. for (var k = 0; k < (interiors ? interiors.length : 0); k++) {
  30692. if (contain$1(interiors[k])) {
  30693. continue loopGeo;
  30694. }
  30695. }
  30696. return true;
  30697. }
  30698. }
  30699. return false;
  30700. },
  30701. transformTo: function (x, y, width, height) {
  30702. var rect = this.getBoundingRect();
  30703. var aspect = rect.width / rect.height;
  30704. if (!width) {
  30705. width = aspect * height;
  30706. }
  30707. else if (!height) {
  30708. height = width / aspect;
  30709. }
  30710. var target = new BoundingRect(x, y, width, height);
  30711. var transform = rect.calculateTransform(target);
  30712. var geometries = this.geometries;
  30713. for (var i = 0; i < geometries.length; i++) {
  30714. // Only support polygon.
  30715. if (geometries[i].type !== 'polygon') {
  30716. continue;
  30717. }
  30718. var exterior = geometries[i].exterior;
  30719. var interiors = geometries[i].interiors;
  30720. for (var p = 0; p < exterior.length; p++) {
  30721. applyTransform(exterior[p], exterior[p], transform);
  30722. }
  30723. for (var h = 0; h < (interiors ? interiors.length : 0); h++) {
  30724. for (var p = 0; p < interiors[h].length; p++) {
  30725. applyTransform(interiors[h][p], interiors[h][p], transform);
  30726. }
  30727. }
  30728. }
  30729. rect = this._rect;
  30730. rect.copy(target);
  30731. // Update center
  30732. this.center = [
  30733. rect.x + rect.width / 2,
  30734. rect.y + rect.height / 2
  30735. ];
  30736. },
  30737. cloneShallow: function (name) {
  30738. name == null && (name = this.name);
  30739. var newRegion = new Region(name, this.geometries, this.center);
  30740. newRegion._rect = this._rect;
  30741. newRegion.transformTo = null; // Simply avoid to be called.
  30742. return newRegion;
  30743. }
  30744. };
  30745. /*
  30746. * Licensed to the Apache Software Foundation (ASF) under one
  30747. * or more contributor license agreements. See the NOTICE file
  30748. * distributed with this work for additional information
  30749. * regarding copyright ownership. The ASF licenses this file
  30750. * to you under the Apache License, Version 2.0 (the
  30751. * "License"); you may not use this file except in compliance
  30752. * with the License. You may obtain a copy of the License at
  30753. *
  30754. * http://www.apache.org/licenses/LICENSE-2.0
  30755. *
  30756. * Unless required by applicable law or agreed to in writing,
  30757. * software distributed under the License is distributed on an
  30758. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  30759. * KIND, either express or implied. See the License for the
  30760. * specific language governing permissions and limitations
  30761. * under the License.
  30762. */
  30763. /**
  30764. * Parse and decode geo json
  30765. * @module echarts/coord/geo/parseGeoJson
  30766. */
  30767. function decode(json) {
  30768. if (!json.UTF8Encoding) {
  30769. return json;
  30770. }
  30771. var encodeScale = json.UTF8Scale;
  30772. if (encodeScale == null) {
  30773. encodeScale = 1024;
  30774. }
  30775. var features = json.features;
  30776. for (var f = 0; f < features.length; f++) {
  30777. var feature = features[f];
  30778. var geometry = feature.geometry;
  30779. var coordinates = geometry.coordinates;
  30780. var encodeOffsets = geometry.encodeOffsets;
  30781. for (var c = 0; c < coordinates.length; c++) {
  30782. var coordinate = coordinates[c];
  30783. if (geometry.type === 'Polygon') {
  30784. coordinates[c] = decodePolygon(
  30785. coordinate,
  30786. encodeOffsets[c],
  30787. encodeScale
  30788. );
  30789. }
  30790. else if (geometry.type === 'MultiPolygon') {
  30791. for (var c2 = 0; c2 < coordinate.length; c2++) {
  30792. var polygon = coordinate[c2];
  30793. coordinate[c2] = decodePolygon(
  30794. polygon,
  30795. encodeOffsets[c][c2],
  30796. encodeScale
  30797. );
  30798. }
  30799. }
  30800. }
  30801. }
  30802. // Has been decoded
  30803. json.UTF8Encoding = false;
  30804. return json;
  30805. }
  30806. function decodePolygon(coordinate, encodeOffsets, encodeScale) {
  30807. var result = [];
  30808. var prevX = encodeOffsets[0];
  30809. var prevY = encodeOffsets[1];
  30810. for (var i = 0; i < coordinate.length; i += 2) {
  30811. var x = coordinate.charCodeAt(i) - 64;
  30812. var y = coordinate.charCodeAt(i + 1) - 64;
  30813. // ZigZag decoding
  30814. x = (x >> 1) ^ (-(x & 1));
  30815. y = (y >> 1) ^ (-(y & 1));
  30816. // Delta deocding
  30817. x += prevX;
  30818. y += prevY;
  30819. prevX = x;
  30820. prevY = y;
  30821. // Dequantize
  30822. result.push([x / encodeScale, y / encodeScale]);
  30823. }
  30824. return result;
  30825. }
  30826. /**
  30827. * @alias module:echarts/coord/geo/parseGeoJson
  30828. * @param {Object} geoJson
  30829. * @return {module:zrender/container/Group}
  30830. */
  30831. var parseGeoJson$1 = function (geoJson) {
  30832. decode(geoJson);
  30833. return map(filter(geoJson.features, function (featureObj) {
  30834. // Output of mapshaper may have geometry null
  30835. return featureObj.geometry
  30836. && featureObj.properties
  30837. && featureObj.geometry.coordinates.length > 0;
  30838. }), function (featureObj) {
  30839. var properties = featureObj.properties;
  30840. var geo = featureObj.geometry;
  30841. var coordinates = geo.coordinates;
  30842. var geometries = [];
  30843. if (geo.type === 'Polygon') {
  30844. geometries.push({
  30845. type: 'polygon',
  30846. // According to the GeoJSON specification.
  30847. // First must be exterior, and the rest are all interior(holes).
  30848. exterior: coordinates[0],
  30849. interiors: coordinates.slice(1)
  30850. });
  30851. }
  30852. if (geo.type === 'MultiPolygon') {
  30853. each$1(coordinates, function (item) {
  30854. if (item[0]) {
  30855. geometries.push({
  30856. type: 'polygon',
  30857. exterior: item[0],
  30858. interiors: item.slice(1)
  30859. });
  30860. }
  30861. });
  30862. }
  30863. var region = new Region(
  30864. properties.name,
  30865. geometries,
  30866. properties.cp
  30867. );
  30868. region.properties = properties;
  30869. return region;
  30870. });
  30871. };
  30872. /*
  30873. * Licensed to the Apache Software Foundation (ASF) under one
  30874. * or more contributor license agreements. See the NOTICE file
  30875. * distributed with this work for additional information
  30876. * regarding copyright ownership. The ASF licenses this file
  30877. * to you under the Apache License, Version 2.0 (the
  30878. * "License"); you may not use this file except in compliance
  30879. * with the License. You may obtain a copy of the License at
  30880. *
  30881. * http://www.apache.org/licenses/LICENSE-2.0
  30882. *
  30883. * Unless required by applicable law or agreed to in writing,
  30884. * software distributed under the License is distributed on an
  30885. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  30886. * KIND, either express or implied. See the License for the
  30887. * specific language governing permissions and limitations
  30888. * under the License.
  30889. */
  30890. var inner$6 = makeInner();
  30891. /**
  30892. * @param {module:echats/coord/Axis} axis
  30893. * @return {Object} {
  30894. * labels: [{
  30895. * formattedLabel: string,
  30896. * rawLabel: string,
  30897. * tickValue: number
  30898. * }, ...],
  30899. * labelCategoryInterval: number
  30900. * }
  30901. */
  30902. function createAxisLabels(axis) {
  30903. // Only ordinal scale support tick interval
  30904. return axis.type === 'category'
  30905. ? makeCategoryLabels(axis)
  30906. : makeRealNumberLabels(axis);
  30907. }
  30908. /**
  30909. * @param {module:echats/coord/Axis} axis
  30910. * @param {module:echarts/model/Model} tickModel For example, can be axisTick, splitLine, splitArea.
  30911. * @return {Object} {
  30912. * ticks: Array.<number>
  30913. * tickCategoryInterval: number
  30914. * }
  30915. */
  30916. function createAxisTicks(axis, tickModel) {
  30917. // Only ordinal scale support tick interval
  30918. return axis.type === 'category'
  30919. ? makeCategoryTicks(axis, tickModel)
  30920. : {ticks: axis.scale.getTicks()};
  30921. }
  30922. function makeCategoryLabels(axis) {
  30923. var labelModel = axis.getLabelModel();
  30924. var result = makeCategoryLabelsActually(axis, labelModel);
  30925. return (!labelModel.get('show') || axis.scale.isBlank())
  30926. ? {labels: [], labelCategoryInterval: result.labelCategoryInterval}
  30927. : result;
  30928. }
  30929. function makeCategoryLabelsActually(axis, labelModel) {
  30930. var labelsCache = getListCache(axis, 'labels');
  30931. var optionLabelInterval = getOptionCategoryInterval(labelModel);
  30932. var result = listCacheGet(labelsCache, optionLabelInterval);
  30933. if (result) {
  30934. return result;
  30935. }
  30936. var labels;
  30937. var numericLabelInterval;
  30938. if (isFunction$1(optionLabelInterval)) {
  30939. labels = makeLabelsByCustomizedCategoryInterval(axis, optionLabelInterval);
  30940. }
  30941. else {
  30942. numericLabelInterval = optionLabelInterval === 'auto'
  30943. ? makeAutoCategoryInterval(axis) : optionLabelInterval;
  30944. labels = makeLabelsByNumericCategoryInterval(axis, numericLabelInterval);
  30945. }
  30946. // Cache to avoid calling interval function repeatly.
  30947. return listCacheSet(labelsCache, optionLabelInterval, {
  30948. labels: labels, labelCategoryInterval: numericLabelInterval
  30949. });
  30950. }
  30951. function makeCategoryTicks(axis, tickModel) {
  30952. var ticksCache = getListCache(axis, 'ticks');
  30953. var optionTickInterval = getOptionCategoryInterval(tickModel);
  30954. var result = listCacheGet(ticksCache, optionTickInterval);
  30955. if (result) {
  30956. return result;
  30957. }
  30958. var ticks;
  30959. var tickCategoryInterval;
  30960. // Optimize for the case that large category data and no label displayed,
  30961. // we should not return all ticks.
  30962. if (!tickModel.get('show') || axis.scale.isBlank()) {
  30963. ticks = [];
  30964. }
  30965. if (isFunction$1(optionTickInterval)) {
  30966. ticks = makeLabelsByCustomizedCategoryInterval(axis, optionTickInterval, true);
  30967. }
  30968. // Always use label interval by default despite label show. Consider this
  30969. // scenario, Use multiple grid with the xAxis sync, and only one xAxis shows
  30970. // labels. `splitLine` and `axisTick` should be consistent in this case.
  30971. else if (optionTickInterval === 'auto') {
  30972. var labelsResult = makeCategoryLabelsActually(axis, axis.getLabelModel());
  30973. tickCategoryInterval = labelsResult.labelCategoryInterval;
  30974. ticks = map(labelsResult.labels, function (labelItem) {
  30975. return labelItem.tickValue;
  30976. });
  30977. }
  30978. else {
  30979. tickCategoryInterval = optionTickInterval;
  30980. ticks = makeLabelsByNumericCategoryInterval(axis, tickCategoryInterval, true);
  30981. }
  30982. // Cache to avoid calling interval function repeatly.
  30983. return listCacheSet(ticksCache, optionTickInterval, {
  30984. ticks: ticks, tickCategoryInterval: tickCategoryInterval
  30985. });
  30986. }
  30987. function makeRealNumberLabels(axis) {
  30988. var ticks = axis.scale.getTicks();
  30989. var labelFormatter = makeLabelFormatter(axis);
  30990. return {
  30991. labels: map(ticks, function (tickValue, idx) {
  30992. return {
  30993. formattedLabel: labelFormatter(tickValue, idx),
  30994. rawLabel: axis.scale.getLabel(tickValue),
  30995. tickValue: tickValue
  30996. };
  30997. })
  30998. };
  30999. }
  31000. // Large category data calculation is performence sensitive, and ticks and label
  31001. // probably be fetched by multiple times. So we cache the result.
  31002. // axis is created each time during a ec process, so we do not need to clear cache.
  31003. function getListCache(axis, prop) {
  31004. // Because key can be funciton, and cache size always be small, we use array cache.
  31005. return inner$6(axis)[prop] || (inner$6(axis)[prop] = []);
  31006. }
  31007. function listCacheGet(cache, key) {
  31008. for (var i = 0; i < cache.length; i++) {
  31009. if (cache[i].key === key) {
  31010. return cache[i].value;
  31011. }
  31012. }
  31013. }
  31014. function listCacheSet(cache, key, value) {
  31015. cache.push({key: key, value: value});
  31016. return value;
  31017. }
  31018. function makeAutoCategoryInterval(axis) {
  31019. var result = inner$6(axis).autoInterval;
  31020. return result != null
  31021. ? result
  31022. : (inner$6(axis).autoInterval = axis.calculateCategoryInterval());
  31023. }
  31024. /**
  31025. * Calculate interval for category axis ticks and labels.
  31026. * To get precise result, at least one of `getRotate` and `isHorizontal`
  31027. * should be implemented in axis.
  31028. */
  31029. function calculateCategoryInterval(axis) {
  31030. var params = fetchAutoCategoryIntervalCalculationParams(axis);
  31031. var labelFormatter = makeLabelFormatter(axis);
  31032. var rotation = (params.axisRotate - params.labelRotate) / 180 * Math.PI;
  31033. var ordinalScale = axis.scale;
  31034. var ordinalExtent = ordinalScale.getExtent();
  31035. // Providing this method is for optimization:
  31036. // avoid generating a long array by `getTicks`
  31037. // in large category data case.
  31038. var tickCount = ordinalScale.count();
  31039. if (ordinalExtent[1] - ordinalExtent[0] < 1) {
  31040. return 0;
  31041. }
  31042. var step = 1;
  31043. // Simple optimization. Empirical value: tick count should less than 40.
  31044. if (tickCount > 40) {
  31045. step = Math.max(1, Math.floor(tickCount / 40));
  31046. }
  31047. var tickValue = ordinalExtent[0];
  31048. var unitSpan = axis.dataToCoord(tickValue + 1) - axis.dataToCoord(tickValue);
  31049. var unitW = Math.abs(unitSpan * Math.cos(rotation));
  31050. var unitH = Math.abs(unitSpan * Math.sin(rotation));
  31051. var maxW = 0;
  31052. var maxH = 0;
  31053. // Caution: Performance sensitive for large category data.
  31054. // Consider dataZoom, we should make appropriate step to avoid O(n) loop.
  31055. for (; tickValue <= ordinalExtent[1]; tickValue += step) {
  31056. var width = 0;
  31057. var height = 0;
  31058. // Not precise, do not consider align and vertical align
  31059. // and each distance from axis line yet.
  31060. var rect = getBoundingRect(
  31061. labelFormatter(tickValue), params.font, 'center', 'top'
  31062. );
  31063. // Magic number
  31064. width = rect.width * 1.3;
  31065. height = rect.height * 1.3;
  31066. // Min size, void long loop.
  31067. maxW = Math.max(maxW, width, 7);
  31068. maxH = Math.max(maxH, height, 7);
  31069. }
  31070. var dw = maxW / unitW;
  31071. var dh = maxH / unitH;
  31072. // 0/0 is NaN, 1/0 is Infinity.
  31073. isNaN(dw) && (dw = Infinity);
  31074. isNaN(dh) && (dh = Infinity);
  31075. var interval = Math.max(0, Math.floor(Math.min(dw, dh)));
  31076. var cache = inner$6(axis.model);
  31077. var lastAutoInterval = cache.lastAutoInterval;
  31078. var lastTickCount = cache.lastTickCount;
  31079. // Use cache to keep interval stable while moving zoom window,
  31080. // otherwise the calculated interval might jitter when the zoom
  31081. // window size is close to the interval-changing size.
  31082. if (lastAutoInterval != null
  31083. && lastTickCount != null
  31084. && Math.abs(lastAutoInterval - interval) <= 1
  31085. && Math.abs(lastTickCount - tickCount) <= 1
  31086. // Always choose the bigger one, otherwise the critical
  31087. // point is not the same when zooming in or zooming out.
  31088. && lastAutoInterval > interval
  31089. ) {
  31090. interval = lastAutoInterval;
  31091. }
  31092. // Only update cache if cache not used, otherwise the
  31093. // changing of interval is too insensitive.
  31094. else {
  31095. cache.lastTickCount = tickCount;
  31096. cache.lastAutoInterval = interval;
  31097. }
  31098. return interval;
  31099. }
  31100. function fetchAutoCategoryIntervalCalculationParams(axis) {
  31101. var labelModel = axis.getLabelModel();
  31102. return {
  31103. axisRotate: axis.getRotate
  31104. ? axis.getRotate()
  31105. : (axis.isHorizontal && !axis.isHorizontal())
  31106. ? 90
  31107. : 0,
  31108. labelRotate: labelModel.get('rotate') || 0,
  31109. font: labelModel.getFont()
  31110. };
  31111. }
  31112. function makeLabelsByNumericCategoryInterval(axis, categoryInterval, onlyTick) {
  31113. var labelFormatter = makeLabelFormatter(axis);
  31114. var ordinalScale = axis.scale;
  31115. var ordinalExtent = ordinalScale.getExtent();
  31116. var labelModel = axis.getLabelModel();
  31117. var result = [];
  31118. // TODO: axisType: ordinalTime, pick the tick from each month/day/year/...
  31119. var step = Math.max((categoryInterval || 0) + 1, 1);
  31120. var startTick = ordinalExtent[0];
  31121. var tickCount = ordinalScale.count();
  31122. // Calculate start tick based on zero if possible to keep label consistent
  31123. // while zooming and moving while interval > 0. Otherwise the selection
  31124. // of displayable ticks and symbols probably keep changing.
  31125. // 3 is empirical value.
  31126. if (startTick !== 0 && step > 1 && tickCount / step > 2) {
  31127. startTick = Math.round(Math.ceil(startTick / step) * step);
  31128. }
  31129. // (1) Only add min max label here but leave overlap checking
  31130. // to render stage, which also ensure the returned list
  31131. // suitable for splitLine and splitArea rendering.
  31132. // (2) Scales except category always contain min max label so
  31133. // do not need to perform this process.
  31134. var showAllLabel = shouldShowAllLabels(axis);
  31135. var includeMinLabel = labelModel.get('showMinLabel') || showAllLabel;
  31136. var includeMaxLabel = labelModel.get('showMaxLabel') || showAllLabel;
  31137. if (includeMinLabel && startTick !== ordinalExtent[0]) {
  31138. addItem(ordinalExtent[0]);
  31139. }
  31140. // Optimize: avoid generating large array by `ordinalScale.getTicks()`.
  31141. var tickValue = startTick;
  31142. for (; tickValue <= ordinalExtent[1]; tickValue += step) {
  31143. addItem(tickValue);
  31144. }
  31145. if (includeMaxLabel && tickValue - step !== ordinalExtent[1]) {
  31146. addItem(ordinalExtent[1]);
  31147. }
  31148. function addItem(tVal) {
  31149. result.push(onlyTick
  31150. ? tVal
  31151. : {
  31152. formattedLabel: labelFormatter(tVal),
  31153. rawLabel: ordinalScale.getLabel(tVal),
  31154. tickValue: tVal
  31155. }
  31156. );
  31157. }
  31158. return result;
  31159. }
  31160. // When interval is function, the result `false` means ignore the tick.
  31161. // It is time consuming for large category data.
  31162. function makeLabelsByCustomizedCategoryInterval(axis, categoryInterval, onlyTick) {
  31163. var ordinalScale = axis.scale;
  31164. var labelFormatter = makeLabelFormatter(axis);
  31165. var result = [];
  31166. each$1(ordinalScale.getTicks(), function (tickValue) {
  31167. var rawLabel = ordinalScale.getLabel(tickValue);
  31168. if (categoryInterval(tickValue, rawLabel)) {
  31169. result.push(onlyTick
  31170. ? tickValue
  31171. : {
  31172. formattedLabel: labelFormatter(tickValue),
  31173. rawLabel: rawLabel,
  31174. tickValue: tickValue
  31175. }
  31176. );
  31177. }
  31178. });
  31179. return result;
  31180. }
  31181. /*
  31182. * Licensed to the Apache Software Foundation (ASF) under one
  31183. * or more contributor license agreements. See the NOTICE file
  31184. * distributed with this work for additional information
  31185. * regarding copyright ownership. The ASF licenses this file
  31186. * to you under the Apache License, Version 2.0 (the
  31187. * "License"); you may not use this file except in compliance
  31188. * with the License. You may obtain a copy of the License at
  31189. *
  31190. * http://www.apache.org/licenses/LICENSE-2.0
  31191. *
  31192. * Unless required by applicable law or agreed to in writing,
  31193. * software distributed under the License is distributed on an
  31194. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  31195. * KIND, either express or implied. See the License for the
  31196. * specific language governing permissions and limitations
  31197. * under the License.
  31198. */
  31199. var NORMALIZED_EXTENT = [0, 1];
  31200. /**
  31201. * Base class of Axis.
  31202. * @constructor
  31203. */
  31204. var Axis = function (dim, scale, extent) {
  31205. /**
  31206. * Axis dimension. Such as 'x', 'y', 'z', 'angle', 'radius'.
  31207. * @type {string}
  31208. */
  31209. this.dim = dim;
  31210. /**
  31211. * Axis scale
  31212. * @type {module:echarts/coord/scale/*}
  31213. */
  31214. this.scale = scale;
  31215. /**
  31216. * @type {Array.<number>}
  31217. * @private
  31218. */
  31219. this._extent = extent || [0, 0];
  31220. /**
  31221. * @type {boolean}
  31222. */
  31223. this.inverse = false;
  31224. /**
  31225. * Usually true when axis has a ordinal scale
  31226. * @type {boolean}
  31227. */
  31228. this.onBand = false;
  31229. };
  31230. Axis.prototype = {
  31231. constructor: Axis,
  31232. /**
  31233. * If axis extent contain given coord
  31234. * @param {number} coord
  31235. * @return {boolean}
  31236. */
  31237. contain: function (coord) {
  31238. var extent = this._extent;
  31239. var min = Math.min(extent[0], extent[1]);
  31240. var max = Math.max(extent[0], extent[1]);
  31241. return coord >= min && coord <= max;
  31242. },
  31243. /**
  31244. * If axis extent contain given data
  31245. * @param {number} data
  31246. * @return {boolean}
  31247. */
  31248. containData: function (data) {
  31249. return this.contain(this.dataToCoord(data));
  31250. },
  31251. /**
  31252. * Get coord extent.
  31253. * @return {Array.<number>}
  31254. */
  31255. getExtent: function () {
  31256. return this._extent.slice();
  31257. },
  31258. /**
  31259. * Get precision used for formatting
  31260. * @param {Array.<number>} [dataExtent]
  31261. * @return {number}
  31262. */
  31263. getPixelPrecision: function (dataExtent) {
  31264. return getPixelPrecision(
  31265. dataExtent || this.scale.getExtent(),
  31266. this._extent
  31267. );
  31268. },
  31269. /**
  31270. * Set coord extent
  31271. * @param {number} start
  31272. * @param {number} end
  31273. */
  31274. setExtent: function (start, end) {
  31275. var extent = this._extent;
  31276. extent[0] = start;
  31277. extent[1] = end;
  31278. },
  31279. /**
  31280. * Convert data to coord. Data is the rank if it has an ordinal scale
  31281. * @param {number} data
  31282. * @param {boolean} clamp
  31283. * @return {number}
  31284. */
  31285. dataToCoord: function (data, clamp) {
  31286. var extent = this._extent;
  31287. var scale = this.scale;
  31288. data = scale.normalize(data);
  31289. if (this.onBand && scale.type === 'ordinal') {
  31290. extent = extent.slice();
  31291. fixExtentWithBands(extent, scale.count());
  31292. }
  31293. return linearMap(data, NORMALIZED_EXTENT, extent, clamp);
  31294. },
  31295. /**
  31296. * Convert coord to data. Data is the rank if it has an ordinal scale
  31297. * @param {number} coord
  31298. * @param {boolean} clamp
  31299. * @return {number}
  31300. */
  31301. coordToData: function (coord, clamp) {
  31302. var extent = this._extent;
  31303. var scale = this.scale;
  31304. if (this.onBand && scale.type === 'ordinal') {
  31305. extent = extent.slice();
  31306. fixExtentWithBands(extent, scale.count());
  31307. }
  31308. var t = linearMap(coord, extent, NORMALIZED_EXTENT, clamp);
  31309. return this.scale.scale(t);
  31310. },
  31311. /**
  31312. * Convert pixel point to data in axis
  31313. * @param {Array.<number>} point
  31314. * @param {boolean} clamp
  31315. * @return {number} data
  31316. */
  31317. pointToData: function (point, clamp) {
  31318. // Should be implemented in derived class if necessary.
  31319. },
  31320. /**
  31321. * Different from `zrUtil.map(axis.getTicks(), axis.dataToCoord, axis)`,
  31322. * `axis.getTicksCoords` considers `onBand`, which is used by
  31323. * `boundaryGap:true` of category axis and splitLine and splitArea.
  31324. * @param {Object} [opt]
  31325. * @param {number} [opt.tickModel=axis.model.getModel('axisTick')]
  31326. * @param {boolean} [opt.clamp] If `true`, the first and the last
  31327. * tick must be at the axis end points. Otherwise, clip ticks
  31328. * that outside the axis extent.
  31329. * @return {Array.<Object>} [{
  31330. * coord: ...,
  31331. * tickValue: ...
  31332. * }, ...]
  31333. */
  31334. getTicksCoords: function (opt) {
  31335. opt = opt || {};
  31336. var tickModel = opt.tickModel || this.getTickModel();
  31337. var result = createAxisTicks(this, tickModel);
  31338. var ticks = result.ticks;
  31339. var ticksCoords = map(ticks, function (tickValue) {
  31340. return {
  31341. coord: this.dataToCoord(tickValue),
  31342. tickValue: tickValue
  31343. };
  31344. }, this);
  31345. var alignWithLabel = tickModel.get('alignWithLabel');
  31346. fixOnBandTicksCoords(
  31347. this, ticksCoords, result.tickCategoryInterval, alignWithLabel, opt.clamp
  31348. );
  31349. return ticksCoords;
  31350. },
  31351. /**
  31352. * @return {Array.<Object>} [{
  31353. * formattedLabel: string,
  31354. * rawLabel: axis.scale.getLabel(tickValue)
  31355. * tickValue: number
  31356. * }, ...]
  31357. */
  31358. getViewLabels: function () {
  31359. return createAxisLabels(this).labels;
  31360. },
  31361. /**
  31362. * @return {module:echarts/coord/model/Model}
  31363. */
  31364. getLabelModel: function () {
  31365. return this.model.getModel('axisLabel');
  31366. },
  31367. /**
  31368. * Notice here we only get the default tick model. For splitLine
  31369. * or splitArea, we should pass the splitLineModel or splitAreaModel
  31370. * manually when calling `getTicksCoords`.
  31371. * In GL, this method may be overrided to:
  31372. * `axisModel.getModel('axisTick', grid3DModel.getModel('axisTick'));`
  31373. * @return {module:echarts/coord/model/Model}
  31374. */
  31375. getTickModel: function () {
  31376. return this.model.getModel('axisTick');
  31377. },
  31378. /**
  31379. * Get width of band
  31380. * @return {number}
  31381. */
  31382. getBandWidth: function () {
  31383. var axisExtent = this._extent;
  31384. var dataExtent = this.scale.getExtent();
  31385. var len = dataExtent[1] - dataExtent[0] + (this.onBand ? 1 : 0);
  31386. // Fix #2728, avoid NaN when only one data.
  31387. len === 0 && (len = 1);
  31388. var size = Math.abs(axisExtent[1] - axisExtent[0]);
  31389. return Math.abs(size) / len;
  31390. },
  31391. /**
  31392. * @abstract
  31393. * @return {boolean} Is horizontal
  31394. */
  31395. isHorizontal: null,
  31396. /**
  31397. * @abstract
  31398. * @return {number} Get axis rotate, by degree.
  31399. */
  31400. getRotate: null,
  31401. /**
  31402. * Only be called in category axis.
  31403. * Can be overrided, consider other axes like in 3D.
  31404. * @return {number} Auto interval for cateogry axis tick and label
  31405. */
  31406. calculateCategoryInterval: function () {
  31407. return calculateCategoryInterval(this);
  31408. }
  31409. };
  31410. function fixExtentWithBands(extent, nTick) {
  31411. var size = extent[1] - extent[0];
  31412. var len = nTick;
  31413. var margin = size / len / 2;
  31414. extent[0] += margin;
  31415. extent[1] -= margin;
  31416. }
  31417. // If axis has labels [1, 2, 3, 4]. Bands on the axis are
  31418. // |---1---|---2---|---3---|---4---|.
  31419. // So the displayed ticks and splitLine/splitArea should between
  31420. // each data item, otherwise cause misleading (e.g., split tow bars
  31421. // of a single data item when there are two bar series).
  31422. // Also consider if tickCategoryInterval > 0 and onBand, ticks and
  31423. // splitLine/spliteArea should layout appropriately corresponding
  31424. // to displayed labels. (So we should not use `getBandWidth` in this
  31425. // case).
  31426. function fixOnBandTicksCoords(axis, ticksCoords, tickCategoryInterval, alignWithLabel, clamp) {
  31427. var ticksLen = ticksCoords.length;
  31428. if (!axis.onBand || alignWithLabel || !ticksLen) {
  31429. return;
  31430. }
  31431. var axisExtent = axis.getExtent();
  31432. var last;
  31433. if (ticksLen === 1) {
  31434. ticksCoords[0].coord = axisExtent[0];
  31435. last = ticksCoords[1] = {coord: axisExtent[0]};
  31436. }
  31437. else {
  31438. var shift = (ticksCoords[1].coord - ticksCoords[0].coord);
  31439. each$1(ticksCoords, function (ticksItem) {
  31440. ticksItem.coord -= shift / 2;
  31441. var tickCategoryInterval = tickCategoryInterval || 0;
  31442. // Avoid split a single data item when odd interval.
  31443. if (tickCategoryInterval % 2 > 0) {
  31444. ticksItem.coord -= shift / ((tickCategoryInterval + 1) * 2);
  31445. }
  31446. });
  31447. last = {coord: ticksCoords[ticksLen - 1].coord + shift};
  31448. ticksCoords.push(last);
  31449. }
  31450. var inverse = axisExtent[0] > axisExtent[1];
  31451. if (littleThan(ticksCoords[0].coord, axisExtent[0])) {
  31452. clamp ? (ticksCoords[0].coord = axisExtent[0]) : ticksCoords.shift();
  31453. }
  31454. if (clamp && littleThan(axisExtent[0], ticksCoords[0].coord)) {
  31455. ticksCoords.unshift({coord: axisExtent[0]});
  31456. }
  31457. if (littleThan(axisExtent[1], last.coord)) {
  31458. clamp ? (last.coord = axisExtent[1]) : ticksCoords.pop();
  31459. }
  31460. if (clamp && littleThan(last.coord, axisExtent[1])) {
  31461. ticksCoords.push({coord: axisExtent[1]});
  31462. }
  31463. function littleThan(a, b) {
  31464. return inverse ? a > b : a < b;
  31465. }
  31466. }
  31467. /*
  31468. * Licensed to the Apache Software Foundation (ASF) under one
  31469. * or more contributor license agreements. See the NOTICE file
  31470. * distributed with this work for additional information
  31471. * regarding copyright ownership. The ASF licenses this file
  31472. * to you under the Apache License, Version 2.0 (the
  31473. * "License"); you may not use this file except in compliance
  31474. * with the License. You may obtain a copy of the License at
  31475. *
  31476. * http://www.apache.org/licenses/LICENSE-2.0
  31477. *
  31478. * Unless required by applicable law or agreed to in writing,
  31479. * software distributed under the License is distributed on an
  31480. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  31481. * KIND, either express or implied. See the License for the
  31482. * specific language governing permissions and limitations
  31483. * under the License.
  31484. */
  31485. /**
  31486. * Do not mount those modules on 'src/echarts' for better tree shaking.
  31487. */
  31488. var parseGeoJson = parseGeoJson$1;
  31489. var ecUtil = {};
  31490. each$1(
  31491. [
  31492. 'map', 'each', 'filter', 'indexOf', 'inherits', 'reduce', 'filter',
  31493. 'bind', 'curry', 'isArray', 'isString', 'isObject', 'isFunction',
  31494. 'extend', 'defaults', 'clone', 'merge'
  31495. ],
  31496. function (name) {
  31497. ecUtil[name] = zrUtil[name];
  31498. }
  31499. );
  31500. var graphic$1 = {};
  31501. each$1(
  31502. [
  31503. 'extendShape', 'extendPath', 'makePath', 'makeImage',
  31504. 'mergePath', 'resizePath', 'createIcon',
  31505. 'setHoverStyle', 'setLabelStyle', 'setTextStyle', 'setText',
  31506. 'getFont', 'updateProps', 'initProps', 'getTransform',
  31507. 'clipPointsByRect', 'clipRectByRect',
  31508. 'Group',
  31509. 'Image',
  31510. 'Text',
  31511. 'Circle',
  31512. 'Sector',
  31513. 'Ring',
  31514. 'Polygon',
  31515. 'Polyline',
  31516. 'Rect',
  31517. 'Line',
  31518. 'BezierCurve',
  31519. 'Arc',
  31520. 'IncrementalDisplayable',
  31521. 'CompoundPath',
  31522. 'LinearGradient',
  31523. 'RadialGradient',
  31524. 'BoundingRect'
  31525. ],
  31526. function (name) {
  31527. graphic$1[name] = graphic[name];
  31528. }
  31529. );
  31530. /*
  31531. * Licensed to the Apache Software Foundation (ASF) under one
  31532. * or more contributor license agreements. See the NOTICE file
  31533. * distributed with this work for additional information
  31534. * regarding copyright ownership. The ASF licenses this file
  31535. * to you under the Apache License, Version 2.0 (the
  31536. * "License"); you may not use this file except in compliance
  31537. * with the License. You may obtain a copy of the License at
  31538. *
  31539. * http://www.apache.org/licenses/LICENSE-2.0
  31540. *
  31541. * Unless required by applicable law or agreed to in writing,
  31542. * software distributed under the License is distributed on an
  31543. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  31544. * KIND, either express or implied. See the License for the
  31545. * specific language governing permissions and limitations
  31546. * under the License.
  31547. */
  31548. SeriesModel.extend({
  31549. type: 'series.line',
  31550. dependencies: ['grid', 'polar'],
  31551. getInitialData: function (option, ecModel) {
  31552. if (__DEV__) {
  31553. var coordSys = option.coordinateSystem;
  31554. if (coordSys !== 'polar' && coordSys !== 'cartesian2d') {
  31555. throw new Error('Line not support coordinateSystem besides cartesian and polar');
  31556. }
  31557. }
  31558. return createListFromArray(this.getSource(), this);
  31559. },
  31560. defaultOption: {
  31561. zlevel: 0,
  31562. z: 2,
  31563. coordinateSystem: 'cartesian2d',
  31564. legendHoverLink: true,
  31565. hoverAnimation: true,
  31566. // stack: null
  31567. // xAxisIndex: 0,
  31568. // yAxisIndex: 0,
  31569. // polarIndex: 0,
  31570. // If clip the overflow value
  31571. clipOverflow: true,
  31572. // cursor: null,
  31573. label: {
  31574. position: 'top'
  31575. },
  31576. // itemStyle: {
  31577. // },
  31578. lineStyle: {
  31579. width: 2,
  31580. type: 'solid'
  31581. },
  31582. // areaStyle: {
  31583. // origin of areaStyle. Valid values:
  31584. // `'auto'/null/undefined`: from axisLine to data
  31585. // `'start'`: from min to data
  31586. // `'end'`: from data to max
  31587. // origin: 'auto'
  31588. // },
  31589. // false, 'start', 'end', 'middle'
  31590. step: false,
  31591. // Disabled if step is true
  31592. smooth: false,
  31593. smoothMonotone: null,
  31594. symbol: 'emptyCircle',
  31595. symbolSize: 4,
  31596. symbolRotate: null,
  31597. showSymbol: true,
  31598. // `false`: follow the label interval strategy.
  31599. // `true`: show all symbols.
  31600. // `'auto'`: If possible, show all symbols, otherwise
  31601. // follow the label interval strategy.
  31602. showAllSymbol: 'auto',
  31603. // Whether to connect break point.
  31604. connectNulls: false,
  31605. // Sampling for large data. Can be: 'average', 'max', 'min', 'sum'.
  31606. sampling: 'none',
  31607. animationEasing: 'linear',
  31608. // Disable progressive
  31609. progressive: 0,
  31610. hoverLayerThreshold: Infinity
  31611. }
  31612. });
  31613. /*
  31614. * Licensed to the Apache Software Foundation (ASF) under one
  31615. * or more contributor license agreements. See the NOTICE file
  31616. * distributed with this work for additional information
  31617. * regarding copyright ownership. The ASF licenses this file
  31618. * to you under the Apache License, Version 2.0 (the
  31619. * "License"); you may not use this file except in compliance
  31620. * with the License. You may obtain a copy of the License at
  31621. *
  31622. * http://www.apache.org/licenses/LICENSE-2.0
  31623. *
  31624. * Unless required by applicable law or agreed to in writing,
  31625. * software distributed under the License is distributed on an
  31626. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  31627. * KIND, either express or implied. See the License for the
  31628. * specific language governing permissions and limitations
  31629. * under the License.
  31630. */
  31631. /**
  31632. * @param {module:echarts/data/List} data
  31633. * @param {number} dataIndex
  31634. * @return {string} label string. Not null/undefined
  31635. */
  31636. function getDefaultLabel(data, dataIndex) {
  31637. var labelDims = data.mapDimension('defaultedLabel', true);
  31638. var len = labelDims.length;
  31639. // Simple optimization (in lots of cases, label dims length is 1)
  31640. if (len === 1) {
  31641. return retrieveRawValue(data, dataIndex, labelDims[0]);
  31642. }
  31643. else if (len) {
  31644. var vals = [];
  31645. for (var i = 0; i < labelDims.length; i++) {
  31646. var val = retrieveRawValue(data, dataIndex, labelDims[i]);
  31647. vals.push(val);
  31648. }
  31649. return vals.join(' ');
  31650. }
  31651. }
  31652. /*
  31653. * Licensed to the Apache Software Foundation (ASF) under one
  31654. * or more contributor license agreements. See the NOTICE file
  31655. * distributed with this work for additional information
  31656. * regarding copyright ownership. The ASF licenses this file
  31657. * to you under the Apache License, Version 2.0 (the
  31658. * "License"); you may not use this file except in compliance
  31659. * with the License. You may obtain a copy of the License at
  31660. *
  31661. * http://www.apache.org/licenses/LICENSE-2.0
  31662. *
  31663. * Unless required by applicable law or agreed to in writing,
  31664. * software distributed under the License is distributed on an
  31665. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  31666. * KIND, either express or implied. See the License for the
  31667. * specific language governing permissions and limitations
  31668. * under the License.
  31669. */
  31670. /**
  31671. * @module echarts/chart/helper/Symbol
  31672. */
  31673. /**
  31674. * @constructor
  31675. * @alias {module:echarts/chart/helper/Symbol}
  31676. * @param {module:echarts/data/List} data
  31677. * @param {number} idx
  31678. * @extends {module:zrender/graphic/Group}
  31679. */
  31680. function SymbolClz$1(data, idx, seriesScope) {
  31681. Group.call(this);
  31682. this.updateData(data, idx, seriesScope);
  31683. }
  31684. var symbolProto = SymbolClz$1.prototype;
  31685. /**
  31686. * @public
  31687. * @static
  31688. * @param {module:echarts/data/List} data
  31689. * @param {number} dataIndex
  31690. * @return {Array.<number>} [width, height]
  31691. */
  31692. var getSymbolSize = SymbolClz$1.getSymbolSize = function (data, idx) {
  31693. var symbolSize = data.getItemVisual(idx, 'symbolSize');
  31694. return symbolSize instanceof Array
  31695. ? symbolSize.slice()
  31696. : [+symbolSize, +symbolSize];
  31697. };
  31698. function getScale(symbolSize) {
  31699. return [symbolSize[0] / 2, symbolSize[1] / 2];
  31700. }
  31701. function driftSymbol(dx, dy) {
  31702. this.parent.drift(dx, dy);
  31703. }
  31704. symbolProto._createSymbol = function (
  31705. symbolType,
  31706. data,
  31707. idx,
  31708. symbolSize,
  31709. keepAspect
  31710. ) {
  31711. // Remove paths created before
  31712. this.removeAll();
  31713. var color = data.getItemVisual(idx, 'color');
  31714. // var symbolPath = createSymbol(
  31715. // symbolType, -0.5, -0.5, 1, 1, color
  31716. // );
  31717. // If width/height are set too small (e.g., set to 1) on ios10
  31718. // and macOS Sierra, a circle stroke become a rect, no matter what
  31719. // the scale is set. So we set width/height as 2. See #4150.
  31720. var symbolPath = createSymbol(
  31721. symbolType, -1, -1, 2, 2, color, keepAspect
  31722. );
  31723. symbolPath.attr({
  31724. z2: 100,
  31725. culling: true,
  31726. scale: getScale(symbolSize)
  31727. });
  31728. // Rewrite drift method
  31729. symbolPath.drift = driftSymbol;
  31730. this._symbolType = symbolType;
  31731. this.add(symbolPath);
  31732. };
  31733. /**
  31734. * Stop animation
  31735. * @param {boolean} toLastFrame
  31736. */
  31737. symbolProto.stopSymbolAnimation = function (toLastFrame) {
  31738. this.childAt(0).stopAnimation(toLastFrame);
  31739. };
  31740. /**
  31741. * FIXME:
  31742. * Caution: This method breaks the encapsulation of this module,
  31743. * but it indeed brings convenience. So do not use the method
  31744. * unless you detailedly know all the implements of `Symbol`,
  31745. * especially animation.
  31746. *
  31747. * Get symbol path element.
  31748. */
  31749. symbolProto.getSymbolPath = function () {
  31750. return this.childAt(0);
  31751. };
  31752. /**
  31753. * Get scale(aka, current symbol size).
  31754. * Including the change caused by animation
  31755. */
  31756. symbolProto.getScale = function () {
  31757. return this.childAt(0).scale;
  31758. };
  31759. /**
  31760. * Highlight symbol
  31761. */
  31762. symbolProto.highlight = function () {
  31763. this.childAt(0).trigger('emphasis');
  31764. };
  31765. /**
  31766. * Downplay symbol
  31767. */
  31768. symbolProto.downplay = function () {
  31769. this.childAt(0).trigger('normal');
  31770. };
  31771. /**
  31772. * @param {number} zlevel
  31773. * @param {number} z
  31774. */
  31775. symbolProto.setZ = function (zlevel, z) {
  31776. var symbolPath = this.childAt(0);
  31777. symbolPath.zlevel = zlevel;
  31778. symbolPath.z = z;
  31779. };
  31780. symbolProto.setDraggable = function (draggable) {
  31781. var symbolPath = this.childAt(0);
  31782. symbolPath.draggable = draggable;
  31783. symbolPath.cursor = draggable ? 'move' : symbolPath.cursor;
  31784. };
  31785. /**
  31786. * Update symbol properties
  31787. * @param {module:echarts/data/List} data
  31788. * @param {number} idx
  31789. * @param {Object} [seriesScope]
  31790. * @param {Object} [seriesScope.itemStyle]
  31791. * @param {Object} [seriesScope.hoverItemStyle]
  31792. * @param {Object} [seriesScope.symbolRotate]
  31793. * @param {Object} [seriesScope.symbolOffset]
  31794. * @param {module:echarts/model/Model} [seriesScope.labelModel]
  31795. * @param {module:echarts/model/Model} [seriesScope.hoverLabelModel]
  31796. * @param {boolean} [seriesScope.hoverAnimation]
  31797. * @param {Object} [seriesScope.cursorStyle]
  31798. * @param {module:echarts/model/Model} [seriesScope.itemModel]
  31799. * @param {string} [seriesScope.symbolInnerColor]
  31800. * @param {Object} [seriesScope.fadeIn=false]
  31801. */
  31802. symbolProto.updateData = function (data, idx, seriesScope) {
  31803. this.silent = false;
  31804. var symbolType = data.getItemVisual(idx, 'symbol') || 'circle';
  31805. var seriesModel = data.hostModel;
  31806. var symbolSize = getSymbolSize(data, idx);
  31807. var isInit = symbolType !== this._symbolType;
  31808. if (isInit) {
  31809. var keepAspect = data.getItemVisual(idx, 'symbolKeepAspect');
  31810. this._createSymbol(symbolType, data, idx, symbolSize, keepAspect);
  31811. }
  31812. else {
  31813. var symbolPath = this.childAt(0);
  31814. symbolPath.silent = false;
  31815. updateProps(symbolPath, {
  31816. scale: getScale(symbolSize)
  31817. }, seriesModel, idx);
  31818. }
  31819. this._updateCommon(data, idx, symbolSize, seriesScope);
  31820. if (isInit) {
  31821. var symbolPath = this.childAt(0);
  31822. var fadeIn = seriesScope && seriesScope.fadeIn;
  31823. var target = {scale: symbolPath.scale.slice()};
  31824. fadeIn && (target.style = {opacity: symbolPath.style.opacity});
  31825. symbolPath.scale = [0, 0];
  31826. fadeIn && (symbolPath.style.opacity = 0);
  31827. initProps(symbolPath, target, seriesModel, idx);
  31828. }
  31829. this._seriesModel = seriesModel;
  31830. };
  31831. // Update common properties
  31832. var normalStyleAccessPath = ['itemStyle'];
  31833. var emphasisStyleAccessPath = ['emphasis', 'itemStyle'];
  31834. var normalLabelAccessPath = ['label'];
  31835. var emphasisLabelAccessPath = ['emphasis', 'label'];
  31836. /**
  31837. * @param {module:echarts/data/List} data
  31838. * @param {number} idx
  31839. * @param {Array.<number>} symbolSize
  31840. * @param {Object} [seriesScope]
  31841. */
  31842. symbolProto._updateCommon = function (data, idx, symbolSize, seriesScope) {
  31843. var symbolPath = this.childAt(0);
  31844. var seriesModel = data.hostModel;
  31845. var color = data.getItemVisual(idx, 'color');
  31846. // Reset style
  31847. if (symbolPath.type !== 'image') {
  31848. symbolPath.useStyle({
  31849. strokeNoScale: true
  31850. });
  31851. }
  31852. var itemStyle = seriesScope && seriesScope.itemStyle;
  31853. var hoverItemStyle = seriesScope && seriesScope.hoverItemStyle;
  31854. var symbolRotate = seriesScope && seriesScope.symbolRotate;
  31855. var symbolOffset = seriesScope && seriesScope.symbolOffset;
  31856. var labelModel = seriesScope && seriesScope.labelModel;
  31857. var hoverLabelModel = seriesScope && seriesScope.hoverLabelModel;
  31858. var hoverAnimation = seriesScope && seriesScope.hoverAnimation;
  31859. var cursorStyle = seriesScope && seriesScope.cursorStyle;
  31860. if (!seriesScope || data.hasItemOption) {
  31861. var itemModel = (seriesScope && seriesScope.itemModel)
  31862. ? seriesScope.itemModel : data.getItemModel(idx);
  31863. // Color must be excluded.
  31864. // Because symbol provide setColor individually to set fill and stroke
  31865. itemStyle = itemModel.getModel(normalStyleAccessPath).getItemStyle(['color']);
  31866. hoverItemStyle = itemModel.getModel(emphasisStyleAccessPath).getItemStyle();
  31867. symbolRotate = itemModel.getShallow('symbolRotate');
  31868. symbolOffset = itemModel.getShallow('symbolOffset');
  31869. labelModel = itemModel.getModel(normalLabelAccessPath);
  31870. hoverLabelModel = itemModel.getModel(emphasisLabelAccessPath);
  31871. hoverAnimation = itemModel.getShallow('hoverAnimation');
  31872. cursorStyle = itemModel.getShallow('cursor');
  31873. }
  31874. else {
  31875. hoverItemStyle = extend({}, hoverItemStyle);
  31876. }
  31877. var elStyle = symbolPath.style;
  31878. symbolPath.attr('rotation', (symbolRotate || 0) * Math.PI / 180 || 0);
  31879. if (symbolOffset) {
  31880. symbolPath.attr('position', [
  31881. parsePercent$1(symbolOffset[0], symbolSize[0]),
  31882. parsePercent$1(symbolOffset[1], symbolSize[1])
  31883. ]);
  31884. }
  31885. cursorStyle && symbolPath.attr('cursor', cursorStyle);
  31886. // PENDING setColor before setStyle!!!
  31887. symbolPath.setColor(color, seriesScope && seriesScope.symbolInnerColor);
  31888. symbolPath.setStyle(itemStyle);
  31889. var opacity = data.getItemVisual(idx, 'opacity');
  31890. if (opacity != null) {
  31891. elStyle.opacity = opacity;
  31892. }
  31893. var liftZ = data.getItemVisual(idx, 'liftZ');
  31894. var z2Origin = symbolPath.__z2Origin;
  31895. if (liftZ != null) {
  31896. if (z2Origin == null) {
  31897. symbolPath.__z2Origin = symbolPath.z2;
  31898. symbolPath.z2 += liftZ;
  31899. }
  31900. }
  31901. else if (z2Origin != null) {
  31902. symbolPath.z2 = z2Origin;
  31903. symbolPath.__z2Origin = null;
  31904. }
  31905. var useNameLabel = seriesScope && seriesScope.useNameLabel;
  31906. setLabelStyle(
  31907. elStyle, hoverItemStyle, labelModel, hoverLabelModel,
  31908. {
  31909. labelFetcher: seriesModel,
  31910. labelDataIndex: idx,
  31911. defaultText: getLabelDefaultText,
  31912. isRectText: true,
  31913. autoColor: color
  31914. }
  31915. );
  31916. // Do not execute util needed.
  31917. function getLabelDefaultText(idx, opt) {
  31918. return useNameLabel ? data.getName(idx) : getDefaultLabel(data, idx);
  31919. }
  31920. symbolPath.__symbolOriginalScale = getScale(symbolSize);
  31921. symbolPath.hoverStyle = hoverItemStyle;
  31922. symbolPath.highDownOnUpdate = (
  31923. hoverAnimation && seriesModel.isAnimationEnabled()
  31924. ) ? highDownOnUpdate : null;
  31925. setHoverStyle(symbolPath);
  31926. };
  31927. function highDownOnUpdate(fromState, toState) {
  31928. // Do not support this hover animation util some scenario required.
  31929. // Animation can only be supported in hover layer when using `el.incremetal`.
  31930. if (this.incremental || this.useHoverLayer) {
  31931. return;
  31932. }
  31933. if (toState === 'emphasis') {
  31934. var scale = this.__symbolOriginalScale;
  31935. var ratio = scale[1] / scale[0];
  31936. var emphasisOpt = {
  31937. scale: [
  31938. Math.max(scale[0] * 1.1, scale[0] + 3),
  31939. Math.max(scale[1] * 1.1, scale[1] + 3 * ratio)
  31940. ]
  31941. };
  31942. // FIXME
  31943. // modify it after support stop specified animation.
  31944. // toState === fromState
  31945. // ? (this.stopAnimation(), this.attr(emphasisOpt))
  31946. this.animateTo(emphasisOpt, 400, 'elasticOut');
  31947. }
  31948. else if (toState === 'normal') {
  31949. this.animateTo({
  31950. scale: this.__symbolOriginalScale
  31951. }, 400, 'elasticOut');
  31952. }
  31953. }
  31954. /**
  31955. * @param {Function} cb
  31956. * @param {Object} [opt]
  31957. * @param {Object} [opt.keepLabel=true]
  31958. */
  31959. symbolProto.fadeOut = function (cb, opt) {
  31960. var symbolPath = this.childAt(0);
  31961. // Avoid mistaken hover when fading out
  31962. this.silent = symbolPath.silent = true;
  31963. // Not show text when animating
  31964. !(opt && opt.keepLabel) && (symbolPath.style.text = null);
  31965. updateProps(
  31966. symbolPath,
  31967. {
  31968. style: {opacity: 0},
  31969. scale: [0, 0]
  31970. },
  31971. this._seriesModel,
  31972. this.dataIndex,
  31973. cb
  31974. );
  31975. };
  31976. inherits(SymbolClz$1, Group);
  31977. /*
  31978. * Licensed to the Apache Software Foundation (ASF) under one
  31979. * or more contributor license agreements. See the NOTICE file
  31980. * distributed with this work for additional information
  31981. * regarding copyright ownership. The ASF licenses this file
  31982. * to you under the Apache License, Version 2.0 (the
  31983. * "License"); you may not use this file except in compliance
  31984. * with the License. You may obtain a copy of the License at
  31985. *
  31986. * http://www.apache.org/licenses/LICENSE-2.0
  31987. *
  31988. * Unless required by applicable law or agreed to in writing,
  31989. * software distributed under the License is distributed on an
  31990. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  31991. * KIND, either express or implied. See the License for the
  31992. * specific language governing permissions and limitations
  31993. * under the License.
  31994. */
  31995. /**
  31996. * @module echarts/chart/helper/SymbolDraw
  31997. */
  31998. /**
  31999. * @constructor
  32000. * @alias module:echarts/chart/helper/SymbolDraw
  32001. * @param {module:zrender/graphic/Group} [symbolCtor]
  32002. */
  32003. function SymbolDraw(symbolCtor) {
  32004. this.group = new Group();
  32005. this._symbolCtor = symbolCtor || SymbolClz$1;
  32006. }
  32007. var symbolDrawProto = SymbolDraw.prototype;
  32008. function symbolNeedsDraw(data, point, idx, opt) {
  32009. return point && !isNaN(point[0]) && !isNaN(point[1])
  32010. && !(opt.isIgnore && opt.isIgnore(idx))
  32011. // We do not set clipShape on group, because it will cut part of
  32012. // the symbol element shape. We use the same clip shape here as
  32013. // the line clip.
  32014. && !(opt.clipShape && !opt.clipShape.contain(point[0], point[1]))
  32015. && data.getItemVisual(idx, 'symbol') !== 'none';
  32016. }
  32017. /**
  32018. * Update symbols draw by new data
  32019. * @param {module:echarts/data/List} data
  32020. * @param {Object} [opt] Or isIgnore
  32021. * @param {Function} [opt.isIgnore]
  32022. * @param {Object} [opt.clipShape]
  32023. */
  32024. symbolDrawProto.updateData = function (data, opt) {
  32025. opt = normalizeUpdateOpt(opt);
  32026. var group = this.group;
  32027. var seriesModel = data.hostModel;
  32028. var oldData = this._data;
  32029. var SymbolCtor = this._symbolCtor;
  32030. var seriesScope = makeSeriesScope(data);
  32031. // There is no oldLineData only when first rendering or switching from
  32032. // stream mode to normal mode, where previous elements should be removed.
  32033. if (!oldData) {
  32034. group.removeAll();
  32035. }
  32036. data.diff(oldData)
  32037. .add(function (newIdx) {
  32038. var point = data.getItemLayout(newIdx);
  32039. if (symbolNeedsDraw(data, point, newIdx, opt)) {
  32040. var symbolEl = new SymbolCtor(data, newIdx, seriesScope);
  32041. symbolEl.attr('position', point);
  32042. data.setItemGraphicEl(newIdx, symbolEl);
  32043. group.add(symbolEl);
  32044. }
  32045. })
  32046. .update(function (newIdx, oldIdx) {
  32047. var symbolEl = oldData.getItemGraphicEl(oldIdx);
  32048. var point = data.getItemLayout(newIdx);
  32049. if (!symbolNeedsDraw(data, point, newIdx, opt)) {
  32050. group.remove(symbolEl);
  32051. return;
  32052. }
  32053. if (!symbolEl) {
  32054. symbolEl = new SymbolCtor(data, newIdx);
  32055. symbolEl.attr('position', point);
  32056. }
  32057. else {
  32058. symbolEl.updateData(data, newIdx, seriesScope);
  32059. updateProps(symbolEl, {
  32060. position: point
  32061. }, seriesModel);
  32062. }
  32063. // Add back
  32064. group.add(symbolEl);
  32065. data.setItemGraphicEl(newIdx, symbolEl);
  32066. })
  32067. .remove(function (oldIdx) {
  32068. var el = oldData.getItemGraphicEl(oldIdx);
  32069. el && el.fadeOut(function () {
  32070. group.remove(el);
  32071. });
  32072. })
  32073. .execute();
  32074. this._data = data;
  32075. };
  32076. symbolDrawProto.isPersistent = function () {
  32077. return true;
  32078. };
  32079. symbolDrawProto.updateLayout = function () {
  32080. var data = this._data;
  32081. if (data) {
  32082. // Not use animation
  32083. data.eachItemGraphicEl(function (el, idx) {
  32084. var point = data.getItemLayout(idx);
  32085. el.attr('position', point);
  32086. });
  32087. }
  32088. };
  32089. symbolDrawProto.incrementalPrepareUpdate = function (data) {
  32090. this._seriesScope = makeSeriesScope(data);
  32091. this._data = null;
  32092. this.group.removeAll();
  32093. };
  32094. /**
  32095. * Update symbols draw by new data
  32096. * @param {module:echarts/data/List} data
  32097. * @param {Object} [opt] Or isIgnore
  32098. * @param {Function} [opt.isIgnore]
  32099. * @param {Object} [opt.clipShape]
  32100. */
  32101. symbolDrawProto.incrementalUpdate = function (taskParams, data, opt) {
  32102. opt = normalizeUpdateOpt(opt);
  32103. function updateIncrementalAndHover(el) {
  32104. if (!el.isGroup) {
  32105. el.incremental = el.useHoverLayer = true;
  32106. }
  32107. }
  32108. for (var idx = taskParams.start; idx < taskParams.end; idx++) {
  32109. var point = data.getItemLayout(idx);
  32110. if (symbolNeedsDraw(data, point, idx, opt)) {
  32111. var el = new this._symbolCtor(data, idx, this._seriesScope);
  32112. el.traverse(updateIncrementalAndHover);
  32113. el.attr('position', point);
  32114. this.group.add(el);
  32115. data.setItemGraphicEl(idx, el);
  32116. }
  32117. }
  32118. };
  32119. function normalizeUpdateOpt(opt) {
  32120. if (opt != null && !isObject$1(opt)) {
  32121. opt = {isIgnore: opt};
  32122. }
  32123. return opt || {};
  32124. }
  32125. symbolDrawProto.remove = function (enableAnimation) {
  32126. var group = this.group;
  32127. var data = this._data;
  32128. // Incremental model do not have this._data.
  32129. if (data && enableAnimation) {
  32130. data.eachItemGraphicEl(function (el) {
  32131. el.fadeOut(function () {
  32132. group.remove(el);
  32133. });
  32134. });
  32135. }
  32136. else {
  32137. group.removeAll();
  32138. }
  32139. };
  32140. function makeSeriesScope(data) {
  32141. var seriesModel = data.hostModel;
  32142. return {
  32143. itemStyle: seriesModel.getModel('itemStyle').getItemStyle(['color']),
  32144. hoverItemStyle: seriesModel.getModel('emphasis.itemStyle').getItemStyle(),
  32145. symbolRotate: seriesModel.get('symbolRotate'),
  32146. symbolOffset: seriesModel.get('symbolOffset'),
  32147. hoverAnimation: seriesModel.get('hoverAnimation'),
  32148. labelModel: seriesModel.getModel('label'),
  32149. hoverLabelModel: seriesModel.getModel('emphasis.label'),
  32150. cursorStyle: seriesModel.get('cursor')
  32151. };
  32152. }
  32153. /*
  32154. * Licensed to the Apache Software Foundation (ASF) under one
  32155. * or more contributor license agreements. See the NOTICE file
  32156. * distributed with this work for additional information
  32157. * regarding copyright ownership. The ASF licenses this file
  32158. * to you under the Apache License, Version 2.0 (the
  32159. * "License"); you may not use this file except in compliance
  32160. * with the License. You may obtain a copy of the License at
  32161. *
  32162. * http://www.apache.org/licenses/LICENSE-2.0
  32163. *
  32164. * Unless required by applicable law or agreed to in writing,
  32165. * software distributed under the License is distributed on an
  32166. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  32167. * KIND, either express or implied. See the License for the
  32168. * specific language governing permissions and limitations
  32169. * under the License.
  32170. */
  32171. /**
  32172. * @param {Object} coordSys
  32173. * @param {module:echarts/data/List} data
  32174. * @param {string} valueOrigin lineSeries.option.areaStyle.origin
  32175. */
  32176. function prepareDataCoordInfo(coordSys, data, valueOrigin) {
  32177. var baseAxis = coordSys.getBaseAxis();
  32178. var valueAxis = coordSys.getOtherAxis(baseAxis);
  32179. var valueStart = getValueStart(valueAxis, valueOrigin);
  32180. var baseAxisDim = baseAxis.dim;
  32181. var valueAxisDim = valueAxis.dim;
  32182. var valueDim = data.mapDimension(valueAxisDim);
  32183. var baseDim = data.mapDimension(baseAxisDim);
  32184. var baseDataOffset = valueAxisDim === 'x' || valueAxisDim === 'radius' ? 1 : 0;
  32185. var dims = map(coordSys.dimensions, function (coordDim) {
  32186. return data.mapDimension(coordDim);
  32187. });
  32188. var stacked;
  32189. var stackResultDim = data.getCalculationInfo('stackResultDimension');
  32190. if (stacked |= isDimensionStacked(data, dims[0] /*, dims[1]*/)) { // jshint ignore:line
  32191. dims[0] = stackResultDim;
  32192. }
  32193. if (stacked |= isDimensionStacked(data, dims[1] /*, dims[0]*/)) { // jshint ignore:line
  32194. dims[1] = stackResultDim;
  32195. }
  32196. return {
  32197. dataDimsForPoint: dims,
  32198. valueStart: valueStart,
  32199. valueAxisDim: valueAxisDim,
  32200. baseAxisDim: baseAxisDim,
  32201. stacked: !!stacked,
  32202. valueDim: valueDim,
  32203. baseDim: baseDim,
  32204. baseDataOffset: baseDataOffset,
  32205. stackedOverDimension: data.getCalculationInfo('stackedOverDimension')
  32206. };
  32207. }
  32208. function getValueStart(valueAxis, valueOrigin) {
  32209. var valueStart = 0;
  32210. var extent = valueAxis.scale.getExtent();
  32211. if (valueOrigin === 'start') {
  32212. valueStart = extent[0];
  32213. }
  32214. else if (valueOrigin === 'end') {
  32215. valueStart = extent[1];
  32216. }
  32217. // auto
  32218. else {
  32219. // Both positive
  32220. if (extent[0] > 0) {
  32221. valueStart = extent[0];
  32222. }
  32223. // Both negative
  32224. else if (extent[1] < 0) {
  32225. valueStart = extent[1];
  32226. }
  32227. // If is one positive, and one negative, onZero shall be true
  32228. }
  32229. return valueStart;
  32230. }
  32231. function getStackedOnPoint(dataCoordInfo, coordSys, data, idx) {
  32232. var value = NaN;
  32233. if (dataCoordInfo.stacked) {
  32234. value = data.get(data.getCalculationInfo('stackedOverDimension'), idx);
  32235. }
  32236. if (isNaN(value)) {
  32237. value = dataCoordInfo.valueStart;
  32238. }
  32239. var baseDataOffset = dataCoordInfo.baseDataOffset;
  32240. var stackedData = [];
  32241. stackedData[baseDataOffset] = data.get(dataCoordInfo.baseDim, idx);
  32242. stackedData[1 - baseDataOffset] = value;
  32243. return coordSys.dataToPoint(stackedData);
  32244. }
  32245. /*
  32246. * Licensed to the Apache Software Foundation (ASF) under one
  32247. * or more contributor license agreements. See the NOTICE file
  32248. * distributed with this work for additional information
  32249. * regarding copyright ownership. The ASF licenses this file
  32250. * to you under the Apache License, Version 2.0 (the
  32251. * "License"); you may not use this file except in compliance
  32252. * with the License. You may obtain a copy of the License at
  32253. *
  32254. * http://www.apache.org/licenses/LICENSE-2.0
  32255. *
  32256. * Unless required by applicable law or agreed to in writing,
  32257. * software distributed under the License is distributed on an
  32258. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  32259. * KIND, either express or implied. See the License for the
  32260. * specific language governing permissions and limitations
  32261. * under the License.
  32262. */
  32263. // var arrayDiff = require('zrender/src/core/arrayDiff');
  32264. // 'zrender/src/core/arrayDiff' has been used before, but it did
  32265. // not do well in performance when roam with fixed dataZoom window.
  32266. // function convertToIntId(newIdList, oldIdList) {
  32267. // // Generate int id instead of string id.
  32268. // // Compare string maybe slow in score function of arrDiff
  32269. // // Assume id in idList are all unique
  32270. // var idIndicesMap = {};
  32271. // var idx = 0;
  32272. // for (var i = 0; i < newIdList.length; i++) {
  32273. // idIndicesMap[newIdList[i]] = idx;
  32274. // newIdList[i] = idx++;
  32275. // }
  32276. // for (var i = 0; i < oldIdList.length; i++) {
  32277. // var oldId = oldIdList[i];
  32278. // // Same with newIdList
  32279. // if (idIndicesMap[oldId]) {
  32280. // oldIdList[i] = idIndicesMap[oldId];
  32281. // }
  32282. // else {
  32283. // oldIdList[i] = idx++;
  32284. // }
  32285. // }
  32286. // }
  32287. function diffData(oldData, newData) {
  32288. var diffResult = [];
  32289. newData.diff(oldData)
  32290. .add(function (idx) {
  32291. diffResult.push({cmd: '+', idx: idx});
  32292. })
  32293. .update(function (newIdx, oldIdx) {
  32294. diffResult.push({cmd: '=', idx: oldIdx, idx1: newIdx});
  32295. })
  32296. .remove(function (idx) {
  32297. diffResult.push({cmd: '-', idx: idx});
  32298. })
  32299. .execute();
  32300. return diffResult;
  32301. }
  32302. var lineAnimationDiff = function (
  32303. oldData, newData,
  32304. oldStackedOnPoints, newStackedOnPoints,
  32305. oldCoordSys, newCoordSys,
  32306. oldValueOrigin, newValueOrigin
  32307. ) {
  32308. var diff = diffData(oldData, newData);
  32309. // var newIdList = newData.mapArray(newData.getId);
  32310. // var oldIdList = oldData.mapArray(oldData.getId);
  32311. // convertToIntId(newIdList, oldIdList);
  32312. // // FIXME One data ?
  32313. // diff = arrayDiff(oldIdList, newIdList);
  32314. var currPoints = [];
  32315. var nextPoints = [];
  32316. // Points for stacking base line
  32317. var currStackedPoints = [];
  32318. var nextStackedPoints = [];
  32319. var status = [];
  32320. var sortedIndices = [];
  32321. var rawIndices = [];
  32322. var newDataOldCoordInfo = prepareDataCoordInfo(oldCoordSys, newData, oldValueOrigin);
  32323. var oldDataNewCoordInfo = prepareDataCoordInfo(newCoordSys, oldData, newValueOrigin);
  32324. for (var i = 0; i < diff.length; i++) {
  32325. var diffItem = diff[i];
  32326. var pointAdded = true;
  32327. // FIXME, animation is not so perfect when dataZoom window moves fast
  32328. // Which is in case remvoing or add more than one data in the tail or head
  32329. switch (diffItem.cmd) {
  32330. case '=':
  32331. var currentPt = oldData.getItemLayout(diffItem.idx);
  32332. var nextPt = newData.getItemLayout(diffItem.idx1);
  32333. // If previous data is NaN, use next point directly
  32334. if (isNaN(currentPt[0]) || isNaN(currentPt[1])) {
  32335. currentPt = nextPt.slice();
  32336. }
  32337. currPoints.push(currentPt);
  32338. nextPoints.push(nextPt);
  32339. currStackedPoints.push(oldStackedOnPoints[diffItem.idx]);
  32340. nextStackedPoints.push(newStackedOnPoints[diffItem.idx1]);
  32341. rawIndices.push(newData.getRawIndex(diffItem.idx1));
  32342. break;
  32343. case '+':
  32344. var idx = diffItem.idx;
  32345. currPoints.push(
  32346. oldCoordSys.dataToPoint([
  32347. newData.get(newDataOldCoordInfo.dataDimsForPoint[0], idx),
  32348. newData.get(newDataOldCoordInfo.dataDimsForPoint[1], idx)
  32349. ])
  32350. );
  32351. nextPoints.push(newData.getItemLayout(idx).slice());
  32352. currStackedPoints.push(
  32353. getStackedOnPoint(newDataOldCoordInfo, oldCoordSys, newData, idx)
  32354. );
  32355. nextStackedPoints.push(newStackedOnPoints[idx]);
  32356. rawIndices.push(newData.getRawIndex(idx));
  32357. break;
  32358. case '-':
  32359. var idx = diffItem.idx;
  32360. var rawIndex = oldData.getRawIndex(idx);
  32361. // Data is replaced. In the case of dynamic data queue
  32362. // FIXME FIXME FIXME
  32363. if (rawIndex !== idx) {
  32364. currPoints.push(oldData.getItemLayout(idx));
  32365. nextPoints.push(newCoordSys.dataToPoint([
  32366. oldData.get(oldDataNewCoordInfo.dataDimsForPoint[0], idx),
  32367. oldData.get(oldDataNewCoordInfo.dataDimsForPoint[1], idx)
  32368. ]));
  32369. currStackedPoints.push(oldStackedOnPoints[idx]);
  32370. nextStackedPoints.push(
  32371. getStackedOnPoint(oldDataNewCoordInfo, newCoordSys, oldData, idx)
  32372. );
  32373. rawIndices.push(rawIndex);
  32374. }
  32375. else {
  32376. pointAdded = false;
  32377. }
  32378. }
  32379. // Original indices
  32380. if (pointAdded) {
  32381. status.push(diffItem);
  32382. sortedIndices.push(sortedIndices.length);
  32383. }
  32384. }
  32385. // Diff result may be crossed if all items are changed
  32386. // Sort by data index
  32387. sortedIndices.sort(function (a, b) {
  32388. return rawIndices[a] - rawIndices[b];
  32389. });
  32390. var sortedCurrPoints = [];
  32391. var sortedNextPoints = [];
  32392. var sortedCurrStackedPoints = [];
  32393. var sortedNextStackedPoints = [];
  32394. var sortedStatus = [];
  32395. for (var i = 0; i < sortedIndices.length; i++) {
  32396. var idx = sortedIndices[i];
  32397. sortedCurrPoints[i] = currPoints[idx];
  32398. sortedNextPoints[i] = nextPoints[idx];
  32399. sortedCurrStackedPoints[i] = currStackedPoints[idx];
  32400. sortedNextStackedPoints[i] = nextStackedPoints[idx];
  32401. sortedStatus[i] = status[idx];
  32402. }
  32403. return {
  32404. current: sortedCurrPoints,
  32405. next: sortedNextPoints,
  32406. stackedOnCurrent: sortedCurrStackedPoints,
  32407. stackedOnNext: sortedNextStackedPoints,
  32408. status: sortedStatus
  32409. };
  32410. };
  32411. /*
  32412. * Licensed to the Apache Software Foundation (ASF) under one
  32413. * or more contributor license agreements. See the NOTICE file
  32414. * distributed with this work for additional information
  32415. * regarding copyright ownership. The ASF licenses this file
  32416. * to you under the Apache License, Version 2.0 (the
  32417. * "License"); you may not use this file except in compliance
  32418. * with the License. You may obtain a copy of the License at
  32419. *
  32420. * http://www.apache.org/licenses/LICENSE-2.0
  32421. *
  32422. * Unless required by applicable law or agreed to in writing,
  32423. * software distributed under the License is distributed on an
  32424. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  32425. * KIND, either express or implied. See the License for the
  32426. * specific language governing permissions and limitations
  32427. * under the License.
  32428. */
  32429. // Poly path support NaN point
  32430. var vec2Min = min;
  32431. var vec2Max = max;
  32432. var scaleAndAdd$1 = scaleAndAdd;
  32433. var v2Copy = copy;
  32434. // Temporary variable
  32435. var v = [];
  32436. var cp0 = [];
  32437. var cp1 = [];
  32438. function isPointNull(p) {
  32439. return isNaN(p[0]) || isNaN(p[1]);
  32440. }
  32441. function drawSegment(
  32442. ctx, points, start, segLen, allLen,
  32443. dir, smoothMin, smoothMax, smooth, smoothMonotone, connectNulls
  32444. ) {
  32445. // if (smoothMonotone == null) {
  32446. // if (isMono(points, 'x')) {
  32447. // return drawMono(ctx, points, start, segLen, allLen,
  32448. // dir, smoothMin, smoothMax, smooth, 'x', connectNulls);
  32449. // }
  32450. // else if (isMono(points, 'y')) {
  32451. // return drawMono(ctx, points, start, segLen, allLen,
  32452. // dir, smoothMin, smoothMax, smooth, 'y', connectNulls);
  32453. // }
  32454. // else {
  32455. // return drawNonMono.apply(this, arguments);
  32456. // }
  32457. // }
  32458. // else if (smoothMonotone !== 'none' && isMono(points, smoothMonotone)) {
  32459. // return drawMono.apply(this, arguments);
  32460. // }
  32461. // else {
  32462. // return drawNonMono.apply(this, arguments);
  32463. // }
  32464. if (smoothMonotone === 'none' || !smoothMonotone) {
  32465. return drawNonMono.apply(this, arguments);
  32466. }
  32467. else {
  32468. return drawMono.apply(this, arguments);
  32469. }
  32470. }
  32471. /**
  32472. * Check if points is in monotone.
  32473. *
  32474. * @param {number[][]} points Array of points which is in [x, y] form
  32475. * @param {string} smoothMonotone 'x', 'y', or 'none', stating for which
  32476. * dimension that is checking.
  32477. * If is 'none', `drawNonMono` should be
  32478. * called.
  32479. * If is undefined, either being monotone
  32480. * in 'x' or 'y' will call `drawMono`.
  32481. */
  32482. // function isMono(points, smoothMonotone) {
  32483. // if (points.length <= 1) {
  32484. // return true;
  32485. // }
  32486. // var dim = smoothMonotone === 'x' ? 0 : 1;
  32487. // var last = points[0][dim];
  32488. // var lastDiff = 0;
  32489. // for (var i = 1; i < points.length; ++i) {
  32490. // var diff = points[i][dim] - last;
  32491. // if (!isNaN(diff) && !isNaN(lastDiff)
  32492. // && diff !== 0 && lastDiff !== 0
  32493. // && ((diff >= 0) !== (lastDiff >= 0))
  32494. // ) {
  32495. // return false;
  32496. // }
  32497. // if (!isNaN(diff) && diff !== 0) {
  32498. // lastDiff = diff;
  32499. // last = points[i][dim];
  32500. // }
  32501. // }
  32502. // return true;
  32503. // }
  32504. /**
  32505. * Draw smoothed line in monotone, in which only vertical or horizontal bezier
  32506. * control points will be used. This should be used when points are monotone
  32507. * either in x or y dimension.
  32508. */
  32509. function drawMono(
  32510. ctx, points, start, segLen, allLen,
  32511. dir, smoothMin, smoothMax, smooth, smoothMonotone, connectNulls
  32512. ) {
  32513. var prevIdx = 0;
  32514. var idx = start;
  32515. for (var k = 0; k < segLen; k++) {
  32516. var p = points[idx];
  32517. if (idx >= allLen || idx < 0) {
  32518. break;
  32519. }
  32520. if (isPointNull(p)) {
  32521. if (connectNulls) {
  32522. idx += dir;
  32523. continue;
  32524. }
  32525. break;
  32526. }
  32527. if (idx === start) {
  32528. ctx[dir > 0 ? 'moveTo' : 'lineTo'](p[0], p[1]);
  32529. }
  32530. else {
  32531. if (smooth > 0) {
  32532. var prevP = points[prevIdx];
  32533. var dim = smoothMonotone === 'y' ? 1 : 0;
  32534. // Length of control point to p, either in x or y, but not both
  32535. var ctrlLen = (p[dim] - prevP[dim]) * smooth;
  32536. v2Copy(cp0, prevP);
  32537. cp0[dim] = prevP[dim] + ctrlLen;
  32538. v2Copy(cp1, p);
  32539. cp1[dim] = p[dim] - ctrlLen;
  32540. ctx.bezierCurveTo(
  32541. cp0[0], cp0[1],
  32542. cp1[0], cp1[1],
  32543. p[0], p[1]
  32544. );
  32545. }
  32546. else {
  32547. ctx.lineTo(p[0], p[1]);
  32548. }
  32549. }
  32550. prevIdx = idx;
  32551. idx += dir;
  32552. }
  32553. return k;
  32554. }
  32555. /**
  32556. * Draw smoothed line in non-monotone, in may cause undesired curve in extreme
  32557. * situations. This should be used when points are non-monotone neither in x or
  32558. * y dimension.
  32559. */
  32560. function drawNonMono(
  32561. ctx, points, start, segLen, allLen,
  32562. dir, smoothMin, smoothMax, smooth, smoothMonotone, connectNulls
  32563. ) {
  32564. var prevIdx = 0;
  32565. var idx = start;
  32566. for (var k = 0; k < segLen; k++) {
  32567. var p = points[idx];
  32568. if (idx >= allLen || idx < 0) {
  32569. break;
  32570. }
  32571. if (isPointNull(p)) {
  32572. if (connectNulls) {
  32573. idx += dir;
  32574. continue;
  32575. }
  32576. break;
  32577. }
  32578. if (idx === start) {
  32579. ctx[dir > 0 ? 'moveTo' : 'lineTo'](p[0], p[1]);
  32580. v2Copy(cp0, p);
  32581. }
  32582. else {
  32583. if (smooth > 0) {
  32584. var nextIdx = idx + dir;
  32585. var nextP = points[nextIdx];
  32586. if (connectNulls) {
  32587. // Find next point not null
  32588. while (nextP && isPointNull(points[nextIdx])) {
  32589. nextIdx += dir;
  32590. nextP = points[nextIdx];
  32591. }
  32592. }
  32593. var ratioNextSeg = 0.5;
  32594. var prevP = points[prevIdx];
  32595. var nextP = points[nextIdx];
  32596. // Last point
  32597. if (!nextP || isPointNull(nextP)) {
  32598. v2Copy(cp1, p);
  32599. }
  32600. else {
  32601. // If next data is null in not connect case
  32602. if (isPointNull(nextP) && !connectNulls) {
  32603. nextP = p;
  32604. }
  32605. sub(v, nextP, prevP);
  32606. var lenPrevSeg;
  32607. var lenNextSeg;
  32608. if (smoothMonotone === 'x' || smoothMonotone === 'y') {
  32609. var dim = smoothMonotone === 'x' ? 0 : 1;
  32610. lenPrevSeg = Math.abs(p[dim] - prevP[dim]);
  32611. lenNextSeg = Math.abs(p[dim] - nextP[dim]);
  32612. }
  32613. else {
  32614. lenPrevSeg = dist(p, prevP);
  32615. lenNextSeg = dist(p, nextP);
  32616. }
  32617. // Use ratio of seg length
  32618. ratioNextSeg = lenNextSeg / (lenNextSeg + lenPrevSeg);
  32619. scaleAndAdd$1(cp1, p, v, -smooth * (1 - ratioNextSeg));
  32620. }
  32621. // Smooth constraint
  32622. vec2Min(cp0, cp0, smoothMax);
  32623. vec2Max(cp0, cp0, smoothMin);
  32624. vec2Min(cp1, cp1, smoothMax);
  32625. vec2Max(cp1, cp1, smoothMin);
  32626. ctx.bezierCurveTo(
  32627. cp0[0], cp0[1],
  32628. cp1[0], cp1[1],
  32629. p[0], p[1]
  32630. );
  32631. // cp0 of next segment
  32632. scaleAndAdd$1(cp0, p, v, smooth * ratioNextSeg);
  32633. }
  32634. else {
  32635. ctx.lineTo(p[0], p[1]);
  32636. }
  32637. }
  32638. prevIdx = idx;
  32639. idx += dir;
  32640. }
  32641. return k;
  32642. }
  32643. function getBoundingBox(points, smoothConstraint) {
  32644. var ptMin = [Infinity, Infinity];
  32645. var ptMax = [-Infinity, -Infinity];
  32646. if (smoothConstraint) {
  32647. for (var i = 0; i < points.length; i++) {
  32648. var pt = points[i];
  32649. if (pt[0] < ptMin[0]) {
  32650. ptMin[0] = pt[0];
  32651. }
  32652. if (pt[1] < ptMin[1]) {
  32653. ptMin[1] = pt[1];
  32654. }
  32655. if (pt[0] > ptMax[0]) {
  32656. ptMax[0] = pt[0];
  32657. }
  32658. if (pt[1] > ptMax[1]) {
  32659. ptMax[1] = pt[1];
  32660. }
  32661. }
  32662. }
  32663. return {
  32664. min: smoothConstraint ? ptMin : ptMax,
  32665. max: smoothConstraint ? ptMax : ptMin
  32666. };
  32667. }
  32668. var Polyline$1 = Path.extend({
  32669. type: 'ec-polyline',
  32670. shape: {
  32671. points: [],
  32672. smooth: 0,
  32673. smoothConstraint: true,
  32674. smoothMonotone: null,
  32675. connectNulls: false
  32676. },
  32677. style: {
  32678. fill: null,
  32679. stroke: '#000'
  32680. },
  32681. brush: fixClipWithShadow(Path.prototype.brush),
  32682. buildPath: function (ctx, shape) {
  32683. var points = shape.points;
  32684. var i = 0;
  32685. var len$$1 = points.length;
  32686. var result = getBoundingBox(points, shape.smoothConstraint);
  32687. if (shape.connectNulls) {
  32688. // Must remove first and last null values avoid draw error in polygon
  32689. for (; len$$1 > 0; len$$1--) {
  32690. if (!isPointNull(points[len$$1 - 1])) {
  32691. break;
  32692. }
  32693. }
  32694. for (; i < len$$1; i++) {
  32695. if (!isPointNull(points[i])) {
  32696. break;
  32697. }
  32698. }
  32699. }
  32700. while (i < len$$1) {
  32701. i += drawSegment(
  32702. ctx, points, i, len$$1, len$$1,
  32703. 1, result.min, result.max, shape.smooth,
  32704. shape.smoothMonotone, shape.connectNulls
  32705. ) + 1;
  32706. }
  32707. }
  32708. });
  32709. var Polygon$1 = Path.extend({
  32710. type: 'ec-polygon',
  32711. shape: {
  32712. points: [],
  32713. // Offset between stacked base points and points
  32714. stackedOnPoints: [],
  32715. smooth: 0,
  32716. stackedOnSmooth: 0,
  32717. smoothConstraint: true,
  32718. smoothMonotone: null,
  32719. connectNulls: false
  32720. },
  32721. brush: fixClipWithShadow(Path.prototype.brush),
  32722. buildPath: function (ctx, shape) {
  32723. var points = shape.points;
  32724. var stackedOnPoints = shape.stackedOnPoints;
  32725. var i = 0;
  32726. var len$$1 = points.length;
  32727. var smoothMonotone = shape.smoothMonotone;
  32728. var bbox = getBoundingBox(points, shape.smoothConstraint);
  32729. var stackedOnBBox = getBoundingBox(stackedOnPoints, shape.smoothConstraint);
  32730. if (shape.connectNulls) {
  32731. // Must remove first and last null values avoid draw error in polygon
  32732. for (; len$$1 > 0; len$$1--) {
  32733. if (!isPointNull(points[len$$1 - 1])) {
  32734. break;
  32735. }
  32736. }
  32737. for (; i < len$$1; i++) {
  32738. if (!isPointNull(points[i])) {
  32739. break;
  32740. }
  32741. }
  32742. }
  32743. while (i < len$$1) {
  32744. var k = drawSegment(
  32745. ctx, points, i, len$$1, len$$1,
  32746. 1, bbox.min, bbox.max, shape.smooth,
  32747. smoothMonotone, shape.connectNulls
  32748. );
  32749. drawSegment(
  32750. ctx, stackedOnPoints, i + k - 1, k, len$$1,
  32751. -1, stackedOnBBox.min, stackedOnBBox.max, shape.stackedOnSmooth,
  32752. smoothMonotone, shape.connectNulls
  32753. );
  32754. i += k + 1;
  32755. ctx.closePath();
  32756. }
  32757. }
  32758. });
  32759. /*
  32760. * Licensed to the Apache Software Foundation (ASF) under one
  32761. * or more contributor license agreements. See the NOTICE file
  32762. * distributed with this work for additional information
  32763. * regarding copyright ownership. The ASF licenses this file
  32764. * to you under the Apache License, Version 2.0 (the
  32765. * "License"); you may not use this file except in compliance
  32766. * with the License. You may obtain a copy of the License at
  32767. *
  32768. * http://www.apache.org/licenses/LICENSE-2.0
  32769. *
  32770. * Unless required by applicable law or agreed to in writing,
  32771. * software distributed under the License is distributed on an
  32772. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  32773. * KIND, either express or implied. See the License for the
  32774. * specific language governing permissions and limitations
  32775. * under the License.
  32776. */
  32777. // FIXME step not support polar
  32778. function isPointsSame(points1, points2) {
  32779. if (points1.length !== points2.length) {
  32780. return;
  32781. }
  32782. for (var i = 0; i < points1.length; i++) {
  32783. var p1 = points1[i];
  32784. var p2 = points2[i];
  32785. if (p1[0] !== p2[0] || p1[1] !== p2[1]) {
  32786. return;
  32787. }
  32788. }
  32789. return true;
  32790. }
  32791. function getSmooth(smooth) {
  32792. return typeof (smooth) === 'number' ? smooth : (smooth ? 0.5 : 0);
  32793. }
  32794. function getAxisExtentWithGap(axis) {
  32795. var extent = axis.getGlobalExtent();
  32796. if (axis.onBand) {
  32797. // Remove extra 1px to avoid line miter in clipped edge
  32798. var halfBandWidth = axis.getBandWidth() / 2 - 1;
  32799. var dir = extent[1] > extent[0] ? 1 : -1;
  32800. extent[0] += dir * halfBandWidth;
  32801. extent[1] -= dir * halfBandWidth;
  32802. }
  32803. return extent;
  32804. }
  32805. /**
  32806. * @param {module:echarts/coord/cartesian/Cartesian2D|module:echarts/coord/polar/Polar} coordSys
  32807. * @param {module:echarts/data/List} data
  32808. * @param {Object} dataCoordInfo
  32809. * @param {Array.<Array.<number>>} points
  32810. */
  32811. function getStackedOnPoints(coordSys, data, dataCoordInfo) {
  32812. if (!dataCoordInfo.valueDim) {
  32813. return [];
  32814. }
  32815. var points = [];
  32816. for (var idx = 0, len = data.count(); idx < len; idx++) {
  32817. points.push(getStackedOnPoint(dataCoordInfo, coordSys, data, idx));
  32818. }
  32819. return points;
  32820. }
  32821. function createGridClipShape(cartesian, hasAnimation, forSymbol, seriesModel) {
  32822. var xExtent = getAxisExtentWithGap(cartesian.getAxis('x'));
  32823. var yExtent = getAxisExtentWithGap(cartesian.getAxis('y'));
  32824. var isHorizontal = cartesian.getBaseAxis().isHorizontal();
  32825. var x = Math.min(xExtent[0], xExtent[1]);
  32826. var y = Math.min(yExtent[0], yExtent[1]);
  32827. var width = Math.max(xExtent[0], xExtent[1]) - x;
  32828. var height = Math.max(yExtent[0], yExtent[1]) - y;
  32829. // Avoid float number rounding error for symbol on the edge of axis extent.
  32830. // See #7913 and `test/dataZoom-clip.html`.
  32831. if (forSymbol) {
  32832. x -= 0.5;
  32833. width += 0.5;
  32834. y -= 0.5;
  32835. height += 0.5;
  32836. }
  32837. else {
  32838. var lineWidth = seriesModel.get('lineStyle.width') || 2;
  32839. // Expand clip shape to avoid clipping when line value exceeds axis
  32840. var expandSize = seriesModel.get('clipOverflow') ? lineWidth / 2 : Math.max(width, height);
  32841. if (isHorizontal) {
  32842. y -= expandSize;
  32843. height += expandSize * 2;
  32844. }
  32845. else {
  32846. x -= expandSize;
  32847. width += expandSize * 2;
  32848. }
  32849. }
  32850. var clipPath = new Rect({
  32851. shape: {
  32852. x: x,
  32853. y: y,
  32854. width: width,
  32855. height: height
  32856. }
  32857. });
  32858. if (hasAnimation) {
  32859. clipPath.shape[isHorizontal ? 'width' : 'height'] = 0;
  32860. initProps(clipPath, {
  32861. shape: {
  32862. width: width,
  32863. height: height
  32864. }
  32865. }, seriesModel);
  32866. }
  32867. return clipPath;
  32868. }
  32869. function createPolarClipShape(polar, hasAnimation, forSymbol, seriesModel) {
  32870. var angleAxis = polar.getAngleAxis();
  32871. var radiusAxis = polar.getRadiusAxis();
  32872. var radiusExtent = radiusAxis.getExtent().slice();
  32873. radiusExtent[0] > radiusExtent[1] && radiusExtent.reverse();
  32874. var angleExtent = angleAxis.getExtent();
  32875. var RADIAN = Math.PI / 180;
  32876. // Avoid float number rounding error for symbol on the edge of axis extent.
  32877. if (forSymbol) {
  32878. radiusExtent[0] -= 0.5;
  32879. radiusExtent[1] += 0.5;
  32880. }
  32881. var clipPath = new Sector({
  32882. shape: {
  32883. cx: round$1(polar.cx, 1),
  32884. cy: round$1(polar.cy, 1),
  32885. r0: round$1(radiusExtent[0], 1),
  32886. r: round$1(radiusExtent[1], 1),
  32887. startAngle: -angleExtent[0] * RADIAN,
  32888. endAngle: -angleExtent[1] * RADIAN,
  32889. clockwise: angleAxis.inverse
  32890. }
  32891. });
  32892. if (hasAnimation) {
  32893. clipPath.shape.endAngle = -angleExtent[0] * RADIAN;
  32894. initProps(clipPath, {
  32895. shape: {
  32896. endAngle: -angleExtent[1] * RADIAN
  32897. }
  32898. }, seriesModel);
  32899. }
  32900. return clipPath;
  32901. }
  32902. function createClipShape(coordSys, hasAnimation, forSymbol, seriesModel) {
  32903. return coordSys.type === 'polar'
  32904. ? createPolarClipShape(coordSys, hasAnimation, forSymbol, seriesModel)
  32905. : createGridClipShape(coordSys, hasAnimation, forSymbol, seriesModel);
  32906. }
  32907. function turnPointsIntoStep(points, coordSys, stepTurnAt) {
  32908. var baseAxis = coordSys.getBaseAxis();
  32909. var baseIndex = baseAxis.dim === 'x' || baseAxis.dim === 'radius' ? 0 : 1;
  32910. var stepPoints = [];
  32911. for (var i = 0; i < points.length - 1; i++) {
  32912. var nextPt = points[i + 1];
  32913. var pt = points[i];
  32914. stepPoints.push(pt);
  32915. var stepPt = [];
  32916. switch (stepTurnAt) {
  32917. case 'end':
  32918. stepPt[baseIndex] = nextPt[baseIndex];
  32919. stepPt[1 - baseIndex] = pt[1 - baseIndex];
  32920. // default is start
  32921. stepPoints.push(stepPt);
  32922. break;
  32923. case 'middle':
  32924. // default is start
  32925. var middle = (pt[baseIndex] + nextPt[baseIndex]) / 2;
  32926. var stepPt2 = [];
  32927. stepPt[baseIndex] = stepPt2[baseIndex] = middle;
  32928. stepPt[1 - baseIndex] = pt[1 - baseIndex];
  32929. stepPt2[1 - baseIndex] = nextPt[1 - baseIndex];
  32930. stepPoints.push(stepPt);
  32931. stepPoints.push(stepPt2);
  32932. break;
  32933. default:
  32934. stepPt[baseIndex] = pt[baseIndex];
  32935. stepPt[1 - baseIndex] = nextPt[1 - baseIndex];
  32936. // default is start
  32937. stepPoints.push(stepPt);
  32938. }
  32939. }
  32940. // Last points
  32941. points[i] && stepPoints.push(points[i]);
  32942. return stepPoints;
  32943. }
  32944. function getVisualGradient(data, coordSys) {
  32945. var visualMetaList = data.getVisual('visualMeta');
  32946. if (!visualMetaList || !visualMetaList.length || !data.count()) {
  32947. // When data.count() is 0, gradient range can not be calculated.
  32948. return;
  32949. }
  32950. if (coordSys.type !== 'cartesian2d') {
  32951. if (__DEV__) {
  32952. console.warn('Visual map on line style is only supported on cartesian2d.');
  32953. }
  32954. return;
  32955. }
  32956. var coordDim;
  32957. var visualMeta;
  32958. for (var i = visualMetaList.length - 1; i >= 0; i--) {
  32959. var dimIndex = visualMetaList[i].dimension;
  32960. var dimName = data.dimensions[dimIndex];
  32961. var dimInfo = data.getDimensionInfo(dimName);
  32962. coordDim = dimInfo && dimInfo.coordDim;
  32963. // Can only be x or y
  32964. if (coordDim === 'x' || coordDim === 'y') {
  32965. visualMeta = visualMetaList[i];
  32966. break;
  32967. }
  32968. }
  32969. if (!visualMeta) {
  32970. if (__DEV__) {
  32971. console.warn('Visual map on line style only support x or y dimension.');
  32972. }
  32973. return;
  32974. }
  32975. // If the area to be rendered is bigger than area defined by LinearGradient,
  32976. // the canvas spec prescribes that the color of the first stop and the last
  32977. // stop should be used. But if two stops are added at offset 0, in effect
  32978. // browsers use the color of the second stop to render area outside
  32979. // LinearGradient. So we can only infinitesimally extend area defined in
  32980. // LinearGradient to render `outerColors`.
  32981. var axis = coordSys.getAxis(coordDim);
  32982. // dataToCoor mapping may not be linear, but must be monotonic.
  32983. var colorStops = map(visualMeta.stops, function (stop) {
  32984. return {
  32985. coord: axis.toGlobalCoord(axis.dataToCoord(stop.value)),
  32986. color: stop.color
  32987. };
  32988. });
  32989. var stopLen = colorStops.length;
  32990. var outerColors = visualMeta.outerColors.slice();
  32991. if (stopLen && colorStops[0].coord > colorStops[stopLen - 1].coord) {
  32992. colorStops.reverse();
  32993. outerColors.reverse();
  32994. }
  32995. var tinyExtent = 10; // Arbitrary value: 10px
  32996. var minCoord = colorStops[0].coord - tinyExtent;
  32997. var maxCoord = colorStops[stopLen - 1].coord + tinyExtent;
  32998. var coordSpan = maxCoord - minCoord;
  32999. if (coordSpan < 1e-3) {
  33000. return 'transparent';
  33001. }
  33002. each$1(colorStops, function (stop) {
  33003. stop.offset = (stop.coord - minCoord) / coordSpan;
  33004. });
  33005. colorStops.push({
  33006. offset: stopLen ? colorStops[stopLen - 1].offset : 0.5,
  33007. color: outerColors[1] || 'transparent'
  33008. });
  33009. colorStops.unshift({ // notice colorStops.length have been changed.
  33010. offset: stopLen ? colorStops[0].offset : 0.5,
  33011. color: outerColors[0] || 'transparent'
  33012. });
  33013. // zrUtil.each(colorStops, function (colorStop) {
  33014. // // Make sure each offset has rounded px to avoid not sharp edge
  33015. // colorStop.offset = (Math.round(colorStop.offset * (end - start) + start) - start) / (end - start);
  33016. // });
  33017. var gradient = new LinearGradient(0, 0, 0, 0, colorStops, true);
  33018. gradient[coordDim] = minCoord;
  33019. gradient[coordDim + '2'] = maxCoord;
  33020. return gradient;
  33021. }
  33022. function getIsIgnoreFunc(seriesModel, data, coordSys) {
  33023. var showAllSymbol = seriesModel.get('showAllSymbol');
  33024. var isAuto = showAllSymbol === 'auto';
  33025. if (showAllSymbol && !isAuto) {
  33026. return;
  33027. }
  33028. var categoryAxis = coordSys.getAxesByScale('ordinal')[0];
  33029. if (!categoryAxis) {
  33030. return;
  33031. }
  33032. // Note that category label interval strategy might bring some weird effect
  33033. // in some scenario: users may wonder why some of the symbols are not
  33034. // displayed. So we show all symbols as possible as we can.
  33035. if (isAuto
  33036. // Simplify the logic, do not determine label overlap here.
  33037. && canShowAllSymbolForCategory(categoryAxis, data)
  33038. ) {
  33039. return;
  33040. }
  33041. // Otherwise follow the label interval strategy on category axis.
  33042. var categoryDataDim = data.mapDimension(categoryAxis.dim);
  33043. var labelMap = {};
  33044. each$1(categoryAxis.getViewLabels(), function (labelItem) {
  33045. labelMap[labelItem.tickValue] = 1;
  33046. });
  33047. return function (dataIndex) {
  33048. return !labelMap.hasOwnProperty(data.get(categoryDataDim, dataIndex));
  33049. };
  33050. }
  33051. function canShowAllSymbolForCategory(categoryAxis, data) {
  33052. // In mose cases, line is monotonous on category axis, and the label size
  33053. // is close with each other. So we check the symbol size and some of the
  33054. // label size alone with the category axis to estimate whether all symbol
  33055. // can be shown without overlap.
  33056. var axisExtent = categoryAxis.getExtent();
  33057. var availSize = Math.abs(axisExtent[1] - axisExtent[0]) / categoryAxis.scale.count();
  33058. isNaN(availSize) && (availSize = 0); // 0/0 is NaN.
  33059. // Sampling some points, max 5.
  33060. var dataLen = data.count();
  33061. var step = Math.max(1, Math.round(dataLen / 5));
  33062. for (var dataIndex = 0; dataIndex < dataLen; dataIndex += step) {
  33063. if (SymbolClz$1.getSymbolSize(
  33064. data, dataIndex
  33065. // Only for cartesian, where `isHorizontal` exists.
  33066. )[categoryAxis.isHorizontal() ? 1 : 0]
  33067. // Empirical number
  33068. * 1.5 > availSize
  33069. ) {
  33070. return false;
  33071. }
  33072. }
  33073. return true;
  33074. }
  33075. Chart.extend({
  33076. type: 'line',
  33077. init: function () {
  33078. var lineGroup = new Group();
  33079. var symbolDraw = new SymbolDraw();
  33080. this.group.add(symbolDraw.group);
  33081. this._symbolDraw = symbolDraw;
  33082. this._lineGroup = lineGroup;
  33083. },
  33084. render: function (seriesModel, ecModel, api) {
  33085. var coordSys = seriesModel.coordinateSystem;
  33086. var group = this.group;
  33087. var data = seriesModel.getData();
  33088. var lineStyleModel = seriesModel.getModel('lineStyle');
  33089. var areaStyleModel = seriesModel.getModel('areaStyle');
  33090. var points = data.mapArray(data.getItemLayout);
  33091. var isCoordSysPolar = coordSys.type === 'polar';
  33092. var prevCoordSys = this._coordSys;
  33093. var symbolDraw = this._symbolDraw;
  33094. var polyline = this._polyline;
  33095. var polygon = this._polygon;
  33096. var lineGroup = this._lineGroup;
  33097. var hasAnimation = seriesModel.get('animation');
  33098. var isAreaChart = !areaStyleModel.isEmpty();
  33099. var valueOrigin = areaStyleModel.get('origin');
  33100. var dataCoordInfo = prepareDataCoordInfo(coordSys, data, valueOrigin);
  33101. var stackedOnPoints = getStackedOnPoints(coordSys, data, dataCoordInfo);
  33102. var showSymbol = seriesModel.get('showSymbol');
  33103. var isIgnoreFunc = showSymbol && !isCoordSysPolar
  33104. && getIsIgnoreFunc(seriesModel, data, coordSys);
  33105. // Remove temporary symbols
  33106. var oldData = this._data;
  33107. oldData && oldData.eachItemGraphicEl(function (el, idx) {
  33108. if (el.__temp) {
  33109. group.remove(el);
  33110. oldData.setItemGraphicEl(idx, null);
  33111. }
  33112. });
  33113. // Remove previous created symbols if showSymbol changed to false
  33114. if (!showSymbol) {
  33115. symbolDraw.remove();
  33116. }
  33117. group.add(lineGroup);
  33118. // FIXME step not support polar
  33119. var step = !isCoordSysPolar && seriesModel.get('step');
  33120. // Initialization animation or coordinate system changed
  33121. if (
  33122. !(polyline && prevCoordSys.type === coordSys.type && step === this._step)
  33123. ) {
  33124. showSymbol && symbolDraw.updateData(data, {
  33125. isIgnore: isIgnoreFunc,
  33126. clipShape: createClipShape(coordSys, false, true, seriesModel)
  33127. });
  33128. if (step) {
  33129. // TODO If stacked series is not step
  33130. points = turnPointsIntoStep(points, coordSys, step);
  33131. stackedOnPoints = turnPointsIntoStep(stackedOnPoints, coordSys, step);
  33132. }
  33133. polyline = this._newPolyline(points, coordSys, hasAnimation);
  33134. if (isAreaChart) {
  33135. polygon = this._newPolygon(
  33136. points, stackedOnPoints,
  33137. coordSys, hasAnimation
  33138. );
  33139. }
  33140. lineGroup.setClipPath(createClipShape(coordSys, true, false, seriesModel));
  33141. }
  33142. else {
  33143. if (isAreaChart && !polygon) {
  33144. // If areaStyle is added
  33145. polygon = this._newPolygon(
  33146. points, stackedOnPoints,
  33147. coordSys, hasAnimation
  33148. );
  33149. }
  33150. else if (polygon && !isAreaChart) {
  33151. // If areaStyle is removed
  33152. lineGroup.remove(polygon);
  33153. polygon = this._polygon = null;
  33154. }
  33155. // Update clipPath
  33156. lineGroup.setClipPath(createClipShape(coordSys, false, false, seriesModel));
  33157. // Always update, or it is wrong in the case turning on legend
  33158. // because points are not changed
  33159. showSymbol && symbolDraw.updateData(data, {
  33160. isIgnore: isIgnoreFunc,
  33161. clipShape: createClipShape(coordSys, false, true, seriesModel)
  33162. });
  33163. // Stop symbol animation and sync with line points
  33164. // FIXME performance?
  33165. data.eachItemGraphicEl(function (el) {
  33166. el.stopAnimation(true);
  33167. });
  33168. // In the case data zoom triggerred refreshing frequently
  33169. // Data may not change if line has a category axis. So it should animate nothing
  33170. if (!isPointsSame(this._stackedOnPoints, stackedOnPoints)
  33171. || !isPointsSame(this._points, points)
  33172. ) {
  33173. if (hasAnimation) {
  33174. this._updateAnimation(
  33175. data, stackedOnPoints, coordSys, api, step, valueOrigin
  33176. );
  33177. }
  33178. else {
  33179. // Not do it in update with animation
  33180. if (step) {
  33181. // TODO If stacked series is not step
  33182. points = turnPointsIntoStep(points, coordSys, step);
  33183. stackedOnPoints = turnPointsIntoStep(stackedOnPoints, coordSys, step);
  33184. }
  33185. polyline.setShape({
  33186. points: points
  33187. });
  33188. polygon && polygon.setShape({
  33189. points: points,
  33190. stackedOnPoints: stackedOnPoints
  33191. });
  33192. }
  33193. }
  33194. }
  33195. var visualColor = getVisualGradient(data, coordSys) || data.getVisual('color');
  33196. polyline.useStyle(defaults(
  33197. // Use color in lineStyle first
  33198. lineStyleModel.getLineStyle(),
  33199. {
  33200. fill: 'none',
  33201. stroke: visualColor,
  33202. lineJoin: 'bevel'
  33203. }
  33204. ));
  33205. var smooth = seriesModel.get('smooth');
  33206. smooth = getSmooth(seriesModel.get('smooth'));
  33207. polyline.setShape({
  33208. smooth: smooth,
  33209. smoothMonotone: seriesModel.get('smoothMonotone'),
  33210. connectNulls: seriesModel.get('connectNulls')
  33211. });
  33212. if (polygon) {
  33213. var stackedOnSeries = data.getCalculationInfo('stackedOnSeries');
  33214. var stackedOnSmooth = 0;
  33215. polygon.useStyle(defaults(
  33216. areaStyleModel.getAreaStyle(),
  33217. {
  33218. fill: visualColor,
  33219. opacity: 0.7,
  33220. lineJoin: 'bevel'
  33221. }
  33222. ));
  33223. if (stackedOnSeries) {
  33224. stackedOnSmooth = getSmooth(stackedOnSeries.get('smooth'));
  33225. }
  33226. polygon.setShape({
  33227. smooth: smooth,
  33228. stackedOnSmooth: stackedOnSmooth,
  33229. smoothMonotone: seriesModel.get('smoothMonotone'),
  33230. connectNulls: seriesModel.get('connectNulls')
  33231. });
  33232. }
  33233. this._data = data;
  33234. // Save the coordinate system for transition animation when data changed
  33235. this._coordSys = coordSys;
  33236. this._stackedOnPoints = stackedOnPoints;
  33237. this._points = points;
  33238. this._step = step;
  33239. this._valueOrigin = valueOrigin;
  33240. },
  33241. dispose: function () {},
  33242. highlight: function (seriesModel, ecModel, api, payload) {
  33243. var data = seriesModel.getData();
  33244. var dataIndex = queryDataIndex(data, payload);
  33245. if (!(dataIndex instanceof Array) && dataIndex != null && dataIndex >= 0) {
  33246. var symbol = data.getItemGraphicEl(dataIndex);
  33247. if (!symbol) {
  33248. // Create a temporary symbol if it is not exists
  33249. var pt = data.getItemLayout(dataIndex);
  33250. if (!pt) {
  33251. // Null data
  33252. return;
  33253. }
  33254. symbol = new SymbolClz$1(data, dataIndex);
  33255. symbol.position = pt;
  33256. symbol.setZ(
  33257. seriesModel.get('zlevel'),
  33258. seriesModel.get('z')
  33259. );
  33260. symbol.ignore = isNaN(pt[0]) || isNaN(pt[1]);
  33261. symbol.__temp = true;
  33262. data.setItemGraphicEl(dataIndex, symbol);
  33263. // Stop scale animation
  33264. symbol.stopSymbolAnimation(true);
  33265. this.group.add(symbol);
  33266. }
  33267. symbol.highlight();
  33268. }
  33269. else {
  33270. // Highlight whole series
  33271. Chart.prototype.highlight.call(
  33272. this, seriesModel, ecModel, api, payload
  33273. );
  33274. }
  33275. },
  33276. downplay: function (seriesModel, ecModel, api, payload) {
  33277. var data = seriesModel.getData();
  33278. var dataIndex = queryDataIndex(data, payload);
  33279. if (dataIndex != null && dataIndex >= 0) {
  33280. var symbol = data.getItemGraphicEl(dataIndex);
  33281. if (symbol) {
  33282. if (symbol.__temp) {
  33283. data.setItemGraphicEl(dataIndex, null);
  33284. this.group.remove(symbol);
  33285. }
  33286. else {
  33287. symbol.downplay();
  33288. }
  33289. }
  33290. }
  33291. else {
  33292. // FIXME
  33293. // can not downplay completely.
  33294. // Downplay whole series
  33295. Chart.prototype.downplay.call(
  33296. this, seriesModel, ecModel, api, payload
  33297. );
  33298. }
  33299. },
  33300. /**
  33301. * @param {module:zrender/container/Group} group
  33302. * @param {Array.<Array.<number>>} points
  33303. * @private
  33304. */
  33305. _newPolyline: function (points) {
  33306. var polyline = this._polyline;
  33307. // Remove previous created polyline
  33308. if (polyline) {
  33309. this._lineGroup.remove(polyline);
  33310. }
  33311. polyline = new Polyline$1({
  33312. shape: {
  33313. points: points
  33314. },
  33315. silent: true,
  33316. z2: 10
  33317. });
  33318. this._lineGroup.add(polyline);
  33319. this._polyline = polyline;
  33320. return polyline;
  33321. },
  33322. /**
  33323. * @param {module:zrender/container/Group} group
  33324. * @param {Array.<Array.<number>>} stackedOnPoints
  33325. * @param {Array.<Array.<number>>} points
  33326. * @private
  33327. */
  33328. _newPolygon: function (points, stackedOnPoints) {
  33329. var polygon = this._polygon;
  33330. // Remove previous created polygon
  33331. if (polygon) {
  33332. this._lineGroup.remove(polygon);
  33333. }
  33334. polygon = new Polygon$1({
  33335. shape: {
  33336. points: points,
  33337. stackedOnPoints: stackedOnPoints
  33338. },
  33339. silent: true
  33340. });
  33341. this._lineGroup.add(polygon);
  33342. this._polygon = polygon;
  33343. return polygon;
  33344. },
  33345. /**
  33346. * @private
  33347. */
  33348. // FIXME Two value axis
  33349. _updateAnimation: function (data, stackedOnPoints, coordSys, api, step, valueOrigin) {
  33350. var polyline = this._polyline;
  33351. var polygon = this._polygon;
  33352. var seriesModel = data.hostModel;
  33353. var diff = lineAnimationDiff(
  33354. this._data, data,
  33355. this._stackedOnPoints, stackedOnPoints,
  33356. this._coordSys, coordSys,
  33357. this._valueOrigin, valueOrigin
  33358. );
  33359. var current = diff.current;
  33360. var stackedOnCurrent = diff.stackedOnCurrent;
  33361. var next = diff.next;
  33362. var stackedOnNext = diff.stackedOnNext;
  33363. if (step) {
  33364. // TODO If stacked series is not step
  33365. current = turnPointsIntoStep(diff.current, coordSys, step);
  33366. stackedOnCurrent = turnPointsIntoStep(diff.stackedOnCurrent, coordSys, step);
  33367. next = turnPointsIntoStep(diff.next, coordSys, step);
  33368. stackedOnNext = turnPointsIntoStep(diff.stackedOnNext, coordSys, step);
  33369. }
  33370. // `diff.current` is subset of `current` (which should be ensured by
  33371. // turnPointsIntoStep), so points in `__points` can be updated when
  33372. // points in `current` are update during animation.
  33373. polyline.shape.__points = diff.current;
  33374. polyline.shape.points = current;
  33375. updateProps(polyline, {
  33376. shape: {
  33377. points: next
  33378. }
  33379. }, seriesModel);
  33380. if (polygon) {
  33381. polygon.setShape({
  33382. points: current,
  33383. stackedOnPoints: stackedOnCurrent
  33384. });
  33385. updateProps(polygon, {
  33386. shape: {
  33387. points: next,
  33388. stackedOnPoints: stackedOnNext
  33389. }
  33390. }, seriesModel);
  33391. }
  33392. var updatedDataInfo = [];
  33393. var diffStatus = diff.status;
  33394. for (var i = 0; i < diffStatus.length; i++) {
  33395. var cmd = diffStatus[i].cmd;
  33396. if (cmd === '=') {
  33397. var el = data.getItemGraphicEl(diffStatus[i].idx1);
  33398. if (el) {
  33399. updatedDataInfo.push({
  33400. el: el,
  33401. ptIdx: i // Index of points
  33402. });
  33403. }
  33404. }
  33405. }
  33406. if (polyline.animators && polyline.animators.length) {
  33407. polyline.animators[0].during(function () {
  33408. for (var i = 0; i < updatedDataInfo.length; i++) {
  33409. var el = updatedDataInfo[i].el;
  33410. el.attr('position', polyline.shape.__points[updatedDataInfo[i].ptIdx]);
  33411. }
  33412. });
  33413. }
  33414. },
  33415. remove: function (ecModel) {
  33416. var group = this.group;
  33417. var oldData = this._data;
  33418. this._lineGroup.removeAll();
  33419. this._symbolDraw.remove(true);
  33420. // Remove temporary created elements when highlighting
  33421. oldData && oldData.eachItemGraphicEl(function (el, idx) {
  33422. if (el.__temp) {
  33423. group.remove(el);
  33424. oldData.setItemGraphicEl(idx, null);
  33425. }
  33426. });
  33427. this._polyline
  33428. = this._polygon
  33429. = this._coordSys
  33430. = this._points
  33431. = this._stackedOnPoints
  33432. = this._data = null;
  33433. }
  33434. });
  33435. /*
  33436. * Licensed to the Apache Software Foundation (ASF) under one
  33437. * or more contributor license agreements. See the NOTICE file
  33438. * distributed with this work for additional information
  33439. * regarding copyright ownership. The ASF licenses this file
  33440. * to you under the Apache License, Version 2.0 (the
  33441. * "License"); you may not use this file except in compliance
  33442. * with the License. You may obtain a copy of the License at
  33443. *
  33444. * http://www.apache.org/licenses/LICENSE-2.0
  33445. *
  33446. * Unless required by applicable law or agreed to in writing,
  33447. * software distributed under the License is distributed on an
  33448. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  33449. * KIND, either express or implied. See the License for the
  33450. * specific language governing permissions and limitations
  33451. * under the License.
  33452. */
  33453. var visualSymbol = function (seriesType, defaultSymbolType, legendSymbol) {
  33454. // Encoding visual for all series include which is filtered for legend drawing
  33455. return {
  33456. seriesType: seriesType,
  33457. // For legend.
  33458. performRawSeries: true,
  33459. reset: function (seriesModel, ecModel, api) {
  33460. var data = seriesModel.getData();
  33461. var symbolType = seriesModel.get('symbol');
  33462. var symbolSize = seriesModel.get('symbolSize');
  33463. var keepAspect = seriesModel.get('symbolKeepAspect');
  33464. var hasSymbolTypeCallback = isFunction$1(symbolType);
  33465. var hasSymbolSizeCallback = isFunction$1(symbolSize);
  33466. var hasCallback = hasSymbolTypeCallback || hasSymbolSizeCallback;
  33467. var seriesSymbol = (!hasSymbolTypeCallback && symbolType) ? symbolType : defaultSymbolType;
  33468. var seriesSymbolSize = !hasSymbolSizeCallback ? symbolSize : null;
  33469. data.setVisual({
  33470. legendSymbol: legendSymbol || seriesSymbol,
  33471. // If seting callback functions on `symbol` or `symbolSize`, for simplicity and avoiding
  33472. // to bring trouble, we do not pick a reuslt from one of its calling on data item here,
  33473. // but just use the default value. Callback on `symbol` or `symbolSize` is convenient in
  33474. // some cases but generally it is not recommanded.
  33475. symbol: seriesSymbol,
  33476. symbolSize: seriesSymbolSize,
  33477. symbolKeepAspect: keepAspect
  33478. });
  33479. // Only visible series has each data be visual encoded
  33480. if (ecModel.isSeriesFiltered(seriesModel)) {
  33481. return;
  33482. }
  33483. function dataEach(data, idx) {
  33484. if (hasCallback) {
  33485. var rawValue = seriesModel.getRawValue(idx);
  33486. var params = seriesModel.getDataParams(idx);
  33487. hasSymbolTypeCallback && data.setItemVisual(idx, 'symbol', symbolType(rawValue, params));
  33488. hasSymbolSizeCallback && data.setItemVisual(idx, 'symbolSize', symbolSize(rawValue, params));
  33489. }
  33490. if (data.hasItemOption) {
  33491. var itemModel = data.getItemModel(idx);
  33492. var itemSymbolType = itemModel.getShallow('symbol', true);
  33493. var itemSymbolSize = itemModel.getShallow('symbolSize', true);
  33494. var itemSymbolKeepAspect = itemModel.getShallow('symbolKeepAspect', true);
  33495. // If has item symbol
  33496. if (itemSymbolType != null) {
  33497. data.setItemVisual(idx, 'symbol', itemSymbolType);
  33498. }
  33499. if (itemSymbolSize != null) {
  33500. // PENDING Transform symbolSize ?
  33501. data.setItemVisual(idx, 'symbolSize', itemSymbolSize);
  33502. }
  33503. if (itemSymbolKeepAspect != null) {
  33504. data.setItemVisual(idx, 'symbolKeepAspect', itemSymbolKeepAspect);
  33505. }
  33506. }
  33507. }
  33508. return { dataEach: (data.hasItemOption || hasCallback) ? dataEach : null };
  33509. }
  33510. };
  33511. };
  33512. /*
  33513. * Licensed to the Apache Software Foundation (ASF) under one
  33514. * or more contributor license agreements. See the NOTICE file
  33515. * distributed with this work for additional information
  33516. * regarding copyright ownership. The ASF licenses this file
  33517. * to you under the Apache License, Version 2.0 (the
  33518. * "License"); you may not use this file except in compliance
  33519. * with the License. You may obtain a copy of the License at
  33520. *
  33521. * http://www.apache.org/licenses/LICENSE-2.0
  33522. *
  33523. * Unless required by applicable law or agreed to in writing,
  33524. * software distributed under the License is distributed on an
  33525. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  33526. * KIND, either express or implied. See the License for the
  33527. * specific language governing permissions and limitations
  33528. * under the License.
  33529. */
  33530. /* global Float32Array */
  33531. var pointsLayout = function (seriesType) {
  33532. return {
  33533. seriesType: seriesType,
  33534. plan: createRenderPlanner(),
  33535. reset: function (seriesModel) {
  33536. var data = seriesModel.getData();
  33537. var coordSys = seriesModel.coordinateSystem;
  33538. var pipelineContext = seriesModel.pipelineContext;
  33539. var isLargeRender = pipelineContext.large;
  33540. if (!coordSys) {
  33541. return;
  33542. }
  33543. var dims = map(coordSys.dimensions, function (dim) {
  33544. return data.mapDimension(dim);
  33545. }).slice(0, 2);
  33546. var dimLen = dims.length;
  33547. var stackResultDim = data.getCalculationInfo('stackResultDimension');
  33548. if (isDimensionStacked(data, dims[0] /*, dims[1]*/)) {
  33549. dims[0] = stackResultDim;
  33550. }
  33551. if (isDimensionStacked(data, dims[1] /*, dims[0]*/)) {
  33552. dims[1] = stackResultDim;
  33553. }
  33554. function progress(params, data) {
  33555. var segCount = params.end - params.start;
  33556. var points = isLargeRender && new Float32Array(segCount * dimLen);
  33557. for (var i = params.start, offset = 0, tmpIn = [], tmpOut = []; i < params.end; i++) {
  33558. var point;
  33559. if (dimLen === 1) {
  33560. var x = data.get(dims[0], i);
  33561. point = !isNaN(x) && coordSys.dataToPoint(x, null, tmpOut);
  33562. }
  33563. else {
  33564. var x = tmpIn[0] = data.get(dims[0], i);
  33565. var y = tmpIn[1] = data.get(dims[1], i);
  33566. // Also {Array.<number>}, not undefined to avoid if...else... statement
  33567. point = !isNaN(x) && !isNaN(y) && coordSys.dataToPoint(tmpIn, null, tmpOut);
  33568. }
  33569. if (isLargeRender) {
  33570. points[offset++] = point ? point[0] : NaN;
  33571. points[offset++] = point ? point[1] : NaN;
  33572. }
  33573. else {
  33574. data.setItemLayout(i, (point && point.slice()) || [NaN, NaN]);
  33575. }
  33576. }
  33577. isLargeRender && data.setLayout('symbolPoints', points);
  33578. }
  33579. return dimLen && {progress: progress};
  33580. }
  33581. };
  33582. };
  33583. /*
  33584. * Licensed to the Apache Software Foundation (ASF) under one
  33585. * or more contributor license agreements. See the NOTICE file
  33586. * distributed with this work for additional information
  33587. * regarding copyright ownership. The ASF licenses this file
  33588. * to you under the Apache License, Version 2.0 (the
  33589. * "License"); you may not use this file except in compliance
  33590. * with the License. You may obtain a copy of the License at
  33591. *
  33592. * http://www.apache.org/licenses/LICENSE-2.0
  33593. *
  33594. * Unless required by applicable law or agreed to in writing,
  33595. * software distributed under the License is distributed on an
  33596. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  33597. * KIND, either express or implied. See the License for the
  33598. * specific language governing permissions and limitations
  33599. * under the License.
  33600. */
  33601. var samplers = {
  33602. average: function (frame) {
  33603. var sum = 0;
  33604. var count = 0;
  33605. for (var i = 0; i < frame.length; i++) {
  33606. if (!isNaN(frame[i])) {
  33607. sum += frame[i];
  33608. count++;
  33609. }
  33610. }
  33611. // Return NaN if count is 0
  33612. return count === 0 ? NaN : sum / count;
  33613. },
  33614. sum: function (frame) {
  33615. var sum = 0;
  33616. for (var i = 0; i < frame.length; i++) {
  33617. // Ignore NaN
  33618. sum += frame[i] || 0;
  33619. }
  33620. return sum;
  33621. },
  33622. max: function (frame) {
  33623. var max = -Infinity;
  33624. for (var i = 0; i < frame.length; i++) {
  33625. frame[i] > max && (max = frame[i]);
  33626. }
  33627. // NaN will cause illegal axis extent.
  33628. return isFinite(max) ? max : NaN;
  33629. },
  33630. min: function (frame) {
  33631. var min = Infinity;
  33632. for (var i = 0; i < frame.length; i++) {
  33633. frame[i] < min && (min = frame[i]);
  33634. }
  33635. // NaN will cause illegal axis extent.
  33636. return isFinite(min) ? min : NaN;
  33637. },
  33638. // TODO
  33639. // Median
  33640. nearest: function (frame) {
  33641. return frame[0];
  33642. }
  33643. };
  33644. var indexSampler = function (frame, value) {
  33645. return Math.round(frame.length / 2);
  33646. };
  33647. var dataSample = function (seriesType) {
  33648. return {
  33649. seriesType: seriesType,
  33650. modifyOutputEnd: true,
  33651. reset: function (seriesModel, ecModel, api) {
  33652. var data = seriesModel.getData();
  33653. var sampling = seriesModel.get('sampling');
  33654. var coordSys = seriesModel.coordinateSystem;
  33655. // Only cartesian2d support down sampling
  33656. if (coordSys.type === 'cartesian2d' && sampling) {
  33657. var baseAxis = coordSys.getBaseAxis();
  33658. var valueAxis = coordSys.getOtherAxis(baseAxis);
  33659. var extent = baseAxis.getExtent();
  33660. // Coordinste system has been resized
  33661. var size = extent[1] - extent[0];
  33662. var rate = Math.round(data.count() / size);
  33663. if (rate > 1) {
  33664. var sampler;
  33665. if (typeof sampling === 'string') {
  33666. sampler = samplers[sampling];
  33667. }
  33668. else if (typeof sampling === 'function') {
  33669. sampler = sampling;
  33670. }
  33671. if (sampler) {
  33672. // Only support sample the first dim mapped from value axis.
  33673. seriesModel.setData(data.downSample(
  33674. data.mapDimension(valueAxis.dim), 1 / rate, sampler, indexSampler
  33675. ));
  33676. }
  33677. }
  33678. }
  33679. }
  33680. };
  33681. };
  33682. /*
  33683. * Licensed to the Apache Software Foundation (ASF) under one
  33684. * or more contributor license agreements. See the NOTICE file
  33685. * distributed with this work for additional information
  33686. * regarding copyright ownership. The ASF licenses this file
  33687. * to you under the Apache License, Version 2.0 (the
  33688. * "License"); you may not use this file except in compliance
  33689. * with the License. You may obtain a copy of the License at
  33690. *
  33691. * http://www.apache.org/licenses/LICENSE-2.0
  33692. *
  33693. * Unless required by applicable law or agreed to in writing,
  33694. * software distributed under the License is distributed on an
  33695. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  33696. * KIND, either express or implied. See the License for the
  33697. * specific language governing permissions and limitations
  33698. * under the License.
  33699. */
  33700. /**
  33701. * Cartesian coordinate system
  33702. * @module echarts/coord/Cartesian
  33703. *
  33704. */
  33705. function dimAxisMapper(dim) {
  33706. return this._axes[dim];
  33707. }
  33708. /**
  33709. * @alias module:echarts/coord/Cartesian
  33710. * @constructor
  33711. */
  33712. var Cartesian = function (name) {
  33713. this._axes = {};
  33714. this._dimList = [];
  33715. /**
  33716. * @type {string}
  33717. */
  33718. this.name = name || '';
  33719. };
  33720. Cartesian.prototype = {
  33721. constructor: Cartesian,
  33722. type: 'cartesian',
  33723. /**
  33724. * Get axis
  33725. * @param {number|string} dim
  33726. * @return {module:echarts/coord/Cartesian~Axis}
  33727. */
  33728. getAxis: function (dim) {
  33729. return this._axes[dim];
  33730. },
  33731. /**
  33732. * Get axes list
  33733. * @return {Array.<module:echarts/coord/Cartesian~Axis>}
  33734. */
  33735. getAxes: function () {
  33736. return map(this._dimList, dimAxisMapper, this);
  33737. },
  33738. /**
  33739. * Get axes list by given scale type
  33740. */
  33741. getAxesByScale: function (scaleType) {
  33742. scaleType = scaleType.toLowerCase();
  33743. return filter(
  33744. this.getAxes(),
  33745. function (axis) {
  33746. return axis.scale.type === scaleType;
  33747. }
  33748. );
  33749. },
  33750. /**
  33751. * Add axis
  33752. * @param {module:echarts/coord/Cartesian.Axis}
  33753. */
  33754. addAxis: function (axis) {
  33755. var dim = axis.dim;
  33756. this._axes[dim] = axis;
  33757. this._dimList.push(dim);
  33758. },
  33759. /**
  33760. * Convert data to coord in nd space
  33761. * @param {Array.<number>|Object.<string, number>} val
  33762. * @return {Array.<number>|Object.<string, number>}
  33763. */
  33764. dataToCoord: function (val) {
  33765. return this._dataCoordConvert(val, 'dataToCoord');
  33766. },
  33767. /**
  33768. * Convert coord in nd space to data
  33769. * @param {Array.<number>|Object.<string, number>} val
  33770. * @return {Array.<number>|Object.<string, number>}
  33771. */
  33772. coordToData: function (val) {
  33773. return this._dataCoordConvert(val, 'coordToData');
  33774. },
  33775. _dataCoordConvert: function (input, method) {
  33776. var dimList = this._dimList;
  33777. var output = input instanceof Array ? [] : {};
  33778. for (var i = 0; i < dimList.length; i++) {
  33779. var dim = dimList[i];
  33780. var axis = this._axes[dim];
  33781. output[dim] = axis[method](input[dim]);
  33782. }
  33783. return output;
  33784. }
  33785. };
  33786. /*
  33787. * Licensed to the Apache Software Foundation (ASF) under one
  33788. * or more contributor license agreements. See the NOTICE file
  33789. * distributed with this work for additional information
  33790. * regarding copyright ownership. The ASF licenses this file
  33791. * to you under the Apache License, Version 2.0 (the
  33792. * "License"); you may not use this file except in compliance
  33793. * with the License. You may obtain a copy of the License at
  33794. *
  33795. * http://www.apache.org/licenses/LICENSE-2.0
  33796. *
  33797. * Unless required by applicable law or agreed to in writing,
  33798. * software distributed under the License is distributed on an
  33799. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  33800. * KIND, either express or implied. See the License for the
  33801. * specific language governing permissions and limitations
  33802. * under the License.
  33803. */
  33804. function Cartesian2D(name) {
  33805. Cartesian.call(this, name);
  33806. }
  33807. Cartesian2D.prototype = {
  33808. constructor: Cartesian2D,
  33809. type: 'cartesian2d',
  33810. /**
  33811. * @type {Array.<string>}
  33812. * @readOnly
  33813. */
  33814. dimensions: ['x', 'y'],
  33815. /**
  33816. * Base axis will be used on stacking.
  33817. *
  33818. * @return {module:echarts/coord/cartesian/Axis2D}
  33819. */
  33820. getBaseAxis: function () {
  33821. return this.getAxesByScale('ordinal')[0]
  33822. || this.getAxesByScale('time')[0]
  33823. || this.getAxis('x');
  33824. },
  33825. /**
  33826. * If contain point
  33827. * @param {Array.<number>} point
  33828. * @return {boolean}
  33829. */
  33830. containPoint: function (point) {
  33831. var axisX = this.getAxis('x');
  33832. var axisY = this.getAxis('y');
  33833. return axisX.contain(axisX.toLocalCoord(point[0]))
  33834. && axisY.contain(axisY.toLocalCoord(point[1]));
  33835. },
  33836. /**
  33837. * If contain data
  33838. * @param {Array.<number>} data
  33839. * @return {boolean}
  33840. */
  33841. containData: function (data) {
  33842. return this.getAxis('x').containData(data[0])
  33843. && this.getAxis('y').containData(data[1]);
  33844. },
  33845. /**
  33846. * @param {Array.<number>} data
  33847. * @param {Array.<number>} out
  33848. * @return {Array.<number>}
  33849. */
  33850. dataToPoint: function (data, reserved, out) {
  33851. var xAxis = this.getAxis('x');
  33852. var yAxis = this.getAxis('y');
  33853. out = out || [];
  33854. out[0] = xAxis.toGlobalCoord(xAxis.dataToCoord(data[0]));
  33855. out[1] = yAxis.toGlobalCoord(yAxis.dataToCoord(data[1]));
  33856. return out;
  33857. },
  33858. /**
  33859. * @param {Array.<number>} data
  33860. * @param {Array.<number>} out
  33861. * @return {Array.<number>}
  33862. */
  33863. clampData: function (data, out) {
  33864. var xScale = this.getAxis('x').scale;
  33865. var yScale = this.getAxis('y').scale;
  33866. var xAxisExtent = xScale.getExtent();
  33867. var yAxisExtent = yScale.getExtent();
  33868. var x = xScale.parse(data[0]);
  33869. var y = yScale.parse(data[1]);
  33870. out = out || [];
  33871. out[0] = Math.min(
  33872. Math.max(Math.min(xAxisExtent[0], xAxisExtent[1]), x),
  33873. Math.max(xAxisExtent[0], xAxisExtent[1])
  33874. );
  33875. out[1] = Math.min(
  33876. Math.max(Math.min(yAxisExtent[0], yAxisExtent[1]), y),
  33877. Math.max(yAxisExtent[0], yAxisExtent[1])
  33878. );
  33879. return out;
  33880. },
  33881. /**
  33882. * @param {Array.<number>} point
  33883. * @param {Array.<number>} out
  33884. * @return {Array.<number>}
  33885. */
  33886. pointToData: function (point, out) {
  33887. var xAxis = this.getAxis('x');
  33888. var yAxis = this.getAxis('y');
  33889. out = out || [];
  33890. out[0] = xAxis.coordToData(xAxis.toLocalCoord(point[0]));
  33891. out[1] = yAxis.coordToData(yAxis.toLocalCoord(point[1]));
  33892. return out;
  33893. },
  33894. /**
  33895. * Get other axis
  33896. * @param {module:echarts/coord/cartesian/Axis2D} axis
  33897. */
  33898. getOtherAxis: function (axis) {
  33899. return this.getAxis(axis.dim === 'x' ? 'y' : 'x');
  33900. }
  33901. };
  33902. inherits(Cartesian2D, Cartesian);
  33903. /*
  33904. * Licensed to the Apache Software Foundation (ASF) under one
  33905. * or more contributor license agreements. See the NOTICE file
  33906. * distributed with this work for additional information
  33907. * regarding copyright ownership. The ASF licenses this file
  33908. * to you under the Apache License, Version 2.0 (the
  33909. * "License"); you may not use this file except in compliance
  33910. * with the License. You may obtain a copy of the License at
  33911. *
  33912. * http://www.apache.org/licenses/LICENSE-2.0
  33913. *
  33914. * Unless required by applicable law or agreed to in writing,
  33915. * software distributed under the License is distributed on an
  33916. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  33917. * KIND, either express or implied. See the License for the
  33918. * specific language governing permissions and limitations
  33919. * under the License.
  33920. */
  33921. /**
  33922. * Extend axis 2d
  33923. * @constructor module:echarts/coord/cartesian/Axis2D
  33924. * @extends {module:echarts/coord/cartesian/Axis}
  33925. * @param {string} dim
  33926. * @param {*} scale
  33927. * @param {Array.<number>} coordExtent
  33928. * @param {string} axisType
  33929. * @param {string} position
  33930. */
  33931. var Axis2D = function (dim, scale, coordExtent, axisType, position) {
  33932. Axis.call(this, dim, scale, coordExtent);
  33933. /**
  33934. * Axis type
  33935. * - 'category'
  33936. * - 'value'
  33937. * - 'time'
  33938. * - 'log'
  33939. * @type {string}
  33940. */
  33941. this.type = axisType || 'value';
  33942. /**
  33943. * Axis position
  33944. * - 'top'
  33945. * - 'bottom'
  33946. * - 'left'
  33947. * - 'right'
  33948. */
  33949. this.position = position || 'bottom';
  33950. };
  33951. Axis2D.prototype = {
  33952. constructor: Axis2D,
  33953. /**
  33954. * Index of axis, can be used as key
  33955. */
  33956. index: 0,
  33957. /**
  33958. * Implemented in <module:echarts/coord/cartesian/Grid>.
  33959. * @return {Array.<module:echarts/coord/cartesian/Axis2D>}
  33960. * If not on zero of other axis, return null/undefined.
  33961. * If no axes, return an empty array.
  33962. */
  33963. getAxesOnZeroOf: null,
  33964. /**
  33965. * Axis model
  33966. * @param {module:echarts/coord/cartesian/AxisModel}
  33967. */
  33968. model: null,
  33969. isHorizontal: function () {
  33970. var position = this.position;
  33971. return position === 'top' || position === 'bottom';
  33972. },
  33973. /**
  33974. * Each item cooresponds to this.getExtent(), which
  33975. * means globalExtent[0] may greater than globalExtent[1],
  33976. * unless `asc` is input.
  33977. *
  33978. * @param {boolean} [asc]
  33979. * @return {Array.<number>}
  33980. */
  33981. getGlobalExtent: function (asc) {
  33982. var ret = this.getExtent();
  33983. ret[0] = this.toGlobalCoord(ret[0]);
  33984. ret[1] = this.toGlobalCoord(ret[1]);
  33985. asc && ret[0] > ret[1] && ret.reverse();
  33986. return ret;
  33987. },
  33988. getOtherAxis: function () {
  33989. this.grid.getOtherAxis();
  33990. },
  33991. /**
  33992. * @override
  33993. */
  33994. pointToData: function (point, clamp) {
  33995. return this.coordToData(this.toLocalCoord(point[this.dim === 'x' ? 0 : 1]), clamp);
  33996. },
  33997. /**
  33998. * Transform global coord to local coord,
  33999. * i.e. var localCoord = axis.toLocalCoord(80);
  34000. * designate by module:echarts/coord/cartesian/Grid.
  34001. * @type {Function}
  34002. */
  34003. toLocalCoord: null,
  34004. /**
  34005. * Transform global coord to local coord,
  34006. * i.e. var globalCoord = axis.toLocalCoord(40);
  34007. * designate by module:echarts/coord/cartesian/Grid.
  34008. * @type {Function}
  34009. */
  34010. toGlobalCoord: null
  34011. };
  34012. inherits(Axis2D, Axis);
  34013. /*
  34014. * Licensed to the Apache Software Foundation (ASF) under one
  34015. * or more contributor license agreements. See the NOTICE file
  34016. * distributed with this work for additional information
  34017. * regarding copyright ownership. The ASF licenses this file
  34018. * to you under the Apache License, Version 2.0 (the
  34019. * "License"); you may not use this file except in compliance
  34020. * with the License. You may obtain a copy of the License at
  34021. *
  34022. * http://www.apache.org/licenses/LICENSE-2.0
  34023. *
  34024. * Unless required by applicable law or agreed to in writing,
  34025. * software distributed under the License is distributed on an
  34026. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  34027. * KIND, either express or implied. See the License for the
  34028. * specific language governing permissions and limitations
  34029. * under the License.
  34030. */
  34031. var defaultOption = {
  34032. show: true,
  34033. zlevel: 0,
  34034. z: 0,
  34035. // Inverse the axis.
  34036. inverse: false,
  34037. // Axis name displayed.
  34038. name: '',
  34039. // 'start' | 'middle' | 'end'
  34040. nameLocation: 'end',
  34041. // By degree. By defualt auto rotate by nameLocation.
  34042. nameRotate: null,
  34043. nameTruncate: {
  34044. maxWidth: null,
  34045. ellipsis: '...',
  34046. placeholder: '.'
  34047. },
  34048. // Use global text style by default.
  34049. nameTextStyle: {},
  34050. // The gap between axisName and axisLine.
  34051. nameGap: 15,
  34052. // Default `false` to support tooltip.
  34053. silent: false,
  34054. // Default `false` to avoid legacy user event listener fail.
  34055. triggerEvent: false,
  34056. tooltip: {
  34057. show: false
  34058. },
  34059. axisPointer: {},
  34060. axisLine: {
  34061. show: true,
  34062. onZero: true,
  34063. onZeroAxisIndex: null,
  34064. lineStyle: {
  34065. color: '#333',
  34066. width: 1,
  34067. type: 'solid'
  34068. },
  34069. // The arrow at both ends the the axis.
  34070. symbol: ['none', 'none'],
  34071. symbolSize: [10, 15]
  34072. },
  34073. axisTick: {
  34074. show: true,
  34075. // Whether axisTick is inside the grid or outside the grid.
  34076. inside: false,
  34077. // The length of axisTick.
  34078. length: 5,
  34079. lineStyle: {
  34080. width: 1
  34081. }
  34082. },
  34083. axisLabel: {
  34084. show: true,
  34085. // Whether axisLabel is inside the grid or outside the grid.
  34086. inside: false,
  34087. rotate: 0,
  34088. // true | false | null/undefined (auto)
  34089. showMinLabel: null,
  34090. // true | false | null/undefined (auto)
  34091. showMaxLabel: null,
  34092. margin: 8,
  34093. // formatter: null,
  34094. fontSize: 12
  34095. },
  34096. splitLine: {
  34097. show: true,
  34098. lineStyle: {
  34099. color: ['#ccc'],
  34100. width: 1,
  34101. type: 'solid'
  34102. }
  34103. },
  34104. splitArea: {
  34105. show: false,
  34106. areaStyle: {
  34107. color: ['rgba(250,250,250,0.3)', 'rgba(200,200,200,0.3)']
  34108. }
  34109. }
  34110. };
  34111. var axisDefault = {};
  34112. axisDefault.categoryAxis = merge({
  34113. // The gap at both ends of the axis. For categoryAxis, boolean.
  34114. boundaryGap: true,
  34115. // Set false to faster category collection.
  34116. // Only usefull in the case like: category is
  34117. // ['2012-01-01', '2012-01-02', ...], where the input
  34118. // data has been ensured not duplicate and is large data.
  34119. // null means "auto":
  34120. // if axis.data provided, do not deduplication,
  34121. // else do deduplication.
  34122. deduplication: null,
  34123. // splitArea: {
  34124. // show: false
  34125. // },
  34126. splitLine: {
  34127. show: false
  34128. },
  34129. axisTick: {
  34130. // If tick is align with label when boundaryGap is true
  34131. alignWithLabel: false,
  34132. interval: 'auto'
  34133. },
  34134. axisLabel: {
  34135. interval: 'auto'
  34136. }
  34137. }, defaultOption);
  34138. axisDefault.valueAxis = merge({
  34139. // The gap at both ends of the axis. For value axis, [GAP, GAP], where
  34140. // `GAP` can be an absolute pixel number (like `35`), or percent (like `'30%'`)
  34141. boundaryGap: [0, 0],
  34142. // TODO
  34143. // min/max: [30, datamin, 60] or [20, datamin] or [datamin, 60]
  34144. // Min value of the axis. can be:
  34145. // + a number
  34146. // + 'dataMin': use the min value in data.
  34147. // + null/undefined: auto decide min value (consider pretty look and boundaryGap).
  34148. // min: null,
  34149. // Max value of the axis. can be:
  34150. // + a number
  34151. // + 'dataMax': use the max value in data.
  34152. // + null/undefined: auto decide max value (consider pretty look and boundaryGap).
  34153. // max: null,
  34154. // Readonly prop, specifies start value of the range when using data zoom.
  34155. // rangeStart: null
  34156. // Readonly prop, specifies end value of the range when using data zoom.
  34157. // rangeEnd: null
  34158. // Optional value can be:
  34159. // + `false`: always include value 0.
  34160. // + `true`: the extent do not consider value 0.
  34161. // scale: false,
  34162. // AxisTick and axisLabel and splitLine are caculated based on splitNumber.
  34163. splitNumber: 5
  34164. // Interval specifies the span of the ticks is mandatorily.
  34165. // interval: null
  34166. // Specify min interval when auto calculate tick interval.
  34167. // minInterval: null
  34168. // Specify max interval when auto calculate tick interval.
  34169. // maxInterval: null
  34170. }, defaultOption);
  34171. axisDefault.timeAxis = defaults({
  34172. scale: true,
  34173. min: 'dataMin',
  34174. max: 'dataMax'
  34175. }, axisDefault.valueAxis);
  34176. axisDefault.logAxis = defaults({
  34177. scale: true,
  34178. logBase: 10
  34179. }, axisDefault.valueAxis);
  34180. /*
  34181. * Licensed to the Apache Software Foundation (ASF) under one
  34182. * or more contributor license agreements. See the NOTICE file
  34183. * distributed with this work for additional information
  34184. * regarding copyright ownership. The ASF licenses this file
  34185. * to you under the Apache License, Version 2.0 (the
  34186. * "License"); you may not use this file except in compliance
  34187. * with the License. You may obtain a copy of the License at
  34188. *
  34189. * http://www.apache.org/licenses/LICENSE-2.0
  34190. *
  34191. * Unless required by applicable law or agreed to in writing,
  34192. * software distributed under the License is distributed on an
  34193. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  34194. * KIND, either express or implied. See the License for the
  34195. * specific language governing permissions and limitations
  34196. * under the License.
  34197. */
  34198. // FIXME axisType is fixed ?
  34199. var AXIS_TYPES = ['value', 'category', 'time', 'log'];
  34200. /**
  34201. * Generate sub axis model class
  34202. * @param {string} axisName 'x' 'y' 'radius' 'angle' 'parallel'
  34203. * @param {module:echarts/model/Component} BaseAxisModelClass
  34204. * @param {Function} axisTypeDefaulter
  34205. * @param {Object} [extraDefaultOption]
  34206. */
  34207. var axisModelCreator = function (axisName, BaseAxisModelClass, axisTypeDefaulter, extraDefaultOption) {
  34208. each$1(AXIS_TYPES, function (axisType) {
  34209. BaseAxisModelClass.extend({
  34210. /**
  34211. * @readOnly
  34212. */
  34213. type: axisName + 'Axis.' + axisType,
  34214. mergeDefaultAndTheme: function (option, ecModel) {
  34215. var layoutMode = this.layoutMode;
  34216. var inputPositionParams = layoutMode
  34217. ? getLayoutParams(option) : {};
  34218. var themeModel = ecModel.getTheme();
  34219. merge(option, themeModel.get(axisType + 'Axis'));
  34220. merge(option, this.getDefaultOption());
  34221. option.type = axisTypeDefaulter(axisName, option);
  34222. if (layoutMode) {
  34223. mergeLayoutParam(option, inputPositionParams, layoutMode);
  34224. }
  34225. },
  34226. /**
  34227. * @override
  34228. */
  34229. optionUpdated: function () {
  34230. var thisOption = this.option;
  34231. if (thisOption.type === 'category') {
  34232. this.__ordinalMeta = OrdinalMeta.createByAxisModel(this);
  34233. }
  34234. },
  34235. /**
  34236. * Should not be called before all of 'getInitailData' finished.
  34237. * Because categories are collected during initializing data.
  34238. */
  34239. getCategories: function (rawData) {
  34240. var option = this.option;
  34241. // FIXME
  34242. // warning if called before all of 'getInitailData' finished.
  34243. if (option.type === 'category') {
  34244. if (rawData) {
  34245. return option.data;
  34246. }
  34247. return this.__ordinalMeta.categories;
  34248. }
  34249. },
  34250. getOrdinalMeta: function () {
  34251. return this.__ordinalMeta;
  34252. },
  34253. defaultOption: mergeAll(
  34254. [
  34255. {},
  34256. axisDefault[axisType + 'Axis'],
  34257. extraDefaultOption
  34258. ],
  34259. true
  34260. )
  34261. });
  34262. });
  34263. ComponentModel.registerSubTypeDefaulter(
  34264. axisName + 'Axis',
  34265. curry(axisTypeDefaulter, axisName)
  34266. );
  34267. };
  34268. /*
  34269. * Licensed to the Apache Software Foundation (ASF) under one
  34270. * or more contributor license agreements. See the NOTICE file
  34271. * distributed with this work for additional information
  34272. * regarding copyright ownership. The ASF licenses this file
  34273. * to you under the Apache License, Version 2.0 (the
  34274. * "License"); you may not use this file except in compliance
  34275. * with the License. You may obtain a copy of the License at
  34276. *
  34277. * http://www.apache.org/licenses/LICENSE-2.0
  34278. *
  34279. * Unless required by applicable law or agreed to in writing,
  34280. * software distributed under the License is distributed on an
  34281. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  34282. * KIND, either express or implied. See the License for the
  34283. * specific language governing permissions and limitations
  34284. * under the License.
  34285. */
  34286. var AxisModel = ComponentModel.extend({
  34287. type: 'cartesian2dAxis',
  34288. /**
  34289. * @type {module:echarts/coord/cartesian/Axis2D}
  34290. */
  34291. axis: null,
  34292. /**
  34293. * @override
  34294. */
  34295. init: function () {
  34296. AxisModel.superApply(this, 'init', arguments);
  34297. this.resetRange();
  34298. },
  34299. /**
  34300. * @override
  34301. */
  34302. mergeOption: function () {
  34303. AxisModel.superApply(this, 'mergeOption', arguments);
  34304. this.resetRange();
  34305. },
  34306. /**
  34307. * @override
  34308. */
  34309. restoreData: function () {
  34310. AxisModel.superApply(this, 'restoreData', arguments);
  34311. this.resetRange();
  34312. },
  34313. /**
  34314. * @override
  34315. * @return {module:echarts/model/Component}
  34316. */
  34317. getCoordSysModel: function () {
  34318. return this.ecModel.queryComponents({
  34319. mainType: 'grid',
  34320. index: this.option.gridIndex,
  34321. id: this.option.gridId
  34322. })[0];
  34323. }
  34324. });
  34325. function getAxisType(axisDim, option) {
  34326. // Default axis with data is category axis
  34327. return option.type || (option.data ? 'category' : 'value');
  34328. }
  34329. merge(AxisModel.prototype, axisModelCommonMixin);
  34330. var extraOption = {
  34331. // gridIndex: 0,
  34332. // gridId: '',
  34333. // Offset is for multiple axis on the same position
  34334. offset: 0
  34335. };
  34336. axisModelCreator('x', AxisModel, getAxisType, extraOption);
  34337. axisModelCreator('y', AxisModel, getAxisType, extraOption);
  34338. /*
  34339. * Licensed to the Apache Software Foundation (ASF) under one
  34340. * or more contributor license agreements. See the NOTICE file
  34341. * distributed with this work for additional information
  34342. * regarding copyright ownership. The ASF licenses this file
  34343. * to you under the Apache License, Version 2.0 (the
  34344. * "License"); you may not use this file except in compliance
  34345. * with the License. You may obtain a copy of the License at
  34346. *
  34347. * http://www.apache.org/licenses/LICENSE-2.0
  34348. *
  34349. * Unless required by applicable law or agreed to in writing,
  34350. * software distributed under the License is distributed on an
  34351. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  34352. * KIND, either express or implied. See the License for the
  34353. * specific language governing permissions and limitations
  34354. * under the License.
  34355. */
  34356. // Grid 是在有直角坐标系的时候必须要存在的
  34357. // 所以这里也要被 Cartesian2D 依赖
  34358. ComponentModel.extend({
  34359. type: 'grid',
  34360. dependencies: ['xAxis', 'yAxis'],
  34361. layoutMode: 'box',
  34362. /**
  34363. * @type {module:echarts/coord/cartesian/Grid}
  34364. */
  34365. coordinateSystem: null,
  34366. defaultOption: {
  34367. show: false,
  34368. zlevel: 0,
  34369. z: 0,
  34370. left: '10%',
  34371. top: 60,
  34372. right: '10%',
  34373. bottom: 60,
  34374. // If grid size contain label
  34375. containLabel: false,
  34376. // width: {totalWidth} - left - right,
  34377. // height: {totalHeight} - top - bottom,
  34378. backgroundColor: 'rgba(0,0,0,0)',
  34379. borderWidth: 1,
  34380. borderColor: '#ccc'
  34381. }
  34382. });
  34383. /*
  34384. * Licensed to the Apache Software Foundation (ASF) under one
  34385. * or more contributor license agreements. See the NOTICE file
  34386. * distributed with this work for additional information
  34387. * regarding copyright ownership. The ASF licenses this file
  34388. * to you under the Apache License, Version 2.0 (the
  34389. * "License"); you may not use this file except in compliance
  34390. * with the License. You may obtain a copy of the License at
  34391. *
  34392. * http://www.apache.org/licenses/LICENSE-2.0
  34393. *
  34394. * Unless required by applicable law or agreed to in writing,
  34395. * software distributed under the License is distributed on an
  34396. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  34397. * KIND, either express or implied. See the License for the
  34398. * specific language governing permissions and limitations
  34399. * under the License.
  34400. */
  34401. /**
  34402. * Grid is a region which contains at most 4 cartesian systems
  34403. *
  34404. * TODO Default cartesian
  34405. */
  34406. // Depends on GridModel, AxisModel, which performs preprocess.
  34407. /**
  34408. * Check if the axis is used in the specified grid
  34409. * @inner
  34410. */
  34411. function isAxisUsedInTheGrid(axisModel, gridModel, ecModel) {
  34412. return axisModel.getCoordSysModel() === gridModel;
  34413. }
  34414. function Grid(gridModel, ecModel, api) {
  34415. /**
  34416. * @type {Object.<string, module:echarts/coord/cartesian/Cartesian2D>}
  34417. * @private
  34418. */
  34419. this._coordsMap = {};
  34420. /**
  34421. * @type {Array.<module:echarts/coord/cartesian/Cartesian>}
  34422. * @private
  34423. */
  34424. this._coordsList = [];
  34425. /**
  34426. * @type {Object.<string, Array.<module:echarts/coord/cartesian/Axis2D>>}
  34427. * @private
  34428. */
  34429. this._axesMap = {};
  34430. /**
  34431. * @type {Array.<module:echarts/coord/cartesian/Axis2D>}
  34432. * @private
  34433. */
  34434. this._axesList = [];
  34435. this._initCartesian(gridModel, ecModel, api);
  34436. this.model = gridModel;
  34437. }
  34438. var gridProto = Grid.prototype;
  34439. gridProto.type = 'grid';
  34440. gridProto.axisPointerEnabled = true;
  34441. gridProto.getRect = function () {
  34442. return this._rect;
  34443. };
  34444. gridProto.update = function (ecModel, api) {
  34445. var axesMap = this._axesMap;
  34446. this._updateScale(ecModel, this.model);
  34447. each$1(axesMap.x, function (xAxis) {
  34448. niceScaleExtent(xAxis.scale, xAxis.model);
  34449. });
  34450. each$1(axesMap.y, function (yAxis) {
  34451. niceScaleExtent(yAxis.scale, yAxis.model);
  34452. });
  34453. // Key: axisDim_axisIndex, value: boolean, whether onZero target.
  34454. var onZeroRecords = {};
  34455. each$1(axesMap.x, function (xAxis) {
  34456. fixAxisOnZero(axesMap, 'y', xAxis, onZeroRecords);
  34457. });
  34458. each$1(axesMap.y, function (yAxis) {
  34459. fixAxisOnZero(axesMap, 'x', yAxis, onZeroRecords);
  34460. });
  34461. // Resize again if containLabel is enabled
  34462. // FIXME It may cause getting wrong grid size in data processing stage
  34463. this.resize(this.model, api);
  34464. };
  34465. function fixAxisOnZero(axesMap, otherAxisDim, axis, onZeroRecords) {
  34466. axis.getAxesOnZeroOf = function () {
  34467. // TODO: onZero of multiple axes.
  34468. return otherAxisOnZeroOf ? [otherAxisOnZeroOf] : [];
  34469. };
  34470. // onZero can not be enabled in these two situations:
  34471. // 1. When any other axis is a category axis.
  34472. // 2. When no axis is cross 0 point.
  34473. var otherAxes = axesMap[otherAxisDim];
  34474. var otherAxisOnZeroOf;
  34475. var axisModel = axis.model;
  34476. var onZero = axisModel.get('axisLine.onZero');
  34477. var onZeroAxisIndex = axisModel.get('axisLine.onZeroAxisIndex');
  34478. if (!onZero) {
  34479. return;
  34480. }
  34481. // If target axis is specified.
  34482. if (onZeroAxisIndex != null) {
  34483. if (canOnZeroToAxis(otherAxes[onZeroAxisIndex])) {
  34484. otherAxisOnZeroOf = otherAxes[onZeroAxisIndex];
  34485. }
  34486. }
  34487. else {
  34488. // Find the first available other axis.
  34489. for (var idx in otherAxes) {
  34490. if (otherAxes.hasOwnProperty(idx)
  34491. && canOnZeroToAxis(otherAxes[idx])
  34492. // Consider that two Y axes on one value axis,
  34493. // if both onZero, the two Y axes overlap.
  34494. && !onZeroRecords[getOnZeroRecordKey(otherAxes[idx])]
  34495. ) {
  34496. otherAxisOnZeroOf = otherAxes[idx];
  34497. break;
  34498. }
  34499. }
  34500. }
  34501. if (otherAxisOnZeroOf) {
  34502. onZeroRecords[getOnZeroRecordKey(otherAxisOnZeroOf)] = true;
  34503. }
  34504. function getOnZeroRecordKey(axis) {
  34505. return axis.dim + '_' + axis.index;
  34506. }
  34507. }
  34508. function canOnZeroToAxis(axis) {
  34509. return axis && axis.type !== 'category' && axis.type !== 'time' && ifAxisCrossZero(axis);
  34510. }
  34511. /**
  34512. * Resize the grid
  34513. * @param {module:echarts/coord/cartesian/GridModel} gridModel
  34514. * @param {module:echarts/ExtensionAPI} api
  34515. */
  34516. gridProto.resize = function (gridModel, api, ignoreContainLabel) {
  34517. var gridRect = getLayoutRect(
  34518. gridModel.getBoxLayoutParams(), {
  34519. width: api.getWidth(),
  34520. height: api.getHeight()
  34521. });
  34522. this._rect = gridRect;
  34523. var axesList = this._axesList;
  34524. adjustAxes();
  34525. // Minus label size
  34526. if (!ignoreContainLabel && gridModel.get('containLabel')) {
  34527. each$1(axesList, function (axis) {
  34528. if (!axis.model.get('axisLabel.inside')) {
  34529. var labelUnionRect = estimateLabelUnionRect(axis);
  34530. if (labelUnionRect) {
  34531. var dim = axis.isHorizontal() ? 'height' : 'width';
  34532. var margin = axis.model.get('axisLabel.margin');
  34533. gridRect[dim] -= labelUnionRect[dim] + margin;
  34534. if (axis.position === 'top') {
  34535. gridRect.y += labelUnionRect.height + margin;
  34536. }
  34537. else if (axis.position === 'left') {
  34538. gridRect.x += labelUnionRect.width + margin;
  34539. }
  34540. }
  34541. }
  34542. });
  34543. adjustAxes();
  34544. }
  34545. function adjustAxes() {
  34546. each$1(axesList, function (axis) {
  34547. var isHorizontal = axis.isHorizontal();
  34548. var extent = isHorizontal ? [0, gridRect.width] : [0, gridRect.height];
  34549. var idx = axis.inverse ? 1 : 0;
  34550. axis.setExtent(extent[idx], extent[1 - idx]);
  34551. updateAxisTransform(axis, isHorizontal ? gridRect.x : gridRect.y);
  34552. });
  34553. }
  34554. };
  34555. /**
  34556. * @param {string} axisType
  34557. * @param {number} [axisIndex]
  34558. */
  34559. gridProto.getAxis = function (axisType, axisIndex) {
  34560. var axesMapOnDim = this._axesMap[axisType];
  34561. if (axesMapOnDim != null) {
  34562. if (axisIndex == null) {
  34563. // Find first axis
  34564. for (var name in axesMapOnDim) {
  34565. if (axesMapOnDim.hasOwnProperty(name)) {
  34566. return axesMapOnDim[name];
  34567. }
  34568. }
  34569. }
  34570. return axesMapOnDim[axisIndex];
  34571. }
  34572. };
  34573. /**
  34574. * @return {Array.<module:echarts/coord/Axis>}
  34575. */
  34576. gridProto.getAxes = function () {
  34577. return this._axesList.slice();
  34578. };
  34579. /**
  34580. * Usage:
  34581. * grid.getCartesian(xAxisIndex, yAxisIndex);
  34582. * grid.getCartesian(xAxisIndex);
  34583. * grid.getCartesian(null, yAxisIndex);
  34584. * grid.getCartesian({xAxisIndex: ..., yAxisIndex: ...});
  34585. *
  34586. * @param {number|Object} [xAxisIndex]
  34587. * @param {number} [yAxisIndex]
  34588. */
  34589. gridProto.getCartesian = function (xAxisIndex, yAxisIndex) {
  34590. if (xAxisIndex != null && yAxisIndex != null) {
  34591. var key = 'x' + xAxisIndex + 'y' + yAxisIndex;
  34592. return this._coordsMap[key];
  34593. }
  34594. if (isObject$1(xAxisIndex)) {
  34595. yAxisIndex = xAxisIndex.yAxisIndex;
  34596. xAxisIndex = xAxisIndex.xAxisIndex;
  34597. }
  34598. // When only xAxisIndex or yAxisIndex given, find its first cartesian.
  34599. for (var i = 0, coordList = this._coordsList; i < coordList.length; i++) {
  34600. if (coordList[i].getAxis('x').index === xAxisIndex
  34601. || coordList[i].getAxis('y').index === yAxisIndex
  34602. ) {
  34603. return coordList[i];
  34604. }
  34605. }
  34606. };
  34607. gridProto.getCartesians = function () {
  34608. return this._coordsList.slice();
  34609. };
  34610. /**
  34611. * @implements
  34612. * see {module:echarts/CoodinateSystem}
  34613. */
  34614. gridProto.convertToPixel = function (ecModel, finder, value) {
  34615. var target = this._findConvertTarget(ecModel, finder);
  34616. return target.cartesian
  34617. ? target.cartesian.dataToPoint(value)
  34618. : target.axis
  34619. ? target.axis.toGlobalCoord(target.axis.dataToCoord(value))
  34620. : null;
  34621. };
  34622. /**
  34623. * @implements
  34624. * see {module:echarts/CoodinateSystem}
  34625. */
  34626. gridProto.convertFromPixel = function (ecModel, finder, value) {
  34627. var target = this._findConvertTarget(ecModel, finder);
  34628. return target.cartesian
  34629. ? target.cartesian.pointToData(value)
  34630. : target.axis
  34631. ? target.axis.coordToData(target.axis.toLocalCoord(value))
  34632. : null;
  34633. };
  34634. /**
  34635. * @inner
  34636. */
  34637. gridProto._findConvertTarget = function (ecModel, finder) {
  34638. var seriesModel = finder.seriesModel;
  34639. var xAxisModel = finder.xAxisModel
  34640. || (seriesModel && seriesModel.getReferringComponents('xAxis')[0]);
  34641. var yAxisModel = finder.yAxisModel
  34642. || (seriesModel && seriesModel.getReferringComponents('yAxis')[0]);
  34643. var gridModel = finder.gridModel;
  34644. var coordsList = this._coordsList;
  34645. var cartesian;
  34646. var axis;
  34647. if (seriesModel) {
  34648. cartesian = seriesModel.coordinateSystem;
  34649. indexOf(coordsList, cartesian) < 0 && (cartesian = null);
  34650. }
  34651. else if (xAxisModel && yAxisModel) {
  34652. cartesian = this.getCartesian(xAxisModel.componentIndex, yAxisModel.componentIndex);
  34653. }
  34654. else if (xAxisModel) {
  34655. axis = this.getAxis('x', xAxisModel.componentIndex);
  34656. }
  34657. else if (yAxisModel) {
  34658. axis = this.getAxis('y', yAxisModel.componentIndex);
  34659. }
  34660. // Lowest priority.
  34661. else if (gridModel) {
  34662. var grid = gridModel.coordinateSystem;
  34663. if (grid === this) {
  34664. cartesian = this._coordsList[0];
  34665. }
  34666. }
  34667. return {cartesian: cartesian, axis: axis};
  34668. };
  34669. /**
  34670. * @implements
  34671. * see {module:echarts/CoodinateSystem}
  34672. */
  34673. gridProto.containPoint = function (point) {
  34674. var coord = this._coordsList[0];
  34675. if (coord) {
  34676. return coord.containPoint(point);
  34677. }
  34678. };
  34679. /**
  34680. * Initialize cartesian coordinate systems
  34681. * @private
  34682. */
  34683. gridProto._initCartesian = function (gridModel, ecModel, api) {
  34684. var axisPositionUsed = {
  34685. left: false,
  34686. right: false,
  34687. top: false,
  34688. bottom: false
  34689. };
  34690. var axesMap = {
  34691. x: {},
  34692. y: {}
  34693. };
  34694. var axesCount = {
  34695. x: 0,
  34696. y: 0
  34697. };
  34698. /// Create axis
  34699. ecModel.eachComponent('xAxis', createAxisCreator('x'), this);
  34700. ecModel.eachComponent('yAxis', createAxisCreator('y'), this);
  34701. if (!axesCount.x || !axesCount.y) {
  34702. // Roll back when there no either x or y axis
  34703. this._axesMap = {};
  34704. this._axesList = [];
  34705. return;
  34706. }
  34707. this._axesMap = axesMap;
  34708. /// Create cartesian2d
  34709. each$1(axesMap.x, function (xAxis, xAxisIndex) {
  34710. each$1(axesMap.y, function (yAxis, yAxisIndex) {
  34711. var key = 'x' + xAxisIndex + 'y' + yAxisIndex;
  34712. var cartesian = new Cartesian2D(key);
  34713. cartesian.grid = this;
  34714. cartesian.model = gridModel;
  34715. this._coordsMap[key] = cartesian;
  34716. this._coordsList.push(cartesian);
  34717. cartesian.addAxis(xAxis);
  34718. cartesian.addAxis(yAxis);
  34719. }, this);
  34720. }, this);
  34721. function createAxisCreator(axisType) {
  34722. return function (axisModel, idx) {
  34723. if (!isAxisUsedInTheGrid(axisModel, gridModel, ecModel)) {
  34724. return;
  34725. }
  34726. var axisPosition = axisModel.get('position');
  34727. if (axisType === 'x') {
  34728. // Fix position
  34729. if (axisPosition !== 'top' && axisPosition !== 'bottom') {
  34730. // Default bottom of X
  34731. axisPosition = axisPositionUsed.bottom ? 'top' : 'bottom';
  34732. }
  34733. }
  34734. else {
  34735. // Fix position
  34736. if (axisPosition !== 'left' && axisPosition !== 'right') {
  34737. // Default left of Y
  34738. axisPosition = axisPositionUsed.left ? 'right' : 'left';
  34739. }
  34740. }
  34741. axisPositionUsed[axisPosition] = true;
  34742. var axis = new Axis2D(
  34743. axisType, createScaleByModel(axisModel),
  34744. [0, 0],
  34745. axisModel.get('type'),
  34746. axisPosition
  34747. );
  34748. var isCategory = axis.type === 'category';
  34749. axis.onBand = isCategory && axisModel.get('boundaryGap');
  34750. axis.inverse = axisModel.get('inverse');
  34751. // Inject axis into axisModel
  34752. axisModel.axis = axis;
  34753. // Inject axisModel into axis
  34754. axis.model = axisModel;
  34755. // Inject grid info axis
  34756. axis.grid = this;
  34757. // Index of axis, can be used as key
  34758. axis.index = idx;
  34759. this._axesList.push(axis);
  34760. axesMap[axisType][idx] = axis;
  34761. axesCount[axisType]++;
  34762. };
  34763. }
  34764. };
  34765. /**
  34766. * Update cartesian properties from series
  34767. * @param {module:echarts/model/Option} option
  34768. * @private
  34769. */
  34770. gridProto._updateScale = function (ecModel, gridModel) {
  34771. // Reset scale
  34772. each$1(this._axesList, function (axis) {
  34773. axis.scale.setExtent(Infinity, -Infinity);
  34774. });
  34775. ecModel.eachSeries(function (seriesModel) {
  34776. if (isCartesian2D(seriesModel)) {
  34777. var axesModels = findAxesModels(seriesModel, ecModel);
  34778. var xAxisModel = axesModels[0];
  34779. var yAxisModel = axesModels[1];
  34780. if (!isAxisUsedInTheGrid(xAxisModel, gridModel, ecModel)
  34781. || !isAxisUsedInTheGrid(yAxisModel, gridModel, ecModel)
  34782. ) {
  34783. return;
  34784. }
  34785. var cartesian = this.getCartesian(
  34786. xAxisModel.componentIndex, yAxisModel.componentIndex
  34787. );
  34788. var data = seriesModel.getData();
  34789. var xAxis = cartesian.getAxis('x');
  34790. var yAxis = cartesian.getAxis('y');
  34791. if (data.type === 'list') {
  34792. unionExtent(data, xAxis, seriesModel);
  34793. unionExtent(data, yAxis, seriesModel);
  34794. }
  34795. }
  34796. }, this);
  34797. function unionExtent(data, axis, seriesModel) {
  34798. each$1(data.mapDimension(axis.dim, true), function (dim) {
  34799. axis.scale.unionExtentFromData(
  34800. // For example, the extent of the orginal dimension
  34801. // is [0.1, 0.5], the extent of the `stackResultDimension`
  34802. // is [7, 9], the final extent should not include [0.1, 0.5].
  34803. data, getStackedDimension(data, dim)
  34804. );
  34805. });
  34806. }
  34807. };
  34808. /**
  34809. * @param {string} [dim] 'x' or 'y' or 'auto' or null/undefined
  34810. * @return {Object} {baseAxes: [], otherAxes: []}
  34811. */
  34812. gridProto.getTooltipAxes = function (dim) {
  34813. var baseAxes = [];
  34814. var otherAxes = [];
  34815. each$1(this.getCartesians(), function (cartesian) {
  34816. var baseAxis = (dim != null && dim !== 'auto')
  34817. ? cartesian.getAxis(dim) : cartesian.getBaseAxis();
  34818. var otherAxis = cartesian.getOtherAxis(baseAxis);
  34819. indexOf(baseAxes, baseAxis) < 0 && baseAxes.push(baseAxis);
  34820. indexOf(otherAxes, otherAxis) < 0 && otherAxes.push(otherAxis);
  34821. });
  34822. return {baseAxes: baseAxes, otherAxes: otherAxes};
  34823. };
  34824. /**
  34825. * @inner
  34826. */
  34827. function updateAxisTransform(axis, coordBase) {
  34828. var axisExtent = axis.getExtent();
  34829. var axisExtentSum = axisExtent[0] + axisExtent[1];
  34830. // Fast transform
  34831. axis.toGlobalCoord = axis.dim === 'x'
  34832. ? function (coord) {
  34833. return coord + coordBase;
  34834. }
  34835. : function (coord) {
  34836. return axisExtentSum - coord + coordBase;
  34837. };
  34838. axis.toLocalCoord = axis.dim === 'x'
  34839. ? function (coord) {
  34840. return coord - coordBase;
  34841. }
  34842. : function (coord) {
  34843. return axisExtentSum - coord + coordBase;
  34844. };
  34845. }
  34846. var axesTypes = ['xAxis', 'yAxis'];
  34847. /**
  34848. * @inner
  34849. */
  34850. function findAxesModels(seriesModel, ecModel) {
  34851. return map(axesTypes, function (axisType) {
  34852. var axisModel = seriesModel.getReferringComponents(axisType)[0];
  34853. if (__DEV__) {
  34854. if (!axisModel) {
  34855. throw new Error(axisType + ' "' + retrieve(
  34856. seriesModel.get(axisType + 'Index'),
  34857. seriesModel.get(axisType + 'Id'),
  34858. 0
  34859. ) + '" not found');
  34860. }
  34861. }
  34862. return axisModel;
  34863. });
  34864. }
  34865. /**
  34866. * @inner
  34867. */
  34868. function isCartesian2D(seriesModel) {
  34869. return seriesModel.get('coordinateSystem') === 'cartesian2d';
  34870. }
  34871. Grid.create = function (ecModel, api) {
  34872. var grids = [];
  34873. ecModel.eachComponent('grid', function (gridModel, idx) {
  34874. var grid = new Grid(gridModel, ecModel, api);
  34875. grid.name = 'grid_' + idx;
  34876. // dataSampling requires axis extent, so resize
  34877. // should be performed in create stage.
  34878. grid.resize(gridModel, api, true);
  34879. gridModel.coordinateSystem = grid;
  34880. grids.push(grid);
  34881. });
  34882. // Inject the coordinateSystems into seriesModel
  34883. ecModel.eachSeries(function (seriesModel) {
  34884. if (!isCartesian2D(seriesModel)) {
  34885. return;
  34886. }
  34887. var axesModels = findAxesModels(seriesModel, ecModel);
  34888. var xAxisModel = axesModels[0];
  34889. var yAxisModel = axesModels[1];
  34890. var gridModel = xAxisModel.getCoordSysModel();
  34891. if (__DEV__) {
  34892. if (!gridModel) {
  34893. throw new Error(
  34894. 'Grid "' + retrieve(
  34895. xAxisModel.get('gridIndex'),
  34896. xAxisModel.get('gridId'),
  34897. 0
  34898. ) + '" not found'
  34899. );
  34900. }
  34901. if (xAxisModel.getCoordSysModel() !== yAxisModel.getCoordSysModel()) {
  34902. throw new Error('xAxis and yAxis must use the same grid');
  34903. }
  34904. }
  34905. var grid = gridModel.coordinateSystem;
  34906. seriesModel.coordinateSystem = grid.getCartesian(
  34907. xAxisModel.componentIndex, yAxisModel.componentIndex
  34908. );
  34909. });
  34910. return grids;
  34911. };
  34912. // For deciding which dimensions to use when creating list data
  34913. Grid.dimensions = Grid.prototype.dimensions = Cartesian2D.prototype.dimensions;
  34914. CoordinateSystemManager.register('cartesian2d', Grid);
  34915. /*
  34916. * Licensed to the Apache Software Foundation (ASF) under one
  34917. * or more contributor license agreements. See the NOTICE file
  34918. * distributed with this work for additional information
  34919. * regarding copyright ownership. The ASF licenses this file
  34920. * to you under the Apache License, Version 2.0 (the
  34921. * "License"); you may not use this file except in compliance
  34922. * with the License. You may obtain a copy of the License at
  34923. *
  34924. * http://www.apache.org/licenses/LICENSE-2.0
  34925. *
  34926. * Unless required by applicable law or agreed to in writing,
  34927. * software distributed under the License is distributed on an
  34928. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  34929. * KIND, either express or implied. See the License for the
  34930. * specific language governing permissions and limitations
  34931. * under the License.
  34932. */
  34933. var PI$2 = Math.PI;
  34934. /**
  34935. * A final axis is translated and rotated from a "standard axis".
  34936. * So opt.position and opt.rotation is required.
  34937. *
  34938. * A standard axis is and axis from [0, 0] to [0, axisExtent[1]],
  34939. * for example: (0, 0) ------------> (0, 50)
  34940. *
  34941. * nameDirection or tickDirection or labelDirection is 1 means tick
  34942. * or label is below the standard axis, whereas is -1 means above
  34943. * the standard axis. labelOffset means offset between label and axis,
  34944. * which is useful when 'onZero', where axisLabel is in the grid and
  34945. * label in outside grid.
  34946. *
  34947. * Tips: like always,
  34948. * positive rotation represents anticlockwise, and negative rotation
  34949. * represents clockwise.
  34950. * The direction of position coordinate is the same as the direction
  34951. * of screen coordinate.
  34952. *
  34953. * Do not need to consider axis 'inverse', which is auto processed by
  34954. * axis extent.
  34955. *
  34956. * @param {module:zrender/container/Group} group
  34957. * @param {Object} axisModel
  34958. * @param {Object} opt Standard axis parameters.
  34959. * @param {Array.<number>} opt.position [x, y]
  34960. * @param {number} opt.rotation by radian
  34961. * @param {number} [opt.nameDirection=1] 1 or -1 Used when nameLocation is 'middle' or 'center'.
  34962. * @param {number} [opt.tickDirection=1] 1 or -1
  34963. * @param {number} [opt.labelDirection=1] 1 or -1
  34964. * @param {number} [opt.labelOffset=0] Usefull when onZero.
  34965. * @param {string} [opt.axisLabelShow] default get from axisModel.
  34966. * @param {string} [opt.axisName] default get from axisModel.
  34967. * @param {number} [opt.axisNameAvailableWidth]
  34968. * @param {number} [opt.labelRotate] by degree, default get from axisModel.
  34969. * @param {number} [opt.strokeContainThreshold] Default label interval when label
  34970. * @param {number} [opt.nameTruncateMaxWidth]
  34971. */
  34972. var AxisBuilder = function (axisModel, opt) {
  34973. /**
  34974. * @readOnly
  34975. */
  34976. this.opt = opt;
  34977. /**
  34978. * @readOnly
  34979. */
  34980. this.axisModel = axisModel;
  34981. // Default value
  34982. defaults(
  34983. opt,
  34984. {
  34985. labelOffset: 0,
  34986. nameDirection: 1,
  34987. tickDirection: 1,
  34988. labelDirection: 1,
  34989. silent: true
  34990. }
  34991. );
  34992. /**
  34993. * @readOnly
  34994. */
  34995. this.group = new Group();
  34996. // FIXME Not use a seperate text group?
  34997. var dumbGroup = new Group({
  34998. position: opt.position.slice(),
  34999. rotation: opt.rotation
  35000. });
  35001. // this.group.add(dumbGroup);
  35002. // this._dumbGroup = dumbGroup;
  35003. dumbGroup.updateTransform();
  35004. this._transform = dumbGroup.transform;
  35005. this._dumbGroup = dumbGroup;
  35006. };
  35007. AxisBuilder.prototype = {
  35008. constructor: AxisBuilder,
  35009. hasBuilder: function (name) {
  35010. return !!builders[name];
  35011. },
  35012. add: function (name) {
  35013. builders[name].call(this);
  35014. },
  35015. getGroup: function () {
  35016. return this.group;
  35017. }
  35018. };
  35019. var builders = {
  35020. /**
  35021. * @private
  35022. */
  35023. axisLine: function () {
  35024. var opt = this.opt;
  35025. var axisModel = this.axisModel;
  35026. if (!axisModel.get('axisLine.show')) {
  35027. return;
  35028. }
  35029. var extent = this.axisModel.axis.getExtent();
  35030. var matrix = this._transform;
  35031. var pt1 = [extent[0], 0];
  35032. var pt2 = [extent[1], 0];
  35033. if (matrix) {
  35034. applyTransform(pt1, pt1, matrix);
  35035. applyTransform(pt2, pt2, matrix);
  35036. }
  35037. var lineStyle = extend(
  35038. {
  35039. lineCap: 'round'
  35040. },
  35041. axisModel.getModel('axisLine.lineStyle').getLineStyle()
  35042. );
  35043. this.group.add(new Line({
  35044. // Id for animation
  35045. anid: 'line',
  35046. subPixelOptimize: true,
  35047. shape: {
  35048. x1: pt1[0],
  35049. y1: pt1[1],
  35050. x2: pt2[0],
  35051. y2: pt2[1]
  35052. },
  35053. style: lineStyle,
  35054. strokeContainThreshold: opt.strokeContainThreshold || 5,
  35055. silent: true,
  35056. z2: 1
  35057. }));
  35058. var arrows = axisModel.get('axisLine.symbol');
  35059. var arrowSize = axisModel.get('axisLine.symbolSize');
  35060. var arrowOffset = axisModel.get('axisLine.symbolOffset') || 0;
  35061. if (typeof arrowOffset === 'number') {
  35062. arrowOffset = [arrowOffset, arrowOffset];
  35063. }
  35064. if (arrows != null) {
  35065. if (typeof arrows === 'string') {
  35066. // Use the same arrow for start and end point
  35067. arrows = [arrows, arrows];
  35068. }
  35069. if (typeof arrowSize === 'string'
  35070. || typeof arrowSize === 'number'
  35071. ) {
  35072. // Use the same size for width and height
  35073. arrowSize = [arrowSize, arrowSize];
  35074. }
  35075. var symbolWidth = arrowSize[0];
  35076. var symbolHeight = arrowSize[1];
  35077. each$1([{
  35078. rotate: opt.rotation + Math.PI / 2,
  35079. offset: arrowOffset[0],
  35080. r: 0
  35081. }, {
  35082. rotate: opt.rotation - Math.PI / 2,
  35083. offset: arrowOffset[1],
  35084. r: Math.sqrt((pt1[0] - pt2[0]) * (pt1[0] - pt2[0])
  35085. + (pt1[1] - pt2[1]) * (pt1[1] - pt2[1]))
  35086. }], function (point, index) {
  35087. if (arrows[index] !== 'none' && arrows[index] != null) {
  35088. var symbol = createSymbol(
  35089. arrows[index],
  35090. -symbolWidth / 2,
  35091. -symbolHeight / 2,
  35092. symbolWidth,
  35093. symbolHeight,
  35094. lineStyle.stroke,
  35095. true
  35096. );
  35097. // Calculate arrow position with offset
  35098. var r = point.r + point.offset;
  35099. var pos = [
  35100. pt1[0] + r * Math.cos(opt.rotation),
  35101. pt1[1] - r * Math.sin(opt.rotation)
  35102. ];
  35103. symbol.attr({
  35104. rotation: point.rotate,
  35105. position: pos,
  35106. silent: true,
  35107. z2: 11
  35108. });
  35109. this.group.add(symbol);
  35110. }
  35111. }, this);
  35112. }
  35113. },
  35114. /**
  35115. * @private
  35116. */
  35117. axisTickLabel: function () {
  35118. var axisModel = this.axisModel;
  35119. var opt = this.opt;
  35120. var tickEls = buildAxisTick(this, axisModel, opt);
  35121. var labelEls = buildAxisLabel(this, axisModel, opt);
  35122. fixMinMaxLabelShow(axisModel, labelEls, tickEls);
  35123. },
  35124. /**
  35125. * @private
  35126. */
  35127. axisName: function () {
  35128. var opt = this.opt;
  35129. var axisModel = this.axisModel;
  35130. var name = retrieve(opt.axisName, axisModel.get('name'));
  35131. if (!name) {
  35132. return;
  35133. }
  35134. var nameLocation = axisModel.get('nameLocation');
  35135. var nameDirection = opt.nameDirection;
  35136. var textStyleModel = axisModel.getModel('nameTextStyle');
  35137. var gap = axisModel.get('nameGap') || 0;
  35138. var extent = this.axisModel.axis.getExtent();
  35139. var gapSignal = extent[0] > extent[1] ? -1 : 1;
  35140. var pos = [
  35141. nameLocation === 'start'
  35142. ? extent[0] - gapSignal * gap
  35143. : nameLocation === 'end'
  35144. ? extent[1] + gapSignal * gap
  35145. : (extent[0] + extent[1]) / 2, // 'middle'
  35146. // Reuse labelOffset.
  35147. isNameLocationCenter(nameLocation) ? opt.labelOffset + nameDirection * gap : 0
  35148. ];
  35149. var labelLayout;
  35150. var nameRotation = axisModel.get('nameRotate');
  35151. if (nameRotation != null) {
  35152. nameRotation = nameRotation * PI$2 / 180; // To radian.
  35153. }
  35154. var axisNameAvailableWidth;
  35155. if (isNameLocationCenter(nameLocation)) {
  35156. labelLayout = innerTextLayout(
  35157. opt.rotation,
  35158. nameRotation != null ? nameRotation : opt.rotation, // Adapt to axis.
  35159. nameDirection
  35160. );
  35161. }
  35162. else {
  35163. labelLayout = endTextLayout(
  35164. opt, nameLocation, nameRotation || 0, extent
  35165. );
  35166. axisNameAvailableWidth = opt.axisNameAvailableWidth;
  35167. if (axisNameAvailableWidth != null) {
  35168. axisNameAvailableWidth = Math.abs(
  35169. axisNameAvailableWidth / Math.sin(labelLayout.rotation)
  35170. );
  35171. !isFinite(axisNameAvailableWidth) && (axisNameAvailableWidth = null);
  35172. }
  35173. }
  35174. var textFont = textStyleModel.getFont();
  35175. var truncateOpt = axisModel.get('nameTruncate', true) || {};
  35176. var ellipsis = truncateOpt.ellipsis;
  35177. var maxWidth = retrieve(
  35178. opt.nameTruncateMaxWidth, truncateOpt.maxWidth, axisNameAvailableWidth
  35179. );
  35180. // FIXME
  35181. // truncate rich text? (consider performance)
  35182. var truncatedText = (ellipsis != null && maxWidth != null)
  35183. ? truncateText$1(
  35184. name, maxWidth, textFont, ellipsis,
  35185. {minChar: 2, placeholder: truncateOpt.placeholder}
  35186. )
  35187. : name;
  35188. var tooltipOpt = axisModel.get('tooltip', true);
  35189. var mainType = axisModel.mainType;
  35190. var formatterParams = {
  35191. componentType: mainType,
  35192. name: name,
  35193. $vars: ['name']
  35194. };
  35195. formatterParams[mainType + 'Index'] = axisModel.componentIndex;
  35196. var textEl = new Text({
  35197. // Id for animation
  35198. anid: 'name',
  35199. __fullText: name,
  35200. __truncatedText: truncatedText,
  35201. position: pos,
  35202. rotation: labelLayout.rotation,
  35203. silent: isLabelSilent(axisModel),
  35204. z2: 1,
  35205. tooltip: (tooltipOpt && tooltipOpt.show)
  35206. ? extend({
  35207. content: name,
  35208. formatter: function () {
  35209. return name;
  35210. },
  35211. formatterParams: formatterParams
  35212. }, tooltipOpt)
  35213. : null
  35214. });
  35215. setTextStyle(textEl.style, textStyleModel, {
  35216. text: truncatedText,
  35217. textFont: textFont,
  35218. textFill: textStyleModel.getTextColor()
  35219. || axisModel.get('axisLine.lineStyle.color'),
  35220. textAlign: textStyleModel.get('align')
  35221. || labelLayout.textAlign,
  35222. textVerticalAlign: textStyleModel.get('verticalAlign')
  35223. || labelLayout.textVerticalAlign
  35224. });
  35225. if (axisModel.get('triggerEvent')) {
  35226. textEl.eventData = makeAxisEventDataBase(axisModel);
  35227. textEl.eventData.targetType = 'axisName';
  35228. textEl.eventData.name = name;
  35229. }
  35230. // FIXME
  35231. this._dumbGroup.add(textEl);
  35232. textEl.updateTransform();
  35233. this.group.add(textEl);
  35234. textEl.decomposeTransform();
  35235. }
  35236. };
  35237. var makeAxisEventDataBase = AxisBuilder.makeAxisEventDataBase = function (axisModel) {
  35238. var eventData = {
  35239. componentType: axisModel.mainType,
  35240. componentIndex: axisModel.componentIndex
  35241. };
  35242. eventData[axisModel.mainType + 'Index'] = axisModel.componentIndex;
  35243. return eventData;
  35244. };
  35245. /**
  35246. * @public
  35247. * @static
  35248. * @param {Object} opt
  35249. * @param {number} axisRotation in radian
  35250. * @param {number} textRotation in radian
  35251. * @param {number} direction
  35252. * @return {Object} {
  35253. * rotation, // according to axis
  35254. * textAlign,
  35255. * textVerticalAlign
  35256. * }
  35257. */
  35258. var innerTextLayout = AxisBuilder.innerTextLayout = function (axisRotation, textRotation, direction) {
  35259. var rotationDiff = remRadian(textRotation - axisRotation);
  35260. var textAlign;
  35261. var textVerticalAlign;
  35262. if (isRadianAroundZero(rotationDiff)) { // Label is parallel with axis line.
  35263. textVerticalAlign = direction > 0 ? 'top' : 'bottom';
  35264. textAlign = 'center';
  35265. }
  35266. else if (isRadianAroundZero(rotationDiff - PI$2)) { // Label is inverse parallel with axis line.
  35267. textVerticalAlign = direction > 0 ? 'bottom' : 'top';
  35268. textAlign = 'center';
  35269. }
  35270. else {
  35271. textVerticalAlign = 'middle';
  35272. if (rotationDiff > 0 && rotationDiff < PI$2) {
  35273. textAlign = direction > 0 ? 'right' : 'left';
  35274. }
  35275. else {
  35276. textAlign = direction > 0 ? 'left' : 'right';
  35277. }
  35278. }
  35279. return {
  35280. rotation: rotationDiff,
  35281. textAlign: textAlign,
  35282. textVerticalAlign: textVerticalAlign
  35283. };
  35284. };
  35285. function endTextLayout(opt, textPosition, textRotate, extent) {
  35286. var rotationDiff = remRadian(textRotate - opt.rotation);
  35287. var textAlign;
  35288. var textVerticalAlign;
  35289. var inverse = extent[0] > extent[1];
  35290. var onLeft = (textPosition === 'start' && !inverse)
  35291. || (textPosition !== 'start' && inverse);
  35292. if (isRadianAroundZero(rotationDiff - PI$2 / 2)) {
  35293. textVerticalAlign = onLeft ? 'bottom' : 'top';
  35294. textAlign = 'center';
  35295. }
  35296. else if (isRadianAroundZero(rotationDiff - PI$2 * 1.5)) {
  35297. textVerticalAlign = onLeft ? 'top' : 'bottom';
  35298. textAlign = 'center';
  35299. }
  35300. else {
  35301. textVerticalAlign = 'middle';
  35302. if (rotationDiff < PI$2 * 1.5 && rotationDiff > PI$2 / 2) {
  35303. textAlign = onLeft ? 'left' : 'right';
  35304. }
  35305. else {
  35306. textAlign = onLeft ? 'right' : 'left';
  35307. }
  35308. }
  35309. return {
  35310. rotation: rotationDiff,
  35311. textAlign: textAlign,
  35312. textVerticalAlign: textVerticalAlign
  35313. };
  35314. }
  35315. var isLabelSilent = AxisBuilder.isLabelSilent = function (axisModel) {
  35316. var tooltipOpt = axisModel.get('tooltip');
  35317. return axisModel.get('silent')
  35318. // Consider mouse cursor, add these restrictions.
  35319. || !(
  35320. axisModel.get('triggerEvent') || (tooltipOpt && tooltipOpt.show)
  35321. );
  35322. };
  35323. function fixMinMaxLabelShow(axisModel, labelEls, tickEls) {
  35324. if (shouldShowAllLabels(axisModel.axis)) {
  35325. return;
  35326. }
  35327. // If min or max are user set, we need to check
  35328. // If the tick on min(max) are overlap on their neighbour tick
  35329. // If they are overlapped, we need to hide the min(max) tick label
  35330. var showMinLabel = axisModel.get('axisLabel.showMinLabel');
  35331. var showMaxLabel = axisModel.get('axisLabel.showMaxLabel');
  35332. // FIXME
  35333. // Have not consider onBand yet, where tick els is more than label els.
  35334. labelEls = labelEls || [];
  35335. tickEls = tickEls || [];
  35336. var firstLabel = labelEls[0];
  35337. var nextLabel = labelEls[1];
  35338. var lastLabel = labelEls[labelEls.length - 1];
  35339. var prevLabel = labelEls[labelEls.length - 2];
  35340. var firstTick = tickEls[0];
  35341. var nextTick = tickEls[1];
  35342. var lastTick = tickEls[tickEls.length - 1];
  35343. var prevTick = tickEls[tickEls.length - 2];
  35344. if (showMinLabel === false) {
  35345. ignoreEl(firstLabel);
  35346. ignoreEl(firstTick);
  35347. }
  35348. else if (isTwoLabelOverlapped(firstLabel, nextLabel)) {
  35349. if (showMinLabel) {
  35350. ignoreEl(nextLabel);
  35351. ignoreEl(nextTick);
  35352. }
  35353. else {
  35354. ignoreEl(firstLabel);
  35355. ignoreEl(firstTick);
  35356. }
  35357. }
  35358. if (showMaxLabel === false) {
  35359. ignoreEl(lastLabel);
  35360. ignoreEl(lastTick);
  35361. }
  35362. else if (isTwoLabelOverlapped(prevLabel, lastLabel)) {
  35363. if (showMaxLabel) {
  35364. ignoreEl(prevLabel);
  35365. ignoreEl(prevTick);
  35366. }
  35367. else {
  35368. ignoreEl(lastLabel);
  35369. ignoreEl(lastTick);
  35370. }
  35371. }
  35372. }
  35373. function ignoreEl(el) {
  35374. el && (el.ignore = true);
  35375. }
  35376. function isTwoLabelOverlapped(current, next, labelLayout) {
  35377. // current and next has the same rotation.
  35378. var firstRect = current && current.getBoundingRect().clone();
  35379. var nextRect = next && next.getBoundingRect().clone();
  35380. if (!firstRect || !nextRect) {
  35381. return;
  35382. }
  35383. // When checking intersect of two rotated labels, we use mRotationBack
  35384. // to avoid that boundingRect is enlarge when using `boundingRect.applyTransform`.
  35385. var mRotationBack = identity([]);
  35386. rotate(mRotationBack, mRotationBack, -current.rotation);
  35387. firstRect.applyTransform(mul$1([], mRotationBack, current.getLocalTransform()));
  35388. nextRect.applyTransform(mul$1([], mRotationBack, next.getLocalTransform()));
  35389. return firstRect.intersect(nextRect);
  35390. }
  35391. function isNameLocationCenter(nameLocation) {
  35392. return nameLocation === 'middle' || nameLocation === 'center';
  35393. }
  35394. function buildAxisTick(axisBuilder, axisModel, opt) {
  35395. var axis = axisModel.axis;
  35396. if (!axisModel.get('axisTick.show') || axis.scale.isBlank()) {
  35397. return;
  35398. }
  35399. var tickModel = axisModel.getModel('axisTick');
  35400. var lineStyleModel = tickModel.getModel('lineStyle');
  35401. var tickLen = tickModel.get('length');
  35402. var ticksCoords = axis.getTicksCoords();
  35403. var pt1 = [];
  35404. var pt2 = [];
  35405. var matrix = axisBuilder._transform;
  35406. var tickEls = [];
  35407. for (var i = 0; i < ticksCoords.length; i++) {
  35408. var tickCoord = ticksCoords[i].coord;
  35409. pt1[0] = tickCoord;
  35410. pt1[1] = 0;
  35411. pt2[0] = tickCoord;
  35412. pt2[1] = opt.tickDirection * tickLen;
  35413. if (matrix) {
  35414. applyTransform(pt1, pt1, matrix);
  35415. applyTransform(pt2, pt2, matrix);
  35416. }
  35417. // Tick line, Not use group transform to have better line draw
  35418. var tickEl = new Line({
  35419. // Id for animation
  35420. anid: 'tick_' + ticksCoords[i].tickValue,
  35421. subPixelOptimize: true,
  35422. shape: {
  35423. x1: pt1[0],
  35424. y1: pt1[1],
  35425. x2: pt2[0],
  35426. y2: pt2[1]
  35427. },
  35428. style: defaults(
  35429. lineStyleModel.getLineStyle(),
  35430. {
  35431. stroke: axisModel.get('axisLine.lineStyle.color')
  35432. }
  35433. ),
  35434. z2: 2,
  35435. silent: true
  35436. });
  35437. axisBuilder.group.add(tickEl);
  35438. tickEls.push(tickEl);
  35439. }
  35440. return tickEls;
  35441. }
  35442. function buildAxisLabel(axisBuilder, axisModel, opt) {
  35443. var axis = axisModel.axis;
  35444. var show = retrieve(opt.axisLabelShow, axisModel.get('axisLabel.show'));
  35445. if (!show || axis.scale.isBlank()) {
  35446. return;
  35447. }
  35448. var labelModel = axisModel.getModel('axisLabel');
  35449. var labelMargin = labelModel.get('margin');
  35450. var labels = axis.getViewLabels();
  35451. // Special label rotate.
  35452. var labelRotation = (
  35453. retrieve(opt.labelRotate, labelModel.get('rotate')) || 0
  35454. ) * PI$2 / 180;
  35455. var labelLayout = innerTextLayout(opt.rotation, labelRotation, opt.labelDirection);
  35456. var rawCategoryData = axisModel.getCategories && axisModel.getCategories(true);
  35457. var labelEls = [];
  35458. var silent = isLabelSilent(axisModel);
  35459. var triggerEvent = axisModel.get('triggerEvent');
  35460. each$1(labels, function (labelItem, index) {
  35461. var tickValue = labelItem.tickValue;
  35462. var formattedLabel = labelItem.formattedLabel;
  35463. var rawLabel = labelItem.rawLabel;
  35464. var itemLabelModel = labelModel;
  35465. if (rawCategoryData && rawCategoryData[tickValue] && rawCategoryData[tickValue].textStyle) {
  35466. itemLabelModel = new Model(
  35467. rawCategoryData[tickValue].textStyle, labelModel, axisModel.ecModel
  35468. );
  35469. }
  35470. var textColor = itemLabelModel.getTextColor()
  35471. || axisModel.get('axisLine.lineStyle.color');
  35472. var tickCoord = axis.dataToCoord(tickValue);
  35473. var pos = [
  35474. tickCoord,
  35475. opt.labelOffset + opt.labelDirection * labelMargin
  35476. ];
  35477. var textEl = new Text({
  35478. // Id for animation
  35479. anid: 'label_' + tickValue,
  35480. position: pos,
  35481. rotation: labelLayout.rotation,
  35482. silent: silent,
  35483. z2: 10
  35484. });
  35485. setTextStyle(textEl.style, itemLabelModel, {
  35486. text: formattedLabel,
  35487. textAlign: itemLabelModel.getShallow('align', true)
  35488. || labelLayout.textAlign,
  35489. textVerticalAlign: itemLabelModel.getShallow('verticalAlign', true)
  35490. || itemLabelModel.getShallow('baseline', true)
  35491. || labelLayout.textVerticalAlign,
  35492. textFill: typeof textColor === 'function'
  35493. ? textColor(
  35494. // (1) In category axis with data zoom, tick is not the original
  35495. // index of axis.data. So tick should not be exposed to user
  35496. // in category axis.
  35497. // (2) Compatible with previous version, which always use formatted label as
  35498. // input. But in interval scale the formatted label is like '223,445', which
  35499. // maked user repalce ','. So we modify it to return original val but remain
  35500. // it as 'string' to avoid error in replacing.
  35501. axis.type === 'category'
  35502. ? rawLabel
  35503. : axis.type === 'value'
  35504. ? tickValue + ''
  35505. : tickValue,
  35506. index
  35507. )
  35508. : textColor
  35509. });
  35510. // Pack data for mouse event
  35511. if (triggerEvent) {
  35512. textEl.eventData = makeAxisEventDataBase(axisModel);
  35513. textEl.eventData.targetType = 'axisLabel';
  35514. textEl.eventData.value = rawLabel;
  35515. }
  35516. // FIXME
  35517. axisBuilder._dumbGroup.add(textEl);
  35518. textEl.updateTransform();
  35519. labelEls.push(textEl);
  35520. axisBuilder.group.add(textEl);
  35521. textEl.decomposeTransform();
  35522. });
  35523. return labelEls;
  35524. }
  35525. /*
  35526. * Licensed to the Apache Software Foundation (ASF) under one
  35527. * or more contributor license agreements. See the NOTICE file
  35528. * distributed with this work for additional information
  35529. * regarding copyright ownership. The ASF licenses this file
  35530. * to you under the Apache License, Version 2.0 (the
  35531. * "License"); you may not use this file except in compliance
  35532. * with the License. You may obtain a copy of the License at
  35533. *
  35534. * http://www.apache.org/licenses/LICENSE-2.0
  35535. *
  35536. * Unless required by applicable law or agreed to in writing,
  35537. * software distributed under the License is distributed on an
  35538. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  35539. * KIND, either express or implied. See the License for the
  35540. * specific language governing permissions and limitations
  35541. * under the License.
  35542. */
  35543. var each$6 = each$1;
  35544. var curry$1 = curry;
  35545. // Build axisPointerModel, mergin tooltip.axisPointer model for each axis.
  35546. // allAxesInfo should be updated when setOption performed.
  35547. function collect(ecModel, api) {
  35548. var result = {
  35549. /**
  35550. * key: makeKey(axis.model)
  35551. * value: {
  35552. * axis,
  35553. * coordSys,
  35554. * axisPointerModel,
  35555. * triggerTooltip,
  35556. * involveSeries,
  35557. * snap,
  35558. * seriesModels,
  35559. * seriesDataCount
  35560. * }
  35561. */
  35562. axesInfo: {},
  35563. seriesInvolved: false,
  35564. /**
  35565. * key: makeKey(coordSys.model)
  35566. * value: Object: key makeKey(axis.model), value: axisInfo
  35567. */
  35568. coordSysAxesInfo: {},
  35569. coordSysMap: {}
  35570. };
  35571. collectAxesInfo(result, ecModel, api);
  35572. // Check seriesInvolved for performance, in case too many series in some chart.
  35573. result.seriesInvolved && collectSeriesInfo(result, ecModel);
  35574. return result;
  35575. }
  35576. function collectAxesInfo(result, ecModel, api) {
  35577. var globalTooltipModel = ecModel.getComponent('tooltip');
  35578. var globalAxisPointerModel = ecModel.getComponent('axisPointer');
  35579. // links can only be set on global.
  35580. var linksOption = globalAxisPointerModel.get('link', true) || [];
  35581. var linkGroups = [];
  35582. // Collect axes info.
  35583. each$6(api.getCoordinateSystems(), function (coordSys) {
  35584. // Some coordinate system do not support axes, like geo.
  35585. if (!coordSys.axisPointerEnabled) {
  35586. return;
  35587. }
  35588. var coordSysKey = makeKey(coordSys.model);
  35589. var axesInfoInCoordSys = result.coordSysAxesInfo[coordSysKey] = {};
  35590. result.coordSysMap[coordSysKey] = coordSys;
  35591. // Set tooltip (like 'cross') is a convienent way to show axisPointer
  35592. // for user. So we enable seting tooltip on coordSys model.
  35593. var coordSysModel = coordSys.model;
  35594. var baseTooltipModel = coordSysModel.getModel('tooltip', globalTooltipModel);
  35595. each$6(coordSys.getAxes(), curry$1(saveTooltipAxisInfo, false, null));
  35596. // If axis tooltip used, choose tooltip axis for each coordSys.
  35597. // Notice this case: coordSys is `grid` but not `cartesian2D` here.
  35598. if (coordSys.getTooltipAxes
  35599. && globalTooltipModel
  35600. // If tooltip.showContent is set as false, tooltip will not
  35601. // show but axisPointer will show as normal.
  35602. && baseTooltipModel.get('show')
  35603. ) {
  35604. // Compatible with previous logic. But series.tooltip.trigger: 'axis'
  35605. // or series.data[n].tooltip.trigger: 'axis' are not support any more.
  35606. var triggerAxis = baseTooltipModel.get('trigger') === 'axis';
  35607. var cross = baseTooltipModel.get('axisPointer.type') === 'cross';
  35608. var tooltipAxes = coordSys.getTooltipAxes(baseTooltipModel.get('axisPointer.axis'));
  35609. if (triggerAxis || cross) {
  35610. each$6(tooltipAxes.baseAxes, curry$1(
  35611. saveTooltipAxisInfo, cross ? 'cross' : true, triggerAxis
  35612. ));
  35613. }
  35614. if (cross) {
  35615. each$6(tooltipAxes.otherAxes, curry$1(saveTooltipAxisInfo, 'cross', false));
  35616. }
  35617. }
  35618. // fromTooltip: true | false | 'cross'
  35619. // triggerTooltip: true | false | null
  35620. function saveTooltipAxisInfo(fromTooltip, triggerTooltip, axis) {
  35621. var axisPointerModel = axis.model.getModel('axisPointer', globalAxisPointerModel);
  35622. var axisPointerShow = axisPointerModel.get('show');
  35623. if (!axisPointerShow || (
  35624. axisPointerShow === 'auto'
  35625. && !fromTooltip
  35626. && !isHandleTrigger(axisPointerModel)
  35627. )) {
  35628. return;
  35629. }
  35630. if (triggerTooltip == null) {
  35631. triggerTooltip = axisPointerModel.get('triggerTooltip');
  35632. }
  35633. axisPointerModel = fromTooltip
  35634. ? makeAxisPointerModel(
  35635. axis, baseTooltipModel, globalAxisPointerModel, ecModel,
  35636. fromTooltip, triggerTooltip
  35637. )
  35638. : axisPointerModel;
  35639. var snap = axisPointerModel.get('snap');
  35640. var key = makeKey(axis.model);
  35641. var involveSeries = triggerTooltip || snap || axis.type === 'category';
  35642. // If result.axesInfo[key] exist, override it (tooltip has higher priority).
  35643. var axisInfo = result.axesInfo[key] = {
  35644. key: key,
  35645. axis: axis,
  35646. coordSys: coordSys,
  35647. axisPointerModel: axisPointerModel,
  35648. triggerTooltip: triggerTooltip,
  35649. involveSeries: involveSeries,
  35650. snap: snap,
  35651. useHandle: isHandleTrigger(axisPointerModel),
  35652. seriesModels: []
  35653. };
  35654. axesInfoInCoordSys[key] = axisInfo;
  35655. result.seriesInvolved |= involveSeries;
  35656. var groupIndex = getLinkGroupIndex(linksOption, axis);
  35657. if (groupIndex != null) {
  35658. var linkGroup = linkGroups[groupIndex] || (linkGroups[groupIndex] = {axesInfo: {}});
  35659. linkGroup.axesInfo[key] = axisInfo;
  35660. linkGroup.mapper = linksOption[groupIndex].mapper;
  35661. axisInfo.linkGroup = linkGroup;
  35662. }
  35663. }
  35664. });
  35665. }
  35666. function makeAxisPointerModel(
  35667. axis, baseTooltipModel, globalAxisPointerModel, ecModel, fromTooltip, triggerTooltip
  35668. ) {
  35669. var tooltipAxisPointerModel = baseTooltipModel.getModel('axisPointer');
  35670. var volatileOption = {};
  35671. each$6(
  35672. [
  35673. 'type', 'snap', 'lineStyle', 'shadowStyle', 'label',
  35674. 'animation', 'animationDurationUpdate', 'animationEasingUpdate', 'z'
  35675. ],
  35676. function (field) {
  35677. volatileOption[field] = clone(tooltipAxisPointerModel.get(field));
  35678. }
  35679. );
  35680. // category axis do not auto snap, otherwise some tick that do not
  35681. // has value can not be hovered. value/time/log axis default snap if
  35682. // triggered from tooltip and trigger tooltip.
  35683. volatileOption.snap = axis.type !== 'category' && !!triggerTooltip;
  35684. // Compatibel with previous behavior, tooltip axis do not show label by default.
  35685. // Only these properties can be overrided from tooltip to axisPointer.
  35686. if (tooltipAxisPointerModel.get('type') === 'cross') {
  35687. volatileOption.type = 'line';
  35688. }
  35689. var labelOption = volatileOption.label || (volatileOption.label = {});
  35690. // Follow the convention, do not show label when triggered by tooltip by default.
  35691. labelOption.show == null && (labelOption.show = false);
  35692. if (fromTooltip === 'cross') {
  35693. // When 'cross', both axes show labels.
  35694. var tooltipAxisPointerLabelShow = tooltipAxisPointerModel.get('label.show');
  35695. labelOption.show = tooltipAxisPointerLabelShow != null ? tooltipAxisPointerLabelShow : true;
  35696. // If triggerTooltip, this is a base axis, which should better not use cross style
  35697. // (cross style is dashed by default)
  35698. if (!triggerTooltip) {
  35699. var crossStyle = volatileOption.lineStyle = tooltipAxisPointerModel.get('crossStyle');
  35700. crossStyle && defaults(labelOption, crossStyle.textStyle);
  35701. }
  35702. }
  35703. return axis.model.getModel(
  35704. 'axisPointer',
  35705. new Model(volatileOption, globalAxisPointerModel, ecModel)
  35706. );
  35707. }
  35708. function collectSeriesInfo(result, ecModel) {
  35709. // Prepare data for axis trigger
  35710. ecModel.eachSeries(function (seriesModel) {
  35711. // Notice this case: this coordSys is `cartesian2D` but not `grid`.
  35712. var coordSys = seriesModel.coordinateSystem;
  35713. var seriesTooltipTrigger = seriesModel.get('tooltip.trigger', true);
  35714. var seriesTooltipShow = seriesModel.get('tooltip.show', true);
  35715. if (!coordSys
  35716. || seriesTooltipTrigger === 'none'
  35717. || seriesTooltipTrigger === false
  35718. || seriesTooltipTrigger === 'item'
  35719. || seriesTooltipShow === false
  35720. || seriesModel.get('axisPointer.show', true) === false
  35721. ) {
  35722. return;
  35723. }
  35724. each$6(result.coordSysAxesInfo[makeKey(coordSys.model)], function (axisInfo) {
  35725. var axis = axisInfo.axis;
  35726. if (coordSys.getAxis(axis.dim) === axis) {
  35727. axisInfo.seriesModels.push(seriesModel);
  35728. axisInfo.seriesDataCount == null && (axisInfo.seriesDataCount = 0);
  35729. axisInfo.seriesDataCount += seriesModel.getData().count();
  35730. }
  35731. });
  35732. }, this);
  35733. }
  35734. /**
  35735. * For example:
  35736. * {
  35737. * axisPointer: {
  35738. * links: [{
  35739. * xAxisIndex: [2, 4],
  35740. * yAxisIndex: 'all'
  35741. * }, {
  35742. * xAxisId: ['a5', 'a7'],
  35743. * xAxisName: 'xxx'
  35744. * }]
  35745. * }
  35746. * }
  35747. */
  35748. function getLinkGroupIndex(linksOption, axis) {
  35749. var axisModel = axis.model;
  35750. var dim = axis.dim;
  35751. for (var i = 0; i < linksOption.length; i++) {
  35752. var linkOption = linksOption[i] || {};
  35753. if (checkPropInLink(linkOption[dim + 'AxisId'], axisModel.id)
  35754. || checkPropInLink(linkOption[dim + 'AxisIndex'], axisModel.componentIndex)
  35755. || checkPropInLink(linkOption[dim + 'AxisName'], axisModel.name)
  35756. ) {
  35757. return i;
  35758. }
  35759. }
  35760. }
  35761. function checkPropInLink(linkPropValue, axisPropValue) {
  35762. return linkPropValue === 'all'
  35763. || (isArray(linkPropValue) && indexOf(linkPropValue, axisPropValue) >= 0)
  35764. || linkPropValue === axisPropValue;
  35765. }
  35766. function fixValue(axisModel) {
  35767. var axisInfo = getAxisInfo(axisModel);
  35768. if (!axisInfo) {
  35769. return;
  35770. }
  35771. var axisPointerModel = axisInfo.axisPointerModel;
  35772. var scale = axisInfo.axis.scale;
  35773. var option = axisPointerModel.option;
  35774. var status = axisPointerModel.get('status');
  35775. var value = axisPointerModel.get('value');
  35776. // Parse init value for category and time axis.
  35777. if (value != null) {
  35778. value = scale.parse(value);
  35779. }
  35780. var useHandle = isHandleTrigger(axisPointerModel);
  35781. // If `handle` used, `axisPointer` will always be displayed, so value
  35782. // and status should be initialized.
  35783. if (status == null) {
  35784. option.status = useHandle ? 'show' : 'hide';
  35785. }
  35786. var extent = scale.getExtent().slice();
  35787. extent[0] > extent[1] && extent.reverse();
  35788. if (// Pick a value on axis when initializing.
  35789. value == null
  35790. // If both `handle` and `dataZoom` are used, value may be out of axis extent,
  35791. // where we should re-pick a value to keep `handle` displaying normally.
  35792. || value > extent[1]
  35793. ) {
  35794. // Make handle displayed on the end of the axis when init, which looks better.
  35795. value = extent[1];
  35796. }
  35797. if (value < extent[0]) {
  35798. value = extent[0];
  35799. }
  35800. option.value = value;
  35801. if (useHandle) {
  35802. option.status = axisInfo.axis.scale.isBlank() ? 'hide' : 'show';
  35803. }
  35804. }
  35805. function getAxisInfo(axisModel) {
  35806. var coordSysAxesInfo = (axisModel.ecModel.getComponent('axisPointer') || {}).coordSysAxesInfo;
  35807. return coordSysAxesInfo && coordSysAxesInfo.axesInfo[makeKey(axisModel)];
  35808. }
  35809. function getAxisPointerModel(axisModel) {
  35810. var axisInfo = getAxisInfo(axisModel);
  35811. return axisInfo && axisInfo.axisPointerModel;
  35812. }
  35813. function isHandleTrigger(axisPointerModel) {
  35814. return !!axisPointerModel.get('handle.show');
  35815. }
  35816. /**
  35817. * @param {module:echarts/model/Model} model
  35818. * @return {string} unique key
  35819. */
  35820. function makeKey(model) {
  35821. return model.type + '||' + model.id;
  35822. }
  35823. /*
  35824. * Licensed to the Apache Software Foundation (ASF) under one
  35825. * or more contributor license agreements. See the NOTICE file
  35826. * distributed with this work for additional information
  35827. * regarding copyright ownership. The ASF licenses this file
  35828. * to you under the Apache License, Version 2.0 (the
  35829. * "License"); you may not use this file except in compliance
  35830. * with the License. You may obtain a copy of the License at
  35831. *
  35832. * http://www.apache.org/licenses/LICENSE-2.0
  35833. *
  35834. * Unless required by applicable law or agreed to in writing,
  35835. * software distributed under the License is distributed on an
  35836. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  35837. * KIND, either express or implied. See the License for the
  35838. * specific language governing permissions and limitations
  35839. * under the License.
  35840. */
  35841. /**
  35842. * Base class of AxisView.
  35843. */
  35844. var AxisView = extendComponentView({
  35845. type: 'axis',
  35846. /**
  35847. * @private
  35848. */
  35849. _axisPointer: null,
  35850. /**
  35851. * @protected
  35852. * @type {string}
  35853. */
  35854. axisPointerClass: null,
  35855. /**
  35856. * @override
  35857. */
  35858. render: function (axisModel, ecModel, api, payload) {
  35859. // FIXME
  35860. // This process should proformed after coordinate systems updated
  35861. // (axis scale updated), and should be performed each time update.
  35862. // So put it here temporarily, although it is not appropriate to
  35863. // put a model-writing procedure in `view`.
  35864. this.axisPointerClass && fixValue(axisModel);
  35865. AxisView.superApply(this, 'render', arguments);
  35866. updateAxisPointer(this, axisModel, ecModel, api, payload, true);
  35867. },
  35868. /**
  35869. * Action handler.
  35870. * @public
  35871. * @param {module:echarts/coord/cartesian/AxisModel} axisModel
  35872. * @param {module:echarts/model/Global} ecModel
  35873. * @param {module:echarts/ExtensionAPI} api
  35874. * @param {Object} payload
  35875. */
  35876. updateAxisPointer: function (axisModel, ecModel, api, payload, force) {
  35877. updateAxisPointer(this, axisModel, ecModel, api, payload, false);
  35878. },
  35879. /**
  35880. * @override
  35881. */
  35882. remove: function (ecModel, api) {
  35883. var axisPointer = this._axisPointer;
  35884. axisPointer && axisPointer.remove(api);
  35885. AxisView.superApply(this, 'remove', arguments);
  35886. },
  35887. /**
  35888. * @override
  35889. */
  35890. dispose: function (ecModel, api) {
  35891. disposeAxisPointer(this, api);
  35892. AxisView.superApply(this, 'dispose', arguments);
  35893. }
  35894. });
  35895. function updateAxisPointer(axisView, axisModel, ecModel, api, payload, forceRender) {
  35896. var Clazz = AxisView.getAxisPointerClass(axisView.axisPointerClass);
  35897. if (!Clazz) {
  35898. return;
  35899. }
  35900. var axisPointerModel = getAxisPointerModel(axisModel);
  35901. axisPointerModel
  35902. ? (axisView._axisPointer || (axisView._axisPointer = new Clazz()))
  35903. .render(axisModel, axisPointerModel, api, forceRender)
  35904. : disposeAxisPointer(axisView, api);
  35905. }
  35906. function disposeAxisPointer(axisView, ecModel, api) {
  35907. var axisPointer = axisView._axisPointer;
  35908. axisPointer && axisPointer.dispose(ecModel, api);
  35909. axisView._axisPointer = null;
  35910. }
  35911. var axisPointerClazz = [];
  35912. AxisView.registerAxisPointerClass = function (type, clazz) {
  35913. if (__DEV__) {
  35914. if (axisPointerClazz[type]) {
  35915. throw new Error('axisPointer ' + type + ' exists');
  35916. }
  35917. }
  35918. axisPointerClazz[type] = clazz;
  35919. };
  35920. AxisView.getAxisPointerClass = function (type) {
  35921. return type && axisPointerClazz[type];
  35922. };
  35923. /*
  35924. * Licensed to the Apache Software Foundation (ASF) under one
  35925. * or more contributor license agreements. See the NOTICE file
  35926. * distributed with this work for additional information
  35927. * regarding copyright ownership. The ASF licenses this file
  35928. * to you under the Apache License, Version 2.0 (the
  35929. * "License"); you may not use this file except in compliance
  35930. * with the License. You may obtain a copy of the License at
  35931. *
  35932. * http://www.apache.org/licenses/LICENSE-2.0
  35933. *
  35934. * Unless required by applicable law or agreed to in writing,
  35935. * software distributed under the License is distributed on an
  35936. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  35937. * KIND, either express or implied. See the License for the
  35938. * specific language governing permissions and limitations
  35939. * under the License.
  35940. */
  35941. /**
  35942. * Can only be called after coordinate system creation stage.
  35943. * (Can be called before coordinate system update stage).
  35944. *
  35945. * @param {Object} opt {labelInside}
  35946. * @return {Object} {
  35947. * position, rotation, labelDirection, labelOffset,
  35948. * tickDirection, labelRotate, z2
  35949. * }
  35950. */
  35951. function layout$1(gridModel, axisModel, opt) {
  35952. opt = opt || {};
  35953. var grid = gridModel.coordinateSystem;
  35954. var axis = axisModel.axis;
  35955. var layout = {};
  35956. var otherAxisOnZeroOf = axis.getAxesOnZeroOf()[0];
  35957. var rawAxisPosition = axis.position;
  35958. var axisPosition = otherAxisOnZeroOf ? 'onZero' : rawAxisPosition;
  35959. var axisDim = axis.dim;
  35960. var rect = grid.getRect();
  35961. var rectBound = [rect.x, rect.x + rect.width, rect.y, rect.y + rect.height];
  35962. var idx = {left: 0, right: 1, top: 0, bottom: 1, onZero: 2};
  35963. var axisOffset = axisModel.get('offset') || 0;
  35964. var posBound = axisDim === 'x'
  35965. ? [rectBound[2] - axisOffset, rectBound[3] + axisOffset]
  35966. : [rectBound[0] - axisOffset, rectBound[1] + axisOffset];
  35967. if (otherAxisOnZeroOf) {
  35968. var onZeroCoord = otherAxisOnZeroOf.toGlobalCoord(otherAxisOnZeroOf.dataToCoord(0));
  35969. posBound[idx.onZero] = Math.max(Math.min(onZeroCoord, posBound[1]), posBound[0]);
  35970. }
  35971. // Axis position
  35972. layout.position = [
  35973. axisDim === 'y' ? posBound[idx[axisPosition]] : rectBound[0],
  35974. axisDim === 'x' ? posBound[idx[axisPosition]] : rectBound[3]
  35975. ];
  35976. // Axis rotation
  35977. layout.rotation = Math.PI / 2 * (axisDim === 'x' ? 0 : 1);
  35978. // Tick and label direction, x y is axisDim
  35979. var dirMap = {top: -1, bottom: 1, left: -1, right: 1};
  35980. layout.labelDirection = layout.tickDirection = layout.nameDirection = dirMap[rawAxisPosition];
  35981. layout.labelOffset = otherAxisOnZeroOf ? posBound[idx[rawAxisPosition]] - posBound[idx.onZero] : 0;
  35982. if (axisModel.get('axisTick.inside')) {
  35983. layout.tickDirection = -layout.tickDirection;
  35984. }
  35985. if (retrieve(opt.labelInside, axisModel.get('axisLabel.inside'))) {
  35986. layout.labelDirection = -layout.labelDirection;
  35987. }
  35988. // Special label rotation
  35989. var labelRotate = axisModel.get('axisLabel.rotate');
  35990. layout.labelRotate = axisPosition === 'top' ? -labelRotate : labelRotate;
  35991. // Over splitLine and splitArea
  35992. layout.z2 = 1;
  35993. return layout;
  35994. }
  35995. /*
  35996. * Licensed to the Apache Software Foundation (ASF) under one
  35997. * or more contributor license agreements. See the NOTICE file
  35998. * distributed with this work for additional information
  35999. * regarding copyright ownership. The ASF licenses this file
  36000. * to you under the Apache License, Version 2.0 (the
  36001. * "License"); you may not use this file except in compliance
  36002. * with the License. You may obtain a copy of the License at
  36003. *
  36004. * http://www.apache.org/licenses/LICENSE-2.0
  36005. *
  36006. * Unless required by applicable law or agreed to in writing,
  36007. * software distributed under the License is distributed on an
  36008. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  36009. * KIND, either express or implied. See the License for the
  36010. * specific language governing permissions and limitations
  36011. * under the License.
  36012. */
  36013. var axisBuilderAttrs = [
  36014. 'axisLine', 'axisTickLabel', 'axisName'
  36015. ];
  36016. var selfBuilderAttrs = [
  36017. 'splitArea', 'splitLine'
  36018. ];
  36019. // function getAlignWithLabel(model, axisModel) {
  36020. // var alignWithLabel = model.get('alignWithLabel');
  36021. // if (alignWithLabel === 'auto') {
  36022. // alignWithLabel = axisModel.get('axisTick.alignWithLabel');
  36023. // }
  36024. // return alignWithLabel;
  36025. // }
  36026. var CartesianAxisView = AxisView.extend({
  36027. type: 'cartesianAxis',
  36028. axisPointerClass: 'CartesianAxisPointer',
  36029. /**
  36030. * @override
  36031. */
  36032. render: function (axisModel, ecModel, api, payload) {
  36033. this.group.removeAll();
  36034. var oldAxisGroup = this._axisGroup;
  36035. this._axisGroup = new Group();
  36036. this.group.add(this._axisGroup);
  36037. if (!axisModel.get('show')) {
  36038. return;
  36039. }
  36040. var gridModel = axisModel.getCoordSysModel();
  36041. var layout = layout$1(gridModel, axisModel);
  36042. var axisBuilder = new AxisBuilder(axisModel, layout);
  36043. each$1(axisBuilderAttrs, axisBuilder.add, axisBuilder);
  36044. this._axisGroup.add(axisBuilder.getGroup());
  36045. each$1(selfBuilderAttrs, function (name) {
  36046. if (axisModel.get(name + '.show')) {
  36047. this['_' + name](axisModel, gridModel);
  36048. }
  36049. }, this);
  36050. groupTransition(oldAxisGroup, this._axisGroup, axisModel);
  36051. CartesianAxisView.superCall(this, 'render', axisModel, ecModel, api, payload);
  36052. },
  36053. remove: function () {
  36054. this._splitAreaColors = null;
  36055. },
  36056. /**
  36057. * @param {module:echarts/coord/cartesian/AxisModel} axisModel
  36058. * @param {module:echarts/coord/cartesian/GridModel} gridModel
  36059. * @private
  36060. */
  36061. _splitLine: function (axisModel, gridModel) {
  36062. var axis = axisModel.axis;
  36063. if (axis.scale.isBlank()) {
  36064. return;
  36065. }
  36066. var splitLineModel = axisModel.getModel('splitLine');
  36067. var lineStyleModel = splitLineModel.getModel('lineStyle');
  36068. var lineColors = lineStyleModel.get('color');
  36069. lineColors = isArray(lineColors) ? lineColors : [lineColors];
  36070. var gridRect = gridModel.coordinateSystem.getRect();
  36071. var isHorizontal = axis.isHorizontal();
  36072. var lineCount = 0;
  36073. var ticksCoords = axis.getTicksCoords({
  36074. tickModel: splitLineModel
  36075. });
  36076. var p1 = [];
  36077. var p2 = [];
  36078. // Simple optimization
  36079. // Batching the lines if color are the same
  36080. var lineStyle = lineStyleModel.getLineStyle();
  36081. for (var i = 0; i < ticksCoords.length; i++) {
  36082. var tickCoord = axis.toGlobalCoord(ticksCoords[i].coord);
  36083. if (isHorizontal) {
  36084. p1[0] = tickCoord;
  36085. p1[1] = gridRect.y;
  36086. p2[0] = tickCoord;
  36087. p2[1] = gridRect.y + gridRect.height;
  36088. }
  36089. else {
  36090. p1[0] = gridRect.x;
  36091. p1[1] = tickCoord;
  36092. p2[0] = gridRect.x + gridRect.width;
  36093. p2[1] = tickCoord;
  36094. }
  36095. var colorIndex = (lineCount++) % lineColors.length;
  36096. var tickValue = ticksCoords[i].tickValue;
  36097. this._axisGroup.add(new Line({
  36098. anid: tickValue != null ? 'line_' + ticksCoords[i].tickValue : null,
  36099. subPixelOptimize: true,
  36100. shape: {
  36101. x1: p1[0],
  36102. y1: p1[1],
  36103. x2: p2[0],
  36104. y2: p2[1]
  36105. },
  36106. style: defaults({
  36107. stroke: lineColors[colorIndex]
  36108. }, lineStyle),
  36109. silent: true
  36110. }));
  36111. }
  36112. },
  36113. /**
  36114. * @param {module:echarts/coord/cartesian/AxisModel} axisModel
  36115. * @param {module:echarts/coord/cartesian/GridModel} gridModel
  36116. * @private
  36117. */
  36118. _splitArea: function (axisModel, gridModel) {
  36119. var axis = axisModel.axis;
  36120. if (axis.scale.isBlank()) {
  36121. return;
  36122. }
  36123. var splitAreaModel = axisModel.getModel('splitArea');
  36124. var areaStyleModel = splitAreaModel.getModel('areaStyle');
  36125. var areaColors = areaStyleModel.get('color');
  36126. var gridRect = gridModel.coordinateSystem.getRect();
  36127. var ticksCoords = axis.getTicksCoords({
  36128. tickModel: splitAreaModel,
  36129. clamp: true
  36130. });
  36131. if (!ticksCoords.length) {
  36132. return;
  36133. }
  36134. // For Making appropriate splitArea animation, the color and anid
  36135. // should be corresponding to previous one if possible.
  36136. var areaColorsLen = areaColors.length;
  36137. var lastSplitAreaColors = this._splitAreaColors;
  36138. var newSplitAreaColors = createHashMap();
  36139. var colorIndex = 0;
  36140. if (lastSplitAreaColors) {
  36141. for (var i = 0; i < ticksCoords.length; i++) {
  36142. var cIndex = lastSplitAreaColors.get(ticksCoords[i].tickValue);
  36143. if (cIndex != null) {
  36144. colorIndex = (cIndex + (areaColorsLen - 1) * i) % areaColorsLen;
  36145. break;
  36146. }
  36147. }
  36148. }
  36149. var prev = axis.toGlobalCoord(ticksCoords[0].coord);
  36150. var areaStyle = areaStyleModel.getAreaStyle();
  36151. areaColors = isArray(areaColors) ? areaColors : [areaColors];
  36152. for (var i = 1; i < ticksCoords.length; i++) {
  36153. var tickCoord = axis.toGlobalCoord(ticksCoords[i].coord);
  36154. var x;
  36155. var y;
  36156. var width;
  36157. var height;
  36158. if (axis.isHorizontal()) {
  36159. x = prev;
  36160. y = gridRect.y;
  36161. width = tickCoord - x;
  36162. height = gridRect.height;
  36163. prev = x + width;
  36164. }
  36165. else {
  36166. x = gridRect.x;
  36167. y = prev;
  36168. width = gridRect.width;
  36169. height = tickCoord - y;
  36170. prev = y + height;
  36171. }
  36172. var tickValue = ticksCoords[i - 1].tickValue;
  36173. tickValue != null && newSplitAreaColors.set(tickValue, colorIndex);
  36174. this._axisGroup.add(new Rect({
  36175. anid: tickValue != null ? 'area_' + tickValue : null,
  36176. shape: {
  36177. x: x,
  36178. y: y,
  36179. width: width,
  36180. height: height
  36181. },
  36182. style: defaults({
  36183. fill: areaColors[colorIndex]
  36184. }, areaStyle),
  36185. silent: true
  36186. }));
  36187. colorIndex = (colorIndex + 1) % areaColorsLen;
  36188. }
  36189. this._splitAreaColors = newSplitAreaColors;
  36190. }
  36191. });
  36192. CartesianAxisView.extend({
  36193. type: 'xAxis'
  36194. });
  36195. CartesianAxisView.extend({
  36196. type: 'yAxis'
  36197. });
  36198. /*
  36199. * Licensed to the Apache Software Foundation (ASF) under one
  36200. * or more contributor license agreements. See the NOTICE file
  36201. * distributed with this work for additional information
  36202. * regarding copyright ownership. The ASF licenses this file
  36203. * to you under the Apache License, Version 2.0 (the
  36204. * "License"); you may not use this file except in compliance
  36205. * with the License. You may obtain a copy of the License at
  36206. *
  36207. * http://www.apache.org/licenses/LICENSE-2.0
  36208. *
  36209. * Unless required by applicable law or agreed to in writing,
  36210. * software distributed under the License is distributed on an
  36211. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  36212. * KIND, either express or implied. See the License for the
  36213. * specific language governing permissions and limitations
  36214. * under the License.
  36215. */
  36216. /*
  36217. * Licensed to the Apache Software Foundation (ASF) under one
  36218. * or more contributor license agreements. See the NOTICE file
  36219. * distributed with this work for additional information
  36220. * regarding copyright ownership. The ASF licenses this file
  36221. * to you under the Apache License, Version 2.0 (the
  36222. * "License"); you may not use this file except in compliance
  36223. * with the License. You may obtain a copy of the License at
  36224. *
  36225. * http://www.apache.org/licenses/LICENSE-2.0
  36226. *
  36227. * Unless required by applicable law or agreed to in writing,
  36228. * software distributed under the License is distributed on an
  36229. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  36230. * KIND, either express or implied. See the License for the
  36231. * specific language governing permissions and limitations
  36232. * under the License.
  36233. */
  36234. // Grid view
  36235. extendComponentView({
  36236. type: 'grid',
  36237. render: function (gridModel, ecModel) {
  36238. this.group.removeAll();
  36239. if (gridModel.get('show')) {
  36240. this.group.add(new Rect({
  36241. shape: gridModel.coordinateSystem.getRect(),
  36242. style: defaults({
  36243. fill: gridModel.get('backgroundColor')
  36244. }, gridModel.getItemStyle()),
  36245. silent: true,
  36246. z2: -1
  36247. }));
  36248. }
  36249. }
  36250. });
  36251. registerPreprocessor(function (option) {
  36252. // Only create grid when need
  36253. if (option.xAxis && option.yAxis && !option.grid) {
  36254. option.grid = {};
  36255. }
  36256. });
  36257. /*
  36258. * Licensed to the Apache Software Foundation (ASF) under one
  36259. * or more contributor license agreements. See the NOTICE file
  36260. * distributed with this work for additional information
  36261. * regarding copyright ownership. The ASF licenses this file
  36262. * to you under the Apache License, Version 2.0 (the
  36263. * "License"); you may not use this file except in compliance
  36264. * with the License. You may obtain a copy of the License at
  36265. *
  36266. * http://www.apache.org/licenses/LICENSE-2.0
  36267. *
  36268. * Unless required by applicable law or agreed to in writing,
  36269. * software distributed under the License is distributed on an
  36270. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  36271. * KIND, either express or implied. See the License for the
  36272. * specific language governing permissions and limitations
  36273. * under the License.
  36274. */
  36275. // In case developer forget to include grid component
  36276. registerVisual(visualSymbol('line', 'circle', 'line'));
  36277. registerLayout(pointsLayout('line'));
  36278. // Down sample after filter
  36279. registerProcessor(
  36280. PRIORITY.PROCESSOR.STATISTIC,
  36281. dataSample('line')
  36282. );
  36283. /*
  36284. * Licensed to the Apache Software Foundation (ASF) under one
  36285. * or more contributor license agreements. See the NOTICE file
  36286. * distributed with this work for additional information
  36287. * regarding copyright ownership. The ASF licenses this file
  36288. * to you under the Apache License, Version 2.0 (the
  36289. * "License"); you may not use this file except in compliance
  36290. * with the License. You may obtain a copy of the License at
  36291. *
  36292. * http://www.apache.org/licenses/LICENSE-2.0
  36293. *
  36294. * Unless required by applicable law or agreed to in writing,
  36295. * software distributed under the License is distributed on an
  36296. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  36297. * KIND, either express or implied. See the License for the
  36298. * specific language governing permissions and limitations
  36299. * under the License.
  36300. */
  36301. var BaseBarSeries = SeriesModel.extend({
  36302. type: 'series.__base_bar__',
  36303. getInitialData: function (option, ecModel) {
  36304. return createListFromArray(this.getSource(), this);
  36305. },
  36306. getMarkerPosition: function (value) {
  36307. var coordSys = this.coordinateSystem;
  36308. if (coordSys) {
  36309. // PENDING if clamp ?
  36310. var pt = coordSys.dataToPoint(coordSys.clampData(value));
  36311. var data = this.getData();
  36312. var offset = data.getLayout('offset');
  36313. var size = data.getLayout('size');
  36314. var offsetIndex = coordSys.getBaseAxis().isHorizontal() ? 0 : 1;
  36315. pt[offsetIndex] += offset + size / 2;
  36316. return pt;
  36317. }
  36318. return [NaN, NaN];
  36319. },
  36320. defaultOption: {
  36321. zlevel: 0, // 一级层叠
  36322. z: 2, // 二级层叠
  36323. coordinateSystem: 'cartesian2d',
  36324. legendHoverLink: true,
  36325. // stack: null
  36326. // Cartesian coordinate system
  36327. // xAxisIndex: 0,
  36328. // yAxisIndex: 0,
  36329. // 最小高度改为0
  36330. barMinHeight: 0,
  36331. // 最小角度为0,仅对极坐标系下的柱状图有效
  36332. barMinAngle: 0,
  36333. // cursor: null,
  36334. large: false,
  36335. largeThreshold: 400,
  36336. progressive: 3e3,
  36337. progressiveChunkMode: 'mod',
  36338. // barMaxWidth: null,
  36339. // 默认自适应
  36340. // barWidth: null,
  36341. // 柱间距离,默认为柱形宽度的30%,可设固定值
  36342. // barGap: '30%',
  36343. // 类目间柱形距离,默认为类目间距的20%,可设固定值
  36344. // barCategoryGap: '20%',
  36345. // label: {
  36346. // show: false
  36347. // },
  36348. itemStyle: {},
  36349. emphasis: {}
  36350. }
  36351. });
  36352. /*
  36353. * Licensed to the Apache Software Foundation (ASF) under one
  36354. * or more contributor license agreements. See the NOTICE file
  36355. * distributed with this work for additional information
  36356. * regarding copyright ownership. The ASF licenses this file
  36357. * to you under the Apache License, Version 2.0 (the
  36358. * "License"); you may not use this file except in compliance
  36359. * with the License. You may obtain a copy of the License at
  36360. *
  36361. * http://www.apache.org/licenses/LICENSE-2.0
  36362. *
  36363. * Unless required by applicable law or agreed to in writing,
  36364. * software distributed under the License is distributed on an
  36365. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  36366. * KIND, either express or implied. See the License for the
  36367. * specific language governing permissions and limitations
  36368. * under the License.
  36369. */
  36370. BaseBarSeries.extend({
  36371. type: 'series.bar',
  36372. dependencies: ['grid', 'polar'],
  36373. brushSelector: 'rect',
  36374. /**
  36375. * @override
  36376. */
  36377. getProgressive: function () {
  36378. // Do not support progressive in normal mode.
  36379. return this.get('large')
  36380. ? this.get('progressive')
  36381. : false;
  36382. },
  36383. /**
  36384. * @override
  36385. */
  36386. getProgressiveThreshold: function () {
  36387. // Do not support progressive in normal mode.
  36388. var progressiveThreshold = this.get('progressiveThreshold');
  36389. var largeThreshold = this.get('largeThreshold');
  36390. if (largeThreshold > progressiveThreshold) {
  36391. progressiveThreshold = largeThreshold;
  36392. }
  36393. return progressiveThreshold;
  36394. }
  36395. });
  36396. /*
  36397. * Licensed to the Apache Software Foundation (ASF) under one
  36398. * or more contributor license agreements. See the NOTICE file
  36399. * distributed with this work for additional information
  36400. * regarding copyright ownership. The ASF licenses this file
  36401. * to you under the Apache License, Version 2.0 (the
  36402. * "License"); you may not use this file except in compliance
  36403. * with the License. You may obtain a copy of the License at
  36404. *
  36405. * http://www.apache.org/licenses/LICENSE-2.0
  36406. *
  36407. * Unless required by applicable law or agreed to in writing,
  36408. * software distributed under the License is distributed on an
  36409. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  36410. * KIND, either express or implied. See the License for the
  36411. * specific language governing permissions and limitations
  36412. * under the License.
  36413. */
  36414. function setLabel(
  36415. normalStyle, hoverStyle, itemModel, color, seriesModel, dataIndex, labelPositionOutside
  36416. ) {
  36417. var labelModel = itemModel.getModel('label');
  36418. var hoverLabelModel = itemModel.getModel('emphasis.label');
  36419. setLabelStyle(
  36420. normalStyle, hoverStyle, labelModel, hoverLabelModel,
  36421. {
  36422. labelFetcher: seriesModel,
  36423. labelDataIndex: dataIndex,
  36424. defaultText: getDefaultLabel(seriesModel.getData(), dataIndex),
  36425. isRectText: true,
  36426. autoColor: color
  36427. }
  36428. );
  36429. fixPosition(normalStyle);
  36430. fixPosition(hoverStyle);
  36431. }
  36432. function fixPosition(style, labelPositionOutside) {
  36433. if (style.textPosition === 'outside') {
  36434. style.textPosition = labelPositionOutside;
  36435. }
  36436. }
  36437. /*
  36438. * Licensed to the Apache Software Foundation (ASF) under one
  36439. * or more contributor license agreements. See the NOTICE file
  36440. * distributed with this work for additional information
  36441. * regarding copyright ownership. The ASF licenses this file
  36442. * to you under the Apache License, Version 2.0 (the
  36443. * "License"); you may not use this file except in compliance
  36444. * with the License. You may obtain a copy of the License at
  36445. *
  36446. * http://www.apache.org/licenses/LICENSE-2.0
  36447. *
  36448. * Unless required by applicable law or agreed to in writing,
  36449. * software distributed under the License is distributed on an
  36450. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  36451. * KIND, either express or implied. See the License for the
  36452. * specific language governing permissions and limitations
  36453. * under the License.
  36454. */
  36455. var getBarItemStyle = makeStyleMapper(
  36456. [
  36457. ['fill', 'color'],
  36458. ['stroke', 'borderColor'],
  36459. ['lineWidth', 'borderWidth'],
  36460. // Compatitable with 2
  36461. ['stroke', 'barBorderColor'],
  36462. ['lineWidth', 'barBorderWidth'],
  36463. ['opacity'],
  36464. ['shadowBlur'],
  36465. ['shadowOffsetX'],
  36466. ['shadowOffsetY'],
  36467. ['shadowColor']
  36468. ]
  36469. );
  36470. var barItemStyle = {
  36471. getBarItemStyle: function (excludes) {
  36472. var style = getBarItemStyle(this, excludes);
  36473. if (this.getBorderLineDash) {
  36474. var lineDash = this.getBorderLineDash();
  36475. lineDash && (style.lineDash = lineDash);
  36476. }
  36477. return style;
  36478. }
  36479. };
  36480. /*
  36481. * Licensed to the Apache Software Foundation (ASF) under one
  36482. * or more contributor license agreements. See the NOTICE file
  36483. * distributed with this work for additional information
  36484. * regarding copyright ownership. The ASF licenses this file
  36485. * to you under the Apache License, Version 2.0 (the
  36486. * "License"); you may not use this file except in compliance
  36487. * with the License. You may obtain a copy of the License at
  36488. *
  36489. * http://www.apache.org/licenses/LICENSE-2.0
  36490. *
  36491. * Unless required by applicable law or agreed to in writing,
  36492. * software distributed under the License is distributed on an
  36493. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  36494. * KIND, either express or implied. See the License for the
  36495. * specific language governing permissions and limitations
  36496. * under the License.
  36497. */
  36498. var BAR_BORDER_WIDTH_QUERY = ['itemStyle', 'barBorderWidth'];
  36499. var _eventPos = [0, 0];
  36500. // FIXME
  36501. // Just for compatible with ec2.
  36502. extend(Model.prototype, barItemStyle);
  36503. extendChartView({
  36504. type: 'bar',
  36505. render: function (seriesModel, ecModel, api) {
  36506. this._updateDrawMode(seriesModel);
  36507. var coordinateSystemType = seriesModel.get('coordinateSystem');
  36508. if (coordinateSystemType === 'cartesian2d'
  36509. || coordinateSystemType === 'polar'
  36510. ) {
  36511. this._isLargeDraw
  36512. ? this._renderLarge(seriesModel, ecModel, api)
  36513. : this._renderNormal(seriesModel, ecModel, api);
  36514. }
  36515. else if (__DEV__) {
  36516. console.warn('Only cartesian2d and polar supported for bar.');
  36517. }
  36518. return this.group;
  36519. },
  36520. incrementalPrepareRender: function (seriesModel, ecModel, api) {
  36521. this._clear();
  36522. this._updateDrawMode(seriesModel);
  36523. },
  36524. incrementalRender: function (params, seriesModel, ecModel, api) {
  36525. // Do not support progressive in normal mode.
  36526. this._incrementalRenderLarge(params, seriesModel);
  36527. },
  36528. _updateDrawMode: function (seriesModel) {
  36529. var isLargeDraw = seriesModel.pipelineContext.large;
  36530. if (this._isLargeDraw == null || isLargeDraw ^ this._isLargeDraw) {
  36531. this._isLargeDraw = isLargeDraw;
  36532. this._clear();
  36533. }
  36534. },
  36535. _renderNormal: function (seriesModel, ecModel, api) {
  36536. var group = this.group;
  36537. var data = seriesModel.getData();
  36538. var oldData = this._data;
  36539. var coord = seriesModel.coordinateSystem;
  36540. var baseAxis = coord.getBaseAxis();
  36541. var isHorizontalOrRadial;
  36542. if (coord.type === 'cartesian2d') {
  36543. isHorizontalOrRadial = baseAxis.isHorizontal();
  36544. }
  36545. else if (coord.type === 'polar') {
  36546. isHorizontalOrRadial = baseAxis.dim === 'angle';
  36547. }
  36548. var animationModel = seriesModel.isAnimationEnabled() ? seriesModel : null;
  36549. data.diff(oldData)
  36550. .add(function (dataIndex) {
  36551. if (!data.hasValue(dataIndex)) {
  36552. return;
  36553. }
  36554. var itemModel = data.getItemModel(dataIndex);
  36555. var layout = getLayout[coord.type](data, dataIndex, itemModel);
  36556. var el = elementCreator[coord.type](
  36557. data, dataIndex, itemModel, layout, isHorizontalOrRadial, animationModel
  36558. );
  36559. data.setItemGraphicEl(dataIndex, el);
  36560. group.add(el);
  36561. updateStyle(
  36562. el, data, dataIndex, itemModel, layout,
  36563. seriesModel, isHorizontalOrRadial, coord.type === 'polar'
  36564. );
  36565. })
  36566. .update(function (newIndex, oldIndex) {
  36567. var el = oldData.getItemGraphicEl(oldIndex);
  36568. if (!data.hasValue(newIndex)) {
  36569. group.remove(el);
  36570. return;
  36571. }
  36572. var itemModel = data.getItemModel(newIndex);
  36573. var layout = getLayout[coord.type](data, newIndex, itemModel);
  36574. if (el) {
  36575. updateProps(el, {shape: layout}, animationModel, newIndex);
  36576. }
  36577. else {
  36578. el = elementCreator[coord.type](
  36579. data, newIndex, itemModel, layout, isHorizontalOrRadial, animationModel, true
  36580. );
  36581. }
  36582. data.setItemGraphicEl(newIndex, el);
  36583. // Add back
  36584. group.add(el);
  36585. updateStyle(
  36586. el, data, newIndex, itemModel, layout,
  36587. seriesModel, isHorizontalOrRadial, coord.type === 'polar'
  36588. );
  36589. })
  36590. .remove(function (dataIndex) {
  36591. var el = oldData.getItemGraphicEl(dataIndex);
  36592. if (coord.type === 'cartesian2d') {
  36593. el && removeRect(dataIndex, animationModel, el);
  36594. }
  36595. else {
  36596. el && removeSector(dataIndex, animationModel, el);
  36597. }
  36598. })
  36599. .execute();
  36600. this._data = data;
  36601. },
  36602. _renderLarge: function (seriesModel, ecModel, api) {
  36603. this._clear();
  36604. createLarge(seriesModel, this.group);
  36605. },
  36606. _incrementalRenderLarge: function (params, seriesModel) {
  36607. createLarge(seriesModel, this.group, true);
  36608. },
  36609. dispose: noop,
  36610. remove: function (ecModel) {
  36611. this._clear(ecModel);
  36612. },
  36613. _clear: function (ecModel) {
  36614. var group = this.group;
  36615. var data = this._data;
  36616. if (ecModel && ecModel.get('animation') && data && !this._isLargeDraw) {
  36617. data.eachItemGraphicEl(function (el) {
  36618. if (el.type === 'sector') {
  36619. removeSector(el.dataIndex, ecModel, el);
  36620. }
  36621. else {
  36622. removeRect(el.dataIndex, ecModel, el);
  36623. }
  36624. });
  36625. }
  36626. else {
  36627. group.removeAll();
  36628. }
  36629. this._data = null;
  36630. }
  36631. });
  36632. var elementCreator = {
  36633. cartesian2d: function (
  36634. data, dataIndex, itemModel, layout, isHorizontal,
  36635. animationModel, isUpdate
  36636. ) {
  36637. var rect = new Rect({shape: extend({}, layout)});
  36638. // Animation
  36639. if (animationModel) {
  36640. var rectShape = rect.shape;
  36641. var animateProperty = isHorizontal ? 'height' : 'width';
  36642. var animateTarget = {};
  36643. rectShape[animateProperty] = 0;
  36644. animateTarget[animateProperty] = layout[animateProperty];
  36645. graphic[isUpdate ? 'updateProps' : 'initProps'](rect, {
  36646. shape: animateTarget
  36647. }, animationModel, dataIndex);
  36648. }
  36649. return rect;
  36650. },
  36651. polar: function (
  36652. data, dataIndex, itemModel, layout, isRadial,
  36653. animationModel, isUpdate
  36654. ) {
  36655. // Keep the same logic with bar in catesion: use end value to control
  36656. // direction. Notice that if clockwise is true (by default), the sector
  36657. // will always draw clockwisely, no matter whether endAngle is greater
  36658. // or less than startAngle.
  36659. var clockwise = layout.startAngle < layout.endAngle;
  36660. var sector = new Sector({
  36661. shape: defaults({clockwise: clockwise}, layout)
  36662. });
  36663. // Animation
  36664. if (animationModel) {
  36665. var sectorShape = sector.shape;
  36666. var animateProperty = isRadial ? 'r' : 'endAngle';
  36667. var animateTarget = {};
  36668. sectorShape[animateProperty] = isRadial ? 0 : layout.startAngle;
  36669. animateTarget[animateProperty] = layout[animateProperty];
  36670. graphic[isUpdate ? 'updateProps' : 'initProps'](sector, {
  36671. shape: animateTarget
  36672. }, animationModel, dataIndex);
  36673. }
  36674. return sector;
  36675. }
  36676. };
  36677. function removeRect(dataIndex, animationModel, el) {
  36678. // Not show text when animating
  36679. el.style.text = null;
  36680. updateProps(el, {
  36681. shape: {
  36682. width: 0
  36683. }
  36684. }, animationModel, dataIndex, function () {
  36685. el.parent && el.parent.remove(el);
  36686. });
  36687. }
  36688. function removeSector(dataIndex, animationModel, el) {
  36689. // Not show text when animating
  36690. el.style.text = null;
  36691. updateProps(el, {
  36692. shape: {
  36693. r: el.shape.r0
  36694. }
  36695. }, animationModel, dataIndex, function () {
  36696. el.parent && el.parent.remove(el);
  36697. });
  36698. }
  36699. var getLayout = {
  36700. cartesian2d: function (data, dataIndex, itemModel) {
  36701. var layout = data.getItemLayout(dataIndex);
  36702. var fixedLineWidth = getLineWidth(itemModel, layout);
  36703. // fix layout with lineWidth
  36704. var signX = layout.width > 0 ? 1 : -1;
  36705. var signY = layout.height > 0 ? 1 : -1;
  36706. return {
  36707. x: layout.x + signX * fixedLineWidth / 2,
  36708. y: layout.y + signY * fixedLineWidth / 2,
  36709. width: layout.width - signX * fixedLineWidth,
  36710. height: layout.height - signY * fixedLineWidth
  36711. };
  36712. },
  36713. polar: function (data, dataIndex, itemModel) {
  36714. var layout = data.getItemLayout(dataIndex);
  36715. return {
  36716. cx: layout.cx,
  36717. cy: layout.cy,
  36718. r0: layout.r0,
  36719. r: layout.r,
  36720. startAngle: layout.startAngle,
  36721. endAngle: layout.endAngle
  36722. };
  36723. }
  36724. };
  36725. function updateStyle(
  36726. el, data, dataIndex, itemModel, layout, seriesModel, isHorizontal, isPolar
  36727. ) {
  36728. var color = data.getItemVisual(dataIndex, 'color');
  36729. var opacity = data.getItemVisual(dataIndex, 'opacity');
  36730. var itemStyleModel = itemModel.getModel('itemStyle');
  36731. var hoverStyle = itemModel.getModel('emphasis.itemStyle').getBarItemStyle();
  36732. if (!isPolar) {
  36733. el.setShape('r', itemStyleModel.get('barBorderRadius') || 0);
  36734. }
  36735. el.useStyle(defaults(
  36736. {
  36737. fill: color,
  36738. opacity: opacity
  36739. },
  36740. itemStyleModel.getBarItemStyle()
  36741. ));
  36742. var cursorStyle = itemModel.getShallow('cursor');
  36743. cursorStyle && el.attr('cursor', cursorStyle);
  36744. var labelPositionOutside = isHorizontal
  36745. ? (layout.height > 0 ? 'bottom' : 'top')
  36746. : (layout.width > 0 ? 'left' : 'right');
  36747. if (!isPolar) {
  36748. setLabel(
  36749. el.style, hoverStyle, itemModel, color,
  36750. seriesModel, dataIndex, labelPositionOutside
  36751. );
  36752. }
  36753. setHoverStyle(el, hoverStyle);
  36754. }
  36755. // In case width or height are too small.
  36756. function getLineWidth(itemModel, rawLayout) {
  36757. var lineWidth = itemModel.get(BAR_BORDER_WIDTH_QUERY) || 0;
  36758. return Math.min(lineWidth, Math.abs(rawLayout.width), Math.abs(rawLayout.height));
  36759. }
  36760. var LargePath = Path.extend({
  36761. type: 'largeBar',
  36762. shape: {points: []},
  36763. buildPath: function (ctx, shape) {
  36764. // Drawing lines is more efficient than drawing
  36765. // a whole line or drawing rects.
  36766. var points = shape.points;
  36767. var startPoint = this.__startPoint;
  36768. var baseDimIdx = this.__baseDimIdx;
  36769. for (var i = 0; i < points.length; i += 2) {
  36770. startPoint[baseDimIdx] = points[i + baseDimIdx];
  36771. ctx.moveTo(startPoint[0], startPoint[1]);
  36772. ctx.lineTo(points[i], points[i + 1]);
  36773. }
  36774. }
  36775. });
  36776. function createLarge(seriesModel, group, incremental) {
  36777. // TODO support polar
  36778. var data = seriesModel.getData();
  36779. var startPoint = [];
  36780. var baseDimIdx = data.getLayout('valueAxisHorizontal') ? 1 : 0;
  36781. startPoint[1 - baseDimIdx] = data.getLayout('valueAxisStart');
  36782. var el = new LargePath({
  36783. shape: {points: data.getLayout('largePoints')},
  36784. incremental: !!incremental,
  36785. __startPoint: startPoint,
  36786. __baseDimIdx: baseDimIdx,
  36787. __largeDataIndices: data.getLayout('largeDataIndices'),
  36788. __barWidth: data.getLayout('barWidth')
  36789. });
  36790. group.add(el);
  36791. setLargeStyle(el, seriesModel, data);
  36792. // Enable tooltip and user mouse/touch event handlers.
  36793. el.seriesIndex = seriesModel.seriesIndex;
  36794. if (!seriesModel.get('silent')) {
  36795. el.on('mousedown', largePathUpdateDataIndex);
  36796. el.on('mousemove', largePathUpdateDataIndex);
  36797. }
  36798. }
  36799. // Use throttle to avoid frequently traverse to find dataIndex.
  36800. var largePathUpdateDataIndex = throttle(function (event) {
  36801. var largePath = this;
  36802. var dataIndex = largePathFindDataIndex(largePath, event.offsetX, event.offsetY);
  36803. largePath.dataIndex = dataIndex >= 0 ? dataIndex : null;
  36804. }, 30, false);
  36805. function largePathFindDataIndex(largePath, x, y) {
  36806. var baseDimIdx = largePath.__baseDimIdx;
  36807. var valueDimIdx = 1 - baseDimIdx;
  36808. var points = largePath.shape.points;
  36809. var largeDataIndices = largePath.__largeDataIndices;
  36810. var barWidthHalf = Math.abs(largePath.__barWidth / 2);
  36811. var startValueVal = largePath.__startPoint[valueDimIdx];
  36812. _eventPos[0] = x;
  36813. _eventPos[1] = y;
  36814. var pointerBaseVal = _eventPos[baseDimIdx];
  36815. var pointerValueVal = _eventPos[1 - baseDimIdx];
  36816. var baseLowerBound = pointerBaseVal - barWidthHalf;
  36817. var baseUpperBound = pointerBaseVal + barWidthHalf;
  36818. for (var i = 0, len = points.length / 2; i < len; i++) {
  36819. var ii = i * 2;
  36820. var barBaseVal = points[ii + baseDimIdx];
  36821. var barValueVal = points[ii + valueDimIdx];
  36822. if (
  36823. barBaseVal >= baseLowerBound && barBaseVal <= baseUpperBound
  36824. && (
  36825. startValueVal <= barValueVal
  36826. ? (pointerValueVal >= startValueVal && pointerValueVal <= barValueVal)
  36827. : (pointerValueVal >= barValueVal && pointerValueVal <= startValueVal)
  36828. )
  36829. ) {
  36830. return largeDataIndices[i];
  36831. }
  36832. }
  36833. return -1;
  36834. }
  36835. function setLargeStyle(el, seriesModel, data) {
  36836. var borderColor = data.getVisual('borderColor') || data.getVisual('color');
  36837. var itemStyle = seriesModel.getModel('itemStyle').getItemStyle(['color', 'borderColor']);
  36838. el.useStyle(itemStyle);
  36839. el.style.fill = null;
  36840. el.style.stroke = borderColor;
  36841. el.style.lineWidth = data.getLayout('barWidth');
  36842. }
  36843. /*
  36844. * Licensed to the Apache Software Foundation (ASF) under one
  36845. * or more contributor license agreements. See the NOTICE file
  36846. * distributed with this work for additional information
  36847. * regarding copyright ownership. The ASF licenses this file
  36848. * to you under the Apache License, Version 2.0 (the
  36849. * "License"); you may not use this file except in compliance
  36850. * with the License. You may obtain a copy of the License at
  36851. *
  36852. * http://www.apache.org/licenses/LICENSE-2.0
  36853. *
  36854. * Unless required by applicable law or agreed to in writing,
  36855. * software distributed under the License is distributed on an
  36856. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  36857. * KIND, either express or implied. See the License for the
  36858. * specific language governing permissions and limitations
  36859. * under the License.
  36860. */
  36861. // In case developer forget to include grid component
  36862. registerLayout(PRIORITY.VISUAL.LAYOUT, curry(layout, 'bar'));
  36863. // Use higher prority to avoid to be blocked by other overall layout, which do not
  36864. // only exist in this module, but probably also exist in other modules, like `barPolar`.
  36865. registerLayout(PRIORITY.VISUAL.PROGRESSIVE_LAYOUT, largeLayout);
  36866. registerVisual({
  36867. seriesType: 'bar',
  36868. reset: function (seriesModel) {
  36869. // Visual coding for legend
  36870. seriesModel.getData().setVisual('legendSymbol', 'roundRect');
  36871. }
  36872. });
  36873. /*
  36874. * Licensed to the Apache Software Foundation (ASF) under one
  36875. * or more contributor license agreements. See the NOTICE file
  36876. * distributed with this work for additional information
  36877. * regarding copyright ownership. The ASF licenses this file
  36878. * to you under the Apache License, Version 2.0 (the
  36879. * "License"); you may not use this file except in compliance
  36880. * with the License. You may obtain a copy of the License at
  36881. *
  36882. * http://www.apache.org/licenses/LICENSE-2.0
  36883. *
  36884. * Unless required by applicable law or agreed to in writing,
  36885. * software distributed under the License is distributed on an
  36886. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  36887. * KIND, either express or implied. See the License for the
  36888. * specific language governing permissions and limitations
  36889. * under the License.
  36890. */
  36891. /**
  36892. * [Usage]:
  36893. * (1)
  36894. * createListSimply(seriesModel, ['value']);
  36895. * (2)
  36896. * createListSimply(seriesModel, {
  36897. * coordDimensions: ['value'],
  36898. * dimensionsCount: 5
  36899. * });
  36900. *
  36901. * @param {module:echarts/model/Series} seriesModel
  36902. * @param {Object|Array.<string|Object>} opt opt or coordDimensions
  36903. * The options in opt, see `echarts/data/helper/createDimensions`
  36904. * @param {Array.<string>} [nameList]
  36905. * @return {module:echarts/data/List}
  36906. */
  36907. var createListSimply = function (seriesModel, opt, nameList) {
  36908. opt = isArray(opt) && {coordDimensions: opt} || extend({}, opt);
  36909. var source = seriesModel.getSource();
  36910. var dimensionsInfo = createDimensions(source, opt);
  36911. var list = new List(dimensionsInfo, seriesModel);
  36912. list.initData(source, nameList);
  36913. return list;
  36914. };
  36915. /*
  36916. * Licensed to the Apache Software Foundation (ASF) under one
  36917. * or more contributor license agreements. See the NOTICE file
  36918. * distributed with this work for additional information
  36919. * regarding copyright ownership. The ASF licenses this file
  36920. * to you under the Apache License, Version 2.0 (the
  36921. * "License"); you may not use this file except in compliance
  36922. * with the License. You may obtain a copy of the License at
  36923. *
  36924. * http://www.apache.org/licenses/LICENSE-2.0
  36925. *
  36926. * Unless required by applicable law or agreed to in writing,
  36927. * software distributed under the License is distributed on an
  36928. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  36929. * KIND, either express or implied. See the License for the
  36930. * specific language governing permissions and limitations
  36931. * under the License.
  36932. */
  36933. /**
  36934. * Data selectable mixin for chart series.
  36935. * To eanble data select, option of series must have `selectedMode`.
  36936. * And each data item will use `selected` to toggle itself selected status
  36937. */
  36938. var selectableMixin = {
  36939. /**
  36940. * @param {Array.<Object>} targetList [{name, value, selected}, ...]
  36941. * If targetList is an array, it should like [{name: ..., value: ...}, ...].
  36942. * If targetList is a "List", it must have coordDim: 'value' dimension and name.
  36943. */
  36944. updateSelectedMap: function (targetList) {
  36945. this._targetList = isArray(targetList) ? targetList.slice() : [];
  36946. this._selectTargetMap = reduce(targetList || [], function (targetMap, target) {
  36947. targetMap.set(target.name, target);
  36948. return targetMap;
  36949. }, createHashMap());
  36950. },
  36951. /**
  36952. * Either name or id should be passed as input here.
  36953. * If both of them are defined, id is used.
  36954. *
  36955. * @param {string|undefined} name name of data
  36956. * @param {number|undefined} id dataIndex of data
  36957. */
  36958. // PENGING If selectedMode is null ?
  36959. select: function (name, id) {
  36960. var target = id != null
  36961. ? this._targetList[id]
  36962. : this._selectTargetMap.get(name);
  36963. var selectedMode = this.get('selectedMode');
  36964. if (selectedMode === 'single') {
  36965. this._selectTargetMap.each(function (target) {
  36966. target.selected = false;
  36967. });
  36968. }
  36969. target && (target.selected = true);
  36970. },
  36971. /**
  36972. * Either name or id should be passed as input here.
  36973. * If both of them are defined, id is used.
  36974. *
  36975. * @param {string|undefined} name name of data
  36976. * @param {number|undefined} id dataIndex of data
  36977. */
  36978. unSelect: function (name, id) {
  36979. var target = id != null
  36980. ? this._targetList[id]
  36981. : this._selectTargetMap.get(name);
  36982. // var selectedMode = this.get('selectedMode');
  36983. // selectedMode !== 'single' && target && (target.selected = false);
  36984. target && (target.selected = false);
  36985. },
  36986. /**
  36987. * Either name or id should be passed as input here.
  36988. * If both of them are defined, id is used.
  36989. *
  36990. * @param {string|undefined} name name of data
  36991. * @param {number|undefined} id dataIndex of data
  36992. */
  36993. toggleSelected: function (name, id) {
  36994. var target = id != null
  36995. ? this._targetList[id]
  36996. : this._selectTargetMap.get(name);
  36997. if (target != null) {
  36998. this[target.selected ? 'unSelect' : 'select'](name, id);
  36999. return target.selected;
  37000. }
  37001. },
  37002. /**
  37003. * Either name or id should be passed as input here.
  37004. * If both of them are defined, id is used.
  37005. *
  37006. * @param {string|undefined} name name of data
  37007. * @param {number|undefined} id dataIndex of data
  37008. */
  37009. isSelected: function (name, id) {
  37010. var target = id != null
  37011. ? this._targetList[id]
  37012. : this._selectTargetMap.get(name);
  37013. return target && target.selected;
  37014. }
  37015. };
  37016. /*
  37017. * Licensed to the Apache Software Foundation (ASF) under one
  37018. * or more contributor license agreements. See the NOTICE file
  37019. * distributed with this work for additional information
  37020. * regarding copyright ownership. The ASF licenses this file
  37021. * to you under the Apache License, Version 2.0 (the
  37022. * "License"); you may not use this file except in compliance
  37023. * with the License. You may obtain a copy of the License at
  37024. *
  37025. * http://www.apache.org/licenses/LICENSE-2.0
  37026. *
  37027. * Unless required by applicable law or agreed to in writing,
  37028. * software distributed under the License is distributed on an
  37029. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  37030. * KIND, either express or implied. See the License for the
  37031. * specific language governing permissions and limitations
  37032. * under the License.
  37033. */
  37034. var PieSeries = extendSeriesModel({
  37035. type: 'series.pie',
  37036. // Overwrite
  37037. init: function (option) {
  37038. PieSeries.superApply(this, 'init', arguments);
  37039. // Enable legend selection for each data item
  37040. // Use a function instead of direct access because data reference may changed
  37041. this.legendDataProvider = function () {
  37042. return this.getRawData();
  37043. };
  37044. this.updateSelectedMap(this._createSelectableList());
  37045. this._defaultLabelLine(option);
  37046. },
  37047. // Overwrite
  37048. mergeOption: function (newOption) {
  37049. PieSeries.superCall(this, 'mergeOption', newOption);
  37050. this.updateSelectedMap(this._createSelectableList());
  37051. },
  37052. getInitialData: function (option, ecModel) {
  37053. return createListSimply(this, ['value']);
  37054. },
  37055. _createSelectableList: function () {
  37056. var data = this.getRawData();
  37057. var valueDim = data.mapDimension('value');
  37058. var targetList = [];
  37059. for (var i = 0, len = data.count(); i < len; i++) {
  37060. targetList.push({
  37061. name: data.getName(i),
  37062. value: data.get(valueDim, i),
  37063. selected: retrieveRawAttr(data, i, 'selected')
  37064. });
  37065. }
  37066. return targetList;
  37067. },
  37068. // Overwrite
  37069. getDataParams: function (dataIndex) {
  37070. var data = this.getData();
  37071. var params = PieSeries.superCall(this, 'getDataParams', dataIndex);
  37072. // FIXME toFixed?
  37073. var valueList = [];
  37074. data.each(data.mapDimension('value'), function (value) {
  37075. valueList.push(value);
  37076. });
  37077. params.percent = getPercentWithPrecision(
  37078. valueList,
  37079. dataIndex,
  37080. data.hostModel.get('percentPrecision')
  37081. );
  37082. params.$vars.push('percent');
  37083. return params;
  37084. },
  37085. _defaultLabelLine: function (option) {
  37086. // Extend labelLine emphasis
  37087. defaultEmphasis(option, 'labelLine', ['show']);
  37088. var labelLineNormalOpt = option.labelLine;
  37089. var labelLineEmphasisOpt = option.emphasis.labelLine;
  37090. // Not show label line if `label.normal.show = false`
  37091. labelLineNormalOpt.show = labelLineNormalOpt.show
  37092. && option.label.show;
  37093. labelLineEmphasisOpt.show = labelLineEmphasisOpt.show
  37094. && option.emphasis.label.show;
  37095. },
  37096. defaultOption: {
  37097. zlevel: 0,
  37098. z: 2,
  37099. legendHoverLink: true,
  37100. hoverAnimation: true,
  37101. // 默认全局居中
  37102. center: ['50%', '50%'],
  37103. radius: [0, '75%'],
  37104. // 默认顺时针
  37105. clockwise: true,
  37106. startAngle: 90,
  37107. // 最小角度改为0
  37108. minAngle: 0,
  37109. // If the angle of a sector less than `minShowLabelAngle`,
  37110. // the label will not be displayed.
  37111. minShowLabelAngle: 0,
  37112. // 选中时扇区偏移量
  37113. selectedOffset: 10,
  37114. // 高亮扇区偏移量
  37115. hoverOffset: 10,
  37116. // If use strategy to avoid label overlapping
  37117. avoidLabelOverlap: true,
  37118. // 选择模式,默认关闭,可选single,multiple
  37119. // selectedMode: false,
  37120. // 南丁格尔玫瑰图模式,'radius'(半径) | 'area'(面积)
  37121. // roseType: null,
  37122. percentPrecision: 2,
  37123. // If still show when all data zero.
  37124. stillShowZeroSum: true,
  37125. // cursor: null,
  37126. label: {
  37127. // If rotate around circle
  37128. rotate: false,
  37129. show: true,
  37130. // 'outer', 'inside', 'center'
  37131. position: 'outer'
  37132. // formatter: 标签文本格式器,同Tooltip.formatter,不支持异步回调
  37133. // 默认使用全局文本样式,详见TEXTSTYLE
  37134. // distance: 当position为inner时有效,为label位置到圆心的距离与圆半径(环状图为内外半径和)的比例系数
  37135. },
  37136. // Enabled when label.normal.position is 'outer'
  37137. labelLine: {
  37138. show: true,
  37139. // 引导线两段中的第一段长度
  37140. length: 15,
  37141. // 引导线两段中的第二段长度
  37142. length2: 15,
  37143. smooth: false,
  37144. lineStyle: {
  37145. // color: 各异,
  37146. width: 1,
  37147. type: 'solid'
  37148. }
  37149. },
  37150. itemStyle: {
  37151. borderWidth: 1
  37152. },
  37153. // Animation type canbe expansion, scale
  37154. animationType: 'expansion',
  37155. animationEasing: 'cubicOut'
  37156. }
  37157. });
  37158. mixin(PieSeries, selectableMixin);
  37159. /*
  37160. * Licensed to the Apache Software Foundation (ASF) under one
  37161. * or more contributor license agreements. See the NOTICE file
  37162. * distributed with this work for additional information
  37163. * regarding copyright ownership. The ASF licenses this file
  37164. * to you under the Apache License, Version 2.0 (the
  37165. * "License"); you may not use this file except in compliance
  37166. * with the License. You may obtain a copy of the License at
  37167. *
  37168. * http://www.apache.org/licenses/LICENSE-2.0
  37169. *
  37170. * Unless required by applicable law or agreed to in writing,
  37171. * software distributed under the License is distributed on an
  37172. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  37173. * KIND, either express or implied. See the License for the
  37174. * specific language governing permissions and limitations
  37175. * under the License.
  37176. */
  37177. /**
  37178. * @param {module:echarts/model/Series} seriesModel
  37179. * @param {boolean} hasAnimation
  37180. * @inner
  37181. */
  37182. function updateDataSelected(uid, seriesModel, hasAnimation, api) {
  37183. var data = seriesModel.getData();
  37184. var dataIndex = this.dataIndex;
  37185. var name = data.getName(dataIndex);
  37186. var selectedOffset = seriesModel.get('selectedOffset');
  37187. api.dispatchAction({
  37188. type: 'pieToggleSelect',
  37189. from: uid,
  37190. name: name,
  37191. seriesId: seriesModel.id
  37192. });
  37193. data.each(function (idx) {
  37194. toggleItemSelected(
  37195. data.getItemGraphicEl(idx),
  37196. data.getItemLayout(idx),
  37197. seriesModel.isSelected(data.getName(idx)),
  37198. selectedOffset,
  37199. hasAnimation
  37200. );
  37201. });
  37202. }
  37203. /**
  37204. * @param {module:zrender/graphic/Sector} el
  37205. * @param {Object} layout
  37206. * @param {boolean} isSelected
  37207. * @param {number} selectedOffset
  37208. * @param {boolean} hasAnimation
  37209. * @inner
  37210. */
  37211. function toggleItemSelected(el, layout, isSelected, selectedOffset, hasAnimation) {
  37212. var midAngle = (layout.startAngle + layout.endAngle) / 2;
  37213. var dx = Math.cos(midAngle);
  37214. var dy = Math.sin(midAngle);
  37215. var offset = isSelected ? selectedOffset : 0;
  37216. var position = [dx * offset, dy * offset];
  37217. hasAnimation
  37218. // animateTo will stop revious animation like update transition
  37219. ? el.animate()
  37220. .when(200, {
  37221. position: position
  37222. })
  37223. .start('bounceOut')
  37224. : el.attr('position', position);
  37225. }
  37226. /**
  37227. * Piece of pie including Sector, Label, LabelLine
  37228. * @constructor
  37229. * @extends {module:zrender/graphic/Group}
  37230. */
  37231. function PiePiece(data, idx) {
  37232. Group.call(this);
  37233. var sector = new Sector({
  37234. z2: 2
  37235. });
  37236. var polyline = new Polyline();
  37237. var text = new Text();
  37238. this.add(sector);
  37239. this.add(polyline);
  37240. this.add(text);
  37241. this.updateData(data, idx, true);
  37242. }
  37243. var piePieceProto = PiePiece.prototype;
  37244. piePieceProto.updateData = function (data, idx, firstCreate) {
  37245. var sector = this.childAt(0);
  37246. var labelLine = this.childAt(1);
  37247. var labelText = this.childAt(2);
  37248. var seriesModel = data.hostModel;
  37249. var itemModel = data.getItemModel(idx);
  37250. var layout = data.getItemLayout(idx);
  37251. var sectorShape = extend({}, layout);
  37252. sectorShape.label = null;
  37253. if (firstCreate) {
  37254. sector.setShape(sectorShape);
  37255. var animationType = seriesModel.getShallow('animationType');
  37256. if (animationType === 'scale') {
  37257. sector.shape.r = layout.r0;
  37258. initProps(sector, {
  37259. shape: {
  37260. r: layout.r
  37261. }
  37262. }, seriesModel, idx);
  37263. }
  37264. // Expansion
  37265. else {
  37266. sector.shape.endAngle = layout.startAngle;
  37267. updateProps(sector, {
  37268. shape: {
  37269. endAngle: layout.endAngle
  37270. }
  37271. }, seriesModel, idx);
  37272. }
  37273. }
  37274. else {
  37275. updateProps(sector, {
  37276. shape: sectorShape
  37277. }, seriesModel, idx);
  37278. }
  37279. // Update common style
  37280. var visualColor = data.getItemVisual(idx, 'color');
  37281. sector.useStyle(
  37282. defaults(
  37283. {
  37284. lineJoin: 'bevel',
  37285. fill: visualColor
  37286. },
  37287. itemModel.getModel('itemStyle').getItemStyle()
  37288. )
  37289. );
  37290. sector.hoverStyle = itemModel.getModel('emphasis.itemStyle').getItemStyle();
  37291. var cursorStyle = itemModel.getShallow('cursor');
  37292. cursorStyle && sector.attr('cursor', cursorStyle);
  37293. // Toggle selected
  37294. toggleItemSelected(
  37295. this,
  37296. data.getItemLayout(idx),
  37297. seriesModel.isSelected(null, idx),
  37298. seriesModel.get('selectedOffset'),
  37299. seriesModel.get('animation')
  37300. );
  37301. this._updateLabel(data, idx);
  37302. this.highDownOnUpdate = (itemModel.get('hoverAnimation') && seriesModel.isAnimationEnabled())
  37303. ? function (fromState, toState) {
  37304. if (toState === 'emphasis') {
  37305. labelLine.ignore = labelLine.hoverIgnore;
  37306. labelText.ignore = labelText.hoverIgnore;
  37307. // Sector may has animation of updating data. Force to move to the last frame
  37308. // Or it may stopped on the wrong shape
  37309. sector.stopAnimation(true);
  37310. sector.animateTo({
  37311. shape: {
  37312. r: layout.r + seriesModel.get('hoverOffset')
  37313. }
  37314. }, 300, 'elasticOut');
  37315. }
  37316. else {
  37317. labelLine.ignore = labelLine.normalIgnore;
  37318. labelText.ignore = labelText.normalIgnore;
  37319. sector.stopAnimation(true);
  37320. sector.animateTo({
  37321. shape: {
  37322. r: layout.r
  37323. }
  37324. }, 300, 'elasticOut');
  37325. }
  37326. }
  37327. : null;
  37328. setHoverStyle(this);
  37329. };
  37330. piePieceProto._updateLabel = function (data, idx) {
  37331. var labelLine = this.childAt(1);
  37332. var labelText = this.childAt(2);
  37333. var seriesModel = data.hostModel;
  37334. var itemModel = data.getItemModel(idx);
  37335. var layout = data.getItemLayout(idx);
  37336. var labelLayout = layout.label;
  37337. var visualColor = data.getItemVisual(idx, 'color');
  37338. if (!labelLayout || isNaN(labelLayout.x) || isNaN(labelLayout.y)) {
  37339. labelText.ignore = labelText.normalIgnore = labelText.hoverIgnore =
  37340. labelLine.ignore = labelLine.normalIgnore = labelLine.hoverIgnore = true;
  37341. return;
  37342. }
  37343. updateProps(labelLine, {
  37344. shape: {
  37345. points: labelLayout.linePoints || [
  37346. [labelLayout.x, labelLayout.y], [labelLayout.x, labelLayout.y], [labelLayout.x, labelLayout.y]
  37347. ]
  37348. }
  37349. }, seriesModel, idx);
  37350. updateProps(labelText, {
  37351. style: {
  37352. x: labelLayout.x,
  37353. y: labelLayout.y
  37354. }
  37355. }, seriesModel, idx);
  37356. labelText.attr({
  37357. rotation: labelLayout.rotation,
  37358. origin: [labelLayout.x, labelLayout.y],
  37359. z2: 10
  37360. });
  37361. var labelModel = itemModel.getModel('label');
  37362. var labelHoverModel = itemModel.getModel('emphasis.label');
  37363. var labelLineModel = itemModel.getModel('labelLine');
  37364. var labelLineHoverModel = itemModel.getModel('emphasis.labelLine');
  37365. var visualColor = data.getItemVisual(idx, 'color');
  37366. setLabelStyle(
  37367. labelText.style, labelText.hoverStyle = {}, labelModel, labelHoverModel,
  37368. {
  37369. labelFetcher: data.hostModel,
  37370. labelDataIndex: idx,
  37371. defaultText: data.getName(idx),
  37372. autoColor: visualColor,
  37373. useInsideStyle: !!labelLayout.inside
  37374. },
  37375. {
  37376. textAlign: labelLayout.textAlign,
  37377. textVerticalAlign: labelLayout.verticalAlign,
  37378. opacity: data.getItemVisual(idx, 'opacity')
  37379. }
  37380. );
  37381. labelText.ignore = labelText.normalIgnore = !labelModel.get('show');
  37382. labelText.hoverIgnore = !labelHoverModel.get('show');
  37383. labelLine.ignore = labelLine.normalIgnore = !labelLineModel.get('show');
  37384. labelLine.hoverIgnore = !labelLineHoverModel.get('show');
  37385. // Default use item visual color
  37386. labelLine.setStyle({
  37387. stroke: visualColor,
  37388. opacity: data.getItemVisual(idx, 'opacity')
  37389. });
  37390. labelLine.setStyle(labelLineModel.getModel('lineStyle').getLineStyle());
  37391. labelLine.hoverStyle = labelLineHoverModel.getModel('lineStyle').getLineStyle();
  37392. var smooth = labelLineModel.get('smooth');
  37393. if (smooth && smooth === true) {
  37394. smooth = 0.4;
  37395. }
  37396. labelLine.setShape({
  37397. smooth: smooth
  37398. });
  37399. };
  37400. inherits(PiePiece, Group);
  37401. // Pie view
  37402. var PieView = Chart.extend({
  37403. type: 'pie',
  37404. init: function () {
  37405. var sectorGroup = new Group();
  37406. this._sectorGroup = sectorGroup;
  37407. },
  37408. render: function (seriesModel, ecModel, api, payload) {
  37409. if (payload && (payload.from === this.uid)) {
  37410. return;
  37411. }
  37412. var data = seriesModel.getData();
  37413. var oldData = this._data;
  37414. var group = this.group;
  37415. var hasAnimation = ecModel.get('animation');
  37416. var isFirstRender = !oldData;
  37417. var animationType = seriesModel.get('animationType');
  37418. var onSectorClick = curry(
  37419. updateDataSelected, this.uid, seriesModel, hasAnimation, api
  37420. );
  37421. var selectedMode = seriesModel.get('selectedMode');
  37422. data.diff(oldData)
  37423. .add(function (idx) {
  37424. var piePiece = new PiePiece(data, idx);
  37425. // Default expansion animation
  37426. if (isFirstRender && animationType !== 'scale') {
  37427. piePiece.eachChild(function (child) {
  37428. child.stopAnimation(true);
  37429. });
  37430. }
  37431. selectedMode && piePiece.on('click', onSectorClick);
  37432. data.setItemGraphicEl(idx, piePiece);
  37433. group.add(piePiece);
  37434. })
  37435. .update(function (newIdx, oldIdx) {
  37436. var piePiece = oldData.getItemGraphicEl(oldIdx);
  37437. piePiece.updateData(data, newIdx);
  37438. piePiece.off('click');
  37439. selectedMode && piePiece.on('click', onSectorClick);
  37440. group.add(piePiece);
  37441. data.setItemGraphicEl(newIdx, piePiece);
  37442. })
  37443. .remove(function (idx) {
  37444. var piePiece = oldData.getItemGraphicEl(idx);
  37445. group.remove(piePiece);
  37446. })
  37447. .execute();
  37448. if (
  37449. hasAnimation && isFirstRender && data.count() > 0
  37450. // Default expansion animation
  37451. && animationType !== 'scale'
  37452. ) {
  37453. var shape = data.getItemLayout(0);
  37454. for (var s = 1; isNaN(shape.startAngle) && s < data.count(); ++s) {
  37455. shape = data.getItemLayout(s);
  37456. }
  37457. var r = Math.max(api.getWidth(), api.getHeight()) / 2;
  37458. var removeClipPath = bind(group.removeClipPath, group);
  37459. group.setClipPath(this._createClipPath(
  37460. shape.cx, shape.cy, r, shape.startAngle, shape.clockwise, removeClipPath, seriesModel
  37461. ));
  37462. }
  37463. else {
  37464. // clipPath is used in first-time animation, so remove it when otherwise. See: #8994
  37465. group.removeClipPath();
  37466. }
  37467. this._data = data;
  37468. },
  37469. dispose: function () {},
  37470. _createClipPath: function (
  37471. cx, cy, r, startAngle, clockwise, cb, seriesModel
  37472. ) {
  37473. var clipPath = new Sector({
  37474. shape: {
  37475. cx: cx,
  37476. cy: cy,
  37477. r0: 0,
  37478. r: r,
  37479. startAngle: startAngle,
  37480. endAngle: startAngle,
  37481. clockwise: clockwise
  37482. }
  37483. });
  37484. initProps(clipPath, {
  37485. shape: {
  37486. endAngle: startAngle + (clockwise ? 1 : -1) * Math.PI * 2
  37487. }
  37488. }, seriesModel, cb);
  37489. return clipPath;
  37490. },
  37491. /**
  37492. * @implement
  37493. */
  37494. containPoint: function (point, seriesModel) {
  37495. var data = seriesModel.getData();
  37496. var itemLayout = data.getItemLayout(0);
  37497. if (itemLayout) {
  37498. var dx = point[0] - itemLayout.cx;
  37499. var dy = point[1] - itemLayout.cy;
  37500. var radius = Math.sqrt(dx * dx + dy * dy);
  37501. return radius <= itemLayout.r && radius >= itemLayout.r0;
  37502. }
  37503. }
  37504. });
  37505. /*
  37506. * Licensed to the Apache Software Foundation (ASF) under one
  37507. * or more contributor license agreements. See the NOTICE file
  37508. * distributed with this work for additional information
  37509. * regarding copyright ownership. The ASF licenses this file
  37510. * to you under the Apache License, Version 2.0 (the
  37511. * "License"); you may not use this file except in compliance
  37512. * with the License. You may obtain a copy of the License at
  37513. *
  37514. * http://www.apache.org/licenses/LICENSE-2.0
  37515. *
  37516. * Unless required by applicable law or agreed to in writing,
  37517. * software distributed under the License is distributed on an
  37518. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  37519. * KIND, either express or implied. See the License for the
  37520. * specific language governing permissions and limitations
  37521. * under the License.
  37522. */
  37523. var createDataSelectAction = function (seriesType, actionInfos) {
  37524. each$1(actionInfos, function (actionInfo) {
  37525. actionInfo.update = 'updateView';
  37526. /**
  37527. * @payload
  37528. * @property {string} seriesName
  37529. * @property {string} name
  37530. */
  37531. registerAction(actionInfo, function (payload, ecModel) {
  37532. var selected = {};
  37533. ecModel.eachComponent(
  37534. {mainType: 'series', subType: seriesType, query: payload},
  37535. function (seriesModel) {
  37536. if (seriesModel[actionInfo.method]) {
  37537. seriesModel[actionInfo.method](
  37538. payload.name,
  37539. payload.dataIndex
  37540. );
  37541. }
  37542. var data = seriesModel.getData();
  37543. // Create selected map
  37544. data.each(function (idx) {
  37545. var name = data.getName(idx);
  37546. selected[name] = seriesModel.isSelected(name)
  37547. || false;
  37548. });
  37549. }
  37550. );
  37551. return {
  37552. name: payload.name,
  37553. selected: selected,
  37554. seriesId: payload.seriesId
  37555. };
  37556. });
  37557. });
  37558. };
  37559. /*
  37560. * Licensed to the Apache Software Foundation (ASF) under one
  37561. * or more contributor license agreements. See the NOTICE file
  37562. * distributed with this work for additional information
  37563. * regarding copyright ownership. The ASF licenses this file
  37564. * to you under the Apache License, Version 2.0 (the
  37565. * "License"); you may not use this file except in compliance
  37566. * with the License. You may obtain a copy of the License at
  37567. *
  37568. * http://www.apache.org/licenses/LICENSE-2.0
  37569. *
  37570. * Unless required by applicable law or agreed to in writing,
  37571. * software distributed under the License is distributed on an
  37572. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  37573. * KIND, either express or implied. See the License for the
  37574. * specific language governing permissions and limitations
  37575. * under the License.
  37576. */
  37577. // Pick color from palette for each data item.
  37578. // Applicable for charts that require applying color palette
  37579. // in data level (like pie, funnel, chord).
  37580. var dataColor = function (seriesType) {
  37581. return {
  37582. getTargetSeries: function (ecModel) {
  37583. // Pie and funnel may use diferrent scope
  37584. var paletteScope = {};
  37585. var seiresModelMap = createHashMap();
  37586. ecModel.eachSeriesByType(seriesType, function (seriesModel) {
  37587. seriesModel.__paletteScope = paletteScope;
  37588. seiresModelMap.set(seriesModel.uid, seriesModel);
  37589. });
  37590. return seiresModelMap;
  37591. },
  37592. reset: function (seriesModel, ecModel) {
  37593. var dataAll = seriesModel.getRawData();
  37594. var idxMap = {};
  37595. var data = seriesModel.getData();
  37596. data.each(function (idx) {
  37597. var rawIdx = data.getRawIndex(idx);
  37598. idxMap[rawIdx] = idx;
  37599. });
  37600. dataAll.each(function (rawIdx) {
  37601. var filteredIdx = idxMap[rawIdx];
  37602. // If series.itemStyle.normal.color is a function. itemVisual may be encoded
  37603. var singleDataColor = filteredIdx != null
  37604. && data.getItemVisual(filteredIdx, 'color', true);
  37605. if (!singleDataColor) {
  37606. // FIXME Performance
  37607. var itemModel = dataAll.getItemModel(rawIdx);
  37608. var color = itemModel.get('itemStyle.color')
  37609. || seriesModel.getColorFromPalette(
  37610. dataAll.getName(rawIdx) || (rawIdx + ''), seriesModel.__paletteScope,
  37611. dataAll.count()
  37612. );
  37613. // Legend may use the visual info in data before processed
  37614. dataAll.setItemVisual(rawIdx, 'color', color);
  37615. // Data is not filtered
  37616. if (filteredIdx != null) {
  37617. data.setItemVisual(filteredIdx, 'color', color);
  37618. }
  37619. }
  37620. else {
  37621. // Set data all color for legend
  37622. dataAll.setItemVisual(rawIdx, 'color', singleDataColor);
  37623. }
  37624. });
  37625. }
  37626. };
  37627. };
  37628. /*
  37629. * Licensed to the Apache Software Foundation (ASF) under one
  37630. * or more contributor license agreements. See the NOTICE file
  37631. * distributed with this work for additional information
  37632. * regarding copyright ownership. The ASF licenses this file
  37633. * to you under the Apache License, Version 2.0 (the
  37634. * "License"); you may not use this file except in compliance
  37635. * with the License. You may obtain a copy of the License at
  37636. *
  37637. * http://www.apache.org/licenses/LICENSE-2.0
  37638. *
  37639. * Unless required by applicable law or agreed to in writing,
  37640. * software distributed under the License is distributed on an
  37641. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  37642. * KIND, either express or implied. See the License for the
  37643. * specific language governing permissions and limitations
  37644. * under the License.
  37645. */
  37646. // FIXME emphasis label position is not same with normal label position
  37647. var RADIAN$1 = Math.PI / 180;
  37648. function adjustSingleSide(list, cx, cy, r, dir, viewWidth, viewHeight) {
  37649. list.sort(function (a, b) {
  37650. return a.y - b.y;
  37651. });
  37652. function shiftDown(start, end, delta, dir) {
  37653. for (var j = start; j < end; j++) {
  37654. list[j].y += delta;
  37655. if (j > start
  37656. && j + 1 < end
  37657. && list[j + 1].y > list[j].y + list[j].height
  37658. ) {
  37659. shiftUp(j, delta / 2);
  37660. return;
  37661. }
  37662. }
  37663. shiftUp(end - 1, delta / 2);
  37664. }
  37665. function shiftUp(end, delta) {
  37666. for (var j = end; j >= 0; j--) {
  37667. list[j].y -= delta;
  37668. if (j > 0
  37669. && list[j].y > list[j - 1].y + list[j - 1].height
  37670. ) {
  37671. break;
  37672. }
  37673. }
  37674. }
  37675. function changeX(list, isDownList, cx, cy, r, dir) {
  37676. var lastDeltaX = dir > 0
  37677. ? isDownList // right-side
  37678. ? Number.MAX_VALUE // down
  37679. : 0 // up
  37680. : isDownList // left-side
  37681. ? Number.MAX_VALUE // down
  37682. : 0; // up
  37683. for (var i = 0, l = list.length; i < l; i++) {
  37684. var deltaY = Math.abs(list[i].y - cy);
  37685. var length = list[i].len;
  37686. var length2 = list[i].len2;
  37687. var deltaX = (deltaY < r + length)
  37688. ? Math.sqrt(
  37689. (r + length + length2) * (r + length + length2)
  37690. - deltaY * deltaY
  37691. )
  37692. : Math.abs(list[i].x - cx);
  37693. if (isDownList && deltaX >= lastDeltaX) {
  37694. // right-down, left-down
  37695. deltaX = lastDeltaX - 10;
  37696. }
  37697. if (!isDownList && deltaX <= lastDeltaX) {
  37698. // right-up, left-up
  37699. deltaX = lastDeltaX + 10;
  37700. }
  37701. list[i].x = cx + deltaX * dir;
  37702. lastDeltaX = deltaX;
  37703. }
  37704. }
  37705. var lastY = 0;
  37706. var delta;
  37707. var len = list.length;
  37708. var upList = [];
  37709. var downList = [];
  37710. for (var i = 0; i < len; i++) {
  37711. delta = list[i].y - lastY;
  37712. if (delta < 0) {
  37713. shiftDown(i, len, -delta, dir);
  37714. }
  37715. lastY = list[i].y + list[i].height;
  37716. }
  37717. if (viewHeight - lastY < 0) {
  37718. shiftUp(len - 1, lastY - viewHeight);
  37719. }
  37720. for (var i = 0; i < len; i++) {
  37721. if (list[i].y >= cy) {
  37722. downList.push(list[i]);
  37723. }
  37724. else {
  37725. upList.push(list[i]);
  37726. }
  37727. }
  37728. changeX(upList, false, cx, cy, r, dir);
  37729. changeX(downList, true, cx, cy, r, dir);
  37730. }
  37731. function avoidOverlap(labelLayoutList, cx, cy, r, viewWidth, viewHeight) {
  37732. var leftList = [];
  37733. var rightList = [];
  37734. for (var i = 0; i < labelLayoutList.length; i++) {
  37735. if (isPositionCenter(labelLayoutList[i])) {
  37736. continue;
  37737. }
  37738. if (labelLayoutList[i].x < cx) {
  37739. leftList.push(labelLayoutList[i]);
  37740. }
  37741. else {
  37742. rightList.push(labelLayoutList[i]);
  37743. }
  37744. }
  37745. adjustSingleSide(rightList, cx, cy, r, 1, viewWidth, viewHeight);
  37746. adjustSingleSide(leftList, cx, cy, r, -1, viewWidth, viewHeight);
  37747. for (var i = 0; i < labelLayoutList.length; i++) {
  37748. if (isPositionCenter(labelLayoutList[i])) {
  37749. continue;
  37750. }
  37751. var linePoints = labelLayoutList[i].linePoints;
  37752. if (linePoints) {
  37753. var dist = linePoints[1][0] - linePoints[2][0];
  37754. if (labelLayoutList[i].x < cx) {
  37755. linePoints[2][0] = labelLayoutList[i].x + 3;
  37756. }
  37757. else {
  37758. linePoints[2][0] = labelLayoutList[i].x - 3;
  37759. }
  37760. linePoints[1][1] = linePoints[2][1] = labelLayoutList[i].y;
  37761. linePoints[1][0] = linePoints[2][0] + dist;
  37762. }
  37763. }
  37764. }
  37765. function isPositionCenter(layout) {
  37766. // Not change x for center label
  37767. return layout.position === 'center';
  37768. }
  37769. var labelLayout = function (seriesModel, r, viewWidth, viewHeight, sum) {
  37770. var data = seriesModel.getData();
  37771. var labelLayoutList = [];
  37772. var cx;
  37773. var cy;
  37774. var hasLabelRotate = false;
  37775. var minShowLabelRadian = (seriesModel.get('minShowLabelAngle') || 0) * RADIAN$1;
  37776. data.each(function (idx) {
  37777. var layout = data.getItemLayout(idx);
  37778. var itemModel = data.getItemModel(idx);
  37779. var labelModel = itemModel.getModel('label');
  37780. // Use position in normal or emphasis
  37781. var labelPosition = labelModel.get('position') || itemModel.get('emphasis.label.position');
  37782. var labelLineModel = itemModel.getModel('labelLine');
  37783. var labelLineLen = labelLineModel.get('length');
  37784. var labelLineLen2 = labelLineModel.get('length2');
  37785. if (layout.angle < minShowLabelRadian) {
  37786. return;
  37787. }
  37788. var midAngle = (layout.startAngle + layout.endAngle) / 2;
  37789. var dx = Math.cos(midAngle);
  37790. var dy = Math.sin(midAngle);
  37791. var textX;
  37792. var textY;
  37793. var linePoints;
  37794. var textAlign;
  37795. cx = layout.cx;
  37796. cy = layout.cy;
  37797. var isLabelInside = labelPosition === 'inside' || labelPosition === 'inner';
  37798. if (labelPosition === 'center') {
  37799. textX = layout.cx;
  37800. textY = layout.cy;
  37801. textAlign = 'center';
  37802. }
  37803. else {
  37804. var x1 = (isLabelInside ? (layout.r + layout.r0) / 2 * dx : layout.r * dx) + cx;
  37805. var y1 = (isLabelInside ? (layout.r + layout.r0) / 2 * dy : layout.r * dy) + cy;
  37806. textX = x1 + dx * 3;
  37807. textY = y1 + dy * 3;
  37808. if (!isLabelInside) {
  37809. // For roseType
  37810. var x2 = x1 + dx * (labelLineLen + r - layout.r);
  37811. var y2 = y1 + dy * (labelLineLen + r - layout.r);
  37812. var x3 = x2 + ((dx < 0 ? -1 : 1) * labelLineLen2);
  37813. var y3 = y2;
  37814. textX = x3 + (dx < 0 ? -5 : 5);
  37815. textY = y3;
  37816. linePoints = [[x1, y1], [x2, y2], [x3, y3]];
  37817. }
  37818. textAlign = isLabelInside ? 'center' : (dx > 0 ? 'left' : 'right');
  37819. }
  37820. var font = labelModel.getFont();
  37821. var labelRotate;
  37822. var rotate = labelModel.get('rotate');
  37823. if (typeof rotate === 'number') {
  37824. labelRotate = rotate * (Math.PI / 180);
  37825. }
  37826. else {
  37827. labelRotate = rotate
  37828. ? (dx < 0 ? -midAngle + Math.PI : -midAngle)
  37829. : 0;
  37830. }
  37831. var text = seriesModel.getFormattedLabel(idx, 'normal')
  37832. || data.getName(idx);
  37833. var textRect = getBoundingRect(
  37834. text, font, textAlign, 'top'
  37835. );
  37836. hasLabelRotate = !!labelRotate;
  37837. layout.label = {
  37838. x: textX,
  37839. y: textY,
  37840. position: labelPosition,
  37841. height: textRect.height,
  37842. len: labelLineLen,
  37843. len2: labelLineLen2,
  37844. linePoints: linePoints,
  37845. textAlign: textAlign,
  37846. verticalAlign: 'middle',
  37847. rotation: labelRotate,
  37848. inside: isLabelInside
  37849. };
  37850. // Not layout the inside label
  37851. if (!isLabelInside) {
  37852. labelLayoutList.push(layout.label);
  37853. }
  37854. });
  37855. if (!hasLabelRotate && seriesModel.get('avoidLabelOverlap')) {
  37856. avoidOverlap(labelLayoutList, cx, cy, r, viewWidth, viewHeight);
  37857. }
  37858. };
  37859. /*
  37860. * Licensed to the Apache Software Foundation (ASF) under one
  37861. * or more contributor license agreements. See the NOTICE file
  37862. * distributed with this work for additional information
  37863. * regarding copyright ownership. The ASF licenses this file
  37864. * to you under the Apache License, Version 2.0 (the
  37865. * "License"); you may not use this file except in compliance
  37866. * with the License. You may obtain a copy of the License at
  37867. *
  37868. * http://www.apache.org/licenses/LICENSE-2.0
  37869. *
  37870. * Unless required by applicable law or agreed to in writing,
  37871. * software distributed under the License is distributed on an
  37872. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  37873. * KIND, either express or implied. See the License for the
  37874. * specific language governing permissions and limitations
  37875. * under the License.
  37876. */
  37877. var PI2$4 = Math.PI * 2;
  37878. var RADIAN = Math.PI / 180;
  37879. var pieLayout = function (seriesType, ecModel, api, payload) {
  37880. ecModel.eachSeriesByType(seriesType, function (seriesModel) {
  37881. var data = seriesModel.getData();
  37882. var valueDim = data.mapDimension('value');
  37883. var center = seriesModel.get('center');
  37884. var radius = seriesModel.get('radius');
  37885. if (!isArray(radius)) {
  37886. radius = [0, radius];
  37887. }
  37888. if (!isArray(center)) {
  37889. center = [center, center];
  37890. }
  37891. var width = api.getWidth();
  37892. var height = api.getHeight();
  37893. var size = Math.min(width, height);
  37894. var cx = parsePercent$1(center[0], width);
  37895. var cy = parsePercent$1(center[1], height);
  37896. var r0 = parsePercent$1(radius[0], size / 2);
  37897. var r = parsePercent$1(radius[1], size / 2);
  37898. var startAngle = -seriesModel.get('startAngle') * RADIAN;
  37899. var minAngle = seriesModel.get('minAngle') * RADIAN;
  37900. var validDataCount = 0;
  37901. data.each(valueDim, function (value) {
  37902. !isNaN(value) && validDataCount++;
  37903. });
  37904. var sum = data.getSum(valueDim);
  37905. // Sum may be 0
  37906. var unitRadian = Math.PI / (sum || validDataCount) * 2;
  37907. var clockwise = seriesModel.get('clockwise');
  37908. var roseType = seriesModel.get('roseType');
  37909. var stillShowZeroSum = seriesModel.get('stillShowZeroSum');
  37910. // [0...max]
  37911. var extent = data.getDataExtent(valueDim);
  37912. extent[0] = 0;
  37913. // In the case some sector angle is smaller than minAngle
  37914. var restAngle = PI2$4;
  37915. var valueSumLargerThanMinAngle = 0;
  37916. var currentAngle = startAngle;
  37917. var dir = clockwise ? 1 : -1;
  37918. data.each(valueDim, function (value, idx) {
  37919. var angle;
  37920. if (isNaN(value)) {
  37921. data.setItemLayout(idx, {
  37922. angle: NaN,
  37923. startAngle: NaN,
  37924. endAngle: NaN,
  37925. clockwise: clockwise,
  37926. cx: cx,
  37927. cy: cy,
  37928. r0: r0,
  37929. r: roseType
  37930. ? NaN
  37931. : r
  37932. });
  37933. return;
  37934. }
  37935. // FIXME 兼容 2.0 但是 roseType 是 area 的时候才是这样?
  37936. if (roseType !== 'area') {
  37937. angle = (sum === 0 && stillShowZeroSum)
  37938. ? unitRadian : (value * unitRadian);
  37939. }
  37940. else {
  37941. angle = PI2$4 / validDataCount;
  37942. }
  37943. if (angle < minAngle) {
  37944. angle = minAngle;
  37945. restAngle -= minAngle;
  37946. }
  37947. else {
  37948. valueSumLargerThanMinAngle += value;
  37949. }
  37950. var endAngle = currentAngle + dir * angle;
  37951. data.setItemLayout(idx, {
  37952. angle: angle,
  37953. startAngle: currentAngle,
  37954. endAngle: endAngle,
  37955. clockwise: clockwise,
  37956. cx: cx,
  37957. cy: cy,
  37958. r0: r0,
  37959. r: roseType
  37960. ? linearMap(value, extent, [r0, r])
  37961. : r
  37962. });
  37963. currentAngle = endAngle;
  37964. });
  37965. // Some sector is constrained by minAngle
  37966. // Rest sectors needs recalculate angle
  37967. if (restAngle < PI2$4 && validDataCount) {
  37968. // Average the angle if rest angle is not enough after all angles is
  37969. // Constrained by minAngle
  37970. if (restAngle <= 1e-3) {
  37971. var angle = PI2$4 / validDataCount;
  37972. data.each(valueDim, function (value, idx) {
  37973. if (!isNaN(value)) {
  37974. var layout = data.getItemLayout(idx);
  37975. layout.angle = angle;
  37976. layout.startAngle = startAngle + dir * idx * angle;
  37977. layout.endAngle = startAngle + dir * (idx + 1) * angle;
  37978. }
  37979. });
  37980. }
  37981. else {
  37982. unitRadian = restAngle / valueSumLargerThanMinAngle;
  37983. currentAngle = startAngle;
  37984. data.each(valueDim, function (value, idx) {
  37985. if (!isNaN(value)) {
  37986. var layout = data.getItemLayout(idx);
  37987. var angle = layout.angle === minAngle
  37988. ? minAngle : value * unitRadian;
  37989. layout.startAngle = currentAngle;
  37990. layout.endAngle = currentAngle + dir * angle;
  37991. currentAngle += dir * angle;
  37992. }
  37993. });
  37994. }
  37995. }
  37996. labelLayout(seriesModel, r, width, height);
  37997. });
  37998. };
  37999. /*
  38000. * Licensed to the Apache Software Foundation (ASF) under one
  38001. * or more contributor license agreements. See the NOTICE file
  38002. * distributed with this work for additional information
  38003. * regarding copyright ownership. The ASF licenses this file
  38004. * to you under the Apache License, Version 2.0 (the
  38005. * "License"); you may not use this file except in compliance
  38006. * with the License. You may obtain a copy of the License at
  38007. *
  38008. * http://www.apache.org/licenses/LICENSE-2.0
  38009. *
  38010. * Unless required by applicable law or agreed to in writing,
  38011. * software distributed under the License is distributed on an
  38012. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  38013. * KIND, either express or implied. See the License for the
  38014. * specific language governing permissions and limitations
  38015. * under the License.
  38016. */
  38017. var dataFilter = function (seriesType) {
  38018. return {
  38019. seriesType: seriesType,
  38020. reset: function (seriesModel, ecModel) {
  38021. var legendModels = ecModel.findComponents({
  38022. mainType: 'legend'
  38023. });
  38024. if (!legendModels || !legendModels.length) {
  38025. return;
  38026. }
  38027. var data = seriesModel.getData();
  38028. data.filterSelf(function (idx) {
  38029. var name = data.getName(idx);
  38030. // If in any legend component the status is not selected.
  38031. for (var i = 0; i < legendModels.length; i++) {
  38032. if (!legendModels[i].isSelected(name)) {
  38033. return false;
  38034. }
  38035. }
  38036. return true;
  38037. });
  38038. }
  38039. };
  38040. };
  38041. /*
  38042. * Licensed to the Apache Software Foundation (ASF) under one
  38043. * or more contributor license agreements. See the NOTICE file
  38044. * distributed with this work for additional information
  38045. * regarding copyright ownership. The ASF licenses this file
  38046. * to you under the Apache License, Version 2.0 (the
  38047. * "License"); you may not use this file except in compliance
  38048. * with the License. You may obtain a copy of the License at
  38049. *
  38050. * http://www.apache.org/licenses/LICENSE-2.0
  38051. *
  38052. * Unless required by applicable law or agreed to in writing,
  38053. * software distributed under the License is distributed on an
  38054. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  38055. * KIND, either express or implied. See the License for the
  38056. * specific language governing permissions and limitations
  38057. * under the License.
  38058. */
  38059. createDataSelectAction('pie', [{
  38060. type: 'pieToggleSelect',
  38061. event: 'pieselectchanged',
  38062. method: 'toggleSelected'
  38063. }, {
  38064. type: 'pieSelect',
  38065. event: 'pieselected',
  38066. method: 'select'
  38067. }, {
  38068. type: 'pieUnSelect',
  38069. event: 'pieunselected',
  38070. method: 'unSelect'
  38071. }]);
  38072. registerVisual(dataColor('pie'));
  38073. registerLayout(curry(pieLayout, 'pie'));
  38074. registerProcessor(dataFilter('pie'));
  38075. /*
  38076. * Licensed to the Apache Software Foundation (ASF) under one
  38077. * or more contributor license agreements. See the NOTICE file
  38078. * distributed with this work for additional information
  38079. * regarding copyright ownership. The ASF licenses this file
  38080. * to you under the Apache License, Version 2.0 (the
  38081. * "License"); you may not use this file except in compliance
  38082. * with the License. You may obtain a copy of the License at
  38083. *
  38084. * http://www.apache.org/licenses/LICENSE-2.0
  38085. *
  38086. * Unless required by applicable law or agreed to in writing,
  38087. * software distributed under the License is distributed on an
  38088. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  38089. * KIND, either express or implied. See the License for the
  38090. * specific language governing permissions and limitations
  38091. * under the License.
  38092. */
  38093. SeriesModel.extend({
  38094. type: 'series.scatter',
  38095. dependencies: ['grid', 'polar', 'geo', 'singleAxis', 'calendar'],
  38096. getInitialData: function (option, ecModel) {
  38097. return createListFromArray(this.getSource(), this);
  38098. },
  38099. brushSelector: 'point',
  38100. getProgressive: function () {
  38101. var progressive = this.option.progressive;
  38102. if (progressive == null) {
  38103. // PENDING
  38104. return this.option.large ? 5e3 : this.get('progressive');
  38105. }
  38106. return progressive;
  38107. },
  38108. getProgressiveThreshold: function () {
  38109. var progressiveThreshold = this.option.progressiveThreshold;
  38110. if (progressiveThreshold == null) {
  38111. // PENDING
  38112. return this.option.large ? 1e4 : this.get('progressiveThreshold');
  38113. }
  38114. return progressiveThreshold;
  38115. },
  38116. defaultOption: {
  38117. coordinateSystem: 'cartesian2d',
  38118. zlevel: 0,
  38119. z: 2,
  38120. legendHoverLink: true,
  38121. hoverAnimation: true,
  38122. // Cartesian coordinate system
  38123. // xAxisIndex: 0,
  38124. // yAxisIndex: 0,
  38125. // Polar coordinate system
  38126. // polarIndex: 0,
  38127. // Geo coordinate system
  38128. // geoIndex: 0,
  38129. // symbol: null, // 图形类型
  38130. symbolSize: 10, // 图形大小,半宽(半径)参数,当图形为方向或菱形则总宽度为symbolSize * 2
  38131. // symbolRotate: null, // 图形旋转控制
  38132. large: false,
  38133. // Available when large is true
  38134. largeThreshold: 2000,
  38135. // cursor: null,
  38136. // label: {
  38137. // show: false
  38138. // distance: 5,
  38139. // formatter: 标签文本格式器,同Tooltip.formatter,不支持异步回调
  38140. // position: 默认自适应,水平布局为'top',垂直布局为'right',可选为
  38141. // 'inside'|'left'|'right'|'top'|'bottom'
  38142. // 默认使用全局文本样式,详见TEXTSTYLE
  38143. // },
  38144. itemStyle: {
  38145. opacity: 0.8
  38146. // color: 各异
  38147. }
  38148. // progressive: null
  38149. }
  38150. });
  38151. /*
  38152. * Licensed to the Apache Software Foundation (ASF) under one
  38153. * or more contributor license agreements. See the NOTICE file
  38154. * distributed with this work for additional information
  38155. * regarding copyright ownership. The ASF licenses this file
  38156. * to you under the Apache License, Version 2.0 (the
  38157. * "License"); you may not use this file except in compliance
  38158. * with the License. You may obtain a copy of the License at
  38159. *
  38160. * http://www.apache.org/licenses/LICENSE-2.0
  38161. *
  38162. * Unless required by applicable law or agreed to in writing,
  38163. * software distributed under the License is distributed on an
  38164. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  38165. * KIND, either express or implied. See the License for the
  38166. * specific language governing permissions and limitations
  38167. * under the License.
  38168. */
  38169. /* global Float32Array */
  38170. // TODO Batch by color
  38171. var BOOST_SIZE_THRESHOLD = 4;
  38172. var LargeSymbolPath = extendShape({
  38173. shape: {
  38174. points: null
  38175. },
  38176. symbolProxy: null,
  38177. buildPath: function (path, shape) {
  38178. var points = shape.points;
  38179. var size = shape.size;
  38180. var symbolProxy = this.symbolProxy;
  38181. var symbolProxyShape = symbolProxy.shape;
  38182. var ctx = path.getContext ? path.getContext() : path;
  38183. var canBoost = ctx && size[0] < BOOST_SIZE_THRESHOLD;
  38184. // Do draw in afterBrush.
  38185. if (canBoost) {
  38186. return;
  38187. }
  38188. for (var i = 0; i < points.length;) {
  38189. var x = points[i++];
  38190. var y = points[i++];
  38191. if (isNaN(x) || isNaN(y)) {
  38192. continue;
  38193. }
  38194. symbolProxyShape.x = x - size[0] / 2;
  38195. symbolProxyShape.y = y - size[1] / 2;
  38196. symbolProxyShape.width = size[0];
  38197. symbolProxyShape.height = size[1];
  38198. symbolProxy.buildPath(path, symbolProxyShape, true);
  38199. }
  38200. },
  38201. afterBrush: function (ctx) {
  38202. var shape = this.shape;
  38203. var points = shape.points;
  38204. var size = shape.size;
  38205. var canBoost = size[0] < BOOST_SIZE_THRESHOLD;
  38206. if (!canBoost) {
  38207. return;
  38208. }
  38209. this.setTransform(ctx);
  38210. // PENDING If style or other canvas status changed?
  38211. for (var i = 0; i < points.length;) {
  38212. var x = points[i++];
  38213. var y = points[i++];
  38214. if (isNaN(x) || isNaN(y)) {
  38215. continue;
  38216. }
  38217. // fillRect is faster than building a rect path and draw.
  38218. // And it support light globalCompositeOperation.
  38219. ctx.fillRect(
  38220. x - size[0] / 2, y - size[1] / 2,
  38221. size[0], size[1]
  38222. );
  38223. }
  38224. this.restoreTransform(ctx);
  38225. },
  38226. findDataIndex: function (x, y) {
  38227. // TODO ???
  38228. // Consider transform
  38229. var shape = this.shape;
  38230. var points = shape.points;
  38231. var size = shape.size;
  38232. var w = Math.max(size[0], 4);
  38233. var h = Math.max(size[1], 4);
  38234. // Not consider transform
  38235. // Treat each element as a rect
  38236. // top down traverse
  38237. for (var idx = points.length / 2 - 1; idx >= 0; idx--) {
  38238. var i = idx * 2;
  38239. var x0 = points[i] - w / 2;
  38240. var y0 = points[i + 1] - h / 2;
  38241. if (x >= x0 && y >= y0 && x <= x0 + w && y <= y0 + h) {
  38242. return idx;
  38243. }
  38244. }
  38245. return -1;
  38246. }
  38247. });
  38248. function LargeSymbolDraw() {
  38249. this.group = new Group();
  38250. }
  38251. var largeSymbolProto = LargeSymbolDraw.prototype;
  38252. largeSymbolProto.isPersistent = function () {
  38253. return !this._incremental;
  38254. };
  38255. /**
  38256. * Update symbols draw by new data
  38257. * @param {module:echarts/data/List} data
  38258. */
  38259. largeSymbolProto.updateData = function (data) {
  38260. this.group.removeAll();
  38261. var symbolEl = new LargeSymbolPath({
  38262. rectHover: true,
  38263. cursor: 'default'
  38264. });
  38265. symbolEl.setShape({
  38266. points: data.getLayout('symbolPoints')
  38267. });
  38268. this._setCommon(symbolEl, data);
  38269. this.group.add(symbolEl);
  38270. this._incremental = null;
  38271. };
  38272. largeSymbolProto.updateLayout = function (data) {
  38273. if (this._incremental) {
  38274. return;
  38275. }
  38276. var points = data.getLayout('symbolPoints');
  38277. this.group.eachChild(function (child) {
  38278. if (child.startIndex != null) {
  38279. var len = (child.endIndex - child.startIndex) * 2;
  38280. var byteOffset = child.startIndex * 4 * 2;
  38281. points = new Float32Array(points.buffer, byteOffset, len);
  38282. }
  38283. child.setShape('points', points);
  38284. });
  38285. };
  38286. largeSymbolProto.incrementalPrepareUpdate = function (data) {
  38287. this.group.removeAll();
  38288. this._clearIncremental();
  38289. // Only use incremental displayables when data amount is larger than 2 million.
  38290. // PENDING Incremental data?
  38291. if (data.count() > 2e6) {
  38292. if (!this._incremental) {
  38293. this._incremental = new IncrementalDisplayble({
  38294. silent: true
  38295. });
  38296. }
  38297. this.group.add(this._incremental);
  38298. }
  38299. else {
  38300. this._incremental = null;
  38301. }
  38302. };
  38303. largeSymbolProto.incrementalUpdate = function (taskParams, data) {
  38304. var symbolEl;
  38305. if (this._incremental) {
  38306. symbolEl = new LargeSymbolPath();
  38307. this._incremental.addDisplayable(symbolEl, true);
  38308. }
  38309. else {
  38310. symbolEl = new LargeSymbolPath({
  38311. rectHover: true,
  38312. cursor: 'default',
  38313. startIndex: taskParams.start,
  38314. endIndex: taskParams.end
  38315. });
  38316. symbolEl.incremental = true;
  38317. this.group.add(symbolEl);
  38318. }
  38319. symbolEl.setShape({
  38320. points: data.getLayout('symbolPoints')
  38321. });
  38322. this._setCommon(symbolEl, data, !!this._incremental);
  38323. };
  38324. largeSymbolProto._setCommon = function (symbolEl, data, isIncremental) {
  38325. var hostModel = data.hostModel;
  38326. // TODO
  38327. // if (data.hasItemVisual.symbolSize) {
  38328. // // TODO typed array?
  38329. // symbolEl.setShape('sizes', data.mapArray(
  38330. // function (idx) {
  38331. // var size = data.getItemVisual(idx, 'symbolSize');
  38332. // return (size instanceof Array) ? size : [size, size];
  38333. // }
  38334. // ));
  38335. // }
  38336. // else {
  38337. var size = data.getVisual('symbolSize');
  38338. symbolEl.setShape('size', (size instanceof Array) ? size : [size, size]);
  38339. // }
  38340. // Create symbolProxy to build path for each data
  38341. symbolEl.symbolProxy = createSymbol(
  38342. data.getVisual('symbol'), 0, 0, 0, 0
  38343. );
  38344. // Use symbolProxy setColor method
  38345. symbolEl.setColor = symbolEl.symbolProxy.setColor;
  38346. var extrudeShadow = symbolEl.shape.size[0] < BOOST_SIZE_THRESHOLD;
  38347. symbolEl.useStyle(
  38348. // Draw shadow when doing fillRect is extremely slow.
  38349. hostModel.getModel('itemStyle').getItemStyle(extrudeShadow ? ['color', 'shadowBlur', 'shadowColor'] : ['color'])
  38350. );
  38351. var visualColor = data.getVisual('color');
  38352. if (visualColor) {
  38353. symbolEl.setColor(visualColor);
  38354. }
  38355. if (!isIncremental) {
  38356. // Enable tooltip
  38357. // PENDING May have performance issue when path is extremely large
  38358. symbolEl.seriesIndex = hostModel.seriesIndex;
  38359. symbolEl.on('mousemove', function (e) {
  38360. symbolEl.dataIndex = null;
  38361. var dataIndex = symbolEl.findDataIndex(e.offsetX, e.offsetY);
  38362. if (dataIndex >= 0) {
  38363. // Provide dataIndex for tooltip
  38364. symbolEl.dataIndex = dataIndex + (symbolEl.startIndex || 0);
  38365. }
  38366. });
  38367. }
  38368. };
  38369. largeSymbolProto.remove = function () {
  38370. this._clearIncremental();
  38371. this._incremental = null;
  38372. this.group.removeAll();
  38373. };
  38374. largeSymbolProto._clearIncremental = function () {
  38375. var incremental = this._incremental;
  38376. if (incremental) {
  38377. incremental.clearDisplaybles();
  38378. }
  38379. };
  38380. /*
  38381. * Licensed to the Apache Software Foundation (ASF) under one
  38382. * or more contributor license agreements. See the NOTICE file
  38383. * distributed with this work for additional information
  38384. * regarding copyright ownership. The ASF licenses this file
  38385. * to you under the Apache License, Version 2.0 (the
  38386. * "License"); you may not use this file except in compliance
  38387. * with the License. You may obtain a copy of the License at
  38388. *
  38389. * http://www.apache.org/licenses/LICENSE-2.0
  38390. *
  38391. * Unless required by applicable law or agreed to in writing,
  38392. * software distributed under the License is distributed on an
  38393. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  38394. * KIND, either express or implied. See the License for the
  38395. * specific language governing permissions and limitations
  38396. * under the License.
  38397. */
  38398. extendChartView({
  38399. type: 'scatter',
  38400. render: function (seriesModel, ecModel, api) {
  38401. var data = seriesModel.getData();
  38402. var symbolDraw = this._updateSymbolDraw(data, seriesModel);
  38403. symbolDraw.updateData(data);
  38404. this._finished = true;
  38405. },
  38406. incrementalPrepareRender: function (seriesModel, ecModel, api) {
  38407. var data = seriesModel.getData();
  38408. var symbolDraw = this._updateSymbolDraw(data, seriesModel);
  38409. symbolDraw.incrementalPrepareUpdate(data);
  38410. this._finished = false;
  38411. },
  38412. incrementalRender: function (taskParams, seriesModel, ecModel) {
  38413. this._symbolDraw.incrementalUpdate(taskParams, seriesModel.getData());
  38414. this._finished = taskParams.end === seriesModel.getData().count();
  38415. },
  38416. updateTransform: function (seriesModel, ecModel, api) {
  38417. var data = seriesModel.getData();
  38418. // Must mark group dirty and make sure the incremental layer will be cleared
  38419. // PENDING
  38420. this.group.dirty();
  38421. if (!this._finished || data.count() > 1e4 || !this._symbolDraw.isPersistent()) {
  38422. return {
  38423. update: true
  38424. };
  38425. }
  38426. else {
  38427. var res = pointsLayout().reset(seriesModel);
  38428. if (res.progress) {
  38429. res.progress({ start: 0, end: data.count() }, data);
  38430. }
  38431. this._symbolDraw.updateLayout(data);
  38432. }
  38433. },
  38434. _updateSymbolDraw: function (data, seriesModel) {
  38435. var symbolDraw = this._symbolDraw;
  38436. var pipelineContext = seriesModel.pipelineContext;
  38437. var isLargeDraw = pipelineContext.large;
  38438. if (!symbolDraw || isLargeDraw !== this._isLargeDraw) {
  38439. symbolDraw && symbolDraw.remove();
  38440. symbolDraw = this._symbolDraw = isLargeDraw
  38441. ? new LargeSymbolDraw()
  38442. : new SymbolDraw();
  38443. this._isLargeDraw = isLargeDraw;
  38444. this.group.removeAll();
  38445. }
  38446. this.group.add(symbolDraw.group);
  38447. return symbolDraw;
  38448. },
  38449. remove: function (ecModel, api) {
  38450. this._symbolDraw && this._symbolDraw.remove(true);
  38451. this._symbolDraw = null;
  38452. },
  38453. dispose: function () {}
  38454. });
  38455. /*
  38456. * Licensed to the Apache Software Foundation (ASF) under one
  38457. * or more contributor license agreements. See the NOTICE file
  38458. * distributed with this work for additional information
  38459. * regarding copyright ownership. The ASF licenses this file
  38460. * to you under the Apache License, Version 2.0 (the
  38461. * "License"); you may not use this file except in compliance
  38462. * with the License. You may obtain a copy of the License at
  38463. *
  38464. * http://www.apache.org/licenses/LICENSE-2.0
  38465. *
  38466. * Unless required by applicable law or agreed to in writing,
  38467. * software distributed under the License is distributed on an
  38468. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  38469. * KIND, either express or implied. See the License for the
  38470. * specific language governing permissions and limitations
  38471. * under the License.
  38472. */
  38473. // import * as zrUtil from 'zrender/src/core/util';
  38474. // In case developer forget to include grid component
  38475. registerVisual(visualSymbol('scatter', 'circle'));
  38476. registerLayout(pointsLayout('scatter'));
  38477. // echarts.registerProcessor(function (ecModel, api) {
  38478. // ecModel.eachSeriesByType('scatter', function (seriesModel) {
  38479. // var data = seriesModel.getData();
  38480. // var coordSys = seriesModel.coordinateSystem;
  38481. // if (coordSys.type !== 'geo') {
  38482. // return;
  38483. // }
  38484. // var startPt = coordSys.pointToData([0, 0]);
  38485. // var endPt = coordSys.pointToData([api.getWidth(), api.getHeight()]);
  38486. // var dims = zrUtil.map(coordSys.dimensions, function (dim) {
  38487. // return data.mapDimension(dim);
  38488. // });
  38489. // var range = {};
  38490. // range[dims[0]] = [Math.min(startPt[0], endPt[0]), Math.max(startPt[0], endPt[0])];
  38491. // range[dims[1]] = [Math.min(startPt[1], endPt[1]), Math.max(startPt[1], endPt[1])];
  38492. // data.selectRange(range);
  38493. // });
  38494. // });
  38495. /*
  38496. * Licensed to the Apache Software Foundation (ASF) under one
  38497. * or more contributor license agreements. See the NOTICE file
  38498. * distributed with this work for additional information
  38499. * regarding copyright ownership. The ASF licenses this file
  38500. * to you under the Apache License, Version 2.0 (the
  38501. * "License"); you may not use this file except in compliance
  38502. * with the License. You may obtain a copy of the License at
  38503. *
  38504. * http://www.apache.org/licenses/LICENSE-2.0
  38505. *
  38506. * Unless required by applicable law or agreed to in writing,
  38507. * software distributed under the License is distributed on an
  38508. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  38509. * KIND, either express or implied. See the License for the
  38510. * specific language governing permissions and limitations
  38511. * under the License.
  38512. */
  38513. function IndicatorAxis(dim, scale, radiusExtent) {
  38514. Axis.call(this, dim, scale, radiusExtent);
  38515. /**
  38516. * Axis type
  38517. * - 'category'
  38518. * - 'value'
  38519. * - 'time'
  38520. * - 'log'
  38521. * @type {string}
  38522. */
  38523. this.type = 'value';
  38524. this.angle = 0;
  38525. /**
  38526. * Indicator name
  38527. * @type {string}
  38528. */
  38529. this.name = '';
  38530. /**
  38531. * @type {module:echarts/model/Model}
  38532. */
  38533. this.model;
  38534. }
  38535. inherits(IndicatorAxis, Axis);
  38536. /*
  38537. * Licensed to the Apache Software Foundation (ASF) under one
  38538. * or more contributor license agreements. See the NOTICE file
  38539. * distributed with this work for additional information
  38540. * regarding copyright ownership. The ASF licenses this file
  38541. * to you under the Apache License, Version 2.0 (the
  38542. * "License"); you may not use this file except in compliance
  38543. * with the License. You may obtain a copy of the License at
  38544. *
  38545. * http://www.apache.org/licenses/LICENSE-2.0
  38546. *
  38547. * Unless required by applicable law or agreed to in writing,
  38548. * software distributed under the License is distributed on an
  38549. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  38550. * KIND, either express or implied. See the License for the
  38551. * specific language governing permissions and limitations
  38552. * under the License.
  38553. */
  38554. // TODO clockwise
  38555. function Radar(radarModel, ecModel, api) {
  38556. this._model = radarModel;
  38557. /**
  38558. * Radar dimensions
  38559. * @type {Array.<string>}
  38560. */
  38561. this.dimensions = [];
  38562. this._indicatorAxes = map(radarModel.getIndicatorModels(), function (indicatorModel, idx) {
  38563. var dim = 'indicator_' + idx;
  38564. var indicatorAxis = new IndicatorAxis(dim, new IntervalScale());
  38565. indicatorAxis.name = indicatorModel.get('name');
  38566. // Inject model and axis
  38567. indicatorAxis.model = indicatorModel;
  38568. indicatorModel.axis = indicatorAxis;
  38569. this.dimensions.push(dim);
  38570. return indicatorAxis;
  38571. }, this);
  38572. this.resize(radarModel, api);
  38573. /**
  38574. * @type {number}
  38575. * @readOnly
  38576. */
  38577. this.cx;
  38578. /**
  38579. * @type {number}
  38580. * @readOnly
  38581. */
  38582. this.cy;
  38583. /**
  38584. * @type {number}
  38585. * @readOnly
  38586. */
  38587. this.r;
  38588. /**
  38589. * @type {number}
  38590. * @readOnly
  38591. */
  38592. this.r0;
  38593. /**
  38594. * @type {number}
  38595. * @readOnly
  38596. */
  38597. this.startAngle;
  38598. }
  38599. Radar.prototype.getIndicatorAxes = function () {
  38600. return this._indicatorAxes;
  38601. };
  38602. Radar.prototype.dataToPoint = function (value, indicatorIndex) {
  38603. var indicatorAxis = this._indicatorAxes[indicatorIndex];
  38604. return this.coordToPoint(indicatorAxis.dataToCoord(value), indicatorIndex);
  38605. };
  38606. Radar.prototype.coordToPoint = function (coord, indicatorIndex) {
  38607. var indicatorAxis = this._indicatorAxes[indicatorIndex];
  38608. var angle = indicatorAxis.angle;
  38609. var x = this.cx + coord * Math.cos(angle);
  38610. var y = this.cy - coord * Math.sin(angle);
  38611. return [x, y];
  38612. };
  38613. Radar.prototype.pointToData = function (pt) {
  38614. var dx = pt[0] - this.cx;
  38615. var dy = pt[1] - this.cy;
  38616. var radius = Math.sqrt(dx * dx + dy * dy);
  38617. dx /= radius;
  38618. dy /= radius;
  38619. var radian = Math.atan2(-dy, dx);
  38620. // Find the closest angle
  38621. // FIXME index can calculated directly
  38622. var minRadianDiff = Infinity;
  38623. var closestAxis;
  38624. var closestAxisIdx = -1;
  38625. for (var i = 0; i < this._indicatorAxes.length; i++) {
  38626. var indicatorAxis = this._indicatorAxes[i];
  38627. var diff = Math.abs(radian - indicatorAxis.angle);
  38628. if (diff < minRadianDiff) {
  38629. closestAxis = indicatorAxis;
  38630. closestAxisIdx = i;
  38631. minRadianDiff = diff;
  38632. }
  38633. }
  38634. return [closestAxisIdx, +(closestAxis && closestAxis.coodToData(radius))];
  38635. };
  38636. Radar.prototype.resize = function (radarModel, api) {
  38637. var center = radarModel.get('center');
  38638. var viewWidth = api.getWidth();
  38639. var viewHeight = api.getHeight();
  38640. var viewSize = Math.min(viewWidth, viewHeight) / 2;
  38641. this.cx = parsePercent$1(center[0], viewWidth);
  38642. this.cy = parsePercent$1(center[1], viewHeight);
  38643. this.startAngle = radarModel.get('startAngle') * Math.PI / 180;
  38644. // radius may be single value like `20`, `'80%'`, or array like `[10, '80%']`
  38645. var radius = radarModel.get('radius');
  38646. if (typeof radius === 'string' || typeof radius === 'number') {
  38647. radius = [0, radius];
  38648. }
  38649. this.r0 = parsePercent$1(radius[0], viewSize);
  38650. this.r = parsePercent$1(radius[1], viewSize);
  38651. each$1(this._indicatorAxes, function (indicatorAxis, idx) {
  38652. indicatorAxis.setExtent(this.r0, this.r);
  38653. var angle = (this.startAngle + idx * Math.PI * 2 / this._indicatorAxes.length);
  38654. // Normalize to [-PI, PI]
  38655. angle = Math.atan2(Math.sin(angle), Math.cos(angle));
  38656. indicatorAxis.angle = angle;
  38657. }, this);
  38658. };
  38659. Radar.prototype.update = function (ecModel, api) {
  38660. var indicatorAxes = this._indicatorAxes;
  38661. var radarModel = this._model;
  38662. each$1(indicatorAxes, function (indicatorAxis) {
  38663. indicatorAxis.scale.setExtent(Infinity, -Infinity);
  38664. });
  38665. ecModel.eachSeriesByType('radar', function (radarSeries, idx) {
  38666. if (radarSeries.get('coordinateSystem') !== 'radar'
  38667. || ecModel.getComponent('radar', radarSeries.get('radarIndex')) !== radarModel
  38668. ) {
  38669. return;
  38670. }
  38671. var data = radarSeries.getData();
  38672. each$1(indicatorAxes, function (indicatorAxis) {
  38673. indicatorAxis.scale.unionExtentFromData(data, data.mapDimension(indicatorAxis.dim));
  38674. });
  38675. }, this);
  38676. var splitNumber = radarModel.get('splitNumber');
  38677. function increaseInterval(interval) {
  38678. var exp10 = Math.pow(10, Math.floor(Math.log(interval) / Math.LN10));
  38679. // Increase interval
  38680. var f = interval / exp10;
  38681. if (f === 2) {
  38682. f = 5;
  38683. }
  38684. else { // f is 2 or 5
  38685. f *= 2;
  38686. }
  38687. return f * exp10;
  38688. }
  38689. // Force all the axis fixing the maxSplitNumber.
  38690. each$1(indicatorAxes, function (indicatorAxis, idx) {
  38691. var rawExtent = getScaleExtent(indicatorAxis.scale, indicatorAxis.model);
  38692. niceScaleExtent(indicatorAxis.scale, indicatorAxis.model);
  38693. var axisModel = indicatorAxis.model;
  38694. var scale = indicatorAxis.scale;
  38695. var fixedMin = axisModel.getMin();
  38696. var fixedMax = axisModel.getMax();
  38697. var interval = scale.getInterval();
  38698. if (fixedMin != null && fixedMax != null) {
  38699. // User set min, max, divide to get new interval
  38700. scale.setExtent(+fixedMin, +fixedMax);
  38701. scale.setInterval(
  38702. (fixedMax - fixedMin) / splitNumber
  38703. );
  38704. }
  38705. else if (fixedMin != null) {
  38706. var max;
  38707. // User set min, expand extent on the other side
  38708. do {
  38709. max = fixedMin + interval * splitNumber;
  38710. scale.setExtent(+fixedMin, max);
  38711. // Interval must been set after extent
  38712. // FIXME
  38713. scale.setInterval(interval);
  38714. interval = increaseInterval(interval);
  38715. } while (max < rawExtent[1] && isFinite(max) && isFinite(rawExtent[1]));
  38716. }
  38717. else if (fixedMax != null) {
  38718. var min;
  38719. // User set min, expand extent on the other side
  38720. do {
  38721. min = fixedMax - interval * splitNumber;
  38722. scale.setExtent(min, +fixedMax);
  38723. scale.setInterval(interval);
  38724. interval = increaseInterval(interval);
  38725. } while (min > rawExtent[0] && isFinite(min) && isFinite(rawExtent[0]));
  38726. }
  38727. else {
  38728. var nicedSplitNumber = scale.getTicks().length - 1;
  38729. if (nicedSplitNumber > splitNumber) {
  38730. interval = increaseInterval(interval);
  38731. }
  38732. // PENDING
  38733. var center = Math.round((rawExtent[0] + rawExtent[1]) / 2 / interval) * interval;
  38734. var halfSplitNumber = Math.round(splitNumber / 2);
  38735. scale.setExtent(
  38736. round$1(center - halfSplitNumber * interval),
  38737. round$1(center + (splitNumber - halfSplitNumber) * interval)
  38738. );
  38739. scale.setInterval(interval);
  38740. }
  38741. });
  38742. };
  38743. /**
  38744. * Radar dimensions is based on the data
  38745. * @type {Array}
  38746. */
  38747. Radar.dimensions = [];
  38748. Radar.create = function (ecModel, api) {
  38749. var radarList = [];
  38750. ecModel.eachComponent('radar', function (radarModel) {
  38751. var radar = new Radar(radarModel, ecModel, api);
  38752. radarList.push(radar);
  38753. radarModel.coordinateSystem = radar;
  38754. });
  38755. ecModel.eachSeriesByType('radar', function (radarSeries) {
  38756. if (radarSeries.get('coordinateSystem') === 'radar') {
  38757. // Inject coordinate system
  38758. radarSeries.coordinateSystem = radarList[radarSeries.get('radarIndex') || 0];
  38759. }
  38760. });
  38761. return radarList;
  38762. };
  38763. CoordinateSystemManager.register('radar', Radar);
  38764. /*
  38765. * Licensed to the Apache Software Foundation (ASF) under one
  38766. * or more contributor license agreements. See the NOTICE file
  38767. * distributed with this work for additional information
  38768. * regarding copyright ownership. The ASF licenses this file
  38769. * to you under the Apache License, Version 2.0 (the
  38770. * "License"); you may not use this file except in compliance
  38771. * with the License. You may obtain a copy of the License at
  38772. *
  38773. * http://www.apache.org/licenses/LICENSE-2.0
  38774. *
  38775. * Unless required by applicable law or agreed to in writing,
  38776. * software distributed under the License is distributed on an
  38777. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  38778. * KIND, either express or implied. See the License for the
  38779. * specific language governing permissions and limitations
  38780. * under the License.
  38781. */
  38782. var valueAxisDefault = axisDefault.valueAxis;
  38783. function defaultsShow(opt, show) {
  38784. return defaults({
  38785. show: show
  38786. }, opt);
  38787. }
  38788. var RadarModel = extendComponentModel({
  38789. type: 'radar',
  38790. optionUpdated: function () {
  38791. var boundaryGap = this.get('boundaryGap');
  38792. var splitNumber = this.get('splitNumber');
  38793. var scale = this.get('scale');
  38794. var axisLine = this.get('axisLine');
  38795. var axisTick = this.get('axisTick');
  38796. var axisLabel = this.get('axisLabel');
  38797. var nameTextStyle = this.get('name');
  38798. var showName = this.get('name.show');
  38799. var nameFormatter = this.get('name.formatter');
  38800. var nameGap = this.get('nameGap');
  38801. var triggerEvent = this.get('triggerEvent');
  38802. var indicatorModels = map(this.get('indicator') || [], function (indicatorOpt) {
  38803. // PENDING
  38804. if (indicatorOpt.max != null && indicatorOpt.max > 0 && !indicatorOpt.min) {
  38805. indicatorOpt.min = 0;
  38806. }
  38807. else if (indicatorOpt.min != null && indicatorOpt.min < 0 && !indicatorOpt.max) {
  38808. indicatorOpt.max = 0;
  38809. }
  38810. var iNameTextStyle = nameTextStyle;
  38811. if (indicatorOpt.color != null) {
  38812. iNameTextStyle = defaults({color: indicatorOpt.color}, nameTextStyle);
  38813. }
  38814. // Use same configuration
  38815. indicatorOpt = merge(clone(indicatorOpt), {
  38816. boundaryGap: boundaryGap,
  38817. splitNumber: splitNumber,
  38818. scale: scale,
  38819. axisLine: axisLine,
  38820. axisTick: axisTick,
  38821. axisLabel: axisLabel,
  38822. // Competitable with 2 and use text
  38823. name: indicatorOpt.text,
  38824. nameLocation: 'end',
  38825. nameGap: nameGap,
  38826. // min: 0,
  38827. nameTextStyle: iNameTextStyle,
  38828. triggerEvent: triggerEvent
  38829. }, false);
  38830. if (!showName) {
  38831. indicatorOpt.name = '';
  38832. }
  38833. if (typeof nameFormatter === 'string') {
  38834. var indName = indicatorOpt.name;
  38835. indicatorOpt.name = nameFormatter.replace('{value}', indName != null ? indName : '');
  38836. }
  38837. else if (typeof nameFormatter === 'function') {
  38838. indicatorOpt.name = nameFormatter(
  38839. indicatorOpt.name, indicatorOpt
  38840. );
  38841. }
  38842. var model = extend(
  38843. new Model(indicatorOpt, null, this.ecModel),
  38844. axisModelCommonMixin
  38845. );
  38846. // For triggerEvent.
  38847. model.mainType = 'radar';
  38848. model.componentIndex = this.componentIndex;
  38849. return model;
  38850. }, this);
  38851. this.getIndicatorModels = function () {
  38852. return indicatorModels;
  38853. };
  38854. },
  38855. defaultOption: {
  38856. zlevel: 0,
  38857. z: 0,
  38858. center: ['50%', '50%'],
  38859. radius: '75%',
  38860. startAngle: 90,
  38861. name: {
  38862. show: true
  38863. // formatter: null
  38864. // textStyle: {}
  38865. },
  38866. boundaryGap: [0, 0],
  38867. splitNumber: 5,
  38868. nameGap: 15,
  38869. scale: false,
  38870. // Polygon or circle
  38871. shape: 'polygon',
  38872. axisLine: merge(
  38873. {
  38874. lineStyle: {
  38875. color: '#bbb'
  38876. }
  38877. },
  38878. valueAxisDefault.axisLine
  38879. ),
  38880. axisLabel: defaultsShow(valueAxisDefault.axisLabel, false),
  38881. axisTick: defaultsShow(valueAxisDefault.axisTick, false),
  38882. splitLine: defaultsShow(valueAxisDefault.splitLine, true),
  38883. splitArea: defaultsShow(valueAxisDefault.splitArea, true),
  38884. // {text, min, max}
  38885. indicator: []
  38886. }
  38887. });
  38888. /*
  38889. * Licensed to the Apache Software Foundation (ASF) under one
  38890. * or more contributor license agreements. See the NOTICE file
  38891. * distributed with this work for additional information
  38892. * regarding copyright ownership. The ASF licenses this file
  38893. * to you under the Apache License, Version 2.0 (the
  38894. * "License"); you may not use this file except in compliance
  38895. * with the License. You may obtain a copy of the License at
  38896. *
  38897. * http://www.apache.org/licenses/LICENSE-2.0
  38898. *
  38899. * Unless required by applicable law or agreed to in writing,
  38900. * software distributed under the License is distributed on an
  38901. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  38902. * KIND, either express or implied. See the License for the
  38903. * specific language governing permissions and limitations
  38904. * under the License.
  38905. */
  38906. var axisBuilderAttrs$1 = [
  38907. 'axisLine', 'axisTickLabel', 'axisName'
  38908. ];
  38909. extendComponentView({
  38910. type: 'radar',
  38911. render: function (radarModel, ecModel, api) {
  38912. var group = this.group;
  38913. group.removeAll();
  38914. this._buildAxes(radarModel);
  38915. this._buildSplitLineAndArea(radarModel);
  38916. },
  38917. _buildAxes: function (radarModel) {
  38918. var radar = radarModel.coordinateSystem;
  38919. var indicatorAxes = radar.getIndicatorAxes();
  38920. var axisBuilders = map(indicatorAxes, function (indicatorAxis) {
  38921. var axisBuilder = new AxisBuilder(indicatorAxis.model, {
  38922. position: [radar.cx, radar.cy],
  38923. rotation: indicatorAxis.angle,
  38924. labelDirection: -1,
  38925. tickDirection: -1,
  38926. nameDirection: 1
  38927. });
  38928. return axisBuilder;
  38929. });
  38930. each$1(axisBuilders, function (axisBuilder) {
  38931. each$1(axisBuilderAttrs$1, axisBuilder.add, axisBuilder);
  38932. this.group.add(axisBuilder.getGroup());
  38933. }, this);
  38934. },
  38935. _buildSplitLineAndArea: function (radarModel) {
  38936. var radar = radarModel.coordinateSystem;
  38937. var indicatorAxes = radar.getIndicatorAxes();
  38938. if (!indicatorAxes.length) {
  38939. return;
  38940. }
  38941. var shape = radarModel.get('shape');
  38942. var splitLineModel = radarModel.getModel('splitLine');
  38943. var splitAreaModel = radarModel.getModel('splitArea');
  38944. var lineStyleModel = splitLineModel.getModel('lineStyle');
  38945. var areaStyleModel = splitAreaModel.getModel('areaStyle');
  38946. var showSplitLine = splitLineModel.get('show');
  38947. var showSplitArea = splitAreaModel.get('show');
  38948. var splitLineColors = lineStyleModel.get('color');
  38949. var splitAreaColors = areaStyleModel.get('color');
  38950. splitLineColors = isArray(splitLineColors) ? splitLineColors : [splitLineColors];
  38951. splitAreaColors = isArray(splitAreaColors) ? splitAreaColors : [splitAreaColors];
  38952. var splitLines = [];
  38953. var splitAreas = [];
  38954. function getColorIndex(areaOrLine, areaOrLineColorList, idx) {
  38955. var colorIndex = idx % areaOrLineColorList.length;
  38956. areaOrLine[colorIndex] = areaOrLine[colorIndex] || [];
  38957. return colorIndex;
  38958. }
  38959. if (shape === 'circle') {
  38960. var ticksRadius = indicatorAxes[0].getTicksCoords();
  38961. var cx = radar.cx;
  38962. var cy = radar.cy;
  38963. for (var i = 0; i < ticksRadius.length; i++) {
  38964. if (showSplitLine) {
  38965. var colorIndex = getColorIndex(splitLines, splitLineColors, i);
  38966. splitLines[colorIndex].push(new Circle({
  38967. shape: {
  38968. cx: cx,
  38969. cy: cy,
  38970. r: ticksRadius[i].coord
  38971. }
  38972. }));
  38973. }
  38974. if (showSplitArea && i < ticksRadius.length - 1) {
  38975. var colorIndex = getColorIndex(splitAreas, splitAreaColors, i);
  38976. splitAreas[colorIndex].push(new Ring({
  38977. shape: {
  38978. cx: cx,
  38979. cy: cy,
  38980. r0: ticksRadius[i].coord,
  38981. r: ticksRadius[i + 1].coord
  38982. }
  38983. }));
  38984. }
  38985. }
  38986. }
  38987. // Polyyon
  38988. else {
  38989. var realSplitNumber;
  38990. var axesTicksPoints = map(indicatorAxes, function (indicatorAxis, idx) {
  38991. var ticksCoords = indicatorAxis.getTicksCoords();
  38992. realSplitNumber = realSplitNumber == null
  38993. ? ticksCoords.length - 1
  38994. : Math.min(ticksCoords.length - 1, realSplitNumber);
  38995. return map(ticksCoords, function (tickCoord) {
  38996. return radar.coordToPoint(tickCoord.coord, idx);
  38997. });
  38998. });
  38999. var prevPoints = [];
  39000. for (var i = 0; i <= realSplitNumber; i++) {
  39001. var points = [];
  39002. for (var j = 0; j < indicatorAxes.length; j++) {
  39003. points.push(axesTicksPoints[j][i]);
  39004. }
  39005. // Close
  39006. if (points[0]) {
  39007. points.push(points[0].slice());
  39008. }
  39009. else {
  39010. if (__DEV__) {
  39011. console.error('Can\'t draw value axis ' + i);
  39012. }
  39013. }
  39014. if (showSplitLine) {
  39015. var colorIndex = getColorIndex(splitLines, splitLineColors, i);
  39016. splitLines[colorIndex].push(new Polyline({
  39017. shape: {
  39018. points: points
  39019. }
  39020. }));
  39021. }
  39022. if (showSplitArea && prevPoints) {
  39023. var colorIndex = getColorIndex(splitAreas, splitAreaColors, i - 1);
  39024. splitAreas[colorIndex].push(new Polygon({
  39025. shape: {
  39026. points: points.concat(prevPoints)
  39027. }
  39028. }));
  39029. }
  39030. prevPoints = points.slice().reverse();
  39031. }
  39032. }
  39033. var lineStyle = lineStyleModel.getLineStyle();
  39034. var areaStyle = areaStyleModel.getAreaStyle();
  39035. // Add splitArea before splitLine
  39036. each$1(splitAreas, function (splitAreas, idx) {
  39037. this.group.add(mergePath(
  39038. splitAreas, {
  39039. style: defaults({
  39040. stroke: 'none',
  39041. fill: splitAreaColors[idx % splitAreaColors.length]
  39042. }, areaStyle),
  39043. silent: true
  39044. }
  39045. ));
  39046. }, this);
  39047. each$1(splitLines, function (splitLines, idx) {
  39048. this.group.add(mergePath(
  39049. splitLines, {
  39050. style: defaults({
  39051. fill: 'none',
  39052. stroke: splitLineColors[idx % splitLineColors.length]
  39053. }, lineStyle),
  39054. silent: true
  39055. }
  39056. ));
  39057. }, this);
  39058. }
  39059. });
  39060. /*
  39061. * Licensed to the Apache Software Foundation (ASF) under one
  39062. * or more contributor license agreements. See the NOTICE file
  39063. * distributed with this work for additional information
  39064. * regarding copyright ownership. The ASF licenses this file
  39065. * to you under the Apache License, Version 2.0 (the
  39066. * "License"); you may not use this file except in compliance
  39067. * with the License. You may obtain a copy of the License at
  39068. *
  39069. * http://www.apache.org/licenses/LICENSE-2.0
  39070. *
  39071. * Unless required by applicable law or agreed to in writing,
  39072. * software distributed under the License is distributed on an
  39073. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  39074. * KIND, either express or implied. See the License for the
  39075. * specific language governing permissions and limitations
  39076. * under the License.
  39077. */
  39078. /*
  39079. * Licensed to the Apache Software Foundation (ASF) under one
  39080. * or more contributor license agreements. See the NOTICE file
  39081. * distributed with this work for additional information
  39082. * regarding copyright ownership. The ASF licenses this file
  39083. * to you under the Apache License, Version 2.0 (the
  39084. * "License"); you may not use this file except in compliance
  39085. * with the License. You may obtain a copy of the License at
  39086. *
  39087. * http://www.apache.org/licenses/LICENSE-2.0
  39088. *
  39089. * Unless required by applicable law or agreed to in writing,
  39090. * software distributed under the License is distributed on an
  39091. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  39092. * KIND, either express or implied. See the License for the
  39093. * specific language governing permissions and limitations
  39094. * under the License.
  39095. */
  39096. var RadarSeries = SeriesModel.extend({
  39097. type: 'series.radar',
  39098. dependencies: ['radar'],
  39099. // Overwrite
  39100. init: function (option) {
  39101. RadarSeries.superApply(this, 'init', arguments);
  39102. // Enable legend selection for each data item
  39103. // Use a function instead of direct access because data reference may changed
  39104. this.legendDataProvider = function () {
  39105. return this.getRawData();
  39106. };
  39107. },
  39108. getInitialData: function (option, ecModel) {
  39109. return createListSimply(this, {
  39110. generateCoord: 'indicator_',
  39111. generateCoordCount: Infinity
  39112. });
  39113. },
  39114. formatTooltip: function (dataIndex) {
  39115. var data = this.getData();
  39116. var coordSys = this.coordinateSystem;
  39117. var indicatorAxes = coordSys.getIndicatorAxes();
  39118. var name = this.getData().getName(dataIndex);
  39119. return encodeHTML(name === '' ? this.name : name) + '<br/>'
  39120. + map(indicatorAxes, function (axis, idx) {
  39121. var val = data.get(data.mapDimension(axis.dim), dataIndex);
  39122. return encodeHTML(axis.name + ' : ' + val);
  39123. }).join('<br />');
  39124. },
  39125. defaultOption: {
  39126. zlevel: 0,
  39127. z: 2,
  39128. coordinateSystem: 'radar',
  39129. legendHoverLink: true,
  39130. radarIndex: 0,
  39131. lineStyle: {
  39132. width: 2,
  39133. type: 'solid'
  39134. },
  39135. label: {
  39136. position: 'top'
  39137. },
  39138. // areaStyle: {
  39139. // },
  39140. // itemStyle: {}
  39141. symbol: 'emptyCircle',
  39142. symbolSize: 4
  39143. // symbolRotate: null
  39144. }
  39145. });
  39146. /*
  39147. * Licensed to the Apache Software Foundation (ASF) under one
  39148. * or more contributor license agreements. See the NOTICE file
  39149. * distributed with this work for additional information
  39150. * regarding copyright ownership. The ASF licenses this file
  39151. * to you under the Apache License, Version 2.0 (the
  39152. * "License"); you may not use this file except in compliance
  39153. * with the License. You may obtain a copy of the License at
  39154. *
  39155. * http://www.apache.org/licenses/LICENSE-2.0
  39156. *
  39157. * Unless required by applicable law or agreed to in writing,
  39158. * software distributed under the License is distributed on an
  39159. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  39160. * KIND, either express or implied. See the License for the
  39161. * specific language governing permissions and limitations
  39162. * under the License.
  39163. */
  39164. function normalizeSymbolSize(symbolSize) {
  39165. if (!isArray(symbolSize)) {
  39166. symbolSize = [+symbolSize, +symbolSize];
  39167. }
  39168. return symbolSize;
  39169. }
  39170. extendChartView({
  39171. type: 'radar',
  39172. render: function (seriesModel, ecModel, api) {
  39173. var polar = seriesModel.coordinateSystem;
  39174. var group = this.group;
  39175. var data = seriesModel.getData();
  39176. var oldData = this._data;
  39177. function createSymbol$$1(data, idx) {
  39178. var symbolType = data.getItemVisual(idx, 'symbol') || 'circle';
  39179. var color = data.getItemVisual(idx, 'color');
  39180. if (symbolType === 'none') {
  39181. return;
  39182. }
  39183. var symbolSize = normalizeSymbolSize(
  39184. data.getItemVisual(idx, 'symbolSize')
  39185. );
  39186. var symbolPath = createSymbol(
  39187. symbolType, -1, -1, 2, 2, color
  39188. );
  39189. symbolPath.attr({
  39190. style: {
  39191. strokeNoScale: true
  39192. },
  39193. z2: 100,
  39194. scale: [symbolSize[0] / 2, symbolSize[1] / 2]
  39195. });
  39196. return symbolPath;
  39197. }
  39198. function updateSymbols(oldPoints, newPoints, symbolGroup, data, idx, isInit) {
  39199. // Simply rerender all
  39200. symbolGroup.removeAll();
  39201. for (var i = 0; i < newPoints.length - 1; i++) {
  39202. var symbolPath = createSymbol$$1(data, idx);
  39203. if (symbolPath) {
  39204. symbolPath.__dimIdx = i;
  39205. if (oldPoints[i]) {
  39206. symbolPath.attr('position', oldPoints[i]);
  39207. graphic[isInit ? 'initProps' : 'updateProps'](
  39208. symbolPath, {
  39209. position: newPoints[i]
  39210. }, seriesModel, idx
  39211. );
  39212. }
  39213. else {
  39214. symbolPath.attr('position', newPoints[i]);
  39215. }
  39216. symbolGroup.add(symbolPath);
  39217. }
  39218. }
  39219. }
  39220. function getInitialPoints(points) {
  39221. return map(points, function (pt) {
  39222. return [polar.cx, polar.cy];
  39223. });
  39224. }
  39225. data.diff(oldData)
  39226. .add(function (idx) {
  39227. var points = data.getItemLayout(idx);
  39228. if (!points) {
  39229. return;
  39230. }
  39231. var polygon = new Polygon();
  39232. var polyline = new Polyline();
  39233. var target = {
  39234. shape: {
  39235. points: points
  39236. }
  39237. };
  39238. polygon.shape.points = getInitialPoints(points);
  39239. polyline.shape.points = getInitialPoints(points);
  39240. initProps(polygon, target, seriesModel, idx);
  39241. initProps(polyline, target, seriesModel, idx);
  39242. var itemGroup = new Group();
  39243. var symbolGroup = new Group();
  39244. itemGroup.add(polyline);
  39245. itemGroup.add(polygon);
  39246. itemGroup.add(symbolGroup);
  39247. updateSymbols(
  39248. polyline.shape.points, points, symbolGroup, data, idx, true
  39249. );
  39250. data.setItemGraphicEl(idx, itemGroup);
  39251. })
  39252. .update(function (newIdx, oldIdx) {
  39253. var itemGroup = oldData.getItemGraphicEl(oldIdx);
  39254. var polyline = itemGroup.childAt(0);
  39255. var polygon = itemGroup.childAt(1);
  39256. var symbolGroup = itemGroup.childAt(2);
  39257. var target = {
  39258. shape: {
  39259. points: data.getItemLayout(newIdx)
  39260. }
  39261. };
  39262. if (!target.shape.points) {
  39263. return;
  39264. }
  39265. updateSymbols(
  39266. polyline.shape.points, target.shape.points, symbolGroup, data, newIdx, false
  39267. );
  39268. updateProps(polyline, target, seriesModel);
  39269. updateProps(polygon, target, seriesModel);
  39270. data.setItemGraphicEl(newIdx, itemGroup);
  39271. })
  39272. .remove(function (idx) {
  39273. group.remove(oldData.getItemGraphicEl(idx));
  39274. })
  39275. .execute();
  39276. data.eachItemGraphicEl(function (itemGroup, idx) {
  39277. var itemModel = data.getItemModel(idx);
  39278. var polyline = itemGroup.childAt(0);
  39279. var polygon = itemGroup.childAt(1);
  39280. var symbolGroup = itemGroup.childAt(2);
  39281. var color = data.getItemVisual(idx, 'color');
  39282. group.add(itemGroup);
  39283. polyline.useStyle(
  39284. defaults(
  39285. itemModel.getModel('lineStyle').getLineStyle(),
  39286. {
  39287. fill: 'none',
  39288. stroke: color
  39289. }
  39290. )
  39291. );
  39292. polyline.hoverStyle = itemModel.getModel('emphasis.lineStyle').getLineStyle();
  39293. var areaStyleModel = itemModel.getModel('areaStyle');
  39294. var hoverAreaStyleModel = itemModel.getModel('emphasis.areaStyle');
  39295. var polygonIgnore = areaStyleModel.isEmpty() && areaStyleModel.parentModel.isEmpty();
  39296. var hoverPolygonIgnore = hoverAreaStyleModel.isEmpty() && hoverAreaStyleModel.parentModel.isEmpty();
  39297. hoverPolygonIgnore = hoverPolygonIgnore && polygonIgnore;
  39298. polygon.ignore = polygonIgnore;
  39299. polygon.useStyle(
  39300. defaults(
  39301. areaStyleModel.getAreaStyle(),
  39302. {
  39303. fill: color,
  39304. opacity: 0.7
  39305. }
  39306. )
  39307. );
  39308. polygon.hoverStyle = hoverAreaStyleModel.getAreaStyle();
  39309. var itemStyle = itemModel.getModel('itemStyle').getItemStyle(['color']);
  39310. var itemHoverStyle = itemModel.getModel('emphasis.itemStyle').getItemStyle();
  39311. var labelModel = itemModel.getModel('label');
  39312. var labelHoverModel = itemModel.getModel('emphasis.label');
  39313. symbolGroup.eachChild(function (symbolPath) {
  39314. symbolPath.setStyle(itemStyle);
  39315. symbolPath.hoverStyle = clone(itemHoverStyle);
  39316. var defaultText = data.get(data.dimensions[symbolPath.__dimIdx], idx);
  39317. (defaultText == null || isNaN(defaultText)) && (defaultText = '');
  39318. setLabelStyle(
  39319. symbolPath.style, symbolPath.hoverStyle, labelModel, labelHoverModel,
  39320. {
  39321. labelFetcher: data.hostModel,
  39322. labelDataIndex: idx,
  39323. labelDimIndex: symbolPath.__dimIdx,
  39324. defaultText: defaultText,
  39325. autoColor: color,
  39326. isRectText: true
  39327. }
  39328. );
  39329. });
  39330. itemGroup.highDownOnUpdate = function (fromState, toState) {
  39331. polygon.attr('ignore', toState === 'emphasis' ? hoverPolygonIgnore : polygonIgnore);
  39332. };
  39333. setHoverStyle(itemGroup);
  39334. });
  39335. this._data = data;
  39336. },
  39337. remove: function () {
  39338. this.group.removeAll();
  39339. this._data = null;
  39340. },
  39341. dispose: function () {}
  39342. });
  39343. /*
  39344. * Licensed to the Apache Software Foundation (ASF) under one
  39345. * or more contributor license agreements. See the NOTICE file
  39346. * distributed with this work for additional information
  39347. * regarding copyright ownership. The ASF licenses this file
  39348. * to you under the Apache License, Version 2.0 (the
  39349. * "License"); you may not use this file except in compliance
  39350. * with the License. You may obtain a copy of the License at
  39351. *
  39352. * http://www.apache.org/licenses/LICENSE-2.0
  39353. *
  39354. * Unless required by applicable law or agreed to in writing,
  39355. * software distributed under the License is distributed on an
  39356. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  39357. * KIND, either express or implied. See the License for the
  39358. * specific language governing permissions and limitations
  39359. * under the License.
  39360. */
  39361. var radarLayout = function (ecModel) {
  39362. ecModel.eachSeriesByType('radar', function (seriesModel) {
  39363. var data = seriesModel.getData();
  39364. var points = [];
  39365. var coordSys = seriesModel.coordinateSystem;
  39366. if (!coordSys) {
  39367. return;
  39368. }
  39369. var axes = coordSys.getIndicatorAxes();
  39370. each$1(axes, function (axis, axisIndex) {
  39371. data.each(data.mapDimension(axes[axisIndex].dim), function (val, dataIndex) {
  39372. points[dataIndex] = points[dataIndex] || [];
  39373. var point = coordSys.dataToPoint(val, axisIndex);
  39374. points[dataIndex][axisIndex] = isValidPoint(point)
  39375. ? point : getValueMissingPoint(coordSys);
  39376. });
  39377. });
  39378. // Close polygon
  39379. data.each(function (idx) {
  39380. // TODO
  39381. // Is it appropriate to connect to the next data when some data is missing?
  39382. // Or, should trade it like `connectNull` in line chart?
  39383. var firstPoint = find(points[idx], function (point) {
  39384. return isValidPoint(point);
  39385. }) || getValueMissingPoint(coordSys);
  39386. // Copy the first actual point to the end of the array
  39387. points[idx].push(firstPoint.slice());
  39388. data.setItemLayout(idx, points[idx]);
  39389. });
  39390. });
  39391. };
  39392. function isValidPoint(point) {
  39393. return !isNaN(point[0]) && !isNaN(point[1]);
  39394. }
  39395. function getValueMissingPoint(coordSys) {
  39396. // It is error-prone to input [NaN, NaN] into polygon, polygon.
  39397. // (probably cause problem when refreshing or animating)
  39398. return [coordSys.cx, coordSys.cy];
  39399. }
  39400. /*
  39401. * Licensed to the Apache Software Foundation (ASF) under one
  39402. * or more contributor license agreements. See the NOTICE file
  39403. * distributed with this work for additional information
  39404. * regarding copyright ownership. The ASF licenses this file
  39405. * to you under the Apache License, Version 2.0 (the
  39406. * "License"); you may not use this file except in compliance
  39407. * with the License. You may obtain a copy of the License at
  39408. *
  39409. * http://www.apache.org/licenses/LICENSE-2.0
  39410. *
  39411. * Unless required by applicable law or agreed to in writing,
  39412. * software distributed under the License is distributed on an
  39413. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  39414. * KIND, either express or implied. See the License for the
  39415. * specific language governing permissions and limitations
  39416. * under the License.
  39417. */
  39418. // Backward compat for radar chart in 2
  39419. var backwardCompat$1 = function (option) {
  39420. var polarOptArr = option.polar;
  39421. if (polarOptArr) {
  39422. if (!isArray(polarOptArr)) {
  39423. polarOptArr = [polarOptArr];
  39424. }
  39425. var polarNotRadar = [];
  39426. each$1(polarOptArr, function (polarOpt, idx) {
  39427. if (polarOpt.indicator) {
  39428. if (polarOpt.type && !polarOpt.shape) {
  39429. polarOpt.shape = polarOpt.type;
  39430. }
  39431. option.radar = option.radar || [];
  39432. if (!isArray(option.radar)) {
  39433. option.radar = [option.radar];
  39434. }
  39435. option.radar.push(polarOpt);
  39436. }
  39437. else {
  39438. polarNotRadar.push(polarOpt);
  39439. }
  39440. });
  39441. option.polar = polarNotRadar;
  39442. }
  39443. each$1(option.series, function (seriesOpt) {
  39444. if (seriesOpt && seriesOpt.type === 'radar' && seriesOpt.polarIndex) {
  39445. seriesOpt.radarIndex = seriesOpt.polarIndex;
  39446. }
  39447. });
  39448. };
  39449. /*
  39450. * Licensed to the Apache Software Foundation (ASF) under one
  39451. * or more contributor license agreements. See the NOTICE file
  39452. * distributed with this work for additional information
  39453. * regarding copyright ownership. The ASF licenses this file
  39454. * to you under the Apache License, Version 2.0 (the
  39455. * "License"); you may not use this file except in compliance
  39456. * with the License. You may obtain a copy of the License at
  39457. *
  39458. * http://www.apache.org/licenses/LICENSE-2.0
  39459. *
  39460. * Unless required by applicable law or agreed to in writing,
  39461. * software distributed under the License is distributed on an
  39462. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  39463. * KIND, either express or implied. See the License for the
  39464. * specific language governing permissions and limitations
  39465. * under the License.
  39466. */
  39467. // Must use radar component
  39468. registerVisual(dataColor('radar'));
  39469. registerVisual(visualSymbol('radar', 'circle'));
  39470. registerLayout(radarLayout);
  39471. registerProcessor(dataFilter('radar'));
  39472. registerPreprocessor(backwardCompat$1);
  39473. /*
  39474. * Licensed to the Apache Software Foundation (ASF) under one
  39475. * or more contributor license agreements. See the NOTICE file
  39476. * distributed with this work for additional information
  39477. * regarding copyright ownership. The ASF licenses this file
  39478. * to you under the Apache License, Version 2.0 (the
  39479. * "License"); you may not use this file except in compliance
  39480. * with the License. You may obtain a copy of the License at
  39481. *
  39482. * http://www.apache.org/licenses/LICENSE-2.0
  39483. *
  39484. * Unless required by applicable law or agreed to in writing,
  39485. * software distributed under the License is distributed on an
  39486. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  39487. * KIND, either express or implied. See the License for the
  39488. * specific language governing permissions and limitations
  39489. * under the License.
  39490. */
  39491. // Fix for 南海诸岛
  39492. var geoCoord = [126, 25];
  39493. var points$1 = [
  39494. [[0, 3.5], [7, 11.2], [15, 11.9], [30, 7], [42, 0.7], [52, 0.7],
  39495. [56, 7.7], [59, 0.7], [64, 0.7], [64, 0], [5, 0], [0, 3.5]],
  39496. [[13, 16.1], [19, 14.7], [16, 21.7], [11, 23.1], [13, 16.1]],
  39497. [[12, 32.2], [14, 38.5], [15, 38.5], [13, 32.2], [12, 32.2]],
  39498. [[16, 47.6], [12, 53.2], [13, 53.2], [18, 47.6], [16, 47.6]],
  39499. [[6, 64.4], [8, 70], [9, 70], [8, 64.4], [6, 64.4]],
  39500. [[23, 82.6], [29, 79.8], [30, 79.8], [25, 82.6], [23, 82.6]],
  39501. [[37, 70.7], [43, 62.3], [44, 62.3], [39, 70.7], [37, 70.7]],
  39502. [[48, 51.1], [51, 45.5], [53, 45.5], [50, 51.1], [48, 51.1]],
  39503. [[51, 35], [51, 28.7], [53, 28.7], [53, 35], [51, 35]],
  39504. [[52, 22.4], [55, 17.5], [56, 17.5], [53, 22.4], [52, 22.4]],
  39505. [[58, 12.6], [62, 7], [63, 7], [60, 12.6], [58, 12.6]],
  39506. [[0, 3.5], [0, 93.1], [64, 93.1], [64, 0], [63, 0], [63, 92.4],
  39507. [1, 92.4], [1, 3.5], [0, 3.5]]
  39508. ];
  39509. for (var i$1 = 0; i$1 < points$1.length; i$1++) {
  39510. for (var k = 0; k < points$1[i$1].length; k++) {
  39511. points$1[i$1][k][0] /= 10.5;
  39512. points$1[i$1][k][1] /= -10.5 / 0.75;
  39513. points$1[i$1][k][0] += geoCoord[0];
  39514. points$1[i$1][k][1] += geoCoord[1];
  39515. }
  39516. }
  39517. var fixNanhai = function (mapType, regions) {
  39518. if (mapType === 'china') {
  39519. regions.push(new Region(
  39520. '南海诸岛',
  39521. map(points$1, function (exterior) {
  39522. return {
  39523. type: 'polygon',
  39524. exterior: exterior
  39525. };
  39526. }), geoCoord
  39527. ));
  39528. }
  39529. };
  39530. /*
  39531. * Licensed to the Apache Software Foundation (ASF) under one
  39532. * or more contributor license agreements. See the NOTICE file
  39533. * distributed with this work for additional information
  39534. * regarding copyright ownership. The ASF licenses this file
  39535. * to you under the Apache License, Version 2.0 (the
  39536. * "License"); you may not use this file except in compliance
  39537. * with the License. You may obtain a copy of the License at
  39538. *
  39539. * http://www.apache.org/licenses/LICENSE-2.0
  39540. *
  39541. * Unless required by applicable law or agreed to in writing,
  39542. * software distributed under the License is distributed on an
  39543. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  39544. * KIND, either express or implied. See the License for the
  39545. * specific language governing permissions and limitations
  39546. * under the License.
  39547. */
  39548. var coordsOffsetMap = {
  39549. '南海诸岛': [32, 80],
  39550. // 全国
  39551. '广东': [0, -10],
  39552. '香港': [10, 5],
  39553. '澳门': [-10, 10],
  39554. //'北京': [-10, 0],
  39555. '天津': [5, 5]
  39556. };
  39557. var fixTextCoord = function (mapType, region) {
  39558. if (mapType === 'china') {
  39559. var coordFix = coordsOffsetMap[region.name];
  39560. if (coordFix) {
  39561. var cp = region.center;
  39562. cp[0] += coordFix[0] / 10.5;
  39563. cp[1] += -coordFix[1] / (10.5 / 0.75);
  39564. }
  39565. }
  39566. };
  39567. /*
  39568. * Licensed to the Apache Software Foundation (ASF) under one
  39569. * or more contributor license agreements. See the NOTICE file
  39570. * distributed with this work for additional information
  39571. * regarding copyright ownership. The ASF licenses this file
  39572. * to you under the Apache License, Version 2.0 (the
  39573. * "License"); you may not use this file except in compliance
  39574. * with the License. You may obtain a copy of the License at
  39575. *
  39576. * http://www.apache.org/licenses/LICENSE-2.0
  39577. *
  39578. * Unless required by applicable law or agreed to in writing,
  39579. * software distributed under the License is distributed on an
  39580. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  39581. * KIND, either express or implied. See the License for the
  39582. * specific language governing permissions and limitations
  39583. * under the License.
  39584. */
  39585. var geoCoordMap = {
  39586. 'Russia': [100, 60],
  39587. 'United States': [-99, 38],
  39588. 'United States of America': [-99, 38]
  39589. };
  39590. var fixGeoCoord = function (mapType, region) {
  39591. if (mapType === 'world') {
  39592. var geoCoord = geoCoordMap[region.name];
  39593. if (geoCoord) {
  39594. var cp = region.center;
  39595. cp[0] = geoCoord[0];
  39596. cp[1] = geoCoord[1];
  39597. }
  39598. }
  39599. };
  39600. /*
  39601. * Licensed to the Apache Software Foundation (ASF) under one
  39602. * or more contributor license agreements. See the NOTICE file
  39603. * distributed with this work for additional information
  39604. * regarding copyright ownership. The ASF licenses this file
  39605. * to you under the Apache License, Version 2.0 (the
  39606. * "License"); you may not use this file except in compliance
  39607. * with the License. You may obtain a copy of the License at
  39608. *
  39609. * http://www.apache.org/licenses/LICENSE-2.0
  39610. *
  39611. * Unless required by applicable law or agreed to in writing,
  39612. * software distributed under the License is distributed on an
  39613. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  39614. * KIND, either express or implied. See the License for the
  39615. * specific language governing permissions and limitations
  39616. * under the License.
  39617. */
  39618. // Fix for 钓鱼岛
  39619. // var Region = require('../Region');
  39620. // var zrUtil = require('zrender/src/core/util');
  39621. // var geoCoord = [126, 25];
  39622. var points$2 = [
  39623. [
  39624. [123.45165252685547, 25.73527164402261],
  39625. [123.49731445312499, 25.73527164402261],
  39626. [123.49731445312499, 25.750734064600884],
  39627. [123.45165252685547, 25.750734064600884],
  39628. [123.45165252685547, 25.73527164402261]
  39629. ]
  39630. ];
  39631. var fixDiaoyuIsland = function (mapType, region) {
  39632. if (mapType === 'china' && region.name === '台湾') {
  39633. region.geometries.push({
  39634. type: 'polygon',
  39635. exterior: points$2[0]
  39636. });
  39637. }
  39638. };
  39639. /*
  39640. * Licensed to the Apache Software Foundation (ASF) under one
  39641. * or more contributor license agreements. See the NOTICE file
  39642. * distributed with this work for additional information
  39643. * regarding copyright ownership. The ASF licenses this file
  39644. * to you under the Apache License, Version 2.0 (the
  39645. * "License"); you may not use this file except in compliance
  39646. * with the License. You may obtain a copy of the License at
  39647. *
  39648. * http://www.apache.org/licenses/LICENSE-2.0
  39649. *
  39650. * Unless required by applicable law or agreed to in writing,
  39651. * software distributed under the License is distributed on an
  39652. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  39653. * KIND, either express or implied. See the License for the
  39654. * specific language governing permissions and limitations
  39655. * under the License.
  39656. */
  39657. // Built-in GEO fixer.
  39658. var inner$7 = makeInner();
  39659. var geoJSONLoader = {
  39660. /**
  39661. * @param {string} mapName
  39662. * @param {Object} mapRecord {specialAreas, geoJSON}
  39663. * @return {Object} {regions, boundingRect}
  39664. */
  39665. load: function (mapName, mapRecord) {
  39666. var parsed = inner$7(mapRecord).parsed;
  39667. if (parsed) {
  39668. return parsed;
  39669. }
  39670. var specialAreas = mapRecord.specialAreas || {};
  39671. var geoJSON = mapRecord.geoJSON;
  39672. var regions;
  39673. // https://jsperf.com/try-catch-performance-overhead
  39674. try {
  39675. regions = geoJSON ? parseGeoJson$1(geoJSON) : [];
  39676. }
  39677. catch (e) {
  39678. throw new Error('Invalid geoJson format\n' + e.message);
  39679. }
  39680. each$1(regions, function (region) {
  39681. var regionName = region.name;
  39682. fixTextCoord(mapName, region);
  39683. fixGeoCoord(mapName, region);
  39684. fixDiaoyuIsland(mapName, region);
  39685. // Some area like Alaska in USA map needs to be tansformed
  39686. // to look better
  39687. var specialArea = specialAreas[regionName];
  39688. if (specialArea) {
  39689. region.transformTo(
  39690. specialArea.left, specialArea.top, specialArea.width, specialArea.height
  39691. );
  39692. }
  39693. });
  39694. fixNanhai(mapName, regions);
  39695. return (inner$7(mapRecord).parsed = {
  39696. regions: regions,
  39697. boundingRect: getBoundingRect$1(regions)
  39698. });
  39699. }
  39700. };
  39701. function getBoundingRect$1(regions) {
  39702. var rect;
  39703. for (var i = 0; i < regions.length; i++) {
  39704. var regionRect = regions[i].getBoundingRect();
  39705. rect = rect || regionRect.clone();
  39706. rect.union(regionRect);
  39707. }
  39708. return rect;
  39709. }
  39710. /*
  39711. * Licensed to the Apache Software Foundation (ASF) under one
  39712. * or more contributor license agreements. See the NOTICE file
  39713. * distributed with this work for additional information
  39714. * regarding copyright ownership. The ASF licenses this file
  39715. * to you under the Apache License, Version 2.0 (the
  39716. * "License"); you may not use this file except in compliance
  39717. * with the License. You may obtain a copy of the License at
  39718. *
  39719. * http://www.apache.org/licenses/LICENSE-2.0
  39720. *
  39721. * Unless required by applicable law or agreed to in writing,
  39722. * software distributed under the License is distributed on an
  39723. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  39724. * KIND, either express or implied. See the License for the
  39725. * specific language governing permissions and limitations
  39726. * under the License.
  39727. */
  39728. var inner$8 = makeInner();
  39729. var geoSVGLoader = {
  39730. /**
  39731. * @param {string} mapName
  39732. * @param {Object} mapRecord {specialAreas, geoJSON}
  39733. * @return {Object} {root, boundingRect}
  39734. */
  39735. load: function (mapName, mapRecord) {
  39736. var originRoot = inner$8(mapRecord).originRoot;
  39737. if (originRoot) {
  39738. return {
  39739. root: originRoot,
  39740. boundingRect: inner$8(mapRecord).boundingRect
  39741. };
  39742. }
  39743. var graphic = buildGraphic(mapRecord);
  39744. inner$8(mapRecord).originRoot = graphic.root;
  39745. inner$8(mapRecord).boundingRect = graphic.boundingRect;
  39746. return graphic;
  39747. },
  39748. makeGraphic: function (mapName, mapRecord, hostKey) {
  39749. // For performance consideration (in large SVG), graphic only maked
  39750. // when necessary and reuse them according to hostKey.
  39751. var field = inner$8(mapRecord);
  39752. var rootMap = field.rootMap || (field.rootMap = createHashMap());
  39753. var root = rootMap.get(hostKey);
  39754. if (root) {
  39755. return root;
  39756. }
  39757. var originRoot = field.originRoot;
  39758. var boundingRect = field.boundingRect;
  39759. // For performance, if originRoot is not used by a view,
  39760. // assign it to a view, but not reproduce graphic elements.
  39761. if (!field.originRootHostKey) {
  39762. field.originRootHostKey = hostKey;
  39763. root = originRoot;
  39764. }
  39765. else {
  39766. root = buildGraphic(mapRecord, boundingRect).root;
  39767. }
  39768. return rootMap.set(hostKey, root);
  39769. },
  39770. removeGraphic: function (mapName, mapRecord, hostKey) {
  39771. var field = inner$8(mapRecord);
  39772. var rootMap = field.rootMap;
  39773. rootMap && rootMap.removeKey(hostKey);
  39774. if (hostKey === field.originRootHostKey) {
  39775. field.originRootHostKey = null;
  39776. }
  39777. }
  39778. };
  39779. function buildGraphic(mapRecord, boundingRect) {
  39780. var svgXML = mapRecord.svgXML;
  39781. var result;
  39782. var root;
  39783. try {
  39784. result = svgXML && parseSVG(svgXML, {
  39785. ignoreViewBox: true,
  39786. ignoreRootClip: true
  39787. }) || {};
  39788. root = result.root;
  39789. assert$1(root != null);
  39790. }
  39791. catch (e) {
  39792. throw new Error('Invalid svg format\n' + e.message);
  39793. }
  39794. var svgWidth = result.width;
  39795. var svgHeight = result.height;
  39796. var viewBoxRect = result.viewBoxRect;
  39797. if (!boundingRect) {
  39798. boundingRect = (svgWidth == null || svgHeight == null)
  39799. // If svg width / height not specified, calculate
  39800. // bounding rect as the width / height
  39801. ? root.getBoundingRect()
  39802. : new BoundingRect(0, 0, 0, 0);
  39803. if (svgWidth != null) {
  39804. boundingRect.width = svgWidth;
  39805. }
  39806. if (svgHeight != null) {
  39807. boundingRect.height = svgHeight;
  39808. }
  39809. }
  39810. if (viewBoxRect) {
  39811. var viewBoxTransform = makeViewBoxTransform(viewBoxRect, boundingRect.width, boundingRect.height);
  39812. var elRoot = root;
  39813. root = new Group();
  39814. root.add(elRoot);
  39815. elRoot.scale = viewBoxTransform.scale;
  39816. elRoot.position = viewBoxTransform.position;
  39817. }
  39818. root.setClipPath(new Rect({
  39819. shape: boundingRect.plain()
  39820. }));
  39821. return {
  39822. root: root,
  39823. boundingRect: boundingRect
  39824. };
  39825. }
  39826. /*
  39827. * Licensed to the Apache Software Foundation (ASF) under one
  39828. * or more contributor license agreements. See the NOTICE file
  39829. * distributed with this work for additional information
  39830. * regarding copyright ownership. The ASF licenses this file
  39831. * to you under the Apache License, Version 2.0 (the
  39832. * "License"); you may not use this file except in compliance
  39833. * with the License. You may obtain a copy of the License at
  39834. *
  39835. * http://www.apache.org/licenses/LICENSE-2.0
  39836. *
  39837. * Unless required by applicable law or agreed to in writing,
  39838. * software distributed under the License is distributed on an
  39839. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  39840. * KIND, either express or implied. See the License for the
  39841. * specific language governing permissions and limitations
  39842. * under the License.
  39843. */
  39844. var loaders = {
  39845. geoJSON: geoJSONLoader,
  39846. svg: geoSVGLoader
  39847. };
  39848. var geoSourceManager = {
  39849. /**
  39850. * @param {string} mapName
  39851. * @param {Object} nameMap
  39852. * @return {Object} source {regions, regionsMap, nameCoordMap, boundingRect}
  39853. */
  39854. load: function (mapName, nameMap) {
  39855. var regions = [];
  39856. var regionsMap = createHashMap();
  39857. var nameCoordMap = createHashMap();
  39858. var boundingRect;
  39859. var mapRecords = retrieveMap(mapName);
  39860. each$1(mapRecords, function (record) {
  39861. var singleSource = loaders[record.type].load(mapName, record);
  39862. each$1(singleSource.regions, function (region) {
  39863. var regionName = region.name;
  39864. // Try use the alias in geoNameMap
  39865. if (nameMap && nameMap.hasOwnProperty(regionName)) {
  39866. region = region.cloneShallow(regionName = nameMap[regionName]);
  39867. }
  39868. regions.push(region);
  39869. regionsMap.set(regionName, region);
  39870. nameCoordMap.set(regionName, region.center);
  39871. });
  39872. var rect = singleSource.boundingRect;
  39873. if (rect) {
  39874. boundingRect
  39875. ? boundingRect.union(rect)
  39876. : (boundingRect = rect.clone());
  39877. }
  39878. });
  39879. return {
  39880. regions: regions,
  39881. regionsMap: regionsMap,
  39882. nameCoordMap: nameCoordMap,
  39883. // FIXME Always return new ?
  39884. boundingRect: boundingRect || new BoundingRect(0, 0, 0, 0)
  39885. };
  39886. },
  39887. /**
  39888. * @param {string} mapName
  39889. * @param {string} hostKey For cache.
  39890. * @return {Array.<module:zrender/Element>} Roots.
  39891. */
  39892. makeGraphic: makeInvoker('makeGraphic'),
  39893. /**
  39894. * @param {string} mapName
  39895. * @param {string} hostKey For cache.
  39896. */
  39897. removeGraphic: makeInvoker('removeGraphic')
  39898. };
  39899. function makeInvoker(methodName) {
  39900. return function (mapName, hostKey) {
  39901. var mapRecords = retrieveMap(mapName);
  39902. var results = [];
  39903. each$1(mapRecords, function (record) {
  39904. var method = loaders[record.type][methodName];
  39905. method && results.push(method(mapName, record, hostKey));
  39906. });
  39907. return results;
  39908. };
  39909. }
  39910. function mapNotExistsError(mapName) {
  39911. if (__DEV__) {
  39912. console.error(
  39913. 'Map ' + mapName + ' not exists. The GeoJSON of the map must be provided.'
  39914. );
  39915. }
  39916. }
  39917. function retrieveMap(mapName) {
  39918. var mapRecords = mapDataStorage.retrieveMap(mapName) || [];
  39919. if (__DEV__) {
  39920. if (!mapRecords.length) {
  39921. mapNotExistsError(mapName);
  39922. }
  39923. }
  39924. return mapRecords;
  39925. }
  39926. /*
  39927. * Licensed to the Apache Software Foundation (ASF) under one
  39928. * or more contributor license agreements. See the NOTICE file
  39929. * distributed with this work for additional information
  39930. * regarding copyright ownership. The ASF licenses this file
  39931. * to you under the Apache License, Version 2.0 (the
  39932. * "License"); you may not use this file except in compliance
  39933. * with the License. You may obtain a copy of the License at
  39934. *
  39935. * http://www.apache.org/licenses/LICENSE-2.0
  39936. *
  39937. * Unless required by applicable law or agreed to in writing,
  39938. * software distributed under the License is distributed on an
  39939. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  39940. * KIND, either express or implied. See the License for the
  39941. * specific language governing permissions and limitations
  39942. * under the License.
  39943. */
  39944. var MapSeries = SeriesModel.extend({
  39945. type: 'series.map',
  39946. dependencies: ['geo'],
  39947. layoutMode: 'box',
  39948. /**
  39949. * Only first map series of same mapType will drawMap
  39950. * @type {boolean}
  39951. */
  39952. needsDrawMap: false,
  39953. /**
  39954. * Group of all map series with same mapType
  39955. * @type {boolean}
  39956. */
  39957. seriesGroup: [],
  39958. getInitialData: function (option) {
  39959. var data = createListSimply(this, ['value']);
  39960. var valueDim = data.mapDimension('value');
  39961. var dataNameMap = createHashMap();
  39962. var selectTargetList = [];
  39963. var toAppendNames = [];
  39964. for (var i = 0, len = data.count(); i < len; i++) {
  39965. var name = data.getName(i);
  39966. dataNameMap.set(name, true);
  39967. selectTargetList.push({
  39968. name: name,
  39969. value: data.get(valueDim, i),
  39970. selected: retrieveRawAttr(data, i, 'selected')
  39971. });
  39972. }
  39973. var geoSource = geoSourceManager.load(this.getMapType(), this.option.nameMap);
  39974. each$1(geoSource.regions, function (region) {
  39975. var name = region.name;
  39976. if (!dataNameMap.get(name)) {
  39977. selectTargetList.push({name: name});
  39978. toAppendNames.push(name);
  39979. }
  39980. });
  39981. this.updateSelectedMap(selectTargetList);
  39982. // Complete data with missing regions. The consequent processes (like visual
  39983. // map and render) can not be performed without a "full data". For example,
  39984. // find `dataIndex` by name.
  39985. data.appendValues([], toAppendNames);
  39986. return data;
  39987. },
  39988. /**
  39989. * If no host geo model, return null, which means using a
  39990. * inner exclusive geo model.
  39991. */
  39992. getHostGeoModel: function () {
  39993. var geoIndex = this.option.geoIndex;
  39994. return geoIndex != null
  39995. ? this.dependentModels.geo[geoIndex]
  39996. : null;
  39997. },
  39998. getMapType: function () {
  39999. return (this.getHostGeoModel() || this).option.map;
  40000. },
  40001. // _fillOption: function (option, mapName) {
  40002. // Shallow clone
  40003. // option = zrUtil.extend({}, option);
  40004. // option.data = geoCreator.getFilledRegions(option.data, mapName, option.nameMap);
  40005. // return option;
  40006. // },
  40007. getRawValue: function (dataIndex) {
  40008. // Use value stored in data instead because it is calculated from multiple series
  40009. // FIXME Provide all value of multiple series ?
  40010. var data = this.getData();
  40011. return data.get(data.mapDimension('value'), dataIndex);
  40012. },
  40013. /**
  40014. * Get model of region
  40015. * @param {string} name
  40016. * @return {module:echarts/model/Model}
  40017. */
  40018. getRegionModel: function (regionName) {
  40019. var data = this.getData();
  40020. return data.getItemModel(data.indexOfName(regionName));
  40021. },
  40022. /**
  40023. * Map tooltip formatter
  40024. *
  40025. * @param {number} dataIndex
  40026. */
  40027. formatTooltip: function (dataIndex) {
  40028. // FIXME orignalData and data is a bit confusing
  40029. var data = this.getData();
  40030. var formattedValue = addCommas(this.getRawValue(dataIndex));
  40031. var name = data.getName(dataIndex);
  40032. var seriesGroup = this.seriesGroup;
  40033. var seriesNames = [];
  40034. for (var i = 0; i < seriesGroup.length; i++) {
  40035. var otherIndex = seriesGroup[i].originalData.indexOfName(name);
  40036. var valueDim = data.mapDimension('value');
  40037. if (!isNaN(seriesGroup[i].originalData.get(valueDim, otherIndex))) {
  40038. seriesNames.push(
  40039. encodeHTML(seriesGroup[i].name)
  40040. );
  40041. }
  40042. }
  40043. return seriesNames.join(', ') + '<br />'
  40044. + encodeHTML(name + ' : ' + formattedValue);
  40045. },
  40046. /**
  40047. * @implement
  40048. */
  40049. getTooltipPosition: function (dataIndex) {
  40050. if (dataIndex != null) {
  40051. var name = this.getData().getName(dataIndex);
  40052. var geo = this.coordinateSystem;
  40053. var region = geo.getRegion(name);
  40054. return region && geo.dataToPoint(region.center);
  40055. }
  40056. },
  40057. setZoom: function (zoom) {
  40058. this.option.zoom = zoom;
  40059. },
  40060. setCenter: function (center) {
  40061. this.option.center = center;
  40062. },
  40063. defaultOption: {
  40064. // 一级层叠
  40065. zlevel: 0,
  40066. // 二级层叠
  40067. z: 2,
  40068. coordinateSystem: 'geo',
  40069. // map should be explicitly specified since ec3.
  40070. map: '',
  40071. // If `geoIndex` is not specified, a exclusive geo will be
  40072. // created. Otherwise use the specified geo component, and
  40073. // `map` and `mapType` are ignored.
  40074. // geoIndex: 0,
  40075. // 'center' | 'left' | 'right' | 'x%' | {number}
  40076. left: 'center',
  40077. // 'center' | 'top' | 'bottom' | 'x%' | {number}
  40078. top: 'center',
  40079. // right
  40080. // bottom
  40081. // width:
  40082. // height
  40083. // Aspect is width / height. Inited to be geoJson bbox aspect
  40084. // This parameter is used for scale this aspect
  40085. aspectScale: 0.75,
  40086. ///// Layout with center and size
  40087. // If you wan't to put map in a fixed size box with right aspect ratio
  40088. // This two properties may more conveninet
  40089. // layoutCenter: [50%, 50%]
  40090. // layoutSize: 100
  40091. // 数值合并方式,默认加和,可选为:
  40092. // 'sum' | 'average' | 'max' | 'min'
  40093. // mapValueCalculation: 'sum',
  40094. // 地图数值计算结果小数精度
  40095. // mapValuePrecision: 0,
  40096. // 显示图例颜色标识(系列标识的小圆点),图例开启时有效
  40097. showLegendSymbol: true,
  40098. // 选择模式,默认关闭,可选single,multiple
  40099. // selectedMode: false,
  40100. dataRangeHoverLink: true,
  40101. // 是否开启缩放及漫游模式
  40102. // roam: false,
  40103. // Define left-top, right-bottom coords to control view
  40104. // For example, [ [180, 90], [-180, -90] ],
  40105. // higher priority than center and zoom
  40106. boundingCoords: null,
  40107. // Default on center of map
  40108. center: null,
  40109. zoom: 1,
  40110. scaleLimit: null,
  40111. label: {
  40112. show: false,
  40113. color: '#000'
  40114. },
  40115. // scaleLimit: null,
  40116. itemStyle: {
  40117. borderWidth: 0.5,
  40118. borderColor: '#444',
  40119. areaColor: '#eee'
  40120. },
  40121. emphasis: {
  40122. label: {
  40123. show: true,
  40124. color: 'rgb(100,0,0)'
  40125. },
  40126. itemStyle: {
  40127. areaColor: 'rgba(255,215,0,0.8)'
  40128. }
  40129. }
  40130. }
  40131. });
  40132. mixin(MapSeries, selectableMixin);
  40133. /*
  40134. * Licensed to the Apache Software Foundation (ASF) under one
  40135. * or more contributor license agreements. See the NOTICE file
  40136. * distributed with this work for additional information
  40137. * regarding copyright ownership. The ASF licenses this file
  40138. * to you under the Apache License, Version 2.0 (the
  40139. * "License"); you may not use this file except in compliance
  40140. * with the License. You may obtain a copy of the License at
  40141. *
  40142. * http://www.apache.org/licenses/LICENSE-2.0
  40143. *
  40144. * Unless required by applicable law or agreed to in writing,
  40145. * software distributed under the License is distributed on an
  40146. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  40147. * KIND, either express or implied. See the License for the
  40148. * specific language governing permissions and limitations
  40149. * under the License.
  40150. */
  40151. var ATTR = '\0_ec_interaction_mutex';
  40152. function take(zr, resourceKey, userKey) {
  40153. var store = getStore(zr);
  40154. store[resourceKey] = userKey;
  40155. }
  40156. function release(zr, resourceKey, userKey) {
  40157. var store = getStore(zr);
  40158. var uKey = store[resourceKey];
  40159. if (uKey === userKey) {
  40160. store[resourceKey] = null;
  40161. }
  40162. }
  40163. function isTaken(zr, resourceKey) {
  40164. return !!getStore(zr)[resourceKey];
  40165. }
  40166. function getStore(zr) {
  40167. return zr[ATTR] || (zr[ATTR] = {});
  40168. }
  40169. /**
  40170. * payload: {
  40171. * type: 'takeGlobalCursor',
  40172. * key: 'dataZoomSelect', or 'brush', or ...,
  40173. * If no userKey, release global cursor.
  40174. * }
  40175. */
  40176. registerAction(
  40177. {type: 'takeGlobalCursor', event: 'globalCursorTaken', update: 'update'},
  40178. function () {}
  40179. );
  40180. /*
  40181. * Licensed to the Apache Software Foundation (ASF) under one
  40182. * or more contributor license agreements. See the NOTICE file
  40183. * distributed with this work for additional information
  40184. * regarding copyright ownership. The ASF licenses this file
  40185. * to you under the Apache License, Version 2.0 (the
  40186. * "License"); you may not use this file except in compliance
  40187. * with the License. You may obtain a copy of the License at
  40188. *
  40189. * http://www.apache.org/licenses/LICENSE-2.0
  40190. *
  40191. * Unless required by applicable law or agreed to in writing,
  40192. * software distributed under the License is distributed on an
  40193. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  40194. * KIND, either express or implied. See the License for the
  40195. * specific language governing permissions and limitations
  40196. * under the License.
  40197. */
  40198. /**
  40199. * @alias module:echarts/component/helper/RoamController
  40200. * @constructor
  40201. * @mixin {module:zrender/mixin/Eventful}
  40202. *
  40203. * @param {module:zrender/zrender~ZRender} zr
  40204. */
  40205. function RoamController(zr) {
  40206. /**
  40207. * @type {Function}
  40208. */
  40209. this.pointerChecker;
  40210. /**
  40211. * @type {module:zrender}
  40212. */
  40213. this._zr = zr;
  40214. /**
  40215. * @type {Object}
  40216. */
  40217. this._opt = {};
  40218. // Avoid two roamController bind the same handler
  40219. var bind$$1 = bind;
  40220. var mousedownHandler = bind$$1(mousedown, this);
  40221. var mousemoveHandler = bind$$1(mousemove, this);
  40222. var mouseupHandler = bind$$1(mouseup, this);
  40223. var mousewheelHandler = bind$$1(mousewheel, this);
  40224. var pinchHandler = bind$$1(pinch, this);
  40225. Eventful.call(this);
  40226. /**
  40227. * @param {Function} pointerChecker
  40228. * input: x, y
  40229. * output: boolean
  40230. */
  40231. this.setPointerChecker = function (pointerChecker) {
  40232. this.pointerChecker = pointerChecker;
  40233. };
  40234. /**
  40235. * Notice: only enable needed types. For example, if 'zoom'
  40236. * is not needed, 'zoom' should not be enabled, otherwise
  40237. * default mousewheel behaviour (scroll page) will be disabled.
  40238. *
  40239. * @param {boolean|string} [controlType=true] Specify the control type,
  40240. * which can be null/undefined or true/false
  40241. * or 'pan/move' or 'zoom'/'scale'
  40242. * @param {Object} [opt]
  40243. * @param {Object} [opt.zoomOnMouseWheel=true] The value can be: true / false / 'shift' / 'ctrl' / 'alt'.
  40244. * @param {Object} [opt.moveOnMouseMove=true] The value can be: true / false / 'shift' / 'ctrl' / 'alt'.
  40245. * @param {Object} [opt.moveOnMouseWheel=false] The value can be: true / false / 'shift' / 'ctrl' / 'alt'.
  40246. * @param {Object} [opt.preventDefaultMouseMove=true] When pan.
  40247. */
  40248. this.enable = function (controlType, opt) {
  40249. // Disable previous first
  40250. this.disable();
  40251. this._opt = defaults(clone(opt) || {}, {
  40252. zoomOnMouseWheel: true,
  40253. moveOnMouseMove: true,
  40254. // By default, wheel do not trigger move.
  40255. moveOnMouseWheel: false,
  40256. preventDefaultMouseMove: true
  40257. });
  40258. if (controlType == null) {
  40259. controlType = true;
  40260. }
  40261. if (controlType === true || (controlType === 'move' || controlType === 'pan')) {
  40262. zr.on('mousedown', mousedownHandler);
  40263. zr.on('mousemove', mousemoveHandler);
  40264. zr.on('mouseup', mouseupHandler);
  40265. }
  40266. if (controlType === true || (controlType === 'scale' || controlType === 'zoom')) {
  40267. zr.on('mousewheel', mousewheelHandler);
  40268. zr.on('pinch', pinchHandler);
  40269. }
  40270. };
  40271. this.disable = function () {
  40272. zr.off('mousedown', mousedownHandler);
  40273. zr.off('mousemove', mousemoveHandler);
  40274. zr.off('mouseup', mouseupHandler);
  40275. zr.off('mousewheel', mousewheelHandler);
  40276. zr.off('pinch', pinchHandler);
  40277. };
  40278. this.dispose = this.disable;
  40279. this.isDragging = function () {
  40280. return this._dragging;
  40281. };
  40282. this.isPinching = function () {
  40283. return this._pinching;
  40284. };
  40285. }
  40286. mixin(RoamController, Eventful);
  40287. function mousedown(e) {
  40288. if (isMiddleOrRightButtonOnMouseUpDown(e)
  40289. || (e.target && e.target.draggable)
  40290. ) {
  40291. return;
  40292. }
  40293. var x = e.offsetX;
  40294. var y = e.offsetY;
  40295. // Only check on mosedown, but not mousemove.
  40296. // Mouse can be out of target when mouse moving.
  40297. if (this.pointerChecker && this.pointerChecker(e, x, y)) {
  40298. this._x = x;
  40299. this._y = y;
  40300. this._dragging = true;
  40301. }
  40302. }
  40303. function mousemove(e) {
  40304. if (!this._dragging
  40305. || !isAvailableBehavior('moveOnMouseMove', e, this._opt)
  40306. || e.gestureEvent === 'pinch'
  40307. || isTaken(this._zr, 'globalPan')
  40308. ) {
  40309. return;
  40310. }
  40311. var x = e.offsetX;
  40312. var y = e.offsetY;
  40313. var oldX = this._x;
  40314. var oldY = this._y;
  40315. var dx = x - oldX;
  40316. var dy = y - oldY;
  40317. this._x = x;
  40318. this._y = y;
  40319. this._opt.preventDefaultMouseMove && stop(e.event);
  40320. trigger(this, 'pan', 'moveOnMouseMove', e, {
  40321. dx: dx, dy: dy, oldX: oldX, oldY: oldY, newX: x, newY: y
  40322. });
  40323. }
  40324. function mouseup(e) {
  40325. if (!isMiddleOrRightButtonOnMouseUpDown(e)) {
  40326. this._dragging = false;
  40327. }
  40328. }
  40329. function mousewheel(e) {
  40330. var shouldZoom = isAvailableBehavior('zoomOnMouseWheel', e, this._opt);
  40331. var shouldMove = isAvailableBehavior('moveOnMouseWheel', e, this._opt);
  40332. var wheelDelta = e.wheelDelta;
  40333. var absWheelDeltaDelta = Math.abs(wheelDelta);
  40334. var originX = e.offsetX;
  40335. var originY = e.offsetY;
  40336. // wheelDelta maybe -0 in chrome mac.
  40337. if (wheelDelta === 0 || (!shouldZoom && !shouldMove)) {
  40338. return;
  40339. }
  40340. // If both `shouldZoom` and `shouldMove` is true, trigger
  40341. // their event both, and the final behavior is determined
  40342. // by event listener themselves.
  40343. if (shouldZoom) {
  40344. // Convenience:
  40345. // Mac and VM Windows on Mac: scroll up: zoom out.
  40346. // Windows: scroll up: zoom in.
  40347. // FIXME: Should do more test in different environment.
  40348. // wheelDelta is too complicated in difference nvironment
  40349. // (https://developer.mozilla.org/en-US/docs/Web/Events/mousewheel),
  40350. // although it has been normallized by zrender.
  40351. // wheelDelta of mouse wheel is bigger than touch pad.
  40352. var factor = absWheelDeltaDelta > 3 ? 1.4 : absWheelDeltaDelta > 1 ? 1.2 : 1.1;
  40353. var scale = wheelDelta > 0 ? factor : 1 / factor;
  40354. checkPointerAndTrigger(this, 'zoom', 'zoomOnMouseWheel', e, {
  40355. scale: scale, originX: originX, originY: originY
  40356. });
  40357. }
  40358. if (shouldMove) {
  40359. // FIXME: Should do more test in different environment.
  40360. var absDelta = Math.abs(wheelDelta);
  40361. // wheelDelta of mouse wheel is bigger than touch pad.
  40362. var scrollDelta = (wheelDelta > 0 ? 1 : -1) * (absDelta > 3 ? 0.4 : absDelta > 1 ? 0.15 : 0.05);
  40363. checkPointerAndTrigger(this, 'scrollMove', 'moveOnMouseWheel', e, {
  40364. scrollDelta: scrollDelta, originX: originX, originY: originY
  40365. });
  40366. }
  40367. }
  40368. function pinch(e) {
  40369. if (isTaken(this._zr, 'globalPan')) {
  40370. return;
  40371. }
  40372. var scale = e.pinchScale > 1 ? 1.1 : 1 / 1.1;
  40373. checkPointerAndTrigger(this, 'zoom', null, e, {
  40374. scale: scale, originX: e.pinchX, originY: e.pinchY
  40375. });
  40376. }
  40377. function checkPointerAndTrigger(controller, eventName, behaviorToCheck, e, contollerEvent) {
  40378. if (controller.pointerChecker
  40379. && controller.pointerChecker(e, contollerEvent.originX, contollerEvent.originY)
  40380. ) {
  40381. // When mouse is out of roamController rect,
  40382. // default befavoius should not be be disabled, otherwise
  40383. // page sliding is disabled, contrary to expectation.
  40384. stop(e.event);
  40385. trigger(controller, eventName, behaviorToCheck, e, contollerEvent);
  40386. }
  40387. }
  40388. function trigger(controller, eventName, behaviorToCheck, e, contollerEvent) {
  40389. // Also provide behavior checker for event listener, for some case that
  40390. // multiple components share one listener.
  40391. contollerEvent.isAvailableBehavior = bind(isAvailableBehavior, null, behaviorToCheck, e);
  40392. controller.trigger(eventName, contollerEvent);
  40393. }
  40394. // settings: {
  40395. // zoomOnMouseWheel
  40396. // moveOnMouseMove
  40397. // moveOnMouseWheel
  40398. // }
  40399. // The value can be: true / false / 'shift' / 'ctrl' / 'alt'.
  40400. function isAvailableBehavior(behaviorToCheck, e, settings) {
  40401. var setting = settings[behaviorToCheck];
  40402. return !behaviorToCheck || (
  40403. setting && (!isString(setting) || e.event[setting + 'Key'])
  40404. );
  40405. }
  40406. /*
  40407. * Licensed to the Apache Software Foundation (ASF) under one
  40408. * or more contributor license agreements. See the NOTICE file
  40409. * distributed with this work for additional information
  40410. * regarding copyright ownership. The ASF licenses this file
  40411. * to you under the Apache License, Version 2.0 (the
  40412. * "License"); you may not use this file except in compliance
  40413. * with the License. You may obtain a copy of the License at
  40414. *
  40415. * http://www.apache.org/licenses/LICENSE-2.0
  40416. *
  40417. * Unless required by applicable law or agreed to in writing,
  40418. * software distributed under the License is distributed on an
  40419. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  40420. * KIND, either express or implied. See the License for the
  40421. * specific language governing permissions and limitations
  40422. * under the License.
  40423. */
  40424. /**
  40425. * For geo and graph.
  40426. *
  40427. * @param {Object} controllerHost
  40428. * @param {module:zrender/Element} controllerHost.target
  40429. */
  40430. function updateViewOnPan(controllerHost, dx, dy) {
  40431. var target = controllerHost.target;
  40432. var pos = target.position;
  40433. pos[0] += dx;
  40434. pos[1] += dy;
  40435. target.dirty();
  40436. }
  40437. /**
  40438. * For geo and graph.
  40439. *
  40440. * @param {Object} controllerHost
  40441. * @param {module:zrender/Element} controllerHost.target
  40442. * @param {number} controllerHost.zoom
  40443. * @param {number} controllerHost.zoomLimit like: {min: 1, max: 2}
  40444. */
  40445. function updateViewOnZoom(controllerHost, zoomDelta, zoomX, zoomY) {
  40446. var target = controllerHost.target;
  40447. var zoomLimit = controllerHost.zoomLimit;
  40448. var pos = target.position;
  40449. var scale = target.scale;
  40450. var newZoom = controllerHost.zoom = controllerHost.zoom || 1;
  40451. newZoom *= zoomDelta;
  40452. if (zoomLimit) {
  40453. var zoomMin = zoomLimit.min || 0;
  40454. var zoomMax = zoomLimit.max || Infinity;
  40455. newZoom = Math.max(
  40456. Math.min(zoomMax, newZoom),
  40457. zoomMin
  40458. );
  40459. }
  40460. var zoomScale = newZoom / controllerHost.zoom;
  40461. controllerHost.zoom = newZoom;
  40462. // Keep the mouse center when scaling
  40463. pos[0] -= (zoomX - pos[0]) * (zoomScale - 1);
  40464. pos[1] -= (zoomY - pos[1]) * (zoomScale - 1);
  40465. scale[0] *= zoomScale;
  40466. scale[1] *= zoomScale;
  40467. target.dirty();
  40468. }
  40469. /*
  40470. * Licensed to the Apache Software Foundation (ASF) under one
  40471. * or more contributor license agreements. See the NOTICE file
  40472. * distributed with this work for additional information
  40473. * regarding copyright ownership. The ASF licenses this file
  40474. * to you under the Apache License, Version 2.0 (the
  40475. * "License"); you may not use this file except in compliance
  40476. * with the License. You may obtain a copy of the License at
  40477. *
  40478. * http://www.apache.org/licenses/LICENSE-2.0
  40479. *
  40480. * Unless required by applicable law or agreed to in writing,
  40481. * software distributed under the License is distributed on an
  40482. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  40483. * KIND, either express or implied. See the License for the
  40484. * specific language governing permissions and limitations
  40485. * under the License.
  40486. */
  40487. var IRRELEVANT_EXCLUDES = {'axisPointer': 1, 'tooltip': 1, 'brush': 1};
  40488. /**
  40489. * Avoid that: mouse click on a elements that is over geo or graph,
  40490. * but roam is triggered.
  40491. */
  40492. function onIrrelevantElement(e, api, targetCoordSysModel) {
  40493. var model = api.getComponentByElement(e.topTarget);
  40494. // If model is axisModel, it works only if it is injected with coordinateSystem.
  40495. var coordSys = model && model.coordinateSystem;
  40496. return model
  40497. && model !== targetCoordSysModel
  40498. && !IRRELEVANT_EXCLUDES[model.mainType]
  40499. && (coordSys && coordSys.model !== targetCoordSysModel);
  40500. }
  40501. /*
  40502. * Licensed to the Apache Software Foundation (ASF) under one
  40503. * or more contributor license agreements. See the NOTICE file
  40504. * distributed with this work for additional information
  40505. * regarding copyright ownership. The ASF licenses this file
  40506. * to you under the Apache License, Version 2.0 (the
  40507. * "License"); you may not use this file except in compliance
  40508. * with the License. You may obtain a copy of the License at
  40509. *
  40510. * http://www.apache.org/licenses/LICENSE-2.0
  40511. *
  40512. * Unless required by applicable law or agreed to in writing,
  40513. * software distributed under the License is distributed on an
  40514. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  40515. * KIND, either express or implied. See the License for the
  40516. * specific language governing permissions and limitations
  40517. * under the License.
  40518. */
  40519. function getFixedItemStyle(model, scale) {
  40520. var itemStyle = model.getItemStyle();
  40521. var areaColor = model.get('areaColor');
  40522. // If user want the color not to be changed when hover,
  40523. // they should both set areaColor and color to be null.
  40524. if (areaColor != null) {
  40525. itemStyle.fill = areaColor;
  40526. }
  40527. return itemStyle;
  40528. }
  40529. function updateMapSelectHandler(mapDraw, mapOrGeoModel, regionsGroup, api, fromView) {
  40530. regionsGroup.off('click');
  40531. regionsGroup.off('mousedown');
  40532. if (mapOrGeoModel.get('selectedMode')) {
  40533. regionsGroup.on('mousedown', function () {
  40534. mapDraw._mouseDownFlag = true;
  40535. });
  40536. regionsGroup.on('click', function (e) {
  40537. if (!mapDraw._mouseDownFlag) {
  40538. return;
  40539. }
  40540. mapDraw._mouseDownFlag = false;
  40541. var el = e.target;
  40542. while (!el.__regions) {
  40543. el = el.parent;
  40544. }
  40545. if (!el) {
  40546. return;
  40547. }
  40548. var action = {
  40549. type: (mapOrGeoModel.mainType === 'geo' ? 'geo' : 'map') + 'ToggleSelect',
  40550. batch: map(el.__regions, function (region) {
  40551. return {
  40552. name: region.name,
  40553. from: fromView.uid
  40554. };
  40555. })
  40556. };
  40557. action[mapOrGeoModel.mainType + 'Id'] = mapOrGeoModel.id;
  40558. api.dispatchAction(action);
  40559. updateMapSelected(mapOrGeoModel, regionsGroup);
  40560. });
  40561. }
  40562. }
  40563. function updateMapSelected(mapOrGeoModel, regionsGroup) {
  40564. // FIXME
  40565. regionsGroup.eachChild(function (otherRegionEl) {
  40566. each$1(otherRegionEl.__regions, function (region) {
  40567. otherRegionEl.trigger(mapOrGeoModel.isSelected(region.name) ? 'emphasis' : 'normal');
  40568. });
  40569. });
  40570. }
  40571. /**
  40572. * @alias module:echarts/component/helper/MapDraw
  40573. * @param {module:echarts/ExtensionAPI} api
  40574. * @param {boolean} updateGroup
  40575. */
  40576. function MapDraw(api, updateGroup) {
  40577. var group = new Group();
  40578. /**
  40579. * @type {string}
  40580. * @private
  40581. */
  40582. this.uid = getUID('ec_map_draw');
  40583. /**
  40584. * @type {module:echarts/component/helper/RoamController}
  40585. * @private
  40586. */
  40587. this._controller = new RoamController(api.getZr());
  40588. /**
  40589. * @type {Object} {target, zoom, zoomLimit}
  40590. * @private
  40591. */
  40592. this._controllerHost = {target: updateGroup ? group : null};
  40593. /**
  40594. * @type {module:zrender/container/Group}
  40595. * @readOnly
  40596. */
  40597. this.group = group;
  40598. /**
  40599. * @type {boolean}
  40600. * @private
  40601. */
  40602. this._updateGroup = updateGroup;
  40603. /**
  40604. * This flag is used to make sure that only one among
  40605. * `pan`, `zoom`, `click` can occurs, otherwise 'selected'
  40606. * action may be triggered when `pan`, which is unexpected.
  40607. * @type {booelan}
  40608. */
  40609. this._mouseDownFlag;
  40610. /**
  40611. * @type {string}
  40612. */
  40613. this._mapName;
  40614. /**
  40615. * @type {boolean}
  40616. */
  40617. this._initialized;
  40618. /**
  40619. * @type {module:zrender/container/Group}
  40620. */
  40621. group.add(this._regionsGroup = new Group());
  40622. /**
  40623. * @type {module:zrender/container/Group}
  40624. */
  40625. group.add(this._backgroundGroup = new Group());
  40626. }
  40627. MapDraw.prototype = {
  40628. constructor: MapDraw,
  40629. draw: function (mapOrGeoModel, ecModel, api, fromView, payload) {
  40630. var isGeo = mapOrGeoModel.mainType === 'geo';
  40631. // Map series has data. GEO model that controlled by map series
  40632. // will be assigned with map data. Other GEO model has no data.
  40633. var data = mapOrGeoModel.getData && mapOrGeoModel.getData();
  40634. isGeo && ecModel.eachComponent({mainType: 'series', subType: 'map'}, function (mapSeries) {
  40635. if (!data && mapSeries.getHostGeoModel() === mapOrGeoModel) {
  40636. data = mapSeries.getData();
  40637. }
  40638. });
  40639. var geo = mapOrGeoModel.coordinateSystem;
  40640. this._updateBackground(geo);
  40641. var regionsGroup = this._regionsGroup;
  40642. var group = this.group;
  40643. var scale = geo.scale;
  40644. var transform = {
  40645. position: geo.position,
  40646. scale: scale
  40647. };
  40648. // No animation when first draw or in action
  40649. if (!regionsGroup.childAt(0) || payload) {
  40650. group.attr(transform);
  40651. }
  40652. else {
  40653. updateProps(group, transform, mapOrGeoModel);
  40654. }
  40655. regionsGroup.removeAll();
  40656. var itemStyleAccessPath = ['itemStyle'];
  40657. var hoverItemStyleAccessPath = ['emphasis', 'itemStyle'];
  40658. var labelAccessPath = ['label'];
  40659. var hoverLabelAccessPath = ['emphasis', 'label'];
  40660. var nameMap = createHashMap();
  40661. each$1(geo.regions, function (region) {
  40662. // Consider in GeoJson properties.name may be duplicated, for example,
  40663. // there is multiple region named "United Kindom" or "France" (so many
  40664. // colonies). And it is not appropriate to merge them in geo, which
  40665. // will make them share the same label and bring trouble in label
  40666. // location calculation.
  40667. var regionGroup = nameMap.get(region.name)
  40668. || nameMap.set(region.name, new Group());
  40669. var compoundPath = new CompoundPath({
  40670. segmentIgnoreThreshold: 1,
  40671. shape: {
  40672. paths: []
  40673. }
  40674. });
  40675. regionGroup.add(compoundPath);
  40676. var regionModel = mapOrGeoModel.getRegionModel(region.name) || mapOrGeoModel;
  40677. var itemStyleModel = regionModel.getModel(itemStyleAccessPath);
  40678. var hoverItemStyleModel = regionModel.getModel(hoverItemStyleAccessPath);
  40679. var itemStyle = getFixedItemStyle(itemStyleModel, scale);
  40680. var hoverItemStyle = getFixedItemStyle(hoverItemStyleModel, scale);
  40681. var labelModel = regionModel.getModel(labelAccessPath);
  40682. var hoverLabelModel = regionModel.getModel(hoverLabelAccessPath);
  40683. var dataIdx;
  40684. // Use the itemStyle in data if has data
  40685. if (data) {
  40686. dataIdx = data.indexOfName(region.name);
  40687. // Only visual color of each item will be used. It can be encoded by dataRange
  40688. // But visual color of series is used in symbol drawing
  40689. //
  40690. // Visual color for each series is for the symbol draw
  40691. var visualColor = data.getItemVisual(dataIdx, 'color', true);
  40692. if (visualColor) {
  40693. itemStyle.fill = visualColor;
  40694. }
  40695. }
  40696. each$1(region.geometries, function (geometry) {
  40697. if (geometry.type !== 'polygon') {
  40698. return;
  40699. }
  40700. compoundPath.shape.paths.push(new Polygon({
  40701. segmentIgnoreThreshold: 1,
  40702. shape: {
  40703. points: geometry.exterior
  40704. }
  40705. }));
  40706. for (var i = 0; i < (geometry.interiors ? geometry.interiors.length : 0); i++) {
  40707. compoundPath.shape.paths.push(new Polygon({
  40708. segmentIgnoreThreshold: 1,
  40709. shape: {
  40710. points: geometry.interiors[i]
  40711. }
  40712. }));
  40713. }
  40714. });
  40715. compoundPath.setStyle(itemStyle);
  40716. compoundPath.style.strokeNoScale = true;
  40717. compoundPath.culling = true;
  40718. // Label
  40719. var showLabel = labelModel.get('show');
  40720. var hoverShowLabel = hoverLabelModel.get('show');
  40721. var isDataNaN = data && isNaN(data.get(data.mapDimension('value'), dataIdx));
  40722. var itemLayout = data && data.getItemLayout(dataIdx);
  40723. // In the following cases label will be drawn
  40724. // 1. In map series and data value is NaN
  40725. // 2. In geo component
  40726. // 4. Region has no series legendSymbol, which will be add a showLabel flag in mapSymbolLayout
  40727. if (
  40728. (isGeo || isDataNaN && (showLabel || hoverShowLabel))
  40729. || (itemLayout && itemLayout.showLabel)
  40730. ) {
  40731. var query = !isGeo ? dataIdx : region.name;
  40732. var labelFetcher;
  40733. // Consider dataIdx not found.
  40734. if (!data || dataIdx >= 0) {
  40735. labelFetcher = mapOrGeoModel;
  40736. }
  40737. var textEl = new Text({
  40738. position: region.center.slice(),
  40739. // FIXME
  40740. // label rotation is not support yet in geo or regions of series-map
  40741. // that has no data. The rotation will be effected by this `scale`.
  40742. // So needed to change to RectText?
  40743. scale: [1 / scale[0], 1 / scale[1]],
  40744. z2: 10,
  40745. silent: true
  40746. });
  40747. setLabelStyle(
  40748. textEl.style, textEl.hoverStyle = {}, labelModel, hoverLabelModel,
  40749. {
  40750. labelFetcher: labelFetcher,
  40751. labelDataIndex: query,
  40752. defaultText: region.name,
  40753. useInsideStyle: false
  40754. },
  40755. {
  40756. textAlign: 'center',
  40757. textVerticalAlign: 'middle'
  40758. }
  40759. );
  40760. regionGroup.add(textEl);
  40761. }
  40762. // setItemGraphicEl, setHoverStyle after all polygons and labels
  40763. // are added to the rigionGroup
  40764. if (data) {
  40765. data.setItemGraphicEl(dataIdx, regionGroup);
  40766. }
  40767. else {
  40768. var regionModel = mapOrGeoModel.getRegionModel(region.name);
  40769. // Package custom mouse event for geo component
  40770. compoundPath.eventData = {
  40771. componentType: 'geo',
  40772. componentIndex: mapOrGeoModel.componentIndex,
  40773. geoIndex: mapOrGeoModel.componentIndex,
  40774. name: region.name,
  40775. region: (regionModel && regionModel.option) || {}
  40776. };
  40777. }
  40778. var groupRegions = regionGroup.__regions || (regionGroup.__regions = []);
  40779. groupRegions.push(region);
  40780. regionGroup.highDownSilentOnTouch = !!mapOrGeoModel.get('selectedMode');
  40781. setHoverStyle(regionGroup, hoverItemStyle);
  40782. regionsGroup.add(regionGroup);
  40783. });
  40784. this._updateController(mapOrGeoModel, ecModel, api);
  40785. updateMapSelectHandler(this, mapOrGeoModel, regionsGroup, api, fromView);
  40786. updateMapSelected(mapOrGeoModel, regionsGroup);
  40787. },
  40788. remove: function () {
  40789. this._regionsGroup.removeAll();
  40790. this._backgroundGroup.removeAll();
  40791. this._controller.dispose();
  40792. this._mapName && geoSourceManager.removeGraphic(this._mapName, this.uid);
  40793. this._mapName = null;
  40794. this._controllerHost = {};
  40795. },
  40796. _updateBackground: function (geo) {
  40797. var mapName = geo.map;
  40798. if (this._mapName !== mapName) {
  40799. each$1(geoSourceManager.makeGraphic(mapName, this.uid), function (root) {
  40800. this._backgroundGroup.add(root);
  40801. }, this);
  40802. }
  40803. this._mapName = mapName;
  40804. },
  40805. _updateController: function (mapOrGeoModel, ecModel, api) {
  40806. var geo = mapOrGeoModel.coordinateSystem;
  40807. var controller = this._controller;
  40808. var controllerHost = this._controllerHost;
  40809. controllerHost.zoomLimit = mapOrGeoModel.get('scaleLimit');
  40810. controllerHost.zoom = geo.getZoom();
  40811. // roamType is will be set default true if it is null
  40812. controller.enable(mapOrGeoModel.get('roam') || false);
  40813. var mainType = mapOrGeoModel.mainType;
  40814. function makeActionBase() {
  40815. var action = {
  40816. type: 'geoRoam',
  40817. componentType: mainType
  40818. };
  40819. action[mainType + 'Id'] = mapOrGeoModel.id;
  40820. return action;
  40821. }
  40822. controller.off('pan').on('pan', function (e) {
  40823. this._mouseDownFlag = false;
  40824. updateViewOnPan(controllerHost, e.dx, e.dy);
  40825. api.dispatchAction(extend(makeActionBase(), {
  40826. dx: e.dx,
  40827. dy: e.dy
  40828. }));
  40829. }, this);
  40830. controller.off('zoom').on('zoom', function (e) {
  40831. this._mouseDownFlag = false;
  40832. updateViewOnZoom(controllerHost, e.scale, e.originX, e.originY);
  40833. api.dispatchAction(extend(makeActionBase(), {
  40834. zoom: e.scale,
  40835. originX: e.originX,
  40836. originY: e.originY
  40837. }));
  40838. if (this._updateGroup) {
  40839. var scale = this.group.scale;
  40840. this._regionsGroup.traverse(function (el) {
  40841. if (el.type === 'text') {
  40842. el.attr('scale', [1 / scale[0], 1 / scale[1]]);
  40843. }
  40844. });
  40845. }
  40846. }, this);
  40847. controller.setPointerChecker(function (e, x, y) {
  40848. return geo.getViewRectAfterRoam().contain(x, y)
  40849. && !onIrrelevantElement(e, api, mapOrGeoModel);
  40850. });
  40851. }
  40852. };
  40853. /*
  40854. * Licensed to the Apache Software Foundation (ASF) under one
  40855. * or more contributor license agreements. See the NOTICE file
  40856. * distributed with this work for additional information
  40857. * regarding copyright ownership. The ASF licenses this file
  40858. * to you under the Apache License, Version 2.0 (the
  40859. * "License"); you may not use this file except in compliance
  40860. * with the License. You may obtain a copy of the License at
  40861. *
  40862. * http://www.apache.org/licenses/LICENSE-2.0
  40863. *
  40864. * Unless required by applicable law or agreed to in writing,
  40865. * software distributed under the License is distributed on an
  40866. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  40867. * KIND, either express or implied. See the License for the
  40868. * specific language governing permissions and limitations
  40869. * under the License.
  40870. */
  40871. var HIGH_DOWN_PROP = '__seriesMapHighDown';
  40872. var RECORD_VERSION_PROP = '__seriesMapCallKey';
  40873. extendChartView({
  40874. type: 'map',
  40875. render: function (mapModel, ecModel, api, payload) {
  40876. // Not render if it is an toggleSelect action from self
  40877. if (payload && payload.type === 'mapToggleSelect'
  40878. && payload.from === this.uid
  40879. ) {
  40880. return;
  40881. }
  40882. var group = this.group;
  40883. group.removeAll();
  40884. if (mapModel.getHostGeoModel()) {
  40885. return;
  40886. }
  40887. // Not update map if it is an roam action from self
  40888. if (!(payload && payload.type === 'geoRoam'
  40889. && payload.componentType === 'series'
  40890. && payload.seriesId === mapModel.id
  40891. )
  40892. ) {
  40893. if (mapModel.needsDrawMap) {
  40894. var mapDraw = this._mapDraw || new MapDraw(api, true);
  40895. group.add(mapDraw.group);
  40896. mapDraw.draw(mapModel, ecModel, api, this, payload);
  40897. this._mapDraw = mapDraw;
  40898. }
  40899. else {
  40900. // Remove drawed map
  40901. this._mapDraw && this._mapDraw.remove();
  40902. this._mapDraw = null;
  40903. }
  40904. }
  40905. else {
  40906. var mapDraw = this._mapDraw;
  40907. mapDraw && group.add(mapDraw.group);
  40908. }
  40909. mapModel.get('showLegendSymbol') && ecModel.getComponent('legend')
  40910. && this._renderSymbols(mapModel, ecModel, api);
  40911. },
  40912. remove: function () {
  40913. this._mapDraw && this._mapDraw.remove();
  40914. this._mapDraw = null;
  40915. this.group.removeAll();
  40916. },
  40917. dispose: function () {
  40918. this._mapDraw && this._mapDraw.remove();
  40919. this._mapDraw = null;
  40920. },
  40921. _renderSymbols: function (mapModel, ecModel, api) {
  40922. var originalData = mapModel.originalData;
  40923. var group = this.group;
  40924. originalData.each(originalData.mapDimension('value'), function (value, originalDataIndex) {
  40925. if (isNaN(value)) {
  40926. return;
  40927. }
  40928. var layout = originalData.getItemLayout(originalDataIndex);
  40929. if (!layout || !layout.point) {
  40930. // Not exists in map
  40931. return;
  40932. }
  40933. var point = layout.point;
  40934. var offset = layout.offset;
  40935. var circle = new Circle({
  40936. style: {
  40937. // Because the special of map draw.
  40938. // Which needs statistic of multiple series and draw on one map.
  40939. // And each series also need a symbol with legend color
  40940. //
  40941. // Layout and visual are put one the different data
  40942. fill: mapModel.getData().getVisual('color')
  40943. },
  40944. shape: {
  40945. cx: point[0] + offset * 9,
  40946. cy: point[1],
  40947. r: 3
  40948. },
  40949. silent: true,
  40950. // Do not overlap the first series, on which labels are displayed.
  40951. z2: 8 + (!offset ? Z2_EMPHASIS_LIFT + 1 : 0)
  40952. });
  40953. // Only the series that has the first value on the same region is in charge of rendering the label.
  40954. // But consider the case:
  40955. // series: [
  40956. // {id: 'X', type: 'map', map: 'm', {data: [{name: 'A', value: 11}, {name: 'B', {value: 22}]},
  40957. // {id: 'Y', type: 'map', map: 'm', {data: [{name: 'A', value: 21}, {name: 'C', {value: 33}]}
  40958. // ]
  40959. // The offset `0` of item `A` is at series `X`, but of item `C` is at series `Y`.
  40960. // For backward compatibility, we follow the rule that render label `A` by the
  40961. // settings on series `X` but render label `C` by the settings on series `Y`.
  40962. if (!offset) {
  40963. var fullData = mapModel.mainSeries.getData();
  40964. var name = originalData.getName(originalDataIndex);
  40965. var fullIndex = fullData.indexOfName(name);
  40966. var itemModel = originalData.getItemModel(originalDataIndex);
  40967. var labelModel = itemModel.getModel('label');
  40968. var hoverLabelModel = itemModel.getModel('emphasis.label');
  40969. var regionGroup = fullData.getItemGraphicEl(fullIndex);
  40970. // `getFormattedLabel` needs to use `getData` inside. Here
  40971. // `mapModel.getData()` is shallow cloned from `mainSeries.getData()`.
  40972. // FIXME
  40973. // If this is not the `mainSeries`, the item model (like label formatter)
  40974. // set on original data item will never get. But it has been working
  40975. // like that from the begining, and this scenario is rarely encountered.
  40976. // So it won't be fixed until have to.
  40977. var normalText = retrieve2(
  40978. mapModel.getFormattedLabel(fullIndex, 'normal'),
  40979. name
  40980. );
  40981. var emphasisText = retrieve2(
  40982. mapModel.getFormattedLabel(fullIndex, 'emphasis'),
  40983. normalText
  40984. );
  40985. var highDownRecord = regionGroup[HIGH_DOWN_PROP];
  40986. var recordVersion = Math.random();
  40987. // Prevent from register listeners duplicatedly when roaming.
  40988. if (!highDownRecord) {
  40989. highDownRecord = regionGroup[HIGH_DOWN_PROP] = {};
  40990. var onEmphasis = curry(onRegionHighDown, true);
  40991. var onNormal = curry(onRegionHighDown, false);
  40992. regionGroup.on('mouseover', onEmphasis)
  40993. .on('mouseout', onNormal)
  40994. .on('emphasis', onEmphasis)
  40995. .on('normal', onNormal);
  40996. }
  40997. // Prevent removed regions effect current grapics.
  40998. regionGroup[RECORD_VERSION_PROP] = recordVersion;
  40999. extend(highDownRecord, {
  41000. recordVersion: recordVersion,
  41001. circle: circle,
  41002. labelModel: labelModel,
  41003. hoverLabelModel: hoverLabelModel,
  41004. emphasisText: emphasisText,
  41005. normalText: normalText
  41006. });
  41007. // FIXME
  41008. // Consider set option when emphasis.
  41009. enterRegionHighDown(highDownRecord, false);
  41010. }
  41011. group.add(circle);
  41012. });
  41013. }
  41014. });
  41015. function onRegionHighDown(toHighOrDown) {
  41016. var highDownRecord = this[HIGH_DOWN_PROP];
  41017. if (highDownRecord && highDownRecord.recordVersion === this[RECORD_VERSION_PROP]) {
  41018. enterRegionHighDown(highDownRecord, toHighOrDown);
  41019. }
  41020. }
  41021. function enterRegionHighDown(highDownRecord, toHighOrDown) {
  41022. var circle = highDownRecord.circle;
  41023. var labelModel = highDownRecord.labelModel;
  41024. var hoverLabelModel = highDownRecord.hoverLabelModel;
  41025. var emphasisText = highDownRecord.emphasisText;
  41026. var normalText = highDownRecord.normalText;
  41027. if (toHighOrDown) {
  41028. circle.style.extendFrom(
  41029. setTextStyle({}, hoverLabelModel, {
  41030. text: hoverLabelModel.get('show') ? emphasisText : null
  41031. }, {isRectText: true, useInsideStyle: false}, true)
  41032. );
  41033. // Make label upper than others if overlaps.
  41034. circle.__mapOriginalZ2 = circle.z2;
  41035. circle.z2 += Z2_EMPHASIS_LIFT;
  41036. }
  41037. else {
  41038. setTextStyle(circle.style, labelModel, {
  41039. text: labelModel.get('show') ? normalText : null,
  41040. textPosition: labelModel.getShallow('position') || 'bottom'
  41041. }, {isRectText: true, useInsideStyle: false});
  41042. // Trigger normalize style like padding.
  41043. circle.dirty(false);
  41044. if (circle.__mapOriginalZ2 != null) {
  41045. circle.z2 = circle.__mapOriginalZ2;
  41046. circle.__mapOriginalZ2 = null;
  41047. }
  41048. }
  41049. }
  41050. /*
  41051. * Licensed to the Apache Software Foundation (ASF) under one
  41052. * or more contributor license agreements. See the NOTICE file
  41053. * distributed with this work for additional information
  41054. * regarding copyright ownership. The ASF licenses this file
  41055. * to you under the Apache License, Version 2.0 (the
  41056. * "License"); you may not use this file except in compliance
  41057. * with the License. You may obtain a copy of the License at
  41058. *
  41059. * http://www.apache.org/licenses/LICENSE-2.0
  41060. *
  41061. * Unless required by applicable law or agreed to in writing,
  41062. * software distributed under the License is distributed on an
  41063. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  41064. * KIND, either express or implied. See the License for the
  41065. * specific language governing permissions and limitations
  41066. * under the License.
  41067. */
  41068. /**
  41069. * @param {module:echarts/coord/View} view
  41070. * @param {Object} payload
  41071. * @param {Object} [zoomLimit]
  41072. */
  41073. function updateCenterAndZoom(
  41074. view, payload, zoomLimit
  41075. ) {
  41076. var previousZoom = view.getZoom();
  41077. var center = view.getCenter();
  41078. var zoom = payload.zoom;
  41079. var point = view.dataToPoint(center);
  41080. if (payload.dx != null && payload.dy != null) {
  41081. point[0] -= payload.dx;
  41082. point[1] -= payload.dy;
  41083. var center = view.pointToData(point);
  41084. view.setCenter(center);
  41085. }
  41086. if (zoom != null) {
  41087. if (zoomLimit) {
  41088. var zoomMin = zoomLimit.min || 0;
  41089. var zoomMax = zoomLimit.max || Infinity;
  41090. zoom = Math.max(
  41091. Math.min(previousZoom * zoom, zoomMax),
  41092. zoomMin
  41093. ) / previousZoom;
  41094. }
  41095. // Zoom on given point(originX, originY)
  41096. view.scale[0] *= zoom;
  41097. view.scale[1] *= zoom;
  41098. var position = view.position;
  41099. var fixX = (payload.originX - position[0]) * (zoom - 1);
  41100. var fixY = (payload.originY - position[1]) * (zoom - 1);
  41101. position[0] -= fixX;
  41102. position[1] -= fixY;
  41103. view.updateTransform();
  41104. // Get the new center
  41105. var center = view.pointToData(point);
  41106. view.setCenter(center);
  41107. view.setZoom(zoom * previousZoom);
  41108. }
  41109. return {
  41110. center: view.getCenter(),
  41111. zoom: view.getZoom()
  41112. };
  41113. }
  41114. /*
  41115. * Licensed to the Apache Software Foundation (ASF) under one
  41116. * or more contributor license agreements. See the NOTICE file
  41117. * distributed with this work for additional information
  41118. * regarding copyright ownership. The ASF licenses this file
  41119. * to you under the Apache License, Version 2.0 (the
  41120. * "License"); you may not use this file except in compliance
  41121. * with the License. You may obtain a copy of the License at
  41122. *
  41123. * http://www.apache.org/licenses/LICENSE-2.0
  41124. *
  41125. * Unless required by applicable law or agreed to in writing,
  41126. * software distributed under the License is distributed on an
  41127. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  41128. * KIND, either express or implied. See the License for the
  41129. * specific language governing permissions and limitations
  41130. * under the License.
  41131. */
  41132. /**
  41133. * @payload
  41134. * @property {string} [componentType=series]
  41135. * @property {number} [dx]
  41136. * @property {number} [dy]
  41137. * @property {number} [zoom]
  41138. * @property {number} [originX]
  41139. * @property {number} [originY]
  41140. */
  41141. registerAction({
  41142. type: 'geoRoam',
  41143. event: 'geoRoam',
  41144. update: 'updateTransform'
  41145. }, function (payload, ecModel) {
  41146. var componentType = payload.componentType || 'series';
  41147. ecModel.eachComponent(
  41148. { mainType: componentType, query: payload },
  41149. function (componentModel) {
  41150. var geo = componentModel.coordinateSystem;
  41151. if (geo.type !== 'geo') {
  41152. return;
  41153. }
  41154. var res = updateCenterAndZoom(
  41155. geo, payload, componentModel.get('scaleLimit')
  41156. );
  41157. componentModel.setCenter
  41158. && componentModel.setCenter(res.center);
  41159. componentModel.setZoom
  41160. && componentModel.setZoom(res.zoom);
  41161. // All map series with same `map` use the same geo coordinate system
  41162. // So the center and zoom must be in sync. Include the series not selected by legend
  41163. if (componentType === 'series') {
  41164. each$1(componentModel.seriesGroup, function (seriesModel) {
  41165. seriesModel.setCenter(res.center);
  41166. seriesModel.setZoom(res.zoom);
  41167. });
  41168. }
  41169. }
  41170. );
  41171. });
  41172. /*
  41173. * Licensed to the Apache Software Foundation (ASF) under one
  41174. * or more contributor license agreements. See the NOTICE file
  41175. * distributed with this work for additional information
  41176. * regarding copyright ownership. The ASF licenses this file
  41177. * to you under the Apache License, Version 2.0 (the
  41178. * "License"); you may not use this file except in compliance
  41179. * with the License. You may obtain a copy of the License at
  41180. *
  41181. * http://www.apache.org/licenses/LICENSE-2.0
  41182. *
  41183. * Unless required by applicable law or agreed to in writing,
  41184. * software distributed under the License is distributed on an
  41185. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  41186. * KIND, either express or implied. See the License for the
  41187. * specific language governing permissions and limitations
  41188. * under the License.
  41189. */
  41190. /**
  41191. * Simple view coordinate system
  41192. * Mapping given x, y to transformd view x, y
  41193. */
  41194. var v2ApplyTransform$1 = applyTransform;
  41195. // Dummy transform node
  41196. function TransformDummy() {
  41197. Transformable.call(this);
  41198. }
  41199. mixin(TransformDummy, Transformable);
  41200. function View(name) {
  41201. /**
  41202. * @type {string}
  41203. */
  41204. this.name = name;
  41205. /**
  41206. * @type {Object}
  41207. */
  41208. this.zoomLimit;
  41209. Transformable.call(this);
  41210. this._roamTransformable = new TransformDummy();
  41211. this._rawTransformable = new TransformDummy();
  41212. this._center;
  41213. this._zoom;
  41214. }
  41215. View.prototype = {
  41216. constructor: View,
  41217. type: 'view',
  41218. /**
  41219. * @param {Array.<string>}
  41220. * @readOnly
  41221. */
  41222. dimensions: ['x', 'y'],
  41223. /**
  41224. * Set bounding rect
  41225. * @param {number} x
  41226. * @param {number} y
  41227. * @param {number} width
  41228. * @param {number} height
  41229. */
  41230. // PENDING to getRect
  41231. setBoundingRect: function (x, y, width, height) {
  41232. this._rect = new BoundingRect(x, y, width, height);
  41233. return this._rect;
  41234. },
  41235. /**
  41236. * @return {module:zrender/core/BoundingRect}
  41237. */
  41238. // PENDING to getRect
  41239. getBoundingRect: function () {
  41240. return this._rect;
  41241. },
  41242. /**
  41243. * @param {number} x
  41244. * @param {number} y
  41245. * @param {number} width
  41246. * @param {number} height
  41247. */
  41248. setViewRect: function (x, y, width, height) {
  41249. this.transformTo(x, y, width, height);
  41250. this._viewRect = new BoundingRect(x, y, width, height);
  41251. },
  41252. /**
  41253. * Transformed to particular position and size
  41254. * @param {number} x
  41255. * @param {number} y
  41256. * @param {number} width
  41257. * @param {number} height
  41258. */
  41259. transformTo: function (x, y, width, height) {
  41260. var rect = this.getBoundingRect();
  41261. var rawTransform = this._rawTransformable;
  41262. rawTransform.transform = rect.calculateTransform(
  41263. new BoundingRect(x, y, width, height)
  41264. );
  41265. rawTransform.decomposeTransform();
  41266. this._updateTransform();
  41267. },
  41268. /**
  41269. * Set center of view
  41270. * @param {Array.<number>} [centerCoord]
  41271. */
  41272. setCenter: function (centerCoord) {
  41273. if (!centerCoord) {
  41274. return;
  41275. }
  41276. this._center = centerCoord;
  41277. this._updateCenterAndZoom();
  41278. },
  41279. /**
  41280. * @param {number} zoom
  41281. */
  41282. setZoom: function (zoom) {
  41283. zoom = zoom || 1;
  41284. var zoomLimit = this.zoomLimit;
  41285. if (zoomLimit) {
  41286. if (zoomLimit.max != null) {
  41287. zoom = Math.min(zoomLimit.max, zoom);
  41288. }
  41289. if (zoomLimit.min != null) {
  41290. zoom = Math.max(zoomLimit.min, zoom);
  41291. }
  41292. }
  41293. this._zoom = zoom;
  41294. this._updateCenterAndZoom();
  41295. },
  41296. /**
  41297. * Get default center without roam
  41298. */
  41299. getDefaultCenter: function () {
  41300. // Rect before any transform
  41301. var rawRect = this.getBoundingRect();
  41302. var cx = rawRect.x + rawRect.width / 2;
  41303. var cy = rawRect.y + rawRect.height / 2;
  41304. return [cx, cy];
  41305. },
  41306. getCenter: function () {
  41307. return this._center || this.getDefaultCenter();
  41308. },
  41309. getZoom: function () {
  41310. return this._zoom || 1;
  41311. },
  41312. /**
  41313. * @return {Array.<number}
  41314. */
  41315. getRoamTransform: function () {
  41316. return this._roamTransformable.getLocalTransform();
  41317. },
  41318. /**
  41319. * Remove roam
  41320. */
  41321. _updateCenterAndZoom: function () {
  41322. // Must update after view transform updated
  41323. var rawTransformMatrix = this._rawTransformable.getLocalTransform();
  41324. var roamTransform = this._roamTransformable;
  41325. var defaultCenter = this.getDefaultCenter();
  41326. var center = this.getCenter();
  41327. var zoom = this.getZoom();
  41328. center = applyTransform([], center, rawTransformMatrix);
  41329. defaultCenter = applyTransform([], defaultCenter, rawTransformMatrix);
  41330. roamTransform.origin = center;
  41331. roamTransform.position = [
  41332. defaultCenter[0] - center[0],
  41333. defaultCenter[1] - center[1]
  41334. ];
  41335. roamTransform.scale = [zoom, zoom];
  41336. this._updateTransform();
  41337. },
  41338. /**
  41339. * Update transform from roam and mapLocation
  41340. * @private
  41341. */
  41342. _updateTransform: function () {
  41343. var roamTransformable = this._roamTransformable;
  41344. var rawTransformable = this._rawTransformable;
  41345. rawTransformable.parent = roamTransformable;
  41346. roamTransformable.updateTransform();
  41347. rawTransformable.updateTransform();
  41348. copy$1(this.transform || (this.transform = []), rawTransformable.transform || create$1());
  41349. this._rawTransform = rawTransformable.getLocalTransform();
  41350. this.invTransform = this.invTransform || [];
  41351. invert(this.invTransform, this.transform);
  41352. this.decomposeTransform();
  41353. },
  41354. /**
  41355. * @return {module:zrender/core/BoundingRect}
  41356. */
  41357. getViewRect: function () {
  41358. return this._viewRect;
  41359. },
  41360. /**
  41361. * Get view rect after roam transform
  41362. * @return {module:zrender/core/BoundingRect}
  41363. */
  41364. getViewRectAfterRoam: function () {
  41365. var rect = this.getBoundingRect().clone();
  41366. rect.applyTransform(this.transform);
  41367. return rect;
  41368. },
  41369. /**
  41370. * Convert a single (lon, lat) data item to (x, y) point.
  41371. * @param {Array.<number>} data
  41372. * @param {boolean} noRoam
  41373. * @param {Array.<number>} [out]
  41374. * @return {Array.<number>}
  41375. */
  41376. dataToPoint: function (data, noRoam, out) {
  41377. var transform = noRoam ? this._rawTransform : this.transform;
  41378. out = out || [];
  41379. return transform
  41380. ? v2ApplyTransform$1(out, data, transform)
  41381. : copy(out, data);
  41382. },
  41383. /**
  41384. * Convert a (x, y) point to (lon, lat) data
  41385. * @param {Array.<number>} point
  41386. * @return {Array.<number>}
  41387. */
  41388. pointToData: function (point) {
  41389. var invTransform = this.invTransform;
  41390. return invTransform
  41391. ? v2ApplyTransform$1([], point, invTransform)
  41392. : [point[0], point[1]];
  41393. },
  41394. /**
  41395. * @implements
  41396. * see {module:echarts/CoodinateSystem}
  41397. */
  41398. convertToPixel: curry(doConvert$1, 'dataToPoint'),
  41399. /**
  41400. * @implements
  41401. * see {module:echarts/CoodinateSystem}
  41402. */
  41403. convertFromPixel: curry(doConvert$1, 'pointToData'),
  41404. /**
  41405. * @implements
  41406. * see {module:echarts/CoodinateSystem}
  41407. */
  41408. containPoint: function (point) {
  41409. return this.getViewRectAfterRoam().contain(point[0], point[1]);
  41410. }
  41411. /**
  41412. * @return {number}
  41413. */
  41414. // getScalarScale: function () {
  41415. // // Use determinant square root of transform to mutiply scalar
  41416. // var m = this.transform;
  41417. // var det = Math.sqrt(Math.abs(m[0] * m[3] - m[2] * m[1]));
  41418. // return det;
  41419. // }
  41420. };
  41421. mixin(View, Transformable);
  41422. function doConvert$1(methodName, ecModel, finder, value) {
  41423. var seriesModel = finder.seriesModel;
  41424. var coordSys = seriesModel ? seriesModel.coordinateSystem : null; // e.g., graph.
  41425. return coordSys === this ? coordSys[methodName](value) : null;
  41426. }
  41427. /*
  41428. * Licensed to the Apache Software Foundation (ASF) under one
  41429. * or more contributor license agreements. See the NOTICE file
  41430. * distributed with this work for additional information
  41431. * regarding copyright ownership. The ASF licenses this file
  41432. * to you under the Apache License, Version 2.0 (the
  41433. * "License"); you may not use this file except in compliance
  41434. * with the License. You may obtain a copy of the License at
  41435. *
  41436. * http://www.apache.org/licenses/LICENSE-2.0
  41437. *
  41438. * Unless required by applicable law or agreed to in writing,
  41439. * software distributed under the License is distributed on an
  41440. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  41441. * KIND, either express or implied. See the License for the
  41442. * specific language governing permissions and limitations
  41443. * under the License.
  41444. */
  41445. /**
  41446. * [Geo description]
  41447. * For backward compatibility, the orginal interface:
  41448. * `name, map, geoJson, specialAreas, nameMap` is kept.
  41449. *
  41450. * @param {string|Object} name
  41451. * @param {string} map Map type
  41452. * Specify the positioned areas by left, top, width, height
  41453. * @param {Object.<string, string>} [nameMap]
  41454. * Specify name alias
  41455. * @param {boolean} [invertLongitute=true]
  41456. */
  41457. function Geo(name, map$$1, nameMap, invertLongitute) {
  41458. View.call(this, name);
  41459. /**
  41460. * Map type
  41461. * @type {string}
  41462. */
  41463. this.map = map$$1;
  41464. var source = geoSourceManager.load(map$$1, nameMap);
  41465. this._nameCoordMap = source.nameCoordMap;
  41466. this._regionsMap = source.regionsMap;
  41467. this._invertLongitute = invertLongitute == null ? true : invertLongitute;
  41468. /**
  41469. * @readOnly
  41470. */
  41471. this.regions = source.regions;
  41472. /**
  41473. * @type {module:zrender/src/core/BoundingRect}
  41474. */
  41475. this._rect = source.boundingRect;
  41476. }
  41477. Geo.prototype = {
  41478. constructor: Geo,
  41479. type: 'geo',
  41480. /**
  41481. * @param {Array.<string>}
  41482. * @readOnly
  41483. */
  41484. dimensions: ['lng', 'lat'],
  41485. /**
  41486. * If contain given lng,lat coord
  41487. * @param {Array.<number>}
  41488. * @readOnly
  41489. */
  41490. containCoord: function (coord) {
  41491. var regions = this.regions;
  41492. for (var i = 0; i < regions.length; i++) {
  41493. if (regions[i].contain(coord)) {
  41494. return true;
  41495. }
  41496. }
  41497. return false;
  41498. },
  41499. /**
  41500. * @override
  41501. */
  41502. transformTo: function (x, y, width, height) {
  41503. var rect = this.getBoundingRect();
  41504. var invertLongitute = this._invertLongitute;
  41505. rect = rect.clone();
  41506. if (invertLongitute) {
  41507. // Longitute is inverted
  41508. rect.y = -rect.y - rect.height;
  41509. }
  41510. var rawTransformable = this._rawTransformable;
  41511. rawTransformable.transform = rect.calculateTransform(
  41512. new BoundingRect(x, y, width, height)
  41513. );
  41514. rawTransformable.decomposeTransform();
  41515. if (invertLongitute) {
  41516. var scale = rawTransformable.scale;
  41517. scale[1] = -scale[1];
  41518. }
  41519. rawTransformable.updateTransform();
  41520. this._updateTransform();
  41521. },
  41522. /**
  41523. * @param {string} name
  41524. * @return {module:echarts/coord/geo/Region}
  41525. */
  41526. getRegion: function (name) {
  41527. return this._regionsMap.get(name);
  41528. },
  41529. getRegionByCoord: function (coord) {
  41530. var regions = this.regions;
  41531. for (var i = 0; i < regions.length; i++) {
  41532. if (regions[i].contain(coord)) {
  41533. return regions[i];
  41534. }
  41535. }
  41536. },
  41537. /**
  41538. * Add geoCoord for indexing by name
  41539. * @param {string} name
  41540. * @param {Array.<number>} geoCoord
  41541. */
  41542. addGeoCoord: function (name, geoCoord) {
  41543. this._nameCoordMap.set(name, geoCoord);
  41544. },
  41545. /**
  41546. * Get geoCoord by name
  41547. * @param {string} name
  41548. * @return {Array.<number>}
  41549. */
  41550. getGeoCoord: function (name) {
  41551. return this._nameCoordMap.get(name);
  41552. },
  41553. /**
  41554. * @override
  41555. */
  41556. getBoundingRect: function () {
  41557. return this._rect;
  41558. },
  41559. /**
  41560. * @param {string|Array.<number>} data
  41561. * @param {boolean} noRoam
  41562. * @param {Array.<number>} [out]
  41563. * @return {Array.<number>}
  41564. */
  41565. dataToPoint: function (data, noRoam, out) {
  41566. if (typeof data === 'string') {
  41567. // Map area name to geoCoord
  41568. data = this.getGeoCoord(data);
  41569. }
  41570. if (data) {
  41571. return View.prototype.dataToPoint.call(this, data, noRoam, out);
  41572. }
  41573. },
  41574. /**
  41575. * @override
  41576. */
  41577. convertToPixel: curry(doConvert, 'dataToPoint'),
  41578. /**
  41579. * @override
  41580. */
  41581. convertFromPixel: curry(doConvert, 'pointToData')
  41582. };
  41583. mixin(Geo, View);
  41584. function doConvert(methodName, ecModel, finder, value) {
  41585. var geoModel = finder.geoModel;
  41586. var seriesModel = finder.seriesModel;
  41587. var coordSys = geoModel
  41588. ? geoModel.coordinateSystem
  41589. : seriesModel
  41590. ? (
  41591. seriesModel.coordinateSystem // For map.
  41592. || (seriesModel.getReferringComponents('geo')[0] || {}).coordinateSystem
  41593. )
  41594. : null;
  41595. return coordSys === this ? coordSys[methodName](value) : null;
  41596. }
  41597. /*
  41598. * Licensed to the Apache Software Foundation (ASF) under one
  41599. * or more contributor license agreements. See the NOTICE file
  41600. * distributed with this work for additional information
  41601. * regarding copyright ownership. The ASF licenses this file
  41602. * to you under the Apache License, Version 2.0 (the
  41603. * "License"); you may not use this file except in compliance
  41604. * with the License. You may obtain a copy of the License at
  41605. *
  41606. * http://www.apache.org/licenses/LICENSE-2.0
  41607. *
  41608. * Unless required by applicable law or agreed to in writing,
  41609. * software distributed under the License is distributed on an
  41610. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  41611. * KIND, either express or implied. See the License for the
  41612. * specific language governing permissions and limitations
  41613. * under the License.
  41614. */
  41615. /**
  41616. * Resize method bound to the geo
  41617. * @param {module:echarts/coord/geo/GeoModel|module:echarts/chart/map/MapModel} geoModel
  41618. * @param {module:echarts/ExtensionAPI} api
  41619. */
  41620. function resizeGeo(geoModel, api) {
  41621. var boundingCoords = geoModel.get('boundingCoords');
  41622. if (boundingCoords != null) {
  41623. var leftTop = boundingCoords[0];
  41624. var rightBottom = boundingCoords[1];
  41625. if (isNaN(leftTop[0]) || isNaN(leftTop[1]) || isNaN(rightBottom[0]) || isNaN(rightBottom[1])) {
  41626. if (__DEV__) {
  41627. console.error('Invalid boundingCoords');
  41628. }
  41629. }
  41630. else {
  41631. this.setBoundingRect(leftTop[0], leftTop[1], rightBottom[0] - leftTop[0], rightBottom[1] - leftTop[1]);
  41632. }
  41633. }
  41634. var rect = this.getBoundingRect();
  41635. var boxLayoutOption;
  41636. var center = geoModel.get('layoutCenter');
  41637. var size = geoModel.get('layoutSize');
  41638. var viewWidth = api.getWidth();
  41639. var viewHeight = api.getHeight();
  41640. var aspect = rect.width / rect.height * this.aspectScale;
  41641. var useCenterAndSize = false;
  41642. if (center && size) {
  41643. center = [
  41644. parsePercent$1(center[0], viewWidth),
  41645. parsePercent$1(center[1], viewHeight)
  41646. ];
  41647. size = parsePercent$1(size, Math.min(viewWidth, viewHeight));
  41648. if (!isNaN(center[0]) && !isNaN(center[1]) && !isNaN(size)) {
  41649. useCenterAndSize = true;
  41650. }
  41651. else {
  41652. if (__DEV__) {
  41653. console.warn('Given layoutCenter or layoutSize data are invalid. Use left/top/width/height instead.');
  41654. }
  41655. }
  41656. }
  41657. var viewRect;
  41658. if (useCenterAndSize) {
  41659. var viewRect = {};
  41660. if (aspect > 1) {
  41661. // Width is same with size
  41662. viewRect.width = size;
  41663. viewRect.height = size / aspect;
  41664. }
  41665. else {
  41666. viewRect.height = size;
  41667. viewRect.width = size * aspect;
  41668. }
  41669. viewRect.y = center[1] - viewRect.height / 2;
  41670. viewRect.x = center[0] - viewRect.width / 2;
  41671. }
  41672. else {
  41673. // Use left/top/width/height
  41674. boxLayoutOption = geoModel.getBoxLayoutParams();
  41675. // 0.75 rate
  41676. boxLayoutOption.aspect = aspect;
  41677. viewRect = getLayoutRect(boxLayoutOption, {
  41678. width: viewWidth,
  41679. height: viewHeight
  41680. });
  41681. }
  41682. this.setViewRect(viewRect.x, viewRect.y, viewRect.width, viewRect.height);
  41683. this.setCenter(geoModel.get('center'));
  41684. this.setZoom(geoModel.get('zoom'));
  41685. }
  41686. /**
  41687. * @param {module:echarts/coord/Geo} geo
  41688. * @param {module:echarts/model/Model} model
  41689. * @inner
  41690. */
  41691. function setGeoCoords(geo, model) {
  41692. each$1(model.get('geoCoord'), function (geoCoord, name) {
  41693. geo.addGeoCoord(name, geoCoord);
  41694. });
  41695. }
  41696. var geoCreator = {
  41697. // For deciding which dimensions to use when creating list data
  41698. dimensions: Geo.prototype.dimensions,
  41699. create: function (ecModel, api) {
  41700. var geoList = [];
  41701. // FIXME Create each time may be slow
  41702. ecModel.eachComponent('geo', function (geoModel, idx) {
  41703. var name = geoModel.get('map');
  41704. var aspectScale = geoModel.get('aspectScale');
  41705. var invertLongitute = true;
  41706. var mapRecords = mapDataStorage.retrieveMap(name);
  41707. if (mapRecords && mapRecords[0] && mapRecords[0].type === 'svg') {
  41708. aspectScale == null && (aspectScale = 1);
  41709. invertLongitute = false;
  41710. }
  41711. else {
  41712. aspectScale == null && (aspectScale = 0.75);
  41713. }
  41714. var geo = new Geo(name + idx, name, geoModel.get('nameMap'), invertLongitute);
  41715. geo.aspectScale = aspectScale;
  41716. geo.zoomLimit = geoModel.get('scaleLimit');
  41717. geoList.push(geo);
  41718. setGeoCoords(geo, geoModel);
  41719. geoModel.coordinateSystem = geo;
  41720. geo.model = geoModel;
  41721. // Inject resize method
  41722. geo.resize = resizeGeo;
  41723. geo.resize(geoModel, api);
  41724. });
  41725. ecModel.eachSeries(function (seriesModel) {
  41726. var coordSys = seriesModel.get('coordinateSystem');
  41727. if (coordSys === 'geo') {
  41728. var geoIndex = seriesModel.get('geoIndex') || 0;
  41729. seriesModel.coordinateSystem = geoList[geoIndex];
  41730. }
  41731. });
  41732. // If has map series
  41733. var mapModelGroupBySeries = {};
  41734. ecModel.eachSeriesByType('map', function (seriesModel) {
  41735. if (!seriesModel.getHostGeoModel()) {
  41736. var mapType = seriesModel.getMapType();
  41737. mapModelGroupBySeries[mapType] = mapModelGroupBySeries[mapType] || [];
  41738. mapModelGroupBySeries[mapType].push(seriesModel);
  41739. }
  41740. });
  41741. each$1(mapModelGroupBySeries, function (mapSeries, mapType) {
  41742. var nameMapList = map(mapSeries, function (singleMapSeries) {
  41743. return singleMapSeries.get('nameMap');
  41744. });
  41745. var geo = new Geo(mapType, mapType, mergeAll(nameMapList));
  41746. geo.zoomLimit = retrieve.apply(null, map(mapSeries, function (singleMapSeries) {
  41747. return singleMapSeries.get('scaleLimit');
  41748. }));
  41749. geoList.push(geo);
  41750. // Inject resize method
  41751. geo.resize = resizeGeo;
  41752. geo.aspectScale = mapSeries[0].get('aspectScale');
  41753. geo.resize(mapSeries[0], api);
  41754. each$1(mapSeries, function (singleMapSeries) {
  41755. singleMapSeries.coordinateSystem = geo;
  41756. setGeoCoords(geo, singleMapSeries);
  41757. });
  41758. });
  41759. return geoList;
  41760. },
  41761. /**
  41762. * Fill given regions array
  41763. * @param {Array.<Object>} originRegionArr
  41764. * @param {string} mapName
  41765. * @param {Object} [nameMap]
  41766. * @return {Array}
  41767. */
  41768. getFilledRegions: function (originRegionArr, mapName, nameMap) {
  41769. // Not use the original
  41770. var regionsArr = (originRegionArr || []).slice();
  41771. var dataNameMap = createHashMap();
  41772. for (var i = 0; i < regionsArr.length; i++) {
  41773. dataNameMap.set(regionsArr[i].name, regionsArr[i]);
  41774. }
  41775. var source = geoSourceManager.load(mapName, nameMap);
  41776. each$1(source.regions, function (region) {
  41777. var name = region.name;
  41778. !dataNameMap.get(name) && regionsArr.push({name: name});
  41779. });
  41780. return regionsArr;
  41781. }
  41782. };
  41783. registerCoordinateSystem('geo', geoCreator);
  41784. /*
  41785. * Licensed to the Apache Software Foundation (ASF) under one
  41786. * or more contributor license agreements. See the NOTICE file
  41787. * distributed with this work for additional information
  41788. * regarding copyright ownership. The ASF licenses this file
  41789. * to you under the Apache License, Version 2.0 (the
  41790. * "License"); you may not use this file except in compliance
  41791. * with the License. You may obtain a copy of the License at
  41792. *
  41793. * http://www.apache.org/licenses/LICENSE-2.0
  41794. *
  41795. * Unless required by applicable law or agreed to in writing,
  41796. * software distributed under the License is distributed on an
  41797. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  41798. * KIND, either express or implied. See the License for the
  41799. * specific language governing permissions and limitations
  41800. * under the License.
  41801. */
  41802. var mapSymbolLayout = function (ecModel) {
  41803. var processedMapType = {};
  41804. ecModel.eachSeriesByType('map', function (mapSeries) {
  41805. var mapType = mapSeries.getMapType();
  41806. if (mapSeries.getHostGeoModel() || processedMapType[mapType]) {
  41807. return;
  41808. }
  41809. var mapSymbolOffsets = {};
  41810. each$1(mapSeries.seriesGroup, function (subMapSeries) {
  41811. var geo = subMapSeries.coordinateSystem;
  41812. var data = subMapSeries.originalData;
  41813. if (subMapSeries.get('showLegendSymbol') && ecModel.getComponent('legend')) {
  41814. data.each(data.mapDimension('value'), function (value, idx) {
  41815. var name = data.getName(idx);
  41816. var region = geo.getRegion(name);
  41817. // If input series.data is [11, 22, '-'/null/undefined, 44],
  41818. // it will be filled with NaN: [11, 22, NaN, 44] and NaN will
  41819. // not be drawn. So here must validate if value is NaN.
  41820. if (!region || isNaN(value)) {
  41821. return;
  41822. }
  41823. var offset = mapSymbolOffsets[name] || 0;
  41824. var point = geo.dataToPoint(region.center);
  41825. mapSymbolOffsets[name] = offset + 1;
  41826. data.setItemLayout(idx, {
  41827. point: point,
  41828. offset: offset
  41829. });
  41830. });
  41831. }
  41832. });
  41833. // Show label of those region not has legendSymbol(which is offset 0)
  41834. var data = mapSeries.getData();
  41835. data.each(function (idx) {
  41836. var name = data.getName(idx);
  41837. var layout = data.getItemLayout(idx) || {};
  41838. layout.showLabel = !mapSymbolOffsets[name];
  41839. data.setItemLayout(idx, layout);
  41840. });
  41841. processedMapType[mapType] = true;
  41842. });
  41843. };
  41844. /*
  41845. * Licensed to the Apache Software Foundation (ASF) under one
  41846. * or more contributor license agreements. See the NOTICE file
  41847. * distributed with this work for additional information
  41848. * regarding copyright ownership. The ASF licenses this file
  41849. * to you under the Apache License, Version 2.0 (the
  41850. * "License"); you may not use this file except in compliance
  41851. * with the License. You may obtain a copy of the License at
  41852. *
  41853. * http://www.apache.org/licenses/LICENSE-2.0
  41854. *
  41855. * Unless required by applicable law or agreed to in writing,
  41856. * software distributed under the License is distributed on an
  41857. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  41858. * KIND, either express or implied. See the License for the
  41859. * specific language governing permissions and limitations
  41860. * under the License.
  41861. */
  41862. var mapVisual = function (ecModel) {
  41863. ecModel.eachSeriesByType('map', function (seriesModel) {
  41864. var colorList = seriesModel.get('color');
  41865. var itemStyleModel = seriesModel.getModel('itemStyle');
  41866. var areaColor = itemStyleModel.get('areaColor');
  41867. var color = itemStyleModel.get('color')
  41868. || colorList[seriesModel.seriesIndex % colorList.length];
  41869. seriesModel.getData().setVisual({
  41870. 'areaColor': areaColor,
  41871. 'color': color
  41872. });
  41873. });
  41874. };
  41875. /*
  41876. * Licensed to the Apache Software Foundation (ASF) under one
  41877. * or more contributor license agreements. See the NOTICE file
  41878. * distributed with this work for additional information
  41879. * regarding copyright ownership. The ASF licenses this file
  41880. * to you under the Apache License, Version 2.0 (the
  41881. * "License"); you may not use this file except in compliance
  41882. * with the License. You may obtain a copy of the License at
  41883. *
  41884. * http://www.apache.org/licenses/LICENSE-2.0
  41885. *
  41886. * Unless required by applicable law or agreed to in writing,
  41887. * software distributed under the License is distributed on an
  41888. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  41889. * KIND, either express or implied. See the License for the
  41890. * specific language governing permissions and limitations
  41891. * under the License.
  41892. */
  41893. // FIXME 公用?
  41894. /**
  41895. * @param {Array.<module:echarts/data/List>} datas
  41896. * @param {string} statisticType 'average' 'sum'
  41897. * @inner
  41898. */
  41899. function dataStatistics(datas, statisticType) {
  41900. var dataNameMap = {};
  41901. each$1(datas, function (data) {
  41902. data.each(data.mapDimension('value'), function (value, idx) {
  41903. // Add prefix to avoid conflict with Object.prototype.
  41904. var mapKey = 'ec-' + data.getName(idx);
  41905. dataNameMap[mapKey] = dataNameMap[mapKey] || [];
  41906. if (!isNaN(value)) {
  41907. dataNameMap[mapKey].push(value);
  41908. }
  41909. });
  41910. });
  41911. return datas[0].map(datas[0].mapDimension('value'), function (value, idx) {
  41912. var mapKey = 'ec-' + datas[0].getName(idx);
  41913. var sum = 0;
  41914. var min = Infinity;
  41915. var max = -Infinity;
  41916. var len = dataNameMap[mapKey].length;
  41917. for (var i = 0; i < len; i++) {
  41918. min = Math.min(min, dataNameMap[mapKey][i]);
  41919. max = Math.max(max, dataNameMap[mapKey][i]);
  41920. sum += dataNameMap[mapKey][i];
  41921. }
  41922. var result;
  41923. if (statisticType === 'min') {
  41924. result = min;
  41925. }
  41926. else if (statisticType === 'max') {
  41927. result = max;
  41928. }
  41929. else if (statisticType === 'average') {
  41930. result = sum / len;
  41931. }
  41932. else {
  41933. result = sum;
  41934. }
  41935. return len === 0 ? NaN : result;
  41936. });
  41937. }
  41938. var mapDataStatistic = function (ecModel) {
  41939. var seriesGroups = {};
  41940. ecModel.eachSeriesByType('map', function (seriesModel) {
  41941. var hostGeoModel = seriesModel.getHostGeoModel();
  41942. var key = hostGeoModel ? 'o' + hostGeoModel.id : 'i' + seriesModel.getMapType();
  41943. (seriesGroups[key] = seriesGroups[key] || []).push(seriesModel);
  41944. });
  41945. each$1(seriesGroups, function (seriesList, key) {
  41946. var data = dataStatistics(
  41947. map(seriesList, function (seriesModel) {
  41948. return seriesModel.getData();
  41949. }),
  41950. seriesList[0].get('mapValueCalculation')
  41951. );
  41952. for (var i = 0; i < seriesList.length; i++) {
  41953. seriesList[i].originalData = seriesList[i].getData();
  41954. }
  41955. // FIXME Put where?
  41956. for (var i = 0; i < seriesList.length; i++) {
  41957. seriesList[i].seriesGroup = seriesList;
  41958. seriesList[i].needsDrawMap = i === 0 && !seriesList[i].getHostGeoModel();
  41959. seriesList[i].setData(data.cloneShallow());
  41960. seriesList[i].mainSeries = seriesList[0];
  41961. }
  41962. });
  41963. };
  41964. /*
  41965. * Licensed to the Apache Software Foundation (ASF) under one
  41966. * or more contributor license agreements. See the NOTICE file
  41967. * distributed with this work for additional information
  41968. * regarding copyright ownership. The ASF licenses this file
  41969. * to you under the Apache License, Version 2.0 (the
  41970. * "License"); you may not use this file except in compliance
  41971. * with the License. You may obtain a copy of the License at
  41972. *
  41973. * http://www.apache.org/licenses/LICENSE-2.0
  41974. *
  41975. * Unless required by applicable law or agreed to in writing,
  41976. * software distributed under the License is distributed on an
  41977. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  41978. * KIND, either express or implied. See the License for the
  41979. * specific language governing permissions and limitations
  41980. * under the License.
  41981. */
  41982. var backwardCompat$2 = function (option) {
  41983. // Save geoCoord
  41984. var mapSeries = [];
  41985. each$1(option.series, function (seriesOpt) {
  41986. if (seriesOpt && seriesOpt.type === 'map') {
  41987. mapSeries.push(seriesOpt);
  41988. seriesOpt.map = seriesOpt.map || seriesOpt.mapType;
  41989. // Put x, y, width, height, x2, y2 in the top level
  41990. defaults(seriesOpt, seriesOpt.mapLocation);
  41991. }
  41992. });
  41993. };
  41994. /*
  41995. * Licensed to the Apache Software Foundation (ASF) under one
  41996. * or more contributor license agreements. See the NOTICE file
  41997. * distributed with this work for additional information
  41998. * regarding copyright ownership. The ASF licenses this file
  41999. * to you under the Apache License, Version 2.0 (the
  42000. * "License"); you may not use this file except in compliance
  42001. * with the License. You may obtain a copy of the License at
  42002. *
  42003. * http://www.apache.org/licenses/LICENSE-2.0
  42004. *
  42005. * Unless required by applicable law or agreed to in writing,
  42006. * software distributed under the License is distributed on an
  42007. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  42008. * KIND, either express or implied. See the License for the
  42009. * specific language governing permissions and limitations
  42010. * under the License.
  42011. */
  42012. registerLayout(mapSymbolLayout);
  42013. registerVisual(mapVisual);
  42014. registerProcessor(PRIORITY.PROCESSOR.STATISTIC, mapDataStatistic);
  42015. registerPreprocessor(backwardCompat$2);
  42016. createDataSelectAction('map', [{
  42017. type: 'mapToggleSelect',
  42018. event: 'mapselectchanged',
  42019. method: 'toggleSelected'
  42020. }, {
  42021. type: 'mapSelect',
  42022. event: 'mapselected',
  42023. method: 'select'
  42024. }, {
  42025. type: 'mapUnSelect',
  42026. event: 'mapunselected',
  42027. method: 'unSelect'
  42028. }]);
  42029. /*
  42030. * Licensed to the Apache Software Foundation (ASF) under one
  42031. * or more contributor license agreements. See the NOTICE file
  42032. * distributed with this work for additional information
  42033. * regarding copyright ownership. The ASF licenses this file
  42034. * to you under the Apache License, Version 2.0 (the
  42035. * "License"); you may not use this file except in compliance
  42036. * with the License. You may obtain a copy of the License at
  42037. *
  42038. * http://www.apache.org/licenses/LICENSE-2.0
  42039. *
  42040. * Unless required by applicable law or agreed to in writing,
  42041. * software distributed under the License is distributed on an
  42042. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  42043. * KIND, either express or implied. See the License for the
  42044. * specific language governing permissions and limitations
  42045. * under the License.
  42046. */
  42047. /**
  42048. * Link lists and struct (graph or tree)
  42049. */
  42050. var each$7 = each$1;
  42051. var DATAS = '\0__link_datas';
  42052. var MAIN_DATA = '\0__link_mainData';
  42053. // Caution:
  42054. // In most case, either list or its shallow clones (see list.cloneShallow)
  42055. // is active in echarts process. So considering heap memory consumption,
  42056. // we do not clone tree or graph, but share them among list and its shallow clones.
  42057. // But in some rare case, we have to keep old list (like do animation in chart). So
  42058. // please take care that both the old list and the new list share the same tree/graph.
  42059. /**
  42060. * @param {Object} opt
  42061. * @param {module:echarts/data/List} opt.mainData
  42062. * @param {Object} [opt.struct] For example, instance of Graph or Tree.
  42063. * @param {string} [opt.structAttr] designation: list[structAttr] = struct;
  42064. * @param {Object} [opt.datas] {dataType: data},
  42065. * like: {node: nodeList, edge: edgeList}.
  42066. * Should contain mainData.
  42067. * @param {Object} [opt.datasAttr] {dataType: attr},
  42068. * designation: struct[datasAttr[dataType]] = list;
  42069. */
  42070. function linkList(opt) {
  42071. var mainData = opt.mainData;
  42072. var datas = opt.datas;
  42073. if (!datas) {
  42074. datas = {main: mainData};
  42075. opt.datasAttr = {main: 'data'};
  42076. }
  42077. opt.datas = opt.mainData = null;
  42078. linkAll(mainData, datas, opt);
  42079. // Porxy data original methods.
  42080. each$7(datas, function (data) {
  42081. each$7(mainData.TRANSFERABLE_METHODS, function (methodName) {
  42082. data.wrapMethod(methodName, curry(transferInjection, opt));
  42083. });
  42084. });
  42085. // Beyond transfer, additional features should be added to `cloneShallow`.
  42086. mainData.wrapMethod('cloneShallow', curry(cloneShallowInjection, opt));
  42087. // Only mainData trigger change, because struct.update may trigger
  42088. // another changable methods, which may bring about dead lock.
  42089. each$7(mainData.CHANGABLE_METHODS, function (methodName) {
  42090. mainData.wrapMethod(methodName, curry(changeInjection, opt));
  42091. });
  42092. // Make sure datas contains mainData.
  42093. assert$1(datas[mainData.dataType] === mainData);
  42094. }
  42095. function transferInjection(opt, res) {
  42096. if (isMainData(this)) {
  42097. // Transfer datas to new main data.
  42098. var datas = extend({}, this[DATAS]);
  42099. datas[this.dataType] = res;
  42100. linkAll(res, datas, opt);
  42101. }
  42102. else {
  42103. // Modify the reference in main data to point newData.
  42104. linkSingle(res, this.dataType, this[MAIN_DATA], opt);
  42105. }
  42106. return res;
  42107. }
  42108. function changeInjection(opt, res) {
  42109. opt.struct && opt.struct.update(this);
  42110. return res;
  42111. }
  42112. function cloneShallowInjection(opt, res) {
  42113. // cloneShallow, which brings about some fragilities, may be inappropriate
  42114. // to be exposed as an API. So for implementation simplicity we can make
  42115. // the restriction that cloneShallow of not-mainData should not be invoked
  42116. // outside, but only be invoked here.
  42117. each$7(res[DATAS], function (data, dataType) {
  42118. data !== res && linkSingle(data.cloneShallow(), dataType, res, opt);
  42119. });
  42120. return res;
  42121. }
  42122. /**
  42123. * Supplement method to List.
  42124. *
  42125. * @public
  42126. * @param {string} [dataType] If not specified, return mainData.
  42127. * @return {module:echarts/data/List}
  42128. */
  42129. function getLinkedData(dataType) {
  42130. var mainData = this[MAIN_DATA];
  42131. return (dataType == null || mainData == null)
  42132. ? mainData
  42133. : mainData[DATAS][dataType];
  42134. }
  42135. function isMainData(data) {
  42136. return data[MAIN_DATA] === data;
  42137. }
  42138. function linkAll(mainData, datas, opt) {
  42139. mainData[DATAS] = {};
  42140. each$7(datas, function (data, dataType) {
  42141. linkSingle(data, dataType, mainData, opt);
  42142. });
  42143. }
  42144. function linkSingle(data, dataType, mainData, opt) {
  42145. mainData[DATAS][dataType] = data;
  42146. data[MAIN_DATA] = mainData;
  42147. data.dataType = dataType;
  42148. if (opt.struct) {
  42149. data[opt.structAttr] = opt.struct;
  42150. opt.struct[opt.datasAttr[dataType]] = data;
  42151. }
  42152. // Supplement method.
  42153. data.getLinkedData = getLinkedData;
  42154. }
  42155. /*
  42156. * Licensed to the Apache Software Foundation (ASF) under one
  42157. * or more contributor license agreements. See the NOTICE file
  42158. * distributed with this work for additional information
  42159. * regarding copyright ownership. The ASF licenses this file
  42160. * to you under the Apache License, Version 2.0 (the
  42161. * "License"); you may not use this file except in compliance
  42162. * with the License. You may obtain a copy of the License at
  42163. *
  42164. * http://www.apache.org/licenses/LICENSE-2.0
  42165. *
  42166. * Unless required by applicable law or agreed to in writing,
  42167. * software distributed under the License is distributed on an
  42168. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  42169. * KIND, either express or implied. See the License for the
  42170. * specific language governing permissions and limitations
  42171. * under the License.
  42172. */
  42173. /**
  42174. * Tree data structure
  42175. *
  42176. * @module echarts/data/Tree
  42177. */
  42178. /**
  42179. * @constructor module:echarts/data/Tree~TreeNode
  42180. * @param {string} name
  42181. * @param {module:echarts/data/Tree} hostTree
  42182. */
  42183. var TreeNode = function (name, hostTree) {
  42184. /**
  42185. * @type {string}
  42186. */
  42187. this.name = name || '';
  42188. /**
  42189. * Depth of node
  42190. *
  42191. * @type {number}
  42192. * @readOnly
  42193. */
  42194. this.depth = 0;
  42195. /**
  42196. * Height of the subtree rooted at this node.
  42197. * @type {number}
  42198. * @readOnly
  42199. */
  42200. this.height = 0;
  42201. /**
  42202. * @type {module:echarts/data/Tree~TreeNode}
  42203. * @readOnly
  42204. */
  42205. this.parentNode = null;
  42206. /**
  42207. * Reference to list item.
  42208. * Do not persistent dataIndex outside,
  42209. * besause it may be changed by list.
  42210. * If dataIndex -1,
  42211. * this node is logical deleted (filtered) in list.
  42212. *
  42213. * @type {Object}
  42214. * @readOnly
  42215. */
  42216. this.dataIndex = -1;
  42217. /**
  42218. * @type {Array.<module:echarts/data/Tree~TreeNode>}
  42219. * @readOnly
  42220. */
  42221. this.children = [];
  42222. /**
  42223. * @type {Array.<module:echarts/data/Tree~TreeNode>}
  42224. * @pubilc
  42225. */
  42226. this.viewChildren = [];
  42227. /**
  42228. * @type {moduel:echarts/data/Tree}
  42229. * @readOnly
  42230. */
  42231. this.hostTree = hostTree;
  42232. };
  42233. TreeNode.prototype = {
  42234. constructor: TreeNode,
  42235. /**
  42236. * The node is removed.
  42237. * @return {boolean} is removed.
  42238. */
  42239. isRemoved: function () {
  42240. return this.dataIndex < 0;
  42241. },
  42242. /**
  42243. * Travel this subtree (include this node).
  42244. * Usage:
  42245. * node.eachNode(function () { ... }); // preorder
  42246. * node.eachNode('preorder', function () { ... }); // preorder
  42247. * node.eachNode('postorder', function () { ... }); // postorder
  42248. * node.eachNode(
  42249. * {order: 'postorder', attr: 'viewChildren'},
  42250. * function () { ... }
  42251. * ); // postorder
  42252. *
  42253. * @param {(Object|string)} options If string, means order.
  42254. * @param {string=} options.order 'preorder' or 'postorder'
  42255. * @param {string=} options.attr 'children' or 'viewChildren'
  42256. * @param {Function} cb If in preorder and return false,
  42257. * its subtree will not be visited.
  42258. * @param {Object} [context]
  42259. */
  42260. eachNode: function (options, cb, context) {
  42261. if (typeof options === 'function') {
  42262. context = cb;
  42263. cb = options;
  42264. options = null;
  42265. }
  42266. options = options || {};
  42267. if (isString(options)) {
  42268. options = {order: options};
  42269. }
  42270. var order = options.order || 'preorder';
  42271. var children = this[options.attr || 'children'];
  42272. var suppressVisitSub;
  42273. order === 'preorder' && (suppressVisitSub = cb.call(context, this));
  42274. for (var i = 0; !suppressVisitSub && i < children.length; i++) {
  42275. children[i].eachNode(options, cb, context);
  42276. }
  42277. order === 'postorder' && cb.call(context, this);
  42278. },
  42279. /**
  42280. * Update depth and height of this subtree.
  42281. *
  42282. * @param {number} depth
  42283. */
  42284. updateDepthAndHeight: function (depth) {
  42285. var height = 0;
  42286. this.depth = depth;
  42287. for (var i = 0; i < this.children.length; i++) {
  42288. var child = this.children[i];
  42289. child.updateDepthAndHeight(depth + 1);
  42290. if (child.height > height) {
  42291. height = child.height;
  42292. }
  42293. }
  42294. this.height = height + 1;
  42295. },
  42296. /**
  42297. * @param {string} id
  42298. * @return {module:echarts/data/Tree~TreeNode}
  42299. */
  42300. getNodeById: function (id) {
  42301. if (this.getId() === id) {
  42302. return this;
  42303. }
  42304. for (var i = 0, children = this.children, len = children.length; i < len; i++) {
  42305. var res = children[i].getNodeById(id);
  42306. if (res) {
  42307. return res;
  42308. }
  42309. }
  42310. },
  42311. /**
  42312. * @param {module:echarts/data/Tree~TreeNode} node
  42313. * @return {boolean}
  42314. */
  42315. contains: function (node) {
  42316. if (node === this) {
  42317. return true;
  42318. }
  42319. for (var i = 0, children = this.children, len = children.length; i < len; i++) {
  42320. var res = children[i].contains(node);
  42321. if (res) {
  42322. return res;
  42323. }
  42324. }
  42325. },
  42326. /**
  42327. * @param {boolean} includeSelf Default false.
  42328. * @return {Array.<module:echarts/data/Tree~TreeNode>} order: [root, child, grandchild, ...]
  42329. */
  42330. getAncestors: function (includeSelf) {
  42331. var ancestors = [];
  42332. var node = includeSelf ? this : this.parentNode;
  42333. while (node) {
  42334. ancestors.push(node);
  42335. node = node.parentNode;
  42336. }
  42337. ancestors.reverse();
  42338. return ancestors;
  42339. },
  42340. /**
  42341. * @param {string|Array=} [dimension='value'] Default 'value'. can be 0, 1, 2, 3
  42342. * @return {number} Value.
  42343. */
  42344. getValue: function (dimension) {
  42345. var data = this.hostTree.data;
  42346. return data.get(data.getDimension(dimension || 'value'), this.dataIndex);
  42347. },
  42348. /**
  42349. * @param {Object} layout
  42350. * @param {boolean=} [merge=false]
  42351. */
  42352. setLayout: function (layout, merge$$1) {
  42353. this.dataIndex >= 0
  42354. && this.hostTree.data.setItemLayout(this.dataIndex, layout, merge$$1);
  42355. },
  42356. /**
  42357. * @return {Object} layout
  42358. */
  42359. getLayout: function () {
  42360. return this.hostTree.data.getItemLayout(this.dataIndex);
  42361. },
  42362. /**
  42363. * @param {string} [path]
  42364. * @return {module:echarts/model/Model}
  42365. */
  42366. getModel: function (path) {
  42367. if (this.dataIndex < 0) {
  42368. return;
  42369. }
  42370. var hostTree = this.hostTree;
  42371. var itemModel = hostTree.data.getItemModel(this.dataIndex);
  42372. var levelModel = this.getLevelModel();
  42373. var leavesModel;
  42374. if (!levelModel && (this.children.length === 0 || (this.children.length !== 0 && this.isExpand === false))) {
  42375. leavesModel = this.getLeavesModel();
  42376. }
  42377. return itemModel.getModel(path, (levelModel || leavesModel || hostTree.hostModel).getModel(path));
  42378. },
  42379. /**
  42380. * @return {module:echarts/model/Model}
  42381. */
  42382. getLevelModel: function () {
  42383. return (this.hostTree.levelModels || [])[this.depth];
  42384. },
  42385. /**
  42386. * @return {module:echarts/model/Model}
  42387. */
  42388. getLeavesModel: function () {
  42389. return this.hostTree.leavesModel;
  42390. },
  42391. /**
  42392. * @example
  42393. * setItemVisual('color', color);
  42394. * setItemVisual({
  42395. * 'color': color
  42396. * });
  42397. */
  42398. setVisual: function (key, value) {
  42399. this.dataIndex >= 0
  42400. && this.hostTree.data.setItemVisual(this.dataIndex, key, value);
  42401. },
  42402. /**
  42403. * Get item visual
  42404. */
  42405. getVisual: function (key, ignoreParent) {
  42406. return this.hostTree.data.getItemVisual(this.dataIndex, key, ignoreParent);
  42407. },
  42408. /**
  42409. * @public
  42410. * @return {number}
  42411. */
  42412. getRawIndex: function () {
  42413. return this.hostTree.data.getRawIndex(this.dataIndex);
  42414. },
  42415. /**
  42416. * @public
  42417. * @return {string}
  42418. */
  42419. getId: function () {
  42420. return this.hostTree.data.getId(this.dataIndex);
  42421. },
  42422. /**
  42423. * if this is an ancestor of another node
  42424. *
  42425. * @public
  42426. * @param {TreeNode} node another node
  42427. * @return {boolean} if is ancestor
  42428. */
  42429. isAncestorOf: function (node) {
  42430. var parent = node.parentNode;
  42431. while (parent) {
  42432. if (parent === this) {
  42433. return true;
  42434. }
  42435. parent = parent.parentNode;
  42436. }
  42437. return false;
  42438. },
  42439. /**
  42440. * if this is an descendant of another node
  42441. *
  42442. * @public
  42443. * @param {TreeNode} node another node
  42444. * @return {boolean} if is descendant
  42445. */
  42446. isDescendantOf: function (node) {
  42447. return node !== this && node.isAncestorOf(this);
  42448. }
  42449. };
  42450. /**
  42451. * @constructor
  42452. * @alias module:echarts/data/Tree
  42453. * @param {module:echarts/model/Model} hostModel
  42454. * @param {Array.<Object>} levelOptions
  42455. * @param {Object} leavesOption
  42456. */
  42457. function Tree(hostModel, levelOptions, leavesOption) {
  42458. /**
  42459. * @type {module:echarts/data/Tree~TreeNode}
  42460. * @readOnly
  42461. */
  42462. this.root;
  42463. /**
  42464. * @type {module:echarts/data/List}
  42465. * @readOnly
  42466. */
  42467. this.data;
  42468. /**
  42469. * Index of each item is the same as the raw index of coresponding list item.
  42470. * @private
  42471. * @type {Array.<module:echarts/data/Tree~TreeNode}
  42472. */
  42473. this._nodes = [];
  42474. /**
  42475. * @private
  42476. * @readOnly
  42477. * @type {module:echarts/model/Model}
  42478. */
  42479. this.hostModel = hostModel;
  42480. /**
  42481. * @private
  42482. * @readOnly
  42483. * @type {Array.<module:echarts/model/Model}
  42484. */
  42485. this.levelModels = map(levelOptions || [], function (levelDefine) {
  42486. return new Model(levelDefine, hostModel, hostModel.ecModel);
  42487. });
  42488. this.leavesModel = new Model(leavesOption || {}, hostModel, hostModel.ecModel);
  42489. }
  42490. Tree.prototype = {
  42491. constructor: Tree,
  42492. type: 'tree',
  42493. /**
  42494. * Travel this subtree (include this node).
  42495. * Usage:
  42496. * node.eachNode(function () { ... }); // preorder
  42497. * node.eachNode('preorder', function () { ... }); // preorder
  42498. * node.eachNode('postorder', function () { ... }); // postorder
  42499. * node.eachNode(
  42500. * {order: 'postorder', attr: 'viewChildren'},
  42501. * function () { ... }
  42502. * ); // postorder
  42503. *
  42504. * @param {(Object|string)} options If string, means order.
  42505. * @param {string=} options.order 'preorder' or 'postorder'
  42506. * @param {string=} options.attr 'children' or 'viewChildren'
  42507. * @param {Function} cb
  42508. * @param {Object} [context]
  42509. */
  42510. eachNode: function (options, cb, context) {
  42511. this.root.eachNode(options, cb, context);
  42512. },
  42513. /**
  42514. * @param {number} dataIndex
  42515. * @return {module:echarts/data/Tree~TreeNode}
  42516. */
  42517. getNodeByDataIndex: function (dataIndex) {
  42518. var rawIndex = this.data.getRawIndex(dataIndex);
  42519. return this._nodes[rawIndex];
  42520. },
  42521. /**
  42522. * @param {string} name
  42523. * @return {module:echarts/data/Tree~TreeNode}
  42524. */
  42525. getNodeByName: function (name) {
  42526. return this.root.getNodeByName(name);
  42527. },
  42528. /**
  42529. * Update item available by list,
  42530. * when list has been performed options like 'filterSelf' or 'map'.
  42531. */
  42532. update: function () {
  42533. var data = this.data;
  42534. var nodes = this._nodes;
  42535. for (var i = 0, len = nodes.length; i < len; i++) {
  42536. nodes[i].dataIndex = -1;
  42537. }
  42538. for (var i = 0, len = data.count(); i < len; i++) {
  42539. nodes[data.getRawIndex(i)].dataIndex = i;
  42540. }
  42541. },
  42542. /**
  42543. * Clear all layouts
  42544. */
  42545. clearLayouts: function () {
  42546. this.data.clearItemLayouts();
  42547. }
  42548. };
  42549. /**
  42550. * data node format:
  42551. * {
  42552. * name: ...
  42553. * value: ...
  42554. * children: [
  42555. * {
  42556. * name: ...
  42557. * value: ...
  42558. * children: ...
  42559. * },
  42560. * ...
  42561. * ]
  42562. * }
  42563. *
  42564. * @static
  42565. * @param {Object} dataRoot Root node.
  42566. * @param {module:echarts/model/Model} hostModel
  42567. * @param {Object} treeOptions
  42568. * @param {Array.<Object>} treeOptions.levels
  42569. * @param {Array.<Object>} treeOptions.leaves
  42570. * @return module:echarts/data/Tree
  42571. */
  42572. Tree.createTree = function (dataRoot, hostModel, treeOptions) {
  42573. var tree = new Tree(hostModel, treeOptions.levels, treeOptions.leaves);
  42574. var listData = [];
  42575. var dimMax = 1;
  42576. buildHierarchy(dataRoot);
  42577. function buildHierarchy(dataNode, parentNode) {
  42578. var value = dataNode.value;
  42579. dimMax = Math.max(dimMax, isArray(value) ? value.length : 1);
  42580. listData.push(dataNode);
  42581. var node = new TreeNode(dataNode.name, tree);
  42582. parentNode
  42583. ? addChild(node, parentNode)
  42584. : (tree.root = node);
  42585. tree._nodes.push(node);
  42586. var children = dataNode.children;
  42587. if (children) {
  42588. for (var i = 0; i < children.length; i++) {
  42589. buildHierarchy(children[i], node);
  42590. }
  42591. }
  42592. }
  42593. tree.root.updateDepthAndHeight(0);
  42594. var dimensionsInfo = createDimensions(listData, {
  42595. coordDimensions: ['value'],
  42596. dimensionsCount: dimMax
  42597. });
  42598. var list = new List(dimensionsInfo, hostModel);
  42599. list.initData(listData);
  42600. linkList({
  42601. mainData: list,
  42602. struct: tree,
  42603. structAttr: 'tree'
  42604. });
  42605. tree.update();
  42606. return tree;
  42607. };
  42608. /**
  42609. * It is needed to consider the mess of 'list', 'hostModel' when creating a TreeNote,
  42610. * so this function is not ready and not necessary to be public.
  42611. *
  42612. * @param {(module:echarts/data/Tree~TreeNode|Object)} child
  42613. */
  42614. function addChild(child, node) {
  42615. var children = node.children;
  42616. if (child.parentNode === node) {
  42617. return;
  42618. }
  42619. children.push(child);
  42620. child.parentNode = node;
  42621. }
  42622. /*
  42623. * Licensed to the Apache Software Foundation (ASF) under one
  42624. * or more contributor license agreements. See the NOTICE file
  42625. * distributed with this work for additional information
  42626. * regarding copyright ownership. The ASF licenses this file
  42627. * to you under the Apache License, Version 2.0 (the
  42628. * "License"); you may not use this file except in compliance
  42629. * with the License. You may obtain a copy of the License at
  42630. *
  42631. * http://www.apache.org/licenses/LICENSE-2.0
  42632. *
  42633. * Unless required by applicable law or agreed to in writing,
  42634. * software distributed under the License is distributed on an
  42635. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  42636. * KIND, either express or implied. See the License for the
  42637. * specific language governing permissions and limitations
  42638. * under the License.
  42639. */
  42640. SeriesModel.extend({
  42641. type: 'series.tree',
  42642. layoutInfo: null,
  42643. // can support the position parameters 'left', 'top','right','bottom', 'width',
  42644. // 'height' in the setOption() with 'merge' mode normal.
  42645. layoutMode: 'box',
  42646. /**
  42647. * Init a tree data structure from data in option series
  42648. * @param {Object} option the object used to config echarts view
  42649. * @return {module:echarts/data/List} storage initial data
  42650. */
  42651. getInitialData: function (option) {
  42652. //create an virtual root
  42653. var root = {name: option.name, children: option.data};
  42654. var leaves = option.leaves || {};
  42655. var treeOption = {};
  42656. treeOption.leaves = leaves;
  42657. var tree = Tree.createTree(root, this, treeOption);
  42658. var treeDepth = 0;
  42659. tree.eachNode('preorder', function (node) {
  42660. if (node.depth > treeDepth) {
  42661. treeDepth = node.depth;
  42662. }
  42663. });
  42664. var expandAndCollapse = option.expandAndCollapse;
  42665. var expandTreeDepth = (expandAndCollapse && option.initialTreeDepth >= 0)
  42666. ? option.initialTreeDepth : treeDepth;
  42667. tree.root.eachNode('preorder', function (node) {
  42668. var item = node.hostTree.data.getRawDataItem(node.dataIndex);
  42669. // Add item.collapsed != null, because users can collapse node original in the series.data.
  42670. node.isExpand = (item && item.collapsed != null)
  42671. ? !item.collapsed
  42672. : node.depth <= expandTreeDepth;
  42673. });
  42674. return tree.data;
  42675. },
  42676. /**
  42677. * Make the configuration 'orient' backward compatibly, with 'horizontal = LR', 'vertical = TB'.
  42678. * @returns {string} orient
  42679. */
  42680. getOrient: function () {
  42681. var orient = this.get('orient');
  42682. if (orient === 'horizontal') {
  42683. orient = 'LR';
  42684. }
  42685. else if (orient === 'vertical') {
  42686. orient = 'TB';
  42687. }
  42688. return orient;
  42689. },
  42690. setZoom: function (zoom) {
  42691. this.option.zoom = zoom;
  42692. },
  42693. setCenter: function (center) {
  42694. this.option.center = center;
  42695. },
  42696. /**
  42697. * @override
  42698. * @param {number} dataIndex
  42699. */
  42700. formatTooltip: function (dataIndex) {
  42701. var tree = this.getData().tree;
  42702. var realRoot = tree.root.children[0];
  42703. var node = tree.getNodeByDataIndex(dataIndex);
  42704. var value = node.getValue();
  42705. var name = node.name;
  42706. while (node && (node !== realRoot)) {
  42707. name = node.parentNode.name + '.' + name;
  42708. node = node.parentNode;
  42709. }
  42710. return encodeHTML(name + (
  42711. (isNaN(value) || value == null) ? '' : ' : ' + value
  42712. ));
  42713. },
  42714. defaultOption: {
  42715. zlevel: 0,
  42716. z: 2,
  42717. coordinateSystem: 'view',
  42718. // the position of the whole view
  42719. left: '12%',
  42720. top: '12%',
  42721. right: '12%',
  42722. bottom: '12%',
  42723. // the layout of the tree, two value can be selected, 'orthogonal' or 'radial'
  42724. layout: 'orthogonal',
  42725. roam: false, // true | false | 'move' | 'scale', see module:component/helper/RoamController.
  42726. // Symbol size scale ratio in roam
  42727. nodeScaleRatio: 0.4,
  42728. // Default on center of graph
  42729. center: null,
  42730. zoom: 1,
  42731. // The orient of orthoginal layout, can be setted to 'LR', 'TB', 'RL', 'BT'.
  42732. // and the backward compatibility configuration 'horizontal = LR', 'vertical = TB'.
  42733. orient: 'LR',
  42734. symbol: 'emptyCircle',
  42735. symbolSize: 7,
  42736. expandAndCollapse: true,
  42737. initialTreeDepth: 2,
  42738. lineStyle: {
  42739. color: '#ccc',
  42740. width: 1.5,
  42741. curveness: 0.5
  42742. },
  42743. itemStyle: {
  42744. color: 'lightsteelblue',
  42745. borderColor: '#c23531',
  42746. borderWidth: 1.5
  42747. },
  42748. label: {
  42749. show: true,
  42750. color: '#555'
  42751. },
  42752. leaves: {
  42753. label: {
  42754. show: true
  42755. }
  42756. },
  42757. animationEasing: 'linear',
  42758. animationDuration: 700,
  42759. animationDurationUpdate: 1000
  42760. }
  42761. });
  42762. /*
  42763. * Licensed to the Apache Software Foundation (ASF) under one
  42764. * or more contributor license agreements. See the NOTICE file
  42765. * distributed with this work for additional information
  42766. * regarding copyright ownership. The ASF licenses this file
  42767. * to you under the Apache License, Version 2.0 (the
  42768. * "License"); you may not use this file except in compliance
  42769. * with the License. You may obtain a copy of the License at
  42770. *
  42771. * http://www.apache.org/licenses/LICENSE-2.0
  42772. *
  42773. * Unless required by applicable law or agreed to in writing,
  42774. * software distributed under the License is distributed on an
  42775. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  42776. * KIND, either express or implied. See the License for the
  42777. * specific language governing permissions and limitations
  42778. * under the License.
  42779. */
  42780. /*
  42781. * A third-party license is embeded for some of the code in this file:
  42782. * The tree layoutHelper implementation was originally copied from
  42783. * "d3.js"(https://github.com/d3/d3-hierarchy) with
  42784. * some modifications made for this project.
  42785. * (see more details in the comment of the specific method below.)
  42786. * The use of the source code of this file is also subject to the terms
  42787. * and consitions of the licence of "d3.js" (BSD-3Clause, see
  42788. * </licenses/LICENSE-d3>).
  42789. */
  42790. /**
  42791. * @file The layout algorithm of node-link tree diagrams. Here we using Reingold-Tilford algorithm to drawing
  42792. * the tree.
  42793. */
  42794. /**
  42795. * Initialize all computational message for following algorithm.
  42796. *
  42797. * @param {module:echarts/data/Tree~TreeNode} root The virtual root of the tree.
  42798. */
  42799. function init$2(root) {
  42800. root.hierNode = {
  42801. defaultAncestor: null,
  42802. ancestor: root,
  42803. prelim: 0,
  42804. modifier: 0,
  42805. change: 0,
  42806. shift: 0,
  42807. i: 0,
  42808. thread: null
  42809. };
  42810. var nodes = [root];
  42811. var node;
  42812. var children;
  42813. while (node = nodes.pop()) { // jshint ignore:line
  42814. children = node.children;
  42815. if (node.isExpand && children.length) {
  42816. var n = children.length;
  42817. for (var i = n - 1; i >= 0; i--) {
  42818. var child = children[i];
  42819. child.hierNode = {
  42820. defaultAncestor: null,
  42821. ancestor: child,
  42822. prelim: 0,
  42823. modifier: 0,
  42824. change: 0,
  42825. shift: 0,
  42826. i: i,
  42827. thread: null
  42828. };
  42829. nodes.push(child);
  42830. }
  42831. }
  42832. }
  42833. }
  42834. /**
  42835. * The implementation of this function was originally copied from "d3.js"
  42836. * <https://github.com/d3/d3-hierarchy/blob/4c1f038f2725d6eae2e49b61d01456400694bac4/src/tree.js>
  42837. * with some modifications made for this program.
  42838. * See the license statement at the head of this file.
  42839. *
  42840. * Computes a preliminary x coordinate for node. Before that, this function is
  42841. * applied recursively to the children of node, as well as the function
  42842. * apportion(). After spacing out the children by calling executeShifts(), the
  42843. * node is placed to the midpoint of its outermost children.
  42844. *
  42845. * @param {module:echarts/data/Tree~TreeNode} node
  42846. * @param {Function} separation
  42847. */
  42848. function firstWalk(node, separation) {
  42849. var children = node.isExpand ? node.children : [];
  42850. var siblings = node.parentNode.children;
  42851. var subtreeW = node.hierNode.i ? siblings[node.hierNode.i - 1] : null;
  42852. if (children.length) {
  42853. executeShifts(node);
  42854. var midPoint = (children[0].hierNode.prelim + children[children.length - 1].hierNode.prelim) / 2;
  42855. if (subtreeW) {
  42856. node.hierNode.prelim = subtreeW.hierNode.prelim + separation(node, subtreeW);
  42857. node.hierNode.modifier = node.hierNode.prelim - midPoint;
  42858. }
  42859. else {
  42860. node.hierNode.prelim = midPoint;
  42861. }
  42862. }
  42863. else if (subtreeW) {
  42864. node.hierNode.prelim = subtreeW.hierNode.prelim + separation(node, subtreeW);
  42865. }
  42866. node.parentNode.hierNode.defaultAncestor = apportion(
  42867. node,
  42868. subtreeW,
  42869. node.parentNode.hierNode.defaultAncestor || siblings[0],
  42870. separation
  42871. );
  42872. }
  42873. /**
  42874. * The implementation of this function was originally copied from "d3.js"
  42875. * <https://github.com/d3/d3-hierarchy/blob/4c1f038f2725d6eae2e49b61d01456400694bac4/src/tree.js>
  42876. * with some modifications made for this program.
  42877. * See the license statement at the head of this file.
  42878. *
  42879. * Computes all real x-coordinates by summing up the modifiers recursively.
  42880. *
  42881. * @param {module:echarts/data/Tree~TreeNode} node
  42882. */
  42883. function secondWalk(node) {
  42884. var nodeX = node.hierNode.prelim + node.parentNode.hierNode.modifier;
  42885. node.setLayout({x: nodeX}, true);
  42886. node.hierNode.modifier += node.parentNode.hierNode.modifier;
  42887. }
  42888. function separation(cb) {
  42889. return arguments.length ? cb : defaultSeparation;
  42890. }
  42891. /**
  42892. * Transform the common coordinate to radial coordinate.
  42893. *
  42894. * @param {number} x
  42895. * @param {number} y
  42896. * @return {Object}
  42897. */
  42898. function radialCoordinate(x, y) {
  42899. var radialCoor = {};
  42900. x -= Math.PI / 2;
  42901. radialCoor.x = y * Math.cos(x);
  42902. radialCoor.y = y * Math.sin(x);
  42903. return radialCoor;
  42904. }
  42905. /**
  42906. * Get the layout position of the whole view.
  42907. *
  42908. * @param {module:echarts/model/Series} seriesModel the model object of sankey series
  42909. * @param {module:echarts/ExtensionAPI} api provide the API list that the developer can call
  42910. * @return {module:zrender/core/BoundingRect} size of rect to draw the sankey view
  42911. */
  42912. function getViewRect(seriesModel, api) {
  42913. return getLayoutRect(
  42914. seriesModel.getBoxLayoutParams(), {
  42915. width: api.getWidth(),
  42916. height: api.getHeight()
  42917. }
  42918. );
  42919. }
  42920. /**
  42921. * All other shifts, applied to the smaller subtrees between w- and w+, are
  42922. * performed by this function.
  42923. *
  42924. * The implementation of this function was originally copied from "d3.js"
  42925. * <https://github.com/d3/d3-hierarchy/blob/4c1f038f2725d6eae2e49b61d01456400694bac4/src/tree.js>
  42926. * with some modifications made for this program.
  42927. * See the license statement at the head of this file.
  42928. *
  42929. * @param {module:echarts/data/Tree~TreeNode} node
  42930. */
  42931. function executeShifts(node) {
  42932. var children = node.children;
  42933. var n = children.length;
  42934. var shift = 0;
  42935. var change = 0;
  42936. while (--n >= 0) {
  42937. var child = children[n];
  42938. child.hierNode.prelim += shift;
  42939. child.hierNode.modifier += shift;
  42940. change += child.hierNode.change;
  42941. shift += child.hierNode.shift + change;
  42942. }
  42943. }
  42944. /**
  42945. * The implementation of this function was originally copied from "d3.js"
  42946. * <https://github.com/d3/d3-hierarchy/blob/4c1f038f2725d6eae2e49b61d01456400694bac4/src/tree.js>
  42947. * with some modifications made for this program.
  42948. * See the license statement at the head of this file.
  42949. *
  42950. * The core of the algorithm. Here, a new subtree is combined with the
  42951. * previous subtrees. Threads are used to traverse the inside and outside
  42952. * contours of the left and right subtree up to the highest common level.
  42953. * Whenever two nodes of the inside contours conflict, we compute the left
  42954. * one of the greatest uncommon ancestors using the function nextAncestor()
  42955. * and call moveSubtree() to shift the subtree and prepare the shifts of
  42956. * smaller subtrees. Finally, we add a new thread (if necessary).
  42957. *
  42958. * @param {module:echarts/data/Tree~TreeNode} subtreeV
  42959. * @param {module:echarts/data/Tree~TreeNode} subtreeW
  42960. * @param {module:echarts/data/Tree~TreeNode} ancestor
  42961. * @param {Function} separation
  42962. * @return {module:echarts/data/Tree~TreeNode}
  42963. */
  42964. function apportion(subtreeV, subtreeW, ancestor, separation) {
  42965. if (subtreeW) {
  42966. var nodeOutRight = subtreeV;
  42967. var nodeInRight = subtreeV;
  42968. var nodeOutLeft = nodeInRight.parentNode.children[0];
  42969. var nodeInLeft = subtreeW;
  42970. var sumOutRight = nodeOutRight.hierNode.modifier;
  42971. var sumInRight = nodeInRight.hierNode.modifier;
  42972. var sumOutLeft = nodeOutLeft.hierNode.modifier;
  42973. var sumInLeft = nodeInLeft.hierNode.modifier;
  42974. while (nodeInLeft = nextRight(nodeInLeft), nodeInRight = nextLeft(nodeInRight), nodeInLeft && nodeInRight) {
  42975. nodeOutRight = nextRight(nodeOutRight);
  42976. nodeOutLeft = nextLeft(nodeOutLeft);
  42977. nodeOutRight.hierNode.ancestor = subtreeV;
  42978. var shift = nodeInLeft.hierNode.prelim + sumInLeft - nodeInRight.hierNode.prelim
  42979. - sumInRight + separation(nodeInLeft, nodeInRight);
  42980. if (shift > 0) {
  42981. moveSubtree(nextAncestor(nodeInLeft, subtreeV, ancestor), subtreeV, shift);
  42982. sumInRight += shift;
  42983. sumOutRight += shift;
  42984. }
  42985. sumInLeft += nodeInLeft.hierNode.modifier;
  42986. sumInRight += nodeInRight.hierNode.modifier;
  42987. sumOutRight += nodeOutRight.hierNode.modifier;
  42988. sumOutLeft += nodeOutLeft.hierNode.modifier;
  42989. }
  42990. if (nodeInLeft && !nextRight(nodeOutRight)) {
  42991. nodeOutRight.hierNode.thread = nodeInLeft;
  42992. nodeOutRight.hierNode.modifier += sumInLeft - sumOutRight;
  42993. }
  42994. if (nodeInRight && !nextLeft(nodeOutLeft)) {
  42995. nodeOutLeft.hierNode.thread = nodeInRight;
  42996. nodeOutLeft.hierNode.modifier += sumInRight - sumOutLeft;
  42997. ancestor = subtreeV;
  42998. }
  42999. }
  43000. return ancestor;
  43001. }
  43002. /**
  43003. * This function is used to traverse the right contour of a subtree.
  43004. * It returns the rightmost child of node or the thread of node. The function
  43005. * returns null if and only if node is on the highest depth of its subtree.
  43006. *
  43007. * @param {module:echarts/data/Tree~TreeNode} node
  43008. * @return {module:echarts/data/Tree~TreeNode}
  43009. */
  43010. function nextRight(node) {
  43011. var children = node.children;
  43012. return children.length && node.isExpand ? children[children.length - 1] : node.hierNode.thread;
  43013. }
  43014. /**
  43015. * This function is used to traverse the left contour of a subtree (or a subforest).
  43016. * It returns the leftmost child of node or the thread of node. The function
  43017. * returns null if and only if node is on the highest depth of its subtree.
  43018. *
  43019. * @param {module:echarts/data/Tree~TreeNode} node
  43020. * @return {module:echarts/data/Tree~TreeNode}
  43021. */
  43022. function nextLeft(node) {
  43023. var children = node.children;
  43024. return children.length && node.isExpand ? children[0] : node.hierNode.thread;
  43025. }
  43026. /**
  43027. * If nodeInLeft’s ancestor is a sibling of node, returns nodeInLeft’s ancestor.
  43028. * Otherwise, returns the specified ancestor.
  43029. *
  43030. * @param {module:echarts/data/Tree~TreeNode} nodeInLeft
  43031. * @param {module:echarts/data/Tree~TreeNode} node
  43032. * @param {module:echarts/data/Tree~TreeNode} ancestor
  43033. * @return {module:echarts/data/Tree~TreeNode}
  43034. */
  43035. function nextAncestor(nodeInLeft, node, ancestor) {
  43036. return nodeInLeft.hierNode.ancestor.parentNode === node.parentNode
  43037. ? nodeInLeft.hierNode.ancestor : ancestor;
  43038. }
  43039. /**
  43040. * The implementation of this function was originally copied from "d3.js"
  43041. * <https://github.com/d3/d3-hierarchy/blob/4c1f038f2725d6eae2e49b61d01456400694bac4/src/tree.js>
  43042. * with some modifications made for this program.
  43043. * See the license statement at the head of this file.
  43044. *
  43045. * Shifts the current subtree rooted at wr.
  43046. * This is done by increasing prelim(w+) and modifier(w+) by shift.
  43047. *
  43048. * @param {module:echarts/data/Tree~TreeNode} wl
  43049. * @param {module:echarts/data/Tree~TreeNode} wr
  43050. * @param {number} shift [description]
  43051. */
  43052. function moveSubtree(wl, wr, shift) {
  43053. var change = shift / (wr.hierNode.i - wl.hierNode.i);
  43054. wr.hierNode.change -= change;
  43055. wr.hierNode.shift += shift;
  43056. wr.hierNode.modifier += shift;
  43057. wr.hierNode.prelim += shift;
  43058. wl.hierNode.change += change;
  43059. }
  43060. /**
  43061. * The implementation of this function was originally copied from "d3.js"
  43062. * <https://github.com/d3/d3-hierarchy/blob/4c1f038f2725d6eae2e49b61d01456400694bac4/src/tree.js>
  43063. * with some modifications made for this program.
  43064. * See the license statement at the head of this file.
  43065. */
  43066. function defaultSeparation(node1, node2) {
  43067. return node1.parentNode === node2.parentNode ? 1 : 2;
  43068. }
  43069. /*
  43070. * Licensed to the Apache Software Foundation (ASF) under one
  43071. * or more contributor license agreements. See the NOTICE file
  43072. * distributed with this work for additional information
  43073. * regarding copyright ownership. The ASF licenses this file
  43074. * to you under the Apache License, Version 2.0 (the
  43075. * "License"); you may not use this file except in compliance
  43076. * with the License. You may obtain a copy of the License at
  43077. *
  43078. * http://www.apache.org/licenses/LICENSE-2.0
  43079. *
  43080. * Unless required by applicable law or agreed to in writing,
  43081. * software distributed under the License is distributed on an
  43082. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  43083. * KIND, either express or implied. See the License for the
  43084. * specific language governing permissions and limitations
  43085. * under the License.
  43086. */
  43087. extendChartView({
  43088. type: 'tree',
  43089. /**
  43090. * Init the chart
  43091. * @override
  43092. * @param {module:echarts/model/Global} ecModel
  43093. * @param {module:echarts/ExtensionAPI} api
  43094. */
  43095. init: function (ecModel, api) {
  43096. /**
  43097. * @private
  43098. * @type {module:echarts/data/Tree}
  43099. */
  43100. this._oldTree;
  43101. /**
  43102. * @private
  43103. * @type {module:zrender/container/Group}
  43104. */
  43105. this._mainGroup = new Group();
  43106. /**
  43107. * @private
  43108. * @type {module:echarts/componet/helper/RoamController}
  43109. */
  43110. this._controller = new RoamController(api.getZr());
  43111. this._controllerHost = {target: this.group};
  43112. this.group.add(this._mainGroup);
  43113. },
  43114. render: function (seriesModel, ecModel, api, payload) {
  43115. var data = seriesModel.getData();
  43116. var layoutInfo = seriesModel.layoutInfo;
  43117. var group = this._mainGroup;
  43118. var layout = seriesModel.get('layout');
  43119. if (layout === 'radial') {
  43120. group.attr('position', [layoutInfo.x + layoutInfo.width / 2, layoutInfo.y + layoutInfo.height / 2]);
  43121. }
  43122. else {
  43123. group.attr('position', [layoutInfo.x, layoutInfo.y]);
  43124. }
  43125. this._updateViewCoordSys(seriesModel);
  43126. this._updateController(seriesModel, ecModel, api);
  43127. var oldData = this._data;
  43128. var seriesScope = {
  43129. expandAndCollapse: seriesModel.get('expandAndCollapse'),
  43130. layout: layout,
  43131. orient: seriesModel.getOrient(),
  43132. curvature: seriesModel.get('lineStyle.curveness'),
  43133. symbolRotate: seriesModel.get('symbolRotate'),
  43134. symbolOffset: seriesModel.get('symbolOffset'),
  43135. hoverAnimation: seriesModel.get('hoverAnimation'),
  43136. useNameLabel: true,
  43137. fadeIn: true
  43138. };
  43139. data.diff(oldData)
  43140. .add(function (newIdx) {
  43141. if (symbolNeedsDraw$1(data, newIdx)) {
  43142. // Create node and edge
  43143. updateNode(data, newIdx, null, group, seriesModel, seriesScope);
  43144. }
  43145. })
  43146. .update(function (newIdx, oldIdx) {
  43147. var symbolEl = oldData.getItemGraphicEl(oldIdx);
  43148. if (!symbolNeedsDraw$1(data, newIdx)) {
  43149. symbolEl && removeNode(oldData, oldIdx, symbolEl, group, seriesModel, seriesScope);
  43150. return;
  43151. }
  43152. // Update node and edge
  43153. updateNode(data, newIdx, symbolEl, group, seriesModel, seriesScope);
  43154. })
  43155. .remove(function (oldIdx) {
  43156. var symbolEl = oldData.getItemGraphicEl(oldIdx);
  43157. // When remove a collapsed node of subtree, since the collapsed
  43158. // node haven't been initialized with a symbol element,
  43159. // you can't found it's symbol element through index.
  43160. // so if we want to remove the symbol element we should insure
  43161. // that the symbol element is not null.
  43162. if (symbolEl) {
  43163. removeNode(oldData, oldIdx, symbolEl, group, seriesModel, seriesScope);
  43164. }
  43165. })
  43166. .execute();
  43167. this._nodeScaleRatio = seriesModel.get('nodeScaleRatio');
  43168. this._updateNodeAndLinkScale(seriesModel);
  43169. if (seriesScope.expandAndCollapse === true) {
  43170. data.eachItemGraphicEl(function (el, dataIndex) {
  43171. el.off('click').on('click', function () {
  43172. api.dispatchAction({
  43173. type: 'treeExpandAndCollapse',
  43174. seriesId: seriesModel.id,
  43175. dataIndex: dataIndex
  43176. });
  43177. });
  43178. });
  43179. }
  43180. this._data = data;
  43181. },
  43182. _updateViewCoordSys: function (seriesModel) {
  43183. var data = seriesModel.getData();
  43184. var points = [];
  43185. data.each(function (idx) {
  43186. var layout = data.getItemLayout(idx);
  43187. if (layout && !isNaN(layout.x) && !isNaN(layout.y)) {
  43188. points.push([+layout.x, +layout.y]);
  43189. }
  43190. });
  43191. var min = [];
  43192. var max = [];
  43193. fromPoints(points, min, max);
  43194. // If width or height is 0
  43195. if (max[0] - min[0] === 0) {
  43196. max[0] += 1;
  43197. min[0] -= 1;
  43198. }
  43199. if (max[1] - min[1] === 0) {
  43200. max[1] += 1;
  43201. min[1] -= 1;
  43202. }
  43203. var viewCoordSys = seriesModel.coordinateSystem = new View();
  43204. viewCoordSys.zoomLimit = seriesModel.get('scaleLimit');
  43205. viewCoordSys.setBoundingRect(min[0], min[1], max[0] - min[0], max[1] - min[1]);
  43206. viewCoordSys.setCenter(seriesModel.get('center'));
  43207. viewCoordSys.setZoom(seriesModel.get('zoom'));
  43208. // Here we use viewCoordSys just for computing the 'position' and 'scale' of the group
  43209. this.group.attr({
  43210. position: viewCoordSys.position,
  43211. scale: viewCoordSys.scale
  43212. });
  43213. this._viewCoordSys = viewCoordSys;
  43214. },
  43215. _updateController: function (seriesModel, ecModel, api) {
  43216. var controller = this._controller;
  43217. var controllerHost = this._controllerHost;
  43218. var group = this.group;
  43219. controller.setPointerChecker(function (e, x, y) {
  43220. var rect = group.getBoundingRect();
  43221. rect.applyTransform(group.transform);
  43222. return rect.contain(x, y)
  43223. && !onIrrelevantElement(e, api, seriesModel);
  43224. });
  43225. controller.enable(seriesModel.get('roam'));
  43226. controllerHost.zoomLimit = seriesModel.get('scaleLimit');
  43227. controllerHost.zoom = seriesModel.coordinateSystem.getZoom();
  43228. controller
  43229. .off('pan')
  43230. .off('zoom')
  43231. .on('pan', function (e) {
  43232. updateViewOnPan(controllerHost, e.dx, e.dy);
  43233. api.dispatchAction({
  43234. seriesId: seriesModel.id,
  43235. type: 'treeRoam',
  43236. dx: e.dx,
  43237. dy: e.dy
  43238. });
  43239. }, this)
  43240. .on('zoom', function (e) {
  43241. updateViewOnZoom(controllerHost, e.scale, e.originX, e.originY);
  43242. api.dispatchAction({
  43243. seriesId: seriesModel.id,
  43244. type: 'treeRoam',
  43245. zoom: e.scale,
  43246. originX: e.originX,
  43247. originY: e.originY
  43248. });
  43249. this._updateNodeAndLinkScale(seriesModel);
  43250. }, this);
  43251. },
  43252. _updateNodeAndLinkScale: function (seriesModel) {
  43253. var data = seriesModel.getData();
  43254. var nodeScale = this._getNodeGlobalScale(seriesModel);
  43255. var invScale = [nodeScale, nodeScale];
  43256. data.eachItemGraphicEl(function (el, idx) {
  43257. el.attr('scale', invScale);
  43258. });
  43259. },
  43260. _getNodeGlobalScale: function (seriesModel) {
  43261. var coordSys = seriesModel.coordinateSystem;
  43262. if (coordSys.type !== 'view') {
  43263. return 1;
  43264. }
  43265. var nodeScaleRatio = this._nodeScaleRatio;
  43266. var groupScale = coordSys.scale;
  43267. var groupZoom = (groupScale && groupScale[0]) || 1;
  43268. // Scale node when zoom changes
  43269. var roamZoom = coordSys.getZoom();
  43270. var nodeScale = (roamZoom - 1) * nodeScaleRatio + 1;
  43271. return nodeScale / groupZoom;
  43272. },
  43273. dispose: function () {
  43274. this._controller && this._controller.dispose();
  43275. this._controllerHost = {};
  43276. },
  43277. remove: function () {
  43278. this._mainGroup.removeAll();
  43279. this._data = null;
  43280. }
  43281. });
  43282. function symbolNeedsDraw$1(data, dataIndex) {
  43283. var layout = data.getItemLayout(dataIndex);
  43284. return layout
  43285. && !isNaN(layout.x) && !isNaN(layout.y)
  43286. && data.getItemVisual(dataIndex, 'symbol') !== 'none';
  43287. }
  43288. function getTreeNodeStyle(node, itemModel, seriesScope) {
  43289. seriesScope.itemModel = itemModel;
  43290. seriesScope.itemStyle = itemModel.getModel('itemStyle').getItemStyle();
  43291. seriesScope.hoverItemStyle = itemModel.getModel('emphasis.itemStyle').getItemStyle();
  43292. seriesScope.lineStyle = itemModel.getModel('lineStyle').getLineStyle();
  43293. seriesScope.labelModel = itemModel.getModel('label');
  43294. seriesScope.hoverLabelModel = itemModel.getModel('emphasis.label');
  43295. if (node.isExpand === false && node.children.length !== 0) {
  43296. seriesScope.symbolInnerColor = seriesScope.itemStyle.fill;
  43297. }
  43298. else {
  43299. seriesScope.symbolInnerColor = '#fff';
  43300. }
  43301. return seriesScope;
  43302. }
  43303. function updateNode(data, dataIndex, symbolEl, group, seriesModel, seriesScope) {
  43304. var isInit = !symbolEl;
  43305. var node = data.tree.getNodeByDataIndex(dataIndex);
  43306. var itemModel = node.getModel();
  43307. var seriesScope = getTreeNodeStyle(node, itemModel, seriesScope);
  43308. var virtualRoot = data.tree.root;
  43309. var source = node.parentNode === virtualRoot ? node : node.parentNode || node;
  43310. var sourceSymbolEl = data.getItemGraphicEl(source.dataIndex);
  43311. var sourceLayout = source.getLayout();
  43312. var sourceOldLayout = sourceSymbolEl
  43313. ? {
  43314. x: sourceSymbolEl.position[0],
  43315. y: sourceSymbolEl.position[1],
  43316. rawX: sourceSymbolEl.__radialOldRawX,
  43317. rawY: sourceSymbolEl.__radialOldRawY
  43318. }
  43319. : sourceLayout;
  43320. var targetLayout = node.getLayout();
  43321. if (isInit) {
  43322. symbolEl = new SymbolClz$1(data, dataIndex, seriesScope);
  43323. symbolEl.attr('position', [sourceOldLayout.x, sourceOldLayout.y]);
  43324. }
  43325. else {
  43326. symbolEl.updateData(data, dataIndex, seriesScope);
  43327. }
  43328. symbolEl.__radialOldRawX = symbolEl.__radialRawX;
  43329. symbolEl.__radialOldRawY = symbolEl.__radialRawY;
  43330. symbolEl.__radialRawX = targetLayout.rawX;
  43331. symbolEl.__radialRawY = targetLayout.rawY;
  43332. group.add(symbolEl);
  43333. data.setItemGraphicEl(dataIndex, symbolEl);
  43334. updateProps(symbolEl, {
  43335. position: [targetLayout.x, targetLayout.y]
  43336. }, seriesModel);
  43337. var symbolPath = symbolEl.getSymbolPath();
  43338. if (seriesScope.layout === 'radial') {
  43339. var realRoot = virtualRoot.children[0];
  43340. var rootLayout = realRoot.getLayout();
  43341. var length = realRoot.children.length;
  43342. var rad;
  43343. var isLeft;
  43344. if (targetLayout.x === rootLayout.x && node.isExpand === true) {
  43345. var center = {};
  43346. center.x = (realRoot.children[0].getLayout().x + realRoot.children[length - 1].getLayout().x) / 2;
  43347. center.y = (realRoot.children[0].getLayout().y + realRoot.children[length - 1].getLayout().y) / 2;
  43348. rad = Math.atan2(center.y - rootLayout.y, center.x - rootLayout.x);
  43349. if (rad < 0) {
  43350. rad = Math.PI * 2 + rad;
  43351. }
  43352. isLeft = center.x < rootLayout.x;
  43353. if (isLeft) {
  43354. rad = rad - Math.PI;
  43355. }
  43356. }
  43357. else {
  43358. rad = Math.atan2(targetLayout.y - rootLayout.y, targetLayout.x - rootLayout.x);
  43359. if (rad < 0) {
  43360. rad = Math.PI * 2 + rad;
  43361. }
  43362. if (node.children.length === 0 || (node.children.length !== 0 && node.isExpand === false)) {
  43363. isLeft = targetLayout.x < rootLayout.x;
  43364. if (isLeft) {
  43365. rad = rad - Math.PI;
  43366. }
  43367. }
  43368. else {
  43369. isLeft = targetLayout.x > rootLayout.x;
  43370. if (!isLeft) {
  43371. rad = rad - Math.PI;
  43372. }
  43373. }
  43374. }
  43375. var textPosition = isLeft ? 'left' : 'right';
  43376. symbolPath.setStyle({
  43377. textPosition: textPosition,
  43378. textRotation: -rad,
  43379. textOrigin: 'center',
  43380. verticalAlign: 'middle'
  43381. });
  43382. }
  43383. if (node.parentNode && node.parentNode !== virtualRoot) {
  43384. var edge = symbolEl.__edge;
  43385. if (!edge) {
  43386. edge = symbolEl.__edge = new BezierCurve({
  43387. shape: getEdgeShape(seriesScope, sourceOldLayout, sourceOldLayout),
  43388. style: defaults({opacity: 0, strokeNoScale: true}, seriesScope.lineStyle)
  43389. });
  43390. }
  43391. updateProps(edge, {
  43392. shape: getEdgeShape(seriesScope, sourceLayout, targetLayout),
  43393. style: {opacity: 1}
  43394. }, seriesModel);
  43395. group.add(edge);
  43396. }
  43397. }
  43398. function removeNode(data, dataIndex, symbolEl, group, seriesModel, seriesScope) {
  43399. var node = data.tree.getNodeByDataIndex(dataIndex);
  43400. var virtualRoot = data.tree.root;
  43401. var itemModel = node.getModel();
  43402. var seriesScope = getTreeNodeStyle(node, itemModel, seriesScope);
  43403. var source = node.parentNode === virtualRoot ? node : node.parentNode || node;
  43404. var sourceLayout;
  43405. while (sourceLayout = source.getLayout(), sourceLayout == null) {
  43406. source = source.parentNode === virtualRoot ? source : source.parentNode || source;
  43407. }
  43408. updateProps(symbolEl, {
  43409. position: [sourceLayout.x + 1, sourceLayout.y + 1]
  43410. }, seriesModel, function () {
  43411. group.remove(symbolEl);
  43412. data.setItemGraphicEl(dataIndex, null);
  43413. });
  43414. symbolEl.fadeOut(null, {keepLabel: true});
  43415. var edge = symbolEl.__edge;
  43416. if (edge) {
  43417. updateProps(edge, {
  43418. shape: getEdgeShape(seriesScope, sourceLayout, sourceLayout),
  43419. style: {
  43420. opacity: 0
  43421. }
  43422. }, seriesModel, function () {
  43423. group.remove(edge);
  43424. });
  43425. }
  43426. }
  43427. function getEdgeShape(seriesScope, sourceLayout, targetLayout) {
  43428. var cpx1;
  43429. var cpy1;
  43430. var cpx2;
  43431. var cpy2;
  43432. var orient = seriesScope.orient;
  43433. var x1;
  43434. var x2;
  43435. var y1;
  43436. var y2;
  43437. if (seriesScope.layout === 'radial') {
  43438. x1 = sourceLayout.rawX;
  43439. y1 = sourceLayout.rawY;
  43440. x2 = targetLayout.rawX;
  43441. y2 = targetLayout.rawY;
  43442. var radialCoor1 = radialCoordinate(x1, y1);
  43443. var radialCoor2 = radialCoordinate(x1, y1 + (y2 - y1) * seriesScope.curvature);
  43444. var radialCoor3 = radialCoordinate(x2, y2 + (y1 - y2) * seriesScope.curvature);
  43445. var radialCoor4 = radialCoordinate(x2, y2);
  43446. return {
  43447. x1: radialCoor1.x,
  43448. y1: radialCoor1.y,
  43449. x2: radialCoor4.x,
  43450. y2: radialCoor4.y,
  43451. cpx1: radialCoor2.x,
  43452. cpy1: radialCoor2.y,
  43453. cpx2: radialCoor3.x,
  43454. cpy2: radialCoor3.y
  43455. };
  43456. }
  43457. else {
  43458. x1 = sourceLayout.x;
  43459. y1 = sourceLayout.y;
  43460. x2 = targetLayout.x;
  43461. y2 = targetLayout.y;
  43462. if (orient === 'LR' || orient === 'RL') {
  43463. cpx1 = x1 + (x2 - x1) * seriesScope.curvature;
  43464. cpy1 = y1;
  43465. cpx2 = x2 + (x1 - x2) * seriesScope.curvature;
  43466. cpy2 = y2;
  43467. }
  43468. if (orient === 'TB' || orient === 'BT') {
  43469. cpx1 = x1;
  43470. cpy1 = y1 + (y2 - y1) * seriesScope.curvature;
  43471. cpx2 = x2;
  43472. cpy2 = y2 + (y1 - y2) * seriesScope.curvature;
  43473. }
  43474. }
  43475. return {
  43476. x1: x1,
  43477. y1: y1,
  43478. x2: x2,
  43479. y2: y2,
  43480. cpx1: cpx1,
  43481. cpy1: cpy1,
  43482. cpx2: cpx2,
  43483. cpy2: cpy2
  43484. };
  43485. }
  43486. /*
  43487. * Licensed to the Apache Software Foundation (ASF) under one
  43488. * or more contributor license agreements. See the NOTICE file
  43489. * distributed with this work for additional information
  43490. * regarding copyright ownership. The ASF licenses this file
  43491. * to you under the Apache License, Version 2.0 (the
  43492. * "License"); you may not use this file except in compliance
  43493. * with the License. You may obtain a copy of the License at
  43494. *
  43495. * http://www.apache.org/licenses/LICENSE-2.0
  43496. *
  43497. * Unless required by applicable law or agreed to in writing,
  43498. * software distributed under the License is distributed on an
  43499. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  43500. * KIND, either express or implied. See the License for the
  43501. * specific language governing permissions and limitations
  43502. * under the License.
  43503. */
  43504. registerAction({
  43505. type: 'treeExpandAndCollapse',
  43506. event: 'treeExpandAndCollapse',
  43507. update: 'update'
  43508. }, function (payload, ecModel) {
  43509. ecModel.eachComponent({mainType: 'series', subType: 'tree', query: payload}, function (seriesModel) {
  43510. var dataIndex = payload.dataIndex;
  43511. var tree = seriesModel.getData().tree;
  43512. var node = tree.getNodeByDataIndex(dataIndex);
  43513. node.isExpand = !node.isExpand;
  43514. });
  43515. });
  43516. registerAction({
  43517. type: 'treeRoam',
  43518. event: 'treeRoam',
  43519. // Here we set 'none' instead of 'update', because roam action
  43520. // just need to update the transform matrix without having to recalculate
  43521. // the layout. So don't need to go through the whole update process, such
  43522. // as 'dataPrcocess', 'coordSystemUpdate', 'layout' and so on.
  43523. update: 'none'
  43524. }, function (payload, ecModel) {
  43525. ecModel.eachComponent({mainType: 'series', subType: 'tree', query: payload}, function (seriesModel) {
  43526. var coordSys = seriesModel.coordinateSystem;
  43527. var res = updateCenterAndZoom(coordSys, payload);
  43528. seriesModel.setCenter
  43529. && seriesModel.setCenter(res.center);
  43530. seriesModel.setZoom
  43531. && seriesModel.setZoom(res.zoom);
  43532. });
  43533. });
  43534. /*
  43535. * Licensed to the Apache Software Foundation (ASF) under one
  43536. * or more contributor license agreements. See the NOTICE file
  43537. * distributed with this work for additional information
  43538. * regarding copyright ownership. The ASF licenses this file
  43539. * to you under the Apache License, Version 2.0 (the
  43540. * "License"); you may not use this file except in compliance
  43541. * with the License. You may obtain a copy of the License at
  43542. *
  43543. * http://www.apache.org/licenses/LICENSE-2.0
  43544. *
  43545. * Unless required by applicable law or agreed to in writing,
  43546. * software distributed under the License is distributed on an
  43547. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  43548. * KIND, either express or implied. See the License for the
  43549. * specific language governing permissions and limitations
  43550. * under the License.
  43551. */
  43552. /**
  43553. * Traverse the tree from bottom to top and do something
  43554. * @param {module:echarts/data/Tree~TreeNode} root The real root of the tree
  43555. * @param {Function} callback
  43556. */
  43557. function eachAfter(root, callback, separation) {
  43558. var nodes = [root];
  43559. var next = [];
  43560. var node;
  43561. while (node = nodes.pop()) { // jshint ignore:line
  43562. next.push(node);
  43563. if (node.isExpand) {
  43564. var children = node.children;
  43565. if (children.length) {
  43566. for (var i = 0; i < children.length; i++) {
  43567. nodes.push(children[i]);
  43568. }
  43569. }
  43570. }
  43571. }
  43572. while (node = next.pop()) { // jshint ignore:line
  43573. callback(node, separation);
  43574. }
  43575. }
  43576. /**
  43577. * Traverse the tree from top to bottom and do something
  43578. * @param {module:echarts/data/Tree~TreeNode} root The real root of the tree
  43579. * @param {Function} callback
  43580. */
  43581. function eachBefore(root, callback) {
  43582. var nodes = [root];
  43583. var node;
  43584. while (node = nodes.pop()) { // jshint ignore:line
  43585. callback(node);
  43586. if (node.isExpand) {
  43587. var children = node.children;
  43588. if (children.length) {
  43589. for (var i = children.length - 1; i >= 0; i--) {
  43590. nodes.push(children[i]);
  43591. }
  43592. }
  43593. }
  43594. }
  43595. }
  43596. /*
  43597. * Licensed to the Apache Software Foundation (ASF) under one
  43598. * or more contributor license agreements. See the NOTICE file
  43599. * distributed with this work for additional information
  43600. * regarding copyright ownership. The ASF licenses this file
  43601. * to you under the Apache License, Version 2.0 (the
  43602. * "License"); you may not use this file except in compliance
  43603. * with the License. You may obtain a copy of the License at
  43604. *
  43605. * http://www.apache.org/licenses/LICENSE-2.0
  43606. *
  43607. * Unless required by applicable law or agreed to in writing,
  43608. * software distributed under the License is distributed on an
  43609. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  43610. * KIND, either express or implied. See the License for the
  43611. * specific language governing permissions and limitations
  43612. * under the License.
  43613. */
  43614. var treeLayout = function (ecModel, api) {
  43615. ecModel.eachSeriesByType('tree', function (seriesModel) {
  43616. commonLayout(seriesModel, api);
  43617. });
  43618. };
  43619. function commonLayout(seriesModel, api) {
  43620. var layoutInfo = getViewRect(seriesModel, api);
  43621. seriesModel.layoutInfo = layoutInfo;
  43622. var layout = seriesModel.get('layout');
  43623. var width = 0;
  43624. var height = 0;
  43625. var separation$$1 = null;
  43626. if (layout === 'radial') {
  43627. width = 2 * Math.PI;
  43628. height = Math.min(layoutInfo.height, layoutInfo.width) / 2;
  43629. separation$$1 = separation(function (node1, node2) {
  43630. return (node1.parentNode === node2.parentNode ? 1 : 2) / node1.depth;
  43631. });
  43632. }
  43633. else {
  43634. width = layoutInfo.width;
  43635. height = layoutInfo.height;
  43636. separation$$1 = separation();
  43637. }
  43638. var virtualRoot = seriesModel.getData().tree.root;
  43639. var realRoot = virtualRoot.children[0];
  43640. if (realRoot) {
  43641. init$2(virtualRoot);
  43642. eachAfter(realRoot, firstWalk, separation$$1);
  43643. virtualRoot.hierNode.modifier = -realRoot.hierNode.prelim;
  43644. eachBefore(realRoot, secondWalk);
  43645. var left = realRoot;
  43646. var right = realRoot;
  43647. var bottom = realRoot;
  43648. eachBefore(realRoot, function (node) {
  43649. var x = node.getLayout().x;
  43650. if (x < left.getLayout().x) {
  43651. left = node;
  43652. }
  43653. if (x > right.getLayout().x) {
  43654. right = node;
  43655. }
  43656. if (node.depth > bottom.depth) {
  43657. bottom = node;
  43658. }
  43659. });
  43660. var delta = left === right ? 1 : separation$$1(left, right) / 2;
  43661. var tx = delta - left.getLayout().x;
  43662. var kx = 0;
  43663. var ky = 0;
  43664. var coorX = 0;
  43665. var coorY = 0;
  43666. if (layout === 'radial') {
  43667. kx = width / (right.getLayout().x + delta + tx);
  43668. // here we use (node.depth - 1), bucause the real root's depth is 1
  43669. ky = height / ((bottom.depth - 1) || 1);
  43670. eachBefore(realRoot, function (node) {
  43671. coorX = (node.getLayout().x + tx) * kx;
  43672. coorY = (node.depth - 1) * ky;
  43673. var finalCoor = radialCoordinate(coorX, coorY);
  43674. node.setLayout({x: finalCoor.x, y: finalCoor.y, rawX: coorX, rawY: coorY}, true);
  43675. });
  43676. }
  43677. else {
  43678. var orient = seriesModel.getOrient();
  43679. if (orient === 'RL' || orient === 'LR') {
  43680. ky = height / (right.getLayout().x + delta + tx);
  43681. kx = width / ((bottom.depth - 1) || 1);
  43682. eachBefore(realRoot, function (node) {
  43683. coorY = (node.getLayout().x + tx) * ky;
  43684. coorX = orient === 'LR'
  43685. ? (node.depth - 1) * kx
  43686. : width - (node.depth - 1) * kx;
  43687. node.setLayout({x: coorX, y: coorY}, true);
  43688. });
  43689. }
  43690. else if (orient === 'TB' || orient === 'BT') {
  43691. kx = width / (right.getLayout().x + delta + tx);
  43692. ky = height / ((bottom.depth - 1) || 1);
  43693. eachBefore(realRoot, function (node) {
  43694. coorX = (node.getLayout().x + tx) * kx;
  43695. coorY = orient === 'TB'
  43696. ? (node.depth - 1) * ky
  43697. : height - (node.depth - 1) * ky;
  43698. node.setLayout({x: coorX, y: coorY}, true);
  43699. });
  43700. }
  43701. }
  43702. }
  43703. }
  43704. /*
  43705. * Licensed to the Apache Software Foundation (ASF) under one
  43706. * or more contributor license agreements. See the NOTICE file
  43707. * distributed with this work for additional information
  43708. * regarding copyright ownership. The ASF licenses this file
  43709. * to you under the Apache License, Version 2.0 (the
  43710. * "License"); you may not use this file except in compliance
  43711. * with the License. You may obtain a copy of the License at
  43712. *
  43713. * http://www.apache.org/licenses/LICENSE-2.0
  43714. *
  43715. * Unless required by applicable law or agreed to in writing,
  43716. * software distributed under the License is distributed on an
  43717. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  43718. * KIND, either express or implied. See the License for the
  43719. * specific language governing permissions and limitations
  43720. * under the License.
  43721. */
  43722. registerVisual(visualSymbol('tree', 'circle'));
  43723. registerLayout(treeLayout);
  43724. /*
  43725. * Licensed to the Apache Software Foundation (ASF) under one
  43726. * or more contributor license agreements. See the NOTICE file
  43727. * distributed with this work for additional information
  43728. * regarding copyright ownership. The ASF licenses this file
  43729. * to you under the Apache License, Version 2.0 (the
  43730. * "License"); you may not use this file except in compliance
  43731. * with the License. You may obtain a copy of the License at
  43732. *
  43733. * http://www.apache.org/licenses/LICENSE-2.0
  43734. *
  43735. * Unless required by applicable law or agreed to in writing,
  43736. * software distributed under the License is distributed on an
  43737. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  43738. * KIND, either express or implied. See the License for the
  43739. * specific language governing permissions and limitations
  43740. * under the License.
  43741. */
  43742. function retrieveTargetInfo(payload, validPayloadTypes, seriesModel) {
  43743. if (payload && indexOf(validPayloadTypes, payload.type) >= 0) {
  43744. var root = seriesModel.getData().tree.root;
  43745. var targetNode = payload.targetNode;
  43746. if (typeof targetNode === 'string') {
  43747. targetNode = root.getNodeById(targetNode);
  43748. }
  43749. if (targetNode && root.contains(targetNode)) {
  43750. return {node: targetNode};
  43751. }
  43752. var targetNodeId = payload.targetNodeId;
  43753. if (targetNodeId != null && (targetNode = root.getNodeById(targetNodeId))) {
  43754. return {node: targetNode};
  43755. }
  43756. }
  43757. }
  43758. // Not includes the given node at the last item.
  43759. function getPathToRoot(node) {
  43760. var path = [];
  43761. while (node) {
  43762. node = node.parentNode;
  43763. node && path.push(node);
  43764. }
  43765. return path.reverse();
  43766. }
  43767. function aboveViewRoot(viewRoot, node) {
  43768. var viewPath = getPathToRoot(viewRoot);
  43769. return indexOf(viewPath, node) >= 0;
  43770. }
  43771. // From root to the input node (the input node will be included).
  43772. function wrapTreePathInfo(node, seriesModel) {
  43773. var treePathInfo = [];
  43774. while (node) {
  43775. var nodeDataIndex = node.dataIndex;
  43776. treePathInfo.push({
  43777. name: node.name,
  43778. dataIndex: nodeDataIndex,
  43779. value: seriesModel.getRawValue(nodeDataIndex)
  43780. });
  43781. node = node.parentNode;
  43782. }
  43783. treePathInfo.reverse();
  43784. return treePathInfo;
  43785. }
  43786. /*
  43787. * Licensed to the Apache Software Foundation (ASF) under one
  43788. * or more contributor license agreements. See the NOTICE file
  43789. * distributed with this work for additional information
  43790. * regarding copyright ownership. The ASF licenses this file
  43791. * to you under the Apache License, Version 2.0 (the
  43792. * "License"); you may not use this file except in compliance
  43793. * with the License. You may obtain a copy of the License at
  43794. *
  43795. * http://www.apache.org/licenses/LICENSE-2.0
  43796. *
  43797. * Unless required by applicable law or agreed to in writing,
  43798. * software distributed under the License is distributed on an
  43799. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  43800. * KIND, either express or implied. See the License for the
  43801. * specific language governing permissions and limitations
  43802. * under the License.
  43803. */
  43804. SeriesModel.extend({
  43805. type: 'series.treemap',
  43806. layoutMode: 'box',
  43807. dependencies: ['grid', 'polar'],
  43808. preventUsingHoverLayer: true,
  43809. /**
  43810. * @type {module:echarts/data/Tree~Node}
  43811. */
  43812. _viewRoot: null,
  43813. defaultOption: {
  43814. // Disable progressive rendering
  43815. progressive: 0,
  43816. // center: ['50%', '50%'], // not supported in ec3.
  43817. // size: ['80%', '80%'], // deprecated, compatible with ec2.
  43818. left: 'center',
  43819. top: 'middle',
  43820. right: null,
  43821. bottom: null,
  43822. width: '80%',
  43823. height: '80%',
  43824. sort: true, // Can be null or false or true
  43825. // (order by desc default, asc not supported yet (strange effect))
  43826. clipWindow: 'origin', // Size of clipped window when zooming. 'origin' or 'fullscreen'
  43827. squareRatio: 0.5 * (1 + Math.sqrt(5)), // golden ratio
  43828. leafDepth: null, // Nodes on depth from root are regarded as leaves.
  43829. // Count from zero (zero represents only view root).
  43830. drillDownIcon: '▶', // Use html character temporarily because it is complicated
  43831. // to align specialized icon. ▷▶❒❐▼✚
  43832. zoomToNodeRatio: 0.32 * 0.32, // Be effective when using zoomToNode. Specify the proportion of the
  43833. // target node area in the view area.
  43834. roam: true, // true, false, 'scale' or 'zoom', 'move'.
  43835. nodeClick: 'zoomToNode', // Leaf node click behaviour: 'zoomToNode', 'link', false.
  43836. // If leafDepth is set and clicking a node which has children but
  43837. // be on left depth, the behaviour would be changing root. Otherwise
  43838. // use behavious defined above.
  43839. animation: true,
  43840. animationDurationUpdate: 900,
  43841. animationEasing: 'quinticInOut',
  43842. breadcrumb: {
  43843. show: true,
  43844. height: 22,
  43845. left: 'center',
  43846. top: 'bottom',
  43847. // right
  43848. // bottom
  43849. emptyItemWidth: 25, // Width of empty node.
  43850. itemStyle: {
  43851. color: 'rgba(0,0,0,0.7)', //'#5793f3',
  43852. borderColor: 'rgba(255,255,255,0.7)',
  43853. borderWidth: 1,
  43854. shadowColor: 'rgba(150,150,150,1)',
  43855. shadowBlur: 3,
  43856. shadowOffsetX: 0,
  43857. shadowOffsetY: 0,
  43858. textStyle: {
  43859. color: '#fff'
  43860. }
  43861. },
  43862. emphasis: {
  43863. textStyle: {}
  43864. }
  43865. },
  43866. label: {
  43867. show: true,
  43868. // Do not use textDistance, for ellipsis rect just the same as treemap node rect.
  43869. distance: 0,
  43870. padding: 5,
  43871. position: 'inside', // Can be [5, '5%'] or position stirng like 'insideTopLeft', ...
  43872. // formatter: null,
  43873. color: '#fff',
  43874. ellipsis: true
  43875. // align
  43876. // verticalAlign
  43877. },
  43878. upperLabel: { // Label when node is parent.
  43879. show: false,
  43880. position: [0, '50%'],
  43881. height: 20,
  43882. // formatter: null,
  43883. color: '#fff',
  43884. ellipsis: true,
  43885. // align: null,
  43886. verticalAlign: 'middle'
  43887. },
  43888. itemStyle: {
  43889. color: null, // Can be 'none' if not necessary.
  43890. colorAlpha: null, // Can be 'none' if not necessary.
  43891. colorSaturation: null, // Can be 'none' if not necessary.
  43892. borderWidth: 0,
  43893. gapWidth: 0,
  43894. borderColor: '#fff',
  43895. borderColorSaturation: null // If specified, borderColor will be ineffective, and the
  43896. // border color is evaluated by color of current node and
  43897. // borderColorSaturation.
  43898. },
  43899. emphasis: {
  43900. upperLabel: {
  43901. show: true,
  43902. position: [0, '50%'],
  43903. color: '#fff',
  43904. ellipsis: true,
  43905. verticalAlign: 'middle'
  43906. }
  43907. },
  43908. visualDimension: 0, // Can be 0, 1, 2, 3.
  43909. visualMin: null,
  43910. visualMax: null,
  43911. color: [], // + treemapSeries.color should not be modified. Please only modified
  43912. // level[n].color (if necessary).
  43913. // + Specify color list of each level. level[0].color would be global
  43914. // color list if not specified. (see method `setDefault`).
  43915. // + But set as a empty array to forbid fetch color from global palette
  43916. // when using nodeModel.get('color'), otherwise nodes on deep level
  43917. // will always has color palette set and are not able to inherit color
  43918. // from parent node.
  43919. // + TreemapSeries.color can not be set as 'none', otherwise effect
  43920. // legend color fetching (see seriesColor.js).
  43921. colorAlpha: null, // Array. Specify color alpha range of each level, like [0.2, 0.8]
  43922. colorSaturation: null, // Array. Specify color saturation of each level, like [0.2, 0.5]
  43923. colorMappingBy: 'index', // 'value' or 'index' or 'id'.
  43924. visibleMin: 10, // If area less than this threshold (unit: pixel^2), node will not
  43925. // be rendered. Only works when sort is 'asc' or 'desc'.
  43926. childrenVisibleMin: null, // If area of a node less than this threshold (unit: pixel^2),
  43927. // grandchildren will not show.
  43928. // Why grandchildren? If not grandchildren but children,
  43929. // some siblings show children and some not,
  43930. // the appearance may be mess and not consistent,
  43931. levels: [] // Each item: {
  43932. // visibleMin, itemStyle, visualDimension, label
  43933. // }
  43934. // data: {
  43935. // value: [],
  43936. // children: [],
  43937. // link: 'http://xxx.xxx.xxx',
  43938. // target: 'blank' or 'self'
  43939. // }
  43940. },
  43941. /**
  43942. * @override
  43943. */
  43944. getInitialData: function (option, ecModel) {
  43945. // Create a virtual root.
  43946. var root = {name: option.name, children: option.data};
  43947. completeTreeValue(root);
  43948. var levels = option.levels || [];
  43949. levels = option.levels = setDefault(levels, ecModel);
  43950. var treeOption = {};
  43951. treeOption.levels = levels;
  43952. // Make sure always a new tree is created when setOption,
  43953. // in TreemapView, we check whether oldTree === newTree
  43954. // to choose mappings approach among old shapes and new shapes.
  43955. return Tree.createTree(root, this, treeOption).data;
  43956. },
  43957. optionUpdated: function () {
  43958. this.resetViewRoot();
  43959. },
  43960. /**
  43961. * @override
  43962. * @param {number} dataIndex
  43963. * @param {boolean} [mutipleSeries=false]
  43964. */
  43965. formatTooltip: function (dataIndex) {
  43966. var data = this.getData();
  43967. var value = this.getRawValue(dataIndex);
  43968. var formattedValue = isArray(value)
  43969. ? addCommas(value[0]) : addCommas(value);
  43970. var name = data.getName(dataIndex);
  43971. return encodeHTML(name + ': ' + formattedValue);
  43972. },
  43973. /**
  43974. * Add tree path to tooltip param
  43975. *
  43976. * @override
  43977. * @param {number} dataIndex
  43978. * @return {Object}
  43979. */
  43980. getDataParams: function (dataIndex) {
  43981. var params = SeriesModel.prototype.getDataParams.apply(this, arguments);
  43982. var node = this.getData().tree.getNodeByDataIndex(dataIndex);
  43983. params.treePathInfo = wrapTreePathInfo(node, this);
  43984. return params;
  43985. },
  43986. /**
  43987. * @public
  43988. * @param {Object} layoutInfo {
  43989. * x: containerGroup x
  43990. * y: containerGroup y
  43991. * width: containerGroup width
  43992. * height: containerGroup height
  43993. * }
  43994. */
  43995. setLayoutInfo: function (layoutInfo) {
  43996. /**
  43997. * @readOnly
  43998. * @type {Object}
  43999. */
  44000. this.layoutInfo = this.layoutInfo || {};
  44001. extend(this.layoutInfo, layoutInfo);
  44002. },
  44003. /**
  44004. * @param {string} id
  44005. * @return {number} index
  44006. */
  44007. mapIdToIndex: function (id) {
  44008. // A feature is implemented:
  44009. // index is monotone increasing with the sequence of
  44010. // input id at the first time.
  44011. // This feature can make sure that each data item and its
  44012. // mapped color have the same index between data list and
  44013. // color list at the beginning, which is useful for user
  44014. // to adjust data-color mapping.
  44015. /**
  44016. * @private
  44017. * @type {Object}
  44018. */
  44019. var idIndexMap = this._idIndexMap;
  44020. if (!idIndexMap) {
  44021. idIndexMap = this._idIndexMap = createHashMap();
  44022. /**
  44023. * @private
  44024. * @type {number}
  44025. */
  44026. this._idIndexMapCount = 0;
  44027. }
  44028. var index = idIndexMap.get(id);
  44029. if (index == null) {
  44030. idIndexMap.set(id, index = this._idIndexMapCount++);
  44031. }
  44032. return index;
  44033. },
  44034. getViewRoot: function () {
  44035. return this._viewRoot;
  44036. },
  44037. /**
  44038. * @param {module:echarts/data/Tree~Node} [viewRoot]
  44039. */
  44040. resetViewRoot: function (viewRoot) {
  44041. viewRoot
  44042. ? (this._viewRoot = viewRoot)
  44043. : (viewRoot = this._viewRoot);
  44044. var root = this.getRawData().tree.root;
  44045. if (!viewRoot
  44046. || (viewRoot !== root && !root.contains(viewRoot))
  44047. ) {
  44048. this._viewRoot = root;
  44049. }
  44050. }
  44051. });
  44052. /**
  44053. * @param {Object} dataNode
  44054. */
  44055. function completeTreeValue(dataNode) {
  44056. // Postorder travel tree.
  44057. // If value of none-leaf node is not set,
  44058. // calculate it by suming up the value of all children.
  44059. var sum = 0;
  44060. each$1(dataNode.children, function (child) {
  44061. completeTreeValue(child);
  44062. var childValue = child.value;
  44063. isArray(childValue) && (childValue = childValue[0]);
  44064. sum += childValue;
  44065. });
  44066. var thisValue = dataNode.value;
  44067. if (isArray(thisValue)) {
  44068. thisValue = thisValue[0];
  44069. }
  44070. if (thisValue == null || isNaN(thisValue)) {
  44071. thisValue = sum;
  44072. }
  44073. // Value should not less than 0.
  44074. if (thisValue < 0) {
  44075. thisValue = 0;
  44076. }
  44077. isArray(dataNode.value)
  44078. ? (dataNode.value[0] = thisValue)
  44079. : (dataNode.value = thisValue);
  44080. }
  44081. /**
  44082. * set default to level configuration
  44083. */
  44084. function setDefault(levels, ecModel) {
  44085. var globalColorList = ecModel.get('color');
  44086. if (!globalColorList) {
  44087. return;
  44088. }
  44089. levels = levels || [];
  44090. var hasColorDefine;
  44091. each$1(levels, function (levelDefine) {
  44092. var model = new Model(levelDefine);
  44093. var modelColor = model.get('color');
  44094. if (model.get('itemStyle.color')
  44095. || (modelColor && modelColor !== 'none')
  44096. ) {
  44097. hasColorDefine = true;
  44098. }
  44099. });
  44100. if (!hasColorDefine) {
  44101. var level0 = levels[0] || (levels[0] = {});
  44102. level0.color = globalColorList.slice();
  44103. }
  44104. return levels;
  44105. }
  44106. /*
  44107. * Licensed to the Apache Software Foundation (ASF) under one
  44108. * or more contributor license agreements. See the NOTICE file
  44109. * distributed with this work for additional information
  44110. * regarding copyright ownership. The ASF licenses this file
  44111. * to you under the Apache License, Version 2.0 (the
  44112. * "License"); you may not use this file except in compliance
  44113. * with the License. You may obtain a copy of the License at
  44114. *
  44115. * http://www.apache.org/licenses/LICENSE-2.0
  44116. *
  44117. * Unless required by applicable law or agreed to in writing,
  44118. * software distributed under the License is distributed on an
  44119. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  44120. * KIND, either express or implied. See the License for the
  44121. * specific language governing permissions and limitations
  44122. * under the License.
  44123. */
  44124. var TEXT_PADDING = 8;
  44125. var ITEM_GAP = 8;
  44126. var ARRAY_LENGTH = 5;
  44127. function Breadcrumb(containerGroup) {
  44128. /**
  44129. * @private
  44130. * @type {module:zrender/container/Group}
  44131. */
  44132. this.group = new Group();
  44133. containerGroup.add(this.group);
  44134. }
  44135. Breadcrumb.prototype = {
  44136. constructor: Breadcrumb,
  44137. render: function (seriesModel, api, targetNode, onSelect) {
  44138. var model = seriesModel.getModel('breadcrumb');
  44139. var thisGroup = this.group;
  44140. thisGroup.removeAll();
  44141. if (!model.get('show') || !targetNode) {
  44142. return;
  44143. }
  44144. var normalStyleModel = model.getModel('itemStyle');
  44145. // var emphasisStyleModel = model.getModel('emphasis.itemStyle');
  44146. var textStyleModel = normalStyleModel.getModel('textStyle');
  44147. var layoutParam = {
  44148. pos: {
  44149. left: model.get('left'),
  44150. right: model.get('right'),
  44151. top: model.get('top'),
  44152. bottom: model.get('bottom')
  44153. },
  44154. box: {
  44155. width: api.getWidth(),
  44156. height: api.getHeight()
  44157. },
  44158. emptyItemWidth: model.get('emptyItemWidth'),
  44159. totalWidth: 0,
  44160. renderList: []
  44161. };
  44162. this._prepare(targetNode, layoutParam, textStyleModel);
  44163. this._renderContent(seriesModel, layoutParam, normalStyleModel, textStyleModel, onSelect);
  44164. positionElement(thisGroup, layoutParam.pos, layoutParam.box);
  44165. },
  44166. /**
  44167. * Prepare render list and total width
  44168. * @private
  44169. */
  44170. _prepare: function (targetNode, layoutParam, textStyleModel) {
  44171. for (var node = targetNode; node; node = node.parentNode) {
  44172. var text = node.getModel().get('name');
  44173. var textRect = textStyleModel.getTextRect(text);
  44174. var itemWidth = Math.max(
  44175. textRect.width + TEXT_PADDING * 2,
  44176. layoutParam.emptyItemWidth
  44177. );
  44178. layoutParam.totalWidth += itemWidth + ITEM_GAP;
  44179. layoutParam.renderList.push({node: node, text: text, width: itemWidth});
  44180. }
  44181. },
  44182. /**
  44183. * @private
  44184. */
  44185. _renderContent: function (
  44186. seriesModel, layoutParam, normalStyleModel, textStyleModel, onSelect
  44187. ) {
  44188. // Start rendering.
  44189. var lastX = 0;
  44190. var emptyItemWidth = layoutParam.emptyItemWidth;
  44191. var height = seriesModel.get('breadcrumb.height');
  44192. var availableSize = getAvailableSize(layoutParam.pos, layoutParam.box);
  44193. var totalWidth = layoutParam.totalWidth;
  44194. var renderList = layoutParam.renderList;
  44195. for (var i = renderList.length - 1; i >= 0; i--) {
  44196. var item = renderList[i];
  44197. var itemNode = item.node;
  44198. var itemWidth = item.width;
  44199. var text = item.text;
  44200. // Hdie text and shorten width if necessary.
  44201. if (totalWidth > availableSize.width) {
  44202. totalWidth -= itemWidth - emptyItemWidth;
  44203. itemWidth = emptyItemWidth;
  44204. text = null;
  44205. }
  44206. var el = new Polygon({
  44207. shape: {
  44208. points: makeItemPoints(
  44209. lastX, 0, itemWidth, height,
  44210. i === renderList.length - 1, i === 0
  44211. )
  44212. },
  44213. style: defaults(
  44214. normalStyleModel.getItemStyle(),
  44215. {
  44216. lineJoin: 'bevel',
  44217. text: text,
  44218. textFill: textStyleModel.getTextColor(),
  44219. textFont: textStyleModel.getFont()
  44220. }
  44221. ),
  44222. z: 10,
  44223. onclick: curry(onSelect, itemNode)
  44224. });
  44225. this.group.add(el);
  44226. packEventData(el, seriesModel, itemNode);
  44227. lastX += itemWidth + ITEM_GAP;
  44228. }
  44229. },
  44230. /**
  44231. * @override
  44232. */
  44233. remove: function () {
  44234. this.group.removeAll();
  44235. }
  44236. };
  44237. function makeItemPoints(x, y, itemWidth, itemHeight, head, tail) {
  44238. var points = [
  44239. [head ? x : x - ARRAY_LENGTH, y],
  44240. [x + itemWidth, y],
  44241. [x + itemWidth, y + itemHeight],
  44242. [head ? x : x - ARRAY_LENGTH, y + itemHeight]
  44243. ];
  44244. !tail && points.splice(2, 0, [x + itemWidth + ARRAY_LENGTH, y + itemHeight / 2]);
  44245. !head && points.push([x, y + itemHeight / 2]);
  44246. return points;
  44247. }
  44248. // Package custom mouse event.
  44249. function packEventData(el, seriesModel, itemNode) {
  44250. el.eventData = {
  44251. componentType: 'series',
  44252. componentSubType: 'treemap',
  44253. componentIndex: seriesModel.componentIndex,
  44254. seriesIndex: seriesModel.componentIndex,
  44255. seriesName: seriesModel.name,
  44256. seriesType: 'treemap',
  44257. selfType: 'breadcrumb', // Distinguish with click event on treemap node.
  44258. nodeData: {
  44259. dataIndex: itemNode && itemNode.dataIndex,
  44260. name: itemNode && itemNode.name
  44261. },
  44262. treePathInfo: itemNode && wrapTreePathInfo(itemNode, seriesModel)
  44263. };
  44264. }
  44265. /*
  44266. * Licensed to the Apache Software Foundation (ASF) under one
  44267. * or more contributor license agreements. See the NOTICE file
  44268. * distributed with this work for additional information
  44269. * regarding copyright ownership. The ASF licenses this file
  44270. * to you under the Apache License, Version 2.0 (the
  44271. * "License"); you may not use this file except in compliance
  44272. * with the License. You may obtain a copy of the License at
  44273. *
  44274. * http://www.apache.org/licenses/LICENSE-2.0
  44275. *
  44276. * Unless required by applicable law or agreed to in writing,
  44277. * software distributed under the License is distributed on an
  44278. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  44279. * KIND, either express or implied. See the License for the
  44280. * specific language governing permissions and limitations
  44281. * under the License.
  44282. */
  44283. /**
  44284. * @param {number} [time=500] Time in ms
  44285. * @param {string} [easing='linear']
  44286. * @param {number} [delay=0]
  44287. * @param {Function} [callback]
  44288. *
  44289. * @example
  44290. * // Animate position
  44291. * animation
  44292. * .createWrap()
  44293. * .add(el1, {position: [10, 10]})
  44294. * .add(el2, {shape: {width: 500}, style: {fill: 'red'}}, 400)
  44295. * .done(function () { // done })
  44296. * .start('cubicOut');
  44297. */
  44298. function createWrap() {
  44299. var storage = [];
  44300. var elExistsMap = {};
  44301. var doneCallback;
  44302. return {
  44303. /**
  44304. * Caution: a el can only be added once, otherwise 'done'
  44305. * might not be called. This method checks this (by el.id),
  44306. * suppresses adding and returns false when existing el found.
  44307. *
  44308. * @param {modele:zrender/Element} el
  44309. * @param {Object} target
  44310. * @param {number} [time=500]
  44311. * @param {number} [delay=0]
  44312. * @param {string} [easing='linear']
  44313. * @return {boolean} Whether adding succeeded.
  44314. *
  44315. * @example
  44316. * add(el, target, time, delay, easing);
  44317. * add(el, target, time, easing);
  44318. * add(el, target, time);
  44319. * add(el, target);
  44320. */
  44321. add: function (el, target, time, delay, easing) {
  44322. if (isString(delay)) {
  44323. easing = delay;
  44324. delay = 0;
  44325. }
  44326. if (elExistsMap[el.id]) {
  44327. return false;
  44328. }
  44329. elExistsMap[el.id] = 1;
  44330. storage.push(
  44331. {el: el, target: target, time: time, delay: delay, easing: easing}
  44332. );
  44333. return true;
  44334. },
  44335. /**
  44336. * Only execute when animation finished. Will not execute when any
  44337. * of 'stop' or 'stopAnimation' called.
  44338. *
  44339. * @param {Function} callback
  44340. */
  44341. done: function (callback) {
  44342. doneCallback = callback;
  44343. return this;
  44344. },
  44345. /**
  44346. * Will stop exist animation firstly.
  44347. */
  44348. start: function () {
  44349. var count = storage.length;
  44350. for (var i = 0, len = storage.length; i < len; i++) {
  44351. var item = storage[i];
  44352. item.el.animateTo(item.target, item.time, item.delay, item.easing, done);
  44353. }
  44354. return this;
  44355. function done() {
  44356. count--;
  44357. if (!count) {
  44358. storage.length = 0;
  44359. elExistsMap = {};
  44360. doneCallback && doneCallback();
  44361. }
  44362. }
  44363. }
  44364. };
  44365. }
  44366. /*
  44367. * Licensed to the Apache Software Foundation (ASF) under one
  44368. * or more contributor license agreements. See the NOTICE file
  44369. * distributed with this work for additional information
  44370. * regarding copyright ownership. The ASF licenses this file
  44371. * to you under the Apache License, Version 2.0 (the
  44372. * "License"); you may not use this file except in compliance
  44373. * with the License. You may obtain a copy of the License at
  44374. *
  44375. * http://www.apache.org/licenses/LICENSE-2.0
  44376. *
  44377. * Unless required by applicable law or agreed to in writing,
  44378. * software distributed under the License is distributed on an
  44379. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  44380. * KIND, either express or implied. See the License for the
  44381. * specific language governing permissions and limitations
  44382. * under the License.
  44383. */
  44384. var bind$1 = bind;
  44385. var Group$2 = Group;
  44386. var Rect$1 = Rect;
  44387. var each$8 = each$1;
  44388. var DRAG_THRESHOLD = 3;
  44389. var PATH_LABEL_NOAMAL = ['label'];
  44390. var PATH_LABEL_EMPHASIS = ['emphasis', 'label'];
  44391. var PATH_UPPERLABEL_NORMAL = ['upperLabel'];
  44392. var PATH_UPPERLABEL_EMPHASIS = ['emphasis', 'upperLabel'];
  44393. var Z_BASE = 10; // Should bigger than every z.
  44394. var Z_BG = 1;
  44395. var Z_CONTENT = 2;
  44396. var getItemStyleEmphasis = makeStyleMapper([
  44397. ['fill', 'color'],
  44398. // `borderColor` and `borderWidth` has been occupied,
  44399. // so use `stroke` to indicate the stroke of the rect.
  44400. ['stroke', 'strokeColor'],
  44401. ['lineWidth', 'strokeWidth'],
  44402. ['shadowBlur'],
  44403. ['shadowOffsetX'],
  44404. ['shadowOffsetY'],
  44405. ['shadowColor']
  44406. ]);
  44407. var getItemStyleNormal = function (model) {
  44408. // Normal style props should include emphasis style props.
  44409. var itemStyle = getItemStyleEmphasis(model);
  44410. // Clear styles set by emphasis.
  44411. itemStyle.stroke = itemStyle.fill = itemStyle.lineWidth = null;
  44412. return itemStyle;
  44413. };
  44414. extendChartView({
  44415. type: 'treemap',
  44416. /**
  44417. * @override
  44418. */
  44419. init: function (o, api) {
  44420. /**
  44421. * @private
  44422. * @type {module:zrender/container/Group}
  44423. */
  44424. this._containerGroup;
  44425. /**
  44426. * @private
  44427. * @type {Object.<string, Array.<module:zrender/container/Group>>}
  44428. */
  44429. this._storage = createStorage();
  44430. /**
  44431. * @private
  44432. * @type {module:echarts/data/Tree}
  44433. */
  44434. this._oldTree;
  44435. /**
  44436. * @private
  44437. * @type {module:echarts/chart/treemap/Breadcrumb}
  44438. */
  44439. this._breadcrumb;
  44440. /**
  44441. * @private
  44442. * @type {module:echarts/component/helper/RoamController}
  44443. */
  44444. this._controller;
  44445. /**
  44446. * 'ready', 'animating'
  44447. * @private
  44448. */
  44449. this._state = 'ready';
  44450. },
  44451. /**
  44452. * @override
  44453. */
  44454. render: function (seriesModel, ecModel, api, payload) {
  44455. var models = ecModel.findComponents({
  44456. mainType: 'series', subType: 'treemap', query: payload
  44457. });
  44458. if (indexOf(models, seriesModel) < 0) {
  44459. return;
  44460. }
  44461. this.seriesModel = seriesModel;
  44462. this.api = api;
  44463. this.ecModel = ecModel;
  44464. var types = ['treemapZoomToNode', 'treemapRootToNode'];
  44465. var targetInfo = retrieveTargetInfo(payload, types, seriesModel);
  44466. var payloadType = payload && payload.type;
  44467. var layoutInfo = seriesModel.layoutInfo;
  44468. var isInit = !this._oldTree;
  44469. var thisStorage = this._storage;
  44470. // Mark new root when action is treemapRootToNode.
  44471. var reRoot = (payloadType === 'treemapRootToNode' && targetInfo && thisStorage)
  44472. ? {
  44473. rootNodeGroup: thisStorage.nodeGroup[targetInfo.node.getRawIndex()],
  44474. direction: payload.direction
  44475. }
  44476. : null;
  44477. var containerGroup = this._giveContainerGroup(layoutInfo);
  44478. var renderResult = this._doRender(containerGroup, seriesModel, reRoot);
  44479. (
  44480. !isInit && (
  44481. !payloadType
  44482. || payloadType === 'treemapZoomToNode'
  44483. || payloadType === 'treemapRootToNode'
  44484. )
  44485. )
  44486. ? this._doAnimation(containerGroup, renderResult, seriesModel, reRoot)
  44487. : renderResult.renderFinally();
  44488. this._resetController(api);
  44489. this._renderBreadcrumb(seriesModel, api, targetInfo);
  44490. },
  44491. /**
  44492. * @private
  44493. */
  44494. _giveContainerGroup: function (layoutInfo) {
  44495. var containerGroup = this._containerGroup;
  44496. if (!containerGroup) {
  44497. // FIXME
  44498. // 加一层containerGroup是为了clip,但是现在clip功能并没有实现。
  44499. containerGroup = this._containerGroup = new Group$2();
  44500. this._initEvents(containerGroup);
  44501. this.group.add(containerGroup);
  44502. }
  44503. containerGroup.attr('position', [layoutInfo.x, layoutInfo.y]);
  44504. return containerGroup;
  44505. },
  44506. /**
  44507. * @private
  44508. */
  44509. _doRender: function (containerGroup, seriesModel, reRoot) {
  44510. var thisTree = seriesModel.getData().tree;
  44511. var oldTree = this._oldTree;
  44512. // Clear last shape records.
  44513. var lastsForAnimation = createStorage();
  44514. var thisStorage = createStorage();
  44515. var oldStorage = this._storage;
  44516. var willInvisibleEls = [];
  44517. var doRenderNode = curry(
  44518. renderNode, seriesModel,
  44519. thisStorage, oldStorage, reRoot,
  44520. lastsForAnimation, willInvisibleEls
  44521. );
  44522. // Notice: when thisTree and oldTree are the same tree (see list.cloneShallow),
  44523. // the oldTree is actually losted, so we can not find all of the old graphic
  44524. // elements from tree. So we use this stragegy: make element storage, move
  44525. // from old storage to new storage, clear old storage.
  44526. dualTravel(
  44527. thisTree.root ? [thisTree.root] : [],
  44528. (oldTree && oldTree.root) ? [oldTree.root] : [],
  44529. containerGroup,
  44530. thisTree === oldTree || !oldTree,
  44531. 0
  44532. );
  44533. // Process all removing.
  44534. var willDeleteEls = clearStorage(oldStorage);
  44535. this._oldTree = thisTree;
  44536. this._storage = thisStorage;
  44537. return {
  44538. lastsForAnimation: lastsForAnimation,
  44539. willDeleteEls: willDeleteEls,
  44540. renderFinally: renderFinally
  44541. };
  44542. function dualTravel(thisViewChildren, oldViewChildren, parentGroup, sameTree, depth) {
  44543. // When 'render' is triggered by action,
  44544. // 'this' and 'old' may be the same tree,
  44545. // we use rawIndex in that case.
  44546. if (sameTree) {
  44547. oldViewChildren = thisViewChildren;
  44548. each$8(thisViewChildren, function (child, index) {
  44549. !child.isRemoved() && processNode(index, index);
  44550. });
  44551. }
  44552. // Diff hierarchically (diff only in each subtree, but not whole).
  44553. // because, consistency of view is important.
  44554. else {
  44555. (new DataDiffer(oldViewChildren, thisViewChildren, getKey, getKey))
  44556. .add(processNode)
  44557. .update(processNode)
  44558. .remove(curry(processNode, null))
  44559. .execute();
  44560. }
  44561. function getKey(node) {
  44562. // Identify by name or raw index.
  44563. return node.getId();
  44564. }
  44565. function processNode(newIndex, oldIndex) {
  44566. var thisNode = newIndex != null ? thisViewChildren[newIndex] : null;
  44567. var oldNode = oldIndex != null ? oldViewChildren[oldIndex] : null;
  44568. var group = doRenderNode(thisNode, oldNode, parentGroup, depth);
  44569. group && dualTravel(
  44570. thisNode && thisNode.viewChildren || [],
  44571. oldNode && oldNode.viewChildren || [],
  44572. group,
  44573. sameTree,
  44574. depth + 1
  44575. );
  44576. }
  44577. }
  44578. function clearStorage(storage) {
  44579. var willDeleteEls = createStorage();
  44580. storage && each$8(storage, function (store, storageName) {
  44581. var delEls = willDeleteEls[storageName];
  44582. each$8(store, function (el) {
  44583. el && (delEls.push(el), el.__tmWillDelete = 1);
  44584. });
  44585. });
  44586. return willDeleteEls;
  44587. }
  44588. function renderFinally() {
  44589. each$8(willDeleteEls, function (els) {
  44590. each$8(els, function (el) {
  44591. el.parent && el.parent.remove(el);
  44592. });
  44593. });
  44594. each$8(willInvisibleEls, function (el) {
  44595. el.invisible = true;
  44596. // Setting invisible is for optimizing, so no need to set dirty,
  44597. // just mark as invisible.
  44598. el.dirty();
  44599. });
  44600. }
  44601. },
  44602. /**
  44603. * @private
  44604. */
  44605. _doAnimation: function (containerGroup, renderResult, seriesModel, reRoot) {
  44606. if (!seriesModel.get('animation')) {
  44607. return;
  44608. }
  44609. var duration = seriesModel.get('animationDurationUpdate');
  44610. var easing = seriesModel.get('animationEasing');
  44611. var animationWrap = createWrap();
  44612. // Make delete animations.
  44613. each$8(renderResult.willDeleteEls, function (store, storageName) {
  44614. each$8(store, function (el, rawIndex) {
  44615. if (el.invisible) {
  44616. return;
  44617. }
  44618. var parent = el.parent; // Always has parent, and parent is nodeGroup.
  44619. var target;
  44620. if (reRoot && reRoot.direction === 'drillDown') {
  44621. target = parent === reRoot.rootNodeGroup
  44622. // This is the content element of view root.
  44623. // Only `content` will enter this branch, because
  44624. // `background` and `nodeGroup` will not be deleted.
  44625. ? {
  44626. shape: {
  44627. x: 0,
  44628. y: 0,
  44629. width: parent.__tmNodeWidth,
  44630. height: parent.__tmNodeHeight
  44631. },
  44632. style: {
  44633. opacity: 0
  44634. }
  44635. }
  44636. // Others.
  44637. : {style: {opacity: 0}};
  44638. }
  44639. else {
  44640. var targetX = 0;
  44641. var targetY = 0;
  44642. if (!parent.__tmWillDelete) {
  44643. // Let node animate to right-bottom corner, cooperating with fadeout,
  44644. // which is appropriate for user understanding.
  44645. // Divided by 2 for reRoot rolling up effect.
  44646. targetX = parent.__tmNodeWidth / 2;
  44647. targetY = parent.__tmNodeHeight / 2;
  44648. }
  44649. target = storageName === 'nodeGroup'
  44650. ? {position: [targetX, targetY], style: {opacity: 0}}
  44651. : {
  44652. shape: {x: targetX, y: targetY, width: 0, height: 0},
  44653. style: {opacity: 0}
  44654. };
  44655. }
  44656. target && animationWrap.add(el, target, duration, easing);
  44657. });
  44658. });
  44659. // Make other animations
  44660. each$8(this._storage, function (store, storageName) {
  44661. each$8(store, function (el, rawIndex) {
  44662. var last = renderResult.lastsForAnimation[storageName][rawIndex];
  44663. var target = {};
  44664. if (!last) {
  44665. return;
  44666. }
  44667. if (storageName === 'nodeGroup') {
  44668. if (last.old) {
  44669. target.position = el.position.slice();
  44670. el.attr('position', last.old);
  44671. }
  44672. }
  44673. else {
  44674. if (last.old) {
  44675. target.shape = extend({}, el.shape);
  44676. el.setShape(last.old);
  44677. }
  44678. if (last.fadein) {
  44679. el.setStyle('opacity', 0);
  44680. target.style = {opacity: 1};
  44681. }
  44682. // When animation is stopped for succedent animation starting,
  44683. // el.style.opacity might not be 1
  44684. else if (el.style.opacity !== 1) {
  44685. target.style = {opacity: 1};
  44686. }
  44687. }
  44688. animationWrap.add(el, target, duration, easing);
  44689. });
  44690. }, this);
  44691. this._state = 'animating';
  44692. animationWrap
  44693. .done(bind$1(function () {
  44694. this._state = 'ready';
  44695. renderResult.renderFinally();
  44696. }, this))
  44697. .start();
  44698. },
  44699. /**
  44700. * @private
  44701. */
  44702. _resetController: function (api) {
  44703. var controller = this._controller;
  44704. // Init controller.
  44705. if (!controller) {
  44706. controller = this._controller = new RoamController(api.getZr());
  44707. controller.enable(this.seriesModel.get('roam'));
  44708. controller.on('pan', bind$1(this._onPan, this));
  44709. controller.on('zoom', bind$1(this._onZoom, this));
  44710. }
  44711. var rect = new BoundingRect(0, 0, api.getWidth(), api.getHeight());
  44712. controller.setPointerChecker(function (e, x, y) {
  44713. return rect.contain(x, y);
  44714. });
  44715. },
  44716. /**
  44717. * @private
  44718. */
  44719. _clearController: function () {
  44720. var controller = this._controller;
  44721. if (controller) {
  44722. controller.dispose();
  44723. controller = null;
  44724. }
  44725. },
  44726. /**
  44727. * @private
  44728. */
  44729. _onPan: function (e) {
  44730. if (this._state !== 'animating'
  44731. && (Math.abs(e.dx) > DRAG_THRESHOLD || Math.abs(e.dy) > DRAG_THRESHOLD)
  44732. ) {
  44733. // These param must not be cached.
  44734. var root = this.seriesModel.getData().tree.root;
  44735. if (!root) {
  44736. return;
  44737. }
  44738. var rootLayout = root.getLayout();
  44739. if (!rootLayout) {
  44740. return;
  44741. }
  44742. this.api.dispatchAction({
  44743. type: 'treemapMove',
  44744. from: this.uid,
  44745. seriesId: this.seriesModel.id,
  44746. rootRect: {
  44747. x: rootLayout.x + e.dx, y: rootLayout.y + e.dy,
  44748. width: rootLayout.width, height: rootLayout.height
  44749. }
  44750. });
  44751. }
  44752. },
  44753. /**
  44754. * @private
  44755. */
  44756. _onZoom: function (e) {
  44757. var mouseX = e.originX;
  44758. var mouseY = e.originY;
  44759. if (this._state !== 'animating') {
  44760. // These param must not be cached.
  44761. var root = this.seriesModel.getData().tree.root;
  44762. if (!root) {
  44763. return;
  44764. }
  44765. var rootLayout = root.getLayout();
  44766. if (!rootLayout) {
  44767. return;
  44768. }
  44769. var rect = new BoundingRect(
  44770. rootLayout.x, rootLayout.y, rootLayout.width, rootLayout.height
  44771. );
  44772. var layoutInfo = this.seriesModel.layoutInfo;
  44773. // Transform mouse coord from global to containerGroup.
  44774. mouseX -= layoutInfo.x;
  44775. mouseY -= layoutInfo.y;
  44776. // Scale root bounding rect.
  44777. var m = create$1();
  44778. translate(m, m, [-mouseX, -mouseY]);
  44779. scale$1(m, m, [e.scale, e.scale]);
  44780. translate(m, m, [mouseX, mouseY]);
  44781. rect.applyTransform(m);
  44782. this.api.dispatchAction({
  44783. type: 'treemapRender',
  44784. from: this.uid,
  44785. seriesId: this.seriesModel.id,
  44786. rootRect: {
  44787. x: rect.x, y: rect.y,
  44788. width: rect.width, height: rect.height
  44789. }
  44790. });
  44791. }
  44792. },
  44793. /**
  44794. * @private
  44795. */
  44796. _initEvents: function (containerGroup) {
  44797. containerGroup.on('click', function (e) {
  44798. if (this._state !== 'ready') {
  44799. return;
  44800. }
  44801. var nodeClick = this.seriesModel.get('nodeClick', true);
  44802. if (!nodeClick) {
  44803. return;
  44804. }
  44805. var targetInfo = this.findTarget(e.offsetX, e.offsetY);
  44806. if (!targetInfo) {
  44807. return;
  44808. }
  44809. var node = targetInfo.node;
  44810. if (node.getLayout().isLeafRoot) {
  44811. this._rootToNode(targetInfo);
  44812. }
  44813. else {
  44814. if (nodeClick === 'zoomToNode') {
  44815. this._zoomToNode(targetInfo);
  44816. }
  44817. else if (nodeClick === 'link') {
  44818. var itemModel = node.hostTree.data.getItemModel(node.dataIndex);
  44819. var link = itemModel.get('link', true);
  44820. var linkTarget = itemModel.get('target', true) || 'blank';
  44821. link && window.open(link, linkTarget);
  44822. }
  44823. }
  44824. }, this);
  44825. },
  44826. /**
  44827. * @private
  44828. */
  44829. _renderBreadcrumb: function (seriesModel, api, targetInfo) {
  44830. if (!targetInfo) {
  44831. targetInfo = seriesModel.get('leafDepth', true) != null
  44832. ? {node: seriesModel.getViewRoot()}
  44833. // FIXME
  44834. // better way?
  44835. // Find breadcrumb tail on center of containerGroup.
  44836. : this.findTarget(api.getWidth() / 2, api.getHeight() / 2);
  44837. if (!targetInfo) {
  44838. targetInfo = {node: seriesModel.getData().tree.root};
  44839. }
  44840. }
  44841. (this._breadcrumb || (this._breadcrumb = new Breadcrumb(this.group)))
  44842. .render(seriesModel, api, targetInfo.node, bind$1(onSelect, this));
  44843. function onSelect(node) {
  44844. if (this._state !== 'animating') {
  44845. aboveViewRoot(seriesModel.getViewRoot(), node)
  44846. ? this._rootToNode({node: node})
  44847. : this._zoomToNode({node: node});
  44848. }
  44849. }
  44850. },
  44851. /**
  44852. * @override
  44853. */
  44854. remove: function () {
  44855. this._clearController();
  44856. this._containerGroup && this._containerGroup.removeAll();
  44857. this._storage = createStorage();
  44858. this._state = 'ready';
  44859. this._breadcrumb && this._breadcrumb.remove();
  44860. },
  44861. dispose: function () {
  44862. this._clearController();
  44863. },
  44864. /**
  44865. * @private
  44866. */
  44867. _zoomToNode: function (targetInfo) {
  44868. this.api.dispatchAction({
  44869. type: 'treemapZoomToNode',
  44870. from: this.uid,
  44871. seriesId: this.seriesModel.id,
  44872. targetNode: targetInfo.node
  44873. });
  44874. },
  44875. /**
  44876. * @private
  44877. */
  44878. _rootToNode: function (targetInfo) {
  44879. this.api.dispatchAction({
  44880. type: 'treemapRootToNode',
  44881. from: this.uid,
  44882. seriesId: this.seriesModel.id,
  44883. targetNode: targetInfo.node
  44884. });
  44885. },
  44886. /**
  44887. * @public
  44888. * @param {number} x Global coord x.
  44889. * @param {number} y Global coord y.
  44890. * @return {Object} info If not found, return undefined;
  44891. * @return {number} info.node Target node.
  44892. * @return {number} info.offsetX x refer to target node.
  44893. * @return {number} info.offsetY y refer to target node.
  44894. */
  44895. findTarget: function (x, y) {
  44896. var targetInfo;
  44897. var viewRoot = this.seriesModel.getViewRoot();
  44898. viewRoot.eachNode({attr: 'viewChildren', order: 'preorder'}, function (node) {
  44899. var bgEl = this._storage.background[node.getRawIndex()];
  44900. // If invisible, there might be no element.
  44901. if (bgEl) {
  44902. var point = bgEl.transformCoordToLocal(x, y);
  44903. var shape = bgEl.shape;
  44904. // For performance consideration, dont use 'getBoundingRect'.
  44905. if (shape.x <= point[0]
  44906. && point[0] <= shape.x + shape.width
  44907. && shape.y <= point[1]
  44908. && point[1] <= shape.y + shape.height
  44909. ) {
  44910. targetInfo = {node: node, offsetX: point[0], offsetY: point[1]};
  44911. }
  44912. else {
  44913. return false; // Suppress visit subtree.
  44914. }
  44915. }
  44916. }, this);
  44917. return targetInfo;
  44918. }
  44919. });
  44920. /**
  44921. * @inner
  44922. */
  44923. function createStorage() {
  44924. return {nodeGroup: [], background: [], content: []};
  44925. }
  44926. /**
  44927. * @inner
  44928. * @return Return undefined means do not travel further.
  44929. */
  44930. function renderNode(
  44931. seriesModel, thisStorage, oldStorage, reRoot,
  44932. lastsForAnimation, willInvisibleEls,
  44933. thisNode, oldNode, parentGroup, depth
  44934. ) {
  44935. // Whether under viewRoot.
  44936. if (!thisNode) {
  44937. // Deleting nodes will be performed finally. This method just find
  44938. // element from old storage, or create new element, set them to new
  44939. // storage, and set styles.
  44940. return;
  44941. }
  44942. // -------------------------------------------------------------------
  44943. // Start of closure variables available in "Procedures in renderNode".
  44944. var thisLayout = thisNode.getLayout();
  44945. if (!thisLayout || !thisLayout.isInView) {
  44946. return;
  44947. }
  44948. var thisWidth = thisLayout.width;
  44949. var thisHeight = thisLayout.height;
  44950. var borderWidth = thisLayout.borderWidth;
  44951. var thisInvisible = thisLayout.invisible;
  44952. var thisRawIndex = thisNode.getRawIndex();
  44953. var oldRawIndex = oldNode && oldNode.getRawIndex();
  44954. var thisViewChildren = thisNode.viewChildren;
  44955. var upperHeight = thisLayout.upperHeight;
  44956. var isParent = thisViewChildren && thisViewChildren.length;
  44957. var itemStyleNormalModel = thisNode.getModel('itemStyle');
  44958. var itemStyleEmphasisModel = thisNode.getModel('emphasis.itemStyle');
  44959. // End of closure ariables available in "Procedures in renderNode".
  44960. // -----------------------------------------------------------------
  44961. // Node group
  44962. var group = giveGraphic('nodeGroup', Group$2);
  44963. if (!group) {
  44964. return;
  44965. }
  44966. parentGroup.add(group);
  44967. // x,y are not set when el is above view root.
  44968. group.attr('position', [thisLayout.x || 0, thisLayout.y || 0]);
  44969. group.__tmNodeWidth = thisWidth;
  44970. group.__tmNodeHeight = thisHeight;
  44971. if (thisLayout.isAboveViewRoot) {
  44972. return group;
  44973. }
  44974. // Background
  44975. var bg = giveGraphic('background', Rect$1, depth, Z_BG);
  44976. bg && renderBackground(group, bg, isParent && thisLayout.upperHeight);
  44977. // No children, render content.
  44978. if (!isParent) {
  44979. var content = giveGraphic('content', Rect$1, depth, Z_CONTENT);
  44980. content && renderContent(group, content);
  44981. }
  44982. return group;
  44983. // ----------------------------
  44984. // | Procedures in renderNode |
  44985. // ----------------------------
  44986. function renderBackground(group, bg, useUpperLabel) {
  44987. // For tooltip.
  44988. bg.dataIndex = thisNode.dataIndex;
  44989. bg.seriesIndex = seriesModel.seriesIndex;
  44990. bg.setShape({x: 0, y: 0, width: thisWidth, height: thisHeight});
  44991. var visualBorderColor = thisNode.getVisual('borderColor', true);
  44992. var emphasisBorderColor = itemStyleEmphasisModel.get('borderColor');
  44993. updateStyle(bg, function () {
  44994. var normalStyle = getItemStyleNormal(itemStyleNormalModel);
  44995. normalStyle.fill = visualBorderColor;
  44996. var emphasisStyle = getItemStyleEmphasis(itemStyleEmphasisModel);
  44997. emphasisStyle.fill = emphasisBorderColor;
  44998. if (useUpperLabel) {
  44999. var upperLabelWidth = thisWidth - 2 * borderWidth;
  45000. prepareText(
  45001. normalStyle, emphasisStyle, visualBorderColor, upperLabelWidth, upperHeight,
  45002. {x: borderWidth, y: 0, width: upperLabelWidth, height: upperHeight}
  45003. );
  45004. }
  45005. // For old bg.
  45006. else {
  45007. normalStyle.text = emphasisStyle.text = null;
  45008. }
  45009. bg.setStyle(normalStyle);
  45010. setHoverStyle(bg, emphasisStyle);
  45011. });
  45012. group.add(bg);
  45013. }
  45014. function renderContent(group, content) {
  45015. // For tooltip.
  45016. content.dataIndex = thisNode.dataIndex;
  45017. content.seriesIndex = seriesModel.seriesIndex;
  45018. var contentWidth = Math.max(thisWidth - 2 * borderWidth, 0);
  45019. var contentHeight = Math.max(thisHeight - 2 * borderWidth, 0);
  45020. content.culling = true;
  45021. content.setShape({
  45022. x: borderWidth,
  45023. y: borderWidth,
  45024. width: contentWidth,
  45025. height: contentHeight
  45026. });
  45027. var visualColor = thisNode.getVisual('color', true);
  45028. updateStyle(content, function () {
  45029. var normalStyle = getItemStyleNormal(itemStyleNormalModel);
  45030. normalStyle.fill = visualColor;
  45031. var emphasisStyle = getItemStyleEmphasis(itemStyleEmphasisModel);
  45032. prepareText(normalStyle, emphasisStyle, visualColor, contentWidth, contentHeight);
  45033. content.setStyle(normalStyle);
  45034. setHoverStyle(content, emphasisStyle);
  45035. });
  45036. group.add(content);
  45037. }
  45038. function updateStyle(element, cb) {
  45039. if (!thisInvisible) {
  45040. // If invisible, do not set visual, otherwise the element will
  45041. // change immediately before animation. We think it is OK to
  45042. // remain its origin color when moving out of the view window.
  45043. cb();
  45044. if (!element.__tmWillVisible) {
  45045. element.invisible = false;
  45046. }
  45047. }
  45048. else {
  45049. // Delay invisible setting utill animation finished,
  45050. // avoid element vanish suddenly before animation.
  45051. !element.invisible && willInvisibleEls.push(element);
  45052. }
  45053. }
  45054. function prepareText(normalStyle, emphasisStyle, visualColor, width, height, upperLabelRect) {
  45055. var nodeModel = thisNode.getModel();
  45056. var text = retrieve(
  45057. seriesModel.getFormattedLabel(
  45058. thisNode.dataIndex, 'normal', null, null, upperLabelRect ? 'upperLabel' : 'label'
  45059. ),
  45060. nodeModel.get('name')
  45061. );
  45062. if (!upperLabelRect && thisLayout.isLeafRoot) {
  45063. var iconChar = seriesModel.get('drillDownIcon', true);
  45064. text = iconChar ? iconChar + ' ' + text : text;
  45065. }
  45066. var normalLabelModel = nodeModel.getModel(
  45067. upperLabelRect ? PATH_UPPERLABEL_NORMAL : PATH_LABEL_NOAMAL
  45068. );
  45069. var emphasisLabelModel = nodeModel.getModel(
  45070. upperLabelRect ? PATH_UPPERLABEL_EMPHASIS : PATH_LABEL_EMPHASIS
  45071. );
  45072. var isShow = normalLabelModel.getShallow('show');
  45073. setLabelStyle(
  45074. normalStyle, emphasisStyle, normalLabelModel, emphasisLabelModel,
  45075. {
  45076. defaultText: isShow ? text : null,
  45077. autoColor: visualColor,
  45078. isRectText: true
  45079. }
  45080. );
  45081. upperLabelRect && (normalStyle.textRect = clone(upperLabelRect));
  45082. normalStyle.truncate = (isShow && normalLabelModel.get('ellipsis'))
  45083. ? {
  45084. outerWidth: width,
  45085. outerHeight: height,
  45086. minChar: 2
  45087. }
  45088. : null;
  45089. }
  45090. function giveGraphic(storageName, Ctor, depth, z) {
  45091. var element = oldRawIndex != null && oldStorage[storageName][oldRawIndex];
  45092. var lasts = lastsForAnimation[storageName];
  45093. if (element) {
  45094. // Remove from oldStorage
  45095. oldStorage[storageName][oldRawIndex] = null;
  45096. prepareAnimationWhenHasOld(lasts, element, storageName);
  45097. }
  45098. // If invisible and no old element, do not create new element (for optimizing).
  45099. else if (!thisInvisible) {
  45100. element = new Ctor({z: calculateZ(depth, z)});
  45101. element.__tmDepth = depth;
  45102. element.__tmStorageName = storageName;
  45103. prepareAnimationWhenNoOld(lasts, element, storageName);
  45104. }
  45105. // Set to thisStorage
  45106. return (thisStorage[storageName][thisRawIndex] = element);
  45107. }
  45108. function prepareAnimationWhenHasOld(lasts, element, storageName) {
  45109. var lastCfg = lasts[thisRawIndex] = {};
  45110. lastCfg.old = storageName === 'nodeGroup'
  45111. ? element.position.slice()
  45112. : extend({}, element.shape);
  45113. }
  45114. // If a element is new, we need to find the animation start point carefully,
  45115. // otherwise it will looks strange when 'zoomToNode'.
  45116. function prepareAnimationWhenNoOld(lasts, element, storageName) {
  45117. var lastCfg = lasts[thisRawIndex] = {};
  45118. var parentNode = thisNode.parentNode;
  45119. if (parentNode && (!reRoot || reRoot.direction === 'drillDown')) {
  45120. var parentOldX = 0;
  45121. var parentOldY = 0;
  45122. // New nodes appear from right-bottom corner in 'zoomToNode' animation.
  45123. // For convenience, get old bounding rect from background.
  45124. var parentOldBg = lastsForAnimation.background[parentNode.getRawIndex()];
  45125. if (!reRoot && parentOldBg && parentOldBg.old) {
  45126. parentOldX = parentOldBg.old.width;
  45127. parentOldY = parentOldBg.old.height;
  45128. }
  45129. // When no parent old shape found, its parent is new too,
  45130. // so we can just use {x:0, y:0}.
  45131. lastCfg.old = storageName === 'nodeGroup'
  45132. ? [0, parentOldY]
  45133. : {x: parentOldX, y: parentOldY, width: 0, height: 0};
  45134. }
  45135. // Fade in, user can be aware that these nodes are new.
  45136. lastCfg.fadein = storageName !== 'nodeGroup';
  45137. }
  45138. }
  45139. // We can not set all backgroud with the same z, Because the behaviour of
  45140. // drill down and roll up differ background creation sequence from tree
  45141. // hierarchy sequence, which cause that lowser background element overlap
  45142. // upper ones. So we calculate z based on depth.
  45143. // Moreover, we try to shrink down z interval to [0, 1] to avoid that
  45144. // treemap with large z overlaps other components.
  45145. function calculateZ(depth, zInLevel) {
  45146. var zb = depth * Z_BASE + zInLevel;
  45147. return (zb - 1) / zb;
  45148. }
  45149. /*
  45150. * Licensed to the Apache Software Foundation (ASF) under one
  45151. * or more contributor license agreements. See the NOTICE file
  45152. * distributed with this work for additional information
  45153. * regarding copyright ownership. The ASF licenses this file
  45154. * to you under the Apache License, Version 2.0 (the
  45155. * "License"); you may not use this file except in compliance
  45156. * with the License. You may obtain a copy of the License at
  45157. *
  45158. * http://www.apache.org/licenses/LICENSE-2.0
  45159. *
  45160. * Unless required by applicable law or agreed to in writing,
  45161. * software distributed under the License is distributed on an
  45162. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  45163. * KIND, either express or implied. See the License for the
  45164. * specific language governing permissions and limitations
  45165. * under the License.
  45166. */
  45167. /**
  45168. * @file Treemap action
  45169. */
  45170. var noop$1 = function () {};
  45171. var actionTypes = [
  45172. 'treemapZoomToNode',
  45173. 'treemapRender',
  45174. 'treemapMove'
  45175. ];
  45176. for (var i$2 = 0; i$2 < actionTypes.length; i$2++) {
  45177. registerAction({type: actionTypes[i$2], update: 'updateView'}, noop$1);
  45178. }
  45179. registerAction(
  45180. {type: 'treemapRootToNode', update: 'updateView'},
  45181. function (payload, ecModel) {
  45182. ecModel.eachComponent(
  45183. {mainType: 'series', subType: 'treemap', query: payload},
  45184. handleRootToNode
  45185. );
  45186. function handleRootToNode(model, index) {
  45187. var types = ['treemapZoomToNode', 'treemapRootToNode'];
  45188. var targetInfo = retrieveTargetInfo(payload, types, model);
  45189. if (targetInfo) {
  45190. var originViewRoot = model.getViewRoot();
  45191. if (originViewRoot) {
  45192. payload.direction = aboveViewRoot(originViewRoot, targetInfo.node)
  45193. ? 'rollUp' : 'drillDown';
  45194. }
  45195. model.resetViewRoot(targetInfo.node);
  45196. }
  45197. }
  45198. }
  45199. );
  45200. /*
  45201. * Licensed to the Apache Software Foundation (ASF) under one
  45202. * or more contributor license agreements. See the NOTICE file
  45203. * distributed with this work for additional information
  45204. * regarding copyright ownership. The ASF licenses this file
  45205. * to you under the Apache License, Version 2.0 (the
  45206. * "License"); you may not use this file except in compliance
  45207. * with the License. You may obtain a copy of the License at
  45208. *
  45209. * http://www.apache.org/licenses/LICENSE-2.0
  45210. *
  45211. * Unless required by applicable law or agreed to in writing,
  45212. * software distributed under the License is distributed on an
  45213. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  45214. * KIND, either express or implied. See the License for the
  45215. * specific language governing permissions and limitations
  45216. * under the License.
  45217. */
  45218. var each$9 = each$1;
  45219. var isObject$5 = isObject$1;
  45220. var CATEGORY_DEFAULT_VISUAL_INDEX = -1;
  45221. /**
  45222. * @param {Object} option
  45223. * @param {string} [option.type] See visualHandlers.
  45224. * @param {string} [option.mappingMethod] 'linear' or 'piecewise' or 'category' or 'fixed'
  45225. * @param {Array.<number>=} [option.dataExtent] [minExtent, maxExtent],
  45226. * required when mappingMethod is 'linear'
  45227. * @param {Array.<Object>=} [option.pieceList] [
  45228. * {value: someValue},
  45229. * {interval: [min1, max1], visual: {...}},
  45230. * {interval: [min2, max2]}
  45231. * ],
  45232. * required when mappingMethod is 'piecewise'.
  45233. * Visual for only each piece can be specified.
  45234. * @param {Array.<string|Object>=} [option.categories] ['cate1', 'cate2']
  45235. * required when mappingMethod is 'category'.
  45236. * If no option.categories, categories is set
  45237. * as [0, 1, 2, ...].
  45238. * @param {boolean} [option.loop=false] Whether loop mapping when mappingMethod is 'category'.
  45239. * @param {(Array|Object|*)} [option.visual] Visual data.
  45240. * when mappingMethod is 'category',
  45241. * visual data can be array or object
  45242. * (like: {cate1: '#222', none: '#fff'})
  45243. * or primary types (which represents
  45244. * defualt category visual), otherwise visual
  45245. * can be array or primary (which will be
  45246. * normalized to array).
  45247. *
  45248. */
  45249. var VisualMapping = function (option) {
  45250. var mappingMethod = option.mappingMethod;
  45251. var visualType = option.type;
  45252. /**
  45253. * @readOnly
  45254. * @type {Object}
  45255. */
  45256. var thisOption = this.option = clone(option);
  45257. /**
  45258. * @readOnly
  45259. * @type {string}
  45260. */
  45261. this.type = visualType;
  45262. /**
  45263. * @readOnly
  45264. * @type {string}
  45265. */
  45266. this.mappingMethod = mappingMethod;
  45267. /**
  45268. * @private
  45269. * @type {Function}
  45270. */
  45271. this._normalizeData = normalizers[mappingMethod];
  45272. var visualHandler = visualHandlers[visualType];
  45273. /**
  45274. * @public
  45275. * @type {Function}
  45276. */
  45277. this.applyVisual = visualHandler.applyVisual;
  45278. /**
  45279. * @public
  45280. * @type {Function}
  45281. */
  45282. this.getColorMapper = visualHandler.getColorMapper;
  45283. /**
  45284. * @private
  45285. * @type {Function}
  45286. */
  45287. this._doMap = visualHandler._doMap[mappingMethod];
  45288. if (mappingMethod === 'piecewise') {
  45289. normalizeVisualRange(thisOption);
  45290. preprocessForPiecewise(thisOption);
  45291. }
  45292. else if (mappingMethod === 'category') {
  45293. thisOption.categories
  45294. ? preprocessForSpecifiedCategory(thisOption)
  45295. // categories is ordinal when thisOption.categories not specified,
  45296. // which need no more preprocess except normalize visual.
  45297. : normalizeVisualRange(thisOption, true);
  45298. }
  45299. else { // mappingMethod === 'linear' or 'fixed'
  45300. assert$1(mappingMethod !== 'linear' || thisOption.dataExtent);
  45301. normalizeVisualRange(thisOption);
  45302. }
  45303. };
  45304. VisualMapping.prototype = {
  45305. constructor: VisualMapping,
  45306. mapValueToVisual: function (value) {
  45307. var normalized = this._normalizeData(value);
  45308. return this._doMap(normalized, value);
  45309. },
  45310. getNormalizer: function () {
  45311. return bind(this._normalizeData, this);
  45312. }
  45313. };
  45314. var visualHandlers = VisualMapping.visualHandlers = {
  45315. color: {
  45316. applyVisual: makeApplyVisual('color'),
  45317. /**
  45318. * Create a mapper function
  45319. * @return {Function}
  45320. */
  45321. getColorMapper: function () {
  45322. var thisOption = this.option;
  45323. return bind(
  45324. thisOption.mappingMethod === 'category'
  45325. ? function (value, isNormalized) {
  45326. !isNormalized && (value = this._normalizeData(value));
  45327. return doMapCategory.call(this, value);
  45328. }
  45329. : function (value, isNormalized, out) {
  45330. // If output rgb array
  45331. // which will be much faster and useful in pixel manipulation
  45332. var returnRGBArray = !!out;
  45333. !isNormalized && (value = this._normalizeData(value));
  45334. out = fastLerp(value, thisOption.parsedVisual, out);
  45335. return returnRGBArray ? out : stringify(out, 'rgba');
  45336. },
  45337. this
  45338. );
  45339. },
  45340. _doMap: {
  45341. linear: function (normalized) {
  45342. return stringify(
  45343. fastLerp(normalized, this.option.parsedVisual),
  45344. 'rgba'
  45345. );
  45346. },
  45347. category: doMapCategory,
  45348. piecewise: function (normalized, value) {
  45349. var result = getSpecifiedVisual.call(this, value);
  45350. if (result == null) {
  45351. result = stringify(
  45352. fastLerp(normalized, this.option.parsedVisual),
  45353. 'rgba'
  45354. );
  45355. }
  45356. return result;
  45357. },
  45358. fixed: doMapFixed
  45359. }
  45360. },
  45361. colorHue: makePartialColorVisualHandler(function (color, value) {
  45362. return modifyHSL(color, value);
  45363. }),
  45364. colorSaturation: makePartialColorVisualHandler(function (color, value) {
  45365. return modifyHSL(color, null, value);
  45366. }),
  45367. colorLightness: makePartialColorVisualHandler(function (color, value) {
  45368. return modifyHSL(color, null, null, value);
  45369. }),
  45370. colorAlpha: makePartialColorVisualHandler(function (color, value) {
  45371. return modifyAlpha(color, value);
  45372. }),
  45373. opacity: {
  45374. applyVisual: makeApplyVisual('opacity'),
  45375. _doMap: makeDoMap([0, 1])
  45376. },
  45377. liftZ: {
  45378. applyVisual: makeApplyVisual('liftZ'),
  45379. _doMap: {
  45380. linear: doMapFixed,
  45381. category: doMapFixed,
  45382. piecewise: doMapFixed,
  45383. fixed: doMapFixed
  45384. }
  45385. },
  45386. symbol: {
  45387. applyVisual: function (value, getter, setter) {
  45388. var symbolCfg = this.mapValueToVisual(value);
  45389. if (isString(symbolCfg)) {
  45390. setter('symbol', symbolCfg);
  45391. }
  45392. else if (isObject$5(symbolCfg)) {
  45393. for (var name in symbolCfg) {
  45394. if (symbolCfg.hasOwnProperty(name)) {
  45395. setter(name, symbolCfg[name]);
  45396. }
  45397. }
  45398. }
  45399. },
  45400. _doMap: {
  45401. linear: doMapToArray,
  45402. category: doMapCategory,
  45403. piecewise: function (normalized, value) {
  45404. var result = getSpecifiedVisual.call(this, value);
  45405. if (result == null) {
  45406. result = doMapToArray.call(this, normalized);
  45407. }
  45408. return result;
  45409. },
  45410. fixed: doMapFixed
  45411. }
  45412. },
  45413. symbolSize: {
  45414. applyVisual: makeApplyVisual('symbolSize'),
  45415. _doMap: makeDoMap([0, 1])
  45416. }
  45417. };
  45418. function preprocessForPiecewise(thisOption) {
  45419. var pieceList = thisOption.pieceList;
  45420. thisOption.hasSpecialVisual = false;
  45421. each$1(pieceList, function (piece, index) {
  45422. piece.originIndex = index;
  45423. // piece.visual is "result visual value" but not
  45424. // a visual range, so it does not need to be normalized.
  45425. if (piece.visual != null) {
  45426. thisOption.hasSpecialVisual = true;
  45427. }
  45428. });
  45429. }
  45430. function preprocessForSpecifiedCategory(thisOption) {
  45431. // Hash categories.
  45432. var categories = thisOption.categories;
  45433. var visual = thisOption.visual;
  45434. var categoryMap = thisOption.categoryMap = {};
  45435. each$9(categories, function (cate, index) {
  45436. categoryMap[cate] = index;
  45437. });
  45438. // Process visual map input.
  45439. if (!isArray(visual)) {
  45440. var visualArr = [];
  45441. if (isObject$1(visual)) {
  45442. each$9(visual, function (v, cate) {
  45443. var index = categoryMap[cate];
  45444. visualArr[index != null ? index : CATEGORY_DEFAULT_VISUAL_INDEX] = v;
  45445. });
  45446. }
  45447. else { // Is primary type, represents default visual.
  45448. visualArr[CATEGORY_DEFAULT_VISUAL_INDEX] = visual;
  45449. }
  45450. visual = setVisualToOption(thisOption, visualArr);
  45451. }
  45452. // Remove categories that has no visual,
  45453. // then we can mapping them to CATEGORY_DEFAULT_VISUAL_INDEX.
  45454. for (var i = categories.length - 1; i >= 0; i--) {
  45455. if (visual[i] == null) {
  45456. delete categoryMap[categories[i]];
  45457. categories.pop();
  45458. }
  45459. }
  45460. }
  45461. function normalizeVisualRange(thisOption, isCategory) {
  45462. var visual = thisOption.visual;
  45463. var visualArr = [];
  45464. if (isObject$1(visual)) {
  45465. each$9(visual, function (v) {
  45466. visualArr.push(v);
  45467. });
  45468. }
  45469. else if (visual != null) {
  45470. visualArr.push(visual);
  45471. }
  45472. var doNotNeedPair = {color: 1, symbol: 1};
  45473. if (!isCategory
  45474. && visualArr.length === 1
  45475. && !doNotNeedPair.hasOwnProperty(thisOption.type)
  45476. ) {
  45477. // Do not care visualArr.length === 0, which is illegal.
  45478. visualArr[1] = visualArr[0];
  45479. }
  45480. setVisualToOption(thisOption, visualArr);
  45481. }
  45482. function makePartialColorVisualHandler(applyValue) {
  45483. return {
  45484. applyVisual: function (value, getter, setter) {
  45485. value = this.mapValueToVisual(value);
  45486. // Must not be array value
  45487. setter('color', applyValue(getter('color'), value));
  45488. },
  45489. _doMap: makeDoMap([0, 1])
  45490. };
  45491. }
  45492. function doMapToArray(normalized) {
  45493. var visual = this.option.visual;
  45494. return visual[
  45495. Math.round(linearMap(normalized, [0, 1], [0, visual.length - 1], true))
  45496. ] || {};
  45497. }
  45498. function makeApplyVisual(visualType) {
  45499. return function (value, getter, setter) {
  45500. setter(visualType, this.mapValueToVisual(value));
  45501. };
  45502. }
  45503. function doMapCategory(normalized) {
  45504. var visual = this.option.visual;
  45505. return visual[
  45506. (this.option.loop && normalized !== CATEGORY_DEFAULT_VISUAL_INDEX)
  45507. ? normalized % visual.length
  45508. : normalized
  45509. ];
  45510. }
  45511. function doMapFixed() {
  45512. return this.option.visual[0];
  45513. }
  45514. function makeDoMap(sourceExtent) {
  45515. return {
  45516. linear: function (normalized) {
  45517. return linearMap(normalized, sourceExtent, this.option.visual, true);
  45518. },
  45519. category: doMapCategory,
  45520. piecewise: function (normalized, value) {
  45521. var result = getSpecifiedVisual.call(this, value);
  45522. if (result == null) {
  45523. result = linearMap(normalized, sourceExtent, this.option.visual, true);
  45524. }
  45525. return result;
  45526. },
  45527. fixed: doMapFixed
  45528. };
  45529. }
  45530. function getSpecifiedVisual(value) {
  45531. var thisOption = this.option;
  45532. var pieceList = thisOption.pieceList;
  45533. if (thisOption.hasSpecialVisual) {
  45534. var pieceIndex = VisualMapping.findPieceIndex(value, pieceList);
  45535. var piece = pieceList[pieceIndex];
  45536. if (piece && piece.visual) {
  45537. return piece.visual[this.type];
  45538. }
  45539. }
  45540. }
  45541. function setVisualToOption(thisOption, visualArr) {
  45542. thisOption.visual = visualArr;
  45543. if (thisOption.type === 'color') {
  45544. thisOption.parsedVisual = map(visualArr, function (item) {
  45545. return parse(item);
  45546. });
  45547. }
  45548. return visualArr;
  45549. }
  45550. /**
  45551. * Normalizers by mapping methods.
  45552. */
  45553. var normalizers = {
  45554. linear: function (value) {
  45555. return linearMap(value, this.option.dataExtent, [0, 1], true);
  45556. },
  45557. piecewise: function (value) {
  45558. var pieceList = this.option.pieceList;
  45559. var pieceIndex = VisualMapping.findPieceIndex(value, pieceList, true);
  45560. if (pieceIndex != null) {
  45561. return linearMap(pieceIndex, [0, pieceList.length - 1], [0, 1], true);
  45562. }
  45563. },
  45564. category: function (value) {
  45565. var index = this.option.categories
  45566. ? this.option.categoryMap[value]
  45567. : value; // ordinal
  45568. return index == null ? CATEGORY_DEFAULT_VISUAL_INDEX : index;
  45569. },
  45570. fixed: noop
  45571. };
  45572. /**
  45573. * List available visual types.
  45574. *
  45575. * @public
  45576. * @return {Array.<string>}
  45577. */
  45578. VisualMapping.listVisualTypes = function () {
  45579. var visualTypes = [];
  45580. each$1(visualHandlers, function (handler, key) {
  45581. visualTypes.push(key);
  45582. });
  45583. return visualTypes;
  45584. };
  45585. /**
  45586. * @public
  45587. */
  45588. VisualMapping.addVisualHandler = function (name, handler) {
  45589. visualHandlers[name] = handler;
  45590. };
  45591. /**
  45592. * @public
  45593. */
  45594. VisualMapping.isValidType = function (visualType) {
  45595. return visualHandlers.hasOwnProperty(visualType);
  45596. };
  45597. /**
  45598. * Convinent method.
  45599. * Visual can be Object or Array or primary type.
  45600. *
  45601. * @public
  45602. */
  45603. VisualMapping.eachVisual = function (visual, callback, context) {
  45604. if (isObject$1(visual)) {
  45605. each$1(visual, callback, context);
  45606. }
  45607. else {
  45608. callback.call(context, visual);
  45609. }
  45610. };
  45611. VisualMapping.mapVisual = function (visual, callback, context) {
  45612. var isPrimary;
  45613. var newVisual = isArray(visual)
  45614. ? []
  45615. : isObject$1(visual)
  45616. ? {}
  45617. : (isPrimary = true, null);
  45618. VisualMapping.eachVisual(visual, function (v, key) {
  45619. var newVal = callback.call(context, v, key);
  45620. isPrimary ? (newVisual = newVal) : (newVisual[key] = newVal);
  45621. });
  45622. return newVisual;
  45623. };
  45624. /**
  45625. * @public
  45626. * @param {Object} obj
  45627. * @return {Object} new object containers visual values.
  45628. * If no visuals, return null.
  45629. */
  45630. VisualMapping.retrieveVisuals = function (obj) {
  45631. var ret = {};
  45632. var hasVisual;
  45633. obj && each$9(visualHandlers, function (h, visualType) {
  45634. if (obj.hasOwnProperty(visualType)) {
  45635. ret[visualType] = obj[visualType];
  45636. hasVisual = true;
  45637. }
  45638. });
  45639. return hasVisual ? ret : null;
  45640. };
  45641. /**
  45642. * Give order to visual types, considering colorSaturation, colorAlpha depends on color.
  45643. *
  45644. * @public
  45645. * @param {(Object|Array)} visualTypes If Object, like: {color: ..., colorSaturation: ...}
  45646. * IF Array, like: ['color', 'symbol', 'colorSaturation']
  45647. * @return {Array.<string>} Sorted visual types.
  45648. */
  45649. VisualMapping.prepareVisualTypes = function (visualTypes) {
  45650. if (isObject$5(visualTypes)) {
  45651. var types = [];
  45652. each$9(visualTypes, function (item, type) {
  45653. types.push(type);
  45654. });
  45655. visualTypes = types;
  45656. }
  45657. else if (isArray(visualTypes)) {
  45658. visualTypes = visualTypes.slice();
  45659. }
  45660. else {
  45661. return [];
  45662. }
  45663. visualTypes.sort(function (type1, type2) {
  45664. // color should be front of colorSaturation, colorAlpha, ...
  45665. // symbol and symbolSize do not matter.
  45666. return (type2 === 'color' && type1 !== 'color' && type1.indexOf('color') === 0)
  45667. ? 1 : -1;
  45668. });
  45669. return visualTypes;
  45670. };
  45671. /**
  45672. * 'color', 'colorSaturation', 'colorAlpha', ... are depends on 'color'.
  45673. * Other visuals are only depends on themself.
  45674. *
  45675. * @public
  45676. * @param {string} visualType1
  45677. * @param {string} visualType2
  45678. * @return {boolean}
  45679. */
  45680. VisualMapping.dependsOn = function (visualType1, visualType2) {
  45681. return visualType2 === 'color'
  45682. ? !!(visualType1 && visualType1.indexOf(visualType2) === 0)
  45683. : visualType1 === visualType2;
  45684. };
  45685. /**
  45686. * @param {number} value
  45687. * @param {Array.<Object>} pieceList [{value: ..., interval: [min, max]}, ...]
  45688. * Always from small to big.
  45689. * @param {boolean} [findClosestWhenOutside=false]
  45690. * @return {number} index
  45691. */
  45692. VisualMapping.findPieceIndex = function (value, pieceList, findClosestWhenOutside) {
  45693. var possibleI;
  45694. var abs = Infinity;
  45695. // value has the higher priority.
  45696. for (var i = 0, len = pieceList.length; i < len; i++) {
  45697. var pieceValue = pieceList[i].value;
  45698. if (pieceValue != null) {
  45699. if (pieceValue === value
  45700. // FIXME
  45701. // It is supposed to compare value according to value type of dimension,
  45702. // but currently value type can exactly be string or number.
  45703. // Compromise for numeric-like string (like '12'), especially
  45704. // in the case that visualMap.categories is ['22', '33'].
  45705. || (typeof pieceValue === 'string' && pieceValue === value + '')
  45706. ) {
  45707. return i;
  45708. }
  45709. findClosestWhenOutside && updatePossible(pieceValue, i);
  45710. }
  45711. }
  45712. for (var i = 0, len = pieceList.length; i < len; i++) {
  45713. var piece = pieceList[i];
  45714. var interval = piece.interval;
  45715. var close = piece.close;
  45716. if (interval) {
  45717. if (interval[0] === -Infinity) {
  45718. if (littleThan(close[1], value, interval[1])) {
  45719. return i;
  45720. }
  45721. }
  45722. else if (interval[1] === Infinity) {
  45723. if (littleThan(close[0], interval[0], value)) {
  45724. return i;
  45725. }
  45726. }
  45727. else if (
  45728. littleThan(close[0], interval[0], value)
  45729. && littleThan(close[1], value, interval[1])
  45730. ) {
  45731. return i;
  45732. }
  45733. findClosestWhenOutside && updatePossible(interval[0], i);
  45734. findClosestWhenOutside && updatePossible(interval[1], i);
  45735. }
  45736. }
  45737. if (findClosestWhenOutside) {
  45738. return value === Infinity
  45739. ? pieceList.length - 1
  45740. : value === -Infinity
  45741. ? 0
  45742. : possibleI;
  45743. }
  45744. function updatePossible(val, index) {
  45745. var newAbs = Math.abs(val - value);
  45746. if (newAbs < abs) {
  45747. abs = newAbs;
  45748. possibleI = index;
  45749. }
  45750. }
  45751. };
  45752. function littleThan(close, a, b) {
  45753. return close ? a <= b : a < b;
  45754. }
  45755. /*
  45756. * Licensed to the Apache Software Foundation (ASF) under one
  45757. * or more contributor license agreements. See the NOTICE file
  45758. * distributed with this work for additional information
  45759. * regarding copyright ownership. The ASF licenses this file
  45760. * to you under the Apache License, Version 2.0 (the
  45761. * "License"); you may not use this file except in compliance
  45762. * with the License. You may obtain a copy of the License at
  45763. *
  45764. * http://www.apache.org/licenses/LICENSE-2.0
  45765. *
  45766. * Unless required by applicable law or agreed to in writing,
  45767. * software distributed under the License is distributed on an
  45768. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  45769. * KIND, either express or implied. See the License for the
  45770. * specific language governing permissions and limitations
  45771. * under the License.
  45772. */
  45773. var isArray$2 = isArray;
  45774. var ITEM_STYLE_NORMAL = 'itemStyle';
  45775. var treemapVisual = {
  45776. seriesType: 'treemap',
  45777. reset: function (seriesModel, ecModel, api, payload) {
  45778. var tree = seriesModel.getData().tree;
  45779. var root = tree.root;
  45780. var seriesItemStyleModel = seriesModel.getModel(ITEM_STYLE_NORMAL);
  45781. if (root.isRemoved()) {
  45782. return;
  45783. }
  45784. var levelItemStyles = map(tree.levelModels, function (levelModel) {
  45785. return levelModel ? levelModel.get(ITEM_STYLE_NORMAL) : null;
  45786. });
  45787. travelTree(
  45788. root, // Visual should calculate from tree root but not view root.
  45789. {},
  45790. levelItemStyles,
  45791. seriesItemStyleModel,
  45792. seriesModel.getViewRoot().getAncestors(),
  45793. seriesModel
  45794. );
  45795. }
  45796. };
  45797. function travelTree(
  45798. node, designatedVisual, levelItemStyles, seriesItemStyleModel,
  45799. viewRootAncestors, seriesModel
  45800. ) {
  45801. var nodeModel = node.getModel();
  45802. var nodeLayout = node.getLayout();
  45803. // Optimize
  45804. if (!nodeLayout || nodeLayout.invisible || !nodeLayout.isInView) {
  45805. return;
  45806. }
  45807. var nodeItemStyleModel = node.getModel(ITEM_STYLE_NORMAL);
  45808. var levelItemStyle = levelItemStyles[node.depth];
  45809. var visuals = buildVisuals(
  45810. nodeItemStyleModel, designatedVisual, levelItemStyle, seriesItemStyleModel
  45811. );
  45812. // calculate border color
  45813. var borderColor = nodeItemStyleModel.get('borderColor');
  45814. var borderColorSaturation = nodeItemStyleModel.get('borderColorSaturation');
  45815. var thisNodeColor;
  45816. if (borderColorSaturation != null) {
  45817. // For performance, do not always execute 'calculateColor'.
  45818. thisNodeColor = calculateColor(visuals, node);
  45819. borderColor = calculateBorderColor(borderColorSaturation, thisNodeColor);
  45820. }
  45821. node.setVisual('borderColor', borderColor);
  45822. var viewChildren = node.viewChildren;
  45823. if (!viewChildren || !viewChildren.length) {
  45824. thisNodeColor = calculateColor(visuals, node);
  45825. // Apply visual to this node.
  45826. node.setVisual('color', thisNodeColor);
  45827. }
  45828. else {
  45829. var mapping = buildVisualMapping(
  45830. node, nodeModel, nodeLayout, nodeItemStyleModel, visuals, viewChildren
  45831. );
  45832. // Designate visual to children.
  45833. each$1(viewChildren, function (child, index) {
  45834. // If higher than viewRoot, only ancestors of viewRoot is needed to visit.
  45835. if (child.depth >= viewRootAncestors.length
  45836. || child === viewRootAncestors[child.depth]
  45837. ) {
  45838. var childVisual = mapVisual$1(
  45839. nodeModel, visuals, child, index, mapping, seriesModel
  45840. );
  45841. travelTree(
  45842. child, childVisual, levelItemStyles, seriesItemStyleModel,
  45843. viewRootAncestors, seriesModel
  45844. );
  45845. }
  45846. });
  45847. }
  45848. }
  45849. function buildVisuals(
  45850. nodeItemStyleModel, designatedVisual, levelItemStyle, seriesItemStyleModel
  45851. ) {
  45852. var visuals = extend({}, designatedVisual);
  45853. each$1(['color', 'colorAlpha', 'colorSaturation'], function (visualName) {
  45854. // Priority: thisNode > thisLevel > parentNodeDesignated > seriesModel
  45855. var val = nodeItemStyleModel.get(visualName, true); // Ignore parent
  45856. val == null && levelItemStyle && (val = levelItemStyle[visualName]);
  45857. val == null && (val = designatedVisual[visualName]);
  45858. val == null && (val = seriesItemStyleModel.get(visualName));
  45859. val != null && (visuals[visualName] = val);
  45860. });
  45861. return visuals;
  45862. }
  45863. function calculateColor(visuals) {
  45864. var color = getValueVisualDefine(visuals, 'color');
  45865. if (color) {
  45866. var colorAlpha = getValueVisualDefine(visuals, 'colorAlpha');
  45867. var colorSaturation = getValueVisualDefine(visuals, 'colorSaturation');
  45868. if (colorSaturation) {
  45869. color = modifyHSL(color, null, null, colorSaturation);
  45870. }
  45871. if (colorAlpha) {
  45872. color = modifyAlpha(color, colorAlpha);
  45873. }
  45874. return color;
  45875. }
  45876. }
  45877. function calculateBorderColor(borderColorSaturation, thisNodeColor) {
  45878. return thisNodeColor != null
  45879. ? modifyHSL(thisNodeColor, null, null, borderColorSaturation)
  45880. : null;
  45881. }
  45882. function getValueVisualDefine(visuals, name) {
  45883. var value = visuals[name];
  45884. if (value != null && value !== 'none') {
  45885. return value;
  45886. }
  45887. }
  45888. function buildVisualMapping(
  45889. node, nodeModel, nodeLayout, nodeItemStyleModel, visuals, viewChildren
  45890. ) {
  45891. if (!viewChildren || !viewChildren.length) {
  45892. return;
  45893. }
  45894. var rangeVisual = getRangeVisual(nodeModel, 'color')
  45895. || (
  45896. visuals.color != null
  45897. && visuals.color !== 'none'
  45898. && (
  45899. getRangeVisual(nodeModel, 'colorAlpha')
  45900. || getRangeVisual(nodeModel, 'colorSaturation')
  45901. )
  45902. );
  45903. if (!rangeVisual) {
  45904. return;
  45905. }
  45906. var visualMin = nodeModel.get('visualMin');
  45907. var visualMax = nodeModel.get('visualMax');
  45908. var dataExtent = nodeLayout.dataExtent.slice();
  45909. visualMin != null && visualMin < dataExtent[0] && (dataExtent[0] = visualMin);
  45910. visualMax != null && visualMax > dataExtent[1] && (dataExtent[1] = visualMax);
  45911. var colorMappingBy = nodeModel.get('colorMappingBy');
  45912. var opt = {
  45913. type: rangeVisual.name,
  45914. dataExtent: dataExtent,
  45915. visual: rangeVisual.range
  45916. };
  45917. if (opt.type === 'color'
  45918. && (colorMappingBy === 'index' || colorMappingBy === 'id')
  45919. ) {
  45920. opt.mappingMethod = 'category';
  45921. opt.loop = true;
  45922. // categories is ordinal, so do not set opt.categories.
  45923. }
  45924. else {
  45925. opt.mappingMethod = 'linear';
  45926. }
  45927. var mapping = new VisualMapping(opt);
  45928. mapping.__drColorMappingBy = colorMappingBy;
  45929. return mapping;
  45930. }
  45931. // Notice: If we dont have the attribute 'colorRange', but only use
  45932. // attribute 'color' to represent both concepts of 'colorRange' and 'color',
  45933. // (It means 'colorRange' when 'color' is Array, means 'color' when not array),
  45934. // this problem will be encountered:
  45935. // If a level-1 node dont have children, and its siblings has children,
  45936. // and colorRange is set on level-1, then the node can not be colored.
  45937. // So we separate 'colorRange' and 'color' to different attributes.
  45938. function getRangeVisual(nodeModel, name) {
  45939. // 'colorRange', 'colorARange', 'colorSRange'.
  45940. // If not exsits on this node, fetch from levels and series.
  45941. var range = nodeModel.get(name);
  45942. return (isArray$2(range) && range.length) ? {name: name, range: range} : null;
  45943. }
  45944. function mapVisual$1(nodeModel, visuals, child, index, mapping, seriesModel) {
  45945. var childVisuals = extend({}, visuals);
  45946. if (mapping) {
  45947. var mappingType = mapping.type;
  45948. var colorMappingBy = mappingType === 'color' && mapping.__drColorMappingBy;
  45949. var value = colorMappingBy === 'index'
  45950. ? index
  45951. : colorMappingBy === 'id'
  45952. ? seriesModel.mapIdToIndex(child.getId())
  45953. : child.getValue(nodeModel.get('visualDimension'));
  45954. childVisuals[mappingType] = mapping.mapValueToVisual(value);
  45955. }
  45956. return childVisuals;
  45957. }
  45958. /*
  45959. * Licensed to the Apache Software Foundation (ASF) under one
  45960. * or more contributor license agreements. See the NOTICE file
  45961. * distributed with this work for additional information
  45962. * regarding copyright ownership. The ASF licenses this file
  45963. * to you under the Apache License, Version 2.0 (the
  45964. * "License"); you may not use this file except in compliance
  45965. * with the License. You may obtain a copy of the License at
  45966. *
  45967. * http://www.apache.org/licenses/LICENSE-2.0
  45968. *
  45969. * Unless required by applicable law or agreed to in writing,
  45970. * software distributed under the License is distributed on an
  45971. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  45972. * KIND, either express or implied. See the License for the
  45973. * specific language governing permissions and limitations
  45974. * under the License.
  45975. */
  45976. /*
  45977. * A third-party license is embeded for some of the code in this file:
  45978. * The treemap layout implementation was originally copied from
  45979. * "d3.js" with some modifications made for this project.
  45980. * (See more details in the comment of the method "squarify" below.)
  45981. * The use of the source code of this file is also subject to the terms
  45982. * and consitions of the license of "d3.js" (BSD-3Clause, see
  45983. * </licenses/LICENSE-d3>).
  45984. */
  45985. var mathMax$4 = Math.max;
  45986. var mathMin$4 = Math.min;
  45987. var retrieveValue = retrieve;
  45988. var each$10 = each$1;
  45989. var PATH_BORDER_WIDTH = ['itemStyle', 'borderWidth'];
  45990. var PATH_GAP_WIDTH = ['itemStyle', 'gapWidth'];
  45991. var PATH_UPPER_LABEL_SHOW = ['upperLabel', 'show'];
  45992. var PATH_UPPER_LABEL_HEIGHT = ['upperLabel', 'height'];
  45993. /**
  45994. * @public
  45995. */
  45996. var treemapLayout = {
  45997. seriesType: 'treemap',
  45998. reset: function (seriesModel, ecModel, api, payload) {
  45999. // Layout result in each node:
  46000. // {x, y, width, height, area, borderWidth}
  46001. var ecWidth = api.getWidth();
  46002. var ecHeight = api.getHeight();
  46003. var seriesOption = seriesModel.option;
  46004. var layoutInfo = getLayoutRect(
  46005. seriesModel.getBoxLayoutParams(),
  46006. {
  46007. width: api.getWidth(),
  46008. height: api.getHeight()
  46009. }
  46010. );
  46011. var size = seriesOption.size || []; // Compatible with ec2.
  46012. var containerWidth = parsePercent$1(
  46013. retrieveValue(layoutInfo.width, size[0]),
  46014. ecWidth
  46015. );
  46016. var containerHeight = parsePercent$1(
  46017. retrieveValue(layoutInfo.height, size[1]),
  46018. ecHeight
  46019. );
  46020. // Fetch payload info.
  46021. var payloadType = payload && payload.type;
  46022. var types = ['treemapZoomToNode', 'treemapRootToNode'];
  46023. var targetInfo = retrieveTargetInfo(payload, types, seriesModel);
  46024. var rootRect = (payloadType === 'treemapRender' || payloadType === 'treemapMove')
  46025. ? payload.rootRect : null;
  46026. var viewRoot = seriesModel.getViewRoot();
  46027. var viewAbovePath = getPathToRoot(viewRoot);
  46028. if (payloadType !== 'treemapMove') {
  46029. var rootSize = payloadType === 'treemapZoomToNode'
  46030. ? estimateRootSize(
  46031. seriesModel, targetInfo, viewRoot, containerWidth, containerHeight
  46032. )
  46033. : rootRect
  46034. ? [rootRect.width, rootRect.height]
  46035. : [containerWidth, containerHeight];
  46036. var sort = seriesOption.sort;
  46037. if (sort && sort !== 'asc' && sort !== 'desc') {
  46038. sort = 'desc';
  46039. }
  46040. var options = {
  46041. squareRatio: seriesOption.squareRatio,
  46042. sort: sort,
  46043. leafDepth: seriesOption.leafDepth
  46044. };
  46045. // layout should be cleared because using updateView but not update.
  46046. viewRoot.hostTree.clearLayouts();
  46047. // TODO
  46048. // optimize: if out of view clip, do not layout.
  46049. // But take care that if do not render node out of view clip,
  46050. // how to calculate start po
  46051. var viewRootLayout = {
  46052. x: 0, y: 0,
  46053. width: rootSize[0], height: rootSize[1],
  46054. area: rootSize[0] * rootSize[1]
  46055. };
  46056. viewRoot.setLayout(viewRootLayout);
  46057. squarify(viewRoot, options, false, 0);
  46058. // Supplement layout.
  46059. var viewRootLayout = viewRoot.getLayout();
  46060. each$10(viewAbovePath, function (node, index) {
  46061. var childValue = (viewAbovePath[index + 1] || viewRoot).getValue();
  46062. node.setLayout(extend(
  46063. {dataExtent: [childValue, childValue], borderWidth: 0, upperHeight: 0},
  46064. viewRootLayout
  46065. ));
  46066. });
  46067. }
  46068. var treeRoot = seriesModel.getData().tree.root;
  46069. treeRoot.setLayout(
  46070. calculateRootPosition(layoutInfo, rootRect, targetInfo),
  46071. true
  46072. );
  46073. seriesModel.setLayoutInfo(layoutInfo);
  46074. // FIXME
  46075. // 现在没有clip功能,暂时取ec高宽。
  46076. prunning(
  46077. treeRoot,
  46078. // Transform to base element coordinate system.
  46079. new BoundingRect(-layoutInfo.x, -layoutInfo.y, ecWidth, ecHeight),
  46080. viewAbovePath,
  46081. viewRoot,
  46082. 0
  46083. );
  46084. }
  46085. };
  46086. /**
  46087. * Layout treemap with squarify algorithm.
  46088. * The original presentation of this algorithm
  46089. * was made by Mark Bruls, Kees Huizing, and Jarke J. van Wijk
  46090. * <https://graphics.ethz.ch/teaching/scivis_common/Literature/squarifiedTreeMaps.pdf>.
  46091. * The implementation of this algorithm was originally copied from "d3.js"
  46092. * <https://github.com/d3/d3/blob/9cc9a875e636a1dcf36cc1e07bdf77e1ad6e2c74/src/layout/treemap.js>
  46093. * with some modifications made for this program.
  46094. * See the license statement at the head of this file.
  46095. *
  46096. * @protected
  46097. * @param {module:echarts/data/Tree~TreeNode} node
  46098. * @param {Object} options
  46099. * @param {string} options.sort 'asc' or 'desc'
  46100. * @param {number} options.squareRatio
  46101. * @param {boolean} hideChildren
  46102. * @param {number} depth
  46103. */
  46104. function squarify(node, options, hideChildren, depth) {
  46105. var width;
  46106. var height;
  46107. if (node.isRemoved()) {
  46108. return;
  46109. }
  46110. var thisLayout = node.getLayout();
  46111. width = thisLayout.width;
  46112. height = thisLayout.height;
  46113. // Considering border and gap
  46114. var nodeModel = node.getModel();
  46115. var borderWidth = nodeModel.get(PATH_BORDER_WIDTH);
  46116. var halfGapWidth = nodeModel.get(PATH_GAP_WIDTH) / 2;
  46117. var upperLabelHeight = getUpperLabelHeight(nodeModel);
  46118. var upperHeight = Math.max(borderWidth, upperLabelHeight);
  46119. var layoutOffset = borderWidth - halfGapWidth;
  46120. var layoutOffsetUpper = upperHeight - halfGapWidth;
  46121. var nodeModel = node.getModel();
  46122. node.setLayout({
  46123. borderWidth: borderWidth,
  46124. upperHeight: upperHeight,
  46125. upperLabelHeight: upperLabelHeight
  46126. }, true);
  46127. width = mathMax$4(width - 2 * layoutOffset, 0);
  46128. height = mathMax$4(height - layoutOffset - layoutOffsetUpper, 0);
  46129. var totalArea = width * height;
  46130. var viewChildren = initChildren(
  46131. node, nodeModel, totalArea, options, hideChildren, depth
  46132. );
  46133. if (!viewChildren.length) {
  46134. return;
  46135. }
  46136. var rect = {x: layoutOffset, y: layoutOffsetUpper, width: width, height: height};
  46137. var rowFixedLength = mathMin$4(width, height);
  46138. var best = Infinity; // the best row score so far
  46139. var row = [];
  46140. row.area = 0;
  46141. for (var i = 0, len = viewChildren.length; i < len;) {
  46142. var child = viewChildren[i];
  46143. row.push(child);
  46144. row.area += child.getLayout().area;
  46145. var score = worst(row, rowFixedLength, options.squareRatio);
  46146. // continue with this orientation
  46147. if (score <= best) {
  46148. i++;
  46149. best = score;
  46150. }
  46151. // abort, and try a different orientation
  46152. else {
  46153. row.area -= row.pop().getLayout().area;
  46154. position(row, rowFixedLength, rect, halfGapWidth, false);
  46155. rowFixedLength = mathMin$4(rect.width, rect.height);
  46156. row.length = row.area = 0;
  46157. best = Infinity;
  46158. }
  46159. }
  46160. if (row.length) {
  46161. position(row, rowFixedLength, rect, halfGapWidth, true);
  46162. }
  46163. if (!hideChildren) {
  46164. var childrenVisibleMin = nodeModel.get('childrenVisibleMin');
  46165. if (childrenVisibleMin != null && totalArea < childrenVisibleMin) {
  46166. hideChildren = true;
  46167. }
  46168. }
  46169. for (var i = 0, len = viewChildren.length; i < len; i++) {
  46170. squarify(viewChildren[i], options, hideChildren, depth + 1);
  46171. }
  46172. }
  46173. /**
  46174. * Set area to each child, and calculate data extent for visual coding.
  46175. */
  46176. function initChildren(node, nodeModel, totalArea, options, hideChildren, depth) {
  46177. var viewChildren = node.children || [];
  46178. var orderBy = options.sort;
  46179. orderBy !== 'asc' && orderBy !== 'desc' && (orderBy = null);
  46180. var overLeafDepth = options.leafDepth != null && options.leafDepth <= depth;
  46181. // leafDepth has higher priority.
  46182. if (hideChildren && !overLeafDepth) {
  46183. return (node.viewChildren = []);
  46184. }
  46185. // Sort children, order by desc.
  46186. viewChildren = filter(viewChildren, function (child) {
  46187. return !child.isRemoved();
  46188. });
  46189. sort$1(viewChildren, orderBy);
  46190. var info = statistic(nodeModel, viewChildren, orderBy);
  46191. if (info.sum === 0) {
  46192. return (node.viewChildren = []);
  46193. }
  46194. info.sum = filterByThreshold(nodeModel, totalArea, info.sum, orderBy, viewChildren);
  46195. if (info.sum === 0) {
  46196. return (node.viewChildren = []);
  46197. }
  46198. // Set area to each child.
  46199. for (var i = 0, len = viewChildren.length; i < len; i++) {
  46200. var area = viewChildren[i].getValue() / info.sum * totalArea;
  46201. // Do not use setLayout({...}, true), because it is needed to clear last layout.
  46202. viewChildren[i].setLayout({area: area});
  46203. }
  46204. if (overLeafDepth) {
  46205. viewChildren.length && node.setLayout({isLeafRoot: true}, true);
  46206. viewChildren.length = 0;
  46207. }
  46208. node.viewChildren = viewChildren;
  46209. node.setLayout({dataExtent: info.dataExtent}, true);
  46210. return viewChildren;
  46211. }
  46212. /**
  46213. * Consider 'visibleMin'. Modify viewChildren and get new sum.
  46214. */
  46215. function filterByThreshold(nodeModel, totalArea, sum, orderBy, orderedChildren) {
  46216. // visibleMin is not supported yet when no option.sort.
  46217. if (!orderBy) {
  46218. return sum;
  46219. }
  46220. var visibleMin = nodeModel.get('visibleMin');
  46221. var len = orderedChildren.length;
  46222. var deletePoint = len;
  46223. // Always travel from little value to big value.
  46224. for (var i = len - 1; i >= 0; i--) {
  46225. var value = orderedChildren[
  46226. orderBy === 'asc' ? len - i - 1 : i
  46227. ].getValue();
  46228. if (value / sum * totalArea < visibleMin) {
  46229. deletePoint = i;
  46230. sum -= value;
  46231. }
  46232. }
  46233. orderBy === 'asc'
  46234. ? orderedChildren.splice(0, len - deletePoint)
  46235. : orderedChildren.splice(deletePoint, len - deletePoint);
  46236. return sum;
  46237. }
  46238. /**
  46239. * Sort
  46240. */
  46241. function sort$1(viewChildren, orderBy) {
  46242. if (orderBy) {
  46243. viewChildren.sort(function (a, b) {
  46244. var diff = orderBy === 'asc'
  46245. ? a.getValue() - b.getValue() : b.getValue() - a.getValue();
  46246. return diff === 0
  46247. ? (orderBy === 'asc'
  46248. ? a.dataIndex - b.dataIndex : b.dataIndex - a.dataIndex
  46249. )
  46250. : diff;
  46251. });
  46252. }
  46253. return viewChildren;
  46254. }
  46255. /**
  46256. * Statistic
  46257. */
  46258. function statistic(nodeModel, children, orderBy) {
  46259. // Calculate sum.
  46260. var sum = 0;
  46261. for (var i = 0, len = children.length; i < len; i++) {
  46262. sum += children[i].getValue();
  46263. }
  46264. // Statistic data extent for latter visual coding.
  46265. // Notice: data extent should be calculate based on raw children
  46266. // but not filtered view children, otherwise visual mapping will not
  46267. // be stable when zoom (where children is filtered by visibleMin).
  46268. var dimension = nodeModel.get('visualDimension');
  46269. var dataExtent;
  46270. // The same as area dimension.
  46271. if (!children || !children.length) {
  46272. dataExtent = [NaN, NaN];
  46273. }
  46274. else if (dimension === 'value' && orderBy) {
  46275. dataExtent = [
  46276. children[children.length - 1].getValue(),
  46277. children[0].getValue()
  46278. ];
  46279. orderBy === 'asc' && dataExtent.reverse();
  46280. }
  46281. // Other dimension.
  46282. else {
  46283. var dataExtent = [Infinity, -Infinity];
  46284. each$10(children, function (child) {
  46285. var value = child.getValue(dimension);
  46286. value < dataExtent[0] && (dataExtent[0] = value);
  46287. value > dataExtent[1] && (dataExtent[1] = value);
  46288. });
  46289. }
  46290. return {sum: sum, dataExtent: dataExtent};
  46291. }
  46292. /**
  46293. * Computes the score for the specified row,
  46294. * as the worst aspect ratio.
  46295. */
  46296. function worst(row, rowFixedLength, ratio) {
  46297. var areaMax = 0;
  46298. var areaMin = Infinity;
  46299. for (var i = 0, area, len = row.length; i < len; i++) {
  46300. area = row[i].getLayout().area;
  46301. if (area) {
  46302. area < areaMin && (areaMin = area);
  46303. area > areaMax && (areaMax = area);
  46304. }
  46305. }
  46306. var squareArea = row.area * row.area;
  46307. var f = rowFixedLength * rowFixedLength * ratio;
  46308. return squareArea
  46309. ? mathMax$4(
  46310. (f * areaMax) / squareArea,
  46311. squareArea / (f * areaMin)
  46312. )
  46313. : Infinity;
  46314. }
  46315. /**
  46316. * Positions the specified row of nodes. Modifies `rect`.
  46317. */
  46318. function position(row, rowFixedLength, rect, halfGapWidth, flush) {
  46319. // When rowFixedLength === rect.width,
  46320. // it is horizontal subdivision,
  46321. // rowFixedLength is the width of the subdivision,
  46322. // rowOtherLength is the height of the subdivision,
  46323. // and nodes will be positioned from left to right.
  46324. // wh[idx0WhenH] means: when horizontal,
  46325. // wh[idx0WhenH] => wh[0] => 'width'.
  46326. // xy[idx1WhenH] => xy[1] => 'y'.
  46327. var idx0WhenH = rowFixedLength === rect.width ? 0 : 1;
  46328. var idx1WhenH = 1 - idx0WhenH;
  46329. var xy = ['x', 'y'];
  46330. var wh = ['width', 'height'];
  46331. var last = rect[xy[idx0WhenH]];
  46332. var rowOtherLength = rowFixedLength
  46333. ? row.area / rowFixedLength : 0;
  46334. if (flush || rowOtherLength > rect[wh[idx1WhenH]]) {
  46335. rowOtherLength = rect[wh[idx1WhenH]]; // over+underflow
  46336. }
  46337. for (var i = 0, rowLen = row.length; i < rowLen; i++) {
  46338. var node = row[i];
  46339. var nodeLayout = {};
  46340. var step = rowOtherLength
  46341. ? node.getLayout().area / rowOtherLength : 0;
  46342. var wh1 = nodeLayout[wh[idx1WhenH]] = mathMax$4(rowOtherLength - 2 * halfGapWidth, 0);
  46343. // We use Math.max/min to avoid negative width/height when considering gap width.
  46344. var remain = rect[xy[idx0WhenH]] + rect[wh[idx0WhenH]] - last;
  46345. var modWH = (i === rowLen - 1 || remain < step) ? remain : step;
  46346. var wh0 = nodeLayout[wh[idx0WhenH]] = mathMax$4(modWH - 2 * halfGapWidth, 0);
  46347. nodeLayout[xy[idx1WhenH]] = rect[xy[idx1WhenH]] + mathMin$4(halfGapWidth, wh1 / 2);
  46348. nodeLayout[xy[idx0WhenH]] = last + mathMin$4(halfGapWidth, wh0 / 2);
  46349. last += modWH;
  46350. node.setLayout(nodeLayout, true);
  46351. }
  46352. rect[xy[idx1WhenH]] += rowOtherLength;
  46353. rect[wh[idx1WhenH]] -= rowOtherLength;
  46354. }
  46355. // Return [containerWidth, containerHeight] as defualt.
  46356. function estimateRootSize(seriesModel, targetInfo, viewRoot, containerWidth, containerHeight) {
  46357. // If targetInfo.node exists, we zoom to the node,
  46358. // so estimate whold width and heigth by target node.
  46359. var currNode = (targetInfo || {}).node;
  46360. var defaultSize = [containerWidth, containerHeight];
  46361. if (!currNode || currNode === viewRoot) {
  46362. return defaultSize;
  46363. }
  46364. var parent;
  46365. var viewArea = containerWidth * containerHeight;
  46366. var area = viewArea * seriesModel.option.zoomToNodeRatio;
  46367. while (parent = currNode.parentNode) { // jshint ignore:line
  46368. var sum = 0;
  46369. var siblings = parent.children;
  46370. for (var i = 0, len = siblings.length; i < len; i++) {
  46371. sum += siblings[i].getValue();
  46372. }
  46373. var currNodeValue = currNode.getValue();
  46374. if (currNodeValue === 0) {
  46375. return defaultSize;
  46376. }
  46377. area *= sum / currNodeValue;
  46378. // Considering border, suppose aspect ratio is 1.
  46379. var parentModel = parent.getModel();
  46380. var borderWidth = parentModel.get(PATH_BORDER_WIDTH);
  46381. var upperHeight = Math.max(borderWidth, getUpperLabelHeight(parentModel, borderWidth));
  46382. area += 4 * borderWidth * borderWidth
  46383. + (3 * borderWidth + upperHeight) * Math.pow(area, 0.5);
  46384. area > MAX_SAFE_INTEGER && (area = MAX_SAFE_INTEGER);
  46385. currNode = parent;
  46386. }
  46387. area < viewArea && (area = viewArea);
  46388. var scale = Math.pow(area / viewArea, 0.5);
  46389. return [containerWidth * scale, containerHeight * scale];
  46390. }
  46391. // Root postion base on coord of containerGroup
  46392. function calculateRootPosition(layoutInfo, rootRect, targetInfo) {
  46393. if (rootRect) {
  46394. return {x: rootRect.x, y: rootRect.y};
  46395. }
  46396. var defaultPosition = {x: 0, y: 0};
  46397. if (!targetInfo) {
  46398. return defaultPosition;
  46399. }
  46400. // If targetInfo is fetched by 'retrieveTargetInfo',
  46401. // old tree and new tree are the same tree,
  46402. // so the node still exists and we can visit it.
  46403. var targetNode = targetInfo.node;
  46404. var layout = targetNode.getLayout();
  46405. if (!layout) {
  46406. return defaultPosition;
  46407. }
  46408. // Transform coord from local to container.
  46409. var targetCenter = [layout.width / 2, layout.height / 2];
  46410. var node = targetNode;
  46411. while (node) {
  46412. var nodeLayout = node.getLayout();
  46413. targetCenter[0] += nodeLayout.x;
  46414. targetCenter[1] += nodeLayout.y;
  46415. node = node.parentNode;
  46416. }
  46417. return {
  46418. x: layoutInfo.width / 2 - targetCenter[0],
  46419. y: layoutInfo.height / 2 - targetCenter[1]
  46420. };
  46421. }
  46422. // Mark nodes visible for prunning when visual coding and rendering.
  46423. // Prunning depends on layout and root position, so we have to do it after layout.
  46424. function prunning(node, clipRect, viewAbovePath, viewRoot, depth) {
  46425. var nodeLayout = node.getLayout();
  46426. var nodeInViewAbovePath = viewAbovePath[depth];
  46427. var isAboveViewRoot = nodeInViewAbovePath && nodeInViewAbovePath === node;
  46428. if (
  46429. (nodeInViewAbovePath && !isAboveViewRoot)
  46430. || (depth === viewAbovePath.length && node !== viewRoot)
  46431. ) {
  46432. return;
  46433. }
  46434. node.setLayout({
  46435. // isInView means: viewRoot sub tree + viewAbovePath
  46436. isInView: true,
  46437. // invisible only means: outside view clip so that the node can not
  46438. // see but still layout for animation preparation but not render.
  46439. invisible: !isAboveViewRoot && !clipRect.intersect(nodeLayout),
  46440. isAboveViewRoot: isAboveViewRoot
  46441. }, true);
  46442. // Transform to child coordinate.
  46443. var childClipRect = new BoundingRect(
  46444. clipRect.x - nodeLayout.x,
  46445. clipRect.y - nodeLayout.y,
  46446. clipRect.width,
  46447. clipRect.height
  46448. );
  46449. each$10(node.viewChildren || [], function (child) {
  46450. prunning(child, childClipRect, viewAbovePath, viewRoot, depth + 1);
  46451. });
  46452. }
  46453. function getUpperLabelHeight(model) {
  46454. return model.get(PATH_UPPER_LABEL_SHOW) ? model.get(PATH_UPPER_LABEL_HEIGHT) : 0;
  46455. }
  46456. /*
  46457. * Licensed to the Apache Software Foundation (ASF) under one
  46458. * or more contributor license agreements. See the NOTICE file
  46459. * distributed with this work for additional information
  46460. * regarding copyright ownership. The ASF licenses this file
  46461. * to you under the Apache License, Version 2.0 (the
  46462. * "License"); you may not use this file except in compliance
  46463. * with the License. You may obtain a copy of the License at
  46464. *
  46465. * http://www.apache.org/licenses/LICENSE-2.0
  46466. *
  46467. * Unless required by applicable law or agreed to in writing,
  46468. * software distributed under the License is distributed on an
  46469. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  46470. * KIND, either express or implied. See the License for the
  46471. * specific language governing permissions and limitations
  46472. * under the License.
  46473. */
  46474. registerVisual(treemapVisual);
  46475. registerLayout(treemapLayout);
  46476. /*
  46477. * Licensed to the Apache Software Foundation (ASF) under one
  46478. * or more contributor license agreements. See the NOTICE file
  46479. * distributed with this work for additional information
  46480. * regarding copyright ownership. The ASF licenses this file
  46481. * to you under the Apache License, Version 2.0 (the
  46482. * "License"); you may not use this file except in compliance
  46483. * with the License. You may obtain a copy of the License at
  46484. *
  46485. * http://www.apache.org/licenses/LICENSE-2.0
  46486. *
  46487. * Unless required by applicable law or agreed to in writing,
  46488. * software distributed under the License is distributed on an
  46489. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  46490. * KIND, either express or implied. See the License for the
  46491. * specific language governing permissions and limitations
  46492. * under the License.
  46493. */
  46494. // id may be function name of Object, add a prefix to avoid this problem.
  46495. function generateNodeKey(id) {
  46496. return '_EC_' + id;
  46497. }
  46498. /**
  46499. * @alias module:echarts/data/Graph
  46500. * @constructor
  46501. * @param {boolean} directed
  46502. */
  46503. var Graph = function (directed) {
  46504. /**
  46505. * 是否是有向图
  46506. * @type {boolean}
  46507. * @private
  46508. */
  46509. this._directed = directed || false;
  46510. /**
  46511. * @type {Array.<module:echarts/data/Graph.Node>}
  46512. * @readOnly
  46513. */
  46514. this.nodes = [];
  46515. /**
  46516. * @type {Array.<module:echarts/data/Graph.Edge>}
  46517. * @readOnly
  46518. */
  46519. this.edges = [];
  46520. /**
  46521. * @type {Object.<string, module:echarts/data/Graph.Node>}
  46522. * @private
  46523. */
  46524. this._nodesMap = {};
  46525. /**
  46526. * @type {Object.<string, module:echarts/data/Graph.Edge>}
  46527. * @private
  46528. */
  46529. this._edgesMap = {};
  46530. /**
  46531. * @type {module:echarts/data/List}
  46532. * @readOnly
  46533. */
  46534. this.data;
  46535. /**
  46536. * @type {module:echarts/data/List}
  46537. * @readOnly
  46538. */
  46539. this.edgeData;
  46540. };
  46541. var graphProto = Graph.prototype;
  46542. /**
  46543. * @type {string}
  46544. */
  46545. graphProto.type = 'graph';
  46546. /**
  46547. * If is directed graph
  46548. * @return {boolean}
  46549. */
  46550. graphProto.isDirected = function () {
  46551. return this._directed;
  46552. };
  46553. /**
  46554. * Add a new node
  46555. * @param {string} id
  46556. * @param {number} [dataIndex]
  46557. */
  46558. graphProto.addNode = function (id, dataIndex) {
  46559. id = id == null ? ('' + dataIndex) : ('' + id);
  46560. var nodesMap = this._nodesMap;
  46561. if (nodesMap[generateNodeKey(id)]) {
  46562. if (__DEV__) {
  46563. console.error('Graph nodes have duplicate name or id');
  46564. }
  46565. return;
  46566. }
  46567. var node = new Node(id, dataIndex);
  46568. node.hostGraph = this;
  46569. this.nodes.push(node);
  46570. nodesMap[generateNodeKey(id)] = node;
  46571. return node;
  46572. };
  46573. /**
  46574. * Get node by data index
  46575. * @param {number} dataIndex
  46576. * @return {module:echarts/data/Graph~Node}
  46577. */
  46578. graphProto.getNodeByIndex = function (dataIndex) {
  46579. var rawIdx = this.data.getRawIndex(dataIndex);
  46580. return this.nodes[rawIdx];
  46581. };
  46582. /**
  46583. * Get node by id
  46584. * @param {string} id
  46585. * @return {module:echarts/data/Graph.Node}
  46586. */
  46587. graphProto.getNodeById = function (id) {
  46588. return this._nodesMap[generateNodeKey(id)];
  46589. };
  46590. /**
  46591. * Add a new edge
  46592. * @param {number|string|module:echarts/data/Graph.Node} n1
  46593. * @param {number|string|module:echarts/data/Graph.Node} n2
  46594. * @param {number} [dataIndex=-1]
  46595. * @return {module:echarts/data/Graph.Edge}
  46596. */
  46597. graphProto.addEdge = function (n1, n2, dataIndex) {
  46598. var nodesMap = this._nodesMap;
  46599. var edgesMap = this._edgesMap;
  46600. // PNEDING
  46601. if (typeof n1 === 'number') {
  46602. n1 = this.nodes[n1];
  46603. }
  46604. if (typeof n2 === 'number') {
  46605. n2 = this.nodes[n2];
  46606. }
  46607. if (!Node.isInstance(n1)) {
  46608. n1 = nodesMap[generateNodeKey(n1)];
  46609. }
  46610. if (!Node.isInstance(n2)) {
  46611. n2 = nodesMap[generateNodeKey(n2)];
  46612. }
  46613. if (!n1 || !n2) {
  46614. return;
  46615. }
  46616. var key = n1.id + '-' + n2.id;
  46617. // PENDING
  46618. if (edgesMap[key]) {
  46619. return;
  46620. }
  46621. var edge = new Edge(n1, n2, dataIndex);
  46622. edge.hostGraph = this;
  46623. if (this._directed) {
  46624. n1.outEdges.push(edge);
  46625. n2.inEdges.push(edge);
  46626. }
  46627. n1.edges.push(edge);
  46628. if (n1 !== n2) {
  46629. n2.edges.push(edge);
  46630. }
  46631. this.edges.push(edge);
  46632. edgesMap[key] = edge;
  46633. return edge;
  46634. };
  46635. /**
  46636. * Get edge by data index
  46637. * @param {number} dataIndex
  46638. * @return {module:echarts/data/Graph~Node}
  46639. */
  46640. graphProto.getEdgeByIndex = function (dataIndex) {
  46641. var rawIdx = this.edgeData.getRawIndex(dataIndex);
  46642. return this.edges[rawIdx];
  46643. };
  46644. /**
  46645. * Get edge by two linked nodes
  46646. * @param {module:echarts/data/Graph.Node|string} n1
  46647. * @param {module:echarts/data/Graph.Node|string} n2
  46648. * @return {module:echarts/data/Graph.Edge}
  46649. */
  46650. graphProto.getEdge = function (n1, n2) {
  46651. if (Node.isInstance(n1)) {
  46652. n1 = n1.id;
  46653. }
  46654. if (Node.isInstance(n2)) {
  46655. n2 = n2.id;
  46656. }
  46657. var edgesMap = this._edgesMap;
  46658. if (this._directed) {
  46659. return edgesMap[n1 + '-' + n2];
  46660. }
  46661. else {
  46662. return edgesMap[n1 + '-' + n2]
  46663. || edgesMap[n2 + '-' + n1];
  46664. }
  46665. };
  46666. /**
  46667. * Iterate all nodes
  46668. * @param {Function} cb
  46669. * @param {*} [context]
  46670. */
  46671. graphProto.eachNode = function (cb, context) {
  46672. var nodes = this.nodes;
  46673. var len = nodes.length;
  46674. for (var i = 0; i < len; i++) {
  46675. if (nodes[i].dataIndex >= 0) {
  46676. cb.call(context, nodes[i], i);
  46677. }
  46678. }
  46679. };
  46680. /**
  46681. * Iterate all edges
  46682. * @param {Function} cb
  46683. * @param {*} [context]
  46684. */
  46685. graphProto.eachEdge = function (cb, context) {
  46686. var edges = this.edges;
  46687. var len = edges.length;
  46688. for (var i = 0; i < len; i++) {
  46689. if (edges[i].dataIndex >= 0
  46690. && edges[i].node1.dataIndex >= 0
  46691. && edges[i].node2.dataIndex >= 0
  46692. ) {
  46693. cb.call(context, edges[i], i);
  46694. }
  46695. }
  46696. };
  46697. /**
  46698. * Breadth first traverse
  46699. * @param {Function} cb
  46700. * @param {module:echarts/data/Graph.Node} startNode
  46701. * @param {string} [direction='none'] 'none'|'in'|'out'
  46702. * @param {*} [context]
  46703. */
  46704. graphProto.breadthFirstTraverse = function (
  46705. cb, startNode, direction, context
  46706. ) {
  46707. if (!Node.isInstance(startNode)) {
  46708. startNode = this._nodesMap[generateNodeKey(startNode)];
  46709. }
  46710. if (!startNode) {
  46711. return;
  46712. }
  46713. var edgeType = direction === 'out'
  46714. ? 'outEdges' : (direction === 'in' ? 'inEdges' : 'edges');
  46715. for (var i = 0; i < this.nodes.length; i++) {
  46716. this.nodes[i].__visited = false;
  46717. }
  46718. if (cb.call(context, startNode, null)) {
  46719. return;
  46720. }
  46721. var queue = [startNode];
  46722. while (queue.length) {
  46723. var currentNode = queue.shift();
  46724. var edges = currentNode[edgeType];
  46725. for (var i = 0; i < edges.length; i++) {
  46726. var e = edges[i];
  46727. var otherNode = e.node1 === currentNode
  46728. ? e.node2 : e.node1;
  46729. if (!otherNode.__visited) {
  46730. if (cb.call(context, otherNode, currentNode)) {
  46731. // Stop traversing
  46732. return;
  46733. }
  46734. queue.push(otherNode);
  46735. otherNode.__visited = true;
  46736. }
  46737. }
  46738. }
  46739. };
  46740. // TODO
  46741. // graphProto.depthFirstTraverse = function (
  46742. // cb, startNode, direction, context
  46743. // ) {
  46744. // };
  46745. // Filter update
  46746. graphProto.update = function () {
  46747. var data = this.data;
  46748. var edgeData = this.edgeData;
  46749. var nodes = this.nodes;
  46750. var edges = this.edges;
  46751. for (var i = 0, len = nodes.length; i < len; i++) {
  46752. nodes[i].dataIndex = -1;
  46753. }
  46754. for (var i = 0, len = data.count(); i < len; i++) {
  46755. nodes[data.getRawIndex(i)].dataIndex = i;
  46756. }
  46757. edgeData.filterSelf(function (idx) {
  46758. var edge = edges[edgeData.getRawIndex(idx)];
  46759. return edge.node1.dataIndex >= 0 && edge.node2.dataIndex >= 0;
  46760. });
  46761. // Update edge
  46762. for (var i = 0, len = edges.length; i < len; i++) {
  46763. edges[i].dataIndex = -1;
  46764. }
  46765. for (var i = 0, len = edgeData.count(); i < len; i++) {
  46766. edges[edgeData.getRawIndex(i)].dataIndex = i;
  46767. }
  46768. };
  46769. /**
  46770. * @return {module:echarts/data/Graph}
  46771. */
  46772. graphProto.clone = function () {
  46773. var graph = new Graph(this._directed);
  46774. var nodes = this.nodes;
  46775. var edges = this.edges;
  46776. for (var i = 0; i < nodes.length; i++) {
  46777. graph.addNode(nodes[i].id, nodes[i].dataIndex);
  46778. }
  46779. for (var i = 0; i < edges.length; i++) {
  46780. var e = edges[i];
  46781. graph.addEdge(e.node1.id, e.node2.id, e.dataIndex);
  46782. }
  46783. return graph;
  46784. };
  46785. /**
  46786. * @alias module:echarts/data/Graph.Node
  46787. */
  46788. function Node(id, dataIndex) {
  46789. /**
  46790. * @type {string}
  46791. */
  46792. this.id = id == null ? '' : id;
  46793. /**
  46794. * @type {Array.<module:echarts/data/Graph.Edge>}
  46795. */
  46796. this.inEdges = [];
  46797. /**
  46798. * @type {Array.<module:echarts/data/Graph.Edge>}
  46799. */
  46800. this.outEdges = [];
  46801. /**
  46802. * @type {Array.<module:echarts/data/Graph.Edge>}
  46803. */
  46804. this.edges = [];
  46805. /**
  46806. * @type {module:echarts/data/Graph}
  46807. */
  46808. this.hostGraph;
  46809. /**
  46810. * @type {number}
  46811. */
  46812. this.dataIndex = dataIndex == null ? -1 : dataIndex;
  46813. }
  46814. Node.prototype = {
  46815. constructor: Node,
  46816. /**
  46817. * @return {number}
  46818. */
  46819. degree: function () {
  46820. return this.edges.length;
  46821. },
  46822. /**
  46823. * @return {number}
  46824. */
  46825. inDegree: function () {
  46826. return this.inEdges.length;
  46827. },
  46828. /**
  46829. * @return {number}
  46830. */
  46831. outDegree: function () {
  46832. return this.outEdges.length;
  46833. },
  46834. /**
  46835. * @param {string} [path]
  46836. * @return {module:echarts/model/Model}
  46837. */
  46838. getModel: function (path) {
  46839. if (this.dataIndex < 0) {
  46840. return;
  46841. }
  46842. var graph = this.hostGraph;
  46843. var itemModel = graph.data.getItemModel(this.dataIndex);
  46844. return itemModel.getModel(path);
  46845. }
  46846. };
  46847. /**
  46848. * 图边
  46849. * @alias module:echarts/data/Graph.Edge
  46850. * @param {module:echarts/data/Graph.Node} n1
  46851. * @param {module:echarts/data/Graph.Node} n2
  46852. * @param {number} [dataIndex=-1]
  46853. */
  46854. function Edge(n1, n2, dataIndex) {
  46855. /**
  46856. * 节点1,如果是有向图则为源节点
  46857. * @type {module:echarts/data/Graph.Node}
  46858. */
  46859. this.node1 = n1;
  46860. /**
  46861. * 节点2,如果是有向图则为目标节点
  46862. * @type {module:echarts/data/Graph.Node}
  46863. */
  46864. this.node2 = n2;
  46865. this.dataIndex = dataIndex == null ? -1 : dataIndex;
  46866. }
  46867. /**
  46868. * @param {string} [path]
  46869. * @return {module:echarts/model/Model}
  46870. */
  46871. Edge.prototype.getModel = function (path) {
  46872. if (this.dataIndex < 0) {
  46873. return;
  46874. }
  46875. var graph = this.hostGraph;
  46876. var itemModel = graph.edgeData.getItemModel(this.dataIndex);
  46877. return itemModel.getModel(path);
  46878. };
  46879. var createGraphDataProxyMixin = function (hostName, dataName) {
  46880. return {
  46881. /**
  46882. * @param {string=} [dimension='value'] Default 'value'. can be 'a', 'b', 'c', 'd', 'e'.
  46883. * @return {number}
  46884. */
  46885. getValue: function (dimension) {
  46886. var data = this[hostName][dataName];
  46887. return data.get(data.getDimension(dimension || 'value'), this.dataIndex);
  46888. },
  46889. /**
  46890. * @param {Object|string} key
  46891. * @param {*} [value]
  46892. */
  46893. setVisual: function (key, value) {
  46894. this.dataIndex >= 0
  46895. && this[hostName][dataName].setItemVisual(this.dataIndex, key, value);
  46896. },
  46897. /**
  46898. * @param {string} key
  46899. * @return {boolean}
  46900. */
  46901. getVisual: function (key, ignoreParent) {
  46902. return this[hostName][dataName].getItemVisual(this.dataIndex, key, ignoreParent);
  46903. },
  46904. /**
  46905. * @param {Object} layout
  46906. * @return {boolean} [merge=false]
  46907. */
  46908. setLayout: function (layout, merge$$1) {
  46909. this.dataIndex >= 0
  46910. && this[hostName][dataName].setItemLayout(this.dataIndex, layout, merge$$1);
  46911. },
  46912. /**
  46913. * @return {Object}
  46914. */
  46915. getLayout: function () {
  46916. return this[hostName][dataName].getItemLayout(this.dataIndex);
  46917. },
  46918. /**
  46919. * @return {module:zrender/Element}
  46920. */
  46921. getGraphicEl: function () {
  46922. return this[hostName][dataName].getItemGraphicEl(this.dataIndex);
  46923. },
  46924. /**
  46925. * @return {number}
  46926. */
  46927. getRawIndex: function () {
  46928. return this[hostName][dataName].getRawIndex(this.dataIndex);
  46929. }
  46930. };
  46931. };
  46932. mixin(Node, createGraphDataProxyMixin('hostGraph', 'data'));
  46933. mixin(Edge, createGraphDataProxyMixin('hostGraph', 'edgeData'));
  46934. Graph.Node = Node;
  46935. Graph.Edge = Edge;
  46936. enableClassCheck(Node);
  46937. enableClassCheck(Edge);
  46938. /*
  46939. * Licensed to the Apache Software Foundation (ASF) under one
  46940. * or more contributor license agreements. See the NOTICE file
  46941. * distributed with this work for additional information
  46942. * regarding copyright ownership. The ASF licenses this file
  46943. * to you under the Apache License, Version 2.0 (the
  46944. * "License"); you may not use this file except in compliance
  46945. * with the License. You may obtain a copy of the License at
  46946. *
  46947. * http://www.apache.org/licenses/LICENSE-2.0
  46948. *
  46949. * Unless required by applicable law or agreed to in writing,
  46950. * software distributed under the License is distributed on an
  46951. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  46952. * KIND, either express or implied. See the License for the
  46953. * specific language governing permissions and limitations
  46954. * under the License.
  46955. */
  46956. var createGraphFromNodeEdge = function (nodes, edges, seriesModel, directed, beforeLink) {
  46957. // ??? TODO
  46958. // support dataset?
  46959. var graph = new Graph(directed);
  46960. for (var i = 0; i < nodes.length; i++) {
  46961. graph.addNode(retrieve(
  46962. // Id, name, dataIndex
  46963. nodes[i].id, nodes[i].name, i
  46964. ), i);
  46965. }
  46966. var linkNameList = [];
  46967. var validEdges = [];
  46968. var linkCount = 0;
  46969. for (var i = 0; i < edges.length; i++) {
  46970. var link = edges[i];
  46971. var source = link.source;
  46972. var target = link.target;
  46973. // addEdge may fail when source or target not exists
  46974. if (graph.addEdge(source, target, linkCount)) {
  46975. validEdges.push(link);
  46976. linkNameList.push(retrieve(link.id, source + ' > ' + target));
  46977. linkCount++;
  46978. }
  46979. }
  46980. var coordSys = seriesModel.get('coordinateSystem');
  46981. var nodeData;
  46982. if (coordSys === 'cartesian2d' || coordSys === 'polar') {
  46983. nodeData = createListFromArray(nodes, seriesModel);
  46984. }
  46985. else {
  46986. var coordSysCtor = CoordinateSystemManager.get(coordSys);
  46987. var coordDimensions = (coordSysCtor && coordSysCtor.type !== 'view')
  46988. ? (coordSysCtor.dimensions || []) : [];
  46989. // FIXME: Some geo do not need `value` dimenson, whereas `calendar` needs
  46990. // `value` dimension, but graph need `value` dimension. It's better to
  46991. // uniform this behavior.
  46992. if (indexOf(coordDimensions, 'value') < 0) {
  46993. coordDimensions.concat(['value']);
  46994. }
  46995. var dimensionNames = createDimensions(nodes, {
  46996. coordDimensions: coordDimensions
  46997. });
  46998. nodeData = new List(dimensionNames, seriesModel);
  46999. nodeData.initData(nodes);
  47000. }
  47001. var edgeData = new List(['value'], seriesModel);
  47002. edgeData.initData(validEdges, linkNameList);
  47003. beforeLink && beforeLink(nodeData, edgeData);
  47004. linkList({
  47005. mainData: nodeData,
  47006. struct: graph,
  47007. structAttr: 'graph',
  47008. datas: {node: nodeData, edge: edgeData},
  47009. datasAttr: {node: 'data', edge: 'edgeData'}
  47010. });
  47011. // Update dataIndex of nodes and edges because invalid edge may be removed
  47012. graph.update();
  47013. return graph;
  47014. };
  47015. /*
  47016. * Licensed to the Apache Software Foundation (ASF) under one
  47017. * or more contributor license agreements. See the NOTICE file
  47018. * distributed with this work for additional information
  47019. * regarding copyright ownership. The ASF licenses this file
  47020. * to you under the Apache License, Version 2.0 (the
  47021. * "License"); you may not use this file except in compliance
  47022. * with the License. You may obtain a copy of the License at
  47023. *
  47024. * http://www.apache.org/licenses/LICENSE-2.0
  47025. *
  47026. * Unless required by applicable law or agreed to in writing,
  47027. * software distributed under the License is distributed on an
  47028. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  47029. * KIND, either express or implied. See the License for the
  47030. * specific language governing permissions and limitations
  47031. * under the License.
  47032. */
  47033. var GraphSeries = extendSeriesModel({
  47034. type: 'series.graph',
  47035. init: function (option) {
  47036. GraphSeries.superApply(this, 'init', arguments);
  47037. // Provide data for legend select
  47038. this.legendDataProvider = function () {
  47039. return this._categoriesData;
  47040. };
  47041. this.fillDataTextStyle(option.edges || option.links);
  47042. this._updateCategoriesData();
  47043. },
  47044. mergeOption: function (option) {
  47045. GraphSeries.superApply(this, 'mergeOption', arguments);
  47046. this.fillDataTextStyle(option.edges || option.links);
  47047. this._updateCategoriesData();
  47048. },
  47049. mergeDefaultAndTheme: function (option) {
  47050. GraphSeries.superApply(this, 'mergeDefaultAndTheme', arguments);
  47051. defaultEmphasis(option, ['edgeLabel'], ['show']);
  47052. },
  47053. getInitialData: function (option, ecModel) {
  47054. var edges = option.edges || option.links || [];
  47055. var nodes = option.data || option.nodes || [];
  47056. var self = this;
  47057. if (nodes && edges) {
  47058. return createGraphFromNodeEdge(nodes, edges, this, true, beforeLink).data;
  47059. }
  47060. function beforeLink(nodeData, edgeData) {
  47061. // Overwrite nodeData.getItemModel to
  47062. nodeData.wrapMethod('getItemModel', function (model) {
  47063. var categoriesModels = self._categoriesModels;
  47064. var categoryIdx = model.getShallow('category');
  47065. var categoryModel = categoriesModels[categoryIdx];
  47066. if (categoryModel) {
  47067. categoryModel.parentModel = model.parentModel;
  47068. model.parentModel = categoryModel;
  47069. }
  47070. return model;
  47071. });
  47072. var edgeLabelModel = self.getModel('edgeLabel');
  47073. // For option `edgeLabel` can be found by label.xxx.xxx on item mode.
  47074. var fakeSeriesModel = new Model(
  47075. {label: edgeLabelModel.option},
  47076. edgeLabelModel.parentModel,
  47077. ecModel
  47078. );
  47079. var emphasisEdgeLabelModel = self.getModel('emphasis.edgeLabel');
  47080. var emphasisFakeSeriesModel = new Model(
  47081. {emphasis: {label: emphasisEdgeLabelModel.option}},
  47082. emphasisEdgeLabelModel.parentModel,
  47083. ecModel
  47084. );
  47085. edgeData.wrapMethod('getItemModel', function (model) {
  47086. model.customizeGetParent(edgeGetParent);
  47087. return model;
  47088. });
  47089. function edgeGetParent(path) {
  47090. path = this.parsePath(path);
  47091. return (path && path[0] === 'label')
  47092. ? fakeSeriesModel
  47093. : (path && path[0] === 'emphasis' && path[1] === 'label')
  47094. ? emphasisFakeSeriesModel
  47095. : this.parentModel;
  47096. }
  47097. }
  47098. },
  47099. /**
  47100. * @return {module:echarts/data/Graph}
  47101. */
  47102. getGraph: function () {
  47103. return this.getData().graph;
  47104. },
  47105. /**
  47106. * @return {module:echarts/data/List}
  47107. */
  47108. getEdgeData: function () {
  47109. return this.getGraph().edgeData;
  47110. },
  47111. /**
  47112. * @return {module:echarts/data/List}
  47113. */
  47114. getCategoriesData: function () {
  47115. return this._categoriesData;
  47116. },
  47117. /**
  47118. * @override
  47119. */
  47120. formatTooltip: function (dataIndex, multipleSeries, dataType) {
  47121. if (dataType === 'edge') {
  47122. var nodeData = this.getData();
  47123. var params = this.getDataParams(dataIndex, dataType);
  47124. var edge = nodeData.graph.getEdgeByIndex(dataIndex);
  47125. var sourceName = nodeData.getName(edge.node1.dataIndex);
  47126. var targetName = nodeData.getName(edge.node2.dataIndex);
  47127. var html = [];
  47128. sourceName != null && html.push(sourceName);
  47129. targetName != null && html.push(targetName);
  47130. html = encodeHTML(html.join(' > '));
  47131. if (params.value) {
  47132. html += ' : ' + encodeHTML(params.value);
  47133. }
  47134. return html;
  47135. }
  47136. else { // dataType === 'node' or empty
  47137. return GraphSeries.superApply(this, 'formatTooltip', arguments);
  47138. }
  47139. },
  47140. _updateCategoriesData: function () {
  47141. var categories = map(this.option.categories || [], function (category) {
  47142. // Data must has value
  47143. return category.value != null ? category : extend({
  47144. value: 0
  47145. }, category);
  47146. });
  47147. var categoriesData = new List(['value'], this);
  47148. categoriesData.initData(categories);
  47149. this._categoriesData = categoriesData;
  47150. this._categoriesModels = categoriesData.mapArray(function (idx) {
  47151. return categoriesData.getItemModel(idx, true);
  47152. });
  47153. },
  47154. setZoom: function (zoom) {
  47155. this.option.zoom = zoom;
  47156. },
  47157. setCenter: function (center) {
  47158. this.option.center = center;
  47159. },
  47160. isAnimationEnabled: function () {
  47161. return GraphSeries.superCall(this, 'isAnimationEnabled')
  47162. // Not enable animation when do force layout
  47163. && !(this.get('layout') === 'force' && this.get('force.layoutAnimation'));
  47164. },
  47165. defaultOption: {
  47166. zlevel: 0,
  47167. z: 2,
  47168. coordinateSystem: 'view',
  47169. // Default option for all coordinate systems
  47170. // xAxisIndex: 0,
  47171. // yAxisIndex: 0,
  47172. // polarIndex: 0,
  47173. // geoIndex: 0,
  47174. legendHoverLink: true,
  47175. hoverAnimation: true,
  47176. layout: null,
  47177. focusNodeAdjacency: false,
  47178. // Configuration of circular layout
  47179. circular: {
  47180. rotateLabel: false
  47181. },
  47182. // Configuration of force directed layout
  47183. force: {
  47184. initLayout: null,
  47185. // Node repulsion. Can be an array to represent range.
  47186. repulsion: [0, 50],
  47187. gravity: 0.1,
  47188. // Edge length. Can be an array to represent range.
  47189. edgeLength: 30,
  47190. layoutAnimation: true
  47191. },
  47192. left: 'center',
  47193. top: 'center',
  47194. // right: null,
  47195. // bottom: null,
  47196. // width: '80%',
  47197. // height: '80%',
  47198. symbol: 'circle',
  47199. symbolSize: 10,
  47200. edgeSymbol: ['none', 'none'],
  47201. edgeSymbolSize: 10,
  47202. edgeLabel: {
  47203. position: 'middle'
  47204. },
  47205. draggable: false,
  47206. roam: false,
  47207. // Default on center of graph
  47208. center: null,
  47209. zoom: 1,
  47210. // Symbol size scale ratio in roam
  47211. nodeScaleRatio: 0.6,
  47212. // cursor: null,
  47213. // categories: [],
  47214. // data: []
  47215. // Or
  47216. // nodes: []
  47217. //
  47218. // links: []
  47219. // Or
  47220. // edges: []
  47221. label: {
  47222. show: false,
  47223. formatter: '{b}'
  47224. },
  47225. itemStyle: {},
  47226. lineStyle: {
  47227. color: '#aaa',
  47228. width: 1,
  47229. curveness: 0,
  47230. opacity: 0.5
  47231. },
  47232. emphasis: {
  47233. label: {
  47234. show: true
  47235. }
  47236. }
  47237. }
  47238. });
  47239. /*
  47240. * Licensed to the Apache Software Foundation (ASF) under one
  47241. * or more contributor license agreements. See the NOTICE file
  47242. * distributed with this work for additional information
  47243. * regarding copyright ownership. The ASF licenses this file
  47244. * to you under the Apache License, Version 2.0 (the
  47245. * "License"); you may not use this file except in compliance
  47246. * with the License. You may obtain a copy of the License at
  47247. *
  47248. * http://www.apache.org/licenses/LICENSE-2.0
  47249. *
  47250. * Unless required by applicable law or agreed to in writing,
  47251. * software distributed under the License is distributed on an
  47252. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  47253. * KIND, either express or implied. See the License for the
  47254. * specific language governing permissions and limitations
  47255. * under the License.
  47256. */
  47257. /**
  47258. * Line path for bezier and straight line draw
  47259. */
  47260. var straightLineProto = Line.prototype;
  47261. var bezierCurveProto = BezierCurve.prototype;
  47262. function isLine(shape) {
  47263. return isNaN(+shape.cpx1) || isNaN(+shape.cpy1);
  47264. }
  47265. var LinePath = extendShape({
  47266. type: 'ec-line',
  47267. style: {
  47268. stroke: '#000',
  47269. fill: null
  47270. },
  47271. shape: {
  47272. x1: 0,
  47273. y1: 0,
  47274. x2: 0,
  47275. y2: 0,
  47276. percent: 1,
  47277. cpx1: null,
  47278. cpy1: null
  47279. },
  47280. buildPath: function (ctx, shape) {
  47281. this[isLine(shape) ? '_buildPathLine' : '_buildPathCurve'](ctx, shape);
  47282. },
  47283. _buildPathLine: straightLineProto.buildPath,
  47284. _buildPathCurve: bezierCurveProto.buildPath,
  47285. pointAt: function (t) {
  47286. return this[isLine(this.shape) ? '_pointAtLine' : '_pointAtCurve'](t);
  47287. },
  47288. _pointAtLine: straightLineProto.pointAt,
  47289. _pointAtCurve: bezierCurveProto.pointAt,
  47290. tangentAt: function (t) {
  47291. var shape = this.shape;
  47292. var p = isLine(shape)
  47293. ? [shape.x2 - shape.x1, shape.y2 - shape.y1]
  47294. : this._tangentAtCurve(t);
  47295. return normalize(p, p);
  47296. },
  47297. _tangentAtCurve: bezierCurveProto.tangentAt
  47298. });
  47299. /*
  47300. * Licensed to the Apache Software Foundation (ASF) under one
  47301. * or more contributor license agreements. See the NOTICE file
  47302. * distributed with this work for additional information
  47303. * regarding copyright ownership. The ASF licenses this file
  47304. * to you under the Apache License, Version 2.0 (the
  47305. * "License"); you may not use this file except in compliance
  47306. * with the License. You may obtain a copy of the License at
  47307. *
  47308. * http://www.apache.org/licenses/LICENSE-2.0
  47309. *
  47310. * Unless required by applicable law or agreed to in writing,
  47311. * software distributed under the License is distributed on an
  47312. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  47313. * KIND, either express or implied. See the License for the
  47314. * specific language governing permissions and limitations
  47315. * under the License.
  47316. */
  47317. /**
  47318. * @module echarts/chart/helper/Line
  47319. */
  47320. var SYMBOL_CATEGORIES = ['fromSymbol', 'toSymbol'];
  47321. function makeSymbolTypeKey(symbolCategory) {
  47322. return '_' + symbolCategory + 'Type';
  47323. }
  47324. /**
  47325. * @inner
  47326. */
  47327. function createSymbol$1(name, lineData, idx) {
  47328. var color = lineData.getItemVisual(idx, 'color');
  47329. var symbolType = lineData.getItemVisual(idx, name);
  47330. var symbolSize = lineData.getItemVisual(idx, name + 'Size');
  47331. if (!symbolType || symbolType === 'none') {
  47332. return;
  47333. }
  47334. if (!isArray(symbolSize)) {
  47335. symbolSize = [symbolSize, symbolSize];
  47336. }
  47337. var symbolPath = createSymbol(
  47338. symbolType, -symbolSize[0] / 2, -symbolSize[1] / 2,
  47339. symbolSize[0], symbolSize[1], color
  47340. );
  47341. symbolPath.name = name;
  47342. return symbolPath;
  47343. }
  47344. function createLine(points) {
  47345. var line = new LinePath({
  47346. name: 'line',
  47347. subPixelOptimize: true
  47348. });
  47349. setLinePoints(line.shape, points);
  47350. return line;
  47351. }
  47352. function setLinePoints(targetShape, points) {
  47353. targetShape.x1 = points[0][0];
  47354. targetShape.y1 = points[0][1];
  47355. targetShape.x2 = points[1][0];
  47356. targetShape.y2 = points[1][1];
  47357. targetShape.percent = 1;
  47358. var cp1 = points[2];
  47359. if (cp1) {
  47360. targetShape.cpx1 = cp1[0];
  47361. targetShape.cpy1 = cp1[1];
  47362. }
  47363. else {
  47364. targetShape.cpx1 = NaN;
  47365. targetShape.cpy1 = NaN;
  47366. }
  47367. }
  47368. function updateSymbolAndLabelBeforeLineUpdate() {
  47369. var lineGroup = this;
  47370. var symbolFrom = lineGroup.childOfName('fromSymbol');
  47371. var symbolTo = lineGroup.childOfName('toSymbol');
  47372. var label = lineGroup.childOfName('label');
  47373. // Quick reject
  47374. if (!symbolFrom && !symbolTo && label.ignore) {
  47375. return;
  47376. }
  47377. var invScale = 1;
  47378. var parentNode = this.parent;
  47379. while (parentNode) {
  47380. if (parentNode.scale) {
  47381. invScale /= parentNode.scale[0];
  47382. }
  47383. parentNode = parentNode.parent;
  47384. }
  47385. var line = lineGroup.childOfName('line');
  47386. // If line not changed
  47387. // FIXME Parent scale changed
  47388. if (!this.__dirty && !line.__dirty) {
  47389. return;
  47390. }
  47391. var percent = line.shape.percent;
  47392. var fromPos = line.pointAt(0);
  47393. var toPos = line.pointAt(percent);
  47394. var d = sub([], toPos, fromPos);
  47395. normalize(d, d);
  47396. if (symbolFrom) {
  47397. symbolFrom.attr('position', fromPos);
  47398. var tangent = line.tangentAt(0);
  47399. symbolFrom.attr('rotation', Math.PI / 2 - Math.atan2(
  47400. tangent[1], tangent[0]
  47401. ));
  47402. symbolFrom.attr('scale', [invScale * percent, invScale * percent]);
  47403. }
  47404. if (symbolTo) {
  47405. symbolTo.attr('position', toPos);
  47406. var tangent = line.tangentAt(1);
  47407. symbolTo.attr('rotation', -Math.PI / 2 - Math.atan2(
  47408. tangent[1], tangent[0]
  47409. ));
  47410. symbolTo.attr('scale', [invScale * percent, invScale * percent]);
  47411. }
  47412. if (!label.ignore) {
  47413. label.attr('position', toPos);
  47414. var textPosition;
  47415. var textAlign;
  47416. var textVerticalAlign;
  47417. var distance$$1 = 5 * invScale;
  47418. // End
  47419. if (label.__position === 'end') {
  47420. textPosition = [d[0] * distance$$1 + toPos[0], d[1] * distance$$1 + toPos[1]];
  47421. textAlign = d[0] > 0.8 ? 'left' : (d[0] < -0.8 ? 'right' : 'center');
  47422. textVerticalAlign = d[1] > 0.8 ? 'top' : (d[1] < -0.8 ? 'bottom' : 'middle');
  47423. }
  47424. // Middle
  47425. else if (label.__position === 'middle') {
  47426. var halfPercent = percent / 2;
  47427. var tangent = line.tangentAt(halfPercent);
  47428. var n = [tangent[1], -tangent[0]];
  47429. var cp = line.pointAt(halfPercent);
  47430. if (n[1] > 0) {
  47431. n[0] = -n[0];
  47432. n[1] = -n[1];
  47433. }
  47434. textPosition = [cp[0] + n[0] * distance$$1, cp[1] + n[1] * distance$$1];
  47435. textAlign = 'center';
  47436. textVerticalAlign = 'bottom';
  47437. var rotation = -Math.atan2(tangent[1], tangent[0]);
  47438. if (toPos[0] < fromPos[0]) {
  47439. rotation = Math.PI + rotation;
  47440. }
  47441. label.attr('rotation', rotation);
  47442. }
  47443. // Start
  47444. else {
  47445. textPosition = [-d[0] * distance$$1 + fromPos[0], -d[1] * distance$$1 + fromPos[1]];
  47446. textAlign = d[0] > 0.8 ? 'right' : (d[0] < -0.8 ? 'left' : 'center');
  47447. textVerticalAlign = d[1] > 0.8 ? 'bottom' : (d[1] < -0.8 ? 'top' : 'middle');
  47448. }
  47449. label.attr({
  47450. style: {
  47451. // Use the user specified text align and baseline first
  47452. textVerticalAlign: label.__verticalAlign || textVerticalAlign,
  47453. textAlign: label.__textAlign || textAlign
  47454. },
  47455. position: textPosition,
  47456. scale: [invScale, invScale]
  47457. });
  47458. }
  47459. }
  47460. /**
  47461. * @constructor
  47462. * @extends {module:zrender/graphic/Group}
  47463. * @alias {module:echarts/chart/helper/Line}
  47464. */
  47465. function Line$1(lineData, idx, seriesScope) {
  47466. Group.call(this);
  47467. this._createLine(lineData, idx, seriesScope);
  47468. }
  47469. var lineProto = Line$1.prototype;
  47470. // Update symbol position and rotation
  47471. lineProto.beforeUpdate = updateSymbolAndLabelBeforeLineUpdate;
  47472. lineProto._createLine = function (lineData, idx, seriesScope) {
  47473. var seriesModel = lineData.hostModel;
  47474. var linePoints = lineData.getItemLayout(idx);
  47475. var line = createLine(linePoints);
  47476. line.shape.percent = 0;
  47477. initProps(line, {
  47478. shape: {
  47479. percent: 1
  47480. }
  47481. }, seriesModel, idx);
  47482. this.add(line);
  47483. var label = new Text({
  47484. name: 'label',
  47485. // FIXME
  47486. // Temporary solution for `focusNodeAdjacency`.
  47487. // line label do not use the opacity of lineStyle.
  47488. lineLabelOriginalOpacity: 1
  47489. });
  47490. this.add(label);
  47491. each$1(SYMBOL_CATEGORIES, function (symbolCategory) {
  47492. var symbol = createSymbol$1(symbolCategory, lineData, idx);
  47493. // symbols must added after line to make sure
  47494. // it will be updated after line#update.
  47495. // Or symbol position and rotation update in line#beforeUpdate will be one frame slow
  47496. this.add(symbol);
  47497. this[makeSymbolTypeKey(symbolCategory)] = lineData.getItemVisual(idx, symbolCategory);
  47498. }, this);
  47499. this._updateCommonStl(lineData, idx, seriesScope);
  47500. };
  47501. lineProto.updateData = function (lineData, idx, seriesScope) {
  47502. var seriesModel = lineData.hostModel;
  47503. var line = this.childOfName('line');
  47504. var linePoints = lineData.getItemLayout(idx);
  47505. var target = {
  47506. shape: {}
  47507. };
  47508. setLinePoints(target.shape, linePoints);
  47509. updateProps(line, target, seriesModel, idx);
  47510. each$1(SYMBOL_CATEGORIES, function (symbolCategory) {
  47511. var symbolType = lineData.getItemVisual(idx, symbolCategory);
  47512. var key = makeSymbolTypeKey(symbolCategory);
  47513. // Symbol changed
  47514. if (this[key] !== symbolType) {
  47515. this.remove(this.childOfName(symbolCategory));
  47516. var symbol = createSymbol$1(symbolCategory, lineData, idx);
  47517. this.add(symbol);
  47518. }
  47519. this[key] = symbolType;
  47520. }, this);
  47521. this._updateCommonStl(lineData, idx, seriesScope);
  47522. };
  47523. lineProto._updateCommonStl = function (lineData, idx, seriesScope) {
  47524. var seriesModel = lineData.hostModel;
  47525. var line = this.childOfName('line');
  47526. var lineStyle = seriesScope && seriesScope.lineStyle;
  47527. var hoverLineStyle = seriesScope && seriesScope.hoverLineStyle;
  47528. var labelModel = seriesScope && seriesScope.labelModel;
  47529. var hoverLabelModel = seriesScope && seriesScope.hoverLabelModel;
  47530. // Optimization for large dataset
  47531. if (!seriesScope || lineData.hasItemOption) {
  47532. var itemModel = lineData.getItemModel(idx);
  47533. lineStyle = itemModel.getModel('lineStyle').getLineStyle();
  47534. hoverLineStyle = itemModel.getModel('emphasis.lineStyle').getLineStyle();
  47535. labelModel = itemModel.getModel('label');
  47536. hoverLabelModel = itemModel.getModel('emphasis.label');
  47537. }
  47538. var visualColor = lineData.getItemVisual(idx, 'color');
  47539. var visualOpacity = retrieve3(
  47540. lineData.getItemVisual(idx, 'opacity'),
  47541. lineStyle.opacity,
  47542. 1
  47543. );
  47544. line.useStyle(defaults(
  47545. {
  47546. strokeNoScale: true,
  47547. fill: 'none',
  47548. stroke: visualColor,
  47549. opacity: visualOpacity
  47550. },
  47551. lineStyle
  47552. ));
  47553. line.hoverStyle = hoverLineStyle;
  47554. // Update symbol
  47555. each$1(SYMBOL_CATEGORIES, function (symbolCategory) {
  47556. var symbol = this.childOfName(symbolCategory);
  47557. if (symbol) {
  47558. symbol.setColor(visualColor);
  47559. symbol.setStyle({
  47560. opacity: visualOpacity
  47561. });
  47562. }
  47563. }, this);
  47564. var showLabel = labelModel.getShallow('show');
  47565. var hoverShowLabel = hoverLabelModel.getShallow('show');
  47566. var label = this.childOfName('label');
  47567. var defaultLabelColor;
  47568. var baseText;
  47569. // FIXME: the logic below probably should be merged to `graphic.setLabelStyle`.
  47570. if (showLabel || hoverShowLabel) {
  47571. defaultLabelColor = visualColor || '#000';
  47572. baseText = seriesModel.getFormattedLabel(idx, 'normal', lineData.dataType);
  47573. if (baseText == null) {
  47574. var rawVal = seriesModel.getRawValue(idx);
  47575. baseText = rawVal == null
  47576. ? lineData.getName(idx)
  47577. : isFinite(rawVal)
  47578. ? round$1(rawVal)
  47579. : rawVal;
  47580. }
  47581. }
  47582. var normalText = showLabel ? baseText : null;
  47583. var emphasisText = hoverShowLabel
  47584. ? retrieve2(
  47585. seriesModel.getFormattedLabel(idx, 'emphasis', lineData.dataType),
  47586. baseText
  47587. )
  47588. : null;
  47589. var labelStyle = label.style;
  47590. // Always set `textStyle` even if `normalStyle.text` is null, because default
  47591. // values have to be set on `normalStyle`.
  47592. if (normalText != null || emphasisText != null) {
  47593. setTextStyle(label.style, labelModel, {
  47594. text: normalText
  47595. }, {
  47596. autoColor: defaultLabelColor
  47597. });
  47598. label.__textAlign = labelStyle.textAlign;
  47599. label.__verticalAlign = labelStyle.textVerticalAlign;
  47600. // 'start', 'middle', 'end'
  47601. label.__position = labelModel.get('position') || 'middle';
  47602. }
  47603. if (emphasisText != null) {
  47604. // Only these properties supported in this emphasis style here.
  47605. label.hoverStyle = {
  47606. text: emphasisText,
  47607. textFill: hoverLabelModel.getTextColor(true),
  47608. // For merging hover style to normal style, do not use
  47609. // `hoverLabelModel.getFont()` here.
  47610. fontStyle: hoverLabelModel.getShallow('fontStyle'),
  47611. fontWeight: hoverLabelModel.getShallow('fontWeight'),
  47612. fontSize: hoverLabelModel.getShallow('fontSize'),
  47613. fontFamily: hoverLabelModel.getShallow('fontFamily')
  47614. };
  47615. }
  47616. else {
  47617. label.hoverStyle = {
  47618. text: null
  47619. };
  47620. }
  47621. label.ignore = !showLabel && !hoverShowLabel;
  47622. setHoverStyle(this);
  47623. };
  47624. lineProto.highlight = function () {
  47625. this.trigger('emphasis');
  47626. };
  47627. lineProto.downplay = function () {
  47628. this.trigger('normal');
  47629. };
  47630. lineProto.updateLayout = function (lineData, idx) {
  47631. this.setLinePoints(lineData.getItemLayout(idx));
  47632. };
  47633. lineProto.setLinePoints = function (points) {
  47634. var linePath = this.childOfName('line');
  47635. setLinePoints(linePath.shape, points);
  47636. linePath.dirty();
  47637. };
  47638. inherits(Line$1, Group);
  47639. /*
  47640. * Licensed to the Apache Software Foundation (ASF) under one
  47641. * or more contributor license agreements. See the NOTICE file
  47642. * distributed with this work for additional information
  47643. * regarding copyright ownership. The ASF licenses this file
  47644. * to you under the Apache License, Version 2.0 (the
  47645. * "License"); you may not use this file except in compliance
  47646. * with the License. You may obtain a copy of the License at
  47647. *
  47648. * http://www.apache.org/licenses/LICENSE-2.0
  47649. *
  47650. * Unless required by applicable law or agreed to in writing,
  47651. * software distributed under the License is distributed on an
  47652. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  47653. * KIND, either express or implied. See the License for the
  47654. * specific language governing permissions and limitations
  47655. * under the License.
  47656. */
  47657. /**
  47658. * @module echarts/chart/helper/LineDraw
  47659. */
  47660. // import IncrementalDisplayable from 'zrender/src/graphic/IncrementalDisplayable';
  47661. /**
  47662. * @alias module:echarts/component/marker/LineDraw
  47663. * @constructor
  47664. */
  47665. function LineDraw(ctor) {
  47666. this._ctor = ctor || Line$1;
  47667. this.group = new Group();
  47668. }
  47669. var lineDrawProto = LineDraw.prototype;
  47670. lineDrawProto.isPersistent = function () {
  47671. return true;
  47672. };
  47673. /**
  47674. * @param {module:echarts/data/List} lineData
  47675. */
  47676. lineDrawProto.updateData = function (lineData) {
  47677. var lineDraw = this;
  47678. var group = lineDraw.group;
  47679. var oldLineData = lineDraw._lineData;
  47680. lineDraw._lineData = lineData;
  47681. // There is no oldLineData only when first rendering or switching from
  47682. // stream mode to normal mode, where previous elements should be removed.
  47683. if (!oldLineData) {
  47684. group.removeAll();
  47685. }
  47686. var seriesScope = makeSeriesScope$1(lineData);
  47687. lineData.diff(oldLineData)
  47688. .add(function (idx) {
  47689. doAdd(lineDraw, lineData, idx, seriesScope);
  47690. })
  47691. .update(function (newIdx, oldIdx) {
  47692. doUpdate(lineDraw, oldLineData, lineData, oldIdx, newIdx, seriesScope);
  47693. })
  47694. .remove(function (idx) {
  47695. group.remove(oldLineData.getItemGraphicEl(idx));
  47696. })
  47697. .execute();
  47698. };
  47699. function doAdd(lineDraw, lineData, idx, seriesScope) {
  47700. var itemLayout = lineData.getItemLayout(idx);
  47701. if (!lineNeedsDraw(itemLayout)) {
  47702. return;
  47703. }
  47704. var el = new lineDraw._ctor(lineData, idx, seriesScope);
  47705. lineData.setItemGraphicEl(idx, el);
  47706. lineDraw.group.add(el);
  47707. }
  47708. function doUpdate(lineDraw, oldLineData, newLineData, oldIdx, newIdx, seriesScope) {
  47709. var itemEl = oldLineData.getItemGraphicEl(oldIdx);
  47710. if (!lineNeedsDraw(newLineData.getItemLayout(newIdx))) {
  47711. lineDraw.group.remove(itemEl);
  47712. return;
  47713. }
  47714. if (!itemEl) {
  47715. itemEl = new lineDraw._ctor(newLineData, newIdx, seriesScope);
  47716. }
  47717. else {
  47718. itemEl.updateData(newLineData, newIdx, seriesScope);
  47719. }
  47720. newLineData.setItemGraphicEl(newIdx, itemEl);
  47721. lineDraw.group.add(itemEl);
  47722. }
  47723. lineDrawProto.updateLayout = function () {
  47724. var lineData = this._lineData;
  47725. // Do not support update layout in incremental mode.
  47726. if (!lineData) {
  47727. return;
  47728. }
  47729. lineData.eachItemGraphicEl(function (el, idx) {
  47730. el.updateLayout(lineData, idx);
  47731. }, this);
  47732. };
  47733. lineDrawProto.incrementalPrepareUpdate = function (lineData) {
  47734. this._seriesScope = makeSeriesScope$1(lineData);
  47735. this._lineData = null;
  47736. this.group.removeAll();
  47737. };
  47738. lineDrawProto.incrementalUpdate = function (taskParams, lineData) {
  47739. function updateIncrementalAndHover(el) {
  47740. if (!el.isGroup) {
  47741. el.incremental = el.useHoverLayer = true;
  47742. }
  47743. }
  47744. for (var idx = taskParams.start; idx < taskParams.end; idx++) {
  47745. var itemLayout = lineData.getItemLayout(idx);
  47746. if (lineNeedsDraw(itemLayout)) {
  47747. var el = new this._ctor(lineData, idx, this._seriesScope);
  47748. el.traverse(updateIncrementalAndHover);
  47749. this.group.add(el);
  47750. lineData.setItemGraphicEl(idx, el);
  47751. }
  47752. }
  47753. };
  47754. function makeSeriesScope$1(lineData) {
  47755. var hostModel = lineData.hostModel;
  47756. return {
  47757. lineStyle: hostModel.getModel('lineStyle').getLineStyle(),
  47758. hoverLineStyle: hostModel.getModel('emphasis.lineStyle').getLineStyle(),
  47759. labelModel: hostModel.getModel('label'),
  47760. hoverLabelModel: hostModel.getModel('emphasis.label')
  47761. };
  47762. }
  47763. lineDrawProto.remove = function () {
  47764. this._clearIncremental();
  47765. this._incremental = null;
  47766. this.group.removeAll();
  47767. };
  47768. lineDrawProto._clearIncremental = function () {
  47769. var incremental = this._incremental;
  47770. if (incremental) {
  47771. incremental.clearDisplaybles();
  47772. }
  47773. };
  47774. function isPointNaN(pt) {
  47775. return isNaN(pt[0]) || isNaN(pt[1]);
  47776. }
  47777. function lineNeedsDraw(pts) {
  47778. return !isPointNaN(pts[0]) && !isPointNaN(pts[1]);
  47779. }
  47780. /*
  47781. * Licensed to the Apache Software Foundation (ASF) under one
  47782. * or more contributor license agreements. See the NOTICE file
  47783. * distributed with this work for additional information
  47784. * regarding copyright ownership. The ASF licenses this file
  47785. * to you under the Apache License, Version 2.0 (the
  47786. * "License"); you may not use this file except in compliance
  47787. * with the License. You may obtain a copy of the License at
  47788. *
  47789. * http://www.apache.org/licenses/LICENSE-2.0
  47790. *
  47791. * Unless required by applicable law or agreed to in writing,
  47792. * software distributed under the License is distributed on an
  47793. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  47794. * KIND, either express or implied. See the License for the
  47795. * specific language governing permissions and limitations
  47796. * under the License.
  47797. */
  47798. function getNodeGlobalScale(seriesModel) {
  47799. var coordSys = seriesModel.coordinateSystem;
  47800. if (coordSys.type !== 'view') {
  47801. return 1;
  47802. }
  47803. var nodeScaleRatio = seriesModel.option.nodeScaleRatio;
  47804. var groupScale = coordSys.scale;
  47805. var groupZoom = (groupScale && groupScale[0]) || 1;
  47806. // Scale node when zoom changes
  47807. var roamZoom = coordSys.getZoom();
  47808. var nodeScale = (roamZoom - 1) * nodeScaleRatio + 1;
  47809. return nodeScale / groupZoom;
  47810. }
  47811. function getSymbolSize$1(node) {
  47812. var symbolSize = node.getVisual('symbolSize');
  47813. if (symbolSize instanceof Array) {
  47814. symbolSize = (symbolSize[0] + symbolSize[1]) / 2;
  47815. }
  47816. return +symbolSize;
  47817. }
  47818. /*
  47819. * Licensed to the Apache Software Foundation (ASF) under one
  47820. * or more contributor license agreements. See the NOTICE file
  47821. * distributed with this work for additional information
  47822. * regarding copyright ownership. The ASF licenses this file
  47823. * to you under the Apache License, Version 2.0 (the
  47824. * "License"); you may not use this file except in compliance
  47825. * with the License. You may obtain a copy of the License at
  47826. *
  47827. * http://www.apache.org/licenses/LICENSE-2.0
  47828. *
  47829. * Unless required by applicable law or agreed to in writing,
  47830. * software distributed under the License is distributed on an
  47831. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  47832. * KIND, either express or implied. See the License for the
  47833. * specific language governing permissions and limitations
  47834. * under the License.
  47835. */
  47836. var v1 = [];
  47837. var v2 = [];
  47838. var v3 = [];
  47839. var quadraticAt$1 = quadraticAt;
  47840. var v2DistSquare = distSquare;
  47841. var mathAbs$1 = Math.abs;
  47842. function intersectCurveCircle(curvePoints, center, radius) {
  47843. var p0 = curvePoints[0];
  47844. var p1 = curvePoints[1];
  47845. var p2 = curvePoints[2];
  47846. var d = Infinity;
  47847. var t;
  47848. var radiusSquare = radius * radius;
  47849. var interval = 0.1;
  47850. for (var _t = 0.1; _t <= 0.9; _t += 0.1) {
  47851. v1[0] = quadraticAt$1(p0[0], p1[0], p2[0], _t);
  47852. v1[1] = quadraticAt$1(p0[1], p1[1], p2[1], _t);
  47853. var diff = mathAbs$1(v2DistSquare(v1, center) - radiusSquare);
  47854. if (diff < d) {
  47855. d = diff;
  47856. t = _t;
  47857. }
  47858. }
  47859. // Assume the segment is monotone,Find root through Bisection method
  47860. // At most 32 iteration
  47861. for (var i = 0; i < 32; i++) {
  47862. // var prev = t - interval;
  47863. var next = t + interval;
  47864. // v1[0] = quadraticAt(p0[0], p1[0], p2[0], prev);
  47865. // v1[1] = quadraticAt(p0[1], p1[1], p2[1], prev);
  47866. v2[0] = quadraticAt$1(p0[0], p1[0], p2[0], t);
  47867. v2[1] = quadraticAt$1(p0[1], p1[1], p2[1], t);
  47868. v3[0] = quadraticAt$1(p0[0], p1[0], p2[0], next);
  47869. v3[1] = quadraticAt$1(p0[1], p1[1], p2[1], next);
  47870. var diff = v2DistSquare(v2, center) - radiusSquare;
  47871. if (mathAbs$1(diff) < 1e-2) {
  47872. break;
  47873. }
  47874. // var prevDiff = v2DistSquare(v1, center) - radiusSquare;
  47875. var nextDiff = v2DistSquare(v3, center) - radiusSquare;
  47876. interval /= 2;
  47877. if (diff < 0) {
  47878. if (nextDiff >= 0) {
  47879. t = t + interval;
  47880. }
  47881. else {
  47882. t = t - interval;
  47883. }
  47884. }
  47885. else {
  47886. if (nextDiff >= 0) {
  47887. t = t - interval;
  47888. }
  47889. else {
  47890. t = t + interval;
  47891. }
  47892. }
  47893. }
  47894. return t;
  47895. }
  47896. // Adjust edge to avoid
  47897. var adjustEdge = function (graph, scale$$1) {
  47898. var tmp0 = [];
  47899. var quadraticSubdivide$$1 = quadraticSubdivide;
  47900. var pts = [[], [], []];
  47901. var pts2 = [[], []];
  47902. var v = [];
  47903. scale$$1 /= 2;
  47904. graph.eachEdge(function (edge, idx) {
  47905. var linePoints = edge.getLayout();
  47906. var fromSymbol = edge.getVisual('fromSymbol');
  47907. var toSymbol = edge.getVisual('toSymbol');
  47908. if (!linePoints.__original) {
  47909. linePoints.__original = [
  47910. clone$1(linePoints[0]),
  47911. clone$1(linePoints[1])
  47912. ];
  47913. if (linePoints[2]) {
  47914. linePoints.__original.push(clone$1(linePoints[2]));
  47915. }
  47916. }
  47917. var originalPoints = linePoints.__original;
  47918. // Quadratic curve
  47919. if (linePoints[2] != null) {
  47920. copy(pts[0], originalPoints[0]);
  47921. copy(pts[1], originalPoints[2]);
  47922. copy(pts[2], originalPoints[1]);
  47923. if (fromSymbol && fromSymbol !== 'none') {
  47924. var symbolSize = getSymbolSize$1(edge.node1);
  47925. var t = intersectCurveCircle(pts, originalPoints[0], symbolSize * scale$$1);
  47926. // Subdivide and get the second
  47927. quadraticSubdivide$$1(pts[0][0], pts[1][0], pts[2][0], t, tmp0);
  47928. pts[0][0] = tmp0[3];
  47929. pts[1][0] = tmp0[4];
  47930. quadraticSubdivide$$1(pts[0][1], pts[1][1], pts[2][1], t, tmp0);
  47931. pts[0][1] = tmp0[3];
  47932. pts[1][1] = tmp0[4];
  47933. }
  47934. if (toSymbol && toSymbol !== 'none') {
  47935. var symbolSize = getSymbolSize$1(edge.node2);
  47936. var t = intersectCurveCircle(pts, originalPoints[1], symbolSize * scale$$1);
  47937. // Subdivide and get the first
  47938. quadraticSubdivide$$1(pts[0][0], pts[1][0], pts[2][0], t, tmp0);
  47939. pts[1][0] = tmp0[1];
  47940. pts[2][0] = tmp0[2];
  47941. quadraticSubdivide$$1(pts[0][1], pts[1][1], pts[2][1], t, tmp0);
  47942. pts[1][1] = tmp0[1];
  47943. pts[2][1] = tmp0[2];
  47944. }
  47945. // Copy back to layout
  47946. copy(linePoints[0], pts[0]);
  47947. copy(linePoints[1], pts[2]);
  47948. copy(linePoints[2], pts[1]);
  47949. }
  47950. // Line
  47951. else {
  47952. copy(pts2[0], originalPoints[0]);
  47953. copy(pts2[1], originalPoints[1]);
  47954. sub(v, pts2[1], pts2[0]);
  47955. normalize(v, v);
  47956. if (fromSymbol && fromSymbol !== 'none') {
  47957. var symbolSize = getSymbolSize$1(edge.node1);
  47958. scaleAndAdd(pts2[0], pts2[0], v, symbolSize * scale$$1);
  47959. }
  47960. if (toSymbol && toSymbol !== 'none') {
  47961. var symbolSize = getSymbolSize$1(edge.node2);
  47962. scaleAndAdd(pts2[1], pts2[1], v, -symbolSize * scale$$1);
  47963. }
  47964. copy(linePoints[0], pts2[0]);
  47965. copy(linePoints[1], pts2[1]);
  47966. }
  47967. });
  47968. };
  47969. /*
  47970. * Licensed to the Apache Software Foundation (ASF) under one
  47971. * or more contributor license agreements. See the NOTICE file
  47972. * distributed with this work for additional information
  47973. * regarding copyright ownership. The ASF licenses this file
  47974. * to you under the Apache License, Version 2.0 (the
  47975. * "License"); you may not use this file except in compliance
  47976. * with the License. You may obtain a copy of the License at
  47977. *
  47978. * http://www.apache.org/licenses/LICENSE-2.0
  47979. *
  47980. * Unless required by applicable law or agreed to in writing,
  47981. * software distributed under the License is distributed on an
  47982. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  47983. * KIND, either express or implied. See the License for the
  47984. * specific language governing permissions and limitations
  47985. * under the License.
  47986. */
  47987. var FOCUS_ADJACENCY = '__focusNodeAdjacency';
  47988. var UNFOCUS_ADJACENCY = '__unfocusNodeAdjacency';
  47989. var nodeOpacityPath = ['itemStyle', 'opacity'];
  47990. var lineOpacityPath = ['lineStyle', 'opacity'];
  47991. function getItemOpacity(item, opacityPath) {
  47992. var opacity = item.getVisual('opacity');
  47993. return opacity != null ? opacity : item.getModel().get(opacityPath);
  47994. }
  47995. function fadeOutItem(item, opacityPath, opacityRatio) {
  47996. var el = item.getGraphicEl();
  47997. var opacity = getItemOpacity(item, opacityPath);
  47998. if (opacityRatio != null) {
  47999. opacity == null && (opacity = 1);
  48000. opacity *= opacityRatio;
  48001. }
  48002. el.downplay && el.downplay();
  48003. el.traverse(function (child) {
  48004. if (!child.isGroup) {
  48005. var opct = child.lineLabelOriginalOpacity;
  48006. if (opct == null || opacityRatio != null) {
  48007. opct = opacity;
  48008. }
  48009. child.setStyle('opacity', opct);
  48010. }
  48011. });
  48012. }
  48013. function fadeInItem(item, opacityPath) {
  48014. var opacity = getItemOpacity(item, opacityPath);
  48015. var el = item.getGraphicEl();
  48016. // Should go back to normal opacity first, consider hoverLayer,
  48017. // where current state is copied to elMirror, and support
  48018. // emphasis opacity here.
  48019. el.traverse(function (child) {
  48020. !child.isGroup && child.setStyle('opacity', opacity);
  48021. });
  48022. el.highlight && el.highlight();
  48023. }
  48024. extendChartView({
  48025. type: 'graph',
  48026. init: function (ecModel, api) {
  48027. var symbolDraw = new SymbolDraw();
  48028. var lineDraw = new LineDraw();
  48029. var group = this.group;
  48030. this._controller = new RoamController(api.getZr());
  48031. this._controllerHost = {target: group};
  48032. group.add(symbolDraw.group);
  48033. group.add(lineDraw.group);
  48034. this._symbolDraw = symbolDraw;
  48035. this._lineDraw = lineDraw;
  48036. this._firstRender = true;
  48037. },
  48038. render: function (seriesModel, ecModel, api) {
  48039. var coordSys = seriesModel.coordinateSystem;
  48040. this._model = seriesModel;
  48041. var symbolDraw = this._symbolDraw;
  48042. var lineDraw = this._lineDraw;
  48043. var group = this.group;
  48044. if (coordSys.type === 'view') {
  48045. var groupNewProp = {
  48046. position: coordSys.position,
  48047. scale: coordSys.scale
  48048. };
  48049. if (this._firstRender) {
  48050. group.attr(groupNewProp);
  48051. }
  48052. else {
  48053. updateProps(group, groupNewProp, seriesModel);
  48054. }
  48055. }
  48056. // Fix edge contact point with node
  48057. adjustEdge(seriesModel.getGraph(), getNodeGlobalScale(seriesModel));
  48058. var data = seriesModel.getData();
  48059. symbolDraw.updateData(data);
  48060. var edgeData = seriesModel.getEdgeData();
  48061. lineDraw.updateData(edgeData);
  48062. this._updateNodeAndLinkScale();
  48063. this._updateController(seriesModel, ecModel, api);
  48064. clearTimeout(this._layoutTimeout);
  48065. var forceLayout = seriesModel.forceLayout;
  48066. var layoutAnimation = seriesModel.get('force.layoutAnimation');
  48067. if (forceLayout) {
  48068. this._startForceLayoutIteration(forceLayout, layoutAnimation);
  48069. }
  48070. data.eachItemGraphicEl(function (el, idx) {
  48071. var itemModel = data.getItemModel(idx);
  48072. // Update draggable
  48073. el.off('drag').off('dragend');
  48074. var draggable = itemModel.get('draggable');
  48075. if (draggable) {
  48076. el.on('drag', function () {
  48077. if (forceLayout) {
  48078. forceLayout.warmUp();
  48079. !this._layouting
  48080. && this._startForceLayoutIteration(forceLayout, layoutAnimation);
  48081. forceLayout.setFixed(idx);
  48082. // Write position back to layout
  48083. data.setItemLayout(idx, el.position);
  48084. }
  48085. }, this).on('dragend', function () {
  48086. if (forceLayout) {
  48087. forceLayout.setUnfixed(idx);
  48088. }
  48089. }, this);
  48090. }
  48091. el.setDraggable(draggable && forceLayout);
  48092. el[FOCUS_ADJACENCY] && el.off('mouseover', el[FOCUS_ADJACENCY]);
  48093. el[UNFOCUS_ADJACENCY] && el.off('mouseout', el[UNFOCUS_ADJACENCY]);
  48094. if (itemModel.get('focusNodeAdjacency')) {
  48095. el.on('mouseover', el[FOCUS_ADJACENCY] = function () {
  48096. api.dispatchAction({
  48097. type: 'focusNodeAdjacency',
  48098. seriesId: seriesModel.id,
  48099. dataIndex: el.dataIndex
  48100. });
  48101. });
  48102. el.on('mouseout', el[UNFOCUS_ADJACENCY] = function () {
  48103. api.dispatchAction({
  48104. type: 'unfocusNodeAdjacency',
  48105. seriesId: seriesModel.id
  48106. });
  48107. });
  48108. }
  48109. }, this);
  48110. data.graph.eachEdge(function (edge) {
  48111. var el = edge.getGraphicEl();
  48112. el[FOCUS_ADJACENCY] && el.off('mouseover', el[FOCUS_ADJACENCY]);
  48113. el[UNFOCUS_ADJACENCY] && el.off('mouseout', el[UNFOCUS_ADJACENCY]);
  48114. if (edge.getModel().get('focusNodeAdjacency')) {
  48115. el.on('mouseover', el[FOCUS_ADJACENCY] = function () {
  48116. api.dispatchAction({
  48117. type: 'focusNodeAdjacency',
  48118. seriesId: seriesModel.id,
  48119. edgeDataIndex: edge.dataIndex
  48120. });
  48121. });
  48122. el.on('mouseout', el[UNFOCUS_ADJACENCY] = function () {
  48123. api.dispatchAction({
  48124. type: 'unfocusNodeAdjacency',
  48125. seriesId: seriesModel.id
  48126. });
  48127. });
  48128. }
  48129. });
  48130. var circularRotateLabel = seriesModel.get('layout') === 'circular'
  48131. && seriesModel.get('circular.rotateLabel');
  48132. var cx = data.getLayout('cx');
  48133. var cy = data.getLayout('cy');
  48134. data.eachItemGraphicEl(function (el, idx) {
  48135. var itemModel = data.getItemModel(idx);
  48136. var labelRotate = itemModel.get('label.rotate') || 0;
  48137. var symbolPath = el.getSymbolPath();
  48138. if (circularRotateLabel) {
  48139. var pos = data.getItemLayout(idx);
  48140. var rad = Math.atan2(pos[1] - cy, pos[0] - cx);
  48141. if (rad < 0) {
  48142. rad = Math.PI * 2 + rad;
  48143. }
  48144. var isLeft = pos[0] < cx;
  48145. if (isLeft) {
  48146. rad = rad - Math.PI;
  48147. }
  48148. var textPosition = isLeft ? 'left' : 'right';
  48149. modifyLabelStyle(
  48150. symbolPath,
  48151. {
  48152. textRotation: -rad,
  48153. textPosition: textPosition,
  48154. textOrigin: 'center'
  48155. },
  48156. {
  48157. textPosition: textPosition
  48158. }
  48159. );
  48160. }
  48161. else {
  48162. modifyLabelStyle(
  48163. symbolPath,
  48164. {
  48165. textRotation: labelRotate *= Math.PI / 180
  48166. }
  48167. );
  48168. }
  48169. });
  48170. this._firstRender = false;
  48171. },
  48172. dispose: function () {
  48173. this._controller && this._controller.dispose();
  48174. this._controllerHost = {};
  48175. },
  48176. focusNodeAdjacency: function (seriesModel, ecModel, api, payload) {
  48177. var data = this._model.getData();
  48178. var graph = data.graph;
  48179. var dataIndex = payload.dataIndex;
  48180. var edgeDataIndex = payload.edgeDataIndex;
  48181. var node = graph.getNodeByIndex(dataIndex);
  48182. var edge = graph.getEdgeByIndex(edgeDataIndex);
  48183. if (!node && !edge) {
  48184. return;
  48185. }
  48186. graph.eachNode(function (node) {
  48187. fadeOutItem(node, nodeOpacityPath, 0.1);
  48188. });
  48189. graph.eachEdge(function (edge) {
  48190. fadeOutItem(edge, lineOpacityPath, 0.1);
  48191. });
  48192. if (node) {
  48193. fadeInItem(node, nodeOpacityPath);
  48194. each$1(node.edges, function (adjacentEdge) {
  48195. if (adjacentEdge.dataIndex < 0) {
  48196. return;
  48197. }
  48198. fadeInItem(adjacentEdge, lineOpacityPath);
  48199. fadeInItem(adjacentEdge.node1, nodeOpacityPath);
  48200. fadeInItem(adjacentEdge.node2, nodeOpacityPath);
  48201. });
  48202. }
  48203. if (edge) {
  48204. fadeInItem(edge, lineOpacityPath);
  48205. fadeInItem(edge.node1, nodeOpacityPath);
  48206. fadeInItem(edge.node2, nodeOpacityPath);
  48207. }
  48208. },
  48209. unfocusNodeAdjacency: function (seriesModel, ecModel, api, payload) {
  48210. var graph = this._model.getData().graph;
  48211. graph.eachNode(function (node) {
  48212. fadeOutItem(node, nodeOpacityPath);
  48213. });
  48214. graph.eachEdge(function (edge) {
  48215. fadeOutItem(edge, lineOpacityPath);
  48216. });
  48217. },
  48218. _startForceLayoutIteration: function (forceLayout, layoutAnimation) {
  48219. var self = this;
  48220. (function step() {
  48221. forceLayout.step(function (stopped) {
  48222. self.updateLayout(self._model);
  48223. (self._layouting = !stopped) && (
  48224. layoutAnimation
  48225. ? (self._layoutTimeout = setTimeout(step, 16))
  48226. : step()
  48227. );
  48228. });
  48229. })();
  48230. },
  48231. _updateController: function (seriesModel, ecModel, api) {
  48232. var controller = this._controller;
  48233. var controllerHost = this._controllerHost;
  48234. var group = this.group;
  48235. controller.setPointerChecker(function (e, x, y) {
  48236. var rect = group.getBoundingRect();
  48237. rect.applyTransform(group.transform);
  48238. return rect.contain(x, y)
  48239. && !onIrrelevantElement(e, api, seriesModel);
  48240. });
  48241. if (seriesModel.coordinateSystem.type !== 'view') {
  48242. controller.disable();
  48243. return;
  48244. }
  48245. controller.enable(seriesModel.get('roam'));
  48246. controllerHost.zoomLimit = seriesModel.get('scaleLimit');
  48247. controllerHost.zoom = seriesModel.coordinateSystem.getZoom();
  48248. controller
  48249. .off('pan')
  48250. .off('zoom')
  48251. .on('pan', function (e) {
  48252. updateViewOnPan(controllerHost, e.dx, e.dy);
  48253. api.dispatchAction({
  48254. seriesId: seriesModel.id,
  48255. type: 'graphRoam',
  48256. dx: e.dx,
  48257. dy: e.dy
  48258. });
  48259. })
  48260. .on('zoom', function (e) {
  48261. updateViewOnZoom(controllerHost, e.scale, e.originX, e.originY);
  48262. api.dispatchAction({
  48263. seriesId: seriesModel.id,
  48264. type: 'graphRoam',
  48265. zoom: e.scale,
  48266. originX: e.originX,
  48267. originY: e.originY
  48268. });
  48269. this._updateNodeAndLinkScale();
  48270. adjustEdge(seriesModel.getGraph(), getNodeGlobalScale(seriesModel));
  48271. this._lineDraw.updateLayout();
  48272. }, this);
  48273. },
  48274. _updateNodeAndLinkScale: function () {
  48275. var seriesModel = this._model;
  48276. var data = seriesModel.getData();
  48277. var nodeScale = getNodeGlobalScale(seriesModel);
  48278. var invScale = [nodeScale, nodeScale];
  48279. data.eachItemGraphicEl(function (el, idx) {
  48280. el.attr('scale', invScale);
  48281. });
  48282. },
  48283. updateLayout: function (seriesModel) {
  48284. adjustEdge(seriesModel.getGraph(), getNodeGlobalScale(seriesModel));
  48285. this._symbolDraw.updateLayout();
  48286. this._lineDraw.updateLayout();
  48287. },
  48288. remove: function (ecModel, api) {
  48289. this._symbolDraw && this._symbolDraw.remove();
  48290. this._lineDraw && this._lineDraw.remove();
  48291. }
  48292. });
  48293. /*
  48294. * Licensed to the Apache Software Foundation (ASF) under one
  48295. * or more contributor license agreements. See the NOTICE file
  48296. * distributed with this work for additional information
  48297. * regarding copyright ownership. The ASF licenses this file
  48298. * to you under the Apache License, Version 2.0 (the
  48299. * "License"); you may not use this file except in compliance
  48300. * with the License. You may obtain a copy of the License at
  48301. *
  48302. * http://www.apache.org/licenses/LICENSE-2.0
  48303. *
  48304. * Unless required by applicable law or agreed to in writing,
  48305. * software distributed under the License is distributed on an
  48306. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  48307. * KIND, either express or implied. See the License for the
  48308. * specific language governing permissions and limitations
  48309. * under the License.
  48310. */
  48311. /**
  48312. * @payload
  48313. * @property {number} [seriesIndex]
  48314. * @property {string} [seriesId]
  48315. * @property {string} [seriesName]
  48316. * @property {number} [dataIndex]
  48317. */
  48318. registerAction({
  48319. type: 'focusNodeAdjacency',
  48320. event: 'focusNodeAdjacency',
  48321. update: 'series:focusNodeAdjacency'
  48322. }, function () {});
  48323. /**
  48324. * @payload
  48325. * @property {number} [seriesIndex]
  48326. * @property {string} [seriesId]
  48327. * @property {string} [seriesName]
  48328. */
  48329. registerAction({
  48330. type: 'unfocusNodeAdjacency',
  48331. event: 'unfocusNodeAdjacency',
  48332. update: 'series:unfocusNodeAdjacency'
  48333. }, function () {});
  48334. /*
  48335. * Licensed to the Apache Software Foundation (ASF) under one
  48336. * or more contributor license agreements. See the NOTICE file
  48337. * distributed with this work for additional information
  48338. * regarding copyright ownership. The ASF licenses this file
  48339. * to you under the Apache License, Version 2.0 (the
  48340. * "License"); you may not use this file except in compliance
  48341. * with the License. You may obtain a copy of the License at
  48342. *
  48343. * http://www.apache.org/licenses/LICENSE-2.0
  48344. *
  48345. * Unless required by applicable law or agreed to in writing,
  48346. * software distributed under the License is distributed on an
  48347. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  48348. * KIND, either express or implied. See the License for the
  48349. * specific language governing permissions and limitations
  48350. * under the License.
  48351. */
  48352. var actionInfo = {
  48353. type: 'graphRoam',
  48354. event: 'graphRoam',
  48355. update: 'none'
  48356. };
  48357. /**
  48358. * @payload
  48359. * @property {string} name Series name
  48360. * @property {number} [dx]
  48361. * @property {number} [dy]
  48362. * @property {number} [zoom]
  48363. * @property {number} [originX]
  48364. * @property {number} [originY]
  48365. */
  48366. registerAction(actionInfo, function (payload, ecModel) {
  48367. ecModel.eachComponent({mainType: 'series', query: payload}, function (seriesModel) {
  48368. var coordSys = seriesModel.coordinateSystem;
  48369. var res = updateCenterAndZoom(coordSys, payload);
  48370. seriesModel.setCenter
  48371. && seriesModel.setCenter(res.center);
  48372. seriesModel.setZoom
  48373. && seriesModel.setZoom(res.zoom);
  48374. });
  48375. });
  48376. /*
  48377. * Licensed to the Apache Software Foundation (ASF) under one
  48378. * or more contributor license agreements. See the NOTICE file
  48379. * distributed with this work for additional information
  48380. * regarding copyright ownership. The ASF licenses this file
  48381. * to you under the Apache License, Version 2.0 (the
  48382. * "License"); you may not use this file except in compliance
  48383. * with the License. You may obtain a copy of the License at
  48384. *
  48385. * http://www.apache.org/licenses/LICENSE-2.0
  48386. *
  48387. * Unless required by applicable law or agreed to in writing,
  48388. * software distributed under the License is distributed on an
  48389. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  48390. * KIND, either express or implied. See the License for the
  48391. * specific language governing permissions and limitations
  48392. * under the License.
  48393. */
  48394. var categoryFilter = function (ecModel) {
  48395. var legendModels = ecModel.findComponents({
  48396. mainType: 'legend'
  48397. });
  48398. if (!legendModels || !legendModels.length) {
  48399. return;
  48400. }
  48401. ecModel.eachSeriesByType('graph', function (graphSeries) {
  48402. var categoriesData = graphSeries.getCategoriesData();
  48403. var graph = graphSeries.getGraph();
  48404. var data = graph.data;
  48405. var categoryNames = categoriesData.mapArray(categoriesData.getName);
  48406. data.filterSelf(function (idx) {
  48407. var model = data.getItemModel(idx);
  48408. var category = model.getShallow('category');
  48409. if (category != null) {
  48410. if (typeof category === 'number') {
  48411. category = categoryNames[category];
  48412. }
  48413. // If in any legend component the status is not selected.
  48414. for (var i = 0; i < legendModels.length; i++) {
  48415. if (!legendModels[i].isSelected(category)) {
  48416. return false;
  48417. }
  48418. }
  48419. }
  48420. return true;
  48421. });
  48422. }, this);
  48423. };
  48424. /*
  48425. * Licensed to the Apache Software Foundation (ASF) under one
  48426. * or more contributor license agreements. See the NOTICE file
  48427. * distributed with this work for additional information
  48428. * regarding copyright ownership. The ASF licenses this file
  48429. * to you under the Apache License, Version 2.0 (the
  48430. * "License"); you may not use this file except in compliance
  48431. * with the License. You may obtain a copy of the License at
  48432. *
  48433. * http://www.apache.org/licenses/LICENSE-2.0
  48434. *
  48435. * Unless required by applicable law or agreed to in writing,
  48436. * software distributed under the License is distributed on an
  48437. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  48438. * KIND, either express or implied. See the License for the
  48439. * specific language governing permissions and limitations
  48440. * under the License.
  48441. */
  48442. var categoryVisual = function (ecModel) {
  48443. var paletteScope = {};
  48444. ecModel.eachSeriesByType('graph', function (seriesModel) {
  48445. var categoriesData = seriesModel.getCategoriesData();
  48446. var data = seriesModel.getData();
  48447. var categoryNameIdxMap = {};
  48448. categoriesData.each(function (idx) {
  48449. var name = categoriesData.getName(idx);
  48450. // Add prefix to avoid conflict with Object.prototype.
  48451. categoryNameIdxMap['ec-' + name] = idx;
  48452. var itemModel = categoriesData.getItemModel(idx);
  48453. var color = itemModel.get('itemStyle.color')
  48454. || seriesModel.getColorFromPalette(name, paletteScope);
  48455. categoriesData.setItemVisual(idx, 'color', color);
  48456. var itemStyleList = ['opacity', 'symbol', 'symbolSize', 'symbolKeepAspect'];
  48457. for (var i = 0; i < itemStyleList.length; i++) {
  48458. var itemStyle = itemModel.getShallow(itemStyleList[i], true);
  48459. if (itemStyle != null) {
  48460. categoriesData.setItemVisual(idx, itemStyleList[i], itemStyle);
  48461. }
  48462. }
  48463. });
  48464. // Assign category color to visual
  48465. if (categoriesData.count()) {
  48466. data.each(function (idx) {
  48467. var model = data.getItemModel(idx);
  48468. var category = model.getShallow('category');
  48469. if (category != null) {
  48470. if (typeof category === 'string') {
  48471. category = categoryNameIdxMap['ec-' + category];
  48472. }
  48473. var itemStyleList = ['color', 'opacity', 'symbol', 'symbolSize', 'symbolKeepAspect'];
  48474. for (var i = 0; i < itemStyleList.length; i++) {
  48475. if (data.getItemVisual(idx, itemStyleList[i], true) == null) {
  48476. data.setItemVisual(
  48477. idx, itemStyleList[i],
  48478. categoriesData.getItemVisual(category, itemStyleList[i])
  48479. );
  48480. }
  48481. }
  48482. }
  48483. });
  48484. }
  48485. });
  48486. };
  48487. /*
  48488. * Licensed to the Apache Software Foundation (ASF) under one
  48489. * or more contributor license agreements. See the NOTICE file
  48490. * distributed with this work for additional information
  48491. * regarding copyright ownership. The ASF licenses this file
  48492. * to you under the Apache License, Version 2.0 (the
  48493. * "License"); you may not use this file except in compliance
  48494. * with the License. You may obtain a copy of the License at
  48495. *
  48496. * http://www.apache.org/licenses/LICENSE-2.0
  48497. *
  48498. * Unless required by applicable law or agreed to in writing,
  48499. * software distributed under the License is distributed on an
  48500. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  48501. * KIND, either express or implied. See the License for the
  48502. * specific language governing permissions and limitations
  48503. * under the License.
  48504. */
  48505. function normalize$1(a) {
  48506. if (!(a instanceof Array)) {
  48507. a = [a, a];
  48508. }
  48509. return a;
  48510. }
  48511. var edgeVisual = function (ecModel) {
  48512. ecModel.eachSeriesByType('graph', function (seriesModel) {
  48513. var graph = seriesModel.getGraph();
  48514. var edgeData = seriesModel.getEdgeData();
  48515. var symbolType = normalize$1(seriesModel.get('edgeSymbol'));
  48516. var symbolSize = normalize$1(seriesModel.get('edgeSymbolSize'));
  48517. var colorQuery = 'lineStyle.color'.split('.');
  48518. var opacityQuery = 'lineStyle.opacity'.split('.');
  48519. edgeData.setVisual('fromSymbol', symbolType && symbolType[0]);
  48520. edgeData.setVisual('toSymbol', symbolType && symbolType[1]);
  48521. edgeData.setVisual('fromSymbolSize', symbolSize && symbolSize[0]);
  48522. edgeData.setVisual('toSymbolSize', symbolSize && symbolSize[1]);
  48523. edgeData.setVisual('color', seriesModel.get(colorQuery));
  48524. edgeData.setVisual('opacity', seriesModel.get(opacityQuery));
  48525. edgeData.each(function (idx) {
  48526. var itemModel = edgeData.getItemModel(idx);
  48527. var edge = graph.getEdgeByIndex(idx);
  48528. var symbolType = normalize$1(itemModel.getShallow('symbol', true));
  48529. var symbolSize = normalize$1(itemModel.getShallow('symbolSize', true));
  48530. // Edge visual must after node visual
  48531. var color = itemModel.get(colorQuery);
  48532. var opacity = itemModel.get(opacityQuery);
  48533. switch (color) {
  48534. case 'source':
  48535. color = edge.node1.getVisual('color');
  48536. break;
  48537. case 'target':
  48538. color = edge.node2.getVisual('color');
  48539. break;
  48540. }
  48541. symbolType[0] && edge.setVisual('fromSymbol', symbolType[0]);
  48542. symbolType[1] && edge.setVisual('toSymbol', symbolType[1]);
  48543. symbolSize[0] && edge.setVisual('fromSymbolSize', symbolSize[0]);
  48544. symbolSize[1] && edge.setVisual('toSymbolSize', symbolSize[1]);
  48545. edge.setVisual('color', color);
  48546. edge.setVisual('opacity', opacity);
  48547. });
  48548. });
  48549. };
  48550. /*
  48551. * Licensed to the Apache Software Foundation (ASF) under one
  48552. * or more contributor license agreements. See the NOTICE file
  48553. * distributed with this work for additional information
  48554. * regarding copyright ownership. The ASF licenses this file
  48555. * to you under the Apache License, Version 2.0 (the
  48556. * "License"); you may not use this file except in compliance
  48557. * with the License. You may obtain a copy of the License at
  48558. *
  48559. * http://www.apache.org/licenses/LICENSE-2.0
  48560. *
  48561. * Unless required by applicable law or agreed to in writing,
  48562. * software distributed under the License is distributed on an
  48563. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  48564. * KIND, either express or implied. See the License for the
  48565. * specific language governing permissions and limitations
  48566. * under the License.
  48567. */
  48568. function simpleLayout$1(seriesModel) {
  48569. var coordSys = seriesModel.coordinateSystem;
  48570. if (coordSys && coordSys.type !== 'view') {
  48571. return;
  48572. }
  48573. var graph = seriesModel.getGraph();
  48574. graph.eachNode(function (node) {
  48575. var model = node.getModel();
  48576. node.setLayout([+model.get('x'), +model.get('y')]);
  48577. });
  48578. simpleLayoutEdge(graph);
  48579. }
  48580. function simpleLayoutEdge(graph) {
  48581. graph.eachEdge(function (edge) {
  48582. var curveness = edge.getModel().get('lineStyle.curveness') || 0;
  48583. var p1 = clone$1(edge.node1.getLayout());
  48584. var p2 = clone$1(edge.node2.getLayout());
  48585. var points = [p1, p2];
  48586. if (+curveness) {
  48587. points.push([
  48588. (p1[0] + p2[0]) / 2 - (p1[1] - p2[1]) * curveness,
  48589. (p1[1] + p2[1]) / 2 - (p2[0] - p1[0]) * curveness
  48590. ]);
  48591. }
  48592. edge.setLayout(points);
  48593. });
  48594. }
  48595. /*
  48596. * Licensed to the Apache Software Foundation (ASF) under one
  48597. * or more contributor license agreements. See the NOTICE file
  48598. * distributed with this work for additional information
  48599. * regarding copyright ownership. The ASF licenses this file
  48600. * to you under the Apache License, Version 2.0 (the
  48601. * "License"); you may not use this file except in compliance
  48602. * with the License. You may obtain a copy of the License at
  48603. *
  48604. * http://www.apache.org/licenses/LICENSE-2.0
  48605. *
  48606. * Unless required by applicable law or agreed to in writing,
  48607. * software distributed under the License is distributed on an
  48608. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  48609. * KIND, either express or implied. See the License for the
  48610. * specific language governing permissions and limitations
  48611. * under the License.
  48612. */
  48613. var simpleLayout = function (ecModel, api) {
  48614. ecModel.eachSeriesByType('graph', function (seriesModel) {
  48615. var layout = seriesModel.get('layout');
  48616. var coordSys = seriesModel.coordinateSystem;
  48617. if (coordSys && coordSys.type !== 'view') {
  48618. var data = seriesModel.getData();
  48619. var dimensions = [];
  48620. each$1(coordSys.dimensions, function (coordDim) {
  48621. dimensions = dimensions.concat(data.mapDimension(coordDim, true));
  48622. });
  48623. for (var dataIndex = 0; dataIndex < data.count(); dataIndex++) {
  48624. var value = [];
  48625. var hasValue = false;
  48626. for (var i = 0; i < dimensions.length; i++) {
  48627. var val = data.get(dimensions[i], dataIndex);
  48628. if (!isNaN(val)) {
  48629. hasValue = true;
  48630. }
  48631. value.push(val);
  48632. }
  48633. if (hasValue) {
  48634. data.setItemLayout(dataIndex, coordSys.dataToPoint(value));
  48635. }
  48636. else {
  48637. // Also {Array.<number>}, not undefined to avoid if...else... statement
  48638. data.setItemLayout(dataIndex, [NaN, NaN]);
  48639. }
  48640. }
  48641. simpleLayoutEdge(data.graph);
  48642. }
  48643. else if (!layout || layout === 'none') {
  48644. simpleLayout$1(seriesModel);
  48645. }
  48646. });
  48647. };
  48648. /*
  48649. * Licensed to the Apache Software Foundation (ASF) under one
  48650. * or more contributor license agreements. See the NOTICE file
  48651. * distributed with this work for additional information
  48652. * regarding copyright ownership. The ASF licenses this file
  48653. * to you under the Apache License, Version 2.0 (the
  48654. * "License"); you may not use this file except in compliance
  48655. * with the License. You may obtain a copy of the License at
  48656. *
  48657. * http://www.apache.org/licenses/LICENSE-2.0
  48658. *
  48659. * Unless required by applicable law or agreed to in writing,
  48660. * software distributed under the License is distributed on an
  48661. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  48662. * KIND, either express or implied. See the License for the
  48663. * specific language governing permissions and limitations
  48664. * under the License.
  48665. */
  48666. var PI$3 = Math.PI;
  48667. var _symbolRadiansHalf = [];
  48668. /**
  48669. * `basedOn` can be:
  48670. * 'value':
  48671. * This layout is not accurate and have same bad case. For example,
  48672. * if the min value is very smaller than the max value, the nodes
  48673. * with the min value probably overlap even though there is enough
  48674. * space to layout them. So we only use this approach in the as the
  48675. * init layout of the force layout.
  48676. * FIXME
  48677. * Probably we do not need this method any more but use
  48678. * `basedOn: 'symbolSize'` in force layout if
  48679. * delay its init operations to GraphView.
  48680. * 'symbolSize':
  48681. * This approach work only if all of the symbol size calculated.
  48682. * That is, the progressive rendering is not applied to graph.
  48683. * FIXME
  48684. * If progressive rendering is applied to graph some day,
  48685. * probably we have to use `basedOn: 'value'`.
  48686. *
  48687. * @param {module:echarts/src/model/Series} seriesModel
  48688. * @param {string} basedOn 'value' or 'symbolSize'
  48689. */
  48690. function circularLayout$1(seriesModel, basedOn) {
  48691. var coordSys = seriesModel.coordinateSystem;
  48692. if (coordSys && coordSys.type !== 'view') {
  48693. return;
  48694. }
  48695. var rect = coordSys.getBoundingRect();
  48696. var nodeData = seriesModel.getData();
  48697. var graph = nodeData.graph;
  48698. var cx = rect.width / 2 + rect.x;
  48699. var cy = rect.height / 2 + rect.y;
  48700. var r = Math.min(rect.width, rect.height) / 2;
  48701. var count = nodeData.count();
  48702. nodeData.setLayout({
  48703. cx: cx,
  48704. cy: cy
  48705. });
  48706. if (!count) {
  48707. return;
  48708. }
  48709. _layoutNodesBasedOn[basedOn](seriesModel, coordSys, graph, nodeData, r, cx, cy, count);
  48710. graph.eachEdge(function (edge) {
  48711. var curveness = edge.getModel().get('lineStyle.curveness') || 0;
  48712. var p1 = clone$1(edge.node1.getLayout());
  48713. var p2 = clone$1(edge.node2.getLayout());
  48714. var cp1;
  48715. var x12 = (p1[0] + p2[0]) / 2;
  48716. var y12 = (p1[1] + p2[1]) / 2;
  48717. if (+curveness) {
  48718. curveness *= 3;
  48719. cp1 = [
  48720. cx * curveness + x12 * (1 - curveness),
  48721. cy * curveness + y12 * (1 - curveness)
  48722. ];
  48723. }
  48724. edge.setLayout([p1, p2, cp1]);
  48725. });
  48726. }
  48727. var _layoutNodesBasedOn = {
  48728. value: function (seriesModel, coordSys, graph, nodeData, r, cx, cy, count) {
  48729. var angle = 0;
  48730. var sum = nodeData.getSum('value');
  48731. var unitAngle = Math.PI * 2 / (sum || count);
  48732. graph.eachNode(function (node) {
  48733. var value = node.getValue('value');
  48734. var radianHalf = unitAngle * (sum ? value : 1) / 2;
  48735. angle += radianHalf;
  48736. node.setLayout([
  48737. r * Math.cos(angle) + cx,
  48738. r * Math.sin(angle) + cy
  48739. ]);
  48740. angle += radianHalf;
  48741. });
  48742. },
  48743. symbolSize: function (seriesModel, coordSys, graph, nodeData, r, cx, cy, count) {
  48744. var sumRadian = 0;
  48745. _symbolRadiansHalf.length = count;
  48746. var nodeScale = getNodeGlobalScale(seriesModel);
  48747. graph.eachNode(function (node) {
  48748. var symbolSize = getSymbolSize$1(node);
  48749. // Normally this case will not happen, but we still add
  48750. // some the defensive code (2px is an arbitrary value).
  48751. isNaN(symbolSize) && (symbolSize = 2);
  48752. symbolSize < 0 && (symbolSize = 0);
  48753. symbolSize *= nodeScale;
  48754. var symbolRadianHalf = Math.asin(symbolSize / 2 / r);
  48755. // when `symbolSize / 2` is bigger than `r`.
  48756. isNaN(symbolRadianHalf) && (symbolRadianHalf = PI$3 / 2);
  48757. _symbolRadiansHalf[node.dataIndex] = symbolRadianHalf;
  48758. sumRadian += symbolRadianHalf * 2;
  48759. });
  48760. var halfRemainRadian = (2 * PI$3 - sumRadian) / count / 2;
  48761. var angle = 0;
  48762. graph.eachNode(function (node) {
  48763. var radianHalf = halfRemainRadian + _symbolRadiansHalf[node.dataIndex];
  48764. angle += radianHalf;
  48765. node.setLayout([
  48766. r * Math.cos(angle) + cx,
  48767. r * Math.sin(angle) + cy
  48768. ]);
  48769. angle += radianHalf;
  48770. });
  48771. }
  48772. };
  48773. /*
  48774. * Licensed to the Apache Software Foundation (ASF) under one
  48775. * or more contributor license agreements. See the NOTICE file
  48776. * distributed with this work for additional information
  48777. * regarding copyright ownership. The ASF licenses this file
  48778. * to you under the Apache License, Version 2.0 (the
  48779. * "License"); you may not use this file except in compliance
  48780. * with the License. You may obtain a copy of the License at
  48781. *
  48782. * http://www.apache.org/licenses/LICENSE-2.0
  48783. *
  48784. * Unless required by applicable law or agreed to in writing,
  48785. * software distributed under the License is distributed on an
  48786. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  48787. * KIND, either express or implied. See the License for the
  48788. * specific language governing permissions and limitations
  48789. * under the License.
  48790. */
  48791. var circularLayout = function (ecModel) {
  48792. ecModel.eachSeriesByType('graph', function (seriesModel) {
  48793. if (seriesModel.get('layout') === 'circular') {
  48794. circularLayout$1(seriesModel, 'symbolSize');
  48795. }
  48796. });
  48797. };
  48798. /*
  48799. * Licensed to the Apache Software Foundation (ASF) under one
  48800. * or more contributor license agreements. See the NOTICE file
  48801. * distributed with this work for additional information
  48802. * regarding copyright ownership. The ASF licenses this file
  48803. * to you under the Apache License, Version 2.0 (the
  48804. * "License"); you may not use this file except in compliance
  48805. * with the License. You may obtain a copy of the License at
  48806. *
  48807. * http://www.apache.org/licenses/LICENSE-2.0
  48808. *
  48809. * Unless required by applicable law or agreed to in writing,
  48810. * software distributed under the License is distributed on an
  48811. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  48812. * KIND, either express or implied. See the License for the
  48813. * specific language governing permissions and limitations
  48814. * under the License.
  48815. */
  48816. /*
  48817. * A third-party license is embeded for some of the code in this file:
  48818. * Some formulas were originally copied from "d3.js" with some
  48819. * modifications made for this project.
  48820. * (See more details in the comment of the method "step" below.)
  48821. * The use of the source code of this file is also subject to the terms
  48822. * and consitions of the license of "d3.js" (BSD-3Clause, see
  48823. * </licenses/LICENSE-d3>).
  48824. */
  48825. var scaleAndAdd$2 = scaleAndAdd;
  48826. // function adjacentNode(n, e) {
  48827. // return e.n1 === n ? e.n2 : e.n1;
  48828. // }
  48829. function forceLayout$1(nodes, edges, opts) {
  48830. var rect = opts.rect;
  48831. var width = rect.width;
  48832. var height = rect.height;
  48833. var center = [rect.x + width / 2, rect.y + height / 2];
  48834. // var scale = opts.scale || 1;
  48835. var gravity = opts.gravity == null ? 0.1 : opts.gravity;
  48836. // for (var i = 0; i < edges.length; i++) {
  48837. // var e = edges[i];
  48838. // var n1 = e.n1;
  48839. // var n2 = e.n2;
  48840. // n1.edges = n1.edges || [];
  48841. // n2.edges = n2.edges || [];
  48842. // n1.edges.push(e);
  48843. // n2.edges.push(e);
  48844. // }
  48845. // Init position
  48846. for (var i = 0; i < nodes.length; i++) {
  48847. var n = nodes[i];
  48848. if (!n.p) {
  48849. n.p = create(
  48850. width * (Math.random() - 0.5) + center[0],
  48851. height * (Math.random() - 0.5) + center[1]
  48852. );
  48853. }
  48854. n.pp = clone$1(n.p);
  48855. n.edges = null;
  48856. }
  48857. // Formula in 'Graph Drawing by Force-directed Placement'
  48858. // var k = scale * Math.sqrt(width * height / nodes.length);
  48859. // var k2 = k * k;
  48860. var friction = 0.6;
  48861. return {
  48862. warmUp: function () {
  48863. friction = 0.5;
  48864. },
  48865. setFixed: function (idx) {
  48866. nodes[idx].fixed = true;
  48867. },
  48868. setUnfixed: function (idx) {
  48869. nodes[idx].fixed = false;
  48870. },
  48871. /**
  48872. * Some formulas were originally copied from "d3.js"
  48873. * https://github.com/d3/d3/blob/b516d77fb8566b576088e73410437494717ada26/src/layout/force.js
  48874. * with some modifications made for this project.
  48875. * See the license statement at the head of this file.
  48876. */
  48877. step: function (cb) {
  48878. var v12 = [];
  48879. var nLen = nodes.length;
  48880. for (var i = 0; i < edges.length; i++) {
  48881. var e = edges[i];
  48882. var n1 = e.n1;
  48883. var n2 = e.n2;
  48884. sub(v12, n2.p, n1.p);
  48885. var d = len(v12) - e.d;
  48886. var w = n2.w / (n1.w + n2.w);
  48887. if (isNaN(w)) {
  48888. w = 0;
  48889. }
  48890. normalize(v12, v12);
  48891. !n1.fixed && scaleAndAdd$2(n1.p, n1.p, v12, w * d * friction);
  48892. !n2.fixed && scaleAndAdd$2(n2.p, n2.p, v12, -(1 - w) * d * friction);
  48893. }
  48894. // Gravity
  48895. for (var i = 0; i < nLen; i++) {
  48896. var n = nodes[i];
  48897. if (!n.fixed) {
  48898. sub(v12, center, n.p);
  48899. // var d = vec2.len(v12);
  48900. // vec2.scale(v12, v12, 1 / d);
  48901. // var gravityFactor = gravity;
  48902. scaleAndAdd$2(n.p, n.p, v12, gravity * friction);
  48903. }
  48904. }
  48905. // Repulsive
  48906. // PENDING
  48907. for (var i = 0; i < nLen; i++) {
  48908. var n1 = nodes[i];
  48909. for (var j = i + 1; j < nLen; j++) {
  48910. var n2 = nodes[j];
  48911. sub(v12, n2.p, n1.p);
  48912. var d = len(v12);
  48913. if (d === 0) {
  48914. // Random repulse
  48915. set(v12, Math.random() - 0.5, Math.random() - 0.5);
  48916. d = 1;
  48917. }
  48918. var repFact = (n1.rep + n2.rep) / d / d;
  48919. !n1.fixed && scaleAndAdd$2(n1.pp, n1.pp, v12, repFact);
  48920. !n2.fixed && scaleAndAdd$2(n2.pp, n2.pp, v12, -repFact);
  48921. }
  48922. }
  48923. var v = [];
  48924. for (var i = 0; i < nLen; i++) {
  48925. var n = nodes[i];
  48926. if (!n.fixed) {
  48927. sub(v, n.p, n.pp);
  48928. scaleAndAdd$2(n.p, n.p, v, friction);
  48929. copy(n.pp, n.p);
  48930. }
  48931. }
  48932. friction = friction * 0.992;
  48933. cb && cb(nodes, edges, friction < 0.01);
  48934. }
  48935. };
  48936. }
  48937. /*
  48938. * Licensed to the Apache Software Foundation (ASF) under one
  48939. * or more contributor license agreements. See the NOTICE file
  48940. * distributed with this work for additional information
  48941. * regarding copyright ownership. The ASF licenses this file
  48942. * to you under the Apache License, Version 2.0 (the
  48943. * "License"); you may not use this file except in compliance
  48944. * with the License. You may obtain a copy of the License at
  48945. *
  48946. * http://www.apache.org/licenses/LICENSE-2.0
  48947. *
  48948. * Unless required by applicable law or agreed to in writing,
  48949. * software distributed under the License is distributed on an
  48950. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  48951. * KIND, either express or implied. See the License for the
  48952. * specific language governing permissions and limitations
  48953. * under the License.
  48954. */
  48955. var forceLayout = function (ecModel) {
  48956. ecModel.eachSeriesByType('graph', function (graphSeries) {
  48957. var coordSys = graphSeries.coordinateSystem;
  48958. if (coordSys && coordSys.type !== 'view') {
  48959. return;
  48960. }
  48961. if (graphSeries.get('layout') === 'force') {
  48962. var preservedPoints = graphSeries.preservedPoints || {};
  48963. var graph = graphSeries.getGraph();
  48964. var nodeData = graph.data;
  48965. var edgeData = graph.edgeData;
  48966. var forceModel = graphSeries.getModel('force');
  48967. var initLayout = forceModel.get('initLayout');
  48968. if (graphSeries.preservedPoints) {
  48969. nodeData.each(function (idx) {
  48970. var id = nodeData.getId(idx);
  48971. nodeData.setItemLayout(idx, preservedPoints[id] || [NaN, NaN]);
  48972. });
  48973. }
  48974. else if (!initLayout || initLayout === 'none') {
  48975. simpleLayout$1(graphSeries);
  48976. }
  48977. else if (initLayout === 'circular') {
  48978. circularLayout$1(graphSeries, 'value');
  48979. }
  48980. var nodeDataExtent = nodeData.getDataExtent('value');
  48981. var edgeDataExtent = edgeData.getDataExtent('value');
  48982. // var edgeDataExtent = edgeData.getDataExtent('value');
  48983. var repulsion = forceModel.get('repulsion');
  48984. var edgeLength = forceModel.get('edgeLength');
  48985. if (!isArray(repulsion)) {
  48986. repulsion = [repulsion, repulsion];
  48987. }
  48988. if (!isArray(edgeLength)) {
  48989. edgeLength = [edgeLength, edgeLength];
  48990. }
  48991. // Larger value has smaller length
  48992. edgeLength = [edgeLength[1], edgeLength[0]];
  48993. var nodes = nodeData.mapArray('value', function (value, idx) {
  48994. var point = nodeData.getItemLayout(idx);
  48995. var rep = linearMap(value, nodeDataExtent, repulsion);
  48996. if (isNaN(rep)) {
  48997. rep = (repulsion[0] + repulsion[1]) / 2;
  48998. }
  48999. return {
  49000. w: rep,
  49001. rep: rep,
  49002. fixed: nodeData.getItemModel(idx).get('fixed'),
  49003. p: (!point || isNaN(point[0]) || isNaN(point[1])) ? null : point
  49004. };
  49005. });
  49006. var edges = edgeData.mapArray('value', function (value, idx) {
  49007. var edge = graph.getEdgeByIndex(idx);
  49008. var d = linearMap(value, edgeDataExtent, edgeLength);
  49009. if (isNaN(d)) {
  49010. d = (edgeLength[0] + edgeLength[1]) / 2;
  49011. }
  49012. return {
  49013. n1: nodes[edge.node1.dataIndex],
  49014. n2: nodes[edge.node2.dataIndex],
  49015. d: d,
  49016. curveness: edge.getModel().get('lineStyle.curveness') || 0
  49017. };
  49018. });
  49019. var coordSys = graphSeries.coordinateSystem;
  49020. var rect = coordSys.getBoundingRect();
  49021. var forceInstance = forceLayout$1(nodes, edges, {
  49022. rect: rect,
  49023. gravity: forceModel.get('gravity')
  49024. });
  49025. var oldStep = forceInstance.step;
  49026. forceInstance.step = function (cb) {
  49027. for (var i = 0, l = nodes.length; i < l; i++) {
  49028. if (nodes[i].fixed) {
  49029. // Write back to layout instance
  49030. copy(nodes[i].p, graph.getNodeByIndex(i).getLayout());
  49031. }
  49032. }
  49033. oldStep(function (nodes, edges, stopped) {
  49034. for (var i = 0, l = nodes.length; i < l; i++) {
  49035. if (!nodes[i].fixed) {
  49036. graph.getNodeByIndex(i).setLayout(nodes[i].p);
  49037. }
  49038. preservedPoints[nodeData.getId(i)] = nodes[i].p;
  49039. }
  49040. for (var i = 0, l = edges.length; i < l; i++) {
  49041. var e = edges[i];
  49042. var edge = graph.getEdgeByIndex(i);
  49043. var p1 = e.n1.p;
  49044. var p2 = e.n2.p;
  49045. var points = edge.getLayout();
  49046. points = points ? points.slice() : [];
  49047. points[0] = points[0] || [];
  49048. points[1] = points[1] || [];
  49049. copy(points[0], p1);
  49050. copy(points[1], p2);
  49051. if (+e.curveness) {
  49052. points[2] = [
  49053. (p1[0] + p2[0]) / 2 - (p1[1] - p2[1]) * e.curveness,
  49054. (p1[1] + p2[1]) / 2 - (p2[0] - p1[0]) * e.curveness
  49055. ];
  49056. }
  49057. edge.setLayout(points);
  49058. }
  49059. // Update layout
  49060. cb && cb(stopped);
  49061. });
  49062. };
  49063. graphSeries.forceLayout = forceInstance;
  49064. graphSeries.preservedPoints = preservedPoints;
  49065. // Step to get the layout
  49066. forceInstance.step();
  49067. }
  49068. else {
  49069. // Remove prev injected forceLayout instance
  49070. graphSeries.forceLayout = null;
  49071. }
  49072. });
  49073. };
  49074. /*
  49075. * Licensed to the Apache Software Foundation (ASF) under one
  49076. * or more contributor license agreements. See the NOTICE file
  49077. * distributed with this work for additional information
  49078. * regarding copyright ownership. The ASF licenses this file
  49079. * to you under the Apache License, Version 2.0 (the
  49080. * "License"); you may not use this file except in compliance
  49081. * with the License. You may obtain a copy of the License at
  49082. *
  49083. * http://www.apache.org/licenses/LICENSE-2.0
  49084. *
  49085. * Unless required by applicable law or agreed to in writing,
  49086. * software distributed under the License is distributed on an
  49087. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  49088. * KIND, either express or implied. See the License for the
  49089. * specific language governing permissions and limitations
  49090. * under the License.
  49091. */
  49092. // FIXME Where to create the simple view coordinate system
  49093. function getViewRect$1(seriesModel, api, aspect) {
  49094. var option = seriesModel.getBoxLayoutParams();
  49095. option.aspect = aspect;
  49096. return getLayoutRect(option, {
  49097. width: api.getWidth(),
  49098. height: api.getHeight()
  49099. });
  49100. }
  49101. var createView = function (ecModel, api) {
  49102. var viewList = [];
  49103. ecModel.eachSeriesByType('graph', function (seriesModel) {
  49104. var coordSysType = seriesModel.get('coordinateSystem');
  49105. if (!coordSysType || coordSysType === 'view') {
  49106. var data = seriesModel.getData();
  49107. var positions = data.mapArray(function (idx) {
  49108. var itemModel = data.getItemModel(idx);
  49109. return [+itemModel.get('x'), +itemModel.get('y')];
  49110. });
  49111. var min = [];
  49112. var max = [];
  49113. fromPoints(positions, min, max);
  49114. // If width or height is 0
  49115. if (max[0] - min[0] === 0) {
  49116. max[0] += 1;
  49117. min[0] -= 1;
  49118. }
  49119. if (max[1] - min[1] === 0) {
  49120. max[1] += 1;
  49121. min[1] -= 1;
  49122. }
  49123. var aspect = (max[0] - min[0]) / (max[1] - min[1]);
  49124. // FIXME If get view rect after data processed?
  49125. var viewRect = getViewRect$1(seriesModel, api, aspect);
  49126. // Position may be NaN, use view rect instead
  49127. if (isNaN(aspect)) {
  49128. min = [viewRect.x, viewRect.y];
  49129. max = [viewRect.x + viewRect.width, viewRect.y + viewRect.height];
  49130. }
  49131. var bbWidth = max[0] - min[0];
  49132. var bbHeight = max[1] - min[1];
  49133. var viewWidth = viewRect.width;
  49134. var viewHeight = viewRect.height;
  49135. var viewCoordSys = seriesModel.coordinateSystem = new View();
  49136. viewCoordSys.zoomLimit = seriesModel.get('scaleLimit');
  49137. viewCoordSys.setBoundingRect(
  49138. min[0], min[1], bbWidth, bbHeight
  49139. );
  49140. viewCoordSys.setViewRect(
  49141. viewRect.x, viewRect.y, viewWidth, viewHeight
  49142. );
  49143. // Update roam info
  49144. viewCoordSys.setCenter(seriesModel.get('center'));
  49145. viewCoordSys.setZoom(seriesModel.get('zoom'));
  49146. viewList.push(viewCoordSys);
  49147. }
  49148. });
  49149. return viewList;
  49150. };
  49151. /*
  49152. * Licensed to the Apache Software Foundation (ASF) under one
  49153. * or more contributor license agreements. See the NOTICE file
  49154. * distributed with this work for additional information
  49155. * regarding copyright ownership. The ASF licenses this file
  49156. * to you under the Apache License, Version 2.0 (the
  49157. * "License"); you may not use this file except in compliance
  49158. * with the License. You may obtain a copy of the License at
  49159. *
  49160. * http://www.apache.org/licenses/LICENSE-2.0
  49161. *
  49162. * Unless required by applicable law or agreed to in writing,
  49163. * software distributed under the License is distributed on an
  49164. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  49165. * KIND, either express or implied. See the License for the
  49166. * specific language governing permissions and limitations
  49167. * under the License.
  49168. */
  49169. registerProcessor(categoryFilter);
  49170. registerVisual(visualSymbol('graph', 'circle', null));
  49171. registerVisual(categoryVisual);
  49172. registerVisual(edgeVisual);
  49173. registerLayout(simpleLayout);
  49174. registerLayout(PRIORITY.VISUAL.POST_CHART_LAYOUT, circularLayout);
  49175. registerLayout(forceLayout);
  49176. // Graph view coordinate system
  49177. registerCoordinateSystem('graphView', {
  49178. create: createView
  49179. });
  49180. /*
  49181. * Licensed to the Apache Software Foundation (ASF) under one
  49182. * or more contributor license agreements. See the NOTICE file
  49183. * distributed with this work for additional information
  49184. * regarding copyright ownership. The ASF licenses this file
  49185. * to you under the Apache License, Version 2.0 (the
  49186. * "License"); you may not use this file except in compliance
  49187. * with the License. You may obtain a copy of the License at
  49188. *
  49189. * http://www.apache.org/licenses/LICENSE-2.0
  49190. *
  49191. * Unless required by applicable law or agreed to in writing,
  49192. * software distributed under the License is distributed on an
  49193. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  49194. * KIND, either express or implied. See the License for the
  49195. * specific language governing permissions and limitations
  49196. * under the License.
  49197. */
  49198. var GaugeSeries = SeriesModel.extend({
  49199. type: 'series.gauge',
  49200. getInitialData: function (option, ecModel) {
  49201. var dataOpt = option.data || [];
  49202. if (!isArray(dataOpt)) {
  49203. dataOpt = [dataOpt];
  49204. }
  49205. option.data = dataOpt;
  49206. return createListSimply(this, ['value']);
  49207. },
  49208. defaultOption: {
  49209. zlevel: 0,
  49210. z: 2,
  49211. // 默认全局居中
  49212. center: ['50%', '50%'],
  49213. legendHoverLink: true,
  49214. radius: '75%',
  49215. startAngle: 225,
  49216. endAngle: -45,
  49217. clockwise: true,
  49218. // 最小值
  49219. min: 0,
  49220. // 最大值
  49221. max: 100,
  49222. // 分割段数,默认为10
  49223. splitNumber: 10,
  49224. // 坐标轴线
  49225. axisLine: {
  49226. // 默认显示,属性show控制显示与否
  49227. show: true,
  49228. lineStyle: { // 属性lineStyle控制线条样式
  49229. color: [[0.2, '#91c7ae'], [0.8, '#63869e'], [1, '#c23531']],
  49230. width: 30
  49231. }
  49232. },
  49233. // 分隔线
  49234. splitLine: {
  49235. // 默认显示,属性show控制显示与否
  49236. show: true,
  49237. // 属性length控制线长
  49238. length: 30,
  49239. // 属性lineStyle(详见lineStyle)控制线条样式
  49240. lineStyle: {
  49241. color: '#eee',
  49242. width: 2,
  49243. type: 'solid'
  49244. }
  49245. },
  49246. // 坐标轴小标记
  49247. axisTick: {
  49248. // 属性show控制显示与否,默认不显示
  49249. show: true,
  49250. // 每份split细分多少段
  49251. splitNumber: 5,
  49252. // 属性length控制线长
  49253. length: 8,
  49254. // 属性lineStyle控制线条样式
  49255. lineStyle: {
  49256. color: '#eee',
  49257. width: 1,
  49258. type: 'solid'
  49259. }
  49260. },
  49261. axisLabel: {
  49262. show: true,
  49263. distance: 5,
  49264. // formatter: null,
  49265. color: 'auto'
  49266. },
  49267. pointer: {
  49268. show: true,
  49269. length: '80%',
  49270. width: 8
  49271. },
  49272. itemStyle: {
  49273. color: 'auto'
  49274. },
  49275. title: {
  49276. show: true,
  49277. // x, y,单位px
  49278. offsetCenter: [0, '-40%'],
  49279. // 其余属性默认使用全局文本样式,详见TEXTSTYLE
  49280. color: '#333',
  49281. fontSize: 15
  49282. },
  49283. detail: {
  49284. show: true,
  49285. backgroundColor: 'rgba(0,0,0,0)',
  49286. borderWidth: 0,
  49287. borderColor: '#ccc',
  49288. width: 100,
  49289. height: null, // self-adaption
  49290. padding: [5, 10],
  49291. // x, y,单位px
  49292. offsetCenter: [0, '40%'],
  49293. // formatter: null,
  49294. // 其余属性默认使用全局文本样式,详见TEXTSTYLE
  49295. color: 'auto',
  49296. fontSize: 30
  49297. }
  49298. }
  49299. });
  49300. /*
  49301. * Licensed to the Apache Software Foundation (ASF) under one
  49302. * or more contributor license agreements. See the NOTICE file
  49303. * distributed with this work for additional information
  49304. * regarding copyright ownership. The ASF licenses this file
  49305. * to you under the Apache License, Version 2.0 (the
  49306. * "License"); you may not use this file except in compliance
  49307. * with the License. You may obtain a copy of the License at
  49308. *
  49309. * http://www.apache.org/licenses/LICENSE-2.0
  49310. *
  49311. * Unless required by applicable law or agreed to in writing,
  49312. * software distributed under the License is distributed on an
  49313. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  49314. * KIND, either express or implied. See the License for the
  49315. * specific language governing permissions and limitations
  49316. * under the License.
  49317. */
  49318. var PointerPath = Path.extend({
  49319. type: 'echartsGaugePointer',
  49320. shape: {
  49321. angle: 0,
  49322. width: 10,
  49323. r: 10,
  49324. x: 0,
  49325. y: 0
  49326. },
  49327. buildPath: function (ctx, shape) {
  49328. var mathCos = Math.cos;
  49329. var mathSin = Math.sin;
  49330. var r = shape.r;
  49331. var width = shape.width;
  49332. var angle = shape.angle;
  49333. var x = shape.x - mathCos(angle) * width * (width >= r / 3 ? 1 : 2);
  49334. var y = shape.y - mathSin(angle) * width * (width >= r / 3 ? 1 : 2);
  49335. angle = shape.angle - Math.PI / 2;
  49336. ctx.moveTo(x, y);
  49337. ctx.lineTo(
  49338. shape.x + mathCos(angle) * width,
  49339. shape.y + mathSin(angle) * width
  49340. );
  49341. ctx.lineTo(
  49342. shape.x + mathCos(shape.angle) * r,
  49343. shape.y + mathSin(shape.angle) * r
  49344. );
  49345. ctx.lineTo(
  49346. shape.x - mathCos(angle) * width,
  49347. shape.y - mathSin(angle) * width
  49348. );
  49349. ctx.lineTo(x, y);
  49350. return;
  49351. }
  49352. });
  49353. /*
  49354. * Licensed to the Apache Software Foundation (ASF) under one
  49355. * or more contributor license agreements. See the NOTICE file
  49356. * distributed with this work for additional information
  49357. * regarding copyright ownership. The ASF licenses this file
  49358. * to you under the Apache License, Version 2.0 (the
  49359. * "License"); you may not use this file except in compliance
  49360. * with the License. You may obtain a copy of the License at
  49361. *
  49362. * http://www.apache.org/licenses/LICENSE-2.0
  49363. *
  49364. * Unless required by applicable law or agreed to in writing,
  49365. * software distributed under the License is distributed on an
  49366. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  49367. * KIND, either express or implied. See the License for the
  49368. * specific language governing permissions and limitations
  49369. * under the License.
  49370. */
  49371. function parsePosition(seriesModel, api) {
  49372. var center = seriesModel.get('center');
  49373. var width = api.getWidth();
  49374. var height = api.getHeight();
  49375. var size = Math.min(width, height);
  49376. var cx = parsePercent$1(center[0], api.getWidth());
  49377. var cy = parsePercent$1(center[1], api.getHeight());
  49378. var r = parsePercent$1(seriesModel.get('radius'), size / 2);
  49379. return {
  49380. cx: cx,
  49381. cy: cy,
  49382. r: r
  49383. };
  49384. }
  49385. function formatLabel(label, labelFormatter) {
  49386. if (labelFormatter) {
  49387. if (typeof labelFormatter === 'string') {
  49388. label = labelFormatter.replace('{value}', label != null ? label : '');
  49389. }
  49390. else if (typeof labelFormatter === 'function') {
  49391. label = labelFormatter(label);
  49392. }
  49393. }
  49394. return label;
  49395. }
  49396. var PI2$5 = Math.PI * 2;
  49397. var GaugeView = Chart.extend({
  49398. type: 'gauge',
  49399. render: function (seriesModel, ecModel, api) {
  49400. this.group.removeAll();
  49401. var colorList = seriesModel.get('axisLine.lineStyle.color');
  49402. var posInfo = parsePosition(seriesModel, api);
  49403. this._renderMain(
  49404. seriesModel, ecModel, api, colorList, posInfo
  49405. );
  49406. },
  49407. dispose: function () {},
  49408. _renderMain: function (seriesModel, ecModel, api, colorList, posInfo) {
  49409. var group = this.group;
  49410. var axisLineModel = seriesModel.getModel('axisLine');
  49411. var lineStyleModel = axisLineModel.getModel('lineStyle');
  49412. var clockwise = seriesModel.get('clockwise');
  49413. var startAngle = -seriesModel.get('startAngle') / 180 * Math.PI;
  49414. var endAngle = -seriesModel.get('endAngle') / 180 * Math.PI;
  49415. var angleRangeSpan = (endAngle - startAngle) % PI2$5;
  49416. var prevEndAngle = startAngle;
  49417. var axisLineWidth = lineStyleModel.get('width');
  49418. var showAxis = axisLineModel.get('show');
  49419. for (var i = 0; showAxis && i < colorList.length; i++) {
  49420. // Clamp
  49421. var percent = Math.min(Math.max(colorList[i][0], 0), 1);
  49422. var endAngle = startAngle + angleRangeSpan * percent;
  49423. var sector = new Sector({
  49424. shape: {
  49425. startAngle: prevEndAngle,
  49426. endAngle: endAngle,
  49427. cx: posInfo.cx,
  49428. cy: posInfo.cy,
  49429. clockwise: clockwise,
  49430. r0: posInfo.r - axisLineWidth,
  49431. r: posInfo.r
  49432. },
  49433. silent: true
  49434. });
  49435. sector.setStyle({
  49436. fill: colorList[i][1]
  49437. });
  49438. sector.setStyle(lineStyleModel.getLineStyle(
  49439. // Because we use sector to simulate arc
  49440. // so the properties for stroking are useless
  49441. ['color', 'borderWidth', 'borderColor']
  49442. ));
  49443. group.add(sector);
  49444. prevEndAngle = endAngle;
  49445. }
  49446. var getColor = function (percent) {
  49447. // Less than 0
  49448. if (percent <= 0) {
  49449. return colorList[0][1];
  49450. }
  49451. for (var i = 0; i < colorList.length; i++) {
  49452. if (colorList[i][0] >= percent
  49453. && (i === 0 ? 0 : colorList[i - 1][0]) < percent
  49454. ) {
  49455. return colorList[i][1];
  49456. }
  49457. }
  49458. // More than 1
  49459. return colorList[i - 1][1];
  49460. };
  49461. if (!clockwise) {
  49462. var tmp = startAngle;
  49463. startAngle = endAngle;
  49464. endAngle = tmp;
  49465. }
  49466. this._renderTicks(
  49467. seriesModel, ecModel, api, getColor, posInfo,
  49468. startAngle, endAngle, clockwise
  49469. );
  49470. this._renderPointer(
  49471. seriesModel, ecModel, api, getColor, posInfo,
  49472. startAngle, endAngle, clockwise
  49473. );
  49474. this._renderTitle(
  49475. seriesModel, ecModel, api, getColor, posInfo
  49476. );
  49477. this._renderDetail(
  49478. seriesModel, ecModel, api, getColor, posInfo
  49479. );
  49480. },
  49481. _renderTicks: function (
  49482. seriesModel, ecModel, api, getColor, posInfo,
  49483. startAngle, endAngle, clockwise
  49484. ) {
  49485. var group = this.group;
  49486. var cx = posInfo.cx;
  49487. var cy = posInfo.cy;
  49488. var r = posInfo.r;
  49489. var minVal = +seriesModel.get('min');
  49490. var maxVal = +seriesModel.get('max');
  49491. var splitLineModel = seriesModel.getModel('splitLine');
  49492. var tickModel = seriesModel.getModel('axisTick');
  49493. var labelModel = seriesModel.getModel('axisLabel');
  49494. var splitNumber = seriesModel.get('splitNumber');
  49495. var subSplitNumber = tickModel.get('splitNumber');
  49496. var splitLineLen = parsePercent$1(
  49497. splitLineModel.get('length'), r
  49498. );
  49499. var tickLen = parsePercent$1(
  49500. tickModel.get('length'), r
  49501. );
  49502. var angle = startAngle;
  49503. var step = (endAngle - startAngle) / splitNumber;
  49504. var subStep = step / subSplitNumber;
  49505. var splitLineStyle = splitLineModel.getModel('lineStyle').getLineStyle();
  49506. var tickLineStyle = tickModel.getModel('lineStyle').getLineStyle();
  49507. for (var i = 0; i <= splitNumber; i++) {
  49508. var unitX = Math.cos(angle);
  49509. var unitY = Math.sin(angle);
  49510. // Split line
  49511. if (splitLineModel.get('show')) {
  49512. var splitLine = new Line({
  49513. shape: {
  49514. x1: unitX * r + cx,
  49515. y1: unitY * r + cy,
  49516. x2: unitX * (r - splitLineLen) + cx,
  49517. y2: unitY * (r - splitLineLen) + cy
  49518. },
  49519. style: splitLineStyle,
  49520. silent: true
  49521. });
  49522. if (splitLineStyle.stroke === 'auto') {
  49523. splitLine.setStyle({
  49524. stroke: getColor(i / splitNumber)
  49525. });
  49526. }
  49527. group.add(splitLine);
  49528. }
  49529. // Label
  49530. if (labelModel.get('show')) {
  49531. var label = formatLabel(
  49532. round$1(i / splitNumber * (maxVal - minVal) + minVal),
  49533. labelModel.get('formatter')
  49534. );
  49535. var distance = labelModel.get('distance');
  49536. var autoColor = getColor(i / splitNumber);
  49537. group.add(new Text({
  49538. style: setTextStyle({}, labelModel, {
  49539. text: label,
  49540. x: unitX * (r - splitLineLen - distance) + cx,
  49541. y: unitY * (r - splitLineLen - distance) + cy,
  49542. textVerticalAlign: unitY < -0.4 ? 'top' : (unitY > 0.4 ? 'bottom' : 'middle'),
  49543. textAlign: unitX < -0.4 ? 'left' : (unitX > 0.4 ? 'right' : 'center')
  49544. }, {autoColor: autoColor}),
  49545. silent: true
  49546. }));
  49547. }
  49548. // Axis tick
  49549. if (tickModel.get('show') && i !== splitNumber) {
  49550. for (var j = 0; j <= subSplitNumber; j++) {
  49551. var unitX = Math.cos(angle);
  49552. var unitY = Math.sin(angle);
  49553. var tickLine = new Line({
  49554. shape: {
  49555. x1: unitX * r + cx,
  49556. y1: unitY * r + cy,
  49557. x2: unitX * (r - tickLen) + cx,
  49558. y2: unitY * (r - tickLen) + cy
  49559. },
  49560. silent: true,
  49561. style: tickLineStyle
  49562. });
  49563. if (tickLineStyle.stroke === 'auto') {
  49564. tickLine.setStyle({
  49565. stroke: getColor((i + j / subSplitNumber) / splitNumber)
  49566. });
  49567. }
  49568. group.add(tickLine);
  49569. angle += subStep;
  49570. }
  49571. angle -= subStep;
  49572. }
  49573. else {
  49574. angle += step;
  49575. }
  49576. }
  49577. },
  49578. _renderPointer: function (
  49579. seriesModel, ecModel, api, getColor, posInfo,
  49580. startAngle, endAngle, clockwise
  49581. ) {
  49582. var group = this.group;
  49583. var oldData = this._data;
  49584. if (!seriesModel.get('pointer.show')) {
  49585. // Remove old element
  49586. oldData && oldData.eachItemGraphicEl(function (el) {
  49587. group.remove(el);
  49588. });
  49589. return;
  49590. }
  49591. var valueExtent = [+seriesModel.get('min'), +seriesModel.get('max')];
  49592. var angleExtent = [startAngle, endAngle];
  49593. var data = seriesModel.getData();
  49594. var valueDim = data.mapDimension('value');
  49595. data.diff(oldData)
  49596. .add(function (idx) {
  49597. var pointer = new PointerPath({
  49598. shape: {
  49599. angle: startAngle
  49600. }
  49601. });
  49602. initProps(pointer, {
  49603. shape: {
  49604. angle: linearMap(data.get(valueDim, idx), valueExtent, angleExtent, true)
  49605. }
  49606. }, seriesModel);
  49607. group.add(pointer);
  49608. data.setItemGraphicEl(idx, pointer);
  49609. })
  49610. .update(function (newIdx, oldIdx) {
  49611. var pointer = oldData.getItemGraphicEl(oldIdx);
  49612. updateProps(pointer, {
  49613. shape: {
  49614. angle: linearMap(data.get(valueDim, newIdx), valueExtent, angleExtent, true)
  49615. }
  49616. }, seriesModel);
  49617. group.add(pointer);
  49618. data.setItemGraphicEl(newIdx, pointer);
  49619. })
  49620. .remove(function (idx) {
  49621. var pointer = oldData.getItemGraphicEl(idx);
  49622. group.remove(pointer);
  49623. })
  49624. .execute();
  49625. data.eachItemGraphicEl(function (pointer, idx) {
  49626. var itemModel = data.getItemModel(idx);
  49627. var pointerModel = itemModel.getModel('pointer');
  49628. pointer.setShape({
  49629. x: posInfo.cx,
  49630. y: posInfo.cy,
  49631. width: parsePercent$1(
  49632. pointerModel.get('width'), posInfo.r
  49633. ),
  49634. r: parsePercent$1(pointerModel.get('length'), posInfo.r)
  49635. });
  49636. pointer.useStyle(itemModel.getModel('itemStyle').getItemStyle());
  49637. if (pointer.style.fill === 'auto') {
  49638. pointer.setStyle('fill', getColor(
  49639. linearMap(data.get(valueDim, idx), valueExtent, [0, 1], true)
  49640. ));
  49641. }
  49642. setHoverStyle(
  49643. pointer, itemModel.getModel('emphasis.itemStyle').getItemStyle()
  49644. );
  49645. });
  49646. this._data = data;
  49647. },
  49648. _renderTitle: function (
  49649. seriesModel, ecModel, api, getColor, posInfo
  49650. ) {
  49651. var data = seriesModel.getData();
  49652. var valueDim = data.mapDimension('value');
  49653. var titleModel = seriesModel.getModel('title');
  49654. if (titleModel.get('show')) {
  49655. var offsetCenter = titleModel.get('offsetCenter');
  49656. var x = posInfo.cx + parsePercent$1(offsetCenter[0], posInfo.r);
  49657. var y = posInfo.cy + parsePercent$1(offsetCenter[1], posInfo.r);
  49658. var minVal = +seriesModel.get('min');
  49659. var maxVal = +seriesModel.get('max');
  49660. var value = seriesModel.getData().get(valueDim, 0);
  49661. var autoColor = getColor(
  49662. linearMap(value, [minVal, maxVal], [0, 1], true)
  49663. );
  49664. this.group.add(new Text({
  49665. silent: true,
  49666. style: setTextStyle({}, titleModel, {
  49667. x: x,
  49668. y: y,
  49669. // FIXME First data name ?
  49670. text: data.getName(0),
  49671. textAlign: 'center',
  49672. textVerticalAlign: 'middle'
  49673. }, {autoColor: autoColor, forceRich: true})
  49674. }));
  49675. }
  49676. },
  49677. _renderDetail: function (
  49678. seriesModel, ecModel, api, getColor, posInfo
  49679. ) {
  49680. var detailModel = seriesModel.getModel('detail');
  49681. var minVal = +seriesModel.get('min');
  49682. var maxVal = +seriesModel.get('max');
  49683. if (detailModel.get('show')) {
  49684. var offsetCenter = detailModel.get('offsetCenter');
  49685. var x = posInfo.cx + parsePercent$1(offsetCenter[0], posInfo.r);
  49686. var y = posInfo.cy + parsePercent$1(offsetCenter[1], posInfo.r);
  49687. var width = parsePercent$1(detailModel.get('width'), posInfo.r);
  49688. var height = parsePercent$1(detailModel.get('height'), posInfo.r);
  49689. var data = seriesModel.getData();
  49690. var value = data.get(data.mapDimension('value'), 0);
  49691. var autoColor = getColor(
  49692. linearMap(value, [minVal, maxVal], [0, 1], true)
  49693. );
  49694. this.group.add(new Text({
  49695. silent: true,
  49696. style: setTextStyle({}, detailModel, {
  49697. x: x,
  49698. y: y,
  49699. text: formatLabel(
  49700. // FIXME First data name ?
  49701. value, detailModel.get('formatter')
  49702. ),
  49703. textWidth: isNaN(width) ? null : width,
  49704. textHeight: isNaN(height) ? null : height,
  49705. textAlign: 'center',
  49706. textVerticalAlign: 'middle'
  49707. }, {autoColor: autoColor, forceRich: true})
  49708. }));
  49709. }
  49710. }
  49711. });
  49712. /*
  49713. * Licensed to the Apache Software Foundation (ASF) under one
  49714. * or more contributor license agreements. See the NOTICE file
  49715. * distributed with this work for additional information
  49716. * regarding copyright ownership. The ASF licenses this file
  49717. * to you under the Apache License, Version 2.0 (the
  49718. * "License"); you may not use this file except in compliance
  49719. * with the License. You may obtain a copy of the License at
  49720. *
  49721. * http://www.apache.org/licenses/LICENSE-2.0
  49722. *
  49723. * Unless required by applicable law or agreed to in writing,
  49724. * software distributed under the License is distributed on an
  49725. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  49726. * KIND, either express or implied. See the License for the
  49727. * specific language governing permissions and limitations
  49728. * under the License.
  49729. */
  49730. /*
  49731. * Licensed to the Apache Software Foundation (ASF) under one
  49732. * or more contributor license agreements. See the NOTICE file
  49733. * distributed with this work for additional information
  49734. * regarding copyright ownership. The ASF licenses this file
  49735. * to you under the Apache License, Version 2.0 (the
  49736. * "License"); you may not use this file except in compliance
  49737. * with the License. You may obtain a copy of the License at
  49738. *
  49739. * http://www.apache.org/licenses/LICENSE-2.0
  49740. *
  49741. * Unless required by applicable law or agreed to in writing,
  49742. * software distributed under the License is distributed on an
  49743. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  49744. * KIND, either express or implied. See the License for the
  49745. * specific language governing permissions and limitations
  49746. * under the License.
  49747. */
  49748. var FunnelSeries = extendSeriesModel({
  49749. type: 'series.funnel',
  49750. init: function (option) {
  49751. FunnelSeries.superApply(this, 'init', arguments);
  49752. // Enable legend selection for each data item
  49753. // Use a function instead of direct access because data reference may changed
  49754. this.legendDataProvider = function () {
  49755. return this.getRawData();
  49756. };
  49757. // Extend labelLine emphasis
  49758. this._defaultLabelLine(option);
  49759. },
  49760. getInitialData: function (option, ecModel) {
  49761. return createListSimply(this, ['value']);
  49762. },
  49763. _defaultLabelLine: function (option) {
  49764. // Extend labelLine emphasis
  49765. defaultEmphasis(option, 'labelLine', ['show']);
  49766. var labelLineNormalOpt = option.labelLine;
  49767. var labelLineEmphasisOpt = option.emphasis.labelLine;
  49768. // Not show label line if `label.normal.show = false`
  49769. labelLineNormalOpt.show = labelLineNormalOpt.show
  49770. && option.label.show;
  49771. labelLineEmphasisOpt.show = labelLineEmphasisOpt.show
  49772. && option.emphasis.label.show;
  49773. },
  49774. // Overwrite
  49775. getDataParams: function (dataIndex) {
  49776. var data = this.getData();
  49777. var params = FunnelSeries.superCall(this, 'getDataParams', dataIndex);
  49778. var valueDim = data.mapDimension('value');
  49779. var sum = data.getSum(valueDim);
  49780. // Percent is 0 if sum is 0
  49781. params.percent = !sum ? 0 : +(data.get(valueDim, dataIndex) / sum * 100).toFixed(2);
  49782. params.$vars.push('percent');
  49783. return params;
  49784. },
  49785. defaultOption: {
  49786. zlevel: 0, // 一级层叠
  49787. z: 2, // 二级层叠
  49788. legendHoverLink: true,
  49789. left: 80,
  49790. top: 60,
  49791. right: 80,
  49792. bottom: 60,
  49793. // width: {totalWidth} - left - right,
  49794. // height: {totalHeight} - top - bottom,
  49795. // 默认取数据最小最大值
  49796. // min: 0,
  49797. // max: 100,
  49798. minSize: '0%',
  49799. maxSize: '100%',
  49800. sort: 'descending', // 'ascending', 'descending'
  49801. gap: 0,
  49802. funnelAlign: 'center',
  49803. label: {
  49804. show: true,
  49805. position: 'outer'
  49806. // formatter: 标签文本格式器,同Tooltip.formatter,不支持异步回调
  49807. },
  49808. labelLine: {
  49809. show: true,
  49810. length: 20,
  49811. lineStyle: {
  49812. // color: 各异,
  49813. width: 1,
  49814. type: 'solid'
  49815. }
  49816. },
  49817. itemStyle: {
  49818. // color: 各异,
  49819. borderColor: '#fff',
  49820. borderWidth: 1
  49821. },
  49822. emphasis: {
  49823. label: {
  49824. show: true
  49825. }
  49826. }
  49827. }
  49828. });
  49829. /*
  49830. * Licensed to the Apache Software Foundation (ASF) under one
  49831. * or more contributor license agreements. See the NOTICE file
  49832. * distributed with this work for additional information
  49833. * regarding copyright ownership. The ASF licenses this file
  49834. * to you under the Apache License, Version 2.0 (the
  49835. * "License"); you may not use this file except in compliance
  49836. * with the License. You may obtain a copy of the License at
  49837. *
  49838. * http://www.apache.org/licenses/LICENSE-2.0
  49839. *
  49840. * Unless required by applicable law or agreed to in writing,
  49841. * software distributed under the License is distributed on an
  49842. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  49843. * KIND, either express or implied. See the License for the
  49844. * specific language governing permissions and limitations
  49845. * under the License.
  49846. */
  49847. /**
  49848. * Piece of pie including Sector, Label, LabelLine
  49849. * @constructor
  49850. * @extends {module:zrender/graphic/Group}
  49851. */
  49852. function FunnelPiece(data, idx) {
  49853. Group.call(this);
  49854. var polygon = new Polygon();
  49855. var labelLine = new Polyline();
  49856. var text = new Text();
  49857. this.add(polygon);
  49858. this.add(labelLine);
  49859. this.add(text);
  49860. this.highDownOnUpdate = function (fromState, toState) {
  49861. if (toState === 'emphasis') {
  49862. labelLine.ignore = labelLine.hoverIgnore;
  49863. text.ignore = text.hoverIgnore;
  49864. }
  49865. else {
  49866. labelLine.ignore = labelLine.normalIgnore;
  49867. text.ignore = text.normalIgnore;
  49868. }
  49869. };
  49870. this.updateData(data, idx, true);
  49871. }
  49872. var funnelPieceProto = FunnelPiece.prototype;
  49873. var opacityAccessPath = ['itemStyle', 'opacity'];
  49874. funnelPieceProto.updateData = function (data, idx, firstCreate) {
  49875. var polygon = this.childAt(0);
  49876. var seriesModel = data.hostModel;
  49877. var itemModel = data.getItemModel(idx);
  49878. var layout = data.getItemLayout(idx);
  49879. var opacity = data.getItemModel(idx).get(opacityAccessPath);
  49880. opacity = opacity == null ? 1 : opacity;
  49881. // Reset style
  49882. polygon.useStyle({});
  49883. if (firstCreate) {
  49884. polygon.setShape({
  49885. points: layout.points
  49886. });
  49887. polygon.setStyle({opacity: 0});
  49888. initProps(polygon, {
  49889. style: {
  49890. opacity: opacity
  49891. }
  49892. }, seriesModel, idx);
  49893. }
  49894. else {
  49895. updateProps(polygon, {
  49896. style: {
  49897. opacity: opacity
  49898. },
  49899. shape: {
  49900. points: layout.points
  49901. }
  49902. }, seriesModel, idx);
  49903. }
  49904. // Update common style
  49905. var itemStyleModel = itemModel.getModel('itemStyle');
  49906. var visualColor = data.getItemVisual(idx, 'color');
  49907. polygon.setStyle(
  49908. defaults(
  49909. {
  49910. lineJoin: 'round',
  49911. fill: visualColor
  49912. },
  49913. itemStyleModel.getItemStyle(['opacity'])
  49914. )
  49915. );
  49916. polygon.hoverStyle = itemStyleModel.getModel('emphasis').getItemStyle();
  49917. this._updateLabel(data, idx);
  49918. setHoverStyle(this);
  49919. };
  49920. funnelPieceProto._updateLabel = function (data, idx) {
  49921. var labelLine = this.childAt(1);
  49922. var labelText = this.childAt(2);
  49923. var seriesModel = data.hostModel;
  49924. var itemModel = data.getItemModel(idx);
  49925. var layout = data.getItemLayout(idx);
  49926. var labelLayout = layout.label;
  49927. var visualColor = data.getItemVisual(idx, 'color');
  49928. updateProps(labelLine, {
  49929. shape: {
  49930. points: labelLayout.linePoints || labelLayout.linePoints
  49931. }
  49932. }, seriesModel, idx);
  49933. updateProps(labelText, {
  49934. style: {
  49935. x: labelLayout.x,
  49936. y: labelLayout.y
  49937. }
  49938. }, seriesModel, idx);
  49939. labelText.attr({
  49940. rotation: labelLayout.rotation,
  49941. origin: [labelLayout.x, labelLayout.y],
  49942. z2: 10
  49943. });
  49944. var labelModel = itemModel.getModel('label');
  49945. var labelHoverModel = itemModel.getModel('emphasis.label');
  49946. var labelLineModel = itemModel.getModel('labelLine');
  49947. var labelLineHoverModel = itemModel.getModel('emphasis.labelLine');
  49948. var visualColor = data.getItemVisual(idx, 'color');
  49949. setLabelStyle(
  49950. labelText.style, labelText.hoverStyle = {}, labelModel, labelHoverModel,
  49951. {
  49952. labelFetcher: data.hostModel,
  49953. labelDataIndex: idx,
  49954. defaultText: data.getName(idx),
  49955. autoColor: visualColor,
  49956. useInsideStyle: !!labelLayout.inside
  49957. },
  49958. {
  49959. textAlign: labelLayout.textAlign,
  49960. textVerticalAlign: labelLayout.verticalAlign
  49961. }
  49962. );
  49963. labelText.ignore = labelText.normalIgnore = !labelModel.get('show');
  49964. labelText.hoverIgnore = !labelHoverModel.get('show');
  49965. labelLine.ignore = labelLine.normalIgnore = !labelLineModel.get('show');
  49966. labelLine.hoverIgnore = !labelLineHoverModel.get('show');
  49967. // Default use item visual color
  49968. labelLine.setStyle({
  49969. stroke: visualColor
  49970. });
  49971. labelLine.setStyle(labelLineModel.getModel('lineStyle').getLineStyle());
  49972. labelLine.hoverStyle = labelLineHoverModel.getModel('lineStyle').getLineStyle();
  49973. };
  49974. inherits(FunnelPiece, Group);
  49975. var FunnelView = Chart.extend({
  49976. type: 'funnel',
  49977. render: function (seriesModel, ecModel, api) {
  49978. var data = seriesModel.getData();
  49979. var oldData = this._data;
  49980. var group = this.group;
  49981. data.diff(oldData)
  49982. .add(function (idx) {
  49983. var funnelPiece = new FunnelPiece(data, idx);
  49984. data.setItemGraphicEl(idx, funnelPiece);
  49985. group.add(funnelPiece);
  49986. })
  49987. .update(function (newIdx, oldIdx) {
  49988. var piePiece = oldData.getItemGraphicEl(oldIdx);
  49989. piePiece.updateData(data, newIdx);
  49990. group.add(piePiece);
  49991. data.setItemGraphicEl(newIdx, piePiece);
  49992. })
  49993. .remove(function (idx) {
  49994. var piePiece = oldData.getItemGraphicEl(idx);
  49995. group.remove(piePiece);
  49996. })
  49997. .execute();
  49998. this._data = data;
  49999. },
  50000. remove: function () {
  50001. this.group.removeAll();
  50002. this._data = null;
  50003. },
  50004. dispose: function () {}
  50005. });
  50006. /*
  50007. * Licensed to the Apache Software Foundation (ASF) under one
  50008. * or more contributor license agreements. See the NOTICE file
  50009. * distributed with this work for additional information
  50010. * regarding copyright ownership. The ASF licenses this file
  50011. * to you under the Apache License, Version 2.0 (the
  50012. * "License"); you may not use this file except in compliance
  50013. * with the License. You may obtain a copy of the License at
  50014. *
  50015. * http://www.apache.org/licenses/LICENSE-2.0
  50016. *
  50017. * Unless required by applicable law or agreed to in writing,
  50018. * software distributed under the License is distributed on an
  50019. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  50020. * KIND, either express or implied. See the License for the
  50021. * specific language governing permissions and limitations
  50022. * under the License.
  50023. */
  50024. function getViewRect$2(seriesModel, api) {
  50025. return getLayoutRect(
  50026. seriesModel.getBoxLayoutParams(), {
  50027. width: api.getWidth(),
  50028. height: api.getHeight()
  50029. }
  50030. );
  50031. }
  50032. function getSortedIndices(data, sort) {
  50033. var valueDim = data.mapDimension('value');
  50034. var valueArr = data.mapArray(valueDim, function (val) {
  50035. return val;
  50036. });
  50037. var indices = [];
  50038. var isAscending = sort === 'ascending';
  50039. for (var i = 0, len = data.count(); i < len; i++) {
  50040. indices[i] = i;
  50041. }
  50042. // Add custom sortable function & none sortable opetion by "options.sort"
  50043. if (typeof sort === 'function') {
  50044. indices.sort(sort);
  50045. }
  50046. else if (sort !== 'none') {
  50047. indices.sort(function (a, b) {
  50048. return isAscending ? valueArr[a] - valueArr[b] : valueArr[b] - valueArr[a];
  50049. });
  50050. }
  50051. return indices;
  50052. }
  50053. function labelLayout$1(data) {
  50054. data.each(function (idx) {
  50055. var itemModel = data.getItemModel(idx);
  50056. var labelModel = itemModel.getModel('label');
  50057. var labelPosition = labelModel.get('position');
  50058. var labelLineModel = itemModel.getModel('labelLine');
  50059. var layout = data.getItemLayout(idx);
  50060. var points = layout.points;
  50061. var isLabelInside = labelPosition === 'inner'
  50062. || labelPosition === 'inside' || labelPosition === 'center'
  50063. || labelPosition === 'insideLeft' || labelPosition === 'insideRight';
  50064. var textAlign;
  50065. var textX;
  50066. var textY;
  50067. var linePoints;
  50068. if (isLabelInside) {
  50069. if (labelPosition === 'insideLeft') {
  50070. textX = (points[0][0] + points[3][0]) / 2 + 5;
  50071. textY = (points[0][1] + points[3][1]) / 2;
  50072. textAlign = 'left';
  50073. }
  50074. else if (labelPosition === 'insideRight') {
  50075. textX = (points[1][0] + points[2][0]) / 2 - 5;
  50076. textY = (points[1][1] + points[2][1]) / 2;
  50077. textAlign = 'right';
  50078. }
  50079. else {
  50080. textX = (points[0][0] + points[1][0] + points[2][0] + points[3][0]) / 4;
  50081. textY = (points[0][1] + points[1][1] + points[2][1] + points[3][1]) / 4;
  50082. textAlign = 'center';
  50083. }
  50084. linePoints = [
  50085. [textX, textY], [textX, textY]
  50086. ];
  50087. }
  50088. else {
  50089. var x1;
  50090. var y1;
  50091. var x2;
  50092. var labelLineLen = labelLineModel.get('length');
  50093. if (labelPosition === 'left') {
  50094. // Left side
  50095. x1 = (points[3][0] + points[0][0]) / 2;
  50096. y1 = (points[3][1] + points[0][1]) / 2;
  50097. x2 = x1 - labelLineLen;
  50098. textX = x2 - 5;
  50099. textAlign = 'right';
  50100. }
  50101. else if (labelPosition === 'right') {
  50102. // Right side
  50103. x1 = (points[1][0] + points[2][0]) / 2;
  50104. y1 = (points[1][1] + points[2][1]) / 2;
  50105. x2 = x1 + labelLineLen;
  50106. textX = x2 + 5;
  50107. textAlign = 'left';
  50108. }
  50109. else if (labelPosition === 'rightTop') {
  50110. // RightTop side
  50111. x1 = points[1][0];
  50112. y1 = points[1][1];
  50113. x2 = x1 + labelLineLen;
  50114. textX = x2 + 5;
  50115. textAlign = 'top';
  50116. }
  50117. else if (labelPosition === 'rightBottom') {
  50118. // RightBottom side
  50119. x1 = points[2][0];
  50120. y1 = points[2][1];
  50121. x2 = x1 + labelLineLen;
  50122. textX = x2 + 5;
  50123. textAlign = 'bottom';
  50124. }
  50125. else if (labelPosition === 'leftTop') {
  50126. // LeftTop side
  50127. x1 = points[0][0];
  50128. y1 = points[1][1];
  50129. x2 = x1 - labelLineLen;
  50130. textX = x2 - 5;
  50131. textAlign = 'right';
  50132. }
  50133. else if (labelPosition === 'leftBottom') {
  50134. // LeftBottom side
  50135. x1 = points[3][0];
  50136. y1 = points[2][1];
  50137. x2 = x1 - labelLineLen;
  50138. textX = x2 - 5;
  50139. textAlign = 'right';
  50140. }
  50141. else {
  50142. // Right side
  50143. x1 = (points[1][0] + points[2][0]) / 2;
  50144. y1 = (points[1][1] + points[2][1]) / 2;
  50145. x2 = x1 + labelLineLen;
  50146. textX = x2 + 5;
  50147. textAlign = 'left';
  50148. }
  50149. var y2 = y1;
  50150. linePoints = [[x1, y1], [x2, y2]];
  50151. textY = y2;
  50152. }
  50153. layout.label = {
  50154. linePoints: linePoints,
  50155. x: textX,
  50156. y: textY,
  50157. verticalAlign: 'middle',
  50158. textAlign: textAlign,
  50159. inside: isLabelInside
  50160. };
  50161. });
  50162. }
  50163. var funnelLayout = function (ecModel, api, payload) {
  50164. ecModel.eachSeriesByType('funnel', function (seriesModel) {
  50165. var data = seriesModel.getData();
  50166. var valueDim = data.mapDimension('value');
  50167. var sort = seriesModel.get('sort');
  50168. var viewRect = getViewRect$2(seriesModel, api);
  50169. var indices = getSortedIndices(data, sort);
  50170. var sizeExtent = [
  50171. parsePercent$1(seriesModel.get('minSize'), viewRect.width),
  50172. parsePercent$1(seriesModel.get('maxSize'), viewRect.width)
  50173. ];
  50174. var dataExtent = data.getDataExtent(valueDim);
  50175. var min = seriesModel.get('min');
  50176. var max = seriesModel.get('max');
  50177. if (min == null) {
  50178. min = Math.min(dataExtent[0], 0);
  50179. }
  50180. if (max == null) {
  50181. max = dataExtent[1];
  50182. }
  50183. var funnelAlign = seriesModel.get('funnelAlign');
  50184. var gap = seriesModel.get('gap');
  50185. var itemHeight = (viewRect.height - gap * (data.count() - 1)) / data.count();
  50186. var y = viewRect.y;
  50187. var getLinePoints = function (idx, offY) {
  50188. // End point index is data.count() and we assign it 0
  50189. var val = data.get(valueDim, idx) || 0;
  50190. var itemWidth = linearMap(val, [min, max], sizeExtent, true);
  50191. var x0;
  50192. switch (funnelAlign) {
  50193. case 'left':
  50194. x0 = viewRect.x;
  50195. break;
  50196. case 'center':
  50197. x0 = viewRect.x + (viewRect.width - itemWidth) / 2;
  50198. break;
  50199. case 'right':
  50200. x0 = viewRect.x + viewRect.width - itemWidth;
  50201. break;
  50202. }
  50203. return [
  50204. [x0, offY],
  50205. [x0 + itemWidth, offY]
  50206. ];
  50207. };
  50208. if (sort === 'ascending') {
  50209. // From bottom to top
  50210. itemHeight = -itemHeight;
  50211. gap = -gap;
  50212. y += viewRect.height;
  50213. indices = indices.reverse();
  50214. }
  50215. for (var i = 0; i < indices.length; i++) {
  50216. var idx = indices[i];
  50217. var nextIdx = indices[i + 1];
  50218. var itemModel = data.getItemModel(idx);
  50219. var height = itemModel.get('itemStyle.height');
  50220. if (height == null) {
  50221. height = itemHeight;
  50222. }
  50223. else {
  50224. height = parsePercent$1(height, viewRect.height);
  50225. if (sort === 'ascending') {
  50226. height = -height;
  50227. }
  50228. }
  50229. var start = getLinePoints(idx, y);
  50230. var end = getLinePoints(nextIdx, y + height);
  50231. y += height + gap;
  50232. data.setItemLayout(idx, {
  50233. points: start.concat(end.slice().reverse())
  50234. });
  50235. }
  50236. labelLayout$1(data);
  50237. });
  50238. };
  50239. /*
  50240. * Licensed to the Apache Software Foundation (ASF) under one
  50241. * or more contributor license agreements. See the NOTICE file
  50242. * distributed with this work for additional information
  50243. * regarding copyright ownership. The ASF licenses this file
  50244. * to you under the Apache License, Version 2.0 (the
  50245. * "License"); you may not use this file except in compliance
  50246. * with the License. You may obtain a copy of the License at
  50247. *
  50248. * http://www.apache.org/licenses/LICENSE-2.0
  50249. *
  50250. * Unless required by applicable law or agreed to in writing,
  50251. * software distributed under the License is distributed on an
  50252. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  50253. * KIND, either express or implied. See the License for the
  50254. * specific language governing permissions and limitations
  50255. * under the License.
  50256. */
  50257. registerVisual(dataColor('funnel'));
  50258. registerLayout(funnelLayout);
  50259. registerProcessor(dataFilter('funnel'));
  50260. /*
  50261. * Licensed to the Apache Software Foundation (ASF) under one
  50262. * or more contributor license agreements. See the NOTICE file
  50263. * distributed with this work for additional information
  50264. * regarding copyright ownership. The ASF licenses this file
  50265. * to you under the Apache License, Version 2.0 (the
  50266. * "License"); you may not use this file except in compliance
  50267. * with the License. You may obtain a copy of the License at
  50268. *
  50269. * http://www.apache.org/licenses/LICENSE-2.0
  50270. *
  50271. * Unless required by applicable law or agreed to in writing,
  50272. * software distributed under the License is distributed on an
  50273. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  50274. * KIND, either express or implied. See the License for the
  50275. * specific language governing permissions and limitations
  50276. * under the License.
  50277. */
  50278. var parallelPreprocessor = function (option) {
  50279. createParallelIfNeeded(option);
  50280. mergeAxisOptionFromParallel(option);
  50281. };
  50282. /**
  50283. * Create a parallel coordinate if not exists.
  50284. * @inner
  50285. */
  50286. function createParallelIfNeeded(option) {
  50287. if (option.parallel) {
  50288. return;
  50289. }
  50290. var hasParallelSeries = false;
  50291. each$1(option.series, function (seriesOpt) {
  50292. if (seriesOpt && seriesOpt.type === 'parallel') {
  50293. hasParallelSeries = true;
  50294. }
  50295. });
  50296. if (hasParallelSeries) {
  50297. option.parallel = [{}];
  50298. }
  50299. }
  50300. /**
  50301. * Merge aixs definition from parallel option (if exists) to axis option.
  50302. * @inner
  50303. */
  50304. function mergeAxisOptionFromParallel(option) {
  50305. var axes = normalizeToArray(option.parallelAxis);
  50306. each$1(axes, function (axisOption) {
  50307. if (!isObject$1(axisOption)) {
  50308. return;
  50309. }
  50310. var parallelIndex = axisOption.parallelIndex || 0;
  50311. var parallelOption = normalizeToArray(option.parallel)[parallelIndex];
  50312. if (parallelOption && parallelOption.parallelAxisDefault) {
  50313. merge(axisOption, parallelOption.parallelAxisDefault, false);
  50314. }
  50315. });
  50316. }
  50317. /*
  50318. * Licensed to the Apache Software Foundation (ASF) under one
  50319. * or more contributor license agreements. See the NOTICE file
  50320. * distributed with this work for additional information
  50321. * regarding copyright ownership. The ASF licenses this file
  50322. * to you under the Apache License, Version 2.0 (the
  50323. * "License"); you may not use this file except in compliance
  50324. * with the License. You may obtain a copy of the License at
  50325. *
  50326. * http://www.apache.org/licenses/LICENSE-2.0
  50327. *
  50328. * Unless required by applicable law or agreed to in writing,
  50329. * software distributed under the License is distributed on an
  50330. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  50331. * KIND, either express or implied. See the License for the
  50332. * specific language governing permissions and limitations
  50333. * under the License.
  50334. */
  50335. /**
  50336. * @constructor module:echarts/coord/parallel/ParallelAxis
  50337. * @extends {module:echarts/coord/Axis}
  50338. * @param {string} dim
  50339. * @param {*} scale
  50340. * @param {Array.<number>} coordExtent
  50341. * @param {string} axisType
  50342. */
  50343. var ParallelAxis = function (dim, scale, coordExtent, axisType, axisIndex) {
  50344. Axis.call(this, dim, scale, coordExtent);
  50345. /**
  50346. * Axis type
  50347. * - 'category'
  50348. * - 'value'
  50349. * - 'time'
  50350. * - 'log'
  50351. * @type {string}
  50352. */
  50353. this.type = axisType || 'value';
  50354. /**
  50355. * @type {number}
  50356. * @readOnly
  50357. */
  50358. this.axisIndex = axisIndex;
  50359. };
  50360. ParallelAxis.prototype = {
  50361. constructor: ParallelAxis,
  50362. /**
  50363. * Axis model
  50364. * @param {module:echarts/coord/parallel/AxisModel}
  50365. */
  50366. model: null,
  50367. /**
  50368. * @override
  50369. */
  50370. isHorizontal: function () {
  50371. return this.coordinateSystem.getModel().get('layout') !== 'horizontal';
  50372. }
  50373. };
  50374. inherits(ParallelAxis, Axis);
  50375. /*
  50376. * Licensed to the Apache Software Foundation (ASF) under one
  50377. * or more contributor license agreements. See the NOTICE file
  50378. * distributed with this work for additional information
  50379. * regarding copyright ownership. The ASF licenses this file
  50380. * to you under the Apache License, Version 2.0 (the
  50381. * "License"); you may not use this file except in compliance
  50382. * with the License. You may obtain a copy of the License at
  50383. *
  50384. * http://www.apache.org/licenses/LICENSE-2.0
  50385. *
  50386. * Unless required by applicable law or agreed to in writing,
  50387. * software distributed under the License is distributed on an
  50388. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  50389. * KIND, either express or implied. See the License for the
  50390. * specific language governing permissions and limitations
  50391. * under the License.
  50392. */
  50393. /**
  50394. * Calculate slider move result.
  50395. * Usage:
  50396. * (1) If both handle0 and handle1 are needed to be moved, set minSpan the same as
  50397. * maxSpan and the same as `Math.abs(handleEnd[1] - handleEnds[0])`.
  50398. * (2) If handle0 is forbidden to cross handle1, set minSpan as `0`.
  50399. *
  50400. * @param {number} delta Move length.
  50401. * @param {Array.<number>} handleEnds handleEnds[0] can be bigger then handleEnds[1].
  50402. * handleEnds will be modified in this method.
  50403. * @param {Array.<number>} extent handleEnds is restricted by extent.
  50404. * extent[0] should less or equals than extent[1].
  50405. * @param {number|string} handleIndex Can be 'all', means that both move the two handleEnds.
  50406. * @param {number} [minSpan] The range of dataZoom can not be smaller than that.
  50407. * If not set, handle0 and cross handle1. If set as a non-negative
  50408. * number (including `0`), handles will push each other when reaching
  50409. * the minSpan.
  50410. * @param {number} [maxSpan] The range of dataZoom can not be larger than that.
  50411. * @return {Array.<number>} The input handleEnds.
  50412. */
  50413. var sliderMove = function (delta, handleEnds, extent, handleIndex, minSpan, maxSpan) {
  50414. delta = delta || 0;
  50415. var extentSpan = extent[1] - extent[0];
  50416. // Notice maxSpan and minSpan can be null/undefined.
  50417. if (minSpan != null) {
  50418. minSpan = restrict$1(minSpan, [0, extentSpan]);
  50419. }
  50420. if (maxSpan != null) {
  50421. maxSpan = Math.max(maxSpan, minSpan != null ? minSpan : 0);
  50422. }
  50423. if (handleIndex === 'all') {
  50424. var handleSpan = Math.abs(handleEnds[1] - handleEnds[0]);
  50425. handleSpan = restrict$1(handleSpan, [0, extentSpan]);
  50426. minSpan = maxSpan = restrict$1(handleSpan, [minSpan, maxSpan]);
  50427. handleIndex = 0;
  50428. }
  50429. handleEnds[0] = restrict$1(handleEnds[0], extent);
  50430. handleEnds[1] = restrict$1(handleEnds[1], extent);
  50431. var originalDistSign = getSpanSign(handleEnds, handleIndex);
  50432. handleEnds[handleIndex] += delta;
  50433. // Restrict in extent.
  50434. var extentMinSpan = minSpan || 0;
  50435. var realExtent = extent.slice();
  50436. originalDistSign.sign < 0 ? (realExtent[0] += extentMinSpan) : (realExtent[1] -= extentMinSpan);
  50437. handleEnds[handleIndex] = restrict$1(handleEnds[handleIndex], realExtent);
  50438. // Expand span.
  50439. var currDistSign = getSpanSign(handleEnds, handleIndex);
  50440. if (minSpan != null && (
  50441. currDistSign.sign !== originalDistSign.sign || currDistSign.span < minSpan
  50442. )) {
  50443. // If minSpan exists, 'cross' is forbidden.
  50444. handleEnds[1 - handleIndex] = handleEnds[handleIndex] + originalDistSign.sign * minSpan;
  50445. }
  50446. // Shrink span.
  50447. var currDistSign = getSpanSign(handleEnds, handleIndex);
  50448. if (maxSpan != null && currDistSign.span > maxSpan) {
  50449. handleEnds[1 - handleIndex] = handleEnds[handleIndex] + currDistSign.sign * maxSpan;
  50450. }
  50451. return handleEnds;
  50452. };
  50453. function getSpanSign(handleEnds, handleIndex) {
  50454. var dist = handleEnds[handleIndex] - handleEnds[1 - handleIndex];
  50455. // If `handleEnds[0] === handleEnds[1]`, always believe that handleEnd[0]
  50456. // is at left of handleEnds[1] for non-cross case.
  50457. return {span: Math.abs(dist), sign: dist > 0 ? -1 : dist < 0 ? 1 : handleIndex ? -1 : 1};
  50458. }
  50459. function restrict$1(value, extend) {
  50460. return Math.min(
  50461. extend[1] != null ? extend[1] : Infinity,
  50462. Math.max(extend[0] != null ? extend[0] : -Infinity, value)
  50463. );
  50464. }
  50465. /*
  50466. * Licensed to the Apache Software Foundation (ASF) under one
  50467. * or more contributor license agreements. See the NOTICE file
  50468. * distributed with this work for additional information
  50469. * regarding copyright ownership. The ASF licenses this file
  50470. * to you under the Apache License, Version 2.0 (the
  50471. * "License"); you may not use this file except in compliance
  50472. * with the License. You may obtain a copy of the License at
  50473. *
  50474. * http://www.apache.org/licenses/LICENSE-2.0
  50475. *
  50476. * Unless required by applicable law or agreed to in writing,
  50477. * software distributed under the License is distributed on an
  50478. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  50479. * KIND, either express or implied. See the License for the
  50480. * specific language governing permissions and limitations
  50481. * under the License.
  50482. */
  50483. /**
  50484. * Parallel Coordinates
  50485. * <https://en.wikipedia.org/wiki/Parallel_coordinates>
  50486. */
  50487. var each$11 = each$1;
  50488. var mathMin$5 = Math.min;
  50489. var mathMax$5 = Math.max;
  50490. var mathFloor$2 = Math.floor;
  50491. var mathCeil$2 = Math.ceil;
  50492. var round$2 = round$1;
  50493. var PI$4 = Math.PI;
  50494. function Parallel(parallelModel, ecModel, api) {
  50495. /**
  50496. * key: dimension
  50497. * @type {Object.<string, module:echarts/coord/parallel/Axis>}
  50498. * @private
  50499. */
  50500. this._axesMap = createHashMap();
  50501. /**
  50502. * key: dimension
  50503. * value: {position: [], rotation, }
  50504. * @type {Object.<string, Object>}
  50505. * @private
  50506. */
  50507. this._axesLayout = {};
  50508. /**
  50509. * Always follow axis order.
  50510. * @type {Array.<string>}
  50511. * @readOnly
  50512. */
  50513. this.dimensions = parallelModel.dimensions;
  50514. /**
  50515. * @type {module:zrender/core/BoundingRect}
  50516. */
  50517. this._rect;
  50518. /**
  50519. * @type {module:echarts/coord/parallel/ParallelModel}
  50520. */
  50521. this._model = parallelModel;
  50522. this._init(parallelModel, ecModel, api);
  50523. }
  50524. Parallel.prototype = {
  50525. type: 'parallel',
  50526. constructor: Parallel,
  50527. /**
  50528. * Initialize cartesian coordinate systems
  50529. * @private
  50530. */
  50531. _init: function (parallelModel, ecModel, api) {
  50532. var dimensions = parallelModel.dimensions;
  50533. var parallelAxisIndex = parallelModel.parallelAxisIndex;
  50534. each$11(dimensions, function (dim, idx) {
  50535. var axisIndex = parallelAxisIndex[idx];
  50536. var axisModel = ecModel.getComponent('parallelAxis', axisIndex);
  50537. var axis = this._axesMap.set(dim, new ParallelAxis(
  50538. dim,
  50539. createScaleByModel(axisModel),
  50540. [0, 0],
  50541. axisModel.get('type'),
  50542. axisIndex
  50543. ));
  50544. var isCategory = axis.type === 'category';
  50545. axis.onBand = isCategory && axisModel.get('boundaryGap');
  50546. axis.inverse = axisModel.get('inverse');
  50547. // Injection
  50548. axisModel.axis = axis;
  50549. axis.model = axisModel;
  50550. axis.coordinateSystem = axisModel.coordinateSystem = this;
  50551. }, this);
  50552. },
  50553. /**
  50554. * Update axis scale after data processed
  50555. * @param {module:echarts/model/Global} ecModel
  50556. * @param {module:echarts/ExtensionAPI} api
  50557. */
  50558. update: function (ecModel, api) {
  50559. this._updateAxesFromSeries(this._model, ecModel);
  50560. },
  50561. /**
  50562. * @override
  50563. */
  50564. containPoint: function (point) {
  50565. var layoutInfo = this._makeLayoutInfo();
  50566. var axisBase = layoutInfo.axisBase;
  50567. var layoutBase = layoutInfo.layoutBase;
  50568. var pixelDimIndex = layoutInfo.pixelDimIndex;
  50569. var pAxis = point[1 - pixelDimIndex];
  50570. var pLayout = point[pixelDimIndex];
  50571. return pAxis >= axisBase
  50572. && pAxis <= axisBase + layoutInfo.axisLength
  50573. && pLayout >= layoutBase
  50574. && pLayout <= layoutBase + layoutInfo.layoutLength;
  50575. },
  50576. getModel: function () {
  50577. return this._model;
  50578. },
  50579. /**
  50580. * Update properties from series
  50581. * @private
  50582. */
  50583. _updateAxesFromSeries: function (parallelModel, ecModel) {
  50584. ecModel.eachSeries(function (seriesModel) {
  50585. if (!parallelModel.contains(seriesModel, ecModel)) {
  50586. return;
  50587. }
  50588. var data = seriesModel.getData();
  50589. each$11(this.dimensions, function (dim) {
  50590. var axis = this._axesMap.get(dim);
  50591. axis.scale.unionExtentFromData(data, data.mapDimension(dim));
  50592. niceScaleExtent(axis.scale, axis.model);
  50593. }, this);
  50594. }, this);
  50595. },
  50596. /**
  50597. * Resize the parallel coordinate system.
  50598. * @param {module:echarts/coord/parallel/ParallelModel} parallelModel
  50599. * @param {module:echarts/ExtensionAPI} api
  50600. */
  50601. resize: function (parallelModel, api) {
  50602. this._rect = getLayoutRect(
  50603. parallelModel.getBoxLayoutParams(),
  50604. {
  50605. width: api.getWidth(),
  50606. height: api.getHeight()
  50607. }
  50608. );
  50609. this._layoutAxes();
  50610. },
  50611. /**
  50612. * @return {module:zrender/core/BoundingRect}
  50613. */
  50614. getRect: function () {
  50615. return this._rect;
  50616. },
  50617. /**
  50618. * @private
  50619. */
  50620. _makeLayoutInfo: function () {
  50621. var parallelModel = this._model;
  50622. var rect = this._rect;
  50623. var xy = ['x', 'y'];
  50624. var wh = ['width', 'height'];
  50625. var layout = parallelModel.get('layout');
  50626. var pixelDimIndex = layout === 'horizontal' ? 0 : 1;
  50627. var layoutLength = rect[wh[pixelDimIndex]];
  50628. var layoutExtent = [0, layoutLength];
  50629. var axisCount = this.dimensions.length;
  50630. var axisExpandWidth = restrict(parallelModel.get('axisExpandWidth'), layoutExtent);
  50631. var axisExpandCount = restrict(parallelModel.get('axisExpandCount') || 0, [0, axisCount]);
  50632. var axisExpandable = parallelModel.get('axisExpandable')
  50633. && axisCount > 3
  50634. && axisCount > axisExpandCount
  50635. && axisExpandCount > 1
  50636. && axisExpandWidth > 0
  50637. && layoutLength > 0;
  50638. // `axisExpandWindow` is According to the coordinates of [0, axisExpandLength],
  50639. // for sake of consider the case that axisCollapseWidth is 0 (when screen is narrow),
  50640. // where collapsed axes should be overlapped.
  50641. var axisExpandWindow = parallelModel.get('axisExpandWindow');
  50642. var winSize;
  50643. if (!axisExpandWindow) {
  50644. winSize = restrict(axisExpandWidth * (axisExpandCount - 1), layoutExtent);
  50645. var axisExpandCenter = parallelModel.get('axisExpandCenter') || mathFloor$2(axisCount / 2);
  50646. axisExpandWindow = [axisExpandWidth * axisExpandCenter - winSize / 2];
  50647. axisExpandWindow[1] = axisExpandWindow[0] + winSize;
  50648. }
  50649. else {
  50650. winSize = restrict(axisExpandWindow[1] - axisExpandWindow[0], layoutExtent);
  50651. axisExpandWindow[1] = axisExpandWindow[0] + winSize;
  50652. }
  50653. var axisCollapseWidth = (layoutLength - winSize) / (axisCount - axisExpandCount);
  50654. // Avoid axisCollapseWidth is too small.
  50655. axisCollapseWidth < 3 && (axisCollapseWidth = 0);
  50656. // Find the first and last indices > ewin[0] and < ewin[1].
  50657. var winInnerIndices = [
  50658. mathFloor$2(round$2(axisExpandWindow[0] / axisExpandWidth, 1)) + 1,
  50659. mathCeil$2(round$2(axisExpandWindow[1] / axisExpandWidth, 1)) - 1
  50660. ];
  50661. // Pos in ec coordinates.
  50662. var axisExpandWindow0Pos = axisCollapseWidth / axisExpandWidth * axisExpandWindow[0];
  50663. return {
  50664. layout: layout,
  50665. pixelDimIndex: pixelDimIndex,
  50666. layoutBase: rect[xy[pixelDimIndex]],
  50667. layoutLength: layoutLength,
  50668. axisBase: rect[xy[1 - pixelDimIndex]],
  50669. axisLength: rect[wh[1 - pixelDimIndex]],
  50670. axisExpandable: axisExpandable,
  50671. axisExpandWidth: axisExpandWidth,
  50672. axisCollapseWidth: axisCollapseWidth,
  50673. axisExpandWindow: axisExpandWindow,
  50674. axisCount: axisCount,
  50675. winInnerIndices: winInnerIndices,
  50676. axisExpandWindow0Pos: axisExpandWindow0Pos
  50677. };
  50678. },
  50679. /**
  50680. * @private
  50681. */
  50682. _layoutAxes: function () {
  50683. var rect = this._rect;
  50684. var axes = this._axesMap;
  50685. var dimensions = this.dimensions;
  50686. var layoutInfo = this._makeLayoutInfo();
  50687. var layout = layoutInfo.layout;
  50688. axes.each(function (axis) {
  50689. var axisExtent = [0, layoutInfo.axisLength];
  50690. var idx = axis.inverse ? 1 : 0;
  50691. axis.setExtent(axisExtent[idx], axisExtent[1 - idx]);
  50692. });
  50693. each$11(dimensions, function (dim, idx) {
  50694. var posInfo = (layoutInfo.axisExpandable
  50695. ? layoutAxisWithExpand : layoutAxisWithoutExpand
  50696. )(idx, layoutInfo);
  50697. var positionTable = {
  50698. horizontal: {
  50699. x: posInfo.position,
  50700. y: layoutInfo.axisLength
  50701. },
  50702. vertical: {
  50703. x: 0,
  50704. y: posInfo.position
  50705. }
  50706. };
  50707. var rotationTable = {
  50708. horizontal: PI$4 / 2,
  50709. vertical: 0
  50710. };
  50711. var position = [
  50712. positionTable[layout].x + rect.x,
  50713. positionTable[layout].y + rect.y
  50714. ];
  50715. var rotation = rotationTable[layout];
  50716. var transform = create$1();
  50717. rotate(transform, transform, rotation);
  50718. translate(transform, transform, position);
  50719. // TODO
  50720. // tick等排布信息。
  50721. // TODO
  50722. // 根据axis order 更新 dimensions顺序。
  50723. this._axesLayout[dim] = {
  50724. position: position,
  50725. rotation: rotation,
  50726. transform: transform,
  50727. axisNameAvailableWidth: posInfo.axisNameAvailableWidth,
  50728. axisLabelShow: posInfo.axisLabelShow,
  50729. nameTruncateMaxWidth: posInfo.nameTruncateMaxWidth,
  50730. tickDirection: 1,
  50731. labelDirection: 1
  50732. };
  50733. }, this);
  50734. },
  50735. /**
  50736. * Get axis by dim.
  50737. * @param {string} dim
  50738. * @return {module:echarts/coord/parallel/ParallelAxis} [description]
  50739. */
  50740. getAxis: function (dim) {
  50741. return this._axesMap.get(dim);
  50742. },
  50743. /**
  50744. * Convert a dim value of a single item of series data to Point.
  50745. * @param {*} value
  50746. * @param {string} dim
  50747. * @return {Array}
  50748. */
  50749. dataToPoint: function (value, dim) {
  50750. return this.axisCoordToPoint(
  50751. this._axesMap.get(dim).dataToCoord(value),
  50752. dim
  50753. );
  50754. },
  50755. /**
  50756. * Travel data for one time, get activeState of each data item.
  50757. * @param {module:echarts/data/List} data
  50758. * @param {Functio} cb param: {string} activeState 'active' or 'inactive' or 'normal'
  50759. * {number} dataIndex
  50760. * @param {number} [start=0] the start dataIndex that travel from.
  50761. * @param {number} [end=data.count()] the next dataIndex of the last dataIndex will be travel.
  50762. */
  50763. eachActiveState: function (data, callback, start, end) {
  50764. start == null && (start = 0);
  50765. end == null && (end = data.count());
  50766. var axesMap = this._axesMap;
  50767. var dimensions = this.dimensions;
  50768. var dataDimensions = [];
  50769. var axisModels = [];
  50770. each$1(dimensions, function (axisDim) {
  50771. dataDimensions.push(data.mapDimension(axisDim));
  50772. axisModels.push(axesMap.get(axisDim).model);
  50773. });
  50774. var hasActiveSet = this.hasAxisBrushed();
  50775. for (var dataIndex = start; dataIndex < end; dataIndex++) {
  50776. var activeState;
  50777. if (!hasActiveSet) {
  50778. activeState = 'normal';
  50779. }
  50780. else {
  50781. activeState = 'active';
  50782. var values = data.getValues(dataDimensions, dataIndex);
  50783. for (var j = 0, lenj = dimensions.length; j < lenj; j++) {
  50784. var state = axisModels[j].getActiveState(values[j]);
  50785. if (state === 'inactive') {
  50786. activeState = 'inactive';
  50787. break;
  50788. }
  50789. }
  50790. }
  50791. callback(activeState, dataIndex);
  50792. }
  50793. },
  50794. /**
  50795. * Whether has any activeSet.
  50796. * @return {boolean}
  50797. */
  50798. hasAxisBrushed: function () {
  50799. var dimensions = this.dimensions;
  50800. var axesMap = this._axesMap;
  50801. var hasActiveSet = false;
  50802. for (var j = 0, lenj = dimensions.length; j < lenj; j++) {
  50803. if (axesMap.get(dimensions[j]).model.getActiveState() !== 'normal') {
  50804. hasActiveSet = true;
  50805. }
  50806. }
  50807. return hasActiveSet;
  50808. },
  50809. /**
  50810. * Convert coords of each axis to Point.
  50811. * Return point. For example: [10, 20]
  50812. * @param {Array.<number>} coords
  50813. * @param {string} dim
  50814. * @return {Array.<number>}
  50815. */
  50816. axisCoordToPoint: function (coord, dim) {
  50817. var axisLayout = this._axesLayout[dim];
  50818. return applyTransform$1([coord, 0], axisLayout.transform);
  50819. },
  50820. /**
  50821. * Get axis layout.
  50822. */
  50823. getAxisLayout: function (dim) {
  50824. return clone(this._axesLayout[dim]);
  50825. },
  50826. /**
  50827. * @param {Array.<number>} point
  50828. * @return {Object} {axisExpandWindow, delta, behavior: 'jump' | 'slide' | 'none'}.
  50829. */
  50830. getSlidedAxisExpandWindow: function (point) {
  50831. var layoutInfo = this._makeLayoutInfo();
  50832. var pixelDimIndex = layoutInfo.pixelDimIndex;
  50833. var axisExpandWindow = layoutInfo.axisExpandWindow.slice();
  50834. var winSize = axisExpandWindow[1] - axisExpandWindow[0];
  50835. var extent = [0, layoutInfo.axisExpandWidth * (layoutInfo.axisCount - 1)];
  50836. // Out of the area of coordinate system.
  50837. if (!this.containPoint(point)) {
  50838. return {behavior: 'none', axisExpandWindow: axisExpandWindow};
  50839. }
  50840. // Conver the point from global to expand coordinates.
  50841. var pointCoord = point[pixelDimIndex] - layoutInfo.layoutBase - layoutInfo.axisExpandWindow0Pos;
  50842. // For dragging operation convenience, the window should not be
  50843. // slided when mouse is the center area of the window.
  50844. var delta;
  50845. var behavior = 'slide';
  50846. var axisCollapseWidth = layoutInfo.axisCollapseWidth;
  50847. var triggerArea = this._model.get('axisExpandSlideTriggerArea');
  50848. // But consider touch device, jump is necessary.
  50849. var useJump = triggerArea[0] != null;
  50850. if (axisCollapseWidth) {
  50851. if (useJump && axisCollapseWidth && pointCoord < winSize * triggerArea[0]) {
  50852. behavior = 'jump';
  50853. delta = pointCoord - winSize * triggerArea[2];
  50854. }
  50855. else if (useJump && axisCollapseWidth && pointCoord > winSize * (1 - triggerArea[0])) {
  50856. behavior = 'jump';
  50857. delta = pointCoord - winSize * (1 - triggerArea[2]);
  50858. }
  50859. else {
  50860. (delta = pointCoord - winSize * triggerArea[1]) >= 0
  50861. && (delta = pointCoord - winSize * (1 - triggerArea[1])) <= 0
  50862. && (delta = 0);
  50863. }
  50864. delta *= layoutInfo.axisExpandWidth / axisCollapseWidth;
  50865. delta
  50866. ? sliderMove(delta, axisExpandWindow, extent, 'all')
  50867. // Avoid nonsense triger on mousemove.
  50868. : (behavior = 'none');
  50869. }
  50870. // When screen is too narrow, make it visible and slidable, although it is hard to interact.
  50871. else {
  50872. var winSize = axisExpandWindow[1] - axisExpandWindow[0];
  50873. var pos = extent[1] * pointCoord / winSize;
  50874. axisExpandWindow = [mathMax$5(0, pos - winSize / 2)];
  50875. axisExpandWindow[1] = mathMin$5(extent[1], axisExpandWindow[0] + winSize);
  50876. axisExpandWindow[0] = axisExpandWindow[1] - winSize;
  50877. }
  50878. return {
  50879. axisExpandWindow: axisExpandWindow,
  50880. behavior: behavior
  50881. };
  50882. }
  50883. };
  50884. function restrict(len, extent) {
  50885. return mathMin$5(mathMax$5(len, extent[0]), extent[1]);
  50886. }
  50887. function layoutAxisWithoutExpand(axisIndex, layoutInfo) {
  50888. var step = layoutInfo.layoutLength / (layoutInfo.axisCount - 1);
  50889. return {
  50890. position: step * axisIndex,
  50891. axisNameAvailableWidth: step,
  50892. axisLabelShow: true
  50893. };
  50894. }
  50895. function layoutAxisWithExpand(axisIndex, layoutInfo) {
  50896. var layoutLength = layoutInfo.layoutLength;
  50897. var axisExpandWidth = layoutInfo.axisExpandWidth;
  50898. var axisCount = layoutInfo.axisCount;
  50899. var axisCollapseWidth = layoutInfo.axisCollapseWidth;
  50900. var winInnerIndices = layoutInfo.winInnerIndices;
  50901. var position;
  50902. var axisNameAvailableWidth = axisCollapseWidth;
  50903. var axisLabelShow = false;
  50904. var nameTruncateMaxWidth;
  50905. if (axisIndex < winInnerIndices[0]) {
  50906. position = axisIndex * axisCollapseWidth;
  50907. nameTruncateMaxWidth = axisCollapseWidth;
  50908. }
  50909. else if (axisIndex <= winInnerIndices[1]) {
  50910. position = layoutInfo.axisExpandWindow0Pos
  50911. + axisIndex * axisExpandWidth - layoutInfo.axisExpandWindow[0];
  50912. axisNameAvailableWidth = axisExpandWidth;
  50913. axisLabelShow = true;
  50914. }
  50915. else {
  50916. position = layoutLength - (axisCount - 1 - axisIndex) * axisCollapseWidth;
  50917. nameTruncateMaxWidth = axisCollapseWidth;
  50918. }
  50919. return {
  50920. position: position,
  50921. axisNameAvailableWidth: axisNameAvailableWidth,
  50922. axisLabelShow: axisLabelShow,
  50923. nameTruncateMaxWidth: nameTruncateMaxWidth
  50924. };
  50925. }
  50926. /*
  50927. * Licensed to the Apache Software Foundation (ASF) under one
  50928. * or more contributor license agreements. See the NOTICE file
  50929. * distributed with this work for additional information
  50930. * regarding copyright ownership. The ASF licenses this file
  50931. * to you under the Apache License, Version 2.0 (the
  50932. * "License"); you may not use this file except in compliance
  50933. * with the License. You may obtain a copy of the License at
  50934. *
  50935. * http://www.apache.org/licenses/LICENSE-2.0
  50936. *
  50937. * Unless required by applicable law or agreed to in writing,
  50938. * software distributed under the License is distributed on an
  50939. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  50940. * KIND, either express or implied. See the License for the
  50941. * specific language governing permissions and limitations
  50942. * under the License.
  50943. */
  50944. /**
  50945. * Parallel coordinate system creater.
  50946. */
  50947. function create$2(ecModel, api) {
  50948. var coordSysList = [];
  50949. ecModel.eachComponent('parallel', function (parallelModel, idx) {
  50950. var coordSys = new Parallel(parallelModel, ecModel, api);
  50951. coordSys.name = 'parallel_' + idx;
  50952. coordSys.resize(parallelModel, api);
  50953. parallelModel.coordinateSystem = coordSys;
  50954. coordSys.model = parallelModel;
  50955. coordSysList.push(coordSys);
  50956. });
  50957. // Inject the coordinateSystems into seriesModel
  50958. ecModel.eachSeries(function (seriesModel) {
  50959. if (seriesModel.get('coordinateSystem') === 'parallel') {
  50960. var parallelModel = ecModel.queryComponents({
  50961. mainType: 'parallel',
  50962. index: seriesModel.get('parallelIndex'),
  50963. id: seriesModel.get('parallelId')
  50964. })[0];
  50965. seriesModel.coordinateSystem = parallelModel.coordinateSystem;
  50966. }
  50967. });
  50968. return coordSysList;
  50969. }
  50970. CoordinateSystemManager.register('parallel', {create: create$2});
  50971. /*
  50972. * Licensed to the Apache Software Foundation (ASF) under one
  50973. * or more contributor license agreements. See the NOTICE file
  50974. * distributed with this work for additional information
  50975. * regarding copyright ownership. The ASF licenses this file
  50976. * to you under the Apache License, Version 2.0 (the
  50977. * "License"); you may not use this file except in compliance
  50978. * with the License. You may obtain a copy of the License at
  50979. *
  50980. * http://www.apache.org/licenses/LICENSE-2.0
  50981. *
  50982. * Unless required by applicable law or agreed to in writing,
  50983. * software distributed under the License is distributed on an
  50984. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  50985. * KIND, either express or implied. See the License for the
  50986. * specific language governing permissions and limitations
  50987. * under the License.
  50988. */
  50989. var AxisModel$2 = ComponentModel.extend({
  50990. type: 'baseParallelAxis',
  50991. /**
  50992. * @type {module:echarts/coord/parallel/Axis}
  50993. */
  50994. axis: null,
  50995. /**
  50996. * @type {Array.<Array.<number>}
  50997. * @readOnly
  50998. */
  50999. activeIntervals: [],
  51000. /**
  51001. * @return {Object}
  51002. */
  51003. getAreaSelectStyle: function () {
  51004. return makeStyleMapper(
  51005. [
  51006. ['fill', 'color'],
  51007. ['lineWidth', 'borderWidth'],
  51008. ['stroke', 'borderColor'],
  51009. ['width', 'width'],
  51010. ['opacity', 'opacity']
  51011. ]
  51012. )(this.getModel('areaSelectStyle'));
  51013. },
  51014. /**
  51015. * The code of this feature is put on AxisModel but not ParallelAxis,
  51016. * because axisModel can be alive after echarts updating but instance of
  51017. * ParallelAxis having been disposed. this._activeInterval should be kept
  51018. * when action dispatched (i.e. legend click).
  51019. *
  51020. * @param {Array.<Array<number>>} intervals interval.length === 0
  51021. * means set all active.
  51022. * @public
  51023. */
  51024. setActiveIntervals: function (intervals) {
  51025. var activeIntervals = this.activeIntervals = clone(intervals);
  51026. // Normalize
  51027. if (activeIntervals) {
  51028. for (var i = activeIntervals.length - 1; i >= 0; i--) {
  51029. asc(activeIntervals[i]);
  51030. }
  51031. }
  51032. },
  51033. /**
  51034. * @param {number|string} [value] When attempting to detect 'no activeIntervals set',
  51035. * value can not be input.
  51036. * @return {string} 'normal': no activeIntervals set,
  51037. * 'active',
  51038. * 'inactive'.
  51039. * @public
  51040. */
  51041. getActiveState: function (value) {
  51042. var activeIntervals = this.activeIntervals;
  51043. if (!activeIntervals.length) {
  51044. return 'normal';
  51045. }
  51046. if (value == null || isNaN(value)) {
  51047. return 'inactive';
  51048. }
  51049. // Simple optimization
  51050. if (activeIntervals.length === 1) {
  51051. var interval = activeIntervals[0];
  51052. if (interval[0] <= value && value <= interval[1]) {
  51053. return 'active';
  51054. }
  51055. }
  51056. else {
  51057. for (var i = 0, len = activeIntervals.length; i < len; i++) {
  51058. if (activeIntervals[i][0] <= value && value <= activeIntervals[i][1]) {
  51059. return 'active';
  51060. }
  51061. }
  51062. }
  51063. return 'inactive';
  51064. }
  51065. });
  51066. var defaultOption$1 = {
  51067. type: 'value',
  51068. /**
  51069. * @type {Array.<number>}
  51070. */
  51071. dim: null, // 0, 1, 2, ...
  51072. // parallelIndex: null,
  51073. areaSelectStyle: {
  51074. width: 20,
  51075. borderWidth: 1,
  51076. borderColor: 'rgba(160,197,232)',
  51077. color: 'rgba(160,197,232)',
  51078. opacity: 0.3
  51079. },
  51080. realtime: true, // Whether realtime update view when select.
  51081. z: 10
  51082. };
  51083. merge(AxisModel$2.prototype, axisModelCommonMixin);
  51084. function getAxisType$1(axisName, option) {
  51085. return option.type || (option.data ? 'category' : 'value');
  51086. }
  51087. axisModelCreator('parallel', AxisModel$2, getAxisType$1, defaultOption$1);
  51088. /*
  51089. * Licensed to the Apache Software Foundation (ASF) under one
  51090. * or more contributor license agreements. See the NOTICE file
  51091. * distributed with this work for additional information
  51092. * regarding copyright ownership. The ASF licenses this file
  51093. * to you under the Apache License, Version 2.0 (the
  51094. * "License"); you may not use this file except in compliance
  51095. * with the License. You may obtain a copy of the License at
  51096. *
  51097. * http://www.apache.org/licenses/LICENSE-2.0
  51098. *
  51099. * Unless required by applicable law or agreed to in writing,
  51100. * software distributed under the License is distributed on an
  51101. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  51102. * KIND, either express or implied. See the License for the
  51103. * specific language governing permissions and limitations
  51104. * under the License.
  51105. */
  51106. ComponentModel.extend({
  51107. type: 'parallel',
  51108. dependencies: ['parallelAxis'],
  51109. /**
  51110. * @type {module:echarts/coord/parallel/Parallel}
  51111. */
  51112. coordinateSystem: null,
  51113. /**
  51114. * Each item like: 'dim0', 'dim1', 'dim2', ...
  51115. * @type {Array.<string>}
  51116. * @readOnly
  51117. */
  51118. dimensions: null,
  51119. /**
  51120. * Coresponding to dimensions.
  51121. * @type {Array.<number>}
  51122. * @readOnly
  51123. */
  51124. parallelAxisIndex: null,
  51125. layoutMode: 'box',
  51126. defaultOption: {
  51127. zlevel: 0,
  51128. z: 0,
  51129. left: 80,
  51130. top: 60,
  51131. right: 80,
  51132. bottom: 60,
  51133. // width: {totalWidth} - left - right,
  51134. // height: {totalHeight} - top - bottom,
  51135. layout: 'horizontal', // 'horizontal' or 'vertical'
  51136. // FIXME
  51137. // naming?
  51138. axisExpandable: false,
  51139. axisExpandCenter: null,
  51140. axisExpandCount: 0,
  51141. axisExpandWidth: 50, // FIXME '10%' ?
  51142. axisExpandRate: 17,
  51143. axisExpandDebounce: 50,
  51144. // [out, in, jumpTarget]. In percentage. If use [null, 0.05], null means full.
  51145. // Do not doc to user until necessary.
  51146. axisExpandSlideTriggerArea: [-0.15, 0.05, 0.4],
  51147. axisExpandTriggerOn: 'click', // 'mousemove' or 'click'
  51148. parallelAxisDefault: null
  51149. },
  51150. /**
  51151. * @override
  51152. */
  51153. init: function () {
  51154. ComponentModel.prototype.init.apply(this, arguments);
  51155. this.mergeOption({});
  51156. },
  51157. /**
  51158. * @override
  51159. */
  51160. mergeOption: function (newOption) {
  51161. var thisOption = this.option;
  51162. newOption && merge(thisOption, newOption, true);
  51163. this._initDimensions();
  51164. },
  51165. /**
  51166. * Whether series or axis is in this coordinate system.
  51167. * @param {module:echarts/model/Series|module:echarts/coord/parallel/AxisModel} model
  51168. * @param {module:echarts/model/Global} ecModel
  51169. */
  51170. contains: function (model, ecModel) {
  51171. var parallelIndex = model.get('parallelIndex');
  51172. return parallelIndex != null
  51173. && ecModel.getComponent('parallel', parallelIndex) === this;
  51174. },
  51175. setAxisExpand: function (opt) {
  51176. each$1(
  51177. ['axisExpandable', 'axisExpandCenter', 'axisExpandCount', 'axisExpandWidth', 'axisExpandWindow'],
  51178. function (name) {
  51179. if (opt.hasOwnProperty(name)) {
  51180. this.option[name] = opt[name];
  51181. }
  51182. },
  51183. this
  51184. );
  51185. },
  51186. /**
  51187. * @private
  51188. */
  51189. _initDimensions: function () {
  51190. var dimensions = this.dimensions = [];
  51191. var parallelAxisIndex = this.parallelAxisIndex = [];
  51192. var axisModels = filter(this.dependentModels.parallelAxis, function (axisModel) {
  51193. // Can not use this.contains here, because
  51194. // initialization has not been completed yet.
  51195. return (axisModel.get('parallelIndex') || 0) === this.componentIndex;
  51196. }, this);
  51197. each$1(axisModels, function (axisModel) {
  51198. dimensions.push('dim' + axisModel.get('dim'));
  51199. parallelAxisIndex.push(axisModel.componentIndex);
  51200. });
  51201. }
  51202. });
  51203. /*
  51204. * Licensed to the Apache Software Foundation (ASF) under one
  51205. * or more contributor license agreements. See the NOTICE file
  51206. * distributed with this work for additional information
  51207. * regarding copyright ownership. The ASF licenses this file
  51208. * to you under the Apache License, Version 2.0 (the
  51209. * "License"); you may not use this file except in compliance
  51210. * with the License. You may obtain a copy of the License at
  51211. *
  51212. * http://www.apache.org/licenses/LICENSE-2.0
  51213. *
  51214. * Unless required by applicable law or agreed to in writing,
  51215. * software distributed under the License is distributed on an
  51216. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  51217. * KIND, either express or implied. See the License for the
  51218. * specific language governing permissions and limitations
  51219. * under the License.
  51220. */
  51221. /**
  51222. * @payload
  51223. * @property {string} parallelAxisId
  51224. * @property {Array.<Array.<number>>} intervals
  51225. */
  51226. var actionInfo$1 = {
  51227. type: 'axisAreaSelect',
  51228. event: 'axisAreaSelected'
  51229. // update: 'updateVisual'
  51230. };
  51231. registerAction(actionInfo$1, function (payload, ecModel) {
  51232. ecModel.eachComponent(
  51233. {mainType: 'parallelAxis', query: payload},
  51234. function (parallelAxisModel) {
  51235. parallelAxisModel.axis.model.setActiveIntervals(payload.intervals);
  51236. }
  51237. );
  51238. });
  51239. /**
  51240. * @payload
  51241. */
  51242. registerAction('parallelAxisExpand', function (payload, ecModel) {
  51243. ecModel.eachComponent(
  51244. {mainType: 'parallel', query: payload},
  51245. function (parallelModel) {
  51246. parallelModel.setAxisExpand(payload);
  51247. }
  51248. );
  51249. });
  51250. /*
  51251. * Licensed to the Apache Software Foundation (ASF) under one
  51252. * or more contributor license agreements. See the NOTICE file
  51253. * distributed with this work for additional information
  51254. * regarding copyright ownership. The ASF licenses this file
  51255. * to you under the Apache License, Version 2.0 (the
  51256. * "License"); you may not use this file except in compliance
  51257. * with the License. You may obtain a copy of the License at
  51258. *
  51259. * http://www.apache.org/licenses/LICENSE-2.0
  51260. *
  51261. * Unless required by applicable law or agreed to in writing,
  51262. * software distributed under the License is distributed on an
  51263. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  51264. * KIND, either express or implied. See the License for the
  51265. * specific language governing permissions and limitations
  51266. * under the License.
  51267. */
  51268. var curry$2 = curry;
  51269. var each$12 = each$1;
  51270. var map$2 = map;
  51271. var mathMin$6 = Math.min;
  51272. var mathMax$6 = Math.max;
  51273. var mathPow$2 = Math.pow;
  51274. var COVER_Z = 10000;
  51275. var UNSELECT_THRESHOLD = 6;
  51276. var MIN_RESIZE_LINE_WIDTH = 6;
  51277. var MUTEX_RESOURCE_KEY = 'globalPan';
  51278. var DIRECTION_MAP = {
  51279. w: [0, 0],
  51280. e: [0, 1],
  51281. n: [1, 0],
  51282. s: [1, 1]
  51283. };
  51284. var CURSOR_MAP = {
  51285. w: 'ew',
  51286. e: 'ew',
  51287. n: 'ns',
  51288. s: 'ns',
  51289. ne: 'nesw',
  51290. sw: 'nesw',
  51291. nw: 'nwse',
  51292. se: 'nwse'
  51293. };
  51294. var DEFAULT_BRUSH_OPT = {
  51295. brushStyle: {
  51296. lineWidth: 2,
  51297. stroke: 'rgba(0,0,0,0.3)',
  51298. fill: 'rgba(0,0,0,0.1)'
  51299. },
  51300. transformable: true,
  51301. brushMode: 'single',
  51302. removeOnClick: false
  51303. };
  51304. var baseUID = 0;
  51305. /**
  51306. * @alias module:echarts/component/helper/BrushController
  51307. * @constructor
  51308. * @mixin {module:zrender/mixin/Eventful}
  51309. * @event module:echarts/component/helper/BrushController#brush
  51310. * params:
  51311. * areas: Array.<Array>, coord relates to container group,
  51312. * If no container specified, to global.
  51313. * opt {
  51314. * isEnd: boolean,
  51315. * removeOnClick: boolean
  51316. * }
  51317. *
  51318. * @param {module:zrender/zrender~ZRender} zr
  51319. */
  51320. function BrushController(zr) {
  51321. if (__DEV__) {
  51322. assert$1(zr);
  51323. }
  51324. Eventful.call(this);
  51325. /**
  51326. * @type {module:zrender/zrender~ZRender}
  51327. * @private
  51328. */
  51329. this._zr = zr;
  51330. /**
  51331. * @type {module:zrender/container/Group}
  51332. * @readOnly
  51333. */
  51334. this.group = new Group();
  51335. /**
  51336. * Only for drawing (after enabledBrush).
  51337. * 'line', 'rect', 'polygon' or false
  51338. * If passing false/null/undefined, disable brush.
  51339. * If passing 'auto', determined by panel.defaultBrushType
  51340. * @private
  51341. * @type {string}
  51342. */
  51343. this._brushType;
  51344. /**
  51345. * Only for drawing (after enabledBrush).
  51346. *
  51347. * @private
  51348. * @type {Object}
  51349. */
  51350. this._brushOption;
  51351. /**
  51352. * @private
  51353. * @type {Object}
  51354. */
  51355. this._panels;
  51356. /**
  51357. * @private
  51358. * @type {Array.<nubmer>}
  51359. */
  51360. this._track = [];
  51361. /**
  51362. * @private
  51363. * @type {boolean}
  51364. */
  51365. this._dragging;
  51366. /**
  51367. * @private
  51368. * @type {Array}
  51369. */
  51370. this._covers = [];
  51371. /**
  51372. * @private
  51373. * @type {moudule:zrender/container/Group}
  51374. */
  51375. this._creatingCover;
  51376. /**
  51377. * `true` means global panel
  51378. * @private
  51379. * @type {module:zrender/container/Group|boolean}
  51380. */
  51381. this._creatingPanel;
  51382. /**
  51383. * @private
  51384. * @type {boolean}
  51385. */
  51386. this._enableGlobalPan;
  51387. /**
  51388. * @private
  51389. * @type {boolean}
  51390. */
  51391. if (__DEV__) {
  51392. this._mounted;
  51393. }
  51394. /**
  51395. * @private
  51396. * @type {string}
  51397. */
  51398. this._uid = 'brushController_' + baseUID++;
  51399. /**
  51400. * @private
  51401. * @type {Object}
  51402. */
  51403. this._handlers = {};
  51404. each$12(mouseHandlers, function (handler, eventName) {
  51405. this._handlers[eventName] = bind(handler, this);
  51406. }, this);
  51407. }
  51408. BrushController.prototype = {
  51409. constructor: BrushController,
  51410. /**
  51411. * If set to null/undefined/false, select disabled.
  51412. * @param {Object} brushOption
  51413. * @param {string|boolean} brushOption.brushType 'line', 'rect', 'polygon' or false
  51414. * If passing false/null/undefined, disable brush.
  51415. * If passing 'auto', determined by panel.defaultBrushType.
  51416. * ('auto' can not be used in global panel)
  51417. * @param {number} [brushOption.brushMode='single'] 'single' or 'multiple'
  51418. * @param {boolean} [brushOption.transformable=true]
  51419. * @param {boolean} [brushOption.removeOnClick=false]
  51420. * @param {Object} [brushOption.brushStyle]
  51421. * @param {number} [brushOption.brushStyle.width]
  51422. * @param {number} [brushOption.brushStyle.lineWidth]
  51423. * @param {string} [brushOption.brushStyle.stroke]
  51424. * @param {string} [brushOption.brushStyle.fill]
  51425. * @param {number} [brushOption.z]
  51426. */
  51427. enableBrush: function (brushOption) {
  51428. if (__DEV__) {
  51429. assert$1(this._mounted);
  51430. }
  51431. this._brushType && doDisableBrush(this);
  51432. brushOption.brushType && doEnableBrush(this, brushOption);
  51433. return this;
  51434. },
  51435. /**
  51436. * @param {Array.<Object>} panelOpts If not pass, it is global brush.
  51437. * Each items: {
  51438. * panelId, // mandatory.
  51439. * clipPath, // mandatory. function.
  51440. * isTargetByCursor, // mandatory. function.
  51441. * defaultBrushType, // optional, only used when brushType is 'auto'.
  51442. * getLinearBrushOtherExtent, // optional. function.
  51443. * }
  51444. */
  51445. setPanels: function (panelOpts) {
  51446. if (panelOpts && panelOpts.length) {
  51447. var panels = this._panels = {};
  51448. each$1(panelOpts, function (panelOpts) {
  51449. panels[panelOpts.panelId] = clone(panelOpts);
  51450. });
  51451. }
  51452. else {
  51453. this._panels = null;
  51454. }
  51455. return this;
  51456. },
  51457. /**
  51458. * @param {Object} [opt]
  51459. * @return {boolean} [opt.enableGlobalPan=false]
  51460. */
  51461. mount: function (opt) {
  51462. opt = opt || {};
  51463. if (__DEV__) {
  51464. this._mounted = true; // should be at first.
  51465. }
  51466. this._enableGlobalPan = opt.enableGlobalPan;
  51467. var thisGroup = this.group;
  51468. this._zr.add(thisGroup);
  51469. thisGroup.attr({
  51470. position: opt.position || [0, 0],
  51471. rotation: opt.rotation || 0,
  51472. scale: opt.scale || [1, 1]
  51473. });
  51474. this._transform = thisGroup.getLocalTransform();
  51475. return this;
  51476. },
  51477. eachCover: function (cb, context) {
  51478. each$12(this._covers, cb, context);
  51479. },
  51480. /**
  51481. * Update covers.
  51482. * @param {Array.<Object>} brushOptionList Like:
  51483. * [
  51484. * {id: 'xx', brushType: 'line', range: [23, 44], brushStyle, transformable},
  51485. * {id: 'yy', brushType: 'rect', range: [[23, 44], [23, 54]]},
  51486. * ...
  51487. * ]
  51488. * `brushType` is required in each cover info. (can not be 'auto')
  51489. * `id` is not mandatory.
  51490. * `brushStyle`, `transformable` is not mandatory, use DEFAULT_BRUSH_OPT by default.
  51491. * If brushOptionList is null/undefined, all covers removed.
  51492. */
  51493. updateCovers: function (brushOptionList) {
  51494. if (__DEV__) {
  51495. assert$1(this._mounted);
  51496. }
  51497. brushOptionList = map(brushOptionList, function (brushOption) {
  51498. return merge(clone(DEFAULT_BRUSH_OPT), brushOption, true);
  51499. });
  51500. var tmpIdPrefix = '\0-brush-index-';
  51501. var oldCovers = this._covers;
  51502. var newCovers = this._covers = [];
  51503. var controller = this;
  51504. var creatingCover = this._creatingCover;
  51505. (new DataDiffer(oldCovers, brushOptionList, oldGetKey, getKey))
  51506. .add(addOrUpdate)
  51507. .update(addOrUpdate)
  51508. .remove(remove)
  51509. .execute();
  51510. return this;
  51511. function getKey(brushOption, index) {
  51512. return (brushOption.id != null ? brushOption.id : tmpIdPrefix + index)
  51513. + '-' + brushOption.brushType;
  51514. }
  51515. function oldGetKey(cover, index) {
  51516. return getKey(cover.__brushOption, index);
  51517. }
  51518. function addOrUpdate(newIndex, oldIndex) {
  51519. var newBrushOption = brushOptionList[newIndex];
  51520. // Consider setOption in event listener of brushSelect,
  51521. // where updating cover when creating should be forbiden.
  51522. if (oldIndex != null && oldCovers[oldIndex] === creatingCover) {
  51523. newCovers[newIndex] = oldCovers[oldIndex];
  51524. }
  51525. else {
  51526. var cover = newCovers[newIndex] = oldIndex != null
  51527. ? (
  51528. oldCovers[oldIndex].__brushOption = newBrushOption,
  51529. oldCovers[oldIndex]
  51530. )
  51531. : endCreating(controller, createCover(controller, newBrushOption));
  51532. updateCoverAfterCreation(controller, cover);
  51533. }
  51534. }
  51535. function remove(oldIndex) {
  51536. if (oldCovers[oldIndex] !== creatingCover) {
  51537. controller.group.remove(oldCovers[oldIndex]);
  51538. }
  51539. }
  51540. },
  51541. unmount: function () {
  51542. if (__DEV__) {
  51543. if (!this._mounted) {
  51544. return;
  51545. }
  51546. }
  51547. this.enableBrush(false);
  51548. // container may 'removeAll' outside.
  51549. clearCovers(this);
  51550. this._zr.remove(this.group);
  51551. if (__DEV__) {
  51552. this._mounted = false; // should be at last.
  51553. }
  51554. return this;
  51555. },
  51556. dispose: function () {
  51557. this.unmount();
  51558. this.off();
  51559. }
  51560. };
  51561. mixin(BrushController, Eventful);
  51562. function doEnableBrush(controller, brushOption) {
  51563. var zr = controller._zr;
  51564. // Consider roam, which takes globalPan too.
  51565. if (!controller._enableGlobalPan) {
  51566. take(zr, MUTEX_RESOURCE_KEY, controller._uid);
  51567. }
  51568. each$12(controller._handlers, function (handler, eventName) {
  51569. zr.on(eventName, handler);
  51570. });
  51571. controller._brushType = brushOption.brushType;
  51572. controller._brushOption = merge(clone(DEFAULT_BRUSH_OPT), brushOption, true);
  51573. }
  51574. function doDisableBrush(controller) {
  51575. var zr = controller._zr;
  51576. release(zr, MUTEX_RESOURCE_KEY, controller._uid);
  51577. each$12(controller._handlers, function (handler, eventName) {
  51578. zr.off(eventName, handler);
  51579. });
  51580. controller._brushType = controller._brushOption = null;
  51581. }
  51582. function createCover(controller, brushOption) {
  51583. var cover = coverRenderers[brushOption.brushType].createCover(controller, brushOption);
  51584. cover.__brushOption = brushOption;
  51585. updateZ$1(cover, brushOption);
  51586. controller.group.add(cover);
  51587. return cover;
  51588. }
  51589. function endCreating(controller, creatingCover) {
  51590. var coverRenderer = getCoverRenderer(creatingCover);
  51591. if (coverRenderer.endCreating) {
  51592. coverRenderer.endCreating(controller, creatingCover);
  51593. updateZ$1(creatingCover, creatingCover.__brushOption);
  51594. }
  51595. return creatingCover;
  51596. }
  51597. function updateCoverShape(controller, cover) {
  51598. var brushOption = cover.__brushOption;
  51599. getCoverRenderer(cover).updateCoverShape(
  51600. controller, cover, brushOption.range, brushOption
  51601. );
  51602. }
  51603. function updateZ$1(cover, brushOption) {
  51604. var z = brushOption.z;
  51605. z == null && (z = COVER_Z);
  51606. cover.traverse(function (el) {
  51607. el.z = z;
  51608. el.z2 = z; // Consider in given container.
  51609. });
  51610. }
  51611. function updateCoverAfterCreation(controller, cover) {
  51612. getCoverRenderer(cover).updateCommon(controller, cover);
  51613. updateCoverShape(controller, cover);
  51614. }
  51615. function getCoverRenderer(cover) {
  51616. return coverRenderers[cover.__brushOption.brushType];
  51617. }
  51618. // return target panel or `true` (means global panel)
  51619. function getPanelByPoint(controller, e, localCursorPoint) {
  51620. var panels = controller._panels;
  51621. if (!panels) {
  51622. return true; // Global panel
  51623. }
  51624. var panel;
  51625. var transform = controller._transform;
  51626. each$12(panels, function (pn) {
  51627. pn.isTargetByCursor(e, localCursorPoint, transform) && (panel = pn);
  51628. });
  51629. return panel;
  51630. }
  51631. // Return a panel or true
  51632. function getPanelByCover(controller, cover) {
  51633. var panels = controller._panels;
  51634. if (!panels) {
  51635. return true; // Global panel
  51636. }
  51637. var panelId = cover.__brushOption.panelId;
  51638. // User may give cover without coord sys info,
  51639. // which is then treated as global panel.
  51640. return panelId != null ? panels[panelId] : true;
  51641. }
  51642. function clearCovers(controller) {
  51643. var covers = controller._covers;
  51644. var originalLength = covers.length;
  51645. each$12(covers, function (cover) {
  51646. controller.group.remove(cover);
  51647. }, controller);
  51648. covers.length = 0;
  51649. return !!originalLength;
  51650. }
  51651. function trigger$1(controller, opt) {
  51652. var areas = map$2(controller._covers, function (cover) {
  51653. var brushOption = cover.__brushOption;
  51654. var range = clone(brushOption.range);
  51655. return {
  51656. brushType: brushOption.brushType,
  51657. panelId: brushOption.panelId,
  51658. range: range
  51659. };
  51660. });
  51661. controller.trigger('brush', areas, {
  51662. isEnd: !!opt.isEnd,
  51663. removeOnClick: !!opt.removeOnClick
  51664. });
  51665. }
  51666. function shouldShowCover(controller) {
  51667. var track = controller._track;
  51668. if (!track.length) {
  51669. return false;
  51670. }
  51671. var p2 = track[track.length - 1];
  51672. var p1 = track[0];
  51673. var dx = p2[0] - p1[0];
  51674. var dy = p2[1] - p1[1];
  51675. var dist = mathPow$2(dx * dx + dy * dy, 0.5);
  51676. return dist > UNSELECT_THRESHOLD;
  51677. }
  51678. function getTrackEnds(track) {
  51679. var tail = track.length - 1;
  51680. tail < 0 && (tail = 0);
  51681. return [track[0], track[tail]];
  51682. }
  51683. function createBaseRectCover(doDrift, controller, brushOption, edgeNames) {
  51684. var cover = new Group();
  51685. cover.add(new Rect({
  51686. name: 'main',
  51687. style: makeStyle(brushOption),
  51688. silent: true,
  51689. draggable: true,
  51690. cursor: 'move',
  51691. drift: curry$2(doDrift, controller, cover, 'nswe'),
  51692. ondragend: curry$2(trigger$1, controller, {isEnd: true})
  51693. }));
  51694. each$12(
  51695. edgeNames,
  51696. function (name) {
  51697. cover.add(new Rect({
  51698. name: name,
  51699. style: {opacity: 0},
  51700. draggable: true,
  51701. silent: true,
  51702. invisible: true,
  51703. drift: curry$2(doDrift, controller, cover, name),
  51704. ondragend: curry$2(trigger$1, controller, {isEnd: true})
  51705. }));
  51706. }
  51707. );
  51708. return cover;
  51709. }
  51710. function updateBaseRect(controller, cover, localRange, brushOption) {
  51711. var lineWidth = brushOption.brushStyle.lineWidth || 0;
  51712. var handleSize = mathMax$6(lineWidth, MIN_RESIZE_LINE_WIDTH);
  51713. var x = localRange[0][0];
  51714. var y = localRange[1][0];
  51715. var xa = x - lineWidth / 2;
  51716. var ya = y - lineWidth / 2;
  51717. var x2 = localRange[0][1];
  51718. var y2 = localRange[1][1];
  51719. var x2a = x2 - handleSize + lineWidth / 2;
  51720. var y2a = y2 - handleSize + lineWidth / 2;
  51721. var width = x2 - x;
  51722. var height = y2 - y;
  51723. var widtha = width + lineWidth;
  51724. var heighta = height + lineWidth;
  51725. updateRectShape(controller, cover, 'main', x, y, width, height);
  51726. if (brushOption.transformable) {
  51727. updateRectShape(controller, cover, 'w', xa, ya, handleSize, heighta);
  51728. updateRectShape(controller, cover, 'e', x2a, ya, handleSize, heighta);
  51729. updateRectShape(controller, cover, 'n', xa, ya, widtha, handleSize);
  51730. updateRectShape(controller, cover, 's', xa, y2a, widtha, handleSize);
  51731. updateRectShape(controller, cover, 'nw', xa, ya, handleSize, handleSize);
  51732. updateRectShape(controller, cover, 'ne', x2a, ya, handleSize, handleSize);
  51733. updateRectShape(controller, cover, 'sw', xa, y2a, handleSize, handleSize);
  51734. updateRectShape(controller, cover, 'se', x2a, y2a, handleSize, handleSize);
  51735. }
  51736. }
  51737. function updateCommon(controller, cover) {
  51738. var brushOption = cover.__brushOption;
  51739. var transformable = brushOption.transformable;
  51740. var mainEl = cover.childAt(0);
  51741. mainEl.useStyle(makeStyle(brushOption));
  51742. mainEl.attr({
  51743. silent: !transformable,
  51744. cursor: transformable ? 'move' : 'default'
  51745. });
  51746. each$12(
  51747. ['w', 'e', 'n', 's', 'se', 'sw', 'ne', 'nw'],
  51748. function (name) {
  51749. var el = cover.childOfName(name);
  51750. var globalDir = getGlobalDirection(controller, name);
  51751. el && el.attr({
  51752. silent: !transformable,
  51753. invisible: !transformable,
  51754. cursor: transformable ? CURSOR_MAP[globalDir] + '-resize' : null
  51755. });
  51756. }
  51757. );
  51758. }
  51759. function updateRectShape(controller, cover, name, x, y, w, h) {
  51760. var el = cover.childOfName(name);
  51761. el && el.setShape(pointsToRect(
  51762. clipByPanel(controller, cover, [[x, y], [x + w, y + h]])
  51763. ));
  51764. }
  51765. function makeStyle(brushOption) {
  51766. return defaults({strokeNoScale: true}, brushOption.brushStyle);
  51767. }
  51768. function formatRectRange(x, y, x2, y2) {
  51769. var min = [mathMin$6(x, x2), mathMin$6(y, y2)];
  51770. var max = [mathMax$6(x, x2), mathMax$6(y, y2)];
  51771. return [
  51772. [min[0], max[0]], // x range
  51773. [min[1], max[1]] // y range
  51774. ];
  51775. }
  51776. function getTransform$1(controller) {
  51777. return getTransform(controller.group);
  51778. }
  51779. function getGlobalDirection(controller, localDirection) {
  51780. if (localDirection.length > 1) {
  51781. localDirection = localDirection.split('');
  51782. var globalDir = [
  51783. getGlobalDirection(controller, localDirection[0]),
  51784. getGlobalDirection(controller, localDirection[1])
  51785. ];
  51786. (globalDir[0] === 'e' || globalDir[0] === 'w') && globalDir.reverse();
  51787. return globalDir.join('');
  51788. }
  51789. else {
  51790. var map$$1 = {w: 'left', e: 'right', n: 'top', s: 'bottom'};
  51791. var inverseMap = {left: 'w', right: 'e', top: 'n', bottom: 's'};
  51792. var globalDir = transformDirection(
  51793. map$$1[localDirection], getTransform$1(controller)
  51794. );
  51795. return inverseMap[globalDir];
  51796. }
  51797. }
  51798. function driftRect(toRectRange, fromRectRange, controller, cover, name, dx, dy, e) {
  51799. var brushOption = cover.__brushOption;
  51800. var rectRange = toRectRange(brushOption.range);
  51801. var localDelta = toLocalDelta(controller, dx, dy);
  51802. each$12(name.split(''), function (namePart) {
  51803. var ind = DIRECTION_MAP[namePart];
  51804. rectRange[ind[0]][ind[1]] += localDelta[ind[0]];
  51805. });
  51806. brushOption.range = fromRectRange(formatRectRange(
  51807. rectRange[0][0], rectRange[1][0], rectRange[0][1], rectRange[1][1]
  51808. ));
  51809. updateCoverAfterCreation(controller, cover);
  51810. trigger$1(controller, {isEnd: false});
  51811. }
  51812. function driftPolygon(controller, cover, dx, dy, e) {
  51813. var range = cover.__brushOption.range;
  51814. var localDelta = toLocalDelta(controller, dx, dy);
  51815. each$12(range, function (point) {
  51816. point[0] += localDelta[0];
  51817. point[1] += localDelta[1];
  51818. });
  51819. updateCoverAfterCreation(controller, cover);
  51820. trigger$1(controller, {isEnd: false});
  51821. }
  51822. function toLocalDelta(controller, dx, dy) {
  51823. var thisGroup = controller.group;
  51824. var localD = thisGroup.transformCoordToLocal(dx, dy);
  51825. var localZero = thisGroup.transformCoordToLocal(0, 0);
  51826. return [localD[0] - localZero[0], localD[1] - localZero[1]];
  51827. }
  51828. function clipByPanel(controller, cover, data) {
  51829. var panel = getPanelByCover(controller, cover);
  51830. return (panel && panel !== true)
  51831. ? panel.clipPath(data, controller._transform)
  51832. : clone(data);
  51833. }
  51834. function pointsToRect(points) {
  51835. var xmin = mathMin$6(points[0][0], points[1][0]);
  51836. var ymin = mathMin$6(points[0][1], points[1][1]);
  51837. var xmax = mathMax$6(points[0][0], points[1][0]);
  51838. var ymax = mathMax$6(points[0][1], points[1][1]);
  51839. return {
  51840. x: xmin,
  51841. y: ymin,
  51842. width: xmax - xmin,
  51843. height: ymax - ymin
  51844. };
  51845. }
  51846. function resetCursor(controller, e, localCursorPoint) {
  51847. // Check active
  51848. if (!controller._brushType) {
  51849. return;
  51850. }
  51851. var zr = controller._zr;
  51852. var covers = controller._covers;
  51853. var currPanel = getPanelByPoint(controller, e, localCursorPoint);
  51854. // Check whether in covers.
  51855. if (!controller._dragging) {
  51856. for (var i = 0; i < covers.length; i++) {
  51857. var brushOption = covers[i].__brushOption;
  51858. if (currPanel
  51859. && (currPanel === true || brushOption.panelId === currPanel.panelId)
  51860. && coverRenderers[brushOption.brushType].contain(
  51861. covers[i], localCursorPoint[0], localCursorPoint[1]
  51862. )
  51863. ) {
  51864. // Use cursor style set on cover.
  51865. return;
  51866. }
  51867. }
  51868. }
  51869. currPanel && zr.setCursorStyle('crosshair');
  51870. }
  51871. function preventDefault(e) {
  51872. var rawE = e.event;
  51873. rawE.preventDefault && rawE.preventDefault();
  51874. }
  51875. function mainShapeContain(cover, x, y) {
  51876. return cover.childOfName('main').contain(x, y);
  51877. }
  51878. function updateCoverByMouse(controller, e, localCursorPoint, isEnd) {
  51879. var creatingCover = controller._creatingCover;
  51880. var panel = controller._creatingPanel;
  51881. var thisBrushOption = controller._brushOption;
  51882. var eventParams;
  51883. controller._track.push(localCursorPoint.slice());
  51884. if (shouldShowCover(controller) || creatingCover) {
  51885. if (panel && !creatingCover) {
  51886. thisBrushOption.brushMode === 'single' && clearCovers(controller);
  51887. var brushOption = clone(thisBrushOption);
  51888. brushOption.brushType = determineBrushType(brushOption.brushType, panel);
  51889. brushOption.panelId = panel === true ? null : panel.panelId;
  51890. creatingCover = controller._creatingCover = createCover(controller, brushOption);
  51891. controller._covers.push(creatingCover);
  51892. }
  51893. if (creatingCover) {
  51894. var coverRenderer = coverRenderers[determineBrushType(controller._brushType, panel)];
  51895. var coverBrushOption = creatingCover.__brushOption;
  51896. coverBrushOption.range = coverRenderer.getCreatingRange(
  51897. clipByPanel(controller, creatingCover, controller._track)
  51898. );
  51899. if (isEnd) {
  51900. endCreating(controller, creatingCover);
  51901. coverRenderer.updateCommon(controller, creatingCover);
  51902. }
  51903. updateCoverShape(controller, creatingCover);
  51904. eventParams = {isEnd: isEnd};
  51905. }
  51906. }
  51907. else if (
  51908. isEnd
  51909. && thisBrushOption.brushMode === 'single'
  51910. && thisBrushOption.removeOnClick
  51911. ) {
  51912. // Help user to remove covers easily, only by a tiny drag, in 'single' mode.
  51913. // But a single click do not clear covers, because user may have casual
  51914. // clicks (for example, click on other component and do not expect covers
  51915. // disappear).
  51916. // Only some cover removed, trigger action, but not every click trigger action.
  51917. if (getPanelByPoint(controller, e, localCursorPoint) && clearCovers(controller)) {
  51918. eventParams = {isEnd: isEnd, removeOnClick: true};
  51919. }
  51920. }
  51921. return eventParams;
  51922. }
  51923. function determineBrushType(brushType, panel) {
  51924. if (brushType === 'auto') {
  51925. if (__DEV__) {
  51926. assert$1(
  51927. panel && panel.defaultBrushType,
  51928. 'MUST have defaultBrushType when brushType is "atuo"'
  51929. );
  51930. }
  51931. return panel.defaultBrushType;
  51932. }
  51933. return brushType;
  51934. }
  51935. var mouseHandlers = {
  51936. mousedown: function (e) {
  51937. if (this._dragging) {
  51938. // In case some browser do not support globalOut,
  51939. // and release mose out side the browser.
  51940. handleDragEnd.call(this, e);
  51941. }
  51942. else if (!e.target || !e.target.draggable) {
  51943. preventDefault(e);
  51944. var localCursorPoint = this.group.transformCoordToLocal(e.offsetX, e.offsetY);
  51945. this._creatingCover = null;
  51946. var panel = this._creatingPanel = getPanelByPoint(this, e, localCursorPoint);
  51947. if (panel) {
  51948. this._dragging = true;
  51949. this._track = [localCursorPoint.slice()];
  51950. }
  51951. }
  51952. },
  51953. mousemove: function (e) {
  51954. var localCursorPoint = this.group.transformCoordToLocal(e.offsetX, e.offsetY);
  51955. resetCursor(this, e, localCursorPoint);
  51956. if (this._dragging) {
  51957. preventDefault(e);
  51958. var eventParams = updateCoverByMouse(this, e, localCursorPoint, false);
  51959. eventParams && trigger$1(this, eventParams);
  51960. }
  51961. },
  51962. mouseup: handleDragEnd //,
  51963. // FIXME
  51964. // in tooltip, globalout should not be triggered.
  51965. // globalout: handleDragEnd
  51966. };
  51967. function handleDragEnd(e) {
  51968. if (this._dragging) {
  51969. preventDefault(e);
  51970. var localCursorPoint = this.group.transformCoordToLocal(e.offsetX, e.offsetY);
  51971. var eventParams = updateCoverByMouse(this, e, localCursorPoint, true);
  51972. this._dragging = false;
  51973. this._track = [];
  51974. this._creatingCover = null;
  51975. // trigger event shoule be at final, after procedure will be nested.
  51976. eventParams && trigger$1(this, eventParams);
  51977. }
  51978. }
  51979. /**
  51980. * key: brushType
  51981. * @type {Object}
  51982. */
  51983. var coverRenderers = {
  51984. lineX: getLineRenderer(0),
  51985. lineY: getLineRenderer(1),
  51986. rect: {
  51987. createCover: function (controller, brushOption) {
  51988. return createBaseRectCover(
  51989. curry$2(
  51990. driftRect,
  51991. function (range) {
  51992. return range;
  51993. },
  51994. function (range) {
  51995. return range;
  51996. }
  51997. ),
  51998. controller,
  51999. brushOption,
  52000. ['w', 'e', 'n', 's', 'se', 'sw', 'ne', 'nw']
  52001. );
  52002. },
  52003. getCreatingRange: function (localTrack) {
  52004. var ends = getTrackEnds(localTrack);
  52005. return formatRectRange(ends[1][0], ends[1][1], ends[0][0], ends[0][1]);
  52006. },
  52007. updateCoverShape: function (controller, cover, localRange, brushOption) {
  52008. updateBaseRect(controller, cover, localRange, brushOption);
  52009. },
  52010. updateCommon: updateCommon,
  52011. contain: mainShapeContain
  52012. },
  52013. polygon: {
  52014. createCover: function (controller, brushOption) {
  52015. var cover = new Group();
  52016. // Do not use graphic.Polygon because graphic.Polyline do not close the
  52017. // border of the shape when drawing, which is a better experience for user.
  52018. cover.add(new Polyline({
  52019. name: 'main',
  52020. style: makeStyle(brushOption),
  52021. silent: true
  52022. }));
  52023. return cover;
  52024. },
  52025. getCreatingRange: function (localTrack) {
  52026. return localTrack;
  52027. },
  52028. endCreating: function (controller, cover) {
  52029. cover.remove(cover.childAt(0));
  52030. // Use graphic.Polygon close the shape.
  52031. cover.add(new Polygon({
  52032. name: 'main',
  52033. draggable: true,
  52034. drift: curry$2(driftPolygon, controller, cover),
  52035. ondragend: curry$2(trigger$1, controller, {isEnd: true})
  52036. }));
  52037. },
  52038. updateCoverShape: function (controller, cover, localRange, brushOption) {
  52039. cover.childAt(0).setShape({
  52040. points: clipByPanel(controller, cover, localRange)
  52041. });
  52042. },
  52043. updateCommon: updateCommon,
  52044. contain: mainShapeContain
  52045. }
  52046. };
  52047. function getLineRenderer(xyIndex) {
  52048. return {
  52049. createCover: function (controller, brushOption) {
  52050. return createBaseRectCover(
  52051. curry$2(
  52052. driftRect,
  52053. function (range) {
  52054. var rectRange = [range, [0, 100]];
  52055. xyIndex && rectRange.reverse();
  52056. return rectRange;
  52057. },
  52058. function (rectRange) {
  52059. return rectRange[xyIndex];
  52060. }
  52061. ),
  52062. controller,
  52063. brushOption,
  52064. [['w', 'e'], ['n', 's']][xyIndex]
  52065. );
  52066. },
  52067. getCreatingRange: function (localTrack) {
  52068. var ends = getTrackEnds(localTrack);
  52069. var min = mathMin$6(ends[0][xyIndex], ends[1][xyIndex]);
  52070. var max = mathMax$6(ends[0][xyIndex], ends[1][xyIndex]);
  52071. return [min, max];
  52072. },
  52073. updateCoverShape: function (controller, cover, localRange, brushOption) {
  52074. var otherExtent;
  52075. // If brushWidth not specified, fit the panel.
  52076. var panel = getPanelByCover(controller, cover);
  52077. if (panel !== true && panel.getLinearBrushOtherExtent) {
  52078. otherExtent = panel.getLinearBrushOtherExtent(
  52079. xyIndex, controller._transform
  52080. );
  52081. }
  52082. else {
  52083. var zr = controller._zr;
  52084. otherExtent = [0, [zr.getWidth(), zr.getHeight()][1 - xyIndex]];
  52085. }
  52086. var rectRange = [localRange, otherExtent];
  52087. xyIndex && rectRange.reverse();
  52088. updateBaseRect(controller, cover, rectRange, brushOption);
  52089. },
  52090. updateCommon: updateCommon,
  52091. contain: mainShapeContain
  52092. };
  52093. }
  52094. /*
  52095. * Licensed to the Apache Software Foundation (ASF) under one
  52096. * or more contributor license agreements. See the NOTICE file
  52097. * distributed with this work for additional information
  52098. * regarding copyright ownership. The ASF licenses this file
  52099. * to you under the Apache License, Version 2.0 (the
  52100. * "License"); you may not use this file except in compliance
  52101. * with the License. You may obtain a copy of the License at
  52102. *
  52103. * http://www.apache.org/licenses/LICENSE-2.0
  52104. *
  52105. * Unless required by applicable law or agreed to in writing,
  52106. * software distributed under the License is distributed on an
  52107. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  52108. * KIND, either express or implied. See the License for the
  52109. * specific language governing permissions and limitations
  52110. * under the License.
  52111. */
  52112. function makeRectPanelClipPath(rect) {
  52113. rect = normalizeRect(rect);
  52114. return function (localPoints, transform) {
  52115. return clipPointsByRect(localPoints, rect);
  52116. };
  52117. }
  52118. function makeLinearBrushOtherExtent(rect, specifiedXYIndex) {
  52119. rect = normalizeRect(rect);
  52120. return function (xyIndex) {
  52121. var idx = specifiedXYIndex != null ? specifiedXYIndex : xyIndex;
  52122. var brushWidth = idx ? rect.width : rect.height;
  52123. var base = idx ? rect.x : rect.y;
  52124. return [base, base + (brushWidth || 0)];
  52125. };
  52126. }
  52127. function makeRectIsTargetByCursor(rect, api, targetModel) {
  52128. rect = normalizeRect(rect);
  52129. return function (e, localCursorPoint, transform) {
  52130. return rect.contain(localCursorPoint[0], localCursorPoint[1])
  52131. && !onIrrelevantElement(e, api, targetModel);
  52132. };
  52133. }
  52134. // Consider width/height is negative.
  52135. function normalizeRect(rect) {
  52136. return BoundingRect.create(rect);
  52137. }
  52138. /*
  52139. * Licensed to the Apache Software Foundation (ASF) under one
  52140. * or more contributor license agreements. See the NOTICE file
  52141. * distributed with this work for additional information
  52142. * regarding copyright ownership. The ASF licenses this file
  52143. * to you under the Apache License, Version 2.0 (the
  52144. * "License"); you may not use this file except in compliance
  52145. * with the License. You may obtain a copy of the License at
  52146. *
  52147. * http://www.apache.org/licenses/LICENSE-2.0
  52148. *
  52149. * Unless required by applicable law or agreed to in writing,
  52150. * software distributed under the License is distributed on an
  52151. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  52152. * KIND, either express or implied. See the License for the
  52153. * specific language governing permissions and limitations
  52154. * under the License.
  52155. */
  52156. var elementList = ['axisLine', 'axisTickLabel', 'axisName'];
  52157. var AxisView$2 = extendComponentView({
  52158. type: 'parallelAxis',
  52159. /**
  52160. * @override
  52161. */
  52162. init: function (ecModel, api) {
  52163. AxisView$2.superApply(this, 'init', arguments);
  52164. /**
  52165. * @type {module:echarts/component/helper/BrushController}
  52166. */
  52167. (this._brushController = new BrushController(api.getZr()))
  52168. .on('brush', bind(this._onBrush, this));
  52169. },
  52170. /**
  52171. * @override
  52172. */
  52173. render: function (axisModel, ecModel, api, payload) {
  52174. if (fromAxisAreaSelect(axisModel, ecModel, payload)) {
  52175. return;
  52176. }
  52177. this.axisModel = axisModel;
  52178. this.api = api;
  52179. this.group.removeAll();
  52180. var oldAxisGroup = this._axisGroup;
  52181. this._axisGroup = new Group();
  52182. this.group.add(this._axisGroup);
  52183. if (!axisModel.get('show')) {
  52184. return;
  52185. }
  52186. var coordSysModel = getCoordSysModel(axisModel, ecModel);
  52187. var coordSys = coordSysModel.coordinateSystem;
  52188. var areaSelectStyle = axisModel.getAreaSelectStyle();
  52189. var areaWidth = areaSelectStyle.width;
  52190. var dim = axisModel.axis.dim;
  52191. var axisLayout = coordSys.getAxisLayout(dim);
  52192. var builderOpt = extend(
  52193. {strokeContainThreshold: areaWidth},
  52194. axisLayout
  52195. );
  52196. var axisBuilder = new AxisBuilder(axisModel, builderOpt);
  52197. each$1(elementList, axisBuilder.add, axisBuilder);
  52198. this._axisGroup.add(axisBuilder.getGroup());
  52199. this._refreshBrushController(
  52200. builderOpt, areaSelectStyle, axisModel, coordSysModel, areaWidth, api
  52201. );
  52202. var animationModel = (payload && payload.animation === false) ? null : axisModel;
  52203. groupTransition(oldAxisGroup, this._axisGroup, animationModel);
  52204. },
  52205. // /**
  52206. // * @override
  52207. // */
  52208. // updateVisual: function (axisModel, ecModel, api, payload) {
  52209. // this._brushController && this._brushController
  52210. // .updateCovers(getCoverInfoList(axisModel));
  52211. // },
  52212. _refreshBrushController: function (
  52213. builderOpt, areaSelectStyle, axisModel, coordSysModel, areaWidth, api
  52214. ) {
  52215. // After filtering, axis may change, select area needs to be update.
  52216. var extent = axisModel.axis.getExtent();
  52217. var extentLen = extent[1] - extent[0];
  52218. var extra = Math.min(30, Math.abs(extentLen) * 0.1); // Arbitrary value.
  52219. // width/height might be negative, which will be
  52220. // normalized in BoundingRect.
  52221. var rect = BoundingRect.create({
  52222. x: extent[0],
  52223. y: -areaWidth / 2,
  52224. width: extentLen,
  52225. height: areaWidth
  52226. });
  52227. rect.x -= extra;
  52228. rect.width += 2 * extra;
  52229. this._brushController
  52230. .mount({
  52231. enableGlobalPan: true,
  52232. rotation: builderOpt.rotation,
  52233. position: builderOpt.position
  52234. })
  52235. .setPanels([{
  52236. panelId: 'pl',
  52237. clipPath: makeRectPanelClipPath(rect),
  52238. isTargetByCursor: makeRectIsTargetByCursor(rect, api, coordSysModel),
  52239. getLinearBrushOtherExtent: makeLinearBrushOtherExtent(rect, 0)
  52240. }])
  52241. .enableBrush({
  52242. brushType: 'lineX',
  52243. brushStyle: areaSelectStyle,
  52244. removeOnClick: true
  52245. })
  52246. .updateCovers(getCoverInfoList(axisModel));
  52247. },
  52248. _onBrush: function (coverInfoList, opt) {
  52249. // Do not cache these object, because the mey be changed.
  52250. var axisModel = this.axisModel;
  52251. var axis = axisModel.axis;
  52252. var intervals = map(coverInfoList, function (coverInfo) {
  52253. return [
  52254. axis.coordToData(coverInfo.range[0], true),
  52255. axis.coordToData(coverInfo.range[1], true)
  52256. ];
  52257. });
  52258. // If realtime is true, action is not dispatched on drag end, because
  52259. // the drag end emits the same params with the last drag move event,
  52260. // and may have some delay when using touch pad.
  52261. if (!axisModel.option.realtime === opt.isEnd || opt.removeOnClick) { // jshint ignore:line
  52262. this.api.dispatchAction({
  52263. type: 'axisAreaSelect',
  52264. parallelAxisId: axisModel.id,
  52265. intervals: intervals
  52266. });
  52267. }
  52268. },
  52269. /**
  52270. * @override
  52271. */
  52272. dispose: function () {
  52273. this._brushController.dispose();
  52274. }
  52275. });
  52276. function fromAxisAreaSelect(axisModel, ecModel, payload) {
  52277. return payload
  52278. && payload.type === 'axisAreaSelect'
  52279. && ecModel.findComponents(
  52280. {mainType: 'parallelAxis', query: payload}
  52281. )[0] === axisModel;
  52282. }
  52283. function getCoverInfoList(axisModel) {
  52284. var axis = axisModel.axis;
  52285. return map(axisModel.activeIntervals, function (interval) {
  52286. return {
  52287. brushType: 'lineX',
  52288. panelId: 'pl',
  52289. range: [
  52290. axis.dataToCoord(interval[0], true),
  52291. axis.dataToCoord(interval[1], true)
  52292. ]
  52293. };
  52294. });
  52295. }
  52296. function getCoordSysModel(axisModel, ecModel) {
  52297. return ecModel.getComponent(
  52298. 'parallel', axisModel.get('parallelIndex')
  52299. );
  52300. }
  52301. /*
  52302. * Licensed to the Apache Software Foundation (ASF) under one
  52303. * or more contributor license agreements. See the NOTICE file
  52304. * distributed with this work for additional information
  52305. * regarding copyright ownership. The ASF licenses this file
  52306. * to you under the Apache License, Version 2.0 (the
  52307. * "License"); you may not use this file except in compliance
  52308. * with the License. You may obtain a copy of the License at
  52309. *
  52310. * http://www.apache.org/licenses/LICENSE-2.0
  52311. *
  52312. * Unless required by applicable law or agreed to in writing,
  52313. * software distributed under the License is distributed on an
  52314. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  52315. * KIND, either express or implied. See the License for the
  52316. * specific language governing permissions and limitations
  52317. * under the License.
  52318. */
  52319. /*
  52320. * Licensed to the Apache Software Foundation (ASF) under one
  52321. * or more contributor license agreements. See the NOTICE file
  52322. * distributed with this work for additional information
  52323. * regarding copyright ownership. The ASF licenses this file
  52324. * to you under the Apache License, Version 2.0 (the
  52325. * "License"); you may not use this file except in compliance
  52326. * with the License. You may obtain a copy of the License at
  52327. *
  52328. * http://www.apache.org/licenses/LICENSE-2.0
  52329. *
  52330. * Unless required by applicable law or agreed to in writing,
  52331. * software distributed under the License is distributed on an
  52332. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  52333. * KIND, either express or implied. See the License for the
  52334. * specific language governing permissions and limitations
  52335. * under the License.
  52336. */
  52337. var CLICK_THRESHOLD = 5; // > 4
  52338. // Parallel view
  52339. extendComponentView({
  52340. type: 'parallel',
  52341. render: function (parallelModel, ecModel, api) {
  52342. this._model = parallelModel;
  52343. this._api = api;
  52344. if (!this._handlers) {
  52345. this._handlers = {};
  52346. each$1(handlers, function (handler, eventName) {
  52347. api.getZr().on(eventName, this._handlers[eventName] = bind(handler, this));
  52348. }, this);
  52349. }
  52350. createOrUpdate(
  52351. this,
  52352. '_throttledDispatchExpand',
  52353. parallelModel.get('axisExpandRate'),
  52354. 'fixRate'
  52355. );
  52356. },
  52357. dispose: function (ecModel, api) {
  52358. each$1(this._handlers, function (handler, eventName) {
  52359. api.getZr().off(eventName, handler);
  52360. });
  52361. this._handlers = null;
  52362. },
  52363. /**
  52364. * @param {Object} [opt] If null, cancle the last action triggering for debounce.
  52365. */
  52366. _throttledDispatchExpand: function (opt) {
  52367. this._dispatchExpand(opt);
  52368. },
  52369. _dispatchExpand: function (opt) {
  52370. opt && this._api.dispatchAction(
  52371. extend({type: 'parallelAxisExpand'}, opt)
  52372. );
  52373. }
  52374. });
  52375. var handlers = {
  52376. mousedown: function (e) {
  52377. if (checkTrigger(this, 'click')) {
  52378. this._mouseDownPoint = [e.offsetX, e.offsetY];
  52379. }
  52380. },
  52381. mouseup: function (e) {
  52382. var mouseDownPoint = this._mouseDownPoint;
  52383. if (checkTrigger(this, 'click') && mouseDownPoint) {
  52384. var point = [e.offsetX, e.offsetY];
  52385. var dist = Math.pow(mouseDownPoint[0] - point[0], 2)
  52386. + Math.pow(mouseDownPoint[1] - point[1], 2);
  52387. if (dist > CLICK_THRESHOLD) {
  52388. return;
  52389. }
  52390. var result = this._model.coordinateSystem.getSlidedAxisExpandWindow(
  52391. [e.offsetX, e.offsetY]
  52392. );
  52393. result.behavior !== 'none' && this._dispatchExpand({
  52394. axisExpandWindow: result.axisExpandWindow
  52395. });
  52396. }
  52397. this._mouseDownPoint = null;
  52398. },
  52399. mousemove: function (e) {
  52400. // Should do nothing when brushing.
  52401. if (this._mouseDownPoint || !checkTrigger(this, 'mousemove')) {
  52402. return;
  52403. }
  52404. var model = this._model;
  52405. var result = model.coordinateSystem.getSlidedAxisExpandWindow(
  52406. [e.offsetX, e.offsetY]
  52407. );
  52408. var behavior = result.behavior;
  52409. behavior === 'jump' && this._throttledDispatchExpand.debounceNextCall(model.get('axisExpandDebounce'));
  52410. this._throttledDispatchExpand(
  52411. behavior === 'none'
  52412. ? null // Cancle the last trigger, in case that mouse slide out of the area quickly.
  52413. : {
  52414. axisExpandWindow: result.axisExpandWindow,
  52415. // Jumping uses animation, and sliding suppresses animation.
  52416. animation: behavior === 'jump' ? null : false
  52417. }
  52418. );
  52419. }
  52420. };
  52421. function checkTrigger(view, triggerOn) {
  52422. var model = view._model;
  52423. return model.get('axisExpandable') && model.get('axisExpandTriggerOn') === triggerOn;
  52424. }
  52425. registerPreprocessor(parallelPreprocessor);
  52426. /*
  52427. * Licensed to the Apache Software Foundation (ASF) under one
  52428. * or more contributor license agreements. See the NOTICE file
  52429. * distributed with this work for additional information
  52430. * regarding copyright ownership. The ASF licenses this file
  52431. * to you under the Apache License, Version 2.0 (the
  52432. * "License"); you may not use this file except in compliance
  52433. * with the License. You may obtain a copy of the License at
  52434. *
  52435. * http://www.apache.org/licenses/LICENSE-2.0
  52436. *
  52437. * Unless required by applicable law or agreed to in writing,
  52438. * software distributed under the License is distributed on an
  52439. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  52440. * KIND, either express or implied. See the License for the
  52441. * specific language governing permissions and limitations
  52442. * under the License.
  52443. */
  52444. SeriesModel.extend({
  52445. type: 'series.parallel',
  52446. dependencies: ['parallel'],
  52447. visualColorAccessPath: 'lineStyle.color',
  52448. getInitialData: function (option, ecModel) {
  52449. var source = this.getSource();
  52450. setEncodeAndDimensions(source, this);
  52451. return createListFromArray(source, this);
  52452. },
  52453. /**
  52454. * User can get data raw indices on 'axisAreaSelected' event received.
  52455. *
  52456. * @public
  52457. * @param {string} activeState 'active' or 'inactive' or 'normal'
  52458. * @return {Array.<number>} Raw indices
  52459. */
  52460. getRawIndicesByActiveState: function (activeState) {
  52461. var coordSys = this.coordinateSystem;
  52462. var data = this.getData();
  52463. var indices = [];
  52464. coordSys.eachActiveState(data, function (theActiveState, dataIndex) {
  52465. if (activeState === theActiveState) {
  52466. indices.push(data.getRawIndex(dataIndex));
  52467. }
  52468. });
  52469. return indices;
  52470. },
  52471. defaultOption: {
  52472. zlevel: 0, // 一级层叠
  52473. z: 2, // 二级层叠
  52474. coordinateSystem: 'parallel',
  52475. parallelIndex: 0,
  52476. label: {
  52477. show: false
  52478. },
  52479. inactiveOpacity: 0.05,
  52480. activeOpacity: 1,
  52481. lineStyle: {
  52482. width: 1,
  52483. opacity: 0.45,
  52484. type: 'solid'
  52485. },
  52486. emphasis: {
  52487. label: {
  52488. show: false
  52489. }
  52490. },
  52491. progressive: 500,
  52492. smooth: false, // true | false | number
  52493. animationEasing: 'linear'
  52494. }
  52495. });
  52496. function setEncodeAndDimensions(source, seriesModel) {
  52497. // The mapping of parallelAxis dimension to data dimension can
  52498. // be specified in parallelAxis.option.dim. For example, if
  52499. // parallelAxis.option.dim is 'dim3', it mapping to the third
  52500. // dimension of data. But `data.encode` has higher priority.
  52501. // Moreover, parallelModel.dimension should not be regarded as data
  52502. // dimensions. Consider dimensions = ['dim4', 'dim2', 'dim6'];
  52503. if (source.encodeDefine) {
  52504. return;
  52505. }
  52506. var parallelModel = seriesModel.ecModel.getComponent(
  52507. 'parallel', seriesModel.get('parallelIndex')
  52508. );
  52509. if (!parallelModel) {
  52510. return;
  52511. }
  52512. var encodeDefine = source.encodeDefine = createHashMap();
  52513. each$1(parallelModel.dimensions, function (axisDim) {
  52514. var dataDimIndex = convertDimNameToNumber(axisDim);
  52515. encodeDefine.set(axisDim, dataDimIndex);
  52516. });
  52517. }
  52518. function convertDimNameToNumber(dimName) {
  52519. return +dimName.replace('dim', '');
  52520. }
  52521. /*
  52522. * Licensed to the Apache Software Foundation (ASF) under one
  52523. * or more contributor license agreements. See the NOTICE file
  52524. * distributed with this work for additional information
  52525. * regarding copyright ownership. The ASF licenses this file
  52526. * to you under the Apache License, Version 2.0 (the
  52527. * "License"); you may not use this file except in compliance
  52528. * with the License. You may obtain a copy of the License at
  52529. *
  52530. * http://www.apache.org/licenses/LICENSE-2.0
  52531. *
  52532. * Unless required by applicable law or agreed to in writing,
  52533. * software distributed under the License is distributed on an
  52534. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  52535. * KIND, either express or implied. See the License for the
  52536. * specific language governing permissions and limitations
  52537. * under the License.
  52538. */
  52539. var DEFAULT_SMOOTH = 0.3;
  52540. var ParallelView = Chart.extend({
  52541. type: 'parallel',
  52542. init: function () {
  52543. /**
  52544. * @type {module:zrender/container/Group}
  52545. * @private
  52546. */
  52547. this._dataGroup = new Group();
  52548. this.group.add(this._dataGroup);
  52549. /**
  52550. * @type {module:echarts/data/List}
  52551. */
  52552. this._data;
  52553. /**
  52554. * @type {boolean}
  52555. */
  52556. this._initialized;
  52557. },
  52558. /**
  52559. * @override
  52560. */
  52561. render: function (seriesModel, ecModel, api, payload) {
  52562. var dataGroup = this._dataGroup;
  52563. var data = seriesModel.getData();
  52564. var oldData = this._data;
  52565. var coordSys = seriesModel.coordinateSystem;
  52566. var dimensions = coordSys.dimensions;
  52567. var seriesScope = makeSeriesScope$2(seriesModel);
  52568. data.diff(oldData)
  52569. .add(add)
  52570. .update(update)
  52571. .remove(remove)
  52572. .execute();
  52573. function add(newDataIndex) {
  52574. var line = addEl(data, dataGroup, newDataIndex, dimensions, coordSys);
  52575. updateElCommon(line, data, newDataIndex, seriesScope);
  52576. }
  52577. function update(newDataIndex, oldDataIndex) {
  52578. var line = oldData.getItemGraphicEl(oldDataIndex);
  52579. var points = createLinePoints(data, newDataIndex, dimensions, coordSys);
  52580. data.setItemGraphicEl(newDataIndex, line);
  52581. var animationModel = (payload && payload.animation === false) ? null : seriesModel;
  52582. updateProps(line, {shape: {points: points}}, animationModel, newDataIndex);
  52583. updateElCommon(line, data, newDataIndex, seriesScope);
  52584. }
  52585. function remove(oldDataIndex) {
  52586. var line = oldData.getItemGraphicEl(oldDataIndex);
  52587. dataGroup.remove(line);
  52588. }
  52589. // First create
  52590. if (!this._initialized) {
  52591. this._initialized = true;
  52592. var clipPath = createGridClipShape$1(
  52593. coordSys, seriesModel, function () {
  52594. // Callback will be invoked immediately if there is no animation
  52595. setTimeout(function () {
  52596. dataGroup.removeClipPath();
  52597. });
  52598. }
  52599. );
  52600. dataGroup.setClipPath(clipPath);
  52601. }
  52602. this._data = data;
  52603. },
  52604. incrementalPrepareRender: function (seriesModel, ecModel, api) {
  52605. this._initialized = true;
  52606. this._data = null;
  52607. this._dataGroup.removeAll();
  52608. },
  52609. incrementalRender: function (taskParams, seriesModel, ecModel) {
  52610. var data = seriesModel.getData();
  52611. var coordSys = seriesModel.coordinateSystem;
  52612. var dimensions = coordSys.dimensions;
  52613. var seriesScope = makeSeriesScope$2(seriesModel);
  52614. for (var dataIndex = taskParams.start; dataIndex < taskParams.end; dataIndex++) {
  52615. var line = addEl(data, this._dataGroup, dataIndex, dimensions, coordSys);
  52616. line.incremental = true;
  52617. updateElCommon(line, data, dataIndex, seriesScope);
  52618. }
  52619. },
  52620. dispose: function () {},
  52621. // _renderForProgressive: function (seriesModel) {
  52622. // var dataGroup = this._dataGroup;
  52623. // var data = seriesModel.getData();
  52624. // var oldData = this._data;
  52625. // var coordSys = seriesModel.coordinateSystem;
  52626. // var dimensions = coordSys.dimensions;
  52627. // var option = seriesModel.option;
  52628. // var progressive = option.progressive;
  52629. // var smooth = option.smooth ? SMOOTH : null;
  52630. // // In progressive animation is disabled, so use simple data diff,
  52631. // // which effects performance less.
  52632. // // (Typically performance for data with length 7000+ like:
  52633. // // simpleDiff: 60ms, addEl: 184ms,
  52634. // // in RMBP 2.4GHz intel i7, OSX 10.9 chrome 50.0.2661.102 (64-bit))
  52635. // if (simpleDiff(oldData, data, dimensions)) {
  52636. // dataGroup.removeAll();
  52637. // data.each(function (dataIndex) {
  52638. // addEl(data, dataGroup, dataIndex, dimensions, coordSys);
  52639. // });
  52640. // }
  52641. // updateElCommon(data, progressive, smooth);
  52642. // // Consider switch between progressive and not.
  52643. // data.__plProgressive = true;
  52644. // this._data = data;
  52645. // },
  52646. /**
  52647. * @override
  52648. */
  52649. remove: function () {
  52650. this._dataGroup && this._dataGroup.removeAll();
  52651. this._data = null;
  52652. }
  52653. });
  52654. function createGridClipShape$1(coordSys, seriesModel, cb) {
  52655. var parallelModel = coordSys.model;
  52656. var rect = coordSys.getRect();
  52657. var rectEl = new Rect({
  52658. shape: {
  52659. x: rect.x,
  52660. y: rect.y,
  52661. width: rect.width,
  52662. height: rect.height
  52663. }
  52664. });
  52665. var dim = parallelModel.get('layout') === 'horizontal' ? 'width' : 'height';
  52666. rectEl.setShape(dim, 0);
  52667. initProps(rectEl, {
  52668. shape: {
  52669. width: rect.width,
  52670. height: rect.height
  52671. }
  52672. }, seriesModel, cb);
  52673. return rectEl;
  52674. }
  52675. function createLinePoints(data, dataIndex, dimensions, coordSys) {
  52676. var points = [];
  52677. for (var i = 0; i < dimensions.length; i++) {
  52678. var dimName = dimensions[i];
  52679. var value = data.get(data.mapDimension(dimName), dataIndex);
  52680. if (!isEmptyValue(value, coordSys.getAxis(dimName).type)) {
  52681. points.push(coordSys.dataToPoint(value, dimName));
  52682. }
  52683. }
  52684. return points;
  52685. }
  52686. function addEl(data, dataGroup, dataIndex, dimensions, coordSys) {
  52687. var points = createLinePoints(data, dataIndex, dimensions, coordSys);
  52688. var line = new Polyline({
  52689. shape: {points: points},
  52690. silent: true,
  52691. z2: 10
  52692. });
  52693. dataGroup.add(line);
  52694. data.setItemGraphicEl(dataIndex, line);
  52695. return line;
  52696. }
  52697. function makeSeriesScope$2(seriesModel) {
  52698. var smooth = seriesModel.get('smooth', true);
  52699. smooth === true && (smooth = DEFAULT_SMOOTH);
  52700. return {
  52701. lineStyle: seriesModel.getModel('lineStyle').getLineStyle(),
  52702. smooth: smooth != null ? smooth : DEFAULT_SMOOTH
  52703. };
  52704. }
  52705. function updateElCommon(el, data, dataIndex, seriesScope) {
  52706. var lineStyle = seriesScope.lineStyle;
  52707. if (data.hasItemOption) {
  52708. var lineStyleModel = data.getItemModel(dataIndex).getModel('lineStyle');
  52709. lineStyle = lineStyleModel.getLineStyle();
  52710. }
  52711. el.useStyle(lineStyle);
  52712. var elStyle = el.style;
  52713. elStyle.fill = null;
  52714. // lineStyle.color have been set to itemVisual in module:echarts/visual/seriesColor.
  52715. elStyle.stroke = data.getItemVisual(dataIndex, 'color');
  52716. // lineStyle.opacity have been set to itemVisual in parallelVisual.
  52717. elStyle.opacity = data.getItemVisual(dataIndex, 'opacity');
  52718. seriesScope.smooth && (el.shape.smooth = seriesScope.smooth);
  52719. }
  52720. // function simpleDiff(oldData, newData, dimensions) {
  52721. // var oldLen;
  52722. // if (!oldData
  52723. // || !oldData.__plProgressive
  52724. // || (oldLen = oldData.count()) !== newData.count()
  52725. // ) {
  52726. // return true;
  52727. // }
  52728. // var dimLen = dimensions.length;
  52729. // for (var i = 0; i < oldLen; i++) {
  52730. // for (var j = 0; j < dimLen; j++) {
  52731. // if (oldData.get(dimensions[j], i) !== newData.get(dimensions[j], i)) {
  52732. // return true;
  52733. // }
  52734. // }
  52735. // }
  52736. // return false;
  52737. // }
  52738. // FIXME
  52739. // 公用方法?
  52740. function isEmptyValue(val, axisType) {
  52741. return axisType === 'category'
  52742. ? val == null
  52743. : (val == null || isNaN(val)); // axisType === 'value'
  52744. }
  52745. /*
  52746. * Licensed to the Apache Software Foundation (ASF) under one
  52747. * or more contributor license agreements. See the NOTICE file
  52748. * distributed with this work for additional information
  52749. * regarding copyright ownership. The ASF licenses this file
  52750. * to you under the Apache License, Version 2.0 (the
  52751. * "License"); you may not use this file except in compliance
  52752. * with the License. You may obtain a copy of the License at
  52753. *
  52754. * http://www.apache.org/licenses/LICENSE-2.0
  52755. *
  52756. * Unless required by applicable law or agreed to in writing,
  52757. * software distributed under the License is distributed on an
  52758. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  52759. * KIND, either express or implied. See the License for the
  52760. * specific language governing permissions and limitations
  52761. * under the License.
  52762. */
  52763. var opacityAccessPath$1 = ['lineStyle', 'normal', 'opacity'];
  52764. var parallelVisual = {
  52765. seriesType: 'parallel',
  52766. reset: function (seriesModel, ecModel, api) {
  52767. var itemStyleModel = seriesModel.getModel('itemStyle');
  52768. var lineStyleModel = seriesModel.getModel('lineStyle');
  52769. var globalColors = ecModel.get('color');
  52770. var color = lineStyleModel.get('color')
  52771. || itemStyleModel.get('color')
  52772. || globalColors[seriesModel.seriesIndex % globalColors.length];
  52773. var inactiveOpacity = seriesModel.get('inactiveOpacity');
  52774. var activeOpacity = seriesModel.get('activeOpacity');
  52775. var lineStyle = seriesModel.getModel('lineStyle').getLineStyle();
  52776. var coordSys = seriesModel.coordinateSystem;
  52777. var data = seriesModel.getData();
  52778. var opacityMap = {
  52779. normal: lineStyle.opacity,
  52780. active: activeOpacity,
  52781. inactive: inactiveOpacity
  52782. };
  52783. data.setVisual('color', color);
  52784. function progress(params, data) {
  52785. coordSys.eachActiveState(data, function (activeState, dataIndex) {
  52786. var opacity = opacityMap[activeState];
  52787. if (activeState === 'normal' && data.hasItemOption) {
  52788. var itemOpacity = data.getItemModel(dataIndex).get(opacityAccessPath$1, true);
  52789. itemOpacity != null && (opacity = itemOpacity);
  52790. }
  52791. data.setItemVisual(dataIndex, 'opacity', opacity);
  52792. }, params.start, params.end);
  52793. }
  52794. return {progress: progress};
  52795. }
  52796. };
  52797. /*
  52798. * Licensed to the Apache Software Foundation (ASF) under one
  52799. * or more contributor license agreements. See the NOTICE file
  52800. * distributed with this work for additional information
  52801. * regarding copyright ownership. The ASF licenses this file
  52802. * to you under the Apache License, Version 2.0 (the
  52803. * "License"); you may not use this file except in compliance
  52804. * with the License. You may obtain a copy of the License at
  52805. *
  52806. * http://www.apache.org/licenses/LICENSE-2.0
  52807. *
  52808. * Unless required by applicable law or agreed to in writing,
  52809. * software distributed under the License is distributed on an
  52810. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  52811. * KIND, either express or implied. See the License for the
  52812. * specific language governing permissions and limitations
  52813. * under the License.
  52814. */
  52815. registerVisual(parallelVisual);
  52816. /*
  52817. * Licensed to the Apache Software Foundation (ASF) under one
  52818. * or more contributor license agreements. See the NOTICE file
  52819. * distributed with this work for additional information
  52820. * regarding copyright ownership. The ASF licenses this file
  52821. * to you under the Apache License, Version 2.0 (the
  52822. * "License"); you may not use this file except in compliance
  52823. * with the License. You may obtain a copy of the License at
  52824. *
  52825. * http://www.apache.org/licenses/LICENSE-2.0
  52826. *
  52827. * Unless required by applicable law or agreed to in writing,
  52828. * software distributed under the License is distributed on an
  52829. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  52830. * KIND, either express or implied. See the License for the
  52831. * specific language governing permissions and limitations
  52832. * under the License.
  52833. */
  52834. var SankeySeries = SeriesModel.extend({
  52835. type: 'series.sankey',
  52836. layoutInfo: null,
  52837. levelModels: null,
  52838. /**
  52839. * Init a graph data structure from data in option series
  52840. *
  52841. * @param {Object} option the object used to config echarts view
  52842. * @return {module:echarts/data/List} storage initial data
  52843. */
  52844. getInitialData: function (option, ecModel) {
  52845. var links = option.edges || option.links;
  52846. var nodes = option.data || option.nodes;
  52847. var levels = option.levels;
  52848. var levelModels = this.levelModels = {};
  52849. for (var i = 0; i < levels.length; i++) {
  52850. if (levels[i].depth != null && levels[i].depth >= 0) {
  52851. levelModels[levels[i].depth] = new Model(levels[i], this, ecModel);
  52852. }
  52853. else {
  52854. if (__DEV__) {
  52855. throw new Error('levels[i].depth is mandatory and should be natural number');
  52856. }
  52857. }
  52858. }
  52859. if (nodes && links) {
  52860. var graph = createGraphFromNodeEdge(nodes, links, this, true, beforeLink);
  52861. return graph.data;
  52862. }
  52863. function beforeLink(nodeData, edgeData) {
  52864. nodeData.wrapMethod('getItemModel', function (model, idx) {
  52865. model.customizeGetParent(function (path) {
  52866. var parentModel = this.parentModel;
  52867. var nodeDepth = parentModel.getData().getItemLayout(idx).depth;
  52868. var levelModel = parentModel.levelModels[nodeDepth];
  52869. return levelModel || this.parentModel;
  52870. });
  52871. return model;
  52872. });
  52873. edgeData.wrapMethod('getItemModel', function (model, idx) {
  52874. model.customizeGetParent(function (path) {
  52875. var parentModel = this.parentModel;
  52876. var edge = parentModel.getGraph().getEdgeByIndex(idx);
  52877. var depth = edge.node1.getLayout().depth;
  52878. var levelModel = parentModel.levelModels[depth];
  52879. return levelModel || this.parentModel;
  52880. });
  52881. return model;
  52882. });
  52883. }
  52884. },
  52885. setNodePosition: function (dataIndex, localPosition) {
  52886. var dataItem = this.option.data[dataIndex];
  52887. dataItem.localX = localPosition[0];
  52888. dataItem.localY = localPosition[1];
  52889. },
  52890. /**
  52891. * Return the graphic data structure
  52892. *
  52893. * @return {module:echarts/data/Graph} graphic data structure
  52894. */
  52895. getGraph: function () {
  52896. return this.getData().graph;
  52897. },
  52898. /**
  52899. * Get edge data of graphic data structure
  52900. *
  52901. * @return {module:echarts/data/List} data structure of list
  52902. */
  52903. getEdgeData: function () {
  52904. return this.getGraph().edgeData;
  52905. },
  52906. /**
  52907. * @override
  52908. */
  52909. formatTooltip: function (dataIndex, multipleSeries, dataType) {
  52910. // dataType === 'node' or empty do not show tooltip by default
  52911. if (dataType === 'edge') {
  52912. var params = this.getDataParams(dataIndex, dataType);
  52913. var rawDataOpt = params.data;
  52914. var html = rawDataOpt.source + ' -- ' + rawDataOpt.target;
  52915. if (params.value) {
  52916. html += ' : ' + params.value;
  52917. }
  52918. return encodeHTML(html);
  52919. }
  52920. else if (dataType === 'node') {
  52921. var node = this.getGraph().getNodeByIndex(dataIndex);
  52922. var value = node.getLayout().value;
  52923. var name = this.getDataParams(dataIndex, dataType).data.name;
  52924. if (value) {
  52925. var html = name + ' : ' + value;
  52926. }
  52927. return encodeHTML(html);
  52928. }
  52929. return SankeySeries.superCall(this, 'formatTooltip', dataIndex, multipleSeries);
  52930. },
  52931. optionUpdated: function () {
  52932. var option = this.option;
  52933. if (option.focusNodeAdjacency === true) {
  52934. option.focusNodeAdjacency = 'allEdges';
  52935. }
  52936. },
  52937. defaultOption: {
  52938. zlevel: 0,
  52939. z: 2,
  52940. coordinateSystem: 'view',
  52941. layout: null,
  52942. // The position of the whole view
  52943. left: '5%',
  52944. top: '5%',
  52945. right: '20%',
  52946. bottom: '5%',
  52947. // Value can be 'vertical'
  52948. orient: 'horizontal',
  52949. // The dx of the node
  52950. nodeWidth: 20,
  52951. // The vertical distance between two nodes
  52952. nodeGap: 8,
  52953. // Control if the node can move or not
  52954. draggable: true,
  52955. // Value can be 'inEdges', 'outEdges', 'allEdges', true (the same as 'allEdges').
  52956. focusNodeAdjacency: false,
  52957. // The number of iterations to change the position of the node
  52958. layoutIterations: 32,
  52959. label: {
  52960. show: true,
  52961. position: 'right',
  52962. color: '#000',
  52963. fontSize: 12
  52964. },
  52965. levels: [],
  52966. // Value can be 'left' or 'right'
  52967. nodeAlign: 'justify',
  52968. itemStyle: {
  52969. borderWidth: 1,
  52970. borderColor: '#333'
  52971. },
  52972. lineStyle: {
  52973. color: '#314656',
  52974. opacity: 0.2,
  52975. curveness: 0.5
  52976. },
  52977. emphasis: {
  52978. label: {
  52979. show: true
  52980. },
  52981. lineStyle: {
  52982. opacity: 0.6
  52983. }
  52984. },
  52985. animationEasing: 'linear',
  52986. animationDuration: 1000
  52987. }
  52988. });
  52989. /*
  52990. * Licensed to the Apache Software Foundation (ASF) under one
  52991. * or more contributor license agreements. See the NOTICE file
  52992. * distributed with this work for additional information
  52993. * regarding copyright ownership. The ASF licenses this file
  52994. * to you under the Apache License, Version 2.0 (the
  52995. * "License"); you may not use this file except in compliance
  52996. * with the License. You may obtain a copy of the License at
  52997. *
  52998. * http://www.apache.org/licenses/LICENSE-2.0
  52999. *
  53000. * Unless required by applicable law or agreed to in writing,
  53001. * software distributed under the License is distributed on an
  53002. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  53003. * KIND, either express or implied. See the License for the
  53004. * specific language governing permissions and limitations
  53005. * under the License.
  53006. */
  53007. var nodeOpacityPath$1 = ['itemStyle', 'opacity'];
  53008. var lineOpacityPath$1 = ['lineStyle', 'opacity'];
  53009. function getItemOpacity$1(item, opacityPath) {
  53010. return item.getVisual('opacity') || item.getModel().get(opacityPath);
  53011. }
  53012. function fadeOutItem$1(item, opacityPath, opacityRatio) {
  53013. var el = item.getGraphicEl();
  53014. var opacity = getItemOpacity$1(item, opacityPath);
  53015. if (opacityRatio != null) {
  53016. opacity == null && (opacity = 1);
  53017. opacity *= opacityRatio;
  53018. }
  53019. el.downplay && el.downplay();
  53020. el.traverse(function (child) {
  53021. if (child.type !== 'group') {
  53022. child.setStyle('opacity', opacity);
  53023. }
  53024. });
  53025. }
  53026. function fadeInItem$1(item, opacityPath) {
  53027. var opacity = getItemOpacity$1(item, opacityPath);
  53028. var el = item.getGraphicEl();
  53029. el.highlight && el.highlight();
  53030. el.traverse(function (child) {
  53031. if (child.type !== 'group') {
  53032. child.setStyle('opacity', opacity);
  53033. }
  53034. });
  53035. }
  53036. var SankeyShape = extendShape({
  53037. shape: {
  53038. x1: 0, y1: 0,
  53039. x2: 0, y2: 0,
  53040. cpx1: 0, cpy1: 0,
  53041. cpx2: 0, cpy2: 0,
  53042. extent: 0,
  53043. orient: ''
  53044. },
  53045. buildPath: function (ctx, shape) {
  53046. var extent = shape.extent;
  53047. ctx.moveTo(shape.x1, shape.y1);
  53048. ctx.bezierCurveTo(
  53049. shape.cpx1, shape.cpy1,
  53050. shape.cpx2, shape.cpy2,
  53051. shape.x2, shape.y2
  53052. );
  53053. if (shape.orient === 'vertical') {
  53054. ctx.lineTo(shape.x2 + extent, shape.y2);
  53055. ctx.bezierCurveTo(
  53056. shape.cpx2 + extent, shape.cpy2,
  53057. shape.cpx1 + extent, shape.cpy1,
  53058. shape.x1 + extent, shape.y1
  53059. );
  53060. }
  53061. else {
  53062. ctx.lineTo(shape.x2, shape.y2 + extent);
  53063. ctx.bezierCurveTo(
  53064. shape.cpx2, shape.cpy2 + extent,
  53065. shape.cpx1, shape.cpy1 + extent,
  53066. shape.x1, shape.y1 + extent
  53067. );
  53068. }
  53069. ctx.closePath();
  53070. }
  53071. });
  53072. extendChartView({
  53073. type: 'sankey',
  53074. /**
  53075. * @private
  53076. * @type {module:echarts/chart/sankey/SankeySeries}
  53077. */
  53078. _model: null,
  53079. /**
  53080. * @private
  53081. * @type {boolean}
  53082. */
  53083. _focusAdjacencyDisabled: false,
  53084. render: function (seriesModel, ecModel, api) {
  53085. var sankeyView = this;
  53086. var graph = seriesModel.getGraph();
  53087. var group = this.group;
  53088. var layoutInfo = seriesModel.layoutInfo;
  53089. // view width
  53090. var width = layoutInfo.width;
  53091. // view height
  53092. var height = layoutInfo.height;
  53093. var nodeData = seriesModel.getData();
  53094. var edgeData = seriesModel.getData('edge');
  53095. var orient = seriesModel.get('orient');
  53096. this._model = seriesModel;
  53097. group.removeAll();
  53098. group.attr('position', [layoutInfo.x, layoutInfo.y]);
  53099. // generate a bezire Curve for each edge
  53100. graph.eachEdge(function (edge) {
  53101. var curve = new SankeyShape();
  53102. curve.dataIndex = edge.dataIndex;
  53103. curve.seriesIndex = seriesModel.seriesIndex;
  53104. curve.dataType = 'edge';
  53105. var lineStyleModel = edge.getModel('lineStyle');
  53106. var curvature = lineStyleModel.get('curveness');
  53107. var n1Layout = edge.node1.getLayout();
  53108. var node1Model = edge.node1.getModel();
  53109. var dragX1 = node1Model.get('localX');
  53110. var dragY1 = node1Model.get('localY');
  53111. var n2Layout = edge.node2.getLayout();
  53112. var node2Model = edge.node2.getModel();
  53113. var dragX2 = node2Model.get('localX');
  53114. var dragY2 = node2Model.get('localY');
  53115. var edgeLayout = edge.getLayout();
  53116. var x1;
  53117. var y1;
  53118. var x2;
  53119. var y2;
  53120. var cpx1;
  53121. var cpy1;
  53122. var cpx2;
  53123. var cpy2;
  53124. curve.shape.extent = Math.max(1, edgeLayout.dy);
  53125. curve.shape.orient = orient;
  53126. if (orient === 'vertical') {
  53127. x1 = (dragX1 != null ? dragX1 * width : n1Layout.x) + edgeLayout.sy;
  53128. y1 = (dragY1 != null ? dragY1 * height : n1Layout.y) + n1Layout.dy;
  53129. x2 = (dragX2 != null ? dragX2 * width : n2Layout.x) + edgeLayout.ty;
  53130. y2 = dragY2 != null ? dragY2 * height : n2Layout.y;
  53131. cpx1 = x1;
  53132. cpy1 = y1 * (1 - curvature) + y2 * curvature;
  53133. cpx2 = x2;
  53134. cpy2 = y1 * curvature + y2 * (1 - curvature);
  53135. }
  53136. else {
  53137. x1 = (dragX1 != null ? dragX1 * width : n1Layout.x) + n1Layout.dx;
  53138. y1 = (dragY1 != null ? dragY1 * height : n1Layout.y) + edgeLayout.sy;
  53139. x2 = dragX2 != null ? dragX2 * width : n2Layout.x;
  53140. y2 = (dragY2 != null ? dragY2 * height : n2Layout.y) + edgeLayout.ty;
  53141. cpx1 = x1 * (1 - curvature) + x2 * curvature;
  53142. cpy1 = y1;
  53143. cpx2 = x1 * curvature + x2 * (1 - curvature);
  53144. cpy2 = y2;
  53145. }
  53146. curve.setShape({
  53147. x1: x1,
  53148. y1: y1,
  53149. x2: x2,
  53150. y2: y2,
  53151. cpx1: cpx1,
  53152. cpy1: cpy1,
  53153. cpx2: cpx2,
  53154. cpy2: cpy2
  53155. });
  53156. curve.setStyle(lineStyleModel.getItemStyle());
  53157. // Special color, use source node color or target node color
  53158. switch (curve.style.fill) {
  53159. case 'source':
  53160. curve.style.fill = edge.node1.getVisual('color');
  53161. break;
  53162. case 'target':
  53163. curve.style.fill = edge.node2.getVisual('color');
  53164. break;
  53165. }
  53166. setHoverStyle(curve, edge.getModel('emphasis.lineStyle').getItemStyle());
  53167. group.add(curve);
  53168. edgeData.setItemGraphicEl(edge.dataIndex, curve);
  53169. });
  53170. // Generate a rect for each node
  53171. graph.eachNode(function (node) {
  53172. var layout = node.getLayout();
  53173. var itemModel = node.getModel();
  53174. var dragX = itemModel.get('localX');
  53175. var dragY = itemModel.get('localY');
  53176. var labelModel = itemModel.getModel('label');
  53177. var labelHoverModel = itemModel.getModel('emphasis.label');
  53178. var rect = new Rect({
  53179. shape: {
  53180. x: dragX != null ? dragX * width : layout.x,
  53181. y: dragY != null ? dragY * height : layout.y,
  53182. width: layout.dx,
  53183. height: layout.dy
  53184. },
  53185. style: itemModel.getModel('itemStyle').getItemStyle()
  53186. });
  53187. var hoverStyle = node.getModel('emphasis.itemStyle').getItemStyle();
  53188. setLabelStyle(
  53189. rect.style, hoverStyle, labelModel, labelHoverModel,
  53190. {
  53191. labelFetcher: seriesModel,
  53192. labelDataIndex: node.dataIndex,
  53193. defaultText: node.id,
  53194. isRectText: true
  53195. }
  53196. );
  53197. rect.setStyle('fill', node.getVisual('color'));
  53198. setHoverStyle(rect, hoverStyle);
  53199. group.add(rect);
  53200. nodeData.setItemGraphicEl(node.dataIndex, rect);
  53201. rect.dataType = 'node';
  53202. });
  53203. nodeData.eachItemGraphicEl(function (el, dataIndex) {
  53204. var itemModel = nodeData.getItemModel(dataIndex);
  53205. if (itemModel.get('draggable')) {
  53206. el.drift = function (dx, dy) {
  53207. sankeyView._focusAdjacencyDisabled = true;
  53208. this.shape.x += dx;
  53209. this.shape.y += dy;
  53210. this.dirty();
  53211. api.dispatchAction({
  53212. type: 'dragNode',
  53213. seriesId: seriesModel.id,
  53214. dataIndex: nodeData.getRawIndex(dataIndex),
  53215. localX: this.shape.x / width,
  53216. localY: this.shape.y / height
  53217. });
  53218. };
  53219. el.ondragend = function () {
  53220. sankeyView._focusAdjacencyDisabled = false;
  53221. };
  53222. el.draggable = true;
  53223. el.cursor = 'move';
  53224. }
  53225. if (itemModel.get('focusNodeAdjacency')) {
  53226. el.off('mouseover').on('mouseover', function () {
  53227. if (!sankeyView._focusAdjacencyDisabled) {
  53228. api.dispatchAction({
  53229. type: 'focusNodeAdjacency',
  53230. seriesId: seriesModel.id,
  53231. dataIndex: el.dataIndex
  53232. });
  53233. }
  53234. });
  53235. el.off('mouseout').on('mouseout', function () {
  53236. if (!sankeyView._focusAdjacencyDisabled) {
  53237. api.dispatchAction({
  53238. type: 'unfocusNodeAdjacency',
  53239. seriesId: seriesModel.id
  53240. });
  53241. }
  53242. });
  53243. }
  53244. });
  53245. edgeData.eachItemGraphicEl(function (el, dataIndex) {
  53246. var edgeModel = edgeData.getItemModel(dataIndex);
  53247. if (edgeModel.get('focusNodeAdjacency')) {
  53248. el.off('mouseover').on('mouseover', function () {
  53249. if (!sankeyView._focusAdjacencyDisabled) {
  53250. api.dispatchAction({
  53251. type: 'focusNodeAdjacency',
  53252. seriesId: seriesModel.id,
  53253. edgeDataIndex: el.dataIndex
  53254. });
  53255. }
  53256. });
  53257. el.off('mouseout').on('mouseout', function () {
  53258. if (!sankeyView._focusAdjacencyDisabled) {
  53259. api.dispatchAction({
  53260. type: 'unfocusNodeAdjacency',
  53261. seriesId: seriesModel.id
  53262. });
  53263. }
  53264. });
  53265. }
  53266. });
  53267. if (!this._data && seriesModel.get('animation')) {
  53268. group.setClipPath(createGridClipShape$2(group.getBoundingRect(), seriesModel, function () {
  53269. group.removeClipPath();
  53270. }));
  53271. }
  53272. this._data = seriesModel.getData();
  53273. },
  53274. dispose: function () {},
  53275. focusNodeAdjacency: function (seriesModel, ecModel, api, payload) {
  53276. var data = this._model.getData();
  53277. var graph = data.graph;
  53278. var dataIndex = payload.dataIndex;
  53279. var itemModel = data.getItemModel(dataIndex);
  53280. var edgeDataIndex = payload.edgeDataIndex;
  53281. if (dataIndex == null && edgeDataIndex == null) {
  53282. return;
  53283. }
  53284. var node = graph.getNodeByIndex(dataIndex);
  53285. var edge = graph.getEdgeByIndex(edgeDataIndex);
  53286. graph.eachNode(function (node) {
  53287. fadeOutItem$1(node, nodeOpacityPath$1, 0.1);
  53288. });
  53289. graph.eachEdge(function (edge) {
  53290. fadeOutItem$1(edge, lineOpacityPath$1, 0.1);
  53291. });
  53292. if (node) {
  53293. fadeInItem$1(node, nodeOpacityPath$1);
  53294. var focusNodeAdj = itemModel.get('focusNodeAdjacency');
  53295. if (focusNodeAdj === 'outEdges') {
  53296. each$1(node.outEdges, function (edge) {
  53297. if (edge.dataIndex < 0) {
  53298. return;
  53299. }
  53300. fadeInItem$1(edge, lineOpacityPath$1);
  53301. fadeInItem$1(edge.node2, nodeOpacityPath$1);
  53302. });
  53303. }
  53304. else if (focusNodeAdj === 'inEdges') {
  53305. each$1(node.inEdges, function (edge) {
  53306. if (edge.dataIndex < 0) {
  53307. return;
  53308. }
  53309. fadeInItem$1(edge, lineOpacityPath$1);
  53310. fadeInItem$1(edge.node1, nodeOpacityPath$1);
  53311. });
  53312. }
  53313. else if (focusNodeAdj === 'allEdges') {
  53314. each$1(node.edges, function (edge) {
  53315. if (edge.dataIndex < 0) {
  53316. return;
  53317. }
  53318. fadeInItem$1(edge, lineOpacityPath$1);
  53319. fadeInItem$1(edge.node1, nodeOpacityPath$1);
  53320. fadeInItem$1(edge.node2, nodeOpacityPath$1);
  53321. });
  53322. }
  53323. }
  53324. if (edge) {
  53325. fadeInItem$1(edge, lineOpacityPath$1);
  53326. fadeInItem$1(edge.node1, nodeOpacityPath$1);
  53327. fadeInItem$1(edge.node2, nodeOpacityPath$1);
  53328. }
  53329. },
  53330. unfocusNodeAdjacency: function (seriesModel, ecModel, api, payload) {
  53331. var graph = this._model.getGraph();
  53332. graph.eachNode(function (node) {
  53333. fadeOutItem$1(node, nodeOpacityPath$1);
  53334. });
  53335. graph.eachEdge(function (edge) {
  53336. fadeOutItem$1(edge, lineOpacityPath$1);
  53337. });
  53338. }
  53339. });
  53340. // Add animation to the view
  53341. function createGridClipShape$2(rect, seriesModel, cb) {
  53342. var rectEl = new Rect({
  53343. shape: {
  53344. x: rect.x - 10,
  53345. y: rect.y - 10,
  53346. width: 0,
  53347. height: rect.height + 20
  53348. }
  53349. });
  53350. initProps(rectEl, {
  53351. shape: {
  53352. width: rect.width + 20,
  53353. height: rect.height + 20
  53354. }
  53355. }, seriesModel, cb);
  53356. return rectEl;
  53357. }
  53358. /*
  53359. * Licensed to the Apache Software Foundation (ASF) under one
  53360. * or more contributor license agreements. See the NOTICE file
  53361. * distributed with this work for additional information
  53362. * regarding copyright ownership. The ASF licenses this file
  53363. * to you under the Apache License, Version 2.0 (the
  53364. * "License"); you may not use this file except in compliance
  53365. * with the License. You may obtain a copy of the License at
  53366. *
  53367. * http://www.apache.org/licenses/LICENSE-2.0
  53368. *
  53369. * Unless required by applicable law or agreed to in writing,
  53370. * software distributed under the License is distributed on an
  53371. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  53372. * KIND, either express or implied. See the License for the
  53373. * specific language governing permissions and limitations
  53374. * under the License.
  53375. */
  53376. registerAction({
  53377. type: 'dragNode',
  53378. event: 'dragNode',
  53379. // here can only use 'update' now, other value is not support in echarts.
  53380. update: 'update'
  53381. }, function (payload, ecModel) {
  53382. ecModel.eachComponent({mainType: 'series', subType: 'sankey', query: payload}, function (seriesModel) {
  53383. seriesModel.setNodePosition(payload.dataIndex, [payload.localX, payload.localY]);
  53384. });
  53385. });
  53386. /*
  53387. * Licensed to the Apache Software Foundation (ASF) under one
  53388. * or more contributor license agreements. See the NOTICE file
  53389. * distributed with this work for additional information
  53390. * regarding copyright ownership. The ASF licenses this file
  53391. * to you under the Apache License, Version 2.0 (the
  53392. * "License"); you may not use this file except in compliance
  53393. * with the License. You may obtain a copy of the License at
  53394. *
  53395. * http://www.apache.org/licenses/LICENSE-2.0
  53396. *
  53397. * Unless required by applicable law or agreed to in writing,
  53398. * software distributed under the License is distributed on an
  53399. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  53400. * KIND, either express or implied. See the License for the
  53401. * specific language governing permissions and limitations
  53402. * under the License.
  53403. */
  53404. var sankeyLayout = function (ecModel, api, payload) {
  53405. ecModel.eachSeriesByType('sankey', function (seriesModel) {
  53406. var nodeWidth = seriesModel.get('nodeWidth');
  53407. var nodeGap = seriesModel.get('nodeGap');
  53408. var layoutInfo = getViewRect$3(seriesModel, api);
  53409. seriesModel.layoutInfo = layoutInfo;
  53410. var width = layoutInfo.width;
  53411. var height = layoutInfo.height;
  53412. var graph = seriesModel.getGraph();
  53413. var nodes = graph.nodes;
  53414. var edges = graph.edges;
  53415. computeNodeValues(nodes);
  53416. var filteredNodes = filter(nodes, function (node) {
  53417. return node.getLayout().value === 0;
  53418. });
  53419. var iterations = filteredNodes.length !== 0 ? 0 : seriesModel.get('layoutIterations');
  53420. var orient = seriesModel.get('orient');
  53421. var nodeAlign = seriesModel.get('nodeAlign');
  53422. layoutSankey(nodes, edges, nodeWidth, nodeGap, width, height, iterations, orient, nodeAlign);
  53423. });
  53424. };
  53425. /**
  53426. * Get the layout position of the whole view
  53427. *
  53428. * @param {module:echarts/model/Series} seriesModel the model object of sankey series
  53429. * @param {module:echarts/ExtensionAPI} api provide the API list that the developer can call
  53430. * @return {module:zrender/core/BoundingRect} size of rect to draw the sankey view
  53431. */
  53432. function getViewRect$3(seriesModel, api) {
  53433. return getLayoutRect(
  53434. seriesModel.getBoxLayoutParams(), {
  53435. width: api.getWidth(),
  53436. height: api.getHeight()
  53437. }
  53438. );
  53439. }
  53440. function layoutSankey(nodes, edges, nodeWidth, nodeGap, width, height, iterations, orient, nodeAlign) {
  53441. computeNodeBreadths(nodes, edges, nodeWidth, width, height, orient, nodeAlign);
  53442. computeNodeDepths(nodes, edges, height, width, nodeGap, iterations, orient);
  53443. computeEdgeDepths(nodes, orient);
  53444. }
  53445. /**
  53446. * Compute the value of each node by summing the associated edge's value
  53447. *
  53448. * @param {module:echarts/data/Graph~Node} nodes node of sankey view
  53449. */
  53450. function computeNodeValues(nodes) {
  53451. each$1(nodes, function (node) {
  53452. var value1 = sum(node.outEdges, getEdgeValue);
  53453. var value2 = sum(node.inEdges, getEdgeValue);
  53454. var value = Math.max(value1, value2);
  53455. node.setLayout({value: value}, true);
  53456. });
  53457. }
  53458. /**
  53459. * Compute the x-position for each node.
  53460. *
  53461. * Here we use Kahn algorithm to detect cycle when we traverse
  53462. * the node to computer the initial x position.
  53463. *
  53464. * @param {module:echarts/data/Graph~Node} nodes node of sankey view
  53465. * @param {number} nodeWidth the dx of the node
  53466. * @param {number} width the whole width of the area to draw the view
  53467. */
  53468. function computeNodeBreadths(nodes, edges, nodeWidth, width, height, orient, nodeAlign) {
  53469. // Used to mark whether the edge is deleted. if it is deleted,
  53470. // the value is 0, otherwise it is 1.
  53471. var remainEdges = [];
  53472. // Storage each node's indegree.
  53473. var indegreeArr = [];
  53474. //Used to storage the node with indegree is equal to 0.
  53475. var zeroIndegrees = [];
  53476. var nextTargetNode = [];
  53477. var x = 0;
  53478. var kx = 0;
  53479. for (var i = 0; i < edges.length; i++) {
  53480. remainEdges[i] = 1;
  53481. }
  53482. for (i = 0; i < nodes.length; i++) {
  53483. indegreeArr[i] = nodes[i].inEdges.length;
  53484. if (indegreeArr[i] === 0) {
  53485. zeroIndegrees.push(nodes[i]);
  53486. }
  53487. }
  53488. var maxNodeDepth = -1;
  53489. // Traversing nodes using topological sorting to calculate the
  53490. // horizontal(if orient === 'horizontal') or vertical(if orient === 'vertical')
  53491. // position of the nodes.
  53492. while (zeroIndegrees.length) {
  53493. for (var idx = 0; idx < zeroIndegrees.length; idx++) {
  53494. var node = zeroIndegrees[idx];
  53495. var item = node.hostGraph.data.getRawDataItem(node.dataIndex);
  53496. var isItemDepth = item.depth != null && item.depth >= 0;
  53497. if (isItemDepth && item.depth > maxNodeDepth) {
  53498. maxNodeDepth = item.depth;
  53499. }
  53500. node.setLayout({depth: isItemDepth ? item.depth : x}, true);
  53501. orient === 'vertical'
  53502. ? node.setLayout({dy: nodeWidth}, true)
  53503. : node.setLayout({dx: nodeWidth}, true);
  53504. for (var edgeIdx = 0; edgeIdx < node.outEdges.length; edgeIdx++) {
  53505. var edge = node.outEdges[edgeIdx];
  53506. var indexEdge = edges.indexOf(edge);
  53507. remainEdges[indexEdge] = 0;
  53508. var targetNode = edge.node2;
  53509. var nodeIndex = nodes.indexOf(targetNode);
  53510. if (--indegreeArr[nodeIndex] === 0 && nextTargetNode.indexOf(targetNode) < 0) {
  53511. nextTargetNode.push(targetNode);
  53512. }
  53513. }
  53514. }
  53515. ++x;
  53516. zeroIndegrees = nextTargetNode;
  53517. nextTargetNode = [];
  53518. }
  53519. for (i = 0; i < remainEdges.length; i++) {
  53520. if (remainEdges[i] === 1) {
  53521. throw new Error('Sankey is a DAG, the original data has cycle!');
  53522. }
  53523. }
  53524. var maxDepth = maxNodeDepth > x - 1 ? maxNodeDepth : x - 1;
  53525. if (nodeAlign && nodeAlign !== 'left') {
  53526. adjustNodeWithNodeAlign(nodes, nodeAlign, orient, maxDepth);
  53527. }
  53528. var kx = orient === 'vertical'
  53529. ? (height - nodeWidth) / maxDepth
  53530. : (width - nodeWidth) / maxDepth;
  53531. scaleNodeBreadths(nodes, kx, orient);
  53532. }
  53533. function isNodeDepth(node) {
  53534. var item = node.hostGraph.data.getRawDataItem(node.dataIndex);
  53535. return item.depth != null && item.depth >= 0;
  53536. }
  53537. function adjustNodeWithNodeAlign(nodes, nodeAlign, orient, maxDepth) {
  53538. if (nodeAlign === 'right') {
  53539. var nextSourceNode = [];
  53540. var remainNodes = nodes;
  53541. var nodeHeight = 0;
  53542. while (remainNodes.length) {
  53543. for (var i = 0; i < remainNodes.length; i++) {
  53544. var node = remainNodes[i];
  53545. node.setLayout({skNodeHeight: nodeHeight}, true);
  53546. for (var j = 0; j < node.inEdges.length; j++) {
  53547. var edge = node.inEdges[j];
  53548. if (nextSourceNode.indexOf(edge.node1) < 0) {
  53549. nextSourceNode.push(edge.node1);
  53550. }
  53551. }
  53552. }
  53553. remainNodes = nextSourceNode;
  53554. nextSourceNode = [];
  53555. ++nodeHeight;
  53556. }
  53557. each$1(nodes, function (node) {
  53558. if (!isNodeDepth(node)) {
  53559. node.setLayout({depth: Math.max(0, maxDepth - node.getLayout().skNodeHeight)}, true);
  53560. }
  53561. });
  53562. }
  53563. else if (nodeAlign === 'justify') {
  53564. moveSinksRight(nodes, maxDepth);
  53565. }
  53566. }
  53567. /**
  53568. * All the node without outEgdes are assigned maximum x-position and
  53569. * be aligned in the last column.
  53570. *
  53571. * @param {module:echarts/data/Graph~Node} nodes. node of sankey view.
  53572. * @param {number} maxDepth. use to assign to node without outEdges as x-position.
  53573. */
  53574. function moveSinksRight(nodes, maxDepth) {
  53575. each$1(nodes, function (node) {
  53576. if (!isNodeDepth(node) && !node.outEdges.length) {
  53577. node.setLayout({depth: maxDepth}, true);
  53578. }
  53579. });
  53580. }
  53581. /**
  53582. * Scale node x-position to the width
  53583. *
  53584. * @param {module:echarts/data/Graph~Node} nodes node of sankey view
  53585. * @param {number} kx multiple used to scale nodes
  53586. */
  53587. function scaleNodeBreadths(nodes, kx, orient) {
  53588. each$1(nodes, function (node) {
  53589. var nodeDepth = node.getLayout().depth * kx;
  53590. orient === 'vertical'
  53591. ? node.setLayout({y: nodeDepth}, true)
  53592. : node.setLayout({x: nodeDepth}, true);
  53593. });
  53594. }
  53595. /**
  53596. * Using Gauss-Seidel iterations method to compute the node depth(y-position)
  53597. *
  53598. * @param {module:echarts/data/Graph~Node} nodes node of sankey view
  53599. * @param {module:echarts/data/Graph~Edge} edges edge of sankey view
  53600. * @param {number} height the whole height of the area to draw the view
  53601. * @param {number} nodeGap the vertical distance between two nodes
  53602. * in the same column.
  53603. * @param {number} iterations the number of iterations for the algorithm
  53604. */
  53605. function computeNodeDepths(nodes, edges, height, width, nodeGap, iterations, orient) {
  53606. var nodesByBreadth = prepareNodesByBreadth(nodes, orient);
  53607. initializeNodeDepth(nodesByBreadth, edges, height, width, nodeGap, orient);
  53608. resolveCollisions(nodesByBreadth, nodeGap, height, width, orient);
  53609. for (var alpha = 1; iterations > 0; iterations--) {
  53610. // 0.99 is a experience parameter, ensure that each iterations of
  53611. // changes as small as possible.
  53612. alpha *= 0.99;
  53613. relaxRightToLeft(nodesByBreadth, alpha, orient);
  53614. resolveCollisions(nodesByBreadth, nodeGap, height, width, orient);
  53615. relaxLeftToRight(nodesByBreadth, alpha, orient);
  53616. resolveCollisions(nodesByBreadth, nodeGap, height, width, orient);
  53617. }
  53618. }
  53619. function prepareNodesByBreadth(nodes, orient) {
  53620. var nodesByBreadth = [];
  53621. var keyAttr = orient === 'vertical' ? 'y' : 'x';
  53622. var groupResult = groupData(nodes, function (node) {
  53623. return node.getLayout()[keyAttr];
  53624. });
  53625. groupResult.keys.sort(function (a, b) {
  53626. return a - b;
  53627. });
  53628. each$1(groupResult.keys, function (key) {
  53629. nodesByBreadth.push(groupResult.buckets.get(key));
  53630. });
  53631. return nodesByBreadth;
  53632. }
  53633. /**
  53634. * Compute the original y-position for each node
  53635. *
  53636. * @param {module:echarts/data/Graph~Node} nodes node of sankey view
  53637. * @param {Array.<Array.<module:echarts/data/Graph~Node>>} nodesByBreadth
  53638. * group by the array of all sankey nodes based on the nodes x-position.
  53639. * @param {module:echarts/data/Graph~Edge} edges edge of sankey view
  53640. * @param {number} height the whole height of the area to draw the view
  53641. * @param {number} nodeGap the vertical distance between two nodes
  53642. */
  53643. function initializeNodeDepth(nodesByBreadth, edges, height, width, nodeGap, orient) {
  53644. var minKy = Infinity;
  53645. each$1(nodesByBreadth, function (nodes) {
  53646. var n = nodes.length;
  53647. var sum = 0;
  53648. each$1(nodes, function (node) {
  53649. sum += node.getLayout().value;
  53650. });
  53651. var ky = orient === 'vertical'
  53652. ? (width - (n - 1) * nodeGap) / sum
  53653. : (height - (n - 1) * nodeGap) / sum;
  53654. if (ky < minKy) {
  53655. minKy = ky;
  53656. }
  53657. });
  53658. each$1(nodesByBreadth, function (nodes) {
  53659. each$1(nodes, function (node, i) {
  53660. var nodeDy = node.getLayout().value * minKy;
  53661. if (orient === 'vertical') {
  53662. node.setLayout({x: i}, true);
  53663. node.setLayout({dx: nodeDy}, true);
  53664. }
  53665. else {
  53666. node.setLayout({y: i}, true);
  53667. node.setLayout({dy: nodeDy}, true);
  53668. }
  53669. });
  53670. });
  53671. each$1(edges, function (edge) {
  53672. var edgeDy = +edge.getValue() * minKy;
  53673. edge.setLayout({dy: edgeDy}, true);
  53674. });
  53675. }
  53676. /**
  53677. * Resolve the collision of initialized depth (y-position)
  53678. *
  53679. * @param {Array.<Array.<module:echarts/data/Graph~Node>>} nodesByBreadth
  53680. * group by the array of all sankey nodes based on the nodes x-position.
  53681. * @param {number} nodeGap the vertical distance between two nodes
  53682. * @param {number} height the whole height of the area to draw the view
  53683. */
  53684. function resolveCollisions(nodesByBreadth, nodeGap, height, width, orient) {
  53685. var keyAttr = orient === 'vertical' ? 'x' : 'y';
  53686. each$1(nodesByBreadth, function (nodes) {
  53687. nodes.sort(function (a, b) {
  53688. return a.getLayout()[keyAttr] - b.getLayout()[keyAttr];
  53689. });
  53690. var nodeX;
  53691. var node;
  53692. var dy;
  53693. var y0 = 0;
  53694. var n = nodes.length;
  53695. var nodeDyAttr = orient === 'vertical' ? 'dx' : 'dy';
  53696. for (var i = 0; i < n; i++) {
  53697. node = nodes[i];
  53698. dy = y0 - node.getLayout()[keyAttr];
  53699. if (dy > 0) {
  53700. nodeX = node.getLayout()[keyAttr] + dy;
  53701. orient === 'vertical'
  53702. ? node.setLayout({x: nodeX}, true)
  53703. : node.setLayout({y: nodeX}, true);
  53704. }
  53705. y0 = node.getLayout()[keyAttr] + node.getLayout()[nodeDyAttr] + nodeGap;
  53706. }
  53707. var viewWidth = orient === 'vertical' ? width : height;
  53708. // If the bottommost node goes outside the bounds, push it back up
  53709. dy = y0 - nodeGap - viewWidth;
  53710. if (dy > 0) {
  53711. nodeX = node.getLayout()[keyAttr] - dy;
  53712. orient === 'vertical'
  53713. ? node.setLayout({x: nodeX}, true)
  53714. : node.setLayout({y: nodeX}, true);
  53715. y0 = nodeX;
  53716. for (i = n - 2; i >= 0; --i) {
  53717. node = nodes[i];
  53718. dy = node.getLayout()[keyAttr] + node.getLayout()[nodeDyAttr] + nodeGap - y0;
  53719. if (dy > 0) {
  53720. nodeX = node.getLayout()[keyAttr] - dy;
  53721. orient === 'vertical'
  53722. ? node.setLayout({x: nodeX}, true)
  53723. : node.setLayout({y: nodeX}, true);
  53724. }
  53725. y0 = node.getLayout()[keyAttr];
  53726. }
  53727. }
  53728. });
  53729. }
  53730. /**
  53731. * Change the y-position of the nodes, except most the right side nodes
  53732. *
  53733. * @param {Array.<Array.<module:echarts/data/Graph~Node>>} nodesByBreadth
  53734. * group by the array of all sankey nodes based on the node x-position.
  53735. * @param {number} alpha parameter used to adjust the nodes y-position
  53736. */
  53737. function relaxRightToLeft(nodesByBreadth, alpha, orient) {
  53738. each$1(nodesByBreadth.slice().reverse(), function (nodes) {
  53739. each$1(nodes, function (node) {
  53740. if (node.outEdges.length) {
  53741. var y = sum(node.outEdges, weightedTarget, orient)
  53742. / sum(node.outEdges, getEdgeValue, orient);
  53743. if (orient === 'vertical') {
  53744. var nodeX = node.getLayout().x + (y - center$1(node, orient)) * alpha;
  53745. node.setLayout({x: nodeX}, true);
  53746. }
  53747. else {
  53748. var nodeY = node.getLayout().y + (y - center$1(node, orient)) * alpha;
  53749. node.setLayout({y: nodeY}, true);
  53750. }
  53751. }
  53752. });
  53753. });
  53754. }
  53755. function weightedTarget(edge, orient) {
  53756. return center$1(edge.node2, orient) * edge.getValue();
  53757. }
  53758. function weightedSource(edge, orient) {
  53759. return center$1(edge.node1, orient) * edge.getValue();
  53760. }
  53761. function center$1(node, orient) {
  53762. return orient === 'vertical'
  53763. ? node.getLayout().x + node.getLayout().dx / 2
  53764. : node.getLayout().y + node.getLayout().dy / 2;
  53765. }
  53766. function getEdgeValue(edge) {
  53767. return edge.getValue();
  53768. }
  53769. function sum(array, f, orient) {
  53770. var sum = 0;
  53771. var len = array.length;
  53772. var i = -1;
  53773. while (++i < len) {
  53774. var value = +f.call(array, array[i], orient);
  53775. if (!isNaN(value)) {
  53776. sum += value;
  53777. }
  53778. }
  53779. return sum;
  53780. }
  53781. /**
  53782. * Change the y-position of the nodes, except most the left side nodes
  53783. *
  53784. * @param {Array.<Array.<module:echarts/data/Graph~Node>>} nodesByBreadth
  53785. * group by the array of all sankey nodes based on the node x-position.
  53786. * @param {number} alpha parameter used to adjust the nodes y-position
  53787. */
  53788. function relaxLeftToRight(nodesByBreadth, alpha, orient) {
  53789. each$1(nodesByBreadth, function (nodes) {
  53790. each$1(nodes, function (node) {
  53791. if (node.inEdges.length) {
  53792. var y = sum(node.inEdges, weightedSource, orient)
  53793. / sum(node.inEdges, getEdgeValue, orient);
  53794. if (orient === 'vertical') {
  53795. var nodeX = node.getLayout().x + (y - center$1(node, orient)) * alpha;
  53796. node.setLayout({x: nodeX}, true);
  53797. }
  53798. else {
  53799. var nodeY = node.getLayout().y + (y - center$1(node, orient)) * alpha;
  53800. node.setLayout({y: nodeY}, true);
  53801. }
  53802. }
  53803. });
  53804. });
  53805. }
  53806. /**
  53807. * Compute the depth(y-position) of each edge
  53808. *
  53809. * @param {module:echarts/data/Graph~Node} nodes node of sankey view
  53810. */
  53811. function computeEdgeDepths(nodes, orient) {
  53812. var keyAttr = orient === 'vertical' ? 'x' : 'y';
  53813. each$1(nodes, function (node) {
  53814. node.outEdges.sort(function (a, b) {
  53815. return a.node2.getLayout()[keyAttr] - b.node2.getLayout()[keyAttr];
  53816. });
  53817. node.inEdges.sort(function (a, b) {
  53818. return a.node1.getLayout()[keyAttr] - b.node1.getLayout()[keyAttr];
  53819. });
  53820. });
  53821. each$1(nodes, function (node) {
  53822. var sy = 0;
  53823. var ty = 0;
  53824. each$1(node.outEdges, function (edge) {
  53825. edge.setLayout({sy: sy}, true);
  53826. sy += edge.getLayout().dy;
  53827. });
  53828. each$1(node.inEdges, function (edge) {
  53829. edge.setLayout({ty: ty}, true);
  53830. ty += edge.getLayout().dy;
  53831. });
  53832. });
  53833. }
  53834. /*
  53835. * Licensed to the Apache Software Foundation (ASF) under one
  53836. * or more contributor license agreements. See the NOTICE file
  53837. * distributed with this work for additional information
  53838. * regarding copyright ownership. The ASF licenses this file
  53839. * to you under the Apache License, Version 2.0 (the
  53840. * "License"); you may not use this file except in compliance
  53841. * with the License. You may obtain a copy of the License at
  53842. *
  53843. * http://www.apache.org/licenses/LICENSE-2.0
  53844. *
  53845. * Unless required by applicable law or agreed to in writing,
  53846. * software distributed under the License is distributed on an
  53847. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  53848. * KIND, either express or implied. See the License for the
  53849. * specific language governing permissions and limitations
  53850. * under the License.
  53851. */
  53852. var sankeyVisual = function (ecModel, payload) {
  53853. ecModel.eachSeriesByType('sankey', function (seriesModel) {
  53854. var graph = seriesModel.getGraph();
  53855. var nodes = graph.nodes;
  53856. if (nodes.length) {
  53857. var minValue = Infinity;
  53858. var maxValue = -Infinity;
  53859. each$1(nodes, function (node) {
  53860. var nodeValue = node.getLayout().value;
  53861. if (nodeValue < minValue) {
  53862. minValue = nodeValue;
  53863. }
  53864. if (nodeValue > maxValue) {
  53865. maxValue = nodeValue;
  53866. }
  53867. });
  53868. each$1(nodes, function (node) {
  53869. var mapping = new VisualMapping({
  53870. type: 'color',
  53871. mappingMethod: 'linear',
  53872. dataExtent: [minValue, maxValue],
  53873. visual: seriesModel.get('color')
  53874. });
  53875. var mapValueToColor = mapping.mapValueToVisual(node.getLayout().value);
  53876. var customColor = node.getModel().get('itemStyle.color');
  53877. customColor != null
  53878. ? node.setVisual('color', customColor)
  53879. : node.setVisual('color', mapValueToColor);
  53880. });
  53881. }
  53882. });
  53883. };
  53884. /*
  53885. * Licensed to the Apache Software Foundation (ASF) under one
  53886. * or more contributor license agreements. See the NOTICE file
  53887. * distributed with this work for additional information
  53888. * regarding copyright ownership. The ASF licenses this file
  53889. * to you under the Apache License, Version 2.0 (the
  53890. * "License"); you may not use this file except in compliance
  53891. * with the License. You may obtain a copy of the License at
  53892. *
  53893. * http://www.apache.org/licenses/LICENSE-2.0
  53894. *
  53895. * Unless required by applicable law or agreed to in writing,
  53896. * software distributed under the License is distributed on an
  53897. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  53898. * KIND, either express or implied. See the License for the
  53899. * specific language governing permissions and limitations
  53900. * under the License.
  53901. */
  53902. registerLayout(sankeyLayout);
  53903. registerVisual(sankeyVisual);
  53904. /*
  53905. * Licensed to the Apache Software Foundation (ASF) under one
  53906. * or more contributor license agreements. See the NOTICE file
  53907. * distributed with this work for additional information
  53908. * regarding copyright ownership. The ASF licenses this file
  53909. * to you under the Apache License, Version 2.0 (the
  53910. * "License"); you may not use this file except in compliance
  53911. * with the License. You may obtain a copy of the License at
  53912. *
  53913. * http://www.apache.org/licenses/LICENSE-2.0
  53914. *
  53915. * Unless required by applicable law or agreed to in writing,
  53916. * software distributed under the License is distributed on an
  53917. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  53918. * KIND, either express or implied. See the License for the
  53919. * specific language governing permissions and limitations
  53920. * under the License.
  53921. */
  53922. var seriesModelMixin = {
  53923. /**
  53924. * @private
  53925. * @type {string}
  53926. */
  53927. _baseAxisDim: null,
  53928. /**
  53929. * @override
  53930. */
  53931. getInitialData: function (option, ecModel) {
  53932. // When both types of xAxis and yAxis are 'value', layout is
  53933. // needed to be specified by user. Otherwise, layout can be
  53934. // judged by which axis is category.
  53935. var ordinalMeta;
  53936. var xAxisModel = ecModel.getComponent('xAxis', this.get('xAxisIndex'));
  53937. var yAxisModel = ecModel.getComponent('yAxis', this.get('yAxisIndex'));
  53938. var xAxisType = xAxisModel.get('type');
  53939. var yAxisType = yAxisModel.get('type');
  53940. var addOrdinal;
  53941. // FIXME
  53942. // 考虑时间轴
  53943. if (xAxisType === 'category') {
  53944. option.layout = 'horizontal';
  53945. ordinalMeta = xAxisModel.getOrdinalMeta();
  53946. addOrdinal = true;
  53947. }
  53948. else if (yAxisType === 'category') {
  53949. option.layout = 'vertical';
  53950. ordinalMeta = yAxisModel.getOrdinalMeta();
  53951. addOrdinal = true;
  53952. }
  53953. else {
  53954. option.layout = option.layout || 'horizontal';
  53955. }
  53956. var coordDims = ['x', 'y'];
  53957. var baseAxisDimIndex = option.layout === 'horizontal' ? 0 : 1;
  53958. var baseAxisDim = this._baseAxisDim = coordDims[baseAxisDimIndex];
  53959. var otherAxisDim = coordDims[1 - baseAxisDimIndex];
  53960. var axisModels = [xAxisModel, yAxisModel];
  53961. var baseAxisType = axisModels[baseAxisDimIndex].get('type');
  53962. var otherAxisType = axisModels[1 - baseAxisDimIndex].get('type');
  53963. var data = option.data;
  53964. // ??? FIXME make a stage to perform data transfrom.
  53965. // MUST create a new data, consider setOption({}) again.
  53966. if (data && addOrdinal) {
  53967. var newOptionData = [];
  53968. each$1(data, function (item, index) {
  53969. var newItem;
  53970. if (item.value && isArray(item.value)) {
  53971. newItem = item.value.slice();
  53972. item.value.unshift(index);
  53973. }
  53974. else if (isArray(item)) {
  53975. newItem = item.slice();
  53976. item.unshift(index);
  53977. }
  53978. else {
  53979. newItem = item;
  53980. }
  53981. newOptionData.push(newItem);
  53982. });
  53983. option.data = newOptionData;
  53984. }
  53985. var defaultValueDimensions = this.defaultValueDimensions;
  53986. return createListSimply(
  53987. this,
  53988. {
  53989. coordDimensions: [{
  53990. name: baseAxisDim,
  53991. type: getDimensionTypeByAxis(baseAxisType),
  53992. ordinalMeta: ordinalMeta,
  53993. otherDims: {
  53994. tooltip: false,
  53995. itemName: 0
  53996. },
  53997. dimsDef: ['base']
  53998. }, {
  53999. name: otherAxisDim,
  54000. type: getDimensionTypeByAxis(otherAxisType),
  54001. dimsDef: defaultValueDimensions.slice()
  54002. }],
  54003. dimensionsCount: defaultValueDimensions.length + 1
  54004. }
  54005. );
  54006. },
  54007. /**
  54008. * If horizontal, base axis is x, otherwise y.
  54009. * @override
  54010. */
  54011. getBaseAxis: function () {
  54012. var dim = this._baseAxisDim;
  54013. return this.ecModel.getComponent(dim + 'Axis', this.get(dim + 'AxisIndex')).axis;
  54014. }
  54015. };
  54016. /*
  54017. * Licensed to the Apache Software Foundation (ASF) under one
  54018. * or more contributor license agreements. See the NOTICE file
  54019. * distributed with this work for additional information
  54020. * regarding copyright ownership. The ASF licenses this file
  54021. * to you under the Apache License, Version 2.0 (the
  54022. * "License"); you may not use this file except in compliance
  54023. * with the License. You may obtain a copy of the License at
  54024. *
  54025. * http://www.apache.org/licenses/LICENSE-2.0
  54026. *
  54027. * Unless required by applicable law or agreed to in writing,
  54028. * software distributed under the License is distributed on an
  54029. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  54030. * KIND, either express or implied. See the License for the
  54031. * specific language governing permissions and limitations
  54032. * under the License.
  54033. */
  54034. var BoxplotSeries = SeriesModel.extend({
  54035. type: 'series.boxplot',
  54036. dependencies: ['xAxis', 'yAxis', 'grid'],
  54037. // TODO
  54038. // box width represents group size, so dimension should have 'size'.
  54039. /**
  54040. * @see <https://en.wikipedia.org/wiki/Box_plot>
  54041. * The meanings of 'min' and 'max' depend on user,
  54042. * and echarts do not need to know it.
  54043. * @readOnly
  54044. */
  54045. defaultValueDimensions: [
  54046. {name: 'min', defaultTooltip: true},
  54047. {name: 'Q1', defaultTooltip: true},
  54048. {name: 'median', defaultTooltip: true},
  54049. {name: 'Q3', defaultTooltip: true},
  54050. {name: 'max', defaultTooltip: true}
  54051. ],
  54052. /**
  54053. * @type {Array.<string>}
  54054. * @readOnly
  54055. */
  54056. dimensions: null,
  54057. /**
  54058. * @override
  54059. */
  54060. defaultOption: {
  54061. zlevel: 0, // 一级层叠
  54062. z: 2, // 二级层叠
  54063. coordinateSystem: 'cartesian2d',
  54064. legendHoverLink: true,
  54065. hoverAnimation: true,
  54066. // xAxisIndex: 0,
  54067. // yAxisIndex: 0,
  54068. layout: null, // 'horizontal' or 'vertical'
  54069. boxWidth: [7, 50], // [min, max] can be percent of band width.
  54070. itemStyle: {
  54071. color: '#fff',
  54072. borderWidth: 1
  54073. },
  54074. emphasis: {
  54075. itemStyle: {
  54076. borderWidth: 2,
  54077. shadowBlur: 5,
  54078. shadowOffsetX: 2,
  54079. shadowOffsetY: 2,
  54080. shadowColor: 'rgba(0,0,0,0.4)'
  54081. }
  54082. },
  54083. animationEasing: 'elasticOut',
  54084. animationDuration: 800
  54085. }
  54086. });
  54087. mixin(BoxplotSeries, seriesModelMixin, true);
  54088. /*
  54089. * Licensed to the Apache Software Foundation (ASF) under one
  54090. * or more contributor license agreements. See the NOTICE file
  54091. * distributed with this work for additional information
  54092. * regarding copyright ownership. The ASF licenses this file
  54093. * to you under the Apache License, Version 2.0 (the
  54094. * "License"); you may not use this file except in compliance
  54095. * with the License. You may obtain a copy of the License at
  54096. *
  54097. * http://www.apache.org/licenses/LICENSE-2.0
  54098. *
  54099. * Unless required by applicable law or agreed to in writing,
  54100. * software distributed under the License is distributed on an
  54101. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  54102. * KIND, either express or implied. See the License for the
  54103. * specific language governing permissions and limitations
  54104. * under the License.
  54105. */
  54106. // Update common properties
  54107. var NORMAL_ITEM_STYLE_PATH = ['itemStyle'];
  54108. var EMPHASIS_ITEM_STYLE_PATH = ['emphasis', 'itemStyle'];
  54109. var BoxplotView = Chart.extend({
  54110. type: 'boxplot',
  54111. render: function (seriesModel, ecModel, api) {
  54112. var data = seriesModel.getData();
  54113. var group = this.group;
  54114. var oldData = this._data;
  54115. // There is no old data only when first rendering or switching from
  54116. // stream mode to normal mode, where previous elements should be removed.
  54117. if (!this._data) {
  54118. group.removeAll();
  54119. }
  54120. var constDim = seriesModel.get('layout') === 'horizontal' ? 1 : 0;
  54121. data.diff(oldData)
  54122. .add(function (newIdx) {
  54123. if (data.hasValue(newIdx)) {
  54124. var itemLayout = data.getItemLayout(newIdx);
  54125. var symbolEl = createNormalBox(itemLayout, data, newIdx, constDim, true);
  54126. data.setItemGraphicEl(newIdx, symbolEl);
  54127. group.add(symbolEl);
  54128. }
  54129. })
  54130. .update(function (newIdx, oldIdx) {
  54131. var symbolEl = oldData.getItemGraphicEl(oldIdx);
  54132. // Empty data
  54133. if (!data.hasValue(newIdx)) {
  54134. group.remove(symbolEl);
  54135. return;
  54136. }
  54137. var itemLayout = data.getItemLayout(newIdx);
  54138. if (!symbolEl) {
  54139. symbolEl = createNormalBox(itemLayout, data, newIdx, constDim);
  54140. }
  54141. else {
  54142. updateNormalBoxData(itemLayout, symbolEl, data, newIdx);
  54143. }
  54144. group.add(symbolEl);
  54145. data.setItemGraphicEl(newIdx, symbolEl);
  54146. })
  54147. .remove(function (oldIdx) {
  54148. var el = oldData.getItemGraphicEl(oldIdx);
  54149. el && group.remove(el);
  54150. })
  54151. .execute();
  54152. this._data = data;
  54153. },
  54154. remove: function (ecModel) {
  54155. var group = this.group;
  54156. var data = this._data;
  54157. this._data = null;
  54158. data && data.eachItemGraphicEl(function (el) {
  54159. el && group.remove(el);
  54160. });
  54161. },
  54162. dispose: noop
  54163. });
  54164. var BoxPath = Path.extend({
  54165. type: 'boxplotBoxPath',
  54166. shape: {},
  54167. buildPath: function (ctx, shape) {
  54168. var ends = shape.points;
  54169. var i = 0;
  54170. ctx.moveTo(ends[i][0], ends[i][1]);
  54171. i++;
  54172. for (; i < 4; i++) {
  54173. ctx.lineTo(ends[i][0], ends[i][1]);
  54174. }
  54175. ctx.closePath();
  54176. for (; i < ends.length; i++) {
  54177. ctx.moveTo(ends[i][0], ends[i][1]);
  54178. i++;
  54179. ctx.lineTo(ends[i][0], ends[i][1]);
  54180. }
  54181. }
  54182. });
  54183. function createNormalBox(itemLayout, data, dataIndex, constDim, isInit) {
  54184. var ends = itemLayout.ends;
  54185. var el = new BoxPath({
  54186. shape: {
  54187. points: isInit
  54188. ? transInit(ends, constDim, itemLayout)
  54189. : ends
  54190. }
  54191. });
  54192. updateNormalBoxData(itemLayout, el, data, dataIndex, isInit);
  54193. return el;
  54194. }
  54195. function updateNormalBoxData(itemLayout, el, data, dataIndex, isInit) {
  54196. var seriesModel = data.hostModel;
  54197. var updateMethod = graphic[isInit ? 'initProps' : 'updateProps'];
  54198. updateMethod(
  54199. el,
  54200. {shape: {points: itemLayout.ends}},
  54201. seriesModel,
  54202. dataIndex
  54203. );
  54204. var itemModel = data.getItemModel(dataIndex);
  54205. var normalItemStyleModel = itemModel.getModel(NORMAL_ITEM_STYLE_PATH);
  54206. var borderColor = data.getItemVisual(dataIndex, 'color');
  54207. // Exclude borderColor.
  54208. var itemStyle = normalItemStyleModel.getItemStyle(['borderColor']);
  54209. itemStyle.stroke = borderColor;
  54210. itemStyle.strokeNoScale = true;
  54211. el.useStyle(itemStyle);
  54212. el.z2 = 100;
  54213. var hoverStyle = itemModel.getModel(EMPHASIS_ITEM_STYLE_PATH).getItemStyle();
  54214. setHoverStyle(el, hoverStyle);
  54215. }
  54216. function transInit(points, dim, itemLayout) {
  54217. return map(points, function (point) {
  54218. point = point.slice();
  54219. point[dim] = itemLayout.initBaseline;
  54220. return point;
  54221. });
  54222. }
  54223. /*
  54224. * Licensed to the Apache Software Foundation (ASF) under one
  54225. * or more contributor license agreements. See the NOTICE file
  54226. * distributed with this work for additional information
  54227. * regarding copyright ownership. The ASF licenses this file
  54228. * to you under the Apache License, Version 2.0 (the
  54229. * "License"); you may not use this file except in compliance
  54230. * with the License. You may obtain a copy of the License at
  54231. *
  54232. * http://www.apache.org/licenses/LICENSE-2.0
  54233. *
  54234. * Unless required by applicable law or agreed to in writing,
  54235. * software distributed under the License is distributed on an
  54236. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  54237. * KIND, either express or implied. See the License for the
  54238. * specific language governing permissions and limitations
  54239. * under the License.
  54240. */
  54241. var borderColorQuery = ['itemStyle', 'borderColor'];
  54242. var boxplotVisual = function (ecModel, api) {
  54243. var globalColors = ecModel.get('color');
  54244. ecModel.eachRawSeriesByType('boxplot', function (seriesModel) {
  54245. var defaulColor = globalColors[seriesModel.seriesIndex % globalColors.length];
  54246. var data = seriesModel.getData();
  54247. data.setVisual({
  54248. legendSymbol: 'roundRect',
  54249. // Use name 'color' but not 'borderColor' for legend usage and
  54250. // visual coding from other component like dataRange.
  54251. color: seriesModel.get(borderColorQuery) || defaulColor
  54252. });
  54253. // Only visible series has each data be visual encoded
  54254. if (!ecModel.isSeriesFiltered(seriesModel)) {
  54255. data.each(function (idx) {
  54256. var itemModel = data.getItemModel(idx);
  54257. data.setItemVisual(
  54258. idx,
  54259. {color: itemModel.get(borderColorQuery, true)}
  54260. );
  54261. });
  54262. }
  54263. });
  54264. };
  54265. /*
  54266. * Licensed to the Apache Software Foundation (ASF) under one
  54267. * or more contributor license agreements. See the NOTICE file
  54268. * distributed with this work for additional information
  54269. * regarding copyright ownership. The ASF licenses this file
  54270. * to you under the Apache License, Version 2.0 (the
  54271. * "License"); you may not use this file except in compliance
  54272. * with the License. You may obtain a copy of the License at
  54273. *
  54274. * http://www.apache.org/licenses/LICENSE-2.0
  54275. *
  54276. * Unless required by applicable law or agreed to in writing,
  54277. * software distributed under the License is distributed on an
  54278. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  54279. * KIND, either express or implied. See the License for the
  54280. * specific language governing permissions and limitations
  54281. * under the License.
  54282. */
  54283. var each$13 = each$1;
  54284. var boxplotLayout = function (ecModel) {
  54285. var groupResult = groupSeriesByAxis(ecModel);
  54286. each$13(groupResult, function (groupItem) {
  54287. var seriesModels = groupItem.seriesModels;
  54288. if (!seriesModels.length) {
  54289. return;
  54290. }
  54291. calculateBase(groupItem);
  54292. each$13(seriesModels, function (seriesModel, idx) {
  54293. layoutSingleSeries(
  54294. seriesModel,
  54295. groupItem.boxOffsetList[idx],
  54296. groupItem.boxWidthList[idx]
  54297. );
  54298. });
  54299. });
  54300. };
  54301. /**
  54302. * Group series by axis.
  54303. */
  54304. function groupSeriesByAxis(ecModel) {
  54305. var result = [];
  54306. var axisList = [];
  54307. ecModel.eachSeriesByType('boxplot', function (seriesModel) {
  54308. var baseAxis = seriesModel.getBaseAxis();
  54309. var idx = indexOf(axisList, baseAxis);
  54310. if (idx < 0) {
  54311. idx = axisList.length;
  54312. axisList[idx] = baseAxis;
  54313. result[idx] = {axis: baseAxis, seriesModels: []};
  54314. }
  54315. result[idx].seriesModels.push(seriesModel);
  54316. });
  54317. return result;
  54318. }
  54319. /**
  54320. * Calculate offset and box width for each series.
  54321. */
  54322. function calculateBase(groupItem) {
  54323. var extent;
  54324. var baseAxis = groupItem.axis;
  54325. var seriesModels = groupItem.seriesModels;
  54326. var seriesCount = seriesModels.length;
  54327. var boxWidthList = groupItem.boxWidthList = [];
  54328. var boxOffsetList = groupItem.boxOffsetList = [];
  54329. var boundList = [];
  54330. var bandWidth;
  54331. if (baseAxis.type === 'category') {
  54332. bandWidth = baseAxis.getBandWidth();
  54333. }
  54334. else {
  54335. var maxDataCount = 0;
  54336. each$13(seriesModels, function (seriesModel) {
  54337. maxDataCount = Math.max(maxDataCount, seriesModel.getData().count());
  54338. });
  54339. extent = baseAxis.getExtent(),
  54340. Math.abs(extent[1] - extent[0]) / maxDataCount;
  54341. }
  54342. each$13(seriesModels, function (seriesModel) {
  54343. var boxWidthBound = seriesModel.get('boxWidth');
  54344. if (!isArray(boxWidthBound)) {
  54345. boxWidthBound = [boxWidthBound, boxWidthBound];
  54346. }
  54347. boundList.push([
  54348. parsePercent$1(boxWidthBound[0], bandWidth) || 0,
  54349. parsePercent$1(boxWidthBound[1], bandWidth) || 0
  54350. ]);
  54351. });
  54352. var availableWidth = bandWidth * 0.8 - 2;
  54353. var boxGap = availableWidth / seriesCount * 0.3;
  54354. var boxWidth = (availableWidth - boxGap * (seriesCount - 1)) / seriesCount;
  54355. var base = boxWidth / 2 - availableWidth / 2;
  54356. each$13(seriesModels, function (seriesModel, idx) {
  54357. boxOffsetList.push(base);
  54358. base += boxGap + boxWidth;
  54359. boxWidthList.push(
  54360. Math.min(Math.max(boxWidth, boundList[idx][0]), boundList[idx][1])
  54361. );
  54362. });
  54363. }
  54364. /**
  54365. * Calculate points location for each series.
  54366. */
  54367. function layoutSingleSeries(seriesModel, offset, boxWidth) {
  54368. var coordSys = seriesModel.coordinateSystem;
  54369. var data = seriesModel.getData();
  54370. var halfWidth = boxWidth / 2;
  54371. var cDimIdx = seriesModel.get('layout') === 'horizontal' ? 0 : 1;
  54372. var vDimIdx = 1 - cDimIdx;
  54373. var coordDims = ['x', 'y'];
  54374. var cDim = data.mapDimension(coordDims[cDimIdx]);
  54375. var vDims = data.mapDimension(coordDims[vDimIdx], true);
  54376. if (cDim == null || vDims.length < 5) {
  54377. return;
  54378. }
  54379. for (var dataIndex = 0; dataIndex < data.count(); dataIndex++) {
  54380. var axisDimVal = data.get(cDim, dataIndex);
  54381. var median = getPoint(axisDimVal, vDims[2], dataIndex);
  54382. var end1 = getPoint(axisDimVal, vDims[0], dataIndex);
  54383. var end2 = getPoint(axisDimVal, vDims[1], dataIndex);
  54384. var end4 = getPoint(axisDimVal, vDims[3], dataIndex);
  54385. var end5 = getPoint(axisDimVal, vDims[4], dataIndex);
  54386. var ends = [];
  54387. addBodyEnd(ends, end2, 0);
  54388. addBodyEnd(ends, end4, 1);
  54389. ends.push(end1, end2, end5, end4);
  54390. layEndLine(ends, end1);
  54391. layEndLine(ends, end5);
  54392. layEndLine(ends, median);
  54393. data.setItemLayout(dataIndex, {
  54394. initBaseline: median[vDimIdx],
  54395. ends: ends
  54396. });
  54397. }
  54398. function getPoint(axisDimVal, dimIdx, dataIndex) {
  54399. var val = data.get(dimIdx, dataIndex);
  54400. var p = [];
  54401. p[cDimIdx] = axisDimVal;
  54402. p[vDimIdx] = val;
  54403. var point;
  54404. if (isNaN(axisDimVal) || isNaN(val)) {
  54405. point = [NaN, NaN];
  54406. }
  54407. else {
  54408. point = coordSys.dataToPoint(p);
  54409. point[cDimIdx] += offset;
  54410. }
  54411. return point;
  54412. }
  54413. function addBodyEnd(ends, point, start) {
  54414. var point1 = point.slice();
  54415. var point2 = point.slice();
  54416. point1[cDimIdx] += halfWidth;
  54417. point2[cDimIdx] -= halfWidth;
  54418. start
  54419. ? ends.push(point1, point2)
  54420. : ends.push(point2, point1);
  54421. }
  54422. function layEndLine(ends, endCenter) {
  54423. var from = endCenter.slice();
  54424. var to = endCenter.slice();
  54425. from[cDimIdx] -= halfWidth;
  54426. to[cDimIdx] += halfWidth;
  54427. ends.push(from, to);
  54428. }
  54429. }
  54430. /*
  54431. * Licensed to the Apache Software Foundation (ASF) under one
  54432. * or more contributor license agreements. See the NOTICE file
  54433. * distributed with this work for additional information
  54434. * regarding copyright ownership. The ASF licenses this file
  54435. * to you under the Apache License, Version 2.0 (the
  54436. * "License"); you may not use this file except in compliance
  54437. * with the License. You may obtain a copy of the License at
  54438. *
  54439. * http://www.apache.org/licenses/LICENSE-2.0
  54440. *
  54441. * Unless required by applicable law or agreed to in writing,
  54442. * software distributed under the License is distributed on an
  54443. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  54444. * KIND, either express or implied. See the License for the
  54445. * specific language governing permissions and limitations
  54446. * under the License.
  54447. */
  54448. registerVisual(boxplotVisual);
  54449. registerLayout(boxplotLayout);
  54450. /*
  54451. * Licensed to the Apache Software Foundation (ASF) under one
  54452. * or more contributor license agreements. See the NOTICE file
  54453. * distributed with this work for additional information
  54454. * regarding copyright ownership. The ASF licenses this file
  54455. * to you under the Apache License, Version 2.0 (the
  54456. * "License"); you may not use this file except in compliance
  54457. * with the License. You may obtain a copy of the License at
  54458. *
  54459. * http://www.apache.org/licenses/LICENSE-2.0
  54460. *
  54461. * Unless required by applicable law or agreed to in writing,
  54462. * software distributed under the License is distributed on an
  54463. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  54464. * KIND, either express or implied. See the License for the
  54465. * specific language governing permissions and limitations
  54466. * under the License.
  54467. */
  54468. var CandlestickSeries = SeriesModel.extend({
  54469. type: 'series.candlestick',
  54470. dependencies: ['xAxis', 'yAxis', 'grid'],
  54471. /**
  54472. * @readOnly
  54473. */
  54474. defaultValueDimensions: [
  54475. {name: 'open', defaultTooltip: true},
  54476. {name: 'close', defaultTooltip: true},
  54477. {name: 'lowest', defaultTooltip: true},
  54478. {name: 'highest', defaultTooltip: true}
  54479. ],
  54480. /**
  54481. * @type {Array.<string>}
  54482. * @readOnly
  54483. */
  54484. dimensions: null,
  54485. /**
  54486. * @override
  54487. */
  54488. defaultOption: {
  54489. zlevel: 0,
  54490. z: 2,
  54491. coordinateSystem: 'cartesian2d',
  54492. legendHoverLink: true,
  54493. hoverAnimation: true,
  54494. // xAxisIndex: 0,
  54495. // yAxisIndex: 0,
  54496. layout: null, // 'horizontal' or 'vertical'
  54497. itemStyle: {
  54498. color: '#c23531', // 阳线 positive
  54499. color0: '#314656', // 阴线 negative '#c23531', '#314656'
  54500. borderWidth: 1,
  54501. // FIXME
  54502. // ec2中使用的是lineStyle.color 和 lineStyle.color0
  54503. borderColor: '#c23531',
  54504. borderColor0: '#314656'
  54505. },
  54506. emphasis: {
  54507. itemStyle: {
  54508. borderWidth: 2
  54509. }
  54510. },
  54511. barMaxWidth: null,
  54512. barMinWidth: null,
  54513. barWidth: null,
  54514. large: true,
  54515. largeThreshold: 600,
  54516. progressive: 3e3,
  54517. progressiveThreshold: 1e4,
  54518. progressiveChunkMode: 'mod',
  54519. animationUpdate: false,
  54520. animationEasing: 'linear',
  54521. animationDuration: 300
  54522. },
  54523. /**
  54524. * Get dimension for shadow in dataZoom
  54525. * @return {string} dimension name
  54526. */
  54527. getShadowDim: function () {
  54528. return 'open';
  54529. },
  54530. brushSelector: function (dataIndex, data, selectors) {
  54531. var itemLayout = data.getItemLayout(dataIndex);
  54532. return itemLayout && selectors.rect(itemLayout.brushRect);
  54533. }
  54534. });
  54535. mixin(CandlestickSeries, seriesModelMixin, true);
  54536. /*
  54537. * Licensed to the Apache Software Foundation (ASF) under one
  54538. * or more contributor license agreements. See the NOTICE file
  54539. * distributed with this work for additional information
  54540. * regarding copyright ownership. The ASF licenses this file
  54541. * to you under the Apache License, Version 2.0 (the
  54542. * "License"); you may not use this file except in compliance
  54543. * with the License. You may obtain a copy of the License at
  54544. *
  54545. * http://www.apache.org/licenses/LICENSE-2.0
  54546. *
  54547. * Unless required by applicable law or agreed to in writing,
  54548. * software distributed under the License is distributed on an
  54549. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  54550. * KIND, either express or implied. See the License for the
  54551. * specific language governing permissions and limitations
  54552. * under the License.
  54553. */
  54554. var NORMAL_ITEM_STYLE_PATH$1 = ['itemStyle'];
  54555. var EMPHASIS_ITEM_STYLE_PATH$1 = ['emphasis', 'itemStyle'];
  54556. var SKIP_PROPS = ['color', 'color0', 'borderColor', 'borderColor0'];
  54557. var CandlestickView = Chart.extend({
  54558. type: 'candlestick',
  54559. render: function (seriesModel, ecModel, api) {
  54560. this._updateDrawMode(seriesModel);
  54561. this._isLargeDraw
  54562. ? this._renderLarge(seriesModel)
  54563. : this._renderNormal(seriesModel);
  54564. },
  54565. incrementalPrepareRender: function (seriesModel, ecModel, api) {
  54566. this._clear();
  54567. this._updateDrawMode(seriesModel);
  54568. },
  54569. incrementalRender: function (params, seriesModel, ecModel, api) {
  54570. this._isLargeDraw
  54571. ? this._incrementalRenderLarge(params, seriesModel)
  54572. : this._incrementalRenderNormal(params, seriesModel);
  54573. },
  54574. _updateDrawMode: function (seriesModel) {
  54575. var isLargeDraw = seriesModel.pipelineContext.large;
  54576. if (this._isLargeDraw == null || isLargeDraw ^ this._isLargeDraw) {
  54577. this._isLargeDraw = isLargeDraw;
  54578. this._clear();
  54579. }
  54580. },
  54581. _renderNormal: function (seriesModel) {
  54582. var data = seriesModel.getData();
  54583. var oldData = this._data;
  54584. var group = this.group;
  54585. var isSimpleBox = data.getLayout('isSimpleBox');
  54586. // There is no old data only when first rendering or switching from
  54587. // stream mode to normal mode, where previous elements should be removed.
  54588. if (!this._data) {
  54589. group.removeAll();
  54590. }
  54591. data.diff(oldData)
  54592. .add(function (newIdx) {
  54593. if (data.hasValue(newIdx)) {
  54594. var el;
  54595. var itemLayout = data.getItemLayout(newIdx);
  54596. el = createNormalBox$1(itemLayout, newIdx, true);
  54597. initProps(el, {shape: {points: itemLayout.ends}}, seriesModel, newIdx);
  54598. setBoxCommon(el, data, newIdx, isSimpleBox);
  54599. group.add(el);
  54600. data.setItemGraphicEl(newIdx, el);
  54601. }
  54602. })
  54603. .update(function (newIdx, oldIdx) {
  54604. var el = oldData.getItemGraphicEl(oldIdx);
  54605. // Empty data
  54606. if (!data.hasValue(newIdx)) {
  54607. group.remove(el);
  54608. return;
  54609. }
  54610. var itemLayout = data.getItemLayout(newIdx);
  54611. if (!el) {
  54612. el = createNormalBox$1(itemLayout, newIdx);
  54613. }
  54614. else {
  54615. updateProps(el, {shape: {points: itemLayout.ends}}, seriesModel, newIdx);
  54616. }
  54617. setBoxCommon(el, data, newIdx, isSimpleBox);
  54618. group.add(el);
  54619. data.setItemGraphicEl(newIdx, el);
  54620. })
  54621. .remove(function (oldIdx) {
  54622. var el = oldData.getItemGraphicEl(oldIdx);
  54623. el && group.remove(el);
  54624. })
  54625. .execute();
  54626. this._data = data;
  54627. },
  54628. _renderLarge: function (seriesModel) {
  54629. this._clear();
  54630. createLarge$1(seriesModel, this.group);
  54631. },
  54632. _incrementalRenderNormal: function (params, seriesModel) {
  54633. var data = seriesModel.getData();
  54634. var isSimpleBox = data.getLayout('isSimpleBox');
  54635. var dataIndex;
  54636. while ((dataIndex = params.next()) != null) {
  54637. var el;
  54638. var itemLayout = data.getItemLayout(dataIndex);
  54639. el = createNormalBox$1(itemLayout, dataIndex);
  54640. setBoxCommon(el, data, dataIndex, isSimpleBox);
  54641. el.incremental = true;
  54642. this.group.add(el);
  54643. }
  54644. },
  54645. _incrementalRenderLarge: function (params, seriesModel) {
  54646. createLarge$1(seriesModel, this.group, true);
  54647. },
  54648. remove: function (ecModel) {
  54649. this._clear();
  54650. },
  54651. _clear: function () {
  54652. this.group.removeAll();
  54653. this._data = null;
  54654. },
  54655. dispose: noop
  54656. });
  54657. var NormalBoxPath = Path.extend({
  54658. type: 'normalCandlestickBox',
  54659. shape: {},
  54660. buildPath: function (ctx, shape) {
  54661. var ends = shape.points;
  54662. if (this.__simpleBox) {
  54663. ctx.moveTo(ends[4][0], ends[4][1]);
  54664. ctx.lineTo(ends[6][0], ends[6][1]);
  54665. }
  54666. else {
  54667. ctx.moveTo(ends[0][0], ends[0][1]);
  54668. ctx.lineTo(ends[1][0], ends[1][1]);
  54669. ctx.lineTo(ends[2][0], ends[2][1]);
  54670. ctx.lineTo(ends[3][0], ends[3][1]);
  54671. ctx.closePath();
  54672. ctx.moveTo(ends[4][0], ends[4][1]);
  54673. ctx.lineTo(ends[5][0], ends[5][1]);
  54674. ctx.moveTo(ends[6][0], ends[6][1]);
  54675. ctx.lineTo(ends[7][0], ends[7][1]);
  54676. }
  54677. }
  54678. });
  54679. function createNormalBox$1(itemLayout, dataIndex, isInit) {
  54680. var ends = itemLayout.ends;
  54681. return new NormalBoxPath({
  54682. shape: {
  54683. points: isInit
  54684. ? transInit$1(ends, itemLayout)
  54685. : ends
  54686. },
  54687. z2: 100
  54688. });
  54689. }
  54690. function setBoxCommon(el, data, dataIndex, isSimpleBox) {
  54691. var itemModel = data.getItemModel(dataIndex);
  54692. var normalItemStyleModel = itemModel.getModel(NORMAL_ITEM_STYLE_PATH$1);
  54693. var color = data.getItemVisual(dataIndex, 'color');
  54694. var borderColor = data.getItemVisual(dataIndex, 'borderColor') || color;
  54695. // Color must be excluded.
  54696. // Because symbol provide setColor individually to set fill and stroke
  54697. var itemStyle = normalItemStyleModel.getItemStyle(SKIP_PROPS);
  54698. el.useStyle(itemStyle);
  54699. el.style.strokeNoScale = true;
  54700. el.style.fill = color;
  54701. el.style.stroke = borderColor;
  54702. el.__simpleBox = isSimpleBox;
  54703. var hoverStyle = itemModel.getModel(EMPHASIS_ITEM_STYLE_PATH$1).getItemStyle();
  54704. setHoverStyle(el, hoverStyle);
  54705. }
  54706. function transInit$1(points, itemLayout) {
  54707. return map(points, function (point) {
  54708. point = point.slice();
  54709. point[1] = itemLayout.initBaseline;
  54710. return point;
  54711. });
  54712. }
  54713. var LargeBoxPath = Path.extend({
  54714. type: 'largeCandlestickBox',
  54715. shape: {},
  54716. buildPath: function (ctx, shape) {
  54717. // Drawing lines is more efficient than drawing
  54718. // a whole line or drawing rects.
  54719. var points = shape.points;
  54720. for (var i = 0; i < points.length;) {
  54721. if (this.__sign === points[i++]) {
  54722. var x = points[i++];
  54723. ctx.moveTo(x, points[i++]);
  54724. ctx.lineTo(x, points[i++]);
  54725. }
  54726. else {
  54727. i += 3;
  54728. }
  54729. }
  54730. }
  54731. });
  54732. function createLarge$1(seriesModel, group, incremental) {
  54733. var data = seriesModel.getData();
  54734. var largePoints = data.getLayout('largePoints');
  54735. var elP = new LargeBoxPath({
  54736. shape: {points: largePoints},
  54737. __sign: 1
  54738. });
  54739. group.add(elP);
  54740. var elN = new LargeBoxPath({
  54741. shape: {points: largePoints},
  54742. __sign: -1
  54743. });
  54744. group.add(elN);
  54745. setLargeStyle$1(1, elP, seriesModel, data);
  54746. setLargeStyle$1(-1, elN, seriesModel, data);
  54747. if (incremental) {
  54748. elP.incremental = true;
  54749. elN.incremental = true;
  54750. }
  54751. }
  54752. function setLargeStyle$1(sign, el, seriesModel, data) {
  54753. var suffix = sign > 0 ? 'P' : 'N';
  54754. var borderColor = data.getVisual('borderColor' + suffix)
  54755. || data.getVisual('color' + suffix);
  54756. // Color must be excluded.
  54757. // Because symbol provide setColor individually to set fill and stroke
  54758. var itemStyle = seriesModel.getModel(NORMAL_ITEM_STYLE_PATH$1).getItemStyle(SKIP_PROPS);
  54759. el.useStyle(itemStyle);
  54760. el.style.fill = null;
  54761. el.style.stroke = borderColor;
  54762. // No different
  54763. // el.style.lineWidth = .5;
  54764. }
  54765. /*
  54766. * Licensed to the Apache Software Foundation (ASF) under one
  54767. * or more contributor license agreements. See the NOTICE file
  54768. * distributed with this work for additional information
  54769. * regarding copyright ownership. The ASF licenses this file
  54770. * to you under the Apache License, Version 2.0 (the
  54771. * "License"); you may not use this file except in compliance
  54772. * with the License. You may obtain a copy of the License at
  54773. *
  54774. * http://www.apache.org/licenses/LICENSE-2.0
  54775. *
  54776. * Unless required by applicable law or agreed to in writing,
  54777. * software distributed under the License is distributed on an
  54778. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  54779. * KIND, either express or implied. See the License for the
  54780. * specific language governing permissions and limitations
  54781. * under the License.
  54782. */
  54783. var preprocessor = function (option) {
  54784. if (!option || !isArray(option.series)) {
  54785. return;
  54786. }
  54787. // Translate 'k' to 'candlestick'.
  54788. each$1(option.series, function (seriesItem) {
  54789. if (isObject$1(seriesItem) && seriesItem.type === 'k') {
  54790. seriesItem.type = 'candlestick';
  54791. }
  54792. });
  54793. };
  54794. /*
  54795. * Licensed to the Apache Software Foundation (ASF) under one
  54796. * or more contributor license agreements. See the NOTICE file
  54797. * distributed with this work for additional information
  54798. * regarding copyright ownership. The ASF licenses this file
  54799. * to you under the Apache License, Version 2.0 (the
  54800. * "License"); you may not use this file except in compliance
  54801. * with the License. You may obtain a copy of the License at
  54802. *
  54803. * http://www.apache.org/licenses/LICENSE-2.0
  54804. *
  54805. * Unless required by applicable law or agreed to in writing,
  54806. * software distributed under the License is distributed on an
  54807. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  54808. * KIND, either express or implied. See the License for the
  54809. * specific language governing permissions and limitations
  54810. * under the License.
  54811. */
  54812. var positiveBorderColorQuery = ['itemStyle', 'borderColor'];
  54813. var negativeBorderColorQuery = ['itemStyle', 'borderColor0'];
  54814. var positiveColorQuery = ['itemStyle', 'color'];
  54815. var negativeColorQuery = ['itemStyle', 'color0'];
  54816. var candlestickVisual = {
  54817. seriesType: 'candlestick',
  54818. plan: createRenderPlanner(),
  54819. // For legend.
  54820. performRawSeries: true,
  54821. reset: function (seriesModel, ecModel) {
  54822. var data = seriesModel.getData();
  54823. var isLargeRender = seriesModel.pipelineContext.large;
  54824. data.setVisual({
  54825. legendSymbol: 'roundRect',
  54826. colorP: getColor(1, seriesModel),
  54827. colorN: getColor(-1, seriesModel),
  54828. borderColorP: getBorderColor(1, seriesModel),
  54829. borderColorN: getBorderColor(-1, seriesModel)
  54830. });
  54831. // Only visible series has each data be visual encoded
  54832. if (ecModel.isSeriesFiltered(seriesModel)) {
  54833. return;
  54834. }
  54835. return !isLargeRender && {progress: progress};
  54836. function progress(params, data) {
  54837. var dataIndex;
  54838. while ((dataIndex = params.next()) != null) {
  54839. var itemModel = data.getItemModel(dataIndex);
  54840. var sign = data.getItemLayout(dataIndex).sign;
  54841. data.setItemVisual(
  54842. dataIndex,
  54843. {
  54844. color: getColor(sign, itemModel),
  54845. borderColor: getBorderColor(sign, itemModel)
  54846. }
  54847. );
  54848. }
  54849. }
  54850. function getColor(sign, model) {
  54851. return model.get(
  54852. sign > 0 ? positiveColorQuery : negativeColorQuery
  54853. );
  54854. }
  54855. function getBorderColor(sign, model) {
  54856. return model.get(
  54857. sign > 0 ? positiveBorderColorQuery : negativeBorderColorQuery
  54858. );
  54859. }
  54860. }
  54861. };
  54862. /*
  54863. * Licensed to the Apache Software Foundation (ASF) under one
  54864. * or more contributor license agreements. See the NOTICE file
  54865. * distributed with this work for additional information
  54866. * regarding copyright ownership. The ASF licenses this file
  54867. * to you under the Apache License, Version 2.0 (the
  54868. * "License"); you may not use this file except in compliance
  54869. * with the License. You may obtain a copy of the License at
  54870. *
  54871. * http://www.apache.org/licenses/LICENSE-2.0
  54872. *
  54873. * Unless required by applicable law or agreed to in writing,
  54874. * software distributed under the License is distributed on an
  54875. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  54876. * KIND, either express or implied. See the License for the
  54877. * specific language governing permissions and limitations
  54878. * under the License.
  54879. */
  54880. /* global Float32Array */
  54881. var LargeArr$1 = typeof Float32Array !== 'undefined' ? Float32Array : Array;
  54882. var candlestickLayout = {
  54883. seriesType: 'candlestick',
  54884. plan: createRenderPlanner(),
  54885. reset: function (seriesModel) {
  54886. var coordSys = seriesModel.coordinateSystem;
  54887. var data = seriesModel.getData();
  54888. var candleWidth = calculateCandleWidth(seriesModel, data);
  54889. var cDimIdx = 0;
  54890. var vDimIdx = 1;
  54891. var coordDims = ['x', 'y'];
  54892. var cDim = data.mapDimension(coordDims[cDimIdx]);
  54893. var vDims = data.mapDimension(coordDims[vDimIdx], true);
  54894. var openDim = vDims[0];
  54895. var closeDim = vDims[1];
  54896. var lowestDim = vDims[2];
  54897. var highestDim = vDims[3];
  54898. data.setLayout({
  54899. candleWidth: candleWidth,
  54900. // The value is experimented visually.
  54901. isSimpleBox: candleWidth <= 1.3
  54902. });
  54903. if (cDim == null || vDims.length < 4) {
  54904. return;
  54905. }
  54906. return {
  54907. progress: seriesModel.pipelineContext.large
  54908. ? largeProgress : normalProgress
  54909. };
  54910. function normalProgress(params, data) {
  54911. var dataIndex;
  54912. while ((dataIndex = params.next()) != null) {
  54913. var axisDimVal = data.get(cDim, dataIndex);
  54914. var openVal = data.get(openDim, dataIndex);
  54915. var closeVal = data.get(closeDim, dataIndex);
  54916. var lowestVal = data.get(lowestDim, dataIndex);
  54917. var highestVal = data.get(highestDim, dataIndex);
  54918. var ocLow = Math.min(openVal, closeVal);
  54919. var ocHigh = Math.max(openVal, closeVal);
  54920. var ocLowPoint = getPoint(ocLow, axisDimVal);
  54921. var ocHighPoint = getPoint(ocHigh, axisDimVal);
  54922. var lowestPoint = getPoint(lowestVal, axisDimVal);
  54923. var highestPoint = getPoint(highestVal, axisDimVal);
  54924. var ends = [];
  54925. addBodyEnd(ends, ocHighPoint, 0);
  54926. addBodyEnd(ends, ocLowPoint, 1);
  54927. ends.push(
  54928. subPixelOptimizePoint(highestPoint),
  54929. subPixelOptimizePoint(ocHighPoint),
  54930. subPixelOptimizePoint(lowestPoint),
  54931. subPixelOptimizePoint(ocLowPoint)
  54932. );
  54933. data.setItemLayout(dataIndex, {
  54934. sign: getSign(data, dataIndex, openVal, closeVal, closeDim),
  54935. initBaseline: openVal > closeVal
  54936. ? ocHighPoint[vDimIdx] : ocLowPoint[vDimIdx], // open point.
  54937. ends: ends,
  54938. brushRect: makeBrushRect(lowestVal, highestVal, axisDimVal)
  54939. });
  54940. }
  54941. function getPoint(val, axisDimVal) {
  54942. var p = [];
  54943. p[cDimIdx] = axisDimVal;
  54944. p[vDimIdx] = val;
  54945. return (isNaN(axisDimVal) || isNaN(val))
  54946. ? [NaN, NaN]
  54947. : coordSys.dataToPoint(p);
  54948. }
  54949. function addBodyEnd(ends, point, start) {
  54950. var point1 = point.slice();
  54951. var point2 = point.slice();
  54952. point1[cDimIdx] = subPixelOptimize(
  54953. point1[cDimIdx] + candleWidth / 2, 1, false
  54954. );
  54955. point2[cDimIdx] = subPixelOptimize(
  54956. point2[cDimIdx] - candleWidth / 2, 1, true
  54957. );
  54958. start
  54959. ? ends.push(point1, point2)
  54960. : ends.push(point2, point1);
  54961. }
  54962. function makeBrushRect(lowestVal, highestVal, axisDimVal) {
  54963. var pmin = getPoint(lowestVal, axisDimVal);
  54964. var pmax = getPoint(highestVal, axisDimVal);
  54965. pmin[cDimIdx] -= candleWidth / 2;
  54966. pmax[cDimIdx] -= candleWidth / 2;
  54967. return {
  54968. x: pmin[0],
  54969. y: pmin[1],
  54970. width: vDimIdx ? candleWidth : pmax[0] - pmin[0],
  54971. height: vDimIdx ? pmax[1] - pmin[1] : candleWidth
  54972. };
  54973. }
  54974. function subPixelOptimizePoint(point) {
  54975. point[cDimIdx] = subPixelOptimize(point[cDimIdx], 1);
  54976. return point;
  54977. }
  54978. }
  54979. function largeProgress(params, data) {
  54980. // Structure: [sign, x, yhigh, ylow, sign, x, yhigh, ylow, ...]
  54981. var points = new LargeArr$1(params.count * 5);
  54982. var offset = 0;
  54983. var point;
  54984. var tmpIn = [];
  54985. var tmpOut = [];
  54986. var dataIndex;
  54987. while ((dataIndex = params.next()) != null) {
  54988. var axisDimVal = data.get(cDim, dataIndex);
  54989. var openVal = data.get(openDim, dataIndex);
  54990. var closeVal = data.get(closeDim, dataIndex);
  54991. var lowestVal = data.get(lowestDim, dataIndex);
  54992. var highestVal = data.get(highestDim, dataIndex);
  54993. if (isNaN(axisDimVal) || isNaN(lowestVal) || isNaN(highestVal)) {
  54994. points[offset++] = NaN;
  54995. offset += 4;
  54996. continue;
  54997. }
  54998. points[offset++] = getSign(data, dataIndex, openVal, closeVal, closeDim);
  54999. tmpIn[cDimIdx] = axisDimVal;
  55000. tmpIn[vDimIdx] = lowestVal;
  55001. point = coordSys.dataToPoint(tmpIn, null, tmpOut);
  55002. points[offset++] = point ? point[0] : NaN;
  55003. points[offset++] = point ? point[1] : NaN;
  55004. tmpIn[vDimIdx] = highestVal;
  55005. point = coordSys.dataToPoint(tmpIn, null, tmpOut);
  55006. points[offset++] = point ? point[1] : NaN;
  55007. }
  55008. data.setLayout('largePoints', points);
  55009. }
  55010. }
  55011. };
  55012. function getSign(data, dataIndex, openVal, closeVal, closeDim) {
  55013. var sign;
  55014. if (openVal > closeVal) {
  55015. sign = -1;
  55016. }
  55017. else if (openVal < closeVal) {
  55018. sign = 1;
  55019. }
  55020. else {
  55021. sign = dataIndex > 0
  55022. // If close === open, compare with close of last record
  55023. ? (data.get(closeDim, dataIndex - 1) <= closeVal ? 1 : -1)
  55024. // No record of previous, set to be positive
  55025. : 1;
  55026. }
  55027. return sign;
  55028. }
  55029. function calculateCandleWidth(seriesModel, data) {
  55030. var baseAxis = seriesModel.getBaseAxis();
  55031. var extent;
  55032. var bandWidth = baseAxis.type === 'category'
  55033. ? baseAxis.getBandWidth()
  55034. : (
  55035. extent = baseAxis.getExtent(),
  55036. Math.abs(extent[1] - extent[0]) / data.count()
  55037. );
  55038. var barMaxWidth = parsePercent$1(
  55039. retrieve2(seriesModel.get('barMaxWidth'), bandWidth),
  55040. bandWidth
  55041. );
  55042. var barMinWidth = parsePercent$1(
  55043. retrieve2(seriesModel.get('barMinWidth'), 1),
  55044. bandWidth
  55045. );
  55046. var barWidth = seriesModel.get('barWidth');
  55047. return barWidth != null
  55048. ? parsePercent$1(barWidth, bandWidth)
  55049. // Put max outer to ensure bar visible in spite of overlap.
  55050. : Math.max(Math.min(bandWidth / 2, barMaxWidth), barMinWidth);
  55051. }
  55052. /*
  55053. * Licensed to the Apache Software Foundation (ASF) under one
  55054. * or more contributor license agreements. See the NOTICE file
  55055. * distributed with this work for additional information
  55056. * regarding copyright ownership. The ASF licenses this file
  55057. * to you under the Apache License, Version 2.0 (the
  55058. * "License"); you may not use this file except in compliance
  55059. * with the License. You may obtain a copy of the License at
  55060. *
  55061. * http://www.apache.org/licenses/LICENSE-2.0
  55062. *
  55063. * Unless required by applicable law or agreed to in writing,
  55064. * software distributed under the License is distributed on an
  55065. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  55066. * KIND, either express or implied. See the License for the
  55067. * specific language governing permissions and limitations
  55068. * under the License.
  55069. */
  55070. registerPreprocessor(preprocessor);
  55071. registerVisual(candlestickVisual);
  55072. registerLayout(candlestickLayout);
  55073. /*
  55074. * Licensed to the Apache Software Foundation (ASF) under one
  55075. * or more contributor license agreements. See the NOTICE file
  55076. * distributed with this work for additional information
  55077. * regarding copyright ownership. The ASF licenses this file
  55078. * to you under the Apache License, Version 2.0 (the
  55079. * "License"); you may not use this file except in compliance
  55080. * with the License. You may obtain a copy of the License at
  55081. *
  55082. * http://www.apache.org/licenses/LICENSE-2.0
  55083. *
  55084. * Unless required by applicable law or agreed to in writing,
  55085. * software distributed under the License is distributed on an
  55086. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  55087. * KIND, either express or implied. See the License for the
  55088. * specific language governing permissions and limitations
  55089. * under the License.
  55090. */
  55091. SeriesModel.extend({
  55092. type: 'series.effectScatter',
  55093. dependencies: ['grid', 'polar'],
  55094. getInitialData: function (option, ecModel) {
  55095. return createListFromArray(this.getSource(), this);
  55096. },
  55097. brushSelector: 'point',
  55098. defaultOption: {
  55099. coordinateSystem: 'cartesian2d',
  55100. zlevel: 0,
  55101. z: 2,
  55102. legendHoverLink: true,
  55103. effectType: 'ripple',
  55104. progressive: 0,
  55105. // When to show the effect, option: 'render'|'emphasis'
  55106. showEffectOn: 'render',
  55107. // Ripple effect config
  55108. rippleEffect: {
  55109. period: 4,
  55110. // Scale of ripple
  55111. scale: 2.5,
  55112. // Brush type can be fill or stroke
  55113. brushType: 'fill'
  55114. },
  55115. // Cartesian coordinate system
  55116. // xAxisIndex: 0,
  55117. // yAxisIndex: 0,
  55118. // Polar coordinate system
  55119. // polarIndex: 0,
  55120. // Geo coordinate system
  55121. // geoIndex: 0,
  55122. // symbol: null, // 图形类型
  55123. symbolSize: 10 // 图形大小,半宽(半径)参数,当图形为方向或菱形则总宽度为symbolSize * 2
  55124. // symbolRotate: null, // 图形旋转控制
  55125. // large: false,
  55126. // Available when large is true
  55127. // largeThreshold: 2000,
  55128. // itemStyle: {
  55129. // opacity: 1
  55130. // }
  55131. }
  55132. });
  55133. /*
  55134. * Licensed to the Apache Software Foundation (ASF) under one
  55135. * or more contributor license agreements. See the NOTICE file
  55136. * distributed with this work for additional information
  55137. * regarding copyright ownership. The ASF licenses this file
  55138. * to you under the Apache License, Version 2.0 (the
  55139. * "License"); you may not use this file except in compliance
  55140. * with the License. You may obtain a copy of the License at
  55141. *
  55142. * http://www.apache.org/licenses/LICENSE-2.0
  55143. *
  55144. * Unless required by applicable law or agreed to in writing,
  55145. * software distributed under the License is distributed on an
  55146. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  55147. * KIND, either express or implied. See the License for the
  55148. * specific language governing permissions and limitations
  55149. * under the License.
  55150. */
  55151. /**
  55152. * Symbol with ripple effect
  55153. * @module echarts/chart/helper/EffectSymbol
  55154. */
  55155. var EFFECT_RIPPLE_NUMBER = 3;
  55156. function normalizeSymbolSize$1(symbolSize) {
  55157. if (!isArray(symbolSize)) {
  55158. symbolSize = [+symbolSize, +symbolSize];
  55159. }
  55160. return symbolSize;
  55161. }
  55162. function updateRipplePath(rippleGroup, effectCfg) {
  55163. rippleGroup.eachChild(function (ripplePath) {
  55164. ripplePath.attr({
  55165. z: effectCfg.z,
  55166. zlevel: effectCfg.zlevel,
  55167. style: {
  55168. stroke: effectCfg.brushType === 'stroke' ? effectCfg.color : null,
  55169. fill: effectCfg.brushType === 'fill' ? effectCfg.color : null
  55170. }
  55171. });
  55172. });
  55173. }
  55174. /**
  55175. * @constructor
  55176. * @param {module:echarts/data/List} data
  55177. * @param {number} idx
  55178. * @extends {module:zrender/graphic/Group}
  55179. */
  55180. function EffectSymbol(data, idx) {
  55181. Group.call(this);
  55182. var symbol = new SymbolClz$1(data, idx);
  55183. var rippleGroup = new Group();
  55184. this.add(symbol);
  55185. this.add(rippleGroup);
  55186. rippleGroup.beforeUpdate = function () {
  55187. this.attr(symbol.getScale());
  55188. };
  55189. this.updateData(data, idx);
  55190. }
  55191. var effectSymbolProto = EffectSymbol.prototype;
  55192. effectSymbolProto.stopEffectAnimation = function () {
  55193. this.childAt(1).removeAll();
  55194. };
  55195. effectSymbolProto.startEffectAnimation = function (effectCfg) {
  55196. var symbolType = effectCfg.symbolType;
  55197. var color = effectCfg.color;
  55198. var rippleGroup = this.childAt(1);
  55199. for (var i = 0; i < EFFECT_RIPPLE_NUMBER; i++) {
  55200. // var ripplePath = createSymbol(
  55201. // symbolType, -0.5, -0.5, 1, 1, color
  55202. // );
  55203. // If width/height are set too small (e.g., set to 1) on ios10
  55204. // and macOS Sierra, a circle stroke become a rect, no matter what
  55205. // the scale is set. So we set width/height as 2. See #4136.
  55206. var ripplePath = createSymbol(
  55207. symbolType, -1, -1, 2, 2, color
  55208. );
  55209. ripplePath.attr({
  55210. style: {
  55211. strokeNoScale: true
  55212. },
  55213. z2: 99,
  55214. silent: true,
  55215. scale: [0.5, 0.5]
  55216. });
  55217. var delay = -i / EFFECT_RIPPLE_NUMBER * effectCfg.period + effectCfg.effectOffset;
  55218. // TODO Configurable effectCfg.period
  55219. ripplePath.animate('', true)
  55220. .when(effectCfg.period, {
  55221. scale: [effectCfg.rippleScale / 2, effectCfg.rippleScale / 2]
  55222. })
  55223. .delay(delay)
  55224. .start();
  55225. ripplePath.animateStyle(true)
  55226. .when(effectCfg.period, {
  55227. opacity: 0
  55228. })
  55229. .delay(delay)
  55230. .start();
  55231. rippleGroup.add(ripplePath);
  55232. }
  55233. updateRipplePath(rippleGroup, effectCfg);
  55234. };
  55235. /**
  55236. * Update effect symbol
  55237. */
  55238. effectSymbolProto.updateEffectAnimation = function (effectCfg) {
  55239. var oldEffectCfg = this._effectCfg;
  55240. var rippleGroup = this.childAt(1);
  55241. // Must reinitialize effect if following configuration changed
  55242. var DIFFICULT_PROPS = ['symbolType', 'period', 'rippleScale'];
  55243. for (var i = 0; i < DIFFICULT_PROPS.length; i++) {
  55244. var propName = DIFFICULT_PROPS[i];
  55245. if (oldEffectCfg[propName] !== effectCfg[propName]) {
  55246. this.stopEffectAnimation();
  55247. this.startEffectAnimation(effectCfg);
  55248. return;
  55249. }
  55250. }
  55251. updateRipplePath(rippleGroup, effectCfg);
  55252. };
  55253. /**
  55254. * Highlight symbol
  55255. */
  55256. effectSymbolProto.highlight = function () {
  55257. this.trigger('emphasis');
  55258. };
  55259. /**
  55260. * Downplay symbol
  55261. */
  55262. effectSymbolProto.downplay = function () {
  55263. this.trigger('normal');
  55264. };
  55265. /**
  55266. * Update symbol properties
  55267. * @param {module:echarts/data/List} data
  55268. * @param {number} idx
  55269. */
  55270. effectSymbolProto.updateData = function (data, idx) {
  55271. var seriesModel = data.hostModel;
  55272. this.childAt(0).updateData(data, idx);
  55273. var rippleGroup = this.childAt(1);
  55274. var itemModel = data.getItemModel(idx);
  55275. var symbolType = data.getItemVisual(idx, 'symbol');
  55276. var symbolSize = normalizeSymbolSize$1(data.getItemVisual(idx, 'symbolSize'));
  55277. var color = data.getItemVisual(idx, 'color');
  55278. rippleGroup.attr('scale', symbolSize);
  55279. rippleGroup.traverse(function (ripplePath) {
  55280. ripplePath.attr({
  55281. fill: color
  55282. });
  55283. });
  55284. var symbolOffset = itemModel.getShallow('symbolOffset');
  55285. if (symbolOffset) {
  55286. var pos = rippleGroup.position;
  55287. pos[0] = parsePercent$1(symbolOffset[0], symbolSize[0]);
  55288. pos[1] = parsePercent$1(symbolOffset[1], symbolSize[1]);
  55289. }
  55290. rippleGroup.rotation = (itemModel.getShallow('symbolRotate') || 0) * Math.PI / 180 || 0;
  55291. var effectCfg = {};
  55292. effectCfg.showEffectOn = seriesModel.get('showEffectOn');
  55293. effectCfg.rippleScale = itemModel.get('rippleEffect.scale');
  55294. effectCfg.brushType = itemModel.get('rippleEffect.brushType');
  55295. effectCfg.period = itemModel.get('rippleEffect.period') * 1000;
  55296. effectCfg.effectOffset = idx / data.count();
  55297. effectCfg.z = itemModel.getShallow('z') || 0;
  55298. effectCfg.zlevel = itemModel.getShallow('zlevel') || 0;
  55299. effectCfg.symbolType = symbolType;
  55300. effectCfg.color = color;
  55301. this.off('mouseover').off('mouseout').off('emphasis').off('normal');
  55302. if (effectCfg.showEffectOn === 'render') {
  55303. this._effectCfg
  55304. ? this.updateEffectAnimation(effectCfg)
  55305. : this.startEffectAnimation(effectCfg);
  55306. this._effectCfg = effectCfg;
  55307. }
  55308. else {
  55309. // Not keep old effect config
  55310. this._effectCfg = null;
  55311. this.stopEffectAnimation();
  55312. var symbol = this.childAt(0);
  55313. var onEmphasis = function () {
  55314. symbol.highlight();
  55315. if (effectCfg.showEffectOn !== 'render') {
  55316. this.startEffectAnimation(effectCfg);
  55317. }
  55318. };
  55319. var onNormal = function () {
  55320. symbol.downplay();
  55321. if (effectCfg.showEffectOn !== 'render') {
  55322. this.stopEffectAnimation();
  55323. }
  55324. };
  55325. this.on('mouseover', onEmphasis, this)
  55326. .on('mouseout', onNormal, this)
  55327. .on('emphasis', onEmphasis, this)
  55328. .on('normal', onNormal, this);
  55329. }
  55330. this._effectCfg = effectCfg;
  55331. };
  55332. effectSymbolProto.fadeOut = function (cb) {
  55333. this.off('mouseover').off('mouseout').off('emphasis').off('normal');
  55334. cb && cb();
  55335. };
  55336. inherits(EffectSymbol, Group);
  55337. /*
  55338. * Licensed to the Apache Software Foundation (ASF) under one
  55339. * or more contributor license agreements. See the NOTICE file
  55340. * distributed with this work for additional information
  55341. * regarding copyright ownership. The ASF licenses this file
  55342. * to you under the Apache License, Version 2.0 (the
  55343. * "License"); you may not use this file except in compliance
  55344. * with the License. You may obtain a copy of the License at
  55345. *
  55346. * http://www.apache.org/licenses/LICENSE-2.0
  55347. *
  55348. * Unless required by applicable law or agreed to in writing,
  55349. * software distributed under the License is distributed on an
  55350. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  55351. * KIND, either express or implied. See the License for the
  55352. * specific language governing permissions and limitations
  55353. * under the License.
  55354. */
  55355. extendChartView({
  55356. type: 'effectScatter',
  55357. init: function () {
  55358. this._symbolDraw = new SymbolDraw(EffectSymbol);
  55359. },
  55360. render: function (seriesModel, ecModel, api) {
  55361. var data = seriesModel.getData();
  55362. var effectSymbolDraw = this._symbolDraw;
  55363. effectSymbolDraw.updateData(data);
  55364. this.group.add(effectSymbolDraw.group);
  55365. },
  55366. updateTransform: function (seriesModel, ecModel, api) {
  55367. var data = seriesModel.getData();
  55368. this.group.dirty();
  55369. var res = pointsLayout().reset(seriesModel);
  55370. if (res.progress) {
  55371. res.progress({ start: 0, end: data.count() }, data);
  55372. }
  55373. this._symbolDraw.updateLayout(data);
  55374. },
  55375. _updateGroupTransform: function (seriesModel) {
  55376. var coordSys = seriesModel.coordinateSystem;
  55377. if (coordSys && coordSys.getRoamTransform) {
  55378. this.group.transform = clone$2(coordSys.getRoamTransform());
  55379. this.group.decomposeTransform();
  55380. }
  55381. },
  55382. remove: function (ecModel, api) {
  55383. this._symbolDraw && this._symbolDraw.remove(api);
  55384. },
  55385. dispose: function () {}
  55386. });
  55387. /*
  55388. * Licensed to the Apache Software Foundation (ASF) under one
  55389. * or more contributor license agreements. See the NOTICE file
  55390. * distributed with this work for additional information
  55391. * regarding copyright ownership. The ASF licenses this file
  55392. * to you under the Apache License, Version 2.0 (the
  55393. * "License"); you may not use this file except in compliance
  55394. * with the License. You may obtain a copy of the License at
  55395. *
  55396. * http://www.apache.org/licenses/LICENSE-2.0
  55397. *
  55398. * Unless required by applicable law or agreed to in writing,
  55399. * software distributed under the License is distributed on an
  55400. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  55401. * KIND, either express or implied. See the License for the
  55402. * specific language governing permissions and limitations
  55403. * under the License.
  55404. */
  55405. registerVisual(visualSymbol('effectScatter', 'circle'));
  55406. registerLayout(pointsLayout('effectScatter'));
  55407. /*
  55408. * Licensed to the Apache Software Foundation (ASF) under one
  55409. * or more contributor license agreements. See the NOTICE file
  55410. * distributed with this work for additional information
  55411. * regarding copyright ownership. The ASF licenses this file
  55412. * to you under the Apache License, Version 2.0 (the
  55413. * "License"); you may not use this file except in compliance
  55414. * with the License. You may obtain a copy of the License at
  55415. *
  55416. * http://www.apache.org/licenses/LICENSE-2.0
  55417. *
  55418. * Unless required by applicable law or agreed to in writing,
  55419. * software distributed under the License is distributed on an
  55420. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  55421. * KIND, either express or implied. See the License for the
  55422. * specific language governing permissions and limitations
  55423. * under the License.
  55424. */
  55425. /* global Uint32Array, Float64Array, Float32Array */
  55426. var Uint32Arr = typeof Uint32Array === 'undefined' ? Array : Uint32Array;
  55427. var Float64Arr = typeof Float64Array === 'undefined' ? Array : Float64Array;
  55428. function compatEc2(seriesOpt) {
  55429. var data = seriesOpt.data;
  55430. if (data && data[0] && data[0][0] && data[0][0].coord) {
  55431. if (__DEV__) {
  55432. console.warn('Lines data configuration has been changed to'
  55433. + ' { coords:[[1,2],[2,3]] }');
  55434. }
  55435. seriesOpt.data = map(data, function (itemOpt) {
  55436. var coords = [
  55437. itemOpt[0].coord, itemOpt[1].coord
  55438. ];
  55439. var target = {
  55440. coords: coords
  55441. };
  55442. if (itemOpt[0].name) {
  55443. target.fromName = itemOpt[0].name;
  55444. }
  55445. if (itemOpt[1].name) {
  55446. target.toName = itemOpt[1].name;
  55447. }
  55448. return mergeAll([target, itemOpt[0], itemOpt[1]]);
  55449. });
  55450. }
  55451. }
  55452. var LinesSeries = SeriesModel.extend({
  55453. type: 'series.lines',
  55454. dependencies: ['grid', 'polar'],
  55455. visualColorAccessPath: 'lineStyle.color',
  55456. init: function (option) {
  55457. // The input data may be null/undefined.
  55458. option.data = option.data || [];
  55459. // Not using preprocessor because mergeOption may not have series.type
  55460. compatEc2(option);
  55461. var result = this._processFlatCoordsArray(option.data);
  55462. this._flatCoords = result.flatCoords;
  55463. this._flatCoordsOffset = result.flatCoordsOffset;
  55464. if (result.flatCoords) {
  55465. option.data = new Float32Array(result.count);
  55466. }
  55467. LinesSeries.superApply(this, 'init', arguments);
  55468. },
  55469. mergeOption: function (option) {
  55470. // The input data may be null/undefined.
  55471. option.data = option.data || [];
  55472. compatEc2(option);
  55473. if (option.data) {
  55474. // Only update when have option data to merge.
  55475. var result = this._processFlatCoordsArray(option.data);
  55476. this._flatCoords = result.flatCoords;
  55477. this._flatCoordsOffset = result.flatCoordsOffset;
  55478. if (result.flatCoords) {
  55479. option.data = new Float32Array(result.count);
  55480. }
  55481. }
  55482. LinesSeries.superApply(this, 'mergeOption', arguments);
  55483. },
  55484. appendData: function (params) {
  55485. var result = this._processFlatCoordsArray(params.data);
  55486. if (result.flatCoords) {
  55487. if (!this._flatCoords) {
  55488. this._flatCoords = result.flatCoords;
  55489. this._flatCoordsOffset = result.flatCoordsOffset;
  55490. }
  55491. else {
  55492. this._flatCoords = concatArray(this._flatCoords, result.flatCoords);
  55493. this._flatCoordsOffset = concatArray(this._flatCoordsOffset, result.flatCoordsOffset);
  55494. }
  55495. params.data = new Float32Array(result.count);
  55496. }
  55497. this.getRawData().appendData(params.data);
  55498. },
  55499. _getCoordsFromItemModel: function (idx) {
  55500. var itemModel = this.getData().getItemModel(idx);
  55501. var coords = (itemModel.option instanceof Array)
  55502. ? itemModel.option : itemModel.getShallow('coords');
  55503. if (__DEV__) {
  55504. if (!(coords instanceof Array && coords.length > 0 && coords[0] instanceof Array)) {
  55505. throw new Error(
  55506. 'Invalid coords ' + JSON.stringify(coords) + '. Lines must have 2d coords array in data item.'
  55507. );
  55508. }
  55509. }
  55510. return coords;
  55511. },
  55512. getLineCoordsCount: function (idx) {
  55513. if (this._flatCoordsOffset) {
  55514. return this._flatCoordsOffset[idx * 2 + 1];
  55515. }
  55516. else {
  55517. return this._getCoordsFromItemModel(idx).length;
  55518. }
  55519. },
  55520. getLineCoords: function (idx, out) {
  55521. if (this._flatCoordsOffset) {
  55522. var offset = this._flatCoordsOffset[idx * 2];
  55523. var len = this._flatCoordsOffset[idx * 2 + 1];
  55524. for (var i = 0; i < len; i++) {
  55525. out[i] = out[i] || [];
  55526. out[i][0] = this._flatCoords[offset + i * 2];
  55527. out[i][1] = this._flatCoords[offset + i * 2 + 1];
  55528. }
  55529. return len;
  55530. }
  55531. else {
  55532. var coords = this._getCoordsFromItemModel(idx);
  55533. for (var i = 0; i < coords.length; i++) {
  55534. out[i] = out[i] || [];
  55535. out[i][0] = coords[i][0];
  55536. out[i][1] = coords[i][1];
  55537. }
  55538. return coords.length;
  55539. }
  55540. },
  55541. _processFlatCoordsArray: function (data) {
  55542. var startOffset = 0;
  55543. if (this._flatCoords) {
  55544. startOffset = this._flatCoords.length;
  55545. }
  55546. // Stored as a typed array. In format
  55547. // Points Count(2) | x | y | x | y | Points Count(3) | x | y | x | y | x | y |
  55548. if (typeof data[0] === 'number') {
  55549. var len = data.length;
  55550. // Store offset and len of each segment
  55551. var coordsOffsetAndLenStorage = new Uint32Arr(len);
  55552. var coordsStorage = new Float64Arr(len);
  55553. var coordsCursor = 0;
  55554. var offsetCursor = 0;
  55555. var dataCount = 0;
  55556. for (var i = 0; i < len;) {
  55557. dataCount++;
  55558. var count = data[i++];
  55559. // Offset
  55560. coordsOffsetAndLenStorage[offsetCursor++] = coordsCursor + startOffset;
  55561. // Len
  55562. coordsOffsetAndLenStorage[offsetCursor++] = count;
  55563. for (var k = 0; k < count; k++) {
  55564. var x = data[i++];
  55565. var y = data[i++];
  55566. coordsStorage[coordsCursor++] = x;
  55567. coordsStorage[coordsCursor++] = y;
  55568. if (i > len) {
  55569. if (__DEV__) {
  55570. throw new Error('Invalid data format.');
  55571. }
  55572. }
  55573. }
  55574. }
  55575. return {
  55576. flatCoordsOffset: new Uint32Array(coordsOffsetAndLenStorage.buffer, 0, offsetCursor),
  55577. flatCoords: coordsStorage,
  55578. count: dataCount
  55579. };
  55580. }
  55581. return {
  55582. flatCoordsOffset: null,
  55583. flatCoords: null,
  55584. count: data.length
  55585. };
  55586. },
  55587. getInitialData: function (option, ecModel) {
  55588. if (__DEV__) {
  55589. var CoordSys = CoordinateSystemManager.get(option.coordinateSystem);
  55590. if (!CoordSys) {
  55591. throw new Error('Unkown coordinate system ' + option.coordinateSystem);
  55592. }
  55593. }
  55594. var lineData = new List(['value'], this);
  55595. lineData.hasItemOption = false;
  55596. lineData.initData(option.data, [], function (dataItem, dimName, dataIndex, dimIndex) {
  55597. // dataItem is simply coords
  55598. if (dataItem instanceof Array) {
  55599. return NaN;
  55600. }
  55601. else {
  55602. lineData.hasItemOption = true;
  55603. var value = dataItem.value;
  55604. if (value != null) {
  55605. return value instanceof Array ? value[dimIndex] : value;
  55606. }
  55607. }
  55608. });
  55609. return lineData;
  55610. },
  55611. formatTooltip: function (dataIndex) {
  55612. var data = this.getData();
  55613. var itemModel = data.getItemModel(dataIndex);
  55614. var name = itemModel.get('name');
  55615. if (name) {
  55616. return name;
  55617. }
  55618. var fromName = itemModel.get('fromName');
  55619. var toName = itemModel.get('toName');
  55620. var html = [];
  55621. fromName != null && html.push(fromName);
  55622. toName != null && html.push(toName);
  55623. return encodeHTML(html.join(' > '));
  55624. },
  55625. preventIncremental: function () {
  55626. return !!this.get('effect.show');
  55627. },
  55628. getProgressive: function () {
  55629. var progressive = this.option.progressive;
  55630. if (progressive == null) {
  55631. return this.option.large ? 1e4 : this.get('progressive');
  55632. }
  55633. return progressive;
  55634. },
  55635. getProgressiveThreshold: function () {
  55636. var progressiveThreshold = this.option.progressiveThreshold;
  55637. if (progressiveThreshold == null) {
  55638. return this.option.large ? 2e4 : this.get('progressiveThreshold');
  55639. }
  55640. return progressiveThreshold;
  55641. },
  55642. defaultOption: {
  55643. coordinateSystem: 'geo',
  55644. zlevel: 0,
  55645. z: 2,
  55646. legendHoverLink: true,
  55647. hoverAnimation: true,
  55648. // Cartesian coordinate system
  55649. xAxisIndex: 0,
  55650. yAxisIndex: 0,
  55651. symbol: ['none', 'none'],
  55652. symbolSize: [10, 10],
  55653. // Geo coordinate system
  55654. geoIndex: 0,
  55655. effect: {
  55656. show: false,
  55657. period: 4,
  55658. // Animation delay. support callback
  55659. // delay: 0,
  55660. // If move with constant speed px/sec
  55661. // period will be ignored if this property is > 0,
  55662. constantSpeed: 0,
  55663. symbol: 'circle',
  55664. symbolSize: 3,
  55665. loop: true,
  55666. // Length of trail, 0 - 1
  55667. trailLength: 0.2
  55668. // Same with lineStyle.color
  55669. // color
  55670. },
  55671. large: false,
  55672. // Available when large is true
  55673. largeThreshold: 2000,
  55674. // If lines are polyline
  55675. // polyline not support curveness, label, animation
  55676. polyline: false,
  55677. label: {
  55678. show: false,
  55679. position: 'end'
  55680. // distance: 5,
  55681. // formatter: 标签文本格式器,同Tooltip.formatter,不支持异步回调
  55682. },
  55683. lineStyle: {
  55684. opacity: 0.5
  55685. }
  55686. }
  55687. });
  55688. /*
  55689. * Licensed to the Apache Software Foundation (ASF) under one
  55690. * or more contributor license agreements. See the NOTICE file
  55691. * distributed with this work for additional information
  55692. * regarding copyright ownership. The ASF licenses this file
  55693. * to you under the Apache License, Version 2.0 (the
  55694. * "License"); you may not use this file except in compliance
  55695. * with the License. You may obtain a copy of the License at
  55696. *
  55697. * http://www.apache.org/licenses/LICENSE-2.0
  55698. *
  55699. * Unless required by applicable law or agreed to in writing,
  55700. * software distributed under the License is distributed on an
  55701. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  55702. * KIND, either express or implied. See the License for the
  55703. * specific language governing permissions and limitations
  55704. * under the License.
  55705. */
  55706. /**
  55707. * Provide effect for line
  55708. * @module echarts/chart/helper/EffectLine
  55709. */
  55710. /**
  55711. * @constructor
  55712. * @extends {module:zrender/graphic/Group}
  55713. * @alias {module:echarts/chart/helper/Line}
  55714. */
  55715. function EffectLine(lineData, idx, seriesScope) {
  55716. Group.call(this);
  55717. this.add(this.createLine(lineData, idx, seriesScope));
  55718. this._updateEffectSymbol(lineData, idx);
  55719. }
  55720. var effectLineProto = EffectLine.prototype;
  55721. effectLineProto.createLine = function (lineData, idx, seriesScope) {
  55722. return new Line$1(lineData, idx, seriesScope);
  55723. };
  55724. effectLineProto._updateEffectSymbol = function (lineData, idx) {
  55725. var itemModel = lineData.getItemModel(idx);
  55726. var effectModel = itemModel.getModel('effect');
  55727. var size = effectModel.get('symbolSize');
  55728. var symbolType = effectModel.get('symbol');
  55729. if (!isArray(size)) {
  55730. size = [size, size];
  55731. }
  55732. var color = effectModel.get('color') || lineData.getItemVisual(idx, 'color');
  55733. var symbol = this.childAt(1);
  55734. if (this._symbolType !== symbolType) {
  55735. // Remove previous
  55736. this.remove(symbol);
  55737. symbol = createSymbol(
  55738. symbolType, -0.5, -0.5, 1, 1, color
  55739. );
  55740. symbol.z2 = 100;
  55741. symbol.culling = true;
  55742. this.add(symbol);
  55743. }
  55744. // Symbol may be removed if loop is false
  55745. if (!symbol) {
  55746. return;
  55747. }
  55748. // Shadow color is same with color in default
  55749. symbol.setStyle('shadowColor', color);
  55750. symbol.setStyle(effectModel.getItemStyle(['color']));
  55751. symbol.attr('scale', size);
  55752. symbol.setColor(color);
  55753. symbol.attr('scale', size);
  55754. this._symbolType = symbolType;
  55755. this._updateEffectAnimation(lineData, effectModel, idx);
  55756. };
  55757. effectLineProto._updateEffectAnimation = function (lineData, effectModel, idx) {
  55758. var symbol = this.childAt(1);
  55759. if (!symbol) {
  55760. return;
  55761. }
  55762. var self = this;
  55763. var points = lineData.getItemLayout(idx);
  55764. var period = effectModel.get('period') * 1000;
  55765. var loop = effectModel.get('loop');
  55766. var constantSpeed = effectModel.get('constantSpeed');
  55767. var delayExpr = retrieve(effectModel.get('delay'), function (idx) {
  55768. return idx / lineData.count() * period / 3;
  55769. });
  55770. var isDelayFunc = typeof delayExpr === 'function';
  55771. // Ignore when updating
  55772. symbol.ignore = true;
  55773. this.updateAnimationPoints(symbol, points);
  55774. if (constantSpeed > 0) {
  55775. period = this.getLineLength(symbol) / constantSpeed * 1000;
  55776. }
  55777. if (period !== this._period || loop !== this._loop) {
  55778. symbol.stopAnimation();
  55779. var delay = delayExpr;
  55780. if (isDelayFunc) {
  55781. delay = delayExpr(idx);
  55782. }
  55783. if (symbol.__t > 0) {
  55784. delay = -period * symbol.__t;
  55785. }
  55786. symbol.__t = 0;
  55787. var animator = symbol.animate('', loop)
  55788. .when(period, {
  55789. __t: 1
  55790. })
  55791. .delay(delay)
  55792. .during(function () {
  55793. self.updateSymbolPosition(symbol);
  55794. });
  55795. if (!loop) {
  55796. animator.done(function () {
  55797. self.remove(symbol);
  55798. });
  55799. }
  55800. animator.start();
  55801. }
  55802. this._period = period;
  55803. this._loop = loop;
  55804. };
  55805. effectLineProto.getLineLength = function (symbol) {
  55806. // Not so accurate
  55807. return (dist(symbol.__p1, symbol.__cp1)
  55808. + dist(symbol.__cp1, symbol.__p2));
  55809. };
  55810. effectLineProto.updateAnimationPoints = function (symbol, points) {
  55811. symbol.__p1 = points[0];
  55812. symbol.__p2 = points[1];
  55813. symbol.__cp1 = points[2] || [
  55814. (points[0][0] + points[1][0]) / 2,
  55815. (points[0][1] + points[1][1]) / 2
  55816. ];
  55817. };
  55818. effectLineProto.updateData = function (lineData, idx, seriesScope) {
  55819. this.childAt(0).updateData(lineData, idx, seriesScope);
  55820. this._updateEffectSymbol(lineData, idx);
  55821. };
  55822. effectLineProto.updateSymbolPosition = function (symbol) {
  55823. var p1 = symbol.__p1;
  55824. var p2 = symbol.__p2;
  55825. var cp1 = symbol.__cp1;
  55826. var t = symbol.__t;
  55827. var pos = symbol.position;
  55828. var quadraticAt$$1 = quadraticAt;
  55829. var quadraticDerivativeAt$$1 = quadraticDerivativeAt;
  55830. pos[0] = quadraticAt$$1(p1[0], cp1[0], p2[0], t);
  55831. pos[1] = quadraticAt$$1(p1[1], cp1[1], p2[1], t);
  55832. // Tangent
  55833. var tx = quadraticDerivativeAt$$1(p1[0], cp1[0], p2[0], t);
  55834. var ty = quadraticDerivativeAt$$1(p1[1], cp1[1], p2[1], t);
  55835. symbol.rotation = -Math.atan2(ty, tx) - Math.PI / 2;
  55836. symbol.ignore = false;
  55837. };
  55838. effectLineProto.updateLayout = function (lineData, idx) {
  55839. this.childAt(0).updateLayout(lineData, idx);
  55840. var effectModel = lineData.getItemModel(idx).getModel('effect');
  55841. this._updateEffectAnimation(lineData, effectModel, idx);
  55842. };
  55843. inherits(EffectLine, Group);
  55844. /*
  55845. * Licensed to the Apache Software Foundation (ASF) under one
  55846. * or more contributor license agreements. See the NOTICE file
  55847. * distributed with this work for additional information
  55848. * regarding copyright ownership. The ASF licenses this file
  55849. * to you under the Apache License, Version 2.0 (the
  55850. * "License"); you may not use this file except in compliance
  55851. * with the License. You may obtain a copy of the License at
  55852. *
  55853. * http://www.apache.org/licenses/LICENSE-2.0
  55854. *
  55855. * Unless required by applicable law or agreed to in writing,
  55856. * software distributed under the License is distributed on an
  55857. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  55858. * KIND, either express or implied. See the License for the
  55859. * specific language governing permissions and limitations
  55860. * under the License.
  55861. */
  55862. /**
  55863. * @module echarts/chart/helper/Line
  55864. */
  55865. /**
  55866. * @constructor
  55867. * @extends {module:zrender/graphic/Group}
  55868. * @alias {module:echarts/chart/helper/Polyline}
  55869. */
  55870. function Polyline$2(lineData, idx, seriesScope) {
  55871. Group.call(this);
  55872. this._createPolyline(lineData, idx, seriesScope);
  55873. }
  55874. var polylineProto = Polyline$2.prototype;
  55875. polylineProto._createPolyline = function (lineData, idx, seriesScope) {
  55876. // var seriesModel = lineData.hostModel;
  55877. var points = lineData.getItemLayout(idx);
  55878. var line = new Polyline({
  55879. shape: {
  55880. points: points
  55881. }
  55882. });
  55883. this.add(line);
  55884. this._updateCommonStl(lineData, idx, seriesScope);
  55885. };
  55886. polylineProto.updateData = function (lineData, idx, seriesScope) {
  55887. var seriesModel = lineData.hostModel;
  55888. var line = this.childAt(0);
  55889. var target = {
  55890. shape: {
  55891. points: lineData.getItemLayout(idx)
  55892. }
  55893. };
  55894. updateProps(line, target, seriesModel, idx);
  55895. this._updateCommonStl(lineData, idx, seriesScope);
  55896. };
  55897. polylineProto._updateCommonStl = function (lineData, idx, seriesScope) {
  55898. var line = this.childAt(0);
  55899. var itemModel = lineData.getItemModel(idx);
  55900. var visualColor = lineData.getItemVisual(idx, 'color');
  55901. var lineStyle = seriesScope && seriesScope.lineStyle;
  55902. var hoverLineStyle = seriesScope && seriesScope.hoverLineStyle;
  55903. if (!seriesScope || lineData.hasItemOption) {
  55904. lineStyle = itemModel.getModel('lineStyle').getLineStyle();
  55905. hoverLineStyle = itemModel.getModel('emphasis.lineStyle').getLineStyle();
  55906. }
  55907. line.useStyle(defaults(
  55908. {
  55909. strokeNoScale: true,
  55910. fill: 'none',
  55911. stroke: visualColor
  55912. },
  55913. lineStyle
  55914. ));
  55915. line.hoverStyle = hoverLineStyle;
  55916. setHoverStyle(this);
  55917. };
  55918. polylineProto.updateLayout = function (lineData, idx) {
  55919. var polyline = this.childAt(0);
  55920. polyline.setShape('points', lineData.getItemLayout(idx));
  55921. };
  55922. inherits(Polyline$2, Group);
  55923. /*
  55924. * Licensed to the Apache Software Foundation (ASF) under one
  55925. * or more contributor license agreements. See the NOTICE file
  55926. * distributed with this work for additional information
  55927. * regarding copyright ownership. The ASF licenses this file
  55928. * to you under the Apache License, Version 2.0 (the
  55929. * "License"); you may not use this file except in compliance
  55930. * with the License. You may obtain a copy of the License at
  55931. *
  55932. * http://www.apache.org/licenses/LICENSE-2.0
  55933. *
  55934. * Unless required by applicable law or agreed to in writing,
  55935. * software distributed under the License is distributed on an
  55936. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  55937. * KIND, either express or implied. See the License for the
  55938. * specific language governing permissions and limitations
  55939. * under the License.
  55940. */
  55941. /**
  55942. * Provide effect for line
  55943. * @module echarts/chart/helper/EffectLine
  55944. */
  55945. /**
  55946. * @constructor
  55947. * @extends {module:echarts/chart/helper/EffectLine}
  55948. * @alias {module:echarts/chart/helper/Polyline}
  55949. */
  55950. function EffectPolyline(lineData, idx, seriesScope) {
  55951. EffectLine.call(this, lineData, idx, seriesScope);
  55952. this._lastFrame = 0;
  55953. this._lastFramePercent = 0;
  55954. }
  55955. var effectPolylineProto = EffectPolyline.prototype;
  55956. // Overwrite
  55957. effectPolylineProto.createLine = function (lineData, idx, seriesScope) {
  55958. return new Polyline$2(lineData, idx, seriesScope);
  55959. };
  55960. // Overwrite
  55961. effectPolylineProto.updateAnimationPoints = function (symbol, points) {
  55962. this._points = points;
  55963. var accLenArr = [0];
  55964. var len$$1 = 0;
  55965. for (var i = 1; i < points.length; i++) {
  55966. var p1 = points[i - 1];
  55967. var p2 = points[i];
  55968. len$$1 += dist(p1, p2);
  55969. accLenArr.push(len$$1);
  55970. }
  55971. if (len$$1 === 0) {
  55972. return;
  55973. }
  55974. for (var i = 0; i < accLenArr.length; i++) {
  55975. accLenArr[i] /= len$$1;
  55976. }
  55977. this._offsets = accLenArr;
  55978. this._length = len$$1;
  55979. };
  55980. // Overwrite
  55981. effectPolylineProto.getLineLength = function (symbol) {
  55982. return this._length;
  55983. };
  55984. // Overwrite
  55985. effectPolylineProto.updateSymbolPosition = function (symbol) {
  55986. var t = symbol.__t;
  55987. var points = this._points;
  55988. var offsets = this._offsets;
  55989. var len$$1 = points.length;
  55990. if (!offsets) {
  55991. // Has length 0
  55992. return;
  55993. }
  55994. var lastFrame = this._lastFrame;
  55995. var frame;
  55996. if (t < this._lastFramePercent) {
  55997. // Start from the next frame
  55998. // PENDING start from lastFrame ?
  55999. var start = Math.min(lastFrame + 1, len$$1 - 1);
  56000. for (frame = start; frame >= 0; frame--) {
  56001. if (offsets[frame] <= t) {
  56002. break;
  56003. }
  56004. }
  56005. // PENDING really need to do this ?
  56006. frame = Math.min(frame, len$$1 - 2);
  56007. }
  56008. else {
  56009. for (var frame = lastFrame; frame < len$$1; frame++) {
  56010. if (offsets[frame] > t) {
  56011. break;
  56012. }
  56013. }
  56014. frame = Math.min(frame - 1, len$$1 - 2);
  56015. }
  56016. lerp(
  56017. symbol.position, points[frame], points[frame + 1],
  56018. (t - offsets[frame]) / (offsets[frame + 1] - offsets[frame])
  56019. );
  56020. var tx = points[frame + 1][0] - points[frame][0];
  56021. var ty = points[frame + 1][1] - points[frame][1];
  56022. symbol.rotation = -Math.atan2(ty, tx) - Math.PI / 2;
  56023. this._lastFrame = frame;
  56024. this._lastFramePercent = t;
  56025. symbol.ignore = false;
  56026. };
  56027. inherits(EffectPolyline, EffectLine);
  56028. /*
  56029. * Licensed to the Apache Software Foundation (ASF) under one
  56030. * or more contributor license agreements. See the NOTICE file
  56031. * distributed with this work for additional information
  56032. * regarding copyright ownership. The ASF licenses this file
  56033. * to you under the Apache License, Version 2.0 (the
  56034. * "License"); you may not use this file except in compliance
  56035. * with the License. You may obtain a copy of the License at
  56036. *
  56037. * http://www.apache.org/licenses/LICENSE-2.0
  56038. *
  56039. * Unless required by applicable law or agreed to in writing,
  56040. * software distributed under the License is distributed on an
  56041. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  56042. * KIND, either express or implied. See the License for the
  56043. * specific language governing permissions and limitations
  56044. * under the License.
  56045. */
  56046. // TODO Batch by color
  56047. var LargeLineShape = extendShape({
  56048. shape: {
  56049. polyline: false,
  56050. curveness: 0,
  56051. segs: []
  56052. },
  56053. buildPath: function (path, shape) {
  56054. var segs = shape.segs;
  56055. var curveness = shape.curveness;
  56056. if (shape.polyline) {
  56057. for (var i = 0; i < segs.length;) {
  56058. var count = segs[i++];
  56059. if (count > 0) {
  56060. path.moveTo(segs[i++], segs[i++]);
  56061. for (var k = 1; k < count; k++) {
  56062. path.lineTo(segs[i++], segs[i++]);
  56063. }
  56064. }
  56065. }
  56066. }
  56067. else {
  56068. for (var i = 0; i < segs.length;) {
  56069. var x0 = segs[i++];
  56070. var y0 = segs[i++];
  56071. var x1 = segs[i++];
  56072. var y1 = segs[i++];
  56073. path.moveTo(x0, y0);
  56074. if (curveness > 0) {
  56075. var x2 = (x0 + x1) / 2 - (y0 - y1) * curveness;
  56076. var y2 = (y0 + y1) / 2 - (x1 - x0) * curveness;
  56077. path.quadraticCurveTo(x2, y2, x1, y1);
  56078. }
  56079. else {
  56080. path.lineTo(x1, y1);
  56081. }
  56082. }
  56083. }
  56084. },
  56085. findDataIndex: function (x, y) {
  56086. var shape = this.shape;
  56087. var segs = shape.segs;
  56088. var curveness = shape.curveness;
  56089. if (shape.polyline) {
  56090. var dataIndex = 0;
  56091. for (var i = 0; i < segs.length;) {
  56092. var count = segs[i++];
  56093. if (count > 0) {
  56094. var x0 = segs[i++];
  56095. var y0 = segs[i++];
  56096. for (var k = 1; k < count; k++) {
  56097. var x1 = segs[i++];
  56098. var y1 = segs[i++];
  56099. if (containStroke$1(x0, y0, x1, y1)) {
  56100. return dataIndex;
  56101. }
  56102. }
  56103. }
  56104. dataIndex++;
  56105. }
  56106. }
  56107. else {
  56108. var dataIndex = 0;
  56109. for (var i = 0; i < segs.length;) {
  56110. var x0 = segs[i++];
  56111. var y0 = segs[i++];
  56112. var x1 = segs[i++];
  56113. var y1 = segs[i++];
  56114. if (curveness > 0) {
  56115. var x2 = (x0 + x1) / 2 - (y0 - y1) * curveness;
  56116. var y2 = (y0 + y1) / 2 - (x1 - x0) * curveness;
  56117. if (containStroke$3(x0, y0, x2, y2, x1, y1)) {
  56118. return dataIndex;
  56119. }
  56120. }
  56121. else {
  56122. if (containStroke$1(x0, y0, x1, y1)) {
  56123. return dataIndex;
  56124. }
  56125. }
  56126. dataIndex++;
  56127. }
  56128. }
  56129. return -1;
  56130. }
  56131. });
  56132. function LargeLineDraw() {
  56133. this.group = new Group();
  56134. }
  56135. var largeLineProto = LargeLineDraw.prototype;
  56136. largeLineProto.isPersistent = function () {
  56137. return !this._incremental;
  56138. };
  56139. /**
  56140. * Update symbols draw by new data
  56141. * @param {module:echarts/data/List} data
  56142. */
  56143. largeLineProto.updateData = function (data) {
  56144. this.group.removeAll();
  56145. var lineEl = new LargeLineShape({
  56146. rectHover: true,
  56147. cursor: 'default'
  56148. });
  56149. lineEl.setShape({
  56150. segs: data.getLayout('linesPoints')
  56151. });
  56152. this._setCommon(lineEl, data);
  56153. // Add back
  56154. this.group.add(lineEl);
  56155. this._incremental = null;
  56156. };
  56157. /**
  56158. * @override
  56159. */
  56160. largeLineProto.incrementalPrepareUpdate = function (data) {
  56161. this.group.removeAll();
  56162. this._clearIncremental();
  56163. if (data.count() > 5e5) {
  56164. if (!this._incremental) {
  56165. this._incremental = new IncrementalDisplayble({
  56166. silent: true
  56167. });
  56168. }
  56169. this.group.add(this._incremental);
  56170. }
  56171. else {
  56172. this._incremental = null;
  56173. }
  56174. };
  56175. /**
  56176. * @override
  56177. */
  56178. largeLineProto.incrementalUpdate = function (taskParams, data) {
  56179. var lineEl = new LargeLineShape();
  56180. lineEl.setShape({
  56181. segs: data.getLayout('linesPoints')
  56182. });
  56183. this._setCommon(lineEl, data, !!this._incremental);
  56184. if (!this._incremental) {
  56185. lineEl.rectHover = true;
  56186. lineEl.cursor = 'default';
  56187. lineEl.__startIndex = taskParams.start;
  56188. this.group.add(lineEl);
  56189. }
  56190. else {
  56191. this._incremental.addDisplayable(lineEl, true);
  56192. }
  56193. };
  56194. /**
  56195. * @override
  56196. */
  56197. largeLineProto.remove = function () {
  56198. this._clearIncremental();
  56199. this._incremental = null;
  56200. this.group.removeAll();
  56201. };
  56202. largeLineProto._setCommon = function (lineEl, data, isIncremental) {
  56203. var hostModel = data.hostModel;
  56204. lineEl.setShape({
  56205. polyline: hostModel.get('polyline'),
  56206. curveness: hostModel.get('lineStyle.curveness')
  56207. });
  56208. lineEl.useStyle(
  56209. hostModel.getModel('lineStyle').getLineStyle()
  56210. );
  56211. lineEl.style.strokeNoScale = true;
  56212. var visualColor = data.getVisual('color');
  56213. if (visualColor) {
  56214. lineEl.setStyle('stroke', visualColor);
  56215. }
  56216. lineEl.setStyle('fill');
  56217. if (!isIncremental) {
  56218. // Enable tooltip
  56219. // PENDING May have performance issue when path is extremely large
  56220. lineEl.seriesIndex = hostModel.seriesIndex;
  56221. lineEl.on('mousemove', function (e) {
  56222. lineEl.dataIndex = null;
  56223. var dataIndex = lineEl.findDataIndex(e.offsetX, e.offsetY);
  56224. if (dataIndex > 0) {
  56225. // Provide dataIndex for tooltip
  56226. lineEl.dataIndex = dataIndex + lineEl.__startIndex;
  56227. }
  56228. });
  56229. }
  56230. };
  56231. largeLineProto._clearIncremental = function () {
  56232. var incremental = this._incremental;
  56233. if (incremental) {
  56234. incremental.clearDisplaybles();
  56235. }
  56236. };
  56237. /*
  56238. * Licensed to the Apache Software Foundation (ASF) under one
  56239. * or more contributor license agreements. See the NOTICE file
  56240. * distributed with this work for additional information
  56241. * regarding copyright ownership. The ASF licenses this file
  56242. * to you under the Apache License, Version 2.0 (the
  56243. * "License"); you may not use this file except in compliance
  56244. * with the License. You may obtain a copy of the License at
  56245. *
  56246. * http://www.apache.org/licenses/LICENSE-2.0
  56247. *
  56248. * Unless required by applicable law or agreed to in writing,
  56249. * software distributed under the License is distributed on an
  56250. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  56251. * KIND, either express or implied. See the License for the
  56252. * specific language governing permissions and limitations
  56253. * under the License.
  56254. */
  56255. /* global Float32Array */
  56256. var linesLayout = {
  56257. seriesType: 'lines',
  56258. plan: createRenderPlanner(),
  56259. reset: function (seriesModel) {
  56260. var coordSys = seriesModel.coordinateSystem;
  56261. var isPolyline = seriesModel.get('polyline');
  56262. var isLarge = seriesModel.pipelineContext.large;
  56263. function progress(params, lineData) {
  56264. var lineCoords = [];
  56265. if (isLarge) {
  56266. var points;
  56267. var segCount = params.end - params.start;
  56268. if (isPolyline) {
  56269. var totalCoordsCount = 0;
  56270. for (var i = params.start; i < params.end; i++) {
  56271. totalCoordsCount += seriesModel.getLineCoordsCount(i);
  56272. }
  56273. points = new Float32Array(segCount + totalCoordsCount * 2);
  56274. }
  56275. else {
  56276. points = new Float32Array(segCount * 4);
  56277. }
  56278. var offset = 0;
  56279. var pt = [];
  56280. for (var i = params.start; i < params.end; i++) {
  56281. var len = seriesModel.getLineCoords(i, lineCoords);
  56282. if (isPolyline) {
  56283. points[offset++] = len;
  56284. }
  56285. for (var k = 0; k < len; k++) {
  56286. pt = coordSys.dataToPoint(lineCoords[k], false, pt);
  56287. points[offset++] = pt[0];
  56288. points[offset++] = pt[1];
  56289. }
  56290. }
  56291. lineData.setLayout('linesPoints', points);
  56292. }
  56293. else {
  56294. for (var i = params.start; i < params.end; i++) {
  56295. var itemModel = lineData.getItemModel(i);
  56296. var len = seriesModel.getLineCoords(i, lineCoords);
  56297. var pts = [];
  56298. if (isPolyline) {
  56299. for (var j = 0; j < len; j++) {
  56300. pts.push(coordSys.dataToPoint(lineCoords[j]));
  56301. }
  56302. }
  56303. else {
  56304. pts[0] = coordSys.dataToPoint(lineCoords[0]);
  56305. pts[1] = coordSys.dataToPoint(lineCoords[1]);
  56306. var curveness = itemModel.get('lineStyle.curveness');
  56307. if (+curveness) {
  56308. pts[2] = [
  56309. (pts[0][0] + pts[1][0]) / 2 - (pts[0][1] - pts[1][1]) * curveness,
  56310. (pts[0][1] + pts[1][1]) / 2 - (pts[1][0] - pts[0][0]) * curveness
  56311. ];
  56312. }
  56313. }
  56314. lineData.setItemLayout(i, pts);
  56315. }
  56316. }
  56317. }
  56318. return { progress: progress };
  56319. }
  56320. };
  56321. /*
  56322. * Licensed to the Apache Software Foundation (ASF) under one
  56323. * or more contributor license agreements. See the NOTICE file
  56324. * distributed with this work for additional information
  56325. * regarding copyright ownership. The ASF licenses this file
  56326. * to you under the Apache License, Version 2.0 (the
  56327. * "License"); you may not use this file except in compliance
  56328. * with the License. You may obtain a copy of the License at
  56329. *
  56330. * http://www.apache.org/licenses/LICENSE-2.0
  56331. *
  56332. * Unless required by applicable law or agreed to in writing,
  56333. * software distributed under the License is distributed on an
  56334. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  56335. * KIND, either express or implied. See the License for the
  56336. * specific language governing permissions and limitations
  56337. * under the License.
  56338. */
  56339. extendChartView({
  56340. type: 'lines',
  56341. init: function () {},
  56342. render: function (seriesModel, ecModel, api) {
  56343. var data = seriesModel.getData();
  56344. var lineDraw = this._updateLineDraw(data, seriesModel);
  56345. var zlevel = seriesModel.get('zlevel');
  56346. var trailLength = seriesModel.get('effect.trailLength');
  56347. var zr = api.getZr();
  56348. // Avoid the drag cause ghost shadow
  56349. // FIXME Better way ?
  56350. // SVG doesn't support
  56351. var isSvg = zr.painter.getType() === 'svg';
  56352. if (!isSvg) {
  56353. zr.painter.getLayer(zlevel).clear(true);
  56354. }
  56355. // Config layer with motion blur
  56356. if (this._lastZlevel != null && !isSvg) {
  56357. zr.configLayer(this._lastZlevel, {
  56358. motionBlur: false
  56359. });
  56360. }
  56361. if (this._showEffect(seriesModel) && trailLength) {
  56362. if (__DEV__) {
  56363. var notInIndividual = false;
  56364. ecModel.eachSeries(function (otherSeriesModel) {
  56365. if (otherSeriesModel !== seriesModel && otherSeriesModel.get('zlevel') === zlevel) {
  56366. notInIndividual = true;
  56367. }
  56368. });
  56369. notInIndividual && console.warn('Lines with trail effect should have an individual zlevel');
  56370. }
  56371. if (!isSvg) {
  56372. zr.configLayer(zlevel, {
  56373. motionBlur: true,
  56374. lastFrameAlpha: Math.max(Math.min(trailLength / 10 + 0.9, 1), 0)
  56375. });
  56376. }
  56377. }
  56378. lineDraw.updateData(data);
  56379. this._lastZlevel = zlevel;
  56380. this._finished = true;
  56381. },
  56382. incrementalPrepareRender: function (seriesModel, ecModel, api) {
  56383. var data = seriesModel.getData();
  56384. var lineDraw = this._updateLineDraw(data, seriesModel);
  56385. lineDraw.incrementalPrepareUpdate(data);
  56386. this._clearLayer(api);
  56387. this._finished = false;
  56388. },
  56389. incrementalRender: function (taskParams, seriesModel, ecModel) {
  56390. this._lineDraw.incrementalUpdate(taskParams, seriesModel.getData());
  56391. this._finished = taskParams.end === seriesModel.getData().count();
  56392. },
  56393. updateTransform: function (seriesModel, ecModel, api) {
  56394. var data = seriesModel.getData();
  56395. var pipelineContext = seriesModel.pipelineContext;
  56396. if (!this._finished || pipelineContext.large || pipelineContext.progressiveRender) {
  56397. // TODO Don't have to do update in large mode. Only do it when there are millions of data.
  56398. return {
  56399. update: true
  56400. };
  56401. }
  56402. else {
  56403. // TODO Use same logic with ScatterView.
  56404. // Manually update layout
  56405. var res = linesLayout.reset(seriesModel);
  56406. if (res.progress) {
  56407. res.progress({ start: 0, end: data.count() }, data);
  56408. }
  56409. this._lineDraw.updateLayout();
  56410. this._clearLayer(api);
  56411. }
  56412. },
  56413. _updateLineDraw: function (data, seriesModel) {
  56414. var lineDraw = this._lineDraw;
  56415. var hasEffect = this._showEffect(seriesModel);
  56416. var isPolyline = !!seriesModel.get('polyline');
  56417. var pipelineContext = seriesModel.pipelineContext;
  56418. var isLargeDraw = pipelineContext.large;
  56419. if (__DEV__) {
  56420. if (hasEffect && isLargeDraw) {
  56421. console.warn('Large lines not support effect');
  56422. }
  56423. }
  56424. if (!lineDraw
  56425. || hasEffect !== this._hasEffet
  56426. || isPolyline !== this._isPolyline
  56427. || isLargeDraw !== this._isLargeDraw
  56428. ) {
  56429. if (lineDraw) {
  56430. lineDraw.remove();
  56431. }
  56432. lineDraw = this._lineDraw = isLargeDraw
  56433. ? new LargeLineDraw()
  56434. : new LineDraw(
  56435. isPolyline
  56436. ? (hasEffect ? EffectPolyline : Polyline$2)
  56437. : (hasEffect ? EffectLine : Line$1)
  56438. );
  56439. this._hasEffet = hasEffect;
  56440. this._isPolyline = isPolyline;
  56441. this._isLargeDraw = isLargeDraw;
  56442. this.group.removeAll();
  56443. }
  56444. this.group.add(lineDraw.group);
  56445. return lineDraw;
  56446. },
  56447. _showEffect: function (seriesModel) {
  56448. return !!seriesModel.get('effect.show');
  56449. },
  56450. _clearLayer: function (api) {
  56451. // Not use motion when dragging or zooming
  56452. var zr = api.getZr();
  56453. var isSvg = zr.painter.getType() === 'svg';
  56454. if (!isSvg && this._lastZlevel != null) {
  56455. zr.painter.getLayer(this._lastZlevel).clear(true);
  56456. }
  56457. },
  56458. remove: function (ecModel, api) {
  56459. this._lineDraw && this._lineDraw.remove();
  56460. this._lineDraw = null;
  56461. // Clear motion when lineDraw is removed
  56462. this._clearLayer(api);
  56463. },
  56464. dispose: function () {}
  56465. });
  56466. /*
  56467. * Licensed to the Apache Software Foundation (ASF) under one
  56468. * or more contributor license agreements. See the NOTICE file
  56469. * distributed with this work for additional information
  56470. * regarding copyright ownership. The ASF licenses this file
  56471. * to you under the Apache License, Version 2.0 (the
  56472. * "License"); you may not use this file except in compliance
  56473. * with the License. You may obtain a copy of the License at
  56474. *
  56475. * http://www.apache.org/licenses/LICENSE-2.0
  56476. *
  56477. * Unless required by applicable law or agreed to in writing,
  56478. * software distributed under the License is distributed on an
  56479. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  56480. * KIND, either express or implied. See the License for the
  56481. * specific language governing permissions and limitations
  56482. * under the License.
  56483. */
  56484. function normalize$2(a) {
  56485. if (!(a instanceof Array)) {
  56486. a = [a, a];
  56487. }
  56488. return a;
  56489. }
  56490. var opacityQuery = 'lineStyle.opacity'.split('.');
  56491. var linesVisual = {
  56492. seriesType: 'lines',
  56493. reset: function (seriesModel, ecModel, api) {
  56494. var symbolType = normalize$2(seriesModel.get('symbol'));
  56495. var symbolSize = normalize$2(seriesModel.get('symbolSize'));
  56496. var data = seriesModel.getData();
  56497. data.setVisual('fromSymbol', symbolType && symbolType[0]);
  56498. data.setVisual('toSymbol', symbolType && symbolType[1]);
  56499. data.setVisual('fromSymbolSize', symbolSize && symbolSize[0]);
  56500. data.setVisual('toSymbolSize', symbolSize && symbolSize[1]);
  56501. data.setVisual('opacity', seriesModel.get(opacityQuery));
  56502. function dataEach(data, idx) {
  56503. var itemModel = data.getItemModel(idx);
  56504. var symbolType = normalize$2(itemModel.getShallow('symbol', true));
  56505. var symbolSize = normalize$2(itemModel.getShallow('symbolSize', true));
  56506. var opacity = itemModel.get(opacityQuery);
  56507. symbolType[0] && data.setItemVisual(idx, 'fromSymbol', symbolType[0]);
  56508. symbolType[1] && data.setItemVisual(idx, 'toSymbol', symbolType[1]);
  56509. symbolSize[0] && data.setItemVisual(idx, 'fromSymbolSize', symbolSize[0]);
  56510. symbolSize[1] && data.setItemVisual(idx, 'toSymbolSize', symbolSize[1]);
  56511. data.setItemVisual(idx, 'opacity', opacity);
  56512. }
  56513. return {dataEach: data.hasItemOption ? dataEach : null};
  56514. }
  56515. };
  56516. /*
  56517. * Licensed to the Apache Software Foundation (ASF) under one
  56518. * or more contributor license agreements. See the NOTICE file
  56519. * distributed with this work for additional information
  56520. * regarding copyright ownership. The ASF licenses this file
  56521. * to you under the Apache License, Version 2.0 (the
  56522. * "License"); you may not use this file except in compliance
  56523. * with the License. You may obtain a copy of the License at
  56524. *
  56525. * http://www.apache.org/licenses/LICENSE-2.0
  56526. *
  56527. * Unless required by applicable law or agreed to in writing,
  56528. * software distributed under the License is distributed on an
  56529. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  56530. * KIND, either express or implied. See the License for the
  56531. * specific language governing permissions and limitations
  56532. * under the License.
  56533. */
  56534. registerLayout(linesLayout);
  56535. registerVisual(linesVisual);
  56536. /*
  56537. * Licensed to the Apache Software Foundation (ASF) under one
  56538. * or more contributor license agreements. See the NOTICE file
  56539. * distributed with this work for additional information
  56540. * regarding copyright ownership. The ASF licenses this file
  56541. * to you under the Apache License, Version 2.0 (the
  56542. * "License"); you may not use this file except in compliance
  56543. * with the License. You may obtain a copy of the License at
  56544. *
  56545. * http://www.apache.org/licenses/LICENSE-2.0
  56546. *
  56547. * Unless required by applicable law or agreed to in writing,
  56548. * software distributed under the License is distributed on an
  56549. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  56550. * KIND, either express or implied. See the License for the
  56551. * specific language governing permissions and limitations
  56552. * under the License.
  56553. */
  56554. SeriesModel.extend({
  56555. type: 'series.heatmap',
  56556. getInitialData: function (option, ecModel) {
  56557. return createListFromArray(this.getSource(), this, {
  56558. generateCoord: 'value'
  56559. });
  56560. },
  56561. preventIncremental: function () {
  56562. var coordSysCreator = CoordinateSystemManager.get(this.get('coordinateSystem'));
  56563. if (coordSysCreator && coordSysCreator.dimensions) {
  56564. return coordSysCreator.dimensions[0] === 'lng' && coordSysCreator.dimensions[1] === 'lat';
  56565. }
  56566. },
  56567. defaultOption: {
  56568. // Cartesian2D or geo
  56569. coordinateSystem: 'cartesian2d',
  56570. zlevel: 0,
  56571. z: 2,
  56572. // Cartesian coordinate system
  56573. // xAxisIndex: 0,
  56574. // yAxisIndex: 0,
  56575. // Geo coordinate system
  56576. geoIndex: 0,
  56577. blurSize: 30,
  56578. pointSize: 20,
  56579. maxOpacity: 1,
  56580. minOpacity: 0
  56581. }
  56582. });
  56583. /*
  56584. * Licensed to the Apache Software Foundation (ASF) under one
  56585. * or more contributor license agreements. See the NOTICE file
  56586. * distributed with this work for additional information
  56587. * regarding copyright ownership. The ASF licenses this file
  56588. * to you under the Apache License, Version 2.0 (the
  56589. * "License"); you may not use this file except in compliance
  56590. * with the License. You may obtain a copy of the License at
  56591. *
  56592. * http://www.apache.org/licenses/LICENSE-2.0
  56593. *
  56594. * Unless required by applicable law or agreed to in writing,
  56595. * software distributed under the License is distributed on an
  56596. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  56597. * KIND, either express or implied. See the License for the
  56598. * specific language governing permissions and limitations
  56599. * under the License.
  56600. */
  56601. /* global Uint8ClampedArray */
  56602. var GRADIENT_LEVELS = 256;
  56603. /**
  56604. * Heatmap Chart
  56605. *
  56606. * @class
  56607. */
  56608. function Heatmap() {
  56609. var canvas = createCanvas();
  56610. this.canvas = canvas;
  56611. this.blurSize = 30;
  56612. this.pointSize = 20;
  56613. this.maxOpacity = 1;
  56614. this.minOpacity = 0;
  56615. this._gradientPixels = {};
  56616. }
  56617. Heatmap.prototype = {
  56618. /**
  56619. * Renders Heatmap and returns the rendered canvas
  56620. * @param {Array} data array of data, each has x, y, value
  56621. * @param {number} width canvas width
  56622. * @param {number} height canvas height
  56623. */
  56624. update: function (data, width, height, normalize, colorFunc, isInRange) {
  56625. var brush = this._getBrush();
  56626. var gradientInRange = this._getGradient(data, colorFunc, 'inRange');
  56627. var gradientOutOfRange = this._getGradient(data, colorFunc, 'outOfRange');
  56628. var r = this.pointSize + this.blurSize;
  56629. var canvas = this.canvas;
  56630. var ctx = canvas.getContext('2d');
  56631. var len = data.length;
  56632. canvas.width = width;
  56633. canvas.height = height;
  56634. for (var i = 0; i < len; ++i) {
  56635. var p = data[i];
  56636. var x = p[0];
  56637. var y = p[1];
  56638. var value = p[2];
  56639. // calculate alpha using value
  56640. var alpha = normalize(value);
  56641. // draw with the circle brush with alpha
  56642. ctx.globalAlpha = alpha;
  56643. ctx.drawImage(brush, x - r, y - r);
  56644. }
  56645. if (!canvas.width || !canvas.height) {
  56646. // Avoid "Uncaught DOMException: Failed to execute 'getImageData' on
  56647. // 'CanvasRenderingContext2D': The source height is 0."
  56648. return canvas;
  56649. }
  56650. // colorize the canvas using alpha value and set with gradient
  56651. var imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
  56652. var pixels = imageData.data;
  56653. var offset = 0;
  56654. var pixelLen = pixels.length;
  56655. var minOpacity = this.minOpacity;
  56656. var maxOpacity = this.maxOpacity;
  56657. var diffOpacity = maxOpacity - minOpacity;
  56658. while (offset < pixelLen) {
  56659. var alpha = pixels[offset + 3] / 256;
  56660. var gradientOffset = Math.floor(alpha * (GRADIENT_LEVELS - 1)) * 4;
  56661. // Simple optimize to ignore the empty data
  56662. if (alpha > 0) {
  56663. var gradient = isInRange(alpha) ? gradientInRange : gradientOutOfRange;
  56664. // Any alpha > 0 will be mapped to [minOpacity, maxOpacity]
  56665. alpha > 0 && (alpha = alpha * diffOpacity + minOpacity);
  56666. pixels[offset++] = gradient[gradientOffset];
  56667. pixels[offset++] = gradient[gradientOffset + 1];
  56668. pixels[offset++] = gradient[gradientOffset + 2];
  56669. pixels[offset++] = gradient[gradientOffset + 3] * alpha * 256;
  56670. }
  56671. else {
  56672. offset += 4;
  56673. }
  56674. }
  56675. ctx.putImageData(imageData, 0, 0);
  56676. return canvas;
  56677. },
  56678. /**
  56679. * get canvas of a black circle brush used for canvas to draw later
  56680. * @private
  56681. * @returns {Object} circle brush canvas
  56682. */
  56683. _getBrush: function () {
  56684. var brushCanvas = this._brushCanvas || (this._brushCanvas = createCanvas());
  56685. // set brush size
  56686. var r = this.pointSize + this.blurSize;
  56687. var d = r * 2;
  56688. brushCanvas.width = d;
  56689. brushCanvas.height = d;
  56690. var ctx = brushCanvas.getContext('2d');
  56691. ctx.clearRect(0, 0, d, d);
  56692. // in order to render shadow without the distinct circle,
  56693. // draw the distinct circle in an invisible place,
  56694. // and use shadowOffset to draw shadow in the center of the canvas
  56695. ctx.shadowOffsetX = d;
  56696. ctx.shadowBlur = this.blurSize;
  56697. // draw the shadow in black, and use alpha and shadow blur to generate
  56698. // color in color map
  56699. ctx.shadowColor = '#000';
  56700. // draw circle in the left to the canvas
  56701. ctx.beginPath();
  56702. ctx.arc(-r, r, this.pointSize, 0, Math.PI * 2, true);
  56703. ctx.closePath();
  56704. ctx.fill();
  56705. return brushCanvas;
  56706. },
  56707. /**
  56708. * get gradient color map
  56709. * @private
  56710. */
  56711. _getGradient: function (data, colorFunc, state) {
  56712. var gradientPixels = this._gradientPixels;
  56713. var pixelsSingleState = gradientPixels[state] || (gradientPixels[state] = new Uint8ClampedArray(256 * 4));
  56714. var color = [0, 0, 0, 0];
  56715. var off = 0;
  56716. for (var i = 0; i < 256; i++) {
  56717. colorFunc[state](i / 255, true, color);
  56718. pixelsSingleState[off++] = color[0];
  56719. pixelsSingleState[off++] = color[1];
  56720. pixelsSingleState[off++] = color[2];
  56721. pixelsSingleState[off++] = color[3];
  56722. }
  56723. return pixelsSingleState;
  56724. }
  56725. };
  56726. /*
  56727. * Licensed to the Apache Software Foundation (ASF) under one
  56728. * or more contributor license agreements. See the NOTICE file
  56729. * distributed with this work for additional information
  56730. * regarding copyright ownership. The ASF licenses this file
  56731. * to you under the Apache License, Version 2.0 (the
  56732. * "License"); you may not use this file except in compliance
  56733. * with the License. You may obtain a copy of the License at
  56734. *
  56735. * http://www.apache.org/licenses/LICENSE-2.0
  56736. *
  56737. * Unless required by applicable law or agreed to in writing,
  56738. * software distributed under the License is distributed on an
  56739. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  56740. * KIND, either express or implied. See the License for the
  56741. * specific language governing permissions and limitations
  56742. * under the License.
  56743. */
  56744. function getIsInPiecewiseRange(dataExtent, pieceList, selected) {
  56745. var dataSpan = dataExtent[1] - dataExtent[0];
  56746. pieceList = map(pieceList, function (piece) {
  56747. return {
  56748. interval: [
  56749. (piece.interval[0] - dataExtent[0]) / dataSpan,
  56750. (piece.interval[1] - dataExtent[0]) / dataSpan
  56751. ]
  56752. };
  56753. });
  56754. var len = pieceList.length;
  56755. var lastIndex = 0;
  56756. return function (val) {
  56757. // Try to find in the location of the last found
  56758. for (var i = lastIndex; i < len; i++) {
  56759. var interval = pieceList[i].interval;
  56760. if (interval[0] <= val && val <= interval[1]) {
  56761. lastIndex = i;
  56762. break;
  56763. }
  56764. }
  56765. if (i === len) { // Not found, back interation
  56766. for (var i = lastIndex - 1; i >= 0; i--) {
  56767. var interval = pieceList[i].interval;
  56768. if (interval[0] <= val && val <= interval[1]) {
  56769. lastIndex = i;
  56770. break;
  56771. }
  56772. }
  56773. }
  56774. return i >= 0 && i < len && selected[i];
  56775. };
  56776. }
  56777. function getIsInContinuousRange(dataExtent, range) {
  56778. var dataSpan = dataExtent[1] - dataExtent[0];
  56779. range = [
  56780. (range[0] - dataExtent[0]) / dataSpan,
  56781. (range[1] - dataExtent[0]) / dataSpan
  56782. ];
  56783. return function (val) {
  56784. return val >= range[0] && val <= range[1];
  56785. };
  56786. }
  56787. function isGeoCoordSys(coordSys) {
  56788. var dimensions = coordSys.dimensions;
  56789. // Not use coorSys.type === 'geo' because coordSys maybe extended
  56790. return dimensions[0] === 'lng' && dimensions[1] === 'lat';
  56791. }
  56792. extendChartView({
  56793. type: 'heatmap',
  56794. render: function (seriesModel, ecModel, api) {
  56795. var visualMapOfThisSeries;
  56796. ecModel.eachComponent('visualMap', function (visualMap) {
  56797. visualMap.eachTargetSeries(function (targetSeries) {
  56798. if (targetSeries === seriesModel) {
  56799. visualMapOfThisSeries = visualMap;
  56800. }
  56801. });
  56802. });
  56803. if (__DEV__) {
  56804. if (!visualMapOfThisSeries) {
  56805. throw new Error('Heatmap must use with visualMap');
  56806. }
  56807. }
  56808. this.group.removeAll();
  56809. this._incrementalDisplayable = null;
  56810. var coordSys = seriesModel.coordinateSystem;
  56811. if (coordSys.type === 'cartesian2d' || coordSys.type === 'calendar') {
  56812. this._renderOnCartesianAndCalendar(seriesModel, api, 0, seriesModel.getData().count());
  56813. }
  56814. else if (isGeoCoordSys(coordSys)) {
  56815. this._renderOnGeo(
  56816. coordSys, seriesModel, visualMapOfThisSeries, api
  56817. );
  56818. }
  56819. },
  56820. incrementalPrepareRender: function (seriesModel, ecModel, api) {
  56821. this.group.removeAll();
  56822. },
  56823. incrementalRender: function (params, seriesModel, ecModel, api) {
  56824. var coordSys = seriesModel.coordinateSystem;
  56825. if (coordSys) {
  56826. this._renderOnCartesianAndCalendar(seriesModel, api, params.start, params.end, true);
  56827. }
  56828. },
  56829. _renderOnCartesianAndCalendar: function (seriesModel, api, start, end, incremental) {
  56830. var coordSys = seriesModel.coordinateSystem;
  56831. var width;
  56832. var height;
  56833. if (coordSys.type === 'cartesian2d') {
  56834. var xAxis = coordSys.getAxis('x');
  56835. var yAxis = coordSys.getAxis('y');
  56836. if (__DEV__) {
  56837. if (!(xAxis.type === 'category' && yAxis.type === 'category')) {
  56838. throw new Error('Heatmap on cartesian must have two category axes');
  56839. }
  56840. if (!(xAxis.onBand && yAxis.onBand)) {
  56841. throw new Error('Heatmap on cartesian must have two axes with boundaryGap true');
  56842. }
  56843. }
  56844. width = xAxis.getBandWidth();
  56845. height = yAxis.getBandWidth();
  56846. }
  56847. var group = this.group;
  56848. var data = seriesModel.getData();
  56849. var itemStyleQuery = 'itemStyle';
  56850. var hoverItemStyleQuery = 'emphasis.itemStyle';
  56851. var labelQuery = 'label';
  56852. var hoverLabelQuery = 'emphasis.label';
  56853. var style = seriesModel.getModel(itemStyleQuery).getItemStyle(['color']);
  56854. var hoverStl = seriesModel.getModel(hoverItemStyleQuery).getItemStyle();
  56855. var labelModel = seriesModel.getModel(labelQuery);
  56856. var hoverLabelModel = seriesModel.getModel(hoverLabelQuery);
  56857. var coordSysType = coordSys.type;
  56858. var dataDims = coordSysType === 'cartesian2d'
  56859. ? [
  56860. data.mapDimension('x'),
  56861. data.mapDimension('y'),
  56862. data.mapDimension('value')
  56863. ]
  56864. : [
  56865. data.mapDimension('time'),
  56866. data.mapDimension('value')
  56867. ];
  56868. for (var idx = start; idx < end; idx++) {
  56869. var rect;
  56870. if (coordSysType === 'cartesian2d') {
  56871. // Ignore empty data
  56872. if (isNaN(data.get(dataDims[2], idx))) {
  56873. continue;
  56874. }
  56875. var point = coordSys.dataToPoint([
  56876. data.get(dataDims[0], idx),
  56877. data.get(dataDims[1], idx)
  56878. ]);
  56879. rect = new Rect({
  56880. shape: {
  56881. x: point[0] - width / 2,
  56882. y: point[1] - height / 2,
  56883. width: width,
  56884. height: height
  56885. },
  56886. style: {
  56887. fill: data.getItemVisual(idx, 'color'),
  56888. opacity: data.getItemVisual(idx, 'opacity')
  56889. }
  56890. });
  56891. }
  56892. else {
  56893. // Ignore empty data
  56894. if (isNaN(data.get(dataDims[1], idx))) {
  56895. continue;
  56896. }
  56897. rect = new Rect({
  56898. z2: 1,
  56899. shape: coordSys.dataToRect([data.get(dataDims[0], idx)]).contentShape,
  56900. style: {
  56901. fill: data.getItemVisual(idx, 'color'),
  56902. opacity: data.getItemVisual(idx, 'opacity')
  56903. }
  56904. });
  56905. }
  56906. var itemModel = data.getItemModel(idx);
  56907. // Optimization for large datset
  56908. if (data.hasItemOption) {
  56909. style = itemModel.getModel(itemStyleQuery).getItemStyle(['color']);
  56910. hoverStl = itemModel.getModel(hoverItemStyleQuery).getItemStyle();
  56911. labelModel = itemModel.getModel(labelQuery);
  56912. hoverLabelModel = itemModel.getModel(hoverLabelQuery);
  56913. }
  56914. var rawValue = seriesModel.getRawValue(idx);
  56915. var defaultText = '-';
  56916. if (rawValue && rawValue[2] != null) {
  56917. defaultText = rawValue[2];
  56918. }
  56919. setLabelStyle(
  56920. style, hoverStl, labelModel, hoverLabelModel,
  56921. {
  56922. labelFetcher: seriesModel,
  56923. labelDataIndex: idx,
  56924. defaultText: defaultText,
  56925. isRectText: true
  56926. }
  56927. );
  56928. rect.setStyle(style);
  56929. setHoverStyle(rect, data.hasItemOption ? hoverStl : extend({}, hoverStl));
  56930. rect.incremental = incremental;
  56931. // PENDING
  56932. if (incremental) {
  56933. // Rect must use hover layer if it's incremental.
  56934. rect.useHoverLayer = true;
  56935. }
  56936. group.add(rect);
  56937. data.setItemGraphicEl(idx, rect);
  56938. }
  56939. },
  56940. _renderOnGeo: function (geo, seriesModel, visualMapModel, api) {
  56941. var inRangeVisuals = visualMapModel.targetVisuals.inRange;
  56942. var outOfRangeVisuals = visualMapModel.targetVisuals.outOfRange;
  56943. // if (!visualMapping) {
  56944. // throw new Error('Data range must have color visuals');
  56945. // }
  56946. var data = seriesModel.getData();
  56947. var hmLayer = this._hmLayer || (this._hmLayer || new Heatmap());
  56948. hmLayer.blurSize = seriesModel.get('blurSize');
  56949. hmLayer.pointSize = seriesModel.get('pointSize');
  56950. hmLayer.minOpacity = seriesModel.get('minOpacity');
  56951. hmLayer.maxOpacity = seriesModel.get('maxOpacity');
  56952. var rect = geo.getViewRect().clone();
  56953. var roamTransform = geo.getRoamTransform();
  56954. rect.applyTransform(roamTransform);
  56955. // Clamp on viewport
  56956. var x = Math.max(rect.x, 0);
  56957. var y = Math.max(rect.y, 0);
  56958. var x2 = Math.min(rect.width + rect.x, api.getWidth());
  56959. var y2 = Math.min(rect.height + rect.y, api.getHeight());
  56960. var width = x2 - x;
  56961. var height = y2 - y;
  56962. var dims = [
  56963. data.mapDimension('lng'),
  56964. data.mapDimension('lat'),
  56965. data.mapDimension('value')
  56966. ];
  56967. var points = data.mapArray(dims, function (lng, lat, value) {
  56968. var pt = geo.dataToPoint([lng, lat]);
  56969. pt[0] -= x;
  56970. pt[1] -= y;
  56971. pt.push(value);
  56972. return pt;
  56973. });
  56974. var dataExtent = visualMapModel.getExtent();
  56975. var isInRange = visualMapModel.type === 'visualMap.continuous'
  56976. ? getIsInContinuousRange(dataExtent, visualMapModel.option.range)
  56977. : getIsInPiecewiseRange(
  56978. dataExtent, visualMapModel.getPieceList(), visualMapModel.option.selected
  56979. );
  56980. hmLayer.update(
  56981. points, width, height,
  56982. inRangeVisuals.color.getNormalizer(),
  56983. {
  56984. inRange: inRangeVisuals.color.getColorMapper(),
  56985. outOfRange: outOfRangeVisuals.color.getColorMapper()
  56986. },
  56987. isInRange
  56988. );
  56989. var img = new ZImage({
  56990. style: {
  56991. width: width,
  56992. height: height,
  56993. x: x,
  56994. y: y,
  56995. image: hmLayer.canvas
  56996. },
  56997. silent: true
  56998. });
  56999. this.group.add(img);
  57000. },
  57001. dispose: function () {}
  57002. });
  57003. /*
  57004. * Licensed to the Apache Software Foundation (ASF) under one
  57005. * or more contributor license agreements. See the NOTICE file
  57006. * distributed with this work for additional information
  57007. * regarding copyright ownership. The ASF licenses this file
  57008. * to you under the Apache License, Version 2.0 (the
  57009. * "License"); you may not use this file except in compliance
  57010. * with the License. You may obtain a copy of the License at
  57011. *
  57012. * http://www.apache.org/licenses/LICENSE-2.0
  57013. *
  57014. * Unless required by applicable law or agreed to in writing,
  57015. * software distributed under the License is distributed on an
  57016. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  57017. * KIND, either express or implied. See the License for the
  57018. * specific language governing permissions and limitations
  57019. * under the License.
  57020. */
  57021. /*
  57022. * Licensed to the Apache Software Foundation (ASF) under one
  57023. * or more contributor license agreements. See the NOTICE file
  57024. * distributed with this work for additional information
  57025. * regarding copyright ownership. The ASF licenses this file
  57026. * to you under the Apache License, Version 2.0 (the
  57027. * "License"); you may not use this file except in compliance
  57028. * with the License. You may obtain a copy of the License at
  57029. *
  57030. * http://www.apache.org/licenses/LICENSE-2.0
  57031. *
  57032. * Unless required by applicable law or agreed to in writing,
  57033. * software distributed under the License is distributed on an
  57034. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  57035. * KIND, either express or implied. See the License for the
  57036. * specific language governing permissions and limitations
  57037. * under the License.
  57038. */
  57039. var PictorialBarSeries = BaseBarSeries.extend({
  57040. type: 'series.pictorialBar',
  57041. dependencies: ['grid'],
  57042. defaultOption: {
  57043. symbol: 'circle', // Customized bar shape
  57044. symbolSize: null, // Can be ['100%', '100%'], null means auto.
  57045. symbolRotate: null,
  57046. symbolPosition: null, // 'start' or 'end' or 'center', null means auto.
  57047. symbolOffset: null,
  57048. symbolMargin: null, // start margin and end margin. Can be a number or a percent string.
  57049. // Auto margin by defualt.
  57050. symbolRepeat: false, // false/null/undefined, means no repeat.
  57051. // Can be true, means auto calculate repeat times and cut by data.
  57052. // Can be a number, specifies repeat times, and do not cut by data.
  57053. // Can be 'fixed', means auto calculate repeat times but do not cut by data.
  57054. symbolRepeatDirection: 'end', // 'end' means from 'start' to 'end'.
  57055. symbolClip: false,
  57056. symbolBoundingData: null, // Can be 60 or -40 or [-40, 60]
  57057. symbolPatternSize: 400, // 400 * 400 px
  57058. barGap: '-100%', // In most case, overlap is needed.
  57059. // z can be set in data item, which is z2 actually.
  57060. // Disable progressive
  57061. progressive: 0,
  57062. hoverAnimation: false // Open only when needed.
  57063. },
  57064. getInitialData: function (option) {
  57065. // Disable stack.
  57066. option.stack = null;
  57067. return PictorialBarSeries.superApply(this, 'getInitialData', arguments);
  57068. }
  57069. });
  57070. /*
  57071. * Licensed to the Apache Software Foundation (ASF) under one
  57072. * or more contributor license agreements. See the NOTICE file
  57073. * distributed with this work for additional information
  57074. * regarding copyright ownership. The ASF licenses this file
  57075. * to you under the Apache License, Version 2.0 (the
  57076. * "License"); you may not use this file except in compliance
  57077. * with the License. You may obtain a copy of the License at
  57078. *
  57079. * http://www.apache.org/licenses/LICENSE-2.0
  57080. *
  57081. * Unless required by applicable law or agreed to in writing,
  57082. * software distributed under the License is distributed on an
  57083. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  57084. * KIND, either express or implied. See the License for the
  57085. * specific language governing permissions and limitations
  57086. * under the License.
  57087. */
  57088. var BAR_BORDER_WIDTH_QUERY$1 = ['itemStyle', 'borderWidth'];
  57089. // index: +isHorizontal
  57090. var LAYOUT_ATTRS = [
  57091. {xy: 'x', wh: 'width', index: 0, posDesc: ['left', 'right']},
  57092. {xy: 'y', wh: 'height', index: 1, posDesc: ['top', 'bottom']}
  57093. ];
  57094. var pathForLineWidth = new Circle();
  57095. var BarView$1 = extendChartView({
  57096. type: 'pictorialBar',
  57097. render: function (seriesModel, ecModel, api) {
  57098. var group = this.group;
  57099. var data = seriesModel.getData();
  57100. var oldData = this._data;
  57101. var cartesian = seriesModel.coordinateSystem;
  57102. var baseAxis = cartesian.getBaseAxis();
  57103. var isHorizontal = !!baseAxis.isHorizontal();
  57104. var coordSysRect = cartesian.grid.getRect();
  57105. var opt = {
  57106. ecSize: {width: api.getWidth(), height: api.getHeight()},
  57107. seriesModel: seriesModel,
  57108. coordSys: cartesian,
  57109. coordSysExtent: [
  57110. [coordSysRect.x, coordSysRect.x + coordSysRect.width],
  57111. [coordSysRect.y, coordSysRect.y + coordSysRect.height]
  57112. ],
  57113. isHorizontal: isHorizontal,
  57114. valueDim: LAYOUT_ATTRS[+isHorizontal],
  57115. categoryDim: LAYOUT_ATTRS[1 - isHorizontal]
  57116. };
  57117. data.diff(oldData)
  57118. .add(function (dataIndex) {
  57119. if (!data.hasValue(dataIndex)) {
  57120. return;
  57121. }
  57122. var itemModel = getItemModel(data, dataIndex);
  57123. var symbolMeta = getSymbolMeta(data, dataIndex, itemModel, opt);
  57124. var bar = createBar(data, opt, symbolMeta);
  57125. data.setItemGraphicEl(dataIndex, bar);
  57126. group.add(bar);
  57127. updateCommon$1(bar, opt, symbolMeta);
  57128. })
  57129. .update(function (newIndex, oldIndex) {
  57130. var bar = oldData.getItemGraphicEl(oldIndex);
  57131. if (!data.hasValue(newIndex)) {
  57132. group.remove(bar);
  57133. return;
  57134. }
  57135. var itemModel = getItemModel(data, newIndex);
  57136. var symbolMeta = getSymbolMeta(data, newIndex, itemModel, opt);
  57137. var pictorialShapeStr = getShapeStr(data, symbolMeta);
  57138. if (bar && pictorialShapeStr !== bar.__pictorialShapeStr) {
  57139. group.remove(bar);
  57140. data.setItemGraphicEl(newIndex, null);
  57141. bar = null;
  57142. }
  57143. if (bar) {
  57144. updateBar(bar, opt, symbolMeta);
  57145. }
  57146. else {
  57147. bar = createBar(data, opt, symbolMeta, true);
  57148. }
  57149. data.setItemGraphicEl(newIndex, bar);
  57150. bar.__pictorialSymbolMeta = symbolMeta;
  57151. // Add back
  57152. group.add(bar);
  57153. updateCommon$1(bar, opt, symbolMeta);
  57154. })
  57155. .remove(function (dataIndex) {
  57156. var bar = oldData.getItemGraphicEl(dataIndex);
  57157. bar && removeBar(oldData, dataIndex, bar.__pictorialSymbolMeta.animationModel, bar);
  57158. })
  57159. .execute();
  57160. this._data = data;
  57161. return this.group;
  57162. },
  57163. dispose: noop,
  57164. remove: function (ecModel, api) {
  57165. var group = this.group;
  57166. var data = this._data;
  57167. if (ecModel.get('animation')) {
  57168. if (data) {
  57169. data.eachItemGraphicEl(function (bar) {
  57170. removeBar(data, bar.dataIndex, ecModel, bar);
  57171. });
  57172. }
  57173. }
  57174. else {
  57175. group.removeAll();
  57176. }
  57177. }
  57178. });
  57179. // Set or calculate default value about symbol, and calculate layout info.
  57180. function getSymbolMeta(data, dataIndex, itemModel, opt) {
  57181. var layout = data.getItemLayout(dataIndex);
  57182. var symbolRepeat = itemModel.get('symbolRepeat');
  57183. var symbolClip = itemModel.get('symbolClip');
  57184. var symbolPosition = itemModel.get('symbolPosition') || 'start';
  57185. var symbolRotate = itemModel.get('symbolRotate');
  57186. var rotation = (symbolRotate || 0) * Math.PI / 180 || 0;
  57187. var symbolPatternSize = itemModel.get('symbolPatternSize') || 2;
  57188. var isAnimationEnabled = itemModel.isAnimationEnabled();
  57189. var symbolMeta = {
  57190. dataIndex: dataIndex,
  57191. layout: layout,
  57192. itemModel: itemModel,
  57193. symbolType: data.getItemVisual(dataIndex, 'symbol') || 'circle',
  57194. color: data.getItemVisual(dataIndex, 'color'),
  57195. symbolClip: symbolClip,
  57196. symbolRepeat: symbolRepeat,
  57197. symbolRepeatDirection: itemModel.get('symbolRepeatDirection'),
  57198. symbolPatternSize: symbolPatternSize,
  57199. rotation: rotation,
  57200. animationModel: isAnimationEnabled ? itemModel : null,
  57201. hoverAnimation: isAnimationEnabled && itemModel.get('hoverAnimation'),
  57202. z2: itemModel.getShallow('z', true) || 0
  57203. };
  57204. prepareBarLength(itemModel, symbolRepeat, layout, opt, symbolMeta);
  57205. prepareSymbolSize(
  57206. data, dataIndex, layout, symbolRepeat, symbolClip, symbolMeta.boundingLength,
  57207. symbolMeta.pxSign, symbolPatternSize, opt, symbolMeta
  57208. );
  57209. prepareLineWidth(itemModel, symbolMeta.symbolScale, rotation, opt, symbolMeta);
  57210. var symbolSize = symbolMeta.symbolSize;
  57211. var symbolOffset = itemModel.get('symbolOffset');
  57212. if (isArray(symbolOffset)) {
  57213. symbolOffset = [
  57214. parsePercent$1(symbolOffset[0], symbolSize[0]),
  57215. parsePercent$1(symbolOffset[1], symbolSize[1])
  57216. ];
  57217. }
  57218. prepareLayoutInfo(
  57219. itemModel, symbolSize, layout, symbolRepeat, symbolClip, symbolOffset,
  57220. symbolPosition, symbolMeta.valueLineWidth, symbolMeta.boundingLength, symbolMeta.repeatCutLength,
  57221. opt, symbolMeta
  57222. );
  57223. return symbolMeta;
  57224. }
  57225. // bar length can be negative.
  57226. function prepareBarLength(itemModel, symbolRepeat, layout, opt, output) {
  57227. var valueDim = opt.valueDim;
  57228. var symbolBoundingData = itemModel.get('symbolBoundingData');
  57229. var valueAxis = opt.coordSys.getOtherAxis(opt.coordSys.getBaseAxis());
  57230. var zeroPx = valueAxis.toGlobalCoord(valueAxis.dataToCoord(0));
  57231. var pxSignIdx = 1 - +(layout[valueDim.wh] <= 0);
  57232. var boundingLength;
  57233. if (isArray(symbolBoundingData)) {
  57234. var symbolBoundingExtent = [
  57235. convertToCoordOnAxis(valueAxis, symbolBoundingData[0]) - zeroPx,
  57236. convertToCoordOnAxis(valueAxis, symbolBoundingData[1]) - zeroPx
  57237. ];
  57238. symbolBoundingExtent[1] < symbolBoundingExtent[0] && (symbolBoundingExtent.reverse());
  57239. boundingLength = symbolBoundingExtent[pxSignIdx];
  57240. }
  57241. else if (symbolBoundingData != null) {
  57242. boundingLength = convertToCoordOnAxis(valueAxis, symbolBoundingData) - zeroPx;
  57243. }
  57244. else if (symbolRepeat) {
  57245. boundingLength = opt.coordSysExtent[valueDim.index][pxSignIdx] - zeroPx;
  57246. }
  57247. else {
  57248. boundingLength = layout[valueDim.wh];
  57249. }
  57250. output.boundingLength = boundingLength;
  57251. if (symbolRepeat) {
  57252. output.repeatCutLength = layout[valueDim.wh];
  57253. }
  57254. output.pxSign = boundingLength > 0 ? 1 : boundingLength < 0 ? -1 : 0;
  57255. }
  57256. function convertToCoordOnAxis(axis, value) {
  57257. return axis.toGlobalCoord(axis.dataToCoord(axis.scale.parse(value)));
  57258. }
  57259. // Support ['100%', '100%']
  57260. function prepareSymbolSize(
  57261. data, dataIndex, layout, symbolRepeat, symbolClip, boundingLength,
  57262. pxSign, symbolPatternSize, opt, output
  57263. ) {
  57264. var valueDim = opt.valueDim;
  57265. var categoryDim = opt.categoryDim;
  57266. var categorySize = Math.abs(layout[categoryDim.wh]);
  57267. var symbolSize = data.getItemVisual(dataIndex, 'symbolSize');
  57268. if (isArray(symbolSize)) {
  57269. symbolSize = symbolSize.slice();
  57270. }
  57271. else {
  57272. if (symbolSize == null) {
  57273. symbolSize = '100%';
  57274. }
  57275. symbolSize = [symbolSize, symbolSize];
  57276. }
  57277. // Note: percentage symbolSize (like '100%') do not consider lineWidth, because it is
  57278. // to complicated to calculate real percent value if considering scaled lineWidth.
  57279. // So the actual size will bigger than layout size if lineWidth is bigger than zero,
  57280. // which can be tolerated in pictorial chart.
  57281. symbolSize[categoryDim.index] = parsePercent$1(
  57282. symbolSize[categoryDim.index],
  57283. categorySize
  57284. );
  57285. symbolSize[valueDim.index] = parsePercent$1(
  57286. symbolSize[valueDim.index],
  57287. symbolRepeat ? categorySize : Math.abs(boundingLength)
  57288. );
  57289. output.symbolSize = symbolSize;
  57290. // If x or y is less than zero, show reversed shape.
  57291. var symbolScale = output.symbolScale = [
  57292. symbolSize[0] / symbolPatternSize,
  57293. symbolSize[1] / symbolPatternSize
  57294. ];
  57295. // Follow convention, 'right' and 'top' is the normal scale.
  57296. symbolScale[valueDim.index] *= (opt.isHorizontal ? -1 : 1) * pxSign;
  57297. }
  57298. function prepareLineWidth(itemModel, symbolScale, rotation, opt, output) {
  57299. // In symbols are drawn with scale, so do not need to care about the case that width
  57300. // or height are too small. But symbol use strokeNoScale, where acture lineWidth should
  57301. // be calculated.
  57302. var valueLineWidth = itemModel.get(BAR_BORDER_WIDTH_QUERY$1) || 0;
  57303. if (valueLineWidth) {
  57304. pathForLineWidth.attr({
  57305. scale: symbolScale.slice(),
  57306. rotation: rotation
  57307. });
  57308. pathForLineWidth.updateTransform();
  57309. valueLineWidth /= pathForLineWidth.getLineScale();
  57310. valueLineWidth *= symbolScale[opt.valueDim.index];
  57311. }
  57312. output.valueLineWidth = valueLineWidth;
  57313. }
  57314. function prepareLayoutInfo(
  57315. itemModel, symbolSize, layout, symbolRepeat, symbolClip, symbolOffset,
  57316. symbolPosition, valueLineWidth, boundingLength, repeatCutLength, opt, output
  57317. ) {
  57318. var categoryDim = opt.categoryDim;
  57319. var valueDim = opt.valueDim;
  57320. var pxSign = output.pxSign;
  57321. var unitLength = Math.max(symbolSize[valueDim.index] + valueLineWidth, 0);
  57322. var pathLen = unitLength;
  57323. // Note: rotation will not effect the layout of symbols, because user may
  57324. // want symbols to rotate on its center, which should not be translated
  57325. // when rotating.
  57326. if (symbolRepeat) {
  57327. var absBoundingLength = Math.abs(boundingLength);
  57328. var symbolMargin = retrieve(itemModel.get('symbolMargin'), '15%') + '';
  57329. var hasEndGap = false;
  57330. if (symbolMargin.lastIndexOf('!') === symbolMargin.length - 1) {
  57331. hasEndGap = true;
  57332. symbolMargin = symbolMargin.slice(0, symbolMargin.length - 1);
  57333. }
  57334. symbolMargin = parsePercent$1(symbolMargin, symbolSize[valueDim.index]);
  57335. var uLenWithMargin = Math.max(unitLength + symbolMargin * 2, 0);
  57336. // When symbol margin is less than 0, margin at both ends will be subtracted
  57337. // to ensure that all of the symbols will not be overflow the given area.
  57338. var endFix = hasEndGap ? 0 : symbolMargin * 2;
  57339. // Both final repeatTimes and final symbolMargin area calculated based on
  57340. // boundingLength.
  57341. var repeatSpecified = isNumeric(symbolRepeat);
  57342. var repeatTimes = repeatSpecified
  57343. ? symbolRepeat
  57344. : toIntTimes((absBoundingLength + endFix) / uLenWithMargin);
  57345. // Adjust calculate margin, to ensure each symbol is displayed
  57346. // entirely in the given layout area.
  57347. var mDiff = absBoundingLength - repeatTimes * unitLength;
  57348. symbolMargin = mDiff / 2 / (hasEndGap ? repeatTimes : repeatTimes - 1);
  57349. uLenWithMargin = unitLength + symbolMargin * 2;
  57350. endFix = hasEndGap ? 0 : symbolMargin * 2;
  57351. // Update repeatTimes when not all symbol will be shown.
  57352. if (!repeatSpecified && symbolRepeat !== 'fixed') {
  57353. repeatTimes = repeatCutLength
  57354. ? toIntTimes((Math.abs(repeatCutLength) + endFix) / uLenWithMargin)
  57355. : 0;
  57356. }
  57357. pathLen = repeatTimes * uLenWithMargin - endFix;
  57358. output.repeatTimes = repeatTimes;
  57359. output.symbolMargin = symbolMargin;
  57360. }
  57361. var sizeFix = pxSign * (pathLen / 2);
  57362. var pathPosition = output.pathPosition = [];
  57363. pathPosition[categoryDim.index] = layout[categoryDim.wh] / 2;
  57364. pathPosition[valueDim.index] = symbolPosition === 'start'
  57365. ? sizeFix
  57366. : symbolPosition === 'end'
  57367. ? boundingLength - sizeFix
  57368. : boundingLength / 2; // 'center'
  57369. if (symbolOffset) {
  57370. pathPosition[0] += symbolOffset[0];
  57371. pathPosition[1] += symbolOffset[1];
  57372. }
  57373. var bundlePosition = output.bundlePosition = [];
  57374. bundlePosition[categoryDim.index] = layout[categoryDim.xy];
  57375. bundlePosition[valueDim.index] = layout[valueDim.xy];
  57376. var barRectShape = output.barRectShape = extend({}, layout);
  57377. barRectShape[valueDim.wh] = pxSign * Math.max(
  57378. Math.abs(layout[valueDim.wh]), Math.abs(pathPosition[valueDim.index] + sizeFix)
  57379. );
  57380. barRectShape[categoryDim.wh] = layout[categoryDim.wh];
  57381. var clipShape = output.clipShape = {};
  57382. // Consider that symbol may be overflow layout rect.
  57383. clipShape[categoryDim.xy] = -layout[categoryDim.xy];
  57384. clipShape[categoryDim.wh] = opt.ecSize[categoryDim.wh];
  57385. clipShape[valueDim.xy] = 0;
  57386. clipShape[valueDim.wh] = layout[valueDim.wh];
  57387. }
  57388. function createPath(symbolMeta) {
  57389. var symbolPatternSize = symbolMeta.symbolPatternSize;
  57390. var path = createSymbol(
  57391. // Consider texture img, make a big size.
  57392. symbolMeta.symbolType,
  57393. -symbolPatternSize / 2,
  57394. -symbolPatternSize / 2,
  57395. symbolPatternSize,
  57396. symbolPatternSize,
  57397. symbolMeta.color
  57398. );
  57399. path.attr({
  57400. culling: true
  57401. });
  57402. path.type !== 'image' && path.setStyle({
  57403. strokeNoScale: true
  57404. });
  57405. return path;
  57406. }
  57407. function createOrUpdateRepeatSymbols(bar, opt, symbolMeta, isUpdate) {
  57408. var bundle = bar.__pictorialBundle;
  57409. var symbolSize = symbolMeta.symbolSize;
  57410. var valueLineWidth = symbolMeta.valueLineWidth;
  57411. var pathPosition = symbolMeta.pathPosition;
  57412. var valueDim = opt.valueDim;
  57413. var repeatTimes = symbolMeta.repeatTimes || 0;
  57414. var index = 0;
  57415. var unit = symbolSize[opt.valueDim.index] + valueLineWidth + symbolMeta.symbolMargin * 2;
  57416. eachPath(bar, function (path) {
  57417. path.__pictorialAnimationIndex = index;
  57418. path.__pictorialRepeatTimes = repeatTimes;
  57419. if (index < repeatTimes) {
  57420. updateAttr(path, null, makeTarget(index), symbolMeta, isUpdate);
  57421. }
  57422. else {
  57423. updateAttr(path, null, {scale: [0, 0]}, symbolMeta, isUpdate, function () {
  57424. bundle.remove(path);
  57425. });
  57426. }
  57427. updateHoverAnimation(path, symbolMeta);
  57428. index++;
  57429. });
  57430. for (; index < repeatTimes; index++) {
  57431. var path = createPath(symbolMeta);
  57432. path.__pictorialAnimationIndex = index;
  57433. path.__pictorialRepeatTimes = repeatTimes;
  57434. bundle.add(path);
  57435. var target = makeTarget(index);
  57436. updateAttr(
  57437. path,
  57438. {
  57439. position: target.position,
  57440. scale: [0, 0]
  57441. },
  57442. {
  57443. scale: target.scale,
  57444. rotation: target.rotation
  57445. },
  57446. symbolMeta,
  57447. isUpdate
  57448. );
  57449. // FIXME
  57450. // If all emphasis/normal through action.
  57451. path
  57452. .on('mouseover', onMouseOver)
  57453. .on('mouseout', onMouseOut);
  57454. updateHoverAnimation(path, symbolMeta);
  57455. }
  57456. function makeTarget(index) {
  57457. var position = pathPosition.slice();
  57458. // (start && pxSign > 0) || (end && pxSign < 0): i = repeatTimes - index
  57459. // Otherwise: i = index;
  57460. var pxSign = symbolMeta.pxSign;
  57461. var i = index;
  57462. if (symbolMeta.symbolRepeatDirection === 'start' ? pxSign > 0 : pxSign < 0) {
  57463. i = repeatTimes - 1 - index;
  57464. }
  57465. position[valueDim.index] = unit * (i - repeatTimes / 2 + 0.5) + pathPosition[valueDim.index];
  57466. return {
  57467. position: position,
  57468. scale: symbolMeta.symbolScale.slice(),
  57469. rotation: symbolMeta.rotation
  57470. };
  57471. }
  57472. function onMouseOver() {
  57473. eachPath(bar, function (path) {
  57474. path.trigger('emphasis');
  57475. });
  57476. }
  57477. function onMouseOut() {
  57478. eachPath(bar, function (path) {
  57479. path.trigger('normal');
  57480. });
  57481. }
  57482. }
  57483. function createOrUpdateSingleSymbol(bar, opt, symbolMeta, isUpdate) {
  57484. var bundle = bar.__pictorialBundle;
  57485. var mainPath = bar.__pictorialMainPath;
  57486. if (!mainPath) {
  57487. mainPath = bar.__pictorialMainPath = createPath(symbolMeta);
  57488. bundle.add(mainPath);
  57489. updateAttr(
  57490. mainPath,
  57491. {
  57492. position: symbolMeta.pathPosition.slice(),
  57493. scale: [0, 0],
  57494. rotation: symbolMeta.rotation
  57495. },
  57496. {
  57497. scale: symbolMeta.symbolScale.slice()
  57498. },
  57499. symbolMeta,
  57500. isUpdate
  57501. );
  57502. mainPath
  57503. .on('mouseover', onMouseOver)
  57504. .on('mouseout', onMouseOut);
  57505. }
  57506. else {
  57507. updateAttr(
  57508. mainPath,
  57509. null,
  57510. {
  57511. position: symbolMeta.pathPosition.slice(),
  57512. scale: symbolMeta.symbolScale.slice(),
  57513. rotation: symbolMeta.rotation
  57514. },
  57515. symbolMeta,
  57516. isUpdate
  57517. );
  57518. }
  57519. updateHoverAnimation(mainPath, symbolMeta);
  57520. function onMouseOver() {
  57521. this.trigger('emphasis');
  57522. }
  57523. function onMouseOut() {
  57524. this.trigger('normal');
  57525. }
  57526. }
  57527. // bar rect is used for label.
  57528. function createOrUpdateBarRect(bar, symbolMeta, isUpdate) {
  57529. var rectShape = extend({}, symbolMeta.barRectShape);
  57530. var barRect = bar.__pictorialBarRect;
  57531. if (!barRect) {
  57532. barRect = bar.__pictorialBarRect = new Rect({
  57533. z2: 2,
  57534. shape: rectShape,
  57535. silent: true,
  57536. style: {
  57537. stroke: 'transparent',
  57538. fill: 'transparent',
  57539. lineWidth: 0
  57540. }
  57541. });
  57542. bar.add(barRect);
  57543. }
  57544. else {
  57545. updateAttr(barRect, null, {shape: rectShape}, symbolMeta, isUpdate);
  57546. }
  57547. }
  57548. function createOrUpdateClip(bar, opt, symbolMeta, isUpdate) {
  57549. // If not clip, symbol will be remove and rebuilt.
  57550. if (symbolMeta.symbolClip) {
  57551. var clipPath = bar.__pictorialClipPath;
  57552. var clipShape = extend({}, symbolMeta.clipShape);
  57553. var valueDim = opt.valueDim;
  57554. var animationModel = symbolMeta.animationModel;
  57555. var dataIndex = symbolMeta.dataIndex;
  57556. if (clipPath) {
  57557. updateProps(
  57558. clipPath, {shape: clipShape}, animationModel, dataIndex
  57559. );
  57560. }
  57561. else {
  57562. clipShape[valueDim.wh] = 0;
  57563. clipPath = new Rect({shape: clipShape});
  57564. bar.__pictorialBundle.setClipPath(clipPath);
  57565. bar.__pictorialClipPath = clipPath;
  57566. var target = {};
  57567. target[valueDim.wh] = symbolMeta.clipShape[valueDim.wh];
  57568. graphic[isUpdate ? 'updateProps' : 'initProps'](
  57569. clipPath, {shape: target}, animationModel, dataIndex
  57570. );
  57571. }
  57572. }
  57573. }
  57574. function getItemModel(data, dataIndex) {
  57575. var itemModel = data.getItemModel(dataIndex);
  57576. itemModel.getAnimationDelayParams = getAnimationDelayParams;
  57577. itemModel.isAnimationEnabled = isAnimationEnabled;
  57578. return itemModel;
  57579. }
  57580. function getAnimationDelayParams(path) {
  57581. // The order is the same as the z-order, see `symbolRepeatDiretion`.
  57582. return {
  57583. index: path.__pictorialAnimationIndex,
  57584. count: path.__pictorialRepeatTimes
  57585. };
  57586. }
  57587. function isAnimationEnabled() {
  57588. // `animation` prop can be set on itemModel in pictorial bar chart.
  57589. return this.parentModel.isAnimationEnabled() && !!this.getShallow('animation');
  57590. }
  57591. function updateHoverAnimation(path, symbolMeta) {
  57592. path.off('emphasis').off('normal');
  57593. var scale = symbolMeta.symbolScale.slice();
  57594. symbolMeta.hoverAnimation && path
  57595. .on('emphasis', function () {
  57596. this.animateTo({
  57597. scale: [scale[0] * 1.1, scale[1] * 1.1]
  57598. }, 400, 'elasticOut');
  57599. })
  57600. .on('normal', function () {
  57601. this.animateTo({
  57602. scale: scale.slice()
  57603. }, 400, 'elasticOut');
  57604. });
  57605. }
  57606. function createBar(data, opt, symbolMeta, isUpdate) {
  57607. // bar is the main element for each data.
  57608. var bar = new Group();
  57609. // bundle is used for location and clip.
  57610. var bundle = new Group();
  57611. bar.add(bundle);
  57612. bar.__pictorialBundle = bundle;
  57613. bundle.attr('position', symbolMeta.bundlePosition.slice());
  57614. if (symbolMeta.symbolRepeat) {
  57615. createOrUpdateRepeatSymbols(bar, opt, symbolMeta);
  57616. }
  57617. else {
  57618. createOrUpdateSingleSymbol(bar, opt, symbolMeta);
  57619. }
  57620. createOrUpdateBarRect(bar, symbolMeta, isUpdate);
  57621. createOrUpdateClip(bar, opt, symbolMeta, isUpdate);
  57622. bar.__pictorialShapeStr = getShapeStr(data, symbolMeta);
  57623. bar.__pictorialSymbolMeta = symbolMeta;
  57624. return bar;
  57625. }
  57626. function updateBar(bar, opt, symbolMeta) {
  57627. var animationModel = symbolMeta.animationModel;
  57628. var dataIndex = symbolMeta.dataIndex;
  57629. var bundle = bar.__pictorialBundle;
  57630. updateProps(
  57631. bundle, {position: symbolMeta.bundlePosition.slice()}, animationModel, dataIndex
  57632. );
  57633. if (symbolMeta.symbolRepeat) {
  57634. createOrUpdateRepeatSymbols(bar, opt, symbolMeta, true);
  57635. }
  57636. else {
  57637. createOrUpdateSingleSymbol(bar, opt, symbolMeta, true);
  57638. }
  57639. createOrUpdateBarRect(bar, symbolMeta, true);
  57640. createOrUpdateClip(bar, opt, symbolMeta, true);
  57641. }
  57642. function removeBar(data, dataIndex, animationModel, bar) {
  57643. // Not show text when animating
  57644. var labelRect = bar.__pictorialBarRect;
  57645. labelRect && (labelRect.style.text = null);
  57646. var pathes = [];
  57647. eachPath(bar, function (path) {
  57648. pathes.push(path);
  57649. });
  57650. bar.__pictorialMainPath && pathes.push(bar.__pictorialMainPath);
  57651. // I do not find proper remove animation for clip yet.
  57652. bar.__pictorialClipPath && (animationModel = null);
  57653. each$1(pathes, function (path) {
  57654. updateProps(
  57655. path, {scale: [0, 0]}, animationModel, dataIndex,
  57656. function () {
  57657. bar.parent && bar.parent.remove(bar);
  57658. }
  57659. );
  57660. });
  57661. data.setItemGraphicEl(dataIndex, null);
  57662. }
  57663. function getShapeStr(data, symbolMeta) {
  57664. return [
  57665. data.getItemVisual(symbolMeta.dataIndex, 'symbol') || 'none',
  57666. !!symbolMeta.symbolRepeat,
  57667. !!symbolMeta.symbolClip
  57668. ].join(':');
  57669. }
  57670. function eachPath(bar, cb, context) {
  57671. // Do not use Group#eachChild, because it do not support remove.
  57672. each$1(bar.__pictorialBundle.children(), function (el) {
  57673. el !== bar.__pictorialBarRect && cb.call(context, el);
  57674. });
  57675. }
  57676. function updateAttr(el, immediateAttrs, animationAttrs, symbolMeta, isUpdate, cb) {
  57677. immediateAttrs && el.attr(immediateAttrs);
  57678. // when symbolCip used, only clip path has init animation, otherwise it would be weird effect.
  57679. if (symbolMeta.symbolClip && !isUpdate) {
  57680. animationAttrs && el.attr(animationAttrs);
  57681. }
  57682. else {
  57683. animationAttrs && graphic[isUpdate ? 'updateProps' : 'initProps'](
  57684. el, animationAttrs, symbolMeta.animationModel, symbolMeta.dataIndex, cb
  57685. );
  57686. }
  57687. }
  57688. function updateCommon$1(bar, opt, symbolMeta) {
  57689. var color = symbolMeta.color;
  57690. var dataIndex = symbolMeta.dataIndex;
  57691. var itemModel = symbolMeta.itemModel;
  57692. // Color must be excluded.
  57693. // Because symbol provide setColor individually to set fill and stroke
  57694. var normalStyle = itemModel.getModel('itemStyle').getItemStyle(['color']);
  57695. var hoverStyle = itemModel.getModel('emphasis.itemStyle').getItemStyle();
  57696. var cursorStyle = itemModel.getShallow('cursor');
  57697. eachPath(bar, function (path) {
  57698. // PENDING setColor should be before setStyle!!!
  57699. path.setColor(color);
  57700. path.setStyle(defaults(
  57701. {
  57702. fill: color,
  57703. opacity: symbolMeta.opacity
  57704. },
  57705. normalStyle
  57706. ));
  57707. setHoverStyle(path, hoverStyle);
  57708. cursorStyle && (path.cursor = cursorStyle);
  57709. path.z2 = symbolMeta.z2;
  57710. });
  57711. var barRectHoverStyle = {};
  57712. var barPositionOutside = opt.valueDim.posDesc[+(symbolMeta.boundingLength > 0)];
  57713. var barRect = bar.__pictorialBarRect;
  57714. setLabel(
  57715. barRect.style, barRectHoverStyle, itemModel,
  57716. color, opt.seriesModel, dataIndex, barPositionOutside
  57717. );
  57718. setHoverStyle(barRect, barRectHoverStyle);
  57719. }
  57720. function toIntTimes(times) {
  57721. var roundedTimes = Math.round(times);
  57722. // Escapse accurate error
  57723. return Math.abs(times - roundedTimes) < 1e-4
  57724. ? roundedTimes
  57725. : Math.ceil(times);
  57726. }
  57727. /*
  57728. * Licensed to the Apache Software Foundation (ASF) under one
  57729. * or more contributor license agreements. See the NOTICE file
  57730. * distributed with this work for additional information
  57731. * regarding copyright ownership. The ASF licenses this file
  57732. * to you under the Apache License, Version 2.0 (the
  57733. * "License"); you may not use this file except in compliance
  57734. * with the License. You may obtain a copy of the License at
  57735. *
  57736. * http://www.apache.org/licenses/LICENSE-2.0
  57737. *
  57738. * Unless required by applicable law or agreed to in writing,
  57739. * software distributed under the License is distributed on an
  57740. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  57741. * KIND, either express or implied. See the License for the
  57742. * specific language governing permissions and limitations
  57743. * under the License.
  57744. */
  57745. // In case developer forget to include grid component
  57746. registerLayout(curry(
  57747. layout, 'pictorialBar'
  57748. ));
  57749. registerVisual(visualSymbol('pictorialBar', 'roundRect'));
  57750. /*
  57751. * Licensed to the Apache Software Foundation (ASF) under one
  57752. * or more contributor license agreements. See the NOTICE file
  57753. * distributed with this work for additional information
  57754. * regarding copyright ownership. The ASF licenses this file
  57755. * to you under the Apache License, Version 2.0 (the
  57756. * "License"); you may not use this file except in compliance
  57757. * with the License. You may obtain a copy of the License at
  57758. *
  57759. * http://www.apache.org/licenses/LICENSE-2.0
  57760. *
  57761. * Unless required by applicable law or agreed to in writing,
  57762. * software distributed under the License is distributed on an
  57763. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  57764. * KIND, either express or implied. See the License for the
  57765. * specific language governing permissions and limitations
  57766. * under the License.
  57767. */
  57768. /**
  57769. * @constructor module:echarts/coord/single/SingleAxis
  57770. * @extends {module:echarts/coord/Axis}
  57771. * @param {string} dim
  57772. * @param {*} scale
  57773. * @param {Array.<number>} coordExtent
  57774. * @param {string} axisType
  57775. * @param {string} position
  57776. */
  57777. var SingleAxis = function (dim, scale, coordExtent, axisType, position) {
  57778. Axis.call(this, dim, scale, coordExtent);
  57779. /**
  57780. * Axis type
  57781. * - 'category'
  57782. * - 'value'
  57783. * - 'time'
  57784. * - 'log'
  57785. * @type {string}
  57786. */
  57787. this.type = axisType || 'value';
  57788. /**
  57789. * Axis position
  57790. * - 'top'
  57791. * - 'bottom'
  57792. * - 'left'
  57793. * - 'right'
  57794. * @type {string}
  57795. */
  57796. this.position = position || 'bottom';
  57797. /**
  57798. * Axis orient
  57799. * - 'horizontal'
  57800. * - 'vertical'
  57801. * @type {[type]}
  57802. */
  57803. this.orient = null;
  57804. };
  57805. SingleAxis.prototype = {
  57806. constructor: SingleAxis,
  57807. /**
  57808. * Axis model
  57809. * @type {module:echarts/coord/single/AxisModel}
  57810. */
  57811. model: null,
  57812. /**
  57813. * Judge the orient of the axis.
  57814. * @return {boolean}
  57815. */
  57816. isHorizontal: function () {
  57817. var position = this.position;
  57818. return position === 'top' || position === 'bottom';
  57819. },
  57820. /**
  57821. * @override
  57822. */
  57823. pointToData: function (point, clamp) {
  57824. return this.coordinateSystem.pointToData(point, clamp)[0];
  57825. },
  57826. /**
  57827. * Convert the local coord(processed by dataToCoord())
  57828. * to global coord(concrete pixel coord).
  57829. * designated by module:echarts/coord/single/Single.
  57830. * @type {Function}
  57831. */
  57832. toGlobalCoord: null,
  57833. /**
  57834. * Convert the global coord to local coord.
  57835. * designated by module:echarts/coord/single/Single.
  57836. * @type {Function}
  57837. */
  57838. toLocalCoord: null
  57839. };
  57840. inherits(SingleAxis, Axis);
  57841. /*
  57842. * Licensed to the Apache Software Foundation (ASF) under one
  57843. * or more contributor license agreements. See the NOTICE file
  57844. * distributed with this work for additional information
  57845. * regarding copyright ownership. The ASF licenses this file
  57846. * to you under the Apache License, Version 2.0 (the
  57847. * "License"); you may not use this file except in compliance
  57848. * with the License. You may obtain a copy of the License at
  57849. *
  57850. * http://www.apache.org/licenses/LICENSE-2.0
  57851. *
  57852. * Unless required by applicable law or agreed to in writing,
  57853. * software distributed under the License is distributed on an
  57854. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  57855. * KIND, either express or implied. See the License for the
  57856. * specific language governing permissions and limitations
  57857. * under the License.
  57858. */
  57859. /**
  57860. * Single coordinates system.
  57861. */
  57862. /**
  57863. * Create a single coordinates system.
  57864. *
  57865. * @param {module:echarts/coord/single/AxisModel} axisModel
  57866. * @param {module:echarts/model/Global} ecModel
  57867. * @param {module:echarts/ExtensionAPI} api
  57868. */
  57869. function Single(axisModel, ecModel, api) {
  57870. /**
  57871. * @type {string}
  57872. * @readOnly
  57873. */
  57874. this.dimension = 'single';
  57875. /**
  57876. * Add it just for draw tooltip.
  57877. *
  57878. * @type {Array.<string>}
  57879. * @readOnly
  57880. */
  57881. this.dimensions = ['single'];
  57882. /**
  57883. * @private
  57884. * @type {module:echarts/coord/single/SingleAxis}.
  57885. */
  57886. this._axis = null;
  57887. /**
  57888. * @private
  57889. * @type {module:zrender/core/BoundingRect}
  57890. */
  57891. this._rect;
  57892. this._init(axisModel, ecModel, api);
  57893. /**
  57894. * @type {module:echarts/coord/single/AxisModel}
  57895. */
  57896. this.model = axisModel;
  57897. }
  57898. Single.prototype = {
  57899. type: 'singleAxis',
  57900. axisPointerEnabled: true,
  57901. constructor: Single,
  57902. /**
  57903. * Initialize single coordinate system.
  57904. *
  57905. * @param {module:echarts/coord/single/AxisModel} axisModel
  57906. * @param {module:echarts/model/Global} ecModel
  57907. * @param {module:echarts/ExtensionAPI} api
  57908. * @private
  57909. */
  57910. _init: function (axisModel, ecModel, api) {
  57911. var dim = this.dimension;
  57912. var axis = new SingleAxis(
  57913. dim,
  57914. createScaleByModel(axisModel),
  57915. [0, 0],
  57916. axisModel.get('type'),
  57917. axisModel.get('position')
  57918. );
  57919. var isCategory = axis.type === 'category';
  57920. axis.onBand = isCategory && axisModel.get('boundaryGap');
  57921. axis.inverse = axisModel.get('inverse');
  57922. axis.orient = axisModel.get('orient');
  57923. axisModel.axis = axis;
  57924. axis.model = axisModel;
  57925. axis.coordinateSystem = this;
  57926. this._axis = axis;
  57927. },
  57928. /**
  57929. * Update axis scale after data processed
  57930. * @param {module:echarts/model/Global} ecModel
  57931. * @param {module:echarts/ExtensionAPI} api
  57932. */
  57933. update: function (ecModel, api) {
  57934. ecModel.eachSeries(function (seriesModel) {
  57935. if (seriesModel.coordinateSystem === this) {
  57936. var data = seriesModel.getData();
  57937. each$1(data.mapDimension(this.dimension, true), function (dim) {
  57938. this._axis.scale.unionExtentFromData(data, dim);
  57939. }, this);
  57940. niceScaleExtent(this._axis.scale, this._axis.model);
  57941. }
  57942. }, this);
  57943. },
  57944. /**
  57945. * Resize the single coordinate system.
  57946. *
  57947. * @param {module:echarts/coord/single/AxisModel} axisModel
  57948. * @param {module:echarts/ExtensionAPI} api
  57949. */
  57950. resize: function (axisModel, api) {
  57951. this._rect = getLayoutRect(
  57952. {
  57953. left: axisModel.get('left'),
  57954. top: axisModel.get('top'),
  57955. right: axisModel.get('right'),
  57956. bottom: axisModel.get('bottom'),
  57957. width: axisModel.get('width'),
  57958. height: axisModel.get('height')
  57959. },
  57960. {
  57961. width: api.getWidth(),
  57962. height: api.getHeight()
  57963. }
  57964. );
  57965. this._adjustAxis();
  57966. },
  57967. /**
  57968. * @return {module:zrender/core/BoundingRect}
  57969. */
  57970. getRect: function () {
  57971. return this._rect;
  57972. },
  57973. /**
  57974. * @private
  57975. */
  57976. _adjustAxis: function () {
  57977. var rect = this._rect;
  57978. var axis = this._axis;
  57979. var isHorizontal = axis.isHorizontal();
  57980. var extent = isHorizontal ? [0, rect.width] : [0, rect.height];
  57981. var idx = axis.reverse ? 1 : 0;
  57982. axis.setExtent(extent[idx], extent[1 - idx]);
  57983. this._updateAxisTransform(axis, isHorizontal ? rect.x : rect.y);
  57984. },
  57985. /**
  57986. * @param {module:echarts/coord/single/SingleAxis} axis
  57987. * @param {number} coordBase
  57988. */
  57989. _updateAxisTransform: function (axis, coordBase) {
  57990. var axisExtent = axis.getExtent();
  57991. var extentSum = axisExtent[0] + axisExtent[1];
  57992. var isHorizontal = axis.isHorizontal();
  57993. axis.toGlobalCoord = isHorizontal
  57994. ? function (coord) {
  57995. return coord + coordBase;
  57996. }
  57997. : function (coord) {
  57998. return extentSum - coord + coordBase;
  57999. };
  58000. axis.toLocalCoord = isHorizontal
  58001. ? function (coord) {
  58002. return coord - coordBase;
  58003. }
  58004. : function (coord) {
  58005. return extentSum - coord + coordBase;
  58006. };
  58007. },
  58008. /**
  58009. * Get axis.
  58010. *
  58011. * @return {module:echarts/coord/single/SingleAxis}
  58012. */
  58013. getAxis: function () {
  58014. return this._axis;
  58015. },
  58016. /**
  58017. * Get axis, add it just for draw tooltip.
  58018. *
  58019. * @return {[type]} [description]
  58020. */
  58021. getBaseAxis: function () {
  58022. return this._axis;
  58023. },
  58024. /**
  58025. * @return {Array.<module:echarts/coord/Axis>}
  58026. */
  58027. getAxes: function () {
  58028. return [this._axis];
  58029. },
  58030. /**
  58031. * @return {Object} {baseAxes: [], otherAxes: []}
  58032. */
  58033. getTooltipAxes: function () {
  58034. return {baseAxes: [this.getAxis()]};
  58035. },
  58036. /**
  58037. * If contain point.
  58038. *
  58039. * @param {Array.<number>} point
  58040. * @return {boolean}
  58041. */
  58042. containPoint: function (point) {
  58043. var rect = this.getRect();
  58044. var axis = this.getAxis();
  58045. var orient = axis.orient;
  58046. if (orient === 'horizontal') {
  58047. return axis.contain(axis.toLocalCoord(point[0]))
  58048. && (point[1] >= rect.y && point[1] <= (rect.y + rect.height));
  58049. }
  58050. else {
  58051. return axis.contain(axis.toLocalCoord(point[1]))
  58052. && (point[0] >= rect.y && point[0] <= (rect.y + rect.height));
  58053. }
  58054. },
  58055. /**
  58056. * @param {Array.<number>} point
  58057. * @return {Array.<number>}
  58058. */
  58059. pointToData: function (point) {
  58060. var axis = this.getAxis();
  58061. return [axis.coordToData(axis.toLocalCoord(
  58062. point[axis.orient === 'horizontal' ? 0 : 1]
  58063. ))];
  58064. },
  58065. /**
  58066. * Convert the series data to concrete point.
  58067. *
  58068. * @param {number|Array.<number>} val
  58069. * @return {Array.<number>}
  58070. */
  58071. dataToPoint: function (val) {
  58072. var axis = this.getAxis();
  58073. var rect = this.getRect();
  58074. var pt = [];
  58075. var idx = axis.orient === 'horizontal' ? 0 : 1;
  58076. if (val instanceof Array) {
  58077. val = val[0];
  58078. }
  58079. pt[idx] = axis.toGlobalCoord(axis.dataToCoord(+val));
  58080. pt[1 - idx] = idx === 0 ? (rect.y + rect.height / 2) : (rect.x + rect.width / 2);
  58081. return pt;
  58082. }
  58083. };
  58084. /*
  58085. * Licensed to the Apache Software Foundation (ASF) under one
  58086. * or more contributor license agreements. See the NOTICE file
  58087. * distributed with this work for additional information
  58088. * regarding copyright ownership. The ASF licenses this file
  58089. * to you under the Apache License, Version 2.0 (the
  58090. * "License"); you may not use this file except in compliance
  58091. * with the License. You may obtain a copy of the License at
  58092. *
  58093. * http://www.apache.org/licenses/LICENSE-2.0
  58094. *
  58095. * Unless required by applicable law or agreed to in writing,
  58096. * software distributed under the License is distributed on an
  58097. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  58098. * KIND, either express or implied. See the License for the
  58099. * specific language governing permissions and limitations
  58100. * under the License.
  58101. */
  58102. /**
  58103. * Single coordinate system creator.
  58104. */
  58105. /**
  58106. * Create single coordinate system and inject it into seriesModel.
  58107. *
  58108. * @param {module:echarts/model/Global} ecModel
  58109. * @param {module:echarts/ExtensionAPI} api
  58110. * @return {Array.<module:echarts/coord/single/Single>}
  58111. */
  58112. function create$3(ecModel, api) {
  58113. var singles = [];
  58114. ecModel.eachComponent('singleAxis', function (axisModel, idx) {
  58115. var single = new Single(axisModel, ecModel, api);
  58116. single.name = 'single_' + idx;
  58117. single.resize(axisModel, api);
  58118. axisModel.coordinateSystem = single;
  58119. singles.push(single);
  58120. });
  58121. ecModel.eachSeries(function (seriesModel) {
  58122. if (seriesModel.get('coordinateSystem') === 'singleAxis') {
  58123. var singleAxisModel = ecModel.queryComponents({
  58124. mainType: 'singleAxis',
  58125. index: seriesModel.get('singleAxisIndex'),
  58126. id: seriesModel.get('singleAxisId')
  58127. })[0];
  58128. seriesModel.coordinateSystem = singleAxisModel && singleAxisModel.coordinateSystem;
  58129. }
  58130. });
  58131. return singles;
  58132. }
  58133. CoordinateSystemManager.register('single', {
  58134. create: create$3,
  58135. dimensions: Single.prototype.dimensions
  58136. });
  58137. /*
  58138. * Licensed to the Apache Software Foundation (ASF) under one
  58139. * or more contributor license agreements. See the NOTICE file
  58140. * distributed with this work for additional information
  58141. * regarding copyright ownership. The ASF licenses this file
  58142. * to you under the Apache License, Version 2.0 (the
  58143. * "License"); you may not use this file except in compliance
  58144. * with the License. You may obtain a copy of the License at
  58145. *
  58146. * http://www.apache.org/licenses/LICENSE-2.0
  58147. *
  58148. * Unless required by applicable law or agreed to in writing,
  58149. * software distributed under the License is distributed on an
  58150. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  58151. * KIND, either express or implied. See the License for the
  58152. * specific language governing permissions and limitations
  58153. * under the License.
  58154. */
  58155. /**
  58156. * @param {Object} opt {labelInside}
  58157. * @return {Object} {
  58158. * position, rotation, labelDirection, labelOffset,
  58159. * tickDirection, labelRotate, z2
  58160. * }
  58161. */
  58162. function layout$2(axisModel, opt) {
  58163. opt = opt || {};
  58164. var single = axisModel.coordinateSystem;
  58165. var axis = axisModel.axis;
  58166. var layout = {};
  58167. var axisPosition = axis.position;
  58168. var orient = axis.orient;
  58169. var rect = single.getRect();
  58170. var rectBound = [rect.x, rect.x + rect.width, rect.y, rect.y + rect.height];
  58171. var positionMap = {
  58172. horizontal: {top: rectBound[2], bottom: rectBound[3]},
  58173. vertical: {left: rectBound[0], right: rectBound[1]}
  58174. };
  58175. layout.position = [
  58176. orient === 'vertical'
  58177. ? positionMap.vertical[axisPosition]
  58178. : rectBound[0],
  58179. orient === 'horizontal'
  58180. ? positionMap.horizontal[axisPosition]
  58181. : rectBound[3]
  58182. ];
  58183. var r = {horizontal: 0, vertical: 1};
  58184. layout.rotation = Math.PI / 2 * r[orient];
  58185. var directionMap = {top: -1, bottom: 1, right: 1, left: -1};
  58186. layout.labelDirection = layout.tickDirection
  58187. = layout.nameDirection
  58188. = directionMap[axisPosition];
  58189. if (axisModel.get('axisTick.inside')) {
  58190. layout.tickDirection = -layout.tickDirection;
  58191. }
  58192. if (retrieve(opt.labelInside, axisModel.get('axisLabel.inside'))) {
  58193. layout.labelDirection = -layout.labelDirection;
  58194. }
  58195. var labelRotation = opt.rotate;
  58196. labelRotation == null && (labelRotation = axisModel.get('axisLabel.rotate'));
  58197. layout.labelRotation = axisPosition === 'top' ? -labelRotation : labelRotation;
  58198. layout.z2 = 1;
  58199. return layout;
  58200. }
  58201. /*
  58202. * Licensed to the Apache Software Foundation (ASF) under one
  58203. * or more contributor license agreements. See the NOTICE file
  58204. * distributed with this work for additional information
  58205. * regarding copyright ownership. The ASF licenses this file
  58206. * to you under the Apache License, Version 2.0 (the
  58207. * "License"); you may not use this file except in compliance
  58208. * with the License. You may obtain a copy of the License at
  58209. *
  58210. * http://www.apache.org/licenses/LICENSE-2.0
  58211. *
  58212. * Unless required by applicable law or agreed to in writing,
  58213. * software distributed under the License is distributed on an
  58214. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  58215. * KIND, either express or implied. See the License for the
  58216. * specific language governing permissions and limitations
  58217. * under the License.
  58218. */
  58219. var axisBuilderAttrs$2 = [
  58220. 'axisLine', 'axisTickLabel', 'axisName'
  58221. ];
  58222. var selfBuilderAttr = 'splitLine';
  58223. var SingleAxisView = AxisView.extend({
  58224. type: 'singleAxis',
  58225. axisPointerClass: 'SingleAxisPointer',
  58226. render: function (axisModel, ecModel, api, payload) {
  58227. var group = this.group;
  58228. group.removeAll();
  58229. var layout = layout$2(axisModel);
  58230. var axisBuilder = new AxisBuilder(axisModel, layout);
  58231. each$1(axisBuilderAttrs$2, axisBuilder.add, axisBuilder);
  58232. group.add(axisBuilder.getGroup());
  58233. if (axisModel.get(selfBuilderAttr + '.show')) {
  58234. this['_' + selfBuilderAttr](axisModel);
  58235. }
  58236. SingleAxisView.superCall(this, 'render', axisModel, ecModel, api, payload);
  58237. },
  58238. _splitLine: function (axisModel) {
  58239. var axis = axisModel.axis;
  58240. if (axis.scale.isBlank()) {
  58241. return;
  58242. }
  58243. var splitLineModel = axisModel.getModel('splitLine');
  58244. var lineStyleModel = splitLineModel.getModel('lineStyle');
  58245. var lineWidth = lineStyleModel.get('width');
  58246. var lineColors = lineStyleModel.get('color');
  58247. lineColors = lineColors instanceof Array ? lineColors : [lineColors];
  58248. var gridRect = axisModel.coordinateSystem.getRect();
  58249. var isHorizontal = axis.isHorizontal();
  58250. var splitLines = [];
  58251. var lineCount = 0;
  58252. var ticksCoords = axis.getTicksCoords({
  58253. tickModel: splitLineModel
  58254. });
  58255. var p1 = [];
  58256. var p2 = [];
  58257. for (var i = 0; i < ticksCoords.length; ++i) {
  58258. var tickCoord = axis.toGlobalCoord(ticksCoords[i].coord);
  58259. if (isHorizontal) {
  58260. p1[0] = tickCoord;
  58261. p1[1] = gridRect.y;
  58262. p2[0] = tickCoord;
  58263. p2[1] = gridRect.y + gridRect.height;
  58264. }
  58265. else {
  58266. p1[0] = gridRect.x;
  58267. p1[1] = tickCoord;
  58268. p2[0] = gridRect.x + gridRect.width;
  58269. p2[1] = tickCoord;
  58270. }
  58271. var colorIndex = (lineCount++) % lineColors.length;
  58272. splitLines[colorIndex] = splitLines[colorIndex] || [];
  58273. splitLines[colorIndex].push(new Line({
  58274. subPixelOptimize: true,
  58275. shape: {
  58276. x1: p1[0],
  58277. y1: p1[1],
  58278. x2: p2[0],
  58279. y2: p2[1]
  58280. },
  58281. style: {
  58282. lineWidth: lineWidth
  58283. },
  58284. silent: true
  58285. }));
  58286. }
  58287. for (var i = 0; i < splitLines.length; ++i) {
  58288. this.group.add(mergePath(splitLines[i], {
  58289. style: {
  58290. stroke: lineColors[i % lineColors.length],
  58291. lineDash: lineStyleModel.getLineDash(lineWidth),
  58292. lineWidth: lineWidth
  58293. },
  58294. silent: true
  58295. }));
  58296. }
  58297. }
  58298. });
  58299. /*
  58300. * Licensed to the Apache Software Foundation (ASF) under one
  58301. * or more contributor license agreements. See the NOTICE file
  58302. * distributed with this work for additional information
  58303. * regarding copyright ownership. The ASF licenses this file
  58304. * to you under the Apache License, Version 2.0 (the
  58305. * "License"); you may not use this file except in compliance
  58306. * with the License. You may obtain a copy of the License at
  58307. *
  58308. * http://www.apache.org/licenses/LICENSE-2.0
  58309. *
  58310. * Unless required by applicable law or agreed to in writing,
  58311. * software distributed under the License is distributed on an
  58312. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  58313. * KIND, either express or implied. See the License for the
  58314. * specific language governing permissions and limitations
  58315. * under the License.
  58316. */
  58317. var AxisModel$4 = ComponentModel.extend({
  58318. type: 'singleAxis',
  58319. layoutMode: 'box',
  58320. /**
  58321. * @type {module:echarts/coord/single/SingleAxis}
  58322. */
  58323. axis: null,
  58324. /**
  58325. * @type {module:echarts/coord/single/Single}
  58326. */
  58327. coordinateSystem: null,
  58328. /**
  58329. * @override
  58330. */
  58331. getCoordSysModel: function () {
  58332. return this;
  58333. }
  58334. });
  58335. var defaultOption$2 = {
  58336. left: '5%',
  58337. top: '5%',
  58338. right: '5%',
  58339. bottom: '5%',
  58340. type: 'value',
  58341. position: 'bottom',
  58342. orient: 'horizontal',
  58343. axisLine: {
  58344. show: true,
  58345. lineStyle: {
  58346. width: 1,
  58347. type: 'solid'
  58348. }
  58349. },
  58350. // Single coordinate system and single axis is the,
  58351. // which is used as the parent tooltip model.
  58352. // same model, so we set default tooltip show as true.
  58353. tooltip: {
  58354. show: true
  58355. },
  58356. axisTick: {
  58357. show: true,
  58358. length: 6,
  58359. lineStyle: {
  58360. width: 1
  58361. }
  58362. },
  58363. axisLabel: {
  58364. show: true,
  58365. interval: 'auto'
  58366. },
  58367. splitLine: {
  58368. show: true,
  58369. lineStyle: {
  58370. type: 'dashed',
  58371. opacity: 0.2
  58372. }
  58373. }
  58374. };
  58375. function getAxisType$2(axisName, option) {
  58376. return option.type || (option.data ? 'category' : 'value');
  58377. }
  58378. merge(AxisModel$4.prototype, axisModelCommonMixin);
  58379. axisModelCreator('single', AxisModel$4, getAxisType$2, defaultOption$2);
  58380. /*
  58381. * Licensed to the Apache Software Foundation (ASF) under one
  58382. * or more contributor license agreements. See the NOTICE file
  58383. * distributed with this work for additional information
  58384. * regarding copyright ownership. The ASF licenses this file
  58385. * to you under the Apache License, Version 2.0 (the
  58386. * "License"); you may not use this file except in compliance
  58387. * with the License. You may obtain a copy of the License at
  58388. *
  58389. * http://www.apache.org/licenses/LICENSE-2.0
  58390. *
  58391. * Unless required by applicable law or agreed to in writing,
  58392. * software distributed under the License is distributed on an
  58393. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  58394. * KIND, either express or implied. See the License for the
  58395. * specific language governing permissions and limitations
  58396. * under the License.
  58397. */
  58398. /**
  58399. * @param {Object} finder contains {seriesIndex, dataIndex, dataIndexInside}
  58400. * @param {module:echarts/model/Global} ecModel
  58401. * @return {Object} {point: [x, y], el: ...} point Will not be null.
  58402. */
  58403. var findPointFromSeries = function (finder, ecModel) {
  58404. var point = [];
  58405. var seriesIndex = finder.seriesIndex;
  58406. var seriesModel;
  58407. if (seriesIndex == null || !(
  58408. seriesModel = ecModel.getSeriesByIndex(seriesIndex)
  58409. )) {
  58410. return {point: []};
  58411. }
  58412. var data = seriesModel.getData();
  58413. var dataIndex = queryDataIndex(data, finder);
  58414. if (dataIndex == null || dataIndex < 0 || isArray(dataIndex)) {
  58415. return {point: []};
  58416. }
  58417. var el = data.getItemGraphicEl(dataIndex);
  58418. var coordSys = seriesModel.coordinateSystem;
  58419. if (seriesModel.getTooltipPosition) {
  58420. point = seriesModel.getTooltipPosition(dataIndex) || [];
  58421. }
  58422. else if (coordSys && coordSys.dataToPoint) {
  58423. point = coordSys.dataToPoint(
  58424. data.getValues(
  58425. map(coordSys.dimensions, function (dim) {
  58426. return data.mapDimension(dim);
  58427. }), dataIndex, true
  58428. )
  58429. ) || [];
  58430. }
  58431. else if (el) {
  58432. // Use graphic bounding rect
  58433. var rect = el.getBoundingRect().clone();
  58434. rect.applyTransform(el.transform);
  58435. point = [
  58436. rect.x + rect.width / 2,
  58437. rect.y + rect.height / 2
  58438. ];
  58439. }
  58440. return {point: point, el: el};
  58441. };
  58442. /*
  58443. * Licensed to the Apache Software Foundation (ASF) under one
  58444. * or more contributor license agreements. See the NOTICE file
  58445. * distributed with this work for additional information
  58446. * regarding copyright ownership. The ASF licenses this file
  58447. * to you under the Apache License, Version 2.0 (the
  58448. * "License"); you may not use this file except in compliance
  58449. * with the License. You may obtain a copy of the License at
  58450. *
  58451. * http://www.apache.org/licenses/LICENSE-2.0
  58452. *
  58453. * Unless required by applicable law or agreed to in writing,
  58454. * software distributed under the License is distributed on an
  58455. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  58456. * KIND, either express or implied. See the License for the
  58457. * specific language governing permissions and limitations
  58458. * under the License.
  58459. */
  58460. var each$14 = each$1;
  58461. var curry$3 = curry;
  58462. var inner$9 = makeInner();
  58463. /**
  58464. * Basic logic: check all axis, if they do not demand show/highlight,
  58465. * then hide/downplay them.
  58466. *
  58467. * @param {Object} coordSysAxesInfo
  58468. * @param {Object} payload
  58469. * @param {string} [payload.currTrigger] 'click' | 'mousemove' | 'leave'
  58470. * @param {Array.<number>} [payload.x] x and y, which are mandatory, specify a point to
  58471. * trigger axisPointer and tooltip.
  58472. * @param {Array.<number>} [payload.y] x and y, which are mandatory, specify a point to
  58473. * trigger axisPointer and tooltip.
  58474. * @param {Object} [payload.seriesIndex] finder, optional, restrict target axes.
  58475. * @param {Object} [payload.dataIndex] finder, restrict target axes.
  58476. * @param {Object} [payload.axesInfo] finder, restrict target axes.
  58477. * [{
  58478. * axisDim: 'x'|'y'|'angle'|...,
  58479. * axisIndex: ...,
  58480. * value: ...
  58481. * }, ...]
  58482. * @param {Function} [payload.dispatchAction]
  58483. * @param {Object} [payload.tooltipOption]
  58484. * @param {Object|Array.<number>|Function} [payload.position] Tooltip position,
  58485. * which can be specified in dispatchAction
  58486. * @param {module:echarts/model/Global} ecModel
  58487. * @param {module:echarts/ExtensionAPI} api
  58488. * @return {Object} content of event obj for echarts.connect.
  58489. */
  58490. var axisTrigger = function (payload, ecModel, api) {
  58491. var currTrigger = payload.currTrigger;
  58492. var point = [payload.x, payload.y];
  58493. var finder = payload;
  58494. var dispatchAction = payload.dispatchAction || bind(api.dispatchAction, api);
  58495. var coordSysAxesInfo = ecModel.getComponent('axisPointer').coordSysAxesInfo;
  58496. // Pending
  58497. // See #6121. But we are not able to reproduce it yet.
  58498. if (!coordSysAxesInfo) {
  58499. return;
  58500. }
  58501. if (illegalPoint(point)) {
  58502. // Used in the default behavior of `connection`: use the sample seriesIndex
  58503. // and dataIndex. And also used in the tooltipView trigger.
  58504. point = findPointFromSeries({
  58505. seriesIndex: finder.seriesIndex,
  58506. // Do not use dataIndexInside from other ec instance.
  58507. // FIXME: auto detect it?
  58508. dataIndex: finder.dataIndex
  58509. }, ecModel).point;
  58510. }
  58511. var isIllegalPoint = illegalPoint(point);
  58512. // Axis and value can be specified when calling dispatchAction({type: 'updateAxisPointer'}).
  58513. // Notice: In this case, it is difficult to get the `point` (which is necessary to show
  58514. // tooltip, so if point is not given, we just use the point found by sample seriesIndex
  58515. // and dataIndex.
  58516. var inputAxesInfo = finder.axesInfo;
  58517. var axesInfo = coordSysAxesInfo.axesInfo;
  58518. var shouldHide = currTrigger === 'leave' || illegalPoint(point);
  58519. var outputFinder = {};
  58520. var showValueMap = {};
  58521. var dataByCoordSys = {list: [], map: {}};
  58522. var updaters = {
  58523. showPointer: curry$3(showPointer, showValueMap),
  58524. showTooltip: curry$3(showTooltip, dataByCoordSys)
  58525. };
  58526. // Process for triggered axes.
  58527. each$14(coordSysAxesInfo.coordSysMap, function (coordSys, coordSysKey) {
  58528. // If a point given, it must be contained by the coordinate system.
  58529. var coordSysContainsPoint = isIllegalPoint || coordSys.containPoint(point);
  58530. each$14(coordSysAxesInfo.coordSysAxesInfo[coordSysKey], function (axisInfo, key) {
  58531. var axis = axisInfo.axis;
  58532. var inputAxisInfo = findInputAxisInfo(inputAxesInfo, axisInfo);
  58533. // If no inputAxesInfo, no axis is restricted.
  58534. if (!shouldHide && coordSysContainsPoint && (!inputAxesInfo || inputAxisInfo)) {
  58535. var val = inputAxisInfo && inputAxisInfo.value;
  58536. if (val == null && !isIllegalPoint) {
  58537. val = axis.pointToData(point);
  58538. }
  58539. val != null && processOnAxis(axisInfo, val, updaters, false, outputFinder);
  58540. }
  58541. });
  58542. });
  58543. // Process for linked axes.
  58544. var linkTriggers = {};
  58545. each$14(axesInfo, function (tarAxisInfo, tarKey) {
  58546. var linkGroup = tarAxisInfo.linkGroup;
  58547. // If axis has been triggered in the previous stage, it should not be triggered by link.
  58548. if (linkGroup && !showValueMap[tarKey]) {
  58549. each$14(linkGroup.axesInfo, function (srcAxisInfo, srcKey) {
  58550. var srcValItem = showValueMap[srcKey];
  58551. // If srcValItem exist, source axis is triggered, so link to target axis.
  58552. if (srcAxisInfo !== tarAxisInfo && srcValItem) {
  58553. var val = srcValItem.value;
  58554. linkGroup.mapper && (val = tarAxisInfo.axis.scale.parse(linkGroup.mapper(
  58555. val, makeMapperParam(srcAxisInfo), makeMapperParam(tarAxisInfo)
  58556. )));
  58557. linkTriggers[tarAxisInfo.key] = val;
  58558. }
  58559. });
  58560. }
  58561. });
  58562. each$14(linkTriggers, function (val, tarKey) {
  58563. processOnAxis(axesInfo[tarKey], val, updaters, true, outputFinder);
  58564. });
  58565. updateModelActually(showValueMap, axesInfo, outputFinder);
  58566. dispatchTooltipActually(dataByCoordSys, point, payload, dispatchAction);
  58567. dispatchHighDownActually(axesInfo, dispatchAction, api);
  58568. return outputFinder;
  58569. };
  58570. function processOnAxis(axisInfo, newValue, updaters, dontSnap, outputFinder) {
  58571. var axis = axisInfo.axis;
  58572. if (axis.scale.isBlank() || !axis.containData(newValue)) {
  58573. return;
  58574. }
  58575. if (!axisInfo.involveSeries) {
  58576. updaters.showPointer(axisInfo, newValue);
  58577. return;
  58578. }
  58579. // Heavy calculation. So put it after axis.containData checking.
  58580. var payloadInfo = buildPayloadsBySeries(newValue, axisInfo);
  58581. var payloadBatch = payloadInfo.payloadBatch;
  58582. var snapToValue = payloadInfo.snapToValue;
  58583. // Fill content of event obj for echarts.connect.
  58584. // By defualt use the first involved series data as a sample to connect.
  58585. if (payloadBatch[0] && outputFinder.seriesIndex == null) {
  58586. extend(outputFinder, payloadBatch[0]);
  58587. }
  58588. // If no linkSource input, this process is for collecting link
  58589. // target, where snap should not be accepted.
  58590. if (!dontSnap && axisInfo.snap) {
  58591. if (axis.containData(snapToValue) && snapToValue != null) {
  58592. newValue = snapToValue;
  58593. }
  58594. }
  58595. updaters.showPointer(axisInfo, newValue, payloadBatch, outputFinder);
  58596. // Tooltip should always be snapToValue, otherwise there will be
  58597. // incorrect "axis value ~ series value" mapping displayed in tooltip.
  58598. updaters.showTooltip(axisInfo, payloadInfo, snapToValue);
  58599. }
  58600. function buildPayloadsBySeries(value, axisInfo) {
  58601. var axis = axisInfo.axis;
  58602. var dim = axis.dim;
  58603. var snapToValue = value;
  58604. var payloadBatch = [];
  58605. var minDist = Number.MAX_VALUE;
  58606. var minDiff = -1;
  58607. each$14(axisInfo.seriesModels, function (series, idx) {
  58608. var dataDim = series.getData().mapDimension(dim, true);
  58609. var seriesNestestValue;
  58610. var dataIndices;
  58611. if (series.getAxisTooltipData) {
  58612. var result = series.getAxisTooltipData(dataDim, value, axis);
  58613. dataIndices = result.dataIndices;
  58614. seriesNestestValue = result.nestestValue;
  58615. }
  58616. else {
  58617. dataIndices = series.getData().indicesOfNearest(
  58618. dataDim[0],
  58619. value,
  58620. // Add a threshold to avoid find the wrong dataIndex
  58621. // when data length is not same.
  58622. // false,
  58623. axis.type === 'category' ? 0.5 : null
  58624. );
  58625. if (!dataIndices.length) {
  58626. return;
  58627. }
  58628. seriesNestestValue = series.getData().get(dataDim[0], dataIndices[0]);
  58629. }
  58630. if (seriesNestestValue == null || !isFinite(seriesNestestValue)) {
  58631. return;
  58632. }
  58633. var diff = value - seriesNestestValue;
  58634. var dist = Math.abs(diff);
  58635. // Consider category case
  58636. if (dist <= minDist) {
  58637. if (dist < minDist || (diff >= 0 && minDiff < 0)) {
  58638. minDist = dist;
  58639. minDiff = diff;
  58640. snapToValue = seriesNestestValue;
  58641. payloadBatch.length = 0;
  58642. }
  58643. each$14(dataIndices, function (dataIndex) {
  58644. payloadBatch.push({
  58645. seriesIndex: series.seriesIndex,
  58646. dataIndexInside: dataIndex,
  58647. dataIndex: series.getData().getRawIndex(dataIndex)
  58648. });
  58649. });
  58650. }
  58651. });
  58652. return {
  58653. payloadBatch: payloadBatch,
  58654. snapToValue: snapToValue
  58655. };
  58656. }
  58657. function showPointer(showValueMap, axisInfo, value, payloadBatch) {
  58658. showValueMap[axisInfo.key] = {value: value, payloadBatch: payloadBatch};
  58659. }
  58660. function showTooltip(dataByCoordSys, axisInfo, payloadInfo, value) {
  58661. var payloadBatch = payloadInfo.payloadBatch;
  58662. var axis = axisInfo.axis;
  58663. var axisModel = axis.model;
  58664. var axisPointerModel = axisInfo.axisPointerModel;
  58665. // If no data, do not create anything in dataByCoordSys,
  58666. // whose length will be used to judge whether dispatch action.
  58667. if (!axisInfo.triggerTooltip || !payloadBatch.length) {
  58668. return;
  58669. }
  58670. var coordSysModel = axisInfo.coordSys.model;
  58671. var coordSysKey = makeKey(coordSysModel);
  58672. var coordSysItem = dataByCoordSys.map[coordSysKey];
  58673. if (!coordSysItem) {
  58674. coordSysItem = dataByCoordSys.map[coordSysKey] = {
  58675. coordSysId: coordSysModel.id,
  58676. coordSysIndex: coordSysModel.componentIndex,
  58677. coordSysType: coordSysModel.type,
  58678. coordSysMainType: coordSysModel.mainType,
  58679. dataByAxis: []
  58680. };
  58681. dataByCoordSys.list.push(coordSysItem);
  58682. }
  58683. coordSysItem.dataByAxis.push({
  58684. axisDim: axis.dim,
  58685. axisIndex: axisModel.componentIndex,
  58686. axisType: axisModel.type,
  58687. axisId: axisModel.id,
  58688. value: value,
  58689. // Caustion: viewHelper.getValueLabel is actually on "view stage", which
  58690. // depends that all models have been updated. So it should not be performed
  58691. // here. Considering axisPointerModel used here is volatile, which is hard
  58692. // to be retrieve in TooltipView, we prepare parameters here.
  58693. valueLabelOpt: {
  58694. precision: axisPointerModel.get('label.precision'),
  58695. formatter: axisPointerModel.get('label.formatter')
  58696. },
  58697. seriesDataIndices: payloadBatch.slice()
  58698. });
  58699. }
  58700. function updateModelActually(showValueMap, axesInfo, outputFinder) {
  58701. var outputAxesInfo = outputFinder.axesInfo = [];
  58702. // Basic logic: If no 'show' required, 'hide' this axisPointer.
  58703. each$14(axesInfo, function (axisInfo, key) {
  58704. var option = axisInfo.axisPointerModel.option;
  58705. var valItem = showValueMap[key];
  58706. if (valItem) {
  58707. !axisInfo.useHandle && (option.status = 'show');
  58708. option.value = valItem.value;
  58709. // For label formatter param and highlight.
  58710. option.seriesDataIndices = (valItem.payloadBatch || []).slice();
  58711. }
  58712. // When always show (e.g., handle used), remain
  58713. // original value and status.
  58714. else {
  58715. // If hide, value still need to be set, consider
  58716. // click legend to toggle axis blank.
  58717. !axisInfo.useHandle && (option.status = 'hide');
  58718. }
  58719. // If status is 'hide', should be no info in payload.
  58720. option.status === 'show' && outputAxesInfo.push({
  58721. axisDim: axisInfo.axis.dim,
  58722. axisIndex: axisInfo.axis.model.componentIndex,
  58723. value: option.value
  58724. });
  58725. });
  58726. }
  58727. function dispatchTooltipActually(dataByCoordSys, point, payload, dispatchAction) {
  58728. // Basic logic: If no showTip required, hideTip will be dispatched.
  58729. if (illegalPoint(point) || !dataByCoordSys.list.length) {
  58730. dispatchAction({type: 'hideTip'});
  58731. return;
  58732. }
  58733. // In most case only one axis (or event one series is used). It is
  58734. // convinient to fetch payload.seriesIndex and payload.dataIndex
  58735. // dirtectly. So put the first seriesIndex and dataIndex of the first
  58736. // axis on the payload.
  58737. var sampleItem = ((dataByCoordSys.list[0].dataByAxis[0] || {}).seriesDataIndices || [])[0] || {};
  58738. dispatchAction({
  58739. type: 'showTip',
  58740. escapeConnect: true,
  58741. x: point[0],
  58742. y: point[1],
  58743. tooltipOption: payload.tooltipOption,
  58744. position: payload.position,
  58745. dataIndexInside: sampleItem.dataIndexInside,
  58746. dataIndex: sampleItem.dataIndex,
  58747. seriesIndex: sampleItem.seriesIndex,
  58748. dataByCoordSys: dataByCoordSys.list
  58749. });
  58750. }
  58751. function dispatchHighDownActually(axesInfo, dispatchAction, api) {
  58752. // FIXME
  58753. // highlight status modification shoule be a stage of main process?
  58754. // (Consider confilct (e.g., legend and axisPointer) and setOption)
  58755. var zr = api.getZr();
  58756. var highDownKey = 'axisPointerLastHighlights';
  58757. var lastHighlights = inner$9(zr)[highDownKey] || {};
  58758. var newHighlights = inner$9(zr)[highDownKey] = {};
  58759. // Update highlight/downplay status according to axisPointer model.
  58760. // Build hash map and remove duplicate incidentally.
  58761. each$14(axesInfo, function (axisInfo, key) {
  58762. var option = axisInfo.axisPointerModel.option;
  58763. option.status === 'show' && each$14(option.seriesDataIndices, function (batchItem) {
  58764. var key = batchItem.seriesIndex + ' | ' + batchItem.dataIndex;
  58765. newHighlights[key] = batchItem;
  58766. });
  58767. });
  58768. // Diff.
  58769. var toHighlight = [];
  58770. var toDownplay = [];
  58771. each$1(lastHighlights, function (batchItem, key) {
  58772. !newHighlights[key] && toDownplay.push(batchItem);
  58773. });
  58774. each$1(newHighlights, function (batchItem, key) {
  58775. !lastHighlights[key] && toHighlight.push(batchItem);
  58776. });
  58777. toDownplay.length && api.dispatchAction({
  58778. type: 'downplay', escapeConnect: true, batch: toDownplay
  58779. });
  58780. toHighlight.length && api.dispatchAction({
  58781. type: 'highlight', escapeConnect: true, batch: toHighlight
  58782. });
  58783. }
  58784. function findInputAxisInfo(inputAxesInfo, axisInfo) {
  58785. for (var i = 0; i < (inputAxesInfo || []).length; i++) {
  58786. var inputAxisInfo = inputAxesInfo[i];
  58787. if (axisInfo.axis.dim === inputAxisInfo.axisDim
  58788. && axisInfo.axis.model.componentIndex === inputAxisInfo.axisIndex
  58789. ) {
  58790. return inputAxisInfo;
  58791. }
  58792. }
  58793. }
  58794. function makeMapperParam(axisInfo) {
  58795. var axisModel = axisInfo.axis.model;
  58796. var item = {};
  58797. var dim = item.axisDim = axisInfo.axis.dim;
  58798. item.axisIndex = item[dim + 'AxisIndex'] = axisModel.componentIndex;
  58799. item.axisName = item[dim + 'AxisName'] = axisModel.name;
  58800. item.axisId = item[dim + 'AxisId'] = axisModel.id;
  58801. return item;
  58802. }
  58803. function illegalPoint(point) {
  58804. return !point || point[0] == null || isNaN(point[0]) || point[1] == null || isNaN(point[1]);
  58805. }
  58806. /*
  58807. * Licensed to the Apache Software Foundation (ASF) under one
  58808. * or more contributor license agreements. See the NOTICE file
  58809. * distributed with this work for additional information
  58810. * regarding copyright ownership. The ASF licenses this file
  58811. * to you under the Apache License, Version 2.0 (the
  58812. * "License"); you may not use this file except in compliance
  58813. * with the License. You may obtain a copy of the License at
  58814. *
  58815. * http://www.apache.org/licenses/LICENSE-2.0
  58816. *
  58817. * Unless required by applicable law or agreed to in writing,
  58818. * software distributed under the License is distributed on an
  58819. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  58820. * KIND, either express or implied. See the License for the
  58821. * specific language governing permissions and limitations
  58822. * under the License.
  58823. */
  58824. var AxisPointerModel = extendComponentModel({
  58825. type: 'axisPointer',
  58826. coordSysAxesInfo: null,
  58827. defaultOption: {
  58828. // 'auto' means that show when triggered by tooltip or handle.
  58829. show: 'auto',
  58830. // 'click' | 'mousemove' | 'none'
  58831. triggerOn: null, // set default in AxisPonterView.js
  58832. zlevel: 0,
  58833. z: 50,
  58834. type: 'line', // 'line' 'shadow' 'cross' 'none'.
  58835. // axispointer triggered by tootip determine snap automatically,
  58836. // see `modelHelper`.
  58837. snap: false,
  58838. triggerTooltip: true,
  58839. value: null,
  58840. status: null, // Init value depends on whether handle is used.
  58841. // [group0, group1, ...]
  58842. // Each group can be: {
  58843. // mapper: function () {},
  58844. // singleTooltip: 'multiple', // 'multiple' or 'single'
  58845. // xAxisId: ...,
  58846. // yAxisName: ...,
  58847. // angleAxisIndex: ...
  58848. // }
  58849. // mapper: can be ignored.
  58850. // input: {axisInfo, value}
  58851. // output: {axisInfo, value}
  58852. link: [],
  58853. // Do not set 'auto' here, otherwise global animation: false
  58854. // will not effect at this axispointer.
  58855. animation: null,
  58856. animationDurationUpdate: 200,
  58857. lineStyle: {
  58858. color: '#aaa',
  58859. width: 1,
  58860. type: 'solid'
  58861. },
  58862. shadowStyle: {
  58863. color: 'rgba(150,150,150,0.3)'
  58864. },
  58865. label: {
  58866. show: true,
  58867. formatter: null, // string | Function
  58868. precision: 'auto', // Or a number like 0, 1, 2 ...
  58869. margin: 3,
  58870. color: '#fff',
  58871. padding: [5, 7, 5, 7],
  58872. backgroundColor: 'auto', // default: axis line color
  58873. borderColor: null,
  58874. borderWidth: 0,
  58875. shadowBlur: 3,
  58876. shadowColor: '#aaa'
  58877. // Considering applicability, common style should
  58878. // better not have shadowOffset.
  58879. // shadowOffsetX: 0,
  58880. // shadowOffsetY: 2
  58881. },
  58882. handle: {
  58883. show: false,
  58884. /* eslint-disable */
  58885. 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
  58886. /* eslint-enable */
  58887. size: 45,
  58888. // handle margin is from symbol center to axis, which is stable when circular move.
  58889. margin: 50,
  58890. // color: '#1b8bbd'
  58891. // color: '#2f4554'
  58892. color: '#333',
  58893. shadowBlur: 3,
  58894. shadowColor: '#aaa',
  58895. shadowOffsetX: 0,
  58896. shadowOffsetY: 2,
  58897. // For mobile performance
  58898. throttle: 40
  58899. }
  58900. }
  58901. });
  58902. /*
  58903. * Licensed to the Apache Software Foundation (ASF) under one
  58904. * or more contributor license agreements. See the NOTICE file
  58905. * distributed with this work for additional information
  58906. * regarding copyright ownership. The ASF licenses this file
  58907. * to you under the Apache License, Version 2.0 (the
  58908. * "License"); you may not use this file except in compliance
  58909. * with the License. You may obtain a copy of the License at
  58910. *
  58911. * http://www.apache.org/licenses/LICENSE-2.0
  58912. *
  58913. * Unless required by applicable law or agreed to in writing,
  58914. * software distributed under the License is distributed on an
  58915. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  58916. * KIND, either express or implied. See the License for the
  58917. * specific language governing permissions and limitations
  58918. * under the License.
  58919. */
  58920. var inner$10 = makeInner();
  58921. var each$15 = each$1;
  58922. /**
  58923. * @param {string} key
  58924. * @param {module:echarts/ExtensionAPI} api
  58925. * @param {Function} handler
  58926. * param: {string} currTrigger
  58927. * param: {Array.<number>} point
  58928. */
  58929. function register(key, api, handler) {
  58930. if (env$1.node) {
  58931. return;
  58932. }
  58933. var zr = api.getZr();
  58934. inner$10(zr).records || (inner$10(zr).records = {});
  58935. initGlobalListeners(zr, api);
  58936. var record = inner$10(zr).records[key] || (inner$10(zr).records[key] = {});
  58937. record.handler = handler;
  58938. }
  58939. function initGlobalListeners(zr, api) {
  58940. if (inner$10(zr).initialized) {
  58941. return;
  58942. }
  58943. inner$10(zr).initialized = true;
  58944. useHandler('click', curry(doEnter, 'click'));
  58945. useHandler('mousemove', curry(doEnter, 'mousemove'));
  58946. // useHandler('mouseout', onLeave);
  58947. useHandler('globalout', onLeave);
  58948. function useHandler(eventType, cb) {
  58949. zr.on(eventType, function (e) {
  58950. var dis = makeDispatchAction(api);
  58951. each$15(inner$10(zr).records, function (record) {
  58952. record && cb(record, e, dis.dispatchAction);
  58953. });
  58954. dispatchTooltipFinally(dis.pendings, api);
  58955. });
  58956. }
  58957. }
  58958. function dispatchTooltipFinally(pendings, api) {
  58959. var showLen = pendings.showTip.length;
  58960. var hideLen = pendings.hideTip.length;
  58961. var actuallyPayload;
  58962. if (showLen) {
  58963. actuallyPayload = pendings.showTip[showLen - 1];
  58964. }
  58965. else if (hideLen) {
  58966. actuallyPayload = pendings.hideTip[hideLen - 1];
  58967. }
  58968. if (actuallyPayload) {
  58969. actuallyPayload.dispatchAction = null;
  58970. api.dispatchAction(actuallyPayload);
  58971. }
  58972. }
  58973. function onLeave(record, e, dispatchAction) {
  58974. record.handler('leave', null, dispatchAction);
  58975. }
  58976. function doEnter(currTrigger, record, e, dispatchAction) {
  58977. record.handler(currTrigger, e, dispatchAction);
  58978. }
  58979. function makeDispatchAction(api) {
  58980. var pendings = {
  58981. showTip: [],
  58982. hideTip: []
  58983. };
  58984. // FIXME
  58985. // better approach?
  58986. // 'showTip' and 'hideTip' can be triggered by axisPointer and tooltip,
  58987. // which may be conflict, (axisPointer call showTip but tooltip call hideTip);
  58988. // So we have to add "final stage" to merge those dispatched actions.
  58989. var dispatchAction = function (payload) {
  58990. var pendingList = pendings[payload.type];
  58991. if (pendingList) {
  58992. pendingList.push(payload);
  58993. }
  58994. else {
  58995. payload.dispatchAction = dispatchAction;
  58996. api.dispatchAction(payload);
  58997. }
  58998. };
  58999. return {
  59000. dispatchAction: dispatchAction,
  59001. pendings: pendings
  59002. };
  59003. }
  59004. /**
  59005. * @param {string} key
  59006. * @param {module:echarts/ExtensionAPI} api
  59007. */
  59008. function unregister(key, api) {
  59009. if (env$1.node) {
  59010. return;
  59011. }
  59012. var zr = api.getZr();
  59013. var record = (inner$10(zr).records || {})[key];
  59014. if (record) {
  59015. inner$10(zr).records[key] = null;
  59016. }
  59017. }
  59018. /*
  59019. * Licensed to the Apache Software Foundation (ASF) under one
  59020. * or more contributor license agreements. See the NOTICE file
  59021. * distributed with this work for additional information
  59022. * regarding copyright ownership. The ASF licenses this file
  59023. * to you under the Apache License, Version 2.0 (the
  59024. * "License"); you may not use this file except in compliance
  59025. * with the License. You may obtain a copy of the License at
  59026. *
  59027. * http://www.apache.org/licenses/LICENSE-2.0
  59028. *
  59029. * Unless required by applicable law or agreed to in writing,
  59030. * software distributed under the License is distributed on an
  59031. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  59032. * KIND, either express or implied. See the License for the
  59033. * specific language governing permissions and limitations
  59034. * under the License.
  59035. */
  59036. var AxisPointerView = extendComponentView({
  59037. type: 'axisPointer',
  59038. render: function (globalAxisPointerModel, ecModel, api) {
  59039. var globalTooltipModel = ecModel.getComponent('tooltip');
  59040. var triggerOn = globalAxisPointerModel.get('triggerOn')
  59041. || (globalTooltipModel && globalTooltipModel.get('triggerOn') || 'mousemove|click');
  59042. // Register global listener in AxisPointerView to enable
  59043. // AxisPointerView to be independent to Tooltip.
  59044. register(
  59045. 'axisPointer',
  59046. api,
  59047. function (currTrigger, e, dispatchAction) {
  59048. // If 'none', it is not controlled by mouse totally.
  59049. if (triggerOn !== 'none'
  59050. && (currTrigger === 'leave' || triggerOn.indexOf(currTrigger) >= 0)
  59051. ) {
  59052. dispatchAction({
  59053. type: 'updateAxisPointer',
  59054. currTrigger: currTrigger,
  59055. x: e && e.offsetX,
  59056. y: e && e.offsetY
  59057. });
  59058. }
  59059. }
  59060. );
  59061. },
  59062. /**
  59063. * @override
  59064. */
  59065. remove: function (ecModel, api) {
  59066. unregister(api.getZr(), 'axisPointer');
  59067. AxisPointerView.superApply(this._model, 'remove', arguments);
  59068. },
  59069. /**
  59070. * @override
  59071. */
  59072. dispose: function (ecModel, api) {
  59073. unregister('axisPointer', api);
  59074. AxisPointerView.superApply(this._model, 'dispose', arguments);
  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 inner$11 = makeInner();
  59096. var clone$4 = clone;
  59097. var bind$2 = bind;
  59098. /**
  59099. * Base axis pointer class in 2D.
  59100. * Implemenents {module:echarts/component/axis/IAxisPointer}.
  59101. */
  59102. function BaseAxisPointer() {
  59103. }
  59104. BaseAxisPointer.prototype = {
  59105. /**
  59106. * @private
  59107. */
  59108. _group: null,
  59109. /**
  59110. * @private
  59111. */
  59112. _lastGraphicKey: null,
  59113. /**
  59114. * @private
  59115. */
  59116. _handle: null,
  59117. /**
  59118. * @private
  59119. */
  59120. _dragging: false,
  59121. /**
  59122. * @private
  59123. */
  59124. _lastValue: null,
  59125. /**
  59126. * @private
  59127. */
  59128. _lastStatus: null,
  59129. /**
  59130. * @private
  59131. */
  59132. _payloadInfo: null,
  59133. /**
  59134. * In px, arbitrary value. Do not set too small,
  59135. * no animation is ok for most cases.
  59136. * @protected
  59137. */
  59138. animationThreshold: 15,
  59139. /**
  59140. * @implement
  59141. */
  59142. render: function (axisModel, axisPointerModel, api, forceRender) {
  59143. var value = axisPointerModel.get('value');
  59144. var status = axisPointerModel.get('status');
  59145. // Bind them to `this`, not in closure, otherwise they will not
  59146. // be replaced when user calling setOption in not merge mode.
  59147. this._axisModel = axisModel;
  59148. this._axisPointerModel = axisPointerModel;
  59149. this._api = api;
  59150. // Optimize: `render` will be called repeatly during mouse move.
  59151. // So it is power consuming if performing `render` each time,
  59152. // especially on mobile device.
  59153. if (!forceRender
  59154. && this._lastValue === value
  59155. && this._lastStatus === status
  59156. ) {
  59157. return;
  59158. }
  59159. this._lastValue = value;
  59160. this._lastStatus = status;
  59161. var group = this._group;
  59162. var handle = this._handle;
  59163. if (!status || status === 'hide') {
  59164. // Do not clear here, for animation better.
  59165. group && group.hide();
  59166. handle && handle.hide();
  59167. return;
  59168. }
  59169. group && group.show();
  59170. handle && handle.show();
  59171. // Otherwise status is 'show'
  59172. var elOption = {};
  59173. this.makeElOption(elOption, value, axisModel, axisPointerModel, api);
  59174. // Enable change axis pointer type.
  59175. var graphicKey = elOption.graphicKey;
  59176. if (graphicKey !== this._lastGraphicKey) {
  59177. this.clear(api);
  59178. }
  59179. this._lastGraphicKey = graphicKey;
  59180. var moveAnimation = this._moveAnimation
  59181. = this.determineAnimation(axisModel, axisPointerModel);
  59182. if (!group) {
  59183. group = this._group = new Group();
  59184. this.createPointerEl(group, elOption, axisModel, axisPointerModel);
  59185. this.createLabelEl(group, elOption, axisModel, axisPointerModel);
  59186. api.getZr().add(group);
  59187. }
  59188. else {
  59189. var doUpdateProps = curry(updateProps$1, axisPointerModel, moveAnimation);
  59190. this.updatePointerEl(group, elOption, doUpdateProps, axisPointerModel);
  59191. this.updateLabelEl(group, elOption, doUpdateProps, axisPointerModel);
  59192. }
  59193. updateMandatoryProps(group, axisPointerModel, true);
  59194. this._renderHandle(value);
  59195. },
  59196. /**
  59197. * @implement
  59198. */
  59199. remove: function (api) {
  59200. this.clear(api);
  59201. },
  59202. /**
  59203. * @implement
  59204. */
  59205. dispose: function (api) {
  59206. this.clear(api);
  59207. },
  59208. /**
  59209. * @protected
  59210. */
  59211. determineAnimation: function (axisModel, axisPointerModel) {
  59212. var animation = axisPointerModel.get('animation');
  59213. var axis = axisModel.axis;
  59214. var isCategoryAxis = axis.type === 'category';
  59215. var useSnap = axisPointerModel.get('snap');
  59216. // Value axis without snap always do not snap.
  59217. if (!useSnap && !isCategoryAxis) {
  59218. return false;
  59219. }
  59220. if (animation === 'auto' || animation == null) {
  59221. var animationThreshold = this.animationThreshold;
  59222. if (isCategoryAxis && axis.getBandWidth() > animationThreshold) {
  59223. return true;
  59224. }
  59225. // It is important to auto animation when snap used. Consider if there is
  59226. // a dataZoom, animation will be disabled when too many points exist, while
  59227. // it will be enabled for better visual effect when little points exist.
  59228. if (useSnap) {
  59229. var seriesDataCount = getAxisInfo(axisModel).seriesDataCount;
  59230. var axisExtent = axis.getExtent();
  59231. // Approximate band width
  59232. return Math.abs(axisExtent[0] - axisExtent[1]) / seriesDataCount > animationThreshold;
  59233. }
  59234. return false;
  59235. }
  59236. return animation === true;
  59237. },
  59238. /**
  59239. * add {pointer, label, graphicKey} to elOption
  59240. * @protected
  59241. */
  59242. makeElOption: function (elOption, value, axisModel, axisPointerModel, api) {
  59243. // Shoule be implemenented by sub-class.
  59244. },
  59245. /**
  59246. * @protected
  59247. */
  59248. createPointerEl: function (group, elOption, axisModel, axisPointerModel) {
  59249. var pointerOption = elOption.pointer;
  59250. if (pointerOption) {
  59251. var pointerEl = inner$11(group).pointerEl = new graphic[pointerOption.type](
  59252. clone$4(elOption.pointer)
  59253. );
  59254. group.add(pointerEl);
  59255. }
  59256. },
  59257. /**
  59258. * @protected
  59259. */
  59260. createLabelEl: function (group, elOption, axisModel, axisPointerModel) {
  59261. if (elOption.label) {
  59262. var labelEl = inner$11(group).labelEl = new Rect(
  59263. clone$4(elOption.label)
  59264. );
  59265. group.add(labelEl);
  59266. updateLabelShowHide(labelEl, axisPointerModel);
  59267. }
  59268. },
  59269. /**
  59270. * @protected
  59271. */
  59272. updatePointerEl: function (group, elOption, updateProps$$1) {
  59273. var pointerEl = inner$11(group).pointerEl;
  59274. if (pointerEl && elOption.pointer) {
  59275. pointerEl.setStyle(elOption.pointer.style);
  59276. updateProps$$1(pointerEl, {shape: elOption.pointer.shape});
  59277. }
  59278. },
  59279. /**
  59280. * @protected
  59281. */
  59282. updateLabelEl: function (group, elOption, updateProps$$1, axisPointerModel) {
  59283. var labelEl = inner$11(group).labelEl;
  59284. if (labelEl) {
  59285. labelEl.setStyle(elOption.label.style);
  59286. updateProps$$1(labelEl, {
  59287. // Consider text length change in vertical axis, animation should
  59288. // be used on shape, otherwise the effect will be weird.
  59289. shape: elOption.label.shape,
  59290. position: elOption.label.position
  59291. });
  59292. updateLabelShowHide(labelEl, axisPointerModel);
  59293. }
  59294. },
  59295. /**
  59296. * @private
  59297. */
  59298. _renderHandle: function (value) {
  59299. if (this._dragging || !this.updateHandleTransform) {
  59300. return;
  59301. }
  59302. var axisPointerModel = this._axisPointerModel;
  59303. var zr = this._api.getZr();
  59304. var handle = this._handle;
  59305. var handleModel = axisPointerModel.getModel('handle');
  59306. var status = axisPointerModel.get('status');
  59307. if (!handleModel.get('show') || !status || status === 'hide') {
  59308. handle && zr.remove(handle);
  59309. this._handle = null;
  59310. return;
  59311. }
  59312. var isInit;
  59313. if (!this._handle) {
  59314. isInit = true;
  59315. handle = this._handle = createIcon(
  59316. handleModel.get('icon'),
  59317. {
  59318. cursor: 'move',
  59319. draggable: true,
  59320. onmousemove: function (e) {
  59321. // Fot mobile devicem, prevent screen slider on the button.
  59322. stop(e.event);
  59323. },
  59324. onmousedown: bind$2(this._onHandleDragMove, this, 0, 0),
  59325. drift: bind$2(this._onHandleDragMove, this),
  59326. ondragend: bind$2(this._onHandleDragEnd, this)
  59327. }
  59328. );
  59329. zr.add(handle);
  59330. }
  59331. updateMandatoryProps(handle, axisPointerModel, false);
  59332. // update style
  59333. var includeStyles = [
  59334. 'color', 'borderColor', 'borderWidth', 'opacity',
  59335. 'shadowColor', 'shadowBlur', 'shadowOffsetX', 'shadowOffsetY'
  59336. ];
  59337. handle.setStyle(handleModel.getItemStyle(null, includeStyles));
  59338. // update position
  59339. var handleSize = handleModel.get('size');
  59340. if (!isArray(handleSize)) {
  59341. handleSize = [handleSize, handleSize];
  59342. }
  59343. handle.attr('scale', [handleSize[0] / 2, handleSize[1] / 2]);
  59344. createOrUpdate(
  59345. this,
  59346. '_doDispatchAxisPointer',
  59347. handleModel.get('throttle') || 0,
  59348. 'fixRate'
  59349. );
  59350. this._moveHandleToValue(value, isInit);
  59351. },
  59352. /**
  59353. * @private
  59354. */
  59355. _moveHandleToValue: function (value, isInit) {
  59356. updateProps$1(
  59357. this._axisPointerModel,
  59358. !isInit && this._moveAnimation,
  59359. this._handle,
  59360. getHandleTransProps(this.getHandleTransform(
  59361. value, this._axisModel, this._axisPointerModel
  59362. ))
  59363. );
  59364. },
  59365. /**
  59366. * @private
  59367. */
  59368. _onHandleDragMove: function (dx, dy) {
  59369. var handle = this._handle;
  59370. if (!handle) {
  59371. return;
  59372. }
  59373. this._dragging = true;
  59374. // Persistent for throttle.
  59375. var trans = this.updateHandleTransform(
  59376. getHandleTransProps(handle),
  59377. [dx, dy],
  59378. this._axisModel,
  59379. this._axisPointerModel
  59380. );
  59381. this._payloadInfo = trans;
  59382. handle.stopAnimation();
  59383. handle.attr(getHandleTransProps(trans));
  59384. inner$11(handle).lastProp = null;
  59385. this._doDispatchAxisPointer();
  59386. },
  59387. /**
  59388. * Throttled method.
  59389. * @private
  59390. */
  59391. _doDispatchAxisPointer: function () {
  59392. var handle = this._handle;
  59393. if (!handle) {
  59394. return;
  59395. }
  59396. var payloadInfo = this._payloadInfo;
  59397. var axisModel = this._axisModel;
  59398. this._api.dispatchAction({
  59399. type: 'updateAxisPointer',
  59400. x: payloadInfo.cursorPoint[0],
  59401. y: payloadInfo.cursorPoint[1],
  59402. tooltipOption: payloadInfo.tooltipOption,
  59403. axesInfo: [{
  59404. axisDim: axisModel.axis.dim,
  59405. axisIndex: axisModel.componentIndex
  59406. }]
  59407. });
  59408. },
  59409. /**
  59410. * @private
  59411. */
  59412. _onHandleDragEnd: function (moveAnimation) {
  59413. this._dragging = false;
  59414. var handle = this._handle;
  59415. if (!handle) {
  59416. return;
  59417. }
  59418. var value = this._axisPointerModel.get('value');
  59419. // Consider snap or categroy axis, handle may be not consistent with
  59420. // axisPointer. So move handle to align the exact value position when
  59421. // drag ended.
  59422. this._moveHandleToValue(value);
  59423. // For the effect: tooltip will be shown when finger holding on handle
  59424. // button, and will be hidden after finger left handle button.
  59425. this._api.dispatchAction({
  59426. type: 'hideTip'
  59427. });
  59428. },
  59429. /**
  59430. * Should be implemenented by sub-class if support `handle`.
  59431. * @protected
  59432. * @param {number} value
  59433. * @param {module:echarts/model/Model} axisModel
  59434. * @param {module:echarts/model/Model} axisPointerModel
  59435. * @return {Object} {position: [x, y], rotation: 0}
  59436. */
  59437. getHandleTransform: null,
  59438. /**
  59439. * * Should be implemenented by sub-class if support `handle`.
  59440. * @protected
  59441. * @param {Object} transform {position, rotation}
  59442. * @param {Array.<number>} delta [dx, dy]
  59443. * @param {module:echarts/model/Model} axisModel
  59444. * @param {module:echarts/model/Model} axisPointerModel
  59445. * @return {Object} {position: [x, y], rotation: 0, cursorPoint: [x, y]}
  59446. */
  59447. updateHandleTransform: null,
  59448. /**
  59449. * @private
  59450. */
  59451. clear: function (api) {
  59452. this._lastValue = null;
  59453. this._lastStatus = null;
  59454. var zr = api.getZr();
  59455. var group = this._group;
  59456. var handle = this._handle;
  59457. if (zr && group) {
  59458. this._lastGraphicKey = null;
  59459. group && zr.remove(group);
  59460. handle && zr.remove(handle);
  59461. this._group = null;
  59462. this._handle = null;
  59463. this._payloadInfo = null;
  59464. }
  59465. },
  59466. /**
  59467. * @protected
  59468. */
  59469. doClear: function () {
  59470. // Implemented by sub-class if necessary.
  59471. },
  59472. /**
  59473. * @protected
  59474. * @param {Array.<number>} xy
  59475. * @param {Array.<number>} wh
  59476. * @param {number} [xDimIndex=0] or 1
  59477. */
  59478. buildLabel: function (xy, wh, xDimIndex) {
  59479. xDimIndex = xDimIndex || 0;
  59480. return {
  59481. x: xy[xDimIndex],
  59482. y: xy[1 - xDimIndex],
  59483. width: wh[xDimIndex],
  59484. height: wh[1 - xDimIndex]
  59485. };
  59486. }
  59487. };
  59488. BaseAxisPointer.prototype.constructor = BaseAxisPointer;
  59489. function updateProps$1(animationModel, moveAnimation, el, props) {
  59490. // Animation optimize.
  59491. if (!propsEqual(inner$11(el).lastProp, props)) {
  59492. inner$11(el).lastProp = props;
  59493. moveAnimation
  59494. ? updateProps(el, props, animationModel)
  59495. : (el.stopAnimation(), el.attr(props));
  59496. }
  59497. }
  59498. function propsEqual(lastProps, newProps) {
  59499. if (isObject$1(lastProps) && isObject$1(newProps)) {
  59500. var equals = true;
  59501. each$1(newProps, function (item, key) {
  59502. equals = equals && propsEqual(lastProps[key], item);
  59503. });
  59504. return !!equals;
  59505. }
  59506. else {
  59507. return lastProps === newProps;
  59508. }
  59509. }
  59510. function updateLabelShowHide(labelEl, axisPointerModel) {
  59511. labelEl[axisPointerModel.get('label.show') ? 'show' : 'hide']();
  59512. }
  59513. function getHandleTransProps(trans) {
  59514. return {
  59515. position: trans.position.slice(),
  59516. rotation: trans.rotation || 0
  59517. };
  59518. }
  59519. function updateMandatoryProps(group, axisPointerModel, silent) {
  59520. var z = axisPointerModel.get('z');
  59521. var zlevel = axisPointerModel.get('zlevel');
  59522. group && group.traverse(function (el) {
  59523. if (el.type !== 'group') {
  59524. z != null && (el.z = z);
  59525. zlevel != null && (el.zlevel = zlevel);
  59526. el.silent = silent;
  59527. }
  59528. });
  59529. }
  59530. enableClassExtend(BaseAxisPointer);
  59531. /*
  59532. * Licensed to the Apache Software Foundation (ASF) under one
  59533. * or more contributor license agreements. See the NOTICE file
  59534. * distributed with this work for additional information
  59535. * regarding copyright ownership. The ASF licenses this file
  59536. * to you under the Apache License, Version 2.0 (the
  59537. * "License"); you may not use this file except in compliance
  59538. * with the License. You may obtain a copy of the License at
  59539. *
  59540. * http://www.apache.org/licenses/LICENSE-2.0
  59541. *
  59542. * Unless required by applicable law or agreed to in writing,
  59543. * software distributed under the License is distributed on an
  59544. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  59545. * KIND, either express or implied. See the License for the
  59546. * specific language governing permissions and limitations
  59547. * under the License.
  59548. */
  59549. /**
  59550. * @param {module:echarts/model/Model} axisPointerModel
  59551. */
  59552. function buildElStyle(axisPointerModel) {
  59553. var axisPointerType = axisPointerModel.get('type');
  59554. var styleModel = axisPointerModel.getModel(axisPointerType + 'Style');
  59555. var style;
  59556. if (axisPointerType === 'line') {
  59557. style = styleModel.getLineStyle();
  59558. style.fill = null;
  59559. }
  59560. else if (axisPointerType === 'shadow') {
  59561. style = styleModel.getAreaStyle();
  59562. style.stroke = null;
  59563. }
  59564. return style;
  59565. }
  59566. /**
  59567. * @param {Function} labelPos {align, verticalAlign, position}
  59568. */
  59569. function buildLabelElOption(
  59570. elOption, axisModel, axisPointerModel, api, labelPos
  59571. ) {
  59572. var value = axisPointerModel.get('value');
  59573. var text = getValueLabel(
  59574. value, axisModel.axis, axisModel.ecModel,
  59575. axisPointerModel.get('seriesDataIndices'),
  59576. {
  59577. precision: axisPointerModel.get('label.precision'),
  59578. formatter: axisPointerModel.get('label.formatter')
  59579. }
  59580. );
  59581. var labelModel = axisPointerModel.getModel('label');
  59582. var paddings = normalizeCssArray$1(labelModel.get('padding') || 0);
  59583. var font = labelModel.getFont();
  59584. var textRect = getBoundingRect(text, font);
  59585. var position = labelPos.position;
  59586. var width = textRect.width + paddings[1] + paddings[3];
  59587. var height = textRect.height + paddings[0] + paddings[2];
  59588. // Adjust by align.
  59589. var align = labelPos.align;
  59590. align === 'right' && (position[0] -= width);
  59591. align === 'center' && (position[0] -= width / 2);
  59592. var verticalAlign = labelPos.verticalAlign;
  59593. verticalAlign === 'bottom' && (position[1] -= height);
  59594. verticalAlign === 'middle' && (position[1] -= height / 2);
  59595. // Not overflow ec container
  59596. confineInContainer(position, width, height, api);
  59597. var bgColor = labelModel.get('backgroundColor');
  59598. if (!bgColor || bgColor === 'auto') {
  59599. bgColor = axisModel.get('axisLine.lineStyle.color');
  59600. }
  59601. elOption.label = {
  59602. shape: {x: 0, y: 0, width: width, height: height, r: labelModel.get('borderRadius')},
  59603. position: position.slice(),
  59604. // TODO: rich
  59605. style: {
  59606. text: text,
  59607. textFont: font,
  59608. textFill: labelModel.getTextColor(),
  59609. textPosition: 'inside',
  59610. textPadding: paddings,
  59611. fill: bgColor,
  59612. stroke: labelModel.get('borderColor') || 'transparent',
  59613. lineWidth: labelModel.get('borderWidth') || 0,
  59614. shadowBlur: labelModel.get('shadowBlur'),
  59615. shadowColor: labelModel.get('shadowColor'),
  59616. shadowOffsetX: labelModel.get('shadowOffsetX'),
  59617. shadowOffsetY: labelModel.get('shadowOffsetY')
  59618. },
  59619. // Lable should be over axisPointer.
  59620. z2: 10
  59621. };
  59622. }
  59623. // Do not overflow ec container
  59624. function confineInContainer(position, width, height, api) {
  59625. var viewWidth = api.getWidth();
  59626. var viewHeight = api.getHeight();
  59627. position[0] = Math.min(position[0] + width, viewWidth) - width;
  59628. position[1] = Math.min(position[1] + height, viewHeight) - height;
  59629. position[0] = Math.max(position[0], 0);
  59630. position[1] = Math.max(position[1], 0);
  59631. }
  59632. /**
  59633. * @param {number} value
  59634. * @param {module:echarts/coord/Axis} axis
  59635. * @param {module:echarts/model/Global} ecModel
  59636. * @param {Object} opt
  59637. * @param {Array.<Object>} seriesDataIndices
  59638. * @param {number|string} opt.precision 'auto' or a number
  59639. * @param {string|Function} opt.formatter label formatter
  59640. */
  59641. function getValueLabel(value, axis, ecModel, seriesDataIndices, opt) {
  59642. value = axis.scale.parse(value);
  59643. var text = axis.scale.getLabel(
  59644. // If `precision` is set, width can be fixed (like '12.00500'), which
  59645. // helps to debounce when when moving label.
  59646. value, {precision: opt.precision}
  59647. );
  59648. var formatter = opt.formatter;
  59649. if (formatter) {
  59650. var params = {
  59651. value: getAxisRawValue(axis, value),
  59652. axisDimension: axis.dim,
  59653. axisIndex: axis.index,
  59654. seriesData: []
  59655. };
  59656. each$1(seriesDataIndices, function (idxItem) {
  59657. var series = ecModel.getSeriesByIndex(idxItem.seriesIndex);
  59658. var dataIndex = idxItem.dataIndexInside;
  59659. var dataParams = series && series.getDataParams(dataIndex);
  59660. dataParams && params.seriesData.push(dataParams);
  59661. });
  59662. if (isString(formatter)) {
  59663. text = formatter.replace('{value}', text);
  59664. }
  59665. else if (isFunction$1(formatter)) {
  59666. text = formatter(params);
  59667. }
  59668. }
  59669. return text;
  59670. }
  59671. /**
  59672. * @param {module:echarts/coord/Axis} axis
  59673. * @param {number} value
  59674. * @param {Object} layoutInfo {
  59675. * rotation, position, labelOffset, labelDirection, labelMargin
  59676. * }
  59677. */
  59678. function getTransformedPosition(axis, value, layoutInfo) {
  59679. var transform = create$1();
  59680. rotate(transform, transform, layoutInfo.rotation);
  59681. translate(transform, transform, layoutInfo.position);
  59682. return applyTransform$1([
  59683. axis.dataToCoord(value),
  59684. (layoutInfo.labelOffset || 0)
  59685. + (layoutInfo.labelDirection || 1) * (layoutInfo.labelMargin || 0)
  59686. ], transform);
  59687. }
  59688. function buildCartesianSingleLabelElOption(
  59689. value, elOption, layoutInfo, axisModel, axisPointerModel, api
  59690. ) {
  59691. var textLayout = AxisBuilder.innerTextLayout(
  59692. layoutInfo.rotation, 0, layoutInfo.labelDirection
  59693. );
  59694. layoutInfo.labelMargin = axisPointerModel.get('label.margin');
  59695. buildLabelElOption(elOption, axisModel, axisPointerModel, api, {
  59696. position: getTransformedPosition(axisModel.axis, value, layoutInfo),
  59697. align: textLayout.textAlign,
  59698. verticalAlign: textLayout.textVerticalAlign
  59699. });
  59700. }
  59701. /**
  59702. * @param {Array.<number>} p1
  59703. * @param {Array.<number>} p2
  59704. * @param {number} [xDimIndex=0] or 1
  59705. */
  59706. function makeLineShape(p1, p2, xDimIndex) {
  59707. xDimIndex = xDimIndex || 0;
  59708. return {
  59709. x1: p1[xDimIndex],
  59710. y1: p1[1 - xDimIndex],
  59711. x2: p2[xDimIndex],
  59712. y2: p2[1 - xDimIndex]
  59713. };
  59714. }
  59715. /**
  59716. * @param {Array.<number>} xy
  59717. * @param {Array.<number>} wh
  59718. * @param {number} [xDimIndex=0] or 1
  59719. */
  59720. function makeRectShape(xy, wh, xDimIndex) {
  59721. xDimIndex = xDimIndex || 0;
  59722. return {
  59723. x: xy[xDimIndex],
  59724. y: xy[1 - xDimIndex],
  59725. width: wh[xDimIndex],
  59726. height: wh[1 - xDimIndex]
  59727. };
  59728. }
  59729. function makeSectorShape(cx, cy, r0, r, startAngle, endAngle) {
  59730. return {
  59731. cx: cx,
  59732. cy: cy,
  59733. r0: r0,
  59734. r: r,
  59735. startAngle: startAngle,
  59736. endAngle: endAngle,
  59737. clockwise: true
  59738. };
  59739. }
  59740. /*
  59741. * Licensed to the Apache Software Foundation (ASF) under one
  59742. * or more contributor license agreements. See the NOTICE file
  59743. * distributed with this work for additional information
  59744. * regarding copyright ownership. The ASF licenses this file
  59745. * to you under the Apache License, Version 2.0 (the
  59746. * "License"); you may not use this file except in compliance
  59747. * with the License. You may obtain a copy of the License at
  59748. *
  59749. * http://www.apache.org/licenses/LICENSE-2.0
  59750. *
  59751. * Unless required by applicable law or agreed to in writing,
  59752. * software distributed under the License is distributed on an
  59753. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  59754. * KIND, either express or implied. See the License for the
  59755. * specific language governing permissions and limitations
  59756. * under the License.
  59757. */
  59758. var CartesianAxisPointer = BaseAxisPointer.extend({
  59759. /**
  59760. * @override
  59761. */
  59762. makeElOption: function (elOption, value, axisModel, axisPointerModel, api) {
  59763. var axis = axisModel.axis;
  59764. var grid = axis.grid;
  59765. var axisPointerType = axisPointerModel.get('type');
  59766. var otherExtent = getCartesian(grid, axis).getOtherAxis(axis).getGlobalExtent();
  59767. var pixelValue = axis.toGlobalCoord(axis.dataToCoord(value, true));
  59768. if (axisPointerType && axisPointerType !== 'none') {
  59769. var elStyle = buildElStyle(axisPointerModel);
  59770. var pointerOption = pointerShapeBuilder[axisPointerType](
  59771. axis, pixelValue, otherExtent
  59772. );
  59773. pointerOption.style = elStyle;
  59774. elOption.graphicKey = pointerOption.type;
  59775. elOption.pointer = pointerOption;
  59776. }
  59777. var layoutInfo = layout$1(grid.model, axisModel);
  59778. buildCartesianSingleLabelElOption(
  59779. value, elOption, layoutInfo, axisModel, axisPointerModel, api
  59780. );
  59781. },
  59782. /**
  59783. * @override
  59784. */
  59785. getHandleTransform: function (value, axisModel, axisPointerModel) {
  59786. var layoutInfo = layout$1(axisModel.axis.grid.model, axisModel, {
  59787. labelInside: false
  59788. });
  59789. layoutInfo.labelMargin = axisPointerModel.get('handle.margin');
  59790. return {
  59791. position: getTransformedPosition(axisModel.axis, value, layoutInfo),
  59792. rotation: layoutInfo.rotation + (layoutInfo.labelDirection < 0 ? Math.PI : 0)
  59793. };
  59794. },
  59795. /**
  59796. * @override
  59797. */
  59798. updateHandleTransform: function (transform, delta, axisModel, axisPointerModel) {
  59799. var axis = axisModel.axis;
  59800. var grid = axis.grid;
  59801. var axisExtent = axis.getGlobalExtent(true);
  59802. var otherExtent = getCartesian(grid, axis).getOtherAxis(axis).getGlobalExtent();
  59803. var dimIndex = axis.dim === 'x' ? 0 : 1;
  59804. var currPosition = transform.position;
  59805. currPosition[dimIndex] += delta[dimIndex];
  59806. currPosition[dimIndex] = Math.min(axisExtent[1], currPosition[dimIndex]);
  59807. currPosition[dimIndex] = Math.max(axisExtent[0], currPosition[dimIndex]);
  59808. var cursorOtherValue = (otherExtent[1] + otherExtent[0]) / 2;
  59809. var cursorPoint = [cursorOtherValue, cursorOtherValue];
  59810. cursorPoint[dimIndex] = currPosition[dimIndex];
  59811. // Make tooltip do not overlap axisPointer and in the middle of the grid.
  59812. var tooltipOptions = [{verticalAlign: 'middle'}, {align: 'center'}];
  59813. return {
  59814. position: currPosition,
  59815. rotation: transform.rotation,
  59816. cursorPoint: cursorPoint,
  59817. tooltipOption: tooltipOptions[dimIndex]
  59818. };
  59819. }
  59820. });
  59821. function getCartesian(grid, axis) {
  59822. var opt = {};
  59823. opt[axis.dim + 'AxisIndex'] = axis.index;
  59824. return grid.getCartesian(opt);
  59825. }
  59826. var pointerShapeBuilder = {
  59827. line: function (axis, pixelValue, otherExtent) {
  59828. var targetShape = makeLineShape(
  59829. [pixelValue, otherExtent[0]],
  59830. [pixelValue, otherExtent[1]],
  59831. getAxisDimIndex(axis)
  59832. );
  59833. return {
  59834. type: 'Line',
  59835. subPixelOptimize: true,
  59836. shape: targetShape
  59837. };
  59838. },
  59839. shadow: function (axis, pixelValue, otherExtent) {
  59840. var bandWidth = Math.max(1, axis.getBandWidth());
  59841. var span = otherExtent[1] - otherExtent[0];
  59842. return {
  59843. type: 'Rect',
  59844. shape: makeRectShape(
  59845. [pixelValue - bandWidth / 2, otherExtent[0]],
  59846. [bandWidth, span],
  59847. getAxisDimIndex(axis)
  59848. )
  59849. };
  59850. }
  59851. };
  59852. function getAxisDimIndex(axis) {
  59853. return axis.dim === 'x' ? 0 : 1;
  59854. }
  59855. AxisView.registerAxisPointerClass('CartesianAxisPointer', CartesianAxisPointer);
  59856. /*
  59857. * Licensed to the Apache Software Foundation (ASF) under one
  59858. * or more contributor license agreements. See the NOTICE file
  59859. * distributed with this work for additional information
  59860. * regarding copyright ownership. The ASF licenses this file
  59861. * to you under the Apache License, Version 2.0 (the
  59862. * "License"); you may not use this file except in compliance
  59863. * with the License. You may obtain a copy of the License at
  59864. *
  59865. * http://www.apache.org/licenses/LICENSE-2.0
  59866. *
  59867. * Unless required by applicable law or agreed to in writing,
  59868. * software distributed under the License is distributed on an
  59869. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  59870. * KIND, either express or implied. See the License for the
  59871. * specific language governing permissions and limitations
  59872. * under the License.
  59873. */
  59874. // CartesianAxisPointer is not supposed to be required here. But consider
  59875. // echarts.simple.js and online build tooltip, which only require gridSimple,
  59876. // CartesianAxisPointer should be able to required somewhere.
  59877. registerPreprocessor(function (option) {
  59878. // Always has a global axisPointerModel for default setting.
  59879. if (option) {
  59880. (!option.axisPointer || option.axisPointer.length === 0)
  59881. && (option.axisPointer = {});
  59882. var link = option.axisPointer.link;
  59883. // Normalize to array to avoid object mergin. But if link
  59884. // is not set, remain null/undefined, otherwise it will
  59885. // override existent link setting.
  59886. if (link && !isArray(link)) {
  59887. option.axisPointer.link = [link];
  59888. }
  59889. }
  59890. });
  59891. // This process should proformed after coordinate systems created
  59892. // and series data processed. So put it on statistic processing stage.
  59893. registerProcessor(PRIORITY.PROCESSOR.STATISTIC, function (ecModel, api) {
  59894. // Build axisPointerModel, mergin tooltip.axisPointer model for each axis.
  59895. // allAxesInfo should be updated when setOption performed.
  59896. ecModel.getComponent('axisPointer').coordSysAxesInfo
  59897. = collect(ecModel, api);
  59898. });
  59899. // Broadcast to all views.
  59900. registerAction({
  59901. type: 'updateAxisPointer',
  59902. event: 'updateAxisPointer',
  59903. update: ':updateAxisPointer'
  59904. }, axisTrigger);
  59905. /*
  59906. * Licensed to the Apache Software Foundation (ASF) under one
  59907. * or more contributor license agreements. See the NOTICE file
  59908. * distributed with this work for additional information
  59909. * regarding copyright ownership. The ASF licenses this file
  59910. * to you under the Apache License, Version 2.0 (the
  59911. * "License"); you may not use this file except in compliance
  59912. * with the License. You may obtain a copy of the License at
  59913. *
  59914. * http://www.apache.org/licenses/LICENSE-2.0
  59915. *
  59916. * Unless required by applicable law or agreed to in writing,
  59917. * software distributed under the License is distributed on an
  59918. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  59919. * KIND, either express or implied. See the License for the
  59920. * specific language governing permissions and limitations
  59921. * under the License.
  59922. */
  59923. var XY = ['x', 'y'];
  59924. var WH = ['width', 'height'];
  59925. var SingleAxisPointer = BaseAxisPointer.extend({
  59926. /**
  59927. * @override
  59928. */
  59929. makeElOption: function (elOption, value, axisModel, axisPointerModel, api) {
  59930. var axis = axisModel.axis;
  59931. var coordSys = axis.coordinateSystem;
  59932. var otherExtent = getGlobalExtent(coordSys, 1 - getPointDimIndex(axis));
  59933. var pixelValue = coordSys.dataToPoint(value)[0];
  59934. var axisPointerType = axisPointerModel.get('type');
  59935. if (axisPointerType && axisPointerType !== 'none') {
  59936. var elStyle = buildElStyle(axisPointerModel);
  59937. var pointerOption = pointerShapeBuilder$1[axisPointerType](
  59938. axis, pixelValue, otherExtent
  59939. );
  59940. pointerOption.style = elStyle;
  59941. elOption.graphicKey = pointerOption.type;
  59942. elOption.pointer = pointerOption;
  59943. }
  59944. var layoutInfo = layout$2(axisModel);
  59945. buildCartesianSingleLabelElOption(
  59946. value, elOption, layoutInfo, axisModel, axisPointerModel, api
  59947. );
  59948. },
  59949. /**
  59950. * @override
  59951. */
  59952. getHandleTransform: function (value, axisModel, axisPointerModel) {
  59953. var layoutInfo = layout$2(axisModel, {labelInside: false});
  59954. layoutInfo.labelMargin = axisPointerModel.get('handle.margin');
  59955. return {
  59956. position: getTransformedPosition(axisModel.axis, value, layoutInfo),
  59957. rotation: layoutInfo.rotation + (layoutInfo.labelDirection < 0 ? Math.PI : 0)
  59958. };
  59959. },
  59960. /**
  59961. * @override
  59962. */
  59963. updateHandleTransform: function (transform, delta, axisModel, axisPointerModel) {
  59964. var axis = axisModel.axis;
  59965. var coordSys = axis.coordinateSystem;
  59966. var dimIndex = getPointDimIndex(axis);
  59967. var axisExtent = getGlobalExtent(coordSys, dimIndex);
  59968. var currPosition = transform.position;
  59969. currPosition[dimIndex] += delta[dimIndex];
  59970. currPosition[dimIndex] = Math.min(axisExtent[1], currPosition[dimIndex]);
  59971. currPosition[dimIndex] = Math.max(axisExtent[0], currPosition[dimIndex]);
  59972. var otherExtent = getGlobalExtent(coordSys, 1 - dimIndex);
  59973. var cursorOtherValue = (otherExtent[1] + otherExtent[0]) / 2;
  59974. var cursorPoint = [cursorOtherValue, cursorOtherValue];
  59975. cursorPoint[dimIndex] = currPosition[dimIndex];
  59976. return {
  59977. position: currPosition,
  59978. rotation: transform.rotation,
  59979. cursorPoint: cursorPoint,
  59980. tooltipOption: {
  59981. verticalAlign: 'middle'
  59982. }
  59983. };
  59984. }
  59985. });
  59986. var pointerShapeBuilder$1 = {
  59987. line: function (axis, pixelValue, otherExtent) {
  59988. var targetShape = makeLineShape(
  59989. [pixelValue, otherExtent[0]],
  59990. [pixelValue, otherExtent[1]],
  59991. getPointDimIndex(axis)
  59992. );
  59993. return {
  59994. type: 'Line',
  59995. subPixelOptimize: true,
  59996. shape: targetShape
  59997. };
  59998. },
  59999. shadow: function (axis, pixelValue, otherExtent) {
  60000. var bandWidth = axis.getBandWidth();
  60001. var span = otherExtent[1] - otherExtent[0];
  60002. return {
  60003. type: 'Rect',
  60004. shape: makeRectShape(
  60005. [pixelValue - bandWidth / 2, otherExtent[0]],
  60006. [bandWidth, span],
  60007. getPointDimIndex(axis)
  60008. )
  60009. };
  60010. }
  60011. };
  60012. function getPointDimIndex(axis) {
  60013. return axis.isHorizontal() ? 0 : 1;
  60014. }
  60015. function getGlobalExtent(coordSys, dimIndex) {
  60016. var rect = coordSys.getRect();
  60017. return [rect[XY[dimIndex]], rect[XY[dimIndex]] + rect[WH[dimIndex]]];
  60018. }
  60019. AxisView.registerAxisPointerClass('SingleAxisPointer', SingleAxisPointer);
  60020. /*
  60021. * Licensed to the Apache Software Foundation (ASF) under one
  60022. * or more contributor license agreements. See the NOTICE file
  60023. * distributed with this work for additional information
  60024. * regarding copyright ownership. The ASF licenses this file
  60025. * to you under the Apache License, Version 2.0 (the
  60026. * "License"); you may not use this file except in compliance
  60027. * with the License. You may obtain a copy of the License at
  60028. *
  60029. * http://www.apache.org/licenses/LICENSE-2.0
  60030. *
  60031. * Unless required by applicable law or agreed to in writing,
  60032. * software distributed under the License is distributed on an
  60033. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  60034. * KIND, either express or implied. See the License for the
  60035. * specific language governing permissions and limitations
  60036. * under the License.
  60037. */
  60038. extendComponentView({
  60039. type: 'single'
  60040. });
  60041. /*
  60042. * Licensed to the Apache Software Foundation (ASF) under one
  60043. * or more contributor license agreements. See the NOTICE file
  60044. * distributed with this work for additional information
  60045. * regarding copyright ownership. The ASF licenses this file
  60046. * to you under the Apache License, Version 2.0 (the
  60047. * "License"); you may not use this file except in compliance
  60048. * with the License. You may obtain a copy of the License at
  60049. *
  60050. * http://www.apache.org/licenses/LICENSE-2.0
  60051. *
  60052. * Unless required by applicable law or agreed to in writing,
  60053. * software distributed under the License is distributed on an
  60054. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  60055. * KIND, either express or implied. See the License for the
  60056. * specific language governing permissions and limitations
  60057. * under the License.
  60058. */
  60059. var DATA_NAME_INDEX = 2;
  60060. var ThemeRiverSeries = SeriesModel.extend({
  60061. type: 'series.themeRiver',
  60062. dependencies: ['singleAxis'],
  60063. /**
  60064. * @readOnly
  60065. * @type {module:zrender/core/util#HashMap}
  60066. */
  60067. nameMap: null,
  60068. /**
  60069. * @override
  60070. */
  60071. init: function (option) {
  60072. // eslint-disable-next-line
  60073. ThemeRiverSeries.superApply(this, 'init', arguments);
  60074. // Put this function here is for the sake of consistency of code style.
  60075. // Enable legend selection for each data item
  60076. // Use a function instead of direct access because data reference may changed
  60077. this.legendDataProvider = function () {
  60078. return this.getRawData();
  60079. };
  60080. },
  60081. /**
  60082. * If there is no value of a certain point in the time for some event,set it value to 0.
  60083. *
  60084. * @param {Array} data initial data in the option
  60085. * @return {Array}
  60086. */
  60087. fixData: function (data) {
  60088. var rawDataLength = data.length;
  60089. // grouped data by name
  60090. var groupResult = groupData(data, function (item) {
  60091. return item[2];
  60092. });
  60093. var layData = [];
  60094. groupResult.buckets.each(function (items, key) {
  60095. layData.push({name: key, dataList: items});
  60096. });
  60097. var layerNum = layData.length;
  60098. var largestLayer = -1;
  60099. var index = -1;
  60100. for (var i = 0; i < layerNum; ++i) {
  60101. var len = layData[i].dataList.length;
  60102. if (len > largestLayer) {
  60103. largestLayer = len;
  60104. index = i;
  60105. }
  60106. }
  60107. for (var k = 0; k < layerNum; ++k) {
  60108. if (k === index) {
  60109. continue;
  60110. }
  60111. var name = layData[k].name;
  60112. for (var j = 0; j < largestLayer; ++j) {
  60113. var timeValue = layData[index].dataList[j][0];
  60114. var length = layData[k].dataList.length;
  60115. var keyIndex = -1;
  60116. for (var l = 0; l < length; ++l) {
  60117. var value = layData[k].dataList[l][0];
  60118. if (value === timeValue) {
  60119. keyIndex = l;
  60120. break;
  60121. }
  60122. }
  60123. if (keyIndex === -1) {
  60124. data[rawDataLength] = [];
  60125. data[rawDataLength][0] = timeValue;
  60126. data[rawDataLength][1] = 0;
  60127. data[rawDataLength][2] = name;
  60128. rawDataLength++;
  60129. }
  60130. }
  60131. }
  60132. return data;
  60133. },
  60134. /**
  60135. * @override
  60136. * @param {Object} option the initial option that user gived
  60137. * @param {module:echarts/model/Model} ecModel the model object for themeRiver option
  60138. * @return {module:echarts/data/List}
  60139. */
  60140. getInitialData: function (option, ecModel) {
  60141. var singleAxisModel = ecModel.queryComponents({
  60142. mainType: 'singleAxis',
  60143. index: this.get('singleAxisIndex'),
  60144. id: this.get('singleAxisId')
  60145. })[0];
  60146. var axisType = singleAxisModel.get('type');
  60147. // filter the data item with the value of label is undefined
  60148. var filterData = filter(option.data, function (dataItem) {
  60149. return dataItem[2] !== undefined;
  60150. });
  60151. // ??? TODO design a stage to transfer data for themeRiver and lines?
  60152. var data = this.fixData(filterData || []);
  60153. var nameList = [];
  60154. var nameMap = this.nameMap = createHashMap();
  60155. var count = 0;
  60156. for (var i = 0; i < data.length; ++i) {
  60157. nameList.push(data[i][DATA_NAME_INDEX]);
  60158. if (!nameMap.get(data[i][DATA_NAME_INDEX])) {
  60159. nameMap.set(data[i][DATA_NAME_INDEX], count);
  60160. count++;
  60161. }
  60162. }
  60163. var dimensionsInfo = createDimensions(data, {
  60164. coordDimensions: ['single'],
  60165. dimensionsDefine: [
  60166. {
  60167. name: 'time',
  60168. type: getDimensionTypeByAxis(axisType)
  60169. },
  60170. {
  60171. name: 'value',
  60172. type: 'float'
  60173. },
  60174. {
  60175. name: 'name',
  60176. type: 'ordinal'
  60177. }
  60178. ],
  60179. encodeDefine: {
  60180. single: 0,
  60181. value: 1,
  60182. itemName: 2
  60183. }
  60184. });
  60185. var list = new List(dimensionsInfo, this);
  60186. list.initData(data);
  60187. return list;
  60188. },
  60189. /**
  60190. * The raw data is divided into multiple layers and each layer
  60191. * has same name.
  60192. *
  60193. * @return {Array.<Array.<number>>}
  60194. */
  60195. getLayerSeries: function () {
  60196. var data = this.getData();
  60197. var lenCount = data.count();
  60198. var indexArr = [];
  60199. for (var i = 0; i < lenCount; ++i) {
  60200. indexArr[i] = i;
  60201. }
  60202. var timeDim = data.mapDimension('single');
  60203. // data group by name
  60204. var groupResult = groupData(indexArr, function (index) {
  60205. return data.get('name', index);
  60206. });
  60207. var layerSeries = [];
  60208. groupResult.buckets.each(function (items, key) {
  60209. items.sort(function (index1, index2) {
  60210. return data.get(timeDim, index1) - data.get(timeDim, index2);
  60211. });
  60212. layerSeries.push({name: key, indices: items});
  60213. });
  60214. return layerSeries;
  60215. },
  60216. /**
  60217. * Get data indices for show tooltip content
  60218. * @param {Array.<string>|string} dim single coordinate dimension
  60219. * @param {number} value axis value
  60220. * @param {module:echarts/coord/single/SingleAxis} baseAxis single Axis used
  60221. * the themeRiver.
  60222. * @return {Object} {dataIndices, nestestValue}
  60223. */
  60224. getAxisTooltipData: function (dim, value, baseAxis) {
  60225. if (!isArray(dim)) {
  60226. dim = dim ? [dim] : [];
  60227. }
  60228. var data = this.getData();
  60229. var layerSeries = this.getLayerSeries();
  60230. var indices = [];
  60231. var layerNum = layerSeries.length;
  60232. var nestestValue;
  60233. for (var i = 0; i < layerNum; ++i) {
  60234. var minDist = Number.MAX_VALUE;
  60235. var nearestIdx = -1;
  60236. var pointNum = layerSeries[i].indices.length;
  60237. for (var j = 0; j < pointNum; ++j) {
  60238. var theValue = data.get(dim[0], layerSeries[i].indices[j]);
  60239. var dist = Math.abs(theValue - value);
  60240. if (dist <= minDist) {
  60241. nestestValue = theValue;
  60242. minDist = dist;
  60243. nearestIdx = layerSeries[i].indices[j];
  60244. }
  60245. }
  60246. indices.push(nearestIdx);
  60247. }
  60248. return {dataIndices: indices, nestestValue: nestestValue};
  60249. },
  60250. /**
  60251. * @override
  60252. * @param {number} dataIndex index of data
  60253. */
  60254. formatTooltip: function (dataIndex) {
  60255. var data = this.getData();
  60256. var htmlName = data.getName(dataIndex);
  60257. var htmlValue = data.get(data.mapDimension('value'), dataIndex);
  60258. if (isNaN(htmlValue) || htmlValue == null) {
  60259. htmlValue = '-';
  60260. }
  60261. return encodeHTML(htmlName + ' : ' + htmlValue);
  60262. },
  60263. defaultOption: {
  60264. zlevel: 0,
  60265. z: 2,
  60266. coordinateSystem: 'singleAxis',
  60267. // gap in axis's orthogonal orientation
  60268. boundaryGap: ['10%', '10%'],
  60269. // legendHoverLink: true,
  60270. singleAxisIndex: 0,
  60271. animationEasing: 'linear',
  60272. label: {
  60273. margin: 4,
  60274. show: true,
  60275. position: 'left',
  60276. color: '#000',
  60277. fontSize: 11
  60278. },
  60279. emphasis: {
  60280. label: {
  60281. show: true
  60282. }
  60283. }
  60284. }
  60285. });
  60286. /*
  60287. * Licensed to the Apache Software Foundation (ASF) under one
  60288. * or more contributor license agreements. See the NOTICE file
  60289. * distributed with this work for additional information
  60290. * regarding copyright ownership. The ASF licenses this file
  60291. * to you under the Apache License, Version 2.0 (the
  60292. * "License"); you may not use this file except in compliance
  60293. * with the License. You may obtain a copy of the License at
  60294. *
  60295. * http://www.apache.org/licenses/LICENSE-2.0
  60296. *
  60297. * Unless required by applicable law or agreed to in writing,
  60298. * software distributed under the License is distributed on an
  60299. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  60300. * KIND, either express or implied. See the License for the
  60301. * specific language governing permissions and limitations
  60302. * under the License.
  60303. */
  60304. extendChartView({
  60305. type: 'themeRiver',
  60306. init: function () {
  60307. this._layers = [];
  60308. },
  60309. render: function (seriesModel, ecModel, api) {
  60310. var data = seriesModel.getData();
  60311. var group = this.group;
  60312. var layerSeries = seriesModel.getLayerSeries();
  60313. var layoutInfo = data.getLayout('layoutInfo');
  60314. var rect = layoutInfo.rect;
  60315. var boundaryGap = layoutInfo.boundaryGap;
  60316. group.attr('position', [0, rect.y + boundaryGap[0]]);
  60317. function keyGetter(item) {
  60318. return item.name;
  60319. }
  60320. var dataDiffer = new DataDiffer(
  60321. this._layersSeries || [], layerSeries,
  60322. keyGetter, keyGetter
  60323. );
  60324. var newLayersGroups = {};
  60325. dataDiffer
  60326. .add(bind(process, this, 'add'))
  60327. .update(bind(process, this, 'update'))
  60328. .remove(bind(process, this, 'remove'))
  60329. .execute();
  60330. function process(status, idx, oldIdx) {
  60331. var oldLayersGroups = this._layers;
  60332. if (status === 'remove') {
  60333. group.remove(oldLayersGroups[idx]);
  60334. return;
  60335. }
  60336. var points0 = [];
  60337. var points1 = [];
  60338. var color;
  60339. var indices = layerSeries[idx].indices;
  60340. for (var j = 0; j < indices.length; j++) {
  60341. var layout = data.getItemLayout(indices[j]);
  60342. var x = layout.x;
  60343. var y0 = layout.y0;
  60344. var y = layout.y;
  60345. points0.push([x, y0]);
  60346. points1.push([x, y0 + y]);
  60347. color = data.getItemVisual(indices[j], 'color');
  60348. }
  60349. var polygon;
  60350. var text;
  60351. var textLayout = data.getItemLayout(indices[0]);
  60352. var itemModel = data.getItemModel(indices[j - 1]);
  60353. var labelModel = itemModel.getModel('label');
  60354. var margin = labelModel.get('margin');
  60355. if (status === 'add') {
  60356. var layerGroup = newLayersGroups[idx] = new Group();
  60357. polygon = new Polygon$1({
  60358. shape: {
  60359. points: points0,
  60360. stackedOnPoints: points1,
  60361. smooth: 0.4,
  60362. stackedOnSmooth: 0.4,
  60363. smoothConstraint: false
  60364. },
  60365. z2: 0
  60366. });
  60367. text = new Text({
  60368. style: {
  60369. x: textLayout.x - margin,
  60370. y: textLayout.y0 + textLayout.y / 2
  60371. }
  60372. });
  60373. layerGroup.add(polygon);
  60374. layerGroup.add(text);
  60375. group.add(layerGroup);
  60376. polygon.setClipPath(createGridClipShape$3(polygon.getBoundingRect(), seriesModel, function () {
  60377. polygon.removeClipPath();
  60378. }));
  60379. }
  60380. else {
  60381. var layerGroup = oldLayersGroups[oldIdx];
  60382. polygon = layerGroup.childAt(0);
  60383. text = layerGroup.childAt(1);
  60384. group.add(layerGroup);
  60385. newLayersGroups[idx] = layerGroup;
  60386. updateProps(polygon, {
  60387. shape: {
  60388. points: points0,
  60389. stackedOnPoints: points1
  60390. }
  60391. }, seriesModel);
  60392. updateProps(text, {
  60393. style: {
  60394. x: textLayout.x - margin,
  60395. y: textLayout.y0 + textLayout.y / 2
  60396. }
  60397. }, seriesModel);
  60398. }
  60399. var hoverItemStyleModel = itemModel.getModel('emphasis.itemStyle');
  60400. var itemStyleModel = itemModel.getModel('itemStyle');
  60401. setTextStyle(text.style, labelModel, {
  60402. text: labelModel.get('show')
  60403. ? seriesModel.getFormattedLabel(indices[j - 1], 'normal')
  60404. || data.getName(indices[j - 1])
  60405. : null,
  60406. textVerticalAlign: 'middle'
  60407. });
  60408. polygon.setStyle(extend({
  60409. fill: color
  60410. }, itemStyleModel.getItemStyle(['color'])));
  60411. setHoverStyle(polygon, hoverItemStyleModel.getItemStyle());
  60412. }
  60413. this._layersSeries = layerSeries;
  60414. this._layers = newLayersGroups;
  60415. },
  60416. dispose: function () {}
  60417. });
  60418. // add animation to the view
  60419. function createGridClipShape$3(rect, seriesModel, cb) {
  60420. var rectEl = new Rect({
  60421. shape: {
  60422. x: rect.x - 10,
  60423. y: rect.y - 10,
  60424. width: 0,
  60425. height: rect.height + 20
  60426. }
  60427. });
  60428. initProps(rectEl, {
  60429. shape: {
  60430. width: rect.width + 20,
  60431. height: rect.height + 20
  60432. }
  60433. }, seriesModel, cb);
  60434. return rectEl;
  60435. }
  60436. /*
  60437. * Licensed to the Apache Software Foundation (ASF) under one
  60438. * or more contributor license agreements. See the NOTICE file
  60439. * distributed with this work for additional information
  60440. * regarding copyright ownership. The ASF licenses this file
  60441. * to you under the Apache License, Version 2.0 (the
  60442. * "License"); you may not use this file except in compliance
  60443. * with the License. You may obtain a copy of the License at
  60444. *
  60445. * http://www.apache.org/licenses/LICENSE-2.0
  60446. *
  60447. * Unless required by applicable law or agreed to in writing,
  60448. * software distributed under the License is distributed on an
  60449. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  60450. * KIND, either express or implied. See the License for the
  60451. * specific language governing permissions and limitations
  60452. * under the License.
  60453. */
  60454. var themeRiverLayout = function (ecModel, api) {
  60455. ecModel.eachSeriesByType('themeRiver', function (seriesModel) {
  60456. var data = seriesModel.getData();
  60457. var single = seriesModel.coordinateSystem;
  60458. var layoutInfo = {};
  60459. // use the axis boundingRect for view
  60460. var rect = single.getRect();
  60461. layoutInfo.rect = rect;
  60462. var boundaryGap = seriesModel.get('boundaryGap');
  60463. var axis = single.getAxis();
  60464. layoutInfo.boundaryGap = boundaryGap;
  60465. if (axis.orient === 'horizontal') {
  60466. boundaryGap[0] = parsePercent$1(boundaryGap[0], rect.height);
  60467. boundaryGap[1] = parsePercent$1(boundaryGap[1], rect.height);
  60468. var height = rect.height - boundaryGap[0] - boundaryGap[1];
  60469. themeRiverLayout$1(data, seriesModel, height);
  60470. }
  60471. else {
  60472. boundaryGap[0] = parsePercent$1(boundaryGap[0], rect.width);
  60473. boundaryGap[1] = parsePercent$1(boundaryGap[1], rect.width);
  60474. var width = rect.width - boundaryGap[0] - boundaryGap[1];
  60475. themeRiverLayout$1(data, seriesModel, width);
  60476. }
  60477. data.setLayout('layoutInfo', layoutInfo);
  60478. });
  60479. };
  60480. /**
  60481. * The layout information about themeriver
  60482. *
  60483. * @param {module:echarts/data/List} data data in the series
  60484. * @param {module:echarts/model/Series} seriesModel the model object of themeRiver series
  60485. * @param {number} height value used to compute every series height
  60486. */
  60487. function themeRiverLayout$1(data, seriesModel, height) {
  60488. if (!data.count()) {
  60489. return;
  60490. }
  60491. var coordSys = seriesModel.coordinateSystem;
  60492. // the data in each layer are organized into a series.
  60493. var layerSeries = seriesModel.getLayerSeries();
  60494. // the points in each layer.
  60495. var timeDim = data.mapDimension('single');
  60496. var valueDim = data.mapDimension('value');
  60497. var layerPoints = map(layerSeries, function (singleLayer) {
  60498. return map(singleLayer.indices, function (idx) {
  60499. var pt = coordSys.dataToPoint(data.get(timeDim, idx));
  60500. pt[1] = data.get(valueDim, idx);
  60501. return pt;
  60502. });
  60503. });
  60504. var base = computeBaseline(layerPoints);
  60505. var baseLine = base.y0;
  60506. var ky = height / base.max;
  60507. // set layout information for each item.
  60508. var n = layerSeries.length;
  60509. var m = layerSeries[0].indices.length;
  60510. var baseY0;
  60511. for (var j = 0; j < m; ++j) {
  60512. baseY0 = baseLine[j] * ky;
  60513. data.setItemLayout(layerSeries[0].indices[j], {
  60514. layerIndex: 0,
  60515. x: layerPoints[0][j][0],
  60516. y0: baseY0,
  60517. y: layerPoints[0][j][1] * ky
  60518. });
  60519. for (var i = 1; i < n; ++i) {
  60520. baseY0 += layerPoints[i - 1][j][1] * ky;
  60521. data.setItemLayout(layerSeries[i].indices[j], {
  60522. layerIndex: i,
  60523. x: layerPoints[i][j][0],
  60524. y0: baseY0,
  60525. y: layerPoints[i][j][1] * ky
  60526. });
  60527. }
  60528. }
  60529. }
  60530. /**
  60531. * Compute the baseLine of the rawdata
  60532. * Inspired by Lee Byron's paper Stacked Graphs - Geometry & Aesthetics
  60533. *
  60534. * @param {Array.<Array>} data the points in each layer
  60535. * @return {Object}
  60536. */
  60537. function computeBaseline(data) {
  60538. var layerNum = data.length;
  60539. var pointNum = data[0].length;
  60540. var sums = [];
  60541. var y0 = [];
  60542. var max = 0;
  60543. var temp;
  60544. var base = {};
  60545. for (var i = 0; i < pointNum; ++i) {
  60546. for (var j = 0, temp = 0; j < layerNum; ++j) {
  60547. temp += data[j][i][1];
  60548. }
  60549. if (temp > max) {
  60550. max = temp;
  60551. }
  60552. sums.push(temp);
  60553. }
  60554. for (var k = 0; k < pointNum; ++k) {
  60555. y0[k] = (max - sums[k]) / 2;
  60556. }
  60557. max = 0;
  60558. for (var l = 0; l < pointNum; ++l) {
  60559. var sum = sums[l] + y0[l];
  60560. if (sum > max) {
  60561. max = sum;
  60562. }
  60563. }
  60564. base.y0 = y0;
  60565. base.max = max;
  60566. return base;
  60567. }
  60568. /*
  60569. * Licensed to the Apache Software Foundation (ASF) under one
  60570. * or more contributor license agreements. See the NOTICE file
  60571. * distributed with this work for additional information
  60572. * regarding copyright ownership. The ASF licenses this file
  60573. * to you under the Apache License, Version 2.0 (the
  60574. * "License"); you may not use this file except in compliance
  60575. * with the License. You may obtain a copy of the License at
  60576. *
  60577. * http://www.apache.org/licenses/LICENSE-2.0
  60578. *
  60579. * Unless required by applicable law or agreed to in writing,
  60580. * software distributed under the License is distributed on an
  60581. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  60582. * KIND, either express or implied. See the License for the
  60583. * specific language governing permissions and limitations
  60584. * under the License.
  60585. */
  60586. var themeRiverVisual = function (ecModel) {
  60587. ecModel.eachSeriesByType('themeRiver', function (seriesModel) {
  60588. var data = seriesModel.getData();
  60589. var rawData = seriesModel.getRawData();
  60590. var colorList = seriesModel.get('color');
  60591. var idxMap = createHashMap();
  60592. data.each(function (idx) {
  60593. idxMap.set(data.getRawIndex(idx), idx);
  60594. });
  60595. rawData.each(function (rawIndex) {
  60596. var name = rawData.getName(rawIndex);
  60597. var color = colorList[(seriesModel.nameMap.get(name) - 1) % colorList.length];
  60598. rawData.setItemVisual(rawIndex, 'color', color);
  60599. var idx = idxMap.get(rawIndex);
  60600. if (idx != null) {
  60601. data.setItemVisual(idx, 'color', color);
  60602. }
  60603. });
  60604. });
  60605. };
  60606. /*
  60607. * Licensed to the Apache Software Foundation (ASF) under one
  60608. * or more contributor license agreements. See the NOTICE file
  60609. * distributed with this work for additional information
  60610. * regarding copyright ownership. The ASF licenses this file
  60611. * to you under the Apache License, Version 2.0 (the
  60612. * "License"); you may not use this file except in compliance
  60613. * with the License. You may obtain a copy of the License at
  60614. *
  60615. * http://www.apache.org/licenses/LICENSE-2.0
  60616. *
  60617. * Unless required by applicable law or agreed to in writing,
  60618. * software distributed under the License is distributed on an
  60619. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  60620. * KIND, either express or implied. See the License for the
  60621. * specific language governing permissions and limitations
  60622. * under the License.
  60623. */
  60624. registerLayout(themeRiverLayout);
  60625. registerVisual(themeRiverVisual);
  60626. registerProcessor(dataFilter('themeRiver'));
  60627. /*
  60628. * Licensed to the Apache Software Foundation (ASF) under one
  60629. * or more contributor license agreements. See the NOTICE file
  60630. * distributed with this work for additional information
  60631. * regarding copyright ownership. The ASF licenses this file
  60632. * to you under the Apache License, Version 2.0 (the
  60633. * "License"); you may not use this file except in compliance
  60634. * with the License. You may obtain a copy of the License at
  60635. *
  60636. * http://www.apache.org/licenses/LICENSE-2.0
  60637. *
  60638. * Unless required by applicable law or agreed to in writing,
  60639. * software distributed under the License is distributed on an
  60640. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  60641. * KIND, either express or implied. See the License for the
  60642. * specific language governing permissions and limitations
  60643. * under the License.
  60644. */
  60645. SeriesModel.extend({
  60646. type: 'series.sunburst',
  60647. /**
  60648. * @type {module:echarts/data/Tree~Node}
  60649. */
  60650. _viewRoot: null,
  60651. getInitialData: function (option, ecModel) {
  60652. // Create a virtual root.
  60653. var root = { name: option.name, children: option.data };
  60654. completeTreeValue$1(root);
  60655. var levels = option.levels || [];
  60656. // levels = option.levels = setDefault(levels, ecModel);
  60657. var treeOption = {};
  60658. treeOption.levels = levels;
  60659. // Make sure always a new tree is created when setOption,
  60660. // in TreemapView, we check whether oldTree === newTree
  60661. // to choose mappings approach among old shapes and new shapes.
  60662. return Tree.createTree(root, this, treeOption).data;
  60663. },
  60664. optionUpdated: function () {
  60665. this.resetViewRoot();
  60666. },
  60667. /*
  60668. * @override
  60669. */
  60670. getDataParams: function (dataIndex) {
  60671. var params = SeriesModel.prototype.getDataParams.apply(this, arguments);
  60672. var node = this.getData().tree.getNodeByDataIndex(dataIndex);
  60673. params.treePathInfo = wrapTreePathInfo(node, this);
  60674. return params;
  60675. },
  60676. defaultOption: {
  60677. zlevel: 0,
  60678. z: 2,
  60679. // 默认全局居中
  60680. center: ['50%', '50%'],
  60681. radius: [0, '75%'],
  60682. // 默认顺时针
  60683. clockwise: true,
  60684. startAngle: 90,
  60685. // 最小角度改为0
  60686. minAngle: 0,
  60687. percentPrecision: 2,
  60688. // If still show when all data zero.
  60689. stillShowZeroSum: true,
  60690. // Policy of highlighting pieces when hover on one
  60691. // Valid values: 'none' (for not downplay others), 'descendant',
  60692. // 'ancestor', 'self'
  60693. highlightPolicy: 'descendant',
  60694. // 'rootToNode', 'link', or false
  60695. nodeClick: 'rootToNode',
  60696. renderLabelForZeroData: false,
  60697. label: {
  60698. // could be: 'radial', 'tangential', or 'none'
  60699. rotate: 'radial',
  60700. show: true,
  60701. opacity: 1,
  60702. // 'left' is for inner side of inside, and 'right' is for outter
  60703. // side for inside
  60704. align: 'center',
  60705. position: 'inside',
  60706. distance: 5,
  60707. silent: true,
  60708. emphasis: {}
  60709. },
  60710. itemStyle: {
  60711. borderWidth: 1,
  60712. borderColor: 'white',
  60713. borderType: 'solid',
  60714. shadowBlur: 0,
  60715. shadowColor: 'rgba(0, 0, 0, 0.2)',
  60716. shadowOffsetX: 0,
  60717. shadowOffsetY: 0,
  60718. opacity: 1,
  60719. emphasis: {},
  60720. highlight: {
  60721. opacity: 1
  60722. },
  60723. downplay: {
  60724. opacity: 0.9
  60725. }
  60726. },
  60727. // Animation type canbe expansion, scale
  60728. animationType: 'expansion',
  60729. animationDuration: 1000,
  60730. animationDurationUpdate: 500,
  60731. animationEasing: 'cubicOut',
  60732. data: [],
  60733. levels: [],
  60734. /**
  60735. * Sort order.
  60736. *
  60737. * Valid values: 'desc', 'asc', null, or callback function.
  60738. * 'desc' and 'asc' for descend and ascendant order;
  60739. * null for not sorting;
  60740. * example of callback function:
  60741. * function(nodeA, nodeB) {
  60742. * return nodeA.getValue() - nodeB.getValue();
  60743. * }
  60744. */
  60745. sort: 'desc'
  60746. },
  60747. getViewRoot: function () {
  60748. return this._viewRoot;
  60749. },
  60750. /**
  60751. * @param {module:echarts/data/Tree~Node} [viewRoot]
  60752. */
  60753. resetViewRoot: function (viewRoot) {
  60754. viewRoot
  60755. ? (this._viewRoot = viewRoot)
  60756. : (viewRoot = this._viewRoot);
  60757. var root = this.getRawData().tree.root;
  60758. if (!viewRoot
  60759. || (viewRoot !== root && !root.contains(viewRoot))
  60760. ) {
  60761. this._viewRoot = root;
  60762. }
  60763. }
  60764. });
  60765. /**
  60766. * @param {Object} dataNode
  60767. */
  60768. function completeTreeValue$1(dataNode) {
  60769. // Postorder travel tree.
  60770. // If value of none-leaf node is not set,
  60771. // calculate it by suming up the value of all children.
  60772. var sum = 0;
  60773. each$1(dataNode.children, function (child) {
  60774. completeTreeValue$1(child);
  60775. var childValue = child.value;
  60776. isArray(childValue) && (childValue = childValue[0]);
  60777. sum += childValue;
  60778. });
  60779. var thisValue = dataNode.value;
  60780. if (isArray(thisValue)) {
  60781. thisValue = thisValue[0];
  60782. }
  60783. if (thisValue == null || isNaN(thisValue)) {
  60784. thisValue = sum;
  60785. }
  60786. // Value should not less than 0.
  60787. if (thisValue < 0) {
  60788. thisValue = 0;
  60789. }
  60790. isArray(dataNode.value)
  60791. ? (dataNode.value[0] = thisValue)
  60792. : (dataNode.value = thisValue);
  60793. }
  60794. /*
  60795. * Licensed to the Apache Software Foundation (ASF) under one
  60796. * or more contributor license agreements. See the NOTICE file
  60797. * distributed with this work for additional information
  60798. * regarding copyright ownership. The ASF licenses this file
  60799. * to you under the Apache License, Version 2.0 (the
  60800. * "License"); you may not use this file except in compliance
  60801. * with the License. You may obtain a copy of the License at
  60802. *
  60803. * http://www.apache.org/licenses/LICENSE-2.0
  60804. *
  60805. * Unless required by applicable law or agreed to in writing,
  60806. * software distributed under the License is distributed on an
  60807. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  60808. * KIND, either express or implied. See the License for the
  60809. * specific language governing permissions and limitations
  60810. * under the License.
  60811. */
  60812. var NodeHighlightPolicy = {
  60813. NONE: 'none', // not downplay others
  60814. DESCENDANT: 'descendant',
  60815. ANCESTOR: 'ancestor',
  60816. SELF: 'self'
  60817. };
  60818. var DEFAULT_SECTOR_Z = 2;
  60819. var DEFAULT_TEXT_Z = 4;
  60820. /**
  60821. * Sunburstce of Sunburst including Sector, Label, LabelLine
  60822. * @constructor
  60823. * @extends {module:zrender/graphic/Group}
  60824. */
  60825. function SunburstPiece(node, seriesModel, ecModel) {
  60826. Group.call(this);
  60827. var sector = new Sector({
  60828. z2: DEFAULT_SECTOR_Z
  60829. });
  60830. sector.seriesIndex = seriesModel.seriesIndex;
  60831. var text = new Text({
  60832. z2: DEFAULT_TEXT_Z,
  60833. silent: node.getModel('label').get('silent')
  60834. });
  60835. this.add(sector);
  60836. this.add(text);
  60837. this.updateData(true, node, 'normal', seriesModel, ecModel);
  60838. // Hover to change label and labelLine
  60839. function onEmphasis() {
  60840. text.ignore = text.hoverIgnore;
  60841. }
  60842. function onNormal() {
  60843. text.ignore = text.normalIgnore;
  60844. }
  60845. this.on('emphasis', onEmphasis)
  60846. .on('normal', onNormal)
  60847. .on('mouseover', onEmphasis)
  60848. .on('mouseout', onNormal);
  60849. }
  60850. var SunburstPieceProto = SunburstPiece.prototype;
  60851. SunburstPieceProto.updateData = function (
  60852. firstCreate,
  60853. node,
  60854. state,
  60855. seriesModel,
  60856. ecModel
  60857. ) {
  60858. this.node = node;
  60859. node.piece = this;
  60860. seriesModel = seriesModel || this._seriesModel;
  60861. ecModel = ecModel || this._ecModel;
  60862. var sector = this.childAt(0);
  60863. sector.dataIndex = node.dataIndex;
  60864. var itemModel = node.getModel();
  60865. var layout = node.getLayout();
  60866. // if (!layout) {
  60867. // console.log(node.getLayout());
  60868. // }
  60869. var sectorShape = extend({}, layout);
  60870. sectorShape.label = null;
  60871. var visualColor = getNodeColor(node, seriesModel, ecModel);
  60872. fillDefaultColor(node, seriesModel, visualColor);
  60873. var normalStyle = itemModel.getModel('itemStyle').getItemStyle();
  60874. var style;
  60875. if (state === 'normal') {
  60876. style = normalStyle;
  60877. }
  60878. else {
  60879. var stateStyle = itemModel.getModel(state + '.itemStyle')
  60880. .getItemStyle();
  60881. style = merge(stateStyle, normalStyle);
  60882. }
  60883. style = defaults(
  60884. {
  60885. lineJoin: 'bevel',
  60886. fill: style.fill || visualColor
  60887. },
  60888. style
  60889. );
  60890. if (firstCreate) {
  60891. sector.setShape(sectorShape);
  60892. sector.shape.r = layout.r0;
  60893. updateProps(
  60894. sector,
  60895. {
  60896. shape: {
  60897. r: layout.r
  60898. }
  60899. },
  60900. seriesModel,
  60901. node.dataIndex
  60902. );
  60903. sector.useStyle(style);
  60904. }
  60905. else if (typeof style.fill === 'object' && style.fill.type
  60906. || typeof sector.style.fill === 'object' && sector.style.fill.type
  60907. ) {
  60908. // Disable animation for gradient since no interpolation method
  60909. // is supported for gradient
  60910. updateProps(sector, {
  60911. shape: sectorShape
  60912. }, seriesModel);
  60913. sector.useStyle(style);
  60914. }
  60915. else {
  60916. updateProps(sector, {
  60917. shape: sectorShape,
  60918. style: style
  60919. }, seriesModel);
  60920. }
  60921. this._updateLabel(seriesModel, visualColor, state);
  60922. var cursorStyle = itemModel.getShallow('cursor');
  60923. cursorStyle && sector.attr('cursor', cursorStyle);
  60924. if (firstCreate) {
  60925. var highlightPolicy = seriesModel.getShallow('highlightPolicy');
  60926. this._initEvents(sector, node, seriesModel, highlightPolicy);
  60927. }
  60928. this._seriesModel = seriesModel || this._seriesModel;
  60929. this._ecModel = ecModel || this._ecModel;
  60930. };
  60931. SunburstPieceProto.onEmphasis = function (highlightPolicy) {
  60932. var that = this;
  60933. this.node.hostTree.root.eachNode(function (n) {
  60934. if (n.piece) {
  60935. if (that.node === n) {
  60936. n.piece.updateData(false, n, 'emphasis');
  60937. }
  60938. else if (isNodeHighlighted(n, that.node, highlightPolicy)) {
  60939. n.piece.childAt(0).trigger('highlight');
  60940. }
  60941. else if (highlightPolicy !== NodeHighlightPolicy.NONE) {
  60942. n.piece.childAt(0).trigger('downplay');
  60943. }
  60944. }
  60945. });
  60946. };
  60947. SunburstPieceProto.onNormal = function () {
  60948. this.node.hostTree.root.eachNode(function (n) {
  60949. if (n.piece) {
  60950. n.piece.updateData(false, n, 'normal');
  60951. }
  60952. });
  60953. };
  60954. SunburstPieceProto.onHighlight = function () {
  60955. this.updateData(false, this.node, 'highlight');
  60956. };
  60957. SunburstPieceProto.onDownplay = function () {
  60958. this.updateData(false, this.node, 'downplay');
  60959. };
  60960. SunburstPieceProto._updateLabel = function (seriesModel, visualColor, state) {
  60961. var itemModel = this.node.getModel();
  60962. var normalModel = itemModel.getModel('label');
  60963. var labelModel = state === 'normal' || state === 'emphasis'
  60964. ? normalModel
  60965. : itemModel.getModel(state + '.label');
  60966. var labelHoverModel = itemModel.getModel('emphasis.label');
  60967. var text = retrieve(
  60968. seriesModel.getFormattedLabel(
  60969. this.node.dataIndex, state, null, null, 'label'
  60970. ),
  60971. this.node.name
  60972. );
  60973. if (getLabelAttr('show') === false) {
  60974. text = '';
  60975. }
  60976. var layout = this.node.getLayout();
  60977. var labelMinAngle = labelModel.get('minAngle');
  60978. if (labelMinAngle == null) {
  60979. labelMinAngle = normalModel.get('minAngle');
  60980. }
  60981. labelMinAngle = labelMinAngle / 180 * Math.PI;
  60982. var angle = layout.endAngle - layout.startAngle;
  60983. if (labelMinAngle != null && Math.abs(angle) < labelMinAngle) {
  60984. // Not displaying text when angle is too small
  60985. text = '';
  60986. }
  60987. var label = this.childAt(1);
  60988. setLabelStyle(
  60989. label.style, label.hoverStyle || {}, normalModel, labelHoverModel,
  60990. {
  60991. defaultText: labelModel.getShallow('show') ? text : null,
  60992. autoColor: visualColor,
  60993. useInsideStyle: true
  60994. }
  60995. );
  60996. var midAngle = (layout.startAngle + layout.endAngle) / 2;
  60997. var dx = Math.cos(midAngle);
  60998. var dy = Math.sin(midAngle);
  60999. var r;
  61000. var labelPosition = getLabelAttr('position');
  61001. var labelPadding = getLabelAttr('distance') || 0;
  61002. var textAlign = getLabelAttr('align');
  61003. if (labelPosition === 'outside') {
  61004. r = layout.r + labelPadding;
  61005. textAlign = midAngle > Math.PI / 2 ? 'right' : 'left';
  61006. }
  61007. else {
  61008. if (!textAlign || textAlign === 'center') {
  61009. r = (layout.r + layout.r0) / 2;
  61010. textAlign = 'center';
  61011. }
  61012. else if (textAlign === 'left') {
  61013. r = layout.r0 + labelPadding;
  61014. if (midAngle > Math.PI / 2) {
  61015. textAlign = 'right';
  61016. }
  61017. }
  61018. else if (textAlign === 'right') {
  61019. r = layout.r - labelPadding;
  61020. if (midAngle > Math.PI / 2) {
  61021. textAlign = 'left';
  61022. }
  61023. }
  61024. }
  61025. label.attr('style', {
  61026. text: text,
  61027. textAlign: textAlign,
  61028. textVerticalAlign: getLabelAttr('verticalAlign') || 'middle',
  61029. opacity: getLabelAttr('opacity')
  61030. });
  61031. var textX = r * dx + layout.cx;
  61032. var textY = r * dy + layout.cy;
  61033. label.attr('position', [textX, textY]);
  61034. var rotateType = getLabelAttr('rotate');
  61035. var rotate = 0;
  61036. if (rotateType === 'radial') {
  61037. rotate = -midAngle;
  61038. if (rotate < -Math.PI / 2) {
  61039. rotate += Math.PI;
  61040. }
  61041. }
  61042. else if (rotateType === 'tangential') {
  61043. rotate = Math.PI / 2 - midAngle;
  61044. if (rotate > Math.PI / 2) {
  61045. rotate -= Math.PI;
  61046. }
  61047. else if (rotate < -Math.PI / 2) {
  61048. rotate += Math.PI;
  61049. }
  61050. } else if (typeof rotateType === 'number') {
  61051. rotate = rotateType * Math.PI / 180;
  61052. }
  61053. label.attr('rotation', rotate);
  61054. function getLabelAttr(name) {
  61055. var stateAttr = labelModel.get(name);
  61056. if (stateAttr == null) {
  61057. return normalModel.get(name);
  61058. }
  61059. else {
  61060. return stateAttr;
  61061. }
  61062. }
  61063. };
  61064. SunburstPieceProto._initEvents = function (
  61065. sector,
  61066. node,
  61067. seriesModel,
  61068. highlightPolicy
  61069. ) {
  61070. sector.off('mouseover').off('mouseout').off('emphasis').off('normal');
  61071. var that = this;
  61072. var onEmphasis = function () {
  61073. that.onEmphasis(highlightPolicy);
  61074. };
  61075. var onNormal = function () {
  61076. that.onNormal();
  61077. };
  61078. var onDownplay = function () {
  61079. that.onDownplay();
  61080. };
  61081. var onHighlight = function () {
  61082. that.onHighlight();
  61083. };
  61084. if (seriesModel.isAnimationEnabled()) {
  61085. sector
  61086. .on('mouseover', onEmphasis)
  61087. .on('mouseout', onNormal)
  61088. .on('emphasis', onEmphasis)
  61089. .on('normal', onNormal)
  61090. .on('downplay', onDownplay)
  61091. .on('highlight', onHighlight);
  61092. }
  61093. };
  61094. inherits(SunburstPiece, Group);
  61095. /**
  61096. * Get node color
  61097. *
  61098. * @param {TreeNode} node the node to get color
  61099. * @param {module:echarts/model/Series} seriesModel series
  61100. * @param {module:echarts/model/Global} ecModel echarts defaults
  61101. */
  61102. function getNodeColor(node, seriesModel, ecModel) {
  61103. // Color from visualMap
  61104. var visualColor = node.getVisual('color');
  61105. var visualMetaList = node.getVisual('visualMeta');
  61106. if (!visualMetaList || visualMetaList.length === 0) {
  61107. // Use first-generation color if has no visualMap
  61108. visualColor = null;
  61109. }
  61110. // Self color or level color
  61111. var color = node.getModel('itemStyle').get('color');
  61112. if (color) {
  61113. return color;
  61114. }
  61115. else if (visualColor) {
  61116. // Color mapping
  61117. return visualColor;
  61118. }
  61119. else if (node.depth === 0) {
  61120. // Virtual root node
  61121. return ecModel.option.color[0];
  61122. }
  61123. else {
  61124. // First-generation color
  61125. var length = ecModel.option.color.length;
  61126. color = ecModel.option.color[getRootId(node) % length];
  61127. }
  61128. return color;
  61129. }
  61130. /**
  61131. * Get index of root in sorted order
  61132. *
  61133. * @param {TreeNode} node current node
  61134. * @return {number} index in root
  61135. */
  61136. function getRootId(node) {
  61137. var ancestor = node;
  61138. while (ancestor.depth > 1) {
  61139. ancestor = ancestor.parentNode;
  61140. }
  61141. var virtualRoot = node.getAncestors()[0];
  61142. return indexOf(virtualRoot.children, ancestor);
  61143. }
  61144. function isNodeHighlighted(node, activeNode, policy) {
  61145. if (policy === NodeHighlightPolicy.NONE) {
  61146. return false;
  61147. }
  61148. else if (policy === NodeHighlightPolicy.SELF) {
  61149. return node === activeNode;
  61150. }
  61151. else if (policy === NodeHighlightPolicy.ANCESTOR) {
  61152. return node === activeNode || node.isAncestorOf(activeNode);
  61153. }
  61154. else {
  61155. return node === activeNode || node.isDescendantOf(activeNode);
  61156. }
  61157. }
  61158. // Fix tooltip callback function params.color incorrect when pick a default color
  61159. function fillDefaultColor(node, seriesModel, color) {
  61160. var data = seriesModel.getData();
  61161. data.setItemVisual(node.dataIndex, 'color', color);
  61162. }
  61163. /*
  61164. * Licensed to the Apache Software Foundation (ASF) under one
  61165. * or more contributor license agreements. See the NOTICE file
  61166. * distributed with this work for additional information
  61167. * regarding copyright ownership. The ASF licenses this file
  61168. * to you under the Apache License, Version 2.0 (the
  61169. * "License"); you may not use this file except in compliance
  61170. * with the License. You may obtain a copy of the License at
  61171. *
  61172. * http://www.apache.org/licenses/LICENSE-2.0
  61173. *
  61174. * Unless required by applicable law or agreed to in writing,
  61175. * software distributed under the License is distributed on an
  61176. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  61177. * KIND, either express or implied. See the License for the
  61178. * specific language governing permissions and limitations
  61179. * under the License.
  61180. */
  61181. var ROOT_TO_NODE_ACTION = 'sunburstRootToNode';
  61182. var SunburstView = Chart.extend({
  61183. type: 'sunburst',
  61184. init: function () {
  61185. },
  61186. render: function (seriesModel, ecModel, api, payload) {
  61187. var that = this;
  61188. this.seriesModel = seriesModel;
  61189. this.api = api;
  61190. this.ecModel = ecModel;
  61191. var data = seriesModel.getData();
  61192. var virtualRoot = data.tree.root;
  61193. var newRoot = seriesModel.getViewRoot();
  61194. var group = this.group;
  61195. var renderLabelForZeroData = seriesModel.get('renderLabelForZeroData');
  61196. var newChildren = [];
  61197. newRoot.eachNode(function (node) {
  61198. newChildren.push(node);
  61199. });
  61200. var oldChildren = this._oldChildren || [];
  61201. dualTravel(newChildren, oldChildren);
  61202. renderRollUp(virtualRoot, newRoot);
  61203. if (payload && payload.highlight && payload.highlight.piece) {
  61204. var highlightPolicy = seriesModel.getShallow('highlightPolicy');
  61205. payload.highlight.piece.onEmphasis(highlightPolicy);
  61206. }
  61207. else if (payload && payload.unhighlight) {
  61208. var piece = this.virtualPiece;
  61209. if (!piece && virtualRoot.children.length) {
  61210. piece = virtualRoot.children[0].piece;
  61211. }
  61212. if (piece) {
  61213. piece.onNormal();
  61214. }
  61215. }
  61216. this._initEvents();
  61217. this._oldChildren = newChildren;
  61218. function dualTravel(newChildren, oldChildren) {
  61219. if (newChildren.length === 0 && oldChildren.length === 0) {
  61220. return;
  61221. }
  61222. new DataDiffer(oldChildren, newChildren, getKey, getKey)
  61223. .add(processNode)
  61224. .update(processNode)
  61225. .remove(curry(processNode, null))
  61226. .execute();
  61227. function getKey(node) {
  61228. return node.getId();
  61229. }
  61230. function processNode(newId, oldId) {
  61231. var newNode = newId == null ? null : newChildren[newId];
  61232. var oldNode = oldId == null ? null : oldChildren[oldId];
  61233. doRenderNode(newNode, oldNode);
  61234. }
  61235. }
  61236. function doRenderNode(newNode, oldNode) {
  61237. if (!renderLabelForZeroData && newNode && !newNode.getValue()) {
  61238. // Not render data with value 0
  61239. newNode = null;
  61240. }
  61241. if (newNode !== virtualRoot && oldNode !== virtualRoot) {
  61242. if (oldNode && oldNode.piece) {
  61243. if (newNode) {
  61244. // Update
  61245. oldNode.piece.updateData(
  61246. false, newNode, 'normal', seriesModel, ecModel);
  61247. // For tooltip
  61248. data.setItemGraphicEl(newNode.dataIndex, oldNode.piece);
  61249. }
  61250. else {
  61251. // Remove
  61252. removeNode(oldNode);
  61253. }
  61254. }
  61255. else if (newNode) {
  61256. // Add
  61257. var piece = new SunburstPiece(
  61258. newNode,
  61259. seriesModel,
  61260. ecModel
  61261. );
  61262. group.add(piece);
  61263. // For tooltip
  61264. data.setItemGraphicEl(newNode.dataIndex, piece);
  61265. }
  61266. }
  61267. }
  61268. function removeNode(node) {
  61269. if (!node) {
  61270. return;
  61271. }
  61272. if (node.piece) {
  61273. group.remove(node.piece);
  61274. node.piece = null;
  61275. }
  61276. }
  61277. function renderRollUp(virtualRoot, viewRoot) {
  61278. if (viewRoot.depth > 0) {
  61279. // Render
  61280. if (that.virtualPiece) {
  61281. // Update
  61282. that.virtualPiece.updateData(
  61283. false, virtualRoot, 'normal', seriesModel, ecModel);
  61284. }
  61285. else {
  61286. // Add
  61287. that.virtualPiece = new SunburstPiece(
  61288. virtualRoot,
  61289. seriesModel,
  61290. ecModel
  61291. );
  61292. group.add(that.virtualPiece);
  61293. }
  61294. if (viewRoot.piece._onclickEvent) {
  61295. viewRoot.piece.off('click', viewRoot.piece._onclickEvent);
  61296. }
  61297. var event = function (e) {
  61298. that._rootToNode(viewRoot.parentNode);
  61299. };
  61300. viewRoot.piece._onclickEvent = event;
  61301. that.virtualPiece.on('click', event);
  61302. }
  61303. else if (that.virtualPiece) {
  61304. // Remove
  61305. group.remove(that.virtualPiece);
  61306. that.virtualPiece = null;
  61307. }
  61308. }
  61309. },
  61310. dispose: function () {
  61311. },
  61312. /**
  61313. * @private
  61314. */
  61315. _initEvents: function () {
  61316. var that = this;
  61317. var event = function (e) {
  61318. var targetFound = false;
  61319. var viewRoot = that.seriesModel.getViewRoot();
  61320. viewRoot.eachNode(function (node) {
  61321. if (!targetFound
  61322. && node.piece && node.piece.childAt(0) === e.target
  61323. ) {
  61324. var nodeClick = node.getModel().get('nodeClick');
  61325. if (nodeClick === 'rootToNode') {
  61326. that._rootToNode(node);
  61327. }
  61328. else if (nodeClick === 'link') {
  61329. var itemModel = node.getModel();
  61330. var link = itemModel.get('link');
  61331. if (link) {
  61332. var linkTarget = itemModel.get('target', true)
  61333. || '_blank';
  61334. window.open(link, linkTarget);
  61335. }
  61336. }
  61337. targetFound = true;
  61338. }
  61339. });
  61340. };
  61341. if (this.group._onclickEvent) {
  61342. this.group.off('click', this.group._onclickEvent);
  61343. }
  61344. this.group.on('click', event);
  61345. this.group._onclickEvent = event;
  61346. },
  61347. /**
  61348. * @private
  61349. */
  61350. _rootToNode: function (node) {
  61351. if (node !== this.seriesModel.getViewRoot()) {
  61352. this.api.dispatchAction({
  61353. type: ROOT_TO_NODE_ACTION,
  61354. from: this.uid,
  61355. seriesId: this.seriesModel.id,
  61356. targetNode: node
  61357. });
  61358. }
  61359. },
  61360. /**
  61361. * @implement
  61362. */
  61363. containPoint: function (point, seriesModel) {
  61364. var treeRoot = seriesModel.getData();
  61365. var itemLayout = treeRoot.getItemLayout(0);
  61366. if (itemLayout) {
  61367. var dx = point[0] - itemLayout.cx;
  61368. var dy = point[1] - itemLayout.cy;
  61369. var radius = Math.sqrt(dx * dx + dy * dy);
  61370. return radius <= itemLayout.r && radius >= itemLayout.r0;
  61371. }
  61372. }
  61373. });
  61374. /*
  61375. * Licensed to the Apache Software Foundation (ASF) under one
  61376. * or more contributor license agreements. See the NOTICE file
  61377. * distributed with this work for additional information
  61378. * regarding copyright ownership. The ASF licenses this file
  61379. * to you under the Apache License, Version 2.0 (the
  61380. * "License"); you may not use this file except in compliance
  61381. * with the License. You may obtain a copy of the License at
  61382. *
  61383. * http://www.apache.org/licenses/LICENSE-2.0
  61384. *
  61385. * Unless required by applicable law or agreed to in writing,
  61386. * software distributed under the License is distributed on an
  61387. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  61388. * KIND, either express or implied. See the License for the
  61389. * specific language governing permissions and limitations
  61390. * under the License.
  61391. */
  61392. /**
  61393. * @file Sunburst action
  61394. */
  61395. var ROOT_TO_NODE_ACTION$1 = 'sunburstRootToNode';
  61396. registerAction(
  61397. {type: ROOT_TO_NODE_ACTION$1, update: 'updateView'},
  61398. function (payload, ecModel) {
  61399. ecModel.eachComponent(
  61400. {mainType: 'series', subType: 'sunburst', query: payload},
  61401. handleRootToNode
  61402. );
  61403. function handleRootToNode(model, index) {
  61404. var targetInfo = retrieveTargetInfo(payload, [ROOT_TO_NODE_ACTION$1], model);
  61405. if (targetInfo) {
  61406. var originViewRoot = model.getViewRoot();
  61407. if (originViewRoot) {
  61408. payload.direction = aboveViewRoot(originViewRoot, targetInfo.node)
  61409. ? 'rollUp' : 'drillDown';
  61410. }
  61411. model.resetViewRoot(targetInfo.node);
  61412. }
  61413. }
  61414. }
  61415. );
  61416. var HIGHLIGHT_ACTION = 'sunburstHighlight';
  61417. registerAction(
  61418. {type: HIGHLIGHT_ACTION, update: 'updateView'},
  61419. function (payload, ecModel) {
  61420. ecModel.eachComponent(
  61421. {mainType: 'series', subType: 'sunburst', query: payload},
  61422. handleHighlight
  61423. );
  61424. function handleHighlight(model, index) {
  61425. var targetInfo = retrieveTargetInfo(payload, [HIGHLIGHT_ACTION], model);
  61426. if (targetInfo) {
  61427. payload.highlight = targetInfo.node;
  61428. }
  61429. }
  61430. }
  61431. );
  61432. var UNHIGHLIGHT_ACTION = 'sunburstUnhighlight';
  61433. registerAction(
  61434. {type: UNHIGHLIGHT_ACTION, update: 'updateView'},
  61435. function (payload, ecModel) {
  61436. ecModel.eachComponent(
  61437. {mainType: 'series', subType: 'sunburst', query: payload},
  61438. handleUnhighlight
  61439. );
  61440. function handleUnhighlight(model, index) {
  61441. payload.unhighlight = true;
  61442. }
  61443. }
  61444. );
  61445. /*
  61446. * Licensed to the Apache Software Foundation (ASF) under one
  61447. * or more contributor license agreements. See the NOTICE file
  61448. * distributed with this work for additional information
  61449. * regarding copyright ownership. The ASF licenses this file
  61450. * to you under the Apache License, Version 2.0 (the
  61451. * "License"); you may not use this file except in compliance
  61452. * with the License. You may obtain a copy of the License at
  61453. *
  61454. * http://www.apache.org/licenses/LICENSE-2.0
  61455. *
  61456. * Unless required by applicable law or agreed to in writing,
  61457. * software distributed under the License is distributed on an
  61458. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  61459. * KIND, either express or implied. See the License for the
  61460. * specific language governing permissions and limitations
  61461. * under the License.
  61462. */
  61463. var RADIAN$2 = Math.PI / 180;
  61464. var sunburstLayout = function (seriesType, ecModel, api, payload) {
  61465. ecModel.eachSeriesByType(seriesType, function (seriesModel) {
  61466. var center = seriesModel.get('center');
  61467. var radius = seriesModel.get('radius');
  61468. if (!isArray(radius)) {
  61469. radius = [0, radius];
  61470. }
  61471. if (!isArray(center)) {
  61472. center = [center, center];
  61473. }
  61474. var width = api.getWidth();
  61475. var height = api.getHeight();
  61476. var size = Math.min(width, height);
  61477. var cx = parsePercent$1(center[0], width);
  61478. var cy = parsePercent$1(center[1], height);
  61479. var r0 = parsePercent$1(radius[0], size / 2);
  61480. var r = parsePercent$1(radius[1], size / 2);
  61481. var startAngle = -seriesModel.get('startAngle') * RADIAN$2;
  61482. var minAngle = seriesModel.get('minAngle') * RADIAN$2;
  61483. var virtualRoot = seriesModel.getData().tree.root;
  61484. var treeRoot = seriesModel.getViewRoot();
  61485. var rootDepth = treeRoot.depth;
  61486. var sort = seriesModel.get('sort');
  61487. if (sort != null) {
  61488. initChildren$1(treeRoot, sort);
  61489. }
  61490. var validDataCount = 0;
  61491. each$1(treeRoot.children, function (child) {
  61492. !isNaN(child.getValue()) && validDataCount++;
  61493. });
  61494. var sum = treeRoot.getValue();
  61495. // Sum may be 0
  61496. var unitRadian = Math.PI / (sum || validDataCount) * 2;
  61497. var renderRollupNode = treeRoot.depth > 0;
  61498. var levels = treeRoot.height - (renderRollupNode ? -1 : 1);
  61499. var rPerLevel = (r - r0) / (levels || 1);
  61500. var clockwise = seriesModel.get('clockwise');
  61501. var stillShowZeroSum = seriesModel.get('stillShowZeroSum');
  61502. // In the case some sector angle is smaller than minAngle
  61503. var dir = clockwise ? 1 : -1;
  61504. /**
  61505. * Render a tree
  61506. * @return increased angle
  61507. */
  61508. var renderNode = function (node, startAngle) {
  61509. if (!node) {
  61510. return;
  61511. }
  61512. var endAngle = startAngle;
  61513. // Render self
  61514. if (node !== virtualRoot) {
  61515. // Tree node is virtual, so it doesn't need to be drawn
  61516. var value = node.getValue();
  61517. var angle = (sum === 0 && stillShowZeroSum)
  61518. ? unitRadian : (value * unitRadian);
  61519. if (angle < minAngle) {
  61520. angle = minAngle;
  61521. }
  61522. else {
  61523. }
  61524. endAngle = startAngle + dir * angle;
  61525. var depth = node.depth - rootDepth
  61526. - (renderRollupNode ? -1 : 1);
  61527. var rStart = r0 + rPerLevel * depth;
  61528. var rEnd = r0 + rPerLevel * (depth + 1);
  61529. var itemModel = node.getModel();
  61530. if (itemModel.get('r0') != null) {
  61531. rStart = parsePercent$1(itemModel.get('r0'), size / 2);
  61532. }
  61533. if (itemModel.get('r') != null) {
  61534. rEnd = parsePercent$1(itemModel.get('r'), size / 2);
  61535. }
  61536. node.setLayout({
  61537. angle: angle,
  61538. startAngle: startAngle,
  61539. endAngle: endAngle,
  61540. clockwise: clockwise,
  61541. cx: cx,
  61542. cy: cy,
  61543. r0: rStart,
  61544. r: rEnd
  61545. });
  61546. }
  61547. // Render children
  61548. if (node.children && node.children.length) {
  61549. // currentAngle = startAngle;
  61550. var siblingAngle = 0;
  61551. each$1(node.children, function (node) {
  61552. siblingAngle += renderNode(node, startAngle + siblingAngle);
  61553. });
  61554. }
  61555. return endAngle - startAngle;
  61556. };
  61557. // Virtual root node for roll up
  61558. if (renderRollupNode) {
  61559. var rStart = r0;
  61560. var rEnd = r0 + rPerLevel;
  61561. var angle = Math.PI * 2;
  61562. virtualRoot.setLayout({
  61563. angle: angle,
  61564. startAngle: startAngle,
  61565. endAngle: startAngle + angle,
  61566. clockwise: clockwise,
  61567. cx: cx,
  61568. cy: cy,
  61569. r0: rStart,
  61570. r: rEnd
  61571. });
  61572. }
  61573. renderNode(treeRoot, startAngle);
  61574. });
  61575. };
  61576. /**
  61577. * Init node children by order and update visual
  61578. *
  61579. * @param {TreeNode} node root node
  61580. * @param {boolean} isAsc if is in ascendant order
  61581. */
  61582. function initChildren$1(node, isAsc) {
  61583. var children = node.children || [];
  61584. node.children = sort$2(children, isAsc);
  61585. // Init children recursively
  61586. if (children.length) {
  61587. each$1(node.children, function (child) {
  61588. initChildren$1(child, isAsc);
  61589. });
  61590. }
  61591. }
  61592. /**
  61593. * Sort children nodes
  61594. *
  61595. * @param {TreeNode[]} children children of node to be sorted
  61596. * @param {string | function | null} sort sort method
  61597. * See SunburstSeries.js for details.
  61598. */
  61599. function sort$2(children, sortOrder) {
  61600. if (typeof sortOrder === 'function') {
  61601. return children.sort(sortOrder);
  61602. }
  61603. else {
  61604. var isAsc = sortOrder === 'asc';
  61605. return children.sort(function (a, b) {
  61606. var diff = (a.getValue() - b.getValue()) * (isAsc ? 1 : -1);
  61607. return diff === 0
  61608. ? (a.dataIndex - b.dataIndex) * (isAsc ? -1 : 1)
  61609. : diff;
  61610. });
  61611. }
  61612. }
  61613. /*
  61614. * Licensed to the Apache Software Foundation (ASF) under one
  61615. * or more contributor license agreements. See the NOTICE file
  61616. * distributed with this work for additional information
  61617. * regarding copyright ownership. The ASF licenses this file
  61618. * to you under the Apache License, Version 2.0 (the
  61619. * "License"); you may not use this file except in compliance
  61620. * with the License. You may obtain a copy of the License at
  61621. *
  61622. * http://www.apache.org/licenses/LICENSE-2.0
  61623. *
  61624. * Unless required by applicable law or agreed to in writing,
  61625. * software distributed under the License is distributed on an
  61626. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  61627. * KIND, either express or implied. See the License for the
  61628. * specific language governing permissions and limitations
  61629. * under the License.
  61630. */
  61631. registerVisual(curry(dataColor, 'sunburst'));
  61632. registerLayout(curry(sunburstLayout, 'sunburst'));
  61633. registerProcessor(curry(dataFilter, 'sunburst'));
  61634. /*
  61635. * Licensed to the Apache Software Foundation (ASF) under one
  61636. * or more contributor license agreements. See the NOTICE file
  61637. * distributed with this work for additional information
  61638. * regarding copyright ownership. The ASF licenses this file
  61639. * to you under the Apache License, Version 2.0 (the
  61640. * "License"); you may not use this file except in compliance
  61641. * with the License. You may obtain a copy of the License at
  61642. *
  61643. * http://www.apache.org/licenses/LICENSE-2.0
  61644. *
  61645. * Unless required by applicable law or agreed to in writing,
  61646. * software distributed under the License is distributed on an
  61647. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  61648. * KIND, either express or implied. See the License for the
  61649. * specific language governing permissions and limitations
  61650. * under the License.
  61651. */
  61652. function dataToCoordSize(dataSize, dataItem) {
  61653. // dataItem is necessary in log axis.
  61654. dataItem = dataItem || [0, 0];
  61655. return map(['x', 'y'], function (dim, dimIdx) {
  61656. var axis = this.getAxis(dim);
  61657. var val = dataItem[dimIdx];
  61658. var halfSize = dataSize[dimIdx] / 2;
  61659. return axis.type === 'category'
  61660. ? axis.getBandWidth()
  61661. : Math.abs(axis.dataToCoord(val - halfSize) - axis.dataToCoord(val + halfSize));
  61662. }, this);
  61663. }
  61664. var prepareCartesian2d = function (coordSys) {
  61665. var rect = coordSys.grid.getRect();
  61666. return {
  61667. coordSys: {
  61668. // The name exposed to user is always 'cartesian2d' but not 'grid'.
  61669. type: 'cartesian2d',
  61670. x: rect.x,
  61671. y: rect.y,
  61672. width: rect.width,
  61673. height: rect.height
  61674. },
  61675. api: {
  61676. coord: function (data) {
  61677. // do not provide "out" param
  61678. return coordSys.dataToPoint(data);
  61679. },
  61680. size: bind(dataToCoordSize, coordSys)
  61681. }
  61682. };
  61683. };
  61684. /*
  61685. * Licensed to the Apache Software Foundation (ASF) under one
  61686. * or more contributor license agreements. See the NOTICE file
  61687. * distributed with this work for additional information
  61688. * regarding copyright ownership. The ASF licenses this file
  61689. * to you under the Apache License, Version 2.0 (the
  61690. * "License"); you may not use this file except in compliance
  61691. * with the License. You may obtain a copy of the License at
  61692. *
  61693. * http://www.apache.org/licenses/LICENSE-2.0
  61694. *
  61695. * Unless required by applicable law or agreed to in writing,
  61696. * software distributed under the License is distributed on an
  61697. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  61698. * KIND, either express or implied. See the License for the
  61699. * specific language governing permissions and limitations
  61700. * under the License.
  61701. */
  61702. function dataToCoordSize$1(dataSize, dataItem) {
  61703. dataItem = dataItem || [0, 0];
  61704. return map([0, 1], function (dimIdx) {
  61705. var val = dataItem[dimIdx];
  61706. var halfSize = dataSize[dimIdx] / 2;
  61707. var p1 = [];
  61708. var p2 = [];
  61709. p1[dimIdx] = val - halfSize;
  61710. p2[dimIdx] = val + halfSize;
  61711. p1[1 - dimIdx] = p2[1 - dimIdx] = dataItem[1 - dimIdx];
  61712. return Math.abs(this.dataToPoint(p1)[dimIdx] - this.dataToPoint(p2)[dimIdx]);
  61713. }, this);
  61714. }
  61715. var prepareGeo = function (coordSys) {
  61716. var rect = coordSys.getBoundingRect();
  61717. return {
  61718. coordSys: {
  61719. type: 'geo',
  61720. x: rect.x,
  61721. y: rect.y,
  61722. width: rect.width,
  61723. height: rect.height,
  61724. zoom: coordSys.getZoom()
  61725. },
  61726. api: {
  61727. coord: function (data) {
  61728. // do not provide "out" and noRoam param,
  61729. // Compatible with this usage:
  61730. // echarts.util.map(item.points, api.coord)
  61731. return coordSys.dataToPoint(data);
  61732. },
  61733. size: bind(dataToCoordSize$1, coordSys)
  61734. }
  61735. };
  61736. };
  61737. /*
  61738. * Licensed to the Apache Software Foundation (ASF) under one
  61739. * or more contributor license agreements. See the NOTICE file
  61740. * distributed with this work for additional information
  61741. * regarding copyright ownership. The ASF licenses this file
  61742. * to you under the Apache License, Version 2.0 (the
  61743. * "License"); you may not use this file except in compliance
  61744. * with the License. You may obtain a copy of the License at
  61745. *
  61746. * http://www.apache.org/licenses/LICENSE-2.0
  61747. *
  61748. * Unless required by applicable law or agreed to in writing,
  61749. * software distributed under the License is distributed on an
  61750. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  61751. * KIND, either express or implied. See the License for the
  61752. * specific language governing permissions and limitations
  61753. * under the License.
  61754. */
  61755. function dataToCoordSize$2(dataSize, dataItem) {
  61756. // dataItem is necessary in log axis.
  61757. var axis = this.getAxis();
  61758. var val = dataItem instanceof Array ? dataItem[0] : dataItem;
  61759. var halfSize = (dataSize instanceof Array ? dataSize[0] : dataSize) / 2;
  61760. return axis.type === 'category'
  61761. ? axis.getBandWidth()
  61762. : Math.abs(axis.dataToCoord(val - halfSize) - axis.dataToCoord(val + halfSize));
  61763. }
  61764. var prepareSingleAxis = function (coordSys) {
  61765. var rect = coordSys.getRect();
  61766. return {
  61767. coordSys: {
  61768. type: 'singleAxis',
  61769. x: rect.x,
  61770. y: rect.y,
  61771. width: rect.width,
  61772. height: rect.height
  61773. },
  61774. api: {
  61775. coord: function (val) {
  61776. // do not provide "out" param
  61777. return coordSys.dataToPoint(val);
  61778. },
  61779. size: bind(dataToCoordSize$2, coordSys)
  61780. }
  61781. };
  61782. };
  61783. /*
  61784. * Licensed to the Apache Software Foundation (ASF) under one
  61785. * or more contributor license agreements. See the NOTICE file
  61786. * distributed with this work for additional information
  61787. * regarding copyright ownership. The ASF licenses this file
  61788. * to you under the Apache License, Version 2.0 (the
  61789. * "License"); you may not use this file except in compliance
  61790. * with the License. You may obtain a copy of the License at
  61791. *
  61792. * http://www.apache.org/licenses/LICENSE-2.0
  61793. *
  61794. * Unless required by applicable law or agreed to in writing,
  61795. * software distributed under the License is distributed on an
  61796. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  61797. * KIND, either express or implied. See the License for the
  61798. * specific language governing permissions and limitations
  61799. * under the License.
  61800. */
  61801. function dataToCoordSize$3(dataSize, dataItem) {
  61802. // dataItem is necessary in log axis.
  61803. return map(['Radius', 'Angle'], function (dim, dimIdx) {
  61804. var axis = this['get' + dim + 'Axis']();
  61805. var val = dataItem[dimIdx];
  61806. var halfSize = dataSize[dimIdx] / 2;
  61807. var method = 'dataTo' + dim;
  61808. var result = axis.type === 'category'
  61809. ? axis.getBandWidth()
  61810. : Math.abs(axis[method](val - halfSize) - axis[method](val + halfSize));
  61811. if (dim === 'Angle') {
  61812. result = result * Math.PI / 180;
  61813. }
  61814. return result;
  61815. }, this);
  61816. }
  61817. var preparePolar = function (coordSys) {
  61818. var radiusAxis = coordSys.getRadiusAxis();
  61819. var angleAxis = coordSys.getAngleAxis();
  61820. var radius = radiusAxis.getExtent();
  61821. radius[0] > radius[1] && radius.reverse();
  61822. return {
  61823. coordSys: {
  61824. type: 'polar',
  61825. cx: coordSys.cx,
  61826. cy: coordSys.cy,
  61827. r: radius[1],
  61828. r0: radius[0]
  61829. },
  61830. api: {
  61831. coord: bind(function (data) {
  61832. var radius = radiusAxis.dataToRadius(data[0]);
  61833. var angle = angleAxis.dataToAngle(data[1]);
  61834. var coord = coordSys.coordToPoint([radius, angle]);
  61835. coord.push(radius, angle * Math.PI / 180);
  61836. return coord;
  61837. }),
  61838. size: bind(dataToCoordSize$3, coordSys)
  61839. }
  61840. };
  61841. };
  61842. /*
  61843. * Licensed to the Apache Software Foundation (ASF) under one
  61844. * or more contributor license agreements. See the NOTICE file
  61845. * distributed with this work for additional information
  61846. * regarding copyright ownership. The ASF licenses this file
  61847. * to you under the Apache License, Version 2.0 (the
  61848. * "License"); you may not use this file except in compliance
  61849. * with the License. You may obtain a copy of the License at
  61850. *
  61851. * http://www.apache.org/licenses/LICENSE-2.0
  61852. *
  61853. * Unless required by applicable law or agreed to in writing,
  61854. * software distributed under the License is distributed on an
  61855. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  61856. * KIND, either express or implied. See the License for the
  61857. * specific language governing permissions and limitations
  61858. * under the License.
  61859. */
  61860. var prepareCalendar = function (coordSys) {
  61861. var rect = coordSys.getRect();
  61862. var rangeInfo = coordSys.getRangeInfo();
  61863. return {
  61864. coordSys: {
  61865. type: 'calendar',
  61866. x: rect.x,
  61867. y: rect.y,
  61868. width: rect.width,
  61869. height: rect.height,
  61870. cellWidth: coordSys.getCellWidth(),
  61871. cellHeight: coordSys.getCellHeight(),
  61872. rangeInfo: {
  61873. start: rangeInfo.start,
  61874. end: rangeInfo.end,
  61875. weeks: rangeInfo.weeks,
  61876. dayCount: rangeInfo.allDay
  61877. }
  61878. },
  61879. api: {
  61880. coord: function (data, clamp) {
  61881. return coordSys.dataToPoint(data, clamp);
  61882. }
  61883. }
  61884. };
  61885. };
  61886. /*
  61887. * Licensed to the Apache Software Foundation (ASF) under one
  61888. * or more contributor license agreements. See the NOTICE file
  61889. * distributed with this work for additional information
  61890. * regarding copyright ownership. The ASF licenses this file
  61891. * to you under the Apache License, Version 2.0 (the
  61892. * "License"); you may not use this file except in compliance
  61893. * with the License. You may obtain a copy of the License at
  61894. *
  61895. * http://www.apache.org/licenses/LICENSE-2.0
  61896. *
  61897. * Unless required by applicable law or agreed to in writing,
  61898. * software distributed under the License is distributed on an
  61899. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  61900. * KIND, either express or implied. See the License for the
  61901. * specific language governing permissions and limitations
  61902. * under the License.
  61903. */
  61904. var CACHED_LABEL_STYLE_PROPERTIES$1 = CACHED_LABEL_STYLE_PROPERTIES;
  61905. var ITEM_STYLE_NORMAL_PATH = ['itemStyle'];
  61906. var ITEM_STYLE_EMPHASIS_PATH = ['emphasis', 'itemStyle'];
  61907. var LABEL_NORMAL = ['label'];
  61908. var LABEL_EMPHASIS = ['emphasis', 'label'];
  61909. // Use prefix to avoid index to be the same as el.name,
  61910. // which will cause weird udpate animation.
  61911. var GROUP_DIFF_PREFIX = 'e\0\0';
  61912. /**
  61913. * To reduce total package size of each coordinate systems, the modules `prepareCustom`
  61914. * of each coordinate systems are not required by each coordinate systems directly, but
  61915. * required by the module `custom`.
  61916. *
  61917. * prepareInfoForCustomSeries {Function}: optional
  61918. * @return {Object} {coordSys: {...}, api: {
  61919. * coord: function (data, clamp) {}, // return point in global.
  61920. * size: function (dataSize, dataItem) {} // return size of each axis in coordSys.
  61921. * }}
  61922. */
  61923. var prepareCustoms = {
  61924. cartesian2d: prepareCartesian2d,
  61925. geo: prepareGeo,
  61926. singleAxis: prepareSingleAxis,
  61927. polar: preparePolar,
  61928. calendar: prepareCalendar
  61929. };
  61930. // ------
  61931. // Model
  61932. // ------
  61933. SeriesModel.extend({
  61934. type: 'series.custom',
  61935. dependencies: ['grid', 'polar', 'geo', 'singleAxis', 'calendar'],
  61936. defaultOption: {
  61937. coordinateSystem: 'cartesian2d', // Can be set as 'none'
  61938. zlevel: 0,
  61939. z: 2,
  61940. legendHoverLink: true,
  61941. useTransform: true
  61942. // Cartesian coordinate system
  61943. // xAxisIndex: 0,
  61944. // yAxisIndex: 0,
  61945. // Polar coordinate system
  61946. // polarIndex: 0,
  61947. // Geo coordinate system
  61948. // geoIndex: 0,
  61949. // label: {}
  61950. // itemStyle: {}
  61951. },
  61952. /**
  61953. * @override
  61954. */
  61955. getInitialData: function (option, ecModel) {
  61956. return createListFromArray(this.getSource(), this);
  61957. },
  61958. /**
  61959. * @override
  61960. */
  61961. getDataParams: function (dataIndex, dataType, el) {
  61962. var params = SeriesModel.prototype.getDataParams.apply(this, arguments);
  61963. el && (params.info = el.info);
  61964. return params;
  61965. }
  61966. });
  61967. // -----
  61968. // View
  61969. // -----
  61970. Chart.extend({
  61971. type: 'custom',
  61972. /**
  61973. * @private
  61974. * @type {module:echarts/data/List}
  61975. */
  61976. _data: null,
  61977. /**
  61978. * @override
  61979. */
  61980. render: function (customSeries, ecModel, api, payload) {
  61981. var oldData = this._data;
  61982. var data = customSeries.getData();
  61983. var group = this.group;
  61984. var renderItem = makeRenderItem(customSeries, data, ecModel, api);
  61985. // By default, merge mode is applied. In most cases, custom series is
  61986. // used in the scenario that data amount is not large but graphic elements
  61987. // is complicated, where merge mode is probably necessary for optimization.
  61988. // For example, reuse graphic elements and only update the transform when
  61989. // roam or data zoom according to `actionType`.
  61990. data.diff(oldData)
  61991. .add(function (newIdx) {
  61992. createOrUpdate$1(
  61993. null, newIdx, renderItem(newIdx, payload), customSeries, group, data
  61994. );
  61995. })
  61996. .update(function (newIdx, oldIdx) {
  61997. var el = oldData.getItemGraphicEl(oldIdx);
  61998. createOrUpdate$1(
  61999. el, newIdx, renderItem(newIdx, payload), customSeries, group, data
  62000. );
  62001. })
  62002. .remove(function (oldIdx) {
  62003. var el = oldData.getItemGraphicEl(oldIdx);
  62004. el && group.remove(el);
  62005. })
  62006. .execute();
  62007. this._data = data;
  62008. },
  62009. incrementalPrepareRender: function (customSeries, ecModel, api) {
  62010. this.group.removeAll();
  62011. this._data = null;
  62012. },
  62013. incrementalRender: function (params, customSeries, ecModel, api, payload) {
  62014. var data = customSeries.getData();
  62015. var renderItem = makeRenderItem(customSeries, data, ecModel, api);
  62016. function setIncrementalAndHoverLayer(el) {
  62017. if (!el.isGroup) {
  62018. el.incremental = true;
  62019. el.useHoverLayer = true;
  62020. }
  62021. }
  62022. for (var idx = params.start; idx < params.end; idx++) {
  62023. var el = createOrUpdate$1(null, idx, renderItem(idx, payload), customSeries, this.group, data);
  62024. el.traverse(setIncrementalAndHoverLayer);
  62025. }
  62026. },
  62027. /**
  62028. * @override
  62029. */
  62030. dispose: noop,
  62031. /**
  62032. * @override
  62033. */
  62034. filterForExposedEvent: function (eventType, query, targetEl, packedEvent) {
  62035. var elementName = query.element;
  62036. if (elementName == null || targetEl.name === elementName) {
  62037. return true;
  62038. }
  62039. // Enable to give a name on a group made by `renderItem`, and listen
  62040. // events that triggerd by its descendents.
  62041. while ((targetEl = targetEl.parent) && targetEl !== this.group) {
  62042. if (targetEl.name === elementName) {
  62043. return true;
  62044. }
  62045. }
  62046. return false;
  62047. }
  62048. });
  62049. function createEl(elOption) {
  62050. var graphicType = elOption.type;
  62051. var el;
  62052. if (graphicType === 'path') {
  62053. var shape = elOption.shape;
  62054. // Using pathRect brings convenience to users sacle svg path.
  62055. var pathRect = (shape.width != null && shape.height != null)
  62056. ? {
  62057. x: shape.x || 0,
  62058. y: shape.y || 0,
  62059. width: shape.width,
  62060. height: shape.height
  62061. }
  62062. : null;
  62063. var pathData = getPathData(shape);
  62064. // Path is also used for icon, so layout 'center' by default.
  62065. el = makePath(pathData, null, pathRect, shape.layout || 'center');
  62066. el.__customPathData = pathData;
  62067. }
  62068. else if (graphicType === 'image') {
  62069. el = new ZImage({});
  62070. el.__customImagePath = elOption.style.image;
  62071. }
  62072. else if (graphicType === 'text') {
  62073. el = new Text({});
  62074. el.__customText = elOption.style.text;
  62075. }
  62076. else {
  62077. var Clz = graphic[graphicType.charAt(0).toUpperCase() + graphicType.slice(1)];
  62078. if (__DEV__) {
  62079. assert$1(Clz, 'graphic type "' + graphicType + '" can not be found.');
  62080. }
  62081. el = new Clz();
  62082. }
  62083. el.__customGraphicType = graphicType;
  62084. el.name = elOption.name;
  62085. return el;
  62086. }
  62087. function updateEl(el, dataIndex, elOption, animatableModel, data, isInit, isRoot) {
  62088. var transitionProps = {};
  62089. var elOptionStyle = elOption.style || {};
  62090. elOption.shape && (transitionProps.shape = clone(elOption.shape));
  62091. elOption.position && (transitionProps.position = elOption.position.slice());
  62092. elOption.scale && (transitionProps.scale = elOption.scale.slice());
  62093. elOption.origin && (transitionProps.origin = elOption.origin.slice());
  62094. elOption.rotation && (transitionProps.rotation = elOption.rotation);
  62095. if (el.type === 'image' && elOption.style) {
  62096. var targetStyle = transitionProps.style = {};
  62097. each$1(['x', 'y', 'width', 'height'], function (prop) {
  62098. prepareStyleTransition(prop, targetStyle, elOptionStyle, el.style, isInit);
  62099. });
  62100. }
  62101. if (el.type === 'text' && elOption.style) {
  62102. var targetStyle = transitionProps.style = {};
  62103. each$1(['x', 'y'], function (prop) {
  62104. prepareStyleTransition(prop, targetStyle, elOptionStyle, el.style, isInit);
  62105. });
  62106. // Compatible with previous: both support
  62107. // textFill and fill, textStroke and stroke in 'text' element.
  62108. !elOptionStyle.hasOwnProperty('textFill') && elOptionStyle.fill && (
  62109. elOptionStyle.textFill = elOptionStyle.fill
  62110. );
  62111. !elOptionStyle.hasOwnProperty('textStroke') && elOptionStyle.stroke && (
  62112. elOptionStyle.textStroke = elOptionStyle.stroke
  62113. );
  62114. }
  62115. if (el.type !== 'group') {
  62116. el.useStyle(elOptionStyle);
  62117. // Init animation.
  62118. if (isInit) {
  62119. el.style.opacity = 0;
  62120. var targetOpacity = elOptionStyle.opacity;
  62121. targetOpacity == null && (targetOpacity = 1);
  62122. initProps(el, {style: {opacity: targetOpacity}}, animatableModel, dataIndex);
  62123. }
  62124. }
  62125. if (isInit) {
  62126. el.attr(transitionProps);
  62127. }
  62128. else {
  62129. updateProps(el, transitionProps, animatableModel, dataIndex);
  62130. }
  62131. // Merge by default.
  62132. // z2 must not be null/undefined, otherwise sort error may occur.
  62133. elOption.hasOwnProperty('z2') && el.attr('z2', elOption.z2 || 0);
  62134. elOption.hasOwnProperty('silent') && el.attr('silent', elOption.silent);
  62135. elOption.hasOwnProperty('invisible') && el.attr('invisible', elOption.invisible);
  62136. elOption.hasOwnProperty('ignore') && el.attr('ignore', elOption.ignore);
  62137. // `elOption.info` enables user to mount some info on
  62138. // elements and use them in event handlers.
  62139. // Update them only when user specified, otherwise, remain.
  62140. elOption.hasOwnProperty('info') && el.attr('info', elOption.info);
  62141. // If `elOption.styleEmphasis` is `false`, remove hover style. The
  62142. // logic is ensured by `graphicUtil.setElementHoverStyle`.
  62143. var styleEmphasis = elOption.styleEmphasis;
  62144. var disableStyleEmphasis = styleEmphasis === false;
  62145. if (!(
  62146. // Try to escapse setting hover style for performance.
  62147. (el.__cusHasEmphStl && styleEmphasis == null)
  62148. || (!el.__cusHasEmphStl && disableStyleEmphasis)
  62149. )) {
  62150. // Should not use graphicUtil.setHoverStyle, since the styleEmphasis
  62151. // should not be share by group and its descendants.
  62152. setElementHoverStyle(el, styleEmphasis);
  62153. el.__cusHasEmphStl = !disableStyleEmphasis;
  62154. }
  62155. if (isRoot) {
  62156. setAsHighDownDispatcher(el, !disableStyleEmphasis);
  62157. }
  62158. }
  62159. function prepareStyleTransition(prop, targetStyle, elOptionStyle, oldElStyle, isInit) {
  62160. if (elOptionStyle[prop] != null && !isInit) {
  62161. targetStyle[prop] = elOptionStyle[prop];
  62162. elOptionStyle[prop] = oldElStyle[prop];
  62163. }
  62164. }
  62165. function makeRenderItem(customSeries, data, ecModel, api) {
  62166. var renderItem = customSeries.get('renderItem');
  62167. var coordSys = customSeries.coordinateSystem;
  62168. var prepareResult = {};
  62169. if (coordSys) {
  62170. if (__DEV__) {
  62171. assert$1(renderItem, 'series.render is required.');
  62172. assert$1(
  62173. coordSys.prepareCustoms || prepareCustoms[coordSys.type],
  62174. 'This coordSys does not support custom series.'
  62175. );
  62176. }
  62177. prepareResult = coordSys.prepareCustoms
  62178. ? coordSys.prepareCustoms()
  62179. : prepareCustoms[coordSys.type](coordSys);
  62180. }
  62181. var userAPI = defaults({
  62182. getWidth: api.getWidth,
  62183. getHeight: api.getHeight,
  62184. getZr: api.getZr,
  62185. getDevicePixelRatio: api.getDevicePixelRatio,
  62186. value: value,
  62187. style: style,
  62188. styleEmphasis: styleEmphasis,
  62189. visual: visual,
  62190. barLayout: barLayout,
  62191. currentSeriesIndices: currentSeriesIndices,
  62192. font: font
  62193. }, prepareResult.api || {});
  62194. var userParams = {
  62195. // The life cycle of context: current round of rendering.
  62196. // The global life cycle is probably not necessary, because
  62197. // user can store global status by themselves.
  62198. context: {},
  62199. seriesId: customSeries.id,
  62200. seriesName: customSeries.name,
  62201. seriesIndex: customSeries.seriesIndex,
  62202. coordSys: prepareResult.coordSys,
  62203. dataInsideLength: data.count(),
  62204. encode: wrapEncodeDef(customSeries.getData())
  62205. };
  62206. // Do not support call `api` asynchronously without dataIndexInside input.
  62207. var currDataIndexInside;
  62208. var currDirty = true;
  62209. var currItemModel;
  62210. var currLabelNormalModel;
  62211. var currLabelEmphasisModel;
  62212. var currVisualColor;
  62213. return function (dataIndexInside, payload) {
  62214. currDataIndexInside = dataIndexInside;
  62215. currDirty = true;
  62216. return renderItem && renderItem(
  62217. defaults({
  62218. dataIndexInside: dataIndexInside,
  62219. dataIndex: data.getRawIndex(dataIndexInside),
  62220. // Can be used for optimization when zoom or roam.
  62221. actionType: payload ? payload.type : null
  62222. }, userParams),
  62223. userAPI
  62224. );
  62225. };
  62226. // Do not update cache until api called.
  62227. function updateCache(dataIndexInside) {
  62228. dataIndexInside == null && (dataIndexInside = currDataIndexInside);
  62229. if (currDirty) {
  62230. currItemModel = data.getItemModel(dataIndexInside);
  62231. currLabelNormalModel = currItemModel.getModel(LABEL_NORMAL);
  62232. currLabelEmphasisModel = currItemModel.getModel(LABEL_EMPHASIS);
  62233. currVisualColor = data.getItemVisual(dataIndexInside, 'color');
  62234. currDirty = false;
  62235. }
  62236. }
  62237. /**
  62238. * @public
  62239. * @param {number|string} dim
  62240. * @param {number} [dataIndexInside=currDataIndexInside]
  62241. * @return {number|string} value
  62242. */
  62243. function value(dim, dataIndexInside) {
  62244. dataIndexInside == null && (dataIndexInside = currDataIndexInside);
  62245. return data.get(data.getDimension(dim || 0), dataIndexInside);
  62246. }
  62247. /**
  62248. * By default, `visual` is applied to style (to support visualMap).
  62249. * `visual.color` is applied at `fill`. If user want apply visual.color on `stroke`,
  62250. * it can be implemented as:
  62251. * `api.style({stroke: api.visual('color'), fill: null})`;
  62252. * @public
  62253. * @param {Object} [extra]
  62254. * @param {number} [dataIndexInside=currDataIndexInside]
  62255. */
  62256. function style(extra, dataIndexInside) {
  62257. dataIndexInside == null && (dataIndexInside = currDataIndexInside);
  62258. updateCache(dataIndexInside);
  62259. var itemStyle = currItemModel.getModel(ITEM_STYLE_NORMAL_PATH).getItemStyle();
  62260. currVisualColor != null && (itemStyle.fill = currVisualColor);
  62261. var opacity = data.getItemVisual(dataIndexInside, 'opacity');
  62262. opacity != null && (itemStyle.opacity = opacity);
  62263. var labelModel = extra
  62264. ? applyExtraBefore(extra, currLabelNormalModel)
  62265. : currLabelNormalModel;
  62266. setTextStyle(itemStyle, labelModel, null, {
  62267. autoColor: currVisualColor,
  62268. isRectText: true
  62269. });
  62270. itemStyle.text = labelModel.getShallow('show')
  62271. ? retrieve2(
  62272. customSeries.getFormattedLabel(dataIndexInside, 'normal'),
  62273. getDefaultLabel(data, dataIndexInside)
  62274. )
  62275. : null;
  62276. extra && applyExtraAfter(itemStyle, extra);
  62277. return itemStyle;
  62278. }
  62279. /**
  62280. * @public
  62281. * @param {Object} [extra]
  62282. * @param {number} [dataIndexInside=currDataIndexInside]
  62283. */
  62284. function styleEmphasis(extra, dataIndexInside) {
  62285. dataIndexInside == null && (dataIndexInside = currDataIndexInside);
  62286. updateCache(dataIndexInside);
  62287. var itemStyle = currItemModel.getModel(ITEM_STYLE_EMPHASIS_PATH).getItemStyle();
  62288. var labelModel = extra
  62289. ? applyExtraBefore(extra, currLabelEmphasisModel)
  62290. : currLabelEmphasisModel;
  62291. setTextStyle(itemStyle, labelModel, null, {
  62292. isRectText: true
  62293. }, true);
  62294. itemStyle.text = labelModel.getShallow('show')
  62295. ? retrieve3(
  62296. customSeries.getFormattedLabel(dataIndexInside, 'emphasis'),
  62297. customSeries.getFormattedLabel(dataIndexInside, 'normal'),
  62298. getDefaultLabel(data, dataIndexInside)
  62299. )
  62300. : null;
  62301. extra && applyExtraAfter(itemStyle, extra);
  62302. return itemStyle;
  62303. }
  62304. /**
  62305. * @public
  62306. * @param {string} visualType
  62307. * @param {number} [dataIndexInside=currDataIndexInside]
  62308. */
  62309. function visual(visualType, dataIndexInside) {
  62310. dataIndexInside == null && (dataIndexInside = currDataIndexInside);
  62311. return data.getItemVisual(dataIndexInside, visualType);
  62312. }
  62313. /**
  62314. * @public
  62315. * @param {number} opt.count Positive interger.
  62316. * @param {number} [opt.barWidth]
  62317. * @param {number} [opt.barMaxWidth]
  62318. * @param {number} [opt.barGap]
  62319. * @param {number} [opt.barCategoryGap]
  62320. * @return {Object} {width, offset, offsetCenter} is not support, return undefined.
  62321. */
  62322. function barLayout(opt) {
  62323. if (coordSys.getBaseAxis) {
  62324. var baseAxis = coordSys.getBaseAxis();
  62325. return getLayoutOnAxis(defaults({axis: baseAxis}, opt), api);
  62326. }
  62327. }
  62328. /**
  62329. * @public
  62330. * @return {Array.<number>}
  62331. */
  62332. function currentSeriesIndices() {
  62333. return ecModel.getCurrentSeriesIndices();
  62334. }
  62335. /**
  62336. * @public
  62337. * @param {Object} opt
  62338. * @param {string} [opt.fontStyle]
  62339. * @param {number} [opt.fontWeight]
  62340. * @param {number} [opt.fontSize]
  62341. * @param {string} [opt.fontFamily]
  62342. * @return {string} font string
  62343. */
  62344. function font(opt) {
  62345. return getFont(opt, ecModel);
  62346. }
  62347. }
  62348. function wrapEncodeDef(data) {
  62349. var encodeDef = {};
  62350. each$1(data.dimensions, function (dimName, dataDimIndex) {
  62351. var dimInfo = data.getDimensionInfo(dimName);
  62352. if (!dimInfo.isExtraCoord) {
  62353. var coordDim = dimInfo.coordDim;
  62354. var dataDims = encodeDef[coordDim] = encodeDef[coordDim] || [];
  62355. dataDims[dimInfo.coordDimIndex] = dataDimIndex;
  62356. }
  62357. });
  62358. return encodeDef;
  62359. }
  62360. function createOrUpdate$1(el, dataIndex, elOption, animatableModel, group, data) {
  62361. el = doCreateOrUpdate(el, dataIndex, elOption, animatableModel, group, data, true);
  62362. el && data.setItemGraphicEl(dataIndex, el);
  62363. return el;
  62364. }
  62365. function doCreateOrUpdate(el, dataIndex, elOption, animatableModel, group, data, isRoot) {
  62366. // [Rule]
  62367. // By default, follow merge mode.
  62368. // (It probably brings benifit for performance in some cases of large data, where
  62369. // user program can be optimized to that only updated props needed to be re-calculated,
  62370. // or according to `actionType` some calculation can be skipped.)
  62371. // If `renderItem` returns `null`/`undefined`/`false`, remove the previous el if existing.
  62372. // (It seems that violate the "merge" principle, but most of users probably intuitively
  62373. // regard "return;" as "show nothing element whatever", so make a exception to meet the
  62374. // most cases.)
  62375. var simplyRemove = !elOption; // `null`/`undefined`/`false`
  62376. elOption = elOption || {};
  62377. var elOptionType = elOption.type;
  62378. var elOptionShape = elOption.shape;
  62379. var elOptionStyle = elOption.style;
  62380. if (el && (
  62381. simplyRemove
  62382. // || elOption.$merge === false
  62383. // If `elOptionType` is `null`, follow the merge principle.
  62384. || (elOptionType != null
  62385. && elOptionType !== el.__customGraphicType
  62386. )
  62387. || (elOptionType === 'path'
  62388. && hasOwnPathData(elOptionShape) && getPathData(elOptionShape) !== el.__customPathData
  62389. )
  62390. || (elOptionType === 'image'
  62391. && hasOwn(elOptionStyle, 'image') && elOptionStyle.image !== el.__customImagePath
  62392. )
  62393. // FIXME test and remove this restriction?
  62394. || (elOptionType === 'text'
  62395. && hasOwn(elOptionShape, 'text') && elOptionStyle.text !== el.__customText
  62396. )
  62397. )) {
  62398. group.remove(el);
  62399. el = null;
  62400. }
  62401. // `elOption.type` is undefined when `renderItem` returns nothing.
  62402. if (simplyRemove) {
  62403. return;
  62404. }
  62405. var isInit = !el;
  62406. !el && (el = createEl(elOption));
  62407. updateEl(el, dataIndex, elOption, animatableModel, data, isInit, isRoot);
  62408. if (elOptionType === 'group') {
  62409. mergeChildren(el, dataIndex, elOption, animatableModel, data);
  62410. }
  62411. // Always add whatever already added to ensure sequence.
  62412. group.add(el);
  62413. return el;
  62414. }
  62415. // Usage:
  62416. // (1) By default, `elOption.$mergeChildren` is `'byIndex'`, which indicates that
  62417. // the existing children will not be removed, and enables the feature that
  62418. // update some of the props of some of the children simply by construct
  62419. // the returned children of `renderItem` like:
  62420. // `var children = group.children = []; children[3] = {opacity: 0.5};`
  62421. // (2) If `elOption.$mergeChildren` is `'byName'`, add/update/remove children
  62422. // by child.name. But that might be lower performance.
  62423. // (3) If `elOption.$mergeChildren` is `false`, the existing children will be
  62424. // replaced totally.
  62425. // (4) If `!elOption.children`, following the "merge" principle, nothing will happen.
  62426. //
  62427. // For implementation simpleness, do not provide a direct way to remove sinlge
  62428. // child (otherwise the total indicies of the children array have to be modified).
  62429. // User can remove a single child by set its `ignore` as `true` or replace
  62430. // it by another element, where its `$merge` can be set as `true` if necessary.
  62431. function mergeChildren(el, dataIndex, elOption, animatableModel, data) {
  62432. var newChildren = elOption.children;
  62433. var newLen = newChildren ? newChildren.length : 0;
  62434. var mergeChildren = elOption.$mergeChildren;
  62435. // `diffChildrenByName` has been deprecated.
  62436. var byName = mergeChildren === 'byName' || elOption.diffChildrenByName;
  62437. var notMerge = mergeChildren === false;
  62438. // For better performance on roam update, only enter if necessary.
  62439. if (!newLen && !byName && !notMerge) {
  62440. return;
  62441. }
  62442. if (byName) {
  62443. diffGroupChildren({
  62444. oldChildren: el.children() || [],
  62445. newChildren: newChildren || [],
  62446. dataIndex: dataIndex,
  62447. animatableModel: animatableModel,
  62448. group: el,
  62449. data: data
  62450. });
  62451. return;
  62452. }
  62453. notMerge && el.removeAll();
  62454. // Mapping children of a group simply by index, which
  62455. // might be better performance.
  62456. var index = 0;
  62457. for (; index < newLen; index++) {
  62458. newChildren[index] && doCreateOrUpdate(
  62459. el.childAt(index),
  62460. dataIndex,
  62461. newChildren[index],
  62462. animatableModel,
  62463. el,
  62464. data
  62465. );
  62466. }
  62467. if (__DEV__) {
  62468. assert$1(
  62469. !notMerge || el.childCount() === index,
  62470. 'MUST NOT contain empty item in children array when `group.$mergeChildren` is `false`.'
  62471. );
  62472. }
  62473. }
  62474. function diffGroupChildren(context) {
  62475. (new DataDiffer(
  62476. context.oldChildren,
  62477. context.newChildren,
  62478. getKey,
  62479. getKey,
  62480. context
  62481. ))
  62482. .add(processAddUpdate)
  62483. .update(processAddUpdate)
  62484. .remove(processRemove)
  62485. .execute();
  62486. }
  62487. function getKey(item, idx) {
  62488. var name = item && item.name;
  62489. return name != null ? name : GROUP_DIFF_PREFIX + idx;
  62490. }
  62491. function processAddUpdate(newIndex, oldIndex) {
  62492. var context = this.context;
  62493. var childOption = newIndex != null ? context.newChildren[newIndex] : null;
  62494. var child = oldIndex != null ? context.oldChildren[oldIndex] : null;
  62495. doCreateOrUpdate(
  62496. child,
  62497. context.dataIndex,
  62498. childOption,
  62499. context.animatableModel,
  62500. context.group,
  62501. context.data
  62502. );
  62503. }
  62504. // `graphic#applyDefaultTextStyle` will cache
  62505. // textFill, textStroke, textStrokeWidth.
  62506. // We have to do this trick.
  62507. function applyExtraBefore(extra, model) {
  62508. var dummyModel = new Model({}, model);
  62509. each$1(CACHED_LABEL_STYLE_PROPERTIES$1, function (stylePropName, modelPropName) {
  62510. if (extra.hasOwnProperty(stylePropName)) {
  62511. dummyModel.option[modelPropName] = extra[stylePropName];
  62512. }
  62513. });
  62514. return dummyModel;
  62515. }
  62516. function applyExtraAfter(itemStyle, extra) {
  62517. for (var key in extra) {
  62518. if (extra.hasOwnProperty(key)
  62519. || !CACHED_LABEL_STYLE_PROPERTIES$1.hasOwnProperty(key)
  62520. ) {
  62521. itemStyle[key] = extra[key];
  62522. }
  62523. }
  62524. }
  62525. function processRemove(oldIndex) {
  62526. var context = this.context;
  62527. var child = context.oldChildren[oldIndex];
  62528. child && context.group.remove(child);
  62529. }
  62530. function getPathData(shape) {
  62531. // "d" follows the SVG convention.
  62532. return shape && (shape.pathData || shape.d);
  62533. }
  62534. function hasOwnPathData(shape) {
  62535. return shape && (shape.hasOwnProperty('pathData') || shape.hasOwnProperty('d'));
  62536. }
  62537. function hasOwn(host, prop) {
  62538. return host && host.hasOwnProperty(prop);
  62539. }
  62540. /*
  62541. * Licensed to the Apache Software Foundation (ASF) under one
  62542. * or more contributor license agreements. See the NOTICE file
  62543. * distributed with this work for additional information
  62544. * regarding copyright ownership. The ASF licenses this file
  62545. * to you under the Apache License, Version 2.0 (the
  62546. * "License"); you may not use this file except in compliance
  62547. * with the License. You may obtain a copy of the License at
  62548. *
  62549. * http://www.apache.org/licenses/LICENSE-2.0
  62550. *
  62551. * Unless required by applicable law or agreed to in writing,
  62552. * software distributed under the License is distributed on an
  62553. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  62554. * KIND, either express or implied. See the License for the
  62555. * specific language governing permissions and limitations
  62556. * under the License.
  62557. */
  62558. /*
  62559. * Licensed to the Apache Software Foundation (ASF) under one
  62560. * or more contributor license agreements. See the NOTICE file
  62561. * distributed with this work for additional information
  62562. * regarding copyright ownership. The ASF licenses this file
  62563. * to you under the Apache License, Version 2.0 (the
  62564. * "License"); you may not use this file except in compliance
  62565. * with the License. You may obtain a copy of the License at
  62566. *
  62567. * http://www.apache.org/licenses/LICENSE-2.0
  62568. *
  62569. * Unless required by applicable law or agreed to in writing,
  62570. * software distributed under the License is distributed on an
  62571. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  62572. * KIND, either express or implied. See the License for the
  62573. * specific language governing permissions and limitations
  62574. * under the License.
  62575. */
  62576. function getSeriesStackId$1(seriesModel) {
  62577. return seriesModel.get('stack')
  62578. || '__ec_stack_' + seriesModel.seriesIndex;
  62579. }
  62580. function getAxisKey$1(polar, axis) {
  62581. return axis.dim + polar.model.componentIndex;
  62582. }
  62583. /**
  62584. * @param {string} seriesType
  62585. * @param {module:echarts/model/Global} ecModel
  62586. * @param {module:echarts/ExtensionAPI} api
  62587. */
  62588. function barLayoutPolar(seriesType, ecModel, api) {
  62589. var lastStackCoords = {};
  62590. var barWidthAndOffset = calRadialBar(
  62591. filter(
  62592. ecModel.getSeriesByType(seriesType),
  62593. function (seriesModel) {
  62594. return !ecModel.isSeriesFiltered(seriesModel)
  62595. && seriesModel.coordinateSystem
  62596. && seriesModel.coordinateSystem.type === 'polar';
  62597. }
  62598. )
  62599. );
  62600. ecModel.eachSeriesByType(seriesType, function (seriesModel) {
  62601. // Check series coordinate, do layout for polar only
  62602. if (seriesModel.coordinateSystem.type !== 'polar') {
  62603. return;
  62604. }
  62605. var data = seriesModel.getData();
  62606. var polar = seriesModel.coordinateSystem;
  62607. var baseAxis = polar.getBaseAxis();
  62608. var axisKey = getAxisKey$1(polar, baseAxis);
  62609. var stackId = getSeriesStackId$1(seriesModel);
  62610. var columnLayoutInfo
  62611. = barWidthAndOffset[axisKey][stackId];
  62612. var columnOffset = columnLayoutInfo.offset;
  62613. var columnWidth = columnLayoutInfo.width;
  62614. var valueAxis = polar.getOtherAxis(baseAxis);
  62615. var cx = seriesModel.coordinateSystem.cx;
  62616. var cy = seriesModel.coordinateSystem.cy;
  62617. var barMinHeight = seriesModel.get('barMinHeight') || 0;
  62618. var barMinAngle = seriesModel.get('barMinAngle') || 0;
  62619. lastStackCoords[stackId] = lastStackCoords[stackId] || [];
  62620. var valueDim = data.mapDimension(valueAxis.dim);
  62621. var baseDim = data.mapDimension(baseAxis.dim);
  62622. var stacked = isDimensionStacked(data, valueDim /*, baseDim*/);
  62623. var valueAxisStart = valueAxis.getExtent()[0];
  62624. for (var idx = 0, len = data.count(); idx < len; idx++) {
  62625. var value = data.get(valueDim, idx);
  62626. var baseValue = data.get(baseDim, idx);
  62627. if (isNaN(value)) {
  62628. continue;
  62629. }
  62630. var sign = value >= 0 ? 'p' : 'n';
  62631. var baseCoord = valueAxisStart;
  62632. // Because of the barMinHeight, we can not use the value in
  62633. // stackResultDimension directly.
  62634. // Only ordinal axis can be stacked.
  62635. if (stacked) {
  62636. if (!lastStackCoords[stackId][baseValue]) {
  62637. lastStackCoords[stackId][baseValue] = {
  62638. p: valueAxisStart, // Positive stack
  62639. n: valueAxisStart // Negative stack
  62640. };
  62641. }
  62642. // Should also consider #4243
  62643. baseCoord = lastStackCoords[stackId][baseValue][sign];
  62644. }
  62645. var r0;
  62646. var r;
  62647. var startAngle;
  62648. var endAngle;
  62649. // radial sector
  62650. if (valueAxis.dim === 'radius') {
  62651. var radiusSpan = valueAxis.dataToRadius(value) - valueAxisStart;
  62652. var angle = baseAxis.dataToAngle(baseValue);
  62653. if (Math.abs(radiusSpan) < barMinHeight) {
  62654. radiusSpan = (radiusSpan < 0 ? -1 : 1) * barMinHeight;
  62655. }
  62656. r0 = baseCoord;
  62657. r = baseCoord + radiusSpan;
  62658. startAngle = angle - columnOffset;
  62659. endAngle = startAngle - columnWidth;
  62660. stacked && (lastStackCoords[stackId][baseValue][sign] = r);
  62661. }
  62662. // tangential sector
  62663. else {
  62664. // angleAxis must be clamped.
  62665. var angleSpan = valueAxis.dataToAngle(value, true) - valueAxisStart;
  62666. var radius = baseAxis.dataToRadius(baseValue);
  62667. if (Math.abs(angleSpan) < barMinAngle) {
  62668. angleSpan = (angleSpan < 0 ? -1 : 1) * barMinAngle;
  62669. }
  62670. r0 = radius + columnOffset;
  62671. r = r0 + columnWidth;
  62672. startAngle = baseCoord;
  62673. endAngle = baseCoord + angleSpan;
  62674. // if the previous stack is at the end of the ring,
  62675. // add a round to differentiate it from origin
  62676. // var extent = angleAxis.getExtent();
  62677. // var stackCoord = angle;
  62678. // if (stackCoord === extent[0] && value > 0) {
  62679. // stackCoord = extent[1];
  62680. // }
  62681. // else if (stackCoord === extent[1] && value < 0) {
  62682. // stackCoord = extent[0];
  62683. // }
  62684. stacked && (lastStackCoords[stackId][baseValue][sign] = endAngle);
  62685. }
  62686. data.setItemLayout(idx, {
  62687. cx: cx,
  62688. cy: cy,
  62689. r0: r0,
  62690. r: r,
  62691. // Consider that positive angle is anti-clockwise,
  62692. // while positive radian of sector is clockwise
  62693. startAngle: -startAngle * Math.PI / 180,
  62694. endAngle: -endAngle * Math.PI / 180
  62695. });
  62696. }
  62697. }, this);
  62698. }
  62699. /**
  62700. * Calculate bar width and offset for radial bar charts
  62701. */
  62702. function calRadialBar(barSeries, api) {
  62703. // Columns info on each category axis. Key is polar name
  62704. var columnsMap = {};
  62705. each$1(barSeries, function (seriesModel, idx) {
  62706. var data = seriesModel.getData();
  62707. var polar = seriesModel.coordinateSystem;
  62708. var baseAxis = polar.getBaseAxis();
  62709. var axisKey = getAxisKey$1(polar, baseAxis);
  62710. var axisExtent = baseAxis.getExtent();
  62711. var bandWidth = baseAxis.type === 'category'
  62712. ? baseAxis.getBandWidth()
  62713. : (Math.abs(axisExtent[1] - axisExtent[0]) / data.count());
  62714. var columnsOnAxis = columnsMap[axisKey] || {
  62715. bandWidth: bandWidth,
  62716. remainedWidth: bandWidth,
  62717. autoWidthCount: 0,
  62718. categoryGap: '20%',
  62719. gap: '30%',
  62720. stacks: {}
  62721. };
  62722. var stacks = columnsOnAxis.stacks;
  62723. columnsMap[axisKey] = columnsOnAxis;
  62724. var stackId = getSeriesStackId$1(seriesModel);
  62725. if (!stacks[stackId]) {
  62726. columnsOnAxis.autoWidthCount++;
  62727. }
  62728. stacks[stackId] = stacks[stackId] || {
  62729. width: 0,
  62730. maxWidth: 0
  62731. };
  62732. var barWidth = parsePercent$1(
  62733. seriesModel.get('barWidth'),
  62734. bandWidth
  62735. );
  62736. var barMaxWidth = parsePercent$1(
  62737. seriesModel.get('barMaxWidth'),
  62738. bandWidth
  62739. );
  62740. var barGap = seriesModel.get('barGap');
  62741. var barCategoryGap = seriesModel.get('barCategoryGap');
  62742. if (barWidth && !stacks[stackId].width) {
  62743. barWidth = Math.min(columnsOnAxis.remainedWidth, barWidth);
  62744. stacks[stackId].width = barWidth;
  62745. columnsOnAxis.remainedWidth -= barWidth;
  62746. }
  62747. barMaxWidth && (stacks[stackId].maxWidth = barMaxWidth);
  62748. (barGap != null) && (columnsOnAxis.gap = barGap);
  62749. (barCategoryGap != null) && (columnsOnAxis.categoryGap = barCategoryGap);
  62750. });
  62751. var result = {};
  62752. each$1(columnsMap, function (columnsOnAxis, coordSysName) {
  62753. result[coordSysName] = {};
  62754. var stacks = columnsOnAxis.stacks;
  62755. var bandWidth = columnsOnAxis.bandWidth;
  62756. var categoryGap = parsePercent$1(columnsOnAxis.categoryGap, bandWidth);
  62757. var barGapPercent = parsePercent$1(columnsOnAxis.gap, 1);
  62758. var remainedWidth = columnsOnAxis.remainedWidth;
  62759. var autoWidthCount = columnsOnAxis.autoWidthCount;
  62760. var autoWidth = (remainedWidth - categoryGap)
  62761. / (autoWidthCount + (autoWidthCount - 1) * barGapPercent);
  62762. autoWidth = Math.max(autoWidth, 0);
  62763. // Find if any auto calculated bar exceeded maxBarWidth
  62764. each$1(stacks, function (column, stack) {
  62765. var maxWidth = column.maxWidth;
  62766. if (maxWidth && maxWidth < autoWidth) {
  62767. maxWidth = Math.min(maxWidth, remainedWidth);
  62768. if (column.width) {
  62769. maxWidth = Math.min(maxWidth, column.width);
  62770. }
  62771. remainedWidth -= maxWidth;
  62772. column.width = maxWidth;
  62773. autoWidthCount--;
  62774. }
  62775. });
  62776. // Recalculate width again
  62777. autoWidth = (remainedWidth - categoryGap)
  62778. / (autoWidthCount + (autoWidthCount - 1) * barGapPercent);
  62779. autoWidth = Math.max(autoWidth, 0);
  62780. var widthSum = 0;
  62781. var lastColumn;
  62782. each$1(stacks, function (column, idx) {
  62783. if (!column.width) {
  62784. column.width = autoWidth;
  62785. }
  62786. lastColumn = column;
  62787. widthSum += column.width * (1 + barGapPercent);
  62788. });
  62789. if (lastColumn) {
  62790. widthSum -= lastColumn.width * barGapPercent;
  62791. }
  62792. var offset = -widthSum / 2;
  62793. each$1(stacks, function (column, stackId) {
  62794. result[coordSysName][stackId] = result[coordSysName][stackId] || {
  62795. offset: offset,
  62796. width: column.width
  62797. };
  62798. offset += column.width * (1 + barGapPercent);
  62799. });
  62800. });
  62801. return result;
  62802. }
  62803. /*
  62804. * Licensed to the Apache Software Foundation (ASF) under one
  62805. * or more contributor license agreements. See the NOTICE file
  62806. * distributed with this work for additional information
  62807. * regarding copyright ownership. The ASF licenses this file
  62808. * to you under the Apache License, Version 2.0 (the
  62809. * "License"); you may not use this file except in compliance
  62810. * with the License. You may obtain a copy of the License at
  62811. *
  62812. * http://www.apache.org/licenses/LICENSE-2.0
  62813. *
  62814. * Unless required by applicable law or agreed to in writing,
  62815. * software distributed under the License is distributed on an
  62816. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  62817. * KIND, either express or implied. See the License for the
  62818. * specific language governing permissions and limitations
  62819. * under the License.
  62820. */
  62821. function RadiusAxis(scale, radiusExtent) {
  62822. Axis.call(this, 'radius', scale, radiusExtent);
  62823. /**
  62824. * Axis type
  62825. * - 'category'
  62826. * - 'value'
  62827. * - 'time'
  62828. * - 'log'
  62829. * @type {string}
  62830. */
  62831. this.type = 'category';
  62832. }
  62833. RadiusAxis.prototype = {
  62834. constructor: RadiusAxis,
  62835. /**
  62836. * @override
  62837. */
  62838. pointToData: function (point, clamp) {
  62839. return this.polar.pointToData(point, clamp)[this.dim === 'radius' ? 0 : 1];
  62840. },
  62841. dataToRadius: Axis.prototype.dataToCoord,
  62842. radiusToData: Axis.prototype.coordToData
  62843. };
  62844. inherits(RadiusAxis, Axis);
  62845. /*
  62846. * Licensed to the Apache Software Foundation (ASF) under one
  62847. * or more contributor license agreements. See the NOTICE file
  62848. * distributed with this work for additional information
  62849. * regarding copyright ownership. The ASF licenses this file
  62850. * to you under the Apache License, Version 2.0 (the
  62851. * "License"); you may not use this file except in compliance
  62852. * with the License. You may obtain a copy of the License at
  62853. *
  62854. * http://www.apache.org/licenses/LICENSE-2.0
  62855. *
  62856. * Unless required by applicable law or agreed to in writing,
  62857. * software distributed under the License is distributed on an
  62858. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  62859. * KIND, either express or implied. See the License for the
  62860. * specific language governing permissions and limitations
  62861. * under the License.
  62862. */
  62863. var inner$12 = makeInner();
  62864. function AngleAxis(scale, angleExtent) {
  62865. angleExtent = angleExtent || [0, 360];
  62866. Axis.call(this, 'angle', scale, angleExtent);
  62867. /**
  62868. * Axis type
  62869. * - 'category'
  62870. * - 'value'
  62871. * - 'time'
  62872. * - 'log'
  62873. * @type {string}
  62874. */
  62875. this.type = 'category';
  62876. }
  62877. AngleAxis.prototype = {
  62878. constructor: AngleAxis,
  62879. /**
  62880. * @override
  62881. */
  62882. pointToData: function (point, clamp) {
  62883. return this.polar.pointToData(point, clamp)[this.dim === 'radius' ? 0 : 1];
  62884. },
  62885. dataToAngle: Axis.prototype.dataToCoord,
  62886. angleToData: Axis.prototype.coordToData,
  62887. /**
  62888. * Only be called in category axis.
  62889. * Angle axis uses text height to decide interval
  62890. *
  62891. * @override
  62892. * @return {number} Auto interval for cateogry axis tick and label
  62893. */
  62894. calculateCategoryInterval: function () {
  62895. var axis = this;
  62896. var labelModel = axis.getLabelModel();
  62897. var ordinalScale = axis.scale;
  62898. var ordinalExtent = ordinalScale.getExtent();
  62899. // Providing this method is for optimization:
  62900. // avoid generating a long array by `getTicks`
  62901. // in large category data case.
  62902. var tickCount = ordinalScale.count();
  62903. if (ordinalExtent[1] - ordinalExtent[0] < 1) {
  62904. return 0;
  62905. }
  62906. var tickValue = ordinalExtent[0];
  62907. var unitSpan = axis.dataToCoord(tickValue + 1) - axis.dataToCoord(tickValue);
  62908. var unitH = Math.abs(unitSpan);
  62909. // Not precise, just use height as text width
  62910. // and each distance from axis line yet.
  62911. var rect = getBoundingRect(
  62912. tickValue, labelModel.getFont(), 'center', 'top'
  62913. );
  62914. var maxH = Math.max(rect.height, 7);
  62915. var dh = maxH / unitH;
  62916. // 0/0 is NaN, 1/0 is Infinity.
  62917. isNaN(dh) && (dh = Infinity);
  62918. var interval = Math.max(0, Math.floor(dh));
  62919. var cache = inner$12(axis.model);
  62920. var lastAutoInterval = cache.lastAutoInterval;
  62921. var lastTickCount = cache.lastTickCount;
  62922. // Use cache to keep interval stable while moving zoom window,
  62923. // otherwise the calculated interval might jitter when the zoom
  62924. // window size is close to the interval-changing size.
  62925. if (lastAutoInterval != null
  62926. && lastTickCount != null
  62927. && Math.abs(lastAutoInterval - interval) <= 1
  62928. && Math.abs(lastTickCount - tickCount) <= 1
  62929. // Always choose the bigger one, otherwise the critical
  62930. // point is not the same when zooming in or zooming out.
  62931. && lastAutoInterval > interval
  62932. ) {
  62933. interval = lastAutoInterval;
  62934. }
  62935. // Only update cache if cache not used, otherwise the
  62936. // changing of interval is too insensitive.
  62937. else {
  62938. cache.lastTickCount = tickCount;
  62939. cache.lastAutoInterval = interval;
  62940. }
  62941. return interval;
  62942. }
  62943. };
  62944. inherits(AngleAxis, Axis);
  62945. /*
  62946. * Licensed to the Apache Software Foundation (ASF) under one
  62947. * or more contributor license agreements. See the NOTICE file
  62948. * distributed with this work for additional information
  62949. * regarding copyright ownership. The ASF licenses this file
  62950. * to you under the Apache License, Version 2.0 (the
  62951. * "License"); you may not use this file except in compliance
  62952. * with the License. You may obtain a copy of the License at
  62953. *
  62954. * http://www.apache.org/licenses/LICENSE-2.0
  62955. *
  62956. * Unless required by applicable law or agreed to in writing,
  62957. * software distributed under the License is distributed on an
  62958. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  62959. * KIND, either express or implied. See the License for the
  62960. * specific language governing permissions and limitations
  62961. * under the License.
  62962. */
  62963. /**
  62964. * @module echarts/coord/polar/Polar
  62965. */
  62966. /**
  62967. * @alias {module:echarts/coord/polar/Polar}
  62968. * @constructor
  62969. * @param {string} name
  62970. */
  62971. var Polar = function (name) {
  62972. /**
  62973. * @type {string}
  62974. */
  62975. this.name = name || '';
  62976. /**
  62977. * x of polar center
  62978. * @type {number}
  62979. */
  62980. this.cx = 0;
  62981. /**
  62982. * y of polar center
  62983. * @type {number}
  62984. */
  62985. this.cy = 0;
  62986. /**
  62987. * @type {module:echarts/coord/polar/RadiusAxis}
  62988. * @private
  62989. */
  62990. this._radiusAxis = new RadiusAxis();
  62991. /**
  62992. * @type {module:echarts/coord/polar/AngleAxis}
  62993. * @private
  62994. */
  62995. this._angleAxis = new AngleAxis();
  62996. this._radiusAxis.polar = this._angleAxis.polar = this;
  62997. };
  62998. Polar.prototype = {
  62999. type: 'polar',
  63000. axisPointerEnabled: true,
  63001. constructor: Polar,
  63002. /**
  63003. * @param {Array.<string>}
  63004. * @readOnly
  63005. */
  63006. dimensions: ['radius', 'angle'],
  63007. /**
  63008. * @type {module:echarts/coord/PolarModel}
  63009. */
  63010. model: null,
  63011. /**
  63012. * If contain coord
  63013. * @param {Array.<number>} point
  63014. * @return {boolean}
  63015. */
  63016. containPoint: function (point) {
  63017. var coord = this.pointToCoord(point);
  63018. return this._radiusAxis.contain(coord[0])
  63019. && this._angleAxis.contain(coord[1]);
  63020. },
  63021. /**
  63022. * If contain data
  63023. * @param {Array.<number>} data
  63024. * @return {boolean}
  63025. */
  63026. containData: function (data) {
  63027. return this._radiusAxis.containData(data[0])
  63028. && this._angleAxis.containData(data[1]);
  63029. },
  63030. /**
  63031. * @param {string} dim
  63032. * @return {module:echarts/coord/polar/AngleAxis|module:echarts/coord/polar/RadiusAxis}
  63033. */
  63034. getAxis: function (dim) {
  63035. return this['_' + dim + 'Axis'];
  63036. },
  63037. /**
  63038. * @return {Array.<module:echarts/coord/Axis>}
  63039. */
  63040. getAxes: function () {
  63041. return [this._radiusAxis, this._angleAxis];
  63042. },
  63043. /**
  63044. * Get axes by type of scale
  63045. * @param {string} scaleType
  63046. * @return {module:echarts/coord/polar/AngleAxis|module:echarts/coord/polar/RadiusAxis}
  63047. */
  63048. getAxesByScale: function (scaleType) {
  63049. var axes = [];
  63050. var angleAxis = this._angleAxis;
  63051. var radiusAxis = this._radiusAxis;
  63052. angleAxis.scale.type === scaleType && axes.push(angleAxis);
  63053. radiusAxis.scale.type === scaleType && axes.push(radiusAxis);
  63054. return axes;
  63055. },
  63056. /**
  63057. * @return {module:echarts/coord/polar/AngleAxis}
  63058. */
  63059. getAngleAxis: function () {
  63060. return this._angleAxis;
  63061. },
  63062. /**
  63063. * @return {module:echarts/coord/polar/RadiusAxis}
  63064. */
  63065. getRadiusAxis: function () {
  63066. return this._radiusAxis;
  63067. },
  63068. /**
  63069. * @param {module:echarts/coord/polar/Axis}
  63070. * @return {module:echarts/coord/polar/Axis}
  63071. */
  63072. getOtherAxis: function (axis) {
  63073. var angleAxis = this._angleAxis;
  63074. return axis === angleAxis ? this._radiusAxis : angleAxis;
  63075. },
  63076. /**
  63077. * Base axis will be used on stacking.
  63078. *
  63079. * @return {module:echarts/coord/polar/Axis}
  63080. */
  63081. getBaseAxis: function () {
  63082. return this.getAxesByScale('ordinal')[0]
  63083. || this.getAxesByScale('time')[0]
  63084. || this.getAngleAxis();
  63085. },
  63086. /**
  63087. * @param {string} [dim] 'radius' or 'angle' or 'auto' or null/undefined
  63088. * @return {Object} {baseAxes: [], otherAxes: []}
  63089. */
  63090. getTooltipAxes: function (dim) {
  63091. var baseAxis = (dim != null && dim !== 'auto')
  63092. ? this.getAxis(dim) : this.getBaseAxis();
  63093. return {
  63094. baseAxes: [baseAxis],
  63095. otherAxes: [this.getOtherAxis(baseAxis)]
  63096. };
  63097. },
  63098. /**
  63099. * Convert a single data item to (x, y) point.
  63100. * Parameter data is an array which the first element is radius and the second is angle
  63101. * @param {Array.<number>} data
  63102. * @param {boolean} [clamp=false]
  63103. * @return {Array.<number>}
  63104. */
  63105. dataToPoint: function (data, clamp) {
  63106. return this.coordToPoint([
  63107. this._radiusAxis.dataToRadius(data[0], clamp),
  63108. this._angleAxis.dataToAngle(data[1], clamp)
  63109. ]);
  63110. },
  63111. /**
  63112. * Convert a (x, y) point to data
  63113. * @param {Array.<number>} point
  63114. * @param {boolean} [clamp=false]
  63115. * @return {Array.<number>}
  63116. */
  63117. pointToData: function (point, clamp) {
  63118. var coord = this.pointToCoord(point);
  63119. return [
  63120. this._radiusAxis.radiusToData(coord[0], clamp),
  63121. this._angleAxis.angleToData(coord[1], clamp)
  63122. ];
  63123. },
  63124. /**
  63125. * Convert a (x, y) point to (radius, angle) coord
  63126. * @param {Array.<number>} point
  63127. * @return {Array.<number>}
  63128. */
  63129. pointToCoord: function (point) {
  63130. var dx = point[0] - this.cx;
  63131. var dy = point[1] - this.cy;
  63132. var angleAxis = this.getAngleAxis();
  63133. var extent = angleAxis.getExtent();
  63134. var minAngle = Math.min(extent[0], extent[1]);
  63135. var maxAngle = Math.max(extent[0], extent[1]);
  63136. // Fix fixed extent in polarCreator
  63137. // FIXME
  63138. angleAxis.inverse
  63139. ? (minAngle = maxAngle - 360)
  63140. : (maxAngle = minAngle + 360);
  63141. var radius = Math.sqrt(dx * dx + dy * dy);
  63142. dx /= radius;
  63143. dy /= radius;
  63144. var radian = Math.atan2(-dy, dx) / Math.PI * 180;
  63145. // move to angleExtent
  63146. var dir = radian < minAngle ? 1 : -1;
  63147. while (radian < minAngle || radian > maxAngle) {
  63148. radian += dir * 360;
  63149. }
  63150. return [radius, radian];
  63151. },
  63152. /**
  63153. * Convert a (radius, angle) coord to (x, y) point
  63154. * @param {Array.<number>} coord
  63155. * @return {Array.<number>}
  63156. */
  63157. coordToPoint: function (coord) {
  63158. var radius = coord[0];
  63159. var radian = coord[1] / 180 * Math.PI;
  63160. var x = Math.cos(radian) * radius + this.cx;
  63161. // Inverse the y
  63162. var y = -Math.sin(radian) * radius + this.cy;
  63163. return [x, y];
  63164. }
  63165. };
  63166. /*
  63167. * Licensed to the Apache Software Foundation (ASF) under one
  63168. * or more contributor license agreements. See the NOTICE file
  63169. * distributed with this work for additional information
  63170. * regarding copyright ownership. The ASF licenses this file
  63171. * to you under the Apache License, Version 2.0 (the
  63172. * "License"); you may not use this file except in compliance
  63173. * with the License. You may obtain a copy of the License at
  63174. *
  63175. * http://www.apache.org/licenses/LICENSE-2.0
  63176. *
  63177. * Unless required by applicable law or agreed to in writing,
  63178. * software distributed under the License is distributed on an
  63179. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  63180. * KIND, either express or implied. See the License for the
  63181. * specific language governing permissions and limitations
  63182. * under the License.
  63183. */
  63184. var PolarAxisModel = ComponentModel.extend({
  63185. type: 'polarAxis',
  63186. /**
  63187. * @type {module:echarts/coord/polar/AngleAxis|module:echarts/coord/polar/RadiusAxis}
  63188. */
  63189. axis: null,
  63190. /**
  63191. * @override
  63192. */
  63193. getCoordSysModel: function () {
  63194. return this.ecModel.queryComponents({
  63195. mainType: 'polar',
  63196. index: this.option.polarIndex,
  63197. id: this.option.polarId
  63198. })[0];
  63199. }
  63200. });
  63201. merge(PolarAxisModel.prototype, axisModelCommonMixin);
  63202. var polarAxisDefaultExtendedOption = {
  63203. angle: {
  63204. // polarIndex: 0,
  63205. // polarId: '',
  63206. startAngle: 90,
  63207. clockwise: true,
  63208. splitNumber: 12,
  63209. axisLabel: {
  63210. rotate: false
  63211. }
  63212. },
  63213. radius: {
  63214. // polarIndex: 0,
  63215. // polarId: '',
  63216. splitNumber: 5
  63217. }
  63218. };
  63219. function getAxisType$3(axisDim, option) {
  63220. // Default axis with data is category axis
  63221. return option.type || (option.data ? 'category' : 'value');
  63222. }
  63223. axisModelCreator('angle', PolarAxisModel, getAxisType$3, polarAxisDefaultExtendedOption.angle);
  63224. axisModelCreator('radius', PolarAxisModel, getAxisType$3, polarAxisDefaultExtendedOption.radius);
  63225. /*
  63226. * Licensed to the Apache Software Foundation (ASF) under one
  63227. * or more contributor license agreements. See the NOTICE file
  63228. * distributed with this work for additional information
  63229. * regarding copyright ownership. The ASF licenses this file
  63230. * to you under the Apache License, Version 2.0 (the
  63231. * "License"); you may not use this file except in compliance
  63232. * with the License. You may obtain a copy of the License at
  63233. *
  63234. * http://www.apache.org/licenses/LICENSE-2.0
  63235. *
  63236. * Unless required by applicable law or agreed to in writing,
  63237. * software distributed under the License is distributed on an
  63238. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  63239. * KIND, either express or implied. See the License for the
  63240. * specific language governing permissions and limitations
  63241. * under the License.
  63242. */
  63243. extendComponentModel({
  63244. type: 'polar',
  63245. dependencies: ['polarAxis', 'angleAxis'],
  63246. /**
  63247. * @type {module:echarts/coord/polar/Polar}
  63248. */
  63249. coordinateSystem: null,
  63250. /**
  63251. * @param {string} axisType
  63252. * @return {module:echarts/coord/polar/AxisModel}
  63253. */
  63254. findAxisModel: function (axisType) {
  63255. var foundAxisModel;
  63256. var ecModel = this.ecModel;
  63257. ecModel.eachComponent(axisType, function (axisModel) {
  63258. if (axisModel.getCoordSysModel() === this) {
  63259. foundAxisModel = axisModel;
  63260. }
  63261. }, this);
  63262. return foundAxisModel;
  63263. },
  63264. defaultOption: {
  63265. zlevel: 0,
  63266. z: 0,
  63267. center: ['50%', '50%'],
  63268. radius: '80%'
  63269. }
  63270. });
  63271. /*
  63272. * Licensed to the Apache Software Foundation (ASF) under one
  63273. * or more contributor license agreements. See the NOTICE file
  63274. * distributed with this work for additional information
  63275. * regarding copyright ownership. The ASF licenses this file
  63276. * to you under the Apache License, Version 2.0 (the
  63277. * "License"); you may not use this file except in compliance
  63278. * with the License. You may obtain a copy of the License at
  63279. *
  63280. * http://www.apache.org/licenses/LICENSE-2.0
  63281. *
  63282. * Unless required by applicable law or agreed to in writing,
  63283. * software distributed under the License is distributed on an
  63284. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  63285. * KIND, either express or implied. See the License for the
  63286. * specific language governing permissions and limitations
  63287. * under the License.
  63288. */
  63289. // TODO Axis scale
  63290. /**
  63291. * Resize method bound to the polar
  63292. * @param {module:echarts/coord/polar/PolarModel} polarModel
  63293. * @param {module:echarts/ExtensionAPI} api
  63294. */
  63295. function resizePolar(polar, polarModel, api) {
  63296. var center = polarModel.get('center');
  63297. var width = api.getWidth();
  63298. var height = api.getHeight();
  63299. polar.cx = parsePercent$1(center[0], width);
  63300. polar.cy = parsePercent$1(center[1], height);
  63301. var radiusAxis = polar.getRadiusAxis();
  63302. var size = Math.min(width, height) / 2;
  63303. var radius = parsePercent$1(polarModel.get('radius'), size);
  63304. radiusAxis.inverse
  63305. ? radiusAxis.setExtent(radius, 0)
  63306. : radiusAxis.setExtent(0, radius);
  63307. }
  63308. /**
  63309. * Update polar
  63310. */
  63311. function updatePolarScale(ecModel, api) {
  63312. var polar = this;
  63313. var angleAxis = polar.getAngleAxis();
  63314. var radiusAxis = polar.getRadiusAxis();
  63315. // Reset scale
  63316. angleAxis.scale.setExtent(Infinity, -Infinity);
  63317. radiusAxis.scale.setExtent(Infinity, -Infinity);
  63318. ecModel.eachSeries(function (seriesModel) {
  63319. if (seriesModel.coordinateSystem === polar) {
  63320. var data = seriesModel.getData();
  63321. each$1(data.mapDimension('radius', true), function (dim) {
  63322. radiusAxis.scale.unionExtentFromData(
  63323. data, getStackedDimension(data, dim)
  63324. );
  63325. });
  63326. each$1(data.mapDimension('angle', true), function (dim) {
  63327. angleAxis.scale.unionExtentFromData(
  63328. data, getStackedDimension(data, dim)
  63329. );
  63330. });
  63331. }
  63332. });
  63333. niceScaleExtent(angleAxis.scale, angleAxis.model);
  63334. niceScaleExtent(radiusAxis.scale, radiusAxis.model);
  63335. // Fix extent of category angle axis
  63336. if (angleAxis.type === 'category' && !angleAxis.onBand) {
  63337. var extent = angleAxis.getExtent();
  63338. var diff = 360 / angleAxis.scale.count();
  63339. angleAxis.inverse ? (extent[1] += diff) : (extent[1] -= diff);
  63340. angleAxis.setExtent(extent[0], extent[1]);
  63341. }
  63342. }
  63343. /**
  63344. * Set common axis properties
  63345. * @param {module:echarts/coord/polar/AngleAxis|module:echarts/coord/polar/RadiusAxis}
  63346. * @param {module:echarts/coord/polar/AxisModel}
  63347. * @inner
  63348. */
  63349. function setAxis(axis, axisModel) {
  63350. axis.type = axisModel.get('type');
  63351. axis.scale = createScaleByModel(axisModel);
  63352. axis.onBand = axisModel.get('boundaryGap') && axis.type === 'category';
  63353. axis.inverse = axisModel.get('inverse');
  63354. if (axisModel.mainType === 'angleAxis') {
  63355. axis.inverse ^= axisModel.get('clockwise');
  63356. var startAngle = axisModel.get('startAngle');
  63357. axis.setExtent(startAngle, startAngle + (axis.inverse ? -360 : 360));
  63358. }
  63359. // Inject axis instance
  63360. axisModel.axis = axis;
  63361. axis.model = axisModel;
  63362. }
  63363. var polarCreator = {
  63364. dimensions: Polar.prototype.dimensions,
  63365. create: function (ecModel, api) {
  63366. var polarList = [];
  63367. ecModel.eachComponent('polar', function (polarModel, idx) {
  63368. var polar = new Polar(idx);
  63369. // Inject resize and update method
  63370. polar.update = updatePolarScale;
  63371. var radiusAxis = polar.getRadiusAxis();
  63372. var angleAxis = polar.getAngleAxis();
  63373. var radiusAxisModel = polarModel.findAxisModel('radiusAxis');
  63374. var angleAxisModel = polarModel.findAxisModel('angleAxis');
  63375. setAxis(radiusAxis, radiusAxisModel);
  63376. setAxis(angleAxis, angleAxisModel);
  63377. resizePolar(polar, polarModel, api);
  63378. polarList.push(polar);
  63379. polarModel.coordinateSystem = polar;
  63380. polar.model = polarModel;
  63381. });
  63382. // Inject coordinateSystem to series
  63383. ecModel.eachSeries(function (seriesModel) {
  63384. if (seriesModel.get('coordinateSystem') === 'polar') {
  63385. var polarModel = ecModel.queryComponents({
  63386. mainType: 'polar',
  63387. index: seriesModel.get('polarIndex'),
  63388. id: seriesModel.get('polarId')
  63389. })[0];
  63390. if (__DEV__) {
  63391. if (!polarModel) {
  63392. throw new Error(
  63393. 'Polar "' + retrieve(
  63394. seriesModel.get('polarIndex'),
  63395. seriesModel.get('polarId'),
  63396. 0
  63397. ) + '" not found'
  63398. );
  63399. }
  63400. }
  63401. seriesModel.coordinateSystem = polarModel.coordinateSystem;
  63402. }
  63403. });
  63404. return polarList;
  63405. }
  63406. };
  63407. CoordinateSystemManager.register('polar', polarCreator);
  63408. /*
  63409. * Licensed to the Apache Software Foundation (ASF) under one
  63410. * or more contributor license agreements. See the NOTICE file
  63411. * distributed with this work for additional information
  63412. * regarding copyright ownership. The ASF licenses this file
  63413. * to you under the Apache License, Version 2.0 (the
  63414. * "License"); you may not use this file except in compliance
  63415. * with the License. You may obtain a copy of the License at
  63416. *
  63417. * http://www.apache.org/licenses/LICENSE-2.0
  63418. *
  63419. * Unless required by applicable law or agreed to in writing,
  63420. * software distributed under the License is distributed on an
  63421. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  63422. * KIND, either express or implied. See the License for the
  63423. * specific language governing permissions and limitations
  63424. * under the License.
  63425. */
  63426. var elementList$1 = ['axisLine', 'axisLabel', 'axisTick', 'splitLine', 'splitArea'];
  63427. function getAxisLineShape(polar, rExtent, angle) {
  63428. rExtent[1] > rExtent[0] && (rExtent = rExtent.slice().reverse());
  63429. var start = polar.coordToPoint([rExtent[0], angle]);
  63430. var end = polar.coordToPoint([rExtent[1], angle]);
  63431. return {
  63432. x1: start[0],
  63433. y1: start[1],
  63434. x2: end[0],
  63435. y2: end[1]
  63436. };
  63437. }
  63438. function getRadiusIdx(polar) {
  63439. var radiusAxis = polar.getRadiusAxis();
  63440. return radiusAxis.inverse ? 0 : 1;
  63441. }
  63442. // Remove the last tick which will overlap the first tick
  63443. function fixAngleOverlap(list) {
  63444. var firstItem = list[0];
  63445. var lastItem = list[list.length - 1];
  63446. if (firstItem
  63447. && lastItem
  63448. && Math.abs(Math.abs(firstItem.coord - lastItem.coord) - 360) < 1e-4
  63449. ) {
  63450. list.pop();
  63451. }
  63452. }
  63453. AxisView.extend({
  63454. type: 'angleAxis',
  63455. axisPointerClass: 'PolarAxisPointer',
  63456. render: function (angleAxisModel, ecModel) {
  63457. this.group.removeAll();
  63458. if (!angleAxisModel.get('show')) {
  63459. return;
  63460. }
  63461. var angleAxis = angleAxisModel.axis;
  63462. var polar = angleAxis.polar;
  63463. var radiusExtent = polar.getRadiusAxis().getExtent();
  63464. var ticksAngles = angleAxis.getTicksCoords();
  63465. var labels = map(angleAxis.getViewLabels(), function (labelItem) {
  63466. var labelItem = clone(labelItem);
  63467. labelItem.coord = angleAxis.dataToCoord(labelItem.tickValue);
  63468. return labelItem;
  63469. });
  63470. fixAngleOverlap(labels);
  63471. fixAngleOverlap(ticksAngles);
  63472. each$1(elementList$1, function (name) {
  63473. if (angleAxisModel.get(name + '.show')
  63474. && (!angleAxis.scale.isBlank() || name === 'axisLine')
  63475. ) {
  63476. this['_' + name](angleAxisModel, polar, ticksAngles, radiusExtent, labels);
  63477. }
  63478. }, this);
  63479. },
  63480. /**
  63481. * @private
  63482. */
  63483. _axisLine: function (angleAxisModel, polar, ticksAngles, radiusExtent) {
  63484. var lineStyleModel = angleAxisModel.getModel('axisLine.lineStyle');
  63485. var circle = new Circle({
  63486. shape: {
  63487. cx: polar.cx,
  63488. cy: polar.cy,
  63489. r: radiusExtent[getRadiusIdx(polar)]
  63490. },
  63491. style: lineStyleModel.getLineStyle(),
  63492. z2: 1,
  63493. silent: true
  63494. });
  63495. circle.style.fill = null;
  63496. this.group.add(circle);
  63497. },
  63498. /**
  63499. * @private
  63500. */
  63501. _axisTick: function (angleAxisModel, polar, ticksAngles, radiusExtent) {
  63502. var tickModel = angleAxisModel.getModel('axisTick');
  63503. var tickLen = (tickModel.get('inside') ? -1 : 1) * tickModel.get('length');
  63504. var radius = radiusExtent[getRadiusIdx(polar)];
  63505. var lines = map(ticksAngles, function (tickAngleItem) {
  63506. return new Line({
  63507. shape: getAxisLineShape(polar, [radius, radius + tickLen], tickAngleItem.coord)
  63508. });
  63509. });
  63510. this.group.add(mergePath(
  63511. lines, {
  63512. style: defaults(
  63513. tickModel.getModel('lineStyle').getLineStyle(),
  63514. {
  63515. stroke: angleAxisModel.get('axisLine.lineStyle.color')
  63516. }
  63517. )
  63518. }
  63519. ));
  63520. },
  63521. /**
  63522. * @private
  63523. */
  63524. _axisLabel: function (angleAxisModel, polar, ticksAngles, radiusExtent, labels) {
  63525. var rawCategoryData = angleAxisModel.getCategories(true);
  63526. var commonLabelModel = angleAxisModel.getModel('axisLabel');
  63527. var labelMargin = commonLabelModel.get('margin');
  63528. var triggerEvent = angleAxisModel.get('triggerEvent');
  63529. // Use length of ticksAngles because it may remove the last tick to avoid overlapping
  63530. each$1(labels, function (labelItem, idx) {
  63531. var labelModel = commonLabelModel;
  63532. var tickValue = labelItem.tickValue;
  63533. var r = radiusExtent[getRadiusIdx(polar)];
  63534. var p = polar.coordToPoint([r + labelMargin, labelItem.coord]);
  63535. var cx = polar.cx;
  63536. var cy = polar.cy;
  63537. var labelTextAlign = Math.abs(p[0] - cx) / r < 0.3
  63538. ? 'center' : (p[0] > cx ? 'left' : 'right');
  63539. var labelTextVerticalAlign = Math.abs(p[1] - cy) / r < 0.3
  63540. ? 'middle' : (p[1] > cy ? 'top' : 'bottom');
  63541. if (rawCategoryData && rawCategoryData[tickValue] && rawCategoryData[tickValue].textStyle) {
  63542. labelModel = new Model(
  63543. rawCategoryData[tickValue].textStyle, commonLabelModel, commonLabelModel.ecModel
  63544. );
  63545. }
  63546. var textEl = new Text({
  63547. silent: AxisBuilder.isLabelSilent(angleAxisModel)
  63548. });
  63549. this.group.add(textEl);
  63550. setTextStyle(textEl.style, labelModel, {
  63551. x: p[0],
  63552. y: p[1],
  63553. textFill: labelModel.getTextColor() || angleAxisModel.get('axisLine.lineStyle.color'),
  63554. text: labelItem.formattedLabel,
  63555. textAlign: labelTextAlign,
  63556. textVerticalAlign: labelTextVerticalAlign
  63557. });
  63558. // Pack data for mouse event
  63559. if (triggerEvent) {
  63560. textEl.eventData = AxisBuilder.makeAxisEventDataBase(angleAxisModel);
  63561. textEl.eventData.targetType = 'axisLabel';
  63562. textEl.eventData.value = labelItem.rawLabel;
  63563. }
  63564. }, this);
  63565. },
  63566. /**
  63567. * @private
  63568. */
  63569. _splitLine: function (angleAxisModel, polar, ticksAngles, radiusExtent) {
  63570. var splitLineModel = angleAxisModel.getModel('splitLine');
  63571. var lineStyleModel = splitLineModel.getModel('lineStyle');
  63572. var lineColors = lineStyleModel.get('color');
  63573. var lineCount = 0;
  63574. lineColors = lineColors instanceof Array ? lineColors : [lineColors];
  63575. var splitLines = [];
  63576. for (var i = 0; i < ticksAngles.length; i++) {
  63577. var colorIndex = (lineCount++) % lineColors.length;
  63578. splitLines[colorIndex] = splitLines[colorIndex] || [];
  63579. splitLines[colorIndex].push(new Line({
  63580. shape: getAxisLineShape(polar, radiusExtent, ticksAngles[i].coord)
  63581. }));
  63582. }
  63583. // Simple optimization
  63584. // Batching the lines if color are the same
  63585. for (var i = 0; i < splitLines.length; i++) {
  63586. this.group.add(mergePath(splitLines[i], {
  63587. style: defaults({
  63588. stroke: lineColors[i % lineColors.length]
  63589. }, lineStyleModel.getLineStyle()),
  63590. silent: true,
  63591. z: angleAxisModel.get('z')
  63592. }));
  63593. }
  63594. },
  63595. /**
  63596. * @private
  63597. */
  63598. _splitArea: function (angleAxisModel, polar, ticksAngles, radiusExtent) {
  63599. if (!ticksAngles.length) {
  63600. return;
  63601. }
  63602. var splitAreaModel = angleAxisModel.getModel('splitArea');
  63603. var areaStyleModel = splitAreaModel.getModel('areaStyle');
  63604. var areaColors = areaStyleModel.get('color');
  63605. var lineCount = 0;
  63606. areaColors = areaColors instanceof Array ? areaColors : [areaColors];
  63607. var splitAreas = [];
  63608. var RADIAN = Math.PI / 180;
  63609. var prevAngle = -ticksAngles[0].coord * RADIAN;
  63610. var r0 = Math.min(radiusExtent[0], radiusExtent[1]);
  63611. var r1 = Math.max(radiusExtent[0], radiusExtent[1]);
  63612. var clockwise = angleAxisModel.get('clockwise');
  63613. for (var i = 1; i < ticksAngles.length; i++) {
  63614. var colorIndex = (lineCount++) % areaColors.length;
  63615. splitAreas[colorIndex] = splitAreas[colorIndex] || [];
  63616. splitAreas[colorIndex].push(new Sector({
  63617. shape: {
  63618. cx: polar.cx,
  63619. cy: polar.cy,
  63620. r0: r0,
  63621. r: r1,
  63622. startAngle: prevAngle,
  63623. endAngle: -ticksAngles[i].coord * RADIAN,
  63624. clockwise: clockwise
  63625. },
  63626. silent: true
  63627. }));
  63628. prevAngle = -ticksAngles[i].coord * RADIAN;
  63629. }
  63630. // Simple optimization
  63631. // Batching the lines if color are the same
  63632. for (var i = 0; i < splitAreas.length; i++) {
  63633. this.group.add(mergePath(splitAreas[i], {
  63634. style: defaults({
  63635. fill: areaColors[i % areaColors.length]
  63636. }, areaStyleModel.getAreaStyle()),
  63637. silent: true
  63638. }));
  63639. }
  63640. }
  63641. });
  63642. /*
  63643. * Licensed to the Apache Software Foundation (ASF) under one
  63644. * or more contributor license agreements. See the NOTICE file
  63645. * distributed with this work for additional information
  63646. * regarding copyright ownership. The ASF licenses this file
  63647. * to you under the Apache License, Version 2.0 (the
  63648. * "License"); you may not use this file except in compliance
  63649. * with the License. You may obtain a copy of the License at
  63650. *
  63651. * http://www.apache.org/licenses/LICENSE-2.0
  63652. *
  63653. * Unless required by applicable law or agreed to in writing,
  63654. * software distributed under the License is distributed on an
  63655. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  63656. * KIND, either express or implied. See the License for the
  63657. * specific language governing permissions and limitations
  63658. * under the License.
  63659. */
  63660. /*
  63661. * Licensed to the Apache Software Foundation (ASF) under one
  63662. * or more contributor license agreements. See the NOTICE file
  63663. * distributed with this work for additional information
  63664. * regarding copyright ownership. The ASF licenses this file
  63665. * to you under the Apache License, Version 2.0 (the
  63666. * "License"); you may not use this file except in compliance
  63667. * with the License. You may obtain a copy of the License at
  63668. *
  63669. * http://www.apache.org/licenses/LICENSE-2.0
  63670. *
  63671. * Unless required by applicable law or agreed to in writing,
  63672. * software distributed under the License is distributed on an
  63673. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  63674. * KIND, either express or implied. See the License for the
  63675. * specific language governing permissions and limitations
  63676. * under the License.
  63677. */
  63678. var axisBuilderAttrs$3 = [
  63679. 'axisLine', 'axisTickLabel', 'axisName'
  63680. ];
  63681. var selfBuilderAttrs$1 = [
  63682. 'splitLine', 'splitArea'
  63683. ];
  63684. AxisView.extend({
  63685. type: 'radiusAxis',
  63686. axisPointerClass: 'PolarAxisPointer',
  63687. render: function (radiusAxisModel, ecModel) {
  63688. this.group.removeAll();
  63689. if (!radiusAxisModel.get('show')) {
  63690. return;
  63691. }
  63692. var radiusAxis = radiusAxisModel.axis;
  63693. var polar = radiusAxis.polar;
  63694. var angleAxis = polar.getAngleAxis();
  63695. var ticksCoords = radiusAxis.getTicksCoords();
  63696. var axisAngle = angleAxis.getExtent()[0];
  63697. var radiusExtent = radiusAxis.getExtent();
  63698. var layout = layoutAxis(polar, radiusAxisModel, axisAngle);
  63699. var axisBuilder = new AxisBuilder(radiusAxisModel, layout);
  63700. each$1(axisBuilderAttrs$3, axisBuilder.add, axisBuilder);
  63701. this.group.add(axisBuilder.getGroup());
  63702. each$1(selfBuilderAttrs$1, function (name) {
  63703. if (radiusAxisModel.get(name + '.show') && !radiusAxis.scale.isBlank()) {
  63704. this['_' + name](radiusAxisModel, polar, axisAngle, radiusExtent, ticksCoords);
  63705. }
  63706. }, this);
  63707. },
  63708. /**
  63709. * @private
  63710. */
  63711. _splitLine: function (radiusAxisModel, polar, axisAngle, radiusExtent, ticksCoords) {
  63712. var splitLineModel = radiusAxisModel.getModel('splitLine');
  63713. var lineStyleModel = splitLineModel.getModel('lineStyle');
  63714. var lineColors = lineStyleModel.get('color');
  63715. var lineCount = 0;
  63716. lineColors = lineColors instanceof Array ? lineColors : [lineColors];
  63717. var splitLines = [];
  63718. for (var i = 0; i < ticksCoords.length; i++) {
  63719. var colorIndex = (lineCount++) % lineColors.length;
  63720. splitLines[colorIndex] = splitLines[colorIndex] || [];
  63721. splitLines[colorIndex].push(new Circle({
  63722. shape: {
  63723. cx: polar.cx,
  63724. cy: polar.cy,
  63725. r: ticksCoords[i].coord
  63726. },
  63727. silent: true
  63728. }));
  63729. }
  63730. // Simple optimization
  63731. // Batching the lines if color are the same
  63732. for (var i = 0; i < splitLines.length; i++) {
  63733. this.group.add(mergePath(splitLines[i], {
  63734. style: defaults({
  63735. stroke: lineColors[i % lineColors.length],
  63736. fill: null
  63737. }, lineStyleModel.getLineStyle()),
  63738. silent: true
  63739. }));
  63740. }
  63741. },
  63742. /**
  63743. * @private
  63744. */
  63745. _splitArea: function (radiusAxisModel, polar, axisAngle, radiusExtent, ticksCoords) {
  63746. if (!ticksCoords.length) {
  63747. return;
  63748. }
  63749. var splitAreaModel = radiusAxisModel.getModel('splitArea');
  63750. var areaStyleModel = splitAreaModel.getModel('areaStyle');
  63751. var areaColors = areaStyleModel.get('color');
  63752. var lineCount = 0;
  63753. areaColors = areaColors instanceof Array ? areaColors : [areaColors];
  63754. var splitAreas = [];
  63755. var prevRadius = ticksCoords[0].coord;
  63756. for (var i = 1; i < ticksCoords.length; i++) {
  63757. var colorIndex = (lineCount++) % areaColors.length;
  63758. splitAreas[colorIndex] = splitAreas[colorIndex] || [];
  63759. splitAreas[colorIndex].push(new Sector({
  63760. shape: {
  63761. cx: polar.cx,
  63762. cy: polar.cy,
  63763. r0: prevRadius,
  63764. r: ticksCoords[i].coord,
  63765. startAngle: 0,
  63766. endAngle: Math.PI * 2
  63767. },
  63768. silent: true
  63769. }));
  63770. prevRadius = ticksCoords[i].coord;
  63771. }
  63772. // Simple optimization
  63773. // Batching the lines if color are the same
  63774. for (var i = 0; i < splitAreas.length; i++) {
  63775. this.group.add(mergePath(splitAreas[i], {
  63776. style: defaults({
  63777. fill: areaColors[i % areaColors.length]
  63778. }, areaStyleModel.getAreaStyle()),
  63779. silent: true
  63780. }));
  63781. }
  63782. }
  63783. });
  63784. /**
  63785. * @inner
  63786. */
  63787. function layoutAxis(polar, radiusAxisModel, axisAngle) {
  63788. return {
  63789. position: [polar.cx, polar.cy],
  63790. rotation: axisAngle / 180 * Math.PI,
  63791. labelDirection: -1,
  63792. tickDirection: -1,
  63793. nameDirection: 1,
  63794. labelRotate: radiusAxisModel.getModel('axisLabel').get('rotate'),
  63795. // Over splitLine and splitArea
  63796. z2: 1
  63797. };
  63798. }
  63799. /*
  63800. * Licensed to the Apache Software Foundation (ASF) under one
  63801. * or more contributor license agreements. See the NOTICE file
  63802. * distributed with this work for additional information
  63803. * regarding copyright ownership. The ASF licenses this file
  63804. * to you under the Apache License, Version 2.0 (the
  63805. * "License"); you may not use this file except in compliance
  63806. * with the License. You may obtain a copy of the License at
  63807. *
  63808. * http://www.apache.org/licenses/LICENSE-2.0
  63809. *
  63810. * Unless required by applicable law or agreed to in writing,
  63811. * software distributed under the License is distributed on an
  63812. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  63813. * KIND, either express or implied. See the License for the
  63814. * specific language governing permissions and limitations
  63815. * under the License.
  63816. */
  63817. /*
  63818. * Licensed to the Apache Software Foundation (ASF) under one
  63819. * or more contributor license agreements. See the NOTICE file
  63820. * distributed with this work for additional information
  63821. * regarding copyright ownership. The ASF licenses this file
  63822. * to you under the Apache License, Version 2.0 (the
  63823. * "License"); you may not use this file except in compliance
  63824. * with the License. You may obtain a copy of the License at
  63825. *
  63826. * http://www.apache.org/licenses/LICENSE-2.0
  63827. *
  63828. * Unless required by applicable law or agreed to in writing,
  63829. * software distributed under the License is distributed on an
  63830. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  63831. * KIND, either express or implied. See the License for the
  63832. * specific language governing permissions and limitations
  63833. * under the License.
  63834. */
  63835. var PolarAxisPointer = BaseAxisPointer.extend({
  63836. /**
  63837. * @override
  63838. */
  63839. makeElOption: function (elOption, value, axisModel, axisPointerModel, api) {
  63840. var axis = axisModel.axis;
  63841. if (axis.dim === 'angle') {
  63842. this.animationThreshold = Math.PI / 18;
  63843. }
  63844. var polar = axis.polar;
  63845. var otherAxis = polar.getOtherAxis(axis);
  63846. var otherExtent = otherAxis.getExtent();
  63847. var coordValue;
  63848. coordValue = axis['dataTo' + capitalFirst(axis.dim)](value);
  63849. var axisPointerType = axisPointerModel.get('type');
  63850. if (axisPointerType && axisPointerType !== 'none') {
  63851. var elStyle = buildElStyle(axisPointerModel);
  63852. var pointerOption = pointerShapeBuilder$2[axisPointerType](
  63853. axis, polar, coordValue, otherExtent, elStyle
  63854. );
  63855. pointerOption.style = elStyle;
  63856. elOption.graphicKey = pointerOption.type;
  63857. elOption.pointer = pointerOption;
  63858. }
  63859. var labelMargin = axisPointerModel.get('label.margin');
  63860. var labelPos = getLabelPosition(value, axisModel, axisPointerModel, polar, labelMargin);
  63861. buildLabelElOption(elOption, axisModel, axisPointerModel, api, labelPos);
  63862. }
  63863. // Do not support handle, utill any user requires it.
  63864. });
  63865. function getLabelPosition(value, axisModel, axisPointerModel, polar, labelMargin) {
  63866. var axis = axisModel.axis;
  63867. var coord = axis.dataToCoord(value);
  63868. var axisAngle = polar.getAngleAxis().getExtent()[0];
  63869. axisAngle = axisAngle / 180 * Math.PI;
  63870. var radiusExtent = polar.getRadiusAxis().getExtent();
  63871. var position;
  63872. var align;
  63873. var verticalAlign;
  63874. if (axis.dim === 'radius') {
  63875. var transform = create$1();
  63876. rotate(transform, transform, axisAngle);
  63877. translate(transform, transform, [polar.cx, polar.cy]);
  63878. position = applyTransform$1([coord, -labelMargin], transform);
  63879. var labelRotation = axisModel.getModel('axisLabel').get('rotate') || 0;
  63880. var labelLayout = AxisBuilder.innerTextLayout(
  63881. axisAngle, labelRotation * Math.PI / 180, -1
  63882. );
  63883. align = labelLayout.textAlign;
  63884. verticalAlign = labelLayout.textVerticalAlign;
  63885. }
  63886. else { // angle axis
  63887. var r = radiusExtent[1];
  63888. position = polar.coordToPoint([r + labelMargin, coord]);
  63889. var cx = polar.cx;
  63890. var cy = polar.cy;
  63891. align = Math.abs(position[0] - cx) / r < 0.3
  63892. ? 'center' : (position[0] > cx ? 'left' : 'right');
  63893. verticalAlign = Math.abs(position[1] - cy) / r < 0.3
  63894. ? 'middle' : (position[1] > cy ? 'top' : 'bottom');
  63895. }
  63896. return {
  63897. position: position,
  63898. align: align,
  63899. verticalAlign: verticalAlign
  63900. };
  63901. }
  63902. var pointerShapeBuilder$2 = {
  63903. line: function (axis, polar, coordValue, otherExtent, elStyle) {
  63904. return axis.dim === 'angle'
  63905. ? {
  63906. type: 'Line',
  63907. shape: makeLineShape(
  63908. polar.coordToPoint([otherExtent[0], coordValue]),
  63909. polar.coordToPoint([otherExtent[1], coordValue])
  63910. )
  63911. }
  63912. : {
  63913. type: 'Circle',
  63914. shape: {
  63915. cx: polar.cx,
  63916. cy: polar.cy,
  63917. r: coordValue
  63918. }
  63919. };
  63920. },
  63921. shadow: function (axis, polar, coordValue, otherExtent, elStyle) {
  63922. var bandWidth = Math.max(1, axis.getBandWidth());
  63923. var radian = Math.PI / 180;
  63924. return axis.dim === 'angle'
  63925. ? {
  63926. type: 'Sector',
  63927. shape: makeSectorShape(
  63928. polar.cx, polar.cy,
  63929. otherExtent[0], otherExtent[1],
  63930. // In ECharts y is negative if angle is positive
  63931. (-coordValue - bandWidth / 2) * radian,
  63932. (-coordValue + bandWidth / 2) * radian
  63933. )
  63934. }
  63935. : {
  63936. type: 'Sector',
  63937. shape: makeSectorShape(
  63938. polar.cx, polar.cy,
  63939. coordValue - bandWidth / 2,
  63940. coordValue + bandWidth / 2,
  63941. 0, Math.PI * 2
  63942. )
  63943. };
  63944. }
  63945. };
  63946. AxisView.registerAxisPointerClass('PolarAxisPointer', PolarAxisPointer);
  63947. /*
  63948. * Licensed to the Apache Software Foundation (ASF) under one
  63949. * or more contributor license agreements. See the NOTICE file
  63950. * distributed with this work for additional information
  63951. * regarding copyright ownership. The ASF licenses this file
  63952. * to you under the Apache License, Version 2.0 (the
  63953. * "License"); you may not use this file except in compliance
  63954. * with the License. You may obtain a copy of the License at
  63955. *
  63956. * http://www.apache.org/licenses/LICENSE-2.0
  63957. *
  63958. * Unless required by applicable law or agreed to in writing,
  63959. * software distributed under the License is distributed on an
  63960. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  63961. * KIND, either express or implied. See the License for the
  63962. * specific language governing permissions and limitations
  63963. * under the License.
  63964. */
  63965. // For reducing size of echarts.min, barLayoutPolar is required by polar.
  63966. registerLayout(curry(barLayoutPolar, 'bar'));
  63967. // Polar view
  63968. extendComponentView({
  63969. type: 'polar'
  63970. });
  63971. /*
  63972. * Licensed to the Apache Software Foundation (ASF) under one
  63973. * or more contributor license agreements. See the NOTICE file
  63974. * distributed with this work for additional information
  63975. * regarding copyright ownership. The ASF licenses this file
  63976. * to you under the Apache License, Version 2.0 (the
  63977. * "License"); you may not use this file except in compliance
  63978. * with the License. You may obtain a copy of the License at
  63979. *
  63980. * http://www.apache.org/licenses/LICENSE-2.0
  63981. *
  63982. * Unless required by applicable law or agreed to in writing,
  63983. * software distributed under the License is distributed on an
  63984. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  63985. * KIND, either express or implied. See the License for the
  63986. * specific language governing permissions and limitations
  63987. * under the License.
  63988. */
  63989. var GeoModel = ComponentModel.extend({
  63990. type: 'geo',
  63991. /**
  63992. * @type {module:echarts/coord/geo/Geo}
  63993. */
  63994. coordinateSystem: null,
  63995. layoutMode: 'box',
  63996. init: function (option) {
  63997. ComponentModel.prototype.init.apply(this, arguments);
  63998. // Default label emphasis `show`
  63999. defaultEmphasis(option, 'label', ['show']);
  64000. },
  64001. optionUpdated: function () {
  64002. var option = this.option;
  64003. var self = this;
  64004. option.regions = geoCreator.getFilledRegions(option.regions, option.map, option.nameMap);
  64005. this._optionModelMap = reduce(option.regions || [], function (optionModelMap, regionOpt) {
  64006. if (regionOpt.name) {
  64007. optionModelMap.set(regionOpt.name, new Model(regionOpt, self));
  64008. }
  64009. return optionModelMap;
  64010. }, createHashMap());
  64011. this.updateSelectedMap(option.regions);
  64012. },
  64013. defaultOption: {
  64014. zlevel: 0,
  64015. z: 0,
  64016. show: true,
  64017. left: 'center',
  64018. top: 'center',
  64019. // width:,
  64020. // height:,
  64021. // right
  64022. // bottom
  64023. // Aspect is width / height. Inited to be geoJson bbox aspect
  64024. // This parameter is used for scale this aspect
  64025. // If svg used, aspectScale is 1 by default.
  64026. // aspectScale: 0.75,
  64027. aspectScale: null,
  64028. ///// Layout with center and size
  64029. // If you wan't to put map in a fixed size box with right aspect ratio
  64030. // This two properties may more conveninet
  64031. // layoutCenter: [50%, 50%]
  64032. // layoutSize: 100
  64033. silent: false,
  64034. // Map type
  64035. map: '',
  64036. // Define left-top, right-bottom coords to control view
  64037. // For example, [ [180, 90], [-180, -90] ]
  64038. boundingCoords: null,
  64039. // Default on center of map
  64040. center: null,
  64041. zoom: 1,
  64042. scaleLimit: null,
  64043. // selectedMode: false
  64044. label: {
  64045. show: false,
  64046. color: '#000'
  64047. },
  64048. itemStyle: {
  64049. // color: 各异,
  64050. borderWidth: 0.5,
  64051. borderColor: '#444',
  64052. color: '#eee'
  64053. },
  64054. emphasis: {
  64055. label: {
  64056. show: true,
  64057. color: 'rgb(100,0,0)'
  64058. },
  64059. itemStyle: {
  64060. color: 'rgba(255,215,0,0.8)'
  64061. }
  64062. },
  64063. regions: []
  64064. },
  64065. /**
  64066. * Get model of region
  64067. * @param {string} name
  64068. * @return {module:echarts/model/Model}
  64069. */
  64070. getRegionModel: function (name) {
  64071. return this._optionModelMap.get(name) || new Model(null, this, this.ecModel);
  64072. },
  64073. /**
  64074. * Format label
  64075. * @param {string} name Region name
  64076. * @param {string} [status='normal'] 'normal' or 'emphasis'
  64077. * @return {string}
  64078. */
  64079. getFormattedLabel: function (name, status) {
  64080. var regionModel = this.getRegionModel(name);
  64081. var formatter = regionModel.get('label.' + status + '.formatter');
  64082. var params = {
  64083. name: name
  64084. };
  64085. if (typeof formatter === 'function') {
  64086. params.status = status;
  64087. return formatter(params);
  64088. }
  64089. else if (typeof formatter === 'string') {
  64090. return formatter.replace('{a}', name != null ? name : '');
  64091. }
  64092. },
  64093. setZoom: function (zoom) {
  64094. this.option.zoom = zoom;
  64095. },
  64096. setCenter: function (center) {
  64097. this.option.center = center;
  64098. }
  64099. });
  64100. mixin(GeoModel, selectableMixin);
  64101. /*
  64102. * Licensed to the Apache Software Foundation (ASF) under one
  64103. * or more contributor license agreements. See the NOTICE file
  64104. * distributed with this work for additional information
  64105. * regarding copyright ownership. The ASF licenses this file
  64106. * to you under the Apache License, Version 2.0 (the
  64107. * "License"); you may not use this file except in compliance
  64108. * with the License. You may obtain a copy of the License at
  64109. *
  64110. * http://www.apache.org/licenses/LICENSE-2.0
  64111. *
  64112. * Unless required by applicable law or agreed to in writing,
  64113. * software distributed under the License is distributed on an
  64114. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  64115. * KIND, either express or implied. See the License for the
  64116. * specific language governing permissions and limitations
  64117. * under the License.
  64118. */
  64119. extendComponentView({
  64120. type: 'geo',
  64121. init: function (ecModel, api) {
  64122. var mapDraw = new MapDraw(api, true);
  64123. this._mapDraw = mapDraw;
  64124. this.group.add(mapDraw.group);
  64125. },
  64126. render: function (geoModel, ecModel, api, payload) {
  64127. // Not render if it is an toggleSelect action from self
  64128. if (payload && payload.type === 'geoToggleSelect'
  64129. && payload.from === this.uid
  64130. ) {
  64131. return;
  64132. }
  64133. var mapDraw = this._mapDraw;
  64134. if (geoModel.get('show')) {
  64135. mapDraw.draw(geoModel, ecModel, api, this, payload);
  64136. }
  64137. else {
  64138. this._mapDraw.group.removeAll();
  64139. }
  64140. this.group.silent = geoModel.get('silent');
  64141. },
  64142. dispose: function () {
  64143. this._mapDraw && this._mapDraw.remove();
  64144. }
  64145. });
  64146. /*
  64147. * Licensed to the Apache Software Foundation (ASF) under one
  64148. * or more contributor license agreements. See the NOTICE file
  64149. * distributed with this work for additional information
  64150. * regarding copyright ownership. The ASF licenses this file
  64151. * to you under the Apache License, Version 2.0 (the
  64152. * "License"); you may not use this file except in compliance
  64153. * with the License. You may obtain a copy of the License at
  64154. *
  64155. * http://www.apache.org/licenses/LICENSE-2.0
  64156. *
  64157. * Unless required by applicable law or agreed to in writing,
  64158. * software distributed under the License is distributed on an
  64159. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  64160. * KIND, either express or implied. See the License for the
  64161. * specific language governing permissions and limitations
  64162. * under the License.
  64163. */
  64164. function makeAction(method, actionInfo) {
  64165. actionInfo.update = 'updateView';
  64166. registerAction(actionInfo, function (payload, ecModel) {
  64167. var selected = {};
  64168. ecModel.eachComponent(
  64169. { mainType: 'geo', query: payload},
  64170. function (geoModel) {
  64171. geoModel[method](payload.name);
  64172. var geo = geoModel.coordinateSystem;
  64173. each$1(geo.regions, function (region) {
  64174. selected[region.name] = geoModel.isSelected(region.name) || false;
  64175. });
  64176. }
  64177. );
  64178. return {
  64179. selected: selected,
  64180. name: payload.name
  64181. };
  64182. });
  64183. }
  64184. makeAction('toggleSelected', {
  64185. type: 'geoToggleSelect',
  64186. event: 'geoselectchanged'
  64187. });
  64188. makeAction('select', {
  64189. type: 'geoSelect',
  64190. event: 'geoselected'
  64191. });
  64192. makeAction('unSelect', {
  64193. type: 'geoUnSelect',
  64194. event: 'geounselected'
  64195. });
  64196. /*
  64197. * Licensed to the Apache Software Foundation (ASF) under one
  64198. * or more contributor license agreements. See the NOTICE file
  64199. * distributed with this work for additional information
  64200. * regarding copyright ownership. The ASF licenses this file
  64201. * to you under the Apache License, Version 2.0 (the
  64202. * "License"); you may not use this file except in compliance
  64203. * with the License. You may obtain a copy of the License at
  64204. *
  64205. * http://www.apache.org/licenses/LICENSE-2.0
  64206. *
  64207. * Unless required by applicable law or agreed to in writing,
  64208. * software distributed under the License is distributed on an
  64209. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  64210. * KIND, either express or implied. See the License for the
  64211. * specific language governing permissions and limitations
  64212. * under the License.
  64213. */
  64214. // (24*60*60*1000)
  64215. var PROXIMATE_ONE_DAY = 86400000;
  64216. /**
  64217. * Calendar
  64218. *
  64219. * @constructor
  64220. *
  64221. * @param {Object} calendarModel calendarModel
  64222. * @param {Object} ecModel ecModel
  64223. * @param {Object} api api
  64224. */
  64225. function Calendar(calendarModel, ecModel, api) {
  64226. this._model = calendarModel;
  64227. }
  64228. Calendar.prototype = {
  64229. constructor: Calendar,
  64230. type: 'calendar',
  64231. dimensions: ['time', 'value'],
  64232. // Required in createListFromData
  64233. getDimensionsInfo: function () {
  64234. return [{name: 'time', type: 'time'}, 'value'];
  64235. },
  64236. getRangeInfo: function () {
  64237. return this._rangeInfo;
  64238. },
  64239. getModel: function () {
  64240. return this._model;
  64241. },
  64242. getRect: function () {
  64243. return this._rect;
  64244. },
  64245. getCellWidth: function () {
  64246. return this._sw;
  64247. },
  64248. getCellHeight: function () {
  64249. return this._sh;
  64250. },
  64251. getOrient: function () {
  64252. return this._orient;
  64253. },
  64254. /**
  64255. * getFirstDayOfWeek
  64256. *
  64257. * @example
  64258. * 0 : start at Sunday
  64259. * 1 : start at Monday
  64260. *
  64261. * @return {number}
  64262. */
  64263. getFirstDayOfWeek: function () {
  64264. return this._firstDayOfWeek;
  64265. },
  64266. /**
  64267. * get date info
  64268. *
  64269. * @param {string|number} date date
  64270. * @return {Object}
  64271. * {
  64272. * y: string, local full year, eg., '1940',
  64273. * m: string, local month, from '01' ot '12',
  64274. * d: string, local date, from '01' to '31' (if exists),
  64275. * day: It is not date.getDay(). It is the location of the cell in a week, from 0 to 6,
  64276. * time: timestamp,
  64277. * formatedDate: string, yyyy-MM-dd,
  64278. * date: original date object.
  64279. * }
  64280. */
  64281. getDateInfo: function (date) {
  64282. date = parseDate(date);
  64283. var y = date.getFullYear();
  64284. var m = date.getMonth() + 1;
  64285. m = m < 10 ? '0' + m : m;
  64286. var d = date.getDate();
  64287. d = d < 10 ? '0' + d : d;
  64288. var day = date.getDay();
  64289. day = Math.abs((day + 7 - this.getFirstDayOfWeek()) % 7);
  64290. return {
  64291. y: y,
  64292. m: m,
  64293. d: d,
  64294. day: day,
  64295. time: date.getTime(),
  64296. formatedDate: y + '-' + m + '-' + d,
  64297. date: date
  64298. };
  64299. },
  64300. getNextNDay: function (date, n) {
  64301. n = n || 0;
  64302. if (n === 0) {
  64303. return this.getDateInfo(date);
  64304. }
  64305. date = new Date(this.getDateInfo(date).time);
  64306. date.setDate(date.getDate() + n);
  64307. return this.getDateInfo(date);
  64308. },
  64309. update: function (ecModel, api) {
  64310. this._firstDayOfWeek = +this._model.getModel('dayLabel').get('firstDay');
  64311. this._orient = this._model.get('orient');
  64312. this._lineWidth = this._model.getModel('itemStyle').getItemStyle().lineWidth || 0;
  64313. this._rangeInfo = this._getRangeInfo(this._initRangeOption());
  64314. var weeks = this._rangeInfo.weeks || 1;
  64315. var whNames = ['width', 'height'];
  64316. var cellSize = this._model.get('cellSize').slice();
  64317. var layoutParams = this._model.getBoxLayoutParams();
  64318. var cellNumbers = this._orient === 'horizontal' ? [weeks, 7] : [7, weeks];
  64319. each$1([0, 1], function (idx) {
  64320. if (cellSizeSpecified(cellSize, idx)) {
  64321. layoutParams[whNames[idx]] = cellSize[idx] * cellNumbers[idx];
  64322. }
  64323. });
  64324. var whGlobal = {
  64325. width: api.getWidth(),
  64326. height: api.getHeight()
  64327. };
  64328. var calendarRect = this._rect = getLayoutRect(layoutParams, whGlobal);
  64329. each$1([0, 1], function (idx) {
  64330. if (!cellSizeSpecified(cellSize, idx)) {
  64331. cellSize[idx] = calendarRect[whNames[idx]] / cellNumbers[idx];
  64332. }
  64333. });
  64334. function cellSizeSpecified(cellSize, idx) {
  64335. return cellSize[idx] != null && cellSize[idx] !== 'auto';
  64336. }
  64337. this._sw = cellSize[0];
  64338. this._sh = cellSize[1];
  64339. },
  64340. /**
  64341. * Convert a time data(time, value) item to (x, y) point.
  64342. *
  64343. * @override
  64344. * @param {Array|number} data data
  64345. * @param {boolean} [clamp=true] out of range
  64346. * @return {Array} point
  64347. */
  64348. dataToPoint: function (data, clamp) {
  64349. isArray(data) && (data = data[0]);
  64350. clamp == null && (clamp = true);
  64351. var dayInfo = this.getDateInfo(data);
  64352. var range = this._rangeInfo;
  64353. var date = dayInfo.formatedDate;
  64354. // if not in range return [NaN, NaN]
  64355. if (clamp && !(
  64356. dayInfo.time >= range.start.time
  64357. && dayInfo.time < range.end.time + PROXIMATE_ONE_DAY
  64358. )) {
  64359. return [NaN, NaN];
  64360. }
  64361. var week = dayInfo.day;
  64362. var nthWeek = this._getRangeInfo([range.start.time, date]).nthWeek;
  64363. if (this._orient === 'vertical') {
  64364. return [
  64365. this._rect.x + week * this._sw + this._sw / 2,
  64366. this._rect.y + nthWeek * this._sh + this._sh / 2
  64367. ];
  64368. }
  64369. return [
  64370. this._rect.x + nthWeek * this._sw + this._sw / 2,
  64371. this._rect.y + week * this._sh + this._sh / 2
  64372. ];
  64373. },
  64374. /**
  64375. * Convert a (x, y) point to time data
  64376. *
  64377. * @override
  64378. * @param {string} point point
  64379. * @return {string} data
  64380. */
  64381. pointToData: function (point) {
  64382. var date = this.pointToDate(point);
  64383. return date && date.time;
  64384. },
  64385. /**
  64386. * Convert a time date item to (x, y) four point.
  64387. *
  64388. * @param {Array} data date[0] is date
  64389. * @param {boolean} [clamp=true] out of range
  64390. * @return {Object} point
  64391. */
  64392. dataToRect: function (data, clamp) {
  64393. var point = this.dataToPoint(data, clamp);
  64394. return {
  64395. contentShape: {
  64396. x: point[0] - (this._sw - this._lineWidth) / 2,
  64397. y: point[1] - (this._sh - this._lineWidth) / 2,
  64398. width: this._sw - this._lineWidth,
  64399. height: this._sh - this._lineWidth
  64400. },
  64401. center: point,
  64402. tl: [
  64403. point[0] - this._sw / 2,
  64404. point[1] - this._sh / 2
  64405. ],
  64406. tr: [
  64407. point[0] + this._sw / 2,
  64408. point[1] - this._sh / 2
  64409. ],
  64410. br: [
  64411. point[0] + this._sw / 2,
  64412. point[1] + this._sh / 2
  64413. ],
  64414. bl: [
  64415. point[0] - this._sw / 2,
  64416. point[1] + this._sh / 2
  64417. ]
  64418. };
  64419. },
  64420. /**
  64421. * Convert a (x, y) point to time date
  64422. *
  64423. * @param {Array} point point
  64424. * @return {Object} date
  64425. */
  64426. pointToDate: function (point) {
  64427. var nthX = Math.floor((point[0] - this._rect.x) / this._sw) + 1;
  64428. var nthY = Math.floor((point[1] - this._rect.y) / this._sh) + 1;
  64429. var range = this._rangeInfo.range;
  64430. if (this._orient === 'vertical') {
  64431. return this._getDateByWeeksAndDay(nthY, nthX - 1, range);
  64432. }
  64433. return this._getDateByWeeksAndDay(nthX, nthY - 1, range);
  64434. },
  64435. /**
  64436. * @inheritDoc
  64437. */
  64438. convertToPixel: curry(doConvert$2, 'dataToPoint'),
  64439. /**
  64440. * @inheritDoc
  64441. */
  64442. convertFromPixel: curry(doConvert$2, 'pointToData'),
  64443. /**
  64444. * initRange
  64445. *
  64446. * @private
  64447. * @return {Array} [start, end]
  64448. */
  64449. _initRangeOption: function () {
  64450. var range = this._model.get('range');
  64451. var rg = range;
  64452. if (isArray(rg) && rg.length === 1) {
  64453. rg = rg[0];
  64454. }
  64455. if (/^\d{4}$/.test(rg)) {
  64456. range = [rg + '-01-01', rg + '-12-31'];
  64457. }
  64458. if (/^\d{4}[\/|-]\d{1,2}$/.test(rg)) {
  64459. var start = this.getDateInfo(rg);
  64460. var firstDay = start.date;
  64461. firstDay.setMonth(firstDay.getMonth() + 1);
  64462. var end = this.getNextNDay(firstDay, -1);
  64463. range = [start.formatedDate, end.formatedDate];
  64464. }
  64465. if (/^\d{4}[\/|-]\d{1,2}[\/|-]\d{1,2}$/.test(rg)) {
  64466. range = [rg, rg];
  64467. }
  64468. var tmp = this._getRangeInfo(range);
  64469. if (tmp.start.time > tmp.end.time) {
  64470. range.reverse();
  64471. }
  64472. return range;
  64473. },
  64474. /**
  64475. * range info
  64476. *
  64477. * @private
  64478. * @param {Array} range range ['2017-01-01', '2017-07-08']
  64479. * If range[0] > range[1], they will not be reversed.
  64480. * @return {Object} obj
  64481. */
  64482. _getRangeInfo: function (range) {
  64483. range = [
  64484. this.getDateInfo(range[0]),
  64485. this.getDateInfo(range[1])
  64486. ];
  64487. var reversed;
  64488. if (range[0].time > range[1].time) {
  64489. reversed = true;
  64490. range.reverse();
  64491. }
  64492. var allDay = Math.floor(range[1].time / PROXIMATE_ONE_DAY)
  64493. - Math.floor(range[0].time / PROXIMATE_ONE_DAY) + 1;
  64494. // Consider case:
  64495. // Firstly set system timezone as "Time Zone: America/Toronto",
  64496. // ```
  64497. // var first = new Date(1478412000000 - 3600 * 1000 * 2.5);
  64498. // var second = new Date(1478412000000);
  64499. // var allDays = Math.floor(second / ONE_DAY) - Math.floor(first / ONE_DAY) + 1;
  64500. // ```
  64501. // will get wrong result because of DST. So we should fix it.
  64502. var date = new Date(range[0].time);
  64503. var startDateNum = date.getDate();
  64504. var endDateNum = range[1].date.getDate();
  64505. date.setDate(startDateNum + allDay - 1);
  64506. // The bias can not over a month, so just compare date.
  64507. if (date.getDate() !== endDateNum) {
  64508. var sign = date.getTime() - range[1].time > 0 ? 1 : -1;
  64509. while (date.getDate() !== endDateNum && (date.getTime() - range[1].time) * sign > 0) {
  64510. allDay -= sign;
  64511. date.setDate(startDateNum + allDay - 1);
  64512. }
  64513. }
  64514. var weeks = Math.floor((allDay + range[0].day + 6) / 7);
  64515. var nthWeek = reversed ? -weeks + 1 : weeks - 1;
  64516. reversed && range.reverse();
  64517. return {
  64518. range: [range[0].formatedDate, range[1].formatedDate],
  64519. start: range[0],
  64520. end: range[1],
  64521. allDay: allDay,
  64522. weeks: weeks,
  64523. // From 0.
  64524. nthWeek: nthWeek,
  64525. fweek: range[0].day,
  64526. lweek: range[1].day
  64527. };
  64528. },
  64529. /**
  64530. * get date by nthWeeks and week day in range
  64531. *
  64532. * @private
  64533. * @param {number} nthWeek the week
  64534. * @param {number} day the week day
  64535. * @param {Array} range [d1, d2]
  64536. * @return {Object}
  64537. */
  64538. _getDateByWeeksAndDay: function (nthWeek, day, range) {
  64539. var rangeInfo = this._getRangeInfo(range);
  64540. if (nthWeek > rangeInfo.weeks
  64541. || (nthWeek === 0 && day < rangeInfo.fweek)
  64542. || (nthWeek === rangeInfo.weeks && day > rangeInfo.lweek)
  64543. ) {
  64544. return false;
  64545. }
  64546. var nthDay = (nthWeek - 1) * 7 - rangeInfo.fweek + day;
  64547. var date = new Date(rangeInfo.start.time);
  64548. date.setDate(rangeInfo.start.d + nthDay);
  64549. return this.getDateInfo(date);
  64550. }
  64551. };
  64552. Calendar.dimensions = Calendar.prototype.dimensions;
  64553. Calendar.getDimensionsInfo = Calendar.prototype.getDimensionsInfo;
  64554. Calendar.create = function (ecModel, api) {
  64555. var calendarList = [];
  64556. ecModel.eachComponent('calendar', function (calendarModel) {
  64557. var calendar = new Calendar(calendarModel, ecModel, api);
  64558. calendarList.push(calendar);
  64559. calendarModel.coordinateSystem = calendar;
  64560. });
  64561. ecModel.eachSeries(function (calendarSeries) {
  64562. if (calendarSeries.get('coordinateSystem') === 'calendar') {
  64563. // Inject coordinate system
  64564. calendarSeries.coordinateSystem = calendarList[calendarSeries.get('calendarIndex') || 0];
  64565. }
  64566. });
  64567. return calendarList;
  64568. };
  64569. function doConvert$2(methodName, ecModel, finder, value) {
  64570. var calendarModel = finder.calendarModel;
  64571. var seriesModel = finder.seriesModel;
  64572. var coordSys = calendarModel
  64573. ? calendarModel.coordinateSystem
  64574. : seriesModel
  64575. ? seriesModel.coordinateSystem
  64576. : null;
  64577. return coordSys === this ? coordSys[methodName](value) : null;
  64578. }
  64579. CoordinateSystemManager.register('calendar', Calendar);
  64580. /*
  64581. * Licensed to the Apache Software Foundation (ASF) under one
  64582. * or more contributor license agreements. See the NOTICE file
  64583. * distributed with this work for additional information
  64584. * regarding copyright ownership. The ASF licenses this file
  64585. * to you under the Apache License, Version 2.0 (the
  64586. * "License"); you may not use this file except in compliance
  64587. * with the License. You may obtain a copy of the License at
  64588. *
  64589. * http://www.apache.org/licenses/LICENSE-2.0
  64590. *
  64591. * Unless required by applicable law or agreed to in writing,
  64592. * software distributed under the License is distributed on an
  64593. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  64594. * KIND, either express or implied. See the License for the
  64595. * specific language governing permissions and limitations
  64596. * under the License.
  64597. */
  64598. var CalendarModel = ComponentModel.extend({
  64599. type: 'calendar',
  64600. /**
  64601. * @type {module:echarts/coord/calendar/Calendar}
  64602. */
  64603. coordinateSystem: null,
  64604. defaultOption: {
  64605. zlevel: 0,
  64606. z: 2,
  64607. left: 80,
  64608. top: 60,
  64609. cellSize: 20,
  64610. // horizontal vertical
  64611. orient: 'horizontal',
  64612. // month separate line style
  64613. splitLine: {
  64614. show: true,
  64615. lineStyle: {
  64616. color: '#000',
  64617. width: 1,
  64618. type: 'solid'
  64619. }
  64620. },
  64621. // rect style temporarily unused emphasis
  64622. itemStyle: {
  64623. color: '#fff',
  64624. borderWidth: 1,
  64625. borderColor: '#ccc'
  64626. },
  64627. // week text style
  64628. dayLabel: {
  64629. show: true,
  64630. // a week first day
  64631. firstDay: 0,
  64632. // start end
  64633. position: 'start',
  64634. margin: '50%', // 50% of cellSize
  64635. nameMap: 'en',
  64636. color: '#000'
  64637. },
  64638. // month text style
  64639. monthLabel: {
  64640. show: true,
  64641. // start end
  64642. position: 'start',
  64643. margin: 5,
  64644. // center or left
  64645. align: 'center',
  64646. // cn en []
  64647. nameMap: 'en',
  64648. formatter: null,
  64649. color: '#000'
  64650. },
  64651. // year text style
  64652. yearLabel: {
  64653. show: true,
  64654. // top bottom left right
  64655. position: null,
  64656. margin: 30,
  64657. formatter: null,
  64658. color: '#ccc',
  64659. fontFamily: 'sans-serif',
  64660. fontWeight: 'bolder',
  64661. fontSize: 20
  64662. }
  64663. },
  64664. /**
  64665. * @override
  64666. */
  64667. init: function (option, parentModel, ecModel, extraOpt) {
  64668. var inputPositionParams = getLayoutParams(option);
  64669. CalendarModel.superApply(this, 'init', arguments);
  64670. mergeAndNormalizeLayoutParams(option, inputPositionParams);
  64671. },
  64672. /**
  64673. * @override
  64674. */
  64675. mergeOption: function (option, extraOpt) {
  64676. CalendarModel.superApply(this, 'mergeOption', arguments);
  64677. mergeAndNormalizeLayoutParams(this.option, option);
  64678. }
  64679. });
  64680. function mergeAndNormalizeLayoutParams(target, raw) {
  64681. // Normalize cellSize
  64682. var cellSize = target.cellSize;
  64683. if (!isArray(cellSize)) {
  64684. cellSize = target.cellSize = [cellSize, cellSize];
  64685. }
  64686. else if (cellSize.length === 1) {
  64687. cellSize[1] = cellSize[0];
  64688. }
  64689. var ignoreSize = map([0, 1], function (hvIdx) {
  64690. // If user have set `width` or both `left` and `right`, cellSize
  64691. // will be automatically set to 'auto', otherwise the default
  64692. // setting of cellSize will make `width` setting not work.
  64693. if (sizeCalculable(raw, hvIdx)) {
  64694. cellSize[hvIdx] = 'auto';
  64695. }
  64696. return cellSize[hvIdx] != null && cellSize[hvIdx] !== 'auto';
  64697. });
  64698. mergeLayoutParam(target, raw, {
  64699. type: 'box', ignoreSize: ignoreSize
  64700. });
  64701. }
  64702. /*
  64703. * Licensed to the Apache Software Foundation (ASF) under one
  64704. * or more contributor license agreements. See the NOTICE file
  64705. * distributed with this work for additional information
  64706. * regarding copyright ownership. The ASF licenses this file
  64707. * to you under the Apache License, Version 2.0 (the
  64708. * "License"); you may not use this file except in compliance
  64709. * with the License. You may obtain a copy of the License at
  64710. *
  64711. * http://www.apache.org/licenses/LICENSE-2.0
  64712. *
  64713. * Unless required by applicable law or agreed to in writing,
  64714. * software distributed under the License is distributed on an
  64715. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  64716. * KIND, either express or implied. See the License for the
  64717. * specific language governing permissions and limitations
  64718. * under the License.
  64719. */
  64720. var MONTH_TEXT = {
  64721. EN: [
  64722. 'Jan', 'Feb', 'Mar',
  64723. 'Apr', 'May', 'Jun',
  64724. 'Jul', 'Aug', 'Sep',
  64725. 'Oct', 'Nov', 'Dec'
  64726. ],
  64727. CN: [
  64728. '一月', '二月', '三月',
  64729. '四月', '五月', '六月',
  64730. '七月', '八月', '九月',
  64731. '十月', '十一月', '十二月'
  64732. ]
  64733. };
  64734. var WEEK_TEXT = {
  64735. EN: ['S', 'M', 'T', 'W', 'T', 'F', 'S'],
  64736. CN: ['日', '一', '二', '三', '四', '五', '六']
  64737. };
  64738. extendComponentView({
  64739. type: 'calendar',
  64740. /**
  64741. * top/left line points
  64742. * @private
  64743. */
  64744. _tlpoints: null,
  64745. /**
  64746. * bottom/right line points
  64747. * @private
  64748. */
  64749. _blpoints: null,
  64750. /**
  64751. * first day of month
  64752. * @private
  64753. */
  64754. _firstDayOfMonth: null,
  64755. /**
  64756. * first day point of month
  64757. * @private
  64758. */
  64759. _firstDayPoints: null,
  64760. render: function (calendarModel, ecModel, api) {
  64761. var group = this.group;
  64762. group.removeAll();
  64763. var coordSys = calendarModel.coordinateSystem;
  64764. // range info
  64765. var rangeData = coordSys.getRangeInfo();
  64766. var orient = coordSys.getOrient();
  64767. this._renderDayRect(calendarModel, rangeData, group);
  64768. // _renderLines must be called prior to following function
  64769. this._renderLines(calendarModel, rangeData, orient, group);
  64770. this._renderYearText(calendarModel, rangeData, orient, group);
  64771. this._renderMonthText(calendarModel, orient, group);
  64772. this._renderWeekText(calendarModel, rangeData, orient, group);
  64773. },
  64774. // render day rect
  64775. _renderDayRect: function (calendarModel, rangeData, group) {
  64776. var coordSys = calendarModel.coordinateSystem;
  64777. var itemRectStyleModel = calendarModel.getModel('itemStyle').getItemStyle();
  64778. var sw = coordSys.getCellWidth();
  64779. var sh = coordSys.getCellHeight();
  64780. for (var i = rangeData.start.time;
  64781. i <= rangeData.end.time;
  64782. i = coordSys.getNextNDay(i, 1).time
  64783. ) {
  64784. var point = coordSys.dataToRect([i], false).tl;
  64785. // every rect
  64786. var rect = new Rect({
  64787. shape: {
  64788. x: point[0],
  64789. y: point[1],
  64790. width: sw,
  64791. height: sh
  64792. },
  64793. cursor: 'default',
  64794. style: itemRectStyleModel
  64795. });
  64796. group.add(rect);
  64797. }
  64798. },
  64799. // render separate line
  64800. _renderLines: function (calendarModel, rangeData, orient, group) {
  64801. var self = this;
  64802. var coordSys = calendarModel.coordinateSystem;
  64803. var lineStyleModel = calendarModel.getModel('splitLine.lineStyle').getLineStyle();
  64804. var show = calendarModel.get('splitLine.show');
  64805. var lineWidth = lineStyleModel.lineWidth;
  64806. this._tlpoints = [];
  64807. this._blpoints = [];
  64808. this._firstDayOfMonth = [];
  64809. this._firstDayPoints = [];
  64810. var firstDay = rangeData.start;
  64811. for (var i = 0; firstDay.time <= rangeData.end.time; i++) {
  64812. addPoints(firstDay.formatedDate);
  64813. if (i === 0) {
  64814. firstDay = coordSys.getDateInfo(rangeData.start.y + '-' + rangeData.start.m);
  64815. }
  64816. var date = firstDay.date;
  64817. date.setMonth(date.getMonth() + 1);
  64818. firstDay = coordSys.getDateInfo(date);
  64819. }
  64820. addPoints(coordSys.getNextNDay(rangeData.end.time, 1).formatedDate);
  64821. function addPoints(date) {
  64822. self._firstDayOfMonth.push(coordSys.getDateInfo(date));
  64823. self._firstDayPoints.push(coordSys.dataToRect([date], false).tl);
  64824. var points = self._getLinePointsOfOneWeek(calendarModel, date, orient);
  64825. self._tlpoints.push(points[0]);
  64826. self._blpoints.push(points[points.length - 1]);
  64827. show && self._drawSplitline(points, lineStyleModel, group);
  64828. }
  64829. // render top/left line
  64830. show && this._drawSplitline(self._getEdgesPoints(self._tlpoints, lineWidth, orient), lineStyleModel, group);
  64831. // render bottom/right line
  64832. show && this._drawSplitline(self._getEdgesPoints(self._blpoints, lineWidth, orient), lineStyleModel, group);
  64833. },
  64834. // get points at both ends
  64835. _getEdgesPoints: function (points, lineWidth, orient) {
  64836. var rs = [points[0].slice(), points[points.length - 1].slice()];
  64837. var idx = orient === 'horizontal' ? 0 : 1;
  64838. // both ends of the line are extend half lineWidth
  64839. rs[0][idx] = rs[0][idx] - lineWidth / 2;
  64840. rs[1][idx] = rs[1][idx] + lineWidth / 2;
  64841. return rs;
  64842. },
  64843. // render split line
  64844. _drawSplitline: function (points, lineStyleModel, group) {
  64845. var poyline = new Polyline({
  64846. z2: 20,
  64847. shape: {
  64848. points: points
  64849. },
  64850. style: lineStyleModel
  64851. });
  64852. group.add(poyline);
  64853. },
  64854. // render month line of one week points
  64855. _getLinePointsOfOneWeek: function (calendarModel, date, orient) {
  64856. var coordSys = calendarModel.coordinateSystem;
  64857. date = coordSys.getDateInfo(date);
  64858. var points = [];
  64859. for (var i = 0; i < 7; i++) {
  64860. var tmpD = coordSys.getNextNDay(date.time, i);
  64861. var point = coordSys.dataToRect([tmpD.time], false);
  64862. points[2 * tmpD.day] = point.tl;
  64863. points[2 * tmpD.day + 1] = point[orient === 'horizontal' ? 'bl' : 'tr'];
  64864. }
  64865. return points;
  64866. },
  64867. _formatterLabel: function (formatter, params) {
  64868. if (typeof formatter === 'string' && formatter) {
  64869. return formatTplSimple(formatter, params);
  64870. }
  64871. if (typeof formatter === 'function') {
  64872. return formatter(params);
  64873. }
  64874. return params.nameMap;
  64875. },
  64876. _yearTextPositionControl: function (textEl, point, orient, position, margin) {
  64877. point = point.slice();
  64878. var aligns = ['center', 'bottom'];
  64879. if (position === 'bottom') {
  64880. point[1] += margin;
  64881. aligns = ['center', 'top'];
  64882. }
  64883. else if (position === 'left') {
  64884. point[0] -= margin;
  64885. }
  64886. else if (position === 'right') {
  64887. point[0] += margin;
  64888. aligns = ['center', 'top'];
  64889. }
  64890. else { // top
  64891. point[1] -= margin;
  64892. }
  64893. var rotate = 0;
  64894. if (position === 'left' || position === 'right') {
  64895. rotate = Math.PI / 2;
  64896. }
  64897. return {
  64898. rotation: rotate,
  64899. position: point,
  64900. style: {
  64901. textAlign: aligns[0],
  64902. textVerticalAlign: aligns[1]
  64903. }
  64904. };
  64905. },
  64906. // render year
  64907. _renderYearText: function (calendarModel, rangeData, orient, group) {
  64908. var yearLabel = calendarModel.getModel('yearLabel');
  64909. if (!yearLabel.get('show')) {
  64910. return;
  64911. }
  64912. var margin = yearLabel.get('margin');
  64913. var pos = yearLabel.get('position');
  64914. if (!pos) {
  64915. pos = orient !== 'horizontal' ? 'top' : 'left';
  64916. }
  64917. var points = [this._tlpoints[this._tlpoints.length - 1], this._blpoints[0]];
  64918. var xc = (points[0][0] + points[1][0]) / 2;
  64919. var yc = (points[0][1] + points[1][1]) / 2;
  64920. var idx = orient === 'horizontal' ? 0 : 1;
  64921. var posPoints = {
  64922. top: [xc, points[idx][1]],
  64923. bottom: [xc, points[1 - idx][1]],
  64924. left: [points[1 - idx][0], yc],
  64925. right: [points[idx][0], yc]
  64926. };
  64927. var name = rangeData.start.y;
  64928. if (+rangeData.end.y > +rangeData.start.y) {
  64929. name = name + '-' + rangeData.end.y;
  64930. }
  64931. var formatter = yearLabel.get('formatter');
  64932. var params = {
  64933. start: rangeData.start.y,
  64934. end: rangeData.end.y,
  64935. nameMap: name
  64936. };
  64937. var content = this._formatterLabel(formatter, params);
  64938. var yearText = new Text({z2: 30});
  64939. setTextStyle(yearText.style, yearLabel, {text: content}),
  64940. yearText.attr(this._yearTextPositionControl(yearText, posPoints[pos], orient, pos, margin));
  64941. group.add(yearText);
  64942. },
  64943. _monthTextPositionControl: function (point, isCenter, orient, position, margin) {
  64944. var align = 'left';
  64945. var vAlign = 'top';
  64946. var x = point[0];
  64947. var y = point[1];
  64948. if (orient === 'horizontal') {
  64949. y = y + margin;
  64950. if (isCenter) {
  64951. align = 'center';
  64952. }
  64953. if (position === 'start') {
  64954. vAlign = 'bottom';
  64955. }
  64956. }
  64957. else {
  64958. x = x + margin;
  64959. if (isCenter) {
  64960. vAlign = 'middle';
  64961. }
  64962. if (position === 'start') {
  64963. align = 'right';
  64964. }
  64965. }
  64966. return {
  64967. x: x,
  64968. y: y,
  64969. textAlign: align,
  64970. textVerticalAlign: vAlign
  64971. };
  64972. },
  64973. // render month and year text
  64974. _renderMonthText: function (calendarModel, orient, group) {
  64975. var monthLabel = calendarModel.getModel('monthLabel');
  64976. if (!monthLabel.get('show')) {
  64977. return;
  64978. }
  64979. var nameMap = monthLabel.get('nameMap');
  64980. var margin = monthLabel.get('margin');
  64981. var pos = monthLabel.get('position');
  64982. var align = monthLabel.get('align');
  64983. var termPoints = [this._tlpoints, this._blpoints];
  64984. if (isString(nameMap)) {
  64985. nameMap = MONTH_TEXT[nameMap.toUpperCase()] || [];
  64986. }
  64987. var idx = pos === 'start' ? 0 : 1;
  64988. var axis = orient === 'horizontal' ? 0 : 1;
  64989. margin = pos === 'start' ? -margin : margin;
  64990. var isCenter = (align === 'center');
  64991. for (var i = 0; i < termPoints[idx].length - 1; i++) {
  64992. var tmp = termPoints[idx][i].slice();
  64993. var firstDay = this._firstDayOfMonth[i];
  64994. if (isCenter) {
  64995. var firstDayPoints = this._firstDayPoints[i];
  64996. tmp[axis] = (firstDayPoints[axis] + termPoints[0][i + 1][axis]) / 2;
  64997. }
  64998. var formatter = monthLabel.get('formatter');
  64999. var name = nameMap[+firstDay.m - 1];
  65000. var params = {
  65001. yyyy: firstDay.y,
  65002. yy: (firstDay.y + '').slice(2),
  65003. MM: firstDay.m,
  65004. M: +firstDay.m,
  65005. nameMap: name
  65006. };
  65007. var content = this._formatterLabel(formatter, params);
  65008. var monthText = new Text({z2: 30});
  65009. extend(
  65010. setTextStyle(monthText.style, monthLabel, {text: content}),
  65011. this._monthTextPositionControl(tmp, isCenter, orient, pos, margin)
  65012. );
  65013. group.add(monthText);
  65014. }
  65015. },
  65016. _weekTextPositionControl: function (point, orient, position, margin, cellSize) {
  65017. var align = 'center';
  65018. var vAlign = 'middle';
  65019. var x = point[0];
  65020. var y = point[1];
  65021. var isStart = position === 'start';
  65022. if (orient === 'horizontal') {
  65023. x = x + margin + (isStart ? 1 : -1) * cellSize[0] / 2;
  65024. align = isStart ? 'right' : 'left';
  65025. }
  65026. else {
  65027. y = y + margin + (isStart ? 1 : -1) * cellSize[1] / 2;
  65028. vAlign = isStart ? 'bottom' : 'top';
  65029. }
  65030. return {
  65031. x: x,
  65032. y: y,
  65033. textAlign: align,
  65034. textVerticalAlign: vAlign
  65035. };
  65036. },
  65037. // render weeks
  65038. _renderWeekText: function (calendarModel, rangeData, orient, group) {
  65039. var dayLabel = calendarModel.getModel('dayLabel');
  65040. if (!dayLabel.get('show')) {
  65041. return;
  65042. }
  65043. var coordSys = calendarModel.coordinateSystem;
  65044. var pos = dayLabel.get('position');
  65045. var nameMap = dayLabel.get('nameMap');
  65046. var margin = dayLabel.get('margin');
  65047. var firstDayOfWeek = coordSys.getFirstDayOfWeek();
  65048. if (isString(nameMap)) {
  65049. nameMap = WEEK_TEXT[nameMap.toUpperCase()] || [];
  65050. }
  65051. var start = coordSys.getNextNDay(
  65052. rangeData.end.time, (7 - rangeData.lweek)
  65053. ).time;
  65054. var cellSize = [coordSys.getCellWidth(), coordSys.getCellHeight()];
  65055. margin = parsePercent$1(margin, cellSize[orient === 'horizontal' ? 0 : 1]);
  65056. if (pos === 'start') {
  65057. start = coordSys.getNextNDay(
  65058. rangeData.start.time, -(7 + rangeData.fweek)
  65059. ).time;
  65060. margin = -margin;
  65061. }
  65062. for (var i = 0; i < 7; i++) {
  65063. var tmpD = coordSys.getNextNDay(start, i);
  65064. var point = coordSys.dataToRect([tmpD.time], false).center;
  65065. var day = i;
  65066. day = Math.abs((i + firstDayOfWeek) % 7);
  65067. var weekText = new Text({z2: 30});
  65068. extend(
  65069. setTextStyle(weekText.style, dayLabel, {text: nameMap[day]}),
  65070. this._weekTextPositionControl(point, orient, pos, margin, cellSize)
  65071. );
  65072. group.add(weekText);
  65073. }
  65074. }
  65075. });
  65076. /*
  65077. * Licensed to the Apache Software Foundation (ASF) under one
  65078. * or more contributor license agreements. See the NOTICE file
  65079. * distributed with this work for additional information
  65080. * regarding copyright ownership. The ASF licenses this file
  65081. * to you under the Apache License, Version 2.0 (the
  65082. * "License"); you may not use this file except in compliance
  65083. * with the License. You may obtain a copy of the License at
  65084. *
  65085. * http://www.apache.org/licenses/LICENSE-2.0
  65086. *
  65087. * Unless required by applicable law or agreed to in writing,
  65088. * software distributed under the License is distributed on an
  65089. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  65090. * KIND, either express or implied. See the License for the
  65091. * specific language governing permissions and limitations
  65092. * under the License.
  65093. */
  65094. /*
  65095. * Licensed to the Apache Software Foundation (ASF) under one
  65096. * or more contributor license agreements. See the NOTICE file
  65097. * distributed with this work for additional information
  65098. * regarding copyright ownership. The ASF licenses this file
  65099. * to you under the Apache License, Version 2.0 (the
  65100. * "License"); you may not use this file except in compliance
  65101. * with the License. You may obtain a copy of the License at
  65102. *
  65103. * http://www.apache.org/licenses/LICENSE-2.0
  65104. *
  65105. * Unless required by applicable law or agreed to in writing,
  65106. * software distributed under the License is distributed on an
  65107. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  65108. * KIND, either express or implied. See the License for the
  65109. * specific language governing permissions and limitations
  65110. * under the License.
  65111. */
  65112. // -------------
  65113. // Preprocessor
  65114. // -------------
  65115. registerPreprocessor(function (option) {
  65116. var graphicOption = option.graphic;
  65117. // Convert
  65118. // {graphic: [{left: 10, type: 'circle'}, ...]}
  65119. // or
  65120. // {graphic: {left: 10, type: 'circle'}}
  65121. // to
  65122. // {graphic: [{elements: [{left: 10, type: 'circle'}, ...]}]}
  65123. if (isArray(graphicOption)) {
  65124. if (!graphicOption[0] || !graphicOption[0].elements) {
  65125. option.graphic = [{elements: graphicOption}];
  65126. }
  65127. else {
  65128. // Only one graphic instance can be instantiated. (We dont
  65129. // want that too many views are created in echarts._viewMap)
  65130. option.graphic = [option.graphic[0]];
  65131. }
  65132. }
  65133. else if (graphicOption && !graphicOption.elements) {
  65134. option.graphic = [{elements: [graphicOption]}];
  65135. }
  65136. });
  65137. // ------
  65138. // Model
  65139. // ------
  65140. var GraphicModel = extendComponentModel({
  65141. type: 'graphic',
  65142. defaultOption: {
  65143. // Extra properties for each elements:
  65144. //
  65145. // left/right/top/bottom: (like 12, '22%', 'center', default undefined)
  65146. // If left/rigth is set, shape.x/shape.cx/position will not be used.
  65147. // If top/bottom is set, shape.y/shape.cy/position will not be used.
  65148. // This mechanism is useful when you want to position a group/element
  65149. // against the right side or the center of this container.
  65150. //
  65151. // width/height: (can only be pixel value, default 0)
  65152. // Only be used to specify contianer(group) size, if needed. And
  65153. // can not be percentage value (like '33%'). See the reason in the
  65154. // layout algorithm below.
  65155. //
  65156. // bounding: (enum: 'all' (default) | 'raw')
  65157. // Specify how to calculate boundingRect when locating.
  65158. // 'all': Get uioned and transformed boundingRect
  65159. // from both itself and its descendants.
  65160. // This mode simplies confining a group of elements in the bounding
  65161. // of their ancester container (e.g., using 'right: 0').
  65162. // 'raw': Only use the boundingRect of itself and before transformed.
  65163. // This mode is similar to css behavior, which is useful when you
  65164. // want an element to be able to overflow its container. (Consider
  65165. // a rotated circle needs to be located in a corner.)
  65166. // info: custom info. enables user to mount some info on elements and use them
  65167. // in event handlers. Update them only when user specified, otherwise, remain.
  65168. // Note: elements is always behind its ancestors in this elements array.
  65169. elements: [],
  65170. parentId: null
  65171. },
  65172. /**
  65173. * Save el options for the sake of the performance (only update modified graphics).
  65174. * The order is the same as those in option. (ancesters -> descendants)
  65175. *
  65176. * @private
  65177. * @type {Array.<Object>}
  65178. */
  65179. _elOptionsToUpdate: null,
  65180. /**
  65181. * @override
  65182. */
  65183. mergeOption: function (option) {
  65184. // Prevent default merge to elements
  65185. var elements = this.option.elements;
  65186. this.option.elements = null;
  65187. GraphicModel.superApply(this, 'mergeOption', arguments);
  65188. this.option.elements = elements;
  65189. },
  65190. /**
  65191. * @override
  65192. */
  65193. optionUpdated: function (newOption, isInit) {
  65194. var thisOption = this.option;
  65195. var newList = (isInit ? thisOption : newOption).elements;
  65196. var existList = thisOption.elements = isInit ? [] : thisOption.elements;
  65197. var flattenedList = [];
  65198. this._flatten(newList, flattenedList);
  65199. var mappingResult = mappingToExists(existList, flattenedList);
  65200. makeIdAndName(mappingResult);
  65201. // Clear elOptionsToUpdate
  65202. var elOptionsToUpdate = this._elOptionsToUpdate = [];
  65203. each$1(mappingResult, function (resultItem, index) {
  65204. var newElOption = resultItem.option;
  65205. if (__DEV__) {
  65206. assert$1(
  65207. isObject$1(newElOption) || resultItem.exist,
  65208. 'Empty graphic option definition'
  65209. );
  65210. }
  65211. if (!newElOption) {
  65212. return;
  65213. }
  65214. elOptionsToUpdate.push(newElOption);
  65215. setKeyInfoToNewElOption(resultItem, newElOption);
  65216. mergeNewElOptionToExist(existList, index, newElOption);
  65217. setLayoutInfoToExist(existList[index], newElOption);
  65218. }, this);
  65219. // Clean
  65220. for (var i = existList.length - 1; i >= 0; i--) {
  65221. if (existList[i] == null) {
  65222. existList.splice(i, 1);
  65223. }
  65224. else {
  65225. // $action should be volatile, otherwise option gotten from
  65226. // `getOption` will contain unexpected $action.
  65227. delete existList[i].$action;
  65228. }
  65229. }
  65230. },
  65231. /**
  65232. * Convert
  65233. * [{
  65234. * type: 'group',
  65235. * id: 'xx',
  65236. * children: [{type: 'circle'}, {type: 'polygon'}]
  65237. * }]
  65238. * to
  65239. * [
  65240. * {type: 'group', id: 'xx'},
  65241. * {type: 'circle', parentId: 'xx'},
  65242. * {type: 'polygon', parentId: 'xx'}
  65243. * ]
  65244. *
  65245. * @private
  65246. * @param {Array.<Object>} optionList option list
  65247. * @param {Array.<Object>} result result of flatten
  65248. * @param {Object} parentOption parent option
  65249. */
  65250. _flatten: function (optionList, result, parentOption) {
  65251. each$1(optionList, function (option) {
  65252. if (!option) {
  65253. return;
  65254. }
  65255. if (parentOption) {
  65256. option.parentOption = parentOption;
  65257. }
  65258. result.push(option);
  65259. var children = option.children;
  65260. if (option.type === 'group' && children) {
  65261. this._flatten(children, result, option);
  65262. }
  65263. // Deleting for JSON output, and for not affecting group creation.
  65264. delete option.children;
  65265. }, this);
  65266. },
  65267. // FIXME
  65268. // Pass to view using payload? setOption has a payload?
  65269. useElOptionsToUpdate: function () {
  65270. var els = this._elOptionsToUpdate;
  65271. // Clear to avoid render duplicately when zooming.
  65272. this._elOptionsToUpdate = null;
  65273. return els;
  65274. }
  65275. });
  65276. // -----
  65277. // View
  65278. // -----
  65279. extendComponentView({
  65280. type: 'graphic',
  65281. /**
  65282. * @override
  65283. */
  65284. init: function (ecModel, api) {
  65285. /**
  65286. * @private
  65287. * @type {module:zrender/core/util.HashMap}
  65288. */
  65289. this._elMap = createHashMap();
  65290. /**
  65291. * @private
  65292. * @type {module:echarts/graphic/GraphicModel}
  65293. */
  65294. this._lastGraphicModel;
  65295. },
  65296. /**
  65297. * @override
  65298. */
  65299. render: function (graphicModel, ecModel, api) {
  65300. // Having leveraged between use cases and algorithm complexity, a very
  65301. // simple layout mechanism is used:
  65302. // The size(width/height) can be determined by itself or its parent (not
  65303. // implemented yet), but can not by its children. (Top-down travel)
  65304. // The location(x/y) can be determined by the bounding rect of itself
  65305. // (can including its descendants or not) and the size of its parent.
  65306. // (Bottom-up travel)
  65307. // When `chart.clear()` or `chart.setOption({...}, true)` with the same id,
  65308. // view will be reused.
  65309. if (graphicModel !== this._lastGraphicModel) {
  65310. this._clear();
  65311. }
  65312. this._lastGraphicModel = graphicModel;
  65313. this._updateElements(graphicModel);
  65314. this._relocate(graphicModel, api);
  65315. },
  65316. /**
  65317. * Update graphic elements.
  65318. *
  65319. * @private
  65320. * @param {Object} graphicModel graphic model
  65321. */
  65322. _updateElements: function (graphicModel) {
  65323. var elOptionsToUpdate = graphicModel.useElOptionsToUpdate();
  65324. if (!elOptionsToUpdate) {
  65325. return;
  65326. }
  65327. var elMap = this._elMap;
  65328. var rootGroup = this.group;
  65329. // Top-down tranverse to assign graphic settings to each elements.
  65330. each$1(elOptionsToUpdate, function (elOption) {
  65331. var $action = elOption.$action;
  65332. var id = elOption.id;
  65333. var existEl = elMap.get(id);
  65334. var parentId = elOption.parentId;
  65335. var targetElParent = parentId != null ? elMap.get(parentId) : rootGroup;
  65336. var elOptionStyle = elOption.style;
  65337. if (elOption.type === 'text' && elOptionStyle) {
  65338. // In top/bottom mode, textVerticalAlign should not be used, which cause
  65339. // inaccurately locating.
  65340. if (elOption.hv && elOption.hv[1]) {
  65341. elOptionStyle.textVerticalAlign = elOptionStyle.textBaseline = null;
  65342. }
  65343. // Compatible with previous setting: both support fill and textFill,
  65344. // stroke and textStroke.
  65345. !elOptionStyle.hasOwnProperty('textFill') && elOptionStyle.fill && (
  65346. elOptionStyle.textFill = elOptionStyle.fill
  65347. );
  65348. !elOptionStyle.hasOwnProperty('textStroke') && elOptionStyle.stroke && (
  65349. elOptionStyle.textStroke = elOptionStyle.stroke
  65350. );
  65351. }
  65352. // Remove unnecessary props to avoid potential problems.
  65353. var elOptionCleaned = getCleanedElOption(elOption);
  65354. // For simple, do not support parent change, otherwise reorder is needed.
  65355. if (__DEV__) {
  65356. existEl && assert$1(
  65357. targetElParent === existEl.parent,
  65358. 'Changing parent is not supported.'
  65359. );
  65360. }
  65361. if (!$action || $action === 'merge') {
  65362. existEl
  65363. ? existEl.attr(elOptionCleaned)
  65364. : createEl$1(id, targetElParent, elOptionCleaned, elMap);
  65365. }
  65366. else if ($action === 'replace') {
  65367. removeEl(existEl, elMap);
  65368. createEl$1(id, targetElParent, elOptionCleaned, elMap);
  65369. }
  65370. else if ($action === 'remove') {
  65371. removeEl(existEl, elMap);
  65372. }
  65373. var el = elMap.get(id);
  65374. if (el) {
  65375. el.__ecGraphicWidth = elOption.width;
  65376. el.__ecGraphicHeight = elOption.height;
  65377. setEventData(el, graphicModel, elOption);
  65378. }
  65379. });
  65380. },
  65381. /**
  65382. * Locate graphic elements.
  65383. *
  65384. * @private
  65385. * @param {Object} graphicModel graphic model
  65386. * @param {module:echarts/ExtensionAPI} api extension API
  65387. */
  65388. _relocate: function (graphicModel, api) {
  65389. var elOptions = graphicModel.option.elements;
  65390. var rootGroup = this.group;
  65391. var elMap = this._elMap;
  65392. // Bottom-up tranvese all elements (consider ec resize) to locate elements.
  65393. for (var i = elOptions.length - 1; i >= 0; i--) {
  65394. var elOption = elOptions[i];
  65395. var el = elMap.get(elOption.id);
  65396. if (!el) {
  65397. continue;
  65398. }
  65399. var parentEl = el.parent;
  65400. var containerInfo = parentEl === rootGroup
  65401. ? {
  65402. width: api.getWidth(),
  65403. height: api.getHeight()
  65404. }
  65405. : { // Like 'position:absolut' in css, default 0.
  65406. width: parentEl.__ecGraphicWidth || 0,
  65407. height: parentEl.__ecGraphicHeight || 0
  65408. };
  65409. positionElement(
  65410. el, elOption, containerInfo, null,
  65411. {hv: elOption.hv, boundingMode: elOption.bounding}
  65412. );
  65413. }
  65414. },
  65415. /**
  65416. * Clear all elements.
  65417. *
  65418. * @private
  65419. */
  65420. _clear: function () {
  65421. var elMap = this._elMap;
  65422. elMap.each(function (el) {
  65423. removeEl(el, elMap);
  65424. });
  65425. this._elMap = createHashMap();
  65426. },
  65427. /**
  65428. * @override
  65429. */
  65430. dispose: function () {
  65431. this._clear();
  65432. }
  65433. });
  65434. function createEl$1(id, targetElParent, elOption, elMap) {
  65435. var graphicType = elOption.type;
  65436. if (__DEV__) {
  65437. assert$1(graphicType, 'graphic type MUST be set');
  65438. }
  65439. var Clz = graphic[graphicType.charAt(0).toUpperCase() + graphicType.slice(1)];
  65440. if (__DEV__) {
  65441. assert$1(Clz, 'graphic type can not be found');
  65442. }
  65443. var el = new Clz(elOption);
  65444. targetElParent.add(el);
  65445. elMap.set(id, el);
  65446. el.__ecGraphicId = id;
  65447. }
  65448. function removeEl(existEl, elMap) {
  65449. var existElParent = existEl && existEl.parent;
  65450. if (existElParent) {
  65451. existEl.type === 'group' && existEl.traverse(function (el) {
  65452. removeEl(el, elMap);
  65453. });
  65454. elMap.removeKey(existEl.__ecGraphicId);
  65455. existElParent.remove(existEl);
  65456. }
  65457. }
  65458. // Remove unnecessary props to avoid potential problems.
  65459. function getCleanedElOption(elOption) {
  65460. elOption = extend({}, elOption);
  65461. each$1(
  65462. ['id', 'parentId', '$action', 'hv', 'bounding'].concat(LOCATION_PARAMS),
  65463. function (name) {
  65464. delete elOption[name];
  65465. }
  65466. );
  65467. return elOption;
  65468. }
  65469. function isSetLoc(obj, props) {
  65470. var isSet;
  65471. each$1(props, function (prop) {
  65472. obj[prop] != null && obj[prop] !== 'auto' && (isSet = true);
  65473. });
  65474. return isSet;
  65475. }
  65476. function setKeyInfoToNewElOption(resultItem, newElOption) {
  65477. var existElOption = resultItem.exist;
  65478. // Set id and type after id assigned.
  65479. newElOption.id = resultItem.keyInfo.id;
  65480. !newElOption.type && existElOption && (newElOption.type = existElOption.type);
  65481. // Set parent id if not specified
  65482. if (newElOption.parentId == null) {
  65483. var newElParentOption = newElOption.parentOption;
  65484. if (newElParentOption) {
  65485. newElOption.parentId = newElParentOption.id;
  65486. }
  65487. else if (existElOption) {
  65488. newElOption.parentId = existElOption.parentId;
  65489. }
  65490. }
  65491. // Clear
  65492. newElOption.parentOption = null;
  65493. }
  65494. function mergeNewElOptionToExist(existList, index, newElOption) {
  65495. // Update existing options, for `getOption` feature.
  65496. var newElOptCopy = extend({}, newElOption);
  65497. var existElOption = existList[index];
  65498. var $action = newElOption.$action || 'merge';
  65499. if ($action === 'merge') {
  65500. if (existElOption) {
  65501. if (__DEV__) {
  65502. var newType = newElOption.type;
  65503. assert$1(
  65504. !newType || existElOption.type === newType,
  65505. 'Please set $action: "replace" to change `type`'
  65506. );
  65507. }
  65508. // We can ensure that newElOptCopy and existElOption are not
  65509. // the same object, so `merge` will not change newElOptCopy.
  65510. merge(existElOption, newElOptCopy, true);
  65511. // Rigid body, use ignoreSize.
  65512. mergeLayoutParam(existElOption, newElOptCopy, {ignoreSize: true});
  65513. // Will be used in render.
  65514. copyLayoutParams(newElOption, existElOption);
  65515. }
  65516. else {
  65517. existList[index] = newElOptCopy;
  65518. }
  65519. }
  65520. else if ($action === 'replace') {
  65521. existList[index] = newElOptCopy;
  65522. }
  65523. else if ($action === 'remove') {
  65524. // null will be cleaned later.
  65525. existElOption && (existList[index] = null);
  65526. }
  65527. }
  65528. function setLayoutInfoToExist(existItem, newElOption) {
  65529. if (!existItem) {
  65530. return;
  65531. }
  65532. existItem.hv = newElOption.hv = [
  65533. // Rigid body, dont care `width`.
  65534. isSetLoc(newElOption, ['left', 'right']),
  65535. // Rigid body, dont care `height`.
  65536. isSetLoc(newElOption, ['top', 'bottom'])
  65537. ];
  65538. // Give default group size. Otherwise layout error may occur.
  65539. if (existItem.type === 'group') {
  65540. existItem.width == null && (existItem.width = newElOption.width = 0);
  65541. existItem.height == null && (existItem.height = newElOption.height = 0);
  65542. }
  65543. }
  65544. function setEventData(el, graphicModel, elOption) {
  65545. var eventData = el.eventData;
  65546. // Simple optimize for large amount of elements that no need event.
  65547. if (!el.silent && !el.ignore && !eventData) {
  65548. eventData = el.eventData = {
  65549. componentType: 'graphic',
  65550. componentIndex: graphicModel.componentIndex,
  65551. name: el.name
  65552. };
  65553. }
  65554. // `elOption.info` enables user to mount some info on
  65555. // elements and use them in event handlers.
  65556. if (eventData) {
  65557. eventData.info = el.info;
  65558. }
  65559. }
  65560. /*
  65561. * Licensed to the Apache Software Foundation (ASF) under one
  65562. * or more contributor license agreements. See the NOTICE file
  65563. * distributed with this work for additional information
  65564. * regarding copyright ownership. The ASF licenses this file
  65565. * to you under the Apache License, Version 2.0 (the
  65566. * "License"); you may not use this file except in compliance
  65567. * with the License. You may obtain a copy of the License at
  65568. *
  65569. * http://www.apache.org/licenses/LICENSE-2.0
  65570. *
  65571. * Unless required by applicable law or agreed to in writing,
  65572. * software distributed under the License is distributed on an
  65573. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  65574. * KIND, either express or implied. See the License for the
  65575. * specific language governing permissions and limitations
  65576. * under the License.
  65577. */
  65578. var features = {};
  65579. function register$1(name, ctor) {
  65580. features[name] = ctor;
  65581. }
  65582. function get$1(name) {
  65583. return features[name];
  65584. }
  65585. /*
  65586. * Licensed to the Apache Software Foundation (ASF) under one
  65587. * or more contributor license agreements. See the NOTICE file
  65588. * distributed with this work for additional information
  65589. * regarding copyright ownership. The ASF licenses this file
  65590. * to you under the Apache License, Version 2.0 (the
  65591. * "License"); you may not use this file except in compliance
  65592. * with the License. You may obtain a copy of the License at
  65593. *
  65594. * http://www.apache.org/licenses/LICENSE-2.0
  65595. *
  65596. * Unless required by applicable law or agreed to in writing,
  65597. * software distributed under the License is distributed on an
  65598. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  65599. * KIND, either express or implied. See the License for the
  65600. * specific language governing permissions and limitations
  65601. * under the License.
  65602. */
  65603. var ToolboxModel = extendComponentModel({
  65604. type: 'toolbox',
  65605. layoutMode: {
  65606. type: 'box',
  65607. ignoreSize: true
  65608. },
  65609. optionUpdated: function () {
  65610. ToolboxModel.superApply(this, 'optionUpdated', arguments);
  65611. each$1(this.option.feature, function (featureOpt, featureName) {
  65612. var Feature = get$1(featureName);
  65613. Feature && merge(featureOpt, Feature.defaultOption);
  65614. });
  65615. },
  65616. defaultOption: {
  65617. show: true,
  65618. z: 6,
  65619. zlevel: 0,
  65620. orient: 'horizontal',
  65621. left: 'right',
  65622. top: 'top',
  65623. // right
  65624. // bottom
  65625. backgroundColor: 'transparent',
  65626. borderColor: '#ccc',
  65627. borderRadius: 0,
  65628. borderWidth: 0,
  65629. padding: 5,
  65630. itemSize: 15,
  65631. itemGap: 8,
  65632. showTitle: true,
  65633. iconStyle: {
  65634. borderColor: '#666',
  65635. color: 'none'
  65636. },
  65637. emphasis: {
  65638. iconStyle: {
  65639. borderColor: '#3E98C5'
  65640. }
  65641. },
  65642. // textStyle: {},
  65643. // feature
  65644. tooltip: {
  65645. show: false
  65646. }
  65647. }
  65648. });
  65649. /*
  65650. * Licensed to the Apache Software Foundation (ASF) under one
  65651. * or more contributor license agreements. See the NOTICE file
  65652. * distributed with this work for additional information
  65653. * regarding copyright ownership. The ASF licenses this file
  65654. * to you under the Apache License, Version 2.0 (the
  65655. * "License"); you may not use this file except in compliance
  65656. * with the License. You may obtain a copy of the License at
  65657. *
  65658. * http://www.apache.org/licenses/LICENSE-2.0
  65659. *
  65660. * Unless required by applicable law or agreed to in writing,
  65661. * software distributed under the License is distributed on an
  65662. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  65663. * KIND, either express or implied. See the License for the
  65664. * specific language governing permissions and limitations
  65665. * under the License.
  65666. */
  65667. /**
  65668. * Layout list like component.
  65669. * It will box layout each items in group of component and then position the whole group in the viewport
  65670. * @param {module:zrender/group/Group} group
  65671. * @param {module:echarts/model/Component} componentModel
  65672. * @param {module:echarts/ExtensionAPI}
  65673. */
  65674. function layout$3(group, componentModel, api) {
  65675. var boxLayoutParams = componentModel.getBoxLayoutParams();
  65676. var padding = componentModel.get('padding');
  65677. var viewportSize = {width: api.getWidth(), height: api.getHeight()};
  65678. var rect = getLayoutRect(
  65679. boxLayoutParams,
  65680. viewportSize,
  65681. padding
  65682. );
  65683. box(
  65684. componentModel.get('orient'),
  65685. group,
  65686. componentModel.get('itemGap'),
  65687. rect.width,
  65688. rect.height
  65689. );
  65690. positionElement(
  65691. group,
  65692. boxLayoutParams,
  65693. viewportSize,
  65694. padding
  65695. );
  65696. }
  65697. function makeBackground(rect, componentModel) {
  65698. var padding = normalizeCssArray$1(
  65699. componentModel.get('padding')
  65700. );
  65701. var style = componentModel.getItemStyle(['color', 'opacity']);
  65702. style.fill = componentModel.get('backgroundColor');
  65703. var rect = new Rect({
  65704. shape: {
  65705. x: rect.x - padding[3],
  65706. y: rect.y - padding[0],
  65707. width: rect.width + padding[1] + padding[3],
  65708. height: rect.height + padding[0] + padding[2],
  65709. r: componentModel.get('borderRadius')
  65710. },
  65711. style: style,
  65712. silent: true,
  65713. z2: -1
  65714. });
  65715. // FIXME
  65716. // `subPixelOptimizeRect` may bring some gap between edge of viewpart
  65717. // and background rect when setting like `left: 0`, `top: 0`.
  65718. // graphic.subPixelOptimizeRect(rect);
  65719. return rect;
  65720. }
  65721. /*
  65722. * Licensed to the Apache Software Foundation (ASF) under one
  65723. * or more contributor license agreements. See the NOTICE file
  65724. * distributed with this work for additional information
  65725. * regarding copyright ownership. The ASF licenses this file
  65726. * to you under the Apache License, Version 2.0 (the
  65727. * "License"); you may not use this file except in compliance
  65728. * with the License. You may obtain a copy of the License at
  65729. *
  65730. * http://www.apache.org/licenses/LICENSE-2.0
  65731. *
  65732. * Unless required by applicable law or agreed to in writing,
  65733. * software distributed under the License is distributed on an
  65734. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  65735. * KIND, either express or implied. See the License for the
  65736. * specific language governing permissions and limitations
  65737. * under the License.
  65738. */
  65739. extendComponentView({
  65740. type: 'toolbox',
  65741. render: function (toolboxModel, ecModel, api, payload) {
  65742. var group = this.group;
  65743. group.removeAll();
  65744. if (!toolboxModel.get('show')) {
  65745. return;
  65746. }
  65747. var itemSize = +toolboxModel.get('itemSize');
  65748. var featureOpts = toolboxModel.get('feature') || {};
  65749. var features = this._features || (this._features = {});
  65750. var featureNames = [];
  65751. each$1(featureOpts, function (opt, name) {
  65752. featureNames.push(name);
  65753. });
  65754. (new DataDiffer(this._featureNames || [], featureNames))
  65755. .add(processFeature)
  65756. .update(processFeature)
  65757. .remove(curry(processFeature, null))
  65758. .execute();
  65759. // Keep for diff.
  65760. this._featureNames = featureNames;
  65761. function processFeature(newIndex, oldIndex) {
  65762. var featureName = featureNames[newIndex];
  65763. var oldName = featureNames[oldIndex];
  65764. var featureOpt = featureOpts[featureName];
  65765. var featureModel = new Model(featureOpt, toolboxModel, toolboxModel.ecModel);
  65766. var feature;
  65767. if (featureName && !oldName) { // Create
  65768. if (isUserFeatureName(featureName)) {
  65769. feature = {
  65770. model: featureModel,
  65771. onclick: featureModel.option.onclick,
  65772. featureName: featureName
  65773. };
  65774. }
  65775. else {
  65776. var Feature = get$1(featureName);
  65777. if (!Feature) {
  65778. return;
  65779. }
  65780. feature = new Feature(featureModel, ecModel, api);
  65781. }
  65782. features[featureName] = feature;
  65783. }
  65784. else {
  65785. feature = features[oldName];
  65786. // If feature does not exsit.
  65787. if (!feature) {
  65788. return;
  65789. }
  65790. feature.model = featureModel;
  65791. feature.ecModel = ecModel;
  65792. feature.api = api;
  65793. }
  65794. if (!featureName && oldName) {
  65795. feature.dispose && feature.dispose(ecModel, api);
  65796. return;
  65797. }
  65798. if (!featureModel.get('show') || feature.unusable) {
  65799. feature.remove && feature.remove(ecModel, api);
  65800. return;
  65801. }
  65802. createIconPaths(featureModel, feature, featureName);
  65803. featureModel.setIconStatus = function (iconName, status) {
  65804. var option = this.option;
  65805. var iconPaths = this.iconPaths;
  65806. option.iconStatus = option.iconStatus || {};
  65807. option.iconStatus[iconName] = status;
  65808. // FIXME
  65809. iconPaths[iconName] && iconPaths[iconName].trigger(status);
  65810. };
  65811. if (feature.render) {
  65812. feature.render(featureModel, ecModel, api, payload);
  65813. }
  65814. }
  65815. function createIconPaths(featureModel, feature, featureName) {
  65816. var iconStyleModel = featureModel.getModel('iconStyle');
  65817. var iconStyleEmphasisModel = featureModel.getModel('emphasis.iconStyle');
  65818. // If one feature has mutiple icon. they are orginaized as
  65819. // {
  65820. // icon: {
  65821. // foo: '',
  65822. // bar: ''
  65823. // },
  65824. // title: {
  65825. // foo: '',
  65826. // bar: ''
  65827. // }
  65828. // }
  65829. var icons = feature.getIcons ? feature.getIcons() : featureModel.get('icon');
  65830. var titles = featureModel.get('title') || {};
  65831. if (typeof icons === 'string') {
  65832. var icon = icons;
  65833. var title = titles;
  65834. icons = {};
  65835. titles = {};
  65836. icons[featureName] = icon;
  65837. titles[featureName] = title;
  65838. }
  65839. var iconPaths = featureModel.iconPaths = {};
  65840. each$1(icons, function (iconStr, iconName) {
  65841. var path = createIcon(
  65842. iconStr,
  65843. {},
  65844. {
  65845. x: -itemSize / 2,
  65846. y: -itemSize / 2,
  65847. width: itemSize,
  65848. height: itemSize
  65849. }
  65850. );
  65851. path.setStyle(iconStyleModel.getItemStyle());
  65852. path.hoverStyle = iconStyleEmphasisModel.getItemStyle();
  65853. var tooltipModel = toolboxModel.getModel('tooltip');
  65854. if (tooltipModel && tooltipModel.get('show')) {
  65855. path.attr('tooltip', extend({
  65856. content: titles[iconName],
  65857. formatter: tooltipModel.get('formatter', true)
  65858. || function () {
  65859. return titles[iconName];
  65860. },
  65861. formatterParams: {
  65862. componentType: 'toolbox',
  65863. name: iconName,
  65864. title: titles[iconName],
  65865. $vars: ['name', 'title']
  65866. },
  65867. position: tooltipModel.get('position', true) || 'bottom'
  65868. }, tooltipModel.option));
  65869. }
  65870. setHoverStyle(path);
  65871. if (toolboxModel.get('showTitle')) {
  65872. path.__title = titles[iconName];
  65873. path.on('mouseover', function () {
  65874. // Should not reuse above hoverStyle, which might be modified.
  65875. var hoverStyle = iconStyleEmphasisModel.getItemStyle();
  65876. path.setStyle({
  65877. text: titles[iconName],
  65878. textPosition: iconStyleEmphasisModel.get('textPosition') || 'bottom',
  65879. textFill: iconStyleEmphasisModel.get('textFill') || hoverStyle.fill || hoverStyle.stroke || '#000',
  65880. textAlign: iconStyleEmphasisModel.get('textAlign') || 'center',
  65881. textBackgroundColor: iconStyleEmphasisModel.get('textBackgroundColor'),
  65882. textBorderRadius: iconStyleEmphasisModel.get('textBorderRadius'),
  65883. textPadding: iconStyleEmphasisModel.get('textPadding')
  65884. });
  65885. })
  65886. .on('mouseout', function () {
  65887. path.setStyle({
  65888. textFill: null,
  65889. textBackgroundColor: null
  65890. });
  65891. });
  65892. }
  65893. path.trigger(featureModel.get('iconStatus.' + iconName) || 'normal');
  65894. group.add(path);
  65895. path.on('click', bind(
  65896. feature.onclick, feature, ecModel, api, iconName
  65897. ));
  65898. iconPaths[iconName] = path;
  65899. });
  65900. }
  65901. layout$3(group, toolboxModel, api);
  65902. // Render background after group is layout
  65903. // FIXME
  65904. group.add(makeBackground(group.getBoundingRect(), toolboxModel));
  65905. // Adjust icon title positions to avoid them out of screen
  65906. group.eachChild(function (icon) {
  65907. var titleText = icon.__title;
  65908. var hoverStyle = icon.hoverStyle;
  65909. // May be background element
  65910. if (hoverStyle && titleText) {
  65911. var rect = getBoundingRect(
  65912. titleText, makeFont(hoverStyle)
  65913. );
  65914. var offsetX = icon.position[0] + group.position[0];
  65915. var offsetY = icon.position[1] + group.position[1] + itemSize;
  65916. var needPutOnTop = false;
  65917. if (offsetY + rect.height > api.getHeight()) {
  65918. hoverStyle.textPosition = 'top';
  65919. needPutOnTop = true;
  65920. }
  65921. var topOffset = needPutOnTop ? (-5 - rect.height) : (itemSize + 8);
  65922. if (offsetX + rect.width / 2 > api.getWidth()) {
  65923. hoverStyle.textPosition = ['100%', topOffset];
  65924. hoverStyle.textAlign = 'right';
  65925. }
  65926. else if (offsetX - rect.width / 2 < 0) {
  65927. hoverStyle.textPosition = [0, topOffset];
  65928. hoverStyle.textAlign = 'left';
  65929. }
  65930. }
  65931. });
  65932. },
  65933. updateView: function (toolboxModel, ecModel, api, payload) {
  65934. each$1(this._features, function (feature) {
  65935. feature.updateView && feature.updateView(feature.model, ecModel, api, payload);
  65936. });
  65937. },
  65938. // updateLayout: function (toolboxModel, ecModel, api, payload) {
  65939. // zrUtil.each(this._features, function (feature) {
  65940. // feature.updateLayout && feature.updateLayout(feature.model, ecModel, api, payload);
  65941. // });
  65942. // },
  65943. remove: function (ecModel, api) {
  65944. each$1(this._features, function (feature) {
  65945. feature.remove && feature.remove(ecModel, api);
  65946. });
  65947. this.group.removeAll();
  65948. },
  65949. dispose: function (ecModel, api) {
  65950. each$1(this._features, function (feature) {
  65951. feature.dispose && feature.dispose(ecModel, api);
  65952. });
  65953. }
  65954. });
  65955. function isUserFeatureName(featureName) {
  65956. return featureName.indexOf('my') === 0;
  65957. }
  65958. /*
  65959. * Licensed to the Apache Software Foundation (ASF) under one
  65960. * or more contributor license agreements. See the NOTICE file
  65961. * distributed with this work for additional information
  65962. * regarding copyright ownership. The ASF licenses this file
  65963. * to you under the Apache License, Version 2.0 (the
  65964. * "License"); you may not use this file except in compliance
  65965. * with the License. You may obtain a copy of the License at
  65966. *
  65967. * http://www.apache.org/licenses/LICENSE-2.0
  65968. *
  65969. * Unless required by applicable law or agreed to in writing,
  65970. * software distributed under the License is distributed on an
  65971. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  65972. * KIND, either express or implied. See the License for the
  65973. * specific language governing permissions and limitations
  65974. * under the License.
  65975. */
  65976. /* global Uint8Array */
  65977. var saveAsImageLang = lang.toolbox.saveAsImage;
  65978. function SaveAsImage(model) {
  65979. this.model = model;
  65980. }
  65981. SaveAsImage.defaultOption = {
  65982. show: true,
  65983. 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',
  65984. title: saveAsImageLang.title,
  65985. type: 'png',
  65986. // Default use option.backgroundColor
  65987. // backgroundColor: '#fff',
  65988. connectedBackgroundColor: '#fff',
  65989. name: '',
  65990. excludeComponents: ['toolbox'],
  65991. pixelRatio: 1,
  65992. lang: saveAsImageLang.lang.slice()
  65993. };
  65994. SaveAsImage.prototype.unusable = !env$1.canvasSupported;
  65995. var proto$2 = SaveAsImage.prototype;
  65996. proto$2.onclick = function (ecModel, api) {
  65997. var model = this.model;
  65998. var title = model.get('name') || ecModel.get('title.0.text') || 'echarts';
  65999. var type = model.get('type', true) || 'png';
  66000. var url = api.getConnectedDataURL({
  66001. type: type,
  66002. backgroundColor: model.get('backgroundColor', true)
  66003. || ecModel.get('backgroundColor') || '#fff',
  66004. connectedBackgroundColor: model.get('connectedBackgroundColor'),
  66005. excludeComponents: model.get('excludeComponents'),
  66006. pixelRatio: model.get('pixelRatio')
  66007. });
  66008. // Chrome and Firefox
  66009. if (typeof MouseEvent === 'function' && !env$1.browser.ie && !env$1.browser.edge) {
  66010. var $a = document.createElement('a');
  66011. $a.download = title + '.' + type;
  66012. $a.target = '_blank';
  66013. $a.href = url;
  66014. var evt = new MouseEvent('click', {
  66015. view: window,
  66016. bubbles: true,
  66017. cancelable: false
  66018. });
  66019. $a.dispatchEvent(evt);
  66020. }
  66021. // IE
  66022. else {
  66023. if (window.navigator.msSaveOrOpenBlob) {
  66024. var bstr = atob(url.split(',')[1]);
  66025. var n = bstr.length;
  66026. var u8arr = new Uint8Array(n);
  66027. while (n--) {
  66028. u8arr[n] = bstr.charCodeAt(n);
  66029. }
  66030. var blob = new Blob([u8arr]);
  66031. window.navigator.msSaveOrOpenBlob(blob, title + '.' + type);
  66032. }
  66033. else {
  66034. var lang$$1 = model.get('lang');
  66035. var html = ''
  66036. + '<body style="margin:0;">'
  66037. + '<img src="' + url + '" style="max-width:100%;" title="' + ((lang$$1 && lang$$1[0]) || '') + '" />'
  66038. + '</body>';
  66039. var tab = window.open();
  66040. tab.document.write(html);
  66041. }
  66042. }
  66043. };
  66044. register$1(
  66045. 'saveAsImage', SaveAsImage
  66046. );
  66047. /*
  66048. * Licensed to the Apache Software Foundation (ASF) under one
  66049. * or more contributor license agreements. See the NOTICE file
  66050. * distributed with this work for additional information
  66051. * regarding copyright ownership. The ASF licenses this file
  66052. * to you under the Apache License, Version 2.0 (the
  66053. * "License"); you may not use this file except in compliance
  66054. * with the License. You may obtain a copy of the License at
  66055. *
  66056. * http://www.apache.org/licenses/LICENSE-2.0
  66057. *
  66058. * Unless required by applicable law or agreed to in writing,
  66059. * software distributed under the License is distributed on an
  66060. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  66061. * KIND, either express or implied. See the License for the
  66062. * specific language governing permissions and limitations
  66063. * under the License.
  66064. */
  66065. var magicTypeLang = lang.toolbox.magicType;
  66066. function MagicType(model) {
  66067. this.model = model;
  66068. }
  66069. MagicType.defaultOption = {
  66070. show: true,
  66071. type: [],
  66072. // Icon group
  66073. icon: {
  66074. /* eslint-disable */
  66075. line: 'M4.1,28.9h7.1l9.3-22l7.4,38l9.7-19.7l3,12.8h14.9M4.1,58h51.4',
  66076. bar: 'M6.7,22.9h10V48h-10V22.9zM24.9,13h10v35h-10V13zM43.2,2h10v46h-10V2zM3.1,58h53.7',
  66077. 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
  66078. tiled: 'M2.3,2.2h22.8V25H2.3V2.2z M35,2.2h22.8V25H35V2.2zM2.3,35h22.8v22.8H2.3V35z M35,35h22.8v22.8H35V35z'
  66079. /* eslint-enable */
  66080. },
  66081. // `line`, `bar`, `stack`, `tiled`
  66082. title: clone(magicTypeLang.title),
  66083. option: {},
  66084. seriesIndex: {}
  66085. };
  66086. var proto$3 = MagicType.prototype;
  66087. proto$3.getIcons = function () {
  66088. var model = this.model;
  66089. var availableIcons = model.get('icon');
  66090. var icons = {};
  66091. each$1(model.get('type'), function (type) {
  66092. if (availableIcons[type]) {
  66093. icons[type] = availableIcons[type];
  66094. }
  66095. });
  66096. return icons;
  66097. };
  66098. var seriesOptGenreator = {
  66099. 'line': function (seriesType, seriesId, seriesModel, model) {
  66100. if (seriesType === 'bar') {
  66101. return merge({
  66102. id: seriesId,
  66103. type: 'line',
  66104. // Preserve data related option
  66105. data: seriesModel.get('data'),
  66106. stack: seriesModel.get('stack'),
  66107. markPoint: seriesModel.get('markPoint'),
  66108. markLine: seriesModel.get('markLine')
  66109. }, model.get('option.line') || {}, true);
  66110. }
  66111. },
  66112. 'bar': function (seriesType, seriesId, seriesModel, model) {
  66113. if (seriesType === 'line') {
  66114. return merge({
  66115. id: seriesId,
  66116. type: 'bar',
  66117. // Preserve data related option
  66118. data: seriesModel.get('data'),
  66119. stack: seriesModel.get('stack'),
  66120. markPoint: seriesModel.get('markPoint'),
  66121. markLine: seriesModel.get('markLine')
  66122. }, model.get('option.bar') || {}, true);
  66123. }
  66124. },
  66125. 'stack': function (seriesType, seriesId, seriesModel, model) {
  66126. if (seriesType === 'line' || seriesType === 'bar') {
  66127. return merge({
  66128. id: seriesId,
  66129. stack: '__ec_magicType_stack__'
  66130. }, model.get('option.stack') || {}, true);
  66131. }
  66132. },
  66133. 'tiled': function (seriesType, seriesId, seriesModel, model) {
  66134. if (seriesType === 'line' || seriesType === 'bar') {
  66135. return merge({
  66136. id: seriesId,
  66137. stack: ''
  66138. }, model.get('option.tiled') || {}, true);
  66139. }
  66140. }
  66141. };
  66142. var radioTypes = [
  66143. ['line', 'bar'],
  66144. ['stack', 'tiled']
  66145. ];
  66146. proto$3.onclick = function (ecModel, api, type) {
  66147. var model = this.model;
  66148. var seriesIndex = model.get('seriesIndex.' + type);
  66149. // Not supported magicType
  66150. if (!seriesOptGenreator[type]) {
  66151. return;
  66152. }
  66153. var newOption = {
  66154. series: []
  66155. };
  66156. var generateNewSeriesTypes = function (seriesModel) {
  66157. var seriesType = seriesModel.subType;
  66158. var seriesId = seriesModel.id;
  66159. var newSeriesOpt = seriesOptGenreator[type](
  66160. seriesType, seriesId, seriesModel, model
  66161. );
  66162. if (newSeriesOpt) {
  66163. // PENDING If merge original option?
  66164. defaults(newSeriesOpt, seriesModel.option);
  66165. newOption.series.push(newSeriesOpt);
  66166. }
  66167. // Modify boundaryGap
  66168. var coordSys = seriesModel.coordinateSystem;
  66169. if (coordSys && coordSys.type === 'cartesian2d' && (type === 'line' || type === 'bar')) {
  66170. var categoryAxis = coordSys.getAxesByScale('ordinal')[0];
  66171. if (categoryAxis) {
  66172. var axisDim = categoryAxis.dim;
  66173. var axisType = axisDim + 'Axis';
  66174. var axisModel = ecModel.queryComponents({
  66175. mainType: axisType,
  66176. index: seriesModel.get(name + 'Index'),
  66177. id: seriesModel.get(name + 'Id')
  66178. })[0];
  66179. var axisIndex = axisModel.componentIndex;
  66180. newOption[axisType] = newOption[axisType] || [];
  66181. for (var i = 0; i <= axisIndex; i++) {
  66182. newOption[axisType][axisIndex] = newOption[axisType][axisIndex] || {};
  66183. }
  66184. newOption[axisType][axisIndex].boundaryGap = type === 'bar';
  66185. }
  66186. }
  66187. };
  66188. each$1(radioTypes, function (radio) {
  66189. if (indexOf(radio, type) >= 0) {
  66190. each$1(radio, function (item) {
  66191. model.setIconStatus(item, 'normal');
  66192. });
  66193. }
  66194. });
  66195. model.setIconStatus(type, 'emphasis');
  66196. ecModel.eachComponent(
  66197. {
  66198. mainType: 'series',
  66199. query: seriesIndex == null ? null : {
  66200. seriesIndex: seriesIndex
  66201. }
  66202. }, generateNewSeriesTypes
  66203. );
  66204. api.dispatchAction({
  66205. type: 'changeMagicType',
  66206. currentType: type,
  66207. newOption: newOption
  66208. });
  66209. };
  66210. registerAction({
  66211. type: 'changeMagicType',
  66212. event: 'magicTypeChanged',
  66213. update: 'prepareAndUpdate'
  66214. }, function (payload, ecModel) {
  66215. ecModel.mergeOption(payload.newOption);
  66216. });
  66217. register$1('magicType', MagicType);
  66218. /*
  66219. * Licensed to the Apache Software Foundation (ASF) under one
  66220. * or more contributor license agreements. See the NOTICE file
  66221. * distributed with this work for additional information
  66222. * regarding copyright ownership. The ASF licenses this file
  66223. * to you under the Apache License, Version 2.0 (the
  66224. * "License"); you may not use this file except in compliance
  66225. * with the License. You may obtain a copy of the License at
  66226. *
  66227. * http://www.apache.org/licenses/LICENSE-2.0
  66228. *
  66229. * Unless required by applicable law or agreed to in writing,
  66230. * software distributed under the License is distributed on an
  66231. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  66232. * KIND, either express or implied. See the License for the
  66233. * specific language governing permissions and limitations
  66234. * under the License.
  66235. */
  66236. var dataViewLang = lang.toolbox.dataView;
  66237. var BLOCK_SPLITER = new Array(60).join('-');
  66238. var ITEM_SPLITER = '\t';
  66239. /**
  66240. * Group series into two types
  66241. * 1. on category axis, like line, bar
  66242. * 2. others, like scatter, pie
  66243. * @param {module:echarts/model/Global} ecModel
  66244. * @return {Object}
  66245. * @inner
  66246. */
  66247. function groupSeries(ecModel) {
  66248. var seriesGroupByCategoryAxis = {};
  66249. var otherSeries = [];
  66250. var meta = [];
  66251. ecModel.eachRawSeries(function (seriesModel) {
  66252. var coordSys = seriesModel.coordinateSystem;
  66253. if (coordSys && (coordSys.type === 'cartesian2d' || coordSys.type === 'polar')) {
  66254. var baseAxis = coordSys.getBaseAxis();
  66255. if (baseAxis.type === 'category') {
  66256. var key = baseAxis.dim + '_' + baseAxis.index;
  66257. if (!seriesGroupByCategoryAxis[key]) {
  66258. seriesGroupByCategoryAxis[key] = {
  66259. categoryAxis: baseAxis,
  66260. valueAxis: coordSys.getOtherAxis(baseAxis),
  66261. series: []
  66262. };
  66263. meta.push({
  66264. axisDim: baseAxis.dim,
  66265. axisIndex: baseAxis.index
  66266. });
  66267. }
  66268. seriesGroupByCategoryAxis[key].series.push(seriesModel);
  66269. }
  66270. else {
  66271. otherSeries.push(seriesModel);
  66272. }
  66273. }
  66274. else {
  66275. otherSeries.push(seriesModel);
  66276. }
  66277. });
  66278. return {
  66279. seriesGroupByCategoryAxis: seriesGroupByCategoryAxis,
  66280. other: otherSeries,
  66281. meta: meta
  66282. };
  66283. }
  66284. /**
  66285. * Assemble content of series on cateogory axis
  66286. * @param {Array.<module:echarts/model/Series>} series
  66287. * @return {string}
  66288. * @inner
  66289. */
  66290. function assembleSeriesWithCategoryAxis(series) {
  66291. var tables = [];
  66292. each$1(series, function (group, key) {
  66293. var categoryAxis = group.categoryAxis;
  66294. var valueAxis = group.valueAxis;
  66295. var valueAxisDim = valueAxis.dim;
  66296. var headers = [' '].concat(map(group.series, function (series) {
  66297. return series.name;
  66298. }));
  66299. var columns = [categoryAxis.model.getCategories()];
  66300. each$1(group.series, function (series) {
  66301. columns.push(series.getRawData().mapArray(valueAxisDim, function (val) {
  66302. return val;
  66303. }));
  66304. });
  66305. // Assemble table content
  66306. var lines = [headers.join(ITEM_SPLITER)];
  66307. for (var i = 0; i < columns[0].length; i++) {
  66308. var items = [];
  66309. for (var j = 0; j < columns.length; j++) {
  66310. items.push(columns[j][i]);
  66311. }
  66312. lines.push(items.join(ITEM_SPLITER));
  66313. }
  66314. tables.push(lines.join('\n'));
  66315. });
  66316. return tables.join('\n\n' + BLOCK_SPLITER + '\n\n');
  66317. }
  66318. /**
  66319. * Assemble content of other series
  66320. * @param {Array.<module:echarts/model/Series>} series
  66321. * @return {string}
  66322. * @inner
  66323. */
  66324. function assembleOtherSeries(series) {
  66325. return map(series, function (series) {
  66326. var data = series.getRawData();
  66327. var lines = [series.name];
  66328. var vals = [];
  66329. data.each(data.dimensions, function () {
  66330. var argLen = arguments.length;
  66331. var dataIndex = arguments[argLen - 1];
  66332. var name = data.getName(dataIndex);
  66333. for (var i = 0; i < argLen - 1; i++) {
  66334. vals[i] = arguments[i];
  66335. }
  66336. lines.push((name ? (name + ITEM_SPLITER) : '') + vals.join(ITEM_SPLITER));
  66337. });
  66338. return lines.join('\n');
  66339. }).join('\n\n' + BLOCK_SPLITER + '\n\n');
  66340. }
  66341. /**
  66342. * @param {module:echarts/model/Global}
  66343. * @return {Object}
  66344. * @inner
  66345. */
  66346. function getContentFromModel(ecModel) {
  66347. var result = groupSeries(ecModel);
  66348. return {
  66349. value: filter([
  66350. assembleSeriesWithCategoryAxis(result.seriesGroupByCategoryAxis),
  66351. assembleOtherSeries(result.other)
  66352. ], function (str) {
  66353. return str.replace(/[\n\t\s]/g, '');
  66354. }).join('\n\n' + BLOCK_SPLITER + '\n\n'),
  66355. meta: result.meta
  66356. };
  66357. }
  66358. function trim$1(str) {
  66359. return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
  66360. }
  66361. /**
  66362. * If a block is tsv format
  66363. */
  66364. function isTSVFormat(block) {
  66365. // Simple method to find out if a block is tsv format
  66366. var firstLine = block.slice(0, block.indexOf('\n'));
  66367. if (firstLine.indexOf(ITEM_SPLITER) >= 0) {
  66368. return true;
  66369. }
  66370. }
  66371. var itemSplitRegex = new RegExp('[' + ITEM_SPLITER + ']+', 'g');
  66372. /**
  66373. * @param {string} tsv
  66374. * @return {Object}
  66375. */
  66376. function parseTSVContents(tsv) {
  66377. var tsvLines = tsv.split(/\n+/g);
  66378. var headers = trim$1(tsvLines.shift()).split(itemSplitRegex);
  66379. var categories = [];
  66380. var series = map(headers, function (header) {
  66381. return {
  66382. name: header,
  66383. data: []
  66384. };
  66385. });
  66386. for (var i = 0; i < tsvLines.length; i++) {
  66387. var items = trim$1(tsvLines[i]).split(itemSplitRegex);
  66388. categories.push(items.shift());
  66389. for (var j = 0; j < items.length; j++) {
  66390. series[j] && (series[j].data[i] = items[j]);
  66391. }
  66392. }
  66393. return {
  66394. series: series,
  66395. categories: categories
  66396. };
  66397. }
  66398. /**
  66399. * @param {string} str
  66400. * @return {Array.<Object>}
  66401. * @inner
  66402. */
  66403. function parseListContents(str) {
  66404. var lines = str.split(/\n+/g);
  66405. var seriesName = trim$1(lines.shift());
  66406. var data = [];
  66407. for (var i = 0; i < lines.length; i++) {
  66408. var items = trim$1(lines[i]).split(itemSplitRegex);
  66409. var name = '';
  66410. var value;
  66411. var hasName = false;
  66412. if (isNaN(items[0])) { // First item is name
  66413. hasName = true;
  66414. name = items[0];
  66415. items = items.slice(1);
  66416. data[i] = {
  66417. name: name,
  66418. value: []
  66419. };
  66420. value = data[i].value;
  66421. }
  66422. else {
  66423. value = data[i] = [];
  66424. }
  66425. for (var j = 0; j < items.length; j++) {
  66426. value.push(+items[j]);
  66427. }
  66428. if (value.length === 1) {
  66429. hasName ? (data[i].value = value[0]) : (data[i] = value[0]);
  66430. }
  66431. }
  66432. return {
  66433. name: seriesName,
  66434. data: data
  66435. };
  66436. }
  66437. /**
  66438. * @param {string} str
  66439. * @param {Array.<Object>} blockMetaList
  66440. * @return {Object}
  66441. * @inner
  66442. */
  66443. function parseContents(str, blockMetaList) {
  66444. var blocks = str.split(new RegExp('\n*' + BLOCK_SPLITER + '\n*', 'g'));
  66445. var newOption = {
  66446. series: []
  66447. };
  66448. each$1(blocks, function (block, idx) {
  66449. if (isTSVFormat(block)) {
  66450. var result = parseTSVContents(block);
  66451. var blockMeta = blockMetaList[idx];
  66452. var axisKey = blockMeta.axisDim + 'Axis';
  66453. if (blockMeta) {
  66454. newOption[axisKey] = newOption[axisKey] || [];
  66455. newOption[axisKey][blockMeta.axisIndex] = {
  66456. data: result.categories
  66457. };
  66458. newOption.series = newOption.series.concat(result.series);
  66459. }
  66460. }
  66461. else {
  66462. var result = parseListContents(block);
  66463. newOption.series.push(result);
  66464. }
  66465. });
  66466. return newOption;
  66467. }
  66468. /**
  66469. * @alias {module:echarts/component/toolbox/feature/DataView}
  66470. * @constructor
  66471. * @param {module:echarts/model/Model} model
  66472. */
  66473. function DataView(model) {
  66474. this._dom = null;
  66475. this.model = model;
  66476. }
  66477. DataView.defaultOption = {
  66478. show: true,
  66479. readOnly: false,
  66480. optionToContent: null,
  66481. contentToOption: null,
  66482. 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',
  66483. title: clone(dataViewLang.title),
  66484. lang: clone(dataViewLang.lang),
  66485. backgroundColor: '#fff',
  66486. textColor: '#000',
  66487. textareaColor: '#fff',
  66488. textareaBorderColor: '#333',
  66489. buttonColor: '#c23531',
  66490. buttonTextColor: '#fff'
  66491. };
  66492. DataView.prototype.onclick = function (ecModel, api) {
  66493. var container = api.getDom();
  66494. var model = this.model;
  66495. if (this._dom) {
  66496. container.removeChild(this._dom);
  66497. }
  66498. var root = document.createElement('div');
  66499. root.style.cssText = 'position:absolute;left:5px;top:5px;bottom:5px;right:5px;';
  66500. root.style.backgroundColor = model.get('backgroundColor') || '#fff';
  66501. // Create elements
  66502. var header = document.createElement('h4');
  66503. var lang$$1 = model.get('lang') || [];
  66504. header.innerHTML = lang$$1[0] || model.get('title');
  66505. header.style.cssText = 'margin: 10px 20px;';
  66506. header.style.color = model.get('textColor');
  66507. var viewMain = document.createElement('div');
  66508. var textarea = document.createElement('textarea');
  66509. viewMain.style.cssText = 'display:block;width:100%;overflow:auto;';
  66510. var optionToContent = model.get('optionToContent');
  66511. var contentToOption = model.get('contentToOption');
  66512. var result = getContentFromModel(ecModel);
  66513. if (typeof optionToContent === 'function') {
  66514. var htmlOrDom = optionToContent(api.getOption());
  66515. if (typeof htmlOrDom === 'string') {
  66516. viewMain.innerHTML = htmlOrDom;
  66517. }
  66518. else if (isDom(htmlOrDom)) {
  66519. viewMain.appendChild(htmlOrDom);
  66520. }
  66521. }
  66522. else {
  66523. // Use default textarea
  66524. viewMain.appendChild(textarea);
  66525. textarea.readOnly = model.get('readOnly');
  66526. textarea.style.cssText = 'width:100%;height:100%;font-family:monospace;font-size:14px;line-height:1.6rem;';
  66527. textarea.style.color = model.get('textColor');
  66528. textarea.style.borderColor = model.get('textareaBorderColor');
  66529. textarea.style.backgroundColor = model.get('textareaColor');
  66530. textarea.value = result.value;
  66531. }
  66532. var blockMetaList = result.meta;
  66533. var buttonContainer = document.createElement('div');
  66534. buttonContainer.style.cssText = 'position:absolute;bottom:0;left:0;right:0;';
  66535. var buttonStyle = 'float:right;margin-right:20px;border:none;'
  66536. + 'cursor:pointer;padding:2px 5px;font-size:12px;border-radius:3px';
  66537. var closeButton = document.createElement('div');
  66538. var refreshButton = document.createElement('div');
  66539. buttonStyle += ';background-color:' + model.get('buttonColor');
  66540. buttonStyle += ';color:' + model.get('buttonTextColor');
  66541. var self = this;
  66542. function close() {
  66543. container.removeChild(root);
  66544. self._dom = null;
  66545. }
  66546. addEventListener(closeButton, 'click', close);
  66547. addEventListener(refreshButton, 'click', function () {
  66548. var newOption;
  66549. try {
  66550. if (typeof contentToOption === 'function') {
  66551. newOption = contentToOption(viewMain, api.getOption());
  66552. }
  66553. else {
  66554. newOption = parseContents(textarea.value, blockMetaList);
  66555. }
  66556. }
  66557. catch (e) {
  66558. close();
  66559. throw new Error('Data view format error ' + e);
  66560. }
  66561. if (newOption) {
  66562. api.dispatchAction({
  66563. type: 'changeDataView',
  66564. newOption: newOption
  66565. });
  66566. }
  66567. close();
  66568. });
  66569. closeButton.innerHTML = lang$$1[1];
  66570. refreshButton.innerHTML = lang$$1[2];
  66571. refreshButton.style.cssText = buttonStyle;
  66572. closeButton.style.cssText = buttonStyle;
  66573. !model.get('readOnly') && buttonContainer.appendChild(refreshButton);
  66574. buttonContainer.appendChild(closeButton);
  66575. root.appendChild(header);
  66576. root.appendChild(viewMain);
  66577. root.appendChild(buttonContainer);
  66578. viewMain.style.height = (container.clientHeight - 80) + 'px';
  66579. container.appendChild(root);
  66580. this._dom = root;
  66581. };
  66582. DataView.prototype.remove = function (ecModel, api) {
  66583. this._dom && api.getDom().removeChild(this._dom);
  66584. };
  66585. DataView.prototype.dispose = function (ecModel, api) {
  66586. this.remove(ecModel, api);
  66587. };
  66588. /**
  66589. * @inner
  66590. */
  66591. function tryMergeDataOption(newData, originalData) {
  66592. return map(newData, function (newVal, idx) {
  66593. var original = originalData && originalData[idx];
  66594. if (isObject$1(original) && !isArray(original)) {
  66595. if (isObject$1(newVal) && !isArray(newVal)) {
  66596. newVal = newVal.value;
  66597. }
  66598. // Original data has option
  66599. return defaults({
  66600. value: newVal
  66601. }, original);
  66602. }
  66603. else {
  66604. return newVal;
  66605. }
  66606. });
  66607. }
  66608. register$1('dataView', DataView);
  66609. registerAction({
  66610. type: 'changeDataView',
  66611. event: 'dataViewChanged',
  66612. update: 'prepareAndUpdate'
  66613. }, function (payload, ecModel) {
  66614. var newSeriesOptList = [];
  66615. each$1(payload.newOption.series, function (seriesOpt) {
  66616. var seriesModel = ecModel.getSeriesByName(seriesOpt.name)[0];
  66617. if (!seriesModel) {
  66618. // New created series
  66619. // Geuss the series type
  66620. newSeriesOptList.push(extend({
  66621. // Default is scatter
  66622. type: 'scatter'
  66623. }, seriesOpt));
  66624. }
  66625. else {
  66626. var originalData = seriesModel.get('data');
  66627. newSeriesOptList.push({
  66628. name: seriesOpt.name,
  66629. data: tryMergeDataOption(seriesOpt.data, originalData)
  66630. });
  66631. }
  66632. });
  66633. ecModel.mergeOption(defaults({
  66634. series: newSeriesOptList
  66635. }, payload.newOption));
  66636. });
  66637. /*
  66638. * Licensed to the Apache Software Foundation (ASF) under one
  66639. * or more contributor license agreements. See the NOTICE file
  66640. * distributed with this work for additional information
  66641. * regarding copyright ownership. The ASF licenses this file
  66642. * to you under the Apache License, Version 2.0 (the
  66643. * "License"); you may not use this file except in compliance
  66644. * with the License. You may obtain a copy of the License at
  66645. *
  66646. * http://www.apache.org/licenses/LICENSE-2.0
  66647. *
  66648. * Unless required by applicable law or agreed to in writing,
  66649. * software distributed under the License is distributed on an
  66650. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  66651. * KIND, either express or implied. See the License for the
  66652. * specific language governing permissions and limitations
  66653. * under the License.
  66654. */
  66655. var each$17 = each$1;
  66656. var indexOf$1 = indexOf;
  66657. var curry$4 = curry;
  66658. var COORD_CONVERTS = ['dataToPoint', 'pointToData'];
  66659. // FIXME
  66660. // how to genarialize to more coordinate systems.
  66661. var INCLUDE_FINDER_MAIN_TYPES = [
  66662. 'grid', 'xAxis', 'yAxis', 'geo', 'graph',
  66663. 'polar', 'radiusAxis', 'angleAxis', 'bmap'
  66664. ];
  66665. /**
  66666. * [option in constructor]:
  66667. * {
  66668. * Index/Id/Name of geo, xAxis, yAxis, grid: See util/model#parseFinder.
  66669. * }
  66670. *
  66671. *
  66672. * [targetInfo]:
  66673. *
  66674. * There can be multiple axes in a single targetInfo. Consider the case
  66675. * of `grid` component, a targetInfo represents a grid which contains one or more
  66676. * cartesian and one or more axes. And consider the case of parallel system,
  66677. * which has multiple axes in a coordinate system.
  66678. * Can be {
  66679. * panelId: ...,
  66680. * coordSys: <a representitive cartesian in grid (first cartesian by default)>,
  66681. * coordSyses: all cartesians.
  66682. * gridModel: <grid component>
  66683. * xAxes: correspond to coordSyses on index
  66684. * yAxes: correspond to coordSyses on index
  66685. * }
  66686. * or {
  66687. * panelId: ...,
  66688. * coordSys: <geo coord sys>
  66689. * coordSyses: [<geo coord sys>]
  66690. * geoModel: <geo component>
  66691. * }
  66692. *
  66693. *
  66694. * [panelOpt]:
  66695. *
  66696. * Make from targetInfo. Input to BrushController.
  66697. * {
  66698. * panelId: ...,
  66699. * rect: ...
  66700. * }
  66701. *
  66702. *
  66703. * [area]:
  66704. *
  66705. * Generated by BrushController or user input.
  66706. * {
  66707. * panelId: Used to locate coordInfo directly. If user inpput, no panelId.
  66708. * brushType: determine how to convert to/from coord('rect' or 'polygon' or 'lineX/Y').
  66709. * Index/Id/Name of geo, xAxis, yAxis, grid: See util/model#parseFinder.
  66710. * range: pixel range.
  66711. * coordRange: representitive coord range (the first one of coordRanges).
  66712. * coordRanges: <Array> coord ranges, used in multiple cartesian in one grid.
  66713. * }
  66714. */
  66715. /**
  66716. * @param {Object} option contains Index/Id/Name of xAxis/yAxis/geo/grid
  66717. * Each can be {number|Array.<number>}. like: {xAxisIndex: [3, 4]}
  66718. * @param {module:echarts/model/Global} ecModel
  66719. * @param {Object} [opt]
  66720. * @param {Array.<string>} [opt.include] include coordinate system types.
  66721. */
  66722. function BrushTargetManager(option, ecModel, opt) {
  66723. /**
  66724. * @private
  66725. * @type {Array.<Object>}
  66726. */
  66727. var targetInfoList = this._targetInfoList = [];
  66728. var info = {};
  66729. var foundCpts = parseFinder$1(ecModel, option);
  66730. each$17(targetInfoBuilders, function (builder, type) {
  66731. if (!opt || !opt.include || indexOf$1(opt.include, type) >= 0) {
  66732. builder(foundCpts, targetInfoList, info);
  66733. }
  66734. });
  66735. }
  66736. var proto$5 = BrushTargetManager.prototype;
  66737. proto$5.setOutputRanges = function (areas, ecModel) {
  66738. this.matchOutputRanges(areas, ecModel, function (area, coordRange, coordSys) {
  66739. (area.coordRanges || (area.coordRanges = [])).push(coordRange);
  66740. // area.coordRange is the first of area.coordRanges
  66741. if (!area.coordRange) {
  66742. area.coordRange = coordRange;
  66743. // In 'category' axis, coord to pixel is not reversible, so we can not
  66744. // rebuild range by coordRange accrately, which may bring trouble when
  66745. // brushing only one item. So we use __rangeOffset to rebuilding range
  66746. // by coordRange. And this it only used in brush component so it is no
  66747. // need to be adapted to coordRanges.
  66748. var result = coordConvert[area.brushType](0, coordSys, coordRange);
  66749. area.__rangeOffset = {
  66750. offset: diffProcessor[area.brushType](result.values, area.range, [1, 1]),
  66751. xyMinMax: result.xyMinMax
  66752. };
  66753. }
  66754. });
  66755. };
  66756. proto$5.matchOutputRanges = function (areas, ecModel, cb) {
  66757. each$17(areas, function (area) {
  66758. var targetInfo = this.findTargetInfo(area, ecModel);
  66759. if (targetInfo && targetInfo !== true) {
  66760. each$1(
  66761. targetInfo.coordSyses,
  66762. function (coordSys) {
  66763. var result = coordConvert[area.brushType](1, coordSys, area.range);
  66764. cb(area, result.values, coordSys, ecModel);
  66765. }
  66766. );
  66767. }
  66768. }, this);
  66769. };
  66770. proto$5.setInputRanges = function (areas, ecModel) {
  66771. each$17(areas, function (area) {
  66772. var targetInfo = this.findTargetInfo(area, ecModel);
  66773. if (__DEV__) {
  66774. assert$1(
  66775. !targetInfo || targetInfo === true || area.coordRange,
  66776. 'coordRange must be specified when coord index specified.'
  66777. );
  66778. assert$1(
  66779. !targetInfo || targetInfo !== true || area.range,
  66780. 'range must be specified in global brush.'
  66781. );
  66782. }
  66783. area.range = area.range || [];
  66784. // convert coordRange to global range and set panelId.
  66785. if (targetInfo && targetInfo !== true) {
  66786. area.panelId = targetInfo.panelId;
  66787. // (1) area.range shoule always be calculate from coordRange but does
  66788. // not keep its original value, for the sake of the dataZoom scenario,
  66789. // where area.coordRange remains unchanged but area.range may be changed.
  66790. // (2) Only support converting one coordRange to pixel range in brush
  66791. // component. So do not consider `coordRanges`.
  66792. // (3) About __rangeOffset, see comment above.
  66793. var result = coordConvert[area.brushType](0, targetInfo.coordSys, area.coordRange);
  66794. var rangeOffset = area.__rangeOffset;
  66795. area.range = rangeOffset
  66796. ? diffProcessor[area.brushType](
  66797. result.values,
  66798. rangeOffset.offset,
  66799. getScales(result.xyMinMax, rangeOffset.xyMinMax)
  66800. )
  66801. : result.values;
  66802. }
  66803. }, this);
  66804. };
  66805. proto$5.makePanelOpts = function (api, getDefaultBrushType) {
  66806. return map(this._targetInfoList, function (targetInfo) {
  66807. var rect = targetInfo.getPanelRect();
  66808. return {
  66809. panelId: targetInfo.panelId,
  66810. defaultBrushType: getDefaultBrushType && getDefaultBrushType(targetInfo),
  66811. clipPath: makeRectPanelClipPath(rect),
  66812. isTargetByCursor: makeRectIsTargetByCursor(
  66813. rect, api, targetInfo.coordSysModel
  66814. ),
  66815. getLinearBrushOtherExtent: makeLinearBrushOtherExtent(rect)
  66816. };
  66817. });
  66818. };
  66819. proto$5.controlSeries = function (area, seriesModel, ecModel) {
  66820. // Check whether area is bound in coord, and series do not belong to that coord.
  66821. // If do not do this check, some brush (like lineX) will controll all axes.
  66822. var targetInfo = this.findTargetInfo(area, ecModel);
  66823. return targetInfo === true || (
  66824. targetInfo && indexOf$1(targetInfo.coordSyses, seriesModel.coordinateSystem) >= 0
  66825. );
  66826. };
  66827. /**
  66828. * If return Object, a coord found.
  66829. * If reutrn true, global found.
  66830. * Otherwise nothing found.
  66831. *
  66832. * @param {Object} area
  66833. * @param {Array} targetInfoList
  66834. * @return {Object|boolean}
  66835. */
  66836. proto$5.findTargetInfo = function (area, ecModel) {
  66837. var targetInfoList = this._targetInfoList;
  66838. var foundCpts = parseFinder$1(ecModel, area);
  66839. for (var i = 0; i < targetInfoList.length; i++) {
  66840. var targetInfo = targetInfoList[i];
  66841. var areaPanelId = area.panelId;
  66842. if (areaPanelId) {
  66843. if (targetInfo.panelId === areaPanelId) {
  66844. return targetInfo;
  66845. }
  66846. }
  66847. else {
  66848. for (var i = 0; i < targetInfoMatchers.length; i++) {
  66849. if (targetInfoMatchers[i](foundCpts, targetInfo)) {
  66850. return targetInfo;
  66851. }
  66852. }
  66853. }
  66854. }
  66855. return true;
  66856. };
  66857. function formatMinMax(minMax) {
  66858. minMax[0] > minMax[1] && minMax.reverse();
  66859. return minMax;
  66860. }
  66861. function parseFinder$1(ecModel, option) {
  66862. return parseFinder(
  66863. ecModel, option, {includeMainTypes: INCLUDE_FINDER_MAIN_TYPES}
  66864. );
  66865. }
  66866. var targetInfoBuilders = {
  66867. grid: function (foundCpts, targetInfoList) {
  66868. var xAxisModels = foundCpts.xAxisModels;
  66869. var yAxisModels = foundCpts.yAxisModels;
  66870. var gridModels = foundCpts.gridModels;
  66871. // Remove duplicated.
  66872. var gridModelMap = createHashMap();
  66873. var xAxesHas = {};
  66874. var yAxesHas = {};
  66875. if (!xAxisModels && !yAxisModels && !gridModels) {
  66876. return;
  66877. }
  66878. each$17(xAxisModels, function (axisModel) {
  66879. var gridModel = axisModel.axis.grid.model;
  66880. gridModelMap.set(gridModel.id, gridModel);
  66881. xAxesHas[gridModel.id] = true;
  66882. });
  66883. each$17(yAxisModels, function (axisModel) {
  66884. var gridModel = axisModel.axis.grid.model;
  66885. gridModelMap.set(gridModel.id, gridModel);
  66886. yAxesHas[gridModel.id] = true;
  66887. });
  66888. each$17(gridModels, function (gridModel) {
  66889. gridModelMap.set(gridModel.id, gridModel);
  66890. xAxesHas[gridModel.id] = true;
  66891. yAxesHas[gridModel.id] = true;
  66892. });
  66893. gridModelMap.each(function (gridModel) {
  66894. var grid = gridModel.coordinateSystem;
  66895. var cartesians = [];
  66896. each$17(grid.getCartesians(), function (cartesian, index) {
  66897. if (indexOf$1(xAxisModels, cartesian.getAxis('x').model) >= 0
  66898. || indexOf$1(yAxisModels, cartesian.getAxis('y').model) >= 0
  66899. ) {
  66900. cartesians.push(cartesian);
  66901. }
  66902. });
  66903. targetInfoList.push({
  66904. panelId: 'grid--' + gridModel.id,
  66905. gridModel: gridModel,
  66906. coordSysModel: gridModel,
  66907. // Use the first one as the representitive coordSys.
  66908. coordSys: cartesians[0],
  66909. coordSyses: cartesians,
  66910. getPanelRect: panelRectBuilder.grid,
  66911. xAxisDeclared: xAxesHas[gridModel.id],
  66912. yAxisDeclared: yAxesHas[gridModel.id]
  66913. });
  66914. });
  66915. },
  66916. geo: function (foundCpts, targetInfoList) {
  66917. each$17(foundCpts.geoModels, function (geoModel) {
  66918. var coordSys = geoModel.coordinateSystem;
  66919. targetInfoList.push({
  66920. panelId: 'geo--' + geoModel.id,
  66921. geoModel: geoModel,
  66922. coordSysModel: geoModel,
  66923. coordSys: coordSys,
  66924. coordSyses: [coordSys],
  66925. getPanelRect: panelRectBuilder.geo
  66926. });
  66927. });
  66928. }
  66929. };
  66930. var targetInfoMatchers = [
  66931. // grid
  66932. function (foundCpts, targetInfo) {
  66933. var xAxisModel = foundCpts.xAxisModel;
  66934. var yAxisModel = foundCpts.yAxisModel;
  66935. var gridModel = foundCpts.gridModel;
  66936. !gridModel && xAxisModel && (gridModel = xAxisModel.axis.grid.model);
  66937. !gridModel && yAxisModel && (gridModel = yAxisModel.axis.grid.model);
  66938. return gridModel && gridModel === targetInfo.gridModel;
  66939. },
  66940. // geo
  66941. function (foundCpts, targetInfo) {
  66942. var geoModel = foundCpts.geoModel;
  66943. return geoModel && geoModel === targetInfo.geoModel;
  66944. }
  66945. ];
  66946. var panelRectBuilder = {
  66947. grid: function () {
  66948. // grid is not Transformable.
  66949. return this.coordSys.grid.getRect().clone();
  66950. },
  66951. geo: function () {
  66952. var coordSys = this.coordSys;
  66953. var rect = coordSys.getBoundingRect().clone();
  66954. // geo roam and zoom transform
  66955. rect.applyTransform(getTransform(coordSys));
  66956. return rect;
  66957. }
  66958. };
  66959. var coordConvert = {
  66960. lineX: curry$4(axisConvert, 0),
  66961. lineY: curry$4(axisConvert, 1),
  66962. rect: function (to, coordSys, rangeOrCoordRange) {
  66963. var xminymin = coordSys[COORD_CONVERTS[to]]([rangeOrCoordRange[0][0], rangeOrCoordRange[1][0]]);
  66964. var xmaxymax = coordSys[COORD_CONVERTS[to]]([rangeOrCoordRange[0][1], rangeOrCoordRange[1][1]]);
  66965. var values = [
  66966. formatMinMax([xminymin[0], xmaxymax[0]]),
  66967. formatMinMax([xminymin[1], xmaxymax[1]])
  66968. ];
  66969. return {values: values, xyMinMax: values};
  66970. },
  66971. polygon: function (to, coordSys, rangeOrCoordRange) {
  66972. var xyMinMax = [[Infinity, -Infinity], [Infinity, -Infinity]];
  66973. var values = map(rangeOrCoordRange, function (item) {
  66974. var p = coordSys[COORD_CONVERTS[to]](item);
  66975. xyMinMax[0][0] = Math.min(xyMinMax[0][0], p[0]);
  66976. xyMinMax[1][0] = Math.min(xyMinMax[1][0], p[1]);
  66977. xyMinMax[0][1] = Math.max(xyMinMax[0][1], p[0]);
  66978. xyMinMax[1][1] = Math.max(xyMinMax[1][1], p[1]);
  66979. return p;
  66980. });
  66981. return {values: values, xyMinMax: xyMinMax};
  66982. }
  66983. };
  66984. function axisConvert(axisNameIndex, to, coordSys, rangeOrCoordRange) {
  66985. if (__DEV__) {
  66986. assert$1(
  66987. coordSys.type === 'cartesian2d',
  66988. 'lineX/lineY brush is available only in cartesian2d.'
  66989. );
  66990. }
  66991. var axis = coordSys.getAxis(['x', 'y'][axisNameIndex]);
  66992. var values = formatMinMax(map([0, 1], function (i) {
  66993. return to
  66994. ? axis.coordToData(axis.toLocalCoord(rangeOrCoordRange[i]))
  66995. : axis.toGlobalCoord(axis.dataToCoord(rangeOrCoordRange[i]));
  66996. }));
  66997. var xyMinMax = [];
  66998. xyMinMax[axisNameIndex] = values;
  66999. xyMinMax[1 - axisNameIndex] = [NaN, NaN];
  67000. return {values: values, xyMinMax: xyMinMax};
  67001. }
  67002. var diffProcessor = {
  67003. lineX: curry$4(axisDiffProcessor, 0),
  67004. lineY: curry$4(axisDiffProcessor, 1),
  67005. rect: function (values, refer, scales) {
  67006. return [
  67007. [values[0][0] - scales[0] * refer[0][0], values[0][1] - scales[0] * refer[0][1]],
  67008. [values[1][0] - scales[1] * refer[1][0], values[1][1] - scales[1] * refer[1][1]]
  67009. ];
  67010. },
  67011. polygon: function (values, refer, scales) {
  67012. return map(values, function (item, idx) {
  67013. return [item[0] - scales[0] * refer[idx][0], item[1] - scales[1] * refer[idx][1]];
  67014. });
  67015. }
  67016. };
  67017. function axisDiffProcessor(axisNameIndex, values, refer, scales) {
  67018. return [
  67019. values[0] - scales[axisNameIndex] * refer[0],
  67020. values[1] - scales[axisNameIndex] * refer[1]
  67021. ];
  67022. }
  67023. // We have to process scale caused by dataZoom manually,
  67024. // although it might be not accurate.
  67025. function getScales(xyMinMaxCurr, xyMinMaxOrigin) {
  67026. var sizeCurr = getSize(xyMinMaxCurr);
  67027. var sizeOrigin = getSize(xyMinMaxOrigin);
  67028. var scales = [sizeCurr[0] / sizeOrigin[0], sizeCurr[1] / sizeOrigin[1]];
  67029. isNaN(scales[0]) && (scales[0] = 1);
  67030. isNaN(scales[1]) && (scales[1] = 1);
  67031. return scales;
  67032. }
  67033. function getSize(xyMinMax) {
  67034. return xyMinMax
  67035. ? [xyMinMax[0][1] - xyMinMax[0][0], xyMinMax[1][1] - xyMinMax[1][0]]
  67036. : [NaN, NaN];
  67037. }
  67038. /*
  67039. * Licensed to the Apache Software Foundation (ASF) under one
  67040. * or more contributor license agreements. See the NOTICE file
  67041. * distributed with this work for additional information
  67042. * regarding copyright ownership. The ASF licenses this file
  67043. * to you under the Apache License, Version 2.0 (the
  67044. * "License"); you may not use this file except in compliance
  67045. * with the License. You may obtain a copy of the License at
  67046. *
  67047. * http://www.apache.org/licenses/LICENSE-2.0
  67048. *
  67049. * Unless required by applicable law or agreed to in writing,
  67050. * software distributed under the License is distributed on an
  67051. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  67052. * KIND, either express or implied. See the License for the
  67053. * specific language governing permissions and limitations
  67054. * under the License.
  67055. */
  67056. var each$18 = each$1;
  67057. var ATTR$1 = '\0_ec_hist_store';
  67058. /**
  67059. * @param {module:echarts/model/Global} ecModel
  67060. * @param {Object} newSnapshot {dataZoomId, batch: [payloadInfo, ...]}
  67061. */
  67062. function push(ecModel, newSnapshot) {
  67063. var store = giveStore(ecModel);
  67064. // If previous dataZoom can not be found,
  67065. // complete an range with current range.
  67066. each$18(newSnapshot, function (batchItem, dataZoomId) {
  67067. var i = store.length - 1;
  67068. for (; i >= 0; i--) {
  67069. var snapshot = store[i];
  67070. if (snapshot[dataZoomId]) {
  67071. break;
  67072. }
  67073. }
  67074. if (i < 0) {
  67075. // No origin range set, create one by current range.
  67076. var dataZoomModel = ecModel.queryComponents(
  67077. {mainType: 'dataZoom', subType: 'select', id: dataZoomId}
  67078. )[0];
  67079. if (dataZoomModel) {
  67080. var percentRange = dataZoomModel.getPercentRange();
  67081. store[0][dataZoomId] = {
  67082. dataZoomId: dataZoomId,
  67083. start: percentRange[0],
  67084. end: percentRange[1]
  67085. };
  67086. }
  67087. }
  67088. });
  67089. store.push(newSnapshot);
  67090. }
  67091. /**
  67092. * @param {module:echarts/model/Global} ecModel
  67093. * @return {Object} snapshot
  67094. */
  67095. function pop(ecModel) {
  67096. var store = giveStore(ecModel);
  67097. var head = store[store.length - 1];
  67098. store.length > 1 && store.pop();
  67099. // Find top for all dataZoom.
  67100. var snapshot = {};
  67101. each$18(head, function (batchItem, dataZoomId) {
  67102. for (var i = store.length - 1; i >= 0; i--) {
  67103. var batchItem = store[i][dataZoomId];
  67104. if (batchItem) {
  67105. snapshot[dataZoomId] = batchItem;
  67106. break;
  67107. }
  67108. }
  67109. });
  67110. return snapshot;
  67111. }
  67112. /**
  67113. * @param {module:echarts/model/Global} ecModel
  67114. */
  67115. function clear$1(ecModel) {
  67116. ecModel[ATTR$1] = null;
  67117. }
  67118. /**
  67119. * @param {module:echarts/model/Global} ecModel
  67120. * @return {number} records. always >= 1.
  67121. */
  67122. function count(ecModel) {
  67123. return giveStore(ecModel).length;
  67124. }
  67125. /**
  67126. * [{key: dataZoomId, value: {dataZoomId, range}}, ...]
  67127. * History length of each dataZoom may be different.
  67128. * this._history[0] is used to store origin range.
  67129. * @type {Array.<Object>}
  67130. */
  67131. function giveStore(ecModel) {
  67132. var store = ecModel[ATTR$1];
  67133. if (!store) {
  67134. store = ecModel[ATTR$1] = [{}];
  67135. }
  67136. return store;
  67137. }
  67138. /*
  67139. * Licensed to the Apache Software Foundation (ASF) under one
  67140. * or more contributor license agreements. See the NOTICE file
  67141. * distributed with this work for additional information
  67142. * regarding copyright ownership. The ASF licenses this file
  67143. * to you under the Apache License, Version 2.0 (the
  67144. * "License"); you may not use this file except in compliance
  67145. * with the License. You may obtain a copy of the License at
  67146. *
  67147. * http://www.apache.org/licenses/LICENSE-2.0
  67148. *
  67149. * Unless required by applicable law or agreed to in writing,
  67150. * software distributed under the License is distributed on an
  67151. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  67152. * KIND, either express or implied. See the License for the
  67153. * specific language governing permissions and limitations
  67154. * under the License.
  67155. */
  67156. ComponentModel.registerSubTypeDefaulter('dataZoom', function () {
  67157. // Default 'slider' when no type specified.
  67158. return 'slider';
  67159. });
  67160. /*
  67161. * Licensed to the Apache Software Foundation (ASF) under one
  67162. * or more contributor license agreements. See the NOTICE file
  67163. * distributed with this work for additional information
  67164. * regarding copyright ownership. The ASF licenses this file
  67165. * to you under the Apache License, Version 2.0 (the
  67166. * "License"); you may not use this file except in compliance
  67167. * with the License. You may obtain a copy of the License at
  67168. *
  67169. * http://www.apache.org/licenses/LICENSE-2.0
  67170. *
  67171. * Unless required by applicable law or agreed to in writing,
  67172. * software distributed under the License is distributed on an
  67173. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  67174. * KIND, either express or implied. See the License for the
  67175. * specific language governing permissions and limitations
  67176. * under the License.
  67177. */
  67178. var AXIS_DIMS = ['x', 'y', 'z', 'radius', 'angle', 'single'];
  67179. // Supported coords.
  67180. var COORDS = ['cartesian2d', 'polar', 'singleAxis'];
  67181. /**
  67182. * @param {string} coordType
  67183. * @return {boolean}
  67184. */
  67185. function isCoordSupported(coordType) {
  67186. return indexOf(COORDS, coordType) >= 0;
  67187. }
  67188. /**
  67189. * Create "each" method to iterate names.
  67190. *
  67191. * @pubilc
  67192. * @param {Array.<string>} names
  67193. * @param {Array.<string>=} attrs
  67194. * @return {Function}
  67195. */
  67196. function createNameEach(names, attrs) {
  67197. names = names.slice();
  67198. var capitalNames = map(names, capitalFirst);
  67199. attrs = (attrs || []).slice();
  67200. var capitalAttrs = map(attrs, capitalFirst);
  67201. return function (callback, context) {
  67202. each$1(names, function (name, index) {
  67203. var nameObj = {name: name, capital: capitalNames[index]};
  67204. for (var j = 0; j < attrs.length; j++) {
  67205. nameObj[attrs[j]] = name + capitalAttrs[j];
  67206. }
  67207. callback.call(context, nameObj);
  67208. });
  67209. };
  67210. }
  67211. /**
  67212. * Iterate each dimension name.
  67213. *
  67214. * @public
  67215. * @param {Function} callback The parameter is like:
  67216. * {
  67217. * name: 'angle',
  67218. * capital: 'Angle',
  67219. * axis: 'angleAxis',
  67220. * axisIndex: 'angleAixs',
  67221. * index: 'angleIndex'
  67222. * }
  67223. * @param {Object} context
  67224. */
  67225. var eachAxisDim$1 = createNameEach(AXIS_DIMS, ['axisIndex', 'axis', 'index', 'id']);
  67226. /**
  67227. * If tow dataZoomModels has the same axis controlled, we say that they are 'linked'.
  67228. * dataZoomModels and 'links' make up one or more graphics.
  67229. * This function finds the graphic where the source dataZoomModel is in.
  67230. *
  67231. * @public
  67232. * @param {Function} forEachNode Node iterator.
  67233. * @param {Function} forEachEdgeType edgeType iterator
  67234. * @param {Function} edgeIdGetter Giving node and edgeType, return an array of edge id.
  67235. * @return {Function} Input: sourceNode, Output: Like {nodes: [], dims: {}}
  67236. */
  67237. function createLinkedNodesFinder(forEachNode, forEachEdgeType, edgeIdGetter) {
  67238. return function (sourceNode) {
  67239. var result = {
  67240. nodes: [],
  67241. records: {} // key: edgeType.name, value: Object (key: edge id, value: boolean).
  67242. };
  67243. forEachEdgeType(function (edgeType) {
  67244. result.records[edgeType.name] = {};
  67245. });
  67246. if (!sourceNode) {
  67247. return result;
  67248. }
  67249. absorb(sourceNode, result);
  67250. var existsLink;
  67251. do {
  67252. existsLink = false;
  67253. forEachNode(processSingleNode);
  67254. }
  67255. while (existsLink);
  67256. function processSingleNode(node) {
  67257. if (!isNodeAbsorded(node, result) && isLinked(node, result)) {
  67258. absorb(node, result);
  67259. existsLink = true;
  67260. }
  67261. }
  67262. return result;
  67263. };
  67264. function isNodeAbsorded(node, result) {
  67265. return indexOf(result.nodes, node) >= 0;
  67266. }
  67267. function isLinked(node, result) {
  67268. var hasLink = false;
  67269. forEachEdgeType(function (edgeType) {
  67270. each$1(edgeIdGetter(node, edgeType) || [], function (edgeId) {
  67271. result.records[edgeType.name][edgeId] && (hasLink = true);
  67272. });
  67273. });
  67274. return hasLink;
  67275. }
  67276. function absorb(node, result) {
  67277. result.nodes.push(node);
  67278. forEachEdgeType(function (edgeType) {
  67279. each$1(edgeIdGetter(node, edgeType) || [], function (edgeId) {
  67280. result.records[edgeType.name][edgeId] = true;
  67281. });
  67282. });
  67283. }
  67284. }
  67285. /*
  67286. * Licensed to the Apache Software Foundation (ASF) under one
  67287. * or more contributor license agreements. See the NOTICE file
  67288. * distributed with this work for additional information
  67289. * regarding copyright ownership. The ASF licenses this file
  67290. * to you under the Apache License, Version 2.0 (the
  67291. * "License"); you may not use this file except in compliance
  67292. * with the License. You may obtain a copy of the License at
  67293. *
  67294. * http://www.apache.org/licenses/LICENSE-2.0
  67295. *
  67296. * Unless required by applicable law or agreed to in writing,
  67297. * software distributed under the License is distributed on an
  67298. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  67299. * KIND, either express or implied. See the License for the
  67300. * specific language governing permissions and limitations
  67301. * under the License.
  67302. */
  67303. var each$20 = each$1;
  67304. var asc$1 = asc;
  67305. /**
  67306. * Operate single axis.
  67307. * One axis can only operated by one axis operator.
  67308. * Different dataZoomModels may be defined to operate the same axis.
  67309. * (i.e. 'inside' data zoom and 'slider' data zoom components)
  67310. * So dataZoomModels share one axisProxy in that case.
  67311. *
  67312. * @class
  67313. */
  67314. var AxisProxy = function (dimName, axisIndex, dataZoomModel, ecModel) {
  67315. /**
  67316. * @private
  67317. * @type {string}
  67318. */
  67319. this._dimName = dimName;
  67320. /**
  67321. * @private
  67322. */
  67323. this._axisIndex = axisIndex;
  67324. /**
  67325. * @private
  67326. * @type {Array.<number>}
  67327. */
  67328. this._valueWindow;
  67329. /**
  67330. * @private
  67331. * @type {Array.<number>}
  67332. */
  67333. this._percentWindow;
  67334. /**
  67335. * @private
  67336. * @type {Array.<number>}
  67337. */
  67338. this._dataExtent;
  67339. /**
  67340. * {minSpan, maxSpan, minValueSpan, maxValueSpan}
  67341. * @private
  67342. * @type {Object}
  67343. */
  67344. this._minMaxSpan;
  67345. /**
  67346. * @readOnly
  67347. * @type {module: echarts/model/Global}
  67348. */
  67349. this.ecModel = ecModel;
  67350. /**
  67351. * @private
  67352. * @type {module: echarts/component/dataZoom/DataZoomModel}
  67353. */
  67354. this._dataZoomModel = dataZoomModel;
  67355. // /**
  67356. // * @readOnly
  67357. // * @private
  67358. // */
  67359. // this.hasSeriesStacked;
  67360. };
  67361. AxisProxy.prototype = {
  67362. constructor: AxisProxy,
  67363. /**
  67364. * Whether the axisProxy is hosted by dataZoomModel.
  67365. *
  67366. * @public
  67367. * @param {module: echarts/component/dataZoom/DataZoomModel} dataZoomModel
  67368. * @return {boolean}
  67369. */
  67370. hostedBy: function (dataZoomModel) {
  67371. return this._dataZoomModel === dataZoomModel;
  67372. },
  67373. /**
  67374. * @return {Array.<number>} Value can only be NaN or finite value.
  67375. */
  67376. getDataValueWindow: function () {
  67377. return this._valueWindow.slice();
  67378. },
  67379. /**
  67380. * @return {Array.<number>}
  67381. */
  67382. getDataPercentWindow: function () {
  67383. return this._percentWindow.slice();
  67384. },
  67385. /**
  67386. * @public
  67387. * @param {number} axisIndex
  67388. * @return {Array} seriesModels
  67389. */
  67390. getTargetSeriesModels: function () {
  67391. var seriesModels = [];
  67392. var ecModel = this.ecModel;
  67393. ecModel.eachSeries(function (seriesModel) {
  67394. if (isCoordSupported(seriesModel.get('coordinateSystem'))) {
  67395. var dimName = this._dimName;
  67396. var axisModel = ecModel.queryComponents({
  67397. mainType: dimName + 'Axis',
  67398. index: seriesModel.get(dimName + 'AxisIndex'),
  67399. id: seriesModel.get(dimName + 'AxisId')
  67400. })[0];
  67401. if (this._axisIndex === (axisModel && axisModel.componentIndex)) {
  67402. seriesModels.push(seriesModel);
  67403. }
  67404. }
  67405. }, this);
  67406. return seriesModels;
  67407. },
  67408. getAxisModel: function () {
  67409. return this.ecModel.getComponent(this._dimName + 'Axis', this._axisIndex);
  67410. },
  67411. getOtherAxisModel: function () {
  67412. var axisDim = this._dimName;
  67413. var ecModel = this.ecModel;
  67414. var axisModel = this.getAxisModel();
  67415. var isCartesian = axisDim === 'x' || axisDim === 'y';
  67416. var otherAxisDim;
  67417. var coordSysIndexName;
  67418. if (isCartesian) {
  67419. coordSysIndexName = 'gridIndex';
  67420. otherAxisDim = axisDim === 'x' ? 'y' : 'x';
  67421. }
  67422. else {
  67423. coordSysIndexName = 'polarIndex';
  67424. otherAxisDim = axisDim === 'angle' ? 'radius' : 'angle';
  67425. }
  67426. var foundOtherAxisModel;
  67427. ecModel.eachComponent(otherAxisDim + 'Axis', function (otherAxisModel) {
  67428. if ((otherAxisModel.get(coordSysIndexName) || 0)
  67429. === (axisModel.get(coordSysIndexName) || 0)
  67430. ) {
  67431. foundOtherAxisModel = otherAxisModel;
  67432. }
  67433. });
  67434. return foundOtherAxisModel;
  67435. },
  67436. getMinMaxSpan: function () {
  67437. return clone(this._minMaxSpan);
  67438. },
  67439. /**
  67440. * Only calculate by given range and this._dataExtent, do not change anything.
  67441. *
  67442. * @param {Object} opt
  67443. * @param {number} [opt.start]
  67444. * @param {number} [opt.end]
  67445. * @param {number} [opt.startValue]
  67446. * @param {number} [opt.endValue]
  67447. */
  67448. calculateDataWindow: function (opt) {
  67449. var dataExtent = this._dataExtent;
  67450. var axisModel = this.getAxisModel();
  67451. var scale = axisModel.axis.scale;
  67452. var rangePropMode = this._dataZoomModel.getRangePropMode();
  67453. var percentExtent = [0, 100];
  67454. var percentWindow = [];
  67455. var valueWindow = [];
  67456. var hasPropModeValue;
  67457. each$20(['start', 'end'], function (prop, idx) {
  67458. var boundPercent = opt[prop];
  67459. var boundValue = opt[prop + 'Value'];
  67460. // Notice: dataZoom is based either on `percentProp` ('start', 'end') or
  67461. // on `valueProp` ('startValue', 'endValue'). (They are based on the data extent
  67462. // but not min/max of axis, which will be calculated by data window then).
  67463. // The former one is suitable for cases that a dataZoom component controls multiple
  67464. // axes with different unit or extent, and the latter one is suitable for accurate
  67465. // zoom by pixel (e.g., in dataZoomSelect).
  67466. // we use `getRangePropMode()` to mark which prop is used. `rangePropMode` is updated
  67467. // only when setOption or dispatchAction, otherwise it remains its original value.
  67468. // (Why not only record `percentProp` and always map to `valueProp`? Because
  67469. // the map `valueProp` -> `percentProp` -> `valueProp` probably not the original
  67470. // `valueProp`. consider two axes constrolled by one dataZoom. They have different
  67471. // data extent. All of values that are overflow the `dataExtent` will be calculated
  67472. // to percent '100%').
  67473. if (rangePropMode[idx] === 'percent') {
  67474. boundPercent == null && (boundPercent = percentExtent[idx]);
  67475. // Use scale.parse to math round for category or time axis.
  67476. boundValue = scale.parse(linearMap(
  67477. boundPercent, percentExtent, dataExtent
  67478. ));
  67479. }
  67480. else {
  67481. hasPropModeValue = true;
  67482. boundValue = boundValue == null ? dataExtent[idx] : scale.parse(boundValue);
  67483. // Calculating `percent` from `value` may be not accurate, because
  67484. // This calculation can not be inversed, because all of values that
  67485. // are overflow the `dataExtent` will be calculated to percent '100%'
  67486. boundPercent = linearMap(
  67487. boundValue, dataExtent, percentExtent
  67488. );
  67489. }
  67490. // valueWindow[idx] = round(boundValue);
  67491. // percentWindow[idx] = round(boundPercent);
  67492. valueWindow[idx] = boundValue;
  67493. percentWindow[idx] = boundPercent;
  67494. });
  67495. asc$1(valueWindow);
  67496. asc$1(percentWindow);
  67497. // The windows from user calling of `dispatchAction` might be out of the extent,
  67498. // or do not obey the `min/maxSpan`, `min/maxValueSpan`. But we dont restrict window
  67499. // by `zoomLock` here, because we see `zoomLock` just as a interaction constraint,
  67500. // where API is able to initialize/modify the window size even though `zoomLock`
  67501. // specified.
  67502. var spans = this._minMaxSpan;
  67503. hasPropModeValue
  67504. ? restrictSet(valueWindow, percentWindow, dataExtent, percentExtent, false)
  67505. : restrictSet(percentWindow, valueWindow, percentExtent, dataExtent, true);
  67506. function restrictSet(fromWindow, toWindow, fromExtent, toExtent, toValue) {
  67507. var suffix = toValue ? 'Span' : 'ValueSpan';
  67508. sliderMove(0, fromWindow, fromExtent, 'all', spans['min' + suffix], spans['max' + suffix]);
  67509. for (var i = 0; i < 2; i++) {
  67510. toWindow[i] = linearMap(fromWindow[i], fromExtent, toExtent, true);
  67511. toValue && (toWindow[i] = scale.parse(toWindow[i]));
  67512. }
  67513. }
  67514. return {
  67515. valueWindow: valueWindow,
  67516. percentWindow: percentWindow
  67517. };
  67518. },
  67519. /**
  67520. * Notice: reset should not be called before series.restoreData() called,
  67521. * so it is recommanded to be called in "process stage" but not "model init
  67522. * stage".
  67523. *
  67524. * @param {module: echarts/component/dataZoom/DataZoomModel} dataZoomModel
  67525. */
  67526. reset: function (dataZoomModel) {
  67527. if (dataZoomModel !== this._dataZoomModel) {
  67528. return;
  67529. }
  67530. var targetSeries = this.getTargetSeriesModels();
  67531. // Culculate data window and data extent, and record them.
  67532. this._dataExtent = calculateDataExtent(this, this._dimName, targetSeries);
  67533. // this.hasSeriesStacked = false;
  67534. // each(targetSeries, function (series) {
  67535. // var data = series.getData();
  67536. // var dataDim = data.mapDimension(this._dimName);
  67537. // var stackedDimension = data.getCalculationInfo('stackedDimension');
  67538. // if (stackedDimension && stackedDimension === dataDim) {
  67539. // this.hasSeriesStacked = true;
  67540. // }
  67541. // }, this);
  67542. // `calculateDataWindow` uses min/maxSpan.
  67543. setMinMaxSpan(this);
  67544. var dataWindow = this.calculateDataWindow(dataZoomModel.option);
  67545. this._valueWindow = dataWindow.valueWindow;
  67546. this._percentWindow = dataWindow.percentWindow;
  67547. // Update axis setting then.
  67548. setAxisModel(this);
  67549. },
  67550. /**
  67551. * @param {module: echarts/component/dataZoom/DataZoomModel} dataZoomModel
  67552. */
  67553. restore: function (dataZoomModel) {
  67554. if (dataZoomModel !== this._dataZoomModel) {
  67555. return;
  67556. }
  67557. this._valueWindow = this._percentWindow = null;
  67558. setAxisModel(this, true);
  67559. },
  67560. /**
  67561. * @param {module: echarts/component/dataZoom/DataZoomModel} dataZoomModel
  67562. */
  67563. filterData: function (dataZoomModel, api) {
  67564. if (dataZoomModel !== this._dataZoomModel) {
  67565. return;
  67566. }
  67567. var axisDim = this._dimName;
  67568. var seriesModels = this.getTargetSeriesModels();
  67569. var filterMode = dataZoomModel.get('filterMode');
  67570. var valueWindow = this._valueWindow;
  67571. if (filterMode === 'none') {
  67572. return;
  67573. }
  67574. // FIXME
  67575. // Toolbox may has dataZoom injected. And if there are stacked bar chart
  67576. // with NaN data, NaN will be filtered and stack will be wrong.
  67577. // So we need to force the mode to be set empty.
  67578. // In fect, it is not a big deal that do not support filterMode-'filter'
  67579. // when using toolbox#dataZoom, utill tooltip#dataZoom support "single axis
  67580. // selection" some day, which might need "adapt to data extent on the
  67581. // otherAxis", which is disabled by filterMode-'empty'.
  67582. // But currently, stack has been fixed to based on value but not index,
  67583. // so this is not an issue any more.
  67584. // var otherAxisModel = this.getOtherAxisModel();
  67585. // if (dataZoomModel.get('$fromToolbox')
  67586. // && otherAxisModel
  67587. // && otherAxisModel.hasSeriesStacked
  67588. // ) {
  67589. // filterMode = 'empty';
  67590. // }
  67591. // TODO
  67592. // filterMode 'weakFilter' and 'empty' is not optimized for huge data yet.
  67593. each$20(seriesModels, function (seriesModel) {
  67594. var seriesData = seriesModel.getData();
  67595. var dataDims = seriesData.mapDimension(axisDim, true);
  67596. if (!dataDims.length) {
  67597. return;
  67598. }
  67599. if (filterMode === 'weakFilter') {
  67600. seriesData.filterSelf(function (dataIndex) {
  67601. var leftOut;
  67602. var rightOut;
  67603. var hasValue;
  67604. for (var i = 0; i < dataDims.length; i++) {
  67605. var value = seriesData.get(dataDims[i], dataIndex);
  67606. var thisHasValue = !isNaN(value);
  67607. var thisLeftOut = value < valueWindow[0];
  67608. var thisRightOut = value > valueWindow[1];
  67609. if (thisHasValue && !thisLeftOut && !thisRightOut) {
  67610. return true;
  67611. }
  67612. thisHasValue && (hasValue = true);
  67613. thisLeftOut && (leftOut = true);
  67614. thisRightOut && (rightOut = true);
  67615. }
  67616. // If both left out and right out, do not filter.
  67617. return hasValue && leftOut && rightOut;
  67618. });
  67619. }
  67620. else {
  67621. each$20(dataDims, function (dim) {
  67622. if (filterMode === 'empty') {
  67623. seriesModel.setData(
  67624. seriesData = seriesData.map(dim, function (value) {
  67625. return !isInWindow(value) ? NaN : value;
  67626. })
  67627. );
  67628. }
  67629. else {
  67630. var range = {};
  67631. range[dim] = valueWindow;
  67632. // console.time('select');
  67633. seriesData.selectRange(range);
  67634. // console.timeEnd('select');
  67635. }
  67636. });
  67637. }
  67638. each$20(dataDims, function (dim) {
  67639. seriesData.setApproximateExtent(valueWindow, dim);
  67640. });
  67641. });
  67642. function isInWindow(value) {
  67643. return value >= valueWindow[0] && value <= valueWindow[1];
  67644. }
  67645. }
  67646. };
  67647. function calculateDataExtent(axisProxy, axisDim, seriesModels) {
  67648. var dataExtent = [Infinity, -Infinity];
  67649. each$20(seriesModels, function (seriesModel) {
  67650. var seriesData = seriesModel.getData();
  67651. if (seriesData) {
  67652. each$20(seriesData.mapDimension(axisDim, true), function (dim) {
  67653. var seriesExtent = seriesData.getApproximateExtent(dim);
  67654. seriesExtent[0] < dataExtent[0] && (dataExtent[0] = seriesExtent[0]);
  67655. seriesExtent[1] > dataExtent[1] && (dataExtent[1] = seriesExtent[1]);
  67656. });
  67657. }
  67658. });
  67659. if (dataExtent[1] < dataExtent[0]) {
  67660. dataExtent = [NaN, NaN];
  67661. }
  67662. // It is important to get "consistent" extent when more then one axes is
  67663. // controlled by a `dataZoom`, otherwise those axes will not be synchronized
  67664. // when zooming. But it is difficult to know what is "consistent", considering
  67665. // axes have different type or even different meanings (For example, two
  67666. // time axes are used to compare data of the same date in different years).
  67667. // So basically dataZoom just obtains extent by series.data (in category axis
  67668. // extent can be obtained from axis.data).
  67669. // Nevertheless, user can set min/max/scale on axes to make extent of axes
  67670. // consistent.
  67671. fixExtentByAxis(axisProxy, dataExtent);
  67672. return dataExtent;
  67673. }
  67674. function fixExtentByAxis(axisProxy, dataExtent) {
  67675. var axisModel = axisProxy.getAxisModel();
  67676. var min = axisModel.getMin(true);
  67677. // For category axis, if min/max/scale are not set, extent is determined
  67678. // by axis.data by default.
  67679. var isCategoryAxis = axisModel.get('type') === 'category';
  67680. var axisDataLen = isCategoryAxis && axisModel.getCategories().length;
  67681. if (min != null && min !== 'dataMin' && typeof min !== 'function') {
  67682. dataExtent[0] = min;
  67683. }
  67684. else if (isCategoryAxis) {
  67685. dataExtent[0] = axisDataLen > 0 ? 0 : NaN;
  67686. }
  67687. var max = axisModel.getMax(true);
  67688. if (max != null && max !== 'dataMax' && typeof max !== 'function') {
  67689. dataExtent[1] = max;
  67690. }
  67691. else if (isCategoryAxis) {
  67692. dataExtent[1] = axisDataLen > 0 ? axisDataLen - 1 : NaN;
  67693. }
  67694. if (!axisModel.get('scale', true)) {
  67695. dataExtent[0] > 0 && (dataExtent[0] = 0);
  67696. dataExtent[1] < 0 && (dataExtent[1] = 0);
  67697. }
  67698. // For value axis, if min/max/scale are not set, we just use the extent obtained
  67699. // by series data, which may be a little different from the extent calculated by
  67700. // `axisHelper.getScaleExtent`. But the different just affects the experience a
  67701. // little when zooming. So it will not be fixed until some users require it strongly.
  67702. return dataExtent;
  67703. }
  67704. function setAxisModel(axisProxy, isRestore) {
  67705. var axisModel = axisProxy.getAxisModel();
  67706. var percentWindow = axisProxy._percentWindow;
  67707. var valueWindow = axisProxy._valueWindow;
  67708. if (!percentWindow) {
  67709. return;
  67710. }
  67711. // [0, 500]: arbitrary value, guess axis extent.
  67712. var precision = getPixelPrecision(valueWindow, [0, 500]);
  67713. precision = Math.min(precision, 20);
  67714. // isRestore or isFull
  67715. var useOrigin = isRestore || (percentWindow[0] === 0 && percentWindow[1] === 100);
  67716. axisModel.setRange(
  67717. useOrigin ? null : +valueWindow[0].toFixed(precision),
  67718. useOrigin ? null : +valueWindow[1].toFixed(precision)
  67719. );
  67720. }
  67721. function setMinMaxSpan(axisProxy) {
  67722. var minMaxSpan = axisProxy._minMaxSpan = {};
  67723. var dataZoomModel = axisProxy._dataZoomModel;
  67724. var dataExtent = axisProxy._dataExtent;
  67725. each$20(['min', 'max'], function (minMax) {
  67726. var percentSpan = dataZoomModel.get(minMax + 'Span');
  67727. var valueSpan = dataZoomModel.get(minMax + 'ValueSpan');
  67728. valueSpan != null && (valueSpan = axisProxy.getAxisModel().axis.scale.parse(valueSpan));
  67729. // minValueSpan and maxValueSpan has higher priority than minSpan and maxSpan
  67730. if (valueSpan != null) {
  67731. percentSpan = linearMap(
  67732. dataExtent[0] + valueSpan, dataExtent, [0, 100], true
  67733. );
  67734. }
  67735. else if (percentSpan != null) {
  67736. valueSpan = linearMap(
  67737. percentSpan, [0, 100], dataExtent, true
  67738. ) - dataExtent[0];
  67739. }
  67740. minMaxSpan[minMax + 'Span'] = percentSpan;
  67741. minMaxSpan[minMax + 'ValueSpan'] = valueSpan;
  67742. });
  67743. }
  67744. /*
  67745. * Licensed to the Apache Software Foundation (ASF) under one
  67746. * or more contributor license agreements. See the NOTICE file
  67747. * distributed with this work for additional information
  67748. * regarding copyright ownership. The ASF licenses this file
  67749. * to you under the Apache License, Version 2.0 (the
  67750. * "License"); you may not use this file except in compliance
  67751. * with the License. You may obtain a copy of the License at
  67752. *
  67753. * http://www.apache.org/licenses/LICENSE-2.0
  67754. *
  67755. * Unless required by applicable law or agreed to in writing,
  67756. * software distributed under the License is distributed on an
  67757. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  67758. * KIND, either express or implied. See the License for the
  67759. * specific language governing permissions and limitations
  67760. * under the License.
  67761. */
  67762. var each$19 = each$1;
  67763. var eachAxisDim = eachAxisDim$1;
  67764. var DataZoomModel = extendComponentModel({
  67765. type: 'dataZoom',
  67766. dependencies: [
  67767. 'xAxis', 'yAxis', 'zAxis', 'radiusAxis', 'angleAxis', 'singleAxis', 'series'
  67768. ],
  67769. /**
  67770. * @protected
  67771. */
  67772. defaultOption: {
  67773. zlevel: 0,
  67774. z: 4, // Higher than normal component (z: 2).
  67775. orient: null, // Default auto by axisIndex. Possible value: 'horizontal', 'vertical'.
  67776. xAxisIndex: null, // Default the first horizontal category axis.
  67777. yAxisIndex: null, // Default the first vertical category axis.
  67778. filterMode: 'filter', // Possible values: 'filter' or 'empty' or 'weakFilter'.
  67779. // 'filter': data items which are out of window will be removed. This option is
  67780. // applicable when filtering outliers. For each data item, it will be
  67781. // filtered if one of the relevant dimensions is out of the window.
  67782. // 'weakFilter': data items which are out of window will be removed. This option
  67783. // is applicable when filtering outliers. For each data item, it will be
  67784. // filtered only if all of the relevant dimensions are out of the same
  67785. // side of the window.
  67786. // 'empty': data items which are out of window will be set to empty.
  67787. // This option is applicable when user should not neglect
  67788. // that there are some data items out of window.
  67789. // 'none': Do not filter.
  67790. // Taking line chart as an example, line will be broken in
  67791. // the filtered points when filterModel is set to 'empty', but
  67792. // be connected when set to 'filter'.
  67793. throttle: null, // Dispatch action by the fixed rate, avoid frequency.
  67794. // default 100. Do not throttle when use null/undefined.
  67795. // If animation === true and animationDurationUpdate > 0,
  67796. // default value is 100, otherwise 20.
  67797. start: 0, // Start percent. 0 ~ 100
  67798. end: 100, // End percent. 0 ~ 100
  67799. startValue: null, // Start value. If startValue specified, start is ignored.
  67800. endValue: null, // End value. If endValue specified, end is ignored.
  67801. minSpan: null, // 0 ~ 100
  67802. maxSpan: null, // 0 ~ 100
  67803. minValueSpan: null, // The range of dataZoom can not be smaller than that.
  67804. maxValueSpan: null, // The range of dataZoom can not be larger than that.
  67805. rangeMode: null // Array, can be 'value' or 'percent'.
  67806. },
  67807. /**
  67808. * @override
  67809. */
  67810. init: function (option, parentModel, ecModel) {
  67811. /**
  67812. * key like x_0, y_1
  67813. * @private
  67814. * @type {Object}
  67815. */
  67816. this._dataIntervalByAxis = {};
  67817. /**
  67818. * @private
  67819. */
  67820. this._dataInfo = {};
  67821. /**
  67822. * key like x_0, y_1
  67823. * @private
  67824. */
  67825. this._axisProxies = {};
  67826. /**
  67827. * @readOnly
  67828. */
  67829. this.textStyleModel;
  67830. /**
  67831. * @private
  67832. */
  67833. this._autoThrottle = true;
  67834. /**
  67835. * 'percent' or 'value'
  67836. * @private
  67837. */
  67838. this._rangePropMode = ['percent', 'percent'];
  67839. var rawOption = retrieveRaw(option);
  67840. this.mergeDefaultAndTheme(option, ecModel);
  67841. this.doInit(rawOption);
  67842. },
  67843. /**
  67844. * @override
  67845. */
  67846. mergeOption: function (newOption) {
  67847. var rawOption = retrieveRaw(newOption);
  67848. //FIX #2591
  67849. merge(this.option, newOption, true);
  67850. this.doInit(rawOption);
  67851. },
  67852. /**
  67853. * @protected
  67854. */
  67855. doInit: function (rawOption) {
  67856. var thisOption = this.option;
  67857. // Disable realtime view update if canvas is not supported.
  67858. if (!env$1.canvasSupported) {
  67859. thisOption.realtime = false;
  67860. }
  67861. this._setDefaultThrottle(rawOption);
  67862. updateRangeUse(this, rawOption);
  67863. each$19([['start', 'startValue'], ['end', 'endValue']], function (names, index) {
  67864. // start/end has higher priority over startValue/endValue if they
  67865. // both set, but we should make chart.setOption({endValue: 1000})
  67866. // effective, rather than chart.setOption({endValue: 1000, end: null}).
  67867. if (this._rangePropMode[index] === 'value') {
  67868. thisOption[names[0]] = null;
  67869. }
  67870. // Otherwise do nothing and use the merge result.
  67871. }, this);
  67872. this.textStyleModel = this.getModel('textStyle');
  67873. this._resetTarget();
  67874. this._giveAxisProxies();
  67875. },
  67876. /**
  67877. * @private
  67878. */
  67879. _giveAxisProxies: function () {
  67880. var axisProxies = this._axisProxies;
  67881. this.eachTargetAxis(function (dimNames, axisIndex, dataZoomModel, ecModel) {
  67882. var axisModel = this.dependentModels[dimNames.axis][axisIndex];
  67883. // If exists, share axisProxy with other dataZoomModels.
  67884. var axisProxy = axisModel.__dzAxisProxy || (
  67885. // Use the first dataZoomModel as the main model of axisProxy.
  67886. axisModel.__dzAxisProxy = new AxisProxy(
  67887. dimNames.name, axisIndex, this, ecModel
  67888. )
  67889. );
  67890. // FIXME
  67891. // dispose __dzAxisProxy
  67892. axisProxies[dimNames.name + '_' + axisIndex] = axisProxy;
  67893. }, this);
  67894. },
  67895. /**
  67896. * @private
  67897. */
  67898. _resetTarget: function () {
  67899. var thisOption = this.option;
  67900. var autoMode = this._judgeAutoMode();
  67901. eachAxisDim(function (dimNames) {
  67902. var axisIndexName = dimNames.axisIndex;
  67903. thisOption[axisIndexName] = normalizeToArray(
  67904. thisOption[axisIndexName]
  67905. );
  67906. }, this);
  67907. if (autoMode === 'axisIndex') {
  67908. this._autoSetAxisIndex();
  67909. }
  67910. else if (autoMode === 'orient') {
  67911. this._autoSetOrient();
  67912. }
  67913. },
  67914. /**
  67915. * @private
  67916. */
  67917. _judgeAutoMode: function () {
  67918. // Auto set only works for setOption at the first time.
  67919. // The following is user's reponsibility. So using merged
  67920. // option is OK.
  67921. var thisOption = this.option;
  67922. var hasIndexSpecified = false;
  67923. eachAxisDim(function (dimNames) {
  67924. // When user set axisIndex as a empty array, we think that user specify axisIndex
  67925. // but do not want use auto mode. Because empty array may be encountered when
  67926. // some error occured.
  67927. if (thisOption[dimNames.axisIndex] != null) {
  67928. hasIndexSpecified = true;
  67929. }
  67930. }, this);
  67931. var orient = thisOption.orient;
  67932. if (orient == null && hasIndexSpecified) {
  67933. return 'orient';
  67934. }
  67935. else if (!hasIndexSpecified) {
  67936. if (orient == null) {
  67937. thisOption.orient = 'horizontal';
  67938. }
  67939. return 'axisIndex';
  67940. }
  67941. },
  67942. /**
  67943. * @private
  67944. */
  67945. _autoSetAxisIndex: function () {
  67946. var autoAxisIndex = true;
  67947. var orient = this.get('orient', true);
  67948. var thisOption = this.option;
  67949. var dependentModels = this.dependentModels;
  67950. if (autoAxisIndex) {
  67951. // Find axis that parallel to dataZoom as default.
  67952. var dimName = orient === 'vertical' ? 'y' : 'x';
  67953. if (dependentModels[dimName + 'Axis'].length) {
  67954. thisOption[dimName + 'AxisIndex'] = [0];
  67955. autoAxisIndex = false;
  67956. }
  67957. else {
  67958. each$19(dependentModels.singleAxis, function (singleAxisModel) {
  67959. if (autoAxisIndex && singleAxisModel.get('orient', true) === orient) {
  67960. thisOption.singleAxisIndex = [singleAxisModel.componentIndex];
  67961. autoAxisIndex = false;
  67962. }
  67963. });
  67964. }
  67965. }
  67966. if (autoAxisIndex) {
  67967. // Find the first category axis as default. (consider polar)
  67968. eachAxisDim(function (dimNames) {
  67969. if (!autoAxisIndex) {
  67970. return;
  67971. }
  67972. var axisIndices = [];
  67973. var axisModels = this.dependentModels[dimNames.axis];
  67974. if (axisModels.length && !axisIndices.length) {
  67975. for (var i = 0, len = axisModels.length; i < len; i++) {
  67976. if (axisModels[i].get('type') === 'category') {
  67977. axisIndices.push(i);
  67978. }
  67979. }
  67980. }
  67981. thisOption[dimNames.axisIndex] = axisIndices;
  67982. if (axisIndices.length) {
  67983. autoAxisIndex = false;
  67984. }
  67985. }, this);
  67986. }
  67987. if (autoAxisIndex) {
  67988. // FIXME
  67989. // 这里是兼容ec2的写法(没指定xAxisIndex和yAxisIndex时把scatter和双数值轴折柱纳入dataZoom控制),
  67990. // 但是实际是否需要Grid.js#getScaleByOption来判断(考虑time,log等axis type)?
  67991. // If both dataZoom.xAxisIndex and dataZoom.yAxisIndex is not specified,
  67992. // dataZoom component auto adopts series that reference to
  67993. // both xAxis and yAxis which type is 'value'.
  67994. this.ecModel.eachSeries(function (seriesModel) {
  67995. if (this._isSeriesHasAllAxesTypeOf(seriesModel, 'value')) {
  67996. eachAxisDim(function (dimNames) {
  67997. var axisIndices = thisOption[dimNames.axisIndex];
  67998. var axisIndex = seriesModel.get(dimNames.axisIndex);
  67999. var axisId = seriesModel.get(dimNames.axisId);
  68000. var axisModel = seriesModel.ecModel.queryComponents({
  68001. mainType: dimNames.axis,
  68002. index: axisIndex,
  68003. id: axisId
  68004. })[0];
  68005. if (__DEV__) {
  68006. if (!axisModel) {
  68007. throw new Error(
  68008. dimNames.axis + ' "' + retrieve(
  68009. axisIndex,
  68010. axisId,
  68011. 0
  68012. ) + '" not found'
  68013. );
  68014. }
  68015. }
  68016. axisIndex = axisModel.componentIndex;
  68017. if (indexOf(axisIndices, axisIndex) < 0) {
  68018. axisIndices.push(axisIndex);
  68019. }
  68020. });
  68021. }
  68022. }, this);
  68023. }
  68024. },
  68025. /**
  68026. * @private
  68027. */
  68028. _autoSetOrient: function () {
  68029. var dim;
  68030. // Find the first axis
  68031. this.eachTargetAxis(function (dimNames) {
  68032. !dim && (dim = dimNames.name);
  68033. }, this);
  68034. this.option.orient = dim === 'y' ? 'vertical' : 'horizontal';
  68035. },
  68036. /**
  68037. * @private
  68038. */
  68039. _isSeriesHasAllAxesTypeOf: function (seriesModel, axisType) {
  68040. // FIXME
  68041. // 需要series的xAxisIndex和yAxisIndex都首先自动设置上。
  68042. // 例如series.type === scatter时。
  68043. var is = true;
  68044. eachAxisDim(function (dimNames) {
  68045. var seriesAxisIndex = seriesModel.get(dimNames.axisIndex);
  68046. var axisModel = this.dependentModels[dimNames.axis][seriesAxisIndex];
  68047. if (!axisModel || axisModel.get('type') !== axisType) {
  68048. is = false;
  68049. }
  68050. }, this);
  68051. return is;
  68052. },
  68053. /**
  68054. * @private
  68055. */
  68056. _setDefaultThrottle: function (rawOption) {
  68057. // When first time user set throttle, auto throttle ends.
  68058. if (rawOption.hasOwnProperty('throttle')) {
  68059. this._autoThrottle = false;
  68060. }
  68061. if (this._autoThrottle) {
  68062. var globalOption = this.ecModel.option;
  68063. this.option.throttle
  68064. = (globalOption.animation && globalOption.animationDurationUpdate > 0)
  68065. ? 100 : 20;
  68066. }
  68067. },
  68068. /**
  68069. * @public
  68070. */
  68071. getFirstTargetAxisModel: function () {
  68072. var firstAxisModel;
  68073. eachAxisDim(function (dimNames) {
  68074. if (firstAxisModel == null) {
  68075. var indices = this.get(dimNames.axisIndex);
  68076. if (indices.length) {
  68077. firstAxisModel = this.dependentModels[dimNames.axis][indices[0]];
  68078. }
  68079. }
  68080. }, this);
  68081. return firstAxisModel;
  68082. },
  68083. /**
  68084. * @public
  68085. * @param {Function} callback param: axisModel, dimNames, axisIndex, dataZoomModel, ecModel
  68086. */
  68087. eachTargetAxis: function (callback, context) {
  68088. var ecModel = this.ecModel;
  68089. eachAxisDim(function (dimNames) {
  68090. each$19(
  68091. this.get(dimNames.axisIndex),
  68092. function (axisIndex) {
  68093. callback.call(context, dimNames, axisIndex, this, ecModel);
  68094. },
  68095. this
  68096. );
  68097. }, this);
  68098. },
  68099. /**
  68100. * @param {string} dimName
  68101. * @param {number} axisIndex
  68102. * @return {module:echarts/component/dataZoom/AxisProxy} If not found, return null/undefined.
  68103. */
  68104. getAxisProxy: function (dimName, axisIndex) {
  68105. return this._axisProxies[dimName + '_' + axisIndex];
  68106. },
  68107. /**
  68108. * @param {string} dimName
  68109. * @param {number} axisIndex
  68110. * @return {module:echarts/model/Model} If not found, return null/undefined.
  68111. */
  68112. getAxisModel: function (dimName, axisIndex) {
  68113. var axisProxy = this.getAxisProxy(dimName, axisIndex);
  68114. return axisProxy && axisProxy.getAxisModel();
  68115. },
  68116. /**
  68117. * If not specified, set to undefined.
  68118. *
  68119. * @public
  68120. * @param {Object} opt
  68121. * @param {number} [opt.start]
  68122. * @param {number} [opt.end]
  68123. * @param {number} [opt.startValue]
  68124. * @param {number} [opt.endValue]
  68125. * @param {boolean} [ignoreUpdateRangeUsg=false]
  68126. */
  68127. setRawRange: function (opt, ignoreUpdateRangeUsg) {
  68128. var option = this.option;
  68129. each$19([['start', 'startValue'], ['end', 'endValue']], function (names) {
  68130. // If only one of 'start' and 'startValue' is not null/undefined, the other
  68131. // should be cleared, which enable clear the option.
  68132. // If both of them are not set, keep option with the original value, which
  68133. // enable use only set start but not set end when calling `dispatchAction`.
  68134. // The same as 'end' and 'endValue'.
  68135. if (opt[names[0]] != null || opt[names[1]] != null) {
  68136. option[names[0]] = opt[names[0]];
  68137. option[names[1]] = opt[names[1]];
  68138. }
  68139. }, this);
  68140. !ignoreUpdateRangeUsg && updateRangeUse(this, opt);
  68141. },
  68142. /**
  68143. * @public
  68144. * @return {Array.<number>} [startPercent, endPercent]
  68145. */
  68146. getPercentRange: function () {
  68147. var axisProxy = this.findRepresentativeAxisProxy();
  68148. if (axisProxy) {
  68149. return axisProxy.getDataPercentWindow();
  68150. }
  68151. },
  68152. /**
  68153. * @public
  68154. * For example, chart.getModel().getComponent('dataZoom').getValueRange('y', 0);
  68155. *
  68156. * @param {string} [axisDimName]
  68157. * @param {number} [axisIndex]
  68158. * @return {Array.<number>} [startValue, endValue] value can only be '-' or finite number.
  68159. */
  68160. getValueRange: function (axisDimName, axisIndex) {
  68161. if (axisDimName == null && axisIndex == null) {
  68162. var axisProxy = this.findRepresentativeAxisProxy();
  68163. if (axisProxy) {
  68164. return axisProxy.getDataValueWindow();
  68165. }
  68166. }
  68167. else {
  68168. return this.getAxisProxy(axisDimName, axisIndex).getDataValueWindow();
  68169. }
  68170. },
  68171. /**
  68172. * @public
  68173. * @param {module:echarts/model/Model} [axisModel] If axisModel given, find axisProxy
  68174. * corresponding to the axisModel
  68175. * @return {module:echarts/component/dataZoom/AxisProxy}
  68176. */
  68177. findRepresentativeAxisProxy: function (axisModel) {
  68178. if (axisModel) {
  68179. return axisModel.__dzAxisProxy;
  68180. }
  68181. // Find the first hosted axisProxy
  68182. var axisProxies = this._axisProxies;
  68183. for (var key in axisProxies) {
  68184. if (axisProxies.hasOwnProperty(key) && axisProxies[key].hostedBy(this)) {
  68185. return axisProxies[key];
  68186. }
  68187. }
  68188. // If no hosted axis find not hosted axisProxy.
  68189. // Consider this case: dataZoomModel1 and dataZoomModel2 control the same axis,
  68190. // and the option.start or option.end settings are different. The percentRange
  68191. // should follow axisProxy.
  68192. // (We encounter this problem in toolbox data zoom.)
  68193. for (var key in axisProxies) {
  68194. if (axisProxies.hasOwnProperty(key) && !axisProxies[key].hostedBy(this)) {
  68195. return axisProxies[key];
  68196. }
  68197. }
  68198. },
  68199. /**
  68200. * @return {Array.<string>}
  68201. */
  68202. getRangePropMode: function () {
  68203. return this._rangePropMode.slice();
  68204. }
  68205. });
  68206. function retrieveRaw(option) {
  68207. var ret = {};
  68208. each$19(
  68209. ['start', 'end', 'startValue', 'endValue', 'throttle'],
  68210. function (name) {
  68211. option.hasOwnProperty(name) && (ret[name] = option[name]);
  68212. }
  68213. );
  68214. return ret;
  68215. }
  68216. function updateRangeUse(dataZoomModel, rawOption) {
  68217. var rangePropMode = dataZoomModel._rangePropMode;
  68218. var rangeModeInOption = dataZoomModel.get('rangeMode');
  68219. each$19([['start', 'startValue'], ['end', 'endValue']], function (names, index) {
  68220. var percentSpecified = rawOption[names[0]] != null;
  68221. var valueSpecified = rawOption[names[1]] != null;
  68222. if (percentSpecified && !valueSpecified) {
  68223. rangePropMode[index] = 'percent';
  68224. }
  68225. else if (!percentSpecified && valueSpecified) {
  68226. rangePropMode[index] = 'value';
  68227. }
  68228. else if (rangeModeInOption) {
  68229. rangePropMode[index] = rangeModeInOption[index];
  68230. }
  68231. else if (percentSpecified) { // percentSpecified && valueSpecified
  68232. rangePropMode[index] = 'percent';
  68233. }
  68234. // else remain its original setting.
  68235. });
  68236. }
  68237. /*
  68238. * Licensed to the Apache Software Foundation (ASF) under one
  68239. * or more contributor license agreements. See the NOTICE file
  68240. * distributed with this work for additional information
  68241. * regarding copyright ownership. The ASF licenses this file
  68242. * to you under the Apache License, Version 2.0 (the
  68243. * "License"); you may not use this file except in compliance
  68244. * with the License. You may obtain a copy of the License at
  68245. *
  68246. * http://www.apache.org/licenses/LICENSE-2.0
  68247. *
  68248. * Unless required by applicable law or agreed to in writing,
  68249. * software distributed under the License is distributed on an
  68250. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  68251. * KIND, either express or implied. See the License for the
  68252. * specific language governing permissions and limitations
  68253. * under the License.
  68254. */
  68255. var DataZoomView = Component$1.extend({
  68256. type: 'dataZoom',
  68257. render: function (dataZoomModel, ecModel, api, payload) {
  68258. this.dataZoomModel = dataZoomModel;
  68259. this.ecModel = ecModel;
  68260. this.api = api;
  68261. },
  68262. /**
  68263. * Find the first target coordinate system.
  68264. *
  68265. * @protected
  68266. * @return {Object} {
  68267. * grid: [
  68268. * {model: coord0, axisModels: [axis1, axis3], coordIndex: 1},
  68269. * {model: coord1, axisModels: [axis0, axis2], coordIndex: 0},
  68270. * ...
  68271. * ], // cartesians must not be null/undefined.
  68272. * polar: [
  68273. * {model: coord0, axisModels: [axis4], coordIndex: 0},
  68274. * ...
  68275. * ], // polars must not be null/undefined.
  68276. * singleAxis: [
  68277. * {model: coord0, axisModels: [], coordIndex: 0}
  68278. * ]
  68279. */
  68280. getTargetCoordInfo: function () {
  68281. var dataZoomModel = this.dataZoomModel;
  68282. var ecModel = this.ecModel;
  68283. var coordSysLists = {};
  68284. dataZoomModel.eachTargetAxis(function (dimNames, axisIndex) {
  68285. var axisModel = ecModel.getComponent(dimNames.axis, axisIndex);
  68286. if (axisModel) {
  68287. var coordModel = axisModel.getCoordSysModel();
  68288. coordModel && save(
  68289. coordModel,
  68290. axisModel,
  68291. coordSysLists[coordModel.mainType] || (coordSysLists[coordModel.mainType] = []),
  68292. coordModel.componentIndex
  68293. );
  68294. }
  68295. }, this);
  68296. function save(coordModel, axisModel, store, coordIndex) {
  68297. var item;
  68298. for (var i = 0; i < store.length; i++) {
  68299. if (store[i].model === coordModel) {
  68300. item = store[i];
  68301. break;
  68302. }
  68303. }
  68304. if (!item) {
  68305. store.push(item = {
  68306. model: coordModel, axisModels: [], coordIndex: coordIndex
  68307. });
  68308. }
  68309. item.axisModels.push(axisModel);
  68310. }
  68311. return coordSysLists;
  68312. }
  68313. });
  68314. /*
  68315. * Licensed to the Apache Software Foundation (ASF) under one
  68316. * or more contributor license agreements. See the NOTICE file
  68317. * distributed with this work for additional information
  68318. * regarding copyright ownership. The ASF licenses this file
  68319. * to you under the Apache License, Version 2.0 (the
  68320. * "License"); you may not use this file except in compliance
  68321. * with the License. You may obtain a copy of the License at
  68322. *
  68323. * http://www.apache.org/licenses/LICENSE-2.0
  68324. *
  68325. * Unless required by applicable law or agreed to in writing,
  68326. * software distributed under the License is distributed on an
  68327. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  68328. * KIND, either express or implied. See the License for the
  68329. * specific language governing permissions and limitations
  68330. * under the License.
  68331. */
  68332. DataZoomModel.extend({
  68333. type: 'dataZoom.select'
  68334. });
  68335. /*
  68336. * Licensed to the Apache Software Foundation (ASF) under one
  68337. * or more contributor license agreements. See the NOTICE file
  68338. * distributed with this work for additional information
  68339. * regarding copyright ownership. The ASF licenses this file
  68340. * to you under the Apache License, Version 2.0 (the
  68341. * "License"); you may not use this file except in compliance
  68342. * with the License. You may obtain a copy of the License at
  68343. *
  68344. * http://www.apache.org/licenses/LICENSE-2.0
  68345. *
  68346. * Unless required by applicable law or agreed to in writing,
  68347. * software distributed under the License is distributed on an
  68348. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  68349. * KIND, either express or implied. See the License for the
  68350. * specific language governing permissions and limitations
  68351. * under the License.
  68352. */
  68353. DataZoomView.extend({
  68354. type: 'dataZoom.select'
  68355. });
  68356. /*
  68357. * Licensed to the Apache Software Foundation (ASF) under one
  68358. * or more contributor license agreements. See the NOTICE file
  68359. * distributed with this work for additional information
  68360. * regarding copyright ownership. The ASF licenses this file
  68361. * to you under the Apache License, Version 2.0 (the
  68362. * "License"); you may not use this file except in compliance
  68363. * with the License. You may obtain a copy of the License at
  68364. *
  68365. * http://www.apache.org/licenses/LICENSE-2.0
  68366. *
  68367. * Unless required by applicable law or agreed to in writing,
  68368. * software distributed under the License is distributed on an
  68369. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  68370. * KIND, either express or implied. See the License for the
  68371. * specific language governing permissions and limitations
  68372. * under the License.
  68373. */
  68374. registerProcessor({
  68375. // `dataZoomProcessor` will only be performed in needed series. Consider if
  68376. // there is a line series and a pie series, it is better not to update the
  68377. // line series if only pie series is needed to be updated.
  68378. getTargetSeries: function (ecModel) {
  68379. var seriesModelMap = createHashMap();
  68380. ecModel.eachComponent('dataZoom', function (dataZoomModel) {
  68381. dataZoomModel.eachTargetAxis(function (dimNames, axisIndex, dataZoomModel) {
  68382. var axisProxy = dataZoomModel.getAxisProxy(dimNames.name, axisIndex);
  68383. each$1(axisProxy.getTargetSeriesModels(), function (seriesModel) {
  68384. seriesModelMap.set(seriesModel.uid, seriesModel);
  68385. });
  68386. });
  68387. });
  68388. return seriesModelMap;
  68389. },
  68390. modifyOutputEnd: true,
  68391. // Consider appendData, where filter should be performed. Because data process is
  68392. // in block mode currently, it is not need to worry about that the overallProgress
  68393. // execute every frame.
  68394. overallReset: function (ecModel, api) {
  68395. ecModel.eachComponent('dataZoom', function (dataZoomModel) {
  68396. // We calculate window and reset axis here but not in model
  68397. // init stage and not after action dispatch handler, because
  68398. // reset should be called after seriesData.restoreData.
  68399. dataZoomModel.eachTargetAxis(function (dimNames, axisIndex, dataZoomModel) {
  68400. dataZoomModel.getAxisProxy(dimNames.name, axisIndex).reset(dataZoomModel, api);
  68401. });
  68402. // Caution: data zoom filtering is order sensitive when using
  68403. // percent range and no min/max/scale set on axis.
  68404. // For example, we have dataZoom definition:
  68405. // [
  68406. // {xAxisIndex: 0, start: 30, end: 70},
  68407. // {yAxisIndex: 0, start: 20, end: 80}
  68408. // ]
  68409. // In this case, [20, 80] of y-dataZoom should be based on data
  68410. // that have filtered by x-dataZoom using range of [30, 70],
  68411. // but should not be based on full raw data. Thus sliding
  68412. // x-dataZoom will change both ranges of xAxis and yAxis,
  68413. // while sliding y-dataZoom will only change the range of yAxis.
  68414. // So we should filter x-axis after reset x-axis immediately,
  68415. // and then reset y-axis and filter y-axis.
  68416. dataZoomModel.eachTargetAxis(function (dimNames, axisIndex, dataZoomModel) {
  68417. dataZoomModel.getAxisProxy(dimNames.name, axisIndex).filterData(dataZoomModel, api);
  68418. });
  68419. });
  68420. ecModel.eachComponent('dataZoom', function (dataZoomModel) {
  68421. // Fullfill all of the range props so that user
  68422. // is able to get them from chart.getOption().
  68423. var axisProxy = dataZoomModel.findRepresentativeAxisProxy();
  68424. var percentRange = axisProxy.getDataPercentWindow();
  68425. var valueRange = axisProxy.getDataValueWindow();
  68426. dataZoomModel.setRawRange({
  68427. start: percentRange[0],
  68428. end: percentRange[1],
  68429. startValue: valueRange[0],
  68430. endValue: valueRange[1]
  68431. }, true);
  68432. });
  68433. }
  68434. });
  68435. /*
  68436. * Licensed to the Apache Software Foundation (ASF) under one
  68437. * or more contributor license agreements. See the NOTICE file
  68438. * distributed with this work for additional information
  68439. * regarding copyright ownership. The ASF licenses this file
  68440. * to you under the Apache License, Version 2.0 (the
  68441. * "License"); you may not use this file except in compliance
  68442. * with the License. You may obtain a copy of the License at
  68443. *
  68444. * http://www.apache.org/licenses/LICENSE-2.0
  68445. *
  68446. * Unless required by applicable law or agreed to in writing,
  68447. * software distributed under the License is distributed on an
  68448. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  68449. * KIND, either express or implied. See the License for the
  68450. * specific language governing permissions and limitations
  68451. * under the License.
  68452. */
  68453. registerAction('dataZoom', function (payload, ecModel) {
  68454. var linkedNodesFinder = createLinkedNodesFinder(
  68455. bind(ecModel.eachComponent, ecModel, 'dataZoom'),
  68456. eachAxisDim$1,
  68457. function (model, dimNames) {
  68458. return model.get(dimNames.axisIndex);
  68459. }
  68460. );
  68461. var effectedModels = [];
  68462. ecModel.eachComponent(
  68463. {mainType: 'dataZoom', query: payload},
  68464. function (model, index) {
  68465. effectedModels.push.apply(
  68466. effectedModels, linkedNodesFinder(model).nodes
  68467. );
  68468. }
  68469. );
  68470. each$1(effectedModels, function (dataZoomModel, index) {
  68471. dataZoomModel.setRawRange({
  68472. start: payload.start,
  68473. end: payload.end,
  68474. startValue: payload.startValue,
  68475. endValue: payload.endValue
  68476. });
  68477. });
  68478. });
  68479. /*
  68480. * Licensed to the Apache Software Foundation (ASF) under one
  68481. * or more contributor license agreements. See the NOTICE file
  68482. * distributed with this work for additional information
  68483. * regarding copyright ownership. The ASF licenses this file
  68484. * to you under the Apache License, Version 2.0 (the
  68485. * "License"); you may not use this file except in compliance
  68486. * with the License. You may obtain a copy of the License at
  68487. *
  68488. * http://www.apache.org/licenses/LICENSE-2.0
  68489. *
  68490. * Unless required by applicable law or agreed to in writing,
  68491. * software distributed under the License is distributed on an
  68492. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  68493. * KIND, either express or implied. See the License for the
  68494. * specific language governing permissions and limitations
  68495. * under the License.
  68496. */
  68497. /**
  68498. * Only work for toolbox dataZoom. User
  68499. * MUST NOT import this module directly.
  68500. */
  68501. /*
  68502. * Licensed to the Apache Software Foundation (ASF) under one
  68503. * or more contributor license agreements. See the NOTICE file
  68504. * distributed with this work for additional information
  68505. * regarding copyright ownership. The ASF licenses this file
  68506. * to you under the Apache License, Version 2.0 (the
  68507. * "License"); you may not use this file except in compliance
  68508. * with the License. You may obtain a copy of the License at
  68509. *
  68510. * http://www.apache.org/licenses/LICENSE-2.0
  68511. *
  68512. * Unless required by applicable law or agreed to in writing,
  68513. * software distributed under the License is distributed on an
  68514. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  68515. * KIND, either express or implied. See the License for the
  68516. * specific language governing permissions and limitations
  68517. * under the License.
  68518. */
  68519. // Use dataZoomSelect
  68520. var dataZoomLang = lang.toolbox.dataZoom;
  68521. var each$16 = each$1;
  68522. // Spectial component id start with \0ec\0, see echarts/model/Global.js~hasInnerId
  68523. var DATA_ZOOM_ID_BASE = '\0_ec_\0toolbox-dataZoom_';
  68524. function DataZoom(model, ecModel, api) {
  68525. /**
  68526. * @private
  68527. * @type {module:echarts/component/helper/BrushController}
  68528. */
  68529. (this._brushController = new BrushController(api.getZr()))
  68530. .on('brush', bind(this._onBrush, this))
  68531. .mount();
  68532. /**
  68533. * @private
  68534. * @type {boolean}
  68535. */
  68536. this._isZoomActive;
  68537. }
  68538. DataZoom.defaultOption = {
  68539. show: true,
  68540. // Icon group
  68541. icon: {
  68542. zoom: 'M0,13.5h26.9 M13.5,26.9V0 M32.1,13.5H58V58H13.5 V32.1',
  68543. back: 'M22,1.4L9.9,13.5l12.3,12.3 M10.3,13.5H54.9v44.6 H10.3v-26'
  68544. },
  68545. // `zoom`, `back`
  68546. title: clone(dataZoomLang.title)
  68547. };
  68548. var proto$4 = DataZoom.prototype;
  68549. proto$4.render = function (featureModel, ecModel, api, payload) {
  68550. this.model = featureModel;
  68551. this.ecModel = ecModel;
  68552. this.api = api;
  68553. updateZoomBtnStatus(featureModel, ecModel, this, payload, api);
  68554. updateBackBtnStatus(featureModel, ecModel);
  68555. };
  68556. proto$4.onclick = function (ecModel, api, type) {
  68557. handlers$1[type].call(this);
  68558. };
  68559. proto$4.remove = function (ecModel, api) {
  68560. this._brushController.unmount();
  68561. };
  68562. proto$4.dispose = function (ecModel, api) {
  68563. this._brushController.dispose();
  68564. };
  68565. /**
  68566. * @private
  68567. */
  68568. var handlers$1 = {
  68569. zoom: function () {
  68570. var nextActive = !this._isZoomActive;
  68571. this.api.dispatchAction({
  68572. type: 'takeGlobalCursor',
  68573. key: 'dataZoomSelect',
  68574. dataZoomSelectActive: nextActive
  68575. });
  68576. },
  68577. back: function () {
  68578. this._dispatchZoomAction(pop(this.ecModel));
  68579. }
  68580. };
  68581. /**
  68582. * @private
  68583. */
  68584. proto$4._onBrush = function (areas, opt) {
  68585. if (!opt.isEnd || !areas.length) {
  68586. return;
  68587. }
  68588. var snapshot = {};
  68589. var ecModel = this.ecModel;
  68590. this._brushController.updateCovers([]); // remove cover
  68591. var brushTargetManager = new BrushTargetManager(
  68592. retrieveAxisSetting(this.model.option), ecModel, {include: ['grid']}
  68593. );
  68594. brushTargetManager.matchOutputRanges(areas, ecModel, function (area, coordRange, coordSys) {
  68595. if (coordSys.type !== 'cartesian2d') {
  68596. return;
  68597. }
  68598. var brushType = area.brushType;
  68599. if (brushType === 'rect') {
  68600. setBatch('x', coordSys, coordRange[0]);
  68601. setBatch('y', coordSys, coordRange[1]);
  68602. }
  68603. else {
  68604. setBatch(({lineX: 'x', lineY: 'y'})[brushType], coordSys, coordRange);
  68605. }
  68606. });
  68607. push(ecModel, snapshot);
  68608. this._dispatchZoomAction(snapshot);
  68609. function setBatch(dimName, coordSys, minMax) {
  68610. var axis = coordSys.getAxis(dimName);
  68611. var axisModel = axis.model;
  68612. var dataZoomModel = findDataZoom(dimName, axisModel, ecModel);
  68613. // Restrict range.
  68614. var minMaxSpan = dataZoomModel.findRepresentativeAxisProxy(axisModel).getMinMaxSpan();
  68615. if (minMaxSpan.minValueSpan != null || minMaxSpan.maxValueSpan != null) {
  68616. minMax = sliderMove(
  68617. 0, minMax.slice(), axis.scale.getExtent(), 0,
  68618. minMaxSpan.minValueSpan, minMaxSpan.maxValueSpan
  68619. );
  68620. }
  68621. dataZoomModel && (snapshot[dataZoomModel.id] = {
  68622. dataZoomId: dataZoomModel.id,
  68623. startValue: minMax[0],
  68624. endValue: minMax[1]
  68625. });
  68626. }
  68627. function findDataZoom(dimName, axisModel, ecModel) {
  68628. var found;
  68629. ecModel.eachComponent({mainType: 'dataZoom', subType: 'select'}, function (dzModel) {
  68630. var has = dzModel.getAxisModel(dimName, axisModel.componentIndex);
  68631. has && (found = dzModel);
  68632. });
  68633. return found;
  68634. }
  68635. };
  68636. /**
  68637. * @private
  68638. */
  68639. proto$4._dispatchZoomAction = function (snapshot) {
  68640. var batch = [];
  68641. // Convert from hash map to array.
  68642. each$16(snapshot, function (batchItem, dataZoomId) {
  68643. batch.push(clone(batchItem));
  68644. });
  68645. batch.length && this.api.dispatchAction({
  68646. type: 'dataZoom',
  68647. from: this.uid,
  68648. batch: batch
  68649. });
  68650. };
  68651. function retrieveAxisSetting(option) {
  68652. var setting = {};
  68653. // Compatible with previous setting: null => all axis, false => no axis.
  68654. each$1(['xAxisIndex', 'yAxisIndex'], function (name) {
  68655. setting[name] = option[name];
  68656. setting[name] == null && (setting[name] = 'all');
  68657. (setting[name] === false || setting[name] === 'none') && (setting[name] = []);
  68658. });
  68659. return setting;
  68660. }
  68661. function updateBackBtnStatus(featureModel, ecModel) {
  68662. featureModel.setIconStatus(
  68663. 'back',
  68664. count(ecModel) > 1 ? 'emphasis' : 'normal'
  68665. );
  68666. }
  68667. function updateZoomBtnStatus(featureModel, ecModel, view, payload, api) {
  68668. var zoomActive = view._isZoomActive;
  68669. if (payload && payload.type === 'takeGlobalCursor') {
  68670. zoomActive = payload.key === 'dataZoomSelect'
  68671. ? payload.dataZoomSelectActive : false;
  68672. }
  68673. view._isZoomActive = zoomActive;
  68674. featureModel.setIconStatus('zoom', zoomActive ? 'emphasis' : 'normal');
  68675. var brushTargetManager = new BrushTargetManager(
  68676. retrieveAxisSetting(featureModel.option), ecModel, {include: ['grid']}
  68677. );
  68678. view._brushController
  68679. .setPanels(brushTargetManager.makePanelOpts(api, function (targetInfo) {
  68680. return (targetInfo.xAxisDeclared && !targetInfo.yAxisDeclared)
  68681. ? 'lineX'
  68682. : (!targetInfo.xAxisDeclared && targetInfo.yAxisDeclared)
  68683. ? 'lineY'
  68684. : 'rect';
  68685. }))
  68686. .enableBrush(
  68687. zoomActive
  68688. ? {
  68689. brushType: 'auto',
  68690. brushStyle: {
  68691. // FIXME user customized?
  68692. lineWidth: 0,
  68693. fill: 'rgba(0,0,0,0.2)'
  68694. }
  68695. }
  68696. : false
  68697. );
  68698. }
  68699. register$1('dataZoom', DataZoom);
  68700. // Create special dataZoom option for select
  68701. // FIXME consider the case of merge option, where axes options are not exists.
  68702. registerPreprocessor(function (option) {
  68703. if (!option) {
  68704. return;
  68705. }
  68706. var dataZoomOpts = option.dataZoom || (option.dataZoom = []);
  68707. if (!isArray(dataZoomOpts)) {
  68708. option.dataZoom = dataZoomOpts = [dataZoomOpts];
  68709. }
  68710. var toolboxOpt = option.toolbox;
  68711. if (toolboxOpt) {
  68712. // Assume there is only one toolbox
  68713. if (isArray(toolboxOpt)) {
  68714. toolboxOpt = toolboxOpt[0];
  68715. }
  68716. if (toolboxOpt && toolboxOpt.feature) {
  68717. var dataZoomOpt = toolboxOpt.feature.dataZoom;
  68718. // FIXME: If add dataZoom when setOption in merge mode,
  68719. // no axis info to be added. See `test/dataZoom-extreme.html`
  68720. addForAxis('xAxis', dataZoomOpt);
  68721. addForAxis('yAxis', dataZoomOpt);
  68722. }
  68723. }
  68724. function addForAxis(axisName, dataZoomOpt) {
  68725. if (!dataZoomOpt) {
  68726. return;
  68727. }
  68728. // Try not to modify model, because it is not merged yet.
  68729. var axisIndicesName = axisName + 'Index';
  68730. var givenAxisIndices = dataZoomOpt[axisIndicesName];
  68731. if (givenAxisIndices != null
  68732. && givenAxisIndices !== 'all'
  68733. && !isArray(givenAxisIndices)
  68734. ) {
  68735. givenAxisIndices = (givenAxisIndices === false || givenAxisIndices === 'none') ? [] : [givenAxisIndices];
  68736. }
  68737. forEachComponent(axisName, function (axisOpt, axisIndex) {
  68738. if (givenAxisIndices != null
  68739. && givenAxisIndices !== 'all'
  68740. && indexOf(givenAxisIndices, axisIndex) === -1
  68741. ) {
  68742. return;
  68743. }
  68744. var newOpt = {
  68745. type: 'select',
  68746. $fromToolbox: true,
  68747. // Id for merge mapping.
  68748. id: DATA_ZOOM_ID_BASE + axisName + axisIndex
  68749. };
  68750. // FIXME
  68751. // Only support one axis now.
  68752. newOpt[axisIndicesName] = axisIndex;
  68753. dataZoomOpts.push(newOpt);
  68754. });
  68755. }
  68756. function forEachComponent(mainType, cb) {
  68757. var opts = option[mainType];
  68758. if (!isArray(opts)) {
  68759. opts = opts ? [opts] : [];
  68760. }
  68761. each$16(opts, cb);
  68762. }
  68763. });
  68764. /*
  68765. * Licensed to the Apache Software Foundation (ASF) under one
  68766. * or more contributor license agreements. See the NOTICE file
  68767. * distributed with this work for additional information
  68768. * regarding copyright ownership. The ASF licenses this file
  68769. * to you under the Apache License, Version 2.0 (the
  68770. * "License"); you may not use this file except in compliance
  68771. * with the License. You may obtain a copy of the License at
  68772. *
  68773. * http://www.apache.org/licenses/LICENSE-2.0
  68774. *
  68775. * Unless required by applicable law or agreed to in writing,
  68776. * software distributed under the License is distributed on an
  68777. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  68778. * KIND, either express or implied. See the License for the
  68779. * specific language governing permissions and limitations
  68780. * under the License.
  68781. */
  68782. var restoreLang = lang.toolbox.restore;
  68783. function Restore(model) {
  68784. this.model = model;
  68785. }
  68786. Restore.defaultOption = {
  68787. show: true,
  68788. /* eslint-disable */
  68789. 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',
  68790. /* eslint-enable */
  68791. title: restoreLang.title
  68792. };
  68793. var proto$6 = Restore.prototype;
  68794. proto$6.onclick = function (ecModel, api, type) {
  68795. clear$1(ecModel);
  68796. api.dispatchAction({
  68797. type: 'restore',
  68798. from: this.uid
  68799. });
  68800. };
  68801. register$1('restore', Restore);
  68802. registerAction(
  68803. {type: 'restore', event: 'restore', update: 'prepareAndUpdate'},
  68804. function (payload, ecModel) {
  68805. ecModel.resetOption('recreate');
  68806. }
  68807. );
  68808. /*
  68809. * Licensed to the Apache Software Foundation (ASF) under one
  68810. * or more contributor license agreements. See the NOTICE file
  68811. * distributed with this work for additional information
  68812. * regarding copyright ownership. The ASF licenses this file
  68813. * to you under the Apache License, Version 2.0 (the
  68814. * "License"); you may not use this file except in compliance
  68815. * with the License. You may obtain a copy of the License at
  68816. *
  68817. * http://www.apache.org/licenses/LICENSE-2.0
  68818. *
  68819. * Unless required by applicable law or agreed to in writing,
  68820. * software distributed under the License is distributed on an
  68821. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  68822. * KIND, either express or implied. See the License for the
  68823. * specific language governing permissions and limitations
  68824. * under the License.
  68825. */
  68826. /*
  68827. * Licensed to the Apache Software Foundation (ASF) under one
  68828. * or more contributor license agreements. See the NOTICE file
  68829. * distributed with this work for additional information
  68830. * regarding copyright ownership. The ASF licenses this file
  68831. * to you under the Apache License, Version 2.0 (the
  68832. * "License"); you may not use this file except in compliance
  68833. * with the License. You may obtain a copy of the License at
  68834. *
  68835. * http://www.apache.org/licenses/LICENSE-2.0
  68836. *
  68837. * Unless required by applicable law or agreed to in writing,
  68838. * software distributed under the License is distributed on an
  68839. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  68840. * KIND, either express or implied. See the License for the
  68841. * specific language governing permissions and limitations
  68842. * under the License.
  68843. */
  68844. extendComponentModel({
  68845. type: 'tooltip',
  68846. dependencies: ['axisPointer'],
  68847. defaultOption: {
  68848. zlevel: 0,
  68849. z: 60,
  68850. show: true,
  68851. // tooltip主体内容
  68852. showContent: true,
  68853. // 'trigger' only works on coordinate system.
  68854. // 'item' | 'axis' | 'none'
  68855. trigger: 'item',
  68856. // 'click' | 'mousemove' | 'none'
  68857. triggerOn: 'mousemove|click',
  68858. alwaysShowContent: false,
  68859. displayMode: 'single', // 'single' | 'multipleByCoordSys'
  68860. renderMode: 'auto', // 'auto' | 'html' | 'richText'
  68861. // 'auto': use html by default, and use non-html if `document` is not defined
  68862. // 'html': use html for tooltip
  68863. // 'richText': use canvas, svg, and etc. for tooltip
  68864. // 位置 {Array} | {Function}
  68865. // position: null
  68866. // Consider triggered from axisPointer handle, verticalAlign should be 'middle'
  68867. // align: null,
  68868. // verticalAlign: null,
  68869. // 是否约束 content 在 viewRect 中。默认 false 是为了兼容以前版本。
  68870. confine: false,
  68871. // 内容格式器:{string}(Template) ¦ {Function}
  68872. // formatter: null
  68873. showDelay: 0,
  68874. // 隐藏延迟,单位ms
  68875. hideDelay: 100,
  68876. // 动画变换时间,单位s
  68877. transitionDuration: 0.4,
  68878. enterable: false,
  68879. // 提示背景颜色,默认为透明度为0.7的黑色
  68880. backgroundColor: 'rgba(50,50,50,0.7)',
  68881. // 提示边框颜色
  68882. borderColor: '#333',
  68883. // 提示边框圆角,单位px,默认为4
  68884. borderRadius: 4,
  68885. // 提示边框线宽,单位px,默认为0(无边框)
  68886. borderWidth: 0,
  68887. // 提示内边距,单位px,默认各方向内边距为5,
  68888. // 接受数组分别设定上右下左边距,同css
  68889. padding: 5,
  68890. // Extra css text
  68891. extraCssText: '',
  68892. // 坐标轴指示器,坐标轴触发有效
  68893. axisPointer: {
  68894. // 默认为直线
  68895. // 可选为:'line' | 'shadow' | 'cross'
  68896. type: 'line',
  68897. // type 为 line 的时候有效,指定 tooltip line 所在的轴,可选
  68898. // 可选 'x' | 'y' | 'angle' | 'radius' | 'auto'
  68899. // 默认 'auto',会选择类型为 category 的轴,对于双数值轴,笛卡尔坐标系会默认选择 x 轴
  68900. // 极坐标系会默认选择 angle 轴
  68901. axis: 'auto',
  68902. animation: 'auto',
  68903. animationDurationUpdate: 200,
  68904. animationEasingUpdate: 'exponentialOut',
  68905. crossStyle: {
  68906. color: '#999',
  68907. width: 1,
  68908. type: 'dashed',
  68909. // TODO formatter
  68910. textStyle: {}
  68911. }
  68912. // lineStyle and shadowStyle should not be specified here,
  68913. // otherwise it will always override those styles on option.axisPointer.
  68914. },
  68915. textStyle: {
  68916. color: '#fff',
  68917. fontSize: 14
  68918. }
  68919. }
  68920. });
  68921. /*
  68922. * Licensed to the Apache Software Foundation (ASF) under one
  68923. * or more contributor license agreements. See the NOTICE file
  68924. * distributed with this work for additional information
  68925. * regarding copyright ownership. The ASF licenses this file
  68926. * to you under the Apache License, Version 2.0 (the
  68927. * "License"); you may not use this file except in compliance
  68928. * with the License. You may obtain a copy of the License at
  68929. *
  68930. * http://www.apache.org/licenses/LICENSE-2.0
  68931. *
  68932. * Unless required by applicable law or agreed to in writing,
  68933. * software distributed under the License is distributed on an
  68934. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  68935. * KIND, either express or implied. See the License for the
  68936. * specific language governing permissions and limitations
  68937. * under the License.
  68938. */
  68939. var each$22 = each$1;
  68940. var toCamelCase$1 = toCamelCase;
  68941. var vendors = ['', '-webkit-', '-moz-', '-o-'];
  68942. var gCssText = 'position:absolute;display:block;border-style:solid;white-space:nowrap;z-index:9999999;';
  68943. /**
  68944. * @param {number} duration
  68945. * @return {string}
  68946. * @inner
  68947. */
  68948. function assembleTransition(duration) {
  68949. var transitionCurve = 'cubic-bezier(0.23, 1, 0.32, 1)';
  68950. var transitionText = 'left ' + duration + 's ' + transitionCurve + ','
  68951. + 'top ' + duration + 's ' + transitionCurve;
  68952. return map(vendors, function (vendorPrefix) {
  68953. return vendorPrefix + 'transition:' + transitionText;
  68954. }).join(';');
  68955. }
  68956. /**
  68957. * @param {Object} textStyle
  68958. * @return {string}
  68959. * @inner
  68960. */
  68961. function assembleFont(textStyleModel) {
  68962. var cssText = [];
  68963. var fontSize = textStyleModel.get('fontSize');
  68964. var color = textStyleModel.getTextColor();
  68965. color && cssText.push('color:' + color);
  68966. cssText.push('font:' + textStyleModel.getFont());
  68967. fontSize
  68968. && cssText.push('line-height:' + Math.round(fontSize * 3 / 2) + 'px');
  68969. each$22(['decoration', 'align'], function (name) {
  68970. var val = textStyleModel.get(name);
  68971. val && cssText.push('text-' + name + ':' + val);
  68972. });
  68973. return cssText.join(';');
  68974. }
  68975. /**
  68976. * @param {Object} tooltipModel
  68977. * @return {string}
  68978. * @inner
  68979. */
  68980. function assembleCssText(tooltipModel) {
  68981. var cssText = [];
  68982. var transitionDuration = tooltipModel.get('transitionDuration');
  68983. var backgroundColor = tooltipModel.get('backgroundColor');
  68984. var textStyleModel = tooltipModel.getModel('textStyle');
  68985. var padding = tooltipModel.get('padding');
  68986. // Animation transition. Do not animate when transitionDuration is 0.
  68987. transitionDuration
  68988. && cssText.push(assembleTransition(transitionDuration));
  68989. if (backgroundColor) {
  68990. if (env$1.canvasSupported) {
  68991. cssText.push('background-Color:' + backgroundColor);
  68992. }
  68993. else {
  68994. // for ie
  68995. cssText.push(
  68996. 'background-Color:#' + toHex(backgroundColor)
  68997. );
  68998. cssText.push('filter:alpha(opacity=70)');
  68999. }
  69000. }
  69001. // Border style
  69002. each$22(['width', 'color', 'radius'], function (name) {
  69003. var borderName = 'border-' + name;
  69004. var camelCase = toCamelCase$1(borderName);
  69005. var val = tooltipModel.get(camelCase);
  69006. val != null
  69007. && cssText.push(borderName + ':' + val + (name === 'color' ? '' : 'px'));
  69008. });
  69009. // Text style
  69010. cssText.push(assembleFont(textStyleModel));
  69011. // Padding
  69012. if (padding != null) {
  69013. cssText.push('padding:' + normalizeCssArray$1(padding).join('px ') + 'px');
  69014. }
  69015. return cssText.join(';') + ';';
  69016. }
  69017. /**
  69018. * @alias module:echarts/component/tooltip/TooltipContent
  69019. * @constructor
  69020. */
  69021. function TooltipContent(container, api) {
  69022. if (env$1.wxa) {
  69023. return null;
  69024. }
  69025. var el = document.createElement('div');
  69026. var zr = this._zr = api.getZr();
  69027. this.el = el;
  69028. this._x = api.getWidth() / 2;
  69029. this._y = api.getHeight() / 2;
  69030. container.appendChild(el);
  69031. this._container = container;
  69032. this._show = false;
  69033. /**
  69034. * @private
  69035. */
  69036. this._hideTimeout;
  69037. // FIXME
  69038. // Is it needed to trigger zr event manually if
  69039. // the browser do not support `pointer-events: none`.
  69040. var self = this;
  69041. el.onmouseenter = function () {
  69042. // clear the timeout in hideLater and keep showing tooltip
  69043. if (self._enterable) {
  69044. clearTimeout(self._hideTimeout);
  69045. self._show = true;
  69046. }
  69047. self._inContent = true;
  69048. };
  69049. el.onmousemove = function (e) {
  69050. e = e || window.event;
  69051. if (!self._enterable) {
  69052. // `pointer-events: none` is set to tooltip content div
  69053. // if `enterable` is set as `false`, and `el.onmousemove`
  69054. // can not be triggered. But in browser that do not
  69055. // support `pointer-events`, we need to do this:
  69056. // Try trigger zrender event to avoid mouse
  69057. // in and out shape too frequently
  69058. var handler = zr.handler;
  69059. normalizeEvent(container, e, true);
  69060. handler.dispatch('mousemove', e);
  69061. }
  69062. };
  69063. el.onmouseleave = function () {
  69064. if (self._enterable) {
  69065. if (self._show) {
  69066. self.hideLater(self._hideDelay);
  69067. }
  69068. }
  69069. self._inContent = false;
  69070. };
  69071. }
  69072. TooltipContent.prototype = {
  69073. constructor: TooltipContent,
  69074. /**
  69075. * @private
  69076. * @type {boolean}
  69077. */
  69078. _enterable: true,
  69079. /**
  69080. * Update when tooltip is rendered
  69081. */
  69082. update: function () {
  69083. // FIXME
  69084. // Move this logic to ec main?
  69085. var container = this._container;
  69086. var stl = container.currentStyle
  69087. || document.defaultView.getComputedStyle(container);
  69088. var domStyle = container.style;
  69089. if (domStyle.position !== 'absolute' && stl.position !== 'absolute') {
  69090. domStyle.position = 'relative';
  69091. }
  69092. // Hide the tooltip
  69093. // PENDING
  69094. // this.hide();
  69095. },
  69096. show: function (tooltipModel) {
  69097. clearTimeout(this._hideTimeout);
  69098. var el = this.el;
  69099. el.style.cssText = gCssText + assembleCssText(tooltipModel)
  69100. // Because of the reason described in:
  69101. // http://stackoverflow.com/questions/21125587/css3-transition-not-working-in-chrome-anymore
  69102. // we should set initial value to `left` and `top`.
  69103. + ';left:' + this._x + 'px;top:' + this._y + 'px;'
  69104. + (tooltipModel.get('extraCssText') || '');
  69105. el.style.display = el.innerHTML ? 'block' : 'none';
  69106. // If mouse occsionally move over the tooltip, a mouseout event will be
  69107. // triggered by canvas, and cuase some unexpectable result like dragging
  69108. // stop, "unfocusAdjacency". Here `pointer-events: none` is used to solve
  69109. // it. Although it is not suppored by IE8~IE10, fortunately it is a rare
  69110. // scenario.
  69111. el.style.pointerEvents = this._enterable ? 'auto' : 'none';
  69112. this._show = true;
  69113. },
  69114. setContent: function (content) {
  69115. this.el.innerHTML = content == null ? '' : content;
  69116. },
  69117. setEnterable: function (enterable) {
  69118. this._enterable = enterable;
  69119. },
  69120. getSize: function () {
  69121. var el = this.el;
  69122. return [el.clientWidth, el.clientHeight];
  69123. },
  69124. moveTo: function (x, y) {
  69125. // xy should be based on canvas root. But tooltipContent is
  69126. // the sibling of canvas root. So padding of ec container
  69127. // should be considered here.
  69128. var zr = this._zr;
  69129. var viewportRootOffset;
  69130. if (zr && zr.painter && (viewportRootOffset = zr.painter.getViewportRootOffset())) {
  69131. x += viewportRootOffset.offsetLeft;
  69132. y += viewportRootOffset.offsetTop;
  69133. }
  69134. var style = this.el.style;
  69135. style.left = x + 'px';
  69136. style.top = y + 'px';
  69137. this._x = x;
  69138. this._y = y;
  69139. },
  69140. hide: function () {
  69141. this.el.style.display = 'none';
  69142. this._show = false;
  69143. },
  69144. hideLater: function (time) {
  69145. if (this._show && !(this._inContent && this._enterable)) {
  69146. if (time) {
  69147. this._hideDelay = time;
  69148. // Set show false to avoid invoke hideLater mutiple times
  69149. this._show = false;
  69150. this._hideTimeout = setTimeout(bind(this.hide, this), time);
  69151. }
  69152. else {
  69153. this.hide();
  69154. }
  69155. }
  69156. },
  69157. isShow: function () {
  69158. return this._show;
  69159. },
  69160. getOuterSize: function () {
  69161. var width = this.el.clientWidth;
  69162. var height = this.el.clientHeight;
  69163. // Consider browser compatibility.
  69164. // IE8 does not support getComputedStyle.
  69165. if (document.defaultView && document.defaultView.getComputedStyle) {
  69166. var stl = document.defaultView.getComputedStyle(this.el);
  69167. if (stl) {
  69168. width += parseInt(stl.borderLeftWidth, 10) + parseInt(stl.borderRightWidth, 10);
  69169. height += parseInt(stl.borderTopWidth, 10) + parseInt(stl.borderBottomWidth, 10);
  69170. }
  69171. }
  69172. return {width: width, height: height};
  69173. }
  69174. };
  69175. /*
  69176. * Licensed to the Apache Software Foundation (ASF) under one
  69177. * or more contributor license agreements. See the NOTICE file
  69178. * distributed with this work for additional information
  69179. * regarding copyright ownership. The ASF licenses this file
  69180. * to you under the Apache License, Version 2.0 (the
  69181. * "License"); you may not use this file except in compliance
  69182. * with the License. You may obtain a copy of the License at
  69183. *
  69184. * http://www.apache.org/licenses/LICENSE-2.0
  69185. *
  69186. * Unless required by applicable law or agreed to in writing,
  69187. * software distributed under the License is distributed on an
  69188. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  69189. * KIND, either express or implied. See the License for the
  69190. * specific language governing permissions and limitations
  69191. * under the License.
  69192. */
  69193. // import Group from 'zrender/src/container/Group';
  69194. /**
  69195. * @alias module:echarts/component/tooltip/TooltipRichContent
  69196. * @constructor
  69197. */
  69198. function TooltipRichContent(api) {
  69199. this._zr = api.getZr();
  69200. this._show = false;
  69201. /**
  69202. * @private
  69203. */
  69204. this._hideTimeout;
  69205. }
  69206. TooltipRichContent.prototype = {
  69207. constructor: TooltipRichContent,
  69208. /**
  69209. * @private
  69210. * @type {boolean}
  69211. */
  69212. _enterable: true,
  69213. /**
  69214. * Update when tooltip is rendered
  69215. */
  69216. update: function () {
  69217. // noop
  69218. },
  69219. show: function (tooltipModel) {
  69220. if (this._hideTimeout) {
  69221. clearTimeout(this._hideTimeout);
  69222. }
  69223. this.el.attr('show', true);
  69224. this._show = true;
  69225. },
  69226. /**
  69227. * Set tooltip content
  69228. *
  69229. * @param {string} content rich text string of content
  69230. * @param {Object} markerRich rich text style
  69231. * @param {Object} tooltipModel tooltip model
  69232. */
  69233. setContent: function (content, markerRich, tooltipModel) {
  69234. if (this.el) {
  69235. this._zr.remove(this.el);
  69236. }
  69237. var markers = {};
  69238. var text = content;
  69239. var prefix = '{marker';
  69240. var suffix = '|}';
  69241. var startId = text.indexOf(prefix);
  69242. while (startId >= 0) {
  69243. var endId = text.indexOf(suffix);
  69244. var name = text.substr(startId + prefix.length, endId - startId - prefix.length);
  69245. if (name.indexOf('sub') > -1) {
  69246. markers['marker' + name] = {
  69247. textWidth: 4,
  69248. textHeight: 4,
  69249. textBorderRadius: 2,
  69250. textBackgroundColor: markerRich[name],
  69251. // TODO: textOffset is not implemented for rich text
  69252. textOffset: [3, 0]
  69253. };
  69254. }
  69255. else {
  69256. markers['marker' + name] = {
  69257. textWidth: 10,
  69258. textHeight: 10,
  69259. textBorderRadius: 5,
  69260. textBackgroundColor: markerRich[name]
  69261. };
  69262. }
  69263. text = text.substr(endId + 1);
  69264. startId = text.indexOf('{marker');
  69265. }
  69266. this.el = new Text({
  69267. style: {
  69268. rich: markers,
  69269. text: content,
  69270. textLineHeight: 20,
  69271. textBackgroundColor: tooltipModel.get('backgroundColor'),
  69272. textBorderRadius: tooltipModel.get('borderRadius'),
  69273. textFill: tooltipModel.get('textStyle.color'),
  69274. textPadding: tooltipModel.get('padding')
  69275. },
  69276. z: tooltipModel.get('z')
  69277. });
  69278. this._zr.add(this.el);
  69279. var self = this;
  69280. this.el.on('mouseover', function () {
  69281. // clear the timeout in hideLater and keep showing tooltip
  69282. if (self._enterable) {
  69283. clearTimeout(self._hideTimeout);
  69284. self._show = true;
  69285. }
  69286. self._inContent = true;
  69287. });
  69288. this.el.on('mouseout', function () {
  69289. if (self._enterable) {
  69290. if (self._show) {
  69291. self.hideLater(self._hideDelay);
  69292. }
  69293. }
  69294. self._inContent = false;
  69295. });
  69296. },
  69297. setEnterable: function (enterable) {
  69298. this._enterable = enterable;
  69299. },
  69300. getSize: function () {
  69301. var bounding = this.el.getBoundingRect();
  69302. return [bounding.width, bounding.height];
  69303. },
  69304. moveTo: function (x, y) {
  69305. if (this.el) {
  69306. this.el.attr('position', [x, y]);
  69307. }
  69308. },
  69309. hide: function () {
  69310. if (this.el) {
  69311. this.el.hide();
  69312. }
  69313. this._show = false;
  69314. },
  69315. hideLater: function (time) {
  69316. if (this._show && !(this._inContent && this._enterable)) {
  69317. if (time) {
  69318. this._hideDelay = time;
  69319. // Set show false to avoid invoke hideLater mutiple times
  69320. this._show = false;
  69321. this._hideTimeout = setTimeout(bind(this.hide, this), time);
  69322. }
  69323. else {
  69324. this.hide();
  69325. }
  69326. }
  69327. },
  69328. isShow: function () {
  69329. return this._show;
  69330. },
  69331. getOuterSize: function () {
  69332. var size = this.getSize();
  69333. return {
  69334. width: size[0],
  69335. height: size[1]
  69336. };
  69337. }
  69338. };
  69339. /*
  69340. * Licensed to the Apache Software Foundation (ASF) under one
  69341. * or more contributor license agreements. See the NOTICE file
  69342. * distributed with this work for additional information
  69343. * regarding copyright ownership. The ASF licenses this file
  69344. * to you under the Apache License, Version 2.0 (the
  69345. * "License"); you may not use this file except in compliance
  69346. * with the License. You may obtain a copy of the License at
  69347. *
  69348. * http://www.apache.org/licenses/LICENSE-2.0
  69349. *
  69350. * Unless required by applicable law or agreed to in writing,
  69351. * software distributed under the License is distributed on an
  69352. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  69353. * KIND, either express or implied. See the License for the
  69354. * specific language governing permissions and limitations
  69355. * under the License.
  69356. */
  69357. var bind$3 = bind;
  69358. var each$21 = each$1;
  69359. var parsePercent$2 = parsePercent$1;
  69360. var proxyRect = new Rect({
  69361. shape: {x: -1, y: -1, width: 2, height: 2}
  69362. });
  69363. extendComponentView({
  69364. type: 'tooltip',
  69365. init: function (ecModel, api) {
  69366. if (env$1.node) {
  69367. return;
  69368. }
  69369. var tooltipModel = ecModel.getComponent('tooltip');
  69370. var renderMode = tooltipModel.get('renderMode');
  69371. this._renderMode = getTooltipRenderMode(renderMode);
  69372. var tooltipContent;
  69373. if (this._renderMode === 'html') {
  69374. tooltipContent = new TooltipContent(api.getDom(), api);
  69375. this._newLine = '<br/>';
  69376. }
  69377. else {
  69378. tooltipContent = new TooltipRichContent(api);
  69379. this._newLine = '\n';
  69380. }
  69381. this._tooltipContent = tooltipContent;
  69382. },
  69383. render: function (tooltipModel, ecModel, api) {
  69384. if (env$1.node) {
  69385. return;
  69386. }
  69387. // Reset
  69388. this.group.removeAll();
  69389. /**
  69390. * @private
  69391. * @type {module:echarts/component/tooltip/TooltipModel}
  69392. */
  69393. this._tooltipModel = tooltipModel;
  69394. /**
  69395. * @private
  69396. * @type {module:echarts/model/Global}
  69397. */
  69398. this._ecModel = ecModel;
  69399. /**
  69400. * @private
  69401. * @type {module:echarts/ExtensionAPI}
  69402. */
  69403. this._api = api;
  69404. /**
  69405. * Should be cleaned when render.
  69406. * @private
  69407. * @type {Array.<Array.<Object>>}
  69408. */
  69409. this._lastDataByCoordSys = null;
  69410. /**
  69411. * @private
  69412. * @type {boolean}
  69413. */
  69414. this._alwaysShowContent = tooltipModel.get('alwaysShowContent');
  69415. var tooltipContent = this._tooltipContent;
  69416. tooltipContent.update();
  69417. tooltipContent.setEnterable(tooltipModel.get('enterable'));
  69418. this._initGlobalListener();
  69419. this._keepShow();
  69420. },
  69421. _initGlobalListener: function () {
  69422. var tooltipModel = this._tooltipModel;
  69423. var triggerOn = tooltipModel.get('triggerOn');
  69424. register(
  69425. 'itemTooltip',
  69426. this._api,
  69427. bind$3(function (currTrigger, e, dispatchAction) {
  69428. // If 'none', it is not controlled by mouse totally.
  69429. if (triggerOn !== 'none') {
  69430. if (triggerOn.indexOf(currTrigger) >= 0) {
  69431. this._tryShow(e, dispatchAction);
  69432. }
  69433. else if (currTrigger === 'leave') {
  69434. this._hide(dispatchAction);
  69435. }
  69436. }
  69437. }, this)
  69438. );
  69439. },
  69440. _keepShow: function () {
  69441. var tooltipModel = this._tooltipModel;
  69442. var ecModel = this._ecModel;
  69443. var api = this._api;
  69444. // Try to keep the tooltip show when refreshing
  69445. if (this._lastX != null
  69446. && this._lastY != null
  69447. // When user is willing to control tooltip totally using API,
  69448. // self.manuallyShowTip({x, y}) might cause tooltip hide,
  69449. // which is not expected.
  69450. && tooltipModel.get('triggerOn') !== 'none'
  69451. ) {
  69452. var self = this;
  69453. clearTimeout(this._refreshUpdateTimeout);
  69454. this._refreshUpdateTimeout = setTimeout(function () {
  69455. // Show tip next tick after other charts are rendered
  69456. // In case highlight action has wrong result
  69457. // FIXME
  69458. !api.isDisposed() && self.manuallyShowTip(tooltipModel, ecModel, api, {
  69459. x: self._lastX,
  69460. y: self._lastY
  69461. });
  69462. });
  69463. }
  69464. },
  69465. /**
  69466. * Show tip manually by
  69467. * dispatchAction({
  69468. * type: 'showTip',
  69469. * x: 10,
  69470. * y: 10
  69471. * });
  69472. * Or
  69473. * dispatchAction({
  69474. * type: 'showTip',
  69475. * seriesIndex: 0,
  69476. * dataIndex or dataIndexInside or name
  69477. * });
  69478. *
  69479. * TODO Batch
  69480. */
  69481. manuallyShowTip: function (tooltipModel, ecModel, api, payload) {
  69482. if (payload.from === this.uid || env$1.node) {
  69483. return;
  69484. }
  69485. var dispatchAction = makeDispatchAction$1(payload, api);
  69486. // Reset ticket
  69487. this._ticket = '';
  69488. // When triggered from axisPointer.
  69489. var dataByCoordSys = payload.dataByCoordSys;
  69490. if (payload.tooltip && payload.x != null && payload.y != null) {
  69491. var el = proxyRect;
  69492. el.position = [payload.x, payload.y];
  69493. el.update();
  69494. el.tooltip = payload.tooltip;
  69495. // Manually show tooltip while view is not using zrender elements.
  69496. this._tryShow({
  69497. offsetX: payload.x,
  69498. offsetY: payload.y,
  69499. target: el
  69500. }, dispatchAction);
  69501. }
  69502. else if (dataByCoordSys) {
  69503. this._tryShow({
  69504. offsetX: payload.x,
  69505. offsetY: payload.y,
  69506. position: payload.position,
  69507. event: {},
  69508. dataByCoordSys: payload.dataByCoordSys,
  69509. tooltipOption: payload.tooltipOption
  69510. }, dispatchAction);
  69511. }
  69512. else if (payload.seriesIndex != null) {
  69513. if (this._manuallyAxisShowTip(tooltipModel, ecModel, api, payload)) {
  69514. return;
  69515. }
  69516. var pointInfo = findPointFromSeries(payload, ecModel);
  69517. var cx = pointInfo.point[0];
  69518. var cy = pointInfo.point[1];
  69519. if (cx != null && cy != null) {
  69520. this._tryShow({
  69521. offsetX: cx,
  69522. offsetY: cy,
  69523. position: payload.position,
  69524. target: pointInfo.el,
  69525. event: {}
  69526. }, dispatchAction);
  69527. }
  69528. }
  69529. else if (payload.x != null && payload.y != null) {
  69530. // FIXME
  69531. // should wrap dispatchAction like `axisPointer/globalListener` ?
  69532. api.dispatchAction({
  69533. type: 'updateAxisPointer',
  69534. x: payload.x,
  69535. y: payload.y
  69536. });
  69537. this._tryShow({
  69538. offsetX: payload.x,
  69539. offsetY: payload.y,
  69540. position: payload.position,
  69541. target: api.getZr().findHover(payload.x, payload.y).target,
  69542. event: {}
  69543. }, dispatchAction);
  69544. }
  69545. },
  69546. manuallyHideTip: function (tooltipModel, ecModel, api, payload) {
  69547. var tooltipContent = this._tooltipContent;
  69548. if (!this._alwaysShowContent && this._tooltipModel) {
  69549. tooltipContent.hideLater(this._tooltipModel.get('hideDelay'));
  69550. }
  69551. this._lastX = this._lastY = null;
  69552. if (payload.from !== this.uid) {
  69553. this._hide(makeDispatchAction$1(payload, api));
  69554. }
  69555. },
  69556. // Be compatible with previous design, that is, when tooltip.type is 'axis' and
  69557. // dispatchAction 'showTip' with seriesIndex and dataIndex will trigger axis pointer
  69558. // and tooltip.
  69559. _manuallyAxisShowTip: function (tooltipModel, ecModel, api, payload) {
  69560. var seriesIndex = payload.seriesIndex;
  69561. var dataIndex = payload.dataIndex;
  69562. var coordSysAxesInfo = ecModel.getComponent('axisPointer').coordSysAxesInfo;
  69563. if (seriesIndex == null || dataIndex == null || coordSysAxesInfo == null) {
  69564. return;
  69565. }
  69566. var seriesModel = ecModel.getSeriesByIndex(seriesIndex);
  69567. if (!seriesModel) {
  69568. return;
  69569. }
  69570. var data = seriesModel.getData();
  69571. var tooltipModel = buildTooltipModel([
  69572. data.getItemModel(dataIndex),
  69573. seriesModel,
  69574. (seriesModel.coordinateSystem || {}).model,
  69575. tooltipModel
  69576. ]);
  69577. if (tooltipModel.get('trigger') !== 'axis') {
  69578. return;
  69579. }
  69580. api.dispatchAction({
  69581. type: 'updateAxisPointer',
  69582. seriesIndex: seriesIndex,
  69583. dataIndex: dataIndex,
  69584. position: payload.position
  69585. });
  69586. return true;
  69587. },
  69588. _tryShow: function (e, dispatchAction) {
  69589. var el = e.target;
  69590. var tooltipModel = this._tooltipModel;
  69591. if (!tooltipModel) {
  69592. return;
  69593. }
  69594. // Save mouse x, mouse y. So we can try to keep showing the tip if chart is refreshed
  69595. this._lastX = e.offsetX;
  69596. this._lastY = e.offsetY;
  69597. var dataByCoordSys = e.dataByCoordSys;
  69598. if (dataByCoordSys && dataByCoordSys.length) {
  69599. this._showAxisTooltip(dataByCoordSys, e);
  69600. }
  69601. // Always show item tooltip if mouse is on the element with dataIndex
  69602. else if (el && el.dataIndex != null) {
  69603. this._lastDataByCoordSys = null;
  69604. this._showSeriesItemTooltip(e, el, dispatchAction);
  69605. }
  69606. // Tooltip provided directly. Like legend.
  69607. else if (el && el.tooltip) {
  69608. this._lastDataByCoordSys = null;
  69609. this._showComponentItemTooltip(e, el, dispatchAction);
  69610. }
  69611. else {
  69612. this._lastDataByCoordSys = null;
  69613. this._hide(dispatchAction);
  69614. }
  69615. },
  69616. _showOrMove: function (tooltipModel, cb) {
  69617. // showDelay is used in this case: tooltip.enterable is set
  69618. // as true. User intent to move mouse into tooltip and click
  69619. // something. `showDelay` makes it easyer to enter the content
  69620. // but tooltip do not move immediately.
  69621. var delay = tooltipModel.get('showDelay');
  69622. cb = bind(cb, this);
  69623. clearTimeout(this._showTimout);
  69624. delay > 0
  69625. ? (this._showTimout = setTimeout(cb, delay))
  69626. : cb();
  69627. },
  69628. _showAxisTooltip: function (dataByCoordSys, e) {
  69629. var ecModel = this._ecModel;
  69630. var globalTooltipModel = this._tooltipModel;
  69631. var point = [e.offsetX, e.offsetY];
  69632. var singleDefaultHTML = [];
  69633. var singleParamsList = [];
  69634. var singleTooltipModel = buildTooltipModel([
  69635. e.tooltipOption,
  69636. globalTooltipModel
  69637. ]);
  69638. var renderMode = this._renderMode;
  69639. var newLine = this._newLine;
  69640. var markers = {};
  69641. each$21(dataByCoordSys, function (itemCoordSys) {
  69642. // var coordParamList = [];
  69643. // var coordDefaultHTML = [];
  69644. // var coordTooltipModel = buildTooltipModel([
  69645. // e.tooltipOption,
  69646. // itemCoordSys.tooltipOption,
  69647. // ecModel.getComponent(itemCoordSys.coordSysMainType, itemCoordSys.coordSysIndex),
  69648. // globalTooltipModel
  69649. // ]);
  69650. // var displayMode = coordTooltipModel.get('displayMode');
  69651. // var paramsList = displayMode === 'single' ? singleParamsList : [];
  69652. each$21(itemCoordSys.dataByAxis, function (item) {
  69653. var axisModel = ecModel.getComponent(item.axisDim + 'Axis', item.axisIndex);
  69654. var axisValue = item.value;
  69655. var seriesDefaultHTML = [];
  69656. if (!axisModel || axisValue == null) {
  69657. return;
  69658. }
  69659. var valueLabel = getValueLabel(
  69660. axisValue, axisModel.axis, ecModel,
  69661. item.seriesDataIndices,
  69662. item.valueLabelOpt
  69663. );
  69664. each$1(item.seriesDataIndices, function (idxItem) {
  69665. var series = ecModel.getSeriesByIndex(idxItem.seriesIndex);
  69666. var dataIndex = idxItem.dataIndexInside;
  69667. var dataParams = series && series.getDataParams(dataIndex);
  69668. dataParams.axisDim = item.axisDim;
  69669. dataParams.axisIndex = item.axisIndex;
  69670. dataParams.axisType = item.axisType;
  69671. dataParams.axisId = item.axisId;
  69672. dataParams.axisValue = getAxisRawValue(axisModel.axis, axisValue);
  69673. dataParams.axisValueLabel = valueLabel;
  69674. if (dataParams) {
  69675. singleParamsList.push(dataParams);
  69676. var seriesTooltip = series.formatTooltip(dataIndex, true, null, renderMode);
  69677. var html;
  69678. if (isObject$1(seriesTooltip)) {
  69679. html = seriesTooltip.html;
  69680. var newMarkers = seriesTooltip.markers;
  69681. merge(markers, newMarkers);
  69682. }
  69683. else {
  69684. html = seriesTooltip;
  69685. }
  69686. seriesDefaultHTML.push(html);
  69687. }
  69688. });
  69689. // Default tooltip content
  69690. // FIXME
  69691. // (1) shold be the first data which has name?
  69692. // (2) themeRiver, firstDataIndex is array, and first line is unnecessary.
  69693. var firstLine = valueLabel;
  69694. if (renderMode !== 'html') {
  69695. singleDefaultHTML.push(seriesDefaultHTML.join(newLine));
  69696. }
  69697. else {
  69698. singleDefaultHTML.push(
  69699. (firstLine ? encodeHTML(firstLine) + newLine : '')
  69700. + seriesDefaultHTML.join(newLine)
  69701. );
  69702. }
  69703. });
  69704. }, this);
  69705. // In most case, the second axis is shown upper than the first one.
  69706. singleDefaultHTML.reverse();
  69707. singleDefaultHTML = singleDefaultHTML.join(this._newLine + this._newLine);
  69708. var positionExpr = e.position;
  69709. this._showOrMove(singleTooltipModel, function () {
  69710. if (this._updateContentNotChangedOnAxis(dataByCoordSys)) {
  69711. this._updatePosition(
  69712. singleTooltipModel,
  69713. positionExpr,
  69714. point[0], point[1],
  69715. this._tooltipContent,
  69716. singleParamsList
  69717. );
  69718. }
  69719. else {
  69720. this._showTooltipContent(
  69721. singleTooltipModel, singleDefaultHTML, singleParamsList, Math.random(),
  69722. point[0], point[1], positionExpr, undefined, markers
  69723. );
  69724. }
  69725. });
  69726. // Do not trigger events here, because this branch only be entered
  69727. // from dispatchAction.
  69728. },
  69729. _showSeriesItemTooltip: function (e, el, dispatchAction) {
  69730. var ecModel = this._ecModel;
  69731. // Use dataModel in element if possible
  69732. // Used when mouseover on a element like markPoint or edge
  69733. // In which case, the data is not main data in series.
  69734. var seriesIndex = el.seriesIndex;
  69735. var seriesModel = ecModel.getSeriesByIndex(seriesIndex);
  69736. // For example, graph link.
  69737. var dataModel = el.dataModel || seriesModel;
  69738. var dataIndex = el.dataIndex;
  69739. var dataType = el.dataType;
  69740. var data = dataModel.getData();
  69741. var tooltipModel = buildTooltipModel([
  69742. data.getItemModel(dataIndex),
  69743. dataModel,
  69744. seriesModel && (seriesModel.coordinateSystem || {}).model,
  69745. this._tooltipModel
  69746. ]);
  69747. var tooltipTrigger = tooltipModel.get('trigger');
  69748. if (tooltipTrigger != null && tooltipTrigger !== 'item') {
  69749. return;
  69750. }
  69751. var params = dataModel.getDataParams(dataIndex, dataType);
  69752. var seriesTooltip = dataModel.formatTooltip(dataIndex, false, dataType, this._renderMode);
  69753. var defaultHtml;
  69754. var markers;
  69755. if (isObject$1(seriesTooltip)) {
  69756. defaultHtml = seriesTooltip.html;
  69757. markers = seriesTooltip.markers;
  69758. }
  69759. else {
  69760. defaultHtml = seriesTooltip;
  69761. markers = null;
  69762. }
  69763. var asyncTicket = 'item_' + dataModel.name + '_' + dataIndex;
  69764. this._showOrMove(tooltipModel, function () {
  69765. this._showTooltipContent(
  69766. tooltipModel, defaultHtml, params, asyncTicket,
  69767. e.offsetX, e.offsetY, e.position, e.target, markers
  69768. );
  69769. });
  69770. // FIXME
  69771. // duplicated showtip if manuallyShowTip is called from dispatchAction.
  69772. dispatchAction({
  69773. type: 'showTip',
  69774. dataIndexInside: dataIndex,
  69775. dataIndex: data.getRawIndex(dataIndex),
  69776. seriesIndex: seriesIndex,
  69777. from: this.uid
  69778. });
  69779. },
  69780. _showComponentItemTooltip: function (e, el, dispatchAction) {
  69781. var tooltipOpt = el.tooltip;
  69782. if (typeof tooltipOpt === 'string') {
  69783. var content = tooltipOpt;
  69784. tooltipOpt = {
  69785. content: content,
  69786. // Fixed formatter
  69787. formatter: content
  69788. };
  69789. }
  69790. var subTooltipModel = new Model(tooltipOpt, this._tooltipModel, this._ecModel);
  69791. var defaultHtml = subTooltipModel.get('content');
  69792. var asyncTicket = Math.random();
  69793. // Do not check whether `trigger` is 'none' here, because `trigger`
  69794. // only works on cooridinate system. In fact, we have not found case
  69795. // that requires setting `trigger` nothing on component yet.
  69796. this._showOrMove(subTooltipModel, function () {
  69797. this._showTooltipContent(
  69798. subTooltipModel, defaultHtml, subTooltipModel.get('formatterParams') || {},
  69799. asyncTicket, e.offsetX, e.offsetY, e.position, el
  69800. );
  69801. });
  69802. // If not dispatch showTip, tip may be hide triggered by axis.
  69803. dispatchAction({
  69804. type: 'showTip',
  69805. from: this.uid
  69806. });
  69807. },
  69808. _showTooltipContent: function (
  69809. tooltipModel, defaultHtml, params, asyncTicket, x, y, positionExpr, el, markers
  69810. ) {
  69811. // Reset ticket
  69812. this._ticket = '';
  69813. if (!tooltipModel.get('showContent') || !tooltipModel.get('show')) {
  69814. return;
  69815. }
  69816. var tooltipContent = this._tooltipContent;
  69817. var formatter = tooltipModel.get('formatter');
  69818. positionExpr = positionExpr || tooltipModel.get('position');
  69819. var html = defaultHtml;
  69820. if (formatter && typeof formatter === 'string') {
  69821. html = formatTpl(formatter, params, true);
  69822. }
  69823. else if (typeof formatter === 'function') {
  69824. var callback = bind$3(function (cbTicket, html) {
  69825. if (cbTicket === this._ticket) {
  69826. tooltipContent.setContent(html, markers, tooltipModel);
  69827. this._updatePosition(
  69828. tooltipModel, positionExpr, x, y, tooltipContent, params, el
  69829. );
  69830. }
  69831. }, this);
  69832. this._ticket = asyncTicket;
  69833. html = formatter(params, asyncTicket, callback);
  69834. }
  69835. tooltipContent.setContent(html, markers, tooltipModel);
  69836. tooltipContent.show(tooltipModel);
  69837. this._updatePosition(
  69838. tooltipModel, positionExpr, x, y, tooltipContent, params, el
  69839. );
  69840. },
  69841. /**
  69842. * @param {string|Function|Array.<number>|Object} positionExpr
  69843. * @param {number} x Mouse x
  69844. * @param {number} y Mouse y
  69845. * @param {boolean} confine Whether confine tooltip content in view rect.
  69846. * @param {Object|<Array.<Object>} params
  69847. * @param {module:zrender/Element} el target element
  69848. * @param {module:echarts/ExtensionAPI} api
  69849. * @return {Array.<number>}
  69850. */
  69851. _updatePosition: function (tooltipModel, positionExpr, x, y, content, params, el) {
  69852. var viewWidth = this._api.getWidth();
  69853. var viewHeight = this._api.getHeight();
  69854. positionExpr = positionExpr || tooltipModel.get('position');
  69855. var contentSize = content.getSize();
  69856. var align = tooltipModel.get('align');
  69857. var vAlign = tooltipModel.get('verticalAlign');
  69858. var rect = el && el.getBoundingRect().clone();
  69859. el && rect.applyTransform(el.transform);
  69860. if (typeof positionExpr === 'function') {
  69861. // Callback of position can be an array or a string specify the position
  69862. positionExpr = positionExpr([x, y], params, content.el, rect, {
  69863. viewSize: [viewWidth, viewHeight],
  69864. contentSize: contentSize.slice()
  69865. });
  69866. }
  69867. if (isArray(positionExpr)) {
  69868. x = parsePercent$2(positionExpr[0], viewWidth);
  69869. y = parsePercent$2(positionExpr[1], viewHeight);
  69870. }
  69871. else if (isObject$1(positionExpr)) {
  69872. positionExpr.width = contentSize[0];
  69873. positionExpr.height = contentSize[1];
  69874. var layoutRect = getLayoutRect(
  69875. positionExpr, {width: viewWidth, height: viewHeight}
  69876. );
  69877. x = layoutRect.x;
  69878. y = layoutRect.y;
  69879. align = null;
  69880. // When positionExpr is left/top/right/bottom,
  69881. // align and verticalAlign will not work.
  69882. vAlign = null;
  69883. }
  69884. // Specify tooltip position by string 'top' 'bottom' 'left' 'right' around graphic element
  69885. else if (typeof positionExpr === 'string' && el) {
  69886. var pos = calcTooltipPosition(
  69887. positionExpr, rect, contentSize
  69888. );
  69889. x = pos[0];
  69890. y = pos[1];
  69891. }
  69892. else {
  69893. var pos = refixTooltipPosition(
  69894. x, y, content, viewWidth, viewHeight, align ? null : 20, vAlign ? null : 20
  69895. );
  69896. x = pos[0];
  69897. y = pos[1];
  69898. }
  69899. align && (x -= isCenterAlign(align) ? contentSize[0] / 2 : align === 'right' ? contentSize[0] : 0);
  69900. vAlign && (y -= isCenterAlign(vAlign) ? contentSize[1] / 2 : vAlign === 'bottom' ? contentSize[1] : 0);
  69901. if (tooltipModel.get('confine')) {
  69902. var pos = confineTooltipPosition(
  69903. x, y, content, viewWidth, viewHeight
  69904. );
  69905. x = pos[0];
  69906. y = pos[1];
  69907. }
  69908. content.moveTo(x, y);
  69909. },
  69910. // FIXME
  69911. // Should we remove this but leave this to user?
  69912. _updateContentNotChangedOnAxis: function (dataByCoordSys) {
  69913. var lastCoordSys = this._lastDataByCoordSys;
  69914. var contentNotChanged = !!lastCoordSys
  69915. && lastCoordSys.length === dataByCoordSys.length;
  69916. contentNotChanged && each$21(lastCoordSys, function (lastItemCoordSys, indexCoordSys) {
  69917. var lastDataByAxis = lastItemCoordSys.dataByAxis || {};
  69918. var thisItemCoordSys = dataByCoordSys[indexCoordSys] || {};
  69919. var thisDataByAxis = thisItemCoordSys.dataByAxis || [];
  69920. contentNotChanged &= lastDataByAxis.length === thisDataByAxis.length;
  69921. contentNotChanged && each$21(lastDataByAxis, function (lastItem, indexAxis) {
  69922. var thisItem = thisDataByAxis[indexAxis] || {};
  69923. var lastIndices = lastItem.seriesDataIndices || [];
  69924. var newIndices = thisItem.seriesDataIndices || [];
  69925. contentNotChanged
  69926. &= lastItem.value === thisItem.value
  69927. && lastItem.axisType === thisItem.axisType
  69928. && lastItem.axisId === thisItem.axisId
  69929. && lastIndices.length === newIndices.length;
  69930. contentNotChanged && each$21(lastIndices, function (lastIdxItem, j) {
  69931. var newIdxItem = newIndices[j];
  69932. contentNotChanged
  69933. &= lastIdxItem.seriesIndex === newIdxItem.seriesIndex
  69934. && lastIdxItem.dataIndex === newIdxItem.dataIndex;
  69935. });
  69936. });
  69937. });
  69938. this._lastDataByCoordSys = dataByCoordSys;
  69939. return !!contentNotChanged;
  69940. },
  69941. _hide: function (dispatchAction) {
  69942. // Do not directly hideLater here, because this behavior may be prevented
  69943. // in dispatchAction when showTip is dispatched.
  69944. // FIXME
  69945. // duplicated hideTip if manuallyHideTip is called from dispatchAction.
  69946. this._lastDataByCoordSys = null;
  69947. dispatchAction({
  69948. type: 'hideTip',
  69949. from: this.uid
  69950. });
  69951. },
  69952. dispose: function (ecModel, api) {
  69953. if (env$1.node) {
  69954. return;
  69955. }
  69956. this._tooltipContent.hide();
  69957. unregister('itemTooltip', api);
  69958. }
  69959. });
  69960. /**
  69961. * @param {Array.<Object|module:echarts/model/Model>} modelCascade
  69962. * From top to bottom. (the last one should be globalTooltipModel);
  69963. */
  69964. function buildTooltipModel(modelCascade) {
  69965. var resultModel = modelCascade.pop();
  69966. while (modelCascade.length) {
  69967. var tooltipOpt = modelCascade.pop();
  69968. if (tooltipOpt) {
  69969. if (Model.isInstance(tooltipOpt)) {
  69970. tooltipOpt = tooltipOpt.get('tooltip', true);
  69971. }
  69972. // In each data item tooltip can be simply write:
  69973. // {
  69974. // value: 10,
  69975. // tooltip: 'Something you need to know'
  69976. // }
  69977. if (typeof tooltipOpt === 'string') {
  69978. tooltipOpt = {formatter: tooltipOpt};
  69979. }
  69980. resultModel = new Model(tooltipOpt, resultModel, resultModel.ecModel);
  69981. }
  69982. }
  69983. return resultModel;
  69984. }
  69985. function makeDispatchAction$1(payload, api) {
  69986. return payload.dispatchAction || bind(api.dispatchAction, api);
  69987. }
  69988. function refixTooltipPosition(x, y, content, viewWidth, viewHeight, gapH, gapV) {
  69989. var size = content.getOuterSize();
  69990. var width = size.width;
  69991. var height = size.height;
  69992. if (gapH != null) {
  69993. if (x + width + gapH > viewWidth) {
  69994. x -= width + gapH;
  69995. }
  69996. else {
  69997. x += gapH;
  69998. }
  69999. }
  70000. if (gapV != null) {
  70001. if (y + height + gapV > viewHeight) {
  70002. y -= height + gapV;
  70003. }
  70004. else {
  70005. y += gapV;
  70006. }
  70007. }
  70008. return [x, y];
  70009. }
  70010. function confineTooltipPosition(x, y, content, viewWidth, viewHeight) {
  70011. var size = content.getOuterSize();
  70012. var width = size.width;
  70013. var height = size.height;
  70014. x = Math.min(x + width, viewWidth) - width;
  70015. y = Math.min(y + height, viewHeight) - height;
  70016. x = Math.max(x, 0);
  70017. y = Math.max(y, 0);
  70018. return [x, y];
  70019. }
  70020. function calcTooltipPosition(position, rect, contentSize) {
  70021. var domWidth = contentSize[0];
  70022. var domHeight = contentSize[1];
  70023. var gap = 5;
  70024. var x = 0;
  70025. var y = 0;
  70026. var rectWidth = rect.width;
  70027. var rectHeight = rect.height;
  70028. switch (position) {
  70029. case 'inside':
  70030. x = rect.x + rectWidth / 2 - domWidth / 2;
  70031. y = rect.y + rectHeight / 2 - domHeight / 2;
  70032. break;
  70033. case 'top':
  70034. x = rect.x + rectWidth / 2 - domWidth / 2;
  70035. y = rect.y - domHeight - gap;
  70036. break;
  70037. case 'bottom':
  70038. x = rect.x + rectWidth / 2 - domWidth / 2;
  70039. y = rect.y + rectHeight + gap;
  70040. break;
  70041. case 'left':
  70042. x = rect.x - domWidth - gap;
  70043. y = rect.y + rectHeight / 2 - domHeight / 2;
  70044. break;
  70045. case 'right':
  70046. x = rect.x + rectWidth + gap;
  70047. y = rect.y + rectHeight / 2 - domHeight / 2;
  70048. }
  70049. return [x, y];
  70050. }
  70051. function isCenterAlign(align) {
  70052. return align === 'center' || align === 'middle';
  70053. }
  70054. /*
  70055. * Licensed to the Apache Software Foundation (ASF) under one
  70056. * or more contributor license agreements. See the NOTICE file
  70057. * distributed with this work for additional information
  70058. * regarding copyright ownership. The ASF licenses this file
  70059. * to you under the Apache License, Version 2.0 (the
  70060. * "License"); you may not use this file except in compliance
  70061. * with the License. You may obtain a copy of the License at
  70062. *
  70063. * http://www.apache.org/licenses/LICENSE-2.0
  70064. *
  70065. * Unless required by applicable law or agreed to in writing,
  70066. * software distributed under the License is distributed on an
  70067. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  70068. * KIND, either express or implied. See the License for the
  70069. * specific language governing permissions and limitations
  70070. * under the License.
  70071. */
  70072. // FIXME Better way to pack data in graphic element
  70073. /**
  70074. * @action
  70075. * @property {string} type
  70076. * @property {number} seriesIndex
  70077. * @property {number} dataIndex
  70078. * @property {number} [x]
  70079. * @property {number} [y]
  70080. */
  70081. registerAction(
  70082. {
  70083. type: 'showTip',
  70084. event: 'showTip',
  70085. update: 'tooltip:manuallyShowTip'
  70086. },
  70087. // noop
  70088. function () {}
  70089. );
  70090. registerAction(
  70091. {
  70092. type: 'hideTip',
  70093. event: 'hideTip',
  70094. update: 'tooltip:manuallyHideTip'
  70095. },
  70096. // noop
  70097. function () {}
  70098. );
  70099. /*
  70100. * Licensed to the Apache Software Foundation (ASF) under one
  70101. * or more contributor license agreements. See the NOTICE file
  70102. * distributed with this work for additional information
  70103. * regarding copyright ownership. The ASF licenses this file
  70104. * to you under the Apache License, Version 2.0 (the
  70105. * "License"); you may not use this file except in compliance
  70106. * with the License. You may obtain a copy of the License at
  70107. *
  70108. * http://www.apache.org/licenses/LICENSE-2.0
  70109. *
  70110. * Unless required by applicable law or agreed to in writing,
  70111. * software distributed under the License is distributed on an
  70112. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  70113. * KIND, either express or implied. See the License for the
  70114. * specific language governing permissions and limitations
  70115. * under the License.
  70116. */
  70117. var DEFAULT_TOOLBOX_BTNS = ['rect', 'polygon', 'keep', 'clear'];
  70118. var preprocessor$1 = function (option, isNew) {
  70119. var brushComponents = option && option.brush;
  70120. if (!isArray(brushComponents)) {
  70121. brushComponents = brushComponents ? [brushComponents] : [];
  70122. }
  70123. if (!brushComponents.length) {
  70124. return;
  70125. }
  70126. var brushComponentSpecifiedBtns = [];
  70127. each$1(brushComponents, function (brushOpt) {
  70128. var tbs = brushOpt.hasOwnProperty('toolbox')
  70129. ? brushOpt.toolbox : [];
  70130. if (tbs instanceof Array) {
  70131. brushComponentSpecifiedBtns = brushComponentSpecifiedBtns.concat(tbs);
  70132. }
  70133. });
  70134. var toolbox = option && option.toolbox;
  70135. if (isArray(toolbox)) {
  70136. toolbox = toolbox[0];
  70137. }
  70138. if (!toolbox) {
  70139. toolbox = {feature: {}};
  70140. option.toolbox = [toolbox];
  70141. }
  70142. var toolboxFeature = (toolbox.feature || (toolbox.feature = {}));
  70143. var toolboxBrush = toolboxFeature.brush || (toolboxFeature.brush = {});
  70144. var brushTypes = toolboxBrush.type || (toolboxBrush.type = []);
  70145. brushTypes.push.apply(brushTypes, brushComponentSpecifiedBtns);
  70146. removeDuplicate(brushTypes);
  70147. if (isNew && !brushTypes.length) {
  70148. brushTypes.push.apply(brushTypes, DEFAULT_TOOLBOX_BTNS);
  70149. }
  70150. };
  70151. function removeDuplicate(arr) {
  70152. var map$$1 = {};
  70153. each$1(arr, function (val) {
  70154. map$$1[val] = 1;
  70155. });
  70156. arr.length = 0;
  70157. each$1(map$$1, function (flag, val) {
  70158. arr.push(val);
  70159. });
  70160. }
  70161. /*
  70162. * Licensed to the Apache Software Foundation (ASF) under one
  70163. * or more contributor license agreements. See the NOTICE file
  70164. * distributed with this work for additional information
  70165. * regarding copyright ownership. The ASF licenses this file
  70166. * to you under the Apache License, Version 2.0 (the
  70167. * "License"); you may not use this file except in compliance
  70168. * with the License. You may obtain a copy of the License at
  70169. *
  70170. * http://www.apache.org/licenses/LICENSE-2.0
  70171. *
  70172. * Unless required by applicable law or agreed to in writing,
  70173. * software distributed under the License is distributed on an
  70174. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  70175. * KIND, either express or implied. See the License for the
  70176. * specific language governing permissions and limitations
  70177. * under the License.
  70178. */
  70179. /**
  70180. * @file Visual solution, for consistent option specification.
  70181. */
  70182. var each$23 = each$1;
  70183. function hasKeys(obj) {
  70184. if (obj) {
  70185. for (var name in obj) {
  70186. if (obj.hasOwnProperty(name)) {
  70187. return true;
  70188. }
  70189. }
  70190. }
  70191. }
  70192. /**
  70193. * @param {Object} option
  70194. * @param {Array.<string>} stateList
  70195. * @param {Function} [supplementVisualOption]
  70196. * @return {Object} visualMappings <state, <visualType, module:echarts/visual/VisualMapping>>
  70197. */
  70198. function createVisualMappings(option, stateList, supplementVisualOption) {
  70199. var visualMappings = {};
  70200. each$23(stateList, function (state) {
  70201. var mappings = visualMappings[state] = createMappings();
  70202. each$23(option[state], function (visualData, visualType) {
  70203. if (!VisualMapping.isValidType(visualType)) {
  70204. return;
  70205. }
  70206. var mappingOption = {
  70207. type: visualType,
  70208. visual: visualData
  70209. };
  70210. supplementVisualOption && supplementVisualOption(mappingOption, state);
  70211. mappings[visualType] = new VisualMapping(mappingOption);
  70212. // Prepare a alpha for opacity, for some case that opacity
  70213. // is not supported, such as rendering using gradient color.
  70214. if (visualType === 'opacity') {
  70215. mappingOption = clone(mappingOption);
  70216. mappingOption.type = 'colorAlpha';
  70217. mappings.__hidden.__alphaForOpacity = new VisualMapping(mappingOption);
  70218. }
  70219. });
  70220. });
  70221. return visualMappings;
  70222. function createMappings() {
  70223. var Creater = function () {};
  70224. // Make sure hidden fields will not be visited by
  70225. // object iteration (with hasOwnProperty checking).
  70226. Creater.prototype.__hidden = Creater.prototype;
  70227. var obj = new Creater();
  70228. return obj;
  70229. }
  70230. }
  70231. /**
  70232. * @param {Object} thisOption
  70233. * @param {Object} newOption
  70234. * @param {Array.<string>} keys
  70235. */
  70236. function replaceVisualOption(thisOption, newOption, keys) {
  70237. // Visual attributes merge is not supported, otherwise it
  70238. // brings overcomplicated merge logic. See #2853. So if
  70239. // newOption has anyone of these keys, all of these keys
  70240. // will be reset. Otherwise, all keys remain.
  70241. var has;
  70242. each$1(keys, function (key) {
  70243. if (newOption.hasOwnProperty(key) && hasKeys(newOption[key])) {
  70244. has = true;
  70245. }
  70246. });
  70247. has && each$1(keys, function (key) {
  70248. if (newOption.hasOwnProperty(key) && hasKeys(newOption[key])) {
  70249. thisOption[key] = clone(newOption[key]);
  70250. }
  70251. else {
  70252. delete thisOption[key];
  70253. }
  70254. });
  70255. }
  70256. /**
  70257. * @param {Array.<string>} stateList
  70258. * @param {Object} visualMappings <state, Object.<visualType, module:echarts/visual/VisualMapping>>
  70259. * @param {module:echarts/data/List} list
  70260. * @param {Function} getValueState param: valueOrIndex, return: state.
  70261. * @param {object} [scope] Scope for getValueState
  70262. * @param {string} [dimension] Concrete dimension, if used.
  70263. */
  70264. // ???! handle brush?
  70265. function applyVisual(stateList, visualMappings, data, getValueState, scope, dimension) {
  70266. var visualTypesMap = {};
  70267. each$1(stateList, function (state) {
  70268. var visualTypes = VisualMapping.prepareVisualTypes(visualMappings[state]);
  70269. visualTypesMap[state] = visualTypes;
  70270. });
  70271. var dataIndex;
  70272. function getVisual(key) {
  70273. return data.getItemVisual(dataIndex, key);
  70274. }
  70275. function setVisual(key, value) {
  70276. data.setItemVisual(dataIndex, key, value);
  70277. }
  70278. if (dimension == null) {
  70279. data.each(eachItem);
  70280. }
  70281. else {
  70282. data.each([dimension], eachItem);
  70283. }
  70284. function eachItem(valueOrIndex, index) {
  70285. dataIndex = dimension == null ? valueOrIndex : index;
  70286. var rawDataItem = data.getRawDataItem(dataIndex);
  70287. // Consider performance
  70288. if (rawDataItem && rawDataItem.visualMap === false) {
  70289. return;
  70290. }
  70291. var valueState = getValueState.call(scope, valueOrIndex);
  70292. var mappings = visualMappings[valueState];
  70293. var visualTypes = visualTypesMap[valueState];
  70294. for (var i = 0, len = visualTypes.length; i < len; i++) {
  70295. var type = visualTypes[i];
  70296. mappings[type] && mappings[type].applyVisual(
  70297. valueOrIndex, getVisual, setVisual
  70298. );
  70299. }
  70300. }
  70301. }
  70302. /**
  70303. * @param {module:echarts/data/List} data
  70304. * @param {Array.<string>} stateList
  70305. * @param {Object} visualMappings <state, Object.<visualType, module:echarts/visual/VisualMapping>>
  70306. * @param {Function} getValueState param: valueOrIndex, return: state.
  70307. * @param {number} [dim] dimension or dimension index.
  70308. */
  70309. function incrementalApplyVisual(stateList, visualMappings, getValueState, dim) {
  70310. var visualTypesMap = {};
  70311. each$1(stateList, function (state) {
  70312. var visualTypes = VisualMapping.prepareVisualTypes(visualMappings[state]);
  70313. visualTypesMap[state] = visualTypes;
  70314. });
  70315. function progress(params, data) {
  70316. if (dim != null) {
  70317. dim = data.getDimension(dim);
  70318. }
  70319. function getVisual(key) {
  70320. return data.getItemVisual(dataIndex, key);
  70321. }
  70322. function setVisual(key, value) {
  70323. data.setItemVisual(dataIndex, key, value);
  70324. }
  70325. var dataIndex;
  70326. while ((dataIndex = params.next()) != null) {
  70327. var rawDataItem = data.getRawDataItem(dataIndex);
  70328. // Consider performance
  70329. if (rawDataItem && rawDataItem.visualMap === false) {
  70330. continue;
  70331. }
  70332. var value = dim != null
  70333. ? data.get(dim, dataIndex, true)
  70334. : dataIndex;
  70335. var valueState = getValueState(value);
  70336. var mappings = visualMappings[valueState];
  70337. var visualTypes = visualTypesMap[valueState];
  70338. for (var i = 0, len = visualTypes.length; i < len; i++) {
  70339. var type = visualTypes[i];
  70340. mappings[type] && mappings[type].applyVisual(value, getVisual, setVisual);
  70341. }
  70342. }
  70343. }
  70344. return {progress: progress};
  70345. }
  70346. /*
  70347. * Licensed to the Apache Software Foundation (ASF) under one
  70348. * or more contributor license agreements. See the NOTICE file
  70349. * distributed with this work for additional information
  70350. * regarding copyright ownership. The ASF licenses this file
  70351. * to you under the Apache License, Version 2.0 (the
  70352. * "License"); you may not use this file except in compliance
  70353. * with the License. You may obtain a copy of the License at
  70354. *
  70355. * http://www.apache.org/licenses/LICENSE-2.0
  70356. *
  70357. * Unless required by applicable law or agreed to in writing,
  70358. * software distributed under the License is distributed on an
  70359. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  70360. * KIND, either express or implied. See the License for the
  70361. * specific language governing permissions and limitations
  70362. * under the License.
  70363. */
  70364. // Key of the first level is brushType: `line`, `rect`, `polygon`.
  70365. // Key of the second level is chart element type: `point`, `rect`.
  70366. // See moudule:echarts/component/helper/BrushController
  70367. // function param:
  70368. // {Object} itemLayout fetch from data.getItemLayout(dataIndex)
  70369. // {Object} selectors {point: selector, rect: selector, ...}
  70370. // {Object} area {range: [[], [], ..], boudingRect}
  70371. // function return:
  70372. // {boolean} Whether in the given brush.
  70373. var selector = {
  70374. lineX: getLineSelectors(0),
  70375. lineY: getLineSelectors(1),
  70376. rect: {
  70377. point: function (itemLayout, selectors, area) {
  70378. return itemLayout && area.boundingRect.contain(itemLayout[0], itemLayout[1]);
  70379. },
  70380. rect: function (itemLayout, selectors, area) {
  70381. return itemLayout && area.boundingRect.intersect(itemLayout);
  70382. }
  70383. },
  70384. polygon: {
  70385. point: function (itemLayout, selectors, area) {
  70386. return itemLayout
  70387. && area.boundingRect.contain(itemLayout[0], itemLayout[1])
  70388. && contain$1(area.range, itemLayout[0], itemLayout[1]);
  70389. },
  70390. rect: function (itemLayout, selectors, area) {
  70391. var points = area.range;
  70392. if (!itemLayout || points.length <= 1) {
  70393. return false;
  70394. }
  70395. var x = itemLayout.x;
  70396. var y = itemLayout.y;
  70397. var width = itemLayout.width;
  70398. var height = itemLayout.height;
  70399. var p = points[0];
  70400. if (contain$1(points, x, y)
  70401. || contain$1(points, x + width, y)
  70402. || contain$1(points, x, y + height)
  70403. || contain$1(points, x + width, y + height)
  70404. || BoundingRect.create(itemLayout).contain(p[0], p[1])
  70405. || linePolygonIntersect(x, y, x + width, y, points)
  70406. || linePolygonIntersect(x, y, x, y + height, points)
  70407. || linePolygonIntersect(x + width, y, x + width, y + height, points)
  70408. || linePolygonIntersect(x, y + height, x + width, y + height, points)
  70409. ) {
  70410. return true;
  70411. }
  70412. }
  70413. }
  70414. };
  70415. function getLineSelectors(xyIndex) {
  70416. var xy = ['x', 'y'];
  70417. var wh = ['width', 'height'];
  70418. return {
  70419. point: function (itemLayout, selectors, area) {
  70420. if (itemLayout) {
  70421. var range = area.range;
  70422. var p = itemLayout[xyIndex];
  70423. return inLineRange(p, range);
  70424. }
  70425. },
  70426. rect: function (itemLayout, selectors, area) {
  70427. if (itemLayout) {
  70428. var range = area.range;
  70429. var layoutRange = [
  70430. itemLayout[xy[xyIndex]],
  70431. itemLayout[xy[xyIndex]] + itemLayout[wh[xyIndex]]
  70432. ];
  70433. layoutRange[1] < layoutRange[0] && layoutRange.reverse();
  70434. return inLineRange(layoutRange[0], range)
  70435. || inLineRange(layoutRange[1], range)
  70436. || inLineRange(range[0], layoutRange)
  70437. || inLineRange(range[1], layoutRange);
  70438. }
  70439. }
  70440. };
  70441. }
  70442. function inLineRange(p, range) {
  70443. return range[0] <= p && p <= range[1];
  70444. }
  70445. /*
  70446. * Licensed to the Apache Software Foundation (ASF) under one
  70447. * or more contributor license agreements. See the NOTICE file
  70448. * distributed with this work for additional information
  70449. * regarding copyright ownership. The ASF licenses this file
  70450. * to you under the Apache License, Version 2.0 (the
  70451. * "License"); you may not use this file except in compliance
  70452. * with the License. You may obtain a copy of the License at
  70453. *
  70454. * http://www.apache.org/licenses/LICENSE-2.0
  70455. *
  70456. * Unless required by applicable law or agreed to in writing,
  70457. * software distributed under the License is distributed on an
  70458. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  70459. * KIND, either express or implied. See the License for the
  70460. * specific language governing permissions and limitations
  70461. * under the License.
  70462. */
  70463. var STATE_LIST = ['inBrush', 'outOfBrush'];
  70464. var DISPATCH_METHOD = '__ecBrushSelect';
  70465. var DISPATCH_FLAG = '__ecInBrushSelectEvent';
  70466. var PRIORITY_BRUSH = PRIORITY.VISUAL.BRUSH;
  70467. /**
  70468. * Layout for visual, the priority higher than other layout, and before brush visual.
  70469. */
  70470. registerLayout(PRIORITY_BRUSH, function (ecModel, api, payload) {
  70471. ecModel.eachComponent({mainType: 'brush'}, function (brushModel) {
  70472. payload && payload.type === 'takeGlobalCursor' && brushModel.setBrushOption(
  70473. payload.key === 'brush' ? payload.brushOption : {brushType: false}
  70474. );
  70475. var brushTargetManager = brushModel.brushTargetManager = new BrushTargetManager(brushModel.option, ecModel);
  70476. brushTargetManager.setInputRanges(brushModel.areas, ecModel);
  70477. });
  70478. });
  70479. /**
  70480. * Register the visual encoding if this modules required.
  70481. */
  70482. registerVisual(PRIORITY_BRUSH, function (ecModel, api, payload) {
  70483. var brushSelected = [];
  70484. var throttleType;
  70485. var throttleDelay;
  70486. ecModel.eachComponent({mainType: 'brush'}, function (brushModel, brushIndex) {
  70487. var thisBrushSelected = {
  70488. brushId: brushModel.id,
  70489. brushIndex: brushIndex,
  70490. brushName: brushModel.name,
  70491. areas: clone(brushModel.areas),
  70492. selected: []
  70493. };
  70494. // Every brush component exists in event params, convenient
  70495. // for user to find by index.
  70496. brushSelected.push(thisBrushSelected);
  70497. var brushOption = brushModel.option;
  70498. var brushLink = brushOption.brushLink;
  70499. var linkedSeriesMap = [];
  70500. var selectedDataIndexForLink = [];
  70501. var rangeInfoBySeries = [];
  70502. var hasBrushExists = 0;
  70503. if (!brushIndex) { // Only the first throttle setting works.
  70504. throttleType = brushOption.throttleType;
  70505. throttleDelay = brushOption.throttleDelay;
  70506. }
  70507. // Add boundingRect and selectors to range.
  70508. var areas = map(brushModel.areas, function (area) {
  70509. return bindSelector(
  70510. defaults(
  70511. {boundingRect: boundingRectBuilders[area.brushType](area)},
  70512. area
  70513. )
  70514. );
  70515. });
  70516. var visualMappings = createVisualMappings(
  70517. brushModel.option, STATE_LIST, function (mappingOption) {
  70518. mappingOption.mappingMethod = 'fixed';
  70519. }
  70520. );
  70521. isArray(brushLink) && each$1(brushLink, function (seriesIndex) {
  70522. linkedSeriesMap[seriesIndex] = 1;
  70523. });
  70524. function linkOthers(seriesIndex) {
  70525. return brushLink === 'all' || linkedSeriesMap[seriesIndex];
  70526. }
  70527. // If no supported brush or no brush on the series,
  70528. // all visuals should be in original state.
  70529. function brushed(rangeInfoList) {
  70530. return !!rangeInfoList.length;
  70531. }
  70532. /**
  70533. * Logic for each series: (If the logic has to be modified one day, do it carefully!)
  70534. *
  70535. * ( brushed ┬ && ┬hasBrushExist ┬ && linkOthers ) => StepA: ┬record, ┬ StepB: ┬visualByRecord.
  70536. * !brushed┘ ├hasBrushExist ┤ └nothing,┘ ├visualByRecord.
  70537. * └!hasBrushExist┘ └nothing.
  70538. * ( !brushed && ┬hasBrushExist ┬ && linkOthers ) => StepA: nothing, StepB: ┬visualByRecord.
  70539. * └!hasBrushExist┘ └nothing.
  70540. * ( brushed ┬ && !linkOthers ) => StepA: nothing, StepB: ┬visualByCheck.
  70541. * !brushed┘ └nothing.
  70542. * ( !brushed && !linkOthers ) => StepA: nothing, StepB: nothing.
  70543. */
  70544. // Step A
  70545. ecModel.eachSeries(function (seriesModel, seriesIndex) {
  70546. var rangeInfoList = rangeInfoBySeries[seriesIndex] = [];
  70547. seriesModel.subType === 'parallel'
  70548. ? stepAParallel(seriesModel, seriesIndex, rangeInfoList)
  70549. : stepAOthers(seriesModel, seriesIndex, rangeInfoList);
  70550. });
  70551. function stepAParallel(seriesModel, seriesIndex) {
  70552. var coordSys = seriesModel.coordinateSystem;
  70553. hasBrushExists |= coordSys.hasAxisBrushed();
  70554. linkOthers(seriesIndex) && coordSys.eachActiveState(
  70555. seriesModel.getData(),
  70556. function (activeState, dataIndex) {
  70557. activeState === 'active' && (selectedDataIndexForLink[dataIndex] = 1);
  70558. }
  70559. );
  70560. }
  70561. function stepAOthers(seriesModel, seriesIndex, rangeInfoList) {
  70562. var selectorsByBrushType = getSelectorsByBrushType(seriesModel);
  70563. if (!selectorsByBrushType || brushModelNotControll(brushModel, seriesIndex)) {
  70564. return;
  70565. }
  70566. each$1(areas, function (area) {
  70567. selectorsByBrushType[area.brushType]
  70568. && brushModel.brushTargetManager.controlSeries(area, seriesModel, ecModel)
  70569. && rangeInfoList.push(area);
  70570. hasBrushExists |= brushed(rangeInfoList);
  70571. });
  70572. if (linkOthers(seriesIndex) && brushed(rangeInfoList)) {
  70573. var data = seriesModel.getData();
  70574. data.each(function (dataIndex) {
  70575. if (checkInRange(selectorsByBrushType, rangeInfoList, data, dataIndex)) {
  70576. selectedDataIndexForLink[dataIndex] = 1;
  70577. }
  70578. });
  70579. }
  70580. }
  70581. // Step B
  70582. ecModel.eachSeries(function (seriesModel, seriesIndex) {
  70583. var seriesBrushSelected = {
  70584. seriesId: seriesModel.id,
  70585. seriesIndex: seriesIndex,
  70586. seriesName: seriesModel.name,
  70587. dataIndex: []
  70588. };
  70589. // Every series exists in event params, convenient
  70590. // for user to find series by seriesIndex.
  70591. thisBrushSelected.selected.push(seriesBrushSelected);
  70592. var selectorsByBrushType = getSelectorsByBrushType(seriesModel);
  70593. var rangeInfoList = rangeInfoBySeries[seriesIndex];
  70594. var data = seriesModel.getData();
  70595. var getValueState = linkOthers(seriesIndex)
  70596. ? function (dataIndex) {
  70597. return selectedDataIndexForLink[dataIndex]
  70598. ? (seriesBrushSelected.dataIndex.push(data.getRawIndex(dataIndex)), 'inBrush')
  70599. : 'outOfBrush';
  70600. }
  70601. : function (dataIndex) {
  70602. return checkInRange(selectorsByBrushType, rangeInfoList, data, dataIndex)
  70603. ? (seriesBrushSelected.dataIndex.push(data.getRawIndex(dataIndex)), 'inBrush')
  70604. : 'outOfBrush';
  70605. };
  70606. // If no supported brush or no brush, all visuals are in original state.
  70607. (linkOthers(seriesIndex) ? hasBrushExists : brushed(rangeInfoList))
  70608. && applyVisual(
  70609. STATE_LIST, visualMappings, data, getValueState
  70610. );
  70611. });
  70612. });
  70613. dispatchAction(api, throttleType, throttleDelay, brushSelected, payload);
  70614. });
  70615. function dispatchAction(api, throttleType, throttleDelay, brushSelected, payload) {
  70616. // This event will not be triggered when `setOpion`, otherwise dead lock may
  70617. // triggered when do `setOption` in event listener, which we do not find
  70618. // satisfactory way to solve yet. Some considered resolutions:
  70619. // (a) Diff with prevoius selected data ant only trigger event when changed.
  70620. // But store previous data and diff precisely (i.e., not only by dataIndex, but
  70621. // also detect value changes in selected data) might bring complexity or fragility.
  70622. // (b) Use spectial param like `silent` to suppress event triggering.
  70623. // But such kind of volatile param may be weird in `setOption`.
  70624. if (!payload) {
  70625. return;
  70626. }
  70627. var zr = api.getZr();
  70628. if (zr[DISPATCH_FLAG]) {
  70629. return;
  70630. }
  70631. if (!zr[DISPATCH_METHOD]) {
  70632. zr[DISPATCH_METHOD] = doDispatch;
  70633. }
  70634. var fn = createOrUpdate(zr, DISPATCH_METHOD, throttleDelay, throttleType);
  70635. fn(api, brushSelected);
  70636. }
  70637. function doDispatch(api, brushSelected) {
  70638. if (!api.isDisposed()) {
  70639. var zr = api.getZr();
  70640. zr[DISPATCH_FLAG] = true;
  70641. api.dispatchAction({
  70642. type: 'brushSelect',
  70643. batch: brushSelected
  70644. });
  70645. zr[DISPATCH_FLAG] = false;
  70646. }
  70647. }
  70648. function checkInRange(selectorsByBrushType, rangeInfoList, data, dataIndex) {
  70649. for (var i = 0, len = rangeInfoList.length; i < len; i++) {
  70650. var area = rangeInfoList[i];
  70651. if (selectorsByBrushType[area.brushType](
  70652. dataIndex, data, area.selectors, area
  70653. )) {
  70654. return true;
  70655. }
  70656. }
  70657. }
  70658. function getSelectorsByBrushType(seriesModel) {
  70659. var brushSelector = seriesModel.brushSelector;
  70660. if (isString(brushSelector)) {
  70661. var sels = [];
  70662. each$1(selector, function (selectorsByElementType, brushType) {
  70663. sels[brushType] = function (dataIndex, data, selectors, area) {
  70664. var itemLayout = data.getItemLayout(dataIndex);
  70665. return selectorsByElementType[brushSelector](itemLayout, selectors, area);
  70666. };
  70667. });
  70668. return sels;
  70669. }
  70670. else if (isFunction$1(brushSelector)) {
  70671. var bSelector = {};
  70672. each$1(selector, function (sel, brushType) {
  70673. bSelector[brushType] = brushSelector;
  70674. });
  70675. return bSelector;
  70676. }
  70677. return brushSelector;
  70678. }
  70679. function brushModelNotControll(brushModel, seriesIndex) {
  70680. var seriesIndices = brushModel.option.seriesIndex;
  70681. return seriesIndices != null
  70682. && seriesIndices !== 'all'
  70683. && (
  70684. isArray(seriesIndices)
  70685. ? indexOf(seriesIndices, seriesIndex) < 0
  70686. : seriesIndex !== seriesIndices
  70687. );
  70688. }
  70689. function bindSelector(area) {
  70690. var selectors = area.selectors = {};
  70691. each$1(selector[area.brushType], function (selFn, elType) {
  70692. // Do not use function binding or curry for performance.
  70693. selectors[elType] = function (itemLayout) {
  70694. return selFn(itemLayout, selectors, area);
  70695. };
  70696. });
  70697. return area;
  70698. }
  70699. var boundingRectBuilders = {
  70700. lineX: noop,
  70701. lineY: noop,
  70702. rect: function (area) {
  70703. return getBoundingRectFromMinMax(area.range);
  70704. },
  70705. polygon: function (area) {
  70706. var minMax;
  70707. var range = area.range;
  70708. for (var i = 0, len = range.length; i < len; i++) {
  70709. minMax = minMax || [[Infinity, -Infinity], [Infinity, -Infinity]];
  70710. var rg = range[i];
  70711. rg[0] < minMax[0][0] && (minMax[0][0] = rg[0]);
  70712. rg[0] > minMax[0][1] && (minMax[0][1] = rg[0]);
  70713. rg[1] < minMax[1][0] && (minMax[1][0] = rg[1]);
  70714. rg[1] > minMax[1][1] && (minMax[1][1] = rg[1]);
  70715. }
  70716. return minMax && getBoundingRectFromMinMax(minMax);
  70717. }
  70718. };
  70719. function getBoundingRectFromMinMax(minMax) {
  70720. return new BoundingRect(
  70721. minMax[0][0],
  70722. minMax[1][0],
  70723. minMax[0][1] - minMax[0][0],
  70724. minMax[1][1] - minMax[1][0]
  70725. );
  70726. }
  70727. /*
  70728. * Licensed to the Apache Software Foundation (ASF) under one
  70729. * or more contributor license agreements. See the NOTICE file
  70730. * distributed with this work for additional information
  70731. * regarding copyright ownership. The ASF licenses this file
  70732. * to you under the Apache License, Version 2.0 (the
  70733. * "License"); you may not use this file except in compliance
  70734. * with the License. You may obtain a copy of the License at
  70735. *
  70736. * http://www.apache.org/licenses/LICENSE-2.0
  70737. *
  70738. * Unless required by applicable law or agreed to in writing,
  70739. * software distributed under the License is distributed on an
  70740. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  70741. * KIND, either express or implied. See the License for the
  70742. * specific language governing permissions and limitations
  70743. * under the License.
  70744. */
  70745. var DEFAULT_OUT_OF_BRUSH_COLOR = ['#ddd'];
  70746. var BrushModel = extendComponentModel({
  70747. type: 'brush',
  70748. dependencies: ['geo', 'grid', 'xAxis', 'yAxis', 'parallel', 'series'],
  70749. /**
  70750. * @protected
  70751. */
  70752. defaultOption: {
  70753. // inBrush: null,
  70754. // outOfBrush: null,
  70755. toolbox: null, // Default value see preprocessor.
  70756. brushLink: null, // Series indices array, broadcast using dataIndex.
  70757. // or 'all', which means all series. 'none' or null means no series.
  70758. seriesIndex: 'all', // seriesIndex array, specify series controlled by this brush component.
  70759. geoIndex: null, //
  70760. xAxisIndex: null,
  70761. yAxisIndex: null,
  70762. brushType: 'rect', // Default brushType, see BrushController.
  70763. brushMode: 'single', // Default brushMode, 'single' or 'multiple'
  70764. transformable: true, // Default transformable.
  70765. brushStyle: { // Default brushStyle
  70766. borderWidth: 1,
  70767. color: 'rgba(120,140,180,0.3)',
  70768. borderColor: 'rgba(120,140,180,0.8)'
  70769. },
  70770. throttleType: 'fixRate', // Throttle in brushSelected event. 'fixRate' or 'debounce'.
  70771. // If null, no throttle. Valid only in the first brush component
  70772. throttleDelay: 0, // Unit: ms, 0 means every event will be triggered.
  70773. // FIXME
  70774. // 试验效果
  70775. removeOnClick: true,
  70776. z: 10000
  70777. },
  70778. /**
  70779. * @readOnly
  70780. * @type {Array.<Object>}
  70781. */
  70782. areas: [],
  70783. /**
  70784. * Current activated brush type.
  70785. * If null, brush is inactived.
  70786. * see module:echarts/component/helper/BrushController
  70787. * @readOnly
  70788. * @type {string}
  70789. */
  70790. brushType: null,
  70791. /**
  70792. * Current brush opt.
  70793. * see module:echarts/component/helper/BrushController
  70794. * @readOnly
  70795. * @type {Object}
  70796. */
  70797. brushOption: {},
  70798. /**
  70799. * @readOnly
  70800. * @type {Array.<Object>}
  70801. */
  70802. coordInfoList: [],
  70803. optionUpdated: function (newOption, isInit) {
  70804. var thisOption = this.option;
  70805. !isInit && replaceVisualOption(
  70806. thisOption, newOption, ['inBrush', 'outOfBrush']
  70807. );
  70808. var inBrush = thisOption.inBrush = thisOption.inBrush || {};
  70809. // Always give default visual, consider setOption at the second time.
  70810. thisOption.outOfBrush = thisOption.outOfBrush || {color: DEFAULT_OUT_OF_BRUSH_COLOR};
  70811. if (!inBrush.hasOwnProperty('liftZ')) {
  70812. // Bigger than the highlight z lift, otherwise it will
  70813. // be effected by the highlight z when brush.
  70814. inBrush.liftZ = 5;
  70815. }
  70816. },
  70817. /**
  70818. * If ranges is null/undefined, range state remain.
  70819. *
  70820. * @param {Array.<Object>} [ranges]
  70821. */
  70822. setAreas: function (areas) {
  70823. if (__DEV__) {
  70824. assert$1(isArray(areas));
  70825. each$1(areas, function (area) {
  70826. assert$1(area.brushType, 'Illegal areas');
  70827. });
  70828. }
  70829. // If ranges is null/undefined, range state remain.
  70830. // This helps user to dispatchAction({type: 'brush'}) with no areas
  70831. // set but just want to get the current brush select info from a `brush` event.
  70832. if (!areas) {
  70833. return;
  70834. }
  70835. this.areas = map(areas, function (area) {
  70836. return generateBrushOption(this.option, area);
  70837. }, this);
  70838. },
  70839. /**
  70840. * see module:echarts/component/helper/BrushController
  70841. * @param {Object} brushOption
  70842. */
  70843. setBrushOption: function (brushOption) {
  70844. this.brushOption = generateBrushOption(this.option, brushOption);
  70845. this.brushType = this.brushOption.brushType;
  70846. }
  70847. });
  70848. function generateBrushOption(option, brushOption) {
  70849. return merge(
  70850. {
  70851. brushType: option.brushType,
  70852. brushMode: option.brushMode,
  70853. transformable: option.transformable,
  70854. brushStyle: new Model(option.brushStyle).getItemStyle(),
  70855. removeOnClick: option.removeOnClick,
  70856. z: option.z
  70857. },
  70858. brushOption,
  70859. true
  70860. );
  70861. }
  70862. /*
  70863. * Licensed to the Apache Software Foundation (ASF) under one
  70864. * or more contributor license agreements. See the NOTICE file
  70865. * distributed with this work for additional information
  70866. * regarding copyright ownership. The ASF licenses this file
  70867. * to you under the Apache License, Version 2.0 (the
  70868. * "License"); you may not use this file except in compliance
  70869. * with the License. You may obtain a copy of the License at
  70870. *
  70871. * http://www.apache.org/licenses/LICENSE-2.0
  70872. *
  70873. * Unless required by applicable law or agreed to in writing,
  70874. * software distributed under the License is distributed on an
  70875. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  70876. * KIND, either express or implied. See the License for the
  70877. * specific language governing permissions and limitations
  70878. * under the License.
  70879. */
  70880. extendComponentView({
  70881. type: 'brush',
  70882. init: function (ecModel, api) {
  70883. /**
  70884. * @readOnly
  70885. * @type {module:echarts/model/Global}
  70886. */
  70887. this.ecModel = ecModel;
  70888. /**
  70889. * @readOnly
  70890. * @type {module:echarts/ExtensionAPI}
  70891. */
  70892. this.api = api;
  70893. /**
  70894. * @readOnly
  70895. * @type {module:echarts/component/brush/BrushModel}
  70896. */
  70897. this.model;
  70898. /**
  70899. * @private
  70900. * @type {module:echarts/component/helper/BrushController}
  70901. */
  70902. (this._brushController = new BrushController(api.getZr()))
  70903. .on('brush', bind(this._onBrush, this))
  70904. .mount();
  70905. },
  70906. /**
  70907. * @override
  70908. */
  70909. render: function (brushModel) {
  70910. this.model = brushModel;
  70911. return updateController.apply(this, arguments);
  70912. },
  70913. /**
  70914. * @override
  70915. */
  70916. updateTransform: updateController,
  70917. /**
  70918. * @override
  70919. */
  70920. updateView: updateController,
  70921. // /**
  70922. // * @override
  70923. // */
  70924. // updateLayout: updateController,
  70925. // /**
  70926. // * @override
  70927. // */
  70928. // updateVisual: updateController,
  70929. /**
  70930. * @override
  70931. */
  70932. dispose: function () {
  70933. this._brushController.dispose();
  70934. },
  70935. /**
  70936. * @private
  70937. */
  70938. _onBrush: function (areas, opt) {
  70939. var modelId = this.model.id;
  70940. this.model.brushTargetManager.setOutputRanges(areas, this.ecModel);
  70941. // Action is not dispatched on drag end, because the drag end
  70942. // emits the same params with the last drag move event, and
  70943. // may have some delay when using touch pad, which makes
  70944. // animation not smooth (when using debounce).
  70945. (!opt.isEnd || opt.removeOnClick) && this.api.dispatchAction({
  70946. type: 'brush',
  70947. brushId: modelId,
  70948. areas: clone(areas),
  70949. $from: modelId
  70950. });
  70951. }
  70952. });
  70953. function updateController(brushModel, ecModel, api, payload) {
  70954. // Do not update controller when drawing.
  70955. (!payload || payload.$from !== brushModel.id) && this._brushController
  70956. .setPanels(brushModel.brushTargetManager.makePanelOpts(api))
  70957. .enableBrush(brushModel.brushOption)
  70958. .updateCovers(brushModel.areas.slice());
  70959. }
  70960. /*
  70961. * Licensed to the Apache Software Foundation (ASF) under one
  70962. * or more contributor license agreements. See the NOTICE file
  70963. * distributed with this work for additional information
  70964. * regarding copyright ownership. The ASF licenses this file
  70965. * to you under the Apache License, Version 2.0 (the
  70966. * "License"); you may not use this file except in compliance
  70967. * with the License. You may obtain a copy of the License at
  70968. *
  70969. * http://www.apache.org/licenses/LICENSE-2.0
  70970. *
  70971. * Unless required by applicable law or agreed to in writing,
  70972. * software distributed under the License is distributed on an
  70973. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  70974. * KIND, either express or implied. See the License for the
  70975. * specific language governing permissions and limitations
  70976. * under the License.
  70977. */
  70978. /**
  70979. * payload: {
  70980. * brushIndex: number, or,
  70981. * brushId: string, or,
  70982. * brushName: string,
  70983. * globalRanges: Array
  70984. * }
  70985. */
  70986. registerAction(
  70987. {type: 'brush', event: 'brush' /*, update: 'updateView' */},
  70988. function (payload, ecModel) {
  70989. ecModel.eachComponent({mainType: 'brush', query: payload}, function (brushModel) {
  70990. brushModel.setAreas(payload.areas);
  70991. });
  70992. }
  70993. );
  70994. /**
  70995. * payload: {
  70996. * brushComponents: [
  70997. * {
  70998. * brushId,
  70999. * brushIndex,
  71000. * brushName,
  71001. * series: [
  71002. * {
  71003. * seriesId,
  71004. * seriesIndex,
  71005. * seriesName,
  71006. * rawIndices: [21, 34, ...]
  71007. * },
  71008. * ...
  71009. * ]
  71010. * },
  71011. * ...
  71012. * ]
  71013. * }
  71014. */
  71015. registerAction(
  71016. {type: 'brushSelect', event: 'brushSelected', update: 'none'},
  71017. function () {}
  71018. );
  71019. /*
  71020. * Licensed to the Apache Software Foundation (ASF) under one
  71021. * or more contributor license agreements. See the NOTICE file
  71022. * distributed with this work for additional information
  71023. * regarding copyright ownership. The ASF licenses this file
  71024. * to you under the Apache License, Version 2.0 (the
  71025. * "License"); you may not use this file except in compliance
  71026. * with the License. You may obtain a copy of the License at
  71027. *
  71028. * http://www.apache.org/licenses/LICENSE-2.0
  71029. *
  71030. * Unless required by applicable law or agreed to in writing,
  71031. * software distributed under the License is distributed on an
  71032. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  71033. * KIND, either express or implied. See the License for the
  71034. * specific language governing permissions and limitations
  71035. * under the License.
  71036. */
  71037. var brushLang = lang.toolbox.brush;
  71038. function Brush(model, ecModel, api) {
  71039. this.model = model;
  71040. this.ecModel = ecModel;
  71041. this.api = api;
  71042. /**
  71043. * @private
  71044. * @type {string}
  71045. */
  71046. this._brushType;
  71047. /**
  71048. * @private
  71049. * @type {string}
  71050. */
  71051. this._brushMode;
  71052. }
  71053. Brush.defaultOption = {
  71054. show: true,
  71055. type: ['rect', 'polygon', 'lineX', 'lineY', 'keep', 'clear'],
  71056. icon: {
  71057. /* eslint-disable */
  71058. 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
  71059. 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
  71060. 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
  71061. 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
  71062. 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
  71063. 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
  71064. /* eslint-enable */
  71065. },
  71066. // `rect`, `polygon`, `lineX`, `lineY`, `keep`, `clear`
  71067. title: clone(brushLang.title)
  71068. };
  71069. var proto$7 = Brush.prototype;
  71070. // proto.updateLayout = function (featureModel, ecModel, api) {
  71071. /* eslint-disable */
  71072. proto$7.render =
  71073. /* eslint-enable */
  71074. proto$7.updateView = function (featureModel, ecModel, api) {
  71075. var brushType;
  71076. var brushMode;
  71077. var isBrushed;
  71078. ecModel.eachComponent({mainType: 'brush'}, function (brushModel) {
  71079. brushType = brushModel.brushType;
  71080. brushMode = brushModel.brushOption.brushMode || 'single';
  71081. isBrushed |= brushModel.areas.length;
  71082. });
  71083. this._brushType = brushType;
  71084. this._brushMode = brushMode;
  71085. each$1(featureModel.get('type', true), function (type) {
  71086. featureModel.setIconStatus(
  71087. type,
  71088. (
  71089. type === 'keep'
  71090. ? brushMode === 'multiple'
  71091. : type === 'clear'
  71092. ? isBrushed
  71093. : type === brushType
  71094. ) ? 'emphasis' : 'normal'
  71095. );
  71096. });
  71097. };
  71098. proto$7.getIcons = function () {
  71099. var model = this.model;
  71100. var availableIcons = model.get('icon', true);
  71101. var icons = {};
  71102. each$1(model.get('type', true), function (type) {
  71103. if (availableIcons[type]) {
  71104. icons[type] = availableIcons[type];
  71105. }
  71106. });
  71107. return icons;
  71108. };
  71109. proto$7.onclick = function (ecModel, api, type) {
  71110. var brushType = this._brushType;
  71111. var brushMode = this._brushMode;
  71112. if (type === 'clear') {
  71113. // Trigger parallel action firstly
  71114. api.dispatchAction({
  71115. type: 'axisAreaSelect',
  71116. intervals: []
  71117. });
  71118. api.dispatchAction({
  71119. type: 'brush',
  71120. command: 'clear',
  71121. // Clear all areas of all brush components.
  71122. areas: []
  71123. });
  71124. }
  71125. else {
  71126. api.dispatchAction({
  71127. type: 'takeGlobalCursor',
  71128. key: 'brush',
  71129. brushOption: {
  71130. brushType: type === 'keep'
  71131. ? brushType
  71132. : (brushType === type ? false : type),
  71133. brushMode: type === 'keep'
  71134. ? (brushMode === 'multiple' ? 'single' : 'multiple')
  71135. : brushMode
  71136. }
  71137. });
  71138. }
  71139. };
  71140. register$1('brush', Brush);
  71141. /*
  71142. * Licensed to the Apache Software Foundation (ASF) under one
  71143. * or more contributor license agreements. See the NOTICE file
  71144. * distributed with this work for additional information
  71145. * regarding copyright ownership. The ASF licenses this file
  71146. * to you under the Apache License, Version 2.0 (the
  71147. * "License"); you may not use this file except in compliance
  71148. * with the License. You may obtain a copy of the License at
  71149. *
  71150. * http://www.apache.org/licenses/LICENSE-2.0
  71151. *
  71152. * Unless required by applicable law or agreed to in writing,
  71153. * software distributed under the License is distributed on an
  71154. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  71155. * KIND, either express or implied. See the License for the
  71156. * specific language governing permissions and limitations
  71157. * under the License.
  71158. */
  71159. /**
  71160. * Brush component entry
  71161. */
  71162. registerPreprocessor(preprocessor$1);
  71163. /*
  71164. * Licensed to the Apache Software Foundation (ASF) under one
  71165. * or more contributor license agreements. See the NOTICE file
  71166. * distributed with this work for additional information
  71167. * regarding copyright ownership. The ASF licenses this file
  71168. * to you under the Apache License, Version 2.0 (the
  71169. * "License"); you may not use this file except in compliance
  71170. * with the License. You may obtain a copy of the License at
  71171. *
  71172. * http://www.apache.org/licenses/LICENSE-2.0
  71173. *
  71174. * Unless required by applicable law or agreed to in writing,
  71175. * software distributed under the License is distributed on an
  71176. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  71177. * KIND, either express or implied. See the License for the
  71178. * specific language governing permissions and limitations
  71179. * under the License.
  71180. */
  71181. // Model
  71182. extendComponentModel({
  71183. type: 'title',
  71184. layoutMode: {type: 'box', ignoreSize: true},
  71185. defaultOption: {
  71186. // 一级层叠
  71187. zlevel: 0,
  71188. // 二级层叠
  71189. z: 6,
  71190. show: true,
  71191. text: '',
  71192. // 超链接跳转
  71193. // link: null,
  71194. // 仅支持self | blank
  71195. target: 'blank',
  71196. subtext: '',
  71197. // 超链接跳转
  71198. // sublink: null,
  71199. // 仅支持self | blank
  71200. subtarget: 'blank',
  71201. // 'center' ¦ 'left' ¦ 'right'
  71202. // ¦ {number}(x坐标,单位px)
  71203. left: 0,
  71204. // 'top' ¦ 'bottom' ¦ 'center'
  71205. // ¦ {number}(y坐标,单位px)
  71206. top: 0,
  71207. // 水平对齐
  71208. // 'auto' | 'left' | 'right' | 'center'
  71209. // 默认根据 left 的位置判断是左对齐还是右对齐
  71210. // textAlign: null
  71211. //
  71212. // 垂直对齐
  71213. // 'auto' | 'top' | 'bottom' | 'middle'
  71214. // 默认根据 top 位置判断是上对齐还是下对齐
  71215. // textVerticalAlign: null
  71216. // textBaseline: null // The same as textVerticalAlign.
  71217. backgroundColor: 'rgba(0,0,0,0)',
  71218. // 标题边框颜色
  71219. borderColor: '#ccc',
  71220. // 标题边框线宽,单位px,默认为0(无边框)
  71221. borderWidth: 0,
  71222. // 标题内边距,单位px,默认各方向内边距为5,
  71223. // 接受数组分别设定上右下左边距,同css
  71224. padding: 5,
  71225. // 主副标题纵向间隔,单位px,默认为10,
  71226. itemGap: 10,
  71227. textStyle: {
  71228. fontSize: 18,
  71229. fontWeight: 'bolder',
  71230. color: '#333'
  71231. },
  71232. subtextStyle: {
  71233. color: '#aaa'
  71234. }
  71235. }
  71236. });
  71237. // View
  71238. extendComponentView({
  71239. type: 'title',
  71240. render: function (titleModel, ecModel, api) {
  71241. this.group.removeAll();
  71242. if (!titleModel.get('show')) {
  71243. return;
  71244. }
  71245. var group = this.group;
  71246. var textStyleModel = titleModel.getModel('textStyle');
  71247. var subtextStyleModel = titleModel.getModel('subtextStyle');
  71248. var textAlign = titleModel.get('textAlign');
  71249. var textVerticalAlign = retrieve2(
  71250. titleModel.get('textBaseline'), titleModel.get('textVerticalAlign')
  71251. );
  71252. var textEl = new Text({
  71253. style: setTextStyle({}, textStyleModel, {
  71254. text: titleModel.get('text'),
  71255. textFill: textStyleModel.getTextColor()
  71256. }, {disableBox: true}),
  71257. z2: 10
  71258. });
  71259. var textRect = textEl.getBoundingRect();
  71260. var subText = titleModel.get('subtext');
  71261. var subTextEl = new Text({
  71262. style: setTextStyle({}, subtextStyleModel, {
  71263. text: subText,
  71264. textFill: subtextStyleModel.getTextColor(),
  71265. y: textRect.height + titleModel.get('itemGap'),
  71266. textVerticalAlign: 'top'
  71267. }, {disableBox: true}),
  71268. z2: 10
  71269. });
  71270. var link = titleModel.get('link');
  71271. var sublink = titleModel.get('sublink');
  71272. var triggerEvent = titleModel.get('triggerEvent', true);
  71273. textEl.silent = !link && !triggerEvent;
  71274. subTextEl.silent = !sublink && !triggerEvent;
  71275. if (link) {
  71276. textEl.on('click', function () {
  71277. window.open(link, '_' + titleModel.get('target'));
  71278. });
  71279. }
  71280. if (sublink) {
  71281. subTextEl.on('click', function () {
  71282. window.open(sublink, '_' + titleModel.get('subtarget'));
  71283. });
  71284. }
  71285. textEl.eventData = subTextEl.eventData = triggerEvent
  71286. ? {
  71287. componentType: 'title',
  71288. componentIndex: titleModel.componentIndex
  71289. }
  71290. : null;
  71291. group.add(textEl);
  71292. subText && group.add(subTextEl);
  71293. // If no subText, but add subTextEl, there will be an empty line.
  71294. var groupRect = group.getBoundingRect();
  71295. var layoutOption = titleModel.getBoxLayoutParams();
  71296. layoutOption.width = groupRect.width;
  71297. layoutOption.height = groupRect.height;
  71298. var layoutRect = getLayoutRect(
  71299. layoutOption, {
  71300. width: api.getWidth(),
  71301. height: api.getHeight()
  71302. }, titleModel.get('padding')
  71303. );
  71304. // Adjust text align based on position
  71305. if (!textAlign) {
  71306. // Align left if title is on the left. center and right is same
  71307. textAlign = titleModel.get('left') || titleModel.get('right');
  71308. if (textAlign === 'middle') {
  71309. textAlign = 'center';
  71310. }
  71311. // Adjust layout by text align
  71312. if (textAlign === 'right') {
  71313. layoutRect.x += layoutRect.width;
  71314. }
  71315. else if (textAlign === 'center') {
  71316. layoutRect.x += layoutRect.width / 2;
  71317. }
  71318. }
  71319. if (!textVerticalAlign) {
  71320. textVerticalAlign = titleModel.get('top') || titleModel.get('bottom');
  71321. if (textVerticalAlign === 'center') {
  71322. textVerticalAlign = 'middle';
  71323. }
  71324. if (textVerticalAlign === 'bottom') {
  71325. layoutRect.y += layoutRect.height;
  71326. }
  71327. else if (textVerticalAlign === 'middle') {
  71328. layoutRect.y += layoutRect.height / 2;
  71329. }
  71330. textVerticalAlign = textVerticalAlign || 'top';
  71331. }
  71332. group.attr('position', [layoutRect.x, layoutRect.y]);
  71333. var alignStyle = {
  71334. textAlign: textAlign,
  71335. textVerticalAlign: textVerticalAlign
  71336. };
  71337. textEl.setStyle(alignStyle);
  71338. subTextEl.setStyle(alignStyle);
  71339. // Render background
  71340. // Get groupRect again because textAlign has been changed
  71341. groupRect = group.getBoundingRect();
  71342. var padding = layoutRect.margin;
  71343. var style = titleModel.getItemStyle(['color', 'opacity']);
  71344. style.fill = titleModel.get('backgroundColor');
  71345. var rect = new Rect({
  71346. shape: {
  71347. x: groupRect.x - padding[3],
  71348. y: groupRect.y - padding[0],
  71349. width: groupRect.width + padding[1] + padding[3],
  71350. height: groupRect.height + padding[0] + padding[2],
  71351. r: titleModel.get('borderRadius')
  71352. },
  71353. style: style,
  71354. subPixelOptimize: true,
  71355. silent: true
  71356. });
  71357. group.add(rect);
  71358. }
  71359. });
  71360. /*
  71361. * Licensed to the Apache Software Foundation (ASF) under one
  71362. * or more contributor license agreements. See the NOTICE file
  71363. * distributed with this work for additional information
  71364. * regarding copyright ownership. The ASF licenses this file
  71365. * to you under the Apache License, Version 2.0 (the
  71366. * "License"); you may not use this file except in compliance
  71367. * with the License. You may obtain a copy of the License at
  71368. *
  71369. * http://www.apache.org/licenses/LICENSE-2.0
  71370. *
  71371. * Unless required by applicable law or agreed to in writing,
  71372. * software distributed under the License is distributed on an
  71373. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  71374. * KIND, either express or implied. See the License for the
  71375. * specific language governing permissions and limitations
  71376. * under the License.
  71377. */
  71378. var preprocessor$2 = function (option) {
  71379. var timelineOpt = option && option.timeline;
  71380. if (!isArray(timelineOpt)) {
  71381. timelineOpt = timelineOpt ? [timelineOpt] : [];
  71382. }
  71383. each$1(timelineOpt, function (opt) {
  71384. if (!opt) {
  71385. return;
  71386. }
  71387. compatibleEC2(opt);
  71388. });
  71389. };
  71390. function compatibleEC2(opt) {
  71391. var type = opt.type;
  71392. var ec2Types = {'number': 'value', 'time': 'time'};
  71393. // Compatible with ec2
  71394. if (ec2Types[type]) {
  71395. opt.axisType = ec2Types[type];
  71396. delete opt.type;
  71397. }
  71398. transferItem(opt);
  71399. if (has$1(opt, 'controlPosition')) {
  71400. var controlStyle = opt.controlStyle || (opt.controlStyle = {});
  71401. if (!has$1(controlStyle, 'position')) {
  71402. controlStyle.position = opt.controlPosition;
  71403. }
  71404. if (controlStyle.position === 'none' && !has$1(controlStyle, 'show')) {
  71405. controlStyle.show = false;
  71406. delete controlStyle.position;
  71407. }
  71408. delete opt.controlPosition;
  71409. }
  71410. each$1(opt.data || [], function (dataItem) {
  71411. if (isObject$1(dataItem) && !isArray(dataItem)) {
  71412. if (!has$1(dataItem, 'value') && has$1(dataItem, 'name')) {
  71413. // In ec2, using name as value.
  71414. dataItem.value = dataItem.name;
  71415. }
  71416. transferItem(dataItem);
  71417. }
  71418. });
  71419. }
  71420. function transferItem(opt) {
  71421. var itemStyle = opt.itemStyle || (opt.itemStyle = {});
  71422. var itemStyleEmphasis = itemStyle.emphasis || (itemStyle.emphasis = {});
  71423. // Transfer label out
  71424. var label = opt.label || (opt.label || {});
  71425. var labelNormal = label.normal || (label.normal = {});
  71426. var excludeLabelAttr = {normal: 1, emphasis: 1};
  71427. each$1(label, function (value, name) {
  71428. if (!excludeLabelAttr[name] && !has$1(labelNormal, name)) {
  71429. labelNormal[name] = value;
  71430. }
  71431. });
  71432. if (itemStyleEmphasis.label && !has$1(label, 'emphasis')) {
  71433. label.emphasis = itemStyleEmphasis.label;
  71434. delete itemStyleEmphasis.label;
  71435. }
  71436. }
  71437. function has$1(obj, attr) {
  71438. return obj.hasOwnProperty(attr);
  71439. }
  71440. /*
  71441. * Licensed to the Apache Software Foundation (ASF) under one
  71442. * or more contributor license agreements. See the NOTICE file
  71443. * distributed with this work for additional information
  71444. * regarding copyright ownership. The ASF licenses this file
  71445. * to you under the Apache License, Version 2.0 (the
  71446. * "License"); you may not use this file except in compliance
  71447. * with the License. You may obtain a copy of the License at
  71448. *
  71449. * http://www.apache.org/licenses/LICENSE-2.0
  71450. *
  71451. * Unless required by applicable law or agreed to in writing,
  71452. * software distributed under the License is distributed on an
  71453. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  71454. * KIND, either express or implied. See the License for the
  71455. * specific language governing permissions and limitations
  71456. * under the License.
  71457. */
  71458. ComponentModel.registerSubTypeDefaulter('timeline', function () {
  71459. // Only slider now.
  71460. return 'slider';
  71461. });
  71462. /*
  71463. * Licensed to the Apache Software Foundation (ASF) under one
  71464. * or more contributor license agreements. See the NOTICE file
  71465. * distributed with this work for additional information
  71466. * regarding copyright ownership. The ASF licenses this file
  71467. * to you under the Apache License, Version 2.0 (the
  71468. * "License"); you may not use this file except in compliance
  71469. * with the License. You may obtain a copy of the License at
  71470. *
  71471. * http://www.apache.org/licenses/LICENSE-2.0
  71472. *
  71473. * Unless required by applicable law or agreed to in writing,
  71474. * software distributed under the License is distributed on an
  71475. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  71476. * KIND, either express or implied. See the License for the
  71477. * specific language governing permissions and limitations
  71478. * under the License.
  71479. */
  71480. registerAction(
  71481. {type: 'timelineChange', event: 'timelineChanged', update: 'prepareAndUpdate'},
  71482. function (payload, ecModel) {
  71483. var timelineModel = ecModel.getComponent('timeline');
  71484. if (timelineModel && payload.currentIndex != null) {
  71485. timelineModel.setCurrentIndex(payload.currentIndex);
  71486. if (!timelineModel.get('loop', true) && timelineModel.isIndexMax()) {
  71487. timelineModel.setPlayState(false);
  71488. }
  71489. }
  71490. // Set normalized currentIndex to payload.
  71491. ecModel.resetOption('timeline');
  71492. return defaults({
  71493. currentIndex: timelineModel.option.currentIndex
  71494. }, payload);
  71495. }
  71496. );
  71497. registerAction(
  71498. {type: 'timelinePlayChange', event: 'timelinePlayChanged', update: 'update'},
  71499. function (payload, ecModel) {
  71500. var timelineModel = ecModel.getComponent('timeline');
  71501. if (timelineModel && payload.playState != null) {
  71502. timelineModel.setPlayState(payload.playState);
  71503. }
  71504. }
  71505. );
  71506. /*
  71507. * Licensed to the Apache Software Foundation (ASF) under one
  71508. * or more contributor license agreements. See the NOTICE file
  71509. * distributed with this work for additional information
  71510. * regarding copyright ownership. The ASF licenses this file
  71511. * to you under the Apache License, Version 2.0 (the
  71512. * "License"); you may not use this file except in compliance
  71513. * with the License. You may obtain a copy of the License at
  71514. *
  71515. * http://www.apache.org/licenses/LICENSE-2.0
  71516. *
  71517. * Unless required by applicable law or agreed to in writing,
  71518. * software distributed under the License is distributed on an
  71519. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  71520. * KIND, either express or implied. See the License for the
  71521. * specific language governing permissions and limitations
  71522. * under the License.
  71523. */
  71524. var TimelineModel = ComponentModel.extend({
  71525. type: 'timeline',
  71526. layoutMode: 'box',
  71527. /**
  71528. * @protected
  71529. */
  71530. defaultOption: {
  71531. zlevel: 0, // 一级层叠
  71532. z: 4, // 二级层叠
  71533. show: true,
  71534. axisType: 'time', // 模式是时间类型,支持 value, category
  71535. realtime: true,
  71536. left: '20%',
  71537. top: null,
  71538. right: '20%',
  71539. bottom: 0,
  71540. width: null,
  71541. height: 40,
  71542. padding: 5,
  71543. controlPosition: 'left', // 'left' 'right' 'top' 'bottom' 'none'
  71544. autoPlay: false,
  71545. rewind: false, // 反向播放
  71546. loop: true,
  71547. playInterval: 2000, // 播放时间间隔,单位ms
  71548. currentIndex: 0,
  71549. itemStyle: {},
  71550. label: {
  71551. color: '#000'
  71552. },
  71553. data: []
  71554. },
  71555. /**
  71556. * @override
  71557. */
  71558. init: function (option, parentModel, ecModel) {
  71559. /**
  71560. * @private
  71561. * @type {module:echarts/data/List}
  71562. */
  71563. this._data;
  71564. /**
  71565. * @private
  71566. * @type {Array.<string>}
  71567. */
  71568. this._names;
  71569. this.mergeDefaultAndTheme(option, ecModel);
  71570. this._initData();
  71571. },
  71572. /**
  71573. * @override
  71574. */
  71575. mergeOption: function (option) {
  71576. TimelineModel.superApply(this, 'mergeOption', arguments);
  71577. this._initData();
  71578. },
  71579. /**
  71580. * @param {number} [currentIndex]
  71581. */
  71582. setCurrentIndex: function (currentIndex) {
  71583. if (currentIndex == null) {
  71584. currentIndex = this.option.currentIndex;
  71585. }
  71586. var count = this._data.count();
  71587. if (this.option.loop) {
  71588. currentIndex = (currentIndex % count + count) % count;
  71589. }
  71590. else {
  71591. currentIndex >= count && (currentIndex = count - 1);
  71592. currentIndex < 0 && (currentIndex = 0);
  71593. }
  71594. this.option.currentIndex = currentIndex;
  71595. },
  71596. /**
  71597. * @return {number} currentIndex
  71598. */
  71599. getCurrentIndex: function () {
  71600. return this.option.currentIndex;
  71601. },
  71602. /**
  71603. * @return {boolean}
  71604. */
  71605. isIndexMax: function () {
  71606. return this.getCurrentIndex() >= this._data.count() - 1;
  71607. },
  71608. /**
  71609. * @param {boolean} state true: play, false: stop
  71610. */
  71611. setPlayState: function (state) {
  71612. this.option.autoPlay = !!state;
  71613. },
  71614. /**
  71615. * @return {boolean} true: play, false: stop
  71616. */
  71617. getPlayState: function () {
  71618. return !!this.option.autoPlay;
  71619. },
  71620. /**
  71621. * @private
  71622. */
  71623. _initData: function () {
  71624. var thisOption = this.option;
  71625. var dataArr = thisOption.data || [];
  71626. var axisType = thisOption.axisType;
  71627. var names = this._names = [];
  71628. if (axisType === 'category') {
  71629. var idxArr = [];
  71630. each$1(dataArr, function (item, index) {
  71631. var value = getDataItemValue(item);
  71632. var newItem;
  71633. if (isObject$1(item)) {
  71634. newItem = clone(item);
  71635. newItem.value = index;
  71636. }
  71637. else {
  71638. newItem = index;
  71639. }
  71640. idxArr.push(newItem);
  71641. if (!isString(value) && (value == null || isNaN(value))) {
  71642. value = '';
  71643. }
  71644. names.push(value + '');
  71645. });
  71646. dataArr = idxArr;
  71647. }
  71648. var dimType = ({category: 'ordinal', time: 'time'})[axisType] || 'number';
  71649. var data = this._data = new List([{name: 'value', type: dimType}], this);
  71650. data.initData(dataArr, names);
  71651. },
  71652. getData: function () {
  71653. return this._data;
  71654. },
  71655. /**
  71656. * @public
  71657. * @return {Array.<string>} categoreis
  71658. */
  71659. getCategories: function () {
  71660. if (this.get('axisType') === 'category') {
  71661. return this._names.slice();
  71662. }
  71663. }
  71664. });
  71665. /*
  71666. * Licensed to the Apache Software Foundation (ASF) under one
  71667. * or more contributor license agreements. See the NOTICE file
  71668. * distributed with this work for additional information
  71669. * regarding copyright ownership. The ASF licenses this file
  71670. * to you under the Apache License, Version 2.0 (the
  71671. * "License"); you may not use this file except in compliance
  71672. * with the License. You may obtain a copy of the License at
  71673. *
  71674. * http://www.apache.org/licenses/LICENSE-2.0
  71675. *
  71676. * Unless required by applicable law or agreed to in writing,
  71677. * software distributed under the License is distributed on an
  71678. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  71679. * KIND, either express or implied. See the License for the
  71680. * specific language governing permissions and limitations
  71681. * under the License.
  71682. */
  71683. var SliderTimelineModel = TimelineModel.extend({
  71684. type: 'timeline.slider',
  71685. /**
  71686. * @protected
  71687. */
  71688. defaultOption: {
  71689. backgroundColor: 'rgba(0,0,0,0)', // 时间轴背景颜色
  71690. borderColor: '#ccc', // 时间轴边框颜色
  71691. borderWidth: 0, // 时间轴边框线宽,单位px,默认为0(无边框)
  71692. orient: 'horizontal', // 'vertical'
  71693. inverse: false,
  71694. tooltip: { // boolean or Object
  71695. trigger: 'item' // data item may also have tootip attr.
  71696. },
  71697. symbol: 'emptyCircle',
  71698. symbolSize: 10,
  71699. lineStyle: {
  71700. show: true,
  71701. width: 2,
  71702. color: '#304654'
  71703. },
  71704. label: { // 文本标签
  71705. position: 'auto', // auto left right top bottom
  71706. // When using number, label position is not
  71707. // restricted by viewRect.
  71708. // positive: right/bottom, negative: left/top
  71709. show: true,
  71710. interval: 'auto',
  71711. rotate: 0,
  71712. // formatter: null,
  71713. // 其余属性默认使用全局文本样式,详见TEXTSTYLE
  71714. color: '#304654'
  71715. },
  71716. itemStyle: {
  71717. color: '#304654',
  71718. borderWidth: 1
  71719. },
  71720. checkpointStyle: {
  71721. symbol: 'circle',
  71722. symbolSize: 13,
  71723. color: '#c23531',
  71724. borderWidth: 5,
  71725. borderColor: 'rgba(194,53,49, 0.5)',
  71726. animation: true,
  71727. animationDuration: 300,
  71728. animationEasing: 'quinticInOut'
  71729. },
  71730. controlStyle: {
  71731. show: true,
  71732. showPlayBtn: true,
  71733. showPrevBtn: true,
  71734. showNextBtn: true,
  71735. itemSize: 22,
  71736. itemGap: 12,
  71737. position: 'left', // 'left' 'right' 'top' 'bottom'
  71738. 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
  71739. 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
  71740. 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
  71741. 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
  71742. color: '#304654',
  71743. borderColor: '#304654',
  71744. borderWidth: 1
  71745. },
  71746. emphasis: {
  71747. label: {
  71748. show: true,
  71749. // 其余属性默认使用全局文本样式,详见TEXTSTYLE
  71750. color: '#c23531'
  71751. },
  71752. itemStyle: {
  71753. color: '#c23531'
  71754. },
  71755. controlStyle: {
  71756. color: '#c23531',
  71757. borderColor: '#c23531',
  71758. borderWidth: 2
  71759. }
  71760. },
  71761. data: []
  71762. }
  71763. });
  71764. mixin(SliderTimelineModel, dataFormatMixin);
  71765. /*
  71766. * Licensed to the Apache Software Foundation (ASF) under one
  71767. * or more contributor license agreements. See the NOTICE file
  71768. * distributed with this work for additional information
  71769. * regarding copyright ownership. The ASF licenses this file
  71770. * to you under the Apache License, Version 2.0 (the
  71771. * "License"); you may not use this file except in compliance
  71772. * with the License. You may obtain a copy of the License at
  71773. *
  71774. * http://www.apache.org/licenses/LICENSE-2.0
  71775. *
  71776. * Unless required by applicable law or agreed to in writing,
  71777. * software distributed under the License is distributed on an
  71778. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  71779. * KIND, either express or implied. See the License for the
  71780. * specific language governing permissions and limitations
  71781. * under the License.
  71782. */
  71783. var TimelineView = Component$1.extend({
  71784. type: 'timeline'
  71785. });
  71786. /*
  71787. * Licensed to the Apache Software Foundation (ASF) under one
  71788. * or more contributor license agreements. See the NOTICE file
  71789. * distributed with this work for additional information
  71790. * regarding copyright ownership. The ASF licenses this file
  71791. * to you under the Apache License, Version 2.0 (the
  71792. * "License"); you may not use this file except in compliance
  71793. * with the License. You may obtain a copy of the License at
  71794. *
  71795. * http://www.apache.org/licenses/LICENSE-2.0
  71796. *
  71797. * Unless required by applicable law or agreed to in writing,
  71798. * software distributed under the License is distributed on an
  71799. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  71800. * KIND, either express or implied. See the License for the
  71801. * specific language governing permissions and limitations
  71802. * under the License.
  71803. */
  71804. /**
  71805. * Extend axis 2d
  71806. * @constructor module:echarts/coord/cartesian/Axis2D
  71807. * @extends {module:echarts/coord/cartesian/Axis}
  71808. * @param {string} dim
  71809. * @param {*} scale
  71810. * @param {Array.<number>} coordExtent
  71811. * @param {string} axisType
  71812. * @param {string} position
  71813. */
  71814. var TimelineAxis = function (dim, scale, coordExtent, axisType) {
  71815. Axis.call(this, dim, scale, coordExtent);
  71816. /**
  71817. * Axis type
  71818. * - 'category'
  71819. * - 'value'
  71820. * - 'time'
  71821. * - 'log'
  71822. * @type {string}
  71823. */
  71824. this.type = axisType || 'value';
  71825. /**
  71826. * Axis model
  71827. * @param {module:echarts/component/TimelineModel}
  71828. */
  71829. this.model = null;
  71830. };
  71831. TimelineAxis.prototype = {
  71832. constructor: TimelineAxis,
  71833. /**
  71834. * @override
  71835. */
  71836. getLabelModel: function () {
  71837. return this.model.getModel('label');
  71838. },
  71839. /**
  71840. * @override
  71841. */
  71842. isHorizontal: function () {
  71843. return this.model.get('orient') === 'horizontal';
  71844. }
  71845. };
  71846. inherits(TimelineAxis, Axis);
  71847. /*
  71848. * Licensed to the Apache Software Foundation (ASF) under one
  71849. * or more contributor license agreements. See the NOTICE file
  71850. * distributed with this work for additional information
  71851. * regarding copyright ownership. The ASF licenses this file
  71852. * to you under the Apache License, Version 2.0 (the
  71853. * "License"); you may not use this file except in compliance
  71854. * with the License. You may obtain a copy of the License at
  71855. *
  71856. * http://www.apache.org/licenses/LICENSE-2.0
  71857. *
  71858. * Unless required by applicable law or agreed to in writing,
  71859. * software distributed under the License is distributed on an
  71860. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  71861. * KIND, either express or implied. See the License for the
  71862. * specific language governing permissions and limitations
  71863. * under the License.
  71864. */
  71865. var bind$4 = bind;
  71866. var each$24 = each$1;
  71867. var PI$5 = Math.PI;
  71868. TimelineView.extend({
  71869. type: 'timeline.slider',
  71870. init: function (ecModel, api) {
  71871. this.api = api;
  71872. /**
  71873. * @private
  71874. * @type {module:echarts/component/timeline/TimelineAxis}
  71875. */
  71876. this._axis;
  71877. /**
  71878. * @private
  71879. * @type {module:zrender/core/BoundingRect}
  71880. */
  71881. this._viewRect;
  71882. /**
  71883. * @type {number}
  71884. */
  71885. this._timer;
  71886. /**
  71887. * @type {module:zrender/Element}
  71888. */
  71889. this._currentPointer;
  71890. /**
  71891. * @type {module:zrender/container/Group}
  71892. */
  71893. this._mainGroup;
  71894. /**
  71895. * @type {module:zrender/container/Group}
  71896. */
  71897. this._labelGroup;
  71898. },
  71899. /**
  71900. * @override
  71901. */
  71902. render: function (timelineModel, ecModel, api, payload) {
  71903. this.model = timelineModel;
  71904. this.api = api;
  71905. this.ecModel = ecModel;
  71906. this.group.removeAll();
  71907. if (timelineModel.get('show', true)) {
  71908. var layoutInfo = this._layout(timelineModel, api);
  71909. var mainGroup = this._createGroup('mainGroup');
  71910. var labelGroup = this._createGroup('labelGroup');
  71911. /**
  71912. * @private
  71913. * @type {module:echarts/component/timeline/TimelineAxis}
  71914. */
  71915. var axis = this._axis = this._createAxis(layoutInfo, timelineModel);
  71916. timelineModel.formatTooltip = function (dataIndex) {
  71917. return encodeHTML(axis.scale.getLabel(dataIndex));
  71918. };
  71919. each$24(
  71920. ['AxisLine', 'AxisTick', 'Control', 'CurrentPointer'],
  71921. function (name) {
  71922. this['_render' + name](layoutInfo, mainGroup, axis, timelineModel);
  71923. },
  71924. this
  71925. );
  71926. this._renderAxisLabel(layoutInfo, labelGroup, axis, timelineModel);
  71927. this._position(layoutInfo, timelineModel);
  71928. }
  71929. this._doPlayStop();
  71930. },
  71931. /**
  71932. * @override
  71933. */
  71934. remove: function () {
  71935. this._clearTimer();
  71936. this.group.removeAll();
  71937. },
  71938. /**
  71939. * @override
  71940. */
  71941. dispose: function () {
  71942. this._clearTimer();
  71943. },
  71944. _layout: function (timelineModel, api) {
  71945. var labelPosOpt = timelineModel.get('label.position');
  71946. var orient = timelineModel.get('orient');
  71947. var viewRect = getViewRect$4(timelineModel, api);
  71948. // Auto label offset.
  71949. if (labelPosOpt == null || labelPosOpt === 'auto') {
  71950. labelPosOpt = orient === 'horizontal'
  71951. ? ((viewRect.y + viewRect.height / 2) < api.getHeight() / 2 ? '-' : '+')
  71952. : ((viewRect.x + viewRect.width / 2) < api.getWidth() / 2 ? '+' : '-');
  71953. }
  71954. else if (isNaN(labelPosOpt)) {
  71955. labelPosOpt = ({
  71956. horizontal: {top: '-', bottom: '+'},
  71957. vertical: {left: '-', right: '+'}
  71958. })[orient][labelPosOpt];
  71959. }
  71960. var labelAlignMap = {
  71961. horizontal: 'center',
  71962. vertical: (labelPosOpt >= 0 || labelPosOpt === '+') ? 'left' : 'right'
  71963. };
  71964. var labelBaselineMap = {
  71965. horizontal: (labelPosOpt >= 0 || labelPosOpt === '+') ? 'top' : 'bottom',
  71966. vertical: 'middle'
  71967. };
  71968. var rotationMap = {
  71969. horizontal: 0,
  71970. vertical: PI$5 / 2
  71971. };
  71972. // Position
  71973. var mainLength = orient === 'vertical' ? viewRect.height : viewRect.width;
  71974. var controlModel = timelineModel.getModel('controlStyle');
  71975. var showControl = controlModel.get('show', true);
  71976. var controlSize = showControl ? controlModel.get('itemSize') : 0;
  71977. var controlGap = showControl ? controlModel.get('itemGap') : 0;
  71978. var sizePlusGap = controlSize + controlGap;
  71979. // Special label rotate.
  71980. var labelRotation = timelineModel.get('label.rotate') || 0;
  71981. labelRotation = labelRotation * PI$5 / 180; // To radian.
  71982. var playPosition;
  71983. var prevBtnPosition;
  71984. var nextBtnPosition;
  71985. var axisExtent;
  71986. var controlPosition = controlModel.get('position', true);
  71987. var showPlayBtn = showControl && controlModel.get('showPlayBtn', true);
  71988. var showPrevBtn = showControl && controlModel.get('showPrevBtn', true);
  71989. var showNextBtn = showControl && controlModel.get('showNextBtn', true);
  71990. var xLeft = 0;
  71991. var xRight = mainLength;
  71992. // position[0] means left, position[1] means middle.
  71993. if (controlPosition === 'left' || controlPosition === 'bottom') {
  71994. showPlayBtn && (playPosition = [0, 0], xLeft += sizePlusGap);
  71995. showPrevBtn && (prevBtnPosition = [xLeft, 0], xLeft += sizePlusGap);
  71996. showNextBtn && (nextBtnPosition = [xRight - controlSize, 0], xRight -= sizePlusGap);
  71997. }
  71998. else { // 'top' 'right'
  71999. showPlayBtn && (playPosition = [xRight - controlSize, 0], xRight -= sizePlusGap);
  72000. showPrevBtn && (prevBtnPosition = [0, 0], xLeft += sizePlusGap);
  72001. showNextBtn && (nextBtnPosition = [xRight - controlSize, 0], xRight -= sizePlusGap);
  72002. }
  72003. axisExtent = [xLeft, xRight];
  72004. if (timelineModel.get('inverse')) {
  72005. axisExtent.reverse();
  72006. }
  72007. return {
  72008. viewRect: viewRect,
  72009. mainLength: mainLength,
  72010. orient: orient,
  72011. rotation: rotationMap[orient],
  72012. labelRotation: labelRotation,
  72013. labelPosOpt: labelPosOpt,
  72014. labelAlign: timelineModel.get('label.align') || labelAlignMap[orient],
  72015. labelBaseline: timelineModel.get('label.verticalAlign')
  72016. || timelineModel.get('label.baseline')
  72017. || labelBaselineMap[orient],
  72018. // Based on mainGroup.
  72019. playPosition: playPosition,
  72020. prevBtnPosition: prevBtnPosition,
  72021. nextBtnPosition: nextBtnPosition,
  72022. axisExtent: axisExtent,
  72023. controlSize: controlSize,
  72024. controlGap: controlGap
  72025. };
  72026. },
  72027. _position: function (layoutInfo, timelineModel) {
  72028. // Position is be called finally, because bounding rect is needed for
  72029. // adapt content to fill viewRect (auto adapt offset).
  72030. // Timeline may be not all in the viewRect when 'offset' is specified
  72031. // as a number, because it is more appropriate that label aligns at
  72032. // 'offset' but not the other edge defined by viewRect.
  72033. var mainGroup = this._mainGroup;
  72034. var labelGroup = this._labelGroup;
  72035. var viewRect = layoutInfo.viewRect;
  72036. if (layoutInfo.orient === 'vertical') {
  72037. // transform to horizontal, inverse rotate by left-top point.
  72038. var m = create$1();
  72039. var rotateOriginX = viewRect.x;
  72040. var rotateOriginY = viewRect.y + viewRect.height;
  72041. translate(m, m, [-rotateOriginX, -rotateOriginY]);
  72042. rotate(m, m, -PI$5 / 2);
  72043. translate(m, m, [rotateOriginX, rotateOriginY]);
  72044. viewRect = viewRect.clone();
  72045. viewRect.applyTransform(m);
  72046. }
  72047. var viewBound = getBound(viewRect);
  72048. var mainBound = getBound(mainGroup.getBoundingRect());
  72049. var labelBound = getBound(labelGroup.getBoundingRect());
  72050. var mainPosition = mainGroup.position;
  72051. var labelsPosition = labelGroup.position;
  72052. labelsPosition[0] = mainPosition[0] = viewBound[0][0];
  72053. var labelPosOpt = layoutInfo.labelPosOpt;
  72054. if (isNaN(labelPosOpt)) { // '+' or '-'
  72055. var mainBoundIdx = labelPosOpt === '+' ? 0 : 1;
  72056. toBound(mainPosition, mainBound, viewBound, 1, mainBoundIdx);
  72057. toBound(labelsPosition, labelBound, viewBound, 1, 1 - mainBoundIdx);
  72058. }
  72059. else {
  72060. var mainBoundIdx = labelPosOpt >= 0 ? 0 : 1;
  72061. toBound(mainPosition, mainBound, viewBound, 1, mainBoundIdx);
  72062. labelsPosition[1] = mainPosition[1] + labelPosOpt;
  72063. }
  72064. mainGroup.attr('position', mainPosition);
  72065. labelGroup.attr('position', labelsPosition);
  72066. mainGroup.rotation = labelGroup.rotation = layoutInfo.rotation;
  72067. setOrigin(mainGroup);
  72068. setOrigin(labelGroup);
  72069. function setOrigin(targetGroup) {
  72070. var pos = targetGroup.position;
  72071. targetGroup.origin = [
  72072. viewBound[0][0] - pos[0],
  72073. viewBound[1][0] - pos[1]
  72074. ];
  72075. }
  72076. function getBound(rect) {
  72077. // [[xmin, xmax], [ymin, ymax]]
  72078. return [
  72079. [rect.x, rect.x + rect.width],
  72080. [rect.y, rect.y + rect.height]
  72081. ];
  72082. }
  72083. function toBound(fromPos, from, to, dimIdx, boundIdx) {
  72084. fromPos[dimIdx] += to[dimIdx][boundIdx] - from[dimIdx][boundIdx];
  72085. }
  72086. },
  72087. _createAxis: function (layoutInfo, timelineModel) {
  72088. var data = timelineModel.getData();
  72089. var axisType = timelineModel.get('axisType');
  72090. var scale = createScaleByModel(timelineModel, axisType);
  72091. // Customize scale. The `tickValue` is `dataIndex`.
  72092. scale.getTicks = function () {
  72093. return data.mapArray(['value'], function (value) {
  72094. return value;
  72095. });
  72096. };
  72097. var dataExtent = data.getDataExtent('value');
  72098. scale.setExtent(dataExtent[0], dataExtent[1]);
  72099. scale.niceTicks();
  72100. var axis = new TimelineAxis('value', scale, layoutInfo.axisExtent, axisType);
  72101. axis.model = timelineModel;
  72102. return axis;
  72103. },
  72104. _createGroup: function (name) {
  72105. var newGroup = this['_' + name] = new Group();
  72106. this.group.add(newGroup);
  72107. return newGroup;
  72108. },
  72109. _renderAxisLine: function (layoutInfo, group, axis, timelineModel) {
  72110. var axisExtent = axis.getExtent();
  72111. if (!timelineModel.get('lineStyle.show')) {
  72112. return;
  72113. }
  72114. group.add(new Line({
  72115. shape: {
  72116. x1: axisExtent[0], y1: 0,
  72117. x2: axisExtent[1], y2: 0
  72118. },
  72119. style: extend(
  72120. {lineCap: 'round'},
  72121. timelineModel.getModel('lineStyle').getLineStyle()
  72122. ),
  72123. silent: true,
  72124. z2: 1
  72125. }));
  72126. },
  72127. /**
  72128. * @private
  72129. */
  72130. _renderAxisTick: function (layoutInfo, group, axis, timelineModel) {
  72131. var data = timelineModel.getData();
  72132. // Show all ticks, despite ignoring strategy.
  72133. var ticks = axis.scale.getTicks();
  72134. // The value is dataIndex, see the costomized scale.
  72135. each$24(ticks, function (value) {
  72136. var tickCoord = axis.dataToCoord(value);
  72137. var itemModel = data.getItemModel(value);
  72138. var itemStyleModel = itemModel.getModel('itemStyle');
  72139. var hoverStyleModel = itemModel.getModel('emphasis.itemStyle');
  72140. var symbolOpt = {
  72141. position: [tickCoord, 0],
  72142. onclick: bind$4(this._changeTimeline, this, value)
  72143. };
  72144. var el = giveSymbol(itemModel, itemStyleModel, group, symbolOpt);
  72145. setHoverStyle(el, hoverStyleModel.getItemStyle());
  72146. if (itemModel.get('tooltip')) {
  72147. el.dataIndex = value;
  72148. el.dataModel = timelineModel;
  72149. }
  72150. else {
  72151. el.dataIndex = el.dataModel = null;
  72152. }
  72153. }, this);
  72154. },
  72155. /**
  72156. * @private
  72157. */
  72158. _renderAxisLabel: function (layoutInfo, group, axis, timelineModel) {
  72159. var labelModel = axis.getLabelModel();
  72160. if (!labelModel.get('show')) {
  72161. return;
  72162. }
  72163. var data = timelineModel.getData();
  72164. var labels = axis.getViewLabels();
  72165. each$24(labels, function (labelItem) {
  72166. // The tickValue is dataIndex, see the costomized scale.
  72167. var dataIndex = labelItem.tickValue;
  72168. var itemModel = data.getItemModel(dataIndex);
  72169. var normalLabelModel = itemModel.getModel('label');
  72170. var hoverLabelModel = itemModel.getModel('emphasis.label');
  72171. var tickCoord = axis.dataToCoord(labelItem.tickValue);
  72172. var textEl = new Text({
  72173. position: [tickCoord, 0],
  72174. rotation: layoutInfo.labelRotation - layoutInfo.rotation,
  72175. onclick: bind$4(this._changeTimeline, this, dataIndex),
  72176. silent: false
  72177. });
  72178. setTextStyle(textEl.style, normalLabelModel, {
  72179. text: labelItem.formattedLabel,
  72180. textAlign: layoutInfo.labelAlign,
  72181. textVerticalAlign: layoutInfo.labelBaseline
  72182. });
  72183. group.add(textEl);
  72184. setHoverStyle(
  72185. textEl, setTextStyle({}, hoverLabelModel)
  72186. );
  72187. }, this);
  72188. },
  72189. /**
  72190. * @private
  72191. */
  72192. _renderControl: function (layoutInfo, group, axis, timelineModel) {
  72193. var controlSize = layoutInfo.controlSize;
  72194. var rotation = layoutInfo.rotation;
  72195. var itemStyle = timelineModel.getModel('controlStyle').getItemStyle();
  72196. var hoverStyle = timelineModel.getModel('emphasis.controlStyle').getItemStyle();
  72197. var rect = [0, -controlSize / 2, controlSize, controlSize];
  72198. var playState = timelineModel.getPlayState();
  72199. var inverse = timelineModel.get('inverse', true);
  72200. makeBtn(
  72201. layoutInfo.nextBtnPosition,
  72202. 'controlStyle.nextIcon',
  72203. bind$4(this._changeTimeline, this, inverse ? '-' : '+')
  72204. );
  72205. makeBtn(
  72206. layoutInfo.prevBtnPosition,
  72207. 'controlStyle.prevIcon',
  72208. bind$4(this._changeTimeline, this, inverse ? '+' : '-')
  72209. );
  72210. makeBtn(
  72211. layoutInfo.playPosition,
  72212. 'controlStyle.' + (playState ? 'stopIcon' : 'playIcon'),
  72213. bind$4(this._handlePlayClick, this, !playState),
  72214. true
  72215. );
  72216. function makeBtn(position, iconPath, onclick, willRotate) {
  72217. if (!position) {
  72218. return;
  72219. }
  72220. var opt = {
  72221. position: position,
  72222. origin: [controlSize / 2, 0],
  72223. rotation: willRotate ? -rotation : 0,
  72224. rectHover: true,
  72225. style: itemStyle,
  72226. onclick: onclick
  72227. };
  72228. var btn = makeIcon(timelineModel, iconPath, rect, opt);
  72229. group.add(btn);
  72230. setHoverStyle(btn, hoverStyle);
  72231. }
  72232. },
  72233. _renderCurrentPointer: function (layoutInfo, group, axis, timelineModel) {
  72234. var data = timelineModel.getData();
  72235. var currentIndex = timelineModel.getCurrentIndex();
  72236. var pointerModel = data.getItemModel(currentIndex).getModel('checkpointStyle');
  72237. var me = this;
  72238. var callback = {
  72239. onCreate: function (pointer) {
  72240. pointer.draggable = true;
  72241. pointer.drift = bind$4(me._handlePointerDrag, me);
  72242. pointer.ondragend = bind$4(me._handlePointerDragend, me);
  72243. pointerMoveTo(pointer, currentIndex, axis, timelineModel, true);
  72244. },
  72245. onUpdate: function (pointer) {
  72246. pointerMoveTo(pointer, currentIndex, axis, timelineModel);
  72247. }
  72248. };
  72249. // Reuse when exists, for animation and drag.
  72250. this._currentPointer = giveSymbol(
  72251. pointerModel, pointerModel, this._mainGroup, {}, this._currentPointer, callback
  72252. );
  72253. },
  72254. _handlePlayClick: function (nextState) {
  72255. this._clearTimer();
  72256. this.api.dispatchAction({
  72257. type: 'timelinePlayChange',
  72258. playState: nextState,
  72259. from: this.uid
  72260. });
  72261. },
  72262. _handlePointerDrag: function (dx, dy, e) {
  72263. this._clearTimer();
  72264. this._pointerChangeTimeline([e.offsetX, e.offsetY]);
  72265. },
  72266. _handlePointerDragend: function (e) {
  72267. this._pointerChangeTimeline([e.offsetX, e.offsetY], true);
  72268. },
  72269. _pointerChangeTimeline: function (mousePos, trigger) {
  72270. var toCoord = this._toAxisCoord(mousePos)[0];
  72271. var axis = this._axis;
  72272. var axisExtent = asc(axis.getExtent().slice());
  72273. toCoord > axisExtent[1] && (toCoord = axisExtent[1]);
  72274. toCoord < axisExtent[0] && (toCoord = axisExtent[0]);
  72275. this._currentPointer.position[0] = toCoord;
  72276. this._currentPointer.dirty();
  72277. var targetDataIndex = this._findNearestTick(toCoord);
  72278. var timelineModel = this.model;
  72279. if (trigger || (
  72280. targetDataIndex !== timelineModel.getCurrentIndex()
  72281. && timelineModel.get('realtime')
  72282. )) {
  72283. this._changeTimeline(targetDataIndex);
  72284. }
  72285. },
  72286. _doPlayStop: function () {
  72287. this._clearTimer();
  72288. if (this.model.getPlayState()) {
  72289. this._timer = setTimeout(
  72290. bind$4(handleFrame, this),
  72291. this.model.get('playInterval')
  72292. );
  72293. }
  72294. function handleFrame() {
  72295. // Do not cache
  72296. var timelineModel = this.model;
  72297. this._changeTimeline(
  72298. timelineModel.getCurrentIndex()
  72299. + (timelineModel.get('rewind', true) ? -1 : 1)
  72300. );
  72301. }
  72302. },
  72303. _toAxisCoord: function (vertex) {
  72304. var trans = this._mainGroup.getLocalTransform();
  72305. return applyTransform$1(vertex, trans, true);
  72306. },
  72307. _findNearestTick: function (axisCoord) {
  72308. var data = this.model.getData();
  72309. var dist = Infinity;
  72310. var targetDataIndex;
  72311. var axis = this._axis;
  72312. data.each(['value'], function (value, dataIndex) {
  72313. var coord = axis.dataToCoord(value);
  72314. var d = Math.abs(coord - axisCoord);
  72315. if (d < dist) {
  72316. dist = d;
  72317. targetDataIndex = dataIndex;
  72318. }
  72319. });
  72320. return targetDataIndex;
  72321. },
  72322. _clearTimer: function () {
  72323. if (this._timer) {
  72324. clearTimeout(this._timer);
  72325. this._timer = null;
  72326. }
  72327. },
  72328. _changeTimeline: function (nextIndex) {
  72329. var currentIndex = this.model.getCurrentIndex();
  72330. if (nextIndex === '+') {
  72331. nextIndex = currentIndex + 1;
  72332. }
  72333. else if (nextIndex === '-') {
  72334. nextIndex = currentIndex - 1;
  72335. }
  72336. this.api.dispatchAction({
  72337. type: 'timelineChange',
  72338. currentIndex: nextIndex,
  72339. from: this.uid
  72340. });
  72341. }
  72342. });
  72343. function getViewRect$4(model, api) {
  72344. return getLayoutRect(
  72345. model.getBoxLayoutParams(),
  72346. {
  72347. width: api.getWidth(),
  72348. height: api.getHeight()
  72349. },
  72350. model.get('padding')
  72351. );
  72352. }
  72353. function makeIcon(timelineModel, objPath, rect, opts) {
  72354. var icon = makePath(
  72355. timelineModel.get(objPath).replace(/^path:\/\//, ''),
  72356. clone(opts || {}),
  72357. new BoundingRect(rect[0], rect[1], rect[2], rect[3]),
  72358. 'center'
  72359. );
  72360. return icon;
  72361. }
  72362. /**
  72363. * Create symbol or update symbol
  72364. * opt: basic position and event handlers
  72365. */
  72366. function giveSymbol(hostModel, itemStyleModel, group, opt, symbol, callback) {
  72367. var color = itemStyleModel.get('color');
  72368. if (!symbol) {
  72369. var symbolType = hostModel.get('symbol');
  72370. symbol = createSymbol(symbolType, -1, -1, 2, 2, color);
  72371. symbol.setStyle('strokeNoScale', true);
  72372. group.add(symbol);
  72373. callback && callback.onCreate(symbol);
  72374. }
  72375. else {
  72376. symbol.setColor(color);
  72377. group.add(symbol); // Group may be new, also need to add.
  72378. callback && callback.onUpdate(symbol);
  72379. }
  72380. // Style
  72381. var itemStyle = itemStyleModel.getItemStyle(['color', 'symbol', 'symbolSize']);
  72382. symbol.setStyle(itemStyle);
  72383. // Transform and events.
  72384. opt = merge({
  72385. rectHover: true,
  72386. z2: 100
  72387. }, opt, true);
  72388. var symbolSize = hostModel.get('symbolSize');
  72389. symbolSize = symbolSize instanceof Array
  72390. ? symbolSize.slice()
  72391. : [+symbolSize, +symbolSize];
  72392. symbolSize[0] /= 2;
  72393. symbolSize[1] /= 2;
  72394. opt.scale = symbolSize;
  72395. var symbolOffset = hostModel.get('symbolOffset');
  72396. if (symbolOffset) {
  72397. var pos = opt.position = opt.position || [0, 0];
  72398. pos[0] += parsePercent$1(symbolOffset[0], symbolSize[0]);
  72399. pos[1] += parsePercent$1(symbolOffset[1], symbolSize[1]);
  72400. }
  72401. var symbolRotate = hostModel.get('symbolRotate');
  72402. opt.rotation = (symbolRotate || 0) * Math.PI / 180 || 0;
  72403. symbol.attr(opt);
  72404. // FIXME
  72405. // (1) When symbol.style.strokeNoScale is true and updateTransform is not performed,
  72406. // getBoundingRect will return wrong result.
  72407. // (This is supposed to be resolved in zrender, but it is a little difficult to
  72408. // leverage performance and auto updateTransform)
  72409. // (2) All of ancesters of symbol do not scale, so we can just updateTransform symbol.
  72410. symbol.updateTransform();
  72411. return symbol;
  72412. }
  72413. function pointerMoveTo(pointer, dataIndex, axis, timelineModel, noAnimation) {
  72414. if (pointer.dragging) {
  72415. return;
  72416. }
  72417. var pointerModel = timelineModel.getModel('checkpointStyle');
  72418. var toCoord = axis.dataToCoord(timelineModel.getData().get(['value'], dataIndex));
  72419. if (noAnimation || !pointerModel.get('animation', true)) {
  72420. pointer.attr({position: [toCoord, 0]});
  72421. }
  72422. else {
  72423. pointer.stopAnimation(true);
  72424. pointer.animateTo(
  72425. {position: [toCoord, 0]},
  72426. pointerModel.get('animationDuration', true),
  72427. pointerModel.get('animationEasing', true)
  72428. );
  72429. }
  72430. }
  72431. /*
  72432. * Licensed to the Apache Software Foundation (ASF) under one
  72433. * or more contributor license agreements. See the NOTICE file
  72434. * distributed with this work for additional information
  72435. * regarding copyright ownership. The ASF licenses this file
  72436. * to you under the Apache License, Version 2.0 (the
  72437. * "License"); you may not use this file except in compliance
  72438. * with the License. You may obtain a copy of the License at
  72439. *
  72440. * http://www.apache.org/licenses/LICENSE-2.0
  72441. *
  72442. * Unless required by applicable law or agreed to in writing,
  72443. * software distributed under the License is distributed on an
  72444. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  72445. * KIND, either express or implied. See the License for the
  72446. * specific language governing permissions and limitations
  72447. * under the License.
  72448. */
  72449. /**
  72450. * DataZoom component entry
  72451. */
  72452. registerPreprocessor(preprocessor$2);
  72453. /*
  72454. * Licensed to the Apache Software Foundation (ASF) under one
  72455. * or more contributor license agreements. See the NOTICE file
  72456. * distributed with this work for additional information
  72457. * regarding copyright ownership. The ASF licenses this file
  72458. * to you under the Apache License, Version 2.0 (the
  72459. * "License"); you may not use this file except in compliance
  72460. * with the License. You may obtain a copy of the License at
  72461. *
  72462. * http://www.apache.org/licenses/LICENSE-2.0
  72463. *
  72464. * Unless required by applicable law or agreed to in writing,
  72465. * software distributed under the License is distributed on an
  72466. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  72467. * KIND, either express or implied. See the License for the
  72468. * specific language governing permissions and limitations
  72469. * under the License.
  72470. */
  72471. var addCommas$1 = addCommas;
  72472. var encodeHTML$1 = encodeHTML;
  72473. function fillLabel(opt) {
  72474. defaultEmphasis(opt, 'label', ['show']);
  72475. }
  72476. var MarkerModel = extendComponentModel({
  72477. type: 'marker',
  72478. dependencies: ['series', 'grid', 'polar', 'geo'],
  72479. /**
  72480. * @overrite
  72481. */
  72482. init: function (option, parentModel, ecModel, extraOpt) {
  72483. if (__DEV__) {
  72484. if (this.type === 'marker') {
  72485. throw new Error('Marker component is abstract component. Use markLine, markPoint, markArea instead.');
  72486. }
  72487. }
  72488. this.mergeDefaultAndTheme(option, ecModel);
  72489. this.mergeOption(option, ecModel, extraOpt.createdBySelf, true);
  72490. },
  72491. /**
  72492. * @return {boolean}
  72493. */
  72494. isAnimationEnabled: function () {
  72495. if (env$1.node) {
  72496. return false;
  72497. }
  72498. var hostSeries = this.__hostSeries;
  72499. return this.getShallow('animation') && hostSeries && hostSeries.isAnimationEnabled();
  72500. },
  72501. mergeOption: function (newOpt, ecModel, createdBySelf, isInit) {
  72502. var MarkerModel = this.constructor;
  72503. var modelPropName = this.mainType + 'Model';
  72504. if (!createdBySelf) {
  72505. ecModel.eachSeries(function (seriesModel) {
  72506. var markerOpt = seriesModel.get(this.mainType, true);
  72507. var markerModel = seriesModel[modelPropName];
  72508. if (!markerOpt || !markerOpt.data) {
  72509. seriesModel[modelPropName] = null;
  72510. return;
  72511. }
  72512. if (!markerModel) {
  72513. if (isInit) {
  72514. // Default label emphasis `position` and `show`
  72515. fillLabel(markerOpt);
  72516. }
  72517. each$1(markerOpt.data, function (item) {
  72518. // FIXME Overwrite fillLabel method ?
  72519. if (item instanceof Array) {
  72520. fillLabel(item[0]);
  72521. fillLabel(item[1]);
  72522. }
  72523. else {
  72524. fillLabel(item);
  72525. }
  72526. });
  72527. markerModel = new MarkerModel(
  72528. markerOpt, this, ecModel
  72529. );
  72530. extend(markerModel, {
  72531. mainType: this.mainType,
  72532. // Use the same series index and name
  72533. seriesIndex: seriesModel.seriesIndex,
  72534. name: seriesModel.name,
  72535. createdBySelf: true
  72536. });
  72537. markerModel.__hostSeries = seriesModel;
  72538. }
  72539. else {
  72540. markerModel.mergeOption(markerOpt, ecModel, true);
  72541. }
  72542. seriesModel[modelPropName] = markerModel;
  72543. }, this);
  72544. }
  72545. },
  72546. formatTooltip: function (dataIndex) {
  72547. var data = this.getData();
  72548. var value = this.getRawValue(dataIndex);
  72549. var formattedValue = isArray(value)
  72550. ? map(value, addCommas$1).join(', ') : addCommas$1(value);
  72551. var name = data.getName(dataIndex);
  72552. var html = encodeHTML$1(this.name);
  72553. if (value != null || name) {
  72554. html += '<br />';
  72555. }
  72556. if (name) {
  72557. html += encodeHTML$1(name);
  72558. if (value != null) {
  72559. html += ' : ';
  72560. }
  72561. }
  72562. if (value != null) {
  72563. html += encodeHTML$1(formattedValue);
  72564. }
  72565. return html;
  72566. },
  72567. getData: function () {
  72568. return this._data;
  72569. },
  72570. setData: function (data) {
  72571. this._data = data;
  72572. }
  72573. });
  72574. mixin(MarkerModel, dataFormatMixin);
  72575. /*
  72576. * Licensed to the Apache Software Foundation (ASF) under one
  72577. * or more contributor license agreements. See the NOTICE file
  72578. * distributed with this work for additional information
  72579. * regarding copyright ownership. The ASF licenses this file
  72580. * to you under the Apache License, Version 2.0 (the
  72581. * "License"); you may not use this file except in compliance
  72582. * with the License. You may obtain a copy of the License at
  72583. *
  72584. * http://www.apache.org/licenses/LICENSE-2.0
  72585. *
  72586. * Unless required by applicable law or agreed to in writing,
  72587. * software distributed under the License is distributed on an
  72588. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  72589. * KIND, either express or implied. See the License for the
  72590. * specific language governing permissions and limitations
  72591. * under the License.
  72592. */
  72593. MarkerModel.extend({
  72594. type: 'markPoint',
  72595. defaultOption: {
  72596. zlevel: 0,
  72597. z: 5,
  72598. symbol: 'pin',
  72599. symbolSize: 50,
  72600. //symbolRotate: 0,
  72601. //symbolOffset: [0, 0]
  72602. tooltip: {
  72603. trigger: 'item'
  72604. },
  72605. label: {
  72606. show: true,
  72607. position: 'inside'
  72608. },
  72609. itemStyle: {
  72610. borderWidth: 2
  72611. },
  72612. emphasis: {
  72613. label: {
  72614. show: true
  72615. }
  72616. }
  72617. }
  72618. });
  72619. /*
  72620. * Licensed to the Apache Software Foundation (ASF) under one
  72621. * or more contributor license agreements. See the NOTICE file
  72622. * distributed with this work for additional information
  72623. * regarding copyright ownership. The ASF licenses this file
  72624. * to you under the Apache License, Version 2.0 (the
  72625. * "License"); you may not use this file except in compliance
  72626. * with the License. You may obtain a copy of the License at
  72627. *
  72628. * http://www.apache.org/licenses/LICENSE-2.0
  72629. *
  72630. * Unless required by applicable law or agreed to in writing,
  72631. * software distributed under the License is distributed on an
  72632. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  72633. * KIND, either express or implied. See the License for the
  72634. * specific language governing permissions and limitations
  72635. * under the License.
  72636. */
  72637. var indexOf$2 = indexOf;
  72638. function hasXOrY(item) {
  72639. return !(isNaN(parseFloat(item.x)) && isNaN(parseFloat(item.y)));
  72640. }
  72641. function hasXAndY(item) {
  72642. return !isNaN(parseFloat(item.x)) && !isNaN(parseFloat(item.y));
  72643. }
  72644. // Make it simple, do not visit all stacked value to count precision.
  72645. // function getPrecision(data, valueAxisDim, dataIndex) {
  72646. // var precision = -1;
  72647. // var stackedDim = data.mapDimension(valueAxisDim);
  72648. // do {
  72649. // precision = Math.max(
  72650. // numberUtil.getPrecision(data.get(stackedDim, dataIndex)),
  72651. // precision
  72652. // );
  72653. // var stackedOnSeries = data.getCalculationInfo('stackedOnSeries');
  72654. // if (stackedOnSeries) {
  72655. // var byValue = data.get(data.getCalculationInfo('stackedByDimension'), dataIndex);
  72656. // data = stackedOnSeries.getData();
  72657. // dataIndex = data.indexOf(data.getCalculationInfo('stackedByDimension'), byValue);
  72658. // stackedDim = data.getCalculationInfo('stackedDimension');
  72659. // }
  72660. // else {
  72661. // data = null;
  72662. // }
  72663. // } while (data);
  72664. // return precision;
  72665. // }
  72666. function markerTypeCalculatorWithExtent(
  72667. mlType, data, otherDataDim, targetDataDim, otherCoordIndex, targetCoordIndex
  72668. ) {
  72669. var coordArr = [];
  72670. var stacked = isDimensionStacked(data, targetDataDim /*, otherDataDim*/);
  72671. var calcDataDim = stacked
  72672. ? data.getCalculationInfo('stackResultDimension')
  72673. : targetDataDim;
  72674. var value = numCalculate(data, calcDataDim, mlType);
  72675. var dataIndex = data.indicesOfNearest(calcDataDim, value)[0];
  72676. coordArr[otherCoordIndex] = data.get(otherDataDim, dataIndex);
  72677. coordArr[targetCoordIndex] = data.get(targetDataDim, dataIndex);
  72678. // Make it simple, do not visit all stacked value to count precision.
  72679. var precision = getPrecision(data.get(targetDataDim, dataIndex));
  72680. precision = Math.min(precision, 20);
  72681. if (precision >= 0) {
  72682. coordArr[targetCoordIndex] = +coordArr[targetCoordIndex].toFixed(precision);
  72683. }
  72684. return coordArr;
  72685. }
  72686. var curry$5 = curry;
  72687. // TODO Specified percent
  72688. var markerTypeCalculator = {
  72689. /**
  72690. * @method
  72691. * @param {module:echarts/data/List} data
  72692. * @param {string} baseAxisDim
  72693. * @param {string} valueAxisDim
  72694. */
  72695. min: curry$5(markerTypeCalculatorWithExtent, 'min'),
  72696. /**
  72697. * @method
  72698. * @param {module:echarts/data/List} data
  72699. * @param {string} baseAxisDim
  72700. * @param {string} valueAxisDim
  72701. */
  72702. max: curry$5(markerTypeCalculatorWithExtent, 'max'),
  72703. /**
  72704. * @method
  72705. * @param {module:echarts/data/List} data
  72706. * @param {string} baseAxisDim
  72707. * @param {string} valueAxisDim
  72708. */
  72709. average: curry$5(markerTypeCalculatorWithExtent, 'average')
  72710. };
  72711. /**
  72712. * Transform markPoint data item to format used in List by do the following
  72713. * 1. Calculate statistic like `max`, `min`, `average`
  72714. * 2. Convert `item.xAxis`, `item.yAxis` to `item.coord` array
  72715. * @param {module:echarts/model/Series} seriesModel
  72716. * @param {module:echarts/coord/*} [coordSys]
  72717. * @param {Object} item
  72718. * @return {Object}
  72719. */
  72720. function dataTransform(seriesModel, item) {
  72721. var data = seriesModel.getData();
  72722. var coordSys = seriesModel.coordinateSystem;
  72723. // 1. If not specify the position with pixel directly
  72724. // 2. If `coord` is not a data array. Which uses `xAxis`,
  72725. // `yAxis` to specify the coord on each dimension
  72726. // parseFloat first because item.x and item.y can be percent string like '20%'
  72727. if (item && !hasXAndY(item) && !isArray(item.coord) && coordSys) {
  72728. var dims = coordSys.dimensions;
  72729. var axisInfo = getAxisInfo$1(item, data, coordSys, seriesModel);
  72730. // Clone the option
  72731. // Transform the properties xAxis, yAxis, radiusAxis, angleAxis, geoCoord to value
  72732. item = clone(item);
  72733. if (item.type
  72734. && markerTypeCalculator[item.type]
  72735. && axisInfo.baseAxis && axisInfo.valueAxis
  72736. ) {
  72737. var otherCoordIndex = indexOf$2(dims, axisInfo.baseAxis.dim);
  72738. var targetCoordIndex = indexOf$2(dims, axisInfo.valueAxis.dim);
  72739. item.coord = markerTypeCalculator[item.type](
  72740. data, axisInfo.baseDataDim, axisInfo.valueDataDim,
  72741. otherCoordIndex, targetCoordIndex
  72742. );
  72743. // Force to use the value of calculated value.
  72744. item.value = item.coord[targetCoordIndex];
  72745. }
  72746. else {
  72747. // FIXME Only has one of xAxis and yAxis.
  72748. var coord = [
  72749. item.xAxis != null ? item.xAxis : item.radiusAxis,
  72750. item.yAxis != null ? item.yAxis : item.angleAxis
  72751. ];
  72752. // Each coord support max, min, average
  72753. for (var i = 0; i < 2; i++) {
  72754. if (markerTypeCalculator[coord[i]]) {
  72755. coord[i] = numCalculate(data, data.mapDimension(dims[i]), coord[i]);
  72756. }
  72757. }
  72758. item.coord = coord;
  72759. }
  72760. }
  72761. return item;
  72762. }
  72763. function getAxisInfo$1(item, data, coordSys, seriesModel) {
  72764. var ret = {};
  72765. if (item.valueIndex != null || item.valueDim != null) {
  72766. ret.valueDataDim = item.valueIndex != null
  72767. ? data.getDimension(item.valueIndex) : item.valueDim;
  72768. ret.valueAxis = coordSys.getAxis(dataDimToCoordDim(seriesModel, ret.valueDataDim));
  72769. ret.baseAxis = coordSys.getOtherAxis(ret.valueAxis);
  72770. ret.baseDataDim = data.mapDimension(ret.baseAxis.dim);
  72771. }
  72772. else {
  72773. ret.baseAxis = seriesModel.getBaseAxis();
  72774. ret.valueAxis = coordSys.getOtherAxis(ret.baseAxis);
  72775. ret.baseDataDim = data.mapDimension(ret.baseAxis.dim);
  72776. ret.valueDataDim = data.mapDimension(ret.valueAxis.dim);
  72777. }
  72778. return ret;
  72779. }
  72780. function dataDimToCoordDim(seriesModel, dataDim) {
  72781. var data = seriesModel.getData();
  72782. var dimensions = data.dimensions;
  72783. dataDim = data.getDimension(dataDim);
  72784. for (var i = 0; i < dimensions.length; i++) {
  72785. var dimItem = data.getDimensionInfo(dimensions[i]);
  72786. if (dimItem.name === dataDim) {
  72787. return dimItem.coordDim;
  72788. }
  72789. }
  72790. }
  72791. /**
  72792. * Filter data which is out of coordinateSystem range
  72793. * [dataFilter description]
  72794. * @param {module:echarts/coord/*} [coordSys]
  72795. * @param {Object} item
  72796. * @return {boolean}
  72797. */
  72798. function dataFilter$1(coordSys, item) {
  72799. // Alwalys return true if there is no coordSys
  72800. return (coordSys && coordSys.containData && item.coord && !hasXOrY(item))
  72801. ? coordSys.containData(item.coord) : true;
  72802. }
  72803. function dimValueGetter(item, dimName, dataIndex, dimIndex) {
  72804. // x, y, radius, angle
  72805. if (dimIndex < 2) {
  72806. return item.coord && item.coord[dimIndex];
  72807. }
  72808. return item.value;
  72809. }
  72810. function numCalculate(data, valueDataDim, type) {
  72811. if (type === 'average') {
  72812. var sum = 0;
  72813. var count = 0;
  72814. data.each(valueDataDim, function (val, idx) {
  72815. if (!isNaN(val)) {
  72816. sum += val;
  72817. count++;
  72818. }
  72819. });
  72820. return sum / count;
  72821. }
  72822. else if (type === 'median') {
  72823. return data.getMedian(valueDataDim);
  72824. }
  72825. else {
  72826. // max & min
  72827. return data.getDataExtent(valueDataDim, true)[type === 'max' ? 1 : 0];
  72828. }
  72829. }
  72830. /*
  72831. * Licensed to the Apache Software Foundation (ASF) under one
  72832. * or more contributor license agreements. See the NOTICE file
  72833. * distributed with this work for additional information
  72834. * regarding copyright ownership. The ASF licenses this file
  72835. * to you under the Apache License, Version 2.0 (the
  72836. * "License"); you may not use this file except in compliance
  72837. * with the License. You may obtain a copy of the License at
  72838. *
  72839. * http://www.apache.org/licenses/LICENSE-2.0
  72840. *
  72841. * Unless required by applicable law or agreed to in writing,
  72842. * software distributed under the License is distributed on an
  72843. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  72844. * KIND, either express or implied. See the License for the
  72845. * specific language governing permissions and limitations
  72846. * under the License.
  72847. */
  72848. var MarkerView = extendComponentView({
  72849. type: 'marker',
  72850. init: function () {
  72851. /**
  72852. * Markline grouped by series
  72853. * @private
  72854. * @type {module:zrender/core/util.HashMap}
  72855. */
  72856. this.markerGroupMap = createHashMap();
  72857. },
  72858. render: function (markerModel, ecModel, api) {
  72859. var markerGroupMap = this.markerGroupMap;
  72860. markerGroupMap.each(function (item) {
  72861. item.__keep = false;
  72862. });
  72863. var markerModelKey = this.type + 'Model';
  72864. ecModel.eachSeries(function (seriesModel) {
  72865. var markerModel = seriesModel[markerModelKey];
  72866. markerModel && this.renderSeries(seriesModel, markerModel, ecModel, api);
  72867. }, this);
  72868. markerGroupMap.each(function (item) {
  72869. !item.__keep && this.group.remove(item.group);
  72870. }, this);
  72871. },
  72872. renderSeries: function () {}
  72873. });
  72874. /*
  72875. * Licensed to the Apache Software Foundation (ASF) under one
  72876. * or more contributor license agreements. See the NOTICE file
  72877. * distributed with this work for additional information
  72878. * regarding copyright ownership. The ASF licenses this file
  72879. * to you under the Apache License, Version 2.0 (the
  72880. * "License"); you may not use this file except in compliance
  72881. * with the License. You may obtain a copy of the License at
  72882. *
  72883. * http://www.apache.org/licenses/LICENSE-2.0
  72884. *
  72885. * Unless required by applicable law or agreed to in writing,
  72886. * software distributed under the License is distributed on an
  72887. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  72888. * KIND, either express or implied. See the License for the
  72889. * specific language governing permissions and limitations
  72890. * under the License.
  72891. */
  72892. function updateMarkerLayout(mpData, seriesModel, api) {
  72893. var coordSys = seriesModel.coordinateSystem;
  72894. mpData.each(function (idx) {
  72895. var itemModel = mpData.getItemModel(idx);
  72896. var point;
  72897. var xPx = parsePercent$1(itemModel.get('x'), api.getWidth());
  72898. var yPx = parsePercent$1(itemModel.get('y'), api.getHeight());
  72899. if (!isNaN(xPx) && !isNaN(yPx)) {
  72900. point = [xPx, yPx];
  72901. }
  72902. // Chart like bar may have there own marker positioning logic
  72903. else if (seriesModel.getMarkerPosition) {
  72904. // Use the getMarkerPoisition
  72905. point = seriesModel.getMarkerPosition(
  72906. mpData.getValues(mpData.dimensions, idx)
  72907. );
  72908. }
  72909. else if (coordSys) {
  72910. var x = mpData.get(coordSys.dimensions[0], idx);
  72911. var y = mpData.get(coordSys.dimensions[1], idx);
  72912. point = coordSys.dataToPoint([x, y]);
  72913. }
  72914. // Use x, y if has any
  72915. if (!isNaN(xPx)) {
  72916. point[0] = xPx;
  72917. }
  72918. if (!isNaN(yPx)) {
  72919. point[1] = yPx;
  72920. }
  72921. mpData.setItemLayout(idx, point);
  72922. });
  72923. }
  72924. MarkerView.extend({
  72925. type: 'markPoint',
  72926. // updateLayout: function (markPointModel, ecModel, api) {
  72927. // ecModel.eachSeries(function (seriesModel) {
  72928. // var mpModel = seriesModel.markPointModel;
  72929. // if (mpModel) {
  72930. // updateMarkerLayout(mpModel.getData(), seriesModel, api);
  72931. // this.markerGroupMap.get(seriesModel.id).updateLayout(mpModel);
  72932. // }
  72933. // }, this);
  72934. // },
  72935. updateTransform: function (markPointModel, ecModel, api) {
  72936. ecModel.eachSeries(function (seriesModel) {
  72937. var mpModel = seriesModel.markPointModel;
  72938. if (mpModel) {
  72939. updateMarkerLayout(mpModel.getData(), seriesModel, api);
  72940. this.markerGroupMap.get(seriesModel.id).updateLayout(mpModel);
  72941. }
  72942. }, this);
  72943. },
  72944. renderSeries: function (seriesModel, mpModel, ecModel, api) {
  72945. var coordSys = seriesModel.coordinateSystem;
  72946. var seriesId = seriesModel.id;
  72947. var seriesData = seriesModel.getData();
  72948. var symbolDrawMap = this.markerGroupMap;
  72949. var symbolDraw = symbolDrawMap.get(seriesId)
  72950. || symbolDrawMap.set(seriesId, new SymbolDraw());
  72951. var mpData = createList$1(coordSys, seriesModel, mpModel);
  72952. // FIXME
  72953. mpModel.setData(mpData);
  72954. updateMarkerLayout(mpModel.getData(), seriesModel, api);
  72955. mpData.each(function (idx) {
  72956. var itemModel = mpData.getItemModel(idx);
  72957. var symbol = itemModel.getShallow('symbol');
  72958. var symbolSize = itemModel.getShallow('symbolSize');
  72959. var isFnSymbol = isFunction$1(symbol);
  72960. var isFnSymbolSize = isFunction$1(symbolSize);
  72961. if (isFnSymbol || isFnSymbolSize) {
  72962. var rawIdx = mpModel.getRawValue(idx);
  72963. var dataParams = mpModel.getDataParams(idx);
  72964. if (isFnSymbol) {
  72965. symbol = symbol(rawIdx, dataParams);
  72966. }
  72967. if (isFnSymbolSize) {
  72968. // FIXME 这里不兼容 ECharts 2.x,2.x 貌似参数是整个数据?
  72969. symbolSize = symbolSize(rawIdx, dataParams);
  72970. }
  72971. }
  72972. mpData.setItemVisual(idx, {
  72973. symbol: symbol,
  72974. symbolSize: symbolSize,
  72975. color: itemModel.get('itemStyle.color')
  72976. || seriesData.getVisual('color')
  72977. });
  72978. });
  72979. // TODO Text are wrong
  72980. symbolDraw.updateData(mpData);
  72981. this.group.add(symbolDraw.group);
  72982. // Set host model for tooltip
  72983. // FIXME
  72984. mpData.eachItemGraphicEl(function (el) {
  72985. el.traverse(function (child) {
  72986. child.dataModel = mpModel;
  72987. });
  72988. });
  72989. symbolDraw.__keep = true;
  72990. symbolDraw.group.silent = mpModel.get('silent') || seriesModel.get('silent');
  72991. }
  72992. });
  72993. /**
  72994. * @inner
  72995. * @param {module:echarts/coord/*} [coordSys]
  72996. * @param {module:echarts/model/Series} seriesModel
  72997. * @param {module:echarts/model/Model} mpModel
  72998. */
  72999. function createList$1(coordSys, seriesModel, mpModel) {
  73000. var coordDimsInfos;
  73001. if (coordSys) {
  73002. coordDimsInfos = map(coordSys && coordSys.dimensions, function (coordDim) {
  73003. var info = seriesModel.getData().getDimensionInfo(
  73004. seriesModel.getData().mapDimension(coordDim)
  73005. ) || {};
  73006. // In map series data don't have lng and lat dimension. Fallback to same with coordSys
  73007. return defaults({name: coordDim}, info);
  73008. });
  73009. }
  73010. else {
  73011. coordDimsInfos = [{
  73012. name: 'value',
  73013. type: 'float'
  73014. }];
  73015. }
  73016. var mpData = new List(coordDimsInfos, mpModel);
  73017. var dataOpt = map(mpModel.get('data'), curry(
  73018. dataTransform, seriesModel
  73019. ));
  73020. if (coordSys) {
  73021. dataOpt = filter(
  73022. dataOpt, curry(dataFilter$1, coordSys)
  73023. );
  73024. }
  73025. mpData.initData(dataOpt, null,
  73026. coordSys ? dimValueGetter : function (item) {
  73027. return item.value;
  73028. }
  73029. );
  73030. return mpData;
  73031. }
  73032. /*
  73033. * Licensed to the Apache Software Foundation (ASF) under one
  73034. * or more contributor license agreements. See the NOTICE file
  73035. * distributed with this work for additional information
  73036. * regarding copyright ownership. The ASF licenses this file
  73037. * to you under the Apache License, Version 2.0 (the
  73038. * "License"); you may not use this file except in compliance
  73039. * with the License. You may obtain a copy of the License at
  73040. *
  73041. * http://www.apache.org/licenses/LICENSE-2.0
  73042. *
  73043. * Unless required by applicable law or agreed to in writing,
  73044. * software distributed under the License is distributed on an
  73045. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  73046. * KIND, either express or implied. See the License for the
  73047. * specific language governing permissions and limitations
  73048. * under the License.
  73049. */
  73050. // HINT Markpoint can't be used too much
  73051. registerPreprocessor(function (opt) {
  73052. // Make sure markPoint component is enabled
  73053. opt.markPoint = opt.markPoint || {};
  73054. });
  73055. /*
  73056. * Licensed to the Apache Software Foundation (ASF) under one
  73057. * or more contributor license agreements. See the NOTICE file
  73058. * distributed with this work for additional information
  73059. * regarding copyright ownership. The ASF licenses this file
  73060. * to you under the Apache License, Version 2.0 (the
  73061. * "License"); you may not use this file except in compliance
  73062. * with the License. You may obtain a copy of the License at
  73063. *
  73064. * http://www.apache.org/licenses/LICENSE-2.0
  73065. *
  73066. * Unless required by applicable law or agreed to in writing,
  73067. * software distributed under the License is distributed on an
  73068. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  73069. * KIND, either express or implied. See the License for the
  73070. * specific language governing permissions and limitations
  73071. * under the License.
  73072. */
  73073. MarkerModel.extend({
  73074. type: 'markLine',
  73075. defaultOption: {
  73076. zlevel: 0,
  73077. z: 5,
  73078. symbol: ['circle', 'arrow'],
  73079. symbolSize: [8, 16],
  73080. //symbolRotate: 0,
  73081. precision: 2,
  73082. tooltip: {
  73083. trigger: 'item'
  73084. },
  73085. label: {
  73086. show: true,
  73087. position: 'end'
  73088. },
  73089. lineStyle: {
  73090. type: 'dashed'
  73091. },
  73092. emphasis: {
  73093. label: {
  73094. show: true
  73095. },
  73096. lineStyle: {
  73097. width: 3
  73098. }
  73099. },
  73100. animationEasing: 'linear'
  73101. }
  73102. });
  73103. /*
  73104. * Licensed to the Apache Software Foundation (ASF) under one
  73105. * or more contributor license agreements. See the NOTICE file
  73106. * distributed with this work for additional information
  73107. * regarding copyright ownership. The ASF licenses this file
  73108. * to you under the Apache License, Version 2.0 (the
  73109. * "License"); you may not use this file except in compliance
  73110. * with the License. You may obtain a copy of the License at
  73111. *
  73112. * http://www.apache.org/licenses/LICENSE-2.0
  73113. *
  73114. * Unless required by applicable law or agreed to in writing,
  73115. * software distributed under the License is distributed on an
  73116. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  73117. * KIND, either express or implied. See the License for the
  73118. * specific language governing permissions and limitations
  73119. * under the License.
  73120. */
  73121. var markLineTransform = function (seriesModel, coordSys, mlModel, item) {
  73122. var data = seriesModel.getData();
  73123. // Special type markLine like 'min', 'max', 'average', 'median'
  73124. var mlType = item.type;
  73125. if (!isArray(item)
  73126. && (
  73127. mlType === 'min' || mlType === 'max' || mlType === 'average' || mlType === 'median'
  73128. // In case
  73129. // data: [{
  73130. // yAxis: 10
  73131. // }]
  73132. || (item.xAxis != null || item.yAxis != null)
  73133. )
  73134. ) {
  73135. var valueAxis;
  73136. var value;
  73137. if (item.yAxis != null || item.xAxis != null) {
  73138. valueAxis = coordSys.getAxis(item.yAxis != null ? 'y' : 'x');
  73139. value = retrieve(item.yAxis, item.xAxis);
  73140. }
  73141. else {
  73142. var axisInfo = getAxisInfo$1(item, data, coordSys, seriesModel);
  73143. valueAxis = axisInfo.valueAxis;
  73144. var valueDataDim = getStackedDimension(data, axisInfo.valueDataDim);
  73145. value = numCalculate(data, valueDataDim, mlType);
  73146. }
  73147. var valueIndex = valueAxis.dim === 'x' ? 0 : 1;
  73148. var baseIndex = 1 - valueIndex;
  73149. var mlFrom = clone(item);
  73150. var mlTo = {};
  73151. mlFrom.type = null;
  73152. mlFrom.coord = [];
  73153. mlTo.coord = [];
  73154. mlFrom.coord[baseIndex] = -Infinity;
  73155. mlTo.coord[baseIndex] = Infinity;
  73156. var precision = mlModel.get('precision');
  73157. if (precision >= 0 && typeof value === 'number') {
  73158. value = +value.toFixed(Math.min(precision, 20));
  73159. }
  73160. mlFrom.coord[valueIndex] = mlTo.coord[valueIndex] = value;
  73161. item = [mlFrom, mlTo, { // Extra option for tooltip and label
  73162. type: mlType,
  73163. valueIndex: item.valueIndex,
  73164. // Force to use the value of calculated value.
  73165. value: value
  73166. }];
  73167. }
  73168. item = [
  73169. dataTransform(seriesModel, item[0]),
  73170. dataTransform(seriesModel, item[1]),
  73171. extend({}, item[2])
  73172. ];
  73173. // Avoid line data type is extended by from(to) data type
  73174. item[2].type = item[2].type || '';
  73175. // Merge from option and to option into line option
  73176. merge(item[2], item[0]);
  73177. merge(item[2], item[1]);
  73178. return item;
  73179. };
  73180. function isInifinity(val) {
  73181. return !isNaN(val) && !isFinite(val);
  73182. }
  73183. // If a markLine has one dim
  73184. function ifMarkLineHasOnlyDim(dimIndex, fromCoord, toCoord, coordSys) {
  73185. var otherDimIndex = 1 - dimIndex;
  73186. var dimName = coordSys.dimensions[dimIndex];
  73187. return isInifinity(fromCoord[otherDimIndex]) && isInifinity(toCoord[otherDimIndex])
  73188. && fromCoord[dimIndex] === toCoord[dimIndex] && coordSys.getAxis(dimName).containData(fromCoord[dimIndex]);
  73189. }
  73190. function markLineFilter(coordSys, item) {
  73191. if (coordSys.type === 'cartesian2d') {
  73192. var fromCoord = item[0].coord;
  73193. var toCoord = item[1].coord;
  73194. // In case
  73195. // {
  73196. // markLine: {
  73197. // data: [{ yAxis: 2 }]
  73198. // }
  73199. // }
  73200. if (
  73201. fromCoord && toCoord
  73202. && (ifMarkLineHasOnlyDim(1, fromCoord, toCoord, coordSys)
  73203. || ifMarkLineHasOnlyDim(0, fromCoord, toCoord, coordSys))
  73204. ) {
  73205. return true;
  73206. }
  73207. }
  73208. return dataFilter$1(coordSys, item[0])
  73209. && dataFilter$1(coordSys, item[1]);
  73210. }
  73211. function updateSingleMarkerEndLayout(
  73212. data, idx, isFrom, seriesModel, api
  73213. ) {
  73214. var coordSys = seriesModel.coordinateSystem;
  73215. var itemModel = data.getItemModel(idx);
  73216. var point;
  73217. var xPx = parsePercent$1(itemModel.get('x'), api.getWidth());
  73218. var yPx = parsePercent$1(itemModel.get('y'), api.getHeight());
  73219. if (!isNaN(xPx) && !isNaN(yPx)) {
  73220. point = [xPx, yPx];
  73221. }
  73222. else {
  73223. // Chart like bar may have there own marker positioning logic
  73224. if (seriesModel.getMarkerPosition) {
  73225. // Use the getMarkerPoisition
  73226. point = seriesModel.getMarkerPosition(
  73227. data.getValues(data.dimensions, idx)
  73228. );
  73229. }
  73230. else {
  73231. var dims = coordSys.dimensions;
  73232. var x = data.get(dims[0], idx);
  73233. var y = data.get(dims[1], idx);
  73234. point = coordSys.dataToPoint([x, y]);
  73235. }
  73236. // Expand line to the edge of grid if value on one axis is Inifnity
  73237. // In case
  73238. // markLine: {
  73239. // data: [{
  73240. // yAxis: 2
  73241. // // or
  73242. // type: 'average'
  73243. // }]
  73244. // }
  73245. if (coordSys.type === 'cartesian2d') {
  73246. var xAxis = coordSys.getAxis('x');
  73247. var yAxis = coordSys.getAxis('y');
  73248. var dims = coordSys.dimensions;
  73249. if (isInifinity(data.get(dims[0], idx))) {
  73250. point[0] = xAxis.toGlobalCoord(xAxis.getExtent()[isFrom ? 0 : 1]);
  73251. }
  73252. else if (isInifinity(data.get(dims[1], idx))) {
  73253. point[1] = yAxis.toGlobalCoord(yAxis.getExtent()[isFrom ? 0 : 1]);
  73254. }
  73255. }
  73256. // Use x, y if has any
  73257. if (!isNaN(xPx)) {
  73258. point[0] = xPx;
  73259. }
  73260. if (!isNaN(yPx)) {
  73261. point[1] = yPx;
  73262. }
  73263. }
  73264. data.setItemLayout(idx, point);
  73265. }
  73266. MarkerView.extend({
  73267. type: 'markLine',
  73268. // updateLayout: function (markLineModel, ecModel, api) {
  73269. // ecModel.eachSeries(function (seriesModel) {
  73270. // var mlModel = seriesModel.markLineModel;
  73271. // if (mlModel) {
  73272. // var mlData = mlModel.getData();
  73273. // var fromData = mlModel.__from;
  73274. // var toData = mlModel.__to;
  73275. // // Update visual and layout of from symbol and to symbol
  73276. // fromData.each(function (idx) {
  73277. // updateSingleMarkerEndLayout(fromData, idx, true, seriesModel, api);
  73278. // updateSingleMarkerEndLayout(toData, idx, false, seriesModel, api);
  73279. // });
  73280. // // Update layout of line
  73281. // mlData.each(function (idx) {
  73282. // mlData.setItemLayout(idx, [
  73283. // fromData.getItemLayout(idx),
  73284. // toData.getItemLayout(idx)
  73285. // ]);
  73286. // });
  73287. // this.markerGroupMap.get(seriesModel.id).updateLayout();
  73288. // }
  73289. // }, this);
  73290. // },
  73291. updateTransform: function (markLineModel, ecModel, api) {
  73292. ecModel.eachSeries(function (seriesModel) {
  73293. var mlModel = seriesModel.markLineModel;
  73294. if (mlModel) {
  73295. var mlData = mlModel.getData();
  73296. var fromData = mlModel.__from;
  73297. var toData = mlModel.__to;
  73298. // Update visual and layout of from symbol and to symbol
  73299. fromData.each(function (idx) {
  73300. updateSingleMarkerEndLayout(fromData, idx, true, seriesModel, api);
  73301. updateSingleMarkerEndLayout(toData, idx, false, seriesModel, api);
  73302. });
  73303. // Update layout of line
  73304. mlData.each(function (idx) {
  73305. mlData.setItemLayout(idx, [
  73306. fromData.getItemLayout(idx),
  73307. toData.getItemLayout(idx)
  73308. ]);
  73309. });
  73310. this.markerGroupMap.get(seriesModel.id).updateLayout();
  73311. }
  73312. }, this);
  73313. },
  73314. renderSeries: function (seriesModel, mlModel, ecModel, api) {
  73315. var coordSys = seriesModel.coordinateSystem;
  73316. var seriesId = seriesModel.id;
  73317. var seriesData = seriesModel.getData();
  73318. var lineDrawMap = this.markerGroupMap;
  73319. var lineDraw = lineDrawMap.get(seriesId)
  73320. || lineDrawMap.set(seriesId, new LineDraw());
  73321. this.group.add(lineDraw.group);
  73322. var mlData = createList$2(coordSys, seriesModel, mlModel);
  73323. var fromData = mlData.from;
  73324. var toData = mlData.to;
  73325. var lineData = mlData.line;
  73326. mlModel.__from = fromData;
  73327. mlModel.__to = toData;
  73328. // Line data for tooltip and formatter
  73329. mlModel.setData(lineData);
  73330. var symbolType = mlModel.get('symbol');
  73331. var symbolSize = mlModel.get('symbolSize');
  73332. if (!isArray(symbolType)) {
  73333. symbolType = [symbolType, symbolType];
  73334. }
  73335. if (typeof symbolSize === 'number') {
  73336. symbolSize = [symbolSize, symbolSize];
  73337. }
  73338. // Update visual and layout of from symbol and to symbol
  73339. mlData.from.each(function (idx) {
  73340. updateDataVisualAndLayout(fromData, idx, true);
  73341. updateDataVisualAndLayout(toData, idx, false);
  73342. });
  73343. // Update visual and layout of line
  73344. lineData.each(function (idx) {
  73345. var lineColor = lineData.getItemModel(idx).get('lineStyle.color');
  73346. lineData.setItemVisual(idx, {
  73347. color: lineColor || fromData.getItemVisual(idx, 'color')
  73348. });
  73349. lineData.setItemLayout(idx, [
  73350. fromData.getItemLayout(idx),
  73351. toData.getItemLayout(idx)
  73352. ]);
  73353. lineData.setItemVisual(idx, {
  73354. 'fromSymbolSize': fromData.getItemVisual(idx, 'symbolSize'),
  73355. 'fromSymbol': fromData.getItemVisual(idx, 'symbol'),
  73356. 'toSymbolSize': toData.getItemVisual(idx, 'symbolSize'),
  73357. 'toSymbol': toData.getItemVisual(idx, 'symbol')
  73358. });
  73359. });
  73360. lineDraw.updateData(lineData);
  73361. // Set host model for tooltip
  73362. // FIXME
  73363. mlData.line.eachItemGraphicEl(function (el, idx) {
  73364. el.traverse(function (child) {
  73365. child.dataModel = mlModel;
  73366. });
  73367. });
  73368. function updateDataVisualAndLayout(data, idx, isFrom) {
  73369. var itemModel = data.getItemModel(idx);
  73370. updateSingleMarkerEndLayout(
  73371. data, idx, isFrom, seriesModel, api
  73372. );
  73373. data.setItemVisual(idx, {
  73374. symbolSize: itemModel.get('symbolSize') || symbolSize[isFrom ? 0 : 1],
  73375. symbol: itemModel.get('symbol', true) || symbolType[isFrom ? 0 : 1],
  73376. color: itemModel.get('itemStyle.color') || seriesData.getVisual('color')
  73377. });
  73378. }
  73379. lineDraw.__keep = true;
  73380. lineDraw.group.silent = mlModel.get('silent') || seriesModel.get('silent');
  73381. }
  73382. });
  73383. /**
  73384. * @inner
  73385. * @param {module:echarts/coord/*} coordSys
  73386. * @param {module:echarts/model/Series} seriesModel
  73387. * @param {module:echarts/model/Model} mpModel
  73388. */
  73389. function createList$2(coordSys, seriesModel, mlModel) {
  73390. var coordDimsInfos;
  73391. if (coordSys) {
  73392. coordDimsInfos = map(coordSys && coordSys.dimensions, function (coordDim) {
  73393. var info = seriesModel.getData().getDimensionInfo(
  73394. seriesModel.getData().mapDimension(coordDim)
  73395. ) || {};
  73396. // In map series data don't have lng and lat dimension. Fallback to same with coordSys
  73397. return defaults({name: coordDim}, info);
  73398. });
  73399. }
  73400. else {
  73401. coordDimsInfos = [{
  73402. name: 'value',
  73403. type: 'float'
  73404. }];
  73405. }
  73406. var fromData = new List(coordDimsInfos, mlModel);
  73407. var toData = new List(coordDimsInfos, mlModel);
  73408. // No dimensions
  73409. var lineData = new List([], mlModel);
  73410. var optData = map(mlModel.get('data'), curry(
  73411. markLineTransform, seriesModel, coordSys, mlModel
  73412. ));
  73413. if (coordSys) {
  73414. optData = filter(
  73415. optData, curry(markLineFilter, coordSys)
  73416. );
  73417. }
  73418. var dimValueGetter$$1 = coordSys ? dimValueGetter : function (item) {
  73419. return item.value;
  73420. };
  73421. fromData.initData(
  73422. map(optData, function (item) {
  73423. return item[0];
  73424. }),
  73425. null,
  73426. dimValueGetter$$1
  73427. );
  73428. toData.initData(
  73429. map(optData, function (item) {
  73430. return item[1];
  73431. }),
  73432. null,
  73433. dimValueGetter$$1
  73434. );
  73435. lineData.initData(
  73436. map(optData, function (item) {
  73437. return item[2];
  73438. })
  73439. );
  73440. lineData.hasItemOption = true;
  73441. return {
  73442. from: fromData,
  73443. to: toData,
  73444. line: lineData
  73445. };
  73446. }
  73447. /*
  73448. * Licensed to the Apache Software Foundation (ASF) under one
  73449. * or more contributor license agreements. See the NOTICE file
  73450. * distributed with this work for additional information
  73451. * regarding copyright ownership. The ASF licenses this file
  73452. * to you under the Apache License, Version 2.0 (the
  73453. * "License"); you may not use this file except in compliance
  73454. * with the License. You may obtain a copy of the License at
  73455. *
  73456. * http://www.apache.org/licenses/LICENSE-2.0
  73457. *
  73458. * Unless required by applicable law or agreed to in writing,
  73459. * software distributed under the License is distributed on an
  73460. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  73461. * KIND, either express or implied. See the License for the
  73462. * specific language governing permissions and limitations
  73463. * under the License.
  73464. */
  73465. registerPreprocessor(function (opt) {
  73466. // Make sure markLine component is enabled
  73467. opt.markLine = opt.markLine || {};
  73468. });
  73469. /*
  73470. * Licensed to the Apache Software Foundation (ASF) under one
  73471. * or more contributor license agreements. See the NOTICE file
  73472. * distributed with this work for additional information
  73473. * regarding copyright ownership. The ASF licenses this file
  73474. * to you under the Apache License, Version 2.0 (the
  73475. * "License"); you may not use this file except in compliance
  73476. * with the License. You may obtain a copy of the License at
  73477. *
  73478. * http://www.apache.org/licenses/LICENSE-2.0
  73479. *
  73480. * Unless required by applicable law or agreed to in writing,
  73481. * software distributed under the License is distributed on an
  73482. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  73483. * KIND, either express or implied. See the License for the
  73484. * specific language governing permissions and limitations
  73485. * under the License.
  73486. */
  73487. MarkerModel.extend({
  73488. type: 'markArea',
  73489. defaultOption: {
  73490. zlevel: 0,
  73491. // PENDING
  73492. z: 1,
  73493. tooltip: {
  73494. trigger: 'item'
  73495. },
  73496. // markArea should fixed on the coordinate system
  73497. animation: false,
  73498. label: {
  73499. show: true,
  73500. position: 'top'
  73501. },
  73502. itemStyle: {
  73503. // color and borderColor default to use color from series
  73504. // color: 'auto'
  73505. // borderColor: 'auto'
  73506. borderWidth: 0
  73507. },
  73508. emphasis: {
  73509. label: {
  73510. show: true,
  73511. position: 'top'
  73512. }
  73513. }
  73514. }
  73515. });
  73516. /*
  73517. * Licensed to the Apache Software Foundation (ASF) under one
  73518. * or more contributor license agreements. See the NOTICE file
  73519. * distributed with this work for additional information
  73520. * regarding copyright ownership. The ASF licenses this file
  73521. * to you under the Apache License, Version 2.0 (the
  73522. * "License"); you may not use this file except in compliance
  73523. * with the License. You may obtain a copy of the License at
  73524. *
  73525. * http://www.apache.org/licenses/LICENSE-2.0
  73526. *
  73527. * Unless required by applicable law or agreed to in writing,
  73528. * software distributed under the License is distributed on an
  73529. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  73530. * KIND, either express or implied. See the License for the
  73531. * specific language governing permissions and limitations
  73532. * under the License.
  73533. */
  73534. // TODO Better on polar
  73535. var markAreaTransform = function (seriesModel, coordSys, maModel, item) {
  73536. var lt = dataTransform(seriesModel, item[0]);
  73537. var rb = dataTransform(seriesModel, item[1]);
  73538. var retrieve$$1 = retrieve;
  73539. // FIXME make sure lt is less than rb
  73540. var ltCoord = lt.coord;
  73541. var rbCoord = rb.coord;
  73542. ltCoord[0] = retrieve$$1(ltCoord[0], -Infinity);
  73543. ltCoord[1] = retrieve$$1(ltCoord[1], -Infinity);
  73544. rbCoord[0] = retrieve$$1(rbCoord[0], Infinity);
  73545. rbCoord[1] = retrieve$$1(rbCoord[1], Infinity);
  73546. // Merge option into one
  73547. var result = mergeAll([{}, lt, rb]);
  73548. result.coord = [
  73549. lt.coord, rb.coord
  73550. ];
  73551. result.x0 = lt.x;
  73552. result.y0 = lt.y;
  73553. result.x1 = rb.x;
  73554. result.y1 = rb.y;
  73555. return result;
  73556. };
  73557. function isInifinity$1(val) {
  73558. return !isNaN(val) && !isFinite(val);
  73559. }
  73560. // If a markArea has one dim
  73561. function ifMarkLineHasOnlyDim$1(dimIndex, fromCoord, toCoord, coordSys) {
  73562. var otherDimIndex = 1 - dimIndex;
  73563. return isInifinity$1(fromCoord[otherDimIndex]) && isInifinity$1(toCoord[otherDimIndex]);
  73564. }
  73565. function markAreaFilter(coordSys, item) {
  73566. var fromCoord = item.coord[0];
  73567. var toCoord = item.coord[1];
  73568. if (coordSys.type === 'cartesian2d') {
  73569. // In case
  73570. // {
  73571. // markArea: {
  73572. // data: [{ yAxis: 2 }]
  73573. // }
  73574. // }
  73575. if (
  73576. fromCoord && toCoord
  73577. && (ifMarkLineHasOnlyDim$1(1, fromCoord, toCoord, coordSys)
  73578. || ifMarkLineHasOnlyDim$1(0, fromCoord, toCoord, coordSys))
  73579. ) {
  73580. return true;
  73581. }
  73582. }
  73583. return dataFilter$1(coordSys, {
  73584. coord: fromCoord,
  73585. x: item.x0,
  73586. y: item.y0
  73587. })
  73588. || dataFilter$1(coordSys, {
  73589. coord: toCoord,
  73590. x: item.x1,
  73591. y: item.y1
  73592. });
  73593. }
  73594. // dims can be ['x0', 'y0'], ['x1', 'y1'], ['x0', 'y1'], ['x1', 'y0']
  73595. function getSingleMarkerEndPoint(data, idx, dims, seriesModel, api) {
  73596. var coordSys = seriesModel.coordinateSystem;
  73597. var itemModel = data.getItemModel(idx);
  73598. var point;
  73599. var xPx = parsePercent$1(itemModel.get(dims[0]), api.getWidth());
  73600. var yPx = parsePercent$1(itemModel.get(dims[1]), api.getHeight());
  73601. if (!isNaN(xPx) && !isNaN(yPx)) {
  73602. point = [xPx, yPx];
  73603. }
  73604. else {
  73605. // Chart like bar may have there own marker positioning logic
  73606. if (seriesModel.getMarkerPosition) {
  73607. // Use the getMarkerPoisition
  73608. point = seriesModel.getMarkerPosition(
  73609. data.getValues(dims, idx)
  73610. );
  73611. }
  73612. else {
  73613. var x = data.get(dims[0], idx);
  73614. var y = data.get(dims[1], idx);
  73615. var pt = [x, y];
  73616. coordSys.clampData && coordSys.clampData(pt, pt);
  73617. point = coordSys.dataToPoint(pt, true);
  73618. }
  73619. if (coordSys.type === 'cartesian2d') {
  73620. var xAxis = coordSys.getAxis('x');
  73621. var yAxis = coordSys.getAxis('y');
  73622. var x = data.get(dims[0], idx);
  73623. var y = data.get(dims[1], idx);
  73624. if (isInifinity$1(x)) {
  73625. point[0] = xAxis.toGlobalCoord(xAxis.getExtent()[dims[0] === 'x0' ? 0 : 1]);
  73626. }
  73627. else if (isInifinity$1(y)) {
  73628. point[1] = yAxis.toGlobalCoord(yAxis.getExtent()[dims[1] === 'y0' ? 0 : 1]);
  73629. }
  73630. }
  73631. // Use x, y if has any
  73632. if (!isNaN(xPx)) {
  73633. point[0] = xPx;
  73634. }
  73635. if (!isNaN(yPx)) {
  73636. point[1] = yPx;
  73637. }
  73638. }
  73639. return point;
  73640. }
  73641. var dimPermutations = [['x0', 'y0'], ['x1', 'y0'], ['x1', 'y1'], ['x0', 'y1']];
  73642. MarkerView.extend({
  73643. type: 'markArea',
  73644. // updateLayout: function (markAreaModel, ecModel, api) {
  73645. // ecModel.eachSeries(function (seriesModel) {
  73646. // var maModel = seriesModel.markAreaModel;
  73647. // if (maModel) {
  73648. // var areaData = maModel.getData();
  73649. // areaData.each(function (idx) {
  73650. // var points = zrUtil.map(dimPermutations, function (dim) {
  73651. // return getSingleMarkerEndPoint(areaData, idx, dim, seriesModel, api);
  73652. // });
  73653. // // Layout
  73654. // areaData.setItemLayout(idx, points);
  73655. // var el = areaData.getItemGraphicEl(idx);
  73656. // el.setShape('points', points);
  73657. // });
  73658. // }
  73659. // }, this);
  73660. // },
  73661. updateTransform: function (markAreaModel, ecModel, api) {
  73662. ecModel.eachSeries(function (seriesModel) {
  73663. var maModel = seriesModel.markAreaModel;
  73664. if (maModel) {
  73665. var areaData = maModel.getData();
  73666. areaData.each(function (idx) {
  73667. var points = map(dimPermutations, function (dim) {
  73668. return getSingleMarkerEndPoint(areaData, idx, dim, seriesModel, api);
  73669. });
  73670. // Layout
  73671. areaData.setItemLayout(idx, points);
  73672. var el = areaData.getItemGraphicEl(idx);
  73673. el.setShape('points', points);
  73674. });
  73675. }
  73676. }, this);
  73677. },
  73678. renderSeries: function (seriesModel, maModel, ecModel, api) {
  73679. var coordSys = seriesModel.coordinateSystem;
  73680. var seriesId = seriesModel.id;
  73681. var seriesData = seriesModel.getData();
  73682. var areaGroupMap = this.markerGroupMap;
  73683. var polygonGroup = areaGroupMap.get(seriesId)
  73684. || areaGroupMap.set(seriesId, {group: new Group()});
  73685. this.group.add(polygonGroup.group);
  73686. polygonGroup.__keep = true;
  73687. var areaData = createList$3(coordSys, seriesModel, maModel);
  73688. // Line data for tooltip and formatter
  73689. maModel.setData(areaData);
  73690. // Update visual and layout of line
  73691. areaData.each(function (idx) {
  73692. // Layout
  73693. areaData.setItemLayout(idx, map(dimPermutations, function (dim) {
  73694. return getSingleMarkerEndPoint(areaData, idx, dim, seriesModel, api);
  73695. }));
  73696. // Visual
  73697. areaData.setItemVisual(idx, {
  73698. color: seriesData.getVisual('color')
  73699. });
  73700. });
  73701. areaData.diff(polygonGroup.__data)
  73702. .add(function (idx) {
  73703. var polygon = new Polygon({
  73704. shape: {
  73705. points: areaData.getItemLayout(idx)
  73706. }
  73707. });
  73708. areaData.setItemGraphicEl(idx, polygon);
  73709. polygonGroup.group.add(polygon);
  73710. })
  73711. .update(function (newIdx, oldIdx) {
  73712. var polygon = polygonGroup.__data.getItemGraphicEl(oldIdx);
  73713. updateProps(polygon, {
  73714. shape: {
  73715. points: areaData.getItemLayout(newIdx)
  73716. }
  73717. }, maModel, newIdx);
  73718. polygonGroup.group.add(polygon);
  73719. areaData.setItemGraphicEl(newIdx, polygon);
  73720. })
  73721. .remove(function (idx) {
  73722. var polygon = polygonGroup.__data.getItemGraphicEl(idx);
  73723. polygonGroup.group.remove(polygon);
  73724. })
  73725. .execute();
  73726. areaData.eachItemGraphicEl(function (polygon, idx) {
  73727. var itemModel = areaData.getItemModel(idx);
  73728. var labelModel = itemModel.getModel('label');
  73729. var labelHoverModel = itemModel.getModel('emphasis.label');
  73730. var color = areaData.getItemVisual(idx, 'color');
  73731. polygon.useStyle(
  73732. defaults(
  73733. itemModel.getModel('itemStyle').getItemStyle(),
  73734. {
  73735. fill: modifyAlpha(color, 0.4),
  73736. stroke: color
  73737. }
  73738. )
  73739. );
  73740. polygon.hoverStyle = itemModel.getModel('emphasis.itemStyle').getItemStyle();
  73741. setLabelStyle(
  73742. polygon.style, polygon.hoverStyle, labelModel, labelHoverModel,
  73743. {
  73744. labelFetcher: maModel,
  73745. labelDataIndex: idx,
  73746. defaultText: areaData.getName(idx) || '',
  73747. isRectText: true,
  73748. autoColor: color
  73749. }
  73750. );
  73751. setHoverStyle(polygon, {});
  73752. polygon.dataModel = maModel;
  73753. });
  73754. polygonGroup.__data = areaData;
  73755. polygonGroup.group.silent = maModel.get('silent') || seriesModel.get('silent');
  73756. }
  73757. });
  73758. /**
  73759. * @inner
  73760. * @param {module:echarts/coord/*} coordSys
  73761. * @param {module:echarts/model/Series} seriesModel
  73762. * @param {module:echarts/model/Model} mpModel
  73763. */
  73764. function createList$3(coordSys, seriesModel, maModel) {
  73765. var coordDimsInfos;
  73766. var areaData;
  73767. var dims = ['x0', 'y0', 'x1', 'y1'];
  73768. if (coordSys) {
  73769. coordDimsInfos = map(coordSys && coordSys.dimensions, function (coordDim) {
  73770. var data = seriesModel.getData();
  73771. var info = data.getDimensionInfo(
  73772. data.mapDimension(coordDim)
  73773. ) || {};
  73774. // In map series data don't have lng and lat dimension. Fallback to same with coordSys
  73775. return defaults({name: coordDim}, info);
  73776. });
  73777. areaData = new List(map(dims, function (dim, idx) {
  73778. return {
  73779. name: dim,
  73780. type: coordDimsInfos[idx % 2].type
  73781. };
  73782. }), maModel);
  73783. }
  73784. else {
  73785. coordDimsInfos = [{
  73786. name: 'value',
  73787. type: 'float'
  73788. }];
  73789. areaData = new List(coordDimsInfos, maModel);
  73790. }
  73791. var optData = map(maModel.get('data'), curry(
  73792. markAreaTransform, seriesModel, coordSys, maModel
  73793. ));
  73794. if (coordSys) {
  73795. optData = filter(
  73796. optData, curry(markAreaFilter, coordSys)
  73797. );
  73798. }
  73799. var dimValueGetter$$1 = coordSys ? function (item, dimName, dataIndex, dimIndex) {
  73800. return item.coord[Math.floor(dimIndex / 2)][dimIndex % 2];
  73801. } : function (item) {
  73802. return item.value;
  73803. };
  73804. areaData.initData(optData, null, dimValueGetter$$1);
  73805. areaData.hasItemOption = true;
  73806. return areaData;
  73807. }
  73808. /*
  73809. * Licensed to the Apache Software Foundation (ASF) under one
  73810. * or more contributor license agreements. See the NOTICE file
  73811. * distributed with this work for additional information
  73812. * regarding copyright ownership. The ASF licenses this file
  73813. * to you under the Apache License, Version 2.0 (the
  73814. * "License"); you may not use this file except in compliance
  73815. * with the License. You may obtain a copy of the License at
  73816. *
  73817. * http://www.apache.org/licenses/LICENSE-2.0
  73818. *
  73819. * Unless required by applicable law or agreed to in writing,
  73820. * software distributed under the License is distributed on an
  73821. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  73822. * KIND, either express or implied. See the License for the
  73823. * specific language governing permissions and limitations
  73824. * under the License.
  73825. */
  73826. registerPreprocessor(function (opt) {
  73827. // Make sure markArea component is enabled
  73828. opt.markArea = opt.markArea || {};
  73829. });
  73830. /*
  73831. * Licensed to the Apache Software Foundation (ASF) under one
  73832. * or more contributor license agreements. See the NOTICE file
  73833. * distributed with this work for additional information
  73834. * regarding copyright ownership. The ASF licenses this file
  73835. * to you under the Apache License, Version 2.0 (the
  73836. * "License"); you may not use this file except in compliance
  73837. * with the License. You may obtain a copy of the License at
  73838. *
  73839. * http://www.apache.org/licenses/LICENSE-2.0
  73840. *
  73841. * Unless required by applicable law or agreed to in writing,
  73842. * software distributed under the License is distributed on an
  73843. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  73844. * KIND, either express or implied. See the License for the
  73845. * specific language governing permissions and limitations
  73846. * under the License.
  73847. */
  73848. var LegendModel = extendComponentModel({
  73849. type: 'legend.plain',
  73850. dependencies: ['series'],
  73851. layoutMode: {
  73852. type: 'box',
  73853. // legend.width/height are maxWidth/maxHeight actually,
  73854. // whereas realy width/height is calculated by its content.
  73855. // (Setting {left: 10, right: 10} does not make sense).
  73856. // So consider the case:
  73857. // `setOption({legend: {left: 10});`
  73858. // then `setOption({legend: {right: 10});`
  73859. // The previous `left` should be cleared by setting `ignoreSize`.
  73860. ignoreSize: true
  73861. },
  73862. init: function (option, parentModel, ecModel) {
  73863. this.mergeDefaultAndTheme(option, ecModel);
  73864. option.selected = option.selected || {};
  73865. },
  73866. mergeOption: function (option) {
  73867. LegendModel.superCall(this, 'mergeOption', option);
  73868. },
  73869. optionUpdated: function () {
  73870. this._updateData(this.ecModel);
  73871. var legendData = this._data;
  73872. // If selectedMode is single, try to select one
  73873. if (legendData[0] && this.get('selectedMode') === 'single') {
  73874. var hasSelected = false;
  73875. // If has any selected in option.selected
  73876. for (var i = 0; i < legendData.length; i++) {
  73877. var name = legendData[i].get('name');
  73878. if (this.isSelected(name)) {
  73879. // Force to unselect others
  73880. this.select(name);
  73881. hasSelected = true;
  73882. break;
  73883. }
  73884. }
  73885. // Try select the first if selectedMode is single
  73886. !hasSelected && this.select(legendData[0].get('name'));
  73887. }
  73888. },
  73889. _updateData: function (ecModel) {
  73890. var potentialData = [];
  73891. var availableNames = [];
  73892. ecModel.eachRawSeries(function (seriesModel) {
  73893. var seriesName = seriesModel.name;
  73894. availableNames.push(seriesName);
  73895. var isPotential;
  73896. if (seriesModel.legendDataProvider) {
  73897. var data = seriesModel.legendDataProvider();
  73898. var names = data.mapArray(data.getName);
  73899. if (!ecModel.isSeriesFiltered(seriesModel)) {
  73900. availableNames = availableNames.concat(names);
  73901. }
  73902. if (names.length) {
  73903. potentialData = potentialData.concat(names);
  73904. }
  73905. else {
  73906. isPotential = true;
  73907. }
  73908. }
  73909. else {
  73910. isPotential = true;
  73911. }
  73912. if (isPotential && isNameSpecified(seriesModel)) {
  73913. potentialData.push(seriesModel.name);
  73914. }
  73915. });
  73916. /**
  73917. * @type {Array.<string>}
  73918. * @private
  73919. */
  73920. this._availableNames = availableNames;
  73921. // If legend.data not specified in option, use availableNames as data,
  73922. // which is convinient for user preparing option.
  73923. var rawData = this.get('data') || potentialData;
  73924. var legendData = map(rawData, function (dataItem) {
  73925. // Can be string or number
  73926. if (typeof dataItem === 'string' || typeof dataItem === 'number') {
  73927. dataItem = {
  73928. name: dataItem
  73929. };
  73930. }
  73931. return new Model(dataItem, this, this.ecModel);
  73932. }, this);
  73933. /**
  73934. * @type {Array.<module:echarts/model/Model>}
  73935. * @private
  73936. */
  73937. this._data = legendData;
  73938. },
  73939. /**
  73940. * @return {Array.<module:echarts/model/Model>}
  73941. */
  73942. getData: function () {
  73943. return this._data;
  73944. },
  73945. /**
  73946. * @param {string} name
  73947. */
  73948. select: function (name) {
  73949. var selected = this.option.selected;
  73950. var selectedMode = this.get('selectedMode');
  73951. if (selectedMode === 'single') {
  73952. var data = this._data;
  73953. each$1(data, function (dataItem) {
  73954. selected[dataItem.get('name')] = false;
  73955. });
  73956. }
  73957. selected[name] = true;
  73958. },
  73959. /**
  73960. * @param {string} name
  73961. */
  73962. unSelect: function (name) {
  73963. if (this.get('selectedMode') !== 'single') {
  73964. this.option.selected[name] = false;
  73965. }
  73966. },
  73967. /**
  73968. * @param {string} name
  73969. */
  73970. toggleSelected: function (name) {
  73971. var selected = this.option.selected;
  73972. // Default is true
  73973. if (!selected.hasOwnProperty(name)) {
  73974. selected[name] = true;
  73975. }
  73976. this[selected[name] ? 'unSelect' : 'select'](name);
  73977. },
  73978. /**
  73979. * @param {string} name
  73980. */
  73981. isSelected: function (name) {
  73982. var selected = this.option.selected;
  73983. return !(selected.hasOwnProperty(name) && !selected[name])
  73984. && indexOf(this._availableNames, name) >= 0;
  73985. },
  73986. defaultOption: {
  73987. // 一级层叠
  73988. zlevel: 0,
  73989. // 二级层叠
  73990. z: 4,
  73991. show: true,
  73992. // 布局方式,默认为水平布局,可选为:
  73993. // 'horizontal' | 'vertical'
  73994. orient: 'horizontal',
  73995. left: 'center',
  73996. // right: 'center',
  73997. top: 0,
  73998. // bottom: null,
  73999. // 水平对齐
  74000. // 'auto' | 'left' | 'right'
  74001. // 默认为 'auto', 根据 x 的位置判断是左对齐还是右对齐
  74002. align: 'auto',
  74003. backgroundColor: 'rgba(0,0,0,0)',
  74004. // 图例边框颜色
  74005. borderColor: '#ccc',
  74006. borderRadius: 0,
  74007. // 图例边框线宽,单位px,默认为0(无边框)
  74008. borderWidth: 0,
  74009. // 图例内边距,单位px,默认各方向内边距为5,
  74010. // 接受数组分别设定上右下左边距,同css
  74011. padding: 5,
  74012. // 各个item之间的间隔,单位px,默认为10,
  74013. // 横向布局时为水平间隔,纵向布局时为纵向间隔
  74014. itemGap: 10,
  74015. // 图例图形宽度
  74016. itemWidth: 25,
  74017. // 图例图形高度
  74018. itemHeight: 14,
  74019. // 图例关闭时候的颜色
  74020. inactiveColor: '#ccc',
  74021. textStyle: {
  74022. // 图例文字颜色
  74023. color: '#333'
  74024. },
  74025. // formatter: '',
  74026. // 选择模式,默认开启图例开关
  74027. selectedMode: true,
  74028. // 配置默认选中状态,可配合LEGEND.SELECTED事件做动态数据载入
  74029. // selected: null,
  74030. // 图例内容(详见legend.data,数组中每一项代表一个item
  74031. // data: [],
  74032. // Tooltip 相关配置
  74033. tooltip: {
  74034. show: false
  74035. }
  74036. }
  74037. });
  74038. /*
  74039. * Licensed to the Apache Software Foundation (ASF) under one
  74040. * or more contributor license agreements. See the NOTICE file
  74041. * distributed with this work for additional information
  74042. * regarding copyright ownership. The ASF licenses this file
  74043. * to you under the Apache License, Version 2.0 (the
  74044. * "License"); you may not use this file except in compliance
  74045. * with the License. You may obtain a copy of the License at
  74046. *
  74047. * http://www.apache.org/licenses/LICENSE-2.0
  74048. *
  74049. * Unless required by applicable law or agreed to in writing,
  74050. * software distributed under the License is distributed on an
  74051. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  74052. * KIND, either express or implied. See the License for the
  74053. * specific language governing permissions and limitations
  74054. * under the License.
  74055. */
  74056. function legendSelectActionHandler(methodName, payload, ecModel) {
  74057. var selectedMap = {};
  74058. var isToggleSelect = methodName === 'toggleSelected';
  74059. var isSelected;
  74060. // Update all legend components
  74061. ecModel.eachComponent('legend', function (legendModel) {
  74062. if (isToggleSelect && isSelected != null) {
  74063. // Force other legend has same selected status
  74064. // Or the first is toggled to true and other are toggled to false
  74065. // In the case one legend has some item unSelected in option. And if other legend
  74066. // doesn't has the item, they will assume it is selected.
  74067. legendModel[isSelected ? 'select' : 'unSelect'](payload.name);
  74068. }
  74069. else {
  74070. legendModel[methodName](payload.name);
  74071. isSelected = legendModel.isSelected(payload.name);
  74072. }
  74073. var legendData = legendModel.getData();
  74074. each$1(legendData, function (model) {
  74075. var name = model.get('name');
  74076. // Wrap element
  74077. if (name === '\n' || name === '') {
  74078. return;
  74079. }
  74080. var isItemSelected = legendModel.isSelected(name);
  74081. if (selectedMap.hasOwnProperty(name)) {
  74082. // Unselected if any legend is unselected
  74083. selectedMap[name] = selectedMap[name] && isItemSelected;
  74084. }
  74085. else {
  74086. selectedMap[name] = isItemSelected;
  74087. }
  74088. });
  74089. });
  74090. // Return the event explicitly
  74091. return {
  74092. name: payload.name,
  74093. selected: selectedMap
  74094. };
  74095. }
  74096. /**
  74097. * @event legendToggleSelect
  74098. * @type {Object}
  74099. * @property {string} type 'legendToggleSelect'
  74100. * @property {string} [from]
  74101. * @property {string} name Series name or data item name
  74102. */
  74103. registerAction(
  74104. 'legendToggleSelect', 'legendselectchanged',
  74105. curry(legendSelectActionHandler, 'toggleSelected')
  74106. );
  74107. /**
  74108. * @event legendSelect
  74109. * @type {Object}
  74110. * @property {string} type 'legendSelect'
  74111. * @property {string} name Series name or data item name
  74112. */
  74113. registerAction(
  74114. 'legendSelect', 'legendselected',
  74115. curry(legendSelectActionHandler, 'select')
  74116. );
  74117. /**
  74118. * @event legendUnSelect
  74119. * @type {Object}
  74120. * @property {string} type 'legendUnSelect'
  74121. * @property {string} name Series name or data item name
  74122. */
  74123. registerAction(
  74124. 'legendUnSelect', 'legendunselected',
  74125. curry(legendSelectActionHandler, 'unSelect')
  74126. );
  74127. /*
  74128. * Licensed to the Apache Software Foundation (ASF) under one
  74129. * or more contributor license agreements. See the NOTICE file
  74130. * distributed with this work for additional information
  74131. * regarding copyright ownership. The ASF licenses this file
  74132. * to you under the Apache License, Version 2.0 (the
  74133. * "License"); you may not use this file except in compliance
  74134. * with the License. You may obtain a copy of the License at
  74135. *
  74136. * http://www.apache.org/licenses/LICENSE-2.0
  74137. *
  74138. * Unless required by applicable law or agreed to in writing,
  74139. * software distributed under the License is distributed on an
  74140. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  74141. * KIND, either express or implied. See the License for the
  74142. * specific language governing permissions and limitations
  74143. * under the License.
  74144. */
  74145. var curry$6 = curry;
  74146. var each$25 = each$1;
  74147. var Group$3 = Group;
  74148. var LegendView = extendComponentView({
  74149. type: 'legend.plain',
  74150. newlineDisabled: false,
  74151. /**
  74152. * @override
  74153. */
  74154. init: function () {
  74155. /**
  74156. * @private
  74157. * @type {module:zrender/container/Group}
  74158. */
  74159. this.group.add(this._contentGroup = new Group$3());
  74160. /**
  74161. * @private
  74162. * @type {module:zrender/Element}
  74163. */
  74164. this._backgroundEl;
  74165. /**
  74166. * If first rendering, `contentGroup.position` is [0, 0], which
  74167. * does not make sense and may cause unexepcted animation if adopted.
  74168. * @private
  74169. * @type {boolean}
  74170. */
  74171. this._isFirstRender = true;
  74172. },
  74173. /**
  74174. * @protected
  74175. */
  74176. getContentGroup: function () {
  74177. return this._contentGroup;
  74178. },
  74179. /**
  74180. * @override
  74181. */
  74182. render: function (legendModel, ecModel, api) {
  74183. var isFirstRender = this._isFirstRender;
  74184. this._isFirstRender = false;
  74185. this.resetInner();
  74186. if (!legendModel.get('show', true)) {
  74187. return;
  74188. }
  74189. var itemAlign = legendModel.get('align');
  74190. if (!itemAlign || itemAlign === 'auto') {
  74191. itemAlign = (
  74192. legendModel.get('left') === 'right'
  74193. && legendModel.get('orient') === 'vertical'
  74194. ) ? 'right' : 'left';
  74195. }
  74196. this.renderInner(itemAlign, legendModel, ecModel, api);
  74197. // Perform layout.
  74198. var positionInfo = legendModel.getBoxLayoutParams();
  74199. var viewportSize = {width: api.getWidth(), height: api.getHeight()};
  74200. var padding = legendModel.get('padding');
  74201. var maxSize = getLayoutRect(positionInfo, viewportSize, padding);
  74202. var mainRect = this.layoutInner(legendModel, itemAlign, maxSize, isFirstRender);
  74203. // Place mainGroup, based on the calculated `mainRect`.
  74204. var layoutRect = getLayoutRect(
  74205. defaults({width: mainRect.width, height: mainRect.height}, positionInfo),
  74206. viewportSize,
  74207. padding
  74208. );
  74209. this.group.attr('position', [layoutRect.x - mainRect.x, layoutRect.y - mainRect.y]);
  74210. // Render background after group is layout.
  74211. this.group.add(
  74212. this._backgroundEl = makeBackground(mainRect, legendModel)
  74213. );
  74214. },
  74215. /**
  74216. * @protected
  74217. */
  74218. resetInner: function () {
  74219. this.getContentGroup().removeAll();
  74220. this._backgroundEl && this.group.remove(this._backgroundEl);
  74221. },
  74222. /**
  74223. * @protected
  74224. */
  74225. renderInner: function (itemAlign, legendModel, ecModel, api) {
  74226. var contentGroup = this.getContentGroup();
  74227. var legendDrawnMap = createHashMap();
  74228. var selectMode = legendModel.get('selectedMode');
  74229. var excludeSeriesId = [];
  74230. ecModel.eachRawSeries(function (seriesModel) {
  74231. !seriesModel.get('legendHoverLink') && excludeSeriesId.push(seriesModel.id);
  74232. });
  74233. each$25(legendModel.getData(), function (itemModel, dataIndex) {
  74234. var name = itemModel.get('name');
  74235. // Use empty string or \n as a newline string
  74236. if (!this.newlineDisabled && (name === '' || name === '\n')) {
  74237. contentGroup.add(new Group$3({
  74238. newline: true
  74239. }));
  74240. return;
  74241. }
  74242. // Representitive series.
  74243. var seriesModel = ecModel.getSeriesByName(name)[0];
  74244. if (legendDrawnMap.get(name)) {
  74245. // Have been drawed
  74246. return;
  74247. }
  74248. // Series legend
  74249. if (seriesModel) {
  74250. var data = seriesModel.getData();
  74251. var color = data.getVisual('color');
  74252. // If color is a callback function
  74253. if (typeof color === 'function') {
  74254. // Use the first data
  74255. color = color(seriesModel.getDataParams(0));
  74256. }
  74257. // Using rect symbol defaultly
  74258. var legendSymbolType = data.getVisual('legendSymbol') || 'roundRect';
  74259. var symbolType = data.getVisual('symbol');
  74260. var itemGroup = this._createItem(
  74261. name, dataIndex, itemModel, legendModel,
  74262. legendSymbolType, symbolType,
  74263. itemAlign, color,
  74264. selectMode
  74265. );
  74266. itemGroup.on('click', curry$6(dispatchSelectAction, name, api))
  74267. .on('mouseover', curry$6(dispatchHighlightAction, seriesModel.name, null, api, excludeSeriesId))
  74268. .on('mouseout', curry$6(dispatchDownplayAction, seriesModel.name, null, api, excludeSeriesId));
  74269. legendDrawnMap.set(name, true);
  74270. }
  74271. else {
  74272. // Data legend of pie, funnel
  74273. ecModel.eachRawSeries(function (seriesModel) {
  74274. // In case multiple series has same data name
  74275. if (legendDrawnMap.get(name)) {
  74276. return;
  74277. }
  74278. if (seriesModel.legendDataProvider) {
  74279. var data = seriesModel.legendDataProvider();
  74280. var idx = data.indexOfName(name);
  74281. if (idx < 0) {
  74282. return;
  74283. }
  74284. var color = data.getItemVisual(idx, 'color');
  74285. var legendSymbolType = 'roundRect';
  74286. var itemGroup = this._createItem(
  74287. name, dataIndex, itemModel, legendModel,
  74288. legendSymbolType, null,
  74289. itemAlign, color,
  74290. selectMode
  74291. );
  74292. // FIXME: consider different series has items with the same name.
  74293. itemGroup.on('click', curry$6(dispatchSelectAction, name, api))
  74294. // Should not specify the series name, consider legend controls
  74295. // more than one pie series.
  74296. .on('mouseover', curry$6(dispatchHighlightAction, null, name, api, excludeSeriesId))
  74297. .on('mouseout', curry$6(dispatchDownplayAction, null, name, api, excludeSeriesId));
  74298. legendDrawnMap.set(name, true);
  74299. }
  74300. }, this);
  74301. }
  74302. if (__DEV__) {
  74303. if (!legendDrawnMap.get(name)) {
  74304. console.warn(
  74305. name + ' series not exists. Legend data should be same with series name or data name.'
  74306. );
  74307. }
  74308. }
  74309. }, this);
  74310. },
  74311. _createItem: function (
  74312. name, dataIndex, itemModel, legendModel,
  74313. legendSymbolType, symbolType,
  74314. itemAlign, color, selectMode
  74315. ) {
  74316. var itemWidth = legendModel.get('itemWidth');
  74317. var itemHeight = legendModel.get('itemHeight');
  74318. var inactiveColor = legendModel.get('inactiveColor');
  74319. var symbolKeepAspect = legendModel.get('symbolKeepAspect');
  74320. var isSelected = legendModel.isSelected(name);
  74321. var itemGroup = new Group$3();
  74322. var textStyleModel = itemModel.getModel('textStyle');
  74323. var itemIcon = itemModel.get('icon');
  74324. var tooltipModel = itemModel.getModel('tooltip');
  74325. var legendGlobalTooltipModel = tooltipModel.parentModel;
  74326. // Use user given icon first
  74327. legendSymbolType = itemIcon || legendSymbolType;
  74328. itemGroup.add(createSymbol(
  74329. legendSymbolType,
  74330. 0,
  74331. 0,
  74332. itemWidth,
  74333. itemHeight,
  74334. isSelected ? color : inactiveColor,
  74335. // symbolKeepAspect default true for legend
  74336. symbolKeepAspect == null ? true : symbolKeepAspect
  74337. ));
  74338. // Compose symbols
  74339. // PENDING
  74340. if (!itemIcon && symbolType
  74341. // At least show one symbol, can't be all none
  74342. && ((symbolType !== legendSymbolType) || symbolType === 'none')
  74343. ) {
  74344. var size = itemHeight * 0.8;
  74345. if (symbolType === 'none') {
  74346. symbolType = 'circle';
  74347. }
  74348. // Put symbol in the center
  74349. itemGroup.add(createSymbol(
  74350. symbolType,
  74351. (itemWidth - size) / 2,
  74352. (itemHeight - size) / 2,
  74353. size,
  74354. size,
  74355. isSelected ? color : inactiveColor,
  74356. // symbolKeepAspect default true for legend
  74357. symbolKeepAspect == null ? true : symbolKeepAspect
  74358. ));
  74359. }
  74360. var textX = itemAlign === 'left' ? itemWidth + 5 : -5;
  74361. var textAlign = itemAlign;
  74362. var formatter = legendModel.get('formatter');
  74363. var content = name;
  74364. if (typeof formatter === 'string' && formatter) {
  74365. content = formatter.replace('{name}', name != null ? name : '');
  74366. }
  74367. else if (typeof formatter === 'function') {
  74368. content = formatter(name);
  74369. }
  74370. itemGroup.add(new Text({
  74371. style: setTextStyle({}, textStyleModel, {
  74372. text: content,
  74373. x: textX,
  74374. y: itemHeight / 2,
  74375. textFill: isSelected ? textStyleModel.getTextColor() : inactiveColor,
  74376. textAlign: textAlign,
  74377. textVerticalAlign: 'middle'
  74378. })
  74379. }));
  74380. // Add a invisible rect to increase the area of mouse hover
  74381. var hitRect = new Rect({
  74382. shape: itemGroup.getBoundingRect(),
  74383. invisible: true,
  74384. tooltip: tooltipModel.get('show') ? extend({
  74385. content: name,
  74386. // Defaul formatter
  74387. formatter: legendGlobalTooltipModel.get('formatter', true) || function () {
  74388. return name;
  74389. },
  74390. formatterParams: {
  74391. componentType: 'legend',
  74392. legendIndex: legendModel.componentIndex,
  74393. name: name,
  74394. $vars: ['name']
  74395. }
  74396. }, tooltipModel.option) : null
  74397. });
  74398. itemGroup.add(hitRect);
  74399. itemGroup.eachChild(function (child) {
  74400. child.silent = true;
  74401. });
  74402. hitRect.silent = !selectMode;
  74403. this.getContentGroup().add(itemGroup);
  74404. setHoverStyle(itemGroup);
  74405. itemGroup.__legendDataIndex = dataIndex;
  74406. return itemGroup;
  74407. },
  74408. /**
  74409. * @protected
  74410. */
  74411. layoutInner: function (legendModel, itemAlign, maxSize) {
  74412. var contentGroup = this.getContentGroup();
  74413. // Place items in contentGroup.
  74414. box(
  74415. legendModel.get('orient'),
  74416. contentGroup,
  74417. legendModel.get('itemGap'),
  74418. maxSize.width,
  74419. maxSize.height
  74420. );
  74421. var contentRect = contentGroup.getBoundingRect();
  74422. contentGroup.attr('position', [-contentRect.x, -contentRect.y]);
  74423. return this.group.getBoundingRect();
  74424. },
  74425. /**
  74426. * @protected
  74427. */
  74428. remove: function () {
  74429. this.getContentGroup().removeAll();
  74430. this._isFirstRender = true;
  74431. }
  74432. });
  74433. function dispatchSelectAction(name, api) {
  74434. api.dispatchAction({
  74435. type: 'legendToggleSelect',
  74436. name: name
  74437. });
  74438. }
  74439. function dispatchHighlightAction(seriesName, dataName, api, excludeSeriesId) {
  74440. // If element hover will move to a hoverLayer.
  74441. var el = api.getZr().storage.getDisplayList()[0];
  74442. if (!(el && el.useHoverLayer)) {
  74443. api.dispatchAction({
  74444. type: 'highlight',
  74445. seriesName: seriesName,
  74446. name: dataName,
  74447. excludeSeriesId: excludeSeriesId
  74448. });
  74449. }
  74450. }
  74451. function dispatchDownplayAction(seriesName, dataName, api, excludeSeriesId) {
  74452. // If element hover will move to a hoverLayer.
  74453. var el = api.getZr().storage.getDisplayList()[0];
  74454. if (!(el && el.useHoverLayer)) {
  74455. api.dispatchAction({
  74456. type: 'downplay',
  74457. seriesName: seriesName,
  74458. name: dataName,
  74459. excludeSeriesId: excludeSeriesId
  74460. });
  74461. }
  74462. }
  74463. /*
  74464. * Licensed to the Apache Software Foundation (ASF) under one
  74465. * or more contributor license agreements. See the NOTICE file
  74466. * distributed with this work for additional information
  74467. * regarding copyright ownership. The ASF licenses this file
  74468. * to you under the Apache License, Version 2.0 (the
  74469. * "License"); you may not use this file except in compliance
  74470. * with the License. You may obtain a copy of the License at
  74471. *
  74472. * http://www.apache.org/licenses/LICENSE-2.0
  74473. *
  74474. * Unless required by applicable law or agreed to in writing,
  74475. * software distributed under the License is distributed on an
  74476. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  74477. * KIND, either express or implied. See the License for the
  74478. * specific language governing permissions and limitations
  74479. * under the License.
  74480. */
  74481. var legendFilter = function (ecModel) {
  74482. var legendModels = ecModel.findComponents({
  74483. mainType: 'legend'
  74484. });
  74485. if (legendModels && legendModels.length) {
  74486. ecModel.filterSeries(function (series) {
  74487. // If in any legend component the status is not selected.
  74488. // Because in legend series is assumed selected when it is not in the legend data.
  74489. for (var i = 0; i < legendModels.length; i++) {
  74490. if (!legendModels[i].isSelected(series.name)) {
  74491. return false;
  74492. }
  74493. }
  74494. return true;
  74495. });
  74496. }
  74497. };
  74498. /*
  74499. * Licensed to the Apache Software Foundation (ASF) under one
  74500. * or more contributor license agreements. See the NOTICE file
  74501. * distributed with this work for additional information
  74502. * regarding copyright ownership. The ASF licenses this file
  74503. * to you under the Apache License, Version 2.0 (the
  74504. * "License"); you may not use this file except in compliance
  74505. * with the License. You may obtain a copy of the License at
  74506. *
  74507. * http://www.apache.org/licenses/LICENSE-2.0
  74508. *
  74509. * Unless required by applicable law or agreed to in writing,
  74510. * software distributed under the License is distributed on an
  74511. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  74512. * KIND, either express or implied. See the License for the
  74513. * specific language governing permissions and limitations
  74514. * under the License.
  74515. */
  74516. // Do not contain scrollable legend, for sake of file size.
  74517. // Series Filter
  74518. registerProcessor(legendFilter);
  74519. ComponentModel.registerSubTypeDefaulter('legend', function () {
  74520. // Default 'plain' when no type specified.
  74521. return 'plain';
  74522. });
  74523. /*
  74524. * Licensed to the Apache Software Foundation (ASF) under one
  74525. * or more contributor license agreements. See the NOTICE file
  74526. * distributed with this work for additional information
  74527. * regarding copyright ownership. The ASF licenses this file
  74528. * to you under the Apache License, Version 2.0 (the
  74529. * "License"); you may not use this file except in compliance
  74530. * with the License. You may obtain a copy of the License at
  74531. *
  74532. * http://www.apache.org/licenses/LICENSE-2.0
  74533. *
  74534. * Unless required by applicable law or agreed to in writing,
  74535. * software distributed under the License is distributed on an
  74536. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  74537. * KIND, either express or implied. See the License for the
  74538. * specific language governing permissions and limitations
  74539. * under the License.
  74540. */
  74541. var ScrollableLegendModel = LegendModel.extend({
  74542. type: 'legend.scroll',
  74543. /**
  74544. * @param {number} scrollDataIndex
  74545. */
  74546. setScrollDataIndex: function (scrollDataIndex) {
  74547. this.option.scrollDataIndex = scrollDataIndex;
  74548. },
  74549. defaultOption: {
  74550. scrollDataIndex: 0,
  74551. pageButtonItemGap: 5,
  74552. pageButtonGap: null,
  74553. pageButtonPosition: 'end', // 'start' or 'end'
  74554. pageFormatter: '{current}/{total}', // If null/undefined, do not show page.
  74555. pageIcons: {
  74556. horizontal: ['M0,0L12,-10L12,10z', 'M0,0L-12,-10L-12,10z'],
  74557. vertical: ['M0,0L20,0L10,-20z', 'M0,0L20,0L10,20z']
  74558. },
  74559. pageIconColor: '#2f4554',
  74560. pageIconInactiveColor: '#aaa',
  74561. pageIconSize: 15, // Can be [10, 3], which represents [width, height]
  74562. pageTextStyle: {
  74563. color: '#333'
  74564. },
  74565. animationDurationUpdate: 800
  74566. },
  74567. /**
  74568. * @override
  74569. */
  74570. init: function (option, parentModel, ecModel, extraOpt) {
  74571. var inputPositionParams = getLayoutParams(option);
  74572. ScrollableLegendModel.superCall(this, 'init', option, parentModel, ecModel, extraOpt);
  74573. mergeAndNormalizeLayoutParams$1(this, option, inputPositionParams);
  74574. },
  74575. /**
  74576. * @override
  74577. */
  74578. mergeOption: function (option, extraOpt) {
  74579. ScrollableLegendModel.superCall(this, 'mergeOption', option, extraOpt);
  74580. mergeAndNormalizeLayoutParams$1(this, this.option, option);
  74581. },
  74582. getOrient: function () {
  74583. return this.get('orient') === 'vertical'
  74584. ? {index: 1, name: 'vertical'}
  74585. : {index: 0, name: 'horizontal'};
  74586. }
  74587. });
  74588. // Do not `ignoreSize` to enable setting {left: 10, right: 10}.
  74589. function mergeAndNormalizeLayoutParams$1(legendModel, target, raw) {
  74590. var orient = legendModel.getOrient();
  74591. var ignoreSize = [1, 1];
  74592. ignoreSize[orient.index] = 0;
  74593. mergeLayoutParam(target, raw, {
  74594. type: 'box', ignoreSize: ignoreSize
  74595. });
  74596. }
  74597. /*
  74598. * Licensed to the Apache Software Foundation (ASF) under one
  74599. * or more contributor license agreements. See the NOTICE file
  74600. * distributed with this work for additional information
  74601. * regarding copyright ownership. The ASF licenses this file
  74602. * to you under the Apache License, Version 2.0 (the
  74603. * "License"); you may not use this file except in compliance
  74604. * with the License. You may obtain a copy of the License at
  74605. *
  74606. * http://www.apache.org/licenses/LICENSE-2.0
  74607. *
  74608. * Unless required by applicable law or agreed to in writing,
  74609. * software distributed under the License is distributed on an
  74610. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  74611. * KIND, either express or implied. See the License for the
  74612. * specific language governing permissions and limitations
  74613. * under the License.
  74614. */
  74615. /**
  74616. * Separate legend and scrollable legend to reduce package size.
  74617. */
  74618. var Group$4 = Group;
  74619. var WH$1 = ['width', 'height'];
  74620. var XY$1 = ['x', 'y'];
  74621. var ScrollableLegendView = LegendView.extend({
  74622. type: 'legend.scroll',
  74623. newlineDisabled: true,
  74624. init: function () {
  74625. ScrollableLegendView.superCall(this, 'init');
  74626. /**
  74627. * @private
  74628. * @type {number} For `scroll`.
  74629. */
  74630. this._currentIndex = 0;
  74631. /**
  74632. * @private
  74633. * @type {module:zrender/container/Group}
  74634. */
  74635. this.group.add(this._containerGroup = new Group$4());
  74636. this._containerGroup.add(this.getContentGroup());
  74637. /**
  74638. * @private
  74639. * @type {module:zrender/container/Group}
  74640. */
  74641. this.group.add(this._controllerGroup = new Group$4());
  74642. /**
  74643. *
  74644. * @private
  74645. */
  74646. this._showController;
  74647. },
  74648. /**
  74649. * @override
  74650. */
  74651. resetInner: function () {
  74652. ScrollableLegendView.superCall(this, 'resetInner');
  74653. this._controllerGroup.removeAll();
  74654. this._containerGroup.removeClipPath();
  74655. this._containerGroup.__rectSize = null;
  74656. },
  74657. /**
  74658. * @override
  74659. */
  74660. renderInner: function (itemAlign, legendModel, ecModel, api) {
  74661. var me = this;
  74662. // Render content items.
  74663. ScrollableLegendView.superCall(this, 'renderInner', itemAlign, legendModel, ecModel, api);
  74664. var controllerGroup = this._controllerGroup;
  74665. // FIXME: support be 'auto' adapt to size number text length,
  74666. // e.g., '3/12345' should not overlap with the control arrow button.
  74667. var pageIconSize = legendModel.get('pageIconSize', true);
  74668. if (!isArray(pageIconSize)) {
  74669. pageIconSize = [pageIconSize, pageIconSize];
  74670. }
  74671. createPageButton('pagePrev', 0);
  74672. var pageTextStyleModel = legendModel.getModel('pageTextStyle');
  74673. controllerGroup.add(new Text({
  74674. name: 'pageText',
  74675. style: {
  74676. textFill: pageTextStyleModel.getTextColor(),
  74677. font: pageTextStyleModel.getFont(),
  74678. textVerticalAlign: 'middle',
  74679. textAlign: 'center'
  74680. },
  74681. silent: true
  74682. }));
  74683. createPageButton('pageNext', 1);
  74684. function createPageButton(name, iconIdx) {
  74685. var pageDataIndexName = name + 'DataIndex';
  74686. var icon = createIcon(
  74687. legendModel.get('pageIcons', true)[legendModel.getOrient().name][iconIdx],
  74688. {
  74689. // Buttons will be created in each render, so we do not need
  74690. // to worry about avoiding using legendModel kept in scope.
  74691. onclick: bind(
  74692. me._pageGo, me, pageDataIndexName, legendModel, api
  74693. )
  74694. },
  74695. {
  74696. x: -pageIconSize[0] / 2,
  74697. y: -pageIconSize[1] / 2,
  74698. width: pageIconSize[0],
  74699. height: pageIconSize[1]
  74700. }
  74701. );
  74702. icon.name = name;
  74703. controllerGroup.add(icon);
  74704. }
  74705. },
  74706. /**
  74707. * @override
  74708. */
  74709. layoutInner: function (legendModel, itemAlign, maxSize, isFirstRender) {
  74710. var contentGroup = this.getContentGroup();
  74711. var containerGroup = this._containerGroup;
  74712. var controllerGroup = this._controllerGroup;
  74713. var orientIdx = legendModel.getOrient().index;
  74714. var wh = WH$1[orientIdx];
  74715. var hw = WH$1[1 - orientIdx];
  74716. var yx = XY$1[1 - orientIdx];
  74717. // Place items in contentGroup.
  74718. box(
  74719. legendModel.get('orient'),
  74720. contentGroup,
  74721. legendModel.get('itemGap'),
  74722. !orientIdx ? null : maxSize.width,
  74723. orientIdx ? null : maxSize.height
  74724. );
  74725. box(
  74726. // Buttons in controller are layout always horizontally.
  74727. 'horizontal',
  74728. controllerGroup,
  74729. legendModel.get('pageButtonItemGap', true)
  74730. );
  74731. var contentRect = contentGroup.getBoundingRect();
  74732. var controllerRect = controllerGroup.getBoundingRect();
  74733. var showController = this._showController = contentRect[wh] > maxSize[wh];
  74734. var contentPos = [-contentRect.x, -contentRect.y];
  74735. // Remain contentPos when scroll animation perfroming.
  74736. // If first rendering, `contentGroup.position` is [0, 0], which
  74737. // does not make sense and may cause unexepcted animation if adopted.
  74738. if (!isFirstRender) {
  74739. contentPos[orientIdx] = contentGroup.position[orientIdx];
  74740. }
  74741. // Layout container group based on 0.
  74742. var containerPos = [0, 0];
  74743. var controllerPos = [-controllerRect.x, -controllerRect.y];
  74744. var pageButtonGap = retrieve2(
  74745. legendModel.get('pageButtonGap', true), legendModel.get('itemGap', true)
  74746. );
  74747. // Place containerGroup and controllerGroup and contentGroup.
  74748. if (showController) {
  74749. var pageButtonPosition = legendModel.get('pageButtonPosition', true);
  74750. // controller is on the right / bottom.
  74751. if (pageButtonPosition === 'end') {
  74752. controllerPos[orientIdx] += maxSize[wh] - controllerRect[wh];
  74753. }
  74754. // controller is on the left / top.
  74755. else {
  74756. containerPos[orientIdx] += controllerRect[wh] + pageButtonGap;
  74757. }
  74758. }
  74759. // Always align controller to content as 'middle'.
  74760. controllerPos[1 - orientIdx] += contentRect[hw] / 2 - controllerRect[hw] / 2;
  74761. contentGroup.attr('position', contentPos);
  74762. containerGroup.attr('position', containerPos);
  74763. controllerGroup.attr('position', controllerPos);
  74764. // Calculate `mainRect` and set `clipPath`.
  74765. // mainRect should not be calculated by `this.group.getBoundingRect()`
  74766. // for sake of the overflow.
  74767. var mainRect = this.group.getBoundingRect();
  74768. var mainRect = {x: 0, y: 0};
  74769. // Consider content may be overflow (should be clipped).
  74770. mainRect[wh] = showController ? maxSize[wh] : contentRect[wh];
  74771. mainRect[hw] = Math.max(contentRect[hw], controllerRect[hw]);
  74772. // `containerRect[yx] + containerPos[1 - orientIdx]` is 0.
  74773. mainRect[yx] = Math.min(0, controllerRect[yx] + controllerPos[1 - orientIdx]);
  74774. containerGroup.__rectSize = maxSize[wh];
  74775. if (showController) {
  74776. var clipShape = {x: 0, y: 0};
  74777. clipShape[wh] = Math.max(maxSize[wh] - controllerRect[wh] - pageButtonGap, 0);
  74778. clipShape[hw] = mainRect[hw];
  74779. containerGroup.setClipPath(new Rect({shape: clipShape}));
  74780. // Consider content may be larger than container, container rect
  74781. // can not be obtained from `containerGroup.getBoundingRect()`.
  74782. containerGroup.__rectSize = clipShape[wh];
  74783. }
  74784. else {
  74785. // Do not remove or ignore controller. Keep them set as place holders.
  74786. controllerGroup.eachChild(function (child) {
  74787. child.attr({invisible: true, silent: true});
  74788. });
  74789. }
  74790. // Content translate animation.
  74791. var pageInfo = this._getPageInfo(legendModel);
  74792. pageInfo.pageIndex != null && updateProps(
  74793. contentGroup,
  74794. {position: pageInfo.contentPosition},
  74795. // When switch from "show controller" to "not show controller", view should be
  74796. // updated immediately without animation, otherwise causes weird efffect.
  74797. showController ? legendModel : false
  74798. );
  74799. this._updatePageInfoView(legendModel, pageInfo);
  74800. return mainRect;
  74801. },
  74802. _pageGo: function (to, legendModel, api) {
  74803. var scrollDataIndex = this._getPageInfo(legendModel)[to];
  74804. scrollDataIndex != null && api.dispatchAction({
  74805. type: 'legendScroll',
  74806. scrollDataIndex: scrollDataIndex,
  74807. legendId: legendModel.id
  74808. });
  74809. },
  74810. _updatePageInfoView: function (legendModel, pageInfo) {
  74811. var controllerGroup = this._controllerGroup;
  74812. each$1(['pagePrev', 'pageNext'], function (name) {
  74813. var canJump = pageInfo[name + 'DataIndex'] != null;
  74814. var icon = controllerGroup.childOfName(name);
  74815. if (icon) {
  74816. icon.setStyle(
  74817. 'fill',
  74818. canJump
  74819. ? legendModel.get('pageIconColor', true)
  74820. : legendModel.get('pageIconInactiveColor', true)
  74821. );
  74822. icon.cursor = canJump ? 'pointer' : 'default';
  74823. }
  74824. });
  74825. var pageText = controllerGroup.childOfName('pageText');
  74826. var pageFormatter = legendModel.get('pageFormatter');
  74827. var pageIndex = pageInfo.pageIndex;
  74828. var current = pageIndex != null ? pageIndex + 1 : 0;
  74829. var total = pageInfo.pageCount;
  74830. pageText && pageFormatter && pageText.setStyle(
  74831. 'text',
  74832. isString(pageFormatter)
  74833. ? pageFormatter.replace('{current}', current).replace('{total}', total)
  74834. : pageFormatter({current: current, total: total})
  74835. );
  74836. },
  74837. /**
  74838. * @param {module:echarts/model/Model} legendModel
  74839. * @return {Object} {
  74840. * contentPosition: Array.<number>, null when data item not found.
  74841. * pageIndex: number, null when data item not found.
  74842. * pageCount: number, always be a number, can be 0.
  74843. * pagePrevDataIndex: number, null when no next page.
  74844. * pageNextDataIndex: number, null when no previous page.
  74845. * }
  74846. */
  74847. _getPageInfo: function (legendModel) {
  74848. var scrollDataIndex = legendModel.get('scrollDataIndex', true);
  74849. var contentGroup = this.getContentGroup();
  74850. var containerRectSize = this._containerGroup.__rectSize;
  74851. var orientIdx = legendModel.getOrient().index;
  74852. var wh = WH$1[orientIdx];
  74853. var xy = XY$1[orientIdx];
  74854. var targetItemIndex = this._findTargetItemIndex(scrollDataIndex);
  74855. var children = contentGroup.children();
  74856. var targetItem = children[targetItemIndex];
  74857. var itemCount = children.length;
  74858. var pCount = !itemCount ? 0 : 1;
  74859. var result = {
  74860. contentPosition: contentGroup.position.slice(),
  74861. pageCount: pCount,
  74862. pageIndex: pCount - 1,
  74863. pagePrevDataIndex: null,
  74864. pageNextDataIndex: null
  74865. };
  74866. if (!targetItem) {
  74867. return result;
  74868. }
  74869. var targetItemInfo = getItemInfo(targetItem);
  74870. result.contentPosition[orientIdx] = -targetItemInfo.s;
  74871. // Strategy:
  74872. // (1) Always align based on the left/top most item.
  74873. // (2) It is user-friendly that the last item shown in the
  74874. // current window is shown at the begining of next window.
  74875. // Otherwise if half of the last item is cut by the window,
  74876. // it will have no chance to display entirely.
  74877. // (3) Consider that item size probably be different, we
  74878. // have calculate pageIndex by size rather than item index,
  74879. // and we can not get page index directly by division.
  74880. // (4) The window is to narrow to contain more than
  74881. // one item, we should make sure that the page can be fliped.
  74882. for (var i = targetItemIndex + 1,
  74883. winStartItemInfo = targetItemInfo,
  74884. winEndItemInfo = targetItemInfo,
  74885. currItemInfo = null;
  74886. i <= itemCount;
  74887. ++i
  74888. ) {
  74889. currItemInfo = getItemInfo(children[i]);
  74890. if (
  74891. // Half of the last item is out of the window.
  74892. (!currItemInfo && winEndItemInfo.e > winStartItemInfo.s + containerRectSize)
  74893. // If the current item does not intersect with the window, the new page
  74894. // can be started at the current item or the last item.
  74895. || (currItemInfo && !intersect(currItemInfo, winStartItemInfo.s))
  74896. ) {
  74897. if (winEndItemInfo.i > winStartItemInfo.i) {
  74898. winStartItemInfo = winEndItemInfo;
  74899. }
  74900. else { // e.g., when page size is smaller than item size.
  74901. winStartItemInfo = currItemInfo;
  74902. }
  74903. if (winStartItemInfo) {
  74904. if (result.pageNextDataIndex == null) {
  74905. result.pageNextDataIndex = winStartItemInfo.i;
  74906. }
  74907. ++result.pageCount;
  74908. }
  74909. }
  74910. winEndItemInfo = currItemInfo;
  74911. }
  74912. for (var i = targetItemIndex - 1,
  74913. winStartItemInfo = targetItemInfo,
  74914. winEndItemInfo = targetItemInfo,
  74915. currItemInfo = null;
  74916. i >= -1;
  74917. --i
  74918. ) {
  74919. currItemInfo = getItemInfo(children[i]);
  74920. if (
  74921. // If the the end item does not intersect with the window started
  74922. // from the current item, a page can be settled.
  74923. (!currItemInfo || !intersect(winEndItemInfo, currItemInfo.s))
  74924. // e.g., when page size is smaller than item size.
  74925. && winStartItemInfo.i < winEndItemInfo.i
  74926. ) {
  74927. winEndItemInfo = winStartItemInfo;
  74928. if (result.pagePrevDataIndex == null) {
  74929. result.pagePrevDataIndex = winStartItemInfo.i;
  74930. }
  74931. ++result.pageCount;
  74932. ++result.pageIndex;
  74933. }
  74934. winStartItemInfo = currItemInfo;
  74935. }
  74936. return result;
  74937. function getItemInfo(el) {
  74938. if (el) {
  74939. var itemRect = el.getBoundingRect();
  74940. var start = itemRect[xy] + el.position[orientIdx];
  74941. return {
  74942. s: start,
  74943. e: start + itemRect[wh],
  74944. i: el.__legendDataIndex
  74945. };
  74946. }
  74947. }
  74948. function intersect(itemInfo, winStart) {
  74949. return itemInfo.e >= winStart && itemInfo.s <= winStart + containerRectSize;
  74950. }
  74951. },
  74952. _findTargetItemIndex: function (targetDataIndex) {
  74953. var index;
  74954. var contentGroup = this.getContentGroup();
  74955. var defaultIndex;
  74956. if (this._showController) {
  74957. contentGroup.eachChild(function (child, idx) {
  74958. var legendDataIdx = child.__legendDataIndex;
  74959. // FIXME
  74960. // If the given targetDataIndex (from model) is illegal,
  74961. // we use defualtIndex. But the index on the legend model and
  74962. // action payload is still illegal. That case will not be
  74963. // changed until some scenario requires.
  74964. if (defaultIndex == null && legendDataIdx != null) {
  74965. defaultIndex = idx;
  74966. }
  74967. if (legendDataIdx === targetDataIndex) {
  74968. index = idx;
  74969. }
  74970. });
  74971. }
  74972. return index != null ? index : defaultIndex;
  74973. }
  74974. });
  74975. /*
  74976. * Licensed to the Apache Software Foundation (ASF) under one
  74977. * or more contributor license agreements. See the NOTICE file
  74978. * distributed with this work for additional information
  74979. * regarding copyright ownership. The ASF licenses this file
  74980. * to you under the Apache License, Version 2.0 (the
  74981. * "License"); you may not use this file except in compliance
  74982. * with the License. You may obtain a copy of the License at
  74983. *
  74984. * http://www.apache.org/licenses/LICENSE-2.0
  74985. *
  74986. * Unless required by applicable law or agreed to in writing,
  74987. * software distributed under the License is distributed on an
  74988. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  74989. * KIND, either express or implied. See the License for the
  74990. * specific language governing permissions and limitations
  74991. * under the License.
  74992. */
  74993. /**
  74994. * @event legendScroll
  74995. * @type {Object}
  74996. * @property {string} type 'legendScroll'
  74997. * @property {string} scrollDataIndex
  74998. */
  74999. registerAction(
  75000. 'legendScroll', 'legendscroll',
  75001. function (payload, ecModel) {
  75002. var scrollDataIndex = payload.scrollDataIndex;
  75003. scrollDataIndex != null && ecModel.eachComponent(
  75004. {mainType: 'legend', subType: 'scroll', query: payload},
  75005. function (legendModel) {
  75006. legendModel.setScrollDataIndex(scrollDataIndex);
  75007. }
  75008. );
  75009. }
  75010. );
  75011. /*
  75012. * Licensed to the Apache Software Foundation (ASF) under one
  75013. * or more contributor license agreements. See the NOTICE file
  75014. * distributed with this work for additional information
  75015. * regarding copyright ownership. The ASF licenses this file
  75016. * to you under the Apache License, Version 2.0 (the
  75017. * "License"); you may not use this file except in compliance
  75018. * with the License. You may obtain a copy of the License at
  75019. *
  75020. * http://www.apache.org/licenses/LICENSE-2.0
  75021. *
  75022. * Unless required by applicable law or agreed to in writing,
  75023. * software distributed under the License is distributed on an
  75024. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  75025. * KIND, either express or implied. See the License for the
  75026. * specific language governing permissions and limitations
  75027. * under the License.
  75028. */
  75029. /**
  75030. * Legend component entry file8
  75031. */
  75032. /*
  75033. * Licensed to the Apache Software Foundation (ASF) under one
  75034. * or more contributor license agreements. See the NOTICE file
  75035. * distributed with this work for additional information
  75036. * regarding copyright ownership. The ASF licenses this file
  75037. * to you under the Apache License, Version 2.0 (the
  75038. * "License"); you may not use this file except in compliance
  75039. * with the License. You may obtain a copy of the License at
  75040. *
  75041. * http://www.apache.org/licenses/LICENSE-2.0
  75042. *
  75043. * Unless required by applicable law or agreed to in writing,
  75044. * software distributed under the License is distributed on an
  75045. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  75046. * KIND, either express or implied. See the License for the
  75047. * specific language governing permissions and limitations
  75048. * under the License.
  75049. */
  75050. var SliderZoomModel = DataZoomModel.extend({
  75051. type: 'dataZoom.slider',
  75052. layoutMode: 'box',
  75053. /**
  75054. * @protected
  75055. */
  75056. defaultOption: {
  75057. show: true,
  75058. // ph => placeholder. Using placehoder here because
  75059. // deault value can only be drived in view stage.
  75060. right: 'ph', // Default align to grid rect.
  75061. top: 'ph', // Default align to grid rect.
  75062. width: 'ph', // Default align to grid rect.
  75063. height: 'ph', // Default align to grid rect.
  75064. left: null, // Default align to grid rect.
  75065. bottom: null, // Default align to grid rect.
  75066. backgroundColor: 'rgba(47,69,84,0)', // Background of slider zoom component.
  75067. // dataBackgroundColor: '#ddd', // Background coor of data shadow and border of box,
  75068. // highest priority, remain for compatibility of
  75069. // previous version, but not recommended any more.
  75070. dataBackground: {
  75071. lineStyle: {
  75072. color: '#2f4554',
  75073. width: 0.5,
  75074. opacity: 0.3
  75075. },
  75076. areaStyle: {
  75077. color: 'rgba(47,69,84,0.3)',
  75078. opacity: 0.3
  75079. }
  75080. },
  75081. borderColor: '#ddd', // border color of the box. For compatibility,
  75082. // if dataBackgroundColor is set, borderColor
  75083. // is ignored.
  75084. fillerColor: 'rgba(167,183,204,0.4)', // Color of selected area.
  75085. // handleColor: 'rgba(89,170,216,0.95)', // Color of handle.
  75086. // 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',
  75087. /* eslint-disable */
  75088. 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',
  75089. /* eslint-enable */
  75090. // Percent of the slider height
  75091. handleSize: '100%',
  75092. handleStyle: {
  75093. color: '#a7b7cc'
  75094. },
  75095. labelPrecision: null,
  75096. labelFormatter: null,
  75097. showDetail: true,
  75098. showDataShadow: 'auto', // Default auto decision.
  75099. realtime: true,
  75100. zoomLock: false, // Whether disable zoom.
  75101. textStyle: {
  75102. color: '#333'
  75103. }
  75104. }
  75105. });
  75106. /*
  75107. * Licensed to the Apache Software Foundation (ASF) under one
  75108. * or more contributor license agreements. See the NOTICE file
  75109. * distributed with this work for additional information
  75110. * regarding copyright ownership. The ASF licenses this file
  75111. * to you under the Apache License, Version 2.0 (the
  75112. * "License"); you may not use this file except in compliance
  75113. * with the License. You may obtain a copy of the License at
  75114. *
  75115. * http://www.apache.org/licenses/LICENSE-2.0
  75116. *
  75117. * Unless required by applicable law or agreed to in writing,
  75118. * software distributed under the License is distributed on an
  75119. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  75120. * KIND, either express or implied. See the License for the
  75121. * specific language governing permissions and limitations
  75122. * under the License.
  75123. */
  75124. var Rect$2 = Rect;
  75125. var linearMap$1 = linearMap;
  75126. var asc$2 = asc;
  75127. var bind$5 = bind;
  75128. var each$26 = each$1;
  75129. // Constants
  75130. var DEFAULT_LOCATION_EDGE_GAP = 7;
  75131. var DEFAULT_FRAME_BORDER_WIDTH = 1;
  75132. var DEFAULT_FILLER_SIZE = 30;
  75133. var HORIZONTAL = 'horizontal';
  75134. var VERTICAL = 'vertical';
  75135. var LABEL_GAP = 5;
  75136. var SHOW_DATA_SHADOW_SERIES_TYPE = ['line', 'bar', 'candlestick', 'scatter'];
  75137. var SliderZoomView = DataZoomView.extend({
  75138. type: 'dataZoom.slider',
  75139. init: function (ecModel, api) {
  75140. /**
  75141. * @private
  75142. * @type {Object}
  75143. */
  75144. this._displayables = {};
  75145. /**
  75146. * @private
  75147. * @type {string}
  75148. */
  75149. this._orient;
  75150. /**
  75151. * [0, 100]
  75152. * @private
  75153. */
  75154. this._range;
  75155. /**
  75156. * [coord of the first handle, coord of the second handle]
  75157. * @private
  75158. */
  75159. this._handleEnds;
  75160. /**
  75161. * [length, thick]
  75162. * @private
  75163. * @type {Array.<number>}
  75164. */
  75165. this._size;
  75166. /**
  75167. * @private
  75168. * @type {number}
  75169. */
  75170. this._handleWidth;
  75171. /**
  75172. * @private
  75173. * @type {number}
  75174. */
  75175. this._handleHeight;
  75176. /**
  75177. * @private
  75178. */
  75179. this._location;
  75180. /**
  75181. * @private
  75182. */
  75183. this._dragging;
  75184. /**
  75185. * @private
  75186. */
  75187. this._dataShadowInfo;
  75188. this.api = api;
  75189. },
  75190. /**
  75191. * @override
  75192. */
  75193. render: function (dataZoomModel, ecModel, api, payload) {
  75194. SliderZoomView.superApply(this, 'render', arguments);
  75195. createOrUpdate(
  75196. this,
  75197. '_dispatchZoomAction',
  75198. this.dataZoomModel.get('throttle'),
  75199. 'fixRate'
  75200. );
  75201. this._orient = dataZoomModel.get('orient');
  75202. if (this.dataZoomModel.get('show') === false) {
  75203. this.group.removeAll();
  75204. return;
  75205. }
  75206. // Notice: this._resetInterval() should not be executed when payload.type
  75207. // is 'dataZoom', origin this._range should be maintained, otherwise 'pan'
  75208. // or 'zoom' info will be missed because of 'throttle' of this.dispatchAction,
  75209. if (!payload || payload.type !== 'dataZoom' || payload.from !== this.uid) {
  75210. this._buildView();
  75211. }
  75212. this._updateView();
  75213. },
  75214. /**
  75215. * @override
  75216. */
  75217. remove: function () {
  75218. SliderZoomView.superApply(this, 'remove', arguments);
  75219. clear(this, '_dispatchZoomAction');
  75220. },
  75221. /**
  75222. * @override
  75223. */
  75224. dispose: function () {
  75225. SliderZoomView.superApply(this, 'dispose', arguments);
  75226. clear(this, '_dispatchZoomAction');
  75227. },
  75228. _buildView: function () {
  75229. var thisGroup = this.group;
  75230. thisGroup.removeAll();
  75231. this._resetLocation();
  75232. this._resetInterval();
  75233. var barGroup = this._displayables.barGroup = new Group();
  75234. this._renderBackground();
  75235. this._renderHandle();
  75236. this._renderDataShadow();
  75237. thisGroup.add(barGroup);
  75238. this._positionGroup();
  75239. },
  75240. /**
  75241. * @private
  75242. */
  75243. _resetLocation: function () {
  75244. var dataZoomModel = this.dataZoomModel;
  75245. var api = this.api;
  75246. // If some of x/y/width/height are not specified,
  75247. // auto-adapt according to target grid.
  75248. var coordRect = this._findCoordRect();
  75249. var ecSize = {width: api.getWidth(), height: api.getHeight()};
  75250. // Default align by coordinate system rect.
  75251. var positionInfo = this._orient === HORIZONTAL
  75252. ? {
  75253. // Why using 'right', because right should be used in vertical,
  75254. // and it is better to be consistent for dealing with position param merge.
  75255. right: ecSize.width - coordRect.x - coordRect.width,
  75256. top: (ecSize.height - DEFAULT_FILLER_SIZE - DEFAULT_LOCATION_EDGE_GAP),
  75257. width: coordRect.width,
  75258. height: DEFAULT_FILLER_SIZE
  75259. }
  75260. : { // vertical
  75261. right: DEFAULT_LOCATION_EDGE_GAP,
  75262. top: coordRect.y,
  75263. width: DEFAULT_FILLER_SIZE,
  75264. height: coordRect.height
  75265. };
  75266. // Do not write back to option and replace value 'ph', because
  75267. // the 'ph' value should be recalculated when resize.
  75268. var layoutParams = getLayoutParams(dataZoomModel.option);
  75269. // Replace the placeholder value.
  75270. each$1(['right', 'top', 'width', 'height'], function (name) {
  75271. if (layoutParams[name] === 'ph') {
  75272. layoutParams[name] = positionInfo[name];
  75273. }
  75274. });
  75275. var layoutRect = getLayoutRect(
  75276. layoutParams,
  75277. ecSize,
  75278. dataZoomModel.padding
  75279. );
  75280. this._location = {x: layoutRect.x, y: layoutRect.y};
  75281. this._size = [layoutRect.width, layoutRect.height];
  75282. this._orient === VERTICAL && this._size.reverse();
  75283. },
  75284. /**
  75285. * @private
  75286. */
  75287. _positionGroup: function () {
  75288. var thisGroup = this.group;
  75289. var location = this._location;
  75290. var orient = this._orient;
  75291. // Just use the first axis to determine mapping.
  75292. var targetAxisModel = this.dataZoomModel.getFirstTargetAxisModel();
  75293. var inverse = targetAxisModel && targetAxisModel.get('inverse');
  75294. var barGroup = this._displayables.barGroup;
  75295. var otherAxisInverse = (this._dataShadowInfo || {}).otherAxisInverse;
  75296. // Transform barGroup.
  75297. barGroup.attr(
  75298. (orient === HORIZONTAL && !inverse)
  75299. ? {scale: otherAxisInverse ? [1, 1] : [1, -1]}
  75300. : (orient === HORIZONTAL && inverse)
  75301. ? {scale: otherAxisInverse ? [-1, 1] : [-1, -1]}
  75302. : (orient === VERTICAL && !inverse)
  75303. ? {scale: otherAxisInverse ? [1, -1] : [1, 1], rotation: Math.PI / 2}
  75304. // Dont use Math.PI, considering shadow direction.
  75305. : {scale: otherAxisInverse ? [-1, -1] : [-1, 1], rotation: Math.PI / 2}
  75306. );
  75307. // Position barGroup
  75308. var rect = thisGroup.getBoundingRect([barGroup]);
  75309. thisGroup.attr('position', [location.x - rect.x, location.y - rect.y]);
  75310. },
  75311. /**
  75312. * @private
  75313. */
  75314. _getViewExtent: function () {
  75315. return [0, this._size[0]];
  75316. },
  75317. _renderBackground: function () {
  75318. var dataZoomModel = this.dataZoomModel;
  75319. var size = this._size;
  75320. var barGroup = this._displayables.barGroup;
  75321. barGroup.add(new Rect$2({
  75322. silent: true,
  75323. shape: {
  75324. x: 0, y: 0, width: size[0], height: size[1]
  75325. },
  75326. style: {
  75327. fill: dataZoomModel.get('backgroundColor')
  75328. },
  75329. z2: -40
  75330. }));
  75331. // Click panel, over shadow, below handles.
  75332. barGroup.add(new Rect$2({
  75333. shape: {
  75334. x: 0, y: 0, width: size[0], height: size[1]
  75335. },
  75336. style: {
  75337. fill: 'transparent'
  75338. },
  75339. z2: 0,
  75340. onclick: bind(this._onClickPanelClick, this)
  75341. }));
  75342. },
  75343. _renderDataShadow: function () {
  75344. var info = this._dataShadowInfo = this._prepareDataShadowInfo();
  75345. if (!info) {
  75346. return;
  75347. }
  75348. var size = this._size;
  75349. var seriesModel = info.series;
  75350. var data = seriesModel.getRawData();
  75351. var otherDim = seriesModel.getShadowDim
  75352. ? seriesModel.getShadowDim() // @see candlestick
  75353. : info.otherDim;
  75354. if (otherDim == null) {
  75355. return;
  75356. }
  75357. var otherDataExtent = data.getDataExtent(otherDim);
  75358. // Nice extent.
  75359. var otherOffset = (otherDataExtent[1] - otherDataExtent[0]) * 0.3;
  75360. otherDataExtent = [
  75361. otherDataExtent[0] - otherOffset,
  75362. otherDataExtent[1] + otherOffset
  75363. ];
  75364. var otherShadowExtent = [0, size[1]];
  75365. var thisShadowExtent = [0, size[0]];
  75366. var areaPoints = [[size[0], 0], [0, 0]];
  75367. var linePoints = [];
  75368. var step = thisShadowExtent[1] / (data.count() - 1);
  75369. var thisCoord = 0;
  75370. // Optimize for large data shadow
  75371. var stride = Math.round(data.count() / size[0]);
  75372. var lastIsEmpty;
  75373. data.each([otherDim], function (value, index) {
  75374. if (stride > 0 && (index % stride)) {
  75375. thisCoord += step;
  75376. return;
  75377. }
  75378. // FIXME
  75379. // Should consider axis.min/axis.max when drawing dataShadow.
  75380. // FIXME
  75381. // 应该使用统一的空判断?还是在list里进行空判断?
  75382. var isEmpty = value == null || isNaN(value) || value === '';
  75383. // See #4235.
  75384. var otherCoord = isEmpty
  75385. ? 0 : linearMap$1(value, otherDataExtent, otherShadowExtent, true);
  75386. // Attempt to draw data shadow precisely when there are empty value.
  75387. if (isEmpty && !lastIsEmpty && index) {
  75388. areaPoints.push([areaPoints[areaPoints.length - 1][0], 0]);
  75389. linePoints.push([linePoints[linePoints.length - 1][0], 0]);
  75390. }
  75391. else if (!isEmpty && lastIsEmpty) {
  75392. areaPoints.push([thisCoord, 0]);
  75393. linePoints.push([thisCoord, 0]);
  75394. }
  75395. areaPoints.push([thisCoord, otherCoord]);
  75396. linePoints.push([thisCoord, otherCoord]);
  75397. thisCoord += step;
  75398. lastIsEmpty = isEmpty;
  75399. });
  75400. var dataZoomModel = this.dataZoomModel;
  75401. // var dataBackgroundModel = dataZoomModel.getModel('dataBackground');
  75402. this._displayables.barGroup.add(new Polygon({
  75403. shape: {points: areaPoints},
  75404. style: defaults(
  75405. {fill: dataZoomModel.get('dataBackgroundColor')},
  75406. dataZoomModel.getModel('dataBackground.areaStyle').getAreaStyle()
  75407. ),
  75408. silent: true,
  75409. z2: -20
  75410. }));
  75411. this._displayables.barGroup.add(new Polyline({
  75412. shape: {points: linePoints},
  75413. style: dataZoomModel.getModel('dataBackground.lineStyle').getLineStyle(),
  75414. silent: true,
  75415. z2: -19
  75416. }));
  75417. },
  75418. _prepareDataShadowInfo: function () {
  75419. var dataZoomModel = this.dataZoomModel;
  75420. var showDataShadow = dataZoomModel.get('showDataShadow');
  75421. if (showDataShadow === false) {
  75422. return;
  75423. }
  75424. // Find a representative series.
  75425. var result;
  75426. var ecModel = this.ecModel;
  75427. dataZoomModel.eachTargetAxis(function (dimNames, axisIndex) {
  75428. var seriesModels = dataZoomModel
  75429. .getAxisProxy(dimNames.name, axisIndex)
  75430. .getTargetSeriesModels();
  75431. each$1(seriesModels, function (seriesModel) {
  75432. if (result) {
  75433. return;
  75434. }
  75435. if (showDataShadow !== true && indexOf(
  75436. SHOW_DATA_SHADOW_SERIES_TYPE, seriesModel.get('type')
  75437. ) < 0
  75438. ) {
  75439. return;
  75440. }
  75441. var thisAxis = ecModel.getComponent(dimNames.axis, axisIndex).axis;
  75442. var otherDim = getOtherDim(dimNames.name);
  75443. var otherAxisInverse;
  75444. var coordSys = seriesModel.coordinateSystem;
  75445. if (otherDim != null && coordSys.getOtherAxis) {
  75446. otherAxisInverse = coordSys.getOtherAxis(thisAxis).inverse;
  75447. }
  75448. otherDim = seriesModel.getData().mapDimension(otherDim);
  75449. result = {
  75450. thisAxis: thisAxis,
  75451. series: seriesModel,
  75452. thisDim: dimNames.name,
  75453. otherDim: otherDim,
  75454. otherAxisInverse: otherAxisInverse
  75455. };
  75456. }, this);
  75457. }, this);
  75458. return result;
  75459. },
  75460. _renderHandle: function () {
  75461. var displaybles = this._displayables;
  75462. var handles = displaybles.handles = [];
  75463. var handleLabels = displaybles.handleLabels = [];
  75464. var barGroup = this._displayables.barGroup;
  75465. var size = this._size;
  75466. var dataZoomModel = this.dataZoomModel;
  75467. barGroup.add(displaybles.filler = new Rect$2({
  75468. draggable: true,
  75469. cursor: getCursor(this._orient),
  75470. drift: bind$5(this._onDragMove, this, 'all'),
  75471. onmousemove: function (e) {
  75472. // Fot mobile devicem, prevent screen slider on the button.
  75473. stop(e.event);
  75474. },
  75475. ondragstart: bind$5(this._showDataInfo, this, true),
  75476. ondragend: bind$5(this._onDragEnd, this),
  75477. onmouseover: bind$5(this._showDataInfo, this, true),
  75478. onmouseout: bind$5(this._showDataInfo, this, false),
  75479. style: {
  75480. fill: dataZoomModel.get('fillerColor'),
  75481. textPosition: 'inside'
  75482. }
  75483. }));
  75484. // Frame border.
  75485. barGroup.add(new Rect$2({
  75486. silent: true,
  75487. subPixelOptimize: true,
  75488. shape: {
  75489. x: 0,
  75490. y: 0,
  75491. width: size[0],
  75492. height: size[1]
  75493. },
  75494. style: {
  75495. stroke: dataZoomModel.get('dataBackgroundColor')
  75496. || dataZoomModel.get('borderColor'),
  75497. lineWidth: DEFAULT_FRAME_BORDER_WIDTH,
  75498. fill: 'rgba(0,0,0,0)'
  75499. }
  75500. }));
  75501. each$26([0, 1], function (handleIndex) {
  75502. var path = createIcon(
  75503. dataZoomModel.get('handleIcon'),
  75504. {
  75505. cursor: getCursor(this._orient),
  75506. draggable: true,
  75507. drift: bind$5(this._onDragMove, this, handleIndex),
  75508. onmousemove: function (e) {
  75509. // Fot mobile devicem, prevent screen slider on the button.
  75510. stop(e.event);
  75511. },
  75512. ondragend: bind$5(this._onDragEnd, this),
  75513. onmouseover: bind$5(this._showDataInfo, this, true),
  75514. onmouseout: bind$5(this._showDataInfo, this, false)
  75515. },
  75516. {x: -1, y: 0, width: 2, height: 2}
  75517. );
  75518. var bRect = path.getBoundingRect();
  75519. this._handleHeight = parsePercent$1(dataZoomModel.get('handleSize'), this._size[1]);
  75520. this._handleWidth = bRect.width / bRect.height * this._handleHeight;
  75521. path.setStyle(dataZoomModel.getModel('handleStyle').getItemStyle());
  75522. var handleColor = dataZoomModel.get('handleColor');
  75523. // Compatitable with previous version
  75524. if (handleColor != null) {
  75525. path.style.fill = handleColor;
  75526. }
  75527. barGroup.add(handles[handleIndex] = path);
  75528. var textStyleModel = dataZoomModel.textStyleModel;
  75529. this.group.add(
  75530. handleLabels[handleIndex] = new Text({
  75531. silent: true,
  75532. invisible: true,
  75533. style: {
  75534. x: 0, y: 0, text: '',
  75535. textVerticalAlign: 'middle',
  75536. textAlign: 'center',
  75537. textFill: textStyleModel.getTextColor(),
  75538. textFont: textStyleModel.getFont()
  75539. },
  75540. z2: 10
  75541. }));
  75542. }, this);
  75543. },
  75544. /**
  75545. * @private
  75546. */
  75547. _resetInterval: function () {
  75548. var range = this._range = this.dataZoomModel.getPercentRange();
  75549. var viewExtent = this._getViewExtent();
  75550. this._handleEnds = [
  75551. linearMap$1(range[0], [0, 100], viewExtent, true),
  75552. linearMap$1(range[1], [0, 100], viewExtent, true)
  75553. ];
  75554. },
  75555. /**
  75556. * @private
  75557. * @param {(number|string)} handleIndex 0 or 1 or 'all'
  75558. * @param {number} delta
  75559. * @return {boolean} changed
  75560. */
  75561. _updateInterval: function (handleIndex, delta) {
  75562. var dataZoomModel = this.dataZoomModel;
  75563. var handleEnds = this._handleEnds;
  75564. var viewExtend = this._getViewExtent();
  75565. var minMaxSpan = dataZoomModel.findRepresentativeAxisProxy().getMinMaxSpan();
  75566. var percentExtent = [0, 100];
  75567. sliderMove(
  75568. delta,
  75569. handleEnds,
  75570. viewExtend,
  75571. dataZoomModel.get('zoomLock') ? 'all' : handleIndex,
  75572. minMaxSpan.minSpan != null
  75573. ? linearMap$1(minMaxSpan.minSpan, percentExtent, viewExtend, true) : null,
  75574. minMaxSpan.maxSpan != null
  75575. ? linearMap$1(minMaxSpan.maxSpan, percentExtent, viewExtend, true) : null
  75576. );
  75577. var lastRange = this._range;
  75578. var range = this._range = asc$2([
  75579. linearMap$1(handleEnds[0], viewExtend, percentExtent, true),
  75580. linearMap$1(handleEnds[1], viewExtend, percentExtent, true)
  75581. ]);
  75582. return !lastRange || lastRange[0] !== range[0] || lastRange[1] !== range[1];
  75583. },
  75584. /**
  75585. * @private
  75586. */
  75587. _updateView: function (nonRealtime) {
  75588. var displaybles = this._displayables;
  75589. var handleEnds = this._handleEnds;
  75590. var handleInterval = asc$2(handleEnds.slice());
  75591. var size = this._size;
  75592. each$26([0, 1], function (handleIndex) {
  75593. // Handles
  75594. var handle = displaybles.handles[handleIndex];
  75595. var handleHeight = this._handleHeight;
  75596. handle.attr({
  75597. scale: [handleHeight / 2, handleHeight / 2],
  75598. position: [handleEnds[handleIndex], size[1] / 2 - handleHeight / 2]
  75599. });
  75600. }, this);
  75601. // Filler
  75602. displaybles.filler.setShape({
  75603. x: handleInterval[0],
  75604. y: 0,
  75605. width: handleInterval[1] - handleInterval[0],
  75606. height: size[1]
  75607. });
  75608. this._updateDataInfo(nonRealtime);
  75609. },
  75610. /**
  75611. * @private
  75612. */
  75613. _updateDataInfo: function (nonRealtime) {
  75614. var dataZoomModel = this.dataZoomModel;
  75615. var displaybles = this._displayables;
  75616. var handleLabels = displaybles.handleLabels;
  75617. var orient = this._orient;
  75618. var labelTexts = ['', ''];
  75619. // FIXME
  75620. // date型,支持formatter,autoformatter(ec2 date.getAutoFormatter)
  75621. if (dataZoomModel.get('showDetail')) {
  75622. var axisProxy = dataZoomModel.findRepresentativeAxisProxy();
  75623. if (axisProxy) {
  75624. var axis = axisProxy.getAxisModel().axis;
  75625. var range = this._range;
  75626. var dataInterval = nonRealtime
  75627. // See #4434, data and axis are not processed and reset yet in non-realtime mode.
  75628. ? axisProxy.calculateDataWindow({
  75629. start: range[0], end: range[1]
  75630. }).valueWindow
  75631. : axisProxy.getDataValueWindow();
  75632. labelTexts = [
  75633. this._formatLabel(dataInterval[0], axis),
  75634. this._formatLabel(dataInterval[1], axis)
  75635. ];
  75636. }
  75637. }
  75638. var orderedHandleEnds = asc$2(this._handleEnds.slice());
  75639. setLabel.call(this, 0);
  75640. setLabel.call(this, 1);
  75641. function setLabel(handleIndex) {
  75642. // Label
  75643. // Text should not transform by barGroup.
  75644. // Ignore handlers transform
  75645. var barTransform = getTransform(
  75646. displaybles.handles[handleIndex].parent, this.group
  75647. );
  75648. var direction = transformDirection(
  75649. handleIndex === 0 ? 'right' : 'left', barTransform
  75650. );
  75651. var offset = this._handleWidth / 2 + LABEL_GAP;
  75652. var textPoint = applyTransform$1(
  75653. [
  75654. orderedHandleEnds[handleIndex] + (handleIndex === 0 ? -offset : offset),
  75655. this._size[1] / 2
  75656. ],
  75657. barTransform
  75658. );
  75659. handleLabels[handleIndex].setStyle({
  75660. x: textPoint[0],
  75661. y: textPoint[1],
  75662. textVerticalAlign: orient === HORIZONTAL ? 'middle' : direction,
  75663. textAlign: orient === HORIZONTAL ? direction : 'center',
  75664. text: labelTexts[handleIndex]
  75665. });
  75666. }
  75667. },
  75668. /**
  75669. * @private
  75670. */
  75671. _formatLabel: function (value, axis) {
  75672. var dataZoomModel = this.dataZoomModel;
  75673. var labelFormatter = dataZoomModel.get('labelFormatter');
  75674. var labelPrecision = dataZoomModel.get('labelPrecision');
  75675. if (labelPrecision == null || labelPrecision === 'auto') {
  75676. labelPrecision = axis.getPixelPrecision();
  75677. }
  75678. var valueStr = (value == null || isNaN(value))
  75679. ? ''
  75680. // FIXME Glue code
  75681. : (axis.type === 'category' || axis.type === 'time')
  75682. ? axis.scale.getLabel(Math.round(value))
  75683. // param of toFixed should less then 20.
  75684. : value.toFixed(Math.min(labelPrecision, 20));
  75685. return isFunction$1(labelFormatter)
  75686. ? labelFormatter(value, valueStr)
  75687. : isString(labelFormatter)
  75688. ? labelFormatter.replace('{value}', valueStr)
  75689. : valueStr;
  75690. },
  75691. /**
  75692. * @private
  75693. * @param {boolean} showOrHide true: show, false: hide
  75694. */
  75695. _showDataInfo: function (showOrHide) {
  75696. // Always show when drgging.
  75697. showOrHide = this._dragging || showOrHide;
  75698. var handleLabels = this._displayables.handleLabels;
  75699. handleLabels[0].attr('invisible', !showOrHide);
  75700. handleLabels[1].attr('invisible', !showOrHide);
  75701. },
  75702. _onDragMove: function (handleIndex, dx, dy) {
  75703. this._dragging = true;
  75704. // Transform dx, dy to bar coordination.
  75705. var barTransform = this._displayables.barGroup.getLocalTransform();
  75706. var vertex = applyTransform$1([dx, dy], barTransform, true);
  75707. var changed = this._updateInterval(handleIndex, vertex[0]);
  75708. var realtime = this.dataZoomModel.get('realtime');
  75709. this._updateView(!realtime);
  75710. // Avoid dispatch dataZoom repeatly but range not changed,
  75711. // which cause bad visual effect when progressive enabled.
  75712. changed && realtime && this._dispatchZoomAction();
  75713. },
  75714. _onDragEnd: function () {
  75715. this._dragging = false;
  75716. this._showDataInfo(false);
  75717. // While in realtime mode and stream mode, dispatch action when
  75718. // drag end will cause the whole view rerender, which is unnecessary.
  75719. var realtime = this.dataZoomModel.get('realtime');
  75720. !realtime && this._dispatchZoomAction();
  75721. },
  75722. _onClickPanelClick: function (e) {
  75723. var size = this._size;
  75724. var localPoint = this._displayables.barGroup.transformCoordToLocal(e.offsetX, e.offsetY);
  75725. if (localPoint[0] < 0 || localPoint[0] > size[0]
  75726. || localPoint[1] < 0 || localPoint[1] > size[1]
  75727. ) {
  75728. return;
  75729. }
  75730. var handleEnds = this._handleEnds;
  75731. var center = (handleEnds[0] + handleEnds[1]) / 2;
  75732. var changed = this._updateInterval('all', localPoint[0] - center);
  75733. this._updateView();
  75734. changed && this._dispatchZoomAction();
  75735. },
  75736. /**
  75737. * This action will be throttled.
  75738. * @private
  75739. */
  75740. _dispatchZoomAction: function () {
  75741. var range = this._range;
  75742. this.api.dispatchAction({
  75743. type: 'dataZoom',
  75744. from: this.uid,
  75745. dataZoomId: this.dataZoomModel.id,
  75746. start: range[0],
  75747. end: range[1]
  75748. });
  75749. },
  75750. /**
  75751. * @private
  75752. */
  75753. _findCoordRect: function () {
  75754. // Find the grid coresponding to the first axis referred by dataZoom.
  75755. var rect;
  75756. each$26(this.getTargetCoordInfo(), function (coordInfoList) {
  75757. if (!rect && coordInfoList.length) {
  75758. var coordSys = coordInfoList[0].model.coordinateSystem;
  75759. rect = coordSys.getRect && coordSys.getRect();
  75760. }
  75761. });
  75762. if (!rect) {
  75763. var width = this.api.getWidth();
  75764. var height = this.api.getHeight();
  75765. rect = {
  75766. x: width * 0.2,
  75767. y: height * 0.2,
  75768. width: width * 0.6,
  75769. height: height * 0.6
  75770. };
  75771. }
  75772. return rect;
  75773. }
  75774. });
  75775. function getOtherDim(thisDim) {
  75776. // FIXME
  75777. // 这个逻辑和getOtherAxis里一致,但是写在这里是否不好
  75778. var map$$1 = {x: 'y', y: 'x', radius: 'angle', angle: 'radius'};
  75779. return map$$1[thisDim];
  75780. }
  75781. function getCursor(orient) {
  75782. return orient === 'vertical' ? 'ns-resize' : 'ew-resize';
  75783. }
  75784. /*
  75785. * Licensed to the Apache Software Foundation (ASF) under one
  75786. * or more contributor license agreements. See the NOTICE file
  75787. * distributed with this work for additional information
  75788. * regarding copyright ownership. The ASF licenses this file
  75789. * to you under the Apache License, Version 2.0 (the
  75790. * "License"); you may not use this file except in compliance
  75791. * with the License. You may obtain a copy of the License at
  75792. *
  75793. * http://www.apache.org/licenses/LICENSE-2.0
  75794. *
  75795. * Unless required by applicable law or agreed to in writing,
  75796. * software distributed under the License is distributed on an
  75797. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  75798. * KIND, either express or implied. See the License for the
  75799. * specific language governing permissions and limitations
  75800. * under the License.
  75801. */
  75802. /*
  75803. * Licensed to the Apache Software Foundation (ASF) under one
  75804. * or more contributor license agreements. See the NOTICE file
  75805. * distributed with this work for additional information
  75806. * regarding copyright ownership. The ASF licenses this file
  75807. * to you under the Apache License, Version 2.0 (the
  75808. * "License"); you may not use this file except in compliance
  75809. * with the License. You may obtain a copy of the License at
  75810. *
  75811. * http://www.apache.org/licenses/LICENSE-2.0
  75812. *
  75813. * Unless required by applicable law or agreed to in writing,
  75814. * software distributed under the License is distributed on an
  75815. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  75816. * KIND, either express or implied. See the License for the
  75817. * specific language governing permissions and limitations
  75818. * under the License.
  75819. */
  75820. DataZoomModel.extend({
  75821. type: 'dataZoom.inside',
  75822. /**
  75823. * @protected
  75824. */
  75825. defaultOption: {
  75826. disabled: false, // Whether disable this inside zoom.
  75827. zoomLock: false, // Whether disable zoom but only pan.
  75828. zoomOnMouseWheel: true, // Can be: true / false / 'shift' / 'ctrl' / 'alt'.
  75829. moveOnMouseMove: true, // Can be: true / false / 'shift' / 'ctrl' / 'alt'.
  75830. moveOnMouseWheel: false, // Can be: true / false / 'shift' / 'ctrl' / 'alt'.
  75831. preventDefaultMouseMove: true
  75832. }
  75833. });
  75834. /*
  75835. * Licensed to the Apache Software Foundation (ASF) under one
  75836. * or more contributor license agreements. See the NOTICE file
  75837. * distributed with this work for additional information
  75838. * regarding copyright ownership. The ASF licenses this file
  75839. * to you under the Apache License, Version 2.0 (the
  75840. * "License"); you may not use this file except in compliance
  75841. * with the License. You may obtain a copy of the License at
  75842. *
  75843. * http://www.apache.org/licenses/LICENSE-2.0
  75844. *
  75845. * Unless required by applicable law or agreed to in writing,
  75846. * software distributed under the License is distributed on an
  75847. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  75848. * KIND, either express or implied. See the License for the
  75849. * specific language governing permissions and limitations
  75850. * under the License.
  75851. */
  75852. // Only create one roam controller for each coordinate system.
  75853. // one roam controller might be refered by two inside data zoom
  75854. // components (for example, one for x and one for y). When user
  75855. // pan or zoom, only dispatch one action for those data zoom
  75856. // components.
  75857. var ATTR$2 = '\0_ec_dataZoom_roams';
  75858. /**
  75859. * @public
  75860. * @param {module:echarts/ExtensionAPI} api
  75861. * @param {Object} dataZoomInfo
  75862. * @param {string} dataZoomInfo.coordId
  75863. * @param {Function} dataZoomInfo.containsPoint
  75864. * @param {Array.<string>} dataZoomInfo.allCoordIds
  75865. * @param {string} dataZoomInfo.dataZoomId
  75866. * @param {Object} dataZoomInfo.getRange
  75867. * @param {Function} dataZoomInfo.getRange.pan
  75868. * @param {Function} dataZoomInfo.getRange.zoom
  75869. * @param {Function} dataZoomInfo.getRange.scrollMove
  75870. * @param {boolean} dataZoomInfo.dataZoomModel
  75871. */
  75872. function register$2(api, dataZoomInfo) {
  75873. var store = giveStore$1(api);
  75874. var theDataZoomId = dataZoomInfo.dataZoomId;
  75875. var theCoordId = dataZoomInfo.coordId;
  75876. // Do clean when a dataZoom changes its target coordnate system.
  75877. // Avoid memory leak, dispose all not-used-registered.
  75878. each$1(store, function (record, coordId) {
  75879. var dataZoomInfos = record.dataZoomInfos;
  75880. if (dataZoomInfos[theDataZoomId]
  75881. && indexOf(dataZoomInfo.allCoordIds, theCoordId) < 0
  75882. ) {
  75883. delete dataZoomInfos[theDataZoomId];
  75884. record.count--;
  75885. }
  75886. });
  75887. cleanStore(store);
  75888. var record = store[theCoordId];
  75889. // Create if needed.
  75890. if (!record) {
  75891. record = store[theCoordId] = {
  75892. coordId: theCoordId,
  75893. dataZoomInfos: {},
  75894. count: 0
  75895. };
  75896. record.controller = createController(api, record);
  75897. record.dispatchAction = curry(dispatchAction$1, api);
  75898. }
  75899. // Update reference of dataZoom.
  75900. !(record.dataZoomInfos[theDataZoomId]) && record.count++;
  75901. record.dataZoomInfos[theDataZoomId] = dataZoomInfo;
  75902. var controllerParams = mergeControllerParams(record.dataZoomInfos);
  75903. record.controller.enable(controllerParams.controlType, controllerParams.opt);
  75904. // Consider resize, area should be always updated.
  75905. record.controller.setPointerChecker(dataZoomInfo.containsPoint);
  75906. // Update throttle.
  75907. createOrUpdate(
  75908. record,
  75909. 'dispatchAction',
  75910. dataZoomInfo.dataZoomModel.get('throttle', true),
  75911. 'fixRate'
  75912. );
  75913. }
  75914. /**
  75915. * @public
  75916. * @param {module:echarts/ExtensionAPI} api
  75917. * @param {string} dataZoomId
  75918. */
  75919. function unregister$1(api, dataZoomId) {
  75920. var store = giveStore$1(api);
  75921. each$1(store, function (record) {
  75922. record.controller.dispose();
  75923. var dataZoomInfos = record.dataZoomInfos;
  75924. if (dataZoomInfos[dataZoomId]) {
  75925. delete dataZoomInfos[dataZoomId];
  75926. record.count--;
  75927. }
  75928. });
  75929. cleanStore(store);
  75930. }
  75931. /**
  75932. * @public
  75933. */
  75934. function generateCoordId(coordModel) {
  75935. return coordModel.type + '\0_' + coordModel.id;
  75936. }
  75937. /**
  75938. * Key: coordId, value: {dataZoomInfos: [], count, controller}
  75939. * @type {Array.<Object>}
  75940. */
  75941. function giveStore$1(api) {
  75942. // Mount store on zrender instance, so that we do not
  75943. // need to worry about dispose.
  75944. var zr = api.getZr();
  75945. return zr[ATTR$2] || (zr[ATTR$2] = {});
  75946. }
  75947. function createController(api, newRecord) {
  75948. var controller = new RoamController(api.getZr());
  75949. each$1(['pan', 'zoom', 'scrollMove'], function (eventName) {
  75950. controller.on(eventName, function (event) {
  75951. var batch = [];
  75952. each$1(newRecord.dataZoomInfos, function (info) {
  75953. // Check whether the behaviors (zoomOnMouseWheel, moveOnMouseMove,
  75954. // moveOnMouseWheel, ...) enabled.
  75955. if (!event.isAvailableBehavior(info.dataZoomModel.option)) {
  75956. return;
  75957. }
  75958. var method = (info.getRange || {})[eventName];
  75959. var range = method && method(newRecord.controller, event);
  75960. !info.dataZoomModel.get('disabled', true) && range && batch.push({
  75961. dataZoomId: info.dataZoomId,
  75962. start: range[0],
  75963. end: range[1]
  75964. });
  75965. });
  75966. batch.length && newRecord.dispatchAction(batch);
  75967. });
  75968. });
  75969. return controller;
  75970. }
  75971. function cleanStore(store) {
  75972. each$1(store, function (record, coordId) {
  75973. if (!record.count) {
  75974. record.controller.dispose();
  75975. delete store[coordId];
  75976. }
  75977. });
  75978. }
  75979. /**
  75980. * This action will be throttled.
  75981. */
  75982. function dispatchAction$1(api, batch) {
  75983. api.dispatchAction({
  75984. type: 'dataZoom',
  75985. batch: batch
  75986. });
  75987. }
  75988. /**
  75989. * Merge roamController settings when multiple dataZooms share one roamController.
  75990. */
  75991. function mergeControllerParams(dataZoomInfos) {
  75992. var controlType;
  75993. // DO NOT use reserved word (true, false, undefined) as key literally. Even if encapsulated
  75994. // as string, it is probably revert to reserved word by compress tool. See #7411.
  75995. var prefix = 'type_';
  75996. var typePriority = {
  75997. 'type_true': 2,
  75998. 'type_move': 1,
  75999. 'type_false': 0,
  76000. 'type_undefined': -1
  76001. };
  76002. var preventDefaultMouseMove = true;
  76003. each$1(dataZoomInfos, function (dataZoomInfo) {
  76004. var dataZoomModel = dataZoomInfo.dataZoomModel;
  76005. var oneType = dataZoomModel.get('disabled', true)
  76006. ? false
  76007. : dataZoomModel.get('zoomLock', true)
  76008. ? 'move'
  76009. : true;
  76010. if (typePriority[prefix + oneType] > typePriority[prefix + controlType]) {
  76011. controlType = oneType;
  76012. }
  76013. // Prevent default move event by default. If one false, do not prevent. Otherwise
  76014. // users may be confused why it does not work when multiple insideZooms exist.
  76015. preventDefaultMouseMove &= dataZoomModel.get('preventDefaultMouseMove', true);
  76016. });
  76017. return {
  76018. controlType: controlType,
  76019. opt: {
  76020. // RoamController will enable all of these functionalities,
  76021. // and the final behavior is determined by its event listener
  76022. // provided by each inside zoom.
  76023. zoomOnMouseWheel: true,
  76024. moveOnMouseMove: true,
  76025. moveOnMouseWheel: true,
  76026. preventDefaultMouseMove: !!preventDefaultMouseMove
  76027. }
  76028. };
  76029. }
  76030. /*
  76031. * Licensed to the Apache Software Foundation (ASF) under one
  76032. * or more contributor license agreements. See the NOTICE file
  76033. * distributed with this work for additional information
  76034. * regarding copyright ownership. The ASF licenses this file
  76035. * to you under the Apache License, Version 2.0 (the
  76036. * "License"); you may not use this file except in compliance
  76037. * with the License. You may obtain a copy of the License at
  76038. *
  76039. * http://www.apache.org/licenses/LICENSE-2.0
  76040. *
  76041. * Unless required by applicable law or agreed to in writing,
  76042. * software distributed under the License is distributed on an
  76043. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  76044. * KIND, either express or implied. See the License for the
  76045. * specific language governing permissions and limitations
  76046. * under the License.
  76047. */
  76048. var bind$6 = bind;
  76049. var InsideZoomView = DataZoomView.extend({
  76050. type: 'dataZoom.inside',
  76051. /**
  76052. * @override
  76053. */
  76054. init: function (ecModel, api) {
  76055. /**
  76056. * 'throttle' is used in this.dispatchAction, so we save range
  76057. * to avoid missing some 'pan' info.
  76058. * @private
  76059. * @type {Array.<number>}
  76060. */
  76061. this._range;
  76062. },
  76063. /**
  76064. * @override
  76065. */
  76066. render: function (dataZoomModel, ecModel, api, payload) {
  76067. InsideZoomView.superApply(this, 'render', arguments);
  76068. // Hence the `throttle` util ensures to preserve command order,
  76069. // here simply updating range all the time will not cause missing
  76070. // any of the the roam change.
  76071. this._range = dataZoomModel.getPercentRange();
  76072. // Reset controllers.
  76073. each$1(this.getTargetCoordInfo(), function (coordInfoList, coordSysName) {
  76074. var allCoordIds = map(coordInfoList, function (coordInfo) {
  76075. return generateCoordId(coordInfo.model);
  76076. });
  76077. each$1(coordInfoList, function (coordInfo) {
  76078. var coordModel = coordInfo.model;
  76079. var getRange = {};
  76080. each$1(['pan', 'zoom', 'scrollMove'], function (eventName) {
  76081. getRange[eventName] = bind$6(roamHandlers[eventName], this, coordInfo, coordSysName);
  76082. }, this);
  76083. register$2(
  76084. api,
  76085. {
  76086. coordId: generateCoordId(coordModel),
  76087. allCoordIds: allCoordIds,
  76088. containsPoint: function (e, x, y) {
  76089. return coordModel.coordinateSystem.containPoint([x, y]);
  76090. },
  76091. dataZoomId: dataZoomModel.id,
  76092. dataZoomModel: dataZoomModel,
  76093. getRange: getRange
  76094. }
  76095. );
  76096. }, this);
  76097. }, this);
  76098. },
  76099. /**
  76100. * @override
  76101. */
  76102. dispose: function () {
  76103. unregister$1(this.api, this.dataZoomModel.id);
  76104. InsideZoomView.superApply(this, 'dispose', arguments);
  76105. this._range = null;
  76106. }
  76107. });
  76108. var roamHandlers = {
  76109. /**
  76110. * @this {module:echarts/component/dataZoom/InsideZoomView}
  76111. */
  76112. zoom: function (coordInfo, coordSysName, controller, e) {
  76113. var lastRange = this._range;
  76114. var range = lastRange.slice();
  76115. // Calculate transform by the first axis.
  76116. var axisModel = coordInfo.axisModels[0];
  76117. if (!axisModel) {
  76118. return;
  76119. }
  76120. var directionInfo = getDirectionInfo[coordSysName](
  76121. null, [e.originX, e.originY], axisModel, controller, coordInfo
  76122. );
  76123. var percentPoint = (
  76124. directionInfo.signal > 0
  76125. ? (directionInfo.pixelStart + directionInfo.pixelLength - directionInfo.pixel)
  76126. : (directionInfo.pixel - directionInfo.pixelStart)
  76127. ) / directionInfo.pixelLength * (range[1] - range[0]) + range[0];
  76128. var scale = Math.max(1 / e.scale, 0);
  76129. range[0] = (range[0] - percentPoint) * scale + percentPoint;
  76130. range[1] = (range[1] - percentPoint) * scale + percentPoint;
  76131. // Restrict range.
  76132. var minMaxSpan = this.dataZoomModel.findRepresentativeAxisProxy().getMinMaxSpan();
  76133. sliderMove(0, range, [0, 100], 0, minMaxSpan.minSpan, minMaxSpan.maxSpan);
  76134. this._range = range;
  76135. if (lastRange[0] !== range[0] || lastRange[1] !== range[1]) {
  76136. return range;
  76137. }
  76138. },
  76139. /**
  76140. * @this {module:echarts/component/dataZoom/InsideZoomView}
  76141. */
  76142. pan: makeMover(function (range, axisModel, coordInfo, coordSysName, controller, e) {
  76143. var directionInfo = getDirectionInfo[coordSysName](
  76144. [e.oldX, e.oldY], [e.newX, e.newY], axisModel, controller, coordInfo
  76145. );
  76146. return directionInfo.signal
  76147. * (range[1] - range[0])
  76148. * directionInfo.pixel / directionInfo.pixelLength;
  76149. }),
  76150. /**
  76151. * @this {module:echarts/component/dataZoom/InsideZoomView}
  76152. */
  76153. scrollMove: makeMover(function (range, axisModel, coordInfo, coordSysName, controller, e) {
  76154. var directionInfo = getDirectionInfo[coordSysName](
  76155. [0, 0], [e.scrollDelta, e.scrollDelta], axisModel, controller, coordInfo
  76156. );
  76157. return directionInfo.signal * (range[1] - range[0]) * e.scrollDelta;
  76158. })
  76159. };
  76160. function makeMover(getPercentDelta) {
  76161. return function (coordInfo, coordSysName, controller, e) {
  76162. var lastRange = this._range;
  76163. var range = lastRange.slice();
  76164. // Calculate transform by the first axis.
  76165. var axisModel = coordInfo.axisModels[0];
  76166. if (!axisModel) {
  76167. return;
  76168. }
  76169. var percentDelta = getPercentDelta(
  76170. range, axisModel, coordInfo, coordSysName, controller, e
  76171. );
  76172. sliderMove(percentDelta, range, [0, 100], 'all');
  76173. this._range = range;
  76174. if (lastRange[0] !== range[0] || lastRange[1] !== range[1]) {
  76175. return range;
  76176. }
  76177. };
  76178. }
  76179. var getDirectionInfo = {
  76180. grid: function (oldPoint, newPoint, axisModel, controller, coordInfo) {
  76181. var axis = axisModel.axis;
  76182. var ret = {};
  76183. var rect = coordInfo.model.coordinateSystem.getRect();
  76184. oldPoint = oldPoint || [0, 0];
  76185. if (axis.dim === 'x') {
  76186. ret.pixel = newPoint[0] - oldPoint[0];
  76187. ret.pixelLength = rect.width;
  76188. ret.pixelStart = rect.x;
  76189. ret.signal = axis.inverse ? 1 : -1;
  76190. }
  76191. else { // axis.dim === 'y'
  76192. ret.pixel = newPoint[1] - oldPoint[1];
  76193. ret.pixelLength = rect.height;
  76194. ret.pixelStart = rect.y;
  76195. ret.signal = axis.inverse ? -1 : 1;
  76196. }
  76197. return ret;
  76198. },
  76199. polar: function (oldPoint, newPoint, axisModel, controller, coordInfo) {
  76200. var axis = axisModel.axis;
  76201. var ret = {};
  76202. var polar = coordInfo.model.coordinateSystem;
  76203. var radiusExtent = polar.getRadiusAxis().getExtent();
  76204. var angleExtent = polar.getAngleAxis().getExtent();
  76205. oldPoint = oldPoint ? polar.pointToCoord(oldPoint) : [0, 0];
  76206. newPoint = polar.pointToCoord(newPoint);
  76207. if (axisModel.mainType === 'radiusAxis') {
  76208. ret.pixel = newPoint[0] - oldPoint[0];
  76209. // ret.pixelLength = Math.abs(radiusExtent[1] - radiusExtent[0]);
  76210. // ret.pixelStart = Math.min(radiusExtent[0], radiusExtent[1]);
  76211. ret.pixelLength = radiusExtent[1] - radiusExtent[0];
  76212. ret.pixelStart = radiusExtent[0];
  76213. ret.signal = axis.inverse ? 1 : -1;
  76214. }
  76215. else { // 'angleAxis'
  76216. ret.pixel = newPoint[1] - oldPoint[1];
  76217. // ret.pixelLength = Math.abs(angleExtent[1] - angleExtent[0]);
  76218. // ret.pixelStart = Math.min(angleExtent[0], angleExtent[1]);
  76219. ret.pixelLength = angleExtent[1] - angleExtent[0];
  76220. ret.pixelStart = angleExtent[0];
  76221. ret.signal = axis.inverse ? -1 : 1;
  76222. }
  76223. return ret;
  76224. },
  76225. singleAxis: function (oldPoint, newPoint, axisModel, controller, coordInfo) {
  76226. var axis = axisModel.axis;
  76227. var rect = coordInfo.model.coordinateSystem.getRect();
  76228. var ret = {};
  76229. oldPoint = oldPoint || [0, 0];
  76230. if (axis.orient === 'horizontal') {
  76231. ret.pixel = newPoint[0] - oldPoint[0];
  76232. ret.pixelLength = rect.width;
  76233. ret.pixelStart = rect.x;
  76234. ret.signal = axis.inverse ? 1 : -1;
  76235. }
  76236. else { // 'vertical'
  76237. ret.pixel = newPoint[1] - oldPoint[1];
  76238. ret.pixelLength = rect.height;
  76239. ret.pixelStart = rect.y;
  76240. ret.signal = axis.inverse ? -1 : 1;
  76241. }
  76242. return ret;
  76243. }
  76244. };
  76245. /*
  76246. * Licensed to the Apache Software Foundation (ASF) under one
  76247. * or more contributor license agreements. See the NOTICE file
  76248. * distributed with this work for additional information
  76249. * regarding copyright ownership. The ASF licenses this file
  76250. * to you under the Apache License, Version 2.0 (the
  76251. * "License"); you may not use this file except in compliance
  76252. * with the License. You may obtain a copy of the License at
  76253. *
  76254. * http://www.apache.org/licenses/LICENSE-2.0
  76255. *
  76256. * Unless required by applicable law or agreed to in writing,
  76257. * software distributed under the License is distributed on an
  76258. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  76259. * KIND, either express or implied. See the License for the
  76260. * specific language governing permissions and limitations
  76261. * under the License.
  76262. */
  76263. /*
  76264. * Licensed to the Apache Software Foundation (ASF) under one
  76265. * or more contributor license agreements. See the NOTICE file
  76266. * distributed with this work for additional information
  76267. * regarding copyright ownership. The ASF licenses this file
  76268. * to you under the Apache License, Version 2.0 (the
  76269. * "License"); you may not use this file except in compliance
  76270. * with the License. You may obtain a copy of the License at
  76271. *
  76272. * http://www.apache.org/licenses/LICENSE-2.0
  76273. *
  76274. * Unless required by applicable law or agreed to in writing,
  76275. * software distributed under the License is distributed on an
  76276. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  76277. * KIND, either express or implied. See the License for the
  76278. * specific language governing permissions and limitations
  76279. * under the License.
  76280. */
  76281. // Do not include './dataZoomSelect',
  76282. // since it only work for toolbox dataZoom.
  76283. /*
  76284. * Licensed to the Apache Software Foundation (ASF) under one
  76285. * or more contributor license agreements. See the NOTICE file
  76286. * distributed with this work for additional information
  76287. * regarding copyright ownership. The ASF licenses this file
  76288. * to you under the Apache License, Version 2.0 (the
  76289. * "License"); you may not use this file except in compliance
  76290. * with the License. You may obtain a copy of the License at
  76291. *
  76292. * http://www.apache.org/licenses/LICENSE-2.0
  76293. *
  76294. * Unless required by applicable law or agreed to in writing,
  76295. * software distributed under the License is distributed on an
  76296. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  76297. * KIND, either express or implied. See the License for the
  76298. * specific language governing permissions and limitations
  76299. * under the License.
  76300. */
  76301. var each$27 = each$1;
  76302. var preprocessor$3 = function (option) {
  76303. var visualMap = option && option.visualMap;
  76304. if (!isArray(visualMap)) {
  76305. visualMap = visualMap ? [visualMap] : [];
  76306. }
  76307. each$27(visualMap, function (opt) {
  76308. if (!opt) {
  76309. return;
  76310. }
  76311. // rename splitList to pieces
  76312. if (has$2(opt, 'splitList') && !has$2(opt, 'pieces')) {
  76313. opt.pieces = opt.splitList;
  76314. delete opt.splitList;
  76315. }
  76316. var pieces = opt.pieces;
  76317. if (pieces && isArray(pieces)) {
  76318. each$27(pieces, function (piece) {
  76319. if (isObject$1(piece)) {
  76320. if (has$2(piece, 'start') && !has$2(piece, 'min')) {
  76321. piece.min = piece.start;
  76322. }
  76323. if (has$2(piece, 'end') && !has$2(piece, 'max')) {
  76324. piece.max = piece.end;
  76325. }
  76326. }
  76327. });
  76328. }
  76329. });
  76330. };
  76331. function has$2(obj, name) {
  76332. return obj && obj.hasOwnProperty && obj.hasOwnProperty(name);
  76333. }
  76334. /*
  76335. * Licensed to the Apache Software Foundation (ASF) under one
  76336. * or more contributor license agreements. See the NOTICE file
  76337. * distributed with this work for additional information
  76338. * regarding copyright ownership. The ASF licenses this file
  76339. * to you under the Apache License, Version 2.0 (the
  76340. * "License"); you may not use this file except in compliance
  76341. * with the License. You may obtain a copy of the License at
  76342. *
  76343. * http://www.apache.org/licenses/LICENSE-2.0
  76344. *
  76345. * Unless required by applicable law or agreed to in writing,
  76346. * software distributed under the License is distributed on an
  76347. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  76348. * KIND, either express or implied. See the License for the
  76349. * specific language governing permissions and limitations
  76350. * under the License.
  76351. */
  76352. ComponentModel.registerSubTypeDefaulter('visualMap', function (option) {
  76353. // Compatible with ec2, when splitNumber === 0, continuous visualMap will be used.
  76354. return (
  76355. !option.categories
  76356. && (
  76357. !(
  76358. option.pieces
  76359. ? option.pieces.length > 0
  76360. : option.splitNumber > 0
  76361. )
  76362. || option.calculable
  76363. )
  76364. )
  76365. ? 'continuous' : 'piecewise';
  76366. });
  76367. /*
  76368. * Licensed to the Apache Software Foundation (ASF) under one
  76369. * or more contributor license agreements. See the NOTICE file
  76370. * distributed with this work for additional information
  76371. * regarding copyright ownership. The ASF licenses this file
  76372. * to you under the Apache License, Version 2.0 (the
  76373. * "License"); you may not use this file except in compliance
  76374. * with the License. You may obtain a copy of the License at
  76375. *
  76376. * http://www.apache.org/licenses/LICENSE-2.0
  76377. *
  76378. * Unless required by applicable law or agreed to in writing,
  76379. * software distributed under the License is distributed on an
  76380. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  76381. * KIND, either express or implied. See the License for the
  76382. * specific language governing permissions and limitations
  76383. * under the License.
  76384. */
  76385. var VISUAL_PRIORITY = PRIORITY.VISUAL.COMPONENT;
  76386. registerVisual(VISUAL_PRIORITY, {
  76387. createOnAllSeries: true,
  76388. reset: function (seriesModel, ecModel) {
  76389. var resetDefines = [];
  76390. ecModel.eachComponent('visualMap', function (visualMapModel) {
  76391. var pipelineContext = seriesModel.pipelineContext;
  76392. if (!visualMapModel.isTargetSeries(seriesModel)
  76393. || (pipelineContext && pipelineContext.large)
  76394. ) {
  76395. return;
  76396. }
  76397. resetDefines.push(incrementalApplyVisual(
  76398. visualMapModel.stateList,
  76399. visualMapModel.targetVisuals,
  76400. bind(visualMapModel.getValueState, visualMapModel),
  76401. visualMapModel.getDataDimension(seriesModel.getData())
  76402. ));
  76403. });
  76404. return resetDefines;
  76405. }
  76406. });
  76407. // Only support color.
  76408. registerVisual(VISUAL_PRIORITY, {
  76409. createOnAllSeries: true,
  76410. reset: function (seriesModel, ecModel) {
  76411. var data = seriesModel.getData();
  76412. var visualMetaList = [];
  76413. ecModel.eachComponent('visualMap', function (visualMapModel) {
  76414. if (visualMapModel.isTargetSeries(seriesModel)) {
  76415. var visualMeta = visualMapModel.getVisualMeta(
  76416. bind(getColorVisual, null, seriesModel, visualMapModel)
  76417. ) || {stops: [], outerColors: []};
  76418. var concreteDim = visualMapModel.getDataDimension(data);
  76419. var dimInfo = data.getDimensionInfo(concreteDim);
  76420. if (dimInfo != null) {
  76421. // visualMeta.dimension should be dimension index, but not concrete dimension.
  76422. visualMeta.dimension = dimInfo.index;
  76423. visualMetaList.push(visualMeta);
  76424. }
  76425. }
  76426. });
  76427. // console.log(JSON.stringify(visualMetaList.map(a => a.stops)));
  76428. seriesModel.getData().setVisual('visualMeta', visualMetaList);
  76429. }
  76430. });
  76431. // FIXME
  76432. // performance and export for heatmap?
  76433. // value can be Infinity or -Infinity
  76434. function getColorVisual(seriesModel, visualMapModel, value, valueState) {
  76435. var mappings = visualMapModel.targetVisuals[valueState];
  76436. var visualTypes = VisualMapping.prepareVisualTypes(mappings);
  76437. var resultVisual = {
  76438. color: seriesModel.getData().getVisual('color') // default color.
  76439. };
  76440. for (var i = 0, len = visualTypes.length; i < len; i++) {
  76441. var type = visualTypes[i];
  76442. var mapping = mappings[
  76443. type === 'opacity' ? '__alphaForOpacity' : type
  76444. ];
  76445. mapping && mapping.applyVisual(value, getVisual, setVisual);
  76446. }
  76447. return resultVisual.color;
  76448. function getVisual(key) {
  76449. return resultVisual[key];
  76450. }
  76451. function setVisual(key, value) {
  76452. resultVisual[key] = value;
  76453. }
  76454. }
  76455. /*
  76456. * Licensed to the Apache Software Foundation (ASF) under one
  76457. * or more contributor license agreements. See the NOTICE file
  76458. * distributed with this work for additional information
  76459. * regarding copyright ownership. The ASF licenses this file
  76460. * to you under the Apache License, Version 2.0 (the
  76461. * "License"); you may not use this file except in compliance
  76462. * with the License. You may obtain a copy of the License at
  76463. *
  76464. * http://www.apache.org/licenses/LICENSE-2.0
  76465. *
  76466. * Unless required by applicable law or agreed to in writing,
  76467. * software distributed under the License is distributed on an
  76468. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  76469. * KIND, either express or implied. See the License for the
  76470. * specific language governing permissions and limitations
  76471. * under the License.
  76472. */
  76473. /**
  76474. * @file Visual mapping.
  76475. */
  76476. var visualDefault = {
  76477. /**
  76478. * @public
  76479. */
  76480. get: function (visualType, key, isCategory) {
  76481. var value = clone(
  76482. (defaultOption$3[visualType] || {})[key]
  76483. );
  76484. return isCategory
  76485. ? (isArray(value) ? value[value.length - 1] : value)
  76486. : value;
  76487. }
  76488. };
  76489. var defaultOption$3 = {
  76490. color: {
  76491. active: ['#006edd', '#e0ffff'],
  76492. inactive: ['rgba(0,0,0,0)']
  76493. },
  76494. colorHue: {
  76495. active: [0, 360],
  76496. inactive: [0, 0]
  76497. },
  76498. colorSaturation: {
  76499. active: [0.3, 1],
  76500. inactive: [0, 0]
  76501. },
  76502. colorLightness: {
  76503. active: [0.9, 0.5],
  76504. inactive: [0, 0]
  76505. },
  76506. colorAlpha: {
  76507. active: [0.3, 1],
  76508. inactive: [0, 0]
  76509. },
  76510. opacity: {
  76511. active: [0.3, 1],
  76512. inactive: [0, 0]
  76513. },
  76514. symbol: {
  76515. active: ['circle', 'roundRect', 'diamond'],
  76516. inactive: ['none']
  76517. },
  76518. symbolSize: {
  76519. active: [10, 50],
  76520. inactive: [0, 0]
  76521. }
  76522. };
  76523. /*
  76524. * Licensed to the Apache Software Foundation (ASF) under one
  76525. * or more contributor license agreements. See the NOTICE file
  76526. * distributed with this work for additional information
  76527. * regarding copyright ownership. The ASF licenses this file
  76528. * to you under the Apache License, Version 2.0 (the
  76529. * "License"); you may not use this file except in compliance
  76530. * with the License. You may obtain a copy of the License at
  76531. *
  76532. * http://www.apache.org/licenses/LICENSE-2.0
  76533. *
  76534. * Unless required by applicable law or agreed to in writing,
  76535. * software distributed under the License is distributed on an
  76536. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  76537. * KIND, either express or implied. See the License for the
  76538. * specific language governing permissions and limitations
  76539. * under the License.
  76540. */
  76541. var mapVisual$2 = VisualMapping.mapVisual;
  76542. var eachVisual = VisualMapping.eachVisual;
  76543. var isArray$3 = isArray;
  76544. var each$28 = each$1;
  76545. var asc$3 = asc;
  76546. var linearMap$2 = linearMap;
  76547. var noop$2 = noop;
  76548. var VisualMapModel = extendComponentModel({
  76549. type: 'visualMap',
  76550. dependencies: ['series'],
  76551. /**
  76552. * @readOnly
  76553. * @type {Array.<string>}
  76554. */
  76555. stateList: ['inRange', 'outOfRange'],
  76556. /**
  76557. * @readOnly
  76558. * @type {Array.<string>}
  76559. */
  76560. replacableOptionKeys: [
  76561. 'inRange', 'outOfRange', 'target', 'controller', 'color'
  76562. ],
  76563. /**
  76564. * [lowerBound, upperBound]
  76565. *
  76566. * @readOnly
  76567. * @type {Array.<number>}
  76568. */
  76569. dataBound: [-Infinity, Infinity],
  76570. /**
  76571. * @readOnly
  76572. * @type {string|Object}
  76573. */
  76574. layoutMode: {type: 'box', ignoreSize: true},
  76575. /**
  76576. * @protected
  76577. */
  76578. defaultOption: {
  76579. show: true,
  76580. zlevel: 0,
  76581. z: 4,
  76582. seriesIndex: 'all', // 'all' or null/undefined: all series.
  76583. // A number or an array of number: the specified series.
  76584. // set min: 0, max: 200, only for campatible with ec2.
  76585. // In fact min max should not have default value.
  76586. min: 0, // min value, must specified if pieces is not specified.
  76587. max: 200, // max value, must specified if pieces is not specified.
  76588. dimension: null,
  76589. inRange: null, // 'color', 'colorHue', 'colorSaturation', 'colorLightness', 'colorAlpha',
  76590. // 'symbol', 'symbolSize'
  76591. outOfRange: null, // 'color', 'colorHue', 'colorSaturation',
  76592. // 'colorLightness', 'colorAlpha',
  76593. // 'symbol', 'symbolSize'
  76594. left: 0, // 'center' ¦ 'left' ¦ 'right' ¦ {number} (px)
  76595. right: null, // The same as left.
  76596. top: null, // 'top' ¦ 'bottom' ¦ 'center' ¦ {number} (px)
  76597. bottom: 0, // The same as top.
  76598. itemWidth: null,
  76599. itemHeight: null,
  76600. inverse: false,
  76601. orient: 'vertical', // 'horizontal' ¦ 'vertical'
  76602. backgroundColor: 'rgba(0,0,0,0)',
  76603. borderColor: '#ccc', // 值域边框颜色
  76604. contentColor: '#5793f3',
  76605. inactiveColor: '#aaa',
  76606. borderWidth: 0, // 值域边框线宽,单位px,默认为0(无边框)
  76607. padding: 5, // 值域内边距,单位px,默认各方向内边距为5,
  76608. // 接受数组分别设定上右下左边距,同css
  76609. textGap: 10, //
  76610. precision: 0, // 小数精度,默认为0,无小数点
  76611. color: null, //颜色(deprecated,兼容ec2,顺序同pieces,不同于inRange/outOfRange)
  76612. formatter: null,
  76613. text: null, // 文本,如['高', '低'],兼容ec2,text[0]对应高值,text[1]对应低值
  76614. textStyle: {
  76615. color: '#333' // 值域文字颜色
  76616. }
  76617. },
  76618. /**
  76619. * @protected
  76620. */
  76621. init: function (option, parentModel, ecModel) {
  76622. /**
  76623. * @private
  76624. * @type {Array.<number>}
  76625. */
  76626. this._dataExtent;
  76627. /**
  76628. * @readOnly
  76629. */
  76630. this.targetVisuals = {};
  76631. /**
  76632. * @readOnly
  76633. */
  76634. this.controllerVisuals = {};
  76635. /**
  76636. * @readOnly
  76637. */
  76638. this.textStyleModel;
  76639. /**
  76640. * [width, height]
  76641. * @readOnly
  76642. * @type {Array.<number>}
  76643. */
  76644. this.itemSize;
  76645. this.mergeDefaultAndTheme(option, ecModel);
  76646. },
  76647. /**
  76648. * @protected
  76649. */
  76650. optionUpdated: function (newOption, isInit) {
  76651. var thisOption = this.option;
  76652. // FIXME
  76653. // necessary?
  76654. // Disable realtime view update if canvas is not supported.
  76655. if (!env$1.canvasSupported) {
  76656. thisOption.realtime = false;
  76657. }
  76658. !isInit && replaceVisualOption(
  76659. thisOption, newOption, this.replacableOptionKeys
  76660. );
  76661. this.textStyleModel = this.getModel('textStyle');
  76662. this.resetItemSize();
  76663. this.completeVisualOption();
  76664. },
  76665. /**
  76666. * @protected
  76667. */
  76668. resetVisual: function (supplementVisualOption) {
  76669. var stateList = this.stateList;
  76670. supplementVisualOption = bind(supplementVisualOption, this);
  76671. this.controllerVisuals = createVisualMappings(
  76672. this.option.controller, stateList, supplementVisualOption
  76673. );
  76674. this.targetVisuals = createVisualMappings(
  76675. this.option.target, stateList, supplementVisualOption
  76676. );
  76677. },
  76678. /**
  76679. * @protected
  76680. * @return {Array.<number>} An array of series indices.
  76681. */
  76682. getTargetSeriesIndices: function () {
  76683. var optionSeriesIndex = this.option.seriesIndex;
  76684. var seriesIndices = [];
  76685. if (optionSeriesIndex == null || optionSeriesIndex === 'all') {
  76686. this.ecModel.eachSeries(function (seriesModel, index) {
  76687. seriesIndices.push(index);
  76688. });
  76689. }
  76690. else {
  76691. seriesIndices = normalizeToArray(optionSeriesIndex);
  76692. }
  76693. return seriesIndices;
  76694. },
  76695. /**
  76696. * @public
  76697. */
  76698. eachTargetSeries: function (callback, context) {
  76699. each$1(this.getTargetSeriesIndices(), function (seriesIndex) {
  76700. callback.call(context, this.ecModel.getSeriesByIndex(seriesIndex));
  76701. }, this);
  76702. },
  76703. /**
  76704. * @pubilc
  76705. */
  76706. isTargetSeries: function (seriesModel) {
  76707. var is = false;
  76708. this.eachTargetSeries(function (model) {
  76709. model === seriesModel && (is = true);
  76710. });
  76711. return is;
  76712. },
  76713. /**
  76714. * @example
  76715. * this.formatValueText(someVal); // format single numeric value to text.
  76716. * this.formatValueText(someVal, true); // format single category value to text.
  76717. * this.formatValueText([min, max]); // format numeric min-max to text.
  76718. * this.formatValueText([this.dataBound[0], max]); // using data lower bound.
  76719. * this.formatValueText([min, this.dataBound[1]]); // using data upper bound.
  76720. *
  76721. * @param {number|Array.<number>} value Real value, or this.dataBound[0 or 1].
  76722. * @param {boolean} [isCategory=false] Only available when value is number.
  76723. * @param {Array.<string>} edgeSymbols Open-close symbol when value is interval.
  76724. * @return {string}
  76725. * @protected
  76726. */
  76727. formatValueText: function (value, isCategory, edgeSymbols) {
  76728. var option = this.option;
  76729. var precision = option.precision;
  76730. var dataBound = this.dataBound;
  76731. var formatter = option.formatter;
  76732. var isMinMax;
  76733. var textValue;
  76734. edgeSymbols = edgeSymbols || ['<', '>'];
  76735. if (isArray(value)) {
  76736. value = value.slice();
  76737. isMinMax = true;
  76738. }
  76739. textValue = isCategory
  76740. ? value
  76741. : (isMinMax
  76742. ? [toFixed(value[0]), toFixed(value[1])]
  76743. : toFixed(value)
  76744. );
  76745. if (isString(formatter)) {
  76746. return formatter
  76747. .replace('{value}', isMinMax ? textValue[0] : textValue)
  76748. .replace('{value2}', isMinMax ? textValue[1] : textValue);
  76749. }
  76750. else if (isFunction$1(formatter)) {
  76751. return isMinMax
  76752. ? formatter(value[0], value[1])
  76753. : formatter(value);
  76754. }
  76755. if (isMinMax) {
  76756. if (value[0] === dataBound[0]) {
  76757. return edgeSymbols[0] + ' ' + textValue[1];
  76758. }
  76759. else if (value[1] === dataBound[1]) {
  76760. return edgeSymbols[1] + ' ' + textValue[0];
  76761. }
  76762. else {
  76763. return textValue[0] + ' - ' + textValue[1];
  76764. }
  76765. }
  76766. else { // Format single value (includes category case).
  76767. return textValue;
  76768. }
  76769. function toFixed(val) {
  76770. return val === dataBound[0]
  76771. ? 'min'
  76772. : val === dataBound[1]
  76773. ? 'max'
  76774. : (+val).toFixed(Math.min(precision, 20));
  76775. }
  76776. },
  76777. /**
  76778. * @protected
  76779. */
  76780. resetExtent: function () {
  76781. var thisOption = this.option;
  76782. // Can not calculate data extent by data here.
  76783. // Because series and data may be modified in processing stage.
  76784. // So we do not support the feature "auto min/max".
  76785. var extent = asc$3([thisOption.min, thisOption.max]);
  76786. this._dataExtent = extent;
  76787. },
  76788. /**
  76789. * @public
  76790. * @param {module:echarts/data/List} list
  76791. * @return {string} Concrete dimention. If return null/undefined,
  76792. * no dimension used.
  76793. */
  76794. getDataDimension: function (list) {
  76795. var optDim = this.option.dimension;
  76796. var listDimensions = list.dimensions;
  76797. if (optDim == null && !listDimensions.length) {
  76798. return;
  76799. }
  76800. if (optDim != null) {
  76801. return list.getDimension(optDim);
  76802. }
  76803. var dimNames = list.dimensions;
  76804. for (var i = dimNames.length - 1; i >= 0; i--) {
  76805. var dimName = dimNames[i];
  76806. var dimInfo = list.getDimensionInfo(dimName);
  76807. if (!dimInfo.isCalculationCoord) {
  76808. return dimName;
  76809. }
  76810. }
  76811. },
  76812. /**
  76813. * @public
  76814. * @override
  76815. */
  76816. getExtent: function () {
  76817. return this._dataExtent.slice();
  76818. },
  76819. /**
  76820. * @protected
  76821. */
  76822. completeVisualOption: function () {
  76823. var ecModel = this.ecModel;
  76824. var thisOption = this.option;
  76825. var base = {inRange: thisOption.inRange, outOfRange: thisOption.outOfRange};
  76826. var target = thisOption.target || (thisOption.target = {});
  76827. var controller = thisOption.controller || (thisOption.controller = {});
  76828. merge(target, base); // Do not override
  76829. merge(controller, base); // Do not override
  76830. var isCategory = this.isCategory();
  76831. completeSingle.call(this, target);
  76832. completeSingle.call(this, controller);
  76833. completeInactive.call(this, target, 'inRange', 'outOfRange');
  76834. // completeInactive.call(this, target, 'outOfRange', 'inRange');
  76835. completeController.call(this, controller);
  76836. function completeSingle(base) {
  76837. // Compatible with ec2 dataRange.color.
  76838. // The mapping order of dataRange.color is: [high value, ..., low value]
  76839. // whereas inRange.color and outOfRange.color is [low value, ..., high value]
  76840. // Notice: ec2 has no inverse.
  76841. if (isArray$3(thisOption.color)
  76842. // If there has been inRange: {symbol: ...}, adding color is a mistake.
  76843. // So adding color only when no inRange defined.
  76844. && !base.inRange
  76845. ) {
  76846. base.inRange = {color: thisOption.color.slice().reverse()};
  76847. }
  76848. // Compatible with previous logic, always give a defautl color, otherwise
  76849. // simple config with no inRange and outOfRange will not work.
  76850. // Originally we use visualMap.color as the default color, but setOption at
  76851. // the second time the default color will be erased. So we change to use
  76852. // constant DEFAULT_COLOR.
  76853. // If user do not want the defualt color, set inRange: {color: null}.
  76854. base.inRange = base.inRange || {color: ecModel.get('gradientColor')};
  76855. // If using shortcut like: {inRange: 'symbol'}, complete default value.
  76856. each$28(this.stateList, function (state) {
  76857. var visualType = base[state];
  76858. if (isString(visualType)) {
  76859. var defa = visualDefault.get(visualType, 'active', isCategory);
  76860. if (defa) {
  76861. base[state] = {};
  76862. base[state][visualType] = defa;
  76863. }
  76864. else {
  76865. // Mark as not specified.
  76866. delete base[state];
  76867. }
  76868. }
  76869. }, this);
  76870. }
  76871. function completeInactive(base, stateExist, stateAbsent) {
  76872. var optExist = base[stateExist];
  76873. var optAbsent = base[stateAbsent];
  76874. if (optExist && !optAbsent) {
  76875. optAbsent = base[stateAbsent] = {};
  76876. each$28(optExist, function (visualData, visualType) {
  76877. if (!VisualMapping.isValidType(visualType)) {
  76878. return;
  76879. }
  76880. var defa = visualDefault.get(visualType, 'inactive', isCategory);
  76881. if (defa != null) {
  76882. optAbsent[visualType] = defa;
  76883. // Compatibable with ec2:
  76884. // Only inactive color to rgba(0,0,0,0) can not
  76885. // make label transparent, so use opacity also.
  76886. if (visualType === 'color'
  76887. && !optAbsent.hasOwnProperty('opacity')
  76888. && !optAbsent.hasOwnProperty('colorAlpha')
  76889. ) {
  76890. optAbsent.opacity = [0, 0];
  76891. }
  76892. }
  76893. });
  76894. }
  76895. }
  76896. function completeController(controller) {
  76897. var symbolExists = (controller.inRange || {}).symbol
  76898. || (controller.outOfRange || {}).symbol;
  76899. var symbolSizeExists = (controller.inRange || {}).symbolSize
  76900. || (controller.outOfRange || {}).symbolSize;
  76901. var inactiveColor = this.get('inactiveColor');
  76902. each$28(this.stateList, function (state) {
  76903. var itemSize = this.itemSize;
  76904. var visuals = controller[state];
  76905. // Set inactive color for controller if no other color
  76906. // attr (like colorAlpha) specified.
  76907. if (!visuals) {
  76908. visuals = controller[state] = {
  76909. color: isCategory ? inactiveColor : [inactiveColor]
  76910. };
  76911. }
  76912. // Consistent symbol and symbolSize if not specified.
  76913. if (visuals.symbol == null) {
  76914. visuals.symbol = symbolExists
  76915. && clone(symbolExists)
  76916. || (isCategory ? 'roundRect' : ['roundRect']);
  76917. }
  76918. if (visuals.symbolSize == null) {
  76919. visuals.symbolSize = symbolSizeExists
  76920. && clone(symbolSizeExists)
  76921. || (isCategory ? itemSize[0] : [itemSize[0], itemSize[0]]);
  76922. }
  76923. // Filter square and none.
  76924. visuals.symbol = mapVisual$2(visuals.symbol, function (symbol) {
  76925. return (symbol === 'none' || symbol === 'square') ? 'roundRect' : symbol;
  76926. });
  76927. // Normalize symbolSize
  76928. var symbolSize = visuals.symbolSize;
  76929. if (symbolSize != null) {
  76930. var max = -Infinity;
  76931. // symbolSize can be object when categories defined.
  76932. eachVisual(symbolSize, function (value) {
  76933. value > max && (max = value);
  76934. });
  76935. visuals.symbolSize = mapVisual$2(symbolSize, function (value) {
  76936. return linearMap$2(value, [0, max], [0, itemSize[0]], true);
  76937. });
  76938. }
  76939. }, this);
  76940. }
  76941. },
  76942. /**
  76943. * @protected
  76944. */
  76945. resetItemSize: function () {
  76946. this.itemSize = [
  76947. parseFloat(this.get('itemWidth')),
  76948. parseFloat(this.get('itemHeight'))
  76949. ];
  76950. },
  76951. /**
  76952. * @public
  76953. */
  76954. isCategory: function () {
  76955. return !!this.option.categories;
  76956. },
  76957. /**
  76958. * @public
  76959. * @abstract
  76960. */
  76961. setSelected: noop$2,
  76962. /**
  76963. * @public
  76964. * @abstract
  76965. * @param {*|module:echarts/data/List} valueOrData
  76966. * @param {number} dataIndex
  76967. * @return {string} state See this.stateList
  76968. */
  76969. getValueState: noop$2,
  76970. /**
  76971. * FIXME
  76972. * Do not publish to thirt-part-dev temporarily
  76973. * util the interface is stable. (Should it return
  76974. * a function but not visual meta?)
  76975. *
  76976. * @pubilc
  76977. * @abstract
  76978. * @param {Function} getColorVisual
  76979. * params: value, valueState
  76980. * return: color
  76981. * @return {Object} visualMeta
  76982. * should includes {stops, outerColors}
  76983. * outerColor means [colorBeyondMinValue, colorBeyondMaxValue]
  76984. */
  76985. getVisualMeta: noop$2
  76986. });
  76987. /*
  76988. * Licensed to the Apache Software Foundation (ASF) under one
  76989. * or more contributor license agreements. See the NOTICE file
  76990. * distributed with this work for additional information
  76991. * regarding copyright ownership. The ASF licenses this file
  76992. * to you under the Apache License, Version 2.0 (the
  76993. * "License"); you may not use this file except in compliance
  76994. * with the License. You may obtain a copy of the License at
  76995. *
  76996. * http://www.apache.org/licenses/LICENSE-2.0
  76997. *
  76998. * Unless required by applicable law or agreed to in writing,
  76999. * software distributed under the License is distributed on an
  77000. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  77001. * KIND, either express or implied. See the License for the
  77002. * specific language governing permissions and limitations
  77003. * under the License.
  77004. */
  77005. // Constant
  77006. var DEFAULT_BAR_BOUND = [20, 140];
  77007. var ContinuousModel = VisualMapModel.extend({
  77008. type: 'visualMap.continuous',
  77009. /**
  77010. * @protected
  77011. */
  77012. defaultOption: {
  77013. align: 'auto', // 'auto', 'left', 'right', 'top', 'bottom'
  77014. calculable: false, // This prop effect default component type determine,
  77015. // See echarts/component/visualMap/typeDefaulter.
  77016. range: null, // selected range. In default case `range` is [min, max]
  77017. // and can auto change along with modification of min max,
  77018. // util use specifid a range.
  77019. realtime: true, // Whether realtime update.
  77020. itemHeight: null, // The length of the range control edge.
  77021. itemWidth: null, // The length of the other side.
  77022. hoverLink: true, // Enable hover highlight.
  77023. hoverLinkDataSize: null, // The size of hovered data.
  77024. hoverLinkOnHandle: null // Whether trigger hoverLink when hover handle.
  77025. // If not specified, follow the value of `realtime`.
  77026. },
  77027. /**
  77028. * @override
  77029. */
  77030. optionUpdated: function (newOption, isInit) {
  77031. ContinuousModel.superApply(this, 'optionUpdated', arguments);
  77032. this.resetExtent();
  77033. this.resetVisual(function (mappingOption) {
  77034. mappingOption.mappingMethod = 'linear';
  77035. mappingOption.dataExtent = this.getExtent();
  77036. });
  77037. this._resetRange();
  77038. },
  77039. /**
  77040. * @protected
  77041. * @override
  77042. */
  77043. resetItemSize: function () {
  77044. ContinuousModel.superApply(this, 'resetItemSize', arguments);
  77045. var itemSize = this.itemSize;
  77046. this._orient === 'horizontal' && itemSize.reverse();
  77047. (itemSize[0] == null || isNaN(itemSize[0])) && (itemSize[0] = DEFAULT_BAR_BOUND[0]);
  77048. (itemSize[1] == null || isNaN(itemSize[1])) && (itemSize[1] = DEFAULT_BAR_BOUND[1]);
  77049. },
  77050. /**
  77051. * @private
  77052. */
  77053. _resetRange: function () {
  77054. var dataExtent = this.getExtent();
  77055. var range = this.option.range;
  77056. if (!range || range.auto) {
  77057. // `range` should always be array (so we dont use other
  77058. // value like 'auto') for user-friend. (consider getOption).
  77059. dataExtent.auto = 1;
  77060. this.option.range = dataExtent;
  77061. }
  77062. else if (isArray(range)) {
  77063. if (range[0] > range[1]) {
  77064. range.reverse();
  77065. }
  77066. range[0] = Math.max(range[0], dataExtent[0]);
  77067. range[1] = Math.min(range[1], dataExtent[1]);
  77068. }
  77069. },
  77070. /**
  77071. * @protected
  77072. * @override
  77073. */
  77074. completeVisualOption: function () {
  77075. VisualMapModel.prototype.completeVisualOption.apply(this, arguments);
  77076. each$1(this.stateList, function (state) {
  77077. var symbolSize = this.option.controller[state].symbolSize;
  77078. if (symbolSize && symbolSize[0] !== symbolSize[1]) {
  77079. symbolSize[0] = 0; // For good looking.
  77080. }
  77081. }, this);
  77082. },
  77083. /**
  77084. * @override
  77085. */
  77086. setSelected: function (selected) {
  77087. this.option.range = selected.slice();
  77088. this._resetRange();
  77089. },
  77090. /**
  77091. * @public
  77092. */
  77093. getSelected: function () {
  77094. var dataExtent = this.getExtent();
  77095. var dataInterval = asc(
  77096. (this.get('range') || []).slice()
  77097. );
  77098. // Clamp
  77099. dataInterval[0] > dataExtent[1] && (dataInterval[0] = dataExtent[1]);
  77100. dataInterval[1] > dataExtent[1] && (dataInterval[1] = dataExtent[1]);
  77101. dataInterval[0] < dataExtent[0] && (dataInterval[0] = dataExtent[0]);
  77102. dataInterval[1] < dataExtent[0] && (dataInterval[1] = dataExtent[0]);
  77103. return dataInterval;
  77104. },
  77105. /**
  77106. * @override
  77107. */
  77108. getValueState: function (value) {
  77109. var range = this.option.range;
  77110. var dataExtent = this.getExtent();
  77111. // When range[0] === dataExtent[0], any value larger than dataExtent[0] maps to 'inRange'.
  77112. // range[1] is processed likewise.
  77113. return (
  77114. (range[0] <= dataExtent[0] || range[0] <= value)
  77115. && (range[1] >= dataExtent[1] || value <= range[1])
  77116. ) ? 'inRange' : 'outOfRange';
  77117. },
  77118. /**
  77119. * @params {Array.<number>} range target value: range[0] <= value && value <= range[1]
  77120. * @return {Array.<Object>} [{seriesId, dataIndices: <Array.<number>>}, ...]
  77121. */
  77122. findTargetDataIndices: function (range) {
  77123. var result = [];
  77124. this.eachTargetSeries(function (seriesModel) {
  77125. var dataIndices = [];
  77126. var data = seriesModel.getData();
  77127. data.each(this.getDataDimension(data), function (value, dataIndex) {
  77128. range[0] <= value && value <= range[1] && dataIndices.push(dataIndex);
  77129. }, this);
  77130. result.push({seriesId: seriesModel.id, dataIndex: dataIndices});
  77131. }, this);
  77132. return result;
  77133. },
  77134. /**
  77135. * @implement
  77136. */
  77137. getVisualMeta: function (getColorVisual) {
  77138. var oVals = getColorStopValues(this, 'outOfRange', this.getExtent());
  77139. var iVals = getColorStopValues(this, 'inRange', this.option.range.slice());
  77140. var stops = [];
  77141. function setStop(value, valueState) {
  77142. stops.push({
  77143. value: value,
  77144. color: getColorVisual(value, valueState)
  77145. });
  77146. }
  77147. // Format to: outOfRange -- inRange -- outOfRange.
  77148. var iIdx = 0;
  77149. var oIdx = 0;
  77150. var iLen = iVals.length;
  77151. var oLen = oVals.length;
  77152. for (; oIdx < oLen && (!iVals.length || oVals[oIdx] <= iVals[0]); oIdx++) {
  77153. // If oVal[oIdx] === iVals[iIdx], oVal[oIdx] should be ignored.
  77154. if (oVals[oIdx] < iVals[iIdx]) {
  77155. setStop(oVals[oIdx], 'outOfRange');
  77156. }
  77157. }
  77158. for (var first = 1; iIdx < iLen; iIdx++, first = 0) {
  77159. // If range is full, value beyond min, max will be clamped.
  77160. // make a singularity
  77161. first && stops.length && setStop(iVals[iIdx], 'outOfRange');
  77162. setStop(iVals[iIdx], 'inRange');
  77163. }
  77164. for (var first = 1; oIdx < oLen; oIdx++) {
  77165. if (!iVals.length || iVals[iVals.length - 1] < oVals[oIdx]) {
  77166. // make a singularity
  77167. if (first) {
  77168. stops.length && setStop(stops[stops.length - 1].value, 'outOfRange');
  77169. first = 0;
  77170. }
  77171. setStop(oVals[oIdx], 'outOfRange');
  77172. }
  77173. }
  77174. var stopsLen = stops.length;
  77175. return {
  77176. stops: stops,
  77177. outerColors: [
  77178. stopsLen ? stops[0].color : 'transparent',
  77179. stopsLen ? stops[stopsLen - 1].color : 'transparent'
  77180. ]
  77181. };
  77182. }
  77183. });
  77184. function getColorStopValues(visualMapModel, valueState, dataExtent) {
  77185. if (dataExtent[0] === dataExtent[1]) {
  77186. return dataExtent.slice();
  77187. }
  77188. // When using colorHue mapping, it is not linear color any more.
  77189. // Moreover, canvas gradient seems not to be accurate linear.
  77190. // FIXME
  77191. // Should be arbitrary value 100? or based on pixel size?
  77192. var count = 200;
  77193. var step = (dataExtent[1] - dataExtent[0]) / count;
  77194. var value = dataExtent[0];
  77195. var stopValues = [];
  77196. for (var i = 0; i <= count && value < dataExtent[1]; i++) {
  77197. stopValues.push(value);
  77198. value += step;
  77199. }
  77200. stopValues.push(dataExtent[1]);
  77201. return stopValues;
  77202. }
  77203. /*
  77204. * Licensed to the Apache Software Foundation (ASF) under one
  77205. * or more contributor license agreements. See the NOTICE file
  77206. * distributed with this work for additional information
  77207. * regarding copyright ownership. The ASF licenses this file
  77208. * to you under the Apache License, Version 2.0 (the
  77209. * "License"); you may not use this file except in compliance
  77210. * with the License. You may obtain a copy of the License at
  77211. *
  77212. * http://www.apache.org/licenses/LICENSE-2.0
  77213. *
  77214. * Unless required by applicable law or agreed to in writing,
  77215. * software distributed under the License is distributed on an
  77216. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  77217. * KIND, either express or implied. See the License for the
  77218. * specific language governing permissions and limitations
  77219. * under the License.
  77220. */
  77221. var VisualMapView = extendComponentView({
  77222. type: 'visualMap',
  77223. /**
  77224. * @readOnly
  77225. * @type {Object}
  77226. */
  77227. autoPositionValues: {left: 1, right: 1, top: 1, bottom: 1},
  77228. init: function (ecModel, api) {
  77229. /**
  77230. * @readOnly
  77231. * @type {module:echarts/model/Global}
  77232. */
  77233. this.ecModel = ecModel;
  77234. /**
  77235. * @readOnly
  77236. * @type {module:echarts/ExtensionAPI}
  77237. */
  77238. this.api = api;
  77239. /**
  77240. * @readOnly
  77241. * @type {module:echarts/component/visualMap/visualMapModel}
  77242. */
  77243. this.visualMapModel;
  77244. },
  77245. /**
  77246. * @protected
  77247. */
  77248. render: function (visualMapModel, ecModel, api, payload) {
  77249. this.visualMapModel = visualMapModel;
  77250. if (visualMapModel.get('show') === false) {
  77251. this.group.removeAll();
  77252. return;
  77253. }
  77254. this.doRender.apply(this, arguments);
  77255. },
  77256. /**
  77257. * @protected
  77258. */
  77259. renderBackground: function (group) {
  77260. var visualMapModel = this.visualMapModel;
  77261. var padding = normalizeCssArray$1(visualMapModel.get('padding') || 0);
  77262. var rect = group.getBoundingRect();
  77263. group.add(new Rect({
  77264. z2: -1, // Lay background rect on the lowest layer.
  77265. silent: true,
  77266. shape: {
  77267. x: rect.x - padding[3],
  77268. y: rect.y - padding[0],
  77269. width: rect.width + padding[3] + padding[1],
  77270. height: rect.height + padding[0] + padding[2]
  77271. },
  77272. style: {
  77273. fill: visualMapModel.get('backgroundColor'),
  77274. stroke: visualMapModel.get('borderColor'),
  77275. lineWidth: visualMapModel.get('borderWidth')
  77276. }
  77277. }));
  77278. },
  77279. /**
  77280. * @protected
  77281. * @param {number} targetValue can be Infinity or -Infinity
  77282. * @param {string=} visualCluster Only can be 'color' 'opacity' 'symbol' 'symbolSize'
  77283. * @param {Object} [opts]
  77284. * @param {string=} [opts.forceState] Specify state, instead of using getValueState method.
  77285. * @param {string=} [opts.convertOpacityToAlpha=false] For color gradient in controller widget.
  77286. * @return {*} Visual value.
  77287. */
  77288. getControllerVisual: function (targetValue, visualCluster, opts) {
  77289. opts = opts || {};
  77290. var forceState = opts.forceState;
  77291. var visualMapModel = this.visualMapModel;
  77292. var visualObj = {};
  77293. // Default values.
  77294. if (visualCluster === 'symbol') {
  77295. visualObj.symbol = visualMapModel.get('itemSymbol');
  77296. }
  77297. if (visualCluster === 'color') {
  77298. var defaultColor = visualMapModel.get('contentColor');
  77299. visualObj.color = defaultColor;
  77300. }
  77301. function getter(key) {
  77302. return visualObj[key];
  77303. }
  77304. function setter(key, value) {
  77305. visualObj[key] = value;
  77306. }
  77307. var mappings = visualMapModel.controllerVisuals[
  77308. forceState || visualMapModel.getValueState(targetValue)
  77309. ];
  77310. var visualTypes = VisualMapping.prepareVisualTypes(mappings);
  77311. each$1(visualTypes, function (type) {
  77312. var visualMapping = mappings[type];
  77313. if (opts.convertOpacityToAlpha && type === 'opacity') {
  77314. type = 'colorAlpha';
  77315. visualMapping = mappings.__alphaForOpacity;
  77316. }
  77317. if (VisualMapping.dependsOn(type, visualCluster)) {
  77318. visualMapping && visualMapping.applyVisual(
  77319. targetValue, getter, setter
  77320. );
  77321. }
  77322. });
  77323. return visualObj[visualCluster];
  77324. },
  77325. /**
  77326. * @protected
  77327. */
  77328. positionGroup: function (group) {
  77329. var model = this.visualMapModel;
  77330. var api = this.api;
  77331. positionElement(
  77332. group,
  77333. model.getBoxLayoutParams(),
  77334. {width: api.getWidth(), height: api.getHeight()}
  77335. );
  77336. },
  77337. /**
  77338. * @protected
  77339. * @abstract
  77340. */
  77341. doRender: noop
  77342. });
  77343. /*
  77344. * Licensed to the Apache Software Foundation (ASF) under one
  77345. * or more contributor license agreements. See the NOTICE file
  77346. * distributed with this work for additional information
  77347. * regarding copyright ownership. The ASF licenses this file
  77348. * to you under the Apache License, Version 2.0 (the
  77349. * "License"); you may not use this file except in compliance
  77350. * with the License. You may obtain a copy of the License at
  77351. *
  77352. * http://www.apache.org/licenses/LICENSE-2.0
  77353. *
  77354. * Unless required by applicable law or agreed to in writing,
  77355. * software distributed under the License is distributed on an
  77356. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  77357. * KIND, either express or implied. See the License for the
  77358. * specific language governing permissions and limitations
  77359. * under the License.
  77360. */
  77361. /**
  77362. * @param {module:echarts/component/visualMap/VisualMapModel} visualMapModel\
  77363. * @param {module:echarts/ExtensionAPI} api
  77364. * @param {Array.<number>} itemSize always [short, long]
  77365. * @return {string} 'left' or 'right' or 'top' or 'bottom'
  77366. */
  77367. function getItemAlign(visualMapModel, api, itemSize) {
  77368. var modelOption = visualMapModel.option;
  77369. var itemAlign = modelOption.align;
  77370. if (itemAlign != null && itemAlign !== 'auto') {
  77371. return itemAlign;
  77372. }
  77373. // Auto decision align.
  77374. var ecSize = {width: api.getWidth(), height: api.getHeight()};
  77375. var realIndex = modelOption.orient === 'horizontal' ? 1 : 0;
  77376. var paramsSet = [
  77377. ['left', 'right', 'width'],
  77378. ['top', 'bottom', 'height']
  77379. ];
  77380. var reals = paramsSet[realIndex];
  77381. var fakeValue = [0, null, 10];
  77382. var layoutInput = {};
  77383. for (var i = 0; i < 3; i++) {
  77384. layoutInput[paramsSet[1 - realIndex][i]] = fakeValue[i];
  77385. layoutInput[reals[i]] = i === 2 ? itemSize[0] : modelOption[reals[i]];
  77386. }
  77387. var rParam = [['x', 'width', 3], ['y', 'height', 0]][realIndex];
  77388. var rect = getLayoutRect(layoutInput, ecSize, modelOption.padding);
  77389. return reals[
  77390. (rect.margin[rParam[2]] || 0) + rect[rParam[0]] + rect[rParam[1]] * 0.5
  77391. < ecSize[rParam[1]] * 0.5 ? 0 : 1
  77392. ];
  77393. }
  77394. /**
  77395. * Prepare dataIndex for outside usage, where dataIndex means rawIndex, and
  77396. * dataIndexInside means filtered index.
  77397. */
  77398. function makeHighDownBatch(batch, visualMapModel) {
  77399. each$1(batch || [], function (batchItem) {
  77400. if (batchItem.dataIndex != null) {
  77401. batchItem.dataIndexInside = batchItem.dataIndex;
  77402. batchItem.dataIndex = null;
  77403. }
  77404. batchItem.highlightKey = 'visualMap' + (visualMapModel ? visualMapModel.componentIndex : '');
  77405. });
  77406. return batch;
  77407. }
  77408. /*
  77409. * Licensed to the Apache Software Foundation (ASF) under one
  77410. * or more contributor license agreements. See the NOTICE file
  77411. * distributed with this work for additional information
  77412. * regarding copyright ownership. The ASF licenses this file
  77413. * to you under the Apache License, Version 2.0 (the
  77414. * "License"); you may not use this file except in compliance
  77415. * with the License. You may obtain a copy of the License at
  77416. *
  77417. * http://www.apache.org/licenses/LICENSE-2.0
  77418. *
  77419. * Unless required by applicable law or agreed to in writing,
  77420. * software distributed under the License is distributed on an
  77421. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  77422. * KIND, either express or implied. See the License for the
  77423. * specific language governing permissions and limitations
  77424. * under the License.
  77425. */
  77426. var linearMap$3 = linearMap;
  77427. var each$29 = each$1;
  77428. var mathMin$7 = Math.min;
  77429. var mathMax$7 = Math.max;
  77430. // Arbitrary value
  77431. var HOVER_LINK_SIZE = 12;
  77432. var HOVER_LINK_OUT = 6;
  77433. // Notice:
  77434. // Any "interval" should be by the order of [low, high].
  77435. // "handle0" (handleIndex === 0) maps to
  77436. // low data value: this._dataInterval[0] and has low coord.
  77437. // "handle1" (handleIndex === 1) maps to
  77438. // high data value: this._dataInterval[1] and has high coord.
  77439. // The logic of transform is implemented in this._createBarGroup.
  77440. var ContinuousView = VisualMapView.extend({
  77441. type: 'visualMap.continuous',
  77442. /**
  77443. * @override
  77444. */
  77445. init: function () {
  77446. ContinuousView.superApply(this, 'init', arguments);
  77447. /**
  77448. * @private
  77449. */
  77450. this._shapes = {};
  77451. /**
  77452. * @private
  77453. */
  77454. this._dataInterval = [];
  77455. /**
  77456. * @private
  77457. */
  77458. this._handleEnds = [];
  77459. /**
  77460. * @private
  77461. */
  77462. this._orient;
  77463. /**
  77464. * @private
  77465. */
  77466. this._useHandle;
  77467. /**
  77468. * @private
  77469. */
  77470. this._hoverLinkDataIndices = [];
  77471. /**
  77472. * @private
  77473. */
  77474. this._dragging;
  77475. /**
  77476. * @private
  77477. */
  77478. this._hovering;
  77479. },
  77480. /**
  77481. * @protected
  77482. * @override
  77483. */
  77484. doRender: function (visualMapModel, ecModel, api, payload) {
  77485. if (!payload || payload.type !== 'selectDataRange' || payload.from !== this.uid) {
  77486. this._buildView();
  77487. }
  77488. },
  77489. /**
  77490. * @private
  77491. */
  77492. _buildView: function () {
  77493. this.group.removeAll();
  77494. var visualMapModel = this.visualMapModel;
  77495. var thisGroup = this.group;
  77496. this._orient = visualMapModel.get('orient');
  77497. this._useHandle = visualMapModel.get('calculable');
  77498. this._resetInterval();
  77499. this._renderBar(thisGroup);
  77500. var dataRangeText = visualMapModel.get('text');
  77501. this._renderEndsText(thisGroup, dataRangeText, 0);
  77502. this._renderEndsText(thisGroup, dataRangeText, 1);
  77503. // Do this for background size calculation.
  77504. this._updateView(true);
  77505. // After updating view, inner shapes is built completely,
  77506. // and then background can be rendered.
  77507. this.renderBackground(thisGroup);
  77508. // Real update view
  77509. this._updateView();
  77510. this._enableHoverLinkToSeries();
  77511. this._enableHoverLinkFromSeries();
  77512. this.positionGroup(thisGroup);
  77513. },
  77514. /**
  77515. * @private
  77516. */
  77517. _renderEndsText: function (group, dataRangeText, endsIndex) {
  77518. if (!dataRangeText) {
  77519. return;
  77520. }
  77521. // Compatible with ec2, text[0] map to high value, text[1] map low value.
  77522. var text = dataRangeText[1 - endsIndex];
  77523. text = text != null ? text + '' : '';
  77524. var visualMapModel = this.visualMapModel;
  77525. var textGap = visualMapModel.get('textGap');
  77526. var itemSize = visualMapModel.itemSize;
  77527. var barGroup = this._shapes.barGroup;
  77528. var position = this._applyTransform(
  77529. [
  77530. itemSize[0] / 2,
  77531. endsIndex === 0 ? -textGap : itemSize[1] + textGap
  77532. ],
  77533. barGroup
  77534. );
  77535. var align = this._applyTransform(
  77536. endsIndex === 0 ? 'bottom' : 'top',
  77537. barGroup
  77538. );
  77539. var orient = this._orient;
  77540. var textStyleModel = this.visualMapModel.textStyleModel;
  77541. this.group.add(new Text({
  77542. style: {
  77543. x: position[0],
  77544. y: position[1],
  77545. textVerticalAlign: orient === 'horizontal' ? 'middle' : align,
  77546. textAlign: orient === 'horizontal' ? align : 'center',
  77547. text: text,
  77548. textFont: textStyleModel.getFont(),
  77549. textFill: textStyleModel.getTextColor()
  77550. }
  77551. }));
  77552. },
  77553. /**
  77554. * @private
  77555. */
  77556. _renderBar: function (targetGroup) {
  77557. var visualMapModel = this.visualMapModel;
  77558. var shapes = this._shapes;
  77559. var itemSize = visualMapModel.itemSize;
  77560. var orient = this._orient;
  77561. var useHandle = this._useHandle;
  77562. var itemAlign = getItemAlign(visualMapModel, this.api, itemSize);
  77563. var barGroup = shapes.barGroup = this._createBarGroup(itemAlign);
  77564. // Bar
  77565. barGroup.add(shapes.outOfRange = createPolygon());
  77566. barGroup.add(shapes.inRange = createPolygon(
  77567. null,
  77568. useHandle ? getCursor$1(this._orient) : null,
  77569. bind(this._dragHandle, this, 'all', false),
  77570. bind(this._dragHandle, this, 'all', true)
  77571. ));
  77572. var textRect = visualMapModel.textStyleModel.getTextRect('国');
  77573. var textSize = mathMax$7(textRect.width, textRect.height);
  77574. // Handle
  77575. if (useHandle) {
  77576. shapes.handleThumbs = [];
  77577. shapes.handleLabels = [];
  77578. shapes.handleLabelPoints = [];
  77579. this._createHandle(barGroup, 0, itemSize, textSize, orient, itemAlign);
  77580. this._createHandle(barGroup, 1, itemSize, textSize, orient, itemAlign);
  77581. }
  77582. this._createIndicator(barGroup, itemSize, textSize, orient);
  77583. targetGroup.add(barGroup);
  77584. },
  77585. /**
  77586. * @private
  77587. */
  77588. _createHandle: function (barGroup, handleIndex, itemSize, textSize, orient) {
  77589. var onDrift = bind(this._dragHandle, this, handleIndex, false);
  77590. var onDragEnd = bind(this._dragHandle, this, handleIndex, true);
  77591. var handleThumb = createPolygon(
  77592. createHandlePoints(handleIndex, textSize),
  77593. getCursor$1(this._orient),
  77594. onDrift,
  77595. onDragEnd
  77596. );
  77597. handleThumb.position[0] = itemSize[0];
  77598. barGroup.add(handleThumb);
  77599. // Text is always horizontal layout but should not be effected by
  77600. // transform (orient/inverse). So label is built separately but not
  77601. // use zrender/graphic/helper/RectText, and is located based on view
  77602. // group (according to handleLabelPoint) but not barGroup.
  77603. var textStyleModel = this.visualMapModel.textStyleModel;
  77604. var handleLabel = new Text({
  77605. draggable: true,
  77606. drift: onDrift,
  77607. onmousemove: function (e) {
  77608. // Fot mobile devicem, prevent screen slider on the button.
  77609. stop(e.event);
  77610. },
  77611. ondragend: onDragEnd,
  77612. style: {
  77613. x: 0, y: 0, text: '',
  77614. textFont: textStyleModel.getFont(),
  77615. textFill: textStyleModel.getTextColor()
  77616. }
  77617. });
  77618. this.group.add(handleLabel);
  77619. var handleLabelPoint = [
  77620. orient === 'horizontal'
  77621. ? textSize / 2
  77622. : textSize * 1.5,
  77623. orient === 'horizontal'
  77624. ? (handleIndex === 0 ? -(textSize * 1.5) : (textSize * 1.5))
  77625. : (handleIndex === 0 ? -textSize / 2 : textSize / 2)
  77626. ];
  77627. var shapes = this._shapes;
  77628. shapes.handleThumbs[handleIndex] = handleThumb;
  77629. shapes.handleLabelPoints[handleIndex] = handleLabelPoint;
  77630. shapes.handleLabels[handleIndex] = handleLabel;
  77631. },
  77632. /**
  77633. * @private
  77634. */
  77635. _createIndicator: function (barGroup, itemSize, textSize, orient) {
  77636. var indicator = createPolygon([[0, 0]], 'move');
  77637. indicator.position[0] = itemSize[0];
  77638. indicator.attr({invisible: true, silent: true});
  77639. barGroup.add(indicator);
  77640. var textStyleModel = this.visualMapModel.textStyleModel;
  77641. var indicatorLabel = new Text({
  77642. silent: true,
  77643. invisible: true,
  77644. style: {
  77645. x: 0, y: 0, text: '',
  77646. textFont: textStyleModel.getFont(),
  77647. textFill: textStyleModel.getTextColor()
  77648. }
  77649. });
  77650. this.group.add(indicatorLabel);
  77651. var indicatorLabelPoint = [
  77652. orient === 'horizontal' ? textSize / 2 : HOVER_LINK_OUT + 3,
  77653. 0
  77654. ];
  77655. var shapes = this._shapes;
  77656. shapes.indicator = indicator;
  77657. shapes.indicatorLabel = indicatorLabel;
  77658. shapes.indicatorLabelPoint = indicatorLabelPoint;
  77659. },
  77660. /**
  77661. * @private
  77662. */
  77663. _dragHandle: function (handleIndex, isEnd, dx, dy) {
  77664. if (!this._useHandle) {
  77665. return;
  77666. }
  77667. this._dragging = !isEnd;
  77668. if (!isEnd) {
  77669. // Transform dx, dy to bar coordination.
  77670. var vertex = this._applyTransform([dx, dy], this._shapes.barGroup, true);
  77671. this._updateInterval(handleIndex, vertex[1]);
  77672. // Considering realtime, update view should be executed
  77673. // before dispatch action.
  77674. this._updateView();
  77675. }
  77676. // dragEnd do not dispatch action when realtime.
  77677. if (isEnd === !this.visualMapModel.get('realtime')) { // jshint ignore:line
  77678. this.api.dispatchAction({
  77679. type: 'selectDataRange',
  77680. from: this.uid,
  77681. visualMapId: this.visualMapModel.id,
  77682. selected: this._dataInterval.slice()
  77683. });
  77684. }
  77685. if (isEnd) {
  77686. !this._hovering && this._clearHoverLinkToSeries();
  77687. }
  77688. else if (useHoverLinkOnHandle(this.visualMapModel)) {
  77689. this._doHoverLinkToSeries(this._handleEnds[handleIndex], false);
  77690. }
  77691. },
  77692. /**
  77693. * @private
  77694. */
  77695. _resetInterval: function () {
  77696. var visualMapModel = this.visualMapModel;
  77697. var dataInterval = this._dataInterval = visualMapModel.getSelected();
  77698. var dataExtent = visualMapModel.getExtent();
  77699. var sizeExtent = [0, visualMapModel.itemSize[1]];
  77700. this._handleEnds = [
  77701. linearMap$3(dataInterval[0], dataExtent, sizeExtent, true),
  77702. linearMap$3(dataInterval[1], dataExtent, sizeExtent, true)
  77703. ];
  77704. },
  77705. /**
  77706. * @private
  77707. * @param {(number|string)} handleIndex 0 or 1 or 'all'
  77708. * @param {number} dx
  77709. * @param {number} dy
  77710. */
  77711. _updateInterval: function (handleIndex, delta) {
  77712. delta = delta || 0;
  77713. var visualMapModel = this.visualMapModel;
  77714. var handleEnds = this._handleEnds;
  77715. var sizeExtent = [0, visualMapModel.itemSize[1]];
  77716. sliderMove(
  77717. delta,
  77718. handleEnds,
  77719. sizeExtent,
  77720. handleIndex,
  77721. // cross is forbiden
  77722. 0
  77723. );
  77724. var dataExtent = visualMapModel.getExtent();
  77725. // Update data interval.
  77726. this._dataInterval = [
  77727. linearMap$3(handleEnds[0], sizeExtent, dataExtent, true),
  77728. linearMap$3(handleEnds[1], sizeExtent, dataExtent, true)
  77729. ];
  77730. },
  77731. /**
  77732. * @private
  77733. */
  77734. _updateView: function (forSketch) {
  77735. var visualMapModel = this.visualMapModel;
  77736. var dataExtent = visualMapModel.getExtent();
  77737. var shapes = this._shapes;
  77738. var outOfRangeHandleEnds = [0, visualMapModel.itemSize[1]];
  77739. var inRangeHandleEnds = forSketch ? outOfRangeHandleEnds : this._handleEnds;
  77740. var visualInRange = this._createBarVisual(
  77741. this._dataInterval, dataExtent, inRangeHandleEnds, 'inRange'
  77742. );
  77743. var visualOutOfRange = this._createBarVisual(
  77744. dataExtent, dataExtent, outOfRangeHandleEnds, 'outOfRange'
  77745. );
  77746. shapes.inRange
  77747. .setStyle({
  77748. fill: visualInRange.barColor,
  77749. opacity: visualInRange.opacity
  77750. })
  77751. .setShape('points', visualInRange.barPoints);
  77752. shapes.outOfRange
  77753. .setStyle({
  77754. fill: visualOutOfRange.barColor,
  77755. opacity: visualOutOfRange.opacity
  77756. })
  77757. .setShape('points', visualOutOfRange.barPoints);
  77758. this._updateHandle(inRangeHandleEnds, visualInRange);
  77759. },
  77760. /**
  77761. * @private
  77762. */
  77763. _createBarVisual: function (dataInterval, dataExtent, handleEnds, forceState) {
  77764. var opts = {
  77765. forceState: forceState,
  77766. convertOpacityToAlpha: true
  77767. };
  77768. var colorStops = this._makeColorGradient(dataInterval, opts);
  77769. var symbolSizes = [
  77770. this.getControllerVisual(dataInterval[0], 'symbolSize', opts),
  77771. this.getControllerVisual(dataInterval[1], 'symbolSize', opts)
  77772. ];
  77773. var barPoints = this._createBarPoints(handleEnds, symbolSizes);
  77774. return {
  77775. barColor: new LinearGradient(0, 0, 0, 1, colorStops),
  77776. barPoints: barPoints,
  77777. handlesColor: [
  77778. colorStops[0].color,
  77779. colorStops[colorStops.length - 1].color
  77780. ]
  77781. };
  77782. },
  77783. /**
  77784. * @private
  77785. */
  77786. _makeColorGradient: function (dataInterval, opts) {
  77787. // Considering colorHue, which is not linear, so we have to sample
  77788. // to calculate gradient color stops, but not only caculate head
  77789. // and tail.
  77790. var sampleNumber = 100; // Arbitrary value.
  77791. var colorStops = [];
  77792. var step = (dataInterval[1] - dataInterval[0]) / sampleNumber;
  77793. colorStops.push({
  77794. color: this.getControllerVisual(dataInterval[0], 'color', opts),
  77795. offset: 0
  77796. });
  77797. for (var i = 1; i < sampleNumber; i++) {
  77798. var currValue = dataInterval[0] + step * i;
  77799. if (currValue > dataInterval[1]) {
  77800. break;
  77801. }
  77802. colorStops.push({
  77803. color: this.getControllerVisual(currValue, 'color', opts),
  77804. offset: i / sampleNumber
  77805. });
  77806. }
  77807. colorStops.push({
  77808. color: this.getControllerVisual(dataInterval[1], 'color', opts),
  77809. offset: 1
  77810. });
  77811. return colorStops;
  77812. },
  77813. /**
  77814. * @private
  77815. */
  77816. _createBarPoints: function (handleEnds, symbolSizes) {
  77817. var itemSize = this.visualMapModel.itemSize;
  77818. return [
  77819. [itemSize[0] - symbolSizes[0], handleEnds[0]],
  77820. [itemSize[0], handleEnds[0]],
  77821. [itemSize[0], handleEnds[1]],
  77822. [itemSize[0] - symbolSizes[1], handleEnds[1]]
  77823. ];
  77824. },
  77825. /**
  77826. * @private
  77827. */
  77828. _createBarGroup: function (itemAlign) {
  77829. var orient = this._orient;
  77830. var inverse = this.visualMapModel.get('inverse');
  77831. return new Group(
  77832. (orient === 'horizontal' && !inverse)
  77833. ? {scale: itemAlign === 'bottom' ? [1, 1] : [-1, 1], rotation: Math.PI / 2}
  77834. : (orient === 'horizontal' && inverse)
  77835. ? {scale: itemAlign === 'bottom' ? [-1, 1] : [1, 1], rotation: -Math.PI / 2}
  77836. : (orient === 'vertical' && !inverse)
  77837. ? {scale: itemAlign === 'left' ? [1, -1] : [-1, -1]}
  77838. : {scale: itemAlign === 'left' ? [1, 1] : [-1, 1]}
  77839. );
  77840. },
  77841. /**
  77842. * @private
  77843. */
  77844. _updateHandle: function (handleEnds, visualInRange) {
  77845. if (!this._useHandle) {
  77846. return;
  77847. }
  77848. var shapes = this._shapes;
  77849. var visualMapModel = this.visualMapModel;
  77850. var handleThumbs = shapes.handleThumbs;
  77851. var handleLabels = shapes.handleLabels;
  77852. each$29([0, 1], function (handleIndex) {
  77853. var handleThumb = handleThumbs[handleIndex];
  77854. handleThumb.setStyle('fill', visualInRange.handlesColor[handleIndex]);
  77855. handleThumb.position[1] = handleEnds[handleIndex];
  77856. // Update handle label position.
  77857. var textPoint = applyTransform$1(
  77858. shapes.handleLabelPoints[handleIndex],
  77859. getTransform(handleThumb, this.group)
  77860. );
  77861. handleLabels[handleIndex].setStyle({
  77862. x: textPoint[0],
  77863. y: textPoint[1],
  77864. text: visualMapModel.formatValueText(this._dataInterval[handleIndex]),
  77865. textVerticalAlign: 'middle',
  77866. textAlign: this._applyTransform(
  77867. this._orient === 'horizontal'
  77868. ? (handleIndex === 0 ? 'bottom' : 'top')
  77869. : 'left',
  77870. shapes.barGroup
  77871. )
  77872. });
  77873. }, this);
  77874. },
  77875. /**
  77876. * @private
  77877. * @param {number} cursorValue
  77878. * @param {number} textValue
  77879. * @param {string} [rangeSymbol]
  77880. * @param {number} [halfHoverLinkSize]
  77881. */
  77882. _showIndicator: function (cursorValue, textValue, rangeSymbol, halfHoverLinkSize) {
  77883. var visualMapModel = this.visualMapModel;
  77884. var dataExtent = visualMapModel.getExtent();
  77885. var itemSize = visualMapModel.itemSize;
  77886. var sizeExtent = [0, itemSize[1]];
  77887. var pos = linearMap$3(cursorValue, dataExtent, sizeExtent, true);
  77888. var shapes = this._shapes;
  77889. var indicator = shapes.indicator;
  77890. if (!indicator) {
  77891. return;
  77892. }
  77893. indicator.position[1] = pos;
  77894. indicator.attr('invisible', false);
  77895. indicator.setShape('points', createIndicatorPoints(
  77896. !!rangeSymbol, halfHoverLinkSize, pos, itemSize[1]
  77897. ));
  77898. var opts = {convertOpacityToAlpha: true};
  77899. var color = this.getControllerVisual(cursorValue, 'color', opts);
  77900. indicator.setStyle('fill', color);
  77901. // Update handle label position.
  77902. var textPoint = applyTransform$1(
  77903. shapes.indicatorLabelPoint,
  77904. getTransform(indicator, this.group)
  77905. );
  77906. var indicatorLabel = shapes.indicatorLabel;
  77907. indicatorLabel.attr('invisible', false);
  77908. var align = this._applyTransform('left', shapes.barGroup);
  77909. var orient = this._orient;
  77910. indicatorLabel.setStyle({
  77911. text: (rangeSymbol ? rangeSymbol : '') + visualMapModel.formatValueText(textValue),
  77912. textVerticalAlign: orient === 'horizontal' ? align : 'middle',
  77913. textAlign: orient === 'horizontal' ? 'center' : align,
  77914. x: textPoint[0],
  77915. y: textPoint[1]
  77916. });
  77917. },
  77918. /**
  77919. * @private
  77920. */
  77921. _enableHoverLinkToSeries: function () {
  77922. var self = this;
  77923. this._shapes.barGroup
  77924. .on('mousemove', function (e) {
  77925. self._hovering = true;
  77926. if (!self._dragging) {
  77927. var itemSize = self.visualMapModel.itemSize;
  77928. var pos = self._applyTransform(
  77929. [e.offsetX, e.offsetY], self._shapes.barGroup, true, true
  77930. );
  77931. // For hover link show when hover handle, which might be
  77932. // below or upper than sizeExtent.
  77933. pos[1] = mathMin$7(mathMax$7(0, pos[1]), itemSize[1]);
  77934. self._doHoverLinkToSeries(
  77935. pos[1],
  77936. 0 <= pos[0] && pos[0] <= itemSize[0]
  77937. );
  77938. }
  77939. })
  77940. .on('mouseout', function () {
  77941. // When mouse is out of handle, hoverLink still need
  77942. // to be displayed when realtime is set as false.
  77943. self._hovering = false;
  77944. !self._dragging && self._clearHoverLinkToSeries();
  77945. });
  77946. },
  77947. /**
  77948. * @private
  77949. */
  77950. _enableHoverLinkFromSeries: function () {
  77951. var zr = this.api.getZr();
  77952. if (this.visualMapModel.option.hoverLink) {
  77953. zr.on('mouseover', this._hoverLinkFromSeriesMouseOver, this);
  77954. zr.on('mouseout', this._hideIndicator, this);
  77955. }
  77956. else {
  77957. this._clearHoverLinkFromSeries();
  77958. }
  77959. },
  77960. /**
  77961. * @private
  77962. */
  77963. _doHoverLinkToSeries: function (cursorPos, hoverOnBar) {
  77964. var visualMapModel = this.visualMapModel;
  77965. var itemSize = visualMapModel.itemSize;
  77966. if (!visualMapModel.option.hoverLink) {
  77967. return;
  77968. }
  77969. var sizeExtent = [0, itemSize[1]];
  77970. var dataExtent = visualMapModel.getExtent();
  77971. // For hover link show when hover handle, which might be below or upper than sizeExtent.
  77972. cursorPos = mathMin$7(mathMax$7(sizeExtent[0], cursorPos), sizeExtent[1]);
  77973. var halfHoverLinkSize = getHalfHoverLinkSize(visualMapModel, dataExtent, sizeExtent);
  77974. var hoverRange = [cursorPos - halfHoverLinkSize, cursorPos + halfHoverLinkSize];
  77975. var cursorValue = linearMap$3(cursorPos, sizeExtent, dataExtent, true);
  77976. var valueRange = [
  77977. linearMap$3(hoverRange[0], sizeExtent, dataExtent, true),
  77978. linearMap$3(hoverRange[1], sizeExtent, dataExtent, true)
  77979. ];
  77980. // Consider data range is out of visualMap range, see test/visualMap-continuous.html,
  77981. // where china and india has very large population.
  77982. hoverRange[0] < sizeExtent[0] && (valueRange[0] = -Infinity);
  77983. hoverRange[1] > sizeExtent[1] && (valueRange[1] = Infinity);
  77984. // Do not show indicator when mouse is over handle,
  77985. // otherwise labels overlap, especially when dragging.
  77986. if (hoverOnBar) {
  77987. if (valueRange[0] === -Infinity) {
  77988. this._showIndicator(cursorValue, valueRange[1], '< ', halfHoverLinkSize);
  77989. }
  77990. else if (valueRange[1] === Infinity) {
  77991. this._showIndicator(cursorValue, valueRange[0], '> ', halfHoverLinkSize);
  77992. }
  77993. else {
  77994. this._showIndicator(cursorValue, cursorValue, '≈ ', halfHoverLinkSize);
  77995. }
  77996. }
  77997. // When realtime is set as false, handles, which are in barGroup,
  77998. // also trigger hoverLink, which help user to realize where they
  77999. // focus on when dragging. (see test/heatmap-large.html)
  78000. // When realtime is set as true, highlight will not show when hover
  78001. // handle, because the label on handle, which displays a exact value
  78002. // but not range, might mislead users.
  78003. var oldBatch = this._hoverLinkDataIndices;
  78004. var newBatch = [];
  78005. if (hoverOnBar || useHoverLinkOnHandle(visualMapModel)) {
  78006. newBatch = this._hoverLinkDataIndices = visualMapModel.findTargetDataIndices(valueRange);
  78007. }
  78008. var resultBatches = compressBatches(oldBatch, newBatch);
  78009. this._dispatchHighDown('downplay', makeHighDownBatch(resultBatches[0], visualMapModel));
  78010. this._dispatchHighDown('highlight', makeHighDownBatch(resultBatches[1], visualMapModel));
  78011. },
  78012. /**
  78013. * @private
  78014. */
  78015. _hoverLinkFromSeriesMouseOver: function (e) {
  78016. var el = e.target;
  78017. var visualMapModel = this.visualMapModel;
  78018. if (!el || el.dataIndex == null) {
  78019. return;
  78020. }
  78021. var dataModel = this.ecModel.getSeriesByIndex(el.seriesIndex);
  78022. if (!visualMapModel.isTargetSeries(dataModel)) {
  78023. return;
  78024. }
  78025. var data = dataModel.getData(el.dataType);
  78026. var value = data.get(visualMapModel.getDataDimension(data), el.dataIndex, true);
  78027. if (!isNaN(value)) {
  78028. this._showIndicator(value, value);
  78029. }
  78030. },
  78031. /**
  78032. * @private
  78033. */
  78034. _hideIndicator: function () {
  78035. var shapes = this._shapes;
  78036. shapes.indicator && shapes.indicator.attr('invisible', true);
  78037. shapes.indicatorLabel && shapes.indicatorLabel.attr('invisible', true);
  78038. },
  78039. /**
  78040. * @private
  78041. */
  78042. _clearHoverLinkToSeries: function () {
  78043. this._hideIndicator();
  78044. var indices = this._hoverLinkDataIndices;
  78045. this._dispatchHighDown('downplay', makeHighDownBatch(indices, this.visualMapModel));
  78046. indices.length = 0;
  78047. },
  78048. /**
  78049. * @private
  78050. */
  78051. _clearHoverLinkFromSeries: function () {
  78052. this._hideIndicator();
  78053. var zr = this.api.getZr();
  78054. zr.off('mouseover', this._hoverLinkFromSeriesMouseOver);
  78055. zr.off('mouseout', this._hideIndicator);
  78056. },
  78057. /**
  78058. * @private
  78059. */
  78060. _applyTransform: function (vertex, element, inverse, global) {
  78061. var transform = getTransform(element, global ? null : this.group);
  78062. return graphic[
  78063. isArray(vertex) ? 'applyTransform' : 'transformDirection'
  78064. ](vertex, transform, inverse);
  78065. },
  78066. /**
  78067. * @private
  78068. */
  78069. _dispatchHighDown: function (type, batch) {
  78070. batch && batch.length && this.api.dispatchAction({
  78071. type: type,
  78072. batch: batch
  78073. });
  78074. },
  78075. /**
  78076. * @override
  78077. */
  78078. dispose: function () {
  78079. this._clearHoverLinkFromSeries();
  78080. this._clearHoverLinkToSeries();
  78081. },
  78082. /**
  78083. * @override
  78084. */
  78085. remove: function () {
  78086. this._clearHoverLinkFromSeries();
  78087. this._clearHoverLinkToSeries();
  78088. }
  78089. });
  78090. function createPolygon(points, cursor, onDrift, onDragEnd) {
  78091. return new Polygon({
  78092. shape: {points: points},
  78093. draggable: !!onDrift,
  78094. cursor: cursor,
  78095. drift: onDrift,
  78096. onmousemove: function (e) {
  78097. // Fot mobile devicem, prevent screen slider on the button.
  78098. stop(e.event);
  78099. },
  78100. ondragend: onDragEnd
  78101. });
  78102. }
  78103. function createHandlePoints(handleIndex, textSize) {
  78104. return handleIndex === 0
  78105. ? [[0, 0], [textSize, 0], [textSize, -textSize]]
  78106. : [[0, 0], [textSize, 0], [textSize, textSize]];
  78107. }
  78108. function createIndicatorPoints(isRange, halfHoverLinkSize, pos, extentMax) {
  78109. return isRange
  78110. ? [ // indicate range
  78111. [0, -mathMin$7(halfHoverLinkSize, mathMax$7(pos, 0))],
  78112. [HOVER_LINK_OUT, 0],
  78113. [0, mathMin$7(halfHoverLinkSize, mathMax$7(extentMax - pos, 0))]
  78114. ]
  78115. : [ // indicate single value
  78116. [0, 0], [5, -5], [5, 5]
  78117. ];
  78118. }
  78119. function getHalfHoverLinkSize(visualMapModel, dataExtent, sizeExtent) {
  78120. var halfHoverLinkSize = HOVER_LINK_SIZE / 2;
  78121. var hoverLinkDataSize = visualMapModel.get('hoverLinkDataSize');
  78122. if (hoverLinkDataSize) {
  78123. halfHoverLinkSize = linearMap$3(hoverLinkDataSize, dataExtent, sizeExtent, true) / 2;
  78124. }
  78125. return halfHoverLinkSize;
  78126. }
  78127. function useHoverLinkOnHandle(visualMapModel) {
  78128. var hoverLinkOnHandle = visualMapModel.get('hoverLinkOnHandle');
  78129. return !!(hoverLinkOnHandle == null ? visualMapModel.get('realtime') : hoverLinkOnHandle);
  78130. }
  78131. function getCursor$1(orient) {
  78132. return orient === 'vertical' ? 'ns-resize' : 'ew-resize';
  78133. }
  78134. /*
  78135. * Licensed to the Apache Software Foundation (ASF) under one
  78136. * or more contributor license agreements. See the NOTICE file
  78137. * distributed with this work for additional information
  78138. * regarding copyright ownership. The ASF licenses this file
  78139. * to you under the Apache License, Version 2.0 (the
  78140. * "License"); you may not use this file except in compliance
  78141. * with the License. You may obtain a copy of the License at
  78142. *
  78143. * http://www.apache.org/licenses/LICENSE-2.0
  78144. *
  78145. * Unless required by applicable law or agreed to in writing,
  78146. * software distributed under the License is distributed on an
  78147. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  78148. * KIND, either express or implied. See the License for the
  78149. * specific language governing permissions and limitations
  78150. * under the License.
  78151. */
  78152. var actionInfo$2 = {
  78153. type: 'selectDataRange',
  78154. event: 'dataRangeSelected',
  78155. // FIXME use updateView appears wrong
  78156. update: 'update'
  78157. };
  78158. registerAction(actionInfo$2, function (payload, ecModel) {
  78159. ecModel.eachComponent({mainType: 'visualMap', query: payload}, function (model) {
  78160. model.setSelected(payload.selected);
  78161. });
  78162. });
  78163. /*
  78164. * Licensed to the Apache Software Foundation (ASF) under one
  78165. * or more contributor license agreements. See the NOTICE file
  78166. * distributed with this work for additional information
  78167. * regarding copyright ownership. The ASF licenses this file
  78168. * to you under the Apache License, Version 2.0 (the
  78169. * "License"); you may not use this file except in compliance
  78170. * with the License. You may obtain a copy of the License at
  78171. *
  78172. * http://www.apache.org/licenses/LICENSE-2.0
  78173. *
  78174. * Unless required by applicable law or agreed to in writing,
  78175. * software distributed under the License is distributed on an
  78176. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  78177. * KIND, either express or implied. See the License for the
  78178. * specific language governing permissions and limitations
  78179. * under the License.
  78180. */
  78181. /**
  78182. * DataZoom component entry
  78183. */
  78184. registerPreprocessor(preprocessor$3);
  78185. /*
  78186. * Licensed to the Apache Software Foundation (ASF) under one
  78187. * or more contributor license agreements. See the NOTICE file
  78188. * distributed with this work for additional information
  78189. * regarding copyright ownership. The ASF licenses this file
  78190. * to you under the Apache License, Version 2.0 (the
  78191. * "License"); you may not use this file except in compliance
  78192. * with the License. You may obtain a copy of the License at
  78193. *
  78194. * http://www.apache.org/licenses/LICENSE-2.0
  78195. *
  78196. * Unless required by applicable law or agreed to in writing,
  78197. * software distributed under the License is distributed on an
  78198. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  78199. * KIND, either express or implied. See the License for the
  78200. * specific language governing permissions and limitations
  78201. * under the License.
  78202. */
  78203. var PiecewiseModel = VisualMapModel.extend({
  78204. type: 'visualMap.piecewise',
  78205. /**
  78206. * Order Rule:
  78207. *
  78208. * option.categories / option.pieces / option.text / option.selected:
  78209. * If !option.inverse,
  78210. * Order when vertical: ['top', ..., 'bottom'].
  78211. * Order when horizontal: ['left', ..., 'right'].
  78212. * If option.inverse, the meaning of
  78213. * the order should be reversed.
  78214. *
  78215. * this._pieceList:
  78216. * The order is always [low, ..., high].
  78217. *
  78218. * Mapping from location to low-high:
  78219. * If !option.inverse
  78220. * When vertical, top is high.
  78221. * When horizontal, right is high.
  78222. * If option.inverse, reverse.
  78223. */
  78224. /**
  78225. * @protected
  78226. */
  78227. defaultOption: {
  78228. selected: null, // Object. If not specified, means selected.
  78229. // When pieces and splitNumber: {'0': true, '5': true}
  78230. // When categories: {'cate1': false, 'cate3': true}
  78231. // When selected === false, means all unselected.
  78232. minOpen: false, // Whether include values that smaller than `min`.
  78233. maxOpen: false, // Whether include values that bigger than `max`.
  78234. align: 'auto', // 'auto', 'left', 'right'
  78235. itemWidth: 20, // When put the controller vertically, it is the length of
  78236. // horizontal side of each item. Otherwise, vertical side.
  78237. itemHeight: 14, // When put the controller vertically, it is the length of
  78238. // vertical side of each item. Otherwise, horizontal side.
  78239. itemSymbol: 'roundRect',
  78240. pieceList: null, // Each item is Object, with some of those attrs:
  78241. // {min, max, lt, gt, lte, gte, value,
  78242. // color, colorSaturation, colorAlpha, opacity,
  78243. // symbol, symbolSize}, which customize the range or visual
  78244. // coding of the certain piece. Besides, see "Order Rule".
  78245. categories: null, // category names, like: ['some1', 'some2', 'some3'].
  78246. // Attr min/max are ignored when categories set. See "Order Rule"
  78247. splitNumber: 5, // If set to 5, auto split five pieces equally.
  78248. // If set to 0 and component type not set, component type will be
  78249. // determined as "continuous". (It is less reasonable but for ec2
  78250. // compatibility, see echarts/component/visualMap/typeDefaulter)
  78251. selectedMode: 'multiple', // Can be 'multiple' or 'single'.
  78252. itemGap: 10, // The gap between two items, in px.
  78253. hoverLink: true, // Enable hover highlight.
  78254. showLabel: null // By default, when text is used, label will hide (the logic
  78255. // is remained for compatibility reason)
  78256. },
  78257. /**
  78258. * @override
  78259. */
  78260. optionUpdated: function (newOption, isInit) {
  78261. PiecewiseModel.superApply(this, 'optionUpdated', arguments);
  78262. /**
  78263. * The order is always [low, ..., high].
  78264. * [{text: string, interval: Array.<number>}, ...]
  78265. * @private
  78266. * @type {Array.<Object>}
  78267. */
  78268. this._pieceList = [];
  78269. this.resetExtent();
  78270. /**
  78271. * 'pieces', 'categories', 'splitNumber'
  78272. * @type {string}
  78273. */
  78274. var mode = this._mode = this._determineMode();
  78275. resetMethods[this._mode].call(this);
  78276. this._resetSelected(newOption, isInit);
  78277. var categories = this.option.categories;
  78278. this.resetVisual(function (mappingOption, state) {
  78279. if (mode === 'categories') {
  78280. mappingOption.mappingMethod = 'category';
  78281. mappingOption.categories = clone(categories);
  78282. }
  78283. else {
  78284. mappingOption.dataExtent = this.getExtent();
  78285. mappingOption.mappingMethod = 'piecewise';
  78286. mappingOption.pieceList = map(this._pieceList, function (piece) {
  78287. var piece = clone(piece);
  78288. if (state !== 'inRange') {
  78289. // FIXME
  78290. // outOfRange do not support special visual in pieces.
  78291. piece.visual = null;
  78292. }
  78293. return piece;
  78294. });
  78295. }
  78296. });
  78297. },
  78298. /**
  78299. * @protected
  78300. * @override
  78301. */
  78302. completeVisualOption: function () {
  78303. // Consider this case:
  78304. // visualMap: {
  78305. // pieces: [{symbol: 'circle', lt: 0}, {symbol: 'rect', gte: 0}]
  78306. // }
  78307. // where no inRange/outOfRange set but only pieces. So we should make
  78308. // default inRange/outOfRange for this case, otherwise visuals that only
  78309. // appear in `pieces` will not be taken into account in visual encoding.
  78310. var option = this.option;
  78311. var visualTypesInPieces = {};
  78312. var visualTypes = VisualMapping.listVisualTypes();
  78313. var isCategory = this.isCategory();
  78314. each$1(option.pieces, function (piece) {
  78315. each$1(visualTypes, function (visualType) {
  78316. if (piece.hasOwnProperty(visualType)) {
  78317. visualTypesInPieces[visualType] = 1;
  78318. }
  78319. });
  78320. });
  78321. each$1(visualTypesInPieces, function (v, visualType) {
  78322. var exists = 0;
  78323. each$1(this.stateList, function (state) {
  78324. exists |= has(option, state, visualType)
  78325. || has(option.target, state, visualType);
  78326. }, this);
  78327. !exists && each$1(this.stateList, function (state) {
  78328. (option[state] || (option[state] = {}))[visualType] = visualDefault.get(
  78329. visualType, state === 'inRange' ? 'active' : 'inactive', isCategory
  78330. );
  78331. });
  78332. }, this);
  78333. function has(obj, state, visualType) {
  78334. return obj && obj[state] && (
  78335. isObject$1(obj[state])
  78336. ? obj[state].hasOwnProperty(visualType)
  78337. : obj[state] === visualType // e.g., inRange: 'symbol'
  78338. );
  78339. }
  78340. VisualMapModel.prototype.completeVisualOption.apply(this, arguments);
  78341. },
  78342. _resetSelected: function (newOption, isInit) {
  78343. var thisOption = this.option;
  78344. var pieceList = this._pieceList;
  78345. // Selected do not merge but all override.
  78346. var selected = (isInit ? thisOption : newOption).selected || {};
  78347. thisOption.selected = selected;
  78348. // Consider 'not specified' means true.
  78349. each$1(pieceList, function (piece, index) {
  78350. var key = this.getSelectedMapKey(piece);
  78351. if (!selected.hasOwnProperty(key)) {
  78352. selected[key] = true;
  78353. }
  78354. }, this);
  78355. if (thisOption.selectedMode === 'single') {
  78356. // Ensure there is only one selected.
  78357. var hasSel = false;
  78358. each$1(pieceList, function (piece, index) {
  78359. var key = this.getSelectedMapKey(piece);
  78360. if (selected[key]) {
  78361. hasSel
  78362. ? (selected[key] = false)
  78363. : (hasSel = true);
  78364. }
  78365. }, this);
  78366. }
  78367. // thisOption.selectedMode === 'multiple', default: all selected.
  78368. },
  78369. /**
  78370. * @public
  78371. */
  78372. getSelectedMapKey: function (piece) {
  78373. return this._mode === 'categories'
  78374. ? piece.value + '' : piece.index + '';
  78375. },
  78376. /**
  78377. * @public
  78378. */
  78379. getPieceList: function () {
  78380. return this._pieceList;
  78381. },
  78382. /**
  78383. * @private
  78384. * @return {string}
  78385. */
  78386. _determineMode: function () {
  78387. var option = this.option;
  78388. return option.pieces && option.pieces.length > 0
  78389. ? 'pieces'
  78390. : this.option.categories
  78391. ? 'categories'
  78392. : 'splitNumber';
  78393. },
  78394. /**
  78395. * @public
  78396. * @override
  78397. */
  78398. setSelected: function (selected) {
  78399. this.option.selected = clone(selected);
  78400. },
  78401. /**
  78402. * @public
  78403. * @override
  78404. */
  78405. getValueState: function (value) {
  78406. var index = VisualMapping.findPieceIndex(value, this._pieceList);
  78407. return index != null
  78408. ? (this.option.selected[this.getSelectedMapKey(this._pieceList[index])]
  78409. ? 'inRange' : 'outOfRange'
  78410. )
  78411. : 'outOfRange';
  78412. },
  78413. /**
  78414. * @public
  78415. * @params {number} pieceIndex piece index in visualMapModel.getPieceList()
  78416. * @return {Array.<Object>} [{seriesId, dataIndex: <Array.<number>>}, ...]
  78417. */
  78418. findTargetDataIndices: function (pieceIndex) {
  78419. var result = [];
  78420. this.eachTargetSeries(function (seriesModel) {
  78421. var dataIndices = [];
  78422. var data = seriesModel.getData();
  78423. data.each(this.getDataDimension(data), function (value, dataIndex) {
  78424. // Should always base on model pieceList, because it is order sensitive.
  78425. var pIdx = VisualMapping.findPieceIndex(value, this._pieceList);
  78426. pIdx === pieceIndex && dataIndices.push(dataIndex);
  78427. }, this);
  78428. result.push({seriesId: seriesModel.id, dataIndex: dataIndices});
  78429. }, this);
  78430. return result;
  78431. },
  78432. /**
  78433. * @private
  78434. * @param {Object} piece piece.value or piece.interval is required.
  78435. * @return {number} Can be Infinity or -Infinity
  78436. */
  78437. getRepresentValue: function (piece) {
  78438. var representValue;
  78439. if (this.isCategory()) {
  78440. representValue = piece.value;
  78441. }
  78442. else {
  78443. if (piece.value != null) {
  78444. representValue = piece.value;
  78445. }
  78446. else {
  78447. var pieceInterval = piece.interval || [];
  78448. representValue = (pieceInterval[0] === -Infinity && pieceInterval[1] === Infinity)
  78449. ? 0
  78450. : (pieceInterval[0] + pieceInterval[1]) / 2;
  78451. }
  78452. }
  78453. return representValue;
  78454. },
  78455. getVisualMeta: function (getColorVisual) {
  78456. // Do not support category. (category axis is ordinal, numerical)
  78457. if (this.isCategory()) {
  78458. return;
  78459. }
  78460. var stops = [];
  78461. var outerColors = [];
  78462. var visualMapModel = this;
  78463. function setStop(interval, valueState) {
  78464. var representValue = visualMapModel.getRepresentValue({interval: interval});
  78465. if (!valueState) {
  78466. valueState = visualMapModel.getValueState(representValue);
  78467. }
  78468. var color = getColorVisual(representValue, valueState);
  78469. if (interval[0] === -Infinity) {
  78470. outerColors[0] = color;
  78471. }
  78472. else if (interval[1] === Infinity) {
  78473. outerColors[1] = color;
  78474. }
  78475. else {
  78476. stops.push(
  78477. {value: interval[0], color: color},
  78478. {value: interval[1], color: color}
  78479. );
  78480. }
  78481. }
  78482. // Suplement
  78483. var pieceList = this._pieceList.slice();
  78484. if (!pieceList.length) {
  78485. pieceList.push({interval: [-Infinity, Infinity]});
  78486. }
  78487. else {
  78488. var edge = pieceList[0].interval[0];
  78489. edge !== -Infinity && pieceList.unshift({interval: [-Infinity, edge]});
  78490. edge = pieceList[pieceList.length - 1].interval[1];
  78491. edge !== Infinity && pieceList.push({interval: [edge, Infinity]});
  78492. }
  78493. var curr = -Infinity;
  78494. each$1(pieceList, function (piece) {
  78495. var interval = piece.interval;
  78496. if (interval) {
  78497. // Fulfill gap.
  78498. interval[0] > curr && setStop([curr, interval[0]], 'outOfRange');
  78499. setStop(interval.slice());
  78500. curr = interval[1];
  78501. }
  78502. }, this);
  78503. return {stops: stops, outerColors: outerColors};
  78504. }
  78505. });
  78506. /**
  78507. * Key is this._mode
  78508. * @type {Object}
  78509. * @this {module:echarts/component/viusalMap/PiecewiseMode}
  78510. */
  78511. var resetMethods = {
  78512. splitNumber: function () {
  78513. var thisOption = this.option;
  78514. var pieceList = this._pieceList;
  78515. var precision = Math.min(thisOption.precision, 20);
  78516. var dataExtent = this.getExtent();
  78517. var splitNumber = thisOption.splitNumber;
  78518. splitNumber = Math.max(parseInt(splitNumber, 10), 1);
  78519. thisOption.splitNumber = splitNumber;
  78520. var splitStep = (dataExtent[1] - dataExtent[0]) / splitNumber;
  78521. // Precision auto-adaption
  78522. while (+splitStep.toFixed(precision) !== splitStep && precision < 5) {
  78523. precision++;
  78524. }
  78525. thisOption.precision = precision;
  78526. splitStep = +splitStep.toFixed(precision);
  78527. var index = 0;
  78528. if (thisOption.minOpen) {
  78529. pieceList.push({
  78530. index: index++,
  78531. interval: [-Infinity, dataExtent[0]],
  78532. close: [0, 0]
  78533. });
  78534. }
  78535. for (
  78536. var curr = dataExtent[0], len = index + splitNumber;
  78537. index < len;
  78538. curr += splitStep
  78539. ) {
  78540. var max = index === splitNumber - 1 ? dataExtent[1] : (curr + splitStep);
  78541. pieceList.push({
  78542. index: index++,
  78543. interval: [curr, max],
  78544. close: [1, 1]
  78545. });
  78546. }
  78547. if (thisOption.maxOpen) {
  78548. pieceList.push({
  78549. index: index++,
  78550. interval: [dataExtent[1], Infinity],
  78551. close: [0, 0]
  78552. });
  78553. }
  78554. reformIntervals(pieceList);
  78555. each$1(pieceList, function (piece) {
  78556. piece.text = this.formatValueText(piece.interval);
  78557. }, this);
  78558. },
  78559. categories: function () {
  78560. var thisOption = this.option;
  78561. each$1(thisOption.categories, function (cate) {
  78562. // FIXME category模式也使用pieceList,但在visualMapping中不是使用pieceList。
  78563. // 是否改一致。
  78564. this._pieceList.push({
  78565. text: this.formatValueText(cate, true),
  78566. value: cate
  78567. });
  78568. }, this);
  78569. // See "Order Rule".
  78570. normalizeReverse(thisOption, this._pieceList);
  78571. },
  78572. pieces: function () {
  78573. var thisOption = this.option;
  78574. var pieceList = this._pieceList;
  78575. each$1(thisOption.pieces, function (pieceListItem, index) {
  78576. if (!isObject$1(pieceListItem)) {
  78577. pieceListItem = {value: pieceListItem};
  78578. }
  78579. var item = {text: '', index: index};
  78580. if (pieceListItem.label != null) {
  78581. item.text = pieceListItem.label;
  78582. }
  78583. if (pieceListItem.hasOwnProperty('value')) {
  78584. var value = item.value = pieceListItem.value;
  78585. item.interval = [value, value];
  78586. item.close = [1, 1];
  78587. }
  78588. else {
  78589. // `min` `max` is legacy option.
  78590. // `lt` `gt` `lte` `gte` is recommanded.
  78591. var interval = item.interval = [];
  78592. var close = item.close = [0, 0];
  78593. var closeList = [1, 0, 1];
  78594. var infinityList = [-Infinity, Infinity];
  78595. var useMinMax = [];
  78596. for (var lg = 0; lg < 2; lg++) {
  78597. var names = [['gte', 'gt', 'min'], ['lte', 'lt', 'max']][lg];
  78598. for (var i = 0; i < 3 && interval[lg] == null; i++) {
  78599. interval[lg] = pieceListItem[names[i]];
  78600. close[lg] = closeList[i];
  78601. useMinMax[lg] = i === 2;
  78602. }
  78603. interval[lg] == null && (interval[lg] = infinityList[lg]);
  78604. }
  78605. useMinMax[0] && interval[1] === Infinity && (close[0] = 0);
  78606. useMinMax[1] && interval[0] === -Infinity && (close[1] = 0);
  78607. if (__DEV__) {
  78608. if (interval[0] > interval[1]) {
  78609. console.warn(
  78610. 'Piece ' + index + 'is illegal: ' + interval
  78611. + ' lower bound should not greater then uppper bound.'
  78612. );
  78613. }
  78614. }
  78615. if (interval[0] === interval[1] && close[0] && close[1]) {
  78616. // Consider: [{min: 5, max: 5, visual: {...}}, {min: 0, max: 5}],
  78617. // we use value to lift the priority when min === max
  78618. item.value = interval[0];
  78619. }
  78620. }
  78621. item.visual = VisualMapping.retrieveVisuals(pieceListItem);
  78622. pieceList.push(item);
  78623. }, this);
  78624. // See "Order Rule".
  78625. normalizeReverse(thisOption, pieceList);
  78626. // Only pieces
  78627. reformIntervals(pieceList);
  78628. each$1(pieceList, function (piece) {
  78629. var close = piece.close;
  78630. var edgeSymbols = [['<', '≤'][close[1]], ['>', '≥'][close[0]]];
  78631. piece.text = piece.text || this.formatValueText(
  78632. piece.value != null ? piece.value : piece.interval,
  78633. false,
  78634. edgeSymbols
  78635. );
  78636. }, this);
  78637. }
  78638. };
  78639. function normalizeReverse(thisOption, pieceList) {
  78640. var inverse = thisOption.inverse;
  78641. if (thisOption.orient === 'vertical' ? !inverse : inverse) {
  78642. pieceList.reverse();
  78643. }
  78644. }
  78645. /*
  78646. * Licensed to the Apache Software Foundation (ASF) under one
  78647. * or more contributor license agreements. See the NOTICE file
  78648. * distributed with this work for additional information
  78649. * regarding copyright ownership. The ASF licenses this file
  78650. * to you under the Apache License, Version 2.0 (the
  78651. * "License"); you may not use this file except in compliance
  78652. * with the License. You may obtain a copy of the License at
  78653. *
  78654. * http://www.apache.org/licenses/LICENSE-2.0
  78655. *
  78656. * Unless required by applicable law or agreed to in writing,
  78657. * software distributed under the License is distributed on an
  78658. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  78659. * KIND, either express or implied. See the License for the
  78660. * specific language governing permissions and limitations
  78661. * under the License.
  78662. */
  78663. var PiecewiseVisualMapView = VisualMapView.extend({
  78664. type: 'visualMap.piecewise',
  78665. /**
  78666. * @protected
  78667. * @override
  78668. */
  78669. doRender: function () {
  78670. var thisGroup = this.group;
  78671. thisGroup.removeAll();
  78672. var visualMapModel = this.visualMapModel;
  78673. var textGap = visualMapModel.get('textGap');
  78674. var textStyleModel = visualMapModel.textStyleModel;
  78675. var textFont = textStyleModel.getFont();
  78676. var textFill = textStyleModel.getTextColor();
  78677. var itemAlign = this._getItemAlign();
  78678. var itemSize = visualMapModel.itemSize;
  78679. var viewData = this._getViewData();
  78680. var endsText = viewData.endsText;
  78681. var showLabel = retrieve(visualMapModel.get('showLabel', true), !endsText);
  78682. endsText && this._renderEndsText(
  78683. thisGroup, endsText[0], itemSize, showLabel, itemAlign
  78684. );
  78685. each$1(viewData.viewPieceList, renderItem, this);
  78686. endsText && this._renderEndsText(
  78687. thisGroup, endsText[1], itemSize, showLabel, itemAlign
  78688. );
  78689. box(
  78690. visualMapModel.get('orient'), thisGroup, visualMapModel.get('itemGap')
  78691. );
  78692. this.renderBackground(thisGroup);
  78693. this.positionGroup(thisGroup);
  78694. function renderItem(item) {
  78695. var piece = item.piece;
  78696. var itemGroup = new Group();
  78697. itemGroup.onclick = bind(this._onItemClick, this, piece);
  78698. this._enableHoverLink(itemGroup, item.indexInModelPieceList);
  78699. var representValue = visualMapModel.getRepresentValue(piece);
  78700. this._createItemSymbol(
  78701. itemGroup, representValue, [0, 0, itemSize[0], itemSize[1]]
  78702. );
  78703. if (showLabel) {
  78704. var visualState = this.visualMapModel.getValueState(representValue);
  78705. itemGroup.add(new Text({
  78706. style: {
  78707. x: itemAlign === 'right' ? -textGap : itemSize[0] + textGap,
  78708. y: itemSize[1] / 2,
  78709. text: piece.text,
  78710. textVerticalAlign: 'middle',
  78711. textAlign: itemAlign,
  78712. textFont: textFont,
  78713. textFill: textFill,
  78714. opacity: visualState === 'outOfRange' ? 0.5 : 1
  78715. }
  78716. }));
  78717. }
  78718. thisGroup.add(itemGroup);
  78719. }
  78720. },
  78721. /**
  78722. * @private
  78723. */
  78724. _enableHoverLink: function (itemGroup, pieceIndex) {
  78725. itemGroup
  78726. .on('mouseover', bind(onHoverLink, this, 'highlight'))
  78727. .on('mouseout', bind(onHoverLink, this, 'downplay'));
  78728. function onHoverLink(method) {
  78729. var visualMapModel = this.visualMapModel;
  78730. visualMapModel.option.hoverLink && this.api.dispatchAction({
  78731. type: method,
  78732. batch: makeHighDownBatch(
  78733. visualMapModel.findTargetDataIndices(pieceIndex),
  78734. visualMapModel
  78735. )
  78736. });
  78737. }
  78738. },
  78739. /**
  78740. * @private
  78741. */
  78742. _getItemAlign: function () {
  78743. var visualMapModel = this.visualMapModel;
  78744. var modelOption = visualMapModel.option;
  78745. if (modelOption.orient === 'vertical') {
  78746. return getItemAlign(
  78747. visualMapModel, this.api, visualMapModel.itemSize
  78748. );
  78749. }
  78750. else { // horizontal, most case left unless specifying right.
  78751. var align = modelOption.align;
  78752. if (!align || align === 'auto') {
  78753. align = 'left';
  78754. }
  78755. return align;
  78756. }
  78757. },
  78758. /**
  78759. * @private
  78760. */
  78761. _renderEndsText: function (group, text, itemSize, showLabel, itemAlign) {
  78762. if (!text) {
  78763. return;
  78764. }
  78765. var itemGroup = new Group();
  78766. var textStyleModel = this.visualMapModel.textStyleModel;
  78767. itemGroup.add(new Text({
  78768. style: {
  78769. x: showLabel ? (itemAlign === 'right' ? itemSize[0] : 0) : itemSize[0] / 2,
  78770. y: itemSize[1] / 2,
  78771. textVerticalAlign: 'middle',
  78772. textAlign: showLabel ? itemAlign : 'center',
  78773. text: text,
  78774. textFont: textStyleModel.getFont(),
  78775. textFill: textStyleModel.getTextColor()
  78776. }
  78777. }));
  78778. group.add(itemGroup);
  78779. },
  78780. /**
  78781. * @private
  78782. * @return {Object} {peiceList, endsText} The order is the same as screen pixel order.
  78783. */
  78784. _getViewData: function () {
  78785. var visualMapModel = this.visualMapModel;
  78786. var viewPieceList = map(visualMapModel.getPieceList(), function (piece, index) {
  78787. return {piece: piece, indexInModelPieceList: index};
  78788. });
  78789. var endsText = visualMapModel.get('text');
  78790. // Consider orient and inverse.
  78791. var orient = visualMapModel.get('orient');
  78792. var inverse = visualMapModel.get('inverse');
  78793. // Order of model pieceList is always [low, ..., high]
  78794. if (orient === 'horizontal' ? inverse : !inverse) {
  78795. viewPieceList.reverse();
  78796. }
  78797. // Origin order of endsText is [high, low]
  78798. else if (endsText) {
  78799. endsText = endsText.slice().reverse();
  78800. }
  78801. return {viewPieceList: viewPieceList, endsText: endsText};
  78802. },
  78803. /**
  78804. * @private
  78805. */
  78806. _createItemSymbol: function (group, representValue, shapeParam) {
  78807. group.add(createSymbol(
  78808. this.getControllerVisual(representValue, 'symbol'),
  78809. shapeParam[0], shapeParam[1], shapeParam[2], shapeParam[3],
  78810. this.getControllerVisual(representValue, 'color')
  78811. ));
  78812. },
  78813. /**
  78814. * @private
  78815. */
  78816. _onItemClick: function (piece) {
  78817. var visualMapModel = this.visualMapModel;
  78818. var option = visualMapModel.option;
  78819. var selected = clone(option.selected);
  78820. var newKey = visualMapModel.getSelectedMapKey(piece);
  78821. if (option.selectedMode === 'single') {
  78822. selected[newKey] = true;
  78823. each$1(selected, function (o, key) {
  78824. selected[key] = key === newKey;
  78825. });
  78826. }
  78827. else {
  78828. selected[newKey] = !selected[newKey];
  78829. }
  78830. this.api.dispatchAction({
  78831. type: 'selectDataRange',
  78832. from: this.uid,
  78833. visualMapId: this.visualMapModel.id,
  78834. selected: selected
  78835. });
  78836. }
  78837. });
  78838. /*
  78839. * Licensed to the Apache Software Foundation (ASF) under one
  78840. * or more contributor license agreements. See the NOTICE file
  78841. * distributed with this work for additional information
  78842. * regarding copyright ownership. The ASF licenses this file
  78843. * to you under the Apache License, Version 2.0 (the
  78844. * "License"); you may not use this file except in compliance
  78845. * with the License. You may obtain a copy of the License at
  78846. *
  78847. * http://www.apache.org/licenses/LICENSE-2.0
  78848. *
  78849. * Unless required by applicable law or agreed to in writing,
  78850. * software distributed under the License is distributed on an
  78851. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  78852. * KIND, either express or implied. See the License for the
  78853. * specific language governing permissions and limitations
  78854. * under the License.
  78855. */
  78856. /**
  78857. * DataZoom component entry
  78858. */
  78859. registerPreprocessor(preprocessor$3);
  78860. /*
  78861. * Licensed to the Apache Software Foundation (ASF) under one
  78862. * or more contributor license agreements. See the NOTICE file
  78863. * distributed with this work for additional information
  78864. * regarding copyright ownership. The ASF licenses this file
  78865. * to you under the Apache License, Version 2.0 (the
  78866. * "License"); you may not use this file except in compliance
  78867. * with the License. You may obtain a copy of the License at
  78868. *
  78869. * http://www.apache.org/licenses/LICENSE-2.0
  78870. *
  78871. * Unless required by applicable law or agreed to in writing,
  78872. * software distributed under the License is distributed on an
  78873. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  78874. * KIND, either express or implied. See the License for the
  78875. * specific language governing permissions and limitations
  78876. * under the License.
  78877. */
  78878. /**
  78879. * visualMap component entry
  78880. */
  78881. var urn = 'urn:schemas-microsoft-com:vml';
  78882. var win = typeof window === 'undefined' ? null : window;
  78883. var vmlInited = false;
  78884. var doc = win && win.document;
  78885. function createNode(tagName) {
  78886. return doCreateNode(tagName);
  78887. }
  78888. // Avoid assign to an exported variable, for transforming to cjs.
  78889. var doCreateNode;
  78890. if (doc && !env$1.canvasSupported) {
  78891. try {
  78892. !doc.namespaces.zrvml && doc.namespaces.add('zrvml', urn);
  78893. doCreateNode = function (tagName) {
  78894. return doc.createElement('<zrvml:' + tagName + ' class="zrvml">');
  78895. };
  78896. }
  78897. catch (e) {
  78898. doCreateNode = function (tagName) {
  78899. return doc.createElement('<' + tagName + ' xmlns="' + urn + '" class="zrvml">');
  78900. };
  78901. }
  78902. }
  78903. // From raphael
  78904. function initVML() {
  78905. if (vmlInited || !doc) {
  78906. return;
  78907. }
  78908. vmlInited = true;
  78909. var styleSheets = doc.styleSheets;
  78910. if (styleSheets.length < 31) {
  78911. doc.createStyleSheet().addRule('.zrvml', 'behavior:url(#default#VML)');
  78912. }
  78913. else {
  78914. // http://msdn.microsoft.com/en-us/library/ms531194%28VS.85%29.aspx
  78915. styleSheets[0].addRule('.zrvml', 'behavior:url(#default#VML)');
  78916. }
  78917. }
  78918. // http://www.w3.org/TR/NOTE-VML
  78919. // TODO Use proxy like svg instead of overwrite brush methods
  78920. var CMD$3 = PathProxy.CMD;
  78921. var round$3 = Math.round;
  78922. var sqrt = Math.sqrt;
  78923. var abs$1 = Math.abs;
  78924. var cos = Math.cos;
  78925. var sin = Math.sin;
  78926. var mathMax$8 = Math.max;
  78927. if (!env$1.canvasSupported) {
  78928. var comma = ',';
  78929. var imageTransformPrefix = 'progid:DXImageTransform.Microsoft';
  78930. var Z = 21600;
  78931. var Z2 = Z / 2;
  78932. var ZLEVEL_BASE = 100000;
  78933. var Z_BASE$1 = 1000;
  78934. var initRootElStyle = function (el) {
  78935. el.style.cssText = 'position:absolute;left:0;top:0;width:1px;height:1px;';
  78936. el.coordsize = Z + ',' + Z;
  78937. el.coordorigin = '0,0';
  78938. };
  78939. var encodeHtmlAttribute = function (s) {
  78940. return String(s).replace(/&/g, '&amp;').replace(/"/g, '&quot;');
  78941. };
  78942. var rgb2Str = function (r, g, b) {
  78943. return 'rgb(' + [r, g, b].join(',') + ')';
  78944. };
  78945. var append = function (parent, child) {
  78946. if (child && parent && child.parentNode !== parent) {
  78947. parent.appendChild(child);
  78948. }
  78949. };
  78950. var remove = function (parent, child) {
  78951. if (child && parent && child.parentNode === parent) {
  78952. parent.removeChild(child);
  78953. }
  78954. };
  78955. var getZIndex = function (zlevel, z, z2) {
  78956. // z 的取值范围为 [0, 1000]
  78957. return (parseFloat(zlevel) || 0) * ZLEVEL_BASE + (parseFloat(z) || 0) * Z_BASE$1 + z2;
  78958. };
  78959. var parsePercent$3 = function (value, maxValue) {
  78960. if (typeof value === 'string') {
  78961. if (value.lastIndexOf('%') >= 0) {
  78962. return parseFloat(value) / 100 * maxValue;
  78963. }
  78964. return parseFloat(value);
  78965. }
  78966. return value;
  78967. };
  78968. /***************************************************
  78969. * PATH
  78970. **************************************************/
  78971. var setColorAndOpacity = function (el, color, opacity) {
  78972. var colorArr = parse(color);
  78973. opacity = +opacity;
  78974. if (isNaN(opacity)) {
  78975. opacity = 1;
  78976. }
  78977. if (colorArr) {
  78978. el.color = rgb2Str(colorArr[0], colorArr[1], colorArr[2]);
  78979. el.opacity = opacity * colorArr[3];
  78980. }
  78981. };
  78982. var getColorAndAlpha = function (color) {
  78983. var colorArr = parse(color);
  78984. return [
  78985. rgb2Str(colorArr[0], colorArr[1], colorArr[2]),
  78986. colorArr[3]
  78987. ];
  78988. };
  78989. var updateFillNode = function (el, style, zrEl) {
  78990. // TODO pattern
  78991. var fill = style.fill;
  78992. if (fill != null) {
  78993. // Modified from excanvas
  78994. if (fill instanceof Gradient) {
  78995. var gradientType;
  78996. var angle = 0;
  78997. var focus = [0, 0];
  78998. // additional offset
  78999. var shift = 0;
  79000. // scale factor for offset
  79001. var expansion = 1;
  79002. var rect = zrEl.getBoundingRect();
  79003. var rectWidth = rect.width;
  79004. var rectHeight = rect.height;
  79005. if (fill.type === 'linear') {
  79006. gradientType = 'gradient';
  79007. var transform = zrEl.transform;
  79008. var p0 = [fill.x * rectWidth, fill.y * rectHeight];
  79009. var p1 = [fill.x2 * rectWidth, fill.y2 * rectHeight];
  79010. if (transform) {
  79011. applyTransform(p0, p0, transform);
  79012. applyTransform(p1, p1, transform);
  79013. }
  79014. var dx = p1[0] - p0[0];
  79015. var dy = p1[1] - p0[1];
  79016. angle = Math.atan2(dx, dy) * 180 / Math.PI;
  79017. // The angle should be a non-negative number.
  79018. if (angle < 0) {
  79019. angle += 360;
  79020. }
  79021. // Very small angles produce an unexpected result because they are
  79022. // converted to a scientific notation string.
  79023. if (angle < 1e-6) {
  79024. angle = 0;
  79025. }
  79026. }
  79027. else {
  79028. gradientType = 'gradientradial';
  79029. var p0 = [fill.x * rectWidth, fill.y * rectHeight];
  79030. var transform = zrEl.transform;
  79031. var scale$$1 = zrEl.scale;
  79032. var width = rectWidth;
  79033. var height = rectHeight;
  79034. focus = [
  79035. // Percent in bounding rect
  79036. (p0[0] - rect.x) / width,
  79037. (p0[1] - rect.y) / height
  79038. ];
  79039. if (transform) {
  79040. applyTransform(p0, p0, transform);
  79041. }
  79042. width /= scale$$1[0] * Z;
  79043. height /= scale$$1[1] * Z;
  79044. var dimension = mathMax$8(width, height);
  79045. shift = 2 * 0 / dimension;
  79046. expansion = 2 * fill.r / dimension - shift;
  79047. }
  79048. // We need to sort the color stops in ascending order by offset,
  79049. // otherwise IE won't interpret it correctly.
  79050. var stops = fill.colorStops.slice();
  79051. stops.sort(function (cs1, cs2) {
  79052. return cs1.offset - cs2.offset;
  79053. });
  79054. var length$$1 = stops.length;
  79055. // Color and alpha list of first and last stop
  79056. var colorAndAlphaList = [];
  79057. var colors = [];
  79058. for (var i = 0; i < length$$1; i++) {
  79059. var stop = stops[i];
  79060. var colorAndAlpha = getColorAndAlpha(stop.color);
  79061. colors.push(stop.offset * expansion + shift + ' ' + colorAndAlpha[0]);
  79062. if (i === 0 || i === length$$1 - 1) {
  79063. colorAndAlphaList.push(colorAndAlpha);
  79064. }
  79065. }
  79066. if (length$$1 >= 2) {
  79067. var color1 = colorAndAlphaList[0][0];
  79068. var color2 = colorAndAlphaList[1][0];
  79069. var opacity1 = colorAndAlphaList[0][1] * style.opacity;
  79070. var opacity2 = colorAndAlphaList[1][1] * style.opacity;
  79071. el.type = gradientType;
  79072. el.method = 'none';
  79073. el.focus = '100%';
  79074. el.angle = angle;
  79075. el.color = color1;
  79076. el.color2 = color2;
  79077. el.colors = colors.join(',');
  79078. // When colors attribute is used, the meanings of opacity and o:opacity2
  79079. // are reversed.
  79080. el.opacity = opacity2;
  79081. // FIXME g_o_:opacity ?
  79082. el.opacity2 = opacity1;
  79083. }
  79084. if (gradientType === 'radial') {
  79085. el.focusposition = focus.join(',');
  79086. }
  79087. }
  79088. else {
  79089. // FIXME Change from Gradient fill to color fill
  79090. setColorAndOpacity(el, fill, style.opacity);
  79091. }
  79092. }
  79093. };
  79094. var updateStrokeNode = function (el, style) {
  79095. // if (style.lineJoin != null) {
  79096. // el.joinstyle = style.lineJoin;
  79097. // }
  79098. // if (style.miterLimit != null) {
  79099. // el.miterlimit = style.miterLimit * Z;
  79100. // }
  79101. // if (style.lineCap != null) {
  79102. // el.endcap = style.lineCap;
  79103. // }
  79104. if (style.lineDash) {
  79105. el.dashstyle = style.lineDash.join(' ');
  79106. }
  79107. if (style.stroke != null && !(style.stroke instanceof Gradient)) {
  79108. setColorAndOpacity(el, style.stroke, style.opacity);
  79109. }
  79110. };
  79111. var updateFillAndStroke = function (vmlEl, type, style, zrEl) {
  79112. var isFill = type === 'fill';
  79113. var el = vmlEl.getElementsByTagName(type)[0];
  79114. // Stroke must have lineWidth
  79115. if (style[type] != null && style[type] !== 'none' && (isFill || (!isFill && style.lineWidth))) {
  79116. vmlEl[isFill ? 'filled' : 'stroked'] = 'true';
  79117. // FIXME Remove before updating, or set `colors` will throw error
  79118. if (style[type] instanceof Gradient) {
  79119. remove(vmlEl, el);
  79120. }
  79121. if (!el) {
  79122. el = createNode(type);
  79123. }
  79124. isFill ? updateFillNode(el, style, zrEl) : updateStrokeNode(el, style);
  79125. append(vmlEl, el);
  79126. }
  79127. else {
  79128. vmlEl[isFill ? 'filled' : 'stroked'] = 'false';
  79129. remove(vmlEl, el);
  79130. }
  79131. };
  79132. var points$3 = [[], [], []];
  79133. var pathDataToString = function (path, m) {
  79134. var M = CMD$3.M;
  79135. var C = CMD$3.C;
  79136. var L = CMD$3.L;
  79137. var A = CMD$3.A;
  79138. var Q = CMD$3.Q;
  79139. var str = [];
  79140. var nPoint;
  79141. var cmdStr;
  79142. var cmd;
  79143. var i;
  79144. var xi;
  79145. var yi;
  79146. var data = path.data;
  79147. var dataLength = path.len();
  79148. for (i = 0; i < dataLength;) {
  79149. cmd = data[i++];
  79150. cmdStr = '';
  79151. nPoint = 0;
  79152. switch (cmd) {
  79153. case M:
  79154. cmdStr = ' m ';
  79155. nPoint = 1;
  79156. xi = data[i++];
  79157. yi = data[i++];
  79158. points$3[0][0] = xi;
  79159. points$3[0][1] = yi;
  79160. break;
  79161. case L:
  79162. cmdStr = ' l ';
  79163. nPoint = 1;
  79164. xi = data[i++];
  79165. yi = data[i++];
  79166. points$3[0][0] = xi;
  79167. points$3[0][1] = yi;
  79168. break;
  79169. case Q:
  79170. case C:
  79171. cmdStr = ' c ';
  79172. nPoint = 3;
  79173. var x1 = data[i++];
  79174. var y1 = data[i++];
  79175. var x2 = data[i++];
  79176. var y2 = data[i++];
  79177. var x3;
  79178. var y3;
  79179. if (cmd === Q) {
  79180. // Convert quadratic to cubic using degree elevation
  79181. x3 = x2;
  79182. y3 = y2;
  79183. x2 = (x2 + 2 * x1) / 3;
  79184. y2 = (y2 + 2 * y1) / 3;
  79185. x1 = (xi + 2 * x1) / 3;
  79186. y1 = (yi + 2 * y1) / 3;
  79187. }
  79188. else {
  79189. x3 = data[i++];
  79190. y3 = data[i++];
  79191. }
  79192. points$3[0][0] = x1;
  79193. points$3[0][1] = y1;
  79194. points$3[1][0] = x2;
  79195. points$3[1][1] = y2;
  79196. points$3[2][0] = x3;
  79197. points$3[2][1] = y3;
  79198. xi = x3;
  79199. yi = y3;
  79200. break;
  79201. case A:
  79202. var x = 0;
  79203. var y = 0;
  79204. var sx = 1;
  79205. var sy = 1;
  79206. var angle = 0;
  79207. if (m) {
  79208. // Extract SRT from matrix
  79209. x = m[4];
  79210. y = m[5];
  79211. sx = sqrt(m[0] * m[0] + m[1] * m[1]);
  79212. sy = sqrt(m[2] * m[2] + m[3] * m[3]);
  79213. angle = Math.atan2(-m[1] / sy, m[0] / sx);
  79214. }
  79215. var cx = data[i++];
  79216. var cy = data[i++];
  79217. var rx = data[i++];
  79218. var ry = data[i++];
  79219. var startAngle = data[i++] + angle;
  79220. var endAngle = data[i++] + startAngle + angle;
  79221. // FIXME
  79222. // var psi = data[i++];
  79223. i++;
  79224. var clockwise = data[i++];
  79225. var x0 = cx + cos(startAngle) * rx;
  79226. var y0 = cy + sin(startAngle) * ry;
  79227. var x1 = cx + cos(endAngle) * rx;
  79228. var y1 = cy + sin(endAngle) * ry;
  79229. var type = clockwise ? ' wa ' : ' at ';
  79230. if (Math.abs(x0 - x1) < 1e-4) {
  79231. // IE won't render arches drawn counter clockwise if x0 == x1.
  79232. if (Math.abs(endAngle - startAngle) > 1e-2) {
  79233. // Offset x0 by 1/80 of a pixel. Use something
  79234. // that can be represented in binary
  79235. if (clockwise) {
  79236. x0 += 270 / Z;
  79237. }
  79238. }
  79239. else {
  79240. // Avoid case draw full circle
  79241. if (Math.abs(y0 - cy) < 1e-4) {
  79242. if ((clockwise && x0 < cx) || (!clockwise && x0 > cx)) {
  79243. y1 -= 270 / Z;
  79244. }
  79245. else {
  79246. y1 += 270 / Z;
  79247. }
  79248. }
  79249. else if ((clockwise && y0 < cy) || (!clockwise && y0 > cy)) {
  79250. x1 += 270 / Z;
  79251. }
  79252. else {
  79253. x1 -= 270 / Z;
  79254. }
  79255. }
  79256. }
  79257. str.push(
  79258. type,
  79259. round$3(((cx - rx) * sx + x) * Z - Z2), comma,
  79260. round$3(((cy - ry) * sy + y) * Z - Z2), comma,
  79261. round$3(((cx + rx) * sx + x) * Z - Z2), comma,
  79262. round$3(((cy + ry) * sy + y) * Z - Z2), comma,
  79263. round$3((x0 * sx + x) * Z - Z2), comma,
  79264. round$3((y0 * sy + y) * Z - Z2), comma,
  79265. round$3((x1 * sx + x) * Z - Z2), comma,
  79266. round$3((y1 * sy + y) * Z - Z2)
  79267. );
  79268. xi = x1;
  79269. yi = y1;
  79270. break;
  79271. case CMD$3.R:
  79272. var p0 = points$3[0];
  79273. var p1 = points$3[1];
  79274. // x0, y0
  79275. p0[0] = data[i++];
  79276. p0[1] = data[i++];
  79277. // x1, y1
  79278. p1[0] = p0[0] + data[i++];
  79279. p1[1] = p0[1] + data[i++];
  79280. if (m) {
  79281. applyTransform(p0, p0, m);
  79282. applyTransform(p1, p1, m);
  79283. }
  79284. p0[0] = round$3(p0[0] * Z - Z2);
  79285. p1[0] = round$3(p1[0] * Z - Z2);
  79286. p0[1] = round$3(p0[1] * Z - Z2);
  79287. p1[1] = round$3(p1[1] * Z - Z2);
  79288. str.push(
  79289. // x0, y0
  79290. ' m ', p0[0], comma, p0[1],
  79291. // x1, y0
  79292. ' l ', p1[0], comma, p0[1],
  79293. // x1, y1
  79294. ' l ', p1[0], comma, p1[1],
  79295. // x0, y1
  79296. ' l ', p0[0], comma, p1[1]
  79297. );
  79298. break;
  79299. case CMD$3.Z:
  79300. // FIXME Update xi, yi
  79301. str.push(' x ');
  79302. }
  79303. if (nPoint > 0) {
  79304. str.push(cmdStr);
  79305. for (var k = 0; k < nPoint; k++) {
  79306. var p = points$3[k];
  79307. m && applyTransform(p, p, m);
  79308. // 不 round 会非常慢
  79309. str.push(
  79310. round$3(p[0] * Z - Z2), comma, round$3(p[1] * Z - Z2),
  79311. k < nPoint - 1 ? comma : ''
  79312. );
  79313. }
  79314. }
  79315. }
  79316. return str.join('');
  79317. };
  79318. // Rewrite the original path method
  79319. Path.prototype.brushVML = function (vmlRoot) {
  79320. var style = this.style;
  79321. var vmlEl = this._vmlEl;
  79322. if (!vmlEl) {
  79323. vmlEl = createNode('shape');
  79324. initRootElStyle(vmlEl);
  79325. this._vmlEl = vmlEl;
  79326. }
  79327. updateFillAndStroke(vmlEl, 'fill', style, this);
  79328. updateFillAndStroke(vmlEl, 'stroke', style, this);
  79329. var m = this.transform;
  79330. var needTransform = m != null;
  79331. var strokeEl = vmlEl.getElementsByTagName('stroke')[0];
  79332. if (strokeEl) {
  79333. var lineWidth = style.lineWidth;
  79334. // Get the line scale.
  79335. // Determinant of this.m_ means how much the area is enlarged by the
  79336. // transformation. So its square root can be used as a scale factor
  79337. // for width.
  79338. if (needTransform && !style.strokeNoScale) {
  79339. var det = m[0] * m[3] - m[1] * m[2];
  79340. lineWidth *= sqrt(abs$1(det));
  79341. }
  79342. strokeEl.weight = lineWidth + 'px';
  79343. }
  79344. var path = this.path || (this.path = new PathProxy());
  79345. if (this.__dirtyPath) {
  79346. path.beginPath();
  79347. path.subPixelOptimize = false;
  79348. this.buildPath(path, this.shape);
  79349. path.toStatic();
  79350. this.__dirtyPath = false;
  79351. }
  79352. vmlEl.path = pathDataToString(path, this.transform);
  79353. vmlEl.style.zIndex = getZIndex(this.zlevel, this.z, this.z2);
  79354. // Append to root
  79355. append(vmlRoot, vmlEl);
  79356. // Text
  79357. if (style.text != null) {
  79358. this.drawRectText(vmlRoot, this.getBoundingRect());
  79359. }
  79360. else {
  79361. this.removeRectText(vmlRoot);
  79362. }
  79363. };
  79364. Path.prototype.onRemove = function (vmlRoot) {
  79365. remove(vmlRoot, this._vmlEl);
  79366. this.removeRectText(vmlRoot);
  79367. };
  79368. Path.prototype.onAdd = function (vmlRoot) {
  79369. append(vmlRoot, this._vmlEl);
  79370. this.appendRectText(vmlRoot);
  79371. };
  79372. /***************************************************
  79373. * IMAGE
  79374. **************************************************/
  79375. var isImage = function (img) {
  79376. // FIXME img instanceof Image 如果 img 是一个字符串的时候,IE8 下会报错
  79377. return (typeof img === 'object') && img.tagName && img.tagName.toUpperCase() === 'IMG';
  79378. // return img instanceof Image;
  79379. };
  79380. // Rewrite the original path method
  79381. ZImage.prototype.brushVML = function (vmlRoot) {
  79382. var style = this.style;
  79383. var image = style.image;
  79384. // Image original width, height
  79385. var ow;
  79386. var oh;
  79387. if (isImage(image)) {
  79388. var src = image.src;
  79389. if (src === this._imageSrc) {
  79390. ow = this._imageWidth;
  79391. oh = this._imageHeight;
  79392. }
  79393. else {
  79394. var imageRuntimeStyle = image.runtimeStyle;
  79395. var oldRuntimeWidth = imageRuntimeStyle.width;
  79396. var oldRuntimeHeight = imageRuntimeStyle.height;
  79397. imageRuntimeStyle.width = 'auto';
  79398. imageRuntimeStyle.height = 'auto';
  79399. // get the original size
  79400. ow = image.width;
  79401. oh = image.height;
  79402. // and remove overides
  79403. imageRuntimeStyle.width = oldRuntimeWidth;
  79404. imageRuntimeStyle.height = oldRuntimeHeight;
  79405. // Caching image original width, height and src
  79406. this._imageSrc = src;
  79407. this._imageWidth = ow;
  79408. this._imageHeight = oh;
  79409. }
  79410. image = src;
  79411. }
  79412. else {
  79413. if (image === this._imageSrc) {
  79414. ow = this._imageWidth;
  79415. oh = this._imageHeight;
  79416. }
  79417. }
  79418. if (!image) {
  79419. return;
  79420. }
  79421. var x = style.x || 0;
  79422. var y = style.y || 0;
  79423. var dw = style.width;
  79424. var dh = style.height;
  79425. var sw = style.sWidth;
  79426. var sh = style.sHeight;
  79427. var sx = style.sx || 0;
  79428. var sy = style.sy || 0;
  79429. var hasCrop = sw && sh;
  79430. var vmlEl = this._vmlEl;
  79431. if (!vmlEl) {
  79432. // FIXME 使用 group 在 left, top 都不是 0 的时候就无法显示了。
  79433. // vmlEl = vmlCore.createNode('group');
  79434. vmlEl = doc.createElement('div');
  79435. initRootElStyle(vmlEl);
  79436. this._vmlEl = vmlEl;
  79437. }
  79438. var vmlElStyle = vmlEl.style;
  79439. var hasRotation = false;
  79440. var m;
  79441. var scaleX = 1;
  79442. var scaleY = 1;
  79443. if (this.transform) {
  79444. m = this.transform;
  79445. scaleX = sqrt(m[0] * m[0] + m[1] * m[1]);
  79446. scaleY = sqrt(m[2] * m[2] + m[3] * m[3]);
  79447. hasRotation = m[1] || m[2];
  79448. }
  79449. if (hasRotation) {
  79450. // If filters are necessary (rotation exists), create them
  79451. // filters are bog-slow, so only create them if abbsolutely necessary
  79452. // The following check doesn't account for skews (which don't exist
  79453. // in the canvas spec (yet) anyway.
  79454. // From excanvas
  79455. var p0 = [x, y];
  79456. var p1 = [x + dw, y];
  79457. var p2 = [x, y + dh];
  79458. var p3 = [x + dw, y + dh];
  79459. applyTransform(p0, p0, m);
  79460. applyTransform(p1, p1, m);
  79461. applyTransform(p2, p2, m);
  79462. applyTransform(p3, p3, m);
  79463. var maxX = mathMax$8(p0[0], p1[0], p2[0], p3[0]);
  79464. var maxY = mathMax$8(p0[1], p1[1], p2[1], p3[1]);
  79465. var transformFilter = [];
  79466. transformFilter.push('M11=', m[0] / scaleX, comma,
  79467. 'M12=', m[2] / scaleY, comma,
  79468. 'M21=', m[1] / scaleX, comma,
  79469. 'M22=', m[3] / scaleY, comma,
  79470. 'Dx=', round$3(x * scaleX + m[4]), comma,
  79471. 'Dy=', round$3(y * scaleY + m[5]));
  79472. vmlElStyle.padding = '0 ' + round$3(maxX) + 'px ' + round$3(maxY) + 'px 0';
  79473. // FIXME DXImageTransform 在 IE11 的兼容模式下不起作用
  79474. vmlElStyle.filter = imageTransformPrefix + '.Matrix('
  79475. + transformFilter.join('') + ', SizingMethod=clip)';
  79476. }
  79477. else {
  79478. if (m) {
  79479. x = x * scaleX + m[4];
  79480. y = y * scaleY + m[5];
  79481. }
  79482. vmlElStyle.filter = '';
  79483. vmlElStyle.left = round$3(x) + 'px';
  79484. vmlElStyle.top = round$3(y) + 'px';
  79485. }
  79486. var imageEl = this._imageEl;
  79487. var cropEl = this._cropEl;
  79488. if (!imageEl) {
  79489. imageEl = doc.createElement('div');
  79490. this._imageEl = imageEl;
  79491. }
  79492. var imageELStyle = imageEl.style;
  79493. if (hasCrop) {
  79494. // Needs know image original width and height
  79495. if (!(ow && oh)) {
  79496. var tmpImage = new Image();
  79497. var self = this;
  79498. tmpImage.onload = function () {
  79499. tmpImage.onload = null;
  79500. ow = tmpImage.width;
  79501. oh = tmpImage.height;
  79502. // Adjust image width and height to fit the ratio destinationSize / sourceSize
  79503. imageELStyle.width = round$3(scaleX * ow * dw / sw) + 'px';
  79504. imageELStyle.height = round$3(scaleY * oh * dh / sh) + 'px';
  79505. // Caching image original width, height and src
  79506. self._imageWidth = ow;
  79507. self._imageHeight = oh;
  79508. self._imageSrc = image;
  79509. };
  79510. tmpImage.src = image;
  79511. }
  79512. else {
  79513. imageELStyle.width = round$3(scaleX * ow * dw / sw) + 'px';
  79514. imageELStyle.height = round$3(scaleY * oh * dh / sh) + 'px';
  79515. }
  79516. if (!cropEl) {
  79517. cropEl = doc.createElement('div');
  79518. cropEl.style.overflow = 'hidden';
  79519. this._cropEl = cropEl;
  79520. }
  79521. var cropElStyle = cropEl.style;
  79522. cropElStyle.width = round$3((dw + sx * dw / sw) * scaleX);
  79523. cropElStyle.height = round$3((dh + sy * dh / sh) * scaleY);
  79524. cropElStyle.filter = imageTransformPrefix + '.Matrix(Dx='
  79525. + (-sx * dw / sw * scaleX) + ',Dy=' + (-sy * dh / sh * scaleY) + ')';
  79526. if (!cropEl.parentNode) {
  79527. vmlEl.appendChild(cropEl);
  79528. }
  79529. if (imageEl.parentNode !== cropEl) {
  79530. cropEl.appendChild(imageEl);
  79531. }
  79532. }
  79533. else {
  79534. imageELStyle.width = round$3(scaleX * dw) + 'px';
  79535. imageELStyle.height = round$3(scaleY * dh) + 'px';
  79536. vmlEl.appendChild(imageEl);
  79537. if (cropEl && cropEl.parentNode) {
  79538. vmlEl.removeChild(cropEl);
  79539. this._cropEl = null;
  79540. }
  79541. }
  79542. var filterStr = '';
  79543. var alpha = style.opacity;
  79544. if (alpha < 1) {
  79545. filterStr += '.Alpha(opacity=' + round$3(alpha * 100) + ') ';
  79546. }
  79547. filterStr += imageTransformPrefix + '.AlphaImageLoader(src=' + image + ', SizingMethod=scale)';
  79548. imageELStyle.filter = filterStr;
  79549. vmlEl.style.zIndex = getZIndex(this.zlevel, this.z, this.z2);
  79550. // Append to root
  79551. append(vmlRoot, vmlEl);
  79552. // Text
  79553. if (style.text != null) {
  79554. this.drawRectText(vmlRoot, this.getBoundingRect());
  79555. }
  79556. };
  79557. ZImage.prototype.onRemove = function (vmlRoot) {
  79558. remove(vmlRoot, this._vmlEl);
  79559. this._vmlEl = null;
  79560. this._cropEl = null;
  79561. this._imageEl = null;
  79562. this.removeRectText(vmlRoot);
  79563. };
  79564. ZImage.prototype.onAdd = function (vmlRoot) {
  79565. append(vmlRoot, this._vmlEl);
  79566. this.appendRectText(vmlRoot);
  79567. };
  79568. /***************************************************
  79569. * TEXT
  79570. **************************************************/
  79571. var DEFAULT_STYLE_NORMAL = 'normal';
  79572. var fontStyleCache = {};
  79573. var fontStyleCacheCount = 0;
  79574. var MAX_FONT_CACHE_SIZE = 100;
  79575. var fontEl = document.createElement('div');
  79576. var getFontStyle = function (fontString) {
  79577. var fontStyle = fontStyleCache[fontString];
  79578. if (!fontStyle) {
  79579. // Clear cache
  79580. if (fontStyleCacheCount > MAX_FONT_CACHE_SIZE) {
  79581. fontStyleCacheCount = 0;
  79582. fontStyleCache = {};
  79583. }
  79584. var style = fontEl.style;
  79585. var fontFamily;
  79586. try {
  79587. style.font = fontString;
  79588. fontFamily = style.fontFamily.split(',')[0];
  79589. }
  79590. catch (e) {
  79591. }
  79592. fontStyle = {
  79593. style: style.fontStyle || DEFAULT_STYLE_NORMAL,
  79594. variant: style.fontVariant || DEFAULT_STYLE_NORMAL,
  79595. weight: style.fontWeight || DEFAULT_STYLE_NORMAL,
  79596. size: parseFloat(style.fontSize || 12) | 0,
  79597. family: fontFamily || 'Microsoft YaHei'
  79598. };
  79599. fontStyleCache[fontString] = fontStyle;
  79600. fontStyleCacheCount++;
  79601. }
  79602. return fontStyle;
  79603. };
  79604. var textMeasureEl;
  79605. // Overwrite measure text method
  79606. $override$1('measureText', function (text, textFont) {
  79607. var doc$$1 = doc;
  79608. if (!textMeasureEl) {
  79609. textMeasureEl = doc$$1.createElement('div');
  79610. textMeasureEl.style.cssText = 'position:absolute;top:-20000px;left:0;'
  79611. + 'padding:0;margin:0;border:none;white-space:pre;';
  79612. doc.body.appendChild(textMeasureEl);
  79613. }
  79614. try {
  79615. textMeasureEl.style.font = textFont;
  79616. }
  79617. catch (ex) {
  79618. // Ignore failures to set to invalid font.
  79619. }
  79620. textMeasureEl.innerHTML = '';
  79621. // Don't use innerHTML or innerText because they allow markup/whitespace.
  79622. textMeasureEl.appendChild(doc$$1.createTextNode(text));
  79623. return {
  79624. width: textMeasureEl.offsetWidth
  79625. };
  79626. });
  79627. var tmpRect$2 = new BoundingRect();
  79628. var drawRectText = function (vmlRoot, rect, textRect, fromTextEl) {
  79629. var style = this.style;
  79630. // Optimize, avoid normalize every time.
  79631. this.__dirty && normalizeTextStyle(style, true);
  79632. var text = style.text;
  79633. // Convert to string
  79634. text != null && (text += '');
  79635. if (!text) {
  79636. return;
  79637. }
  79638. // Convert rich text to plain text. Rich text is not supported in
  79639. // IE8-, but tags in rich text template will be removed.
  79640. if (style.rich) {
  79641. var contentBlock = parseRichText(text, style);
  79642. text = [];
  79643. for (var i = 0; i < contentBlock.lines.length; i++) {
  79644. var tokens = contentBlock.lines[i].tokens;
  79645. var textLine = [];
  79646. for (var j = 0; j < tokens.length; j++) {
  79647. textLine.push(tokens[j].text);
  79648. }
  79649. text.push(textLine.join(''));
  79650. }
  79651. text = text.join('\n');
  79652. }
  79653. var x;
  79654. var y;
  79655. var align = style.textAlign;
  79656. var verticalAlign = style.textVerticalAlign;
  79657. var fontStyle = getFontStyle(style.font);
  79658. // FIXME encodeHtmlAttribute ?
  79659. var font = fontStyle.style + ' ' + fontStyle.variant + ' ' + fontStyle.weight + ' '
  79660. + fontStyle.size + 'px "' + fontStyle.family + '"';
  79661. textRect = textRect || getBoundingRect(
  79662. text, font, align, verticalAlign, style.textPadding, style.textLineHeight
  79663. );
  79664. // Transform rect to view space
  79665. var m = this.transform;
  79666. // Ignore transform for text in other element
  79667. if (m && !fromTextEl) {
  79668. tmpRect$2.copy(rect);
  79669. tmpRect$2.applyTransform(m);
  79670. rect = tmpRect$2;
  79671. }
  79672. if (!fromTextEl) {
  79673. var textPosition = style.textPosition;
  79674. // Text position represented by coord
  79675. if (textPosition instanceof Array) {
  79676. x = rect.x + parsePercent$3(textPosition[0], rect.width);
  79677. y = rect.y + parsePercent$3(textPosition[1], rect.height);
  79678. align = align || 'left';
  79679. }
  79680. else {
  79681. var res = this.calculateTextPosition
  79682. ? this.calculateTextPosition({}, style, rect)
  79683. : calculateTextPosition({}, style, rect);
  79684. x = res.x;
  79685. y = res.y;
  79686. // Default align and baseline when has textPosition
  79687. align = align || res.textAlign;
  79688. verticalAlign = verticalAlign || res.textVerticalAlign;
  79689. }
  79690. }
  79691. else {
  79692. x = rect.x;
  79693. y = rect.y;
  79694. }
  79695. x = adjustTextX(x, textRect.width, align);
  79696. y = adjustTextY(y, textRect.height, verticalAlign);
  79697. // Force baseline 'middle'
  79698. y += textRect.height / 2;
  79699. // var fontSize = fontStyle.size;
  79700. // 1.75 is an arbitrary number, as there is no info about the text baseline
  79701. // switch (baseline) {
  79702. // case 'hanging':
  79703. // case 'top':
  79704. // y += fontSize / 1.75;
  79705. // break;
  79706. // case 'middle':
  79707. // break;
  79708. // default:
  79709. // // case null:
  79710. // // case 'alphabetic':
  79711. // // case 'ideographic':
  79712. // // case 'bottom':
  79713. // y -= fontSize / 2.25;
  79714. // break;
  79715. // }
  79716. // switch (align) {
  79717. // case 'left':
  79718. // break;
  79719. // case 'center':
  79720. // x -= textRect.width / 2;
  79721. // break;
  79722. // case 'right':
  79723. // x -= textRect.width;
  79724. // break;
  79725. // case 'end':
  79726. // align = elementStyle.direction == 'ltr' ? 'right' : 'left';
  79727. // break;
  79728. // case 'start':
  79729. // align = elementStyle.direction == 'rtl' ? 'right' : 'left';
  79730. // break;
  79731. // default:
  79732. // align = 'left';
  79733. // }
  79734. var createNode$$1 = createNode;
  79735. var textVmlEl = this._textVmlEl;
  79736. var pathEl;
  79737. var textPathEl;
  79738. var skewEl;
  79739. if (!textVmlEl) {
  79740. textVmlEl = createNode$$1('line');
  79741. pathEl = createNode$$1('path');
  79742. textPathEl = createNode$$1('textpath');
  79743. skewEl = createNode$$1('skew');
  79744. // FIXME Why here is not cammel case
  79745. // Align 'center' seems wrong
  79746. textPathEl.style['v-text-align'] = 'left';
  79747. initRootElStyle(textVmlEl);
  79748. pathEl.textpathok = true;
  79749. textPathEl.on = true;
  79750. textVmlEl.from = '0 0';
  79751. textVmlEl.to = '1000 0.05';
  79752. append(textVmlEl, skewEl);
  79753. append(textVmlEl, pathEl);
  79754. append(textVmlEl, textPathEl);
  79755. this._textVmlEl = textVmlEl;
  79756. }
  79757. else {
  79758. // 这里是在前面 appendChild 保证顺序的前提下
  79759. skewEl = textVmlEl.firstChild;
  79760. pathEl = skewEl.nextSibling;
  79761. textPathEl = pathEl.nextSibling;
  79762. }
  79763. var coords = [x, y];
  79764. var textVmlElStyle = textVmlEl.style;
  79765. // Ignore transform for text in other element
  79766. if (m && fromTextEl) {
  79767. applyTransform(coords, coords, m);
  79768. skewEl.on = true;
  79769. skewEl.matrix = m[0].toFixed(3) + comma + m[2].toFixed(3) + comma
  79770. + m[1].toFixed(3) + comma + m[3].toFixed(3) + ',0,0';
  79771. // Text position
  79772. skewEl.offset = (round$3(coords[0]) || 0) + ',' + (round$3(coords[1]) || 0);
  79773. // Left top point as origin
  79774. skewEl.origin = '0 0';
  79775. textVmlElStyle.left = '0px';
  79776. textVmlElStyle.top = '0px';
  79777. }
  79778. else {
  79779. skewEl.on = false;
  79780. textVmlElStyle.left = round$3(x) + 'px';
  79781. textVmlElStyle.top = round$3(y) + 'px';
  79782. }
  79783. textPathEl.string = encodeHtmlAttribute(text);
  79784. // TODO
  79785. try {
  79786. textPathEl.style.font = font;
  79787. }
  79788. // Error font format
  79789. catch (e) {}
  79790. updateFillAndStroke(textVmlEl, 'fill', {
  79791. fill: style.textFill,
  79792. opacity: style.opacity
  79793. }, this);
  79794. updateFillAndStroke(textVmlEl, 'stroke', {
  79795. stroke: style.textStroke,
  79796. opacity: style.opacity,
  79797. lineDash: style.lineDash || null // style.lineDash can be `false`.
  79798. }, this);
  79799. textVmlEl.style.zIndex = getZIndex(this.zlevel, this.z, this.z2);
  79800. // Attached to root
  79801. append(vmlRoot, textVmlEl);
  79802. };
  79803. var removeRectText = function (vmlRoot) {
  79804. remove(vmlRoot, this._textVmlEl);
  79805. this._textVmlEl = null;
  79806. };
  79807. var appendRectText = function (vmlRoot) {
  79808. append(vmlRoot, this._textVmlEl);
  79809. };
  79810. var list = [RectText, Displayable, ZImage, Path, Text];
  79811. // In case Displayable has been mixed in RectText
  79812. for (var i$3 = 0; i$3 < list.length; i$3++) {
  79813. var proto$8 = list[i$3].prototype;
  79814. proto$8.drawRectText = drawRectText;
  79815. proto$8.removeRectText = removeRectText;
  79816. proto$8.appendRectText = appendRectText;
  79817. }
  79818. Text.prototype.brushVML = function (vmlRoot) {
  79819. var style = this.style;
  79820. if (style.text != null) {
  79821. this.drawRectText(vmlRoot, {
  79822. x: style.x || 0, y: style.y || 0,
  79823. width: 0, height: 0
  79824. }, this.getBoundingRect(), true);
  79825. }
  79826. else {
  79827. this.removeRectText(vmlRoot);
  79828. }
  79829. };
  79830. Text.prototype.onRemove = function (vmlRoot) {
  79831. this.removeRectText(vmlRoot);
  79832. };
  79833. Text.prototype.onAdd = function (vmlRoot) {
  79834. this.appendRectText(vmlRoot);
  79835. };
  79836. }
  79837. /**
  79838. * VML Painter.
  79839. *
  79840. * @module zrender/vml/Painter
  79841. */
  79842. function parseInt10$1(val) {
  79843. return parseInt(val, 10);
  79844. }
  79845. /**
  79846. * @alias module:zrender/vml/Painter
  79847. */
  79848. function VMLPainter(root, storage) {
  79849. initVML();
  79850. this.root = root;
  79851. this.storage = storage;
  79852. var vmlViewport = document.createElement('div');
  79853. var vmlRoot = document.createElement('div');
  79854. vmlViewport.style.cssText = 'display:inline-block;overflow:hidden;position:relative;width:300px;height:150px;';
  79855. vmlRoot.style.cssText = 'position:absolute;left:0;top:0;';
  79856. root.appendChild(vmlViewport);
  79857. this._vmlRoot = vmlRoot;
  79858. this._vmlViewport = vmlViewport;
  79859. this.resize();
  79860. // Modify storage
  79861. var oldDelFromStorage = storage.delFromStorage;
  79862. var oldAddToStorage = storage.addToStorage;
  79863. storage.delFromStorage = function (el) {
  79864. oldDelFromStorage.call(storage, el);
  79865. if (el) {
  79866. el.onRemove && el.onRemove(vmlRoot);
  79867. }
  79868. };
  79869. storage.addToStorage = function (el) {
  79870. // Displayable already has a vml node
  79871. el.onAdd && el.onAdd(vmlRoot);
  79872. oldAddToStorage.call(storage, el);
  79873. };
  79874. this._firstPaint = true;
  79875. }
  79876. VMLPainter.prototype = {
  79877. constructor: VMLPainter,
  79878. getType: function () {
  79879. return 'vml';
  79880. },
  79881. /**
  79882. * @return {HTMLDivElement}
  79883. */
  79884. getViewportRoot: function () {
  79885. return this._vmlViewport;
  79886. },
  79887. getViewportRootOffset: function () {
  79888. var viewportRoot = this.getViewportRoot();
  79889. if (viewportRoot) {
  79890. return {
  79891. offsetLeft: viewportRoot.offsetLeft || 0,
  79892. offsetTop: viewportRoot.offsetTop || 0
  79893. };
  79894. }
  79895. },
  79896. /**
  79897. * 刷新
  79898. */
  79899. refresh: function () {
  79900. var list = this.storage.getDisplayList(true, true);
  79901. this._paintList(list);
  79902. },
  79903. _paintList: function (list) {
  79904. var vmlRoot = this._vmlRoot;
  79905. for (var i = 0; i < list.length; i++) {
  79906. var el = list[i];
  79907. if (el.invisible || el.ignore) {
  79908. if (!el.__alreadyNotVisible) {
  79909. el.onRemove(vmlRoot);
  79910. }
  79911. // Set as already invisible
  79912. el.__alreadyNotVisible = true;
  79913. }
  79914. else {
  79915. if (el.__alreadyNotVisible) {
  79916. el.onAdd(vmlRoot);
  79917. }
  79918. el.__alreadyNotVisible = false;
  79919. if (el.__dirty) {
  79920. el.beforeBrush && el.beforeBrush();
  79921. (el.brushVML || el.brush).call(el, vmlRoot);
  79922. el.afterBrush && el.afterBrush();
  79923. }
  79924. }
  79925. el.__dirty = false;
  79926. }
  79927. if (this._firstPaint) {
  79928. // Detached from document at first time
  79929. // to avoid page refreshing too many times
  79930. // FIXME 如果每次都先 removeChild 可能会导致一些填充和描边的效果改变
  79931. this._vmlViewport.appendChild(vmlRoot);
  79932. this._firstPaint = false;
  79933. }
  79934. },
  79935. resize: function (width, height) {
  79936. var width = width == null ? this._getWidth() : width;
  79937. var height = height == null ? this._getHeight() : height;
  79938. if (this._width !== width || this._height !== height) {
  79939. this._width = width;
  79940. this._height = height;
  79941. var vmlViewportStyle = this._vmlViewport.style;
  79942. vmlViewportStyle.width = width + 'px';
  79943. vmlViewportStyle.height = height + 'px';
  79944. }
  79945. },
  79946. dispose: function () {
  79947. this.root.innerHTML = '';
  79948. this._vmlRoot =
  79949. this._vmlViewport =
  79950. this.storage = null;
  79951. },
  79952. getWidth: function () {
  79953. return this._width;
  79954. },
  79955. getHeight: function () {
  79956. return this._height;
  79957. },
  79958. clear: function () {
  79959. if (this._vmlViewport) {
  79960. this.root.removeChild(this._vmlViewport);
  79961. }
  79962. },
  79963. _getWidth: function () {
  79964. var root = this.root;
  79965. var stl = root.currentStyle;
  79966. return ((root.clientWidth || parseInt10$1(stl.width))
  79967. - parseInt10$1(stl.paddingLeft)
  79968. - parseInt10$1(stl.paddingRight)) | 0;
  79969. },
  79970. _getHeight: function () {
  79971. var root = this.root;
  79972. var stl = root.currentStyle;
  79973. return ((root.clientHeight || parseInt10$1(stl.height))
  79974. - parseInt10$1(stl.paddingTop)
  79975. - parseInt10$1(stl.paddingBottom)) | 0;
  79976. }
  79977. };
  79978. // Not supported methods
  79979. function createMethodNotSupport(method) {
  79980. return function () {
  79981. zrLog('In IE8.0 VML mode painter not support method "' + method + '"');
  79982. };
  79983. }
  79984. // Unsupported methods
  79985. each$1([
  79986. 'getLayer', 'insertLayer', 'eachLayer', 'eachBuiltinLayer', 'eachOtherLayer', 'getLayers',
  79987. 'modLayer', 'delLayer', 'clearLayer', 'toDataURL', 'pathToImage'
  79988. ], function (name) {
  79989. VMLPainter.prototype[name] = createMethodNotSupport(name);
  79990. });
  79991. registerPainter('vml', VMLPainter);
  79992. var svgURI = 'http://www.w3.org/2000/svg';
  79993. function createElement(name) {
  79994. return document.createElementNS(svgURI, name);
  79995. }
  79996. // TODO
  79997. // 1. shadow
  79998. // 2. Image: sx, sy, sw, sh
  79999. var CMD$4 = PathProxy.CMD;
  80000. var arrayJoin = Array.prototype.join;
  80001. var NONE = 'none';
  80002. var mathRound = Math.round;
  80003. var mathSin$3 = Math.sin;
  80004. var mathCos$3 = Math.cos;
  80005. var PI$6 = Math.PI;
  80006. var PI2$7 = Math.PI * 2;
  80007. var degree = 180 / PI$6;
  80008. var EPSILON$4 = 1e-4;
  80009. function round4(val) {
  80010. return mathRound(val * 1e4) / 1e4;
  80011. }
  80012. function isAroundZero$1(val) {
  80013. return val < EPSILON$4 && val > -EPSILON$4;
  80014. }
  80015. function pathHasFill(style, isText) {
  80016. var fill = isText ? style.textFill : style.fill;
  80017. return fill != null && fill !== NONE;
  80018. }
  80019. function pathHasStroke(style, isText) {
  80020. var stroke = isText ? style.textStroke : style.stroke;
  80021. return stroke != null && stroke !== NONE;
  80022. }
  80023. function setTransform(svgEl, m) {
  80024. if (m) {
  80025. attr(svgEl, 'transform', 'matrix(' + arrayJoin.call(m, ',') + ')');
  80026. }
  80027. }
  80028. function attr(el, key, val) {
  80029. if (!val || val.type !== 'linear' && val.type !== 'radial') {
  80030. // Don't set attribute for gradient, since it need new dom nodes
  80031. el.setAttribute(key, val);
  80032. }
  80033. }
  80034. function attrXLink(el, key, val) {
  80035. el.setAttributeNS('http://www.w3.org/1999/xlink', key, val);
  80036. }
  80037. function bindStyle(svgEl, style, isText, el) {
  80038. if (pathHasFill(style, isText)) {
  80039. var fill = isText ? style.textFill : style.fill;
  80040. fill = fill === 'transparent' ? NONE : fill;
  80041. attr(svgEl, 'fill', fill);
  80042. attr(svgEl, 'fill-opacity', style.fillOpacity != null ? style.fillOpacity * style.opacity : style.opacity);
  80043. }
  80044. else {
  80045. attr(svgEl, 'fill', NONE);
  80046. }
  80047. if (pathHasStroke(style, isText)) {
  80048. var stroke = isText ? style.textStroke : style.stroke;
  80049. stroke = stroke === 'transparent' ? NONE : stroke;
  80050. attr(svgEl, 'stroke', stroke);
  80051. var strokeWidth = isText
  80052. ? style.textStrokeWidth
  80053. : style.lineWidth;
  80054. var strokeScale = !isText && style.strokeNoScale
  80055. ? el.getLineScale()
  80056. : 1;
  80057. attr(svgEl, 'stroke-width', strokeWidth / strokeScale);
  80058. // stroke then fill for text; fill then stroke for others
  80059. attr(svgEl, 'paint-order', isText ? 'stroke' : 'fill');
  80060. attr(svgEl, 'stroke-opacity', style.strokeOpacity != null ? style.strokeOpacity : style.opacity);
  80061. var lineDash = style.lineDash;
  80062. if (lineDash) {
  80063. attr(svgEl, 'stroke-dasharray', style.lineDash.join(','));
  80064. attr(svgEl, 'stroke-dashoffset', mathRound(style.lineDashOffset || 0));
  80065. }
  80066. else {
  80067. attr(svgEl, 'stroke-dasharray', '');
  80068. }
  80069. // PENDING
  80070. style.lineCap && attr(svgEl, 'stroke-linecap', style.lineCap);
  80071. style.lineJoin && attr(svgEl, 'stroke-linejoin', style.lineJoin);
  80072. style.miterLimit && attr(svgEl, 'stroke-miterlimit', style.miterLimit);
  80073. }
  80074. else {
  80075. attr(svgEl, 'stroke', NONE);
  80076. }
  80077. }
  80078. /***************************************************
  80079. * PATH
  80080. **************************************************/
  80081. function pathDataToString$1(path) {
  80082. var str = [];
  80083. var data = path.data;
  80084. var dataLength = path.len();
  80085. for (var i = 0; i < dataLength;) {
  80086. var cmd = data[i++];
  80087. var cmdStr = '';
  80088. var nData = 0;
  80089. switch (cmd) {
  80090. case CMD$4.M:
  80091. cmdStr = 'M';
  80092. nData = 2;
  80093. break;
  80094. case CMD$4.L:
  80095. cmdStr = 'L';
  80096. nData = 2;
  80097. break;
  80098. case CMD$4.Q:
  80099. cmdStr = 'Q';
  80100. nData = 4;
  80101. break;
  80102. case CMD$4.C:
  80103. cmdStr = 'C';
  80104. nData = 6;
  80105. break;
  80106. case CMD$4.A:
  80107. var cx = data[i++];
  80108. var cy = data[i++];
  80109. var rx = data[i++];
  80110. var ry = data[i++];
  80111. var theta = data[i++];
  80112. var dTheta = data[i++];
  80113. var psi = data[i++];
  80114. var clockwise = data[i++];
  80115. var dThetaPositive = Math.abs(dTheta);
  80116. var isCircle = isAroundZero$1(dThetaPositive - PI2$7)
  80117. && !isAroundZero$1(dThetaPositive);
  80118. var large = false;
  80119. if (dThetaPositive >= PI2$7) {
  80120. large = true;
  80121. }
  80122. else if (isAroundZero$1(dThetaPositive)) {
  80123. large = false;
  80124. }
  80125. else {
  80126. large = (dTheta > -PI$6 && dTheta < 0 || dTheta > PI$6)
  80127. === !!clockwise;
  80128. }
  80129. var x0 = round4(cx + rx * mathCos$3(theta));
  80130. var y0 = round4(cy + ry * mathSin$3(theta));
  80131. // It will not draw if start point and end point are exactly the same
  80132. // We need to shift the end point with a small value
  80133. // FIXME A better way to draw circle ?
  80134. if (isCircle) {
  80135. if (clockwise) {
  80136. dTheta = PI2$7 - 1e-4;
  80137. }
  80138. else {
  80139. dTheta = -PI2$7 + 1e-4;
  80140. }
  80141. large = true;
  80142. if (i === 9) {
  80143. // Move to (x0, y0) only when CMD.A comes at the
  80144. // first position of a shape.
  80145. // For instance, when drawing a ring, CMD.A comes
  80146. // after CMD.M, so it's unnecessary to move to
  80147. // (x0, y0).
  80148. str.push('M', x0, y0);
  80149. }
  80150. }
  80151. var x = round4(cx + rx * mathCos$3(theta + dTheta));
  80152. var y = round4(cy + ry * mathSin$3(theta + dTheta));
  80153. // FIXME Ellipse
  80154. str.push('A', round4(rx), round4(ry),
  80155. mathRound(psi * degree), +large, +clockwise, x, y);
  80156. break;
  80157. case CMD$4.Z:
  80158. cmdStr = 'Z';
  80159. break;
  80160. case CMD$4.R:
  80161. var x = round4(data[i++]);
  80162. var y = round4(data[i++]);
  80163. var w = round4(data[i++]);
  80164. var h = round4(data[i++]);
  80165. str.push(
  80166. 'M', x, y,
  80167. 'L', x + w, y,
  80168. 'L', x + w, y + h,
  80169. 'L', x, y + h,
  80170. 'L', x, y
  80171. );
  80172. break;
  80173. }
  80174. cmdStr && str.push(cmdStr);
  80175. for (var j = 0; j < nData; j++) {
  80176. // PENDING With scale
  80177. str.push(round4(data[i++]));
  80178. }
  80179. }
  80180. return str.join(' ');
  80181. }
  80182. var svgPath = {};
  80183. svgPath.brush = function (el) {
  80184. var style = el.style;
  80185. var svgEl = el.__svgEl;
  80186. if (!svgEl) {
  80187. svgEl = createElement('path');
  80188. el.__svgEl = svgEl;
  80189. }
  80190. if (!el.path) {
  80191. el.createPathProxy();
  80192. }
  80193. var path = el.path;
  80194. if (el.__dirtyPath) {
  80195. path.beginPath();
  80196. path.subPixelOptimize = false;
  80197. el.buildPath(path, el.shape);
  80198. el.__dirtyPath = false;
  80199. var pathStr = pathDataToString$1(path);
  80200. if (pathStr.indexOf('NaN') < 0) {
  80201. // Ignore illegal path, which may happen such in out-of-range
  80202. // data in Calendar series.
  80203. attr(svgEl, 'd', pathStr);
  80204. }
  80205. }
  80206. bindStyle(svgEl, style, false, el);
  80207. setTransform(svgEl, el.transform);
  80208. if (style.text != null) {
  80209. svgTextDrawRectText(el, el.getBoundingRect());
  80210. }
  80211. };
  80212. /***************************************************
  80213. * IMAGE
  80214. **************************************************/
  80215. var svgImage = {};
  80216. svgImage.brush = function (el) {
  80217. var style = el.style;
  80218. var image = style.image;
  80219. if (image instanceof HTMLImageElement) {
  80220. var src = image.src;
  80221. image = src;
  80222. }
  80223. if (!image) {
  80224. return;
  80225. }
  80226. var x = style.x || 0;
  80227. var y = style.y || 0;
  80228. var dw = style.width;
  80229. var dh = style.height;
  80230. var svgEl = el.__svgEl;
  80231. if (!svgEl) {
  80232. svgEl = createElement('image');
  80233. el.__svgEl = svgEl;
  80234. }
  80235. if (image !== el.__imageSrc) {
  80236. attrXLink(svgEl, 'href', image);
  80237. // Caching image src
  80238. el.__imageSrc = image;
  80239. }
  80240. attr(svgEl, 'width', dw);
  80241. attr(svgEl, 'height', dh);
  80242. attr(svgEl, 'x', x);
  80243. attr(svgEl, 'y', y);
  80244. setTransform(svgEl, el.transform);
  80245. if (style.text != null) {
  80246. svgTextDrawRectText(el, el.getBoundingRect());
  80247. }
  80248. };
  80249. /***************************************************
  80250. * TEXT
  80251. **************************************************/
  80252. var svgText = {};
  80253. var tmpRect$3 = new BoundingRect();
  80254. var tmpTextPositionResult = {};
  80255. var svgTextDrawRectText = function (el, rect, textRect) {
  80256. var style = el.style;
  80257. el.__dirty && normalizeTextStyle(style, true);
  80258. var text = style.text;
  80259. // Convert to string
  80260. if (text == null) {
  80261. // Draw no text only when text is set to null, but not ''
  80262. return;
  80263. }
  80264. else {
  80265. text += '';
  80266. }
  80267. var textSvgEl = el.__textSvgEl;
  80268. if (!textSvgEl) {
  80269. textSvgEl = createElement('text');
  80270. el.__textSvgEl = textSvgEl;
  80271. }
  80272. var x;
  80273. var y;
  80274. var textPosition = style.textPosition;
  80275. var align = style.textAlign || 'left';
  80276. if (typeof style.fontSize === 'number') {
  80277. style.fontSize += 'px';
  80278. }
  80279. var font = style.font
  80280. || [
  80281. style.fontStyle || '',
  80282. style.fontWeight || '',
  80283. style.fontSize || '',
  80284. style.fontFamily || ''
  80285. ].join(' ')
  80286. || DEFAULT_FONT$1;
  80287. var verticalAlign = style.textVerticalAlign;
  80288. textRect = getBoundingRect(
  80289. text, font, align,
  80290. verticalAlign, style.textPadding, style.textLineHeight
  80291. );
  80292. var lineHeight = textRect.lineHeight;
  80293. // Text position represented by coord
  80294. if (textPosition instanceof Array) {
  80295. x = rect.x + textPosition[0];
  80296. y = rect.y + textPosition[1];
  80297. }
  80298. else {
  80299. var newPos = el.calculateTextPosition
  80300. ? el.calculateTextPosition(tmpTextPositionResult, style, rect)
  80301. : calculateTextPosition(tmpTextPositionResult, style, rect);
  80302. x = newPos.x;
  80303. y = newPos.y;
  80304. verticalAlign = newPos.textVerticalAlign;
  80305. align = newPos.textAlign;
  80306. }
  80307. setVerticalAlign(textSvgEl, verticalAlign);
  80308. if (font) {
  80309. textSvgEl.style.font = font;
  80310. }
  80311. var textPadding = style.textPadding;
  80312. // Make baseline top
  80313. attr(textSvgEl, 'x', x);
  80314. attr(textSvgEl, 'y', y);
  80315. bindStyle(textSvgEl, style, true, el);
  80316. if (el instanceof Text || el.style.transformText) {
  80317. // Transform text with element
  80318. setTransform(textSvgEl, el.transform);
  80319. }
  80320. else {
  80321. if (el.transform) {
  80322. tmpRect$3.copy(rect);
  80323. tmpRect$3.applyTransform(el.transform);
  80324. rect = tmpRect$3;
  80325. }
  80326. else {
  80327. var pos = el.transformCoordToGlobal(rect.x, rect.y);
  80328. rect.x = pos[0];
  80329. rect.y = pos[1];
  80330. el.transform = identity(create$1());
  80331. }
  80332. // Text rotation, but no element transform
  80333. var origin = style.textOrigin;
  80334. if (origin === 'center') {
  80335. x = textRect.width / 2 + x;
  80336. y = textRect.height / 2 + y;
  80337. }
  80338. else if (origin) {
  80339. x = origin[0] + x;
  80340. y = origin[1] + y;
  80341. }
  80342. var rotate$$1 = -style.textRotation || 0;
  80343. var transform = create$1();
  80344. // Apply textRotate to element matrix
  80345. rotate(transform, transform, rotate$$1);
  80346. var pos = [el.transform[4], el.transform[5]];
  80347. translate(transform, transform, pos);
  80348. setTransform(textSvgEl, transform);
  80349. }
  80350. var textLines = text.split('\n');
  80351. var nTextLines = textLines.length;
  80352. var textAnchor = align;
  80353. // PENDING
  80354. if (textAnchor === 'left') {
  80355. textAnchor = 'start';
  80356. textPadding && (x += textPadding[3]);
  80357. }
  80358. else if (textAnchor === 'right') {
  80359. textAnchor = 'end';
  80360. textPadding && (x -= textPadding[1]);
  80361. }
  80362. else if (textAnchor === 'center') {
  80363. textAnchor = 'middle';
  80364. textPadding && (x += (textPadding[3] - textPadding[1]) / 2);
  80365. }
  80366. var dy = 0;
  80367. if (verticalAlign === 'bottom') {
  80368. dy = -textRect.height + lineHeight;
  80369. textPadding && (dy -= textPadding[2]);
  80370. }
  80371. else if (verticalAlign === 'middle') {
  80372. dy = (-textRect.height + lineHeight) / 2;
  80373. textPadding && (y += (textPadding[0] - textPadding[2]) / 2);
  80374. }
  80375. else {
  80376. textPadding && (dy += textPadding[0]);
  80377. }
  80378. // Font may affect position of each tspan elements
  80379. if (el.__text !== text || el.__textFont !== font) {
  80380. var tspanList = el.__tspanList || [];
  80381. el.__tspanList = tspanList;
  80382. for (var i = 0; i < nTextLines; i++) {
  80383. // Using cached tspan elements
  80384. var tspan = tspanList[i];
  80385. if (!tspan) {
  80386. tspan = tspanList[i] = createElement('tspan');
  80387. textSvgEl.appendChild(tspan);
  80388. setVerticalAlign(tspan, verticalAlign);
  80389. attr(tspan, 'text-anchor', textAnchor);
  80390. }
  80391. else {
  80392. tspan.innerHTML = '';
  80393. }
  80394. attr(tspan, 'x', x);
  80395. attr(tspan, 'y', y + i * lineHeight + dy);
  80396. tspan.appendChild(document.createTextNode(textLines[i]));
  80397. }
  80398. // Remove unsed tspan elements
  80399. for (; i < tspanList.length; i++) {
  80400. textSvgEl.removeChild(tspanList[i]);
  80401. }
  80402. tspanList.length = nTextLines;
  80403. el.__text = text;
  80404. el.__textFont = font;
  80405. }
  80406. else if (el.__tspanList.length) {
  80407. // Update span x and y
  80408. var len = el.__tspanList.length;
  80409. for (var i = 0; i < len; ++i) {
  80410. var tspan = el.__tspanList[i];
  80411. if (tspan) {
  80412. attr(tspan, 'x', x);
  80413. attr(tspan, 'y', y + i * lineHeight + dy);
  80414. }
  80415. }
  80416. }
  80417. };
  80418. function setVerticalAlign(textSvgEl, verticalAlign) {
  80419. switch (verticalAlign) {
  80420. case 'middle':
  80421. attr(textSvgEl, 'dominant-baseline', 'middle');
  80422. attr(textSvgEl, 'alignment-baseline', 'middle');
  80423. break;
  80424. case 'bottom':
  80425. attr(textSvgEl, 'dominant-baseline', 'ideographic');
  80426. attr(textSvgEl, 'alignment-baseline', 'ideographic');
  80427. break;
  80428. default:
  80429. attr(textSvgEl, 'dominant-baseline', 'hanging');
  80430. attr(textSvgEl, 'alignment-baseline', 'hanging');
  80431. }
  80432. }
  80433. svgText.drawRectText = svgTextDrawRectText;
  80434. svgText.brush = function (el) {
  80435. var style = el.style;
  80436. if (style.text != null) {
  80437. // 强制设置 textPosition
  80438. style.textPosition = [0, 0];
  80439. svgTextDrawRectText(el, {
  80440. x: style.x || 0, y: style.y || 0,
  80441. width: 0, height: 0
  80442. }, el.getBoundingRect());
  80443. }
  80444. };
  80445. // Myers' Diff Algorithm
  80446. // Modified from https://github.com/kpdecker/jsdiff/blob/master/src/diff/base.js
  80447. function Diff() {}
  80448. Diff.prototype = {
  80449. diff: function (oldArr, newArr, equals) {
  80450. if (!equals) {
  80451. equals = function (a, b) {
  80452. return a === b;
  80453. };
  80454. }
  80455. this.equals = equals;
  80456. var self = this;
  80457. oldArr = oldArr.slice();
  80458. newArr = newArr.slice();
  80459. // Allow subclasses to massage the input prior to running
  80460. var newLen = newArr.length;
  80461. var oldLen = oldArr.length;
  80462. var editLength = 1;
  80463. var maxEditLength = newLen + oldLen;
  80464. var bestPath = [{ newPos: -1, components: [] }];
  80465. // Seed editLength = 0, i.e. the content starts with the same values
  80466. var oldPos = this.extractCommon(bestPath[0], newArr, oldArr, 0);
  80467. if (bestPath[0].newPos + 1 >= newLen && oldPos + 1 >= oldLen) {
  80468. var indices = [];
  80469. for (var i = 0; i < newArr.length; i++) {
  80470. indices.push(i);
  80471. }
  80472. // Identity per the equality and tokenizer
  80473. return [{
  80474. indices: indices, count: newArr.length
  80475. }];
  80476. }
  80477. // Main worker method. checks all permutations of a given edit length for acceptance.
  80478. function execEditLength() {
  80479. for (var diagonalPath = -1 * editLength; diagonalPath <= editLength; diagonalPath += 2) {
  80480. var basePath;
  80481. var addPath = bestPath[diagonalPath - 1];
  80482. var removePath = bestPath[diagonalPath + 1];
  80483. var oldPos = (removePath ? removePath.newPos : 0) - diagonalPath;
  80484. if (addPath) {
  80485. // No one else is going to attempt to use this value, clear it
  80486. bestPath[diagonalPath - 1] = undefined;
  80487. }
  80488. var canAdd = addPath && addPath.newPos + 1 < newLen;
  80489. var canRemove = removePath && 0 <= oldPos && oldPos < oldLen;
  80490. if (!canAdd && !canRemove) {
  80491. // If this path is a terminal then prune
  80492. bestPath[diagonalPath] = undefined;
  80493. continue;
  80494. }
  80495. // Select the diagonal that we want to branch from. We select the prior
  80496. // path whose position in the new string is the farthest from the origin
  80497. // and does not pass the bounds of the diff graph
  80498. if (!canAdd || (canRemove && addPath.newPos < removePath.newPos)) {
  80499. basePath = clonePath(removePath);
  80500. self.pushComponent(basePath.components, undefined, true);
  80501. }
  80502. else {
  80503. basePath = addPath; // No need to clone, we've pulled it from the list
  80504. basePath.newPos++;
  80505. self.pushComponent(basePath.components, true, undefined);
  80506. }
  80507. oldPos = self.extractCommon(basePath, newArr, oldArr, diagonalPath);
  80508. // If we have hit the end of both strings, then we are done
  80509. if (basePath.newPos + 1 >= newLen && oldPos + 1 >= oldLen) {
  80510. return buildValues(self, basePath.components, newArr, oldArr);
  80511. }
  80512. else {
  80513. // Otherwise track this path as a potential candidate and continue.
  80514. bestPath[diagonalPath] = basePath;
  80515. }
  80516. }
  80517. editLength++;
  80518. }
  80519. while (editLength <= maxEditLength) {
  80520. var ret = execEditLength();
  80521. if (ret) {
  80522. return ret;
  80523. }
  80524. }
  80525. },
  80526. pushComponent: function (components, added, removed) {
  80527. var last = components[components.length - 1];
  80528. if (last && last.added === added && last.removed === removed) {
  80529. // We need to clone here as the component clone operation is just
  80530. // as shallow array clone
  80531. components[components.length - 1] = {count: last.count + 1, added: added, removed: removed };
  80532. }
  80533. else {
  80534. components.push({count: 1, added: added, removed: removed });
  80535. }
  80536. },
  80537. extractCommon: function (basePath, newArr, oldArr, diagonalPath) {
  80538. var newLen = newArr.length;
  80539. var oldLen = oldArr.length;
  80540. var newPos = basePath.newPos;
  80541. var oldPos = newPos - diagonalPath;
  80542. var commonCount = 0;
  80543. while (newPos + 1 < newLen && oldPos + 1 < oldLen && this.equals(newArr[newPos + 1], oldArr[oldPos + 1])) {
  80544. newPos++;
  80545. oldPos++;
  80546. commonCount++;
  80547. }
  80548. if (commonCount) {
  80549. basePath.components.push({count: commonCount});
  80550. }
  80551. basePath.newPos = newPos;
  80552. return oldPos;
  80553. },
  80554. tokenize: function (value) {
  80555. return value.slice();
  80556. },
  80557. join: function (value) {
  80558. return value.slice();
  80559. }
  80560. };
  80561. function buildValues(diff, components, newArr, oldArr) {
  80562. var componentPos = 0;
  80563. var componentLen = components.length;
  80564. var newPos = 0;
  80565. var oldPos = 0;
  80566. for (; componentPos < componentLen; componentPos++) {
  80567. var component = components[componentPos];
  80568. if (!component.removed) {
  80569. var indices = [];
  80570. for (var i = newPos; i < newPos + component.count; i++) {
  80571. indices.push(i);
  80572. }
  80573. component.indices = indices;
  80574. newPos += component.count;
  80575. // Common case
  80576. if (!component.added) {
  80577. oldPos += component.count;
  80578. }
  80579. }
  80580. else {
  80581. var indices = [];
  80582. for (var i = oldPos; i < oldPos + component.count; i++) {
  80583. indices.push(i);
  80584. }
  80585. component.indices = indices;
  80586. oldPos += component.count;
  80587. }
  80588. }
  80589. return components;
  80590. }
  80591. function clonePath(path) {
  80592. return { newPos: path.newPos, components: path.components.slice(0) };
  80593. }
  80594. var arrayDiff = new Diff();
  80595. var arrayDiff$1 = function (oldArr, newArr, callback) {
  80596. return arrayDiff.diff(oldArr, newArr, callback);
  80597. };
  80598. /**
  80599. * @file Manages elements that can be defined in <defs> in SVG,
  80600. * e.g., gradients, clip path, etc.
  80601. * @author Zhang Wenli
  80602. */
  80603. var MARK_UNUSED = '0';
  80604. var MARK_USED = '1';
  80605. /**
  80606. * Manages elements that can be defined in <defs> in SVG,
  80607. * e.g., gradients, clip path, etc.
  80608. *
  80609. * @class
  80610. * @param {number} zrId zrender instance id
  80611. * @param {SVGElement} svgRoot root of SVG document
  80612. * @param {string|string[]} tagNames possible tag names
  80613. * @param {string} markLabel label name to make if the element
  80614. * is used
  80615. */
  80616. function Definable(
  80617. zrId,
  80618. svgRoot,
  80619. tagNames,
  80620. markLabel,
  80621. domName
  80622. ) {
  80623. this._zrId = zrId;
  80624. this._svgRoot = svgRoot;
  80625. this._tagNames = typeof tagNames === 'string' ? [tagNames] : tagNames;
  80626. this._markLabel = markLabel;
  80627. this._domName = domName || '_dom';
  80628. this.nextId = 0;
  80629. }
  80630. Definable.prototype.createElement = createElement;
  80631. /**
  80632. * Get the <defs> tag for svgRoot; optionally creates one if not exists.
  80633. *
  80634. * @param {boolean} isForceCreating if need to create when not exists
  80635. * @return {SVGDefsElement} SVG <defs> element, null if it doesn't
  80636. * exist and isForceCreating is false
  80637. */
  80638. Definable.prototype.getDefs = function (isForceCreating) {
  80639. var svgRoot = this._svgRoot;
  80640. var defs = this._svgRoot.getElementsByTagName('defs');
  80641. if (defs.length === 0) {
  80642. // Not exist
  80643. if (isForceCreating) {
  80644. defs = svgRoot.insertBefore(
  80645. this.createElement('defs'), // Create new tag
  80646. svgRoot.firstChild // Insert in the front of svg
  80647. );
  80648. if (!defs.contains) {
  80649. // IE doesn't support contains method
  80650. defs.contains = function (el) {
  80651. var children = defs.children;
  80652. if (!children) {
  80653. return false;
  80654. }
  80655. for (var i = children.length - 1; i >= 0; --i) {
  80656. if (children[i] === el) {
  80657. return true;
  80658. }
  80659. }
  80660. return false;
  80661. };
  80662. }
  80663. return defs;
  80664. }
  80665. else {
  80666. return null;
  80667. }
  80668. }
  80669. else {
  80670. return defs[0];
  80671. }
  80672. };
  80673. /**
  80674. * Update DOM element if necessary.
  80675. *
  80676. * @param {Object|string} element style element. e.g., for gradient,
  80677. * it may be '#ccc' or {type: 'linear', ...}
  80678. * @param {Function|undefined} onUpdate update callback
  80679. */
  80680. Definable.prototype.update = function (element, onUpdate) {
  80681. if (!element) {
  80682. return;
  80683. }
  80684. var defs = this.getDefs(false);
  80685. if (element[this._domName] && defs.contains(element[this._domName])) {
  80686. // Update DOM
  80687. if (typeof onUpdate === 'function') {
  80688. onUpdate(element);
  80689. }
  80690. }
  80691. else {
  80692. // No previous dom, create new
  80693. var dom = this.add(element);
  80694. if (dom) {
  80695. element[this._domName] = dom;
  80696. }
  80697. }
  80698. };
  80699. /**
  80700. * Add gradient dom to defs
  80701. *
  80702. * @param {SVGElement} dom DOM to be added to <defs>
  80703. */
  80704. Definable.prototype.addDom = function (dom) {
  80705. var defs = this.getDefs(true);
  80706. defs.appendChild(dom);
  80707. };
  80708. /**
  80709. * Remove DOM of a given element.
  80710. *
  80711. * @param {SVGElement} element element to remove dom
  80712. */
  80713. Definable.prototype.removeDom = function (element) {
  80714. var defs = this.getDefs(false);
  80715. if (defs && element[this._domName]) {
  80716. defs.removeChild(element[this._domName]);
  80717. element[this._domName] = null;
  80718. }
  80719. };
  80720. /**
  80721. * Get DOMs of this element.
  80722. *
  80723. * @return {HTMLDomElement} doms of this defineable elements in <defs>
  80724. */
  80725. Definable.prototype.getDoms = function () {
  80726. var defs = this.getDefs(false);
  80727. if (!defs) {
  80728. // No dom when defs is not defined
  80729. return [];
  80730. }
  80731. var doms = [];
  80732. each$1(this._tagNames, function (tagName) {
  80733. var tags = defs.getElementsByTagName(tagName);
  80734. // Note that tags is HTMLCollection, which is array-like
  80735. // rather than real array.
  80736. // So `doms.concat(tags)` add tags as one object.
  80737. doms = doms.concat([].slice.call(tags));
  80738. });
  80739. return doms;
  80740. };
  80741. /**
  80742. * Mark DOMs to be unused before painting, and clear unused ones at the end
  80743. * of the painting.
  80744. */
  80745. Definable.prototype.markAllUnused = function () {
  80746. var doms = this.getDoms();
  80747. var that = this;
  80748. each$1(doms, function (dom) {
  80749. dom[that._markLabel] = MARK_UNUSED;
  80750. });
  80751. };
  80752. /**
  80753. * Mark a single DOM to be used.
  80754. *
  80755. * @param {SVGElement} dom DOM to mark
  80756. */
  80757. Definable.prototype.markUsed = function (dom) {
  80758. if (dom) {
  80759. dom[this._markLabel] = MARK_USED;
  80760. }
  80761. };
  80762. /**
  80763. * Remove unused DOMs defined in <defs>
  80764. */
  80765. Definable.prototype.removeUnused = function () {
  80766. var defs = this.getDefs(false);
  80767. if (!defs) {
  80768. // Nothing to remove
  80769. return;
  80770. }
  80771. var doms = this.getDoms();
  80772. var that = this;
  80773. each$1(doms, function (dom) {
  80774. if (dom[that._markLabel] !== MARK_USED) {
  80775. // Remove gradient
  80776. defs.removeChild(dom);
  80777. }
  80778. });
  80779. };
  80780. /**
  80781. * Get SVG proxy.
  80782. *
  80783. * @param {Displayable} displayable displayable element
  80784. * @return {Path|Image|Text} svg proxy of given element
  80785. */
  80786. Definable.prototype.getSvgProxy = function (displayable) {
  80787. if (displayable instanceof Path) {
  80788. return svgPath;
  80789. }
  80790. else if (displayable instanceof ZImage) {
  80791. return svgImage;
  80792. }
  80793. else if (displayable instanceof Text) {
  80794. return svgText;
  80795. }
  80796. else {
  80797. return svgPath;
  80798. }
  80799. };
  80800. /**
  80801. * Get text SVG element.
  80802. *
  80803. * @param {Displayable} displayable displayable element
  80804. * @return {SVGElement} SVG element of text
  80805. */
  80806. Definable.prototype.getTextSvgElement = function (displayable) {
  80807. return displayable.__textSvgEl;
  80808. };
  80809. /**
  80810. * Get SVG element.
  80811. *
  80812. * @param {Displayable} displayable displayable element
  80813. * @return {SVGElement} SVG element
  80814. */
  80815. Definable.prototype.getSvgElement = function (displayable) {
  80816. return displayable.__svgEl;
  80817. };
  80818. /**
  80819. * @file Manages SVG gradient elements.
  80820. * @author Zhang Wenli
  80821. */
  80822. /**
  80823. * Manages SVG gradient elements.
  80824. *
  80825. * @class
  80826. * @extends Definable
  80827. * @param {number} zrId zrender instance id
  80828. * @param {SVGElement} svgRoot root of SVG document
  80829. */
  80830. function GradientManager(zrId, svgRoot) {
  80831. Definable.call(
  80832. this,
  80833. zrId,
  80834. svgRoot,
  80835. ['linearGradient', 'radialGradient'],
  80836. '__gradient_in_use__'
  80837. );
  80838. }
  80839. inherits(GradientManager, Definable);
  80840. /**
  80841. * Create new gradient DOM for fill or stroke if not exist,
  80842. * but will not update gradient if exists.
  80843. *
  80844. * @param {SvgElement} svgElement SVG element to paint
  80845. * @param {Displayable} displayable zrender displayable element
  80846. */
  80847. GradientManager.prototype.addWithoutUpdate = function (
  80848. svgElement,
  80849. displayable
  80850. ) {
  80851. if (displayable && displayable.style) {
  80852. var that = this;
  80853. each$1(['fill', 'stroke'], function (fillOrStroke) {
  80854. if (displayable.style[fillOrStroke]
  80855. && (displayable.style[fillOrStroke].type === 'linear'
  80856. || displayable.style[fillOrStroke].type === 'radial')
  80857. ) {
  80858. var gradient = displayable.style[fillOrStroke];
  80859. var defs = that.getDefs(true);
  80860. // Create dom in <defs> if not exists
  80861. var dom;
  80862. if (gradient._dom) {
  80863. // Gradient exists
  80864. dom = gradient._dom;
  80865. if (!defs.contains(gradient._dom)) {
  80866. // _dom is no longer in defs, recreate
  80867. that.addDom(dom);
  80868. }
  80869. }
  80870. else {
  80871. // New dom
  80872. dom = that.add(gradient);
  80873. }
  80874. that.markUsed(displayable);
  80875. var id = dom.getAttribute('id');
  80876. svgElement.setAttribute(fillOrStroke, 'url(#' + id + ')');
  80877. }
  80878. });
  80879. }
  80880. };
  80881. /**
  80882. * Add a new gradient tag in <defs>
  80883. *
  80884. * @param {Gradient} gradient zr gradient instance
  80885. * @return {SVGLinearGradientElement | SVGRadialGradientElement}
  80886. * created DOM
  80887. */
  80888. GradientManager.prototype.add = function (gradient) {
  80889. var dom;
  80890. if (gradient.type === 'linear') {
  80891. dom = this.createElement('linearGradient');
  80892. }
  80893. else if (gradient.type === 'radial') {
  80894. dom = this.createElement('radialGradient');
  80895. }
  80896. else {
  80897. zrLog('Illegal gradient type.');
  80898. return null;
  80899. }
  80900. // Set dom id with gradient id, since each gradient instance
  80901. // will have no more than one dom element.
  80902. // id may exists before for those dirty elements, in which case
  80903. // id should remain the same, and other attributes should be
  80904. // updated.
  80905. gradient.id = gradient.id || this.nextId++;
  80906. dom.setAttribute('id', 'zr' + this._zrId
  80907. + '-gradient-' + gradient.id);
  80908. this.updateDom(gradient, dom);
  80909. this.addDom(dom);
  80910. return dom;
  80911. };
  80912. /**
  80913. * Update gradient.
  80914. *
  80915. * @param {Gradient} gradient zr gradient instance
  80916. */
  80917. GradientManager.prototype.update = function (gradient) {
  80918. var that = this;
  80919. Definable.prototype.update.call(this, gradient, function () {
  80920. var type = gradient.type;
  80921. var tagName = gradient._dom.tagName;
  80922. if (type === 'linear' && tagName === 'linearGradient'
  80923. || type === 'radial' && tagName === 'radialGradient'
  80924. ) {
  80925. // Gradient type is not changed, update gradient
  80926. that.updateDom(gradient, gradient._dom);
  80927. }
  80928. else {
  80929. // Remove and re-create if type is changed
  80930. that.removeDom(gradient);
  80931. that.add(gradient);
  80932. }
  80933. });
  80934. };
  80935. /**
  80936. * Update gradient dom
  80937. *
  80938. * @param {Gradient} gradient zr gradient instance
  80939. * @param {SVGLinearGradientElement | SVGRadialGradientElement} dom
  80940. * DOM to update
  80941. */
  80942. GradientManager.prototype.updateDom = function (gradient, dom) {
  80943. if (gradient.type === 'linear') {
  80944. dom.setAttribute('x1', gradient.x);
  80945. dom.setAttribute('y1', gradient.y);
  80946. dom.setAttribute('x2', gradient.x2);
  80947. dom.setAttribute('y2', gradient.y2);
  80948. }
  80949. else if (gradient.type === 'radial') {
  80950. dom.setAttribute('cx', gradient.x);
  80951. dom.setAttribute('cy', gradient.y);
  80952. dom.setAttribute('r', gradient.r);
  80953. }
  80954. else {
  80955. zrLog('Illegal gradient type.');
  80956. return;
  80957. }
  80958. if (gradient.global) {
  80959. // x1, x2, y1, y2 in range of 0 to canvas width or height
  80960. dom.setAttribute('gradientUnits', 'userSpaceOnUse');
  80961. }
  80962. else {
  80963. // x1, x2, y1, y2 in range of 0 to 1
  80964. dom.setAttribute('gradientUnits', 'objectBoundingBox');
  80965. }
  80966. // Remove color stops if exists
  80967. dom.innerHTML = '';
  80968. // Add color stops
  80969. var colors = gradient.colorStops;
  80970. for (var i = 0, len = colors.length; i < len; ++i) {
  80971. var stop = this.createElement('stop');
  80972. stop.setAttribute('offset', colors[i].offset * 100 + '%');
  80973. var color = colors[i].color;
  80974. if (color.indexOf('rgba' > -1)) {
  80975. // Fix Safari bug that stop-color not recognizing alpha #9014
  80976. var opacity = parse(color)[3];
  80977. var hex = toHex(color);
  80978. // stop-color cannot be color, since:
  80979. // The opacity value used for the gradient calculation is the
  80980. // *product* of the value of stop-opacity and the opacity of the
  80981. // value of stop-color.
  80982. // See https://www.w3.org/TR/SVG2/pservers.html#StopOpacityProperty
  80983. stop.setAttribute('stop-color', '#' + hex);
  80984. stop.setAttribute('stop-opacity', opacity);
  80985. }
  80986. else {
  80987. stop.setAttribute('stop-color', colors[i].color);
  80988. }
  80989. dom.appendChild(stop);
  80990. }
  80991. // Store dom element in gradient, to avoid creating multiple
  80992. // dom instances for the same gradient element
  80993. gradient._dom = dom;
  80994. };
  80995. /**
  80996. * Mark a single gradient to be used
  80997. *
  80998. * @param {Displayable} displayable displayable element
  80999. */
  81000. GradientManager.prototype.markUsed = function (displayable) {
  81001. if (displayable.style) {
  81002. var gradient = displayable.style.fill;
  81003. if (gradient && gradient._dom) {
  81004. Definable.prototype.markUsed.call(this, gradient._dom);
  81005. }
  81006. gradient = displayable.style.stroke;
  81007. if (gradient && gradient._dom) {
  81008. Definable.prototype.markUsed.call(this, gradient._dom);
  81009. }
  81010. }
  81011. };
  81012. /**
  81013. * @file Manages SVG clipPath elements.
  81014. * @author Zhang Wenli
  81015. */
  81016. /**
  81017. * Manages SVG clipPath elements.
  81018. *
  81019. * @class
  81020. * @extends Definable
  81021. * @param {number} zrId zrender instance id
  81022. * @param {SVGElement} svgRoot root of SVG document
  81023. */
  81024. function ClippathManager(zrId, svgRoot) {
  81025. Definable.call(this, zrId, svgRoot, 'clipPath', '__clippath_in_use__');
  81026. }
  81027. inherits(ClippathManager, Definable);
  81028. /**
  81029. * Update clipPath.
  81030. *
  81031. * @param {Displayable} displayable displayable element
  81032. */
  81033. ClippathManager.prototype.update = function (displayable) {
  81034. var svgEl = this.getSvgElement(displayable);
  81035. if (svgEl) {
  81036. this.updateDom(svgEl, displayable.__clipPaths, false);
  81037. }
  81038. var textEl = this.getTextSvgElement(displayable);
  81039. if (textEl) {
  81040. // Make another clipPath for text, since it's transform
  81041. // matrix is not the same with svgElement
  81042. this.updateDom(textEl, displayable.__clipPaths, true);
  81043. }
  81044. this.markUsed(displayable);
  81045. };
  81046. /**
  81047. * Create an SVGElement of displayable and create a <clipPath> of its
  81048. * clipPath
  81049. *
  81050. * @param {Displayable} parentEl parent element
  81051. * @param {ClipPath[]} clipPaths clipPaths of parent element
  81052. * @param {boolean} isText if parent element is Text
  81053. */
  81054. ClippathManager.prototype.updateDom = function (
  81055. parentEl,
  81056. clipPaths,
  81057. isText
  81058. ) {
  81059. if (clipPaths && clipPaths.length > 0) {
  81060. // Has clipPath, create <clipPath> with the first clipPath
  81061. var defs = this.getDefs(true);
  81062. var clipPath = clipPaths[0];
  81063. var clipPathEl;
  81064. var id;
  81065. var dom = isText ? '_textDom' : '_dom';
  81066. if (clipPath[dom]) {
  81067. // Use a dom that is already in <defs>
  81068. id = clipPath[dom].getAttribute('id');
  81069. clipPathEl = clipPath[dom];
  81070. // Use a dom that is already in <defs>
  81071. if (!defs.contains(clipPathEl)) {
  81072. // This happens when set old clipPath that has
  81073. // been previously removed
  81074. defs.appendChild(clipPathEl);
  81075. }
  81076. }
  81077. else {
  81078. // New <clipPath>
  81079. id = 'zr' + this._zrId + '-clip-' + this.nextId;
  81080. ++this.nextId;
  81081. clipPathEl = this.createElement('clipPath');
  81082. clipPathEl.setAttribute('id', id);
  81083. defs.appendChild(clipPathEl);
  81084. clipPath[dom] = clipPathEl;
  81085. }
  81086. // Build path and add to <clipPath>
  81087. var svgProxy = this.getSvgProxy(clipPath);
  81088. if (clipPath.transform
  81089. && clipPath.parent.invTransform
  81090. && !isText
  81091. ) {
  81092. /**
  81093. * If a clipPath has a parent with transform, the transform
  81094. * of parent should not be considered when setting transform
  81095. * of clipPath. So we need to transform back from parent's
  81096. * transform, which is done by multiplying parent's inverse
  81097. * transform.
  81098. */
  81099. // Store old transform
  81100. var transform = Array.prototype.slice.call(
  81101. clipPath.transform
  81102. );
  81103. // Transform back from parent, and brush path
  81104. mul$1(
  81105. clipPath.transform,
  81106. clipPath.parent.invTransform,
  81107. clipPath.transform
  81108. );
  81109. svgProxy.brush(clipPath);
  81110. // Set back transform of clipPath
  81111. clipPath.transform = transform;
  81112. }
  81113. else {
  81114. svgProxy.brush(clipPath);
  81115. }
  81116. var pathEl = this.getSvgElement(clipPath);
  81117. clipPathEl.innerHTML = '';
  81118. /**
  81119. * Use `cloneNode()` here to appendChild to multiple parents,
  81120. * which may happend when Text and other shapes are using the same
  81121. * clipPath. Since Text will create an extra clipPath DOM due to
  81122. * different transform rules.
  81123. */
  81124. clipPathEl.appendChild(pathEl.cloneNode());
  81125. parentEl.setAttribute('clip-path', 'url(#' + id + ')');
  81126. if (clipPaths.length > 1) {
  81127. // Make the other clipPaths recursively
  81128. this.updateDom(clipPathEl, clipPaths.slice(1), isText);
  81129. }
  81130. }
  81131. else {
  81132. // No clipPath
  81133. if (parentEl) {
  81134. parentEl.setAttribute('clip-path', 'none');
  81135. }
  81136. }
  81137. };
  81138. /**
  81139. * Mark a single clipPath to be used
  81140. *
  81141. * @param {Displayable} displayable displayable element
  81142. */
  81143. ClippathManager.prototype.markUsed = function (displayable) {
  81144. var that = this;
  81145. // displayable.__clipPaths can only be `null`/`undefined` or an non-empty array.
  81146. if (displayable.__clipPaths) {
  81147. each$1(displayable.__clipPaths, function (clipPath) {
  81148. if (clipPath._dom) {
  81149. Definable.prototype.markUsed.call(that, clipPath._dom);
  81150. }
  81151. if (clipPath._textDom) {
  81152. Definable.prototype.markUsed.call(that, clipPath._textDom);
  81153. }
  81154. });
  81155. }
  81156. };
  81157. /**
  81158. * @file Manages SVG shadow elements.
  81159. * @author Zhang Wenli
  81160. */
  81161. /**
  81162. * Manages SVG shadow elements.
  81163. *
  81164. * @class
  81165. * @extends Definable
  81166. * @param {number} zrId zrender instance id
  81167. * @param {SVGElement} svgRoot root of SVG document
  81168. */
  81169. function ShadowManager(zrId, svgRoot) {
  81170. Definable.call(
  81171. this,
  81172. zrId,
  81173. svgRoot,
  81174. ['filter'],
  81175. '__filter_in_use__',
  81176. '_shadowDom'
  81177. );
  81178. }
  81179. inherits(ShadowManager, Definable);
  81180. /**
  81181. * Create new shadow DOM for fill or stroke if not exist,
  81182. * but will not update shadow if exists.
  81183. *
  81184. * @param {SvgElement} svgElement SVG element to paint
  81185. * @param {Displayable} displayable zrender displayable element
  81186. */
  81187. ShadowManager.prototype.addWithoutUpdate = function (
  81188. svgElement,
  81189. displayable
  81190. ) {
  81191. if (displayable && hasShadow(displayable.style)) {
  81192. var style = displayable.style;
  81193. // Create dom in <defs> if not exists
  81194. var dom;
  81195. if (style._shadowDom) {
  81196. // Gradient exists
  81197. dom = style._shadowDom;
  81198. var defs = this.getDefs(true);
  81199. if (!defs.contains(style._shadowDom)) {
  81200. // _shadowDom is no longer in defs, recreate
  81201. this.addDom(dom);
  81202. }
  81203. }
  81204. else {
  81205. // New dom
  81206. dom = this.add(displayable);
  81207. }
  81208. this.markUsed(displayable);
  81209. var id = dom.getAttribute('id');
  81210. svgElement.style.filter = 'url(#' + id + ')';
  81211. }
  81212. };
  81213. /**
  81214. * Add a new shadow tag in <defs>
  81215. *
  81216. * @param {Displayable} displayable zrender displayable element
  81217. * @return {SVGFilterElement} created DOM
  81218. */
  81219. ShadowManager.prototype.add = function (displayable) {
  81220. var dom = this.createElement('filter');
  81221. var style = displayable.style;
  81222. // Set dom id with shadow id, since each shadow instance
  81223. // will have no more than one dom element.
  81224. // id may exists before for those dirty elements, in which case
  81225. // id should remain the same, and other attributes should be
  81226. // updated.
  81227. style._shadowDomId = style._shadowDomId || this.nextId++;
  81228. dom.setAttribute('id', 'zr' + this._zrId
  81229. + '-shadow-' + style._shadowDomId);
  81230. this.updateDom(displayable, dom);
  81231. this.addDom(dom);
  81232. return dom;
  81233. };
  81234. /**
  81235. * Update shadow.
  81236. *
  81237. * @param {Displayable} displayable zrender displayable element
  81238. */
  81239. ShadowManager.prototype.update = function (svgElement, displayable) {
  81240. var style = displayable.style;
  81241. if (hasShadow(style)) {
  81242. var that = this;
  81243. Definable.prototype.update.call(this, displayable, function (style) {
  81244. that.updateDom(displayable, style._shadowDom);
  81245. });
  81246. }
  81247. else {
  81248. // Remove shadow
  81249. this.remove(svgElement, style);
  81250. }
  81251. };
  81252. /**
  81253. * Remove DOM and clear parent filter
  81254. */
  81255. ShadowManager.prototype.remove = function (svgElement, style) {
  81256. if (style._shadowDomId != null) {
  81257. this.removeDom(style);
  81258. svgElement.style.filter = '';
  81259. }
  81260. };
  81261. /**
  81262. * Update shadow dom
  81263. *
  81264. * @param {Displayable} displayable zrender displayable element
  81265. * @param {SVGFilterElement} dom DOM to update
  81266. */
  81267. ShadowManager.prototype.updateDom = function (displayable, dom) {
  81268. var domChild = dom.getElementsByTagName('feDropShadow');
  81269. if (domChild.length === 0) {
  81270. domChild = this.createElement('feDropShadow');
  81271. }
  81272. else {
  81273. domChild = domChild[0];
  81274. }
  81275. var style = displayable.style;
  81276. var scaleX = displayable.scale ? (displayable.scale[0] || 1) : 1;
  81277. var scaleY = displayable.scale ? (displayable.scale[1] || 1) : 1;
  81278. // TODO: textBoxShadowBlur is not supported yet
  81279. var offsetX, offsetY, blur, color;
  81280. if (style.shadowBlur || style.shadowOffsetX || style.shadowOffsetY) {
  81281. offsetX = style.shadowOffsetX || 0;
  81282. offsetY = style.shadowOffsetY || 0;
  81283. blur = style.shadowBlur;
  81284. color = style.shadowColor;
  81285. }
  81286. else if (style.textShadowBlur) {
  81287. offsetX = style.textShadowOffsetX || 0;
  81288. offsetY = style.textShadowOffsetY || 0;
  81289. blur = style.textShadowBlur;
  81290. color = style.textShadowColor;
  81291. }
  81292. else {
  81293. // Remove shadow
  81294. this.removeDom(dom, style);
  81295. return;
  81296. }
  81297. domChild.setAttribute('dx', offsetX / scaleX);
  81298. domChild.setAttribute('dy', offsetY / scaleY);
  81299. domChild.setAttribute('flood-color', color);
  81300. // Divide by two here so that it looks the same as in canvas
  81301. // See: https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-shadowblur
  81302. var stdDx = blur / 2 / scaleX;
  81303. var stdDy = blur / 2 / scaleY;
  81304. var stdDeviation = stdDx + ' ' + stdDy;
  81305. domChild.setAttribute('stdDeviation', stdDeviation);
  81306. // Fix filter clipping problem
  81307. dom.setAttribute('x', '-100%');
  81308. dom.setAttribute('y', '-100%');
  81309. dom.setAttribute('width', Math.ceil(blur / 2 * 200) + '%');
  81310. dom.setAttribute('height', Math.ceil(blur / 2 * 200) + '%');
  81311. dom.appendChild(domChild);
  81312. // Store dom element in shadow, to avoid creating multiple
  81313. // dom instances for the same shadow element
  81314. style._shadowDom = dom;
  81315. };
  81316. /**
  81317. * Mark a single shadow to be used
  81318. *
  81319. * @param {Displayable} displayable displayable element
  81320. */
  81321. ShadowManager.prototype.markUsed = function (displayable) {
  81322. var style = displayable.style;
  81323. if (style && style._shadowDom) {
  81324. Definable.prototype.markUsed.call(this, style._shadowDom);
  81325. }
  81326. };
  81327. function hasShadow(style) {
  81328. // TODO: textBoxShadowBlur is not supported yet
  81329. return style
  81330. && (style.shadowBlur || style.shadowOffsetX || style.shadowOffsetY
  81331. || style.textShadowBlur || style.textShadowOffsetX
  81332. || style.textShadowOffsetY);
  81333. }
  81334. /**
  81335. * SVG Painter
  81336. * @module zrender/svg/Painter
  81337. */
  81338. function parseInt10$2(val) {
  81339. return parseInt(val, 10);
  81340. }
  81341. function getSvgProxy(el) {
  81342. if (el instanceof Path) {
  81343. return svgPath;
  81344. }
  81345. else if (el instanceof ZImage) {
  81346. return svgImage;
  81347. }
  81348. else if (el instanceof Text) {
  81349. return svgText;
  81350. }
  81351. else {
  81352. return svgPath;
  81353. }
  81354. }
  81355. function checkParentAvailable(parent, child) {
  81356. return child && parent && child.parentNode !== parent;
  81357. }
  81358. function insertAfter(parent, child, prevSibling) {
  81359. if (checkParentAvailable(parent, child) && prevSibling) {
  81360. var nextSibling = prevSibling.nextSibling;
  81361. nextSibling ? parent.insertBefore(child, nextSibling)
  81362. : parent.appendChild(child);
  81363. }
  81364. }
  81365. function prepend(parent, child) {
  81366. if (checkParentAvailable(parent, child)) {
  81367. var firstChild = parent.firstChild;
  81368. firstChild ? parent.insertBefore(child, firstChild)
  81369. : parent.appendChild(child);
  81370. }
  81371. }
  81372. function remove$1(parent, child) {
  81373. if (child && parent && child.parentNode === parent) {
  81374. parent.removeChild(child);
  81375. }
  81376. }
  81377. function getTextSvgElement(displayable) {
  81378. return displayable.__textSvgEl;
  81379. }
  81380. function getSvgElement(displayable) {
  81381. return displayable.__svgEl;
  81382. }
  81383. /**
  81384. * @alias module:zrender/svg/Painter
  81385. * @constructor
  81386. * @param {HTMLElement} root 绘图容器
  81387. * @param {module:zrender/Storage} storage
  81388. * @param {Object} opts
  81389. */
  81390. var SVGPainter = function (root, storage, opts, zrId) {
  81391. this.root = root;
  81392. this.storage = storage;
  81393. this._opts = opts = extend({}, opts || {});
  81394. var svgRoot = createElement('svg');
  81395. svgRoot.setAttribute('xmlns', 'http://www.w3.org/2000/svg');
  81396. svgRoot.setAttribute('version', '1.1');
  81397. svgRoot.setAttribute('baseProfile', 'full');
  81398. svgRoot.style.cssText = 'user-select:none;position:absolute;left:0;top:0;';
  81399. this.gradientManager = new GradientManager(zrId, svgRoot);
  81400. this.clipPathManager = new ClippathManager(zrId, svgRoot);
  81401. this.shadowManager = new ShadowManager(zrId, svgRoot);
  81402. var viewport = document.createElement('div');
  81403. viewport.style.cssText = 'overflow:hidden;position:relative';
  81404. this._svgRoot = svgRoot;
  81405. this._viewport = viewport;
  81406. root.appendChild(viewport);
  81407. viewport.appendChild(svgRoot);
  81408. this.resize(opts.width, opts.height);
  81409. this._visibleList = [];
  81410. };
  81411. SVGPainter.prototype = {
  81412. constructor: SVGPainter,
  81413. getType: function () {
  81414. return 'svg';
  81415. },
  81416. getViewportRoot: function () {
  81417. return this._viewport;
  81418. },
  81419. getViewportRootOffset: function () {
  81420. var viewportRoot = this.getViewportRoot();
  81421. if (viewportRoot) {
  81422. return {
  81423. offsetLeft: viewportRoot.offsetLeft || 0,
  81424. offsetTop: viewportRoot.offsetTop || 0
  81425. };
  81426. }
  81427. },
  81428. refresh: function () {
  81429. var list = this.storage.getDisplayList(true);
  81430. this._paintList(list);
  81431. },
  81432. setBackgroundColor: function (backgroundColor) {
  81433. // TODO gradient
  81434. this._viewport.style.background = backgroundColor;
  81435. },
  81436. _paintList: function (list) {
  81437. this.gradientManager.markAllUnused();
  81438. this.clipPathManager.markAllUnused();
  81439. this.shadowManager.markAllUnused();
  81440. var svgRoot = this._svgRoot;
  81441. var visibleList = this._visibleList;
  81442. var listLen = list.length;
  81443. var newVisibleList = [];
  81444. var i;
  81445. for (i = 0; i < listLen; i++) {
  81446. var displayable = list[i];
  81447. var svgProxy = getSvgProxy(displayable);
  81448. var svgElement = getSvgElement(displayable)
  81449. || getTextSvgElement(displayable);
  81450. if (!displayable.invisible) {
  81451. if (displayable.__dirty) {
  81452. svgProxy && svgProxy.brush(displayable);
  81453. // Update clipPath
  81454. this.clipPathManager.update(displayable);
  81455. // Update gradient and shadow
  81456. if (displayable.style) {
  81457. this.gradientManager
  81458. .update(displayable.style.fill);
  81459. this.gradientManager
  81460. .update(displayable.style.stroke);
  81461. this.shadowManager
  81462. .update(svgElement, displayable);
  81463. }
  81464. displayable.__dirty = false;
  81465. }
  81466. newVisibleList.push(displayable);
  81467. }
  81468. }
  81469. var diff = arrayDiff$1(visibleList, newVisibleList);
  81470. var prevSvgElement;
  81471. // First do remove, in case element moved to the head and do remove
  81472. // after add
  81473. for (i = 0; i < diff.length; i++) {
  81474. var item = diff[i];
  81475. if (item.removed) {
  81476. for (var k = 0; k < item.count; k++) {
  81477. var displayable = visibleList[item.indices[k]];
  81478. var svgElement = getSvgElement(displayable);
  81479. var textSvgElement = getTextSvgElement(displayable);
  81480. remove$1(svgRoot, svgElement);
  81481. remove$1(svgRoot, textSvgElement);
  81482. }
  81483. }
  81484. }
  81485. for (i = 0; i < diff.length; i++) {
  81486. var item = diff[i];
  81487. if (item.added) {
  81488. for (var k = 0; k < item.count; k++) {
  81489. var displayable = newVisibleList[item.indices[k]];
  81490. var svgElement = getSvgElement(displayable);
  81491. var textSvgElement = getTextSvgElement(displayable);
  81492. prevSvgElement
  81493. ? insertAfter(svgRoot, svgElement, prevSvgElement)
  81494. : prepend(svgRoot, svgElement);
  81495. if (svgElement) {
  81496. insertAfter(svgRoot, textSvgElement, svgElement);
  81497. }
  81498. else if (prevSvgElement) {
  81499. insertAfter(
  81500. svgRoot, textSvgElement, prevSvgElement
  81501. );
  81502. }
  81503. else {
  81504. prepend(svgRoot, textSvgElement);
  81505. }
  81506. // Insert text
  81507. insertAfter(svgRoot, textSvgElement, svgElement);
  81508. prevSvgElement = textSvgElement || svgElement
  81509. || prevSvgElement;
  81510. this.gradientManager
  81511. .addWithoutUpdate(svgElement, displayable);
  81512. this.shadowManager
  81513. .addWithoutUpdate(prevSvgElement, displayable);
  81514. this.clipPathManager.markUsed(displayable);
  81515. }
  81516. }
  81517. else if (!item.removed) {
  81518. for (var k = 0; k < item.count; k++) {
  81519. var displayable = newVisibleList[item.indices[k]];
  81520. prevSvgElement =
  81521. svgElement =
  81522. getTextSvgElement(displayable)
  81523. || getSvgElement(displayable)
  81524. || prevSvgElement;
  81525. this.gradientManager.markUsed(displayable);
  81526. this.gradientManager
  81527. .addWithoutUpdate(svgElement, displayable);
  81528. this.shadowManager.markUsed(displayable);
  81529. this.shadowManager
  81530. .addWithoutUpdate(svgElement, displayable);
  81531. this.clipPathManager.markUsed(displayable);
  81532. }
  81533. }
  81534. }
  81535. this.gradientManager.removeUnused();
  81536. this.clipPathManager.removeUnused();
  81537. this.shadowManager.removeUnused();
  81538. this._visibleList = newVisibleList;
  81539. },
  81540. _getDefs: function (isForceCreating) {
  81541. var svgRoot = this._svgRoot;
  81542. var defs = this._svgRoot.getElementsByTagName('defs');
  81543. if (defs.length === 0) {
  81544. // Not exist
  81545. if (isForceCreating) {
  81546. var defs = svgRoot.insertBefore(
  81547. createElement('defs'), // Create new tag
  81548. svgRoot.firstChild // Insert in the front of svg
  81549. );
  81550. if (!defs.contains) {
  81551. // IE doesn't support contains method
  81552. defs.contains = function (el) {
  81553. var children = defs.children;
  81554. if (!children) {
  81555. return false;
  81556. }
  81557. for (var i = children.length - 1; i >= 0; --i) {
  81558. if (children[i] === el) {
  81559. return true;
  81560. }
  81561. }
  81562. return false;
  81563. };
  81564. }
  81565. return defs;
  81566. }
  81567. else {
  81568. return null;
  81569. }
  81570. }
  81571. else {
  81572. return defs[0];
  81573. }
  81574. },
  81575. resize: function (width, height) {
  81576. var viewport = this._viewport;
  81577. // FIXME Why ?
  81578. viewport.style.display = 'none';
  81579. // Save input w/h
  81580. var opts = this._opts;
  81581. width != null && (opts.width = width);
  81582. height != null && (opts.height = height);
  81583. width = this._getSize(0);
  81584. height = this._getSize(1);
  81585. viewport.style.display = '';
  81586. if (this._width !== width || this._height !== height) {
  81587. this._width = width;
  81588. this._height = height;
  81589. var viewportStyle = viewport.style;
  81590. viewportStyle.width = width + 'px';
  81591. viewportStyle.height = height + 'px';
  81592. var svgRoot = this._svgRoot;
  81593. // Set width by 'svgRoot.width = width' is invalid
  81594. svgRoot.setAttribute('width', width);
  81595. svgRoot.setAttribute('height', height);
  81596. }
  81597. },
  81598. /**
  81599. * 获取绘图区域宽度
  81600. */
  81601. getWidth: function () {
  81602. return this._width;
  81603. },
  81604. /**
  81605. * 获取绘图区域高度
  81606. */
  81607. getHeight: function () {
  81608. return this._height;
  81609. },
  81610. _getSize: function (whIdx) {
  81611. var opts = this._opts;
  81612. var wh = ['width', 'height'][whIdx];
  81613. var cwh = ['clientWidth', 'clientHeight'][whIdx];
  81614. var plt = ['paddingLeft', 'paddingTop'][whIdx];
  81615. var prb = ['paddingRight', 'paddingBottom'][whIdx];
  81616. if (opts[wh] != null && opts[wh] !== 'auto') {
  81617. return parseFloat(opts[wh]);
  81618. }
  81619. var root = this.root;
  81620. // IE8 does not support getComputedStyle, but it use VML.
  81621. var stl = document.defaultView.getComputedStyle(root);
  81622. return (
  81623. (root[cwh] || parseInt10$2(stl[wh]) || parseInt10$2(root.style[wh]))
  81624. - (parseInt10$2(stl[plt]) || 0)
  81625. - (parseInt10$2(stl[prb]) || 0)
  81626. ) | 0;
  81627. },
  81628. dispose: function () {
  81629. this.root.innerHTML = '';
  81630. this._svgRoot =
  81631. this._viewport =
  81632. this.storage =
  81633. null;
  81634. },
  81635. clear: function () {
  81636. if (this._viewport) {
  81637. this.root.removeChild(this._viewport);
  81638. }
  81639. },
  81640. pathToDataUrl: function () {
  81641. this.refresh();
  81642. var html = this._svgRoot.outerHTML;
  81643. return 'data:image/svg+xml;charset=UTF-8,' + html;
  81644. }
  81645. };
  81646. // Not supported methods
  81647. function createMethodNotSupport$1(method) {
  81648. return function () {
  81649. zrLog('In SVG mode painter not support method "' + method + '"');
  81650. };
  81651. }
  81652. // Unsuppoted methods
  81653. each$1([
  81654. 'getLayer', 'insertLayer', 'eachLayer', 'eachBuiltinLayer',
  81655. 'eachOtherLayer', 'getLayers', 'modLayer', 'delLayer', 'clearLayer',
  81656. 'toDataURL', 'pathToImage'
  81657. ], function (name) {
  81658. SVGPainter.prototype[name] = createMethodNotSupport$1(name);
  81659. });
  81660. registerPainter('svg', SVGPainter);
  81661. /*
  81662. * Licensed to the Apache Software Foundation (ASF) under one
  81663. * or more contributor license agreements. See the NOTICE file
  81664. * distributed with this work for additional information
  81665. * regarding copyright ownership. The ASF licenses this file
  81666. * to you under the Apache License, Version 2.0 (the
  81667. * "License"); you may not use this file except in compliance
  81668. * with the License. You may obtain a copy of the License at
  81669. *
  81670. * http://www.apache.org/licenses/LICENSE-2.0
  81671. *
  81672. * Unless required by applicable law or agreed to in writing,
  81673. * software distributed under the License is distributed on an
  81674. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  81675. * KIND, either express or implied. See the License for the
  81676. * specific language governing permissions and limitations
  81677. * under the License.
  81678. */
  81679. // ----------------------------------------------
  81680. // All of the modules that are allowed to be
  81681. // imported are listed below.
  81682. //
  81683. // Users MUST NOT import other modules that are
  81684. // not included in this list.
  81685. // ----------------------------------------------
  81686. // ----------------
  81687. // Charts (series)
  81688. // ----------------
  81689. // All of the series types, for example:
  81690. // chart.setOption({
  81691. // series: [{
  81692. // type: 'line' // or 'bar', 'pie', ...
  81693. // }]
  81694. // });
  81695. // -------------------
  81696. // Coordinate systems
  81697. // -------------------
  81698. // All of the axis modules have been included in the
  81699. // coordinate system module below, do not need to
  81700. // make extra import.
  81701. // `cartesian` coordinate system. For some historical
  81702. // reasons, it is named as grid, for example:
  81703. // chart.setOption({
  81704. // grid: {...},
  81705. // xAxis: {...},
  81706. // yAxis: {...},
  81707. // series: [{...}]
  81708. // });
  81709. // `polar` coordinate system, for example:
  81710. // chart.setOption({
  81711. // polar: {...},
  81712. // radiusAxis: {...},
  81713. // angleAxis: {...},
  81714. // series: [{
  81715. // coordinateSystem: 'polar'
  81716. // }]
  81717. // });
  81718. // `geo` coordinate system, for example:
  81719. // chart.setOption({
  81720. // geo: {...},
  81721. // series: [{
  81722. // coordinateSystem: 'geo'
  81723. // }]
  81724. // });
  81725. // `singleAxis` coordinate system (notice, it is a coordinate system
  81726. // with only one axis, work for chart like theme river), for example:
  81727. // chart.setOption({
  81728. // singleAxis: {...}
  81729. // series: [{type: 'themeRiver', ...}]
  81730. // });
  81731. // `parallel` coordinate system, only work for parallel series, for example:
  81732. // chart.setOption({
  81733. // parallel: {...},
  81734. // parallelAxis: [{...}, ...],
  81735. // series: [{
  81736. // type: 'parallel'
  81737. // }]
  81738. // });
  81739. // `calendar` coordinate system. for example,
  81740. // chart.setOptionp({
  81741. // calendar: {...},
  81742. // series: [{
  81743. // coordinateSystem: 'calendar'
  81744. // }]
  81745. // );
  81746. // ------------------
  81747. // Other components
  81748. // ------------------
  81749. // `grapchic` component, for example:
  81750. // chart.setOption({
  81751. // graphic: {...}
  81752. // });
  81753. // `toolbox` component, for example:
  81754. // chart.setOption({
  81755. // toolbox: {...}
  81756. // });
  81757. // `tooltip` component, for example:
  81758. // chart.setOption({
  81759. // tooltip: {...}
  81760. // });
  81761. // `axisPointer` component, for example:
  81762. // chart.setOption({
  81763. // tooltip: {axisPointer: {...}, ...}
  81764. // });
  81765. // Or
  81766. // chart.setOption({
  81767. // axisPointer: {...}
  81768. // });
  81769. // `brush` component, for example:
  81770. // chart.setOption({
  81771. // brush: {...}
  81772. // });
  81773. // Or
  81774. // chart.setOption({
  81775. // tooltip: {feature: {brush: {...}}
  81776. // })
  81777. // `title` component, for example:
  81778. // chart.setOption({
  81779. // title: {...}
  81780. // });
  81781. // `timeline` component, for example:
  81782. // chart.setOption({
  81783. // timeline: {...}
  81784. // });
  81785. // `markPoint` component, for example:
  81786. // chart.setOption({
  81787. // series: [{markPoint: {...}}]
  81788. // });
  81789. // `markLine` component, for example:
  81790. // chart.setOption({
  81791. // series: [{markLine: {...}}]
  81792. // });
  81793. // `markArea` component, for example:
  81794. // chart.setOption({
  81795. // series: [{markArea: {...}}]
  81796. // });
  81797. // `legend` component scrollable, for example:
  81798. // chart.setOption({
  81799. // legend: {type: 'scroll'}
  81800. // });
  81801. // `legend` component not scrollable. for example:
  81802. // chart.setOption({
  81803. // legend: {...}
  81804. // });
  81805. // `dataZoom` component including both `dataZoomInside` and `dataZoomSlider`.
  81806. // `dataZoom` component providing drag, pinch, wheel behaviors
  81807. // inside coodinate system, for example:
  81808. // chart.setOption({
  81809. // dataZoom: {type: 'inside'}
  81810. // });
  81811. // `dataZoom` component providing a slider bar, for example:
  81812. // chart.setOption({
  81813. // dataZoom: {type: 'slider'}
  81814. // });
  81815. // `dataZoom` component including both `visualMapContinuous` and `visualMapPiecewise`.
  81816. // `visualMap` component providing continuous bar, for example:
  81817. // chart.setOption({
  81818. // visualMap: {type: 'continuous'}
  81819. // });
  81820. // `visualMap` component providing pieces bar, for example:
  81821. // chart.setOption({
  81822. // visualMap: {type: 'piecewise'}
  81823. // });
  81824. // -----------------
  81825. // Render engines
  81826. // -----------------
  81827. // Provide IE 6,7,8 compatibility.
  81828. // Render via SVG rather than canvas.
  81829. exports.version = version;
  81830. exports.dependencies = dependencies;
  81831. exports.PRIORITY = PRIORITY;
  81832. exports.init = init;
  81833. exports.connect = connect;
  81834. exports.disConnect = disConnect;
  81835. exports.disconnect = disconnect;
  81836. exports.dispose = dispose;
  81837. exports.getInstanceByDom = getInstanceByDom;
  81838. exports.getInstanceById = getInstanceById;
  81839. exports.registerTheme = registerTheme;
  81840. exports.registerPreprocessor = registerPreprocessor;
  81841. exports.registerProcessor = registerProcessor;
  81842. exports.registerPostUpdate = registerPostUpdate;
  81843. exports.registerAction = registerAction;
  81844. exports.registerCoordinateSystem = registerCoordinateSystem;
  81845. exports.getCoordinateSystemDimensions = getCoordinateSystemDimensions;
  81846. exports.registerLayout = registerLayout;
  81847. exports.registerVisual = registerVisual;
  81848. exports.registerLoading = registerLoading;
  81849. exports.extendComponentModel = extendComponentModel;
  81850. exports.extendComponentView = extendComponentView;
  81851. exports.extendSeriesModel = extendSeriesModel;
  81852. exports.extendChartView = extendChartView;
  81853. exports.setCanvasCreator = setCanvasCreator;
  81854. exports.registerMap = registerMap;
  81855. exports.getMap = getMap;
  81856. exports.dataTool = dataTool;
  81857. exports.zrender = zrender;
  81858. exports.number = number;
  81859. exports.format = format;
  81860. exports.throttle = throttle;
  81861. exports.helper = helper;
  81862. exports.matrix = matrix;
  81863. exports.vector = vector;
  81864. exports.color = color;
  81865. exports.parseGeoJSON = parseGeoJson$1;
  81866. exports.parseGeoJson = parseGeoJson;
  81867. exports.util = ecUtil;
  81868. exports.graphic = graphic$1;
  81869. exports.List = List;
  81870. exports.Model = Model;
  81871. exports.Axis = Axis;
  81872. exports.env = env$1;
  81873. })));
  81874. //# sourceMappingURL=echarts.js.map