echarts.js 2.3 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408394093941039411394123941339414394153941639417394183941939420394213942239423394243942539426394273942839429394303943139432394333943439435394363943739438394393944039441394423944339444394453944639447394483944939450394513945239453394543945539456394573945839459394603946139462394633946439465394663946739468394693947039471394723947339474394753947639477394783947939480394813948239483394843948539486394873948839489394903949139492394933949439495394963949739498394993950039501395023950339504395053950639507395083950939510395113951239513395143951539516395173951839519395203952139522395233952439525395263952739528395293953039531395323953339534395353953639537395383953939540395413954239543395443954539546395473954839549395503955139552395533955439555395563955739558395593956039561395623956339564395653956639567395683956939570395713957239573395743957539576395773957839579395803958139582395833958439585395863958739588395893959039591395923959339594395953959639597395983959939600396013960239603396043960539606396073960839609396103961139612396133961439615396163961739618396193962039621396223962339624396253962639627396283962939630396313963239633396343963539636396373963839639396403964139642396433964439645396463964739648396493965039651396523965339654396553965639657396583965939660396613966239663396643966539666396673966839669396703967139672396733967439675396763967739678396793968039681396823968339684396853968639687396883968939690396913969239693396943969539696396973969839699397003970139702397033970439705397063970739708397093971039711397123971339714397153971639717397183971939720397213972239723397243972539726397273972839729397303973139732397333973439735397363973739738397393974039741397423974339744397453974639747397483974939750397513975239753397543975539756397573975839759397603976139762397633976439765397663976739768397693977039771397723977339774397753977639777397783977939780397813978239783397843978539786397873978839789397903979139792397933979439795397963979739798397993980039801398023980339804398053980639807398083980939810398113981239813398143981539816398173981839819398203982139822398233982439825398263982739828398293983039831398323983339834398353983639837398383983939840398413984239843398443984539846398473984839849398503985139852398533985439855398563985739858398593986039861398623986339864398653986639867398683986939870398713987239873398743987539876398773987839879398803988139882398833988439885398863988739888398893989039891398923989339894398953989639897398983989939900399013990239903399043990539906399073990839909399103991139912399133991439915399163991739918399193992039921399223992339924399253992639927399283992939930399313993239933399343993539936399373993839939399403994139942399433994439945399463994739948399493995039951399523995339954399553995639957399583995939960399613996239963399643996539966399673996839969399703997139972399733997439975399763997739978399793998039981399823998339984399853998639987399883998939990399913999239993399943999539996399973999839999400004000140002400034000440005400064000740008400094001040011400124001340014400154001640017400184001940020400214002240023400244002540026400274002840029400304003140032400334003440035400364003740038400394004040041400424004340044400454004640047400484004940050400514005240053400544005540056400574005840059400604006140062400634006440065400664006740068400694007040071400724007340074400754007640077400784007940080400814008240083400844008540086400874008840089400904009140092400934009440095400964009740098400994010040101401024010340104401054010640107401084010940110401114011240113401144011540116401174011840119401204012140122401234012440125401264012740128401294013040131401324013340134401354013640137401384013940140401414014240143401444014540146401474014840149401504015140152401534015440155401564015740158401594016040161401624016340164401654016640167401684016940170401714017240173401744017540176401774017840179401804018140182401834018440185401864018740188401894019040191401924019340194401954019640197401984019940200402014020240203402044020540206402074020840209402104021140212402134021440215402164021740218402194022040221402224022340224402254022640227402284022940230402314023240233402344023540236402374023840239402404024140242402434024440245402464024740248402494025040251402524025340254402554025640257402584025940260402614026240263402644026540266402674026840269402704027140272402734027440275402764027740278402794028040281402824028340284402854028640287402884028940290402914029240293402944029540296402974029840299403004030140302403034030440305403064030740308403094031040311403124031340314403154031640317403184031940320403214032240323403244032540326403274032840329403304033140332403334033440335403364033740338403394034040341403424034340344403454034640347403484034940350403514035240353403544035540356403574035840359403604036140362403634036440365403664036740368403694037040371403724037340374403754037640377403784037940380403814038240383403844038540386403874038840389403904039140392403934039440395403964039740398403994040040401404024040340404404054040640407404084040940410404114041240413404144041540416404174041840419404204042140422404234042440425404264042740428404294043040431404324043340434404354043640437404384043940440404414044240443404444044540446404474044840449404504045140452404534045440455404564045740458404594046040461404624046340464404654046640467404684046940470404714047240473404744047540476404774047840479404804048140482404834048440485404864048740488404894049040491404924049340494404954049640497404984049940500405014050240503405044050540506405074050840509405104051140512405134051440515405164051740518405194052040521405224052340524405254052640527405284052940530405314053240533405344053540536405374053840539405404054140542405434054440545405464054740548405494055040551405524055340554405554055640557405584055940560405614056240563405644056540566405674056840569405704057140572405734057440575405764057740578405794058040581405824058340584405854058640587405884058940590405914059240593405944059540596405974059840599406004060140602406034060440605406064060740608406094061040611406124061340614406154061640617406184061940620406214062240623406244062540626406274062840629406304063140632406334063440635406364063740638406394064040641406424064340644406454064640647406484064940650406514065240653406544065540656406574065840659406604066140662406634066440665406664066740668406694067040671406724067340674406754067640677406784067940680406814068240683406844068540686406874068840689406904069140692406934069440695406964069740698406994070040701407024070340704407054070640707407084070940710407114071240713407144071540716407174071840719407204072140722407234072440725407264072740728407294073040731407324073340734407354073640737407384073940740407414074240743407444074540746407474074840749407504075140752407534075440755407564075740758407594076040761407624076340764407654076640767407684076940770407714077240773407744077540776407774077840779407804078140782407834078440785407864078740788407894079040791407924079340794407954079640797407984079940800408014080240803408044080540806408074080840809408104081140812408134081440815408164081740818408194082040821408224082340824408254082640827408284082940830408314083240833408344083540836408374083840839408404084140842408434084440845408464084740848408494085040851408524085340854408554085640857408584085940860408614086240863408644086540866408674086840869408704087140872408734087440875408764087740878408794088040881408824088340884408854088640887408884088940890408914089240893408944089540896408974089840899409004090140902409034090440905409064090740908409094091040911409124091340914409154091640917409184091940920409214092240923409244092540926409274092840929409304093140932409334093440935409364093740938409394094040941409424094340944409454094640947409484094940950409514095240953409544095540956409574095840959409604096140962409634096440965409664096740968409694097040971409724097340974409754097640977409784097940980409814098240983409844098540986409874098840989409904099140992409934099440995409964099740998409994100041001410024100341004410054100641007410084100941010410114101241013410144101541016410174101841019410204102141022410234102441025410264102741028410294103041031410324103341034410354103641037410384103941040410414104241043410444104541046410474104841049410504105141052410534105441055410564105741058410594106041061410624106341064410654106641067410684106941070410714107241073410744107541076410774107841079410804108141082410834108441085410864108741088410894109041091410924109341094410954109641097410984109941100411014110241103411044110541106411074110841109411104111141112411134111441115411164111741118411194112041121411224112341124411254112641127411284112941130411314113241133411344113541136411374113841139411404114141142411434114441145411464114741148411494115041151411524115341154411554115641157411584115941160411614116241163411644116541166411674116841169411704117141172411734117441175411764117741178411794118041181411824118341184411854118641187411884118941190411914119241193411944119541196411974119841199412004120141202412034120441205412064120741208412094121041211412124121341214412154121641217412184121941220412214122241223412244122541226412274122841229412304123141232412334123441235412364123741238412394124041241412424124341244412454124641247412484124941250412514125241253412544125541256412574125841259412604126141262412634126441265412664126741268412694127041271412724127341274412754127641277412784127941280412814128241283412844128541286412874128841289412904129141292412934129441295412964129741298412994130041301413024130341304413054130641307413084130941310413114131241313413144131541316413174131841319413204132141322413234132441325413264132741328413294133041331413324133341334413354133641337413384133941340413414134241343413444134541346413474134841349413504135141352413534135441355413564135741358413594136041361413624136341364413654136641367413684136941370413714137241373413744137541376413774137841379413804138141382413834138441385413864138741388413894139041391413924139341394413954139641397413984139941400414014140241403414044140541406414074140841409414104141141412414134141441415414164141741418414194142041421414224142341424414254142641427414284142941430414314143241433414344143541436414374143841439414404144141442414434144441445414464144741448414494145041451414524145341454414554145641457414584145941460414614146241463414644146541466414674146841469414704147141472414734147441475414764147741478414794148041481414824148341484414854148641487414884148941490414914149241493414944149541496414974149841499415004150141502415034150441505415064150741508415094151041511415124151341514415154151641517415184151941520415214152241523415244152541526415274152841529415304153141532415334153441535415364153741538415394154041541415424154341544415454154641547415484154941550415514155241553415544155541556415574155841559415604156141562415634156441565415664156741568415694157041571415724157341574415754157641577415784157941580415814158241583415844158541586415874158841589415904159141592415934159441595415964159741598415994160041601416024160341604416054160641607416084160941610416114161241613416144161541616416174161841619416204162141622416234162441625416264162741628416294163041631416324163341634416354163641637416384163941640416414164241643416444164541646416474164841649416504165141652416534165441655416564165741658416594166041661416624166341664416654166641667416684166941670416714167241673416744167541676416774167841679416804168141682416834168441685416864168741688416894169041691416924169341694416954169641697416984169941700417014170241703417044170541706417074170841709417104171141712417134171441715417164171741718417194172041721417224172341724417254172641727417284172941730417314173241733417344173541736417374173841739417404174141742417434174441745417464174741748417494175041751417524175341754417554175641757417584175941760417614176241763417644176541766417674176841769417704177141772417734177441775417764177741778417794178041781417824178341784417854178641787417884178941790417914179241793417944179541796417974179841799418004180141802418034180441805418064180741808418094181041811418124181341814418154181641817418184181941820418214182241823418244182541826418274182841829418304183141832418334183441835418364183741838418394184041841418424184341844418454184641847418484184941850418514185241853418544185541856418574185841859418604186141862418634186441865418664186741868418694187041871418724187341874418754187641877418784187941880418814188241883418844188541886418874188841889418904189141892418934189441895418964189741898418994190041901419024190341904419054190641907419084190941910419114191241913419144191541916419174191841919419204192141922419234192441925419264192741928419294193041931419324193341934419354193641937419384193941940419414194241943419444194541946419474194841949419504195141952419534195441955419564195741958419594196041961419624196341964419654196641967419684196941970419714197241973419744197541976419774197841979419804198141982419834198441985419864198741988419894199041991419924199341994419954199641997419984199942000420014200242003420044200542006420074200842009420104201142012420134201442015420164201742018420194202042021420224202342024420254202642027420284202942030420314203242033420344203542036420374203842039420404204142042420434204442045420464204742048420494205042051420524205342054420554205642057420584205942060420614206242063420644206542066420674206842069420704207142072420734207442075420764207742078420794208042081420824208342084420854208642087420884208942090420914209242093420944209542096420974209842099421004210142102421034210442105421064210742108421094211042111421124211342114421154211642117421184211942120421214212242123421244212542126421274212842129421304213142132421334213442135421364213742138421394214042141421424214342144421454214642147421484214942150421514215242153421544215542156421574215842159421604216142162421634216442165421664216742168421694217042171421724217342174421754217642177421784217942180421814218242183421844218542186421874218842189421904219142192421934219442195421964219742198421994220042201422024220342204422054220642207422084220942210422114221242213422144221542216422174221842219422204222142222422234222442225422264222742228422294223042231422324223342234422354223642237422384223942240422414224242243422444224542246422474224842249422504225142252422534225442255422564225742258422594226042261422624226342264422654226642267422684226942270422714227242273422744227542276422774227842279422804228142282422834228442285422864228742288422894229042291422924229342294422954229642297422984229942300423014230242303423044230542306423074230842309423104231142312423134231442315423164231742318423194232042321423224232342324423254232642327423284232942330423314233242333423344233542336423374233842339423404234142342423434234442345423464234742348423494235042351423524235342354423554235642357423584235942360423614236242363423644236542366423674236842369423704237142372423734237442375423764237742378423794238042381423824238342384423854238642387423884238942390423914239242393423944239542396423974239842399424004240142402424034240442405424064240742408424094241042411424124241342414424154241642417424184241942420424214242242423424244242542426424274242842429424304243142432424334243442435424364243742438424394244042441424424244342444424454244642447424484244942450424514245242453424544245542456424574245842459424604246142462424634246442465424664246742468424694247042471424724247342474424754247642477424784247942480424814248242483424844248542486424874248842489424904249142492424934249442495424964249742498424994250042501425024250342504425054250642507425084250942510425114251242513425144251542516425174251842519425204252142522425234252442525425264252742528425294253042531425324253342534425354253642537425384253942540425414254242543425444254542546425474254842549425504255142552425534255442555425564255742558425594256042561425624256342564425654256642567425684256942570425714257242573425744257542576425774257842579425804258142582425834258442585425864258742588425894259042591425924259342594425954259642597425984259942600426014260242603426044260542606426074260842609426104261142612426134261442615426164261742618426194262042621426224262342624426254262642627426284262942630426314263242633426344263542636426374263842639426404264142642426434264442645426464264742648426494265042651426524265342654426554265642657426584265942660426614266242663426644266542666426674266842669426704267142672426734267442675426764267742678426794268042681426824268342684426854268642687426884268942690426914269242693426944269542696426974269842699427004270142702427034270442705427064270742708427094271042711427124271342714427154271642717427184271942720427214272242723427244272542726427274272842729427304273142732427334273442735427364273742738427394274042741427424274342744427454274642747427484274942750427514275242753427544275542756427574275842759427604276142762427634276442765427664276742768427694277042771427724277342774427754277642777427784277942780427814278242783427844278542786427874278842789427904279142792427934279442795427964279742798427994280042801428024280342804428054280642807428084280942810428114281242813428144281542816428174281842819428204282142822428234282442825428264282742828428294283042831428324283342834428354283642837428384283942840428414284242843428444284542846428474284842849428504285142852428534285442855428564285742858428594286042861428624286342864428654286642867428684286942870428714287242873428744287542876428774287842879428804288142882428834288442885428864288742888428894289042891428924289342894428954289642897428984289942900429014290242903429044290542906429074290842909429104291142912429134291442915429164291742918429194292042921429224292342924429254292642927429284292942930429314293242933429344293542936429374293842939429404294142942429434294442945429464294742948429494295042951429524295342954429554295642957429584295942960429614296242963429644296542966429674296842969429704297142972429734297442975429764297742978429794298042981429824298342984429854298642987429884298942990429914299242993429944299542996429974299842999430004300143002430034300443005430064300743008430094301043011430124301343014430154301643017430184301943020430214302243023430244302543026430274302843029430304303143032430334303443035430364303743038430394304043041430424304343044430454304643047430484304943050430514305243053430544305543056430574305843059430604306143062430634306443065430664306743068430694307043071430724307343074430754307643077430784307943080430814308243083430844308543086430874308843089430904309143092430934309443095430964309743098430994310043101431024310343104431054310643107431084310943110431114311243113431144311543116431174311843119431204312143122431234312443125431264312743128431294313043131431324313343134431354313643137431384313943140431414314243143431444314543146431474314843149431504315143152431534315443155431564315743158431594316043161431624316343164431654316643167431684316943170431714317243173431744317543176431774317843179431804318143182431834318443185431864318743188431894319043191431924319343194431954319643197431984319943200432014320243203432044320543206432074320843209432104321143212432134321443215432164321743218432194322043221432224322343224432254322643227432284322943230432314323243233432344323543236432374323843239432404324143242432434324443245432464324743248432494325043251432524325343254432554325643257432584325943260432614326243263432644326543266432674326843269432704327143272432734327443275432764327743278432794328043281432824328343284432854328643287432884328943290432914329243293432944329543296432974329843299433004330143302433034330443305433064330743308433094331043311433124331343314433154331643317433184331943320433214332243323433244332543326433274332843329433304333143332433334333443335433364333743338433394334043341433424334343344433454334643347433484334943350433514335243353433544335543356433574335843359433604336143362433634336443365433664336743368433694337043371433724337343374433754337643377433784337943380433814338243383433844338543386433874338843389433904339143392433934339443395433964339743398433994340043401434024340343404434054340643407434084340943410434114341243413434144341543416434174341843419434204342143422434234342443425434264342743428434294343043431434324343343434434354343643437434384343943440434414344243443434444344543446434474344843449434504345143452434534345443455434564345743458434594346043461434624346343464434654346643467434684346943470434714347243473434744347543476434774347843479434804348143482434834348443485434864348743488434894349043491434924349343494434954349643497434984349943500435014350243503435044350543506435074350843509435104351143512435134351443515435164351743518435194352043521435224352343524435254352643527435284352943530435314353243533435344353543536435374353843539435404354143542435434354443545435464354743548435494355043551435524355343554435554355643557435584355943560435614356243563435644356543566435674356843569435704357143572435734357443575435764357743578435794358043581435824358343584435854358643587435884358943590435914359243593435944359543596435974359843599436004360143602436034360443605436064360743608436094361043611436124361343614436154361643617436184361943620436214362243623436244362543626436274362843629436304363143632436334363443635436364363743638436394364043641436424364343644436454364643647436484364943650436514365243653436544365543656436574365843659436604366143662436634366443665436664366743668436694367043671436724367343674436754367643677436784367943680436814368243683436844368543686436874368843689436904369143692436934369443695436964369743698436994370043701437024370343704437054370643707437084370943710437114371243713437144371543716437174371843719437204372143722437234372443725437264372743728437294373043731437324373343734437354373643737437384373943740437414374243743437444374543746437474374843749437504375143752437534375443755437564375743758437594376043761437624376343764437654376643767437684376943770437714377243773437744377543776437774377843779437804378143782437834378443785437864378743788437894379043791437924379343794437954379643797437984379943800438014380243803438044380543806438074380843809438104381143812438134381443815438164381743818438194382043821438224382343824438254382643827438284382943830438314383243833438344383543836438374383843839438404384143842438434384443845438464384743848438494385043851438524385343854438554385643857438584385943860438614386243863438644386543866438674386843869438704387143872438734387443875438764387743878438794388043881438824388343884438854388643887438884388943890438914389243893438944389543896438974389843899439004390143902439034390443905439064390743908439094391043911439124391343914439154391643917439184391943920439214392243923439244392543926439274392843929439304393143932439334393443935439364393743938439394394043941439424394343944439454394643947439484394943950439514395243953439544395543956439574395843959439604396143962439634396443965439664396743968439694397043971439724397343974439754397643977439784397943980439814398243983439844398543986439874398843989439904399143992439934399443995439964399743998439994400044001440024400344004440054400644007440084400944010440114401244013440144401544016440174401844019440204402144022440234402444025440264402744028440294403044031440324403344034440354403644037440384403944040440414404244043440444404544046440474404844049440504405144052440534405444055440564405744058440594406044061440624406344064440654406644067440684406944070440714407244073440744407544076440774407844079440804408144082440834408444085440864408744088440894409044091440924409344094440954409644097440984409944100441014410244103441044410544106441074410844109441104411144112441134411444115441164411744118441194412044121441224412344124441254412644127441284412944130441314413244133441344413544136441374413844139441404414144142441434414444145441464414744148441494415044151441524415344154441554415644157441584415944160441614416244163441644416544166441674416844169441704417144172441734417444175441764417744178441794418044181441824418344184441854418644187441884418944190441914419244193441944419544196441974419844199442004420144202442034420444205442064420744208442094421044211442124421344214442154421644217442184421944220442214422244223442244422544226442274422844229442304423144232442334423444235442364423744238442394424044241442424424344244442454424644247442484424944250442514425244253442544425544256442574425844259442604426144262442634426444265442664426744268442694427044271442724427344274442754427644277442784427944280442814428244283442844428544286442874428844289442904429144292442934429444295442964429744298442994430044301443024430344304443054430644307443084430944310443114431244313443144431544316443174431844319443204432144322443234432444325443264432744328443294433044331443324433344334443354433644337443384433944340443414434244343443444434544346443474434844349443504435144352443534435444355443564435744358443594436044361443624436344364443654436644367443684436944370443714437244373443744437544376443774437844379443804438144382443834438444385443864438744388443894439044391443924439344394443954439644397443984439944400444014440244403444044440544406444074440844409444104441144412444134441444415444164441744418444194442044421444224442344424444254442644427444284442944430444314443244433444344443544436444374443844439444404444144442444434444444445444464444744448444494445044451444524445344454444554445644457444584445944460444614446244463444644446544466444674446844469444704447144472444734447444475444764447744478444794448044481444824448344484444854448644487444884448944490444914449244493444944449544496444974449844499445004450144502445034450444505445064450744508445094451044511445124451344514445154451644517445184451944520445214452244523445244452544526445274452844529445304453144532445334453444535445364453744538445394454044541445424454344544445454454644547445484454944550445514455244553445544455544556445574455844559445604456144562445634456444565445664456744568445694457044571445724457344574445754457644577445784457944580445814458244583445844458544586445874458844589445904459144592445934459444595445964459744598445994460044601446024460344604446054460644607446084460944610446114461244613446144461544616446174461844619446204462144622446234462444625446264462744628446294463044631446324463344634446354463644637446384463944640446414464244643446444464544646446474464844649446504465144652446534465444655446564465744658446594466044661446624466344664446654466644667446684466944670446714467244673446744467544676446774467844679446804468144682446834468444685446864468744688446894469044691446924469344694446954469644697446984469944700447014470244703447044470544706447074470844709447104471144712447134471444715447164471744718447194472044721447224472344724447254472644727447284472944730447314473244733447344473544736447374473844739447404474144742447434474444745447464474744748447494475044751447524475344754447554475644757447584475944760447614476244763447644476544766447674476844769447704477144772447734477444775447764477744778447794478044781447824478344784447854478644787447884478944790447914479244793447944479544796447974479844799448004480144802448034480444805448064480744808448094481044811448124481344814448154481644817448184481944820448214482244823448244482544826448274482844829448304483144832448334483444835448364483744838448394484044841448424484344844448454484644847448484484944850448514485244853448544485544856448574485844859448604486144862448634486444865448664486744868448694487044871448724487344874448754487644877448784487944880448814488244883448844488544886448874488844889448904489144892448934489444895448964489744898448994490044901449024490344904449054490644907449084490944910449114491244913449144491544916449174491844919449204492144922449234492444925449264492744928449294493044931449324493344934449354493644937449384493944940449414494244943449444494544946449474494844949449504495144952449534495444955449564495744958449594496044961449624496344964449654496644967449684496944970449714497244973449744497544976449774497844979449804498144982449834498444985449864498744988449894499044991449924499344994449954499644997449984499945000450014500245003450044500545006450074500845009450104501145012450134501445015450164501745018450194502045021450224502345024450254502645027450284502945030450314503245033450344503545036450374503845039450404504145042450434504445045450464504745048450494505045051450524505345054450554505645057450584505945060450614506245063450644506545066450674506845069450704507145072450734507445075450764507745078450794508045081450824508345084450854508645087450884508945090450914509245093450944509545096450974509845099451004510145102451034510445105451064510745108451094511045111451124511345114451154511645117451184511945120451214512245123451244512545126451274512845129451304513145132451334513445135451364513745138451394514045141451424514345144451454514645147451484514945150451514515245153451544515545156451574515845159451604516145162451634516445165451664516745168451694517045171451724517345174451754517645177451784517945180451814518245183451844518545186451874518845189451904519145192451934519445195451964519745198451994520045201452024520345204452054520645207452084520945210452114521245213452144521545216452174521845219452204522145222452234522445225452264522745228452294523045231452324523345234452354523645237452384523945240452414524245243452444524545246452474524845249452504525145252452534525445255452564525745258452594526045261452624526345264452654526645267452684526945270452714527245273452744527545276452774527845279452804528145282452834528445285452864528745288452894529045291452924529345294452954529645297452984529945300453014530245303453044530545306453074530845309453104531145312453134531445315453164531745318453194532045321453224532345324453254532645327453284532945330453314533245333453344533545336453374533845339453404534145342453434534445345453464534745348453494535045351453524535345354453554535645357453584535945360453614536245363453644536545366453674536845369453704537145372453734537445375453764537745378453794538045381453824538345384453854538645387453884538945390453914539245393453944539545396453974539845399454004540145402454034540445405454064540745408454094541045411454124541345414454154541645417454184541945420454214542245423454244542545426454274542845429454304543145432454334543445435454364543745438454394544045441454424544345444454454544645447454484544945450454514545245453454544545545456454574545845459454604546145462454634546445465454664546745468454694547045471454724547345474454754547645477454784547945480454814548245483454844548545486454874548845489454904549145492454934549445495454964549745498454994550045501455024550345504455054550645507455084550945510455114551245513455144551545516455174551845519455204552145522455234552445525455264552745528455294553045531455324553345534455354553645537455384553945540455414554245543455444554545546455474554845549455504555145552455534555445555455564555745558455594556045561455624556345564455654556645567455684556945570455714557245573455744557545576455774557845579455804558145582455834558445585455864558745588455894559045591455924559345594455954559645597455984559945600456014560245603456044560545606456074560845609456104561145612456134561445615456164561745618456194562045621456224562345624456254562645627456284562945630456314563245633456344563545636456374563845639456404564145642456434564445645456464564745648456494565045651456524565345654456554565645657456584565945660456614566245663456644566545666456674566845669456704567145672456734567445675456764567745678456794568045681456824568345684456854568645687456884568945690456914569245693456944569545696456974569845699457004570145702457034570445705457064570745708457094571045711457124571345714457154571645717457184571945720457214572245723457244572545726457274572845729457304573145732457334573445735457364573745738457394574045741457424574345744457454574645747457484574945750457514575245753457544575545756457574575845759457604576145762457634576445765457664576745768457694577045771457724577345774457754577645777457784577945780457814578245783457844578545786457874578845789457904579145792457934579445795457964579745798457994580045801458024580345804458054580645807458084580945810458114581245813458144581545816458174581845819458204582145822458234582445825458264582745828458294583045831458324583345834458354583645837458384583945840458414584245843458444584545846458474584845849458504585145852458534585445855458564585745858458594586045861458624586345864458654586645867458684586945870458714587245873458744587545876458774587845879458804588145882458834588445885458864588745888458894589045891458924589345894458954589645897458984589945900459014590245903459044590545906459074590845909459104591145912459134591445915459164591745918459194592045921459224592345924459254592645927459284592945930459314593245933459344593545936459374593845939459404594145942459434594445945459464594745948459494595045951459524595345954459554595645957459584595945960459614596245963459644596545966459674596845969459704597145972459734597445975459764597745978459794598045981459824598345984459854598645987459884598945990459914599245993459944599545996459974599845999460004600146002460034600446005460064600746008460094601046011460124601346014460154601646017460184601946020460214602246023460244602546026460274602846029460304603146032460334603446035460364603746038460394604046041460424604346044460454604646047460484604946050460514605246053460544605546056460574605846059460604606146062460634606446065460664606746068460694607046071460724607346074460754607646077460784607946080460814608246083460844608546086460874608846089460904609146092460934609446095460964609746098460994610046101461024610346104461054610646107461084610946110461114611246113461144611546116461174611846119461204612146122461234612446125461264612746128461294613046131461324613346134461354613646137461384613946140461414614246143461444614546146461474614846149461504615146152461534615446155461564615746158461594616046161461624616346164461654616646167461684616946170461714617246173461744617546176461774617846179461804618146182461834618446185461864618746188461894619046191461924619346194461954619646197461984619946200462014620246203462044620546206462074620846209462104621146212462134621446215462164621746218462194622046221462224622346224462254622646227462284622946230462314623246233462344623546236462374623846239462404624146242462434624446245462464624746248462494625046251462524625346254462554625646257462584625946260462614626246263462644626546266462674626846269462704627146272462734627446275462764627746278462794628046281462824628346284462854628646287462884628946290462914629246293462944629546296462974629846299463004630146302463034630446305463064630746308463094631046311463124631346314463154631646317463184631946320463214632246323463244632546326463274632846329463304633146332463334633446335463364633746338463394634046341463424634346344463454634646347463484634946350463514635246353463544635546356463574635846359463604636146362463634636446365463664636746368463694637046371463724637346374463754637646377463784637946380463814638246383463844638546386463874638846389463904639146392463934639446395463964639746398463994640046401464024640346404464054640646407464084640946410464114641246413464144641546416464174641846419464204642146422464234642446425464264642746428464294643046431464324643346434464354643646437464384643946440464414644246443464444644546446464474644846449464504645146452464534645446455464564645746458464594646046461464624646346464464654646646467464684646946470464714647246473464744647546476464774647846479464804648146482464834648446485464864648746488464894649046491464924649346494464954649646497464984649946500465014650246503465044650546506465074650846509465104651146512465134651446515465164651746518465194652046521465224652346524465254652646527465284652946530465314653246533465344653546536465374653846539465404654146542465434654446545465464654746548465494655046551465524655346554465554655646557465584655946560465614656246563465644656546566465674656846569465704657146572465734657446575465764657746578465794658046581465824658346584465854658646587465884658946590465914659246593465944659546596465974659846599466004660146602466034660446605466064660746608466094661046611466124661346614466154661646617466184661946620466214662246623466244662546626466274662846629466304663146632466334663446635466364663746638466394664046641466424664346644466454664646647466484664946650466514665246653466544665546656466574665846659466604666146662466634666446665466664666746668466694667046671466724667346674466754667646677466784667946680466814668246683466844668546686466874668846689466904669146692466934669446695466964669746698466994670046701467024670346704467054670646707467084670946710467114671246713467144671546716467174671846719467204672146722467234672446725467264672746728467294673046731467324673346734467354673646737467384673946740467414674246743467444674546746467474674846749467504675146752467534675446755467564675746758467594676046761467624676346764467654676646767467684676946770467714677246773467744677546776467774677846779467804678146782467834678446785467864678746788467894679046791467924679346794467954679646797467984679946800468014680246803468044680546806468074680846809468104681146812468134681446815468164681746818468194682046821468224682346824468254682646827468284682946830468314683246833468344683546836468374683846839468404684146842468434684446845468464684746848468494685046851468524685346854468554685646857468584685946860468614686246863468644686546866468674686846869468704687146872468734687446875468764687746878468794688046881468824688346884468854688646887468884688946890468914689246893468944689546896468974689846899469004690146902469034690446905469064690746908469094691046911469124691346914469154691646917469184691946920469214692246923469244692546926469274692846929469304693146932469334693446935469364693746938469394694046941469424694346944469454694646947469484694946950469514695246953469544695546956469574695846959469604696146962469634696446965469664696746968469694697046971469724697346974469754697646977469784697946980469814698246983469844698546986469874698846989469904699146992469934699446995469964699746998469994700047001470024700347004470054700647007470084700947010470114701247013470144701547016470174701847019470204702147022470234702447025470264702747028470294703047031470324703347034470354703647037470384703947040470414704247043470444704547046470474704847049470504705147052470534705447055470564705747058470594706047061470624706347064470654706647067470684706947070470714707247073470744707547076470774707847079470804708147082470834708447085470864708747088470894709047091470924709347094470954709647097470984709947100471014710247103471044710547106471074710847109471104711147112471134711447115471164711747118471194712047121471224712347124471254712647127471284712947130471314713247133471344713547136471374713847139471404714147142471434714447145471464714747148471494715047151471524715347154471554715647157471584715947160471614716247163471644716547166471674716847169471704717147172471734717447175471764717747178471794718047181471824718347184471854718647187471884718947190471914719247193471944719547196471974719847199472004720147202472034720447205472064720747208472094721047211472124721347214472154721647217472184721947220472214722247223472244722547226472274722847229472304723147232472334723447235472364723747238472394724047241472424724347244472454724647247472484724947250472514725247253472544725547256472574725847259472604726147262472634726447265472664726747268472694727047271472724727347274472754727647277472784727947280472814728247283472844728547286472874728847289472904729147292472934729447295472964729747298472994730047301473024730347304473054730647307473084730947310473114731247313473144731547316473174731847319473204732147322473234732447325473264732747328473294733047331473324733347334473354733647337473384733947340473414734247343473444734547346473474734847349473504735147352473534735447355473564735747358473594736047361473624736347364473654736647367473684736947370473714737247373473744737547376473774737847379473804738147382473834738447385473864738747388473894739047391473924739347394473954739647397473984739947400474014740247403474044740547406474074740847409474104741147412474134741447415474164741747418474194742047421474224742347424474254742647427474284742947430474314743247433474344743547436474374743847439474404744147442474434744447445474464744747448474494745047451474524745347454474554745647457474584745947460474614746247463474644746547466474674746847469474704747147472474734747447475474764747747478474794748047481474824748347484474854748647487474884748947490474914749247493474944749547496474974749847499475004750147502475034750447505475064750747508475094751047511475124751347514475154751647517475184751947520475214752247523475244752547526475274752847529475304753147532475334753447535475364753747538475394754047541475424754347544475454754647547475484754947550475514755247553475544755547556475574755847559475604756147562475634756447565475664756747568475694757047571475724757347574475754757647577475784757947580475814758247583475844758547586475874758847589475904759147592475934759447595475964759747598475994760047601476024760347604476054760647607476084760947610476114761247613476144761547616476174761847619476204762147622476234762447625476264762747628476294763047631476324763347634476354763647637476384763947640476414764247643476444764547646476474764847649476504765147652476534765447655476564765747658476594766047661476624766347664476654766647667476684766947670476714767247673476744767547676476774767847679476804768147682476834768447685476864768747688476894769047691476924769347694476954769647697476984769947700477014770247703477044770547706477074770847709477104771147712477134771447715477164771747718477194772047721477224772347724477254772647727477284772947730477314773247733477344773547736477374773847739477404774147742477434774447745477464774747748477494775047751477524775347754477554775647757477584775947760477614776247763477644776547766477674776847769477704777147772477734777447775477764777747778477794778047781477824778347784477854778647787477884778947790477914779247793477944779547796477974779847799478004780147802478034780447805478064780747808478094781047811478124781347814478154781647817478184781947820478214782247823478244782547826478274782847829478304783147832478334783447835478364783747838478394784047841478424784347844478454784647847478484784947850478514785247853478544785547856478574785847859478604786147862478634786447865478664786747868478694787047871478724787347874478754787647877478784787947880478814788247883478844788547886478874788847889478904789147892478934789447895478964789747898478994790047901479024790347904479054790647907479084790947910479114791247913479144791547916479174791847919479204792147922479234792447925479264792747928479294793047931479324793347934479354793647937479384793947940479414794247943479444794547946479474794847949479504795147952479534795447955479564795747958479594796047961479624796347964479654796647967479684796947970479714797247973479744797547976479774797847979479804798147982479834798447985479864798747988479894799047991479924799347994479954799647997479984799948000480014800248003480044800548006480074800848009480104801148012480134801448015480164801748018480194802048021480224802348024480254802648027480284802948030480314803248033480344803548036480374803848039480404804148042480434804448045480464804748048480494805048051480524805348054480554805648057480584805948060480614806248063480644806548066480674806848069480704807148072480734807448075480764807748078480794808048081480824808348084480854808648087480884808948090480914809248093480944809548096480974809848099481004810148102481034810448105481064810748108481094811048111481124811348114481154811648117481184811948120481214812248123481244812548126481274812848129481304813148132481334813448135481364813748138481394814048141481424814348144481454814648147481484814948150481514815248153481544815548156481574815848159481604816148162481634816448165481664816748168481694817048171481724817348174481754817648177481784817948180481814818248183481844818548186481874818848189481904819148192481934819448195481964819748198481994820048201482024820348204482054820648207482084820948210482114821248213482144821548216482174821848219482204822148222482234822448225482264822748228482294823048231482324823348234482354823648237482384823948240482414824248243482444824548246482474824848249482504825148252482534825448255482564825748258482594826048261482624826348264482654826648267482684826948270482714827248273482744827548276482774827848279482804828148282482834828448285482864828748288482894829048291482924829348294482954829648297482984829948300483014830248303483044830548306483074830848309483104831148312483134831448315483164831748318483194832048321483224832348324483254832648327483284832948330483314833248333483344833548336483374833848339483404834148342483434834448345483464834748348483494835048351483524835348354483554835648357483584835948360483614836248363483644836548366483674836848369483704837148372483734837448375483764837748378483794838048381483824838348384483854838648387483884838948390483914839248393483944839548396483974839848399484004840148402484034840448405484064840748408484094841048411484124841348414484154841648417484184841948420484214842248423484244842548426484274842848429484304843148432484334843448435484364843748438484394844048441484424844348444484454844648447484484844948450484514845248453484544845548456484574845848459484604846148462484634846448465484664846748468484694847048471484724847348474484754847648477484784847948480484814848248483484844848548486484874848848489484904849148492484934849448495484964849748498484994850048501485024850348504485054850648507485084850948510485114851248513485144851548516485174851848519485204852148522485234852448525485264852748528485294853048531485324853348534485354853648537485384853948540485414854248543485444854548546485474854848549485504855148552485534855448555485564855748558485594856048561485624856348564485654856648567485684856948570485714857248573485744857548576485774857848579485804858148582485834858448585485864858748588485894859048591485924859348594485954859648597485984859948600486014860248603486044860548606486074860848609486104861148612486134861448615486164861748618486194862048621486224862348624486254862648627486284862948630486314863248633486344863548636486374863848639486404864148642486434864448645486464864748648486494865048651486524865348654486554865648657486584865948660486614866248663486644866548666486674866848669486704867148672486734867448675486764867748678486794868048681486824868348684486854868648687486884868948690486914869248693486944869548696486974869848699487004870148702487034870448705487064870748708487094871048711487124871348714487154871648717487184871948720487214872248723487244872548726487274872848729487304873148732487334873448735487364873748738487394874048741487424874348744487454874648747487484874948750487514875248753487544875548756487574875848759487604876148762487634876448765487664876748768487694877048771487724877348774487754877648777487784877948780487814878248783487844878548786487874878848789487904879148792487934879448795487964879748798487994880048801488024880348804488054880648807488084880948810488114881248813488144881548816488174881848819488204882148822488234882448825488264882748828488294883048831488324883348834488354883648837488384883948840488414884248843488444884548846488474884848849488504885148852488534885448855488564885748858488594886048861488624886348864488654886648867488684886948870488714887248873488744887548876488774887848879488804888148882488834888448885488864888748888488894889048891488924889348894488954889648897488984889948900489014890248903489044890548906489074890848909489104891148912489134891448915489164891748918489194892048921489224892348924489254892648927489284892948930489314893248933489344893548936489374893848939489404894148942489434894448945489464894748948489494895048951489524895348954489554895648957489584895948960489614896248963489644896548966489674896848969489704897148972489734897448975489764897748978489794898048981489824898348984489854898648987489884898948990489914899248993489944899548996489974899848999490004900149002490034900449005490064900749008490094901049011490124901349014490154901649017490184901949020490214902249023490244902549026490274902849029490304903149032490334903449035490364903749038490394904049041490424904349044490454904649047490484904949050490514905249053490544905549056490574905849059490604906149062490634906449065490664906749068490694907049071490724907349074490754907649077490784907949080490814908249083490844908549086490874908849089490904909149092490934909449095490964909749098490994910049101491024910349104491054910649107491084910949110491114911249113491144911549116491174911849119491204912149122491234912449125491264912749128491294913049131491324913349134491354913649137491384913949140491414914249143491444914549146491474914849149491504915149152491534915449155491564915749158491594916049161491624916349164491654916649167491684916949170491714917249173491744917549176491774917849179491804918149182491834918449185491864918749188491894919049191491924919349194491954919649197491984919949200492014920249203492044920549206492074920849209492104921149212492134921449215492164921749218492194922049221492224922349224492254922649227492284922949230492314923249233492344923549236492374923849239492404924149242492434924449245492464924749248492494925049251492524925349254492554925649257492584925949260492614926249263492644926549266492674926849269492704927149272492734927449275492764927749278492794928049281492824928349284492854928649287492884928949290492914929249293492944929549296492974929849299493004930149302493034930449305493064930749308493094931049311493124931349314493154931649317493184931949320493214932249323493244932549326493274932849329493304933149332493334933449335493364933749338493394934049341493424934349344493454934649347493484934949350493514935249353493544935549356493574935849359493604936149362493634936449365493664936749368493694937049371493724937349374493754937649377493784937949380493814938249383493844938549386493874938849389493904939149392493934939449395493964939749398493994940049401494024940349404494054940649407494084940949410494114941249413494144941549416494174941849419494204942149422494234942449425494264942749428494294943049431494324943349434494354943649437494384943949440494414944249443494444944549446494474944849449494504945149452494534945449455494564945749458494594946049461494624946349464494654946649467494684946949470494714947249473494744947549476494774947849479494804948149482494834948449485494864948749488494894949049491494924949349494494954949649497494984949949500495014950249503495044950549506495074950849509495104951149512495134951449515495164951749518495194952049521495224952349524495254952649527495284952949530495314953249533495344953549536495374953849539495404954149542495434954449545495464954749548495494955049551495524955349554495554955649557495584955949560495614956249563495644956549566495674956849569495704957149572495734957449575495764957749578495794958049581495824958349584495854958649587495884958949590495914959249593495944959549596495974959849599496004960149602496034960449605496064960749608496094961049611496124961349614496154961649617496184961949620496214962249623496244962549626496274962849629496304963149632496334963449635496364963749638496394964049641496424964349644496454964649647496484964949650496514965249653496544965549656496574965849659496604966149662496634966449665496664966749668496694967049671496724967349674496754967649677496784967949680496814968249683496844968549686496874968849689496904969149692496934969449695496964969749698496994970049701497024970349704497054970649707497084970949710497114971249713497144971549716497174971849719497204972149722497234972449725497264972749728497294973049731497324973349734497354973649737497384973949740497414974249743497444974549746497474974849749497504975149752497534975449755497564975749758497594976049761497624976349764497654976649767497684976949770497714977249773497744977549776497774977849779497804978149782497834978449785497864978749788497894979049791497924979349794497954979649797497984979949800498014980249803498044980549806498074980849809498104981149812498134981449815498164981749818498194982049821498224982349824498254982649827498284982949830498314983249833498344983549836498374983849839498404984149842498434984449845498464984749848498494985049851498524985349854498554985649857498584985949860498614986249863498644986549866498674986849869498704987149872498734987449875498764987749878498794988049881498824988349884498854988649887498884988949890498914989249893498944989549896498974989849899499004990149902499034990449905499064990749908499094991049911499124991349914499154991649917499184991949920499214992249923499244992549926499274992849929499304993149932499334993449935499364993749938499394994049941499424994349944499454994649947499484994949950499514995249953499544995549956499574995849959499604996149962499634996449965499664996749968499694997049971499724997349974499754997649977499784997949980499814998249983499844998549986499874998849989499904999149992499934999449995499964999749998499995000050001500025000350004500055000650007500085000950010500115001250013500145001550016500175001850019500205002150022500235002450025500265002750028500295003050031500325003350034500355003650037500385003950040500415004250043500445004550046500475004850049500505005150052500535005450055500565005750058500595006050061500625006350064500655006650067500685006950070500715007250073500745007550076500775007850079500805008150082500835008450085500865008750088500895009050091500925009350094500955009650097500985009950100501015010250103501045010550106501075010850109501105011150112501135011450115501165011750118501195012050121501225012350124501255012650127501285012950130501315013250133501345013550136501375013850139501405014150142501435014450145501465014750148501495015050151501525015350154501555015650157501585015950160501615016250163501645016550166501675016850169501705017150172501735017450175501765017750178501795018050181501825018350184501855018650187501885018950190501915019250193501945019550196501975019850199502005020150202502035020450205502065020750208502095021050211502125021350214502155021650217502185021950220502215022250223502245022550226502275022850229502305023150232502335023450235502365023750238502395024050241502425024350244502455024650247502485024950250502515025250253502545025550256502575025850259502605026150262502635026450265502665026750268502695027050271502725027350274502755027650277502785027950280502815028250283502845028550286502875028850289502905029150292502935029450295502965029750298502995030050301503025030350304503055030650307503085030950310503115031250313503145031550316503175031850319503205032150322503235032450325503265032750328503295033050331503325033350334503355033650337503385033950340503415034250343503445034550346503475034850349503505035150352503535035450355503565035750358503595036050361503625036350364503655036650367503685036950370503715037250373503745037550376503775037850379503805038150382503835038450385503865038750388503895039050391503925039350394503955039650397503985039950400504015040250403504045040550406504075040850409504105041150412504135041450415504165041750418504195042050421504225042350424504255042650427504285042950430504315043250433504345043550436504375043850439504405044150442504435044450445504465044750448504495045050451504525045350454504555045650457504585045950460504615046250463504645046550466504675046850469504705047150472504735047450475504765047750478504795048050481504825048350484504855048650487504885048950490504915049250493504945049550496504975049850499505005050150502505035050450505505065050750508505095051050511505125051350514505155051650517505185051950520505215052250523505245052550526505275052850529505305053150532505335053450535505365053750538505395054050541505425054350544505455054650547505485054950550505515055250553505545055550556505575055850559505605056150562505635056450565505665056750568505695057050571505725057350574505755057650577505785057950580505815058250583505845058550586505875058850589505905059150592505935059450595505965059750598505995060050601506025060350604506055060650607506085060950610506115061250613506145061550616506175061850619506205062150622506235062450625506265062750628506295063050631506325063350634506355063650637506385063950640506415064250643506445064550646506475064850649506505065150652506535065450655506565065750658506595066050661506625066350664506655066650667506685066950670506715067250673506745067550676506775067850679506805068150682506835068450685506865068750688506895069050691506925069350694506955069650697506985069950700507015070250703507045070550706507075070850709507105071150712507135071450715507165071750718507195072050721507225072350724507255072650727507285072950730507315073250733507345073550736507375073850739507405074150742507435074450745507465074750748507495075050751507525075350754507555075650757507585075950760507615076250763507645076550766507675076850769507705077150772507735077450775507765077750778507795078050781507825078350784507855078650787507885078950790507915079250793507945079550796507975079850799508005080150802508035080450805508065080750808508095081050811508125081350814508155081650817508185081950820508215082250823508245082550826508275082850829508305083150832508335083450835508365083750838508395084050841508425084350844508455084650847508485084950850508515085250853508545085550856508575085850859508605086150862508635086450865508665086750868508695087050871508725087350874508755087650877508785087950880508815088250883508845088550886508875088850889508905089150892508935089450895508965089750898508995090050901509025090350904509055090650907509085090950910509115091250913509145091550916509175091850919509205092150922509235092450925509265092750928509295093050931509325093350934509355093650937509385093950940509415094250943509445094550946509475094850949509505095150952509535095450955509565095750958509595096050961509625096350964509655096650967509685096950970509715097250973509745097550976509775097850979509805098150982509835098450985509865098750988509895099050991509925099350994509955099650997509985099951000510015100251003510045100551006510075100851009510105101151012510135101451015510165101751018510195102051021510225102351024510255102651027510285102951030510315103251033510345103551036510375103851039510405104151042510435104451045510465104751048510495105051051510525105351054510555105651057510585105951060510615106251063510645106551066510675106851069510705107151072510735107451075510765107751078510795108051081510825108351084510855108651087510885108951090510915109251093510945109551096510975109851099511005110151102511035110451105511065110751108511095111051111511125111351114511155111651117511185111951120511215112251123511245112551126511275112851129511305113151132511335113451135511365113751138511395114051141511425114351144511455114651147511485114951150511515115251153511545115551156511575115851159511605116151162511635116451165511665116751168511695117051171511725117351174511755117651177511785117951180511815118251183511845118551186511875118851189511905119151192511935119451195511965119751198511995120051201512025120351204512055120651207512085120951210512115121251213512145121551216512175121851219512205122151222512235122451225512265122751228512295123051231512325123351234512355123651237512385123951240512415124251243512445124551246512475124851249512505125151252512535125451255512565125751258512595126051261512625126351264512655126651267512685126951270512715127251273512745127551276512775127851279512805128151282512835128451285512865128751288512895129051291512925129351294512955129651297512985129951300513015130251303513045130551306513075130851309513105131151312513135131451315513165131751318513195132051321513225132351324513255132651327513285132951330513315133251333513345133551336513375133851339513405134151342513435134451345513465134751348513495135051351513525135351354513555135651357513585135951360513615136251363513645136551366513675136851369513705137151372513735137451375513765137751378513795138051381513825138351384513855138651387513885138951390513915139251393513945139551396513975139851399514005140151402514035140451405514065140751408514095141051411514125141351414514155141651417514185141951420514215142251423514245142551426514275142851429514305143151432514335143451435514365143751438514395144051441514425144351444514455144651447514485144951450514515145251453514545145551456514575145851459514605146151462514635146451465514665146751468514695147051471514725147351474514755147651477514785147951480514815148251483514845148551486514875148851489514905149151492514935149451495514965149751498514995150051501515025150351504515055150651507515085150951510515115151251513515145151551516515175151851519515205152151522515235152451525515265152751528515295153051531515325153351534515355153651537515385153951540515415154251543515445154551546515475154851549515505155151552515535155451555515565155751558515595156051561515625156351564515655156651567515685156951570515715157251573515745157551576515775157851579515805158151582515835158451585515865158751588515895159051591515925159351594515955159651597515985159951600516015160251603516045160551606516075160851609516105161151612516135161451615516165161751618516195162051621516225162351624516255162651627516285162951630516315163251633516345163551636516375163851639516405164151642516435164451645516465164751648516495165051651516525165351654516555165651657516585165951660516615166251663516645166551666516675166851669516705167151672516735167451675516765167751678516795168051681516825168351684516855168651687516885168951690516915169251693516945169551696516975169851699517005170151702517035170451705517065170751708517095171051711517125171351714517155171651717517185171951720517215172251723517245172551726517275172851729517305173151732517335173451735517365173751738517395174051741517425174351744517455174651747517485174951750517515175251753517545175551756517575175851759517605176151762517635176451765517665176751768517695177051771517725177351774517755177651777517785177951780517815178251783517845178551786517875178851789517905179151792517935179451795517965179751798517995180051801518025180351804518055180651807518085180951810518115181251813518145181551816518175181851819518205182151822518235182451825518265182751828518295183051831518325183351834518355183651837518385183951840518415184251843518445184551846518475184851849518505185151852518535185451855518565185751858518595186051861518625186351864518655186651867518685186951870518715187251873518745187551876518775187851879518805188151882518835188451885518865188751888518895189051891518925189351894518955189651897518985189951900519015190251903519045190551906519075190851909519105191151912519135191451915519165191751918519195192051921519225192351924519255192651927519285192951930519315193251933519345193551936519375193851939519405194151942519435194451945519465194751948519495195051951519525195351954519555195651957519585195951960519615196251963519645196551966519675196851969519705197151972519735197451975519765197751978519795198051981519825198351984519855198651987519885198951990519915199251993519945199551996519975199851999520005200152002520035200452005520065200752008520095201052011520125201352014520155201652017520185201952020520215202252023520245202552026520275202852029520305203152032520335203452035520365203752038520395204052041520425204352044520455204652047520485204952050520515205252053520545205552056520575205852059520605206152062520635206452065520665206752068520695207052071520725207352074520755207652077520785207952080520815208252083520845208552086520875208852089520905209152092520935209452095520965209752098520995210052101521025210352104521055210652107521085210952110521115211252113521145211552116521175211852119521205212152122521235212452125521265212752128521295213052131521325213352134521355213652137521385213952140521415214252143521445214552146521475214852149521505215152152521535215452155521565215752158521595216052161521625216352164521655216652167521685216952170521715217252173521745217552176521775217852179521805218152182521835218452185521865218752188521895219052191521925219352194521955219652197521985219952200522015220252203522045220552206522075220852209522105221152212522135221452215522165221752218522195222052221522225222352224522255222652227522285222952230522315223252233522345223552236522375223852239522405224152242522435224452245522465224752248522495225052251522525225352254522555225652257522585225952260522615226252263522645226552266522675226852269522705227152272522735227452275522765227752278522795228052281522825228352284522855228652287522885228952290522915229252293522945229552296522975229852299523005230152302523035230452305523065230752308523095231052311523125231352314523155231652317523185231952320523215232252323523245232552326523275232852329523305233152332523335233452335523365233752338523395234052341523425234352344523455234652347523485234952350523515235252353523545235552356523575235852359523605236152362523635236452365523665236752368523695237052371523725237352374523755237652377523785237952380523815238252383523845238552386523875238852389523905239152392523935239452395523965239752398523995240052401524025240352404524055240652407524085240952410524115241252413524145241552416524175241852419524205242152422524235242452425524265242752428524295243052431524325243352434524355243652437524385243952440524415244252443524445244552446524475244852449524505245152452524535245452455524565245752458524595246052461524625246352464524655246652467524685246952470524715247252473524745247552476524775247852479524805248152482524835248452485524865248752488524895249052491524925249352494524955249652497524985249952500525015250252503525045250552506525075250852509525105251152512525135251452515525165251752518525195252052521525225252352524525255252652527525285252952530525315253252533525345253552536525375253852539525405254152542525435254452545525465254752548525495255052551525525255352554525555255652557525585255952560525615256252563525645256552566525675256852569525705257152572525735257452575525765257752578525795258052581525825258352584525855258652587525885258952590525915259252593525945259552596525975259852599526005260152602526035260452605526065260752608526095261052611526125261352614526155261652617526185261952620526215262252623526245262552626526275262852629526305263152632526335263452635526365263752638526395264052641526425264352644526455264652647526485264952650526515265252653526545265552656526575265852659526605266152662526635266452665526665266752668526695267052671526725267352674526755267652677526785267952680526815268252683526845268552686526875268852689526905269152692526935269452695526965269752698526995270052701527025270352704527055270652707527085270952710527115271252713527145271552716527175271852719527205272152722527235272452725527265272752728527295273052731527325273352734527355273652737527385273952740527415274252743527445274552746527475274852749527505275152752527535275452755527565275752758527595276052761527625276352764527655276652767527685276952770527715277252773527745277552776527775277852779527805278152782527835278452785527865278752788527895279052791527925279352794527955279652797527985279952800528015280252803528045280552806528075280852809528105281152812528135281452815528165281752818528195282052821528225282352824528255282652827528285282952830528315283252833528345283552836528375283852839528405284152842528435284452845528465284752848528495285052851528525285352854528555285652857528585285952860528615286252863528645286552866528675286852869528705287152872528735287452875528765287752878528795288052881528825288352884528855288652887528885288952890528915289252893528945289552896528975289852899529005290152902529035290452905529065290752908529095291052911529125291352914529155291652917529185291952920529215292252923529245292552926529275292852929529305293152932529335293452935529365293752938529395294052941529425294352944529455294652947529485294952950529515295252953529545295552956529575295852959529605296152962529635296452965529665296752968529695297052971529725297352974529755297652977529785297952980529815298252983529845298552986529875298852989529905299152992529935299452995529965299752998529995300053001530025300353004530055300653007530085300953010530115301253013530145301553016530175301853019530205302153022530235302453025530265302753028530295303053031530325303353034530355303653037530385303953040530415304253043530445304553046530475304853049530505305153052530535305453055530565305753058530595306053061530625306353064530655306653067530685306953070530715307253073530745307553076530775307853079530805308153082530835308453085530865308753088530895309053091530925309353094530955309653097530985309953100531015310253103531045310553106531075310853109531105311153112531135311453115531165311753118531195312053121531225312353124531255312653127531285312953130531315313253133531345313553136531375313853139531405314153142531435314453145531465314753148531495315053151531525315353154531555315653157531585315953160531615316253163531645316553166531675316853169531705317153172531735317453175531765317753178531795318053181531825318353184531855318653187531885318953190531915319253193531945319553196531975319853199532005320153202532035320453205532065320753208532095321053211532125321353214532155321653217532185321953220532215322253223532245322553226532275322853229532305323153232532335323453235532365323753238532395324053241532425324353244532455324653247532485324953250532515325253253532545325553256532575325853259532605326153262532635326453265532665326753268532695327053271532725327353274532755327653277532785327953280532815328253283532845328553286532875328853289532905329153292532935329453295532965329753298532995330053301533025330353304533055330653307533085330953310533115331253313533145331553316533175331853319533205332153322533235332453325533265332753328533295333053331533325333353334533355333653337533385333953340533415334253343533445334553346533475334853349533505335153352533535335453355533565335753358533595336053361533625336353364533655336653367533685336953370533715337253373533745337553376533775337853379533805338153382533835338453385533865338753388533895339053391533925339353394533955339653397533985339953400534015340253403534045340553406534075340853409534105341153412534135341453415534165341753418534195342053421534225342353424534255342653427534285342953430534315343253433534345343553436534375343853439534405344153442534435344453445534465344753448534495345053451534525345353454534555345653457534585345953460534615346253463534645346553466534675346853469534705347153472534735347453475534765347753478534795348053481534825348353484534855348653487534885348953490534915349253493534945349553496534975349853499535005350153502535035350453505535065350753508535095351053511535125351353514535155351653517535185351953520535215352253523535245352553526535275352853529535305353153532535335353453535535365353753538535395354053541535425354353544535455354653547535485354953550535515355253553535545355553556535575355853559535605356153562535635356453565535665356753568535695357053571535725357353574535755357653577535785357953580535815358253583535845358553586535875358853589535905359153592535935359453595535965359753598535995360053601536025360353604536055360653607536085360953610536115361253613536145361553616536175361853619536205362153622536235362453625536265362753628536295363053631536325363353634536355363653637536385363953640536415364253643536445364553646536475364853649536505365153652536535365453655536565365753658536595366053661536625366353664536655366653667536685366953670536715367253673536745367553676536775367853679536805368153682536835368453685536865368753688536895369053691536925369353694536955369653697536985369953700537015370253703537045370553706537075370853709537105371153712537135371453715537165371753718537195372053721537225372353724537255372653727537285372953730537315373253733537345373553736537375373853739537405374153742537435374453745537465374753748537495375053751537525375353754537555375653757537585375953760537615376253763537645376553766537675376853769537705377153772537735377453775537765377753778537795378053781537825378353784537855378653787537885378953790537915379253793537945379553796537975379853799538005380153802538035380453805538065380753808538095381053811538125381353814538155381653817538185381953820538215382253823538245382553826538275382853829538305383153832538335383453835538365383753838538395384053841538425384353844538455384653847538485384953850538515385253853538545385553856538575385853859538605386153862538635386453865538665386753868538695387053871538725387353874538755387653877538785387953880538815388253883538845388553886538875388853889538905389153892538935389453895538965389753898538995390053901539025390353904539055390653907539085390953910539115391253913539145391553916539175391853919539205392153922539235392453925539265392753928539295393053931539325393353934539355393653937539385393953940539415394253943539445394553946539475394853949539505395153952539535395453955539565395753958539595396053961539625396353964539655396653967539685396953970539715397253973539745397553976539775397853979539805398153982539835398453985539865398753988539895399053991539925399353994539955399653997539985399954000540015400254003540045400554006540075400854009540105401154012540135401454015540165401754018540195402054021540225402354024540255402654027540285402954030540315403254033540345403554036540375403854039540405404154042540435404454045540465404754048540495405054051540525405354054540555405654057540585405954060540615406254063540645406554066540675406854069540705407154072540735407454075540765407754078540795408054081540825408354084540855408654087540885408954090540915409254093540945409554096540975409854099541005410154102541035410454105541065410754108541095411054111541125411354114541155411654117541185411954120541215412254123541245412554126541275412854129541305413154132541335413454135541365413754138541395414054141541425414354144541455414654147541485414954150541515415254153541545415554156541575415854159541605416154162541635416454165541665416754168541695417054171541725417354174541755417654177541785417954180541815418254183541845418554186541875418854189541905419154192541935419454195541965419754198541995420054201542025420354204542055420654207542085420954210542115421254213542145421554216542175421854219542205422154222542235422454225542265422754228542295423054231542325423354234542355423654237542385423954240542415424254243542445424554246542475424854249542505425154252542535425454255542565425754258542595426054261542625426354264542655426654267542685426954270542715427254273542745427554276542775427854279542805428154282542835428454285542865428754288542895429054291542925429354294542955429654297542985429954300543015430254303543045430554306543075430854309543105431154312543135431454315543165431754318543195432054321543225432354324543255432654327543285432954330543315433254333543345433554336543375433854339543405434154342543435434454345543465434754348543495435054351543525435354354543555435654357543585435954360543615436254363543645436554366543675436854369543705437154372543735437454375543765437754378543795438054381543825438354384543855438654387543885438954390543915439254393543945439554396543975439854399544005440154402544035440454405544065440754408544095441054411544125441354414544155441654417544185441954420544215442254423544245442554426544275442854429544305443154432544335443454435544365443754438544395444054441544425444354444544455444654447544485444954450544515445254453544545445554456544575445854459544605446154462544635446454465544665446754468544695447054471544725447354474544755447654477544785447954480544815448254483544845448554486544875448854489544905449154492544935449454495544965449754498544995450054501545025450354504545055450654507545085450954510545115451254513545145451554516545175451854519545205452154522545235452454525545265452754528545295453054531545325453354534545355453654537545385453954540545415454254543545445454554546545475454854549545505455154552545535455454555545565455754558545595456054561545625456354564545655456654567545685456954570545715457254573545745457554576545775457854579545805458154582545835458454585545865458754588545895459054591545925459354594545955459654597545985459954600546015460254603546045460554606546075460854609546105461154612546135461454615546165461754618546195462054621546225462354624546255462654627546285462954630546315463254633546345463554636546375463854639546405464154642546435464454645546465464754648546495465054651546525465354654546555465654657546585465954660546615466254663546645466554666546675466854669546705467154672546735467454675546765467754678546795468054681546825468354684546855468654687546885468954690546915469254693546945469554696546975469854699547005470154702547035470454705547065470754708547095471054711547125471354714547155471654717547185471954720547215472254723547245472554726547275472854729547305473154732547335473454735547365473754738547395474054741547425474354744547455474654747547485474954750547515475254753547545475554756547575475854759547605476154762547635476454765547665476754768547695477054771547725477354774547755477654777547785477954780547815478254783547845478554786547875478854789547905479154792547935479454795547965479754798547995480054801548025480354804548055480654807548085480954810548115481254813548145481554816548175481854819548205482154822548235482454825548265482754828548295483054831548325483354834548355483654837548385483954840548415484254843548445484554846548475484854849548505485154852548535485454855548565485754858548595486054861548625486354864548655486654867548685486954870548715487254873548745487554876548775487854879548805488154882548835488454885548865488754888548895489054891548925489354894548955489654897548985489954900549015490254903549045490554906549075490854909549105491154912549135491454915549165491754918549195492054921549225492354924549255492654927549285492954930549315493254933549345493554936549375493854939549405494154942549435494454945549465494754948549495495054951549525495354954549555495654957549585495954960549615496254963549645496554966549675496854969549705497154972549735497454975549765497754978549795498054981549825498354984549855498654987549885498954990549915499254993549945499554996549975499854999550005500155002550035500455005550065500755008550095501055011550125501355014550155501655017550185501955020550215502255023550245502555026550275502855029550305503155032550335503455035550365503755038550395504055041550425504355044550455504655047550485504955050550515505255053550545505555056550575505855059550605506155062550635506455065550665506755068550695507055071550725507355074550755507655077550785507955080550815508255083550845508555086550875508855089550905509155092550935509455095550965509755098550995510055101551025510355104551055510655107551085510955110551115511255113551145511555116551175511855119551205512155122551235512455125551265512755128551295513055131551325513355134551355513655137551385513955140551415514255143551445514555146551475514855149551505515155152551535515455155551565515755158551595516055161551625516355164551655516655167551685516955170551715517255173551745517555176551775517855179551805518155182551835518455185551865518755188551895519055191551925519355194551955519655197551985519955200552015520255203552045520555206552075520855209552105521155212552135521455215552165521755218552195522055221552225522355224552255522655227552285522955230552315523255233552345523555236552375523855239552405524155242552435524455245552465524755248552495525055251552525525355254552555525655257552585525955260552615526255263552645526555266552675526855269552705527155272552735527455275552765527755278552795528055281552825528355284552855528655287552885528955290552915529255293552945529555296552975529855299553005530155302553035530455305553065530755308553095531055311553125531355314553155531655317553185531955320553215532255323553245532555326553275532855329553305533155332553335533455335553365533755338553395534055341553425534355344553455534655347553485534955350553515535255353553545535555356553575535855359553605536155362553635536455365553665536755368553695537055371553725537355374553755537655377553785537955380553815538255383553845538555386553875538855389553905539155392553935539455395553965539755398553995540055401554025540355404554055540655407554085540955410554115541255413554145541555416554175541855419554205542155422554235542455425554265542755428554295543055431554325543355434554355543655437554385543955440554415544255443554445544555446554475544855449554505545155452554535545455455554565545755458554595546055461554625546355464554655546655467554685546955470554715547255473554745547555476554775547855479554805548155482554835548455485554865548755488554895549055491554925549355494554955549655497554985549955500555015550255503555045550555506555075550855509555105551155512555135551455515555165551755518555195552055521555225552355524555255552655527555285552955530555315553255533555345553555536555375553855539555405554155542555435554455545555465554755548555495555055551555525555355554555555555655557555585555955560555615556255563555645556555566555675556855569555705557155572555735557455575555765557755578555795558055581555825558355584555855558655587555885558955590555915559255593555945559555596555975559855599556005560155602556035560455605556065560755608556095561055611556125561355614556155561655617556185561955620556215562255623556245562555626556275562855629556305563155632556335563455635556365563755638556395564055641556425564355644556455564655647556485564955650556515565255653556545565555656556575565855659556605566155662556635566455665556665566755668556695567055671556725567355674556755567655677556785567955680556815568255683556845568555686556875568855689556905569155692556935569455695556965569755698556995570055701557025570355704557055570655707557085570955710557115571255713557145571555716557175571855719557205572155722557235572455725557265572755728557295573055731557325573355734557355573655737557385573955740557415574255743557445574555746557475574855749557505575155752557535575455755557565575755758557595576055761557625576355764557655576655767557685576955770557715577255773557745577555776557775577855779557805578155782557835578455785557865578755788557895579055791557925579355794557955579655797557985579955800558015580255803558045580555806558075580855809558105581155812558135581455815558165581755818558195582055821558225582355824558255582655827558285582955830558315583255833558345583555836558375583855839558405584155842558435584455845558465584755848558495585055851558525585355854558555585655857558585585955860558615586255863558645586555866558675586855869558705587155872558735587455875558765587755878558795588055881558825588355884558855588655887558885588955890558915589255893558945589555896558975589855899559005590155902559035590455905559065590755908559095591055911559125591355914559155591655917559185591955920559215592255923559245592555926559275592855929559305593155932559335593455935559365593755938559395594055941559425594355944559455594655947559485594955950559515595255953559545595555956559575595855959559605596155962559635596455965559665596755968559695597055971559725597355974559755597655977559785597955980559815598255983559845598555986559875598855989559905599155992559935599455995559965599755998559995600056001560025600356004560055600656007560085600956010560115601256013560145601556016560175601856019560205602156022560235602456025560265602756028560295603056031560325603356034560355603656037560385603956040560415604256043560445604556046560475604856049560505605156052560535605456055560565605756058560595606056061560625606356064560655606656067560685606956070560715607256073560745607556076560775607856079560805608156082560835608456085560865608756088560895609056091560925609356094560955609656097560985609956100561015610256103561045610556106561075610856109561105611156112561135611456115561165611756118561195612056121561225612356124561255612656127561285612956130561315613256133561345613556136561375613856139561405614156142561435614456145561465614756148561495615056151561525615356154561555615656157561585615956160561615616256163561645616556166561675616856169561705617156172561735617456175561765617756178561795618056181561825618356184561855618656187561885618956190561915619256193561945619556196561975619856199562005620156202562035620456205562065620756208562095621056211562125621356214562155621656217562185621956220562215622256223562245622556226562275622856229562305623156232562335623456235562365623756238562395624056241562425624356244562455624656247562485624956250562515625256253562545625556256562575625856259562605626156262562635626456265562665626756268562695627056271562725627356274562755627656277562785627956280562815628256283562845628556286562875628856289562905629156292562935629456295562965629756298562995630056301563025630356304563055630656307563085630956310563115631256313563145631556316563175631856319563205632156322563235632456325563265632756328563295633056331563325633356334563355633656337563385633956340563415634256343563445634556346563475634856349563505635156352563535635456355563565635756358563595636056361563625636356364563655636656367563685636956370563715637256373563745637556376563775637856379563805638156382563835638456385563865638756388563895639056391563925639356394563955639656397563985639956400564015640256403564045640556406564075640856409564105641156412564135641456415564165641756418564195642056421564225642356424564255642656427564285642956430564315643256433564345643556436564375643856439564405644156442564435644456445564465644756448564495645056451564525645356454564555645656457564585645956460564615646256463564645646556466564675646856469564705647156472564735647456475564765647756478564795648056481564825648356484564855648656487564885648956490564915649256493564945649556496564975649856499565005650156502565035650456505565065650756508565095651056511565125651356514565155651656517565185651956520565215652256523565245652556526565275652856529565305653156532565335653456535565365653756538565395654056541565425654356544565455654656547565485654956550565515655256553565545655556556565575655856559565605656156562565635656456565565665656756568565695657056571565725657356574565755657656577565785657956580565815658256583565845658556586565875658856589565905659156592565935659456595565965659756598565995660056601566025660356604566055660656607566085660956610566115661256613566145661556616566175661856619566205662156622566235662456625566265662756628566295663056631566325663356634566355663656637566385663956640566415664256643566445664556646566475664856649566505665156652566535665456655566565665756658566595666056661566625666356664566655666656667566685666956670566715667256673566745667556676566775667856679566805668156682566835668456685566865668756688566895669056691566925669356694566955669656697566985669956700567015670256703567045670556706567075670856709567105671156712567135671456715567165671756718567195672056721567225672356724567255672656727567285672956730567315673256733567345673556736567375673856739567405674156742567435674456745567465674756748567495675056751567525675356754567555675656757567585675956760567615676256763567645676556766567675676856769567705677156772567735677456775567765677756778567795678056781567825678356784567855678656787567885678956790567915679256793567945679556796567975679856799568005680156802568035680456805568065680756808568095681056811568125681356814568155681656817568185681956820568215682256823568245682556826568275682856829568305683156832568335683456835568365683756838568395684056841568425684356844568455684656847568485684956850568515685256853568545685556856568575685856859568605686156862568635686456865568665686756868568695687056871568725687356874568755687656877568785687956880568815688256883568845688556886568875688856889568905689156892568935689456895568965689756898568995690056901569025690356904569055690656907569085690956910569115691256913569145691556916569175691856919569205692156922569235692456925569265692756928569295693056931569325693356934569355693656937569385693956940569415694256943569445694556946569475694856949569505695156952569535695456955569565695756958569595696056961569625696356964569655696656967569685696956970569715697256973569745697556976569775697856979569805698156982569835698456985569865698756988569895699056991569925699356994569955699656997569985699957000570015700257003570045700557006570075700857009570105701157012570135701457015570165701757018570195702057021570225702357024570255702657027570285702957030570315703257033570345703557036570375703857039570405704157042570435704457045570465704757048570495705057051570525705357054570555705657057570585705957060570615706257063570645706557066570675706857069570705707157072570735707457075570765707757078570795708057081570825708357084570855708657087570885708957090570915709257093570945709557096570975709857099571005710157102571035710457105571065710757108571095711057111571125711357114571155711657117571185711957120571215712257123571245712557126571275712857129571305713157132571335713457135571365713757138571395714057141571425714357144571455714657147571485714957150571515715257153571545715557156571575715857159571605716157162571635716457165571665716757168571695717057171571725717357174571755717657177571785717957180571815718257183571845718557186571875718857189571905719157192571935719457195571965719757198571995720057201572025720357204572055720657207572085720957210572115721257213572145721557216572175721857219572205722157222572235722457225572265722757228572295723057231572325723357234572355723657237572385723957240572415724257243572445724557246572475724857249572505725157252572535725457255572565725757258572595726057261572625726357264572655726657267572685726957270572715727257273572745727557276572775727857279572805728157282572835728457285572865728757288572895729057291572925729357294572955729657297572985729957300573015730257303573045730557306573075730857309573105731157312573135731457315573165731757318573195732057321573225732357324573255732657327573285732957330573315733257333573345733557336573375733857339573405734157342573435734457345573465734757348573495735057351573525735357354573555735657357573585735957360573615736257363573645736557366573675736857369573705737157372573735737457375573765737757378573795738057381573825738357384573855738657387573885738957390573915739257393573945739557396573975739857399574005740157402574035740457405574065740757408574095741057411574125741357414574155741657417574185741957420574215742257423574245742557426574275742857429574305743157432574335743457435574365743757438574395744057441574425744357444574455744657447574485744957450574515745257453574545745557456574575745857459574605746157462574635746457465574665746757468574695747057471574725747357474574755747657477574785747957480574815748257483574845748557486574875748857489574905749157492574935749457495574965749757498574995750057501575025750357504575055750657507575085750957510575115751257513575145751557516575175751857519575205752157522575235752457525575265752757528575295753057531575325753357534575355753657537575385753957540575415754257543575445754557546575475754857549575505755157552575535755457555575565755757558575595756057561575625756357564575655756657567575685756957570575715757257573575745757557576575775757857579575805758157582575835758457585575865758757588575895759057591575925759357594575955759657597575985759957600576015760257603576045760557606576075760857609576105761157612576135761457615576165761757618576195762057621576225762357624576255762657627576285762957630576315763257633576345763557636576375763857639576405764157642576435764457645576465764757648576495765057651576525765357654576555765657657576585765957660576615766257663576645766557666576675766857669576705767157672576735767457675576765767757678576795768057681576825768357684576855768657687576885768957690576915769257693576945769557696576975769857699577005770157702577035770457705577065770757708577095771057711577125771357714577155771657717577185771957720577215772257723577245772557726577275772857729577305773157732577335773457735577365773757738577395774057741577425774357744577455774657747577485774957750577515775257753577545775557756577575775857759577605776157762577635776457765577665776757768577695777057771577725777357774577755777657777577785777957780577815778257783577845778557786577875778857789577905779157792577935779457795577965779757798577995780057801578025780357804578055780657807578085780957810578115781257813578145781557816578175781857819578205782157822578235782457825578265782757828578295783057831578325783357834578355783657837578385783957840578415784257843578445784557846578475784857849578505785157852578535785457855578565785757858578595786057861578625786357864578655786657867578685786957870578715787257873578745787557876578775787857879578805788157882578835788457885578865788757888578895789057891578925789357894578955789657897578985789957900579015790257903579045790557906579075790857909579105791157912579135791457915579165791757918579195792057921579225792357924579255792657927579285792957930579315793257933579345793557936579375793857939579405794157942579435794457945579465794757948579495795057951579525795357954579555795657957579585795957960579615796257963579645796557966579675796857969579705797157972579735797457975579765797757978579795798057981579825798357984579855798657987579885798957990579915799257993579945799557996579975799857999580005800158002580035800458005580065800758008580095801058011580125801358014580155801658017580185801958020580215802258023580245802558026580275802858029580305803158032580335803458035580365803758038580395804058041580425804358044580455804658047580485804958050580515805258053580545805558056580575805858059580605806158062580635806458065580665806758068580695807058071580725807358074580755807658077580785807958080580815808258083580845808558086580875808858089580905809158092580935809458095580965809758098580995810058101581025810358104581055810658107581085810958110581115811258113581145811558116581175811858119581205812158122581235812458125581265812758128581295813058131581325813358134581355813658137581385813958140581415814258143581445814558146581475814858149581505815158152581535815458155581565815758158581595816058161581625816358164581655816658167581685816958170581715817258173581745817558176581775817858179581805818158182581835818458185581865818758188581895819058191581925819358194581955819658197581985819958200582015820258203582045820558206582075820858209582105821158212582135821458215582165821758218582195822058221582225822358224582255822658227582285822958230582315823258233582345823558236582375823858239582405824158242582435824458245582465824758248582495825058251582525825358254582555825658257582585825958260582615826258263582645826558266582675826858269582705827158272582735827458275582765827758278582795828058281582825828358284582855828658287582885828958290582915829258293582945829558296582975829858299583005830158302583035830458305583065830758308583095831058311583125831358314583155831658317583185831958320583215832258323583245832558326583275832858329583305833158332583335833458335583365833758338583395834058341583425834358344583455834658347583485834958350583515835258353583545835558356583575835858359583605836158362583635836458365583665836758368583695837058371583725837358374583755837658377583785837958380583815838258383583845838558386583875838858389583905839158392583935839458395583965839758398583995840058401584025840358404584055840658407584085840958410584115841258413584145841558416584175841858419584205842158422584235842458425584265842758428584295843058431584325843358434584355843658437584385843958440584415844258443584445844558446584475844858449584505845158452584535845458455584565845758458584595846058461584625846358464584655846658467584685846958470584715847258473584745847558476584775847858479584805848158482584835848458485584865848758488584895849058491584925849358494584955849658497584985849958500585015850258503585045850558506585075850858509585105851158512585135851458515585165851758518585195852058521585225852358524585255852658527585285852958530585315853258533585345853558536585375853858539585405854158542585435854458545585465854758548585495855058551585525855358554585555855658557585585855958560585615856258563585645856558566585675856858569585705857158572585735857458575585765857758578585795858058581585825858358584585855858658587585885858958590585915859258593585945859558596585975859858599586005860158602586035860458605586065860758608586095861058611586125861358614586155861658617586185861958620586215862258623586245862558626586275862858629586305863158632586335863458635586365863758638586395864058641586425864358644586455864658647586485864958650586515865258653586545865558656586575865858659586605866158662586635866458665586665866758668586695867058671586725867358674586755867658677586785867958680586815868258683586845868558686586875868858689586905869158692586935869458695586965869758698586995870058701587025870358704587055870658707587085870958710587115871258713587145871558716587175871858719587205872158722587235872458725587265872758728587295873058731587325873358734587355873658737587385873958740587415874258743587445874558746587475874858749587505875158752587535875458755587565875758758587595876058761587625876358764587655876658767587685876958770587715877258773587745877558776587775877858779587805878158782587835878458785587865878758788587895879058791587925879358794587955879658797587985879958800588015880258803588045880558806588075880858809588105881158812588135881458815588165881758818588195882058821588225882358824588255882658827588285882958830588315883258833588345883558836588375883858839588405884158842588435884458845588465884758848588495885058851588525885358854588555885658857588585885958860588615886258863588645886558866588675886858869588705887158872588735887458875588765887758878588795888058881588825888358884588855888658887588885888958890588915889258893588945889558896588975889858899589005890158902589035890458905589065890758908589095891058911589125891358914589155891658917589185891958920589215892258923589245892558926589275892858929589305893158932589335893458935589365893758938589395894058941589425894358944589455894658947589485894958950589515895258953589545895558956589575895858959589605896158962589635896458965589665896758968589695897058971589725897358974589755897658977589785897958980589815898258983589845898558986589875898858989589905899158992589935899458995589965899758998589995900059001590025900359004590055900659007590085900959010590115901259013590145901559016590175901859019590205902159022590235902459025590265902759028590295903059031590325903359034590355903659037590385903959040590415904259043590445904559046590475904859049590505905159052590535905459055590565905759058590595906059061590625906359064590655906659067590685906959070590715907259073590745907559076590775907859079590805908159082590835908459085590865908759088590895909059091590925909359094590955909659097590985909959100591015910259103591045910559106591075910859109591105911159112591135911459115591165911759118591195912059121591225912359124591255912659127591285912959130591315913259133591345913559136591375913859139591405914159142591435914459145591465914759148591495915059151591525915359154591555915659157591585915959160591615916259163591645916559166591675916859169591705917159172591735917459175591765917759178591795918059181591825918359184591855918659187591885918959190591915919259193591945919559196591975919859199592005920159202592035920459205592065920759208592095921059211592125921359214592155921659217592185921959220592215922259223592245922559226592275922859229592305923159232592335923459235592365923759238592395924059241592425924359244592455924659247592485924959250592515925259253592545925559256592575925859259592605926159262592635926459265592665926759268592695927059271592725927359274592755927659277592785927959280592815928259283592845928559286592875928859289592905929159292592935929459295592965929759298592995930059301593025930359304593055930659307593085930959310593115931259313593145931559316593175931859319593205932159322593235932459325593265932759328593295933059331593325933359334593355933659337593385933959340593415934259343593445934559346593475934859349593505935159352593535935459355593565935759358593595936059361593625936359364593655936659367593685936959370593715937259373593745937559376593775937859379593805938159382593835938459385593865938759388593895939059391593925939359394593955939659397593985939959400594015940259403594045940559406594075940859409594105941159412594135941459415594165941759418594195942059421594225942359424594255942659427594285942959430594315943259433594345943559436594375943859439594405944159442594435944459445594465944759448594495945059451594525945359454594555945659457594585945959460594615946259463594645946559466594675946859469594705947159472594735947459475594765947759478594795948059481594825948359484594855948659487594885948959490594915949259493594945949559496594975949859499595005950159502595035950459505595065950759508595095951059511595125951359514595155951659517595185951959520595215952259523595245952559526595275952859529595305953159532595335953459535595365953759538595395954059541595425954359544595455954659547595485954959550595515955259553595545955559556595575955859559595605956159562595635956459565595665956759568595695957059571595725957359574595755957659577595785957959580595815958259583595845958559586595875958859589595905959159592595935959459595595965959759598595995960059601596025960359604596055960659607596085960959610596115961259613596145961559616596175961859619596205962159622596235962459625596265962759628596295963059631596325963359634596355963659637596385963959640596415964259643596445964559646596475964859649596505965159652596535965459655596565965759658596595966059661596625966359664596655966659667596685966959670596715967259673596745967559676596775967859679596805968159682596835968459685596865968759688596895969059691596925969359694596955969659697596985969959700597015970259703597045970559706597075970859709597105971159712597135971459715597165971759718597195972059721597225972359724597255972659727597285972959730597315973259733597345973559736597375973859739597405974159742597435974459745597465974759748597495975059751597525975359754597555975659757597585975959760597615976259763597645976559766597675976859769597705977159772597735977459775597765977759778597795978059781597825978359784597855978659787597885978959790597915979259793597945979559796597975979859799598005980159802598035980459805598065980759808598095981059811598125981359814598155981659817598185981959820598215982259823598245982559826598275982859829598305983159832598335983459835598365983759838598395984059841598425984359844598455984659847598485984959850598515985259853598545985559856598575985859859598605986159862598635986459865598665986759868598695987059871598725987359874598755987659877598785987959880598815988259883598845988559886598875988859889598905989159892598935989459895598965989759898598995990059901599025990359904599055990659907599085990959910599115991259913599145991559916599175991859919599205992159922599235992459925599265992759928599295993059931599325993359934599355993659937599385993959940599415994259943599445994559946599475994859949599505995159952599535995459955599565995759958599595996059961599625996359964599655996659967599685996959970599715997259973599745997559976599775997859979599805998159982599835998459985599865998759988599895999059991599925999359994599955999659997599985999960000600016000260003600046000560006600076000860009600106001160012600136001460015600166001760018600196002060021600226002360024600256002660027600286002960030600316003260033600346003560036600376003860039600406004160042600436004460045600466004760048600496005060051600526005360054600556005660057600586005960060600616006260063600646006560066600676006860069600706007160072600736007460075600766007760078600796008060081600826008360084600856008660087600886008960090600916009260093600946009560096600976009860099601006010160102601036010460105601066010760108601096011060111601126011360114601156011660117601186011960120601216012260123601246012560126601276012860129601306013160132601336013460135601366013760138601396014060141601426014360144601456014660147601486014960150601516015260153601546015560156601576015860159601606016160162601636016460165601666016760168601696017060171601726017360174601756017660177601786017960180601816018260183601846018560186601876018860189601906019160192601936019460195601966019760198601996020060201602026020360204602056020660207602086020960210602116021260213602146021560216602176021860219602206022160222602236022460225602266022760228602296023060231602326023360234602356023660237602386023960240602416024260243602446024560246602476024860249602506025160252602536025460255602566025760258602596026060261602626026360264602656026660267602686026960270602716027260273602746027560276602776027860279602806028160282602836028460285602866028760288602896029060291602926029360294602956029660297602986029960300603016030260303603046030560306603076030860309603106031160312603136031460315603166031760318603196032060321603226032360324603256032660327603286032960330603316033260333603346033560336603376033860339603406034160342603436034460345603466034760348603496035060351603526035360354603556035660357603586035960360603616036260363603646036560366603676036860369603706037160372603736037460375603766037760378603796038060381603826038360384603856038660387603886038960390603916039260393603946039560396603976039860399604006040160402604036040460405604066040760408604096041060411604126041360414604156041660417604186041960420604216042260423604246042560426604276042860429604306043160432604336043460435604366043760438604396044060441604426044360444604456044660447604486044960450604516045260453604546045560456604576045860459604606046160462604636046460465604666046760468604696047060471604726047360474604756047660477604786047960480604816048260483604846048560486604876048860489604906049160492604936049460495604966049760498604996050060501605026050360504605056050660507605086050960510605116051260513605146051560516605176051860519605206052160522605236052460525605266052760528605296053060531605326053360534605356053660537605386053960540605416054260543605446054560546605476054860549605506055160552605536055460555605566055760558605596056060561605626056360564605656056660567605686056960570605716057260573605746057560576605776057860579605806058160582605836058460585605866058760588605896059060591605926059360594605956059660597605986059960600606016060260603606046060560606606076060860609606106061160612606136061460615606166061760618606196062060621606226062360624606256062660627606286062960630606316063260633606346063560636606376063860639606406064160642606436064460645606466064760648606496065060651606526065360654606556065660657606586065960660606616066260663606646066560666606676066860669606706067160672606736067460675606766067760678606796068060681606826068360684606856068660687606886068960690606916069260693606946069560696606976069860699607006070160702607036070460705607066070760708607096071060711607126071360714607156071660717607186071960720607216072260723607246072560726607276072860729607306073160732607336073460735607366073760738607396074060741607426074360744607456074660747607486074960750607516075260753607546075560756607576075860759607606076160762607636076460765607666076760768607696077060771607726077360774607756077660777607786077960780607816078260783607846078560786607876078860789607906079160792607936079460795607966079760798607996080060801608026080360804608056080660807608086080960810608116081260813608146081560816608176081860819608206082160822608236082460825608266082760828608296083060831608326083360834608356083660837608386083960840608416084260843608446084560846608476084860849608506085160852608536085460855608566085760858608596086060861608626086360864608656086660867608686086960870608716087260873608746087560876608776087860879608806088160882608836088460885608866088760888608896089060891608926089360894608956089660897608986089960900609016090260903609046090560906609076090860909609106091160912609136091460915609166091760918609196092060921609226092360924609256092660927609286092960930609316093260933609346093560936609376093860939609406094160942609436094460945609466094760948609496095060951609526095360954609556095660957609586095960960609616096260963609646096560966609676096860969609706097160972609736097460975609766097760978609796098060981609826098360984609856098660987609886098960990609916099260993609946099560996609976099860999610006100161002610036100461005610066100761008610096101061011610126101361014610156101661017610186101961020610216102261023610246102561026610276102861029610306103161032610336103461035610366103761038610396104061041610426104361044610456104661047610486104961050610516105261053610546105561056610576105861059610606106161062610636106461065610666106761068610696107061071610726107361074610756107661077610786107961080610816108261083610846108561086610876108861089610906109161092610936109461095610966109761098610996110061101611026110361104611056110661107611086110961110611116111261113611146111561116611176111861119611206112161122611236112461125611266112761128611296113061131611326113361134611356113661137611386113961140611416114261143611446114561146611476114861149611506115161152611536115461155611566115761158611596116061161611626116361164611656116661167611686116961170611716117261173611746117561176611776117861179611806118161182611836118461185611866118761188611896119061191611926119361194611956119661197611986119961200612016120261203612046120561206612076120861209612106121161212612136121461215612166121761218612196122061221612226122361224612256122661227612286122961230612316123261233612346123561236612376123861239612406124161242612436124461245612466124761248612496125061251612526125361254612556125661257612586125961260612616126261263612646126561266612676126861269612706127161272612736127461275612766127761278612796128061281612826128361284612856128661287612886128961290612916129261293612946129561296612976129861299613006130161302613036130461305613066130761308613096131061311613126131361314613156131661317613186131961320613216132261323613246132561326613276132861329613306133161332613336133461335613366133761338613396134061341613426134361344613456134661347613486134961350613516135261353613546135561356613576135861359613606136161362613636136461365613666136761368613696137061371613726137361374613756137661377613786137961380613816138261383613846138561386613876138861389613906139161392613936139461395613966139761398613996140061401614026140361404614056140661407614086140961410614116141261413614146141561416614176141861419614206142161422614236142461425614266142761428614296143061431614326143361434614356143661437614386143961440614416144261443614446144561446614476144861449614506145161452614536145461455614566145761458614596146061461614626146361464614656146661467614686146961470614716147261473614746147561476614776147861479614806148161482614836148461485614866148761488614896149061491614926149361494614956149661497614986149961500615016150261503615046150561506615076150861509615106151161512615136151461515615166151761518615196152061521615226152361524615256152661527615286152961530615316153261533615346153561536615376153861539615406154161542615436154461545615466154761548615496155061551615526155361554615556155661557615586155961560615616156261563615646156561566615676156861569615706157161572615736157461575615766157761578615796158061581615826158361584615856158661587615886158961590615916159261593615946159561596615976159861599616006160161602616036160461605616066160761608616096161061611616126161361614616156161661617616186161961620616216162261623616246162561626616276162861629616306163161632616336163461635616366163761638616396164061641616426164361644616456164661647616486164961650616516165261653616546165561656616576165861659616606166161662616636166461665616666166761668616696167061671616726167361674616756167661677616786167961680616816168261683616846168561686616876168861689616906169161692616936169461695616966169761698616996170061701617026170361704617056170661707617086170961710617116171261713617146171561716617176171861719617206172161722617236172461725617266172761728617296173061731617326173361734617356173661737617386173961740617416174261743617446174561746617476174861749617506175161752617536175461755617566175761758617596176061761617626176361764617656176661767617686176961770617716177261773617746177561776617776177861779617806178161782617836178461785617866178761788617896179061791617926179361794617956179661797617986179961800618016180261803618046180561806618076180861809618106181161812618136181461815618166181761818618196182061821618226182361824618256182661827618286182961830618316183261833618346183561836618376183861839618406184161842618436184461845618466184761848618496185061851618526185361854618556185661857618586185961860618616186261863618646186561866618676186861869618706187161872618736187461875618766187761878618796188061881618826188361884618856188661887618886188961890618916189261893618946189561896618976189861899619006190161902619036190461905619066190761908619096191061911619126191361914619156191661917619186191961920619216192261923619246192561926619276192861929619306193161932619336193461935619366193761938619396194061941619426194361944619456194661947619486194961950619516195261953619546195561956619576195861959619606196161962619636196461965619666196761968619696197061971619726197361974619756197661977619786197961980619816198261983619846198561986619876198861989619906199161992619936199461995619966199761998619996200062001620026200362004620056200662007620086200962010620116201262013620146201562016620176201862019620206202162022620236202462025620266202762028620296203062031620326203362034620356203662037620386203962040620416204262043620446204562046620476204862049620506205162052620536205462055620566205762058620596206062061620626206362064620656206662067620686206962070620716207262073620746207562076620776207862079620806208162082620836208462085620866208762088620896209062091620926209362094620956209662097620986209962100621016210262103621046210562106621076210862109621106211162112621136211462115621166211762118621196212062121621226212362124621256212662127621286212962130621316213262133621346213562136621376213862139621406214162142621436214462145621466214762148621496215062151621526215362154621556215662157621586215962160621616216262163621646216562166621676216862169621706217162172621736217462175621766217762178621796218062181621826218362184621856218662187621886218962190621916219262193621946219562196621976219862199622006220162202622036220462205622066220762208622096221062211622126221362214622156221662217622186221962220622216222262223622246222562226622276222862229622306223162232622336223462235622366223762238622396224062241622426224362244622456224662247622486224962250622516225262253622546225562256622576225862259622606226162262622636226462265622666226762268622696227062271622726227362274622756227662277622786227962280622816228262283622846228562286622876228862289622906229162292622936229462295622966229762298622996230062301623026230362304623056230662307623086230962310623116231262313623146231562316623176231862319623206232162322623236232462325623266232762328623296233062331623326233362334623356233662337623386233962340623416234262343623446234562346623476234862349623506235162352623536235462355623566235762358623596236062361623626236362364623656236662367623686236962370623716237262373623746237562376623776237862379623806238162382623836238462385623866238762388623896239062391623926239362394623956239662397623986239962400624016240262403624046240562406624076240862409624106241162412624136241462415624166241762418624196242062421624226242362424624256242662427624286242962430624316243262433624346243562436624376243862439624406244162442624436244462445624466244762448624496245062451624526245362454624556245662457624586245962460624616246262463624646246562466624676246862469624706247162472624736247462475624766247762478624796248062481624826248362484624856248662487624886248962490624916249262493624946249562496624976249862499625006250162502625036250462505625066250762508625096251062511625126251362514625156251662517625186251962520625216252262523625246252562526625276252862529625306253162532625336253462535625366253762538625396254062541625426254362544625456254662547625486254962550625516255262553625546255562556625576255862559625606256162562625636256462565625666256762568625696257062571625726257362574625756257662577625786257962580625816258262583625846258562586625876258862589625906259162592625936259462595625966259762598625996260062601626026260362604626056260662607626086260962610626116261262613626146261562616626176261862619626206262162622626236262462625626266262762628626296263062631626326263362634626356263662637626386263962640626416264262643626446264562646626476264862649626506265162652626536265462655626566265762658626596266062661626626266362664626656266662667626686266962670626716267262673626746267562676626776267862679626806268162682626836268462685626866268762688626896269062691626926269362694626956269662697626986269962700627016270262703627046270562706627076270862709627106271162712627136271462715627166271762718627196272062721627226272362724627256272662727627286272962730627316273262733627346273562736627376273862739627406274162742627436274462745627466274762748627496275062751627526275362754627556275662757627586275962760627616276262763627646276562766627676276862769627706277162772627736277462775627766277762778627796278062781627826278362784627856278662787627886278962790627916279262793627946279562796627976279862799628006280162802628036280462805628066280762808628096281062811628126281362814628156281662817628186281962820628216282262823628246282562826628276282862829628306283162832628336283462835628366283762838628396284062841628426284362844628456284662847628486284962850628516285262853628546285562856628576285862859628606286162862628636286462865628666286762868628696287062871628726287362874628756287662877628786287962880628816288262883628846288562886628876288862889628906289162892628936289462895628966289762898628996290062901629026290362904629056290662907629086290962910629116291262913629146291562916629176291862919629206292162922629236292462925629266292762928629296293062931629326293362934629356293662937629386293962940629416294262943629446294562946629476294862949629506295162952629536295462955629566295762958629596296062961629626296362964629656296662967629686296962970629716297262973629746297562976629776297862979629806298162982629836298462985629866298762988629896299062991629926299362994629956299662997629986299963000630016300263003630046300563006630076300863009630106301163012630136301463015630166301763018630196302063021630226302363024630256302663027630286302963030630316303263033630346303563036630376303863039630406304163042630436304463045630466304763048630496305063051630526305363054630556305663057630586305963060630616306263063630646306563066630676306863069630706307163072630736307463075630766307763078630796308063081630826308363084630856308663087630886308963090630916309263093630946309563096630976309863099631006310163102631036310463105631066310763108631096311063111631126311363114631156311663117631186311963120631216312263123631246312563126631276312863129631306313163132631336313463135631366313763138631396314063141631426314363144631456314663147631486314963150631516315263153631546315563156631576315863159631606316163162631636316463165631666316763168631696317063171631726317363174631756317663177631786317963180631816318263183631846318563186631876318863189631906319163192631936319463195631966319763198631996320063201632026320363204632056320663207632086320963210632116321263213632146321563216632176321863219632206322163222632236322463225632266322763228632296323063231632326323363234632356323663237632386323963240632416324263243632446324563246632476324863249632506325163252632536325463255632566325763258632596326063261632626326363264632656326663267632686326963270632716327263273632746327563276632776327863279632806328163282632836328463285632866328763288632896329063291632926329363294632956329663297632986329963300633016330263303633046330563306633076330863309633106331163312633136331463315633166331763318633196332063321633226332363324633256332663327633286332963330633316333263333633346333563336633376333863339633406334163342633436334463345633466334763348633496335063351633526335363354633556335663357633586335963360633616336263363633646336563366633676336863369633706337163372633736337463375633766337763378633796338063381633826338363384633856338663387633886338963390633916339263393633946339563396633976339863399634006340163402634036340463405634066340763408634096341063411634126341363414634156341663417634186341963420634216342263423634246342563426634276342863429634306343163432634336343463435634366343763438634396344063441634426344363444634456344663447634486344963450634516345263453634546345563456634576345863459634606346163462634636346463465634666346763468634696347063471634726347363474634756347663477634786347963480634816348263483634846348563486634876348863489634906349163492634936349463495634966349763498634996350063501635026350363504635056350663507635086350963510635116351263513635146351563516635176351863519635206352163522635236352463525635266352763528635296353063531635326353363534635356353663537635386353963540635416354263543635446354563546635476354863549635506355163552635536355463555635566355763558635596356063561635626356363564635656356663567635686356963570635716357263573635746357563576635776357863579635806358163582635836358463585635866358763588635896359063591635926359363594635956359663597635986359963600636016360263603636046360563606636076360863609636106361163612636136361463615636166361763618636196362063621636226362363624636256362663627636286362963630636316363263633636346363563636636376363863639636406364163642636436364463645636466364763648636496365063651636526365363654636556365663657636586365963660636616366263663636646366563666636676366863669636706367163672636736367463675636766367763678636796368063681636826368363684636856368663687636886368963690636916369263693636946369563696636976369863699637006370163702637036370463705637066370763708637096371063711637126371363714637156371663717637186371963720637216372263723637246372563726637276372863729637306373163732637336373463735637366373763738637396374063741637426374363744637456374663747637486374963750637516375263753637546375563756637576375863759637606376163762637636376463765637666376763768637696377063771637726377363774637756377663777637786377963780637816378263783637846378563786637876378863789637906379163792637936379463795637966379763798637996380063801638026380363804638056380663807638086380963810638116381263813638146381563816638176381863819638206382163822638236382463825638266382763828638296383063831638326383363834638356383663837638386383963840638416384263843638446384563846638476384863849638506385163852638536385463855638566385763858638596386063861638626386363864638656386663867638686386963870638716387263873638746387563876638776387863879638806388163882638836388463885638866388763888638896389063891638926389363894638956389663897638986389963900639016390263903639046390563906639076390863909639106391163912639136391463915639166391763918639196392063921639226392363924639256392663927639286392963930639316393263933639346393563936639376393863939639406394163942639436394463945639466394763948639496395063951639526395363954639556395663957639586395963960639616396263963639646396563966639676396863969639706397163972639736397463975639766397763978639796398063981639826398363984639856398663987639886398963990639916399263993639946399563996639976399863999640006400164002640036400464005640066400764008640096401064011640126401364014640156401664017640186401964020640216402264023640246402564026640276402864029640306403164032640336403464035640366403764038640396404064041640426404364044640456404664047640486404964050640516405264053640546405564056640576405864059640606406164062640636406464065640666406764068640696407064071640726407364074640756407664077640786407964080640816408264083640846408564086640876408864089640906409164092640936409464095640966409764098640996410064101641026410364104641056410664107641086410964110641116411264113641146411564116641176411864119641206412164122641236412464125641266412764128641296413064131641326413364134641356413664137641386413964140641416414264143641446414564146641476414864149641506415164152641536415464155641566415764158641596416064161641626416364164641656416664167641686416964170641716417264173641746417564176641776417864179641806418164182641836418464185641866418764188641896419064191641926419364194641956419664197641986419964200642016420264203642046420564206642076420864209642106421164212642136421464215642166421764218642196422064221642226422364224642256422664227642286422964230642316423264233642346423564236642376423864239642406424164242642436424464245642466424764248642496425064251642526425364254642556425664257642586425964260642616426264263642646426564266642676426864269642706427164272642736427464275642766427764278642796428064281642826428364284642856428664287642886428964290642916429264293642946429564296642976429864299643006430164302643036430464305643066430764308643096431064311643126431364314643156431664317643186431964320643216432264323643246432564326643276432864329643306433164332643336433464335643366433764338643396434064341643426434364344643456434664347643486434964350643516435264353643546435564356643576435864359643606436164362643636436464365643666436764368643696437064371643726437364374643756437664377643786437964380643816438264383643846438564386643876438864389643906439164392643936439464395643966439764398643996440064401644026440364404644056440664407644086440964410644116441264413644146441564416644176441864419644206442164422644236442464425644266442764428644296443064431644326443364434644356443664437644386443964440644416444264443644446444564446644476444864449644506445164452644536445464455644566445764458644596446064461644626446364464644656446664467644686446964470644716447264473644746447564476644776447864479644806448164482644836448464485644866448764488644896449064491644926449364494644956449664497644986449964500645016450264503645046450564506645076450864509645106451164512645136451464515645166451764518645196452064521645226452364524645256452664527645286452964530645316453264533645346453564536645376453864539645406454164542645436454464545645466454764548645496455064551645526455364554645556455664557645586455964560645616456264563645646456564566645676456864569645706457164572645736457464575645766457764578645796458064581645826458364584645856458664587645886458964590645916459264593645946459564596645976459864599646006460164602646036460464605646066460764608646096461064611646126461364614646156461664617646186461964620646216462264623646246462564626646276462864629646306463164632646336463464635646366463764638646396464064641646426464364644646456464664647646486464964650646516465264653646546465564656646576465864659646606466164662646636466464665646666466764668646696467064671646726467364674646756467664677646786467964680646816468264683646846468564686646876468864689646906469164692646936469464695646966469764698646996470064701647026470364704647056470664707647086470964710647116471264713647146471564716647176471864719647206472164722647236472464725647266472764728647296473064731647326473364734647356473664737647386473964740647416474264743647446474564746647476474864749647506475164752647536475464755647566475764758647596476064761647626476364764647656476664767647686476964770647716477264773647746477564776647776477864779647806478164782647836478464785647866478764788647896479064791647926479364794647956479664797647986479964800648016480264803648046480564806648076480864809648106481164812648136481464815648166481764818648196482064821648226482364824648256482664827648286482964830648316483264833648346483564836648376483864839648406484164842648436484464845648466484764848648496485064851648526485364854648556485664857648586485964860648616486264863648646486564866648676486864869648706487164872648736487464875648766487764878648796488064881648826488364884648856488664887648886488964890648916489264893648946489564896648976489864899649006490164902649036490464905649066490764908649096491064911649126491364914649156491664917649186491964920649216492264923649246492564926649276492864929649306493164932649336493464935649366493764938649396494064941649426494364944649456494664947649486494964950649516495264953649546495564956649576495864959649606496164962649636496464965649666496764968649696497064971649726497364974649756497664977649786497964980649816498264983649846498564986649876498864989649906499164992649936499464995649966499764998649996500065001650026500365004650056500665007650086500965010650116501265013650146501565016650176501865019650206502165022650236502465025650266502765028650296503065031650326503365034650356503665037650386503965040650416504265043650446504565046650476504865049650506505165052650536505465055650566505765058650596506065061650626506365064650656506665067650686506965070650716507265073650746507565076650776507865079650806508165082650836508465085650866508765088650896509065091650926509365094650956509665097650986509965100651016510265103651046510565106651076510865109651106511165112651136511465115651166511765118651196512065121651226512365124651256512665127651286512965130651316513265133651346513565136651376513865139651406514165142651436514465145651466514765148651496515065151651526515365154651556515665157651586515965160651616516265163651646516565166651676516865169651706517165172651736517465175651766517765178651796518065181651826518365184651856518665187651886518965190651916519265193651946519565196651976519865199652006520165202652036520465205652066520765208652096521065211652126521365214652156521665217652186521965220652216522265223652246522565226652276522865229652306523165232652336523465235652366523765238652396524065241652426524365244652456524665247652486524965250652516525265253652546525565256652576525865259652606526165262652636526465265652666526765268652696527065271652726527365274652756527665277652786527965280652816528265283652846528565286652876528865289652906529165292652936529465295652966529765298652996530065301653026530365304653056530665307653086530965310653116531265313653146531565316653176531865319653206532165322653236532465325653266532765328653296533065331653326533365334653356533665337653386533965340653416534265343653446534565346653476534865349653506535165352653536535465355653566535765358653596536065361653626536365364653656536665367653686536965370653716537265373653746537565376653776537865379653806538165382653836538465385653866538765388653896539065391653926539365394653956539665397653986539965400654016540265403654046540565406654076540865409654106541165412654136541465415654166541765418654196542065421654226542365424654256542665427654286542965430654316543265433654346543565436654376543865439654406544165442654436544465445654466544765448654496545065451654526545365454654556545665457654586545965460654616546265463654646546565466654676546865469654706547165472654736547465475654766547765478654796548065481654826548365484654856548665487654886548965490654916549265493654946549565496654976549865499655006550165502655036550465505655066550765508655096551065511655126551365514655156551665517655186551965520655216552265523655246552565526655276552865529655306553165532655336553465535655366553765538655396554065541655426554365544655456554665547655486554965550655516555265553655546555565556655576555865559655606556165562655636556465565655666556765568655696557065571655726557365574655756557665577655786557965580655816558265583655846558565586655876558865589655906559165592655936559465595655966559765598655996560065601656026560365604656056560665607656086560965610656116561265613656146561565616656176561865619656206562165622656236562465625656266562765628656296563065631656326563365634656356563665637656386563965640656416564265643656446564565646656476564865649656506565165652656536565465655656566565765658656596566065661656626566365664656656566665667656686566965670656716567265673656746567565676656776567865679656806568165682656836568465685656866568765688656896569065691656926569365694656956569665697656986569965700657016570265703657046570565706657076570865709657106571165712657136571465715657166571765718657196572065721657226572365724657256572665727657286572965730657316573265733657346573565736657376573865739657406574165742657436574465745657466574765748657496575065751657526575365754657556575665757657586575965760657616576265763657646576565766657676576865769657706577165772657736577465775657766577765778657796578065781657826578365784657856578665787657886578965790657916579265793657946579565796657976579865799658006580165802658036580465805658066580765808658096581065811658126581365814658156581665817658186581965820658216582265823658246582565826658276582865829658306583165832658336583465835658366583765838658396584065841658426584365844658456584665847658486584965850658516585265853658546585565856658576585865859658606586165862658636586465865658666586765868658696587065871658726587365874658756587665877658786587965880658816588265883658846588565886658876588865889658906589165892658936589465895658966589765898658996590065901659026590365904659056590665907659086590965910659116591265913659146591565916659176591865919659206592165922659236592465925659266592765928659296593065931659326593365934659356593665937659386593965940659416594265943659446594565946659476594865949659506595165952659536595465955659566595765958659596596065961659626596365964659656596665967659686596965970659716597265973659746597565976659776597865979659806598165982659836598465985659866598765988659896599065991659926599365994659956599665997659986599966000660016600266003660046600566006660076600866009660106601166012660136601466015660166601766018660196602066021660226602366024660256602666027660286602966030660316603266033660346603566036660376603866039660406604166042660436604466045660466604766048660496605066051660526605366054660556605666057660586605966060660616606266063660646606566066660676606866069660706607166072660736607466075660766607766078660796608066081660826608366084660856608666087660886608966090660916609266093660946609566096660976609866099661006610166102661036610466105661066610766108661096611066111661126611366114661156611666117661186611966120661216612266123661246612566126661276612866129661306613166132661336613466135661366613766138661396614066141661426614366144661456614666147661486614966150661516615266153661546615566156661576615866159661606616166162661636616466165661666616766168661696617066171661726617366174661756617666177661786617966180661816618266183661846618566186661876618866189661906619166192661936619466195661966619766198661996620066201662026620366204662056620666207662086620966210662116621266213662146621566216662176621866219662206622166222662236622466225662266622766228662296623066231662326623366234662356623666237662386623966240662416624266243662446624566246662476624866249662506625166252662536625466255662566625766258662596626066261662626626366264662656626666267662686626966270662716627266273662746627566276662776627866279662806628166282662836628466285662866628766288662896629066291662926629366294662956629666297662986629966300663016630266303663046630566306663076630866309663106631166312663136631466315663166631766318663196632066321663226632366324663256632666327663286632966330663316633266333663346633566336663376633866339663406634166342663436634466345663466634766348663496635066351663526635366354663556635666357663586635966360663616636266363663646636566366663676636866369663706637166372663736637466375663766637766378663796638066381663826638366384663856638666387663886638966390663916639266393663946639566396663976639866399664006640166402664036640466405664066640766408664096641066411664126641366414664156641666417664186641966420664216642266423664246642566426664276642866429664306643166432664336643466435664366643766438664396644066441664426644366444664456644666447664486644966450664516645266453664546645566456664576645866459664606646166462664636646466465664666646766468664696647066471664726647366474664756647666477664786647966480664816648266483664846648566486664876648866489664906649166492664936649466495664966649766498664996650066501665026650366504665056650666507665086650966510665116651266513665146651566516665176651866519665206652166522665236652466525665266652766528665296653066531665326653366534665356653666537665386653966540665416654266543665446654566546665476654866549665506655166552665536655466555665566655766558665596656066561665626656366564665656656666567665686656966570665716657266573665746657566576665776657866579665806658166582665836658466585665866658766588665896659066591665926659366594665956659666597665986659966600666016660266603666046660566606666076660866609666106661166612666136661466615666166661766618666196662066621666226662366624666256662666627666286662966630666316663266633666346663566636666376663866639666406664166642666436664466645666466664766648666496665066651666526665366654666556665666657666586665966660666616666266663666646666566666666676666866669666706667166672666736667466675666766667766678666796668066681666826668366684666856668666687666886668966690666916669266693666946669566696666976669866699667006670166702667036670466705667066670766708667096671066711667126671366714667156671666717667186671966720667216672266723667246672566726667276672866729667306673166732667336673466735667366673766738667396674066741667426674366744667456674666747667486674966750667516675266753667546675566756667576675866759667606676166762667636676466765667666676766768667696677066771667726677366774667756677666777667786677966780667816678266783667846678566786667876678866789667906679166792667936679466795667966679766798667996680066801668026680366804668056680666807668086680966810668116681266813668146681566816668176681866819668206682166822668236682466825668266682766828668296683066831668326683366834668356683666837668386683966840668416684266843668446684566846668476684866849668506685166852668536685466855668566685766858668596686066861668626686366864668656686666867668686686966870668716687266873668746687566876668776687866879668806688166882668836688466885668866688766888668896689066891668926689366894668956689666897668986689966900669016690266903669046690566906669076690866909669106691166912669136691466915669166691766918669196692066921669226692366924669256692666927669286692966930669316693266933669346693566936669376693866939669406694166942669436694466945669466694766948669496695066951669526695366954669556695666957669586695966960669616696266963669646696566966669676696866969669706697166972669736697466975669766697766978669796698066981669826698366984669856698666987669886698966990669916699266993669946699566996669976699866999670006700167002670036700467005670066700767008670096701067011670126701367014670156701667017670186701967020670216702267023670246702567026670276702867029670306703167032670336703467035670366703767038670396704067041670426704367044670456704667047670486704967050670516705267053670546705567056670576705867059670606706167062670636706467065670666706767068670696707067071670726707367074670756707667077670786707967080670816708267083670846708567086670876708867089670906709167092670936709467095670966709767098670996710067101671026710367104671056710667107671086710967110671116711267113671146711567116671176711867119671206712167122671236712467125671266712767128671296713067131671326713367134671356713667137671386713967140671416714267143671446714567146671476714867149671506715167152671536715467155671566715767158671596716067161671626716367164671656716667167671686716967170671716717267173671746717567176671776717867179671806718167182671836718467185671866718767188671896719067191671926719367194671956719667197671986719967200672016720267203672046720567206672076720867209672106721167212672136721467215672166721767218672196722067221672226722367224672256722667227672286722967230672316723267233672346723567236672376723867239672406724167242672436724467245672466724767248672496725067251672526725367254672556725667257672586725967260672616726267263672646726567266672676726867269672706727167272672736727467275672766727767278672796728067281672826728367284672856728667287672886728967290672916729267293672946729567296672976729867299673006730167302673036730467305673066730767308673096731067311673126731367314673156731667317673186731967320673216732267323673246732567326673276732867329673306733167332673336733467335673366733767338673396734067341673426734367344673456734667347673486734967350673516735267353673546735567356673576735867359673606736167362673636736467365673666736767368673696737067371673726737367374673756737667377673786737967380673816738267383673846738567386673876738867389673906739167392673936739467395673966739767398673996740067401674026740367404674056740667407674086740967410674116741267413674146741567416674176741867419674206742167422674236742467425674266742767428674296743067431674326743367434674356743667437674386743967440674416744267443674446744567446674476744867449674506745167452674536745467455674566745767458674596746067461674626746367464674656746667467674686746967470674716747267473674746747567476674776747867479674806748167482674836748467485674866748767488674896749067491674926749367494674956749667497674986749967500675016750267503675046750567506675076750867509675106751167512675136751467515675166751767518675196752067521675226752367524675256752667527675286752967530675316753267533675346753567536675376753867539675406754167542675436754467545675466754767548675496755067551675526755367554675556755667557675586755967560675616756267563675646756567566675676756867569675706757167572675736757467575675766757767578675796758067581675826758367584675856758667587675886758967590675916759267593675946759567596675976759867599676006760167602676036760467605676066760767608676096761067611676126761367614676156761667617676186761967620676216762267623676246762567626676276762867629676306763167632676336763467635676366763767638676396764067641676426764367644676456764667647676486764967650676516765267653676546765567656676576765867659676606766167662676636766467665676666766767668676696767067671676726767367674676756767667677676786767967680676816768267683676846768567686676876768867689676906769167692676936769467695676966769767698676996770067701677026770367704677056770667707677086770967710677116771267713677146771567716677176771867719677206772167722677236772467725677266772767728677296773067731677326773367734677356773667737677386773967740677416774267743677446774567746677476774867749677506775167752677536775467755677566775767758677596776067761677626776367764677656776667767677686776967770677716777267773677746777567776677776777867779677806778167782677836778467785677866778767788677896779067791677926779367794677956779667797677986779967800678016780267803678046780567806678076780867809678106781167812678136781467815678166781767818678196782067821678226782367824678256782667827678286782967830678316783267833678346783567836678376783867839678406784167842678436784467845678466784767848678496785067851678526785367854678556785667857678586785967860678616786267863678646786567866678676786867869678706787167872678736787467875678766787767878678796788067881678826788367884678856788667887678886788967890678916789267893678946789567896678976789867899679006790167902679036790467905679066790767908679096791067911679126791367914679156791667917679186791967920679216792267923679246792567926679276792867929679306793167932679336793467935679366793767938679396794067941679426794367944679456794667947679486794967950679516795267953679546795567956679576795867959679606796167962679636796467965679666796767968679696797067971679726797367974679756797667977679786797967980679816798267983679846798567986679876798867989679906799167992679936799467995679966799767998679996800068001680026800368004680056800668007680086800968010680116801268013680146801568016680176801868019680206802168022680236802468025680266802768028680296803068031680326803368034680356803668037680386803968040680416804268043680446804568046680476804868049680506805168052680536805468055680566805768058680596806068061680626806368064680656806668067680686806968070680716807268073680746807568076680776807868079680806808168082680836808468085680866808768088680896809068091680926809368094680956809668097680986809968100681016810268103681046810568106681076810868109681106811168112681136811468115681166811768118681196812068121681226812368124681256812668127681286812968130681316813268133681346813568136681376813868139681406814168142681436814468145681466814768148681496815068151681526815368154681556815668157681586815968160681616816268163681646816568166681676816868169681706817168172681736817468175681766817768178681796818068181681826818368184681856818668187681886818968190681916819268193681946819568196681976819868199682006820168202682036820468205682066820768208682096821068211682126821368214682156821668217682186821968220682216822268223682246822568226682276822868229682306823168232682336823468235682366823768238682396824068241682426824368244682456824668247682486824968250682516825268253682546825568256682576825868259682606826168262682636826468265682666826768268682696827068271682726827368274682756827668277682786827968280682816828268283682846828568286682876828868289682906829168292682936829468295682966829768298682996830068301683026830368304683056830668307683086830968310683116831268313683146831568316683176831868319683206832168322683236832468325683266832768328683296833068331683326833368334683356833668337683386833968340683416834268343683446834568346683476834868349683506835168352683536835468355683566835768358683596836068361683626836368364683656836668367683686836968370683716837268373683746837568376683776837868379683806838168382683836838468385683866838768388683896839068391683926839368394683956839668397683986839968400684016840268403684046840568406684076840868409684106841168412684136841468415684166841768418684196842068421684226842368424684256842668427684286842968430684316843268433684346843568436684376843868439684406844168442684436844468445684466844768448684496845068451684526845368454684556845668457684586845968460684616846268463684646846568466684676846868469684706847168472684736847468475684766847768478684796848068481684826848368484684856848668487684886848968490684916849268493684946849568496684976849868499685006850168502685036850468505685066850768508685096851068511685126851368514685156851668517685186851968520685216852268523685246852568526685276852868529685306853168532685336853468535685366853768538685396854068541685426854368544685456854668547685486854968550685516855268553685546855568556685576855868559685606856168562685636856468565685666856768568685696857068571685726857368574685756857668577685786857968580685816858268583685846858568586685876858868589685906859168592685936859468595685966859768598685996860068601686026860368604686056860668607686086860968610686116861268613686146861568616686176861868619686206862168622686236862468625686266862768628686296863068631686326863368634686356863668637686386863968640686416864268643686446864568646686476864868649686506865168652686536865468655686566865768658686596866068661686626866368664686656866668667686686866968670686716867268673686746867568676686776867868679686806868168682686836868468685686866868768688686896869068691686926869368694686956869668697686986869968700687016870268703687046870568706687076870868709687106871168712687136871468715687166871768718687196872068721687226872368724687256872668727687286872968730687316873268733687346873568736687376873868739687406874168742687436874468745687466874768748687496875068751687526875368754687556875668757687586875968760687616876268763687646876568766687676876868769687706877168772687736877468775687766877768778687796878068781687826878368784687856878668787687886878968790687916879268793687946879568796687976879868799688006880168802688036880468805688066880768808688096881068811688126881368814688156881668817688186881968820688216882268823688246882568826688276882868829688306883168832688336883468835688366883768838688396884068841688426884368844688456884668847688486884968850688516885268853688546885568856688576885868859688606886168862688636886468865688666886768868688696887068871688726887368874688756887668877688786887968880688816888268883688846888568886688876888868889688906889168892688936889468895688966889768898688996890068901689026890368904689056890668907689086890968910689116891268913689146891568916689176891868919689206892168922689236892468925689266892768928689296893068931689326893368934689356893668937689386893968940689416894268943689446894568946689476894868949689506895168952689536895468955689566895768958689596896068961689626896368964689656896668967689686896968970689716897268973689746897568976689776897868979689806898168982689836898468985689866898768988689896899068991689926899368994689956899668997689986899969000690016900269003690046900569006690076900869009690106901169012690136901469015690166901769018690196902069021690226902369024690256902669027690286902969030690316903269033690346903569036690376903869039690406904169042690436904469045690466904769048690496905069051690526905369054690556905669057690586905969060690616906269063690646906569066690676906869069690706907169072690736907469075690766907769078690796908069081690826908369084690856908669087690886908969090690916909269093690946909569096690976909869099691006910169102691036910469105691066910769108691096911069111691126911369114691156911669117691186911969120691216912269123691246912569126691276912869129691306913169132691336913469135691366913769138691396914069141691426914369144691456914669147691486914969150691516915269153691546915569156691576915869159691606916169162691636916469165691666916769168691696917069171691726917369174691756917669177691786917969180691816918269183691846918569186691876918869189691906919169192691936919469195691966919769198691996920069201692026920369204692056920669207692086920969210692116921269213692146921569216692176921869219692206922169222692236922469225692266922769228692296923069231692326923369234692356923669237692386923969240692416924269243692446924569246692476924869249692506925169252692536925469255692566925769258692596926069261692626926369264692656926669267692686926969270692716927269273692746927569276692776927869279692806928169282692836928469285692866928769288692896929069291692926929369294692956929669297692986929969300693016930269303693046930569306693076930869309693106931169312693136931469315693166931769318693196932069321693226932369324693256932669327693286932969330693316933269333693346933569336693376933869339693406934169342693436934469345693466934769348693496935069351693526935369354693556935669357693586935969360693616936269363693646936569366693676936869369693706937169372693736937469375693766937769378693796938069381693826938369384693856938669387693886938969390693916939269393693946939569396693976939869399694006940169402694036940469405694066940769408694096941069411694126941369414694156941669417694186941969420694216942269423694246942569426694276942869429694306943169432694336943469435694366943769438694396944069441694426944369444694456944669447694486944969450694516945269453694546945569456694576945869459694606946169462694636946469465694666946769468694696947069471694726947369474694756947669477694786947969480694816948269483694846948569486694876948869489694906949169492694936949469495694966949769498694996950069501695026950369504695056950669507695086950969510695116951269513695146951569516695176951869519695206952169522695236952469525695266952769528695296953069531695326953369534695356953669537695386953969540695416954269543695446954569546695476954869549695506955169552695536955469555695566955769558695596956069561695626956369564695656956669567695686956969570695716957269573695746957569576695776957869579695806958169582695836958469585695866958769588695896959069591695926959369594695956959669597695986959969600696016960269603696046960569606696076960869609696106961169612696136961469615696166961769618696196962069621696226962369624696256962669627696286962969630696316963269633696346963569636696376963869639696406964169642696436964469645696466964769648696496965069651696526965369654696556965669657696586965969660696616966269663696646966569666696676966869669696706967169672696736967469675696766967769678696796968069681696826968369684696856968669687696886968969690696916969269693696946969569696696976969869699697006970169702697036970469705697066970769708697096971069711697126971369714697156971669717697186971969720697216972269723697246972569726697276972869729697306973169732697336973469735697366973769738697396974069741697426974369744697456974669747697486974969750697516975269753697546975569756697576975869759697606976169762697636976469765697666976769768697696977069771697726977369774697756977669777697786977969780697816978269783697846978569786697876978869789697906979169792697936979469795697966979769798697996980069801698026980369804698056980669807698086980969810698116981269813698146981569816698176981869819698206982169822698236982469825698266982769828698296983069831698326983369834698356983669837698386983969840698416984269843698446984569846698476984869849698506985169852698536985469855698566985769858698596986069861698626986369864698656986669867698686986969870698716987269873698746987569876698776987869879698806988169882698836988469885698866988769888698896989069891698926989369894698956989669897698986989969900699016990269903699046990569906699076990869909699106991169912699136991469915699166991769918699196992069921699226992369924699256992669927699286992969930699316993269933699346993569936699376993869939699406994169942699436994469945699466994769948699496995069951699526995369954699556995669957699586995969960699616996269963699646996569966699676996869969699706997169972699736997469975699766997769978699796998069981699826998369984699856998669987699886998969990699916999269993699946999569996699976999869999700007000170002700037000470005700067000770008700097001070011700127001370014700157001670017700187001970020700217002270023700247002570026700277002870029700307003170032700337003470035700367003770038700397004070041700427004370044700457004670047700487004970050700517005270053700547005570056700577005870059700607006170062700637006470065700667006770068700697007070071700727007370074700757007670077700787007970080700817008270083700847008570086700877008870089700907009170092700937009470095700967009770098700997010070101701027010370104701057010670107701087010970110701117011270113701147011570116701177011870119701207012170122701237012470125701267012770128701297013070131701327013370134701357013670137701387013970140701417014270143701447014570146701477014870149701507015170152701537015470155701567015770158701597016070161701627016370164701657016670167701687016970170701717017270173701747017570176701777017870179701807018170182701837018470185701867018770188701897019070191701927019370194701957019670197701987019970200702017020270203702047020570206702077020870209702107021170212702137021470215702167021770218702197022070221702227022370224702257022670227702287022970230702317023270233702347023570236702377023870239702407024170242702437024470245702467024770248702497025070251702527025370254702557025670257702587025970260702617026270263702647026570266702677026870269702707027170272702737027470275702767027770278702797028070281702827028370284702857028670287702887028970290702917029270293702947029570296702977029870299703007030170302703037030470305703067030770308703097031070311703127031370314703157031670317703187031970320703217032270323703247032570326703277032870329703307033170332703337033470335703367033770338703397034070341703427034370344703457034670347703487034970350703517035270353703547035570356703577035870359703607036170362703637036470365703667036770368703697037070371703727037370374703757037670377703787037970380703817038270383703847038570386703877038870389703907039170392703937039470395703967039770398703997040070401704027040370404704057040670407704087040970410704117041270413704147041570416704177041870419704207042170422704237042470425704267042770428704297043070431704327043370434704357043670437704387043970440704417044270443704447044570446704477044870449704507045170452704537045470455704567045770458704597046070461704627046370464704657046670467704687046970470704717047270473704747047570476704777047870479704807048170482704837048470485704867048770488704897049070491704927049370494704957049670497704987049970500705017050270503705047050570506705077050870509705107051170512705137051470515705167051770518705197052070521705227052370524705257052670527705287052970530705317053270533705347053570536705377053870539705407054170542705437054470545705467054770548705497055070551705527055370554705557055670557705587055970560705617056270563705647056570566705677056870569705707057170572705737057470575705767057770578705797058070581705827058370584705857058670587705887058970590705917059270593705947059570596705977059870599706007060170602706037060470605706067060770608706097061070611706127061370614706157061670617706187061970620706217062270623706247062570626706277062870629706307063170632706337063470635706367063770638706397064070641706427064370644706457064670647706487064970650706517065270653706547065570656706577065870659706607066170662706637066470665706667066770668706697067070671706727067370674706757067670677706787067970680706817068270683706847068570686706877068870689706907069170692706937069470695706967069770698706997070070701707027070370704707057070670707707087070970710707117071270713707147071570716707177071870719707207072170722707237072470725707267072770728707297073070731707327073370734707357073670737707387073970740707417074270743707447074570746707477074870749707507075170752707537075470755707567075770758707597076070761707627076370764707657076670767707687076970770707717077270773707747077570776707777077870779707807078170782707837078470785707867078770788707897079070791707927079370794707957079670797707987079970800708017080270803708047080570806708077080870809708107081170812708137081470815708167081770818708197082070821708227082370824708257082670827708287082970830708317083270833708347083570836708377083870839708407084170842708437084470845708467084770848708497085070851708527085370854708557085670857708587085970860708617086270863708647086570866708677086870869708707087170872708737087470875708767087770878708797088070881708827088370884708857088670887708887088970890708917089270893708947089570896708977089870899709007090170902709037090470905709067090770908709097091070911709127091370914709157091670917709187091970920709217092270923709247092570926709277092870929709307093170932709337093470935709367093770938709397094070941709427094370944709457094670947709487094970950709517095270953709547095570956709577095870959709607096170962709637096470965709667096770968709697097070971709727097370974709757097670977709787097970980709817098270983709847098570986709877098870989709907099170992709937099470995709967099770998709997100071001710027100371004710057100671007710087100971010710117101271013710147101571016710177101871019710207102171022710237102471025710267102771028710297103071031710327103371034710357103671037710387103971040710417104271043710447104571046710477104871049710507105171052710537105471055710567105771058710597106071061710627106371064710657106671067710687106971070710717107271073710747107571076710777107871079710807108171082710837108471085710867108771088710897109071091710927109371094710957109671097710987109971100711017110271103711047110571106711077110871109711107111171112711137111471115711167111771118711197112071121711227112371124711257112671127711287112971130711317113271133711347113571136711377113871139711407114171142711437114471145711467114771148711497115071151711527115371154711557115671157711587115971160711617116271163711647116571166711677116871169711707117171172711737117471175711767117771178711797118071181711827118371184711857118671187711887118971190711917119271193711947119571196711977119871199712007120171202712037120471205712067120771208712097121071211712127121371214712157121671217712187121971220712217122271223712247122571226712277122871229712307123171232712337123471235712367123771238712397124071241712427124371244712457124671247712487124971250712517125271253712547125571256712577125871259712607126171262712637126471265712667126771268712697127071271712727127371274712757127671277712787127971280712817128271283712847128571286712877128871289712907129171292712937129471295712967129771298712997130071301713027130371304713057130671307713087130971310713117131271313713147131571316713177131871319713207132171322713237132471325713267132771328713297133071331713327133371334713357133671337713387133971340713417134271343713447134571346713477134871349713507135171352713537135471355713567135771358713597136071361713627136371364713657136671367713687136971370713717137271373713747137571376713777137871379713807138171382713837138471385713867138771388713897139071391713927139371394713957139671397713987139971400714017140271403714047140571406714077140871409714107141171412714137141471415714167141771418714197142071421714227142371424714257142671427714287142971430714317143271433714347143571436714377143871439714407144171442714437144471445714467144771448714497145071451714527145371454714557145671457714587145971460714617146271463714647146571466714677146871469714707147171472714737147471475714767147771478714797148071481714827148371484714857148671487714887148971490714917149271493714947149571496714977149871499715007150171502715037150471505715067150771508715097151071511715127151371514715157151671517715187151971520715217152271523715247152571526715277152871529715307153171532715337153471535715367153771538715397154071541715427154371544715457154671547715487154971550715517155271553715547155571556715577155871559715607156171562715637156471565715667156771568715697157071571715727157371574715757157671577715787157971580715817158271583715847158571586715877158871589715907159171592715937159471595715967159771598715997160071601716027160371604716057160671607716087160971610716117161271613716147161571616716177161871619716207162171622716237162471625716267162771628716297163071631716327163371634716357163671637716387163971640716417164271643716447164571646716477164871649716507165171652716537165471655716567165771658716597166071661716627166371664716657166671667716687166971670716717167271673716747167571676716777167871679716807168171682716837168471685716867168771688716897169071691716927169371694716957169671697716987169971700717017170271703717047170571706717077170871709717107171171712717137171471715717167171771718717197172071721717227172371724717257172671727717287172971730717317173271733717347173571736717377173871739717407174171742717437174471745717467174771748717497175071751717527175371754717557175671757717587175971760717617176271763717647176571766717677176871769717707177171772717737177471775717767177771778717797178071781717827178371784717857178671787717887178971790717917179271793717947179571796717977179871799718007180171802718037180471805718067180771808718097181071811718127181371814718157181671817718187181971820718217182271823718247182571826718277182871829718307183171832718337183471835718367183771838718397184071841718427184371844718457184671847718487184971850718517185271853718547185571856718577185871859718607186171862718637186471865718667186771868718697187071871718727187371874718757187671877718787187971880718817188271883718847188571886718877188871889718907189171892718937189471895718967189771898718997190071901719027190371904719057190671907719087190971910719117191271913719147191571916719177191871919719207192171922719237192471925719267192771928719297193071931719327193371934719357193671937719387193971940719417194271943719447194571946719477194871949719507195171952719537195471955719567195771958719597196071961719627196371964719657196671967719687196971970719717197271973719747197571976719777197871979719807198171982719837198471985719867198771988719897199071991719927199371994719957199671997719987199972000720017200272003720047200572006720077200872009720107201172012720137201472015720167201772018720197202072021720227202372024720257202672027720287202972030720317203272033720347203572036720377203872039720407204172042720437204472045720467204772048720497205072051720527205372054720557205672057720587205972060720617206272063720647206572066720677206872069720707207172072720737207472075720767207772078720797208072081720827208372084720857208672087720887208972090720917209272093720947209572096720977209872099721007210172102721037210472105721067210772108721097211072111721127211372114721157211672117721187211972120721217212272123721247212572126721277212872129721307213172132721337213472135721367213772138721397214072141721427214372144721457214672147721487214972150721517215272153721547215572156721577215872159721607216172162721637216472165721667216772168721697217072171721727217372174721757217672177721787217972180721817218272183721847218572186721877218872189721907219172192721937219472195721967219772198721997220072201722027220372204722057220672207722087220972210722117221272213722147221572216722177221872219722207222172222722237222472225722267222772228722297223072231722327223372234722357223672237722387223972240722417224272243722447224572246722477224872249722507225172252722537225472255722567225772258722597226072261722627226372264722657226672267722687226972270722717227272273722747227572276722777227872279722807228172282722837228472285722867228772288722897229072291722927229372294722957229672297722987229972300723017230272303723047230572306723077230872309723107231172312723137231472315723167231772318723197232072321723227232372324723257232672327723287232972330723317233272333723347233572336723377233872339723407234172342723437234472345723467234772348723497235072351723527235372354723557235672357723587235972360723617236272363723647236572366723677236872369723707237172372723737237472375723767237772378723797238072381723827238372384723857238672387723887238972390723917239272393723947239572396723977239872399724007240172402724037240472405724067240772408724097241072411724127241372414724157241672417724187241972420724217242272423724247242572426724277242872429724307243172432724337243472435724367243772438724397244072441724427244372444724457244672447724487244972450724517245272453724547245572456724577245872459724607246172462724637246472465724667246772468724697247072471724727247372474724757247672477724787247972480724817248272483724847248572486724877248872489724907249172492724937249472495724967249772498724997250072501725027250372504725057250672507725087250972510725117251272513725147251572516725177251872519725207252172522725237252472525725267252772528725297253072531725327253372534725357253672537725387253972540725417254272543725447254572546725477254872549725507255172552725537255472555725567255772558725597256072561725627256372564725657256672567725687256972570725717257272573725747257572576725777257872579725807258172582725837258472585725867258772588725897259072591725927259372594725957259672597725987259972600726017260272603726047260572606726077260872609726107261172612726137261472615726167261772618726197262072621726227262372624726257262672627726287262972630726317263272633726347263572636726377263872639726407264172642726437264472645726467264772648726497265072651726527265372654726557265672657726587265972660726617266272663726647266572666726677266872669726707267172672726737267472675726767267772678726797268072681726827268372684726857268672687726887268972690726917269272693726947269572696726977269872699727007270172702727037270472705727067270772708727097271072711727127271372714727157271672717727187271972720727217272272723727247272572726727277272872729727307273172732727337273472735727367273772738727397274072741727427274372744727457274672747727487274972750727517275272753727547275572756727577275872759727607276172762727637276472765727667276772768727697277072771727727277372774727757277672777727787277972780727817278272783727847278572786727877278872789727907279172792727937279472795727967279772798727997280072801728027280372804728057280672807728087280972810728117281272813728147281572816728177281872819728207282172822728237282472825728267282772828728297283072831728327283372834728357283672837728387283972840728417284272843728447284572846728477284872849728507285172852728537285472855728567285772858728597286072861728627286372864728657286672867728687286972870728717287272873728747287572876728777287872879728807288172882728837288472885728867288772888728897289072891728927289372894728957289672897728987289972900729017290272903729047290572906729077290872909729107291172912729137291472915729167291772918729197292072921729227292372924729257292672927729287292972930729317293272933729347293572936729377293872939729407294172942729437294472945729467294772948729497295072951729527295372954729557295672957729587295972960729617296272963729647296572966729677296872969729707297172972729737297472975729767297772978729797298072981729827298372984729857298672987729887298972990729917299272993729947299572996729977299872999730007300173002730037300473005730067300773008730097301073011730127301373014730157301673017730187301973020730217302273023730247302573026730277302873029730307303173032730337303473035730367303773038730397304073041730427304373044730457304673047730487304973050730517305273053730547305573056730577305873059730607306173062730637306473065730667306773068730697307073071730727307373074730757307673077730787307973080730817308273083730847308573086730877308873089730907309173092730937309473095730967309773098730997310073101731027310373104731057310673107731087310973110731117311273113731147311573116731177311873119731207312173122731237312473125731267312773128731297313073131731327313373134731357313673137731387313973140731417314273143731447314573146731477314873149731507315173152731537315473155731567315773158731597316073161731627316373164731657316673167731687316973170731717317273173731747317573176731777317873179731807318173182731837318473185731867318773188731897319073191731927319373194731957319673197731987319973200732017320273203732047320573206732077320873209732107321173212732137321473215732167321773218732197322073221732227322373224732257322673227732287322973230732317323273233732347323573236732377323873239732407324173242732437324473245732467324773248732497325073251732527325373254732557325673257732587325973260732617326273263732647326573266732677326873269732707327173272732737327473275732767327773278732797328073281732827328373284732857328673287732887328973290732917329273293732947329573296732977329873299733007330173302733037330473305733067330773308733097331073311733127331373314733157331673317733187331973320733217332273323733247332573326733277332873329733307333173332733337333473335733367333773338733397334073341733427334373344733457334673347733487334973350733517335273353733547335573356733577335873359733607336173362733637336473365733667336773368733697337073371733727337373374733757337673377733787337973380733817338273383733847338573386733877338873389733907339173392733937339473395733967339773398733997340073401734027340373404734057340673407734087340973410734117341273413734147341573416734177341873419734207342173422734237342473425734267342773428734297343073431734327343373434734357343673437734387343973440734417344273443734447344573446734477344873449734507345173452734537345473455734567345773458734597346073461734627346373464734657346673467734687346973470734717347273473734747347573476734777347873479734807348173482734837348473485734867348773488734897349073491734927349373494734957349673497734987349973500735017350273503735047350573506735077350873509735107351173512735137351473515735167351773518735197352073521735227352373524735257352673527735287352973530735317353273533735347353573536735377353873539735407354173542735437354473545735467354773548735497355073551735527355373554735557355673557735587355973560735617356273563735647356573566735677356873569735707357173572735737357473575735767357773578735797358073581735827358373584735857358673587735887358973590735917359273593735947359573596735977359873599736007360173602736037360473605736067360773608736097361073611736127361373614736157361673617736187361973620736217362273623736247362573626736277362873629736307363173632736337363473635736367363773638736397364073641736427364373644736457364673647736487364973650736517365273653736547365573656736577365873659736607366173662736637366473665736667366773668736697367073671736727367373674736757367673677736787367973680736817368273683736847368573686736877368873689736907369173692736937369473695736967369773698736997370073701737027370373704737057370673707737087370973710737117371273713737147371573716737177371873719737207372173722737237372473725737267372773728737297373073731737327373373734737357373673737737387373973740737417374273743737447374573746737477374873749737507375173752737537375473755737567375773758737597376073761737627376373764737657376673767737687376973770737717377273773737747377573776737777377873779737807378173782737837378473785737867378773788737897379073791737927379373794737957379673797737987379973800738017380273803738047380573806738077380873809738107381173812738137381473815738167381773818738197382073821738227382373824738257382673827738287382973830738317383273833738347383573836738377383873839738407384173842738437384473845738467384773848738497385073851738527385373854738557385673857738587385973860738617386273863738647386573866738677386873869738707387173872738737387473875738767387773878738797388073881738827388373884738857388673887738887388973890738917389273893738947389573896738977389873899739007390173902739037390473905739067390773908739097391073911739127391373914739157391673917739187391973920739217392273923739247392573926739277392873929739307393173932739337393473935739367393773938739397394073941739427394373944739457394673947739487394973950739517395273953739547395573956739577395873959739607396173962739637396473965739667396773968739697397073971739727397373974739757397673977739787397973980739817398273983739847398573986739877398873989739907399173992739937399473995739967399773998739997400074001740027400374004740057400674007740087400974010740117401274013740147401574016740177401874019740207402174022740237402474025740267402774028740297403074031740327403374034740357403674037740387403974040740417404274043740447404574046740477404874049740507405174052740537405474055740567405774058740597406074061740627406374064740657406674067740687406974070740717407274073740747407574076740777407874079740807408174082740837408474085740867408774088740897409074091740927409374094740957409674097740987409974100741017410274103741047410574106741077410874109741107411174112741137411474115741167411774118741197412074121741227412374124741257412674127741287412974130741317413274133741347413574136741377413874139741407414174142741437414474145741467414774148741497415074151741527415374154741557415674157741587415974160741617416274163741647416574166741677416874169741707417174172741737417474175741767417774178741797418074181741827418374184741857418674187741887418974190741917419274193741947419574196741977419874199742007420174202742037420474205742067420774208742097421074211742127421374214742157421674217742187421974220742217422274223742247422574226742277422874229742307423174232742337423474235742367423774238742397424074241742427424374244742457424674247742487424974250742517425274253742547425574256742577425874259742607426174262742637426474265742667426774268742697427074271742727427374274742757427674277742787427974280742817428274283742847428574286742877428874289742907429174292742937429474295742967429774298742997430074301743027430374304743057430674307743087430974310743117431274313743147431574316743177431874319743207432174322743237432474325743267432774328743297433074331743327433374334743357433674337743387433974340743417434274343743447434574346743477434874349743507435174352743537435474355743567435774358743597436074361743627436374364743657436674367743687436974370743717437274373743747437574376743777437874379743807438174382743837438474385743867438774388743897439074391743927439374394743957439674397743987439974400744017440274403744047440574406744077440874409744107441174412744137441474415744167441774418744197442074421744227442374424744257442674427744287442974430744317443274433744347443574436744377443874439744407444174442744437444474445744467444774448744497445074451744527445374454744557445674457744587445974460744617446274463744647446574466744677446874469744707447174472744737447474475744767447774478744797448074481744827448374484744857448674487744887448974490744917449274493744947449574496744977449874499745007450174502745037450474505745067450774508745097451074511745127451374514745157451674517745187451974520745217452274523745247452574526745277452874529745307453174532745337453474535745367453774538745397454074541745427454374544745457454674547745487454974550745517455274553745547455574556745577455874559745607456174562745637456474565745667456774568745697457074571745727457374574745757457674577745787457974580745817458274583745847458574586745877458874589745907459174592745937459474595745967459774598745997460074601746027460374604746057460674607746087460974610746117461274613746147461574616746177461874619746207462174622746237462474625746267462774628746297463074631746327463374634746357463674637746387463974640746417464274643746447464574646746477464874649746507465174652746537465474655746567465774658746597466074661746627466374664746657466674667746687466974670746717467274673746747467574676746777467874679746807468174682746837468474685746867468774688746897469074691746927469374694746957469674697746987469974700747017470274703747047470574706747077470874709747107471174712747137471474715747167471774718747197472074721747227472374724747257472674727747287472974730747317473274733747347473574736747377473874739747407474174742747437474474745747467474774748747497475074751747527475374754747557475674757747587475974760747617476274763747647476574766747677476874769747707477174772747737477474775747767477774778747797478074781747827478374784747857478674787747887478974790747917479274793747947479574796
  1. (function webpackUniversalModuleDefinition(root, factory) {
  2. if(typeof exports === 'object' && typeof module === 'object')
  3. module.exports = factory();
  4. else if(typeof define === 'function' && define.amd)
  5. define([], factory);
  6. else if(typeof exports === 'object')
  7. exports["echarts"] = factory();
  8. else
  9. root["echarts"] = factory();
  10. })(this, function() {
  11. return /******/ (function(modules) { // webpackBootstrap
  12. /******/ // The module cache
  13. /******/ var installedModules = {};
  14. /******/ // The require function
  15. /******/ function __webpack_require__(moduleId) {
  16. /******/ // Check if module is in cache
  17. /******/ if(installedModules[moduleId])
  18. /******/ return installedModules[moduleId].exports;
  19. /******/ // Create a new module (and put it into the cache)
  20. /******/ var module = installedModules[moduleId] = {
  21. /******/ exports: {},
  22. /******/ id: moduleId,
  23. /******/ loaded: false
  24. /******/ };
  25. /******/ // Execute the module function
  26. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  27. /******/ // Flag the module as loaded
  28. /******/ module.loaded = true;
  29. /******/ // Return the exports of the module
  30. /******/ return module.exports;
  31. /******/ }
  32. /******/ // expose the modules object (__webpack_modules__)
  33. /******/ __webpack_require__.m = modules;
  34. /******/ // expose the module cache
  35. /******/ __webpack_require__.c = installedModules;
  36. /******/ // __webpack_public_path__
  37. /******/ __webpack_require__.p = "";
  38. /******/ // Load entry module and return exports
  39. /******/ return __webpack_require__(0);
  40. /******/ })
  41. /************************************************************************/
  42. /******/ ([
  43. /* 0 */
  44. /***/ function(module, exports, __webpack_require__) {
  45. /**
  46. * Export echarts as CommonJS module
  47. */
  48. module.exports = __webpack_require__(1);
  49. // Import all charts and components
  50. __webpack_require__(113);
  51. __webpack_require__(139);
  52. __webpack_require__(146);
  53. __webpack_require__(155);
  54. __webpack_require__(159);
  55. __webpack_require__(169);
  56. __webpack_require__(192);
  57. __webpack_require__(204);
  58. __webpack_require__(225);
  59. __webpack_require__(229);
  60. __webpack_require__(233);
  61. __webpack_require__(250);
  62. __webpack_require__(256);
  63. __webpack_require__(263);
  64. __webpack_require__(269);
  65. __webpack_require__(273);
  66. __webpack_require__(282);
  67. __webpack_require__(286);
  68. __webpack_require__(289);
  69. __webpack_require__(312);
  70. __webpack_require__(318);
  71. __webpack_require__(319);
  72. __webpack_require__(320);
  73. __webpack_require__(326);
  74. __webpack_require__(297);
  75. __webpack_require__(330);
  76. __webpack_require__(343);
  77. __webpack_require__(234);
  78. __webpack_require__(290);
  79. __webpack_require__(346);
  80. __webpack_require__(357);
  81. __webpack_require__(361);
  82. __webpack_require__(362);
  83. __webpack_require__(375);
  84. __webpack_require__(390);
  85. __webpack_require__(396);
  86. __webpack_require__(399);
  87. __webpack_require__(402);
  88. __webpack_require__(411);
  89. __webpack_require__(423);
  90. /***/ },
  91. /* 1 */
  92. /***/ function(module, exports, __webpack_require__) {
  93. /*!
  94. * ECharts, a javascript interactive chart library.
  95. *
  96. * Copyright (c) 2015, Baidu Inc.
  97. * All rights reserved.
  98. *
  99. * LICENSE
  100. * https://github.com/ecomfe/echarts/blob/master/LICENSE.txt
  101. */
  102. /**
  103. * @module echarts
  104. */
  105. var env = __webpack_require__(2);
  106. var GlobalModel = __webpack_require__(3);
  107. var ExtensionAPI = __webpack_require__(75);
  108. var CoordinateSystemManager = __webpack_require__(76);
  109. var OptionManager = __webpack_require__(77);
  110. var ComponentModel = __webpack_require__(69);
  111. var SeriesModel = __webpack_require__(78);
  112. var ComponentView = __webpack_require__(79);
  113. var ChartView = __webpack_require__(80);
  114. var graphic = __webpack_require__(18);
  115. var modelUtil = __webpack_require__(5);
  116. var throttle = __webpack_require__(81);
  117. var zrender = __webpack_require__(82);
  118. var zrUtil = __webpack_require__(4);
  119. var colorTool = __webpack_require__(31);
  120. var Eventful = __webpack_require__(25);
  121. var timsort = __webpack_require__(86);
  122. var each = zrUtil.each;
  123. var parseClassType = ComponentModel.parseClassType;
  124. var PRIORITY_PROCESSOR_FILTER = 1000;
  125. var PRIORITY_PROCESSOR_STATISTIC = 5000;
  126. var PRIORITY_VISUAL_LAYOUT = 1000;
  127. var PRIORITY_VISUAL_GLOBAL = 2000;
  128. var PRIORITY_VISUAL_CHART = 3000;
  129. var PRIORITY_VISUAL_COMPONENT = 4000;
  130. // FIXME
  131. // necessary?
  132. var PRIORITY_VISUAL_BRUSH = 5000;
  133. // Main process have three entries: `setOption`, `dispatchAction` and `resize`,
  134. // where they must not be invoked nestedly, except the only case: invoke
  135. // dispatchAction with updateMethod "none" in main process.
  136. // This flag is used to carry out this rule.
  137. // All events will be triggered out side main process (i.e. when !this[IN_MAIN_PROCESS]).
  138. var IN_MAIN_PROCESS = '__flagInMainProcess';
  139. var HAS_GRADIENT_OR_PATTERN_BG = '__hasGradientOrPatternBg';
  140. var OPTION_UPDATED = '__optionUpdated';
  141. var ACTION_REG = /^[a-zA-Z0-9_]+$/;
  142. function createRegisterEventWithLowercaseName(method) {
  143. return function (eventName, handler, context) {
  144. // Event name is all lowercase
  145. eventName = eventName && eventName.toLowerCase();
  146. Eventful.prototype[method].call(this, eventName, handler, context);
  147. };
  148. }
  149. /**
  150. * @module echarts~MessageCenter
  151. */
  152. function MessageCenter() {
  153. Eventful.call(this);
  154. }
  155. MessageCenter.prototype.on = createRegisterEventWithLowercaseName('on');
  156. MessageCenter.prototype.off = createRegisterEventWithLowercaseName('off');
  157. MessageCenter.prototype.one = createRegisterEventWithLowercaseName('one');
  158. zrUtil.mixin(MessageCenter, Eventful);
  159. /**
  160. * @module echarts~ECharts
  161. */
  162. function ECharts(dom, theme, opts) {
  163. opts = opts || {};
  164. // Get theme by name
  165. if (typeof theme === 'string') {
  166. theme = themeStorage[theme];
  167. }
  168. /**
  169. * @type {string}
  170. */
  171. this.id;
  172. /**
  173. * Group id
  174. * @type {string}
  175. */
  176. this.group;
  177. /**
  178. * @type {HTMLDomElement}
  179. * @private
  180. */
  181. this._dom = dom;
  182. /**
  183. * @type {module:zrender/ZRender}
  184. * @private
  185. */
  186. var zr = this._zr = zrender.init(dom, {
  187. renderer: opts.renderer || 'canvas',
  188. devicePixelRatio: opts.devicePixelRatio,
  189. width: opts.width,
  190. height: opts.height
  191. });
  192. /**
  193. * Expect 60 pfs.
  194. * @type {Function}
  195. * @private
  196. */
  197. this._throttledZrFlush = throttle.throttle(zrUtil.bind(zr.flush, zr), 17);
  198. /**
  199. * @type {Object}
  200. * @private
  201. */
  202. this._theme = zrUtil.clone(theme);
  203. /**
  204. * @type {Array.<module:echarts/view/Chart>}
  205. * @private
  206. */
  207. this._chartsViews = [];
  208. /**
  209. * @type {Object.<string, module:echarts/view/Chart>}
  210. * @private
  211. */
  212. this._chartsMap = {};
  213. /**
  214. * @type {Array.<module:echarts/view/Component>}
  215. * @private
  216. */
  217. this._componentsViews = [];
  218. /**
  219. * @type {Object.<string, module:echarts/view/Component>}
  220. * @private
  221. */
  222. this._componentsMap = {};
  223. /**
  224. * @type {module:echarts/CoordinateSystem}
  225. * @private
  226. */
  227. this._coordSysMgr = new CoordinateSystemManager();
  228. /**
  229. * @type {module:echarts/ExtensionAPI}
  230. * @private
  231. */
  232. this._api = createExtensionAPI(this);
  233. Eventful.call(this);
  234. /**
  235. * @type {module:echarts~MessageCenter}
  236. * @private
  237. */
  238. this._messageCenter = new MessageCenter();
  239. // Init mouse events
  240. this._initEvents();
  241. // In case some people write `window.onresize = chart.resize`
  242. this.resize = zrUtil.bind(this.resize, this);
  243. // Can't dispatch action during rendering procedure
  244. this._pendingActions = [];
  245. // Sort on demand
  246. function prioritySortFunc(a, b) {
  247. return a.prio - b.prio;
  248. }
  249. timsort(visualFuncs, prioritySortFunc);
  250. timsort(dataProcessorFuncs, prioritySortFunc);
  251. zr.animation.on('frame', this._onframe, this);
  252. // ECharts instance can be used as value.
  253. zrUtil.setAsPrimitive(this);
  254. }
  255. var echartsProto = ECharts.prototype;
  256. echartsProto._onframe = function () {
  257. // Lazy update
  258. if (this[OPTION_UPDATED]) {
  259. var silent = this[OPTION_UPDATED].silent;
  260. this[IN_MAIN_PROCESS] = true;
  261. updateMethods.prepareAndUpdate.call(this);
  262. this[IN_MAIN_PROCESS] = false;
  263. this[OPTION_UPDATED] = false;
  264. flushPendingActions.call(this, silent);
  265. triggerUpdatedEvent.call(this, silent);
  266. }
  267. };
  268. /**
  269. * @return {HTMLDomElement}
  270. */
  271. echartsProto.getDom = function () {
  272. return this._dom;
  273. };
  274. /**
  275. * @return {module:zrender~ZRender}
  276. */
  277. echartsProto.getZr = function () {
  278. return this._zr;
  279. };
  280. /**
  281. * Usage:
  282. * chart.setOption(option, notMerge, lazyUpdate);
  283. * chart.setOption(option, {
  284. * notMerge: ...,
  285. * lazyUpdate: ...,
  286. * silent: ...
  287. * });
  288. *
  289. * @param {Object} option
  290. * @param {Object|boolean} [opts] opts or notMerge.
  291. * @param {boolean} [opts.notMerge=false]
  292. * @param {boolean} [opts.lazyUpdate=false] Useful when setOption frequently.
  293. */
  294. echartsProto.setOption = function (option, notMerge, lazyUpdate) {
  295. if (true) {
  296. zrUtil.assert(!this[IN_MAIN_PROCESS], '`setOption` should not be called during main process.');
  297. }
  298. var silent;
  299. if (zrUtil.isObject(notMerge)) {
  300. lazyUpdate = notMerge.lazyUpdate;
  301. silent = notMerge.silent;
  302. notMerge = notMerge.notMerge;
  303. }
  304. this[IN_MAIN_PROCESS] = true;
  305. if (!this._model || notMerge) {
  306. var optionManager = new OptionManager(this._api);
  307. var theme = this._theme;
  308. var ecModel = this._model = new GlobalModel(null, null, theme, optionManager);
  309. ecModel.init(null, null, theme, optionManager);
  310. }
  311. this._model.setOption(option, optionPreprocessorFuncs);
  312. if (lazyUpdate) {
  313. this[OPTION_UPDATED] = {silent: silent};
  314. this[IN_MAIN_PROCESS] = false;
  315. }
  316. else {
  317. updateMethods.prepareAndUpdate.call(this);
  318. // Ensure zr refresh sychronously, and then pixel in canvas can be
  319. // fetched after `setOption`.
  320. this._zr.flush();
  321. this[OPTION_UPDATED] = false;
  322. this[IN_MAIN_PROCESS] = false;
  323. flushPendingActions.call(this, silent);
  324. triggerUpdatedEvent.call(this, silent);
  325. }
  326. };
  327. /**
  328. * @DEPRECATED
  329. */
  330. echartsProto.setTheme = function () {
  331. console.log('ECharts#setTheme() is DEPRECATED in ECharts 3.0');
  332. };
  333. /**
  334. * @return {module:echarts/model/Global}
  335. */
  336. echartsProto.getModel = function () {
  337. return this._model;
  338. };
  339. /**
  340. * @return {Object}
  341. */
  342. echartsProto.getOption = function () {
  343. return this._model && this._model.getOption();
  344. };
  345. /**
  346. * @return {number}
  347. */
  348. echartsProto.getWidth = function () {
  349. return this._zr.getWidth();
  350. };
  351. /**
  352. * @return {number}
  353. */
  354. echartsProto.getHeight = function () {
  355. return this._zr.getHeight();
  356. };
  357. /**
  358. * @return {number}
  359. */
  360. echartsProto.getDevicePixelRatio = function () {
  361. return this._zr.painter.dpr || window.devicePixelRatio || 1;
  362. };
  363. /**
  364. * Get canvas which has all thing rendered
  365. * @param {Object} opts
  366. * @param {string} [opts.backgroundColor]
  367. */
  368. echartsProto.getRenderedCanvas = function (opts) {
  369. if (!env.canvasSupported) {
  370. return;
  371. }
  372. opts = opts || {};
  373. opts.pixelRatio = opts.pixelRatio || 1;
  374. opts.backgroundColor = opts.backgroundColor
  375. || this._model.get('backgroundColor');
  376. var zr = this._zr;
  377. var list = zr.storage.getDisplayList();
  378. // Stop animations
  379. zrUtil.each(list, function (el) {
  380. el.stopAnimation(true);
  381. });
  382. return zr.painter.getRenderedCanvas(opts);
  383. };
  384. /**
  385. * @return {string}
  386. * @param {Object} opts
  387. * @param {string} [opts.type='png']
  388. * @param {string} [opts.pixelRatio=1]
  389. * @param {string} [opts.backgroundColor]
  390. * @param {string} [opts.excludeComponents]
  391. */
  392. echartsProto.getDataURL = function (opts) {
  393. opts = opts || {};
  394. var excludeComponents = opts.excludeComponents;
  395. var ecModel = this._model;
  396. var excludesComponentViews = [];
  397. var self = this;
  398. each(excludeComponents, function (componentType) {
  399. ecModel.eachComponent({
  400. mainType: componentType
  401. }, function (component) {
  402. var view = self._componentsMap[component.__viewId];
  403. if (!view.group.ignore) {
  404. excludesComponentViews.push(view);
  405. view.group.ignore = true;
  406. }
  407. });
  408. });
  409. var url = this.getRenderedCanvas(opts).toDataURL(
  410. 'image/' + (opts && opts.type || 'png')
  411. );
  412. each(excludesComponentViews, function (view) {
  413. view.group.ignore = false;
  414. });
  415. return url;
  416. };
  417. /**
  418. * @return {string}
  419. * @param {Object} opts
  420. * @param {string} [opts.type='png']
  421. * @param {string} [opts.pixelRatio=1]
  422. * @param {string} [opts.backgroundColor]
  423. */
  424. echartsProto.getConnectedDataURL = function (opts) {
  425. if (!env.canvasSupported) {
  426. return;
  427. }
  428. var groupId = this.group;
  429. var mathMin = Math.min;
  430. var mathMax = Math.max;
  431. var MAX_NUMBER = Infinity;
  432. if (connectedGroups[groupId]) {
  433. var left = MAX_NUMBER;
  434. var top = MAX_NUMBER;
  435. var right = -MAX_NUMBER;
  436. var bottom = -MAX_NUMBER;
  437. var canvasList = [];
  438. var dpr = (opts && opts.pixelRatio) || 1;
  439. zrUtil.each(instances, function (chart, id) {
  440. if (chart.group === groupId) {
  441. var canvas = chart.getRenderedCanvas(
  442. zrUtil.clone(opts)
  443. );
  444. var boundingRect = chart.getDom().getBoundingClientRect();
  445. left = mathMin(boundingRect.left, left);
  446. top = mathMin(boundingRect.top, top);
  447. right = mathMax(boundingRect.right, right);
  448. bottom = mathMax(boundingRect.bottom, bottom);
  449. canvasList.push({
  450. dom: canvas,
  451. left: boundingRect.left,
  452. top: boundingRect.top
  453. });
  454. }
  455. });
  456. left *= dpr;
  457. top *= dpr;
  458. right *= dpr;
  459. bottom *= dpr;
  460. var width = right - left;
  461. var height = bottom - top;
  462. var targetCanvas = zrUtil.createCanvas();
  463. targetCanvas.width = width;
  464. targetCanvas.height = height;
  465. var zr = zrender.init(targetCanvas);
  466. each(canvasList, function (item) {
  467. var img = new graphic.Image({
  468. style: {
  469. x: item.left * dpr - left,
  470. y: item.top * dpr - top,
  471. image: item.dom
  472. }
  473. });
  474. zr.add(img);
  475. });
  476. zr.refreshImmediately();
  477. return targetCanvas.toDataURL('image/' + (opts && opts.type || 'png'));
  478. }
  479. else {
  480. return this.getDataURL(opts);
  481. }
  482. };
  483. /**
  484. * Convert from logical coordinate system to pixel coordinate system.
  485. * See CoordinateSystem#convertToPixel.
  486. * @param {string|Object} finder
  487. * If string, e.g., 'geo', means {geoIndex: 0}.
  488. * If Object, could contain some of these properties below:
  489. * {
  490. * seriesIndex / seriesId / seriesName,
  491. * geoIndex / geoId, geoName,
  492. * bmapIndex / bmapId / bmapName,
  493. * xAxisIndex / xAxisId / xAxisName,
  494. * yAxisIndex / yAxisId / yAxisName,
  495. * gridIndex / gridId / gridName,
  496. * ... (can be extended)
  497. * }
  498. * @param {Array|number} value
  499. * @return {Array|number} result
  500. */
  501. echartsProto.convertToPixel = zrUtil.curry(doConvertPixel, 'convertToPixel');
  502. /**
  503. * Convert from pixel coordinate system to logical coordinate system.
  504. * See CoordinateSystem#convertFromPixel.
  505. * @param {string|Object} finder
  506. * If string, e.g., 'geo', means {geoIndex: 0}.
  507. * If Object, could contain some of these properties below:
  508. * {
  509. * seriesIndex / seriesId / seriesName,
  510. * geoIndex / geoId / geoName,
  511. * bmapIndex / bmapId / bmapName,
  512. * xAxisIndex / xAxisId / xAxisName,
  513. * yAxisIndex / yAxisId / yAxisName
  514. * gridIndex / gridId / gridName,
  515. * ... (can be extended)
  516. * }
  517. * @param {Array|number} value
  518. * @return {Array|number} result
  519. */
  520. echartsProto.convertFromPixel = zrUtil.curry(doConvertPixel, 'convertFromPixel');
  521. function doConvertPixel(methodName, finder, value) {
  522. var ecModel = this._model;
  523. var coordSysList = this._coordSysMgr.getCoordinateSystems();
  524. var result;
  525. finder = modelUtil.parseFinder(ecModel, finder);
  526. for (var i = 0; i < coordSysList.length; i++) {
  527. var coordSys = coordSysList[i];
  528. if (coordSys[methodName]
  529. && (result = coordSys[methodName](ecModel, finder, value)) != null
  530. ) {
  531. return result;
  532. }
  533. }
  534. if (true) {
  535. console.warn(
  536. 'No coordinate system that supports ' + methodName + ' found by the given finder.'
  537. );
  538. }
  539. }
  540. /**
  541. * Is the specified coordinate systems or components contain the given pixel point.
  542. * @param {string|Object} finder
  543. * If string, e.g., 'geo', means {geoIndex: 0}.
  544. * If Object, could contain some of these properties below:
  545. * {
  546. * seriesIndex / seriesId / seriesName,
  547. * geoIndex / geoId / geoName,
  548. * bmapIndex / bmapId / bmapName,
  549. * xAxisIndex / xAxisId / xAxisName,
  550. * yAxisIndex / yAxisId / yAxisName,
  551. * gridIndex / gridId / gridName,
  552. * ... (can be extended)
  553. * }
  554. * @param {Array|number} value
  555. * @return {boolean} result
  556. */
  557. echartsProto.containPixel = function (finder, value) {
  558. var ecModel = this._model;
  559. var result;
  560. finder = modelUtil.parseFinder(ecModel, finder);
  561. zrUtil.each(finder, function (models, key) {
  562. key.indexOf('Models') >= 0 && zrUtil.each(models, function (model) {
  563. var coordSys = model.coordinateSystem;
  564. if (coordSys && coordSys.containPoint) {
  565. result |= !!coordSys.containPoint(value);
  566. }
  567. else if (key === 'seriesModels') {
  568. var view = this._chartsMap[model.__viewId];
  569. if (view && view.containPoint) {
  570. result |= view.containPoint(value, model);
  571. }
  572. else {
  573. if (true) {
  574. console.warn(key + ': ' + (view
  575. ? 'The found component do not support containPoint.'
  576. : 'No view mapping to the found component.'
  577. ));
  578. }
  579. }
  580. }
  581. else {
  582. if (true) {
  583. console.warn(key + ': containPoint is not supported');
  584. }
  585. }
  586. }, this);
  587. }, this);
  588. return !!result;
  589. };
  590. /**
  591. * Get visual from series or data.
  592. * @param {string|Object} finder
  593. * If string, e.g., 'series', means {seriesIndex: 0}.
  594. * If Object, could contain some of these properties below:
  595. * {
  596. * seriesIndex / seriesId / seriesName,
  597. * dataIndex / dataIndexInside
  598. * }
  599. * If dataIndex is not specified, series visual will be fetched,
  600. * but not data item visual.
  601. * If all of seriesIndex, seriesId, seriesName are not specified,
  602. * visual will be fetched from first series.
  603. * @param {string} visualType 'color', 'symbol', 'symbolSize'
  604. */
  605. echartsProto.getVisual = function (finder, visualType) {
  606. var ecModel = this._model;
  607. finder = modelUtil.parseFinder(ecModel, finder, {defaultMainType: 'series'});
  608. var seriesModel = finder.seriesModel;
  609. if (true) {
  610. if (!seriesModel) {
  611. console.warn('There is no specified seires model');
  612. }
  613. }
  614. var data = seriesModel.getData();
  615. var dataIndexInside = finder.hasOwnProperty('dataIndexInside')
  616. ? finder.dataIndexInside
  617. : finder.hasOwnProperty('dataIndex')
  618. ? data.indexOfRawIndex(finder.dataIndex)
  619. : null;
  620. return dataIndexInside != null
  621. ? data.getItemVisual(dataIndexInside, visualType)
  622. : data.getVisual(visualType);
  623. };
  624. /**
  625. * Get view of corresponding component model
  626. * @param {module:echarts/model/Component} componentModel
  627. * @return {module:echarts/view/Component}
  628. */
  629. echartsProto.getViewOfComponentModel = function (componentModel) {
  630. return this._componentsMap[componentModel.__viewId];
  631. };
  632. /**
  633. * Get view of corresponding series model
  634. * @param {module:echarts/model/Series} seriesModel
  635. * @return {module:echarts/view/Chart}
  636. */
  637. echartsProto.getViewOfSeriesModel = function (seriesModel) {
  638. return this._chartsMap[seriesModel.__viewId];
  639. };
  640. var updateMethods = {
  641. /**
  642. * @param {Object} payload
  643. * @private
  644. */
  645. update: function (payload) {
  646. // console.profile && console.profile('update');
  647. var ecModel = this._model;
  648. var api = this._api;
  649. var coordSysMgr = this._coordSysMgr;
  650. var zr = this._zr;
  651. // update before setOption
  652. if (!ecModel) {
  653. return;
  654. }
  655. // Fixme First time update ?
  656. ecModel.restoreData();
  657. // TODO
  658. // Save total ecModel here for undo/redo (after restoring data and before processing data).
  659. // Undo (restoration of total ecModel) can be carried out in 'action' or outside API call.
  660. // Create new coordinate system each update
  661. // In LineView may save the old coordinate system and use it to get the orignal point
  662. coordSysMgr.create(this._model, this._api);
  663. processData.call(this, ecModel, api);
  664. stackSeriesData.call(this, ecModel);
  665. coordSysMgr.update(ecModel, api);
  666. doVisualEncoding.call(this, ecModel, payload);
  667. doRender.call(this, ecModel, payload);
  668. // Set background
  669. var backgroundColor = ecModel.get('backgroundColor') || 'transparent';
  670. var painter = zr.painter;
  671. // TODO all use clearColor ?
  672. if (painter.isSingleCanvas && painter.isSingleCanvas()) {
  673. zr.configLayer(0, {
  674. clearColor: backgroundColor
  675. });
  676. }
  677. else {
  678. // In IE8
  679. if (!env.canvasSupported) {
  680. var colorArr = colorTool.parse(backgroundColor);
  681. backgroundColor = colorTool.stringify(colorArr, 'rgb');
  682. if (colorArr[3] === 0) {
  683. backgroundColor = 'transparent';
  684. }
  685. }
  686. if (backgroundColor.colorStops || backgroundColor.image) {
  687. // Gradient background
  688. // FIXME Fixed layer?
  689. zr.configLayer(0, {
  690. clearColor: backgroundColor
  691. });
  692. this[HAS_GRADIENT_OR_PATTERN_BG] = true;
  693. this._dom.style.background = 'transparent';
  694. }
  695. else {
  696. if (this[HAS_GRADIENT_OR_PATTERN_BG]) {
  697. zr.configLayer(0, {
  698. clearColor: null
  699. });
  700. }
  701. this[HAS_GRADIENT_OR_PATTERN_BG] = false;
  702. this._dom.style.background = backgroundColor;
  703. }
  704. }
  705. each(postUpdateFuncs, function (func) {
  706. func(ecModel, api);
  707. });
  708. // console.profile && console.profileEnd('update');
  709. },
  710. /**
  711. * @param {Object} payload
  712. * @private
  713. */
  714. updateView: function (payload) {
  715. var ecModel = this._model;
  716. // update before setOption
  717. if (!ecModel) {
  718. return;
  719. }
  720. ecModel.eachSeries(function (seriesModel) {
  721. seriesModel.getData().clearAllVisual();
  722. });
  723. doVisualEncoding.call(this, ecModel, payload);
  724. invokeUpdateMethod.call(this, 'updateView', ecModel, payload);
  725. },
  726. /**
  727. * @param {Object} payload
  728. * @private
  729. */
  730. updateVisual: function (payload) {
  731. var ecModel = this._model;
  732. // update before setOption
  733. if (!ecModel) {
  734. return;
  735. }
  736. ecModel.eachSeries(function (seriesModel) {
  737. seriesModel.getData().clearAllVisual();
  738. });
  739. doVisualEncoding.call(this, ecModel, payload, true);
  740. invokeUpdateMethod.call(this, 'updateVisual', ecModel, payload);
  741. },
  742. /**
  743. * @param {Object} payload
  744. * @private
  745. */
  746. updateLayout: function (payload) {
  747. var ecModel = this._model;
  748. // update before setOption
  749. if (!ecModel) {
  750. return;
  751. }
  752. doLayout.call(this, ecModel, payload);
  753. invokeUpdateMethod.call(this, 'updateLayout', ecModel, payload);
  754. },
  755. /**
  756. * @param {Object} payload
  757. * @private
  758. */
  759. prepareAndUpdate: function (payload) {
  760. var ecModel = this._model;
  761. prepareView.call(this, 'component', ecModel);
  762. prepareView.call(this, 'chart', ecModel);
  763. updateMethods.update.call(this, payload);
  764. }
  765. };
  766. /**
  767. * @private
  768. */
  769. function updateDirectly(ecIns, method, payload, mainType, subType) {
  770. var ecModel = ecIns._model;
  771. // broadcast
  772. if (!mainType) {
  773. each(ecIns._componentsViews.concat(ecIns._chartsViews), callView);
  774. return;
  775. }
  776. var query = {};
  777. query[mainType + 'Id'] = payload[mainType + 'Id'];
  778. query[mainType + 'Index'] = payload[mainType + 'Index'];
  779. query[mainType + 'Name'] = payload[mainType + 'Name'];
  780. var condition = {mainType: mainType, query: query};
  781. subType && (condition.subType = subType); // subType may be '' by parseClassType;
  782. // If dispatchAction before setOption, do nothing.
  783. ecModel && ecModel.eachComponent(condition, function (model, index) {
  784. callView(ecIns[
  785. mainType === 'series' ? '_chartsMap' : '_componentsMap'
  786. ][model.__viewId]);
  787. }, ecIns);
  788. function callView(view) {
  789. view && view.__alive && view[method] && view[method](
  790. view.__model, ecModel, ecIns._api, payload
  791. );
  792. }
  793. }
  794. /**
  795. * Resize the chart
  796. * @param {Object} opts
  797. * @param {number} [opts.width] Can be 'auto' (the same as null/undefined)
  798. * @param {number} [opts.height] Can be 'auto' (the same as null/undefined)
  799. * @param {boolean} [opts.silent=false]
  800. */
  801. echartsProto.resize = function (opts) {
  802. if (true) {
  803. zrUtil.assert(!this[IN_MAIN_PROCESS], '`resize` should not be called during main process.');
  804. }
  805. this[IN_MAIN_PROCESS] = true;
  806. this._zr.resize(opts);
  807. var optionChanged = this._model && this._model.resetOption('media');
  808. var updateMethod = optionChanged ? 'prepareAndUpdate' : 'update';
  809. updateMethods[updateMethod].call(this);
  810. // Resize loading effect
  811. this._loadingFX && this._loadingFX.resize();
  812. this[IN_MAIN_PROCESS] = false;
  813. var silent = opts && opts.silent;
  814. flushPendingActions.call(this, silent);
  815. triggerUpdatedEvent.call(this, silent);
  816. };
  817. /**
  818. * Show loading effect
  819. * @param {string} [name='default']
  820. * @param {Object} [cfg]
  821. */
  822. echartsProto.showLoading = function (name, cfg) {
  823. if (zrUtil.isObject(name)) {
  824. cfg = name;
  825. name = '';
  826. }
  827. name = name || 'default';
  828. this.hideLoading();
  829. if (!loadingEffects[name]) {
  830. if (true) {
  831. console.warn('Loading effects ' + name + ' not exists.');
  832. }
  833. return;
  834. }
  835. var el = loadingEffects[name](this._api, cfg);
  836. var zr = this._zr;
  837. this._loadingFX = el;
  838. zr.add(el);
  839. };
  840. /**
  841. * Hide loading effect
  842. */
  843. echartsProto.hideLoading = function () {
  844. this._loadingFX && this._zr.remove(this._loadingFX);
  845. this._loadingFX = null;
  846. };
  847. /**
  848. * @param {Object} eventObj
  849. * @return {Object}
  850. */
  851. echartsProto.makeActionFromEvent = function (eventObj) {
  852. var payload = zrUtil.extend({}, eventObj);
  853. payload.type = eventActionMap[eventObj.type];
  854. return payload;
  855. };
  856. /**
  857. * @pubilc
  858. * @param {Object} payload
  859. * @param {string} [payload.type] Action type
  860. * @param {Object|boolean} [opt] If pass boolean, means opt.silent
  861. * @param {boolean} [opt.silent=false] Whether trigger events.
  862. * @param {boolean} [opt.flush=undefined]
  863. * true: Flush immediately, and then pixel in canvas can be fetched
  864. * immediately. Caution: it might affect performance.
  865. * false: Not not flush.
  866. * undefined: Auto decide whether perform flush.
  867. */
  868. echartsProto.dispatchAction = function (payload, opt) {
  869. if (!zrUtil.isObject(opt)) {
  870. opt = {silent: !!opt};
  871. }
  872. if (!actions[payload.type]) {
  873. return;
  874. }
  875. // May dispatchAction in rendering procedure
  876. if (this[IN_MAIN_PROCESS]) {
  877. this._pendingActions.push(payload);
  878. return;
  879. }
  880. doDispatchAction.call(this, payload, opt.silent);
  881. if (opt.flush) {
  882. this._zr.flush(true);
  883. }
  884. else if (opt.flush !== false && env.browser.weChat) {
  885. // In WeChat embeded browser, `requestAnimationFrame` and `setInterval`
  886. // hang when sliding page (on touch event), which cause that zr does not
  887. // refresh util user interaction finished, which is not expected.
  888. // But `dispatchAction` may be called too frequently when pan on touch
  889. // screen, which impacts performance if do not throttle them.
  890. this._throttledZrFlush();
  891. }
  892. flushPendingActions.call(this, opt.silent);
  893. triggerUpdatedEvent.call(this, opt.silent);
  894. };
  895. function doDispatchAction(payload, silent) {
  896. var payloadType = payload.type;
  897. var escapeConnect = payload.escapeConnect;
  898. var actionWrap = actions[payloadType];
  899. var actionInfo = actionWrap.actionInfo;
  900. var cptType = (actionInfo.update || 'update').split(':');
  901. var updateMethod = cptType.pop();
  902. cptType = cptType[0] != null && parseClassType(cptType[0]);
  903. this[IN_MAIN_PROCESS] = true;
  904. var payloads = [payload];
  905. var batched = false;
  906. // Batch action
  907. if (payload.batch) {
  908. batched = true;
  909. payloads = zrUtil.map(payload.batch, function (item) {
  910. item = zrUtil.defaults(zrUtil.extend({}, item), payload);
  911. item.batch = null;
  912. return item;
  913. });
  914. }
  915. var eventObjBatch = [];
  916. var eventObj;
  917. var isHighDown = payloadType === 'highlight' || payloadType === 'downplay';
  918. each(payloads, function (batchItem) {
  919. // Action can specify the event by return it.
  920. eventObj = actionWrap.action(batchItem, this._model, this._api);
  921. // Emit event outside
  922. eventObj = eventObj || zrUtil.extend({}, batchItem);
  923. // Convert type to eventType
  924. eventObj.type = actionInfo.event || eventObj.type;
  925. eventObjBatch.push(eventObj);
  926. // light update does not perform data process, layout and visual.
  927. if (isHighDown) {
  928. // method, payload, mainType, subType
  929. updateDirectly(this, updateMethod, batchItem, 'series');
  930. }
  931. else if (cptType) {
  932. updateDirectly(this, updateMethod, batchItem, cptType.main, cptType.sub);
  933. }
  934. }, this);
  935. if (updateMethod !== 'none' && !isHighDown && !cptType) {
  936. // Still dirty
  937. if (this[OPTION_UPDATED]) {
  938. // FIXME Pass payload ?
  939. updateMethods.prepareAndUpdate.call(this, payload);
  940. this[OPTION_UPDATED] = false;
  941. }
  942. else {
  943. updateMethods[updateMethod].call(this, payload);
  944. }
  945. }
  946. // Follow the rule of action batch
  947. if (batched) {
  948. eventObj = {
  949. type: actionInfo.event || payloadType,
  950. escapeConnect: escapeConnect,
  951. batch: eventObjBatch
  952. };
  953. }
  954. else {
  955. eventObj = eventObjBatch[0];
  956. }
  957. this[IN_MAIN_PROCESS] = false;
  958. !silent && this._messageCenter.trigger(eventObj.type, eventObj);
  959. }
  960. function flushPendingActions(silent) {
  961. var pendingActions = this._pendingActions;
  962. while (pendingActions.length) {
  963. var payload = pendingActions.shift();
  964. doDispatchAction.call(this, payload, silent);
  965. }
  966. }
  967. function triggerUpdatedEvent(silent) {
  968. !silent && this.trigger('updated');
  969. }
  970. /**
  971. * Register event
  972. * @method
  973. */
  974. echartsProto.on = createRegisterEventWithLowercaseName('on');
  975. echartsProto.off = createRegisterEventWithLowercaseName('off');
  976. echartsProto.one = createRegisterEventWithLowercaseName('one');
  977. /**
  978. * @param {string} methodName
  979. * @private
  980. */
  981. function invokeUpdateMethod(methodName, ecModel, payload) {
  982. var api = this._api;
  983. // Update all components
  984. each(this._componentsViews, function (component) {
  985. var componentModel = component.__model;
  986. component[methodName](componentModel, ecModel, api, payload);
  987. updateZ(componentModel, component);
  988. }, this);
  989. // Upate all charts
  990. ecModel.eachSeries(function (seriesModel, idx) {
  991. var chart = this._chartsMap[seriesModel.__viewId];
  992. chart[methodName](seriesModel, ecModel, api, payload);
  993. updateZ(seriesModel, chart);
  994. updateProgressiveAndBlend(seriesModel, chart);
  995. }, this);
  996. // If use hover layer
  997. updateHoverLayerStatus(this._zr, ecModel);
  998. // Post render
  999. each(postUpdateFuncs, function (func) {
  1000. func(ecModel, api);
  1001. });
  1002. }
  1003. /**
  1004. * Prepare view instances of charts and components
  1005. * @param {module:echarts/model/Global} ecModel
  1006. * @private
  1007. */
  1008. function prepareView(type, ecModel) {
  1009. var isComponent = type === 'component';
  1010. var viewList = isComponent ? this._componentsViews : this._chartsViews;
  1011. var viewMap = isComponent ? this._componentsMap : this._chartsMap;
  1012. var zr = this._zr;
  1013. for (var i = 0; i < viewList.length; i++) {
  1014. viewList[i].__alive = false;
  1015. }
  1016. ecModel[isComponent ? 'eachComponent' : 'eachSeries'](function (componentType, model) {
  1017. if (isComponent) {
  1018. if (componentType === 'series') {
  1019. return;
  1020. }
  1021. }
  1022. else {
  1023. model = componentType;
  1024. }
  1025. // Consider: id same and type changed.
  1026. var viewId = '_ec_' + model.id + '_' + model.type;
  1027. var view = viewMap[viewId];
  1028. if (!view) {
  1029. var classType = parseClassType(model.type);
  1030. var Clazz = isComponent
  1031. ? ComponentView.getClass(classType.main, classType.sub)
  1032. : ChartView.getClass(classType.sub);
  1033. if (Clazz) {
  1034. view = new Clazz();
  1035. view.init(ecModel, this._api);
  1036. viewMap[viewId] = view;
  1037. viewList.push(view);
  1038. zr.add(view.group);
  1039. }
  1040. else {
  1041. // Error
  1042. return;
  1043. }
  1044. }
  1045. model.__viewId = view.__id = viewId;
  1046. view.__alive = true;
  1047. view.__model = model;
  1048. view.group.__ecComponentInfo = {
  1049. mainType: model.mainType,
  1050. index: model.componentIndex
  1051. };
  1052. }, this);
  1053. for (var i = 0; i < viewList.length;) {
  1054. var view = viewList[i];
  1055. if (!view.__alive) {
  1056. zr.remove(view.group);
  1057. view.dispose(ecModel, this._api);
  1058. viewList.splice(i, 1);
  1059. delete viewMap[view.__id];
  1060. view.__id = view.group.__ecComponentInfo = null;
  1061. }
  1062. else {
  1063. i++;
  1064. }
  1065. }
  1066. }
  1067. /**
  1068. * Processor data in each series
  1069. *
  1070. * @param {module:echarts/model/Global} ecModel
  1071. * @private
  1072. */
  1073. function processData(ecModel, api) {
  1074. each(dataProcessorFuncs, function (process) {
  1075. process.func(ecModel, api);
  1076. });
  1077. }
  1078. /**
  1079. * @private
  1080. */
  1081. function stackSeriesData(ecModel) {
  1082. var stackedDataMap = {};
  1083. ecModel.eachSeries(function (series) {
  1084. var stack = series.get('stack');
  1085. var data = series.getData();
  1086. if (stack && data.type === 'list') {
  1087. var previousStack = stackedDataMap[stack];
  1088. // Avoid conflict with Object.prototype
  1089. if (stackedDataMap.hasOwnProperty(stack) && previousStack) {
  1090. data.stackedOn = previousStack;
  1091. }
  1092. stackedDataMap[stack] = data;
  1093. }
  1094. });
  1095. }
  1096. /**
  1097. * Layout before each chart render there series, special visual encoding stage
  1098. *
  1099. * @param {module:echarts/model/Global} ecModel
  1100. * @private
  1101. */
  1102. function doLayout(ecModel, payload) {
  1103. var api = this._api;
  1104. each(visualFuncs, function (visual) {
  1105. if (visual.isLayout) {
  1106. visual.func(ecModel, api, payload);
  1107. }
  1108. });
  1109. }
  1110. /**
  1111. * Encode visual infomation from data after data processing
  1112. *
  1113. * @param {module:echarts/model/Global} ecModel
  1114. * @param {object} layout
  1115. * @param {boolean} [excludesLayout]
  1116. * @private
  1117. */
  1118. function doVisualEncoding(ecModel, payload, excludesLayout) {
  1119. var api = this._api;
  1120. ecModel.clearColorPalette();
  1121. ecModel.eachSeries(function (seriesModel) {
  1122. seriesModel.clearColorPalette();
  1123. });
  1124. each(visualFuncs, function (visual) {
  1125. (!excludesLayout || !visual.isLayout)
  1126. && visual.func(ecModel, api, payload);
  1127. });
  1128. }
  1129. /**
  1130. * Render each chart and component
  1131. * @private
  1132. */
  1133. function doRender(ecModel, payload) {
  1134. var api = this._api;
  1135. // Render all components
  1136. each(this._componentsViews, function (componentView) {
  1137. var componentModel = componentView.__model;
  1138. componentView.render(componentModel, ecModel, api, payload);
  1139. updateZ(componentModel, componentView);
  1140. }, this);
  1141. each(this._chartsViews, function (chart) {
  1142. chart.__alive = false;
  1143. }, this);
  1144. // Render all charts
  1145. ecModel.eachSeries(function (seriesModel, idx) {
  1146. var chartView = this._chartsMap[seriesModel.__viewId];
  1147. chartView.__alive = true;
  1148. chartView.render(seriesModel, ecModel, api, payload);
  1149. chartView.group.silent = !!seriesModel.get('silent');
  1150. updateZ(seriesModel, chartView);
  1151. updateProgressiveAndBlend(seriesModel, chartView);
  1152. }, this);
  1153. // If use hover layer
  1154. updateHoverLayerStatus(this._zr, ecModel);
  1155. // Remove groups of unrendered charts
  1156. each(this._chartsViews, function (chart) {
  1157. if (!chart.__alive) {
  1158. chart.remove(ecModel, api);
  1159. }
  1160. }, this);
  1161. }
  1162. var MOUSE_EVENT_NAMES = [
  1163. 'click', 'dblclick', 'mouseover', 'mouseout', 'mousemove',
  1164. 'mousedown', 'mouseup', 'globalout', 'contextmenu'
  1165. ];
  1166. /**
  1167. * @private
  1168. */
  1169. echartsProto._initEvents = function () {
  1170. each(MOUSE_EVENT_NAMES, function (eveName) {
  1171. this._zr.on(eveName, function (e) {
  1172. var ecModel = this.getModel();
  1173. var el = e.target;
  1174. var params;
  1175. // no e.target when 'globalout'.
  1176. if (eveName === 'globalout') {
  1177. params = {};
  1178. }
  1179. else if (el && el.dataIndex != null) {
  1180. var dataModel = el.dataModel || ecModel.getSeriesByIndex(el.seriesIndex);
  1181. params = dataModel && dataModel.getDataParams(el.dataIndex, el.dataType) || {};
  1182. }
  1183. // If element has custom eventData of components
  1184. else if (el && el.eventData) {
  1185. params = zrUtil.extend({}, el.eventData);
  1186. }
  1187. if (params) {
  1188. params.event = e;
  1189. params.type = eveName;
  1190. this.trigger(eveName, params);
  1191. }
  1192. }, this);
  1193. }, this);
  1194. each(eventActionMap, function (actionType, eventType) {
  1195. this._messageCenter.on(eventType, function (event) {
  1196. this.trigger(eventType, event);
  1197. }, this);
  1198. }, this);
  1199. };
  1200. /**
  1201. * @return {boolean}
  1202. */
  1203. echartsProto.isDisposed = function () {
  1204. return this._disposed;
  1205. };
  1206. /**
  1207. * Clear
  1208. */
  1209. echartsProto.clear = function () {
  1210. this.setOption({ series: [] }, true);
  1211. };
  1212. /**
  1213. * Dispose instance
  1214. */
  1215. echartsProto.dispose = function () {
  1216. if (this._disposed) {
  1217. if (true) {
  1218. console.warn('Instance ' + this.id + ' has been disposed');
  1219. }
  1220. return;
  1221. }
  1222. this._disposed = true;
  1223. var api = this._api;
  1224. var ecModel = this._model;
  1225. each(this._componentsViews, function (component) {
  1226. component.dispose(ecModel, api);
  1227. });
  1228. each(this._chartsViews, function (chart) {
  1229. chart.dispose(ecModel, api);
  1230. });
  1231. // Dispose after all views disposed
  1232. this._zr.dispose();
  1233. delete instances[this.id];
  1234. };
  1235. zrUtil.mixin(ECharts, Eventful);
  1236. function updateHoverLayerStatus(zr, ecModel) {
  1237. var storage = zr.storage;
  1238. var elCount = 0;
  1239. storage.traverse(function (el) {
  1240. if (!el.isGroup) {
  1241. elCount++;
  1242. }
  1243. });
  1244. if (elCount > ecModel.get('hoverLayerThreshold') && !env.node) {
  1245. storage.traverse(function (el) {
  1246. if (!el.isGroup) {
  1247. el.useHoverLayer = true;
  1248. }
  1249. });
  1250. }
  1251. }
  1252. /**
  1253. * Update chart progressive and blend.
  1254. * @param {module:echarts/model/Series|module:echarts/model/Component} model
  1255. * @param {module:echarts/view/Component|module:echarts/view/Chart} view
  1256. */
  1257. function updateProgressiveAndBlend(seriesModel, chartView) {
  1258. // Progressive configuration
  1259. var elCount = 0;
  1260. chartView.group.traverse(function (el) {
  1261. if (el.type !== 'group' && !el.ignore) {
  1262. elCount++;
  1263. }
  1264. });
  1265. var frameDrawNum = +seriesModel.get('progressive');
  1266. var needProgressive = elCount > seriesModel.get('progressiveThreshold') && frameDrawNum && !env.node;
  1267. if (needProgressive) {
  1268. chartView.group.traverse(function (el) {
  1269. // FIXME marker and other components
  1270. if (!el.isGroup) {
  1271. el.progressive = needProgressive ?
  1272. Math.floor(elCount++ / frameDrawNum) : -1;
  1273. if (needProgressive) {
  1274. el.stopAnimation(true);
  1275. }
  1276. }
  1277. });
  1278. }
  1279. // Blend configration
  1280. var blendMode = seriesModel.get('blendMode') || null;
  1281. if (true) {
  1282. if (!env.canvasSupported && blendMode && blendMode !== 'source-over') {
  1283. console.warn('Only canvas support blendMode');
  1284. }
  1285. }
  1286. chartView.group.traverse(function (el) {
  1287. // FIXME marker and other components
  1288. if (!el.isGroup) {
  1289. el.setStyle('blend', blendMode);
  1290. }
  1291. });
  1292. }
  1293. /**
  1294. * @param {module:echarts/model/Series|module:echarts/model/Component} model
  1295. * @param {module:echarts/view/Component|module:echarts/view/Chart} view
  1296. */
  1297. function updateZ(model, view) {
  1298. var z = model.get('z');
  1299. var zlevel = model.get('zlevel');
  1300. // Set z and zlevel
  1301. view.group.traverse(function (el) {
  1302. if (el.type !== 'group') {
  1303. z != null && (el.z = z);
  1304. zlevel != null && (el.zlevel = zlevel);
  1305. }
  1306. });
  1307. }
  1308. function createExtensionAPI(ecInstance) {
  1309. var coordSysMgr = ecInstance._coordSysMgr;
  1310. return zrUtil.extend(new ExtensionAPI(ecInstance), {
  1311. // Inject methods
  1312. getCoordinateSystems: zrUtil.bind(
  1313. coordSysMgr.getCoordinateSystems, coordSysMgr
  1314. ),
  1315. getComponentByElement: function (el) {
  1316. while (el) {
  1317. var modelInfo = el.__ecComponentInfo;
  1318. if (modelInfo != null) {
  1319. return ecInstance._model.getComponent(modelInfo.mainType, modelInfo.index);
  1320. }
  1321. el = el.parent;
  1322. }
  1323. }
  1324. });
  1325. }
  1326. /**
  1327. * @type {Object} key: actionType.
  1328. * @inner
  1329. */
  1330. var actions = {};
  1331. /**
  1332. * Map eventType to actionType
  1333. * @type {Object}
  1334. */
  1335. var eventActionMap = {};
  1336. /**
  1337. * Data processor functions of each stage
  1338. * @type {Array.<Object.<string, Function>>}
  1339. * @inner
  1340. */
  1341. var dataProcessorFuncs = [];
  1342. /**
  1343. * @type {Array.<Function>}
  1344. * @inner
  1345. */
  1346. var optionPreprocessorFuncs = [];
  1347. /**
  1348. * @type {Array.<Function>}
  1349. * @inner
  1350. */
  1351. var postUpdateFuncs = [];
  1352. /**
  1353. * Visual encoding functions of each stage
  1354. * @type {Array.<Object.<string, Function>>}
  1355. * @inner
  1356. */
  1357. var visualFuncs = [];
  1358. /**
  1359. * Theme storage
  1360. * @type {Object.<key, Object>}
  1361. */
  1362. var themeStorage = {};
  1363. /**
  1364. * Loading effects
  1365. */
  1366. var loadingEffects = {};
  1367. var instances = {};
  1368. var connectedGroups = {};
  1369. var idBase = new Date() - 0;
  1370. var groupIdBase = new Date() - 0;
  1371. var DOM_ATTRIBUTE_KEY = '_echarts_instance_';
  1372. /**
  1373. * @alias module:echarts
  1374. */
  1375. var echarts = {
  1376. /**
  1377. * @type {number}
  1378. */
  1379. version: '3.6.1',
  1380. dependencies: {
  1381. zrender: '3.5.1'
  1382. }
  1383. };
  1384. function enableConnect(chart) {
  1385. var STATUS_PENDING = 0;
  1386. var STATUS_UPDATING = 1;
  1387. var STATUS_UPDATED = 2;
  1388. var STATUS_KEY = '__connectUpdateStatus';
  1389. function updateConnectedChartsStatus(charts, status) {
  1390. for (var i = 0; i < charts.length; i++) {
  1391. var otherChart = charts[i];
  1392. otherChart[STATUS_KEY] = status;
  1393. }
  1394. }
  1395. zrUtil.each(eventActionMap, function (actionType, eventType) {
  1396. chart._messageCenter.on(eventType, function (event) {
  1397. if (connectedGroups[chart.group] && chart[STATUS_KEY] !== STATUS_PENDING) {
  1398. if (event && event.escapeConnect) {
  1399. return;
  1400. }
  1401. var action = chart.makeActionFromEvent(event);
  1402. var otherCharts = [];
  1403. zrUtil.each(instances, function (otherChart) {
  1404. if (otherChart !== chart && otherChart.group === chart.group) {
  1405. otherCharts.push(otherChart);
  1406. }
  1407. });
  1408. updateConnectedChartsStatus(otherCharts, STATUS_PENDING);
  1409. each(otherCharts, function (otherChart) {
  1410. if (otherChart[STATUS_KEY] !== STATUS_UPDATING) {
  1411. otherChart.dispatchAction(action);
  1412. }
  1413. });
  1414. updateConnectedChartsStatus(otherCharts, STATUS_UPDATED);
  1415. }
  1416. });
  1417. });
  1418. }
  1419. /**
  1420. * @param {HTMLDomElement} dom
  1421. * @param {Object} [theme]
  1422. * @param {Object} opts
  1423. * @param {number} [opts.devicePixelRatio] Use window.devicePixelRatio by default
  1424. * @param {string} [opts.renderer] Currently only 'canvas' is supported.
  1425. * @param {number} [opts.width] Use clientWidth of the input `dom` by default.
  1426. * Can be 'auto' (the same as null/undefined)
  1427. * @param {number} [opts.height] Use clientHeight of the input `dom` by default.
  1428. * Can be 'auto' (the same as null/undefined)
  1429. */
  1430. echarts.init = function (dom, theme, opts) {
  1431. if (true) {
  1432. // Check version
  1433. if ((zrender.version.replace('.', '') - 0) < (echarts.dependencies.zrender.replace('.', '') - 0)) {
  1434. throw new Error(
  1435. 'ZRender ' + zrender.version
  1436. + ' is too old for ECharts ' + echarts.version
  1437. + '. Current version need ZRender '
  1438. + echarts.dependencies.zrender + '+'
  1439. );
  1440. }
  1441. if (!dom) {
  1442. throw new Error('Initialize failed: invalid dom.');
  1443. }
  1444. }
  1445. var existInstance = echarts.getInstanceByDom(dom);
  1446. if (existInstance) {
  1447. if (true) {
  1448. console.warn('There is a chart instance already initialized on the dom.');
  1449. }
  1450. return existInstance;
  1451. }
  1452. if (true) {
  1453. if (zrUtil.isDom(dom)
  1454. && dom.nodeName.toUpperCase() !== 'CANVAS'
  1455. && (
  1456. (!dom.clientWidth && (!opts || opts.width == null))
  1457. || (!dom.clientHeight && (!opts || opts.height == null))
  1458. )
  1459. ) {
  1460. console.warn('Can\'t get dom width or height');
  1461. }
  1462. }
  1463. var chart = new ECharts(dom, theme, opts);
  1464. chart.id = 'ec_' + idBase++;
  1465. instances[chart.id] = chart;
  1466. if (dom.setAttribute) {
  1467. dom.setAttribute(DOM_ATTRIBUTE_KEY, chart.id);
  1468. }
  1469. else {
  1470. dom[DOM_ATTRIBUTE_KEY] = chart.id;
  1471. }
  1472. enableConnect(chart);
  1473. return chart;
  1474. };
  1475. /**
  1476. * @return {string|Array.<module:echarts~ECharts>} groupId
  1477. */
  1478. echarts.connect = function (groupId) {
  1479. // Is array of charts
  1480. if (zrUtil.isArray(groupId)) {
  1481. var charts = groupId;
  1482. groupId = null;
  1483. // If any chart has group
  1484. zrUtil.each(charts, function (chart) {
  1485. if (chart.group != null) {
  1486. groupId = chart.group;
  1487. }
  1488. });
  1489. groupId = groupId || ('g_' + groupIdBase++);
  1490. zrUtil.each(charts, function (chart) {
  1491. chart.group = groupId;
  1492. });
  1493. }
  1494. connectedGroups[groupId] = true;
  1495. return groupId;
  1496. };
  1497. /**
  1498. * @DEPRECATED
  1499. * @return {string} groupId
  1500. */
  1501. echarts.disConnect = function (groupId) {
  1502. connectedGroups[groupId] = false;
  1503. };
  1504. /**
  1505. * @return {string} groupId
  1506. */
  1507. echarts.disconnect = echarts.disConnect;
  1508. /**
  1509. * Dispose a chart instance
  1510. * @param {module:echarts~ECharts|HTMLDomElement|string} chart
  1511. */
  1512. echarts.dispose = function (chart) {
  1513. if (typeof chart === 'string') {
  1514. chart = instances[chart];
  1515. }
  1516. else if (!(chart instanceof ECharts)){
  1517. // Try to treat as dom
  1518. chart = echarts.getInstanceByDom(chart);
  1519. }
  1520. if ((chart instanceof ECharts) && !chart.isDisposed()) {
  1521. chart.dispose();
  1522. }
  1523. };
  1524. /**
  1525. * @param {HTMLDomElement} dom
  1526. * @return {echarts~ECharts}
  1527. */
  1528. echarts.getInstanceByDom = function (dom) {
  1529. var key;
  1530. if (dom.getAttribute) {
  1531. key = dom.getAttribute(DOM_ATTRIBUTE_KEY);
  1532. }
  1533. else {
  1534. key = dom[DOM_ATTRIBUTE_KEY];
  1535. }
  1536. return instances[key];
  1537. };
  1538. /**
  1539. * @param {string} key
  1540. * @return {echarts~ECharts}
  1541. */
  1542. echarts.getInstanceById = function (key) {
  1543. return instances[key];
  1544. };
  1545. /**
  1546. * Register theme
  1547. */
  1548. echarts.registerTheme = function (name, theme) {
  1549. themeStorage[name] = theme;
  1550. };
  1551. /**
  1552. * Register option preprocessor
  1553. * @param {Function} preprocessorFunc
  1554. */
  1555. echarts.registerPreprocessor = function (preprocessorFunc) {
  1556. optionPreprocessorFuncs.push(preprocessorFunc);
  1557. };
  1558. /**
  1559. * @param {number} [priority=1000]
  1560. * @param {Function} processorFunc
  1561. */
  1562. echarts.registerProcessor = function (priority, processorFunc) {
  1563. if (typeof priority === 'function') {
  1564. processorFunc = priority;
  1565. priority = PRIORITY_PROCESSOR_FILTER;
  1566. }
  1567. if (true) {
  1568. if (isNaN(priority)) {
  1569. throw new Error('Unkown processor priority');
  1570. }
  1571. }
  1572. dataProcessorFuncs.push({
  1573. prio: priority,
  1574. func: processorFunc
  1575. });
  1576. };
  1577. /**
  1578. * Register postUpdater
  1579. * @param {Function} postUpdateFunc
  1580. */
  1581. echarts.registerPostUpdate = function (postUpdateFunc) {
  1582. postUpdateFuncs.push(postUpdateFunc);
  1583. };
  1584. /**
  1585. * Usage:
  1586. * registerAction('someAction', 'someEvent', function () { ... });
  1587. * registerAction('someAction', function () { ... });
  1588. * registerAction(
  1589. * {type: 'someAction', event: 'someEvent', update: 'updateView'},
  1590. * function () { ... }
  1591. * );
  1592. *
  1593. * @param {(string|Object)} actionInfo
  1594. * @param {string} actionInfo.type
  1595. * @param {string} [actionInfo.event]
  1596. * @param {string} [actionInfo.update]
  1597. * @param {string} [eventName]
  1598. * @param {Function} action
  1599. */
  1600. echarts.registerAction = function (actionInfo, eventName, action) {
  1601. if (typeof eventName === 'function') {
  1602. action = eventName;
  1603. eventName = '';
  1604. }
  1605. var actionType = zrUtil.isObject(actionInfo)
  1606. ? actionInfo.type
  1607. : ([actionInfo, actionInfo = {
  1608. event: eventName
  1609. }][0]);
  1610. // Event name is all lowercase
  1611. actionInfo.event = (actionInfo.event || actionType).toLowerCase();
  1612. eventName = actionInfo.event;
  1613. // Validate action type and event name.
  1614. zrUtil.assert(ACTION_REG.test(actionType) && ACTION_REG.test(eventName));
  1615. if (!actions[actionType]) {
  1616. actions[actionType] = {action: action, actionInfo: actionInfo};
  1617. }
  1618. eventActionMap[eventName] = actionType;
  1619. };
  1620. /**
  1621. * @param {string} type
  1622. * @param {*} CoordinateSystem
  1623. */
  1624. echarts.registerCoordinateSystem = function (type, CoordinateSystem) {
  1625. CoordinateSystemManager.register(type, CoordinateSystem);
  1626. };
  1627. /**
  1628. * Layout is a special stage of visual encoding
  1629. * Most visual encoding like color are common for different chart
  1630. * But each chart has it's own layout algorithm
  1631. *
  1632. * @param {number} [priority=1000]
  1633. * @param {Function} layoutFunc
  1634. */
  1635. echarts.registerLayout = function (priority, layoutFunc) {
  1636. if (typeof priority === 'function') {
  1637. layoutFunc = priority;
  1638. priority = PRIORITY_VISUAL_LAYOUT;
  1639. }
  1640. if (true) {
  1641. if (isNaN(priority)) {
  1642. throw new Error('Unkown layout priority');
  1643. }
  1644. }
  1645. visualFuncs.push({
  1646. prio: priority,
  1647. func: layoutFunc,
  1648. isLayout: true
  1649. });
  1650. };
  1651. /**
  1652. * @param {number} [priority=3000]
  1653. * @param {Function} visualFunc
  1654. */
  1655. echarts.registerVisual = function (priority, visualFunc) {
  1656. if (typeof priority === 'function') {
  1657. visualFunc = priority;
  1658. priority = PRIORITY_VISUAL_CHART;
  1659. }
  1660. if (true) {
  1661. if (isNaN(priority)) {
  1662. throw new Error('Unkown visual priority');
  1663. }
  1664. }
  1665. visualFuncs.push({
  1666. prio: priority,
  1667. func: visualFunc
  1668. });
  1669. };
  1670. /**
  1671. * @param {string} name
  1672. */
  1673. echarts.registerLoading = function (name, loadingFx) {
  1674. loadingEffects[name] = loadingFx;
  1675. };
  1676. /**
  1677. * @param {Object} opts
  1678. * @param {string} [superClass]
  1679. */
  1680. echarts.extendComponentModel = function (opts/*, superClass*/) {
  1681. // var Clazz = ComponentModel;
  1682. // if (superClass) {
  1683. // var classType = parseClassType(superClass);
  1684. // Clazz = ComponentModel.getClass(classType.main, classType.sub, true);
  1685. // }
  1686. return ComponentModel.extend(opts);
  1687. };
  1688. /**
  1689. * @param {Object} opts
  1690. * @param {string} [superClass]
  1691. */
  1692. echarts.extendComponentView = function (opts/*, superClass*/) {
  1693. // var Clazz = ComponentView;
  1694. // if (superClass) {
  1695. // var classType = parseClassType(superClass);
  1696. // Clazz = ComponentView.getClass(classType.main, classType.sub, true);
  1697. // }
  1698. return ComponentView.extend(opts);
  1699. };
  1700. /**
  1701. * @param {Object} opts
  1702. * @param {string} [superClass]
  1703. */
  1704. echarts.extendSeriesModel = function (opts/*, superClass*/) {
  1705. // var Clazz = SeriesModel;
  1706. // if (superClass) {
  1707. // superClass = 'series.' + superClass.replace('series.', '');
  1708. // var classType = parseClassType(superClass);
  1709. // Clazz = ComponentModel.getClass(classType.main, classType.sub, true);
  1710. // }
  1711. return SeriesModel.extend(opts);
  1712. };
  1713. /**
  1714. * @param {Object} opts
  1715. * @param {string} [superClass]
  1716. */
  1717. echarts.extendChartView = function (opts/*, superClass*/) {
  1718. // var Clazz = ChartView;
  1719. // if (superClass) {
  1720. // superClass = superClass.replace('series.', '');
  1721. // var classType = parseClassType(superClass);
  1722. // Clazz = ChartView.getClass(classType.main, true);
  1723. // }
  1724. return ChartView.extend(opts);
  1725. };
  1726. /**
  1727. * ZRender need a canvas context to do measureText.
  1728. * But in node environment canvas may be created by node-canvas.
  1729. * So we need to specify how to create a canvas instead of using document.createElement('canvas')
  1730. *
  1731. * Be careful of using it in the browser.
  1732. *
  1733. * @param {Function} creator
  1734. * @example
  1735. * var Canvas = require('canvas');
  1736. * var echarts = require('echarts');
  1737. * echarts.setCanvasCreator(function () {
  1738. * // Small size is enough.
  1739. * return new Canvas(32, 32);
  1740. * });
  1741. */
  1742. echarts.setCanvasCreator = function (creator) {
  1743. zrUtil.createCanvas = creator;
  1744. };
  1745. echarts.registerVisual(PRIORITY_VISUAL_GLOBAL, __webpack_require__(94));
  1746. echarts.registerPreprocessor(__webpack_require__(95));
  1747. echarts.registerLoading('default', __webpack_require__(97));
  1748. // Default action
  1749. echarts.registerAction({
  1750. type: 'highlight',
  1751. event: 'highlight',
  1752. update: 'highlight'
  1753. }, zrUtil.noop);
  1754. echarts.registerAction({
  1755. type: 'downplay',
  1756. event: 'downplay',
  1757. update: 'downplay'
  1758. }, zrUtil.noop);
  1759. // --------
  1760. // Exports
  1761. // --------
  1762. echarts.zrender = zrender;
  1763. echarts.List = __webpack_require__(98);
  1764. echarts.Model = __webpack_require__(12);
  1765. echarts.Axis = __webpack_require__(100);
  1766. echarts.graphic = __webpack_require__(18);
  1767. echarts.number = __webpack_require__(7);
  1768. echarts.format = __webpack_require__(6);
  1769. echarts.throttle = throttle.throttle;
  1770. echarts.matrix = __webpack_require__(11);
  1771. echarts.vector = __webpack_require__(10);
  1772. echarts.color = __webpack_require__(31);
  1773. echarts.util = {};
  1774. each([
  1775. 'map', 'each', 'filter', 'indexOf', 'inherits', 'reduce', 'filter',
  1776. 'bind', 'curry', 'isArray', 'isString', 'isObject', 'isFunction',
  1777. 'extend', 'defaults', 'clone', 'merge'
  1778. ],
  1779. function (name) {
  1780. echarts.util[name] = zrUtil[name];
  1781. }
  1782. );
  1783. echarts.helper = __webpack_require__(108);
  1784. // PRIORITY
  1785. echarts.PRIORITY = {
  1786. PROCESSOR: {
  1787. FILTER: PRIORITY_PROCESSOR_FILTER,
  1788. STATISTIC: PRIORITY_PROCESSOR_STATISTIC
  1789. },
  1790. VISUAL: {
  1791. LAYOUT: PRIORITY_VISUAL_LAYOUT,
  1792. GLOBAL: PRIORITY_VISUAL_GLOBAL,
  1793. CHART: PRIORITY_VISUAL_CHART,
  1794. COMPONENT: PRIORITY_VISUAL_COMPONENT,
  1795. BRUSH: PRIORITY_VISUAL_BRUSH
  1796. }
  1797. };
  1798. module.exports = echarts;
  1799. /***/ },
  1800. /* 2 */
  1801. /***/ function(module, exports) {
  1802. /**
  1803. * echarts设备环境识别
  1804. *
  1805. * @desc echarts基于Canvas,纯Javascript图表库,提供直观,生动,可交互,可个性化定制的数据统计图表。
  1806. * @author firede[firede@firede.us]
  1807. * @desc thanks zepto.
  1808. */
  1809. var env = {};
  1810. if (typeof navigator === 'undefined') {
  1811. // In node
  1812. env = {
  1813. browser: {},
  1814. os: {},
  1815. node: true,
  1816. // Assume canvas is supported
  1817. canvasSupported: true
  1818. };
  1819. }
  1820. else {
  1821. env = detect(navigator.userAgent);
  1822. }
  1823. module.exports = env;
  1824. // Zepto.js
  1825. // (c) 2010-2013 Thomas Fuchs
  1826. // Zepto.js may be freely distributed under the MIT license.
  1827. function detect(ua) {
  1828. var os = {};
  1829. var browser = {};
  1830. // var webkit = ua.match(/Web[kK]it[\/]{0,1}([\d.]+)/);
  1831. // var android = ua.match(/(Android);?[\s\/]+([\d.]+)?/);
  1832. // var ipad = ua.match(/(iPad).*OS\s([\d_]+)/);
  1833. // var ipod = ua.match(/(iPod)(.*OS\s([\d_]+))?/);
  1834. // var iphone = !ipad && ua.match(/(iPhone\sOS)\s([\d_]+)/);
  1835. // var webos = ua.match(/(webOS|hpwOS)[\s\/]([\d.]+)/);
  1836. // var touchpad = webos && ua.match(/TouchPad/);
  1837. // var kindle = ua.match(/Kindle\/([\d.]+)/);
  1838. // var silk = ua.match(/Silk\/([\d._]+)/);
  1839. // var blackberry = ua.match(/(BlackBerry).*Version\/([\d.]+)/);
  1840. // var bb10 = ua.match(/(BB10).*Version\/([\d.]+)/);
  1841. // var rimtabletos = ua.match(/(RIM\sTablet\sOS)\s([\d.]+)/);
  1842. // var playbook = ua.match(/PlayBook/);
  1843. // var chrome = ua.match(/Chrome\/([\d.]+)/) || ua.match(/CriOS\/([\d.]+)/);
  1844. var firefox = ua.match(/Firefox\/([\d.]+)/);
  1845. // var safari = webkit && ua.match(/Mobile\//) && !chrome;
  1846. // var webview = ua.match(/(iPhone|iPod|iPad).*AppleWebKit(?!.*Safari)/) && !chrome;
  1847. var ie = ua.match(/MSIE\s([\d.]+)/)
  1848. // IE 11 Trident/7.0; rv:11.0
  1849. || ua.match(/Trident\/.+?rv:(([\d.]+))/);
  1850. var edge = ua.match(/Edge\/([\d.]+)/); // IE 12 and 12+
  1851. var weChat = (/micromessenger/i).test(ua);
  1852. // Todo: clean this up with a better OS/browser seperation:
  1853. // - discern (more) between multiple browsers on android
  1854. // - decide if kindle fire in silk mode is android or not
  1855. // - Firefox on Android doesn't specify the Android version
  1856. // - possibly devide in os, device and browser hashes
  1857. // if (browser.webkit = !!webkit) browser.version = webkit[1];
  1858. // if (android) os.android = true, os.version = android[2];
  1859. // if (iphone && !ipod) os.ios = os.iphone = true, os.version = iphone[2].replace(/_/g, '.');
  1860. // if (ipad) os.ios = os.ipad = true, os.version = ipad[2].replace(/_/g, '.');
  1861. // if (ipod) os.ios = os.ipod = true, os.version = ipod[3] ? ipod[3].replace(/_/g, '.') : null;
  1862. // if (webos) os.webos = true, os.version = webos[2];
  1863. // if (touchpad) os.touchpad = true;
  1864. // if (blackberry) os.blackberry = true, os.version = blackberry[2];
  1865. // if (bb10) os.bb10 = true, os.version = bb10[2];
  1866. // if (rimtabletos) os.rimtabletos = true, os.version = rimtabletos[2];
  1867. // if (playbook) browser.playbook = true;
  1868. // if (kindle) os.kindle = true, os.version = kindle[1];
  1869. // if (silk) browser.silk = true, browser.version = silk[1];
  1870. // if (!silk && os.android && ua.match(/Kindle Fire/)) browser.silk = true;
  1871. // if (chrome) browser.chrome = true, browser.version = chrome[1];
  1872. if (firefox) {
  1873. browser.firefox = true;
  1874. browser.version = firefox[1];
  1875. }
  1876. // if (safari && (ua.match(/Safari/) || !!os.ios)) browser.safari = true;
  1877. // if (webview) browser.webview = true;
  1878. if (ie) {
  1879. browser.ie = true;
  1880. browser.version = ie[1];
  1881. }
  1882. if (edge) {
  1883. browser.edge = true;
  1884. browser.version = edge[1];
  1885. }
  1886. // It is difficult to detect WeChat in Win Phone precisely, because ua can
  1887. // not be set on win phone. So we do not consider Win Phone.
  1888. if (weChat) {
  1889. browser.weChat = true;
  1890. }
  1891. // os.tablet = !!(ipad || playbook || (android && !ua.match(/Mobile/)) ||
  1892. // (firefox && ua.match(/Tablet/)) || (ie && !ua.match(/Phone/) && ua.match(/Touch/)));
  1893. // os.phone = !!(!os.tablet && !os.ipod && (android || iphone || webos ||
  1894. // (chrome && ua.match(/Android/)) || (chrome && ua.match(/CriOS\/([\d.]+)/)) ||
  1895. // (firefox && ua.match(/Mobile/)) || (ie && ua.match(/Touch/))));
  1896. return {
  1897. browser: browser,
  1898. os: os,
  1899. node: false,
  1900. // 原生canvas支持,改极端点了
  1901. // canvasSupported : !(browser.ie && parseFloat(browser.version) < 9)
  1902. canvasSupported : document.createElement('canvas').getContext ? true : false,
  1903. // @see <http://stackoverflow.com/questions/4817029/whats-the-best-way-to-detect-a-touch-screen-device-using-javascript>
  1904. // works on most browsers
  1905. // IE10/11 does not support touch event, and MS Edge supports them but not by
  1906. // default, so we dont check navigator.maxTouchPoints for them here.
  1907. touchEventsSupported: 'ontouchstart' in window && !browser.ie && !browser.edge,
  1908. // <http://caniuse.com/#search=pointer%20event>.
  1909. pointerEventsSupported: 'onpointerdown' in window
  1910. // Firefox supports pointer but not by default, only MS browsers are reliable on pointer
  1911. // events currently. So we dont use that on other browsers unless tested sufficiently.
  1912. // Although IE 10 supports pointer event, it use old style and is different from the
  1913. // standard. So we exclude that. (IE 10 is hardly used on touch device)
  1914. && (browser.edge || (browser.ie && browser.version >= 11))
  1915. };
  1916. }
  1917. /***/ },
  1918. /* 3 */
  1919. /***/ function(module, exports, __webpack_require__) {
  1920. /**
  1921. * ECharts global model
  1922. *
  1923. * @module {echarts/model/Global}
  1924. */
  1925. /**
  1926. * Caution: If the mechanism should be changed some day, these cases
  1927. * should be considered:
  1928. *
  1929. * (1) In `merge option` mode, if using the same option to call `setOption`
  1930. * many times, the result should be the same (try our best to ensure that).
  1931. * (2) In `merge option` mode, if a component has no id/name specified, it
  1932. * will be merged by index, and the result sequence of the components is
  1933. * consistent to the original sequence.
  1934. * (3) `reset` feature (in toolbox). Find detailed info in comments about
  1935. * `mergeOption` in module:echarts/model/OptionManager.
  1936. */
  1937. var zrUtil = __webpack_require__(4);
  1938. var modelUtil = __webpack_require__(5);
  1939. var Model = __webpack_require__(12);
  1940. var each = zrUtil.each;
  1941. var filter = zrUtil.filter;
  1942. var map = zrUtil.map;
  1943. var isArray = zrUtil.isArray;
  1944. var indexOf = zrUtil.indexOf;
  1945. var isObject = zrUtil.isObject;
  1946. var ComponentModel = __webpack_require__(69);
  1947. var globalDefault = __webpack_require__(73);
  1948. var OPTION_INNER_KEY = '\0_ec_inner';
  1949. /**
  1950. * @alias module:echarts/model/Global
  1951. *
  1952. * @param {Object} option
  1953. * @param {module:echarts/model/Model} parentModel
  1954. * @param {Object} theme
  1955. */
  1956. var GlobalModel = Model.extend({
  1957. constructor: GlobalModel,
  1958. init: function (option, parentModel, theme, optionManager) {
  1959. theme = theme || {};
  1960. this.option = null; // Mark as not initialized.
  1961. /**
  1962. * @type {module:echarts/model/Model}
  1963. * @private
  1964. */
  1965. this._theme = new Model(theme);
  1966. /**
  1967. * @type {module:echarts/model/OptionManager}
  1968. */
  1969. this._optionManager = optionManager;
  1970. },
  1971. setOption: function (option, optionPreprocessorFuncs) {
  1972. zrUtil.assert(
  1973. !(OPTION_INNER_KEY in option),
  1974. 'please use chart.getOption()'
  1975. );
  1976. this._optionManager.setOption(option, optionPreprocessorFuncs);
  1977. this.resetOption(null);
  1978. },
  1979. /**
  1980. * @param {string} type null/undefined: reset all.
  1981. * 'recreate': force recreate all.
  1982. * 'timeline': only reset timeline option
  1983. * 'media': only reset media query option
  1984. * @return {boolean} Whether option changed.
  1985. */
  1986. resetOption: function (type) {
  1987. var optionChanged = false;
  1988. var optionManager = this._optionManager;
  1989. if (!type || type === 'recreate') {
  1990. var baseOption = optionManager.mountOption(type === 'recreate');
  1991. if (!this.option || type === 'recreate') {
  1992. initBase.call(this, baseOption);
  1993. }
  1994. else {
  1995. this.restoreData();
  1996. this.mergeOption(baseOption);
  1997. }
  1998. optionChanged = true;
  1999. }
  2000. if (type === 'timeline' || type === 'media') {
  2001. this.restoreData();
  2002. }
  2003. if (!type || type === 'recreate' || type === 'timeline') {
  2004. var timelineOption = optionManager.getTimelineOption(this);
  2005. timelineOption && (this.mergeOption(timelineOption), optionChanged = true);
  2006. }
  2007. if (!type || type === 'recreate' || type === 'media') {
  2008. var mediaOptions = optionManager.getMediaOption(this, this._api);
  2009. if (mediaOptions.length) {
  2010. each(mediaOptions, function (mediaOption) {
  2011. this.mergeOption(mediaOption, optionChanged = true);
  2012. }, this);
  2013. }
  2014. }
  2015. return optionChanged;
  2016. },
  2017. /**
  2018. * @protected
  2019. */
  2020. mergeOption: function (newOption) {
  2021. var option = this.option;
  2022. var componentsMap = this._componentsMap;
  2023. var newCptTypes = [];
  2024. // 如果不存在对应的 component model 则直接 merge
  2025. each(newOption, function (componentOption, mainType) {
  2026. if (componentOption == null) {
  2027. return;
  2028. }
  2029. if (!ComponentModel.hasClass(mainType)) {
  2030. option[mainType] = option[mainType] == null
  2031. ? zrUtil.clone(componentOption)
  2032. : zrUtil.merge(option[mainType], componentOption, true);
  2033. }
  2034. else {
  2035. newCptTypes.push(mainType);
  2036. }
  2037. });
  2038. // FIXME OPTION 同步是否要改回原来的
  2039. ComponentModel.topologicalTravel(
  2040. newCptTypes, ComponentModel.getAllClassMainTypes(), visitComponent, this
  2041. );
  2042. this._seriesIndices = this._seriesIndices || [];
  2043. function visitComponent(mainType, dependencies) {
  2044. var newCptOptionList = modelUtil.normalizeToArray(newOption[mainType]);
  2045. var mapResult = modelUtil.mappingToExists(
  2046. componentsMap.get(mainType), newCptOptionList
  2047. );
  2048. modelUtil.makeIdAndName(mapResult);
  2049. // Set mainType and complete subType.
  2050. each(mapResult, function (item, index) {
  2051. var opt = item.option;
  2052. if (isObject(opt)) {
  2053. item.keyInfo.mainType = mainType;
  2054. item.keyInfo.subType = determineSubType(mainType, opt, item.exist);
  2055. }
  2056. });
  2057. var dependentModels = getComponentsByTypes(
  2058. componentsMap, dependencies
  2059. );
  2060. option[mainType] = [];
  2061. componentsMap.set(mainType, []);
  2062. each(mapResult, function (resultItem, index) {
  2063. var componentModel = resultItem.exist;
  2064. var newCptOption = resultItem.option;
  2065. zrUtil.assert(
  2066. isObject(newCptOption) || componentModel,
  2067. 'Empty component definition'
  2068. );
  2069. // Consider where is no new option and should be merged using {},
  2070. // see removeEdgeAndAdd in topologicalTravel and
  2071. // ComponentModel.getAllClassMainTypes.
  2072. if (!newCptOption) {
  2073. componentModel.mergeOption({}, this);
  2074. componentModel.optionUpdated({}, false);
  2075. }
  2076. else {
  2077. var ComponentModelClass = ComponentModel.getClass(
  2078. mainType, resultItem.keyInfo.subType, true
  2079. );
  2080. if (componentModel && componentModel instanceof ComponentModelClass) {
  2081. componentModel.name = resultItem.keyInfo.name;
  2082. componentModel.mergeOption(newCptOption, this);
  2083. componentModel.optionUpdated(newCptOption, false);
  2084. }
  2085. else {
  2086. // PENDING Global as parent ?
  2087. var extraOpt = zrUtil.extend(
  2088. {
  2089. dependentModels: dependentModels,
  2090. componentIndex: index
  2091. },
  2092. resultItem.keyInfo
  2093. );
  2094. componentModel = new ComponentModelClass(
  2095. newCptOption, this, this, extraOpt
  2096. );
  2097. zrUtil.extend(componentModel, extraOpt);
  2098. componentModel.init(newCptOption, this, this, extraOpt);
  2099. // Call optionUpdated after init.
  2100. // newCptOption has been used as componentModel.option
  2101. // and may be merged with theme and default, so pass null
  2102. // to avoid confusion.
  2103. componentModel.optionUpdated(null, true);
  2104. }
  2105. }
  2106. componentsMap.get(mainType)[index] = componentModel;
  2107. option[mainType][index] = componentModel.option;
  2108. }, this);
  2109. // Backup series for filtering.
  2110. if (mainType === 'series') {
  2111. this._seriesIndices = createSeriesIndices(componentsMap.get('series'));
  2112. }
  2113. }
  2114. },
  2115. /**
  2116. * Get option for output (cloned option and inner info removed)
  2117. * @public
  2118. * @return {Object}
  2119. */
  2120. getOption: function () {
  2121. var option = zrUtil.clone(this.option);
  2122. each(option, function (opts, mainType) {
  2123. if (ComponentModel.hasClass(mainType)) {
  2124. var opts = modelUtil.normalizeToArray(opts);
  2125. for (var i = opts.length - 1; i >= 0; i--) {
  2126. // Remove options with inner id.
  2127. if (modelUtil.isIdInner(opts[i])) {
  2128. opts.splice(i, 1);
  2129. }
  2130. }
  2131. option[mainType] = opts;
  2132. }
  2133. });
  2134. delete option[OPTION_INNER_KEY];
  2135. return option;
  2136. },
  2137. /**
  2138. * @return {module:echarts/model/Model}
  2139. */
  2140. getTheme: function () {
  2141. return this._theme;
  2142. },
  2143. /**
  2144. * @param {string} mainType
  2145. * @param {number} [idx=0]
  2146. * @return {module:echarts/model/Component}
  2147. */
  2148. getComponent: function (mainType, idx) {
  2149. var list = this._componentsMap.get(mainType);
  2150. if (list) {
  2151. return list[idx || 0];
  2152. }
  2153. },
  2154. /**
  2155. * If none of index and id and name used, return all components with mainType.
  2156. * @param {Object} condition
  2157. * @param {string} condition.mainType
  2158. * @param {string} [condition.subType] If ignore, only query by mainType
  2159. * @param {number|Array.<number>} [condition.index] Either input index or id or name.
  2160. * @param {string|Array.<string>} [condition.id] Either input index or id or name.
  2161. * @param {string|Array.<string>} [condition.name] Either input index or id or name.
  2162. * @return {Array.<module:echarts/model/Component>}
  2163. */
  2164. queryComponents: function (condition) {
  2165. var mainType = condition.mainType;
  2166. if (!mainType) {
  2167. return [];
  2168. }
  2169. var index = condition.index;
  2170. var id = condition.id;
  2171. var name = condition.name;
  2172. var cpts = this._componentsMap.get(mainType);
  2173. if (!cpts || !cpts.length) {
  2174. return [];
  2175. }
  2176. var result;
  2177. if (index != null) {
  2178. if (!isArray(index)) {
  2179. index = [index];
  2180. }
  2181. result = filter(map(index, function (idx) {
  2182. return cpts[idx];
  2183. }), function (val) {
  2184. return !!val;
  2185. });
  2186. }
  2187. else if (id != null) {
  2188. var isIdArray = isArray(id);
  2189. result = filter(cpts, function (cpt) {
  2190. return (isIdArray && indexOf(id, cpt.id) >= 0)
  2191. || (!isIdArray && cpt.id === id);
  2192. });
  2193. }
  2194. else if (name != null) {
  2195. var isNameArray = isArray(name);
  2196. result = filter(cpts, function (cpt) {
  2197. return (isNameArray && indexOf(name, cpt.name) >= 0)
  2198. || (!isNameArray && cpt.name === name);
  2199. });
  2200. }
  2201. else {
  2202. // Return all components with mainType
  2203. result = cpts.slice();
  2204. }
  2205. return filterBySubType(result, condition);
  2206. },
  2207. /**
  2208. * The interface is different from queryComponents,
  2209. * which is convenient for inner usage.
  2210. *
  2211. * @usage
  2212. * var result = findComponents(
  2213. * {mainType: 'dataZoom', query: {dataZoomId: 'abc'}}
  2214. * );
  2215. * var result = findComponents(
  2216. * {mainType: 'series', subType: 'pie', query: {seriesName: 'uio'}}
  2217. * );
  2218. * var result = findComponents(
  2219. * {mainType: 'series'},
  2220. * function (model, index) {...}
  2221. * );
  2222. * // result like [component0, componnet1, ...]
  2223. *
  2224. * @param {Object} condition
  2225. * @param {string} condition.mainType Mandatory.
  2226. * @param {string} [condition.subType] Optional.
  2227. * @param {Object} [condition.query] like {xxxIndex, xxxId, xxxName},
  2228. * where xxx is mainType.
  2229. * If query attribute is null/undefined or has no index/id/name,
  2230. * do not filtering by query conditions, which is convenient for
  2231. * no-payload situations or when target of action is global.
  2232. * @param {Function} [condition.filter] parameter: component, return boolean.
  2233. * @return {Array.<module:echarts/model/Component>}
  2234. */
  2235. findComponents: function (condition) {
  2236. var query = condition.query;
  2237. var mainType = condition.mainType;
  2238. var queryCond = getQueryCond(query);
  2239. var result = queryCond
  2240. ? this.queryComponents(queryCond)
  2241. : this._componentsMap.get(mainType);
  2242. return doFilter(filterBySubType(result, condition));
  2243. function getQueryCond(q) {
  2244. var indexAttr = mainType + 'Index';
  2245. var idAttr = mainType + 'Id';
  2246. var nameAttr = mainType + 'Name';
  2247. return q && (
  2248. q[indexAttr] != null
  2249. || q[idAttr] != null
  2250. || q[nameAttr] != null
  2251. )
  2252. ? {
  2253. mainType: mainType,
  2254. // subType will be filtered finally.
  2255. index: q[indexAttr],
  2256. id: q[idAttr],
  2257. name: q[nameAttr]
  2258. }
  2259. : null;
  2260. }
  2261. function doFilter(res) {
  2262. return condition.filter
  2263. ? filter(res, condition.filter)
  2264. : res;
  2265. }
  2266. },
  2267. /**
  2268. * @usage
  2269. * eachComponent('legend', function (legendModel, index) {
  2270. * ...
  2271. * });
  2272. * eachComponent(function (componentType, model, index) {
  2273. * // componentType does not include subType
  2274. * // (componentType is 'xxx' but not 'xxx.aa')
  2275. * });
  2276. * eachComponent(
  2277. * {mainType: 'dataZoom', query: {dataZoomId: 'abc'}},
  2278. * function (model, index) {...}
  2279. * );
  2280. * eachComponent(
  2281. * {mainType: 'series', subType: 'pie', query: {seriesName: 'uio'}},
  2282. * function (model, index) {...}
  2283. * );
  2284. *
  2285. * @param {string|Object=} mainType When mainType is object, the definition
  2286. * is the same as the method 'findComponents'.
  2287. * @param {Function} cb
  2288. * @param {*} context
  2289. */
  2290. eachComponent: function (mainType, cb, context) {
  2291. var componentsMap = this._componentsMap;
  2292. if (typeof mainType === 'function') {
  2293. context = cb;
  2294. cb = mainType;
  2295. componentsMap.each(function (components, componentType) {
  2296. each(components, function (component, index) {
  2297. cb.call(context, componentType, component, index);
  2298. });
  2299. });
  2300. }
  2301. else if (zrUtil.isString(mainType)) {
  2302. each(componentsMap.get(mainType), cb, context);
  2303. }
  2304. else if (isObject(mainType)) {
  2305. var queryResult = this.findComponents(mainType);
  2306. each(queryResult, cb, context);
  2307. }
  2308. },
  2309. /**
  2310. * @param {string} name
  2311. * @return {Array.<module:echarts/model/Series>}
  2312. */
  2313. getSeriesByName: function (name) {
  2314. var series = this._componentsMap.get('series');
  2315. return filter(series, function (oneSeries) {
  2316. return oneSeries.name === name;
  2317. });
  2318. },
  2319. /**
  2320. * @param {number} seriesIndex
  2321. * @return {module:echarts/model/Series}
  2322. */
  2323. getSeriesByIndex: function (seriesIndex) {
  2324. return this._componentsMap.get('series')[seriesIndex];
  2325. },
  2326. /**
  2327. * @param {string} subType
  2328. * @return {Array.<module:echarts/model/Series>}
  2329. */
  2330. getSeriesByType: function (subType) {
  2331. var series = this._componentsMap.get('series');
  2332. return filter(series, function (oneSeries) {
  2333. return oneSeries.subType === subType;
  2334. });
  2335. },
  2336. /**
  2337. * @return {Array.<module:echarts/model/Series>}
  2338. */
  2339. getSeries: function () {
  2340. return this._componentsMap.get('series').slice();
  2341. },
  2342. /**
  2343. * After filtering, series may be different
  2344. * frome raw series.
  2345. *
  2346. * @param {Function} cb
  2347. * @param {*} context
  2348. */
  2349. eachSeries: function (cb, context) {
  2350. assertSeriesInitialized(this);
  2351. each(this._seriesIndices, function (rawSeriesIndex) {
  2352. var series = this._componentsMap.get('series')[rawSeriesIndex];
  2353. cb.call(context, series, rawSeriesIndex);
  2354. }, this);
  2355. },
  2356. /**
  2357. * Iterate raw series before filtered.
  2358. *
  2359. * @param {Function} cb
  2360. * @param {*} context
  2361. */
  2362. eachRawSeries: function (cb, context) {
  2363. each(this._componentsMap.get('series'), cb, context);
  2364. },
  2365. /**
  2366. * After filtering, series may be different.
  2367. * frome raw series.
  2368. *
  2369. * @parma {string} subType
  2370. * @param {Function} cb
  2371. * @param {*} context
  2372. */
  2373. eachSeriesByType: function (subType, cb, context) {
  2374. assertSeriesInitialized(this);
  2375. each(this._seriesIndices, function (rawSeriesIndex) {
  2376. var series = this._componentsMap.get('series')[rawSeriesIndex];
  2377. if (series.subType === subType) {
  2378. cb.call(context, series, rawSeriesIndex);
  2379. }
  2380. }, this);
  2381. },
  2382. /**
  2383. * Iterate raw series before filtered of given type.
  2384. *
  2385. * @parma {string} subType
  2386. * @param {Function} cb
  2387. * @param {*} context
  2388. */
  2389. eachRawSeriesByType: function (subType, cb, context) {
  2390. return each(this.getSeriesByType(subType), cb, context);
  2391. },
  2392. /**
  2393. * @param {module:echarts/model/Series} seriesModel
  2394. */
  2395. isSeriesFiltered: function (seriesModel) {
  2396. assertSeriesInitialized(this);
  2397. return zrUtil.indexOf(this._seriesIndices, seriesModel.componentIndex) < 0;
  2398. },
  2399. /**
  2400. * @return {Array.<number>}
  2401. */
  2402. getCurrentSeriesIndices: function () {
  2403. return (this._seriesIndices || []).slice();
  2404. },
  2405. /**
  2406. * @param {Function} cb
  2407. * @param {*} context
  2408. */
  2409. filterSeries: function (cb, context) {
  2410. assertSeriesInitialized(this);
  2411. var filteredSeries = filter(
  2412. this._componentsMap.get('series'), cb, context
  2413. );
  2414. this._seriesIndices = createSeriesIndices(filteredSeries);
  2415. },
  2416. restoreData: function () {
  2417. var componentsMap = this._componentsMap;
  2418. this._seriesIndices = createSeriesIndices(componentsMap.get('series'));
  2419. var componentTypes = [];
  2420. componentsMap.each(function (components, componentType) {
  2421. componentTypes.push(componentType);
  2422. });
  2423. ComponentModel.topologicalTravel(
  2424. componentTypes,
  2425. ComponentModel.getAllClassMainTypes(),
  2426. function (componentType, dependencies) {
  2427. each(componentsMap.get(componentType), function (component) {
  2428. component.restoreData();
  2429. });
  2430. }
  2431. );
  2432. }
  2433. });
  2434. /**
  2435. * @inner
  2436. */
  2437. function mergeTheme(option, theme) {
  2438. zrUtil.each(theme, function (themeItem, name) {
  2439. // 如果有 component model 则把具体的 merge 逻辑交给该 model 处理
  2440. if (!ComponentModel.hasClass(name)) {
  2441. if (typeof themeItem === 'object') {
  2442. option[name] = !option[name]
  2443. ? zrUtil.clone(themeItem)
  2444. : zrUtil.merge(option[name], themeItem, false);
  2445. }
  2446. else {
  2447. if (option[name] == null) {
  2448. option[name] = themeItem;
  2449. }
  2450. }
  2451. }
  2452. });
  2453. }
  2454. function initBase(baseOption) {
  2455. baseOption = baseOption;
  2456. // Using OPTION_INNER_KEY to mark that this option can not be used outside,
  2457. // i.e. `chart.setOption(chart.getModel().option);` is forbiden.
  2458. this.option = {};
  2459. this.option[OPTION_INNER_KEY] = 1;
  2460. /**
  2461. * Init with series: [], in case of calling findSeries method
  2462. * before series initialized.
  2463. * @type {Object.<string, Array.<module:echarts/model/Model>>}
  2464. * @private
  2465. */
  2466. this._componentsMap = zrUtil.createHashMap({series: []});
  2467. /**
  2468. * Mapping between filtered series list and raw series list.
  2469. * key: filtered series indices, value: raw series indices.
  2470. * @type {Array.<nubmer>}
  2471. * @private
  2472. */
  2473. this._seriesIndices = null;
  2474. mergeTheme(baseOption, this._theme.option);
  2475. // TODO Needs clone when merging to the unexisted property
  2476. zrUtil.merge(baseOption, globalDefault, false);
  2477. this.mergeOption(baseOption);
  2478. }
  2479. /**
  2480. * @inner
  2481. * @param {Array.<string>|string} types model types
  2482. * @return {Object} key: {string} type, value: {Array.<Object>} models
  2483. */
  2484. function getComponentsByTypes(componentsMap, types) {
  2485. if (!zrUtil.isArray(types)) {
  2486. types = types ? [types] : [];
  2487. }
  2488. var ret = {};
  2489. each(types, function (type) {
  2490. ret[type] = (componentsMap.get(type) || []).slice();
  2491. });
  2492. return ret;
  2493. }
  2494. /**
  2495. * @inner
  2496. */
  2497. function determineSubType(mainType, newCptOption, existComponent) {
  2498. var subType = newCptOption.type
  2499. ? newCptOption.type
  2500. : existComponent
  2501. ? existComponent.subType
  2502. // Use determineSubType only when there is no existComponent.
  2503. : ComponentModel.determineSubType(mainType, newCptOption);
  2504. // tooltip, markline, markpoint may always has no subType
  2505. return subType;
  2506. }
  2507. /**
  2508. * @inner
  2509. */
  2510. function createSeriesIndices(seriesModels) {
  2511. return map(seriesModels, function (series) {
  2512. return series.componentIndex;
  2513. }) || [];
  2514. }
  2515. /**
  2516. * @inner
  2517. */
  2518. function filterBySubType(components, condition) {
  2519. // Using hasOwnProperty for restrict. Consider
  2520. // subType is undefined in user payload.
  2521. return condition.hasOwnProperty('subType')
  2522. ? filter(components, function (cpt) {
  2523. return cpt.subType === condition.subType;
  2524. })
  2525. : components;
  2526. }
  2527. /**
  2528. * @inner
  2529. */
  2530. function assertSeriesInitialized(ecModel) {
  2531. // Components that use _seriesIndices should depends on series component,
  2532. // which make sure that their initialization is after series.
  2533. if (true) {
  2534. if (!ecModel._seriesIndices) {
  2535. throw new Error('Option should contains series.');
  2536. }
  2537. }
  2538. }
  2539. zrUtil.mixin(GlobalModel, __webpack_require__(74));
  2540. module.exports = GlobalModel;
  2541. /***/ },
  2542. /* 4 */
  2543. /***/ function(module, exports) {
  2544. /**
  2545. * @module zrender/core/util
  2546. */
  2547. // 用于处理merge时无法遍历Date等对象的问题
  2548. var BUILTIN_OBJECT = {
  2549. '[object Function]': 1,
  2550. '[object RegExp]': 1,
  2551. '[object Date]': 1,
  2552. '[object Error]': 1,
  2553. '[object CanvasGradient]': 1,
  2554. '[object CanvasPattern]': 1,
  2555. // For node-canvas
  2556. '[object Image]': 1,
  2557. '[object Canvas]': 1
  2558. };
  2559. var TYPED_ARRAY = {
  2560. '[object Int8Array]': 1,
  2561. '[object Uint8Array]': 1,
  2562. '[object Uint8ClampedArray]': 1,
  2563. '[object Int16Array]': 1,
  2564. '[object Uint16Array]': 1,
  2565. '[object Int32Array]': 1,
  2566. '[object Uint32Array]': 1,
  2567. '[object Float32Array]': 1,
  2568. '[object Float64Array]': 1
  2569. };
  2570. var objToString = Object.prototype.toString;
  2571. var arrayProto = Array.prototype;
  2572. var nativeForEach = arrayProto.forEach;
  2573. var nativeFilter = arrayProto.filter;
  2574. var nativeSlice = arrayProto.slice;
  2575. var nativeMap = arrayProto.map;
  2576. var nativeReduce = arrayProto.reduce;
  2577. /**
  2578. * Those data types can be cloned:
  2579. * Plain object, Array, TypedArray, number, string, null, undefined.
  2580. * Those data types will be assgined using the orginal data:
  2581. * BUILTIN_OBJECT
  2582. * Instance of user defined class will be cloned to a plain object, without
  2583. * properties in prototype.
  2584. * Other data types is not supported (not sure what will happen).
  2585. *
  2586. * Caution: do not support clone Date, for performance consideration.
  2587. * (There might be a large number of date in `series.data`).
  2588. * So date should not be modified in and out of echarts.
  2589. *
  2590. * @param {*} source
  2591. * @return {*} new
  2592. */
  2593. function clone(source) {
  2594. if (source == null || typeof source != 'object') {
  2595. return source;
  2596. }
  2597. var result = source;
  2598. var typeStr = objToString.call(source);
  2599. if (typeStr === '[object Array]') {
  2600. result = [];
  2601. for (var i = 0, len = source.length; i < len; i++) {
  2602. result[i] = clone(source[i]);
  2603. }
  2604. }
  2605. else if (TYPED_ARRAY[typeStr]) {
  2606. result = source.constructor.from(source);
  2607. }
  2608. else if (!BUILTIN_OBJECT[typeStr] && !isPrimitive(source) && !isDom(source)) {
  2609. result = {};
  2610. for (var key in source) {
  2611. if (source.hasOwnProperty(key)) {
  2612. result[key] = clone(source[key]);
  2613. }
  2614. }
  2615. }
  2616. return result;
  2617. }
  2618. /**
  2619. * @memberOf module:zrender/core/util
  2620. * @param {*} target
  2621. * @param {*} source
  2622. * @param {boolean} [overwrite=false]
  2623. */
  2624. function merge(target, source, overwrite) {
  2625. // We should escapse that source is string
  2626. // and enter for ... in ...
  2627. if (!isObject(source) || !isObject(target)) {
  2628. return overwrite ? clone(source) : target;
  2629. }
  2630. for (var key in source) {
  2631. if (source.hasOwnProperty(key)) {
  2632. var targetProp = target[key];
  2633. var sourceProp = source[key];
  2634. if (isObject(sourceProp)
  2635. && isObject(targetProp)
  2636. && !isArray(sourceProp)
  2637. && !isArray(targetProp)
  2638. && !isDom(sourceProp)
  2639. && !isDom(targetProp)
  2640. && !isBuiltInObject(sourceProp)
  2641. && !isBuiltInObject(targetProp)
  2642. && !isPrimitive(sourceProp)
  2643. && !isPrimitive(targetProp)
  2644. ) {
  2645. // 如果需要递归覆盖,就递归调用merge
  2646. merge(targetProp, sourceProp, overwrite);
  2647. }
  2648. else if (overwrite || !(key in target)) {
  2649. // 否则只处理overwrite为true,或者在目标对象中没有此属性的情况
  2650. // NOTE,在 target[key] 不存在的时候也是直接覆盖
  2651. target[key] = clone(source[key], true);
  2652. }
  2653. }
  2654. }
  2655. return target;
  2656. }
  2657. /**
  2658. * @param {Array} targetAndSources The first item is target, and the rests are source.
  2659. * @param {boolean} [overwrite=false]
  2660. * @return {*} target
  2661. */
  2662. function mergeAll(targetAndSources, overwrite) {
  2663. var result = targetAndSources[0];
  2664. for (var i = 1, len = targetAndSources.length; i < len; i++) {
  2665. result = merge(result, targetAndSources[i], overwrite);
  2666. }
  2667. return result;
  2668. }
  2669. /**
  2670. * @param {*} target
  2671. * @param {*} source
  2672. * @memberOf module:zrender/core/util
  2673. */
  2674. function extend(target, source) {
  2675. for (var key in source) {
  2676. if (source.hasOwnProperty(key)) {
  2677. target[key] = source[key];
  2678. }
  2679. }
  2680. return target;
  2681. }
  2682. /**
  2683. * @param {*} target
  2684. * @param {*} source
  2685. * @param {boolen} [overlay=false]
  2686. * @memberOf module:zrender/core/util
  2687. */
  2688. function defaults(target, source, overlay) {
  2689. for (var key in source) {
  2690. if (source.hasOwnProperty(key)
  2691. && (overlay ? source[key] != null : target[key] == null)
  2692. ) {
  2693. target[key] = source[key];
  2694. }
  2695. }
  2696. return target;
  2697. }
  2698. function createCanvas() {
  2699. return document.createElement('canvas');
  2700. }
  2701. // FIXME
  2702. var _ctx;
  2703. function getContext() {
  2704. if (!_ctx) {
  2705. // Use util.createCanvas instead of createCanvas
  2706. // because createCanvas may be overwritten in different environment
  2707. _ctx = util.createCanvas().getContext('2d');
  2708. }
  2709. return _ctx;
  2710. }
  2711. /**
  2712. * 查询数组中元素的index
  2713. * @memberOf module:zrender/core/util
  2714. */
  2715. function indexOf(array, value) {
  2716. if (array) {
  2717. if (array.indexOf) {
  2718. return array.indexOf(value);
  2719. }
  2720. for (var i = 0, len = array.length; i < len; i++) {
  2721. if (array[i] === value) {
  2722. return i;
  2723. }
  2724. }
  2725. }
  2726. return -1;
  2727. }
  2728. /**
  2729. * 构造类继承关系
  2730. *
  2731. * @memberOf module:zrender/core/util
  2732. * @param {Function} clazz 源类
  2733. * @param {Function} baseClazz 基类
  2734. */
  2735. function inherits(clazz, baseClazz) {
  2736. var clazzPrototype = clazz.prototype;
  2737. function F() {}
  2738. F.prototype = baseClazz.prototype;
  2739. clazz.prototype = new F();
  2740. for (var prop in clazzPrototype) {
  2741. clazz.prototype[prop] = clazzPrototype[prop];
  2742. }
  2743. clazz.prototype.constructor = clazz;
  2744. clazz.superClass = baseClazz;
  2745. }
  2746. /**
  2747. * @memberOf module:zrender/core/util
  2748. * @param {Object|Function} target
  2749. * @param {Object|Function} sorce
  2750. * @param {boolean} overlay
  2751. */
  2752. function mixin(target, source, overlay) {
  2753. target = 'prototype' in target ? target.prototype : target;
  2754. source = 'prototype' in source ? source.prototype : source;
  2755. defaults(target, source, overlay);
  2756. }
  2757. /**
  2758. * Consider typed array.
  2759. * @param {Array|TypedArray} data
  2760. */
  2761. function isArrayLike(data) {
  2762. if (! data) {
  2763. return;
  2764. }
  2765. if (typeof data == 'string') {
  2766. return false;
  2767. }
  2768. return typeof data.length == 'number';
  2769. }
  2770. /**
  2771. * 数组或对象遍历
  2772. * @memberOf module:zrender/core/util
  2773. * @param {Object|Array} obj
  2774. * @param {Function} cb
  2775. * @param {*} [context]
  2776. */
  2777. function each(obj, cb, context) {
  2778. if (!(obj && cb)) {
  2779. return;
  2780. }
  2781. if (obj.forEach && obj.forEach === nativeForEach) {
  2782. obj.forEach(cb, context);
  2783. }
  2784. else if (obj.length === +obj.length) {
  2785. for (var i = 0, len = obj.length; i < len; i++) {
  2786. cb.call(context, obj[i], i, obj);
  2787. }
  2788. }
  2789. else {
  2790. for (var key in obj) {
  2791. if (obj.hasOwnProperty(key)) {
  2792. cb.call(context, obj[key], key, obj);
  2793. }
  2794. }
  2795. }
  2796. }
  2797. /**
  2798. * 数组映射
  2799. * @memberOf module:zrender/core/util
  2800. * @param {Array} obj
  2801. * @param {Function} cb
  2802. * @param {*} [context]
  2803. * @return {Array}
  2804. */
  2805. function map(obj, cb, context) {
  2806. if (!(obj && cb)) {
  2807. return;
  2808. }
  2809. if (obj.map && obj.map === nativeMap) {
  2810. return obj.map(cb, context);
  2811. }
  2812. else {
  2813. var result = [];
  2814. for (var i = 0, len = obj.length; i < len; i++) {
  2815. result.push(cb.call(context, obj[i], i, obj));
  2816. }
  2817. return result;
  2818. }
  2819. }
  2820. /**
  2821. * @memberOf module:zrender/core/util
  2822. * @param {Array} obj
  2823. * @param {Function} cb
  2824. * @param {Object} [memo]
  2825. * @param {*} [context]
  2826. * @return {Array}
  2827. */
  2828. function reduce(obj, cb, memo, context) {
  2829. if (!(obj && cb)) {
  2830. return;
  2831. }
  2832. if (obj.reduce && obj.reduce === nativeReduce) {
  2833. return obj.reduce(cb, memo, context);
  2834. }
  2835. else {
  2836. for (var i = 0, len = obj.length; i < len; i++) {
  2837. memo = cb.call(context, memo, obj[i], i, obj);
  2838. }
  2839. return memo;
  2840. }
  2841. }
  2842. /**
  2843. * 数组过滤
  2844. * @memberOf module:zrender/core/util
  2845. * @param {Array} obj
  2846. * @param {Function} cb
  2847. * @param {*} [context]
  2848. * @return {Array}
  2849. */
  2850. function filter(obj, cb, context) {
  2851. if (!(obj && cb)) {
  2852. return;
  2853. }
  2854. if (obj.filter && obj.filter === nativeFilter) {
  2855. return obj.filter(cb, context);
  2856. }
  2857. else {
  2858. var result = [];
  2859. for (var i = 0, len = obj.length; i < len; i++) {
  2860. if (cb.call(context, obj[i], i, obj)) {
  2861. result.push(obj[i]);
  2862. }
  2863. }
  2864. return result;
  2865. }
  2866. }
  2867. /**
  2868. * 数组项查找
  2869. * @memberOf module:zrender/core/util
  2870. * @param {Array} obj
  2871. * @param {Function} cb
  2872. * @param {*} [context]
  2873. * @return {Array}
  2874. */
  2875. function find(obj, cb, context) {
  2876. if (!(obj && cb)) {
  2877. return;
  2878. }
  2879. for (var i = 0, len = obj.length; i < len; i++) {
  2880. if (cb.call(context, obj[i], i, obj)) {
  2881. return obj[i];
  2882. }
  2883. }
  2884. }
  2885. /**
  2886. * @memberOf module:zrender/core/util
  2887. * @param {Function} func
  2888. * @param {*} context
  2889. * @return {Function}
  2890. */
  2891. function bind(func, context) {
  2892. var args = nativeSlice.call(arguments, 2);
  2893. return function () {
  2894. return func.apply(context, args.concat(nativeSlice.call(arguments)));
  2895. };
  2896. }
  2897. /**
  2898. * @memberOf module:zrender/core/util
  2899. * @param {Function} func
  2900. * @return {Function}
  2901. */
  2902. function curry(func) {
  2903. var args = nativeSlice.call(arguments, 1);
  2904. return function () {
  2905. return func.apply(this, args.concat(nativeSlice.call(arguments)));
  2906. };
  2907. }
  2908. /**
  2909. * @memberOf module:zrender/core/util
  2910. * @param {*} value
  2911. * @return {boolean}
  2912. */
  2913. function isArray(value) {
  2914. return objToString.call(value) === '[object Array]';
  2915. }
  2916. /**
  2917. * @memberOf module:zrender/core/util
  2918. * @param {*} value
  2919. * @return {boolean}
  2920. */
  2921. function isFunction(value) {
  2922. return typeof value === 'function';
  2923. }
  2924. /**
  2925. * @memberOf module:zrender/core/util
  2926. * @param {*} value
  2927. * @return {boolean}
  2928. */
  2929. function isString(value) {
  2930. return objToString.call(value) === '[object String]';
  2931. }
  2932. /**
  2933. * @memberOf module:zrender/core/util
  2934. * @param {*} value
  2935. * @return {boolean}
  2936. */
  2937. function isObject(value) {
  2938. // Avoid a V8 JIT bug in Chrome 19-20.
  2939. // See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
  2940. var type = typeof value;
  2941. return type === 'function' || (!!value && type == 'object');
  2942. }
  2943. /**
  2944. * @memberOf module:zrender/core/util
  2945. * @param {*} value
  2946. * @return {boolean}
  2947. */
  2948. function isBuiltInObject(value) {
  2949. return !!BUILTIN_OBJECT[objToString.call(value)];
  2950. }
  2951. /**
  2952. * @memberOf module:zrender/core/util
  2953. * @param {*} value
  2954. * @return {boolean}
  2955. */
  2956. function isDom(value) {
  2957. return typeof value === 'object'
  2958. && typeof value.nodeType === 'number'
  2959. && typeof value.ownerDocument === 'object';
  2960. }
  2961. /**
  2962. * Whether is exactly NaN. Notice isNaN('a') returns true.
  2963. * @param {*} value
  2964. * @return {boolean}
  2965. */
  2966. function eqNaN(value) {
  2967. return value !== value;
  2968. }
  2969. /**
  2970. * If value1 is not null, then return value1, otherwise judget rest of values.
  2971. * @memberOf module:zrender/core/util
  2972. * @return {*} Final value
  2973. */
  2974. function retrieve(values) {
  2975. for (var i = 0, len = arguments.length; i < len; i++) {
  2976. if (arguments[i] != null) {
  2977. return arguments[i];
  2978. }
  2979. }
  2980. }
  2981. /**
  2982. * @memberOf module:zrender/core/util
  2983. * @param {Array} arr
  2984. * @param {number} startIndex
  2985. * @param {number} endIndex
  2986. * @return {Array}
  2987. */
  2988. function slice() {
  2989. return Function.call.apply(nativeSlice, arguments);
  2990. }
  2991. /**
  2992. * @memberOf module:zrender/core/util
  2993. * @param {boolean} condition
  2994. * @param {string} message
  2995. */
  2996. function assert(condition, message) {
  2997. if (!condition) {
  2998. throw new Error(message);
  2999. }
  3000. }
  3001. var primitiveKey = '__ec_primitive__';
  3002. /**
  3003. * Set an object as primitive to be ignored traversing children in clone or merge
  3004. */
  3005. function setAsPrimitive(obj) {
  3006. obj[primitiveKey] = true;
  3007. }
  3008. function isPrimitive(obj) {
  3009. return obj[primitiveKey];
  3010. }
  3011. /**
  3012. * @constructor
  3013. * @param {Object} obj Only apply `ownProperty`.
  3014. */
  3015. function HashMap(obj) {
  3016. obj && each(obj, function (value, key) {
  3017. this.set(key, value);
  3018. }, this);
  3019. }
  3020. // Add prefix to avoid conflict with Object.prototype.
  3021. var HASH_MAP_PREFIX = '_ec_';
  3022. var HASH_MAP_PREFIX_LENGTH = 4;
  3023. HashMap.prototype = {
  3024. constructor: HashMap,
  3025. // Do not provide `has` method to avoid defining what is `has`.
  3026. // (We usually treat `null` and `undefined` as the same, different
  3027. // from ES6 Map).
  3028. get: function (key) {
  3029. return this[HASH_MAP_PREFIX + key];
  3030. },
  3031. set: function (key, value) {
  3032. this[HASH_MAP_PREFIX + key] = value;
  3033. // Comparing with invocation chaining, `return value` is more commonly
  3034. // used in this case: `var someVal = map.set('a', genVal());`
  3035. return value;
  3036. },
  3037. // Although util.each can be performed on this hashMap directly, user
  3038. // should not use the exposed keys, who are prefixed.
  3039. each: function (cb, context) {
  3040. context !== void 0 && (cb = bind(cb, context));
  3041. for (var prefixedKey in this) {
  3042. this.hasOwnProperty(prefixedKey)
  3043. && cb(this[prefixedKey], prefixedKey.slice(HASH_MAP_PREFIX_LENGTH));
  3044. }
  3045. },
  3046. // Do not use this method if performance sensitive.
  3047. removeKey: function (key) {
  3048. delete this[key];
  3049. }
  3050. };
  3051. function createHashMap(obj) {
  3052. return new HashMap(obj);
  3053. }
  3054. var util = {
  3055. inherits: inherits,
  3056. mixin: mixin,
  3057. clone: clone,
  3058. merge: merge,
  3059. mergeAll: mergeAll,
  3060. extend: extend,
  3061. defaults: defaults,
  3062. getContext: getContext,
  3063. createCanvas: createCanvas,
  3064. indexOf: indexOf,
  3065. slice: slice,
  3066. find: find,
  3067. isArrayLike: isArrayLike,
  3068. each: each,
  3069. map: map,
  3070. reduce: reduce,
  3071. filter: filter,
  3072. bind: bind,
  3073. curry: curry,
  3074. isArray: isArray,
  3075. isString: isString,
  3076. isObject: isObject,
  3077. isFunction: isFunction,
  3078. isBuiltInObject: isBuiltInObject,
  3079. isDom: isDom,
  3080. eqNaN: eqNaN,
  3081. retrieve: retrieve,
  3082. assert: assert,
  3083. setAsPrimitive: setAsPrimitive,
  3084. createHashMap: createHashMap,
  3085. noop: function () {}
  3086. };
  3087. module.exports = util;
  3088. /***/ },
  3089. /* 5 */
  3090. /***/ function(module, exports, __webpack_require__) {
  3091. var formatUtil = __webpack_require__(6);
  3092. var nubmerUtil = __webpack_require__(7);
  3093. var Model = __webpack_require__(12);
  3094. var zrUtil = __webpack_require__(4);
  3095. var each = zrUtil.each;
  3096. var isObject = zrUtil.isObject;
  3097. var modelUtil = {};
  3098. /**
  3099. * If value is not array, then translate it to array.
  3100. * @param {*} value
  3101. * @return {Array} [value] or value
  3102. */
  3103. modelUtil.normalizeToArray = function (value) {
  3104. return value instanceof Array
  3105. ? value
  3106. : value == null
  3107. ? []
  3108. : [value];
  3109. };
  3110. /**
  3111. * Sync default option between normal and emphasis like `position` and `show`
  3112. * In case some one will write code like
  3113. * label: {
  3114. * normal: {
  3115. * show: false,
  3116. * position: 'outside',
  3117. * textStyle: {
  3118. * fontSize: 18
  3119. * }
  3120. * },
  3121. * emphasis: {
  3122. * show: true
  3123. * }
  3124. * }
  3125. * @param {Object} opt
  3126. * @param {Array.<string>} subOpts
  3127. */
  3128. modelUtil.defaultEmphasis = function (opt, subOpts) {
  3129. if (opt) {
  3130. var emphasisOpt = opt.emphasis = opt.emphasis || {};
  3131. var normalOpt = opt.normal = opt.normal || {};
  3132. // Default emphasis option from normal
  3133. each(subOpts, function (subOptName) {
  3134. var val = zrUtil.retrieve(emphasisOpt[subOptName], normalOpt[subOptName]);
  3135. if (val != null) {
  3136. emphasisOpt[subOptName] = val;
  3137. }
  3138. });
  3139. }
  3140. };
  3141. modelUtil.LABEL_OPTIONS = ['position', 'offset', 'show', 'textStyle', 'distance', 'formatter'];
  3142. /**
  3143. * data could be [12, 2323, {value: 223}, [1221, 23], {value: [2, 23]}]
  3144. * This helper method retieves value from data.
  3145. * @param {string|number|Date|Array|Object} dataItem
  3146. * @return {number|string|Date|Array.<number|string|Date>}
  3147. */
  3148. modelUtil.getDataItemValue = function (dataItem) {
  3149. // Performance sensitive.
  3150. return dataItem && (dataItem.value == null ? dataItem : dataItem.value);
  3151. };
  3152. /**
  3153. * data could be [12, 2323, {value: 223}, [1221, 23], {value: [2, 23]}]
  3154. * This helper method determine if dataItem has extra option besides value
  3155. * @param {string|number|Date|Array|Object} dataItem
  3156. */
  3157. modelUtil.isDataItemOption = function (dataItem) {
  3158. return isObject(dataItem)
  3159. && !(dataItem instanceof Array);
  3160. // // markLine data can be array
  3161. // && !(dataItem[0] && isObject(dataItem[0]) && !(dataItem[0] instanceof Array));
  3162. };
  3163. /**
  3164. * This helper method convert value in data.
  3165. * @param {string|number|Date} value
  3166. * @param {Object|string} [dimInfo] If string (like 'x'), dimType defaults 'number'.
  3167. */
  3168. modelUtil.converDataValue = function (value, dimInfo) {
  3169. // Performance sensitive.
  3170. var dimType = dimInfo && dimInfo.type;
  3171. if (dimType === 'ordinal') {
  3172. return value;
  3173. }
  3174. if (dimType === 'time'
  3175. // spead up when using timestamp
  3176. && typeof value !== 'number'
  3177. && value != null
  3178. && value !== '-'
  3179. ) {
  3180. value = +nubmerUtil.parseDate(value);
  3181. }
  3182. // dimType defaults 'number'.
  3183. // If dimType is not ordinal and value is null or undefined or NaN or '-',
  3184. // parse to NaN.
  3185. return (value == null || value === '')
  3186. ? NaN : +value; // If string (like '-'), using '+' parse to NaN
  3187. };
  3188. /**
  3189. * Create a model proxy to be used in tooltip for edge data, markLine data, markPoint data.
  3190. * @param {module:echarts/data/List} data
  3191. * @param {Object} opt
  3192. * @param {string} [opt.seriesIndex]
  3193. * @param {Object} [opt.name]
  3194. * @param {Object} [opt.mainType]
  3195. * @param {Object} [opt.subType]
  3196. */
  3197. modelUtil.createDataFormatModel = function (data, opt) {
  3198. var model = new Model();
  3199. zrUtil.mixin(model, modelUtil.dataFormatMixin);
  3200. model.seriesIndex = opt.seriesIndex;
  3201. model.name = opt.name || '';
  3202. model.mainType = opt.mainType;
  3203. model.subType = opt.subType;
  3204. model.getData = function () {
  3205. return data;
  3206. };
  3207. return model;
  3208. };
  3209. // PENDING A little ugly
  3210. modelUtil.dataFormatMixin = {
  3211. /**
  3212. * Get params for formatter
  3213. * @param {number} dataIndex
  3214. * @param {string} [dataType]
  3215. * @return {Object}
  3216. */
  3217. getDataParams: function (dataIndex, dataType) {
  3218. var data = this.getData(dataType);
  3219. var rawValue = this.getRawValue(dataIndex, dataType);
  3220. var rawDataIndex = data.getRawIndex(dataIndex);
  3221. var name = data.getName(dataIndex, true);
  3222. var itemOpt = data.getRawDataItem(dataIndex);
  3223. var color = data.getItemVisual(dataIndex, 'color');
  3224. return {
  3225. componentType: this.mainType,
  3226. componentSubType: this.subType,
  3227. seriesType: this.mainType === 'series' ? this.subType : null,
  3228. seriesIndex: this.seriesIndex,
  3229. seriesId: this.id,
  3230. seriesName: this.name,
  3231. name: name,
  3232. dataIndex: rawDataIndex,
  3233. data: itemOpt,
  3234. dataType: dataType,
  3235. value: rawValue,
  3236. color: color,
  3237. marker: formatUtil.getTooltipMarker(color),
  3238. // Param name list for mapping `a`, `b`, `c`, `d`, `e`
  3239. $vars: ['seriesName', 'name', 'value']
  3240. };
  3241. },
  3242. /**
  3243. * Format label
  3244. * @param {number} dataIndex
  3245. * @param {string} [status='normal'] 'normal' or 'emphasis'
  3246. * @param {string} [dataType]
  3247. * @param {number} [dimIndex]
  3248. * @return {string}
  3249. */
  3250. getFormattedLabel: function (dataIndex, status, dataType, dimIndex) {
  3251. status = status || 'normal';
  3252. var data = this.getData(dataType);
  3253. var itemModel = data.getItemModel(dataIndex);
  3254. var params = this.getDataParams(dataIndex, dataType);
  3255. if (dimIndex != null && (params.value instanceof Array)) {
  3256. params.value = params.value[dimIndex];
  3257. }
  3258. var formatter = itemModel.get(['label', status, 'formatter']);
  3259. if (typeof formatter === 'function') {
  3260. params.status = status;
  3261. return formatter(params);
  3262. }
  3263. else if (typeof formatter === 'string') {
  3264. return formatUtil.formatTpl(formatter, params);
  3265. }
  3266. },
  3267. /**
  3268. * Get raw value in option
  3269. * @param {number} idx
  3270. * @param {string} [dataType]
  3271. * @return {Object}
  3272. */
  3273. getRawValue: function (idx, dataType) {
  3274. var data = this.getData(dataType);
  3275. var dataItem = data.getRawDataItem(idx);
  3276. if (dataItem != null) {
  3277. return (isObject(dataItem) && !(dataItem instanceof Array))
  3278. ? dataItem.value : dataItem;
  3279. }
  3280. },
  3281. /**
  3282. * Should be implemented.
  3283. * @param {number} dataIndex
  3284. * @param {boolean} [multipleSeries=false]
  3285. * @param {number} [dataType]
  3286. * @return {string} tooltip string
  3287. */
  3288. formatTooltip: zrUtil.noop
  3289. };
  3290. /**
  3291. * Mapping to exists for merge.
  3292. *
  3293. * @public
  3294. * @param {Array.<Object>|Array.<module:echarts/model/Component>} exists
  3295. * @param {Object|Array.<Object>} newCptOptions
  3296. * @return {Array.<Object>} Result, like [{exist: ..., option: ...}, {}],
  3297. * index of which is the same as exists.
  3298. */
  3299. modelUtil.mappingToExists = function (exists, newCptOptions) {
  3300. // Mapping by the order by original option (but not order of
  3301. // new option) in merge mode. Because we should ensure
  3302. // some specified index (like xAxisIndex) is consistent with
  3303. // original option, which is easy to understand, espatially in
  3304. // media query. And in most case, merge option is used to
  3305. // update partial option but not be expected to change order.
  3306. newCptOptions = (newCptOptions || []).slice();
  3307. var result = zrUtil.map(exists || [], function (obj, index) {
  3308. return {exist: obj};
  3309. });
  3310. // Mapping by id or name if specified.
  3311. each(newCptOptions, function (cptOption, index) {
  3312. if (!isObject(cptOption)) {
  3313. return;
  3314. }
  3315. // id has highest priority.
  3316. for (var i = 0; i < result.length; i++) {
  3317. if (!result[i].option // Consider name: two map to one.
  3318. && cptOption.id != null
  3319. && result[i].exist.id === cptOption.id + ''
  3320. ) {
  3321. result[i].option = cptOption;
  3322. newCptOptions[index] = null;
  3323. return;
  3324. }
  3325. }
  3326. for (var i = 0; i < result.length; i++) {
  3327. var exist = result[i].exist;
  3328. if (!result[i].option // Consider name: two map to one.
  3329. // Can not match when both ids exist but different.
  3330. && (exist.id == null || cptOption.id == null)
  3331. && cptOption.name != null
  3332. && !modelUtil.isIdInner(cptOption)
  3333. && !modelUtil.isIdInner(exist)
  3334. && exist.name === cptOption.name + ''
  3335. ) {
  3336. result[i].option = cptOption;
  3337. newCptOptions[index] = null;
  3338. return;
  3339. }
  3340. }
  3341. });
  3342. // Otherwise mapping by index.
  3343. each(newCptOptions, function (cptOption, index) {
  3344. if (!isObject(cptOption)) {
  3345. return;
  3346. }
  3347. var i = 0;
  3348. for (; i < result.length; i++) {
  3349. var exist = result[i].exist;
  3350. if (!result[i].option
  3351. // Existing model that already has id should be able to
  3352. // mapped to (because after mapping performed model may
  3353. // be assigned with a id, whish should not affect next
  3354. // mapping), except those has inner id.
  3355. && !modelUtil.isIdInner(exist)
  3356. // Caution:
  3357. // Do not overwrite id. But name can be overwritten,
  3358. // because axis use name as 'show label text'.
  3359. // 'exist' always has id and name and we dont
  3360. // need to check it.
  3361. && cptOption.id == null
  3362. ) {
  3363. result[i].option = cptOption;
  3364. break;
  3365. }
  3366. }
  3367. if (i >= result.length) {
  3368. result.push({option: cptOption});
  3369. }
  3370. });
  3371. return result;
  3372. };
  3373. /**
  3374. * Make id and name for mapping result (result of mappingToExists)
  3375. * into `keyInfo` field.
  3376. *
  3377. * @public
  3378. * @param {Array.<Object>} Result, like [{exist: ..., option: ...}, {}],
  3379. * which order is the same as exists.
  3380. * @return {Array.<Object>} The input.
  3381. */
  3382. modelUtil.makeIdAndName = function (mapResult) {
  3383. // We use this id to hash component models and view instances
  3384. // in echarts. id can be specified by user, or auto generated.
  3385. // The id generation rule ensures new view instance are able
  3386. // to mapped to old instance when setOption are called in
  3387. // no-merge mode. So we generate model id by name and plus
  3388. // type in view id.
  3389. // name can be duplicated among components, which is convenient
  3390. // to specify multi components (like series) by one name.
  3391. // Ensure that each id is distinct.
  3392. var idMap = zrUtil.createHashMap();
  3393. each(mapResult, function (item, index) {
  3394. var existCpt = item.exist;
  3395. existCpt && idMap.set(existCpt.id, item);
  3396. });
  3397. each(mapResult, function (item, index) {
  3398. var opt = item.option;
  3399. zrUtil.assert(
  3400. !opt || opt.id == null || !idMap.get(opt.id) || idMap.get(opt.id) === item,
  3401. 'id duplicates: ' + (opt && opt.id)
  3402. );
  3403. opt && opt.id != null && idMap.set(opt.id, item);
  3404. !item.keyInfo && (item.keyInfo = {});
  3405. });
  3406. // Make name and id.
  3407. each(mapResult, function (item, index) {
  3408. var existCpt = item.exist;
  3409. var opt = item.option;
  3410. var keyInfo = item.keyInfo;
  3411. if (!isObject(opt)) {
  3412. return;
  3413. }
  3414. // name can be overwitten. Consider case: axis.name = '20km'.
  3415. // But id generated by name will not be changed, which affect
  3416. // only in that case: setOption with 'not merge mode' and view
  3417. // instance will be recreated, which can be accepted.
  3418. keyInfo.name = opt.name != null
  3419. ? opt.name + ''
  3420. : existCpt
  3421. ? existCpt.name
  3422. : '\0-'; // name may be displayed on screen, so use '-'.
  3423. if (existCpt) {
  3424. keyInfo.id = existCpt.id;
  3425. }
  3426. else if (opt.id != null) {
  3427. keyInfo.id = opt.id + '';
  3428. }
  3429. else {
  3430. // Consider this situatoin:
  3431. // optionA: [{name: 'a'}, {name: 'a'}, {..}]
  3432. // optionB [{..}, {name: 'a'}, {name: 'a'}]
  3433. // Series with the same name between optionA and optionB
  3434. // should be mapped.
  3435. var idNum = 0;
  3436. do {
  3437. keyInfo.id = '\0' + keyInfo.name + '\0' + idNum++;
  3438. }
  3439. while (idMap.get(keyInfo.id));
  3440. }
  3441. idMap.set(keyInfo.id, item);
  3442. });
  3443. };
  3444. /**
  3445. * @public
  3446. * @param {Object} cptOption
  3447. * @return {boolean}
  3448. */
  3449. modelUtil.isIdInner = function (cptOption) {
  3450. return isObject(cptOption)
  3451. && cptOption.id
  3452. && (cptOption.id + '').indexOf('\0_ec_\0') === 0;
  3453. };
  3454. /**
  3455. * A helper for removing duplicate items between batchA and batchB,
  3456. * and in themselves, and categorize by series.
  3457. *
  3458. * @param {Array.<Object>} batchA Like: [{seriesId: 2, dataIndex: [32, 4, 5]}, ...]
  3459. * @param {Array.<Object>} batchB Like: [{seriesId: 2, dataIndex: [32, 4, 5]}, ...]
  3460. * @return {Array.<Array.<Object>, Array.<Object>>} result: [resultBatchA, resultBatchB]
  3461. */
  3462. modelUtil.compressBatches = function (batchA, batchB) {
  3463. var mapA = {};
  3464. var mapB = {};
  3465. makeMap(batchA || [], mapA);
  3466. makeMap(batchB || [], mapB, mapA);
  3467. return [mapToArray(mapA), mapToArray(mapB)];
  3468. function makeMap(sourceBatch, map, otherMap) {
  3469. for (var i = 0, len = sourceBatch.length; i < len; i++) {
  3470. var seriesId = sourceBatch[i].seriesId;
  3471. var dataIndices = modelUtil.normalizeToArray(sourceBatch[i].dataIndex);
  3472. var otherDataIndices = otherMap && otherMap[seriesId];
  3473. for (var j = 0, lenj = dataIndices.length; j < lenj; j++) {
  3474. var dataIndex = dataIndices[j];
  3475. if (otherDataIndices && otherDataIndices[dataIndex]) {
  3476. otherDataIndices[dataIndex] = null;
  3477. }
  3478. else {
  3479. (map[seriesId] || (map[seriesId] = {}))[dataIndex] = 1;
  3480. }
  3481. }
  3482. }
  3483. }
  3484. function mapToArray(map, isData) {
  3485. var result = [];
  3486. for (var i in map) {
  3487. if (map.hasOwnProperty(i) && map[i] != null) {
  3488. if (isData) {
  3489. result.push(+i);
  3490. }
  3491. else {
  3492. var dataIndices = mapToArray(map[i], true);
  3493. dataIndices.length && result.push({seriesId: i, dataIndex: dataIndices});
  3494. }
  3495. }
  3496. }
  3497. return result;
  3498. }
  3499. };
  3500. /**
  3501. * @param {module:echarts/data/List} data
  3502. * @param {Object} payload Contains dataIndex (means rawIndex) / dataIndexInside / name
  3503. * each of which can be Array or primary type.
  3504. * @return {number|Array.<number>} dataIndex If not found, return undefined/null.
  3505. */
  3506. modelUtil.queryDataIndex = function (data, payload) {
  3507. if (payload.dataIndexInside != null) {
  3508. return payload.dataIndexInside;
  3509. }
  3510. else if (payload.dataIndex != null) {
  3511. return zrUtil.isArray(payload.dataIndex)
  3512. ? zrUtil.map(payload.dataIndex, function (value) {
  3513. return data.indexOfRawIndex(value);
  3514. })
  3515. : data.indexOfRawIndex(payload.dataIndex);
  3516. }
  3517. else if (payload.name != null) {
  3518. return zrUtil.isArray(payload.name)
  3519. ? zrUtil.map(payload.name, function (value) {
  3520. return data.indexOfName(value);
  3521. })
  3522. : data.indexOfName(payload.name);
  3523. }
  3524. };
  3525. /**
  3526. * Enable property storage to any host object.
  3527. * Notice: Serialization is not supported.
  3528. *
  3529. * For example:
  3530. * var get = modelUitl.makeGetter();
  3531. *
  3532. * function some(hostObj) {
  3533. * get(hostObj)._someProperty = 1212;
  3534. * ...
  3535. * }
  3536. *
  3537. * @return {Function}
  3538. */
  3539. modelUtil.makeGetter = (function () {
  3540. var index = 0;
  3541. return function () {
  3542. var key = '\0__ec_prop_getter_' + index++;
  3543. return function (hostObj) {
  3544. return hostObj[key] || (hostObj[key] = {});
  3545. };
  3546. };
  3547. })();
  3548. /**
  3549. * @param {module:echarts/model/Global} ecModel
  3550. * @param {string|Object} finder
  3551. * If string, e.g., 'geo', means {geoIndex: 0}.
  3552. * If Object, could contain some of these properties below:
  3553. * {
  3554. * seriesIndex, seriesId, seriesName,
  3555. * geoIndex, geoId, geoName,
  3556. * bmapIndex, bmapId, bmapName,
  3557. * xAxisIndex, xAxisId, xAxisName,
  3558. * yAxisIndex, yAxisId, yAxisName,
  3559. * gridIndex, gridId, gridName,
  3560. * ... (can be extended)
  3561. * }
  3562. * Each properties can be number|string|Array.<number>|Array.<string>
  3563. * For example, a finder could be
  3564. * {
  3565. * seriesIndex: 3,
  3566. * geoId: ['aa', 'cc'],
  3567. * gridName: ['xx', 'rr']
  3568. * }
  3569. * xxxIndex can be set as 'all' (means all xxx) or 'none' (means not specify)
  3570. * If nothing or null/undefined specified, return nothing.
  3571. * @param {Object} [opt]
  3572. * @param {string} [opt.defaultMainType]
  3573. * @param {Array.<string>} [opt.includeMainTypes]
  3574. * @return {Object} result like:
  3575. * {
  3576. * seriesModels: [seriesModel1, seriesModel2],
  3577. * seriesModel: seriesModel1, // The first model
  3578. * geoModels: [geoModel1, geoModel2],
  3579. * geoModel: geoModel1, // The first model
  3580. * ...
  3581. * }
  3582. */
  3583. modelUtil.parseFinder = function (ecModel, finder, opt) {
  3584. if (zrUtil.isString(finder)) {
  3585. var obj = {};
  3586. obj[finder + 'Index'] = 0;
  3587. finder = obj;
  3588. }
  3589. var defaultMainType = opt && opt.defaultMainType;
  3590. if (defaultMainType
  3591. && !has(finder, defaultMainType + 'Index')
  3592. && !has(finder, defaultMainType + 'Id')
  3593. && !has(finder, defaultMainType + 'Name')
  3594. ) {
  3595. finder[defaultMainType + 'Index'] = 0;
  3596. }
  3597. var result = {};
  3598. each(finder, function (value, key) {
  3599. var value = finder[key];
  3600. // Exclude 'dataIndex' and other illgal keys.
  3601. if (key === 'dataIndex' || key === 'dataIndexInside') {
  3602. result[key] = value;
  3603. return;
  3604. }
  3605. var parsedKey = key.match(/^(\w+)(Index|Id|Name)$/) || [];
  3606. var mainType = parsedKey[1];
  3607. var queryType = (parsedKey[2] || '').toLowerCase();
  3608. if (!mainType
  3609. || !queryType
  3610. || value == null
  3611. || (queryType === 'index' && value === 'none')
  3612. || (opt && opt.includeMainTypes && zrUtil.indexOf(opt.includeMainTypes, mainType) < 0)
  3613. ) {
  3614. return;
  3615. }
  3616. var queryParam = {mainType: mainType};
  3617. if (queryType !== 'index' || value !== 'all') {
  3618. queryParam[queryType] = value;
  3619. }
  3620. var models = ecModel.queryComponents(queryParam);
  3621. result[mainType + 'Models'] = models;
  3622. result[mainType + 'Model'] = models[0];
  3623. });
  3624. return result;
  3625. };
  3626. /**
  3627. * @see {module:echarts/data/helper/completeDimensions}
  3628. * @param {module:echarts/data/List} data
  3629. * @param {string|number} dataDim
  3630. * @return {string}
  3631. */
  3632. modelUtil.dataDimToCoordDim = function (data, dataDim) {
  3633. var dimensions = data.dimensions;
  3634. dataDim = data.getDimension(dataDim);
  3635. for (var i = 0; i < dimensions.length; i++) {
  3636. var dimItem = data.getDimensionInfo(dimensions[i]);
  3637. if (dimItem.name === dataDim) {
  3638. return dimItem.coordDim;
  3639. }
  3640. }
  3641. };
  3642. /**
  3643. * @see {module:echarts/data/helper/completeDimensions}
  3644. * @param {module:echarts/data/List} data
  3645. * @param {string} coordDim
  3646. * @return {Array.<string>} data dimensions on the coordDim.
  3647. */
  3648. modelUtil.coordDimToDataDim = function (data, coordDim) {
  3649. var dataDim = [];
  3650. each(data.dimensions, function (dimName) {
  3651. var dimItem = data.getDimensionInfo(dimName);
  3652. if (dimItem.coordDim === coordDim) {
  3653. dataDim[dimItem.coordDimIndex] = dimItem.name;
  3654. }
  3655. });
  3656. return dataDim;
  3657. };
  3658. /**
  3659. * @see {module:echarts/data/helper/completeDimensions}
  3660. * @param {module:echarts/data/List} data
  3661. * @param {string} otherDim Can be `otherDims`
  3662. * like 'label' or 'tooltip'.
  3663. * @return {Array.<string>} data dimensions on the otherDim.
  3664. */
  3665. modelUtil.otherDimToDataDim = function (data, otherDim) {
  3666. var dataDim = [];
  3667. each(data.dimensions, function (dimName) {
  3668. var dimItem = data.getDimensionInfo(dimName);
  3669. var otherDims = dimItem.otherDims;
  3670. var dimIndex = otherDims[otherDim];
  3671. if (dimIndex != null && dimIndex !== false) {
  3672. dataDim[dimIndex] = dimItem.name;
  3673. }
  3674. });
  3675. return dataDim;
  3676. };
  3677. function has(obj, prop) {
  3678. return obj && obj.hasOwnProperty(prop);
  3679. }
  3680. module.exports = modelUtil;
  3681. /***/ },
  3682. /* 6 */
  3683. /***/ function(module, exports, __webpack_require__) {
  3684. var zrUtil = __webpack_require__(4);
  3685. var numberUtil = __webpack_require__(7);
  3686. var textContain = __webpack_require__(8);
  3687. var formatUtil = {};
  3688. /**
  3689. * 每三位默认加,格式化
  3690. * @param {string|number} x
  3691. * @return {string}
  3692. */
  3693. formatUtil.addCommas = function (x) {
  3694. if (isNaN(x)) {
  3695. return '-';
  3696. }
  3697. x = (x + '').split('.');
  3698. return x[0].replace(/(\d{1,3})(?=(?:\d{3})+(?!\d))/g,'$1,')
  3699. + (x.length > 1 ? ('.' + x[1]) : '');
  3700. };
  3701. /**
  3702. * @param {string} str
  3703. * @param {boolean} [upperCaseFirst=false]
  3704. * @return {string} str
  3705. */
  3706. formatUtil.toCamelCase = function (str, upperCaseFirst) {
  3707. str = (str || '').toLowerCase().replace(/-(.)/g, function(match, group1) {
  3708. return group1.toUpperCase();
  3709. });
  3710. if (upperCaseFirst && str) {
  3711. str = str.charAt(0).toUpperCase() + str.slice(1);
  3712. }
  3713. return str;
  3714. };
  3715. /**
  3716. * Normalize css liked array configuration
  3717. * e.g.
  3718. * 3 => [3, 3, 3, 3]
  3719. * [4, 2] => [4, 2, 4, 2]
  3720. * [4, 3, 2] => [4, 3, 2, 3]
  3721. * @param {number|Array.<number>} val
  3722. */
  3723. formatUtil.normalizeCssArray = function (val) {
  3724. var len = val.length;
  3725. if (typeof (val) === 'number') {
  3726. return [val, val, val, val];
  3727. }
  3728. else if (len === 2) {
  3729. // vertical | horizontal
  3730. return [val[0], val[1], val[0], val[1]];
  3731. }
  3732. else if (len === 3) {
  3733. // top | horizontal | bottom
  3734. return [val[0], val[1], val[2], val[1]];
  3735. }
  3736. return val;
  3737. };
  3738. var encodeHTML = formatUtil.encodeHTML = function (source) {
  3739. return String(source)
  3740. .replace(/&/g, '&amp;')
  3741. .replace(/</g, '&lt;')
  3742. .replace(/>/g, '&gt;')
  3743. .replace(/"/g, '&quot;')
  3744. .replace(/'/g, '&#39;');
  3745. };
  3746. var TPL_VAR_ALIAS = ['a', 'b', 'c', 'd', 'e', 'f', 'g'];
  3747. var wrapVar = function (varName, seriesIdx) {
  3748. return '{' + varName + (seriesIdx == null ? '' : seriesIdx) + '}';
  3749. };
  3750. /**
  3751. * Template formatter
  3752. * @param {string} tpl
  3753. * @param {Array.<Object>|Object} paramsList
  3754. * @param {boolean} [encode=false]
  3755. * @return {string}
  3756. */
  3757. formatUtil.formatTpl = function (tpl, paramsList, encode) {
  3758. if (!zrUtil.isArray(paramsList)) {
  3759. paramsList = [paramsList];
  3760. }
  3761. var seriesLen = paramsList.length;
  3762. if (!seriesLen) {
  3763. return '';
  3764. }
  3765. var $vars = paramsList[0].$vars || [];
  3766. for (var i = 0; i < $vars.length; i++) {
  3767. var alias = TPL_VAR_ALIAS[i];
  3768. var val = wrapVar(alias, 0);
  3769. tpl = tpl.replace(wrapVar(alias), encode ? encodeHTML(val) : val);
  3770. }
  3771. for (var seriesIdx = 0; seriesIdx < seriesLen; seriesIdx++) {
  3772. for (var k = 0; k < $vars.length; k++) {
  3773. var val = paramsList[seriesIdx][$vars[k]];
  3774. tpl = tpl.replace(
  3775. wrapVar(TPL_VAR_ALIAS[k], seriesIdx),
  3776. encode ? encodeHTML(val) : val
  3777. );
  3778. }
  3779. }
  3780. return tpl;
  3781. };
  3782. /**
  3783. * simple Template formatter
  3784. *
  3785. * @param {string} tpl
  3786. * @param {Object} param
  3787. * @param {boolean} [encode=false]
  3788. * @return {string}
  3789. */
  3790. formatUtil.formatTplSimple = function (tpl, param, encode) {
  3791. zrUtil.each(param, function (value, key) {
  3792. tpl = tpl.replace(
  3793. '{' + key + '}',
  3794. encode ? encodeHTML(value) : value
  3795. );
  3796. });
  3797. return tpl;
  3798. };
  3799. /**
  3800. * @param {string} color
  3801. * @param {string} [extraCssText]
  3802. * @return {string}
  3803. */
  3804. formatUtil.getTooltipMarker = function (color, extraCssText) {
  3805. return color
  3806. ? '<span style="display:inline-block;margin-right:5px;'
  3807. + 'border-radius:10px;width:9px;height:9px;background-color:'
  3808. + formatUtil.encodeHTML(color) + ';' + (extraCssText || '') + '"></span>'
  3809. : '';
  3810. };
  3811. /**
  3812. * @param {string} str
  3813. * @return {string}
  3814. * @inner
  3815. */
  3816. var s2d = function (str) {
  3817. return str < 10 ? ('0' + str) : str;
  3818. };
  3819. /**
  3820. * ISO Date format
  3821. * @param {string} tpl
  3822. * @param {number} value
  3823. * @param {boolean} [isUTC=false] Default in local time.
  3824. * see `module:echarts/scale/Time`
  3825. * and `module:echarts/util/number#parseDate`.
  3826. * @inner
  3827. */
  3828. formatUtil.formatTime = function (tpl, value, isUTC) {
  3829. if (tpl === 'week'
  3830. || tpl === 'month'
  3831. || tpl === 'quarter'
  3832. || tpl === 'half-year'
  3833. || tpl === 'year'
  3834. ) {
  3835. tpl = 'MM-dd\nyyyy';
  3836. }
  3837. var date = numberUtil.parseDate(value);
  3838. var utc = isUTC ? 'UTC' : '';
  3839. var y = date['get' + utc + 'FullYear']();
  3840. var M = date['get' + utc + 'Month']() + 1;
  3841. var d = date['get' + utc + 'Date']();
  3842. var h = date['get' + utc + 'Hours']();
  3843. var m = date['get' + utc + 'Minutes']();
  3844. var s = date['get' + utc + 'Seconds']();
  3845. tpl = tpl.replace('MM', s2d(M))
  3846. .toLowerCase()
  3847. .replace('yyyy', y)
  3848. .replace('yy', y % 100)
  3849. .replace('dd', s2d(d))
  3850. .replace('d', d)
  3851. .replace('hh', s2d(h))
  3852. .replace('h', h)
  3853. .replace('mm', s2d(m))
  3854. .replace('m', m)
  3855. .replace('ss', s2d(s))
  3856. .replace('s', s);
  3857. return tpl;
  3858. };
  3859. /**
  3860. * Capital first
  3861. * @param {string} str
  3862. * @return {string}
  3863. */
  3864. formatUtil.capitalFirst = function (str) {
  3865. return str ? str.charAt(0).toUpperCase() + str.substr(1) : str;
  3866. };
  3867. formatUtil.truncateText = textContain.truncateText;
  3868. module.exports = formatUtil;
  3869. /***/ },
  3870. /* 7 */
  3871. /***/ function(module, exports) {
  3872. /**
  3873. * 数值处理模块
  3874. * @module echarts/util/number
  3875. */
  3876. var number = {};
  3877. var RADIAN_EPSILON = 1e-4;
  3878. function _trim(str) {
  3879. return str.replace(/^\s+/, '').replace(/\s+$/, '');
  3880. }
  3881. /**
  3882. * Linear mapping a value from domain to range
  3883. * @memberOf module:echarts/util/number
  3884. * @param {(number|Array.<number>)} val
  3885. * @param {Array.<number>} domain Domain extent domain[0] can be bigger than domain[1]
  3886. * @param {Array.<number>} range Range extent range[0] can be bigger than range[1]
  3887. * @param {boolean} clamp
  3888. * @return {(number|Array.<number>}
  3889. */
  3890. number.linearMap = function (val, domain, range, clamp) {
  3891. var subDomain = domain[1] - domain[0];
  3892. var subRange = range[1] - range[0];
  3893. if (subDomain === 0) {
  3894. return subRange === 0
  3895. ? range[0]
  3896. : (range[0] + range[1]) / 2;
  3897. }
  3898. // Avoid accuracy problem in edge, such as
  3899. // 146.39 - 62.83 === 83.55999999999999.
  3900. // See echarts/test/ut/spec/util/number.js#linearMap#accuracyError
  3901. // It is a little verbose for efficiency considering this method
  3902. // is a hotspot.
  3903. if (clamp) {
  3904. if (subDomain > 0) {
  3905. if (val <= domain[0]) {
  3906. return range[0];
  3907. }
  3908. else if (val >= domain[1]) {
  3909. return range[1];
  3910. }
  3911. }
  3912. else {
  3913. if (val >= domain[0]) {
  3914. return range[0];
  3915. }
  3916. else if (val <= domain[1]) {
  3917. return range[1];
  3918. }
  3919. }
  3920. }
  3921. else {
  3922. if (val === domain[0]) {
  3923. return range[0];
  3924. }
  3925. if (val === domain[1]) {
  3926. return range[1];
  3927. }
  3928. }
  3929. return (val - domain[0]) / subDomain * subRange + range[0];
  3930. };
  3931. /**
  3932. * Convert a percent string to absolute number.
  3933. * Returns NaN if percent is not a valid string or number
  3934. * @memberOf module:echarts/util/number
  3935. * @param {string|number} percent
  3936. * @param {number} all
  3937. * @return {number}
  3938. */
  3939. number.parsePercent = function(percent, all) {
  3940. switch (percent) {
  3941. case 'center':
  3942. case 'middle':
  3943. percent = '50%';
  3944. break;
  3945. case 'left':
  3946. case 'top':
  3947. percent = '0%';
  3948. break;
  3949. case 'right':
  3950. case 'bottom':
  3951. percent = '100%';
  3952. break;
  3953. }
  3954. if (typeof percent === 'string') {
  3955. if (_trim(percent).match(/%$/)) {
  3956. return parseFloat(percent) / 100 * all;
  3957. }
  3958. return parseFloat(percent);
  3959. }
  3960. return percent == null ? NaN : +percent;
  3961. };
  3962. /**
  3963. * (1) Fix rounding error of float numbers.
  3964. * (2) Support return string to avoid scientific notation like '3.5e-7'.
  3965. *
  3966. * @param {number} x
  3967. * @param {number} [precision]
  3968. * @param {boolean} [returnStr]
  3969. * @return {number|string}
  3970. */
  3971. number.round = function (x, precision, returnStr) {
  3972. if (precision == null) {
  3973. precision = 10;
  3974. }
  3975. // Avoid range error
  3976. precision = Math.min(Math.max(0, precision), 20);
  3977. x = (+x).toFixed(precision);
  3978. return returnStr ? x : +x;
  3979. };
  3980. number.asc = function (arr) {
  3981. arr.sort(function (a, b) {
  3982. return a - b;
  3983. });
  3984. return arr;
  3985. };
  3986. /**
  3987. * Get precision
  3988. * @param {number} val
  3989. */
  3990. number.getPrecision = function (val) {
  3991. val = +val;
  3992. if (isNaN(val)) {
  3993. return 0;
  3994. }
  3995. // It is much faster than methods converting number to string as follows
  3996. // var tmp = val.toString();
  3997. // return tmp.length - 1 - tmp.indexOf('.');
  3998. // especially when precision is low
  3999. var e = 1;
  4000. var count = 0;
  4001. while (Math.round(val * e) / e !== val) {
  4002. e *= 10;
  4003. count++;
  4004. }
  4005. return count;
  4006. };
  4007. /**
  4008. * @param {string|number} val
  4009. * @return {number}
  4010. */
  4011. number.getPrecisionSafe = function (val) {
  4012. var str = val.toString();
  4013. // Consider scientific notation: '3.4e-12' '3.4e+12'
  4014. var eIndex = str.indexOf('e');
  4015. if (eIndex > 0) {
  4016. var precision = +str.slice(eIndex + 1);
  4017. return precision < 0 ? -precision : 0;
  4018. }
  4019. else {
  4020. var dotIndex = str.indexOf('.');
  4021. return dotIndex < 0 ? 0 : str.length - 1 - dotIndex;
  4022. }
  4023. };
  4024. /**
  4025. * Minimal dicernible data precisioin according to a single pixel.
  4026. *
  4027. * @param {Array.<number>} dataExtent
  4028. * @param {Array.<number>} pixelExtent
  4029. * @return {number} precision
  4030. */
  4031. number.getPixelPrecision = function (dataExtent, pixelExtent) {
  4032. var log = Math.log;
  4033. var LN10 = Math.LN10;
  4034. var dataQuantity = Math.floor(log(dataExtent[1] - dataExtent[0]) / LN10);
  4035. var sizeQuantity = Math.round(log(Math.abs(pixelExtent[1] - pixelExtent[0])) / LN10);
  4036. // toFixed() digits argument must be between 0 and 20.
  4037. var precision = Math.min(Math.max(-dataQuantity + sizeQuantity, 0), 20);
  4038. return !isFinite(precision) ? 20 : precision;
  4039. };
  4040. // Number.MAX_SAFE_INTEGER, ie do not support.
  4041. number.MAX_SAFE_INTEGER = 9007199254740991;
  4042. /**
  4043. * To 0 - 2 * PI, considering negative radian.
  4044. * @param {number} radian
  4045. * @return {number}
  4046. */
  4047. number.remRadian = function (radian) {
  4048. var pi2 = Math.PI * 2;
  4049. return (radian % pi2 + pi2) % pi2;
  4050. };
  4051. /**
  4052. * @param {type} radian
  4053. * @return {boolean}
  4054. */
  4055. number.isRadianAroundZero = function (val) {
  4056. return val > -RADIAN_EPSILON && val < RADIAN_EPSILON;
  4057. };
  4058. 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
  4059. /**
  4060. * @return {number} in minutes
  4061. */
  4062. number.getTimezoneOffset = function () {
  4063. return (new Date()).getTimezoneOffset();
  4064. };
  4065. /**
  4066. * @param {string|Date|number} value These values can be accepted:
  4067. * + An instance of Date, represent a time in its own time zone.
  4068. * + Or string in a subset of ISO 8601, only including:
  4069. * + only year, month, date: '2012-03', '2012-03-01', '2012-03-01 05', '2012-03-01 05:06',
  4070. * + separated with T or space: '2012-03-01T12:22:33.123', '2012-03-01 12:22:33.123',
  4071. * + time zone: '2012-03-01T12:22:33Z', '2012-03-01T12:22:33+8000', '2012-03-01T12:22:33-05:00',
  4072. * all of which will be treated as local time if time zone is not specified
  4073. * (see <https://momentjs.com/>).
  4074. * + Or other string format, including (all of which will be treated as loacal time):
  4075. * '2012', '2012-3-1', '2012/3/1', '2012/03/01',
  4076. * '2009/6/12 2:00', '2009/6/12 2:05:08', '2009/6/12 2:05:08.123'
  4077. * + a timestamp, which represent a time in UTC.
  4078. * @return {Date} date
  4079. */
  4080. number.parseDate = function (value) {
  4081. if (value instanceof Date) {
  4082. return value;
  4083. }
  4084. else if (typeof value === 'string') {
  4085. // Different browsers parse date in different way, so we parse it manually.
  4086. // Some other issues:
  4087. // new Date('1970-01-01') is UTC,
  4088. // new Date('1970/01/01') and new Date('1970-1-01') is local.
  4089. // See issue #3623
  4090. var match = TIME_REG.exec(value);
  4091. if (!match) {
  4092. // return Invalid Date.
  4093. return new Date(NaN);
  4094. }
  4095. var timezoneOffset = number.getTimezoneOffset();
  4096. var timeOffset = !match[8]
  4097. ? 0
  4098. : match[8].toUpperCase() === 'Z'
  4099. ? timezoneOffset
  4100. : +match[8].slice(0, 3) * 60 + timezoneOffset;
  4101. // match[n] can only be string or undefined.
  4102. // But take care of '12' + 1 => '121'.
  4103. return new Date(
  4104. +match[1],
  4105. +(match[2] || 1) - 1,
  4106. +match[3] || 1,
  4107. +match[4] || 0,
  4108. +(match[5] || 0) - timeOffset,
  4109. +match[6] || 0,
  4110. +match[7] || 0
  4111. );
  4112. }
  4113. else if (value == null) {
  4114. return new Date(NaN);
  4115. }
  4116. return new Date(Math.round(value));
  4117. };
  4118. /**
  4119. * Quantity of a number. e.g. 0.1, 1, 10, 100
  4120. *
  4121. * @param {number} val
  4122. * @return {number}
  4123. */
  4124. number.quantity = function (val) {
  4125. return Math.pow(10, quantityExponent(val));
  4126. };
  4127. function quantityExponent(val) {
  4128. return Math.floor(Math.log(val) / Math.LN10);
  4129. }
  4130. /**
  4131. * find a “nice” number approximately equal to x. Round the number if round = true,
  4132. * take ceiling if round = false. The primary observation is that the “nicest”
  4133. * numbers in decimal are 1, 2, and 5, and all power-of-ten multiples of these numbers.
  4134. *
  4135. * See "Nice Numbers for Graph Labels" of Graphic Gems.
  4136. *
  4137. * @param {number} val Non-negative value.
  4138. * @param {boolean} round
  4139. * @return {number}
  4140. */
  4141. number.nice = function (val, round) {
  4142. var exponent = quantityExponent(val);
  4143. var exp10 = Math.pow(10, exponent);
  4144. var f = val / exp10; // 1 <= f < 10
  4145. var nf;
  4146. if (round) {
  4147. if (f < 1.5) { nf = 1; }
  4148. else if (f < 2.5) { nf = 2; }
  4149. else if (f < 4) { nf = 3; }
  4150. else if (f < 7) { nf = 5; }
  4151. else { nf = 10; }
  4152. }
  4153. else {
  4154. if (f < 1) { nf = 1; }
  4155. else if (f < 2) { nf = 2; }
  4156. else if (f < 3) { nf = 3; }
  4157. else if (f < 5) { nf = 5; }
  4158. else { nf = 10; }
  4159. }
  4160. val = nf * exp10;
  4161. // Fix 3 * 0.1 === 0.30000000000000004 issue (see IEEE 754).
  4162. // 20 is the uppper bound of toFixed.
  4163. return exponent >= -20 ? +val.toFixed(exponent < 0 ? -exponent : 0) : val;
  4164. };
  4165. /**
  4166. * Order intervals asc, and split them when overlap.
  4167. * expect(numberUtil.reformIntervals([
  4168. * {interval: [18, 62], close: [1, 1]},
  4169. * {interval: [-Infinity, -70], close: [0, 0]},
  4170. * {interval: [-70, -26], close: [1, 1]},
  4171. * {interval: [-26, 18], close: [1, 1]},
  4172. * {interval: [62, 150], close: [1, 1]},
  4173. * {interval: [106, 150], close: [1, 1]},
  4174. * {interval: [150, Infinity], close: [0, 0]}
  4175. * ])).toEqual([
  4176. * {interval: [-Infinity, -70], close: [0, 0]},
  4177. * {interval: [-70, -26], close: [1, 1]},
  4178. * {interval: [-26, 18], close: [0, 1]},
  4179. * {interval: [18, 62], close: [0, 1]},
  4180. * {interval: [62, 150], close: [0, 1]},
  4181. * {interval: [150, Infinity], close: [0, 0]}
  4182. * ]);
  4183. * @param {Array.<Object>} list, where `close` mean open or close
  4184. * of the interval, and Infinity can be used.
  4185. * @return {Array.<Object>} The origin list, which has been reformed.
  4186. */
  4187. number.reformIntervals = function (list) {
  4188. list.sort(function (a, b) {
  4189. return littleThan(a, b, 0) ? -1 : 1;
  4190. });
  4191. var curr = -Infinity;
  4192. var currClose = 1;
  4193. for (var i = 0; i < list.length;) {
  4194. var interval = list[i].interval;
  4195. var close = list[i].close;
  4196. for (var lg = 0; lg < 2; lg++) {
  4197. if (interval[lg] <= curr) {
  4198. interval[lg] = curr;
  4199. close[lg] = !lg ? 1 - currClose : 1;
  4200. }
  4201. curr = interval[lg];
  4202. currClose = close[lg];
  4203. }
  4204. if (interval[0] === interval[1] && close[0] * close[1] !== 1) {
  4205. list.splice(i, 1);
  4206. }
  4207. else {
  4208. i++;
  4209. }
  4210. }
  4211. return list;
  4212. function littleThan(a, b, lg) {
  4213. return a.interval[lg] < b.interval[lg]
  4214. || (
  4215. a.interval[lg] === b.interval[lg]
  4216. && (
  4217. (a.close[lg] - b.close[lg] === (!lg ? 1 : -1))
  4218. || (!lg && littleThan(a, b, 1))
  4219. )
  4220. );
  4221. }
  4222. };
  4223. /**
  4224. * parseFloat NaNs numeric-cast false positives (null|true|false|"")
  4225. * ...but misinterprets leading-number strings, particularly hex literals ("0x...")
  4226. * subtraction forces infinities to NaN
  4227. *
  4228. * @param {*} v
  4229. * @return {boolean}
  4230. */
  4231. number.isNumeric = function (v) {
  4232. return v - parseFloat(v) >= 0;
  4233. };
  4234. module.exports = number;
  4235. /***/ },
  4236. /* 8 */
  4237. /***/ function(module, exports, __webpack_require__) {
  4238. var textWidthCache = {};
  4239. var textWidthCacheCounter = 0;
  4240. var TEXT_CACHE_MAX = 5000;
  4241. var util = __webpack_require__(4);
  4242. var BoundingRect = __webpack_require__(9);
  4243. var retrieve = util.retrieve;
  4244. function getTextWidth(text, textFont) {
  4245. var key = text + ':' + textFont;
  4246. if (textWidthCache[key]) {
  4247. return textWidthCache[key];
  4248. }
  4249. var textLines = (text + '').split('\n');
  4250. var width = 0;
  4251. for (var i = 0, l = textLines.length; i < l; i++) {
  4252. // measureText 可以被覆盖以兼容不支持 Canvas 的环境
  4253. width = Math.max(textContain.measureText(textLines[i], textFont).width, width);
  4254. }
  4255. if (textWidthCacheCounter > TEXT_CACHE_MAX) {
  4256. textWidthCacheCounter = 0;
  4257. textWidthCache = {};
  4258. }
  4259. textWidthCacheCounter++;
  4260. textWidthCache[key] = width;
  4261. return width;
  4262. }
  4263. function getTextRect(text, textFont, textAlign, textBaseline) {
  4264. var textLineLen = ((text || '') + '').split('\n').length;
  4265. var width = getTextWidth(text, textFont);
  4266. // FIXME 高度计算比较粗暴
  4267. var lineHeight = getTextWidth('国', textFont);
  4268. var height = textLineLen * lineHeight;
  4269. var rect = new BoundingRect(0, 0, width, height);
  4270. // Text has a special line height property
  4271. rect.lineHeight = lineHeight;
  4272. switch (textBaseline) {
  4273. case 'bottom':
  4274. case 'alphabetic':
  4275. rect.y -= lineHeight;
  4276. break;
  4277. case 'middle':
  4278. rect.y -= lineHeight / 2;
  4279. break;
  4280. // case 'hanging':
  4281. // case 'top':
  4282. }
  4283. // FIXME Right to left language
  4284. switch (textAlign) {
  4285. case 'end':
  4286. case 'right':
  4287. rect.x -= rect.width;
  4288. break;
  4289. case 'center':
  4290. rect.x -= rect.width / 2;
  4291. break;
  4292. // case 'start':
  4293. // case 'left':
  4294. }
  4295. return rect;
  4296. }
  4297. function adjustTextPositionOnRect(textPosition, rect, textRect, distance) {
  4298. var x = rect.x;
  4299. var y = rect.y;
  4300. var height = rect.height;
  4301. var width = rect.width;
  4302. var textHeight = textRect.height;
  4303. var lineHeight = textRect.lineHeight;
  4304. var halfHeight = height / 2 - textHeight / 2 + lineHeight;
  4305. var textAlign = 'left';
  4306. switch (textPosition) {
  4307. case 'left':
  4308. x -= distance;
  4309. y += halfHeight;
  4310. textAlign = 'right';
  4311. break;
  4312. case 'right':
  4313. x += distance + width;
  4314. y += halfHeight;
  4315. textAlign = 'left';
  4316. break;
  4317. case 'top':
  4318. x += width / 2;
  4319. y -= distance + textHeight - lineHeight;
  4320. textAlign = 'center';
  4321. break;
  4322. case 'bottom':
  4323. x += width / 2;
  4324. y += height + distance + lineHeight;
  4325. textAlign = 'center';
  4326. break;
  4327. case 'inside':
  4328. x += width / 2;
  4329. y += halfHeight;
  4330. textAlign = 'center';
  4331. break;
  4332. case 'insideLeft':
  4333. x += distance;
  4334. y += halfHeight;
  4335. textAlign = 'left';
  4336. break;
  4337. case 'insideRight':
  4338. x += width - distance;
  4339. y += halfHeight;
  4340. textAlign = 'right';
  4341. break;
  4342. case 'insideTop':
  4343. x += width / 2;
  4344. y += distance + lineHeight;
  4345. textAlign = 'center';
  4346. break;
  4347. case 'insideBottom':
  4348. x += width / 2;
  4349. y += height - textHeight - distance + lineHeight;
  4350. textAlign = 'center';
  4351. break;
  4352. case 'insideTopLeft':
  4353. x += distance;
  4354. y += distance + lineHeight;
  4355. textAlign = 'left';
  4356. break;
  4357. case 'insideTopRight':
  4358. x += width - distance;
  4359. y += distance + lineHeight;
  4360. textAlign = 'right';
  4361. break;
  4362. case 'insideBottomLeft':
  4363. x += distance;
  4364. y += height - textHeight - distance + lineHeight;
  4365. break;
  4366. case 'insideBottomRight':
  4367. x += width - distance;
  4368. y += height - textHeight - distance + lineHeight;
  4369. textAlign = 'right';
  4370. break;
  4371. }
  4372. return {
  4373. x: x,
  4374. y: y,
  4375. textAlign: textAlign,
  4376. textBaseline: 'alphabetic'
  4377. };
  4378. }
  4379. /**
  4380. * Show ellipsis if overflow.
  4381. *
  4382. * @param {string} text
  4383. * @param {string} containerWidth
  4384. * @param {string} textFont
  4385. * @param {number} [ellipsis='...']
  4386. * @param {Object} [options]
  4387. * @param {number} [options.maxIterations=3]
  4388. * @param {number} [options.minChar=0] If truncate result are less
  4389. * then minChar, ellipsis will not show, which is
  4390. * better for user hint in some cases.
  4391. * @param {number} [options.placeholder=''] When all truncated, use the placeholder.
  4392. * @return {string}
  4393. */
  4394. function truncateText(text, containerWidth, textFont, ellipsis, options) {
  4395. if (!containerWidth) {
  4396. return '';
  4397. }
  4398. options = options || {};
  4399. ellipsis = retrieve(ellipsis, '...');
  4400. var maxIterations = retrieve(options.maxIterations, 2);
  4401. var minChar = retrieve(options.minChar, 0);
  4402. // FIXME
  4403. // Other languages?
  4404. var cnCharWidth = getTextWidth('国', textFont);
  4405. // FIXME
  4406. // Consider proportional font?
  4407. var ascCharWidth = getTextWidth('a', textFont);
  4408. var placeholder = retrieve(options.placeholder, '');
  4409. // Example 1: minChar: 3, text: 'asdfzxcv', truncate result: 'asdf', but not: 'a...'.
  4410. // Example 2: minChar: 3, text: '维度', truncate result: '维', but not: '...'.
  4411. var contentWidth = containerWidth = Math.max(0, containerWidth - 1); // Reserve some gap.
  4412. for (var i = 0; i < minChar && contentWidth >= ascCharWidth; i++) {
  4413. contentWidth -= ascCharWidth;
  4414. }
  4415. var ellipsisWidth = getTextWidth(ellipsis);
  4416. if (ellipsisWidth > contentWidth) {
  4417. ellipsis = '';
  4418. ellipsisWidth = 0;
  4419. }
  4420. contentWidth = containerWidth - ellipsisWidth;
  4421. var textLines = (text + '').split('\n');
  4422. for (var i = 0, len = textLines.length; i < len; i++) {
  4423. var textLine = textLines[i];
  4424. var lineWidth = getTextWidth(textLine, textFont);
  4425. if (lineWidth <= containerWidth) {
  4426. continue;
  4427. }
  4428. for (var j = 0;; j++) {
  4429. if (lineWidth <= contentWidth || j >= maxIterations) {
  4430. textLine += ellipsis;
  4431. break;
  4432. }
  4433. var subLength = j === 0
  4434. ? estimateLength(textLine, contentWidth, ascCharWidth, cnCharWidth)
  4435. : lineWidth > 0
  4436. ? Math.floor(textLine.length * contentWidth / lineWidth)
  4437. : 0;
  4438. textLine = textLine.substr(0, subLength);
  4439. lineWidth = getTextWidth(textLine, textFont);
  4440. }
  4441. if (textLine === '') {
  4442. textLine = placeholder;
  4443. }
  4444. textLines[i] = textLine;
  4445. }
  4446. return textLines.join('\n');
  4447. }
  4448. function estimateLength(text, contentWidth, ascCharWidth, cnCharWidth) {
  4449. var width = 0;
  4450. var i = 0;
  4451. for (var len = text.length; i < len && width < contentWidth; i++) {
  4452. var charCode = text.charCodeAt(i);
  4453. width += (0 <= charCode && charCode <= 127) ? ascCharWidth : cnCharWidth;
  4454. }
  4455. return i;
  4456. }
  4457. var textContain = {
  4458. getWidth: getTextWidth,
  4459. getBoundingRect: getTextRect,
  4460. adjustTextPositionOnRect: adjustTextPositionOnRect,
  4461. truncateText: truncateText,
  4462. measureText: function (text, textFont) {
  4463. var ctx = util.getContext();
  4464. ctx.font = textFont || '12px sans-serif';
  4465. return ctx.measureText(text);
  4466. }
  4467. };
  4468. module.exports = textContain;
  4469. /***/ },
  4470. /* 9 */
  4471. /***/ function(module, exports, __webpack_require__) {
  4472. 'use strict';
  4473. /**
  4474. * @module echarts/core/BoundingRect
  4475. */
  4476. var vec2 = __webpack_require__(10);
  4477. var matrix = __webpack_require__(11);
  4478. var v2ApplyTransform = vec2.applyTransform;
  4479. var mathMin = Math.min;
  4480. var mathMax = Math.max;
  4481. /**
  4482. * @alias module:echarts/core/BoundingRect
  4483. */
  4484. function BoundingRect(x, y, width, height) {
  4485. if (width < 0) {
  4486. x = x + width;
  4487. width = -width;
  4488. }
  4489. if (height < 0) {
  4490. y = y + height;
  4491. height = -height;
  4492. }
  4493. /**
  4494. * @type {number}
  4495. */
  4496. this.x = x;
  4497. /**
  4498. * @type {number}
  4499. */
  4500. this.y = y;
  4501. /**
  4502. * @type {number}
  4503. */
  4504. this.width = width;
  4505. /**
  4506. * @type {number}
  4507. */
  4508. this.height = height;
  4509. }
  4510. BoundingRect.prototype = {
  4511. constructor: BoundingRect,
  4512. /**
  4513. * @param {module:echarts/core/BoundingRect} other
  4514. */
  4515. union: function (other) {
  4516. var x = mathMin(other.x, this.x);
  4517. var y = mathMin(other.y, this.y);
  4518. this.width = mathMax(
  4519. other.x + other.width,
  4520. this.x + this.width
  4521. ) - x;
  4522. this.height = mathMax(
  4523. other.y + other.height,
  4524. this.y + this.height
  4525. ) - y;
  4526. this.x = x;
  4527. this.y = y;
  4528. },
  4529. /**
  4530. * @param {Array.<number>} m
  4531. * @methods
  4532. */
  4533. applyTransform: (function () {
  4534. var lt = [];
  4535. var rb = [];
  4536. var lb = [];
  4537. var rt = [];
  4538. return function (m) {
  4539. // In case usage like this
  4540. // el.getBoundingRect().applyTransform(el.transform)
  4541. // And element has no transform
  4542. if (!m) {
  4543. return;
  4544. }
  4545. lt[0] = lb[0] = this.x;
  4546. lt[1] = rt[1] = this.y;
  4547. rb[0] = rt[0] = this.x + this.width;
  4548. rb[1] = lb[1] = this.y + this.height;
  4549. v2ApplyTransform(lt, lt, m);
  4550. v2ApplyTransform(rb, rb, m);
  4551. v2ApplyTransform(lb, lb, m);
  4552. v2ApplyTransform(rt, rt, m);
  4553. this.x = mathMin(lt[0], rb[0], lb[0], rt[0]);
  4554. this.y = mathMin(lt[1], rb[1], lb[1], rt[1]);
  4555. var maxX = mathMax(lt[0], rb[0], lb[0], rt[0]);
  4556. var maxY = mathMax(lt[1], rb[1], lb[1], rt[1]);
  4557. this.width = maxX - this.x;
  4558. this.height = maxY - this.y;
  4559. };
  4560. })(),
  4561. /**
  4562. * Calculate matrix of transforming from self to target rect
  4563. * @param {module:zrender/core/BoundingRect} b
  4564. * @return {Array.<number>}
  4565. */
  4566. calculateTransform: function (b) {
  4567. var a = this;
  4568. var sx = b.width / a.width;
  4569. var sy = b.height / a.height;
  4570. var m = matrix.create();
  4571. // 矩阵右乘
  4572. matrix.translate(m, m, [-a.x, -a.y]);
  4573. matrix.scale(m, m, [sx, sy]);
  4574. matrix.translate(m, m, [b.x, b.y]);
  4575. return m;
  4576. },
  4577. /**
  4578. * @param {(module:echarts/core/BoundingRect|Object)} b
  4579. * @return {boolean}
  4580. */
  4581. intersect: function (b) {
  4582. if (!b) {
  4583. return false;
  4584. }
  4585. if (!(b instanceof BoundingRect)) {
  4586. // Normalize negative width/height.
  4587. b = BoundingRect.create(b);
  4588. }
  4589. var a = this;
  4590. var ax0 = a.x;
  4591. var ax1 = a.x + a.width;
  4592. var ay0 = a.y;
  4593. var ay1 = a.y + a.height;
  4594. var bx0 = b.x;
  4595. var bx1 = b.x + b.width;
  4596. var by0 = b.y;
  4597. var by1 = b.y + b.height;
  4598. return ! (ax1 < bx0 || bx1 < ax0 || ay1 < by0 || by1 < ay0);
  4599. },
  4600. contain: function (x, y) {
  4601. var rect = this;
  4602. return x >= rect.x
  4603. && x <= (rect.x + rect.width)
  4604. && y >= rect.y
  4605. && y <= (rect.y + rect.height);
  4606. },
  4607. /**
  4608. * @return {module:echarts/core/BoundingRect}
  4609. */
  4610. clone: function () {
  4611. return new BoundingRect(this.x, this.y, this.width, this.height);
  4612. },
  4613. /**
  4614. * Copy from another rect
  4615. */
  4616. copy: function (other) {
  4617. this.x = other.x;
  4618. this.y = other.y;
  4619. this.width = other.width;
  4620. this.height = other.height;
  4621. },
  4622. plain: function () {
  4623. return {
  4624. x: this.x,
  4625. y: this.y,
  4626. width: this.width,
  4627. height: this.height
  4628. };
  4629. }
  4630. };
  4631. /**
  4632. * @param {Object|module:zrender/core/BoundingRect} rect
  4633. * @param {number} rect.x
  4634. * @param {number} rect.y
  4635. * @param {number} rect.width
  4636. * @param {number} rect.height
  4637. * @return {module:zrender/core/BoundingRect}
  4638. */
  4639. BoundingRect.create = function (rect) {
  4640. return new BoundingRect(rect.x, rect.y, rect.width, rect.height);
  4641. };
  4642. module.exports = BoundingRect;
  4643. /***/ },
  4644. /* 10 */
  4645. /***/ function(module, exports) {
  4646. var ArrayCtor = typeof Float32Array === 'undefined'
  4647. ? Array
  4648. : Float32Array;
  4649. /**
  4650. * @typedef {Float32Array|Array.<number>} Vector2
  4651. */
  4652. /**
  4653. * 二维向量类
  4654. * @exports zrender/tool/vector
  4655. */
  4656. var vector = {
  4657. /**
  4658. * 创建一个向量
  4659. * @param {number} [x=0]
  4660. * @param {number} [y=0]
  4661. * @return {Vector2}
  4662. */
  4663. create: function (x, y) {
  4664. var out = new ArrayCtor(2);
  4665. if (x == null) {
  4666. x = 0;
  4667. }
  4668. if (y == null) {
  4669. y = 0;
  4670. }
  4671. out[0] = x;
  4672. out[1] = y;
  4673. return out;
  4674. },
  4675. /**
  4676. * 复制向量数据
  4677. * @param {Vector2} out
  4678. * @param {Vector2} v
  4679. * @return {Vector2}
  4680. */
  4681. copy: function (out, v) {
  4682. out[0] = v[0];
  4683. out[1] = v[1];
  4684. return out;
  4685. },
  4686. /**
  4687. * 克隆一个向量
  4688. * @param {Vector2} v
  4689. * @return {Vector2}
  4690. */
  4691. clone: function (v) {
  4692. var out = new ArrayCtor(2);
  4693. out[0] = v[0];
  4694. out[1] = v[1];
  4695. return out;
  4696. },
  4697. /**
  4698. * 设置向量的两个项
  4699. * @param {Vector2} out
  4700. * @param {number} a
  4701. * @param {number} b
  4702. * @return {Vector2} 结果
  4703. */
  4704. set: function (out, a, b) {
  4705. out[0] = a;
  4706. out[1] = b;
  4707. return out;
  4708. },
  4709. /**
  4710. * 向量相加
  4711. * @param {Vector2} out
  4712. * @param {Vector2} v1
  4713. * @param {Vector2} v2
  4714. */
  4715. add: function (out, v1, v2) {
  4716. out[0] = v1[0] + v2[0];
  4717. out[1] = v1[1] + v2[1];
  4718. return out;
  4719. },
  4720. /**
  4721. * 向量缩放后相加
  4722. * @param {Vector2} out
  4723. * @param {Vector2} v1
  4724. * @param {Vector2} v2
  4725. * @param {number} a
  4726. */
  4727. scaleAndAdd: function (out, v1, v2, a) {
  4728. out[0] = v1[0] + v2[0] * a;
  4729. out[1] = v1[1] + v2[1] * a;
  4730. return out;
  4731. },
  4732. /**
  4733. * 向量相减
  4734. * @param {Vector2} out
  4735. * @param {Vector2} v1
  4736. * @param {Vector2} v2
  4737. */
  4738. sub: function (out, v1, v2) {
  4739. out[0] = v1[0] - v2[0];
  4740. out[1] = v1[1] - v2[1];
  4741. return out;
  4742. },
  4743. /**
  4744. * 向量长度
  4745. * @param {Vector2} v
  4746. * @return {number}
  4747. */
  4748. len: function (v) {
  4749. return Math.sqrt(this.lenSquare(v));
  4750. },
  4751. /**
  4752. * 向量长度平方
  4753. * @param {Vector2} v
  4754. * @return {number}
  4755. */
  4756. lenSquare: function (v) {
  4757. return v[0] * v[0] + v[1] * v[1];
  4758. },
  4759. /**
  4760. * 向量乘法
  4761. * @param {Vector2} out
  4762. * @param {Vector2} v1
  4763. * @param {Vector2} v2
  4764. */
  4765. mul: function (out, v1, v2) {
  4766. out[0] = v1[0] * v2[0];
  4767. out[1] = v1[1] * v2[1];
  4768. return out;
  4769. },
  4770. /**
  4771. * 向量除法
  4772. * @param {Vector2} out
  4773. * @param {Vector2} v1
  4774. * @param {Vector2} v2
  4775. */
  4776. div: function (out, v1, v2) {
  4777. out[0] = v1[0] / v2[0];
  4778. out[1] = v1[1] / v2[1];
  4779. return out;
  4780. },
  4781. /**
  4782. * 向量点乘
  4783. * @param {Vector2} v1
  4784. * @param {Vector2} v2
  4785. * @return {number}
  4786. */
  4787. dot: function (v1, v2) {
  4788. return v1[0] * v2[0] + v1[1] * v2[1];
  4789. },
  4790. /**
  4791. * 向量缩放
  4792. * @param {Vector2} out
  4793. * @param {Vector2} v
  4794. * @param {number} s
  4795. */
  4796. scale: function (out, v, s) {
  4797. out[0] = v[0] * s;
  4798. out[1] = v[1] * s;
  4799. return out;
  4800. },
  4801. /**
  4802. * 向量归一化
  4803. * @param {Vector2} out
  4804. * @param {Vector2} v
  4805. */
  4806. normalize: function (out, v) {
  4807. var d = vector.len(v);
  4808. if (d === 0) {
  4809. out[0] = 0;
  4810. out[1] = 0;
  4811. }
  4812. else {
  4813. out[0] = v[0] / d;
  4814. out[1] = v[1] / d;
  4815. }
  4816. return out;
  4817. },
  4818. /**
  4819. * 计算向量间距离
  4820. * @param {Vector2} v1
  4821. * @param {Vector2} v2
  4822. * @return {number}
  4823. */
  4824. distance: function (v1, v2) {
  4825. return Math.sqrt(
  4826. (v1[0] - v2[0]) * (v1[0] - v2[0])
  4827. + (v1[1] - v2[1]) * (v1[1] - v2[1])
  4828. );
  4829. },
  4830. /**
  4831. * 向量距离平方
  4832. * @param {Vector2} v1
  4833. * @param {Vector2} v2
  4834. * @return {number}
  4835. */
  4836. distanceSquare: function (v1, v2) {
  4837. return (v1[0] - v2[0]) * (v1[0] - v2[0])
  4838. + (v1[1] - v2[1]) * (v1[1] - v2[1]);
  4839. },
  4840. /**
  4841. * 求负向量
  4842. * @param {Vector2} out
  4843. * @param {Vector2} v
  4844. */
  4845. negate: function (out, v) {
  4846. out[0] = -v[0];
  4847. out[1] = -v[1];
  4848. return out;
  4849. },
  4850. /**
  4851. * 插值两个点
  4852. * @param {Vector2} out
  4853. * @param {Vector2} v1
  4854. * @param {Vector2} v2
  4855. * @param {number} t
  4856. */
  4857. lerp: function (out, v1, v2, t) {
  4858. out[0] = v1[0] + t * (v2[0] - v1[0]);
  4859. out[1] = v1[1] + t * (v2[1] - v1[1]);
  4860. return out;
  4861. },
  4862. /**
  4863. * 矩阵左乘向量
  4864. * @param {Vector2} out
  4865. * @param {Vector2} v
  4866. * @param {Vector2} m
  4867. */
  4868. applyTransform: function (out, v, m) {
  4869. var x = v[0];
  4870. var y = v[1];
  4871. out[0] = m[0] * x + m[2] * y + m[4];
  4872. out[1] = m[1] * x + m[3] * y + m[5];
  4873. return out;
  4874. },
  4875. /**
  4876. * 求两个向量最小值
  4877. * @param {Vector2} out
  4878. * @param {Vector2} v1
  4879. * @param {Vector2} v2
  4880. */
  4881. min: function (out, v1, v2) {
  4882. out[0] = Math.min(v1[0], v2[0]);
  4883. out[1] = Math.min(v1[1], v2[1]);
  4884. return out;
  4885. },
  4886. /**
  4887. * 求两个向量最大值
  4888. * @param {Vector2} out
  4889. * @param {Vector2} v1
  4890. * @param {Vector2} v2
  4891. */
  4892. max: function (out, v1, v2) {
  4893. out[0] = Math.max(v1[0], v2[0]);
  4894. out[1] = Math.max(v1[1], v2[1]);
  4895. return out;
  4896. }
  4897. };
  4898. vector.length = vector.len;
  4899. vector.lengthSquare = vector.lenSquare;
  4900. vector.dist = vector.distance;
  4901. vector.distSquare = vector.distanceSquare;
  4902. module.exports = vector;
  4903. /***/ },
  4904. /* 11 */
  4905. /***/ function(module, exports) {
  4906. var ArrayCtor = typeof Float32Array === 'undefined'
  4907. ? Array
  4908. : Float32Array;
  4909. /**
  4910. * 3x2矩阵操作类
  4911. * @exports zrender/tool/matrix
  4912. */
  4913. var matrix = {
  4914. /**
  4915. * 创建一个单位矩阵
  4916. * @return {Float32Array|Array.<number>}
  4917. */
  4918. create : function() {
  4919. var out = new ArrayCtor(6);
  4920. matrix.identity(out);
  4921. return out;
  4922. },
  4923. /**
  4924. * 设置矩阵为单位矩阵
  4925. * @param {Float32Array|Array.<number>} out
  4926. */
  4927. identity : function(out) {
  4928. out[0] = 1;
  4929. out[1] = 0;
  4930. out[2] = 0;
  4931. out[3] = 1;
  4932. out[4] = 0;
  4933. out[5] = 0;
  4934. return out;
  4935. },
  4936. /**
  4937. * 复制矩阵
  4938. * @param {Float32Array|Array.<number>} out
  4939. * @param {Float32Array|Array.<number>} m
  4940. */
  4941. copy: function(out, m) {
  4942. out[0] = m[0];
  4943. out[1] = m[1];
  4944. out[2] = m[2];
  4945. out[3] = m[3];
  4946. out[4] = m[4];
  4947. out[5] = m[5];
  4948. return out;
  4949. },
  4950. /**
  4951. * 矩阵相乘
  4952. * @param {Float32Array|Array.<number>} out
  4953. * @param {Float32Array|Array.<number>} m1
  4954. * @param {Float32Array|Array.<number>} m2
  4955. */
  4956. mul : function (out, m1, m2) {
  4957. // Consider matrix.mul(m, m2, m);
  4958. // where out is the same as m2.
  4959. // So use temp variable to escape error.
  4960. var out0 = m1[0] * m2[0] + m1[2] * m2[1];
  4961. var out1 = m1[1] * m2[0] + m1[3] * m2[1];
  4962. var out2 = m1[0] * m2[2] + m1[2] * m2[3];
  4963. var out3 = m1[1] * m2[2] + m1[3] * m2[3];
  4964. var out4 = m1[0] * m2[4] + m1[2] * m2[5] + m1[4];
  4965. var out5 = m1[1] * m2[4] + m1[3] * m2[5] + m1[5];
  4966. out[0] = out0;
  4967. out[1] = out1;
  4968. out[2] = out2;
  4969. out[3] = out3;
  4970. out[4] = out4;
  4971. out[5] = out5;
  4972. return out;
  4973. },
  4974. /**
  4975. * 平移变换
  4976. * @param {Float32Array|Array.<number>} out
  4977. * @param {Float32Array|Array.<number>} a
  4978. * @param {Float32Array|Array.<number>} v
  4979. */
  4980. translate : function(out, a, v) {
  4981. out[0] = a[0];
  4982. out[1] = a[1];
  4983. out[2] = a[2];
  4984. out[3] = a[3];
  4985. out[4] = a[4] + v[0];
  4986. out[5] = a[5] + v[1];
  4987. return out;
  4988. },
  4989. /**
  4990. * 旋转变换
  4991. * @param {Float32Array|Array.<number>} out
  4992. * @param {Float32Array|Array.<number>} a
  4993. * @param {number} rad
  4994. */
  4995. rotate : function(out, a, rad) {
  4996. var aa = a[0];
  4997. var ac = a[2];
  4998. var atx = a[4];
  4999. var ab = a[1];
  5000. var ad = a[3];
  5001. var aty = a[5];
  5002. var st = Math.sin(rad);
  5003. var ct = Math.cos(rad);
  5004. out[0] = aa * ct + ab * st;
  5005. out[1] = -aa * st + ab * ct;
  5006. out[2] = ac * ct + ad * st;
  5007. out[3] = -ac * st + ct * ad;
  5008. out[4] = ct * atx + st * aty;
  5009. out[5] = ct * aty - st * atx;
  5010. return out;
  5011. },
  5012. /**
  5013. * 缩放变换
  5014. * @param {Float32Array|Array.<number>} out
  5015. * @param {Float32Array|Array.<number>} a
  5016. * @param {Float32Array|Array.<number>} v
  5017. */
  5018. scale : function(out, a, v) {
  5019. var vx = v[0];
  5020. var vy = v[1];
  5021. out[0] = a[0] * vx;
  5022. out[1] = a[1] * vy;
  5023. out[2] = a[2] * vx;
  5024. out[3] = a[3] * vy;
  5025. out[4] = a[4] * vx;
  5026. out[5] = a[5] * vy;
  5027. return out;
  5028. },
  5029. /**
  5030. * 求逆矩阵
  5031. * @param {Float32Array|Array.<number>} out
  5032. * @param {Float32Array|Array.<number>} a
  5033. */
  5034. invert : function(out, a) {
  5035. var aa = a[0];
  5036. var ac = a[2];
  5037. var atx = a[4];
  5038. var ab = a[1];
  5039. var ad = a[3];
  5040. var aty = a[5];
  5041. var det = aa * ad - ab * ac;
  5042. if (!det) {
  5043. return null;
  5044. }
  5045. det = 1.0 / det;
  5046. out[0] = ad * det;
  5047. out[1] = -ab * det;
  5048. out[2] = -ac * det;
  5049. out[3] = aa * det;
  5050. out[4] = (ac * aty - ad * atx) * det;
  5051. out[5] = (ab * atx - aa * aty) * det;
  5052. return out;
  5053. }
  5054. };
  5055. module.exports = matrix;
  5056. /***/ },
  5057. /* 12 */
  5058. /***/ function(module, exports, __webpack_require__) {
  5059. /**
  5060. * @module echarts/model/Model
  5061. */
  5062. var zrUtil = __webpack_require__(4);
  5063. var clazzUtil = __webpack_require__(13);
  5064. var env = __webpack_require__(2);
  5065. /**
  5066. * @alias module:echarts/model/Model
  5067. * @constructor
  5068. * @param {Object} option
  5069. * @param {module:echarts/model/Model} [parentModel]
  5070. * @param {module:echarts/model/Global} [ecModel]
  5071. */
  5072. function Model(option, parentModel, ecModel) {
  5073. /**
  5074. * @type {module:echarts/model/Model}
  5075. * @readOnly
  5076. */
  5077. this.parentModel = parentModel;
  5078. /**
  5079. * @type {module:echarts/model/Global}
  5080. * @readOnly
  5081. */
  5082. this.ecModel = ecModel;
  5083. /**
  5084. * @type {Object}
  5085. * @protected
  5086. */
  5087. this.option = option;
  5088. // Simple optimization
  5089. // if (this.init) {
  5090. // if (arguments.length <= 4) {
  5091. // this.init(option, parentModel, ecModel, extraOpt);
  5092. // }
  5093. // else {
  5094. // this.init.apply(this, arguments);
  5095. // }
  5096. // }
  5097. }
  5098. Model.prototype = {
  5099. constructor: Model,
  5100. /**
  5101. * Model 的初始化函数
  5102. * @param {Object} option
  5103. */
  5104. init: null,
  5105. /**
  5106. * 从新的 Option merge
  5107. */
  5108. mergeOption: function (option) {
  5109. zrUtil.merge(this.option, option, true);
  5110. },
  5111. /**
  5112. * @param {string|Array.<string>} path
  5113. * @param {boolean} [ignoreParent=false]
  5114. * @return {*}
  5115. */
  5116. get: function (path, ignoreParent) {
  5117. if (path == null) {
  5118. return this.option;
  5119. }
  5120. return doGet(
  5121. this.option,
  5122. this.parsePath(path),
  5123. !ignoreParent && getParent(this, path)
  5124. );
  5125. },
  5126. /**
  5127. * @param {string} key
  5128. * @param {boolean} [ignoreParent=false]
  5129. * @return {*}
  5130. */
  5131. getShallow: function (key, ignoreParent) {
  5132. var option = this.option;
  5133. var val = option == null ? option : option[key];
  5134. var parentModel = !ignoreParent && getParent(this, key);
  5135. if (val == null && parentModel) {
  5136. val = parentModel.getShallow(key);
  5137. }
  5138. return val;
  5139. },
  5140. /**
  5141. * @param {string|Array.<string>} path
  5142. * @param {module:echarts/model/Model} [parentModel]
  5143. * @return {module:echarts/model/Model}
  5144. */
  5145. getModel: function (path, parentModel) {
  5146. var obj = path == null
  5147. ? this.option
  5148. : doGet(this.option, path = this.parsePath(path));
  5149. var thisParentModel;
  5150. parentModel = parentModel || (
  5151. (thisParentModel = getParent(this, path))
  5152. && thisParentModel.getModel(path)
  5153. );
  5154. return new Model(obj, parentModel, this.ecModel);
  5155. },
  5156. /**
  5157. * If model has option
  5158. */
  5159. isEmpty: function () {
  5160. return this.option == null;
  5161. },
  5162. restoreData: function () {},
  5163. // Pending
  5164. clone: function () {
  5165. var Ctor = this.constructor;
  5166. return new Ctor(zrUtil.clone(this.option));
  5167. },
  5168. setReadOnly: function (properties) {
  5169. clazzUtil.setReadOnly(this, properties);
  5170. },
  5171. // If path is null/undefined, return null/undefined.
  5172. parsePath: function(path) {
  5173. if (typeof path === 'string') {
  5174. path = path.split('.');
  5175. }
  5176. return path;
  5177. },
  5178. /**
  5179. * @param {Function} getParentMethod
  5180. * param {Array.<string>|string} path
  5181. * return {module:echarts/model/Model}
  5182. */
  5183. customizeGetParent: function (getParentMethod) {
  5184. clazzUtil.set(this, 'getParent', getParentMethod);
  5185. },
  5186. isAnimationEnabled: function () {
  5187. if (!env.node) {
  5188. if (this.option.animation != null) {
  5189. return !!this.option.animation;
  5190. }
  5191. else if (this.parentModel) {
  5192. return this.parentModel.isAnimationEnabled();
  5193. }
  5194. }
  5195. }
  5196. };
  5197. function doGet(obj, pathArr, parentModel) {
  5198. for (var i = 0; i < pathArr.length; i++) {
  5199. // Ignore empty
  5200. if (!pathArr[i]) {
  5201. continue;
  5202. }
  5203. // obj could be number/string/... (like 0)
  5204. obj = (obj && typeof obj === 'object') ? obj[pathArr[i]] : null;
  5205. if (obj == null) {
  5206. break;
  5207. }
  5208. }
  5209. if (obj == null && parentModel) {
  5210. obj = parentModel.get(pathArr);
  5211. }
  5212. return obj;
  5213. }
  5214. function getParent(model, path) {
  5215. var getParentMethod = clazzUtil.get(model, 'getParent');
  5216. return getParentMethod ? getParentMethod.call(model, path) : model.parentModel;
  5217. }
  5218. // Enable Model.extend.
  5219. clazzUtil.enableClassExtend(Model);
  5220. var mixin = zrUtil.mixin;
  5221. mixin(Model, __webpack_require__(14));
  5222. mixin(Model, __webpack_require__(16));
  5223. mixin(Model, __webpack_require__(17));
  5224. mixin(Model, __webpack_require__(68));
  5225. module.exports = Model;
  5226. /***/ },
  5227. /* 13 */
  5228. /***/ function(module, exports, __webpack_require__) {
  5229. var zrUtil = __webpack_require__(4);
  5230. var clazz = {};
  5231. var TYPE_DELIMITER = '.';
  5232. var IS_CONTAINER = '___EC__COMPONENT__CONTAINER___';
  5233. var MEMBER_PRIFIX = '\0ec_\0';
  5234. /**
  5235. * Hide private class member.
  5236. * The same behavior as `host[name] = value;` (can be right-value)
  5237. * @public
  5238. */
  5239. clazz.set = function (host, name, value) {
  5240. return (host[MEMBER_PRIFIX + name] = value);
  5241. };
  5242. /**
  5243. * Hide private class member.
  5244. * The same behavior as `host[name];`
  5245. * @public
  5246. */
  5247. clazz.get = function (host, name) {
  5248. return host[MEMBER_PRIFIX + name];
  5249. };
  5250. /**
  5251. * For hidden private class member.
  5252. * The same behavior as `host.hasOwnProperty(name);`
  5253. * @public
  5254. */
  5255. clazz.hasOwn = function (host, name) {
  5256. return host.hasOwnProperty(MEMBER_PRIFIX + name);
  5257. };
  5258. /**
  5259. * Notice, parseClassType('') should returns {main: '', sub: ''}
  5260. * @public
  5261. */
  5262. var parseClassType = clazz.parseClassType = function (componentType) {
  5263. var ret = {main: '', sub: ''};
  5264. if (componentType) {
  5265. componentType = componentType.split(TYPE_DELIMITER);
  5266. ret.main = componentType[0] || '';
  5267. ret.sub = componentType[1] || '';
  5268. }
  5269. return ret;
  5270. };
  5271. /**
  5272. * @public
  5273. */
  5274. function checkClassType(componentType) {
  5275. zrUtil.assert(
  5276. /^[a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)?$/.test(componentType),
  5277. 'componentType "' + componentType + '" illegal'
  5278. );
  5279. }
  5280. /**
  5281. * @public
  5282. */
  5283. clazz.enableClassExtend = function (RootClass, mandatoryMethods) {
  5284. RootClass.$constructor = RootClass;
  5285. RootClass.extend = function (proto) {
  5286. if (true) {
  5287. zrUtil.each(mandatoryMethods, function (method) {
  5288. if (!proto[method]) {
  5289. console.warn(
  5290. 'Method `' + method + '` should be implemented'
  5291. + (proto.type ? ' in ' + proto.type : '') + '.'
  5292. );
  5293. }
  5294. });
  5295. }
  5296. var superClass = this;
  5297. var ExtendedClass = function () {
  5298. if (!proto.$constructor) {
  5299. superClass.apply(this, arguments);
  5300. }
  5301. else {
  5302. proto.$constructor.apply(this, arguments);
  5303. }
  5304. };
  5305. zrUtil.extend(ExtendedClass.prototype, proto);
  5306. ExtendedClass.extend = this.extend;
  5307. ExtendedClass.superCall = superCall;
  5308. ExtendedClass.superApply = superApply;
  5309. zrUtil.inherits(ExtendedClass, this);
  5310. ExtendedClass.superClass = superClass;
  5311. return ExtendedClass;
  5312. };
  5313. };
  5314. // superCall should have class info, which can not be fetch from 'this'.
  5315. // Consider this case:
  5316. // class A has method f,
  5317. // class B inherits class A, overrides method f, f call superApply('f'),
  5318. // class C inherits class B, do not overrides method f,
  5319. // then when method of class C is called, dead loop occured.
  5320. function superCall(context, methodName) {
  5321. var args = zrUtil.slice(arguments, 2);
  5322. return this.superClass.prototype[methodName].apply(context, args);
  5323. }
  5324. function superApply(context, methodName, args) {
  5325. return this.superClass.prototype[methodName].apply(context, args);
  5326. }
  5327. /**
  5328. * @param {Object} entity
  5329. * @param {Object} options
  5330. * @param {boolean} [options.registerWhenExtend]
  5331. * @public
  5332. */
  5333. clazz.enableClassManagement = function (entity, options) {
  5334. options = options || {};
  5335. /**
  5336. * Component model classes
  5337. * key: componentType,
  5338. * value:
  5339. * componentClass, when componentType is 'xxx'
  5340. * or Object.<subKey, componentClass>, when componentType is 'xxx.yy'
  5341. * @type {Object}
  5342. */
  5343. var storage = {};
  5344. entity.registerClass = function (Clazz, componentType) {
  5345. if (componentType) {
  5346. checkClassType(componentType);
  5347. componentType = parseClassType(componentType);
  5348. if (!componentType.sub) {
  5349. if (true) {
  5350. if (storage[componentType.main]) {
  5351. console.warn(componentType.main + ' exists.');
  5352. }
  5353. }
  5354. storage[componentType.main] = Clazz;
  5355. }
  5356. else if (componentType.sub !== IS_CONTAINER) {
  5357. var container = makeContainer(componentType);
  5358. container[componentType.sub] = Clazz;
  5359. }
  5360. }
  5361. return Clazz;
  5362. };
  5363. entity.getClass = function (componentMainType, subType, throwWhenNotFound) {
  5364. var Clazz = storage[componentMainType];
  5365. if (Clazz && Clazz[IS_CONTAINER]) {
  5366. Clazz = subType ? Clazz[subType] : null;
  5367. }
  5368. if (throwWhenNotFound && !Clazz) {
  5369. throw new Error(
  5370. !subType
  5371. ? componentMainType + '.' + 'type should be specified.'
  5372. : 'Component ' + componentMainType + '.' + (subType || '') + ' not exists. Load it first.'
  5373. );
  5374. }
  5375. return Clazz;
  5376. };
  5377. entity.getClassesByMainType = function (componentType) {
  5378. componentType = parseClassType(componentType);
  5379. var result = [];
  5380. var obj = storage[componentType.main];
  5381. if (obj && obj[IS_CONTAINER]) {
  5382. zrUtil.each(obj, function (o, type) {
  5383. type !== IS_CONTAINER && result.push(o);
  5384. });
  5385. }
  5386. else {
  5387. result.push(obj);
  5388. }
  5389. return result;
  5390. };
  5391. entity.hasClass = function (componentType) {
  5392. // Just consider componentType.main.
  5393. componentType = parseClassType(componentType);
  5394. return !!storage[componentType.main];
  5395. };
  5396. /**
  5397. * @return {Array.<string>} Like ['aa', 'bb'], but can not be ['aa.xx']
  5398. */
  5399. entity.getAllClassMainTypes = function () {
  5400. var types = [];
  5401. zrUtil.each(storage, function (obj, type) {
  5402. types.push(type);
  5403. });
  5404. return types;
  5405. };
  5406. /**
  5407. * If a main type is container and has sub types
  5408. * @param {string} mainType
  5409. * @return {boolean}
  5410. */
  5411. entity.hasSubTypes = function (componentType) {
  5412. componentType = parseClassType(componentType);
  5413. var obj = storage[componentType.main];
  5414. return obj && obj[IS_CONTAINER];
  5415. };
  5416. entity.parseClassType = parseClassType;
  5417. function makeContainer(componentType) {
  5418. var container = storage[componentType.main];
  5419. if (!container || !container[IS_CONTAINER]) {
  5420. container = storage[componentType.main] = {};
  5421. container[IS_CONTAINER] = true;
  5422. }
  5423. return container;
  5424. }
  5425. if (options.registerWhenExtend) {
  5426. var originalExtend = entity.extend;
  5427. if (originalExtend) {
  5428. entity.extend = function (proto) {
  5429. var ExtendedClass = originalExtend.call(this, proto);
  5430. return entity.registerClass(ExtendedClass, proto.type);
  5431. };
  5432. }
  5433. }
  5434. return entity;
  5435. };
  5436. /**
  5437. * @param {string|Array.<string>} properties
  5438. */
  5439. clazz.setReadOnly = function (obj, properties) {
  5440. // FIXME It seems broken in IE8 simulation of IE11
  5441. // if (!zrUtil.isArray(properties)) {
  5442. // properties = properties != null ? [properties] : [];
  5443. // }
  5444. // zrUtil.each(properties, function (prop) {
  5445. // var value = obj[prop];
  5446. // Object.defineProperty
  5447. // && Object.defineProperty(obj, prop, {
  5448. // value: value, writable: false
  5449. // });
  5450. // zrUtil.isArray(obj[prop])
  5451. // && Object.freeze
  5452. // && Object.freeze(obj[prop]);
  5453. // });
  5454. };
  5455. module.exports = clazz;
  5456. /***/ },
  5457. /* 14 */
  5458. /***/ function(module, exports, __webpack_require__) {
  5459. var getLineStyle = __webpack_require__(15)(
  5460. [
  5461. ['lineWidth', 'width'],
  5462. ['stroke', 'color'],
  5463. ['opacity'],
  5464. ['shadowBlur'],
  5465. ['shadowOffsetX'],
  5466. ['shadowOffsetY'],
  5467. ['shadowColor']
  5468. ]
  5469. );
  5470. module.exports = {
  5471. getLineStyle: function (excludes) {
  5472. var style = getLineStyle.call(this, excludes);
  5473. var lineDash = this.getLineDash(style.lineWidth);
  5474. lineDash && (style.lineDash = lineDash);
  5475. return style;
  5476. },
  5477. getLineDash: function (lineWidth) {
  5478. if (lineWidth == null) {
  5479. lineWidth = 1;
  5480. }
  5481. var lineType = this.get('type');
  5482. var dotSize = Math.max(lineWidth, 2);
  5483. var dashSize = lineWidth * 4;
  5484. return (lineType === 'solid' || lineType == null) ? null
  5485. : (lineType === 'dashed' ? [dashSize, dashSize] : [dotSize, dotSize]);
  5486. }
  5487. };
  5488. /***/ },
  5489. /* 15 */
  5490. /***/ function(module, exports, __webpack_require__) {
  5491. // TODO Parse shadow style
  5492. // TODO Only shallow path support
  5493. var zrUtil = __webpack_require__(4);
  5494. module.exports = function (properties) {
  5495. // Normalize
  5496. for (var i = 0; i < properties.length; i++) {
  5497. if (!properties[i][1]) {
  5498. properties[i][1] = properties[i][0];
  5499. }
  5500. }
  5501. return function (excludes, includes) {
  5502. var style = {};
  5503. for (var i = 0; i < properties.length; i++) {
  5504. var propName = properties[i][1];
  5505. if ((excludes && zrUtil.indexOf(excludes, propName) >= 0)
  5506. || (includes && zrUtil.indexOf(includes, propName) < 0)
  5507. ) {
  5508. continue;
  5509. }
  5510. var val = this.getShallow(propName);
  5511. if (val != null) {
  5512. style[properties[i][0]] = val;
  5513. }
  5514. }
  5515. return style;
  5516. };
  5517. };
  5518. /***/ },
  5519. /* 16 */
  5520. /***/ function(module, exports, __webpack_require__) {
  5521. module.exports = {
  5522. getAreaStyle: __webpack_require__(15)(
  5523. [
  5524. ['fill', 'color'],
  5525. ['shadowBlur'],
  5526. ['shadowOffsetX'],
  5527. ['shadowOffsetY'],
  5528. ['opacity'],
  5529. ['shadowColor']
  5530. ]
  5531. )
  5532. };
  5533. /***/ },
  5534. /* 17 */
  5535. /***/ function(module, exports, __webpack_require__) {
  5536. var textContain = __webpack_require__(8);
  5537. var graphicUtil = __webpack_require__(18);
  5538. module.exports = {
  5539. /**
  5540. * Get color property or get color from option.textStyle.color
  5541. * @return {string}
  5542. */
  5543. getTextColor: function () {
  5544. var ecModel = this.ecModel;
  5545. return this.getShallow('color')
  5546. || (ecModel && ecModel.get('textStyle.color'));
  5547. },
  5548. /**
  5549. * Create font string from fontStyle, fontWeight, fontSize, fontFamily
  5550. * @return {string}
  5551. */
  5552. getFont: function () {
  5553. return graphicUtil.getFont({
  5554. fontStyle: this.getShallow('fontStyle'),
  5555. fontWeight: this.getShallow('fontWeight'),
  5556. fontSize: this.getShallow('fontSize'),
  5557. fontFamily: this.getShallow('fontFamily')
  5558. }, this.ecModel);
  5559. },
  5560. getTextRect: function (text) {
  5561. return textContain.getBoundingRect(
  5562. text,
  5563. this.getFont(),
  5564. this.getShallow('align'),
  5565. this.getShallow('baseline')
  5566. );
  5567. },
  5568. truncateText: function (text, containerWidth, ellipsis, options) {
  5569. return textContain.truncateText(
  5570. text, containerWidth, this.getFont(), ellipsis, options
  5571. );
  5572. }
  5573. };
  5574. /***/ },
  5575. /* 18 */
  5576. /***/ function(module, exports, __webpack_require__) {
  5577. 'use strict';
  5578. var zrUtil = __webpack_require__(4);
  5579. var pathTool = __webpack_require__(19);
  5580. var Path = __webpack_require__(20);
  5581. var colorTool = __webpack_require__(31);
  5582. var matrix = __webpack_require__(11);
  5583. var vector = __webpack_require__(10);
  5584. var Transformable = __webpack_require__(26);
  5585. var BoundingRect = __webpack_require__(9);
  5586. var round = Math.round;
  5587. var mathMax = Math.max;
  5588. var mathMin = Math.min;
  5589. var graphic = {};
  5590. graphic.Group = __webpack_require__(48);
  5591. graphic.Image = __webpack_require__(49);
  5592. graphic.Text = __webpack_require__(50);
  5593. graphic.Circle = __webpack_require__(51);
  5594. graphic.Sector = __webpack_require__(52);
  5595. graphic.Ring = __webpack_require__(53);
  5596. graphic.Polygon = __webpack_require__(54);
  5597. graphic.Polyline = __webpack_require__(58);
  5598. graphic.Rect = __webpack_require__(59);
  5599. graphic.Line = __webpack_require__(61);
  5600. graphic.BezierCurve = __webpack_require__(62);
  5601. graphic.Arc = __webpack_require__(63);
  5602. graphic.CompoundPath = __webpack_require__(64);
  5603. graphic.LinearGradient = __webpack_require__(65);
  5604. graphic.RadialGradient = __webpack_require__(67);
  5605. graphic.BoundingRect = BoundingRect;
  5606. /**
  5607. * Extend shape with parameters
  5608. */
  5609. graphic.extendShape = function (opts) {
  5610. return Path.extend(opts);
  5611. };
  5612. /**
  5613. * Extend path
  5614. */
  5615. graphic.extendPath = function (pathData, opts) {
  5616. return pathTool.extendFromString(pathData, opts);
  5617. };
  5618. /**
  5619. * Create a path element from path data string
  5620. * @param {string} pathData
  5621. * @param {Object} opts
  5622. * @param {module:zrender/core/BoundingRect} rect
  5623. * @param {string} [layout=cover] 'center' or 'cover'
  5624. */
  5625. graphic.makePath = function (pathData, opts, rect, layout) {
  5626. var path = pathTool.createFromString(pathData, opts);
  5627. var boundingRect = path.getBoundingRect();
  5628. if (rect) {
  5629. var aspect = boundingRect.width / boundingRect.height;
  5630. if (layout === 'center') {
  5631. // Set rect to center, keep width / height ratio.
  5632. var width = rect.height * aspect;
  5633. var height;
  5634. if (width <= rect.width) {
  5635. height = rect.height;
  5636. }
  5637. else {
  5638. width = rect.width;
  5639. height = width / aspect;
  5640. }
  5641. var cx = rect.x + rect.width / 2;
  5642. var cy = rect.y + rect.height / 2;
  5643. rect.x = cx - width / 2;
  5644. rect.y = cy - height / 2;
  5645. rect.width = width;
  5646. rect.height = height;
  5647. }
  5648. graphic.resizePath(path, rect);
  5649. }
  5650. return path;
  5651. };
  5652. graphic.mergePath = pathTool.mergePath,
  5653. /**
  5654. * Resize a path to fit the rect
  5655. * @param {module:zrender/graphic/Path} path
  5656. * @param {Object} rect
  5657. */
  5658. graphic.resizePath = function (path, rect) {
  5659. if (!path.applyTransform) {
  5660. return;
  5661. }
  5662. var pathRect = path.getBoundingRect();
  5663. var m = pathRect.calculateTransform(rect);
  5664. path.applyTransform(m);
  5665. };
  5666. /**
  5667. * Sub pixel optimize line for canvas
  5668. *
  5669. * @param {Object} param
  5670. * @param {Object} [param.shape]
  5671. * @param {number} [param.shape.x1]
  5672. * @param {number} [param.shape.y1]
  5673. * @param {number} [param.shape.x2]
  5674. * @param {number} [param.shape.y2]
  5675. * @param {Object} [param.style]
  5676. * @param {number} [param.style.lineWidth]
  5677. * @return {Object} Modified param
  5678. */
  5679. graphic.subPixelOptimizeLine = function (param) {
  5680. var subPixelOptimize = graphic.subPixelOptimize;
  5681. var shape = param.shape;
  5682. var lineWidth = param.style.lineWidth;
  5683. if (round(shape.x1 * 2) === round(shape.x2 * 2)) {
  5684. shape.x1 = shape.x2 = subPixelOptimize(shape.x1, lineWidth, true);
  5685. }
  5686. if (round(shape.y1 * 2) === round(shape.y2 * 2)) {
  5687. shape.y1 = shape.y2 = subPixelOptimize(shape.y1, lineWidth, true);
  5688. }
  5689. return param;
  5690. };
  5691. /**
  5692. * Sub pixel optimize rect for canvas
  5693. *
  5694. * @param {Object} param
  5695. * @param {Object} [param.shape]
  5696. * @param {number} [param.shape.x]
  5697. * @param {number} [param.shape.y]
  5698. * @param {number} [param.shape.width]
  5699. * @param {number} [param.shape.height]
  5700. * @param {Object} [param.style]
  5701. * @param {number} [param.style.lineWidth]
  5702. * @return {Object} Modified param
  5703. */
  5704. graphic.subPixelOptimizeRect = function (param) {
  5705. var subPixelOptimize = graphic.subPixelOptimize;
  5706. var shape = param.shape;
  5707. var lineWidth = param.style.lineWidth;
  5708. var originX = shape.x;
  5709. var originY = shape.y;
  5710. var originWidth = shape.width;
  5711. var originHeight = shape.height;
  5712. shape.x = subPixelOptimize(shape.x, lineWidth, true);
  5713. shape.y = subPixelOptimize(shape.y, lineWidth, true);
  5714. shape.width = Math.max(
  5715. subPixelOptimize(originX + originWidth, lineWidth, false) - shape.x,
  5716. originWidth === 0 ? 0 : 1
  5717. );
  5718. shape.height = Math.max(
  5719. subPixelOptimize(originY + originHeight, lineWidth, false) - shape.y,
  5720. originHeight === 0 ? 0 : 1
  5721. );
  5722. return param;
  5723. };
  5724. /**
  5725. * Sub pixel optimize for canvas
  5726. *
  5727. * @param {number} position Coordinate, such as x, y
  5728. * @param {number} lineWidth Should be nonnegative integer.
  5729. * @param {boolean=} positiveOrNegative Default false (negative).
  5730. * @return {number} Optimized position.
  5731. */
  5732. graphic.subPixelOptimize = function (position, lineWidth, positiveOrNegative) {
  5733. // Assure that (position + lineWidth / 2) is near integer edge,
  5734. // otherwise line will be fuzzy in canvas.
  5735. var doubledPosition = round(position * 2);
  5736. return (doubledPosition + round(lineWidth)) % 2 === 0
  5737. ? doubledPosition / 2
  5738. : (doubledPosition + (positiveOrNegative ? 1 : -1)) / 2;
  5739. };
  5740. function hasFillOrStroke(fillOrStroke) {
  5741. return fillOrStroke != null && fillOrStroke != 'none';
  5742. }
  5743. function liftColor(color) {
  5744. return typeof color === 'string' ? colorTool.lift(color, -0.1) : color;
  5745. }
  5746. /**
  5747. * @private
  5748. */
  5749. function cacheElementStl(el) {
  5750. if (el.__hoverStlDirty) {
  5751. var stroke = el.style.stroke;
  5752. var fill = el.style.fill;
  5753. // Create hoverStyle on mouseover
  5754. var hoverStyle = el.__hoverStl;
  5755. hoverStyle.fill = hoverStyle.fill
  5756. || (hasFillOrStroke(fill) ? liftColor(fill) : null);
  5757. hoverStyle.stroke = hoverStyle.stroke
  5758. || (hasFillOrStroke(stroke) ? liftColor(stroke) : null);
  5759. var normalStyle = {};
  5760. for (var name in hoverStyle) {
  5761. if (hoverStyle.hasOwnProperty(name)) {
  5762. normalStyle[name] = el.style[name];
  5763. }
  5764. }
  5765. el.__normalStl = normalStyle;
  5766. el.__hoverStlDirty = false;
  5767. }
  5768. }
  5769. /**
  5770. * @private
  5771. */
  5772. function doSingleEnterHover(el) {
  5773. if (el.__isHover) {
  5774. return;
  5775. }
  5776. cacheElementStl(el);
  5777. if (el.useHoverLayer) {
  5778. el.__zr && el.__zr.addHover(el, el.__hoverStl);
  5779. }
  5780. else {
  5781. el.setStyle(el.__hoverStl);
  5782. el.z2 += 1;
  5783. }
  5784. el.__isHover = true;
  5785. }
  5786. /**
  5787. * @inner
  5788. */
  5789. function doSingleLeaveHover(el) {
  5790. if (!el.__isHover) {
  5791. return;
  5792. }
  5793. var normalStl = el.__normalStl;
  5794. if (el.useHoverLayer) {
  5795. el.__zr && el.__zr.removeHover(el);
  5796. }
  5797. else {
  5798. normalStl && el.setStyle(normalStl);
  5799. el.z2 -= 1;
  5800. }
  5801. el.__isHover = false;
  5802. }
  5803. /**
  5804. * @inner
  5805. */
  5806. function doEnterHover(el) {
  5807. el.type === 'group'
  5808. ? el.traverse(function (child) {
  5809. if (child.type !== 'group') {
  5810. doSingleEnterHover(child);
  5811. }
  5812. })
  5813. : doSingleEnterHover(el);
  5814. }
  5815. function doLeaveHover(el) {
  5816. el.type === 'group'
  5817. ? el.traverse(function (child) {
  5818. if (child.type !== 'group') {
  5819. doSingleLeaveHover(child);
  5820. }
  5821. })
  5822. : doSingleLeaveHover(el);
  5823. }
  5824. /**
  5825. * @inner
  5826. */
  5827. function setElementHoverStl(el, hoverStl) {
  5828. // If element has sepcified hoverStyle, then use it instead of given hoverStyle
  5829. // Often used when item group has a label element and it's hoverStyle is different
  5830. el.__hoverStl = el.hoverStyle || hoverStl || {};
  5831. el.__hoverStlDirty = true;
  5832. if (el.__isHover) {
  5833. cacheElementStl(el);
  5834. }
  5835. }
  5836. /**
  5837. * @inner
  5838. */
  5839. function onElementMouseOver(e) {
  5840. if (this.__hoverSilentOnTouch && e.zrByTouch) {
  5841. return;
  5842. }
  5843. // Only if element is not in emphasis status
  5844. !this.__isEmphasis && doEnterHover(this);
  5845. }
  5846. /**
  5847. * @inner
  5848. */
  5849. function onElementMouseOut(e) {
  5850. if (this.__hoverSilentOnTouch && e.zrByTouch) {
  5851. return;
  5852. }
  5853. // Only if element is not in emphasis status
  5854. !this.__isEmphasis && doLeaveHover(this);
  5855. }
  5856. /**
  5857. * @inner
  5858. */
  5859. function enterEmphasis() {
  5860. this.__isEmphasis = true;
  5861. doEnterHover(this);
  5862. }
  5863. /**
  5864. * @inner
  5865. */
  5866. function leaveEmphasis() {
  5867. this.__isEmphasis = false;
  5868. doLeaveHover(this);
  5869. }
  5870. /**
  5871. * Set hover style of element.
  5872. * This method can be called repeatly without side-effects.
  5873. * @param {module:zrender/Element} el
  5874. * @param {Object} [hoverStyle]
  5875. * @param {Object} [opt]
  5876. * @param {boolean} [opt.hoverSilentOnTouch=false]
  5877. * In touch device, mouseover event will be trigger on touchstart event
  5878. * (see module:zrender/dom/HandlerProxy). By this mechanism, we can
  5879. * conviniently use hoverStyle when tap on touch screen without additional
  5880. * code for compatibility.
  5881. * But if the chart/component has select feature, which usually also use
  5882. * hoverStyle, there might be conflict between 'select-highlight' and
  5883. * 'hover-highlight' especially when roam is enabled (see geo for example).
  5884. * In this case, hoverSilentOnTouch should be used to disable hover-highlight
  5885. * on touch device.
  5886. */
  5887. graphic.setHoverStyle = function (el, hoverStyle, opt) {
  5888. el.__hoverSilentOnTouch = opt && opt.hoverSilentOnTouch;
  5889. el.type === 'group'
  5890. ? el.traverse(function (child) {
  5891. if (child.type !== 'group') {
  5892. setElementHoverStl(child, hoverStyle);
  5893. }
  5894. })
  5895. : setElementHoverStl(el, hoverStyle);
  5896. // Duplicated function will be auto-ignored, see Eventful.js.
  5897. el.on('mouseover', onElementMouseOver)
  5898. .on('mouseout', onElementMouseOut);
  5899. // Emphasis, normal can be triggered manually
  5900. el.on('emphasis', enterEmphasis)
  5901. .on('normal', leaveEmphasis);
  5902. };
  5903. /**
  5904. * Set text option in the style
  5905. * @param {Object} textStyle
  5906. * @param {module:echarts/model/Model} labelModel
  5907. * @param {string} color
  5908. */
  5909. graphic.setText = function (textStyle, labelModel, color) {
  5910. var labelPosition = labelModel.getShallow('position') || 'inside';
  5911. var labelOffset = labelModel.getShallow('offset');
  5912. var labelColor = labelPosition.indexOf('inside') >= 0 ? 'white' : color;
  5913. var textStyleModel = labelModel.getModel('textStyle');
  5914. zrUtil.extend(textStyle, {
  5915. textDistance: labelModel.getShallow('distance') || 5,
  5916. textFont: textStyleModel.getFont(),
  5917. textPosition: labelPosition,
  5918. textOffset: labelOffset,
  5919. textFill: textStyleModel.getTextColor() || labelColor
  5920. });
  5921. };
  5922. graphic.getFont = function (opt, ecModel) {
  5923. var gTextStyleModel = ecModel && ecModel.getModel('textStyle');
  5924. return [
  5925. // FIXME in node-canvas fontWeight is before fontStyle
  5926. opt.fontStyle || gTextStyleModel && gTextStyleModel.getShallow('fontStyle') || '',
  5927. opt.fontWeight || gTextStyleModel && gTextStyleModel.getShallow('fontWeight') || '',
  5928. (opt.fontSize || gTextStyleModel && gTextStyleModel.getShallow('fontSize') || 12) + 'px',
  5929. opt.fontFamily || gTextStyleModel && gTextStyleModel.getShallow('fontFamily') || 'sans-serif'
  5930. ].join(' ');
  5931. };
  5932. function animateOrSetProps(isUpdate, el, props, animatableModel, dataIndex, cb) {
  5933. if (typeof dataIndex === 'function') {
  5934. cb = dataIndex;
  5935. dataIndex = null;
  5936. }
  5937. // Do not check 'animation' property directly here. Consider this case:
  5938. // animation model is an `itemModel`, whose does not have `isAnimationEnabled`
  5939. // but its parent model (`seriesModel`) does.
  5940. var animationEnabled = animatableModel && animatableModel.isAnimationEnabled();
  5941. if (animationEnabled) {
  5942. var postfix = isUpdate ? 'Update' : '';
  5943. var duration = animatableModel.getShallow('animationDuration' + postfix);
  5944. var animationEasing = animatableModel.getShallow('animationEasing' + postfix);
  5945. var animationDelay = animatableModel.getShallow('animationDelay' + postfix);
  5946. if (typeof animationDelay === 'function') {
  5947. animationDelay = animationDelay(
  5948. dataIndex,
  5949. animatableModel.getAnimationDelayParams
  5950. ? animatableModel.getAnimationDelayParams(el, dataIndex)
  5951. : null
  5952. );
  5953. }
  5954. if (typeof duration === 'function') {
  5955. duration = duration(dataIndex);
  5956. }
  5957. duration > 0
  5958. ? el.animateTo(props, duration, animationDelay || 0, animationEasing, cb)
  5959. : (el.stopAnimation(), el.attr(props), cb && cb());
  5960. }
  5961. else {
  5962. el.stopAnimation();
  5963. el.attr(props);
  5964. cb && cb();
  5965. }
  5966. }
  5967. /**
  5968. * Update graphic element properties with or without animation according to the configuration in series
  5969. * @param {module:zrender/Element} el
  5970. * @param {Object} props
  5971. * @param {module:echarts/model/Model} [animatableModel]
  5972. * @param {number} [dataIndex]
  5973. * @param {Function} [cb]
  5974. * @example
  5975. * graphic.updateProps(el, {
  5976. * position: [100, 100]
  5977. * }, seriesModel, dataIndex, function () { console.log('Animation done!'); });
  5978. * // Or
  5979. * graphic.updateProps(el, {
  5980. * position: [100, 100]
  5981. * }, seriesModel, function () { console.log('Animation done!'); });
  5982. */
  5983. graphic.updateProps = function (el, props, animatableModel, dataIndex, cb) {
  5984. animateOrSetProps(true, el, props, animatableModel, dataIndex, cb);
  5985. };
  5986. /**
  5987. * Init graphic element properties with or without animation according to the configuration in series
  5988. * @param {module:zrender/Element} el
  5989. * @param {Object} props
  5990. * @param {module:echarts/model/Model} [animatableModel]
  5991. * @param {number} [dataIndex]
  5992. * @param {Function} cb
  5993. */
  5994. graphic.initProps = function (el, props, animatableModel, dataIndex, cb) {
  5995. animateOrSetProps(false, el, props, animatableModel, dataIndex, cb);
  5996. };
  5997. /**
  5998. * Get transform matrix of target (param target),
  5999. * in coordinate of its ancestor (param ancestor)
  6000. *
  6001. * @param {module:zrender/mixin/Transformable} target
  6002. * @param {module:zrender/mixin/Transformable} [ancestor]
  6003. */
  6004. graphic.getTransform = function (target, ancestor) {
  6005. var mat = matrix.identity([]);
  6006. while (target && target !== ancestor) {
  6007. matrix.mul(mat, target.getLocalTransform(), mat);
  6008. target = target.parent;
  6009. }
  6010. return mat;
  6011. };
  6012. /**
  6013. * Apply transform to an vertex.
  6014. * @param {Array.<number>} target [x, y]
  6015. * @param {Array.<number>|TypedArray.<number>|Object} transform Can be:
  6016. * + Transform matrix: like [1, 0, 0, 1, 0, 0]
  6017. * + {position, rotation, scale}, the same as `zrender/Transformable`.
  6018. * @param {boolean=} invert Whether use invert matrix.
  6019. * @return {Array.<number>} [x, y]
  6020. */
  6021. graphic.applyTransform = function (target, transform, invert) {
  6022. if (transform && !zrUtil.isArrayLike(transform)) {
  6023. transform = Transformable.getLocalTransform(transform);
  6024. }
  6025. if (invert) {
  6026. transform = matrix.invert([], transform);
  6027. }
  6028. return vector.applyTransform([], target, transform);
  6029. };
  6030. /**
  6031. * @param {string} direction 'left' 'right' 'top' 'bottom'
  6032. * @param {Array.<number>} transform Transform matrix: like [1, 0, 0, 1, 0, 0]
  6033. * @param {boolean=} invert Whether use invert matrix.
  6034. * @return {string} Transformed direction. 'left' 'right' 'top' 'bottom'
  6035. */
  6036. graphic.transformDirection = function (direction, transform, invert) {
  6037. // Pick a base, ensure that transform result will not be (0, 0).
  6038. var hBase = (transform[4] === 0 || transform[5] === 0 || transform[0] === 0)
  6039. ? 1 : Math.abs(2 * transform[4] / transform[0]);
  6040. var vBase = (transform[4] === 0 || transform[5] === 0 || transform[2] === 0)
  6041. ? 1 : Math.abs(2 * transform[4] / transform[2]);
  6042. var vertex = [
  6043. direction === 'left' ? -hBase : direction === 'right' ? hBase : 0,
  6044. direction === 'top' ? -vBase : direction === 'bottom' ? vBase : 0
  6045. ];
  6046. vertex = graphic.applyTransform(vertex, transform, invert);
  6047. return Math.abs(vertex[0]) > Math.abs(vertex[1])
  6048. ? (vertex[0] > 0 ? 'right' : 'left')
  6049. : (vertex[1] > 0 ? 'bottom' : 'top');
  6050. };
  6051. /**
  6052. * Apply group transition animation from g1 to g2.
  6053. * If no animatableModel, no animation.
  6054. */
  6055. graphic.groupTransition = function (g1, g2, animatableModel, cb) {
  6056. if (!g1 || !g2) {
  6057. return;
  6058. }
  6059. function getElMap(g) {
  6060. var elMap = {};
  6061. g.traverse(function (el) {
  6062. if (!el.isGroup && el.anid) {
  6063. elMap[el.anid] = el;
  6064. }
  6065. });
  6066. return elMap;
  6067. }
  6068. function getAnimatableProps(el) {
  6069. var obj = {
  6070. position: vector.clone(el.position),
  6071. rotation: el.rotation
  6072. };
  6073. if (el.shape) {
  6074. obj.shape = zrUtil.extend({}, el.shape);
  6075. }
  6076. return obj;
  6077. }
  6078. var elMap1 = getElMap(g1);
  6079. g2.traverse(function (el) {
  6080. if (!el.isGroup && el.anid) {
  6081. var oldEl = elMap1[el.anid];
  6082. if (oldEl) {
  6083. var newProp = getAnimatableProps(el);
  6084. el.attr(getAnimatableProps(oldEl));
  6085. graphic.updateProps(el, newProp, animatableModel, el.dataIndex);
  6086. }
  6087. // else {
  6088. // if (el.previousProps) {
  6089. // graphic.updateProps
  6090. // }
  6091. // }
  6092. }
  6093. });
  6094. };
  6095. /**
  6096. * @param {Array.<Array.<number>>} points Like: [[23, 44], [53, 66], ...]
  6097. * @param {Object} rect {x, y, width, height}
  6098. * @return {Array.<Array.<number>>} A new clipped points.
  6099. */
  6100. graphic.clipPointsByRect = function (points, rect) {
  6101. return zrUtil.map(points, function (point) {
  6102. var x = point[0];
  6103. x = mathMax(x, rect.x);
  6104. x = mathMin(x, rect.x + rect.width);
  6105. var y = point[1];
  6106. y = mathMax(y, rect.y);
  6107. y = mathMin(y, rect.y + rect.height);
  6108. return [x, y];
  6109. });
  6110. };
  6111. /**
  6112. * @param {Object} targetRect {x, y, width, height}
  6113. * @param {Object} rect {x, y, width, height}
  6114. * @return {Object} A new clipped rect. If rect size are negative, return undefined.
  6115. */
  6116. graphic.clipRectByRect = function (targetRect, rect) {
  6117. var x = mathMax(targetRect.x, rect.x);
  6118. var x2 = mathMin(targetRect.x + targetRect.width, rect.x + rect.width);
  6119. var y = mathMax(targetRect.y, rect.y);
  6120. var y2 = mathMin(targetRect.y + targetRect.height, rect.y + rect.height);
  6121. if (x2 >= x && y2 >= y) {
  6122. return {
  6123. x: x,
  6124. y: y,
  6125. width: x2 - x,
  6126. height: y2 - y
  6127. };
  6128. }
  6129. };
  6130. module.exports = graphic;
  6131. /***/ },
  6132. /* 19 */
  6133. /***/ function(module, exports, __webpack_require__) {
  6134. var Path = __webpack_require__(20);
  6135. var PathProxy = __webpack_require__(36);
  6136. var transformPath = __webpack_require__(47);
  6137. // command chars
  6138. var cc = [
  6139. 'm', 'M', 'l', 'L', 'v', 'V', 'h', 'H', 'z', 'Z',
  6140. 'c', 'C', 'q', 'Q', 't', 'T', 's', 'S', 'a', 'A'
  6141. ];
  6142. var mathSqrt = Math.sqrt;
  6143. var mathSin = Math.sin;
  6144. var mathCos = Math.cos;
  6145. var PI = Math.PI;
  6146. var vMag = function(v) {
  6147. return Math.sqrt(v[0] * v[0] + v[1] * v[1]);
  6148. };
  6149. var vRatio = function(u, v) {
  6150. return (u[0] * v[0] + u[1] * v[1]) / (vMag(u) * vMag(v));
  6151. };
  6152. var vAngle = function(u, v) {
  6153. return (u[0] * v[1] < u[1] * v[0] ? -1 : 1)
  6154. * Math.acos(vRatio(u, v));
  6155. };
  6156. function processArc(x1, y1, x2, y2, fa, fs, rx, ry, psiDeg, cmd, path) {
  6157. var psi = psiDeg * (PI / 180.0);
  6158. var xp = mathCos(psi) * (x1 - x2) / 2.0
  6159. + mathSin(psi) * (y1 - y2) / 2.0;
  6160. var yp = -1 * mathSin(psi) * (x1 - x2) / 2.0
  6161. + mathCos(psi) * (y1 - y2) / 2.0;
  6162. var lambda = (xp * xp) / (rx * rx) + (yp * yp) / (ry * ry);
  6163. if (lambda > 1) {
  6164. rx *= mathSqrt(lambda);
  6165. ry *= mathSqrt(lambda);
  6166. }
  6167. var f = (fa === fs ? -1 : 1)
  6168. * mathSqrt((((rx * rx) * (ry * ry))
  6169. - ((rx * rx) * (yp * yp))
  6170. - ((ry * ry) * (xp * xp))) / ((rx * rx) * (yp * yp)
  6171. + (ry * ry) * (xp * xp))
  6172. ) || 0;
  6173. var cxp = f * rx * yp / ry;
  6174. var cyp = f * -ry * xp / rx;
  6175. var cx = (x1 + x2) / 2.0
  6176. + mathCos(psi) * cxp
  6177. - mathSin(psi) * cyp;
  6178. var cy = (y1 + y2) / 2.0
  6179. + mathSin(psi) * cxp
  6180. + mathCos(psi) * cyp;
  6181. var theta = vAngle([ 1, 0 ], [ (xp - cxp) / rx, (yp - cyp) / ry ]);
  6182. var u = [ (xp - cxp) / rx, (yp - cyp) / ry ];
  6183. var v = [ (-1 * xp - cxp) / rx, (-1 * yp - cyp) / ry ];
  6184. var dTheta = vAngle(u, v);
  6185. if (vRatio(u, v) <= -1) {
  6186. dTheta = PI;
  6187. }
  6188. if (vRatio(u, v) >= 1) {
  6189. dTheta = 0;
  6190. }
  6191. if (fs === 0 && dTheta > 0) {
  6192. dTheta = dTheta - 2 * PI;
  6193. }
  6194. if (fs === 1 && dTheta < 0) {
  6195. dTheta = dTheta + 2 * PI;
  6196. }
  6197. path.addData(cmd, cx, cy, rx, ry, theta, dTheta, psi, fs);
  6198. }
  6199. function createPathProxyFromString(data) {
  6200. if (!data) {
  6201. return [];
  6202. }
  6203. // command string
  6204. var cs = data.replace(/-/g, ' -')
  6205. .replace(/ /g, ' ')
  6206. .replace(/ /g, ',')
  6207. .replace(/,,/g, ',');
  6208. var n;
  6209. // create pipes so that we can split the data
  6210. for (n = 0; n < cc.length; n++) {
  6211. cs = cs.replace(new RegExp(cc[n], 'g'), '|' + cc[n]);
  6212. }
  6213. // create array
  6214. var arr = cs.split('|');
  6215. // init context point
  6216. var cpx = 0;
  6217. var cpy = 0;
  6218. var path = new PathProxy();
  6219. var CMD = PathProxy.CMD;
  6220. var prevCmd;
  6221. for (n = 1; n < arr.length; n++) {
  6222. var str = arr[n];
  6223. var c = str.charAt(0);
  6224. var off = 0;
  6225. var p = str.slice(1).replace(/e,-/g, 'e-').split(',');
  6226. var cmd;
  6227. if (p.length > 0 && p[0] === '') {
  6228. p.shift();
  6229. }
  6230. for (var i = 0; i < p.length; i++) {
  6231. p[i] = parseFloat(p[i]);
  6232. }
  6233. while (off < p.length && !isNaN(p[off])) {
  6234. if (isNaN(p[0])) {
  6235. break;
  6236. }
  6237. var ctlPtx;
  6238. var ctlPty;
  6239. var rx;
  6240. var ry;
  6241. var psi;
  6242. var fa;
  6243. var fs;
  6244. var x1 = cpx;
  6245. var y1 = cpy;
  6246. // convert l, H, h, V, and v to L
  6247. switch (c) {
  6248. case 'l':
  6249. cpx += p[off++];
  6250. cpy += p[off++];
  6251. cmd = CMD.L;
  6252. path.addData(cmd, cpx, cpy);
  6253. break;
  6254. case 'L':
  6255. cpx = p[off++];
  6256. cpy = p[off++];
  6257. cmd = CMD.L;
  6258. path.addData(cmd, cpx, cpy);
  6259. break;
  6260. case 'm':
  6261. cpx += p[off++];
  6262. cpy += p[off++];
  6263. cmd = CMD.M;
  6264. path.addData(cmd, cpx, cpy);
  6265. c = 'l';
  6266. break;
  6267. case 'M':
  6268. cpx = p[off++];
  6269. cpy = p[off++];
  6270. cmd = CMD.M;
  6271. path.addData(cmd, cpx, cpy);
  6272. c = 'L';
  6273. break;
  6274. case 'h':
  6275. cpx += p[off++];
  6276. cmd = CMD.L;
  6277. path.addData(cmd, cpx, cpy);
  6278. break;
  6279. case 'H':
  6280. cpx = p[off++];
  6281. cmd = CMD.L;
  6282. path.addData(cmd, cpx, cpy);
  6283. break;
  6284. case 'v':
  6285. cpy += p[off++];
  6286. cmd = CMD.L;
  6287. path.addData(cmd, cpx, cpy);
  6288. break;
  6289. case 'V':
  6290. cpy = p[off++];
  6291. cmd = CMD.L;
  6292. path.addData(cmd, cpx, cpy);
  6293. break;
  6294. case 'C':
  6295. cmd = CMD.C;
  6296. path.addData(
  6297. cmd, p[off++], p[off++], p[off++], p[off++], p[off++], p[off++]
  6298. );
  6299. cpx = p[off - 2];
  6300. cpy = p[off - 1];
  6301. break;
  6302. case 'c':
  6303. cmd = CMD.C;
  6304. path.addData(
  6305. cmd,
  6306. p[off++] + cpx, p[off++] + cpy,
  6307. p[off++] + cpx, p[off++] + cpy,
  6308. p[off++] + cpx, p[off++] + cpy
  6309. );
  6310. cpx += p[off - 2];
  6311. cpy += p[off - 1];
  6312. break;
  6313. case 'S':
  6314. ctlPtx = cpx;
  6315. ctlPty = cpy;
  6316. var len = path.len();
  6317. var pathData = path.data;
  6318. if (prevCmd === CMD.C) {
  6319. ctlPtx += cpx - pathData[len - 4];
  6320. ctlPty += cpy - pathData[len - 3];
  6321. }
  6322. cmd = CMD.C;
  6323. x1 = p[off++];
  6324. y1 = p[off++];
  6325. cpx = p[off++];
  6326. cpy = p[off++];
  6327. path.addData(cmd, ctlPtx, ctlPty, x1, y1, cpx, cpy);
  6328. break;
  6329. case 's':
  6330. ctlPtx = cpx;
  6331. ctlPty = cpy;
  6332. var len = path.len();
  6333. var pathData = path.data;
  6334. if (prevCmd === CMD.C) {
  6335. ctlPtx += cpx - pathData[len - 4];
  6336. ctlPty += cpy - pathData[len - 3];
  6337. }
  6338. cmd = CMD.C;
  6339. x1 = cpx + p[off++];
  6340. y1 = cpy + p[off++];
  6341. cpx += p[off++];
  6342. cpy += p[off++];
  6343. path.addData(cmd, ctlPtx, ctlPty, x1, y1, cpx, cpy);
  6344. break;
  6345. case 'Q':
  6346. x1 = p[off++];
  6347. y1 = p[off++];
  6348. cpx = p[off++];
  6349. cpy = p[off++];
  6350. cmd = CMD.Q;
  6351. path.addData(cmd, x1, y1, cpx, cpy);
  6352. break;
  6353. case 'q':
  6354. x1 = p[off++] + cpx;
  6355. y1 = p[off++] + cpy;
  6356. cpx += p[off++];
  6357. cpy += p[off++];
  6358. cmd = CMD.Q;
  6359. path.addData(cmd, x1, y1, cpx, cpy);
  6360. break;
  6361. case 'T':
  6362. ctlPtx = cpx;
  6363. ctlPty = cpy;
  6364. var len = path.len();
  6365. var pathData = path.data;
  6366. if (prevCmd === CMD.Q) {
  6367. ctlPtx += cpx - pathData[len - 4];
  6368. ctlPty += cpy - pathData[len - 3];
  6369. }
  6370. cpx = p[off++];
  6371. cpy = p[off++];
  6372. cmd = CMD.Q;
  6373. path.addData(cmd, ctlPtx, ctlPty, cpx, cpy);
  6374. break;
  6375. case 't':
  6376. ctlPtx = cpx;
  6377. ctlPty = cpy;
  6378. var len = path.len();
  6379. var pathData = path.data;
  6380. if (prevCmd === CMD.Q) {
  6381. ctlPtx += cpx - pathData[len - 4];
  6382. ctlPty += cpy - pathData[len - 3];
  6383. }
  6384. cpx += p[off++];
  6385. cpy += p[off++];
  6386. cmd = CMD.Q;
  6387. path.addData(cmd, ctlPtx, ctlPty, cpx, cpy);
  6388. break;
  6389. case 'A':
  6390. rx = p[off++];
  6391. ry = p[off++];
  6392. psi = p[off++];
  6393. fa = p[off++];
  6394. fs = p[off++];
  6395. x1 = cpx, y1 = cpy;
  6396. cpx = p[off++];
  6397. cpy = p[off++];
  6398. cmd = CMD.A;
  6399. processArc(
  6400. x1, y1, cpx, cpy, fa, fs, rx, ry, psi, cmd, path
  6401. );
  6402. break;
  6403. case 'a':
  6404. rx = p[off++];
  6405. ry = p[off++];
  6406. psi = p[off++];
  6407. fa = p[off++];
  6408. fs = p[off++];
  6409. x1 = cpx, y1 = cpy;
  6410. cpx += p[off++];
  6411. cpy += p[off++];
  6412. cmd = CMD.A;
  6413. processArc(
  6414. x1, y1, cpx, cpy, fa, fs, rx, ry, psi, cmd, path
  6415. );
  6416. break;
  6417. }
  6418. }
  6419. if (c === 'z' || c === 'Z') {
  6420. cmd = CMD.Z;
  6421. path.addData(cmd);
  6422. }
  6423. prevCmd = cmd;
  6424. }
  6425. path.toStatic();
  6426. return path;
  6427. }
  6428. // TODO Optimize double memory cost problem
  6429. function createPathOptions(str, opts) {
  6430. var pathProxy = createPathProxyFromString(str);
  6431. opts = opts || {};
  6432. opts.buildPath = function (path) {
  6433. if (path.setData) {
  6434. path.setData(pathProxy.data);
  6435. // Svg and vml renderer don't have context
  6436. var ctx = path.getContext();
  6437. if (ctx) {
  6438. path.rebuildPath(ctx);
  6439. }
  6440. }
  6441. else {
  6442. var ctx = path;
  6443. pathProxy.rebuildPath(ctx);
  6444. }
  6445. };
  6446. opts.applyTransform = function (m) {
  6447. transformPath(pathProxy, m);
  6448. this.dirty(true);
  6449. };
  6450. return opts;
  6451. }
  6452. module.exports = {
  6453. /**
  6454. * Create a Path object from path string data
  6455. * http://www.w3.org/TR/SVG/paths.html#PathData
  6456. * @param {Object} opts Other options
  6457. */
  6458. createFromString: function (str, opts) {
  6459. return new Path(createPathOptions(str, opts));
  6460. },
  6461. /**
  6462. * Create a Path class from path string data
  6463. * @param {string} str
  6464. * @param {Object} opts Other options
  6465. */
  6466. extendFromString: function (str, opts) {
  6467. return Path.extend(createPathOptions(str, opts));
  6468. },
  6469. /**
  6470. * Merge multiple paths
  6471. */
  6472. // TODO Apply transform
  6473. // TODO stroke dash
  6474. // TODO Optimize double memory cost problem
  6475. mergePath: function (pathEls, opts) {
  6476. var pathList = [];
  6477. var len = pathEls.length;
  6478. for (var i = 0; i < len; i++) {
  6479. var pathEl = pathEls[i];
  6480. if (!pathEl.path) {
  6481. pathEl.createPathProxy();
  6482. }
  6483. if (pathEl.__dirtyPath) {
  6484. pathEl.buildPath(pathEl.path, pathEl.shape, true);
  6485. }
  6486. pathList.push(pathEl.path);
  6487. }
  6488. var pathBundle = new Path(opts);
  6489. // Need path proxy.
  6490. pathBundle.createPathProxy();
  6491. pathBundle.buildPath = function (path) {
  6492. path.appendPath(pathList);
  6493. // Svg and vml renderer don't have context
  6494. var ctx = path.getContext();
  6495. if (ctx) {
  6496. path.rebuildPath(ctx);
  6497. }
  6498. };
  6499. return pathBundle;
  6500. }
  6501. };
  6502. /***/ },
  6503. /* 20 */
  6504. /***/ function(module, exports, __webpack_require__) {
  6505. /**
  6506. * Path element
  6507. * @module zrender/graphic/Path
  6508. */
  6509. var Displayable = __webpack_require__(21);
  6510. var zrUtil = __webpack_require__(4);
  6511. var PathProxy = __webpack_require__(36);
  6512. var pathContain = __webpack_require__(39);
  6513. var Pattern = __webpack_require__(46);
  6514. var getCanvasPattern = Pattern.prototype.getCanvasPattern;
  6515. var abs = Math.abs;
  6516. var pathProxyForDraw = new PathProxy(true);
  6517. /**
  6518. * @alias module:zrender/graphic/Path
  6519. * @extends module:zrender/graphic/Displayable
  6520. * @constructor
  6521. * @param {Object} opts
  6522. */
  6523. function Path(opts) {
  6524. Displayable.call(this, opts);
  6525. /**
  6526. * @type {module:zrender/core/PathProxy}
  6527. * @readOnly
  6528. */
  6529. this.path = null;
  6530. }
  6531. Path.prototype = {
  6532. constructor: Path,
  6533. type: 'path',
  6534. __dirtyPath: true,
  6535. strokeContainThreshold: 5,
  6536. brush: function (ctx, prevEl) {
  6537. var style = this.style;
  6538. var path = this.path || pathProxyForDraw;
  6539. var hasStroke = style.hasStroke();
  6540. var hasFill = style.hasFill();
  6541. var fill = style.fill;
  6542. var stroke = style.stroke;
  6543. var hasFillGradient = hasFill && !!(fill.colorStops);
  6544. var hasStrokeGradient = hasStroke && !!(stroke.colorStops);
  6545. var hasFillPattern = hasFill && !!(fill.image);
  6546. var hasStrokePattern = hasStroke && !!(stroke.image);
  6547. style.bind(ctx, this, prevEl);
  6548. this.setTransform(ctx);
  6549. if (this.__dirty) {
  6550. var rect;
  6551. // Update gradient because bounding rect may changed
  6552. if (hasFillGradient) {
  6553. rect = rect || this.getBoundingRect();
  6554. this._fillGradient = style.getGradient(ctx, fill, rect);
  6555. }
  6556. if (hasStrokeGradient) {
  6557. rect = rect || this.getBoundingRect();
  6558. this._strokeGradient = style.getGradient(ctx, stroke, rect);
  6559. }
  6560. }
  6561. // Use the gradient or pattern
  6562. if (hasFillGradient) {
  6563. // PENDING If may have affect the state
  6564. ctx.fillStyle = this._fillGradient;
  6565. }
  6566. else if (hasFillPattern) {
  6567. ctx.fillStyle = getCanvasPattern.call(fill, ctx);
  6568. }
  6569. if (hasStrokeGradient) {
  6570. ctx.strokeStyle = this._strokeGradient;
  6571. }
  6572. else if (hasStrokePattern) {
  6573. ctx.strokeStyle = getCanvasPattern.call(stroke, ctx);
  6574. }
  6575. var lineDash = style.lineDash;
  6576. var lineDashOffset = style.lineDashOffset;
  6577. var ctxLineDash = !!ctx.setLineDash;
  6578. // Update path sx, sy
  6579. var scale = this.getGlobalScale();
  6580. path.setScale(scale[0], scale[1]);
  6581. // Proxy context
  6582. // Rebuild path in following 2 cases
  6583. // 1. Path is dirty
  6584. // 2. Path needs javascript implemented lineDash stroking.
  6585. // In this case, lineDash information will not be saved in PathProxy
  6586. if (this.__dirtyPath
  6587. || (lineDash && !ctxLineDash && hasStroke)
  6588. ) {
  6589. path.beginPath(ctx);
  6590. // Setting line dash before build path
  6591. if (lineDash && !ctxLineDash) {
  6592. path.setLineDash(lineDash);
  6593. path.setLineDashOffset(lineDashOffset);
  6594. }
  6595. this.buildPath(path, this.shape, false);
  6596. // Clear path dirty flag
  6597. if (this.path) {
  6598. this.__dirtyPath = false;
  6599. }
  6600. }
  6601. else {
  6602. // Replay path building
  6603. ctx.beginPath();
  6604. this.path.rebuildPath(ctx);
  6605. }
  6606. hasFill && path.fill(ctx);
  6607. if (lineDash && ctxLineDash) {
  6608. ctx.setLineDash(lineDash);
  6609. ctx.lineDashOffset = lineDashOffset;
  6610. }
  6611. hasStroke && path.stroke(ctx);
  6612. if (lineDash && ctxLineDash) {
  6613. // PENDING
  6614. // Remove lineDash
  6615. ctx.setLineDash([]);
  6616. }
  6617. this.restoreTransform(ctx);
  6618. // Draw rect text
  6619. if (style.text != null) {
  6620. // var rect = this.getBoundingRect();
  6621. this.drawRectText(ctx, this.getBoundingRect());
  6622. }
  6623. },
  6624. // When bundling path, some shape may decide if use moveTo to begin a new subpath or closePath
  6625. // Like in circle
  6626. buildPath: function (ctx, shapeCfg, inBundle) {},
  6627. createPathProxy: function () {
  6628. this.path = new PathProxy();
  6629. },
  6630. getBoundingRect: function () {
  6631. var rect = this._rect;
  6632. var style = this.style;
  6633. var needsUpdateRect = !rect;
  6634. if (needsUpdateRect) {
  6635. var path = this.path;
  6636. if (!path) {
  6637. // Create path on demand.
  6638. path = this.path = new PathProxy();
  6639. }
  6640. if (this.__dirtyPath) {
  6641. path.beginPath();
  6642. this.buildPath(path, this.shape, false);
  6643. }
  6644. rect = path.getBoundingRect();
  6645. }
  6646. this._rect = rect;
  6647. if (style.hasStroke()) {
  6648. // Needs update rect with stroke lineWidth when
  6649. // 1. Element changes scale or lineWidth
  6650. // 2. Shape is changed
  6651. var rectWithStroke = this._rectWithStroke || (this._rectWithStroke = rect.clone());
  6652. if (this.__dirty || needsUpdateRect) {
  6653. rectWithStroke.copy(rect);
  6654. // FIXME Must after updateTransform
  6655. var w = style.lineWidth;
  6656. // PENDING, Min line width is needed when line is horizontal or vertical
  6657. var lineScale = style.strokeNoScale ? this.getLineScale() : 1;
  6658. // Only add extra hover lineWidth when there are no fill
  6659. if (!style.hasFill()) {
  6660. w = Math.max(w, this.strokeContainThreshold || 4);
  6661. }
  6662. // Consider line width
  6663. // Line scale can't be 0;
  6664. if (lineScale > 1e-10) {
  6665. rectWithStroke.width += w / lineScale;
  6666. rectWithStroke.height += w / lineScale;
  6667. rectWithStroke.x -= w / lineScale / 2;
  6668. rectWithStroke.y -= w / lineScale / 2;
  6669. }
  6670. }
  6671. // Return rect with stroke
  6672. return rectWithStroke;
  6673. }
  6674. return rect;
  6675. },
  6676. contain: function (x, y) {
  6677. var localPos = this.transformCoordToLocal(x, y);
  6678. var rect = this.getBoundingRect();
  6679. var style = this.style;
  6680. x = localPos[0];
  6681. y = localPos[1];
  6682. if (rect.contain(x, y)) {
  6683. var pathData = this.path.data;
  6684. if (style.hasStroke()) {
  6685. var lineWidth = style.lineWidth;
  6686. var lineScale = style.strokeNoScale ? this.getLineScale() : 1;
  6687. // Line scale can't be 0;
  6688. if (lineScale > 1e-10) {
  6689. // Only add extra hover lineWidth when there are no fill
  6690. if (!style.hasFill()) {
  6691. lineWidth = Math.max(lineWidth, this.strokeContainThreshold);
  6692. }
  6693. if (pathContain.containStroke(
  6694. pathData, lineWidth / lineScale, x, y
  6695. )) {
  6696. return true;
  6697. }
  6698. }
  6699. }
  6700. if (style.hasFill()) {
  6701. return pathContain.contain(pathData, x, y);
  6702. }
  6703. }
  6704. return false;
  6705. },
  6706. /**
  6707. * @param {boolean} dirtyPath
  6708. */
  6709. dirty: function (dirtyPath) {
  6710. if (dirtyPath == null) {
  6711. dirtyPath = true;
  6712. }
  6713. // Only mark dirty, not mark clean
  6714. if (dirtyPath) {
  6715. this.__dirtyPath = dirtyPath;
  6716. this._rect = null;
  6717. }
  6718. this.__dirty = true;
  6719. this.__zr && this.__zr.refresh();
  6720. // Used as a clipping path
  6721. if (this.__clipTarget) {
  6722. this.__clipTarget.dirty();
  6723. }
  6724. },
  6725. /**
  6726. * Alias for animate('shape')
  6727. * @param {boolean} loop
  6728. */
  6729. animateShape: function (loop) {
  6730. return this.animate('shape', loop);
  6731. },
  6732. // Overwrite attrKV
  6733. attrKV: function (key, value) {
  6734. // FIXME
  6735. if (key === 'shape') {
  6736. this.setShape(value);
  6737. this.__dirtyPath = true;
  6738. this._rect = null;
  6739. }
  6740. else {
  6741. Displayable.prototype.attrKV.call(this, key, value);
  6742. }
  6743. },
  6744. /**
  6745. * @param {Object|string} key
  6746. * @param {*} value
  6747. */
  6748. setShape: function (key, value) {
  6749. var shape = this.shape;
  6750. // Path from string may not have shape
  6751. if (shape) {
  6752. if (zrUtil.isObject(key)) {
  6753. for (var name in key) {
  6754. if (key.hasOwnProperty(name)) {
  6755. shape[name] = key[name];
  6756. }
  6757. }
  6758. }
  6759. else {
  6760. shape[key] = value;
  6761. }
  6762. this.dirty(true);
  6763. }
  6764. return this;
  6765. },
  6766. getLineScale: function () {
  6767. var m = this.transform;
  6768. // Get the line scale.
  6769. // Determinant of `m` means how much the area is enlarged by the
  6770. // transformation. So its square root can be used as a scale factor
  6771. // for width.
  6772. return m && abs(m[0] - 1) > 1e-10 && abs(m[3] - 1) > 1e-10
  6773. ? Math.sqrt(abs(m[0] * m[3] - m[2] * m[1]))
  6774. : 1;
  6775. }
  6776. };
  6777. /**
  6778. * 扩展一个 Path element, 比如星形,圆等。
  6779. * Extend a path element
  6780. * @param {Object} props
  6781. * @param {string} props.type Path type
  6782. * @param {Function} props.init Initialize
  6783. * @param {Function} props.buildPath Overwrite buildPath method
  6784. * @param {Object} [props.style] Extended default style config
  6785. * @param {Object} [props.shape] Extended default shape config
  6786. */
  6787. Path.extend = function (defaults) {
  6788. var Sub = function (opts) {
  6789. Path.call(this, opts);
  6790. if (defaults.style) {
  6791. // Extend default style
  6792. this.style.extendFrom(defaults.style, false);
  6793. }
  6794. // Extend default shape
  6795. var defaultShape = defaults.shape;
  6796. if (defaultShape) {
  6797. this.shape = this.shape || {};
  6798. var thisShape = this.shape;
  6799. for (var name in defaultShape) {
  6800. if (
  6801. ! thisShape.hasOwnProperty(name)
  6802. && defaultShape.hasOwnProperty(name)
  6803. ) {
  6804. thisShape[name] = defaultShape[name];
  6805. }
  6806. }
  6807. }
  6808. defaults.init && defaults.init.call(this, opts);
  6809. };
  6810. zrUtil.inherits(Sub, Path);
  6811. // FIXME 不能 extend position, rotation 等引用对象
  6812. for (var name in defaults) {
  6813. // Extending prototype values and methods
  6814. if (name !== 'style' && name !== 'shape') {
  6815. Sub.prototype[name] = defaults[name];
  6816. }
  6817. }
  6818. return Sub;
  6819. };
  6820. zrUtil.inherits(Path, Displayable);
  6821. module.exports = Path;
  6822. /***/ },
  6823. /* 21 */
  6824. /***/ function(module, exports, __webpack_require__) {
  6825. /**
  6826. * 可绘制的图形基类
  6827. * Base class of all displayable graphic objects
  6828. * @module zrender/graphic/Displayable
  6829. */
  6830. var zrUtil = __webpack_require__(4);
  6831. var Style = __webpack_require__(22);
  6832. var Element = __webpack_require__(23);
  6833. var RectText = __webpack_require__(35);
  6834. // var Stateful = require('./mixin/Stateful');
  6835. /**
  6836. * @alias module:zrender/graphic/Displayable
  6837. * @extends module:zrender/Element
  6838. * @extends module:zrender/graphic/mixin/RectText
  6839. */
  6840. function Displayable(opts) {
  6841. opts = opts || {};
  6842. Element.call(this, opts);
  6843. // Extend properties
  6844. for (var name in opts) {
  6845. if (
  6846. opts.hasOwnProperty(name) &&
  6847. name !== 'style'
  6848. ) {
  6849. this[name] = opts[name];
  6850. }
  6851. }
  6852. /**
  6853. * @type {module:zrender/graphic/Style}
  6854. */
  6855. this.style = new Style(opts.style);
  6856. this._rect = null;
  6857. // Shapes for cascade clipping.
  6858. this.__clipPaths = [];
  6859. // FIXME Stateful must be mixined after style is setted
  6860. // Stateful.call(this, opts);
  6861. }
  6862. Displayable.prototype = {
  6863. constructor: Displayable,
  6864. type: 'displayable',
  6865. /**
  6866. * Displayable 是否为脏,Painter 中会根据该标记判断是否需要是否需要重新绘制
  6867. * Dirty flag. From which painter will determine if this displayable object needs brush
  6868. * @name module:zrender/graphic/Displayable#__dirty
  6869. * @type {boolean}
  6870. */
  6871. __dirty: true,
  6872. /**
  6873. * 图形是否可见,为true时不绘制图形,但是仍能触发鼠标事件
  6874. * If ignore drawing of the displayable object. Mouse event will still be triggered
  6875. * @name module:/zrender/graphic/Displayable#invisible
  6876. * @type {boolean}
  6877. * @default false
  6878. */
  6879. invisible: false,
  6880. /**
  6881. * @name module:/zrender/graphic/Displayable#z
  6882. * @type {number}
  6883. * @default 0
  6884. */
  6885. z: 0,
  6886. /**
  6887. * @name module:/zrender/graphic/Displayable#z
  6888. * @type {number}
  6889. * @default 0
  6890. */
  6891. z2: 0,
  6892. /**
  6893. * z层level,决定绘画在哪层canvas中
  6894. * @name module:/zrender/graphic/Displayable#zlevel
  6895. * @type {number}
  6896. * @default 0
  6897. */
  6898. zlevel: 0,
  6899. /**
  6900. * 是否可拖拽
  6901. * @name module:/zrender/graphic/Displayable#draggable
  6902. * @type {boolean}
  6903. * @default false
  6904. */
  6905. draggable: false,
  6906. /**
  6907. * 是否正在拖拽
  6908. * @name module:/zrender/graphic/Displayable#draggable
  6909. * @type {boolean}
  6910. * @default false
  6911. */
  6912. dragging: false,
  6913. /**
  6914. * 是否相应鼠标事件
  6915. * @name module:/zrender/graphic/Displayable#silent
  6916. * @type {boolean}
  6917. * @default false
  6918. */
  6919. silent: false,
  6920. /**
  6921. * If enable culling
  6922. * @type {boolean}
  6923. * @default false
  6924. */
  6925. culling: false,
  6926. /**
  6927. * Mouse cursor when hovered
  6928. * @name module:/zrender/graphic/Displayable#cursor
  6929. * @type {string}
  6930. */
  6931. cursor: 'pointer',
  6932. /**
  6933. * If hover area is bounding rect
  6934. * @name module:/zrender/graphic/Displayable#rectHover
  6935. * @type {string}
  6936. */
  6937. rectHover: false,
  6938. /**
  6939. * Render the element progressively when the value >= 0,
  6940. * usefull for large data.
  6941. * @type {number}
  6942. */
  6943. progressive: -1,
  6944. beforeBrush: function (ctx) {},
  6945. afterBrush: function (ctx) {},
  6946. /**
  6947. * 图形绘制方法
  6948. * @param {Canvas2DRenderingContext} ctx
  6949. */
  6950. // Interface
  6951. brush: function (ctx, prevEl) {},
  6952. /**
  6953. * 获取最小包围盒
  6954. * @return {module:zrender/core/BoundingRect}
  6955. */
  6956. // Interface
  6957. getBoundingRect: function () {},
  6958. /**
  6959. * 判断坐标 x, y 是否在图形上
  6960. * If displayable element contain coord x, y
  6961. * @param {number} x
  6962. * @param {number} y
  6963. * @return {boolean}
  6964. */
  6965. contain: function (x, y) {
  6966. return this.rectContain(x, y);
  6967. },
  6968. /**
  6969. * @param {Function} cb
  6970. * @param {} context
  6971. */
  6972. traverse: function (cb, context) {
  6973. cb.call(context, this);
  6974. },
  6975. /**
  6976. * 判断坐标 x, y 是否在图形的包围盒上
  6977. * If bounding rect of element contain coord x, y
  6978. * @param {number} x
  6979. * @param {number} y
  6980. * @return {boolean}
  6981. */
  6982. rectContain: function (x, y) {
  6983. var coord = this.transformCoordToLocal(x, y);
  6984. var rect = this.getBoundingRect();
  6985. return rect.contain(coord[0], coord[1]);
  6986. },
  6987. /**
  6988. * 标记图形元素为脏,并且在下一帧重绘
  6989. * Mark displayable element dirty and refresh next frame
  6990. */
  6991. dirty: function () {
  6992. this.__dirty = true;
  6993. this._rect = null;
  6994. this.__zr && this.__zr.refresh();
  6995. },
  6996. /**
  6997. * 图形是否会触发事件
  6998. * If displayable object binded any event
  6999. * @return {boolean}
  7000. */
  7001. // TODO, 通过 bind 绑定的事件
  7002. // isSilent: function () {
  7003. // return !(
  7004. // this.hoverable || this.draggable
  7005. // || this.onmousemove || this.onmouseover || this.onmouseout
  7006. // || this.onmousedown || this.onmouseup || this.onclick
  7007. // || this.ondragenter || this.ondragover || this.ondragleave
  7008. // || this.ondrop
  7009. // );
  7010. // },
  7011. /**
  7012. * Alias for animate('style')
  7013. * @param {boolean} loop
  7014. */
  7015. animateStyle: function (loop) {
  7016. return this.animate('style', loop);
  7017. },
  7018. attrKV: function (key, value) {
  7019. if (key !== 'style') {
  7020. Element.prototype.attrKV.call(this, key, value);
  7021. }
  7022. else {
  7023. this.style.set(value);
  7024. }
  7025. },
  7026. /**
  7027. * @param {Object|string} key
  7028. * @param {*} value
  7029. */
  7030. setStyle: function (key, value) {
  7031. this.style.set(key, value);
  7032. this.dirty(false);
  7033. return this;
  7034. },
  7035. /**
  7036. * Use given style object
  7037. * @param {Object} obj
  7038. */
  7039. useStyle: function (obj) {
  7040. this.style = new Style(obj);
  7041. this.dirty(false);
  7042. return this;
  7043. }
  7044. };
  7045. zrUtil.inherits(Displayable, Element);
  7046. zrUtil.mixin(Displayable, RectText);
  7047. // zrUtil.mixin(Displayable, Stateful);
  7048. module.exports = Displayable;
  7049. /***/ },
  7050. /* 22 */
  7051. /***/ function(module, exports) {
  7052. /**
  7053. * @module zrender/graphic/Style
  7054. */
  7055. var STYLE_COMMON_PROPS = [
  7056. ['shadowBlur', 0], ['shadowOffsetX', 0], ['shadowOffsetY', 0], ['shadowColor', '#000'],
  7057. ['lineCap', 'butt'], ['lineJoin', 'miter'], ['miterLimit', 10]
  7058. ];
  7059. // var SHADOW_PROPS = STYLE_COMMON_PROPS.slice(0, 4);
  7060. // var LINE_PROPS = STYLE_COMMON_PROPS.slice(4);
  7061. var Style = function (opts) {
  7062. this.extendFrom(opts);
  7063. };
  7064. function createLinearGradient(ctx, obj, rect) {
  7065. var x = obj.x == null ? 0 : obj.x;
  7066. var x2 = obj.x2 == null ? 1 : obj.x2;
  7067. var y = obj.y == null ? 0 : obj.y;
  7068. var y2 = obj.y2 == null ? 0 : obj.y2;
  7069. if (!obj.global) {
  7070. x = x * rect.width + rect.x;
  7071. x2 = x2 * rect.width + rect.x;
  7072. y = y * rect.height + rect.y;
  7073. y2 = y2 * rect.height + rect.y;
  7074. }
  7075. var canvasGradient = ctx.createLinearGradient(x, y, x2, y2);
  7076. return canvasGradient;
  7077. }
  7078. function createRadialGradient(ctx, obj, rect) {
  7079. var width = rect.width;
  7080. var height = rect.height;
  7081. var min = Math.min(width, height);
  7082. var x = obj.x == null ? 0.5 : obj.x;
  7083. var y = obj.y == null ? 0.5 : obj.y;
  7084. var r = obj.r == null ? 0.5 : obj.r;
  7085. if (!obj.global) {
  7086. x = x * width + rect.x;
  7087. y = y * height + rect.y;
  7088. r = r * min;
  7089. }
  7090. var canvasGradient = ctx.createRadialGradient(x, y, 0, x, y, r);
  7091. return canvasGradient;
  7092. }
  7093. Style.prototype = {
  7094. constructor: Style,
  7095. /**
  7096. * @type {string}
  7097. */
  7098. fill: '#000000',
  7099. /**
  7100. * @type {string}
  7101. */
  7102. stroke: null,
  7103. /**
  7104. * @type {number}
  7105. */
  7106. opacity: 1,
  7107. /**
  7108. * @type {Array.<number>}
  7109. */
  7110. lineDash: null,
  7111. /**
  7112. * @type {number}
  7113. */
  7114. lineDashOffset: 0,
  7115. /**
  7116. * @type {number}
  7117. */
  7118. shadowBlur: 0,
  7119. /**
  7120. * @type {number}
  7121. */
  7122. shadowOffsetX: 0,
  7123. /**
  7124. * @type {number}
  7125. */
  7126. shadowOffsetY: 0,
  7127. /**
  7128. * @type {number}
  7129. */
  7130. lineWidth: 1,
  7131. /**
  7132. * If stroke ignore scale
  7133. * @type {Boolean}
  7134. */
  7135. strokeNoScale: false,
  7136. // Bounding rect text configuration
  7137. // Not affected by element transform
  7138. /**
  7139. * @type {string}
  7140. */
  7141. text: null,
  7142. /**
  7143. * @type {string}
  7144. */
  7145. textFill: '#000',
  7146. /**
  7147. * @type {string}
  7148. */
  7149. textStroke: null,
  7150. /**
  7151. * 'inside', 'left', 'right', 'top', 'bottom'
  7152. * [x, y]
  7153. * @type {string|Array.<number>}
  7154. * @default 'inside'
  7155. */
  7156. textPosition: 'inside',
  7157. /**
  7158. * [x, y]
  7159. * @type {Array.<number>}
  7160. */
  7161. textOffset: null,
  7162. /**
  7163. * @type {string}
  7164. */
  7165. textBaseline: null,
  7166. /**
  7167. * @type {string}
  7168. */
  7169. textAlign: null,
  7170. /**
  7171. * @type {string}
  7172. */
  7173. textVerticalAlign: null,
  7174. /**
  7175. * Only useful in Path and Image element
  7176. * @type {number}
  7177. */
  7178. textDistance: 5,
  7179. /**
  7180. * Only useful in Path and Image element
  7181. * @type {number}
  7182. */
  7183. textShadowBlur: 0,
  7184. /**
  7185. * Only useful in Path and Image element
  7186. * @type {number}
  7187. */
  7188. textShadowOffsetX: 0,
  7189. /**
  7190. * Only useful in Path and Image element
  7191. * @type {number}
  7192. */
  7193. textShadowOffsetY: 0,
  7194. /**
  7195. * If transform text
  7196. * Only useful in Path and Image element
  7197. * @type {boolean}
  7198. */
  7199. textTransform: false,
  7200. /**
  7201. * Text rotate around position of Path or Image
  7202. * Only useful in Path and Image element and textTransform is false.
  7203. */
  7204. textRotation: 0,
  7205. /**
  7206. * @type {string}
  7207. * https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/globalCompositeOperation
  7208. */
  7209. blend: null,
  7210. /**
  7211. * @param {CanvasRenderingContext2D} ctx
  7212. */
  7213. bind: function (ctx, el, prevEl) {
  7214. var style = this;
  7215. var prevStyle = prevEl && prevEl.style;
  7216. var firstDraw = !prevStyle;
  7217. for (var i = 0; i < STYLE_COMMON_PROPS.length; i++) {
  7218. var prop = STYLE_COMMON_PROPS[i];
  7219. var styleName = prop[0];
  7220. if (firstDraw || style[styleName] !== prevStyle[styleName]) {
  7221. // FIXME Invalid property value will cause style leak from previous element.
  7222. ctx[styleName] = style[styleName] || prop[1];
  7223. }
  7224. }
  7225. if ((firstDraw || style.fill !== prevStyle.fill)) {
  7226. ctx.fillStyle = style.fill;
  7227. }
  7228. if ((firstDraw || style.stroke !== prevStyle.stroke)) {
  7229. ctx.strokeStyle = style.stroke;
  7230. }
  7231. if ((firstDraw || style.opacity !== prevStyle.opacity)) {
  7232. ctx.globalAlpha = style.opacity == null ? 1 : style.opacity;
  7233. }
  7234. if ((firstDraw || style.blend !== prevStyle.blend)) {
  7235. ctx.globalCompositeOperation = style.blend || 'source-over';
  7236. }
  7237. if (this.hasStroke()) {
  7238. var lineWidth = style.lineWidth;
  7239. ctx.lineWidth = lineWidth / (
  7240. (this.strokeNoScale && el && el.getLineScale) ? el.getLineScale() : 1
  7241. );
  7242. }
  7243. },
  7244. hasFill: function () {
  7245. var fill = this.fill;
  7246. return fill != null && fill !== 'none';
  7247. },
  7248. hasStroke: function () {
  7249. var stroke = this.stroke;
  7250. return stroke != null && stroke !== 'none' && this.lineWidth > 0;
  7251. },
  7252. /**
  7253. * Extend from other style
  7254. * @param {zrender/graphic/Style} otherStyle
  7255. * @param {boolean} overwrite
  7256. */
  7257. extendFrom: function (otherStyle, overwrite) {
  7258. if (otherStyle) {
  7259. var target = this;
  7260. for (var name in otherStyle) {
  7261. if (otherStyle.hasOwnProperty(name)
  7262. && (overwrite || ! target.hasOwnProperty(name))
  7263. ) {
  7264. target[name] = otherStyle[name];
  7265. }
  7266. }
  7267. }
  7268. },
  7269. /**
  7270. * Batch setting style with a given object
  7271. * @param {Object|string} obj
  7272. * @param {*} [obj]
  7273. */
  7274. set: function (obj, value) {
  7275. if (typeof obj === 'string') {
  7276. this[obj] = value;
  7277. }
  7278. else {
  7279. this.extendFrom(obj, true);
  7280. }
  7281. },
  7282. /**
  7283. * Clone
  7284. * @return {zrender/graphic/Style} [description]
  7285. */
  7286. clone: function () {
  7287. var newStyle = new this.constructor();
  7288. newStyle.extendFrom(this, true);
  7289. return newStyle;
  7290. },
  7291. getGradient: function (ctx, obj, rect) {
  7292. var method = obj.type === 'radial' ? createRadialGradient : createLinearGradient;
  7293. var canvasGradient = method(ctx, obj, rect);
  7294. var colorStops = obj.colorStops;
  7295. for (var i = 0; i < colorStops.length; i++) {
  7296. canvasGradient.addColorStop(
  7297. colorStops[i].offset, colorStops[i].color
  7298. );
  7299. }
  7300. return canvasGradient;
  7301. }
  7302. };
  7303. var styleProto = Style.prototype;
  7304. for (var i = 0; i < STYLE_COMMON_PROPS.length; i++) {
  7305. var prop = STYLE_COMMON_PROPS[i];
  7306. if (!(prop[0] in styleProto)) {
  7307. styleProto[prop[0]] = prop[1];
  7308. }
  7309. }
  7310. // Provide for others
  7311. Style.getGradient = styleProto.getGradient;
  7312. module.exports = Style;
  7313. /***/ },
  7314. /* 23 */
  7315. /***/ function(module, exports, __webpack_require__) {
  7316. 'use strict';
  7317. /**
  7318. * @module zrender/Element
  7319. */
  7320. var guid = __webpack_require__(24);
  7321. var Eventful = __webpack_require__(25);
  7322. var Transformable = __webpack_require__(26);
  7323. var Animatable = __webpack_require__(27);
  7324. var zrUtil = __webpack_require__(4);
  7325. /**
  7326. * @alias module:zrender/Element
  7327. * @constructor
  7328. * @extends {module:zrender/mixin/Animatable}
  7329. * @extends {module:zrender/mixin/Transformable}
  7330. * @extends {module:zrender/mixin/Eventful}
  7331. */
  7332. var Element = function (opts) {
  7333. Transformable.call(this, opts);
  7334. Eventful.call(this, opts);
  7335. Animatable.call(this, opts);
  7336. /**
  7337. * 画布元素ID
  7338. * @type {string}
  7339. */
  7340. this.id = opts.id || guid();
  7341. };
  7342. Element.prototype = {
  7343. /**
  7344. * 元素类型
  7345. * Element type
  7346. * @type {string}
  7347. */
  7348. type: 'element',
  7349. /**
  7350. * 元素名字
  7351. * Element name
  7352. * @type {string}
  7353. */
  7354. name: '',
  7355. /**
  7356. * ZRender 实例对象,会在 element 添加到 zrender 实例中后自动赋值
  7357. * ZRender instance will be assigned when element is associated with zrender
  7358. * @name module:/zrender/Element#__zr
  7359. * @type {module:zrender/ZRender}
  7360. */
  7361. __zr: null,
  7362. /**
  7363. * 图形是否忽略,为true时忽略图形的绘制以及事件触发
  7364. * If ignore drawing and events of the element object
  7365. * @name module:/zrender/Element#ignore
  7366. * @type {boolean}
  7367. * @default false
  7368. */
  7369. ignore: false,
  7370. /**
  7371. * 用于裁剪的路径(shape),所有 Group 内的路径在绘制时都会被这个路径裁剪
  7372. * 该路径会继承被裁减对象的变换
  7373. * @type {module:zrender/graphic/Path}
  7374. * @see http://www.w3.org/TR/2dcontext/#clipping-region
  7375. * @readOnly
  7376. */
  7377. clipPath: null,
  7378. /**
  7379. * Drift element
  7380. * @param {number} dx dx on the global space
  7381. * @param {number} dy dy on the global space
  7382. */
  7383. drift: function (dx, dy) {
  7384. switch (this.draggable) {
  7385. case 'horizontal':
  7386. dy = 0;
  7387. break;
  7388. case 'vertical':
  7389. dx = 0;
  7390. break;
  7391. }
  7392. var m = this.transform;
  7393. if (!m) {
  7394. m = this.transform = [1, 0, 0, 1, 0, 0];
  7395. }
  7396. m[4] += dx;
  7397. m[5] += dy;
  7398. this.decomposeTransform();
  7399. this.dirty(false);
  7400. },
  7401. /**
  7402. * Hook before update
  7403. */
  7404. beforeUpdate: function () {},
  7405. /**
  7406. * Hook after update
  7407. */
  7408. afterUpdate: function () {},
  7409. /**
  7410. * Update each frame
  7411. */
  7412. update: function () {
  7413. this.updateTransform();
  7414. },
  7415. /**
  7416. * @param {Function} cb
  7417. * @param {} context
  7418. */
  7419. traverse: function (cb, context) {},
  7420. /**
  7421. * @protected
  7422. */
  7423. attrKV: function (key, value) {
  7424. if (key === 'position' || key === 'scale' || key === 'origin') {
  7425. // Copy the array
  7426. if (value) {
  7427. var target = this[key];
  7428. if (!target) {
  7429. target = this[key] = [];
  7430. }
  7431. target[0] = value[0];
  7432. target[1] = value[1];
  7433. }
  7434. }
  7435. else {
  7436. this[key] = value;
  7437. }
  7438. },
  7439. /**
  7440. * Hide the element
  7441. */
  7442. hide: function () {
  7443. this.ignore = true;
  7444. this.__zr && this.__zr.refresh();
  7445. },
  7446. /**
  7447. * Show the element
  7448. */
  7449. show: function () {
  7450. this.ignore = false;
  7451. this.__zr && this.__zr.refresh();
  7452. },
  7453. /**
  7454. * @param {string|Object} key
  7455. * @param {*} value
  7456. */
  7457. attr: function (key, value) {
  7458. if (typeof key === 'string') {
  7459. this.attrKV(key, value);
  7460. }
  7461. else if (zrUtil.isObject(key)) {
  7462. for (var name in key) {
  7463. if (key.hasOwnProperty(name)) {
  7464. this.attrKV(name, key[name]);
  7465. }
  7466. }
  7467. }
  7468. this.dirty(false);
  7469. return this;
  7470. },
  7471. /**
  7472. * @param {module:zrender/graphic/Path} clipPath
  7473. */
  7474. setClipPath: function (clipPath) {
  7475. var zr = this.__zr;
  7476. if (zr) {
  7477. clipPath.addSelfToZr(zr);
  7478. }
  7479. // Remove previous clip path
  7480. if (this.clipPath && this.clipPath !== clipPath) {
  7481. this.removeClipPath();
  7482. }
  7483. this.clipPath = clipPath;
  7484. clipPath.__zr = zr;
  7485. clipPath.__clipTarget = this;
  7486. this.dirty(false);
  7487. },
  7488. /**
  7489. */
  7490. removeClipPath: function () {
  7491. var clipPath = this.clipPath;
  7492. if (clipPath) {
  7493. if (clipPath.__zr) {
  7494. clipPath.removeSelfFromZr(clipPath.__zr);
  7495. }
  7496. clipPath.__zr = null;
  7497. clipPath.__clipTarget = null;
  7498. this.clipPath = null;
  7499. this.dirty(false);
  7500. }
  7501. },
  7502. /**
  7503. * Add self from zrender instance.
  7504. * Not recursively because it will be invoked when element added to storage.
  7505. * @param {module:zrender/ZRender} zr
  7506. */
  7507. addSelfToZr: function (zr) {
  7508. this.__zr = zr;
  7509. // 添加动画
  7510. var animators = this.animators;
  7511. if (animators) {
  7512. for (var i = 0; i < animators.length; i++) {
  7513. zr.animation.addAnimator(animators[i]);
  7514. }
  7515. }
  7516. if (this.clipPath) {
  7517. this.clipPath.addSelfToZr(zr);
  7518. }
  7519. },
  7520. /**
  7521. * Remove self from zrender instance.
  7522. * Not recursively because it will be invoked when element added to storage.
  7523. * @param {module:zrender/ZRender} zr
  7524. */
  7525. removeSelfFromZr: function (zr) {
  7526. this.__zr = null;
  7527. // 移除动画
  7528. var animators = this.animators;
  7529. if (animators) {
  7530. for (var i = 0; i < animators.length; i++) {
  7531. zr.animation.removeAnimator(animators[i]);
  7532. }
  7533. }
  7534. if (this.clipPath) {
  7535. this.clipPath.removeSelfFromZr(zr);
  7536. }
  7537. }
  7538. };
  7539. zrUtil.mixin(Element, Animatable);
  7540. zrUtil.mixin(Element, Transformable);
  7541. zrUtil.mixin(Element, Eventful);
  7542. module.exports = Element;
  7543. /***/ },
  7544. /* 24 */
  7545. /***/ function(module, exports) {
  7546. /**
  7547. * zrender: 生成唯一id
  7548. *
  7549. * @author errorrik (errorrik@gmail.com)
  7550. */
  7551. var idStart = 0x0907;
  7552. module.exports = function () {
  7553. return idStart++;
  7554. };
  7555. /***/ },
  7556. /* 25 */
  7557. /***/ function(module, exports) {
  7558. /**
  7559. * 事件扩展
  7560. * @module zrender/mixin/Eventful
  7561. * @author Kener (@Kener-林峰, kener.linfeng@gmail.com)
  7562. * pissang (https://www.github.com/pissang)
  7563. */
  7564. var arrySlice = Array.prototype.slice;
  7565. /**
  7566. * 事件分发器
  7567. * @alias module:zrender/mixin/Eventful
  7568. * @constructor
  7569. */
  7570. var Eventful = function () {
  7571. this._$handlers = {};
  7572. };
  7573. Eventful.prototype = {
  7574. constructor: Eventful,
  7575. /**
  7576. * 单次触发绑定,trigger后销毁
  7577. *
  7578. * @param {string} event 事件名
  7579. * @param {Function} handler 响应函数
  7580. * @param {Object} context
  7581. */
  7582. one: function (event, handler, context) {
  7583. var _h = this._$handlers;
  7584. if (!handler || !event) {
  7585. return this;
  7586. }
  7587. if (!_h[event]) {
  7588. _h[event] = [];
  7589. }
  7590. for (var i = 0; i < _h[event].length; i++) {
  7591. if (_h[event][i].h === handler) {
  7592. return this;
  7593. }
  7594. }
  7595. _h[event].push({
  7596. h: handler,
  7597. one: true,
  7598. ctx: context || this
  7599. });
  7600. return this;
  7601. },
  7602. /**
  7603. * 绑定事件
  7604. * @param {string} event 事件名
  7605. * @param {Function} handler 事件处理函数
  7606. * @param {Object} [context]
  7607. */
  7608. on: function (event, handler, context) {
  7609. var _h = this._$handlers;
  7610. if (!handler || !event) {
  7611. return this;
  7612. }
  7613. if (!_h[event]) {
  7614. _h[event] = [];
  7615. }
  7616. for (var i = 0; i < _h[event].length; i++) {
  7617. if (_h[event][i].h === handler) {
  7618. return this;
  7619. }
  7620. }
  7621. _h[event].push({
  7622. h: handler,
  7623. one: false,
  7624. ctx: context || this
  7625. });
  7626. return this;
  7627. },
  7628. /**
  7629. * 是否绑定了事件
  7630. * @param {string} event
  7631. * @return {boolean}
  7632. */
  7633. isSilent: function (event) {
  7634. var _h = this._$handlers;
  7635. return _h[event] && _h[event].length;
  7636. },
  7637. /**
  7638. * 解绑事件
  7639. * @param {string} event 事件名
  7640. * @param {Function} [handler] 事件处理函数
  7641. */
  7642. off: function (event, handler) {
  7643. var _h = this._$handlers;
  7644. if (!event) {
  7645. this._$handlers = {};
  7646. return this;
  7647. }
  7648. if (handler) {
  7649. if (_h[event]) {
  7650. var newList = [];
  7651. for (var i = 0, l = _h[event].length; i < l; i++) {
  7652. if (_h[event][i]['h'] != handler) {
  7653. newList.push(_h[event][i]);
  7654. }
  7655. }
  7656. _h[event] = newList;
  7657. }
  7658. if (_h[event] && _h[event].length === 0) {
  7659. delete _h[event];
  7660. }
  7661. }
  7662. else {
  7663. delete _h[event];
  7664. }
  7665. return this;
  7666. },
  7667. /**
  7668. * 事件分发
  7669. *
  7670. * @param {string} type 事件类型
  7671. */
  7672. trigger: function (type) {
  7673. if (this._$handlers[type]) {
  7674. var args = arguments;
  7675. var argLen = args.length;
  7676. if (argLen > 3) {
  7677. args = arrySlice.call(args, 1);
  7678. }
  7679. var _h = this._$handlers[type];
  7680. var len = _h.length;
  7681. for (var i = 0; i < len;) {
  7682. // Optimize advise from backbone
  7683. switch (argLen) {
  7684. case 1:
  7685. _h[i]['h'].call(_h[i]['ctx']);
  7686. break;
  7687. case 2:
  7688. _h[i]['h'].call(_h[i]['ctx'], args[1]);
  7689. break;
  7690. case 3:
  7691. _h[i]['h'].call(_h[i]['ctx'], args[1], args[2]);
  7692. break;
  7693. default:
  7694. // have more than 2 given arguments
  7695. _h[i]['h'].apply(_h[i]['ctx'], args);
  7696. break;
  7697. }
  7698. if (_h[i]['one']) {
  7699. _h.splice(i, 1);
  7700. len--;
  7701. }
  7702. else {
  7703. i++;
  7704. }
  7705. }
  7706. }
  7707. return this;
  7708. },
  7709. /**
  7710. * 带有context的事件分发, 最后一个参数是事件回调的context
  7711. * @param {string} type 事件类型
  7712. */
  7713. triggerWithContext: function (type) {
  7714. if (this._$handlers[type]) {
  7715. var args = arguments;
  7716. var argLen = args.length;
  7717. if (argLen > 4) {
  7718. args = arrySlice.call(args, 1, args.length - 1);
  7719. }
  7720. var ctx = args[args.length - 1];
  7721. var _h = this._$handlers[type];
  7722. var len = _h.length;
  7723. for (var i = 0; i < len;) {
  7724. // Optimize advise from backbone
  7725. switch (argLen) {
  7726. case 1:
  7727. _h[i]['h'].call(ctx);
  7728. break;
  7729. case 2:
  7730. _h[i]['h'].call(ctx, args[1]);
  7731. break;
  7732. case 3:
  7733. _h[i]['h'].call(ctx, args[1], args[2]);
  7734. break;
  7735. default:
  7736. // have more than 2 given arguments
  7737. _h[i]['h'].apply(ctx, args);
  7738. break;
  7739. }
  7740. if (_h[i]['one']) {
  7741. _h.splice(i, 1);
  7742. len--;
  7743. }
  7744. else {
  7745. i++;
  7746. }
  7747. }
  7748. }
  7749. return this;
  7750. }
  7751. };
  7752. // 对象可以通过 onxxxx 绑定事件
  7753. /**
  7754. * @event module:zrender/mixin/Eventful#onclick
  7755. * @type {Function}
  7756. * @default null
  7757. */
  7758. /**
  7759. * @event module:zrender/mixin/Eventful#onmouseover
  7760. * @type {Function}
  7761. * @default null
  7762. */
  7763. /**
  7764. * @event module:zrender/mixin/Eventful#onmouseout
  7765. * @type {Function}
  7766. * @default null
  7767. */
  7768. /**
  7769. * @event module:zrender/mixin/Eventful#onmousemove
  7770. * @type {Function}
  7771. * @default null
  7772. */
  7773. /**
  7774. * @event module:zrender/mixin/Eventful#onmousewheel
  7775. * @type {Function}
  7776. * @default null
  7777. */
  7778. /**
  7779. * @event module:zrender/mixin/Eventful#onmousedown
  7780. * @type {Function}
  7781. * @default null
  7782. */
  7783. /**
  7784. * @event module:zrender/mixin/Eventful#onmouseup
  7785. * @type {Function}
  7786. * @default null
  7787. */
  7788. /**
  7789. * @event module:zrender/mixin/Eventful#ondrag
  7790. * @type {Function}
  7791. * @default null
  7792. */
  7793. /**
  7794. * @event module:zrender/mixin/Eventful#ondragstart
  7795. * @type {Function}
  7796. * @default null
  7797. */
  7798. /**
  7799. * @event module:zrender/mixin/Eventful#ondragend
  7800. * @type {Function}
  7801. * @default null
  7802. */
  7803. /**
  7804. * @event module:zrender/mixin/Eventful#ondragenter
  7805. * @type {Function}
  7806. * @default null
  7807. */
  7808. /**
  7809. * @event module:zrender/mixin/Eventful#ondragleave
  7810. * @type {Function}
  7811. * @default null
  7812. */
  7813. /**
  7814. * @event module:zrender/mixin/Eventful#ondragover
  7815. * @type {Function}
  7816. * @default null
  7817. */
  7818. /**
  7819. * @event module:zrender/mixin/Eventful#ondrop
  7820. * @type {Function}
  7821. * @default null
  7822. */
  7823. module.exports = Eventful;
  7824. /***/ },
  7825. /* 26 */
  7826. /***/ function(module, exports, __webpack_require__) {
  7827. 'use strict';
  7828. /**
  7829. * 提供变换扩展
  7830. * @module zrender/mixin/Transformable
  7831. * @author pissang (https://www.github.com/pissang)
  7832. */
  7833. var matrix = __webpack_require__(11);
  7834. var vector = __webpack_require__(10);
  7835. var mIdentity = matrix.identity;
  7836. var EPSILON = 5e-5;
  7837. function isNotAroundZero(val) {
  7838. return val > EPSILON || val < -EPSILON;
  7839. }
  7840. /**
  7841. * @alias module:zrender/mixin/Transformable
  7842. * @constructor
  7843. */
  7844. var Transformable = function (opts) {
  7845. opts = opts || {};
  7846. // If there are no given position, rotation, scale
  7847. if (!opts.position) {
  7848. /**
  7849. * 平移
  7850. * @type {Array.<number>}
  7851. * @default [0, 0]
  7852. */
  7853. this.position = [0, 0];
  7854. }
  7855. if (opts.rotation == null) {
  7856. /**
  7857. * 旋转
  7858. * @type {Array.<number>}
  7859. * @default 0
  7860. */
  7861. this.rotation = 0;
  7862. }
  7863. if (!opts.scale) {
  7864. /**
  7865. * 缩放
  7866. * @type {Array.<number>}
  7867. * @default [1, 1]
  7868. */
  7869. this.scale = [1, 1];
  7870. }
  7871. /**
  7872. * 旋转和缩放的原点
  7873. * @type {Array.<number>}
  7874. * @default null
  7875. */
  7876. this.origin = this.origin || null;
  7877. };
  7878. var transformableProto = Transformable.prototype;
  7879. transformableProto.transform = null;
  7880. /**
  7881. * 判断是否需要有坐标变换
  7882. * 如果有坐标变换, 则从position, rotation, scale以及父节点的transform计算出自身的transform矩阵
  7883. */
  7884. transformableProto.needLocalTransform = function () {
  7885. return isNotAroundZero(this.rotation)
  7886. || isNotAroundZero(this.position[0])
  7887. || isNotAroundZero(this.position[1])
  7888. || isNotAroundZero(this.scale[0] - 1)
  7889. || isNotAroundZero(this.scale[1] - 1);
  7890. };
  7891. transformableProto.updateTransform = function () {
  7892. var parent = this.parent;
  7893. var parentHasTransform = parent && parent.transform;
  7894. var needLocalTransform = this.needLocalTransform();
  7895. var m = this.transform;
  7896. if (!(needLocalTransform || parentHasTransform)) {
  7897. m && mIdentity(m);
  7898. return;
  7899. }
  7900. m = m || matrix.create();
  7901. if (needLocalTransform) {
  7902. this.getLocalTransform(m);
  7903. }
  7904. else {
  7905. mIdentity(m);
  7906. }
  7907. // 应用父节点变换
  7908. if (parentHasTransform) {
  7909. if (needLocalTransform) {
  7910. matrix.mul(m, parent.transform, m);
  7911. }
  7912. else {
  7913. matrix.copy(m, parent.transform);
  7914. }
  7915. }
  7916. // 保存这个变换矩阵
  7917. this.transform = m;
  7918. this.invTransform = this.invTransform || matrix.create();
  7919. matrix.invert(this.invTransform, m);
  7920. };
  7921. transformableProto.getLocalTransform = function (m) {
  7922. return Transformable.getLocalTransform(this, m);
  7923. };
  7924. /**
  7925. * 将自己的transform应用到context上
  7926. * @param {Context2D} ctx
  7927. */
  7928. transformableProto.setTransform = function (ctx) {
  7929. var m = this.transform;
  7930. var dpr = ctx.dpr || 1;
  7931. if (m) {
  7932. ctx.setTransform(dpr * m[0], dpr * m[1], dpr * m[2], dpr * m[3], dpr * m[4], dpr * m[5]);
  7933. }
  7934. else {
  7935. ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
  7936. }
  7937. };
  7938. transformableProto.restoreTransform = function (ctx) {
  7939. var dpr = ctx.dpr || 1;
  7940. ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
  7941. };
  7942. var tmpTransform = [];
  7943. /**
  7944. * 分解`transform`矩阵到`position`, `rotation`, `scale`
  7945. */
  7946. transformableProto.decomposeTransform = function () {
  7947. if (!this.transform) {
  7948. return;
  7949. }
  7950. var parent = this.parent;
  7951. var m = this.transform;
  7952. if (parent && parent.transform) {
  7953. // Get local transform and decompose them to position, scale, rotation
  7954. matrix.mul(tmpTransform, parent.invTransform, m);
  7955. m = tmpTransform;
  7956. }
  7957. var sx = m[0] * m[0] + m[1] * m[1];
  7958. var sy = m[2] * m[2] + m[3] * m[3];
  7959. var position = this.position;
  7960. var scale = this.scale;
  7961. if (isNotAroundZero(sx - 1)) {
  7962. sx = Math.sqrt(sx);
  7963. }
  7964. if (isNotAroundZero(sy - 1)) {
  7965. sy = Math.sqrt(sy);
  7966. }
  7967. if (m[0] < 0) {
  7968. sx = -sx;
  7969. }
  7970. if (m[3] < 0) {
  7971. sy = -sy;
  7972. }
  7973. position[0] = m[4];
  7974. position[1] = m[5];
  7975. scale[0] = sx;
  7976. scale[1] = sy;
  7977. this.rotation = Math.atan2(-m[1] / sy, m[0] / sx);
  7978. };
  7979. /**
  7980. * Get global scale
  7981. * @return {Array.<number>}
  7982. */
  7983. transformableProto.getGlobalScale = function () {
  7984. var m = this.transform;
  7985. if (!m) {
  7986. return [1, 1];
  7987. }
  7988. var sx = Math.sqrt(m[0] * m[0] + m[1] * m[1]);
  7989. var sy = Math.sqrt(m[2] * m[2] + m[3] * m[3]);
  7990. if (m[0] < 0) {
  7991. sx = -sx;
  7992. }
  7993. if (m[3] < 0) {
  7994. sy = -sy;
  7995. }
  7996. return [sx, sy];
  7997. };
  7998. /**
  7999. * 变换坐标位置到 shape 的局部坐标空间
  8000. * @method
  8001. * @param {number} x
  8002. * @param {number} y
  8003. * @return {Array.<number>}
  8004. */
  8005. transformableProto.transformCoordToLocal = function (x, y) {
  8006. var v2 = [x, y];
  8007. var invTransform = this.invTransform;
  8008. if (invTransform) {
  8009. vector.applyTransform(v2, v2, invTransform);
  8010. }
  8011. return v2;
  8012. };
  8013. /**
  8014. * 变换局部坐标位置到全局坐标空间
  8015. * @method
  8016. * @param {number} x
  8017. * @param {number} y
  8018. * @return {Array.<number>}
  8019. */
  8020. transformableProto.transformCoordToGlobal = function (x, y) {
  8021. var v2 = [x, y];
  8022. var transform = this.transform;
  8023. if (transform) {
  8024. vector.applyTransform(v2, v2, transform);
  8025. }
  8026. return v2;
  8027. };
  8028. /**
  8029. * @static
  8030. * @param {Object} target
  8031. * @param {Array.<number>} target.origin
  8032. * @param {number} target.rotation
  8033. * @param {Array.<number>} target.position
  8034. * @param {Array.<number>} [m]
  8035. */
  8036. Transformable.getLocalTransform = function (target, m) {
  8037. m = m || [];
  8038. mIdentity(m);
  8039. var origin = target.origin;
  8040. var scale = target.scale || [1, 1];
  8041. var rotation = target.rotation || 0;
  8042. var position = target.position || [0, 0];
  8043. if (origin) {
  8044. // Translate to origin
  8045. m[4] -= origin[0];
  8046. m[5] -= origin[1];
  8047. }
  8048. matrix.scale(m, m, scale);
  8049. if (rotation) {
  8050. matrix.rotate(m, m, rotation);
  8051. }
  8052. if (origin) {
  8053. // Translate back from origin
  8054. m[4] += origin[0];
  8055. m[5] += origin[1];
  8056. }
  8057. m[4] += position[0];
  8058. m[5] += position[1];
  8059. return m;
  8060. };
  8061. module.exports = Transformable;
  8062. /***/ },
  8063. /* 27 */
  8064. /***/ function(module, exports, __webpack_require__) {
  8065. 'use strict';
  8066. /**
  8067. * @module zrender/mixin/Animatable
  8068. */
  8069. var Animator = __webpack_require__(28);
  8070. var util = __webpack_require__(4);
  8071. var isString = util.isString;
  8072. var isFunction = util.isFunction;
  8073. var isObject = util.isObject;
  8074. var log = __webpack_require__(33);
  8075. /**
  8076. * @alias modue:zrender/mixin/Animatable
  8077. * @constructor
  8078. */
  8079. var Animatable = function () {
  8080. /**
  8081. * @type {Array.<module:zrender/animation/Animator>}
  8082. * @readOnly
  8083. */
  8084. this.animators = [];
  8085. };
  8086. Animatable.prototype = {
  8087. constructor: Animatable,
  8088. /**
  8089. * 动画
  8090. *
  8091. * @param {string} path 需要添加动画的属性获取路径,可以通过a.b.c来获取深层的属性
  8092. * @param {boolean} [loop] 动画是否循环
  8093. * @return {module:zrender/animation/Animator}
  8094. * @example:
  8095. * el.animate('style', false)
  8096. * .when(1000, {x: 10} )
  8097. * .done(function(){ // Animation done })
  8098. * .start()
  8099. */
  8100. animate: function (path, loop) {
  8101. var target;
  8102. var animatingShape = false;
  8103. var el = this;
  8104. var zr = this.__zr;
  8105. if (path) {
  8106. var pathSplitted = path.split('.');
  8107. var prop = el;
  8108. // If animating shape
  8109. animatingShape = pathSplitted[0] === 'shape';
  8110. for (var i = 0, l = pathSplitted.length; i < l; i++) {
  8111. if (!prop) {
  8112. continue;
  8113. }
  8114. prop = prop[pathSplitted[i]];
  8115. }
  8116. if (prop) {
  8117. target = prop;
  8118. }
  8119. }
  8120. else {
  8121. target = el;
  8122. }
  8123. if (!target) {
  8124. log(
  8125. 'Property "'
  8126. + path
  8127. + '" is not existed in element '
  8128. + el.id
  8129. );
  8130. return;
  8131. }
  8132. var animators = el.animators;
  8133. var animator = new Animator(target, loop);
  8134. animator.during(function (target) {
  8135. el.dirty(animatingShape);
  8136. })
  8137. .done(function () {
  8138. // FIXME Animator will not be removed if use `Animator#stop` to stop animation
  8139. animators.splice(util.indexOf(animators, animator), 1);
  8140. });
  8141. animators.push(animator);
  8142. // If animate after added to the zrender
  8143. if (zr) {
  8144. zr.animation.addAnimator(animator);
  8145. }
  8146. return animator;
  8147. },
  8148. /**
  8149. * 停止动画
  8150. * @param {boolean} forwardToLast If move to last frame before stop
  8151. */
  8152. stopAnimation: function (forwardToLast) {
  8153. var animators = this.animators;
  8154. var len = animators.length;
  8155. for (var i = 0; i < len; i++) {
  8156. animators[i].stop(forwardToLast);
  8157. }
  8158. animators.length = 0;
  8159. return this;
  8160. },
  8161. /**
  8162. * @param {Object} target
  8163. * @param {number} [time=500] Time in ms
  8164. * @param {string} [easing='linear']
  8165. * @param {number} [delay=0]
  8166. * @param {Function} [callback]
  8167. *
  8168. * @example
  8169. * // Animate position
  8170. * el.animateTo({
  8171. * position: [10, 10]
  8172. * }, function () { // done })
  8173. *
  8174. * // Animate shape, style and position in 100ms, delayed 100ms, with cubicOut easing
  8175. * el.animateTo({
  8176. * shape: {
  8177. * width: 500
  8178. * },
  8179. * style: {
  8180. * fill: 'red'
  8181. * }
  8182. * position: [10, 10]
  8183. * }, 100, 100, 'cubicOut', function () { // done })
  8184. */
  8185. // TODO Return animation key
  8186. animateTo: function (target, time, delay, easing, callback) {
  8187. // animateTo(target, time, easing, callback);
  8188. if (isString(delay)) {
  8189. callback = easing;
  8190. easing = delay;
  8191. delay = 0;
  8192. }
  8193. // animateTo(target, time, delay, callback);
  8194. else if (isFunction(easing)) {
  8195. callback = easing;
  8196. easing = 'linear';
  8197. delay = 0;
  8198. }
  8199. // animateTo(target, time, callback);
  8200. else if (isFunction(delay)) {
  8201. callback = delay;
  8202. delay = 0;
  8203. }
  8204. // animateTo(target, callback)
  8205. else if (isFunction(time)) {
  8206. callback = time;
  8207. time = 500;
  8208. }
  8209. // animateTo(target)
  8210. else if (!time) {
  8211. time = 500;
  8212. }
  8213. // Stop all previous animations
  8214. this.stopAnimation();
  8215. this._animateToShallow('', this, target, time, delay, easing, callback);
  8216. // Animators may be removed immediately after start
  8217. // if there is nothing to animate
  8218. var animators = this.animators.slice();
  8219. var count = animators.length;
  8220. function done() {
  8221. count--;
  8222. if (!count) {
  8223. callback && callback();
  8224. }
  8225. }
  8226. // No animators. This should be checked before animators[i].start(),
  8227. // because 'done' may be executed immediately if no need to animate.
  8228. if (!count) {
  8229. callback && callback();
  8230. }
  8231. // Start after all animators created
  8232. // Incase any animator is done immediately when all animation properties are not changed
  8233. for (var i = 0; i < animators.length; i++) {
  8234. animators[i]
  8235. .done(done)
  8236. .start(easing);
  8237. }
  8238. },
  8239. /**
  8240. * @private
  8241. * @param {string} path=''
  8242. * @param {Object} source=this
  8243. * @param {Object} target
  8244. * @param {number} [time=500]
  8245. * @param {number} [delay=0]
  8246. *
  8247. * @example
  8248. * // Animate position
  8249. * el._animateToShallow({
  8250. * position: [10, 10]
  8251. * })
  8252. *
  8253. * // Animate shape, style and position in 100ms, delayed 100ms
  8254. * el._animateToShallow({
  8255. * shape: {
  8256. * width: 500
  8257. * },
  8258. * style: {
  8259. * fill: 'red'
  8260. * }
  8261. * position: [10, 10]
  8262. * }, 100, 100)
  8263. */
  8264. _animateToShallow: function (path, source, target, time, delay) {
  8265. var objShallow = {};
  8266. var propertyCount = 0;
  8267. for (var name in target) {
  8268. if (!target.hasOwnProperty(name)) {
  8269. continue;
  8270. }
  8271. if (source[name] != null) {
  8272. if (isObject(target[name]) && !util.isArrayLike(target[name])) {
  8273. this._animateToShallow(
  8274. path ? path + '.' + name : name,
  8275. source[name],
  8276. target[name],
  8277. time,
  8278. delay
  8279. );
  8280. }
  8281. else {
  8282. objShallow[name] = target[name];
  8283. propertyCount++;
  8284. }
  8285. }
  8286. else if (target[name] != null) {
  8287. // Attr directly if not has property
  8288. // FIXME, if some property not needed for element ?
  8289. if (!path) {
  8290. this.attr(name, target[name]);
  8291. }
  8292. else { // Shape or style
  8293. var props = {};
  8294. props[path] = {};
  8295. props[path][name] = target[name];
  8296. this.attr(props);
  8297. }
  8298. }
  8299. }
  8300. if (propertyCount > 0) {
  8301. this.animate(path, false)
  8302. .when(time == null ? 500 : time, objShallow)
  8303. .delay(delay || 0);
  8304. }
  8305. return this;
  8306. }
  8307. };
  8308. module.exports = Animatable;
  8309. /***/ },
  8310. /* 28 */
  8311. /***/ function(module, exports, __webpack_require__) {
  8312. /**
  8313. * @module echarts/animation/Animator
  8314. */
  8315. var Clip = __webpack_require__(29);
  8316. var color = __webpack_require__(31);
  8317. var util = __webpack_require__(4);
  8318. var isArrayLike = util.isArrayLike;
  8319. var arraySlice = Array.prototype.slice;
  8320. function defaultGetter(target, key) {
  8321. return target[key];
  8322. }
  8323. function defaultSetter(target, key, value) {
  8324. target[key] = value;
  8325. }
  8326. /**
  8327. * @param {number} p0
  8328. * @param {number} p1
  8329. * @param {number} percent
  8330. * @return {number}
  8331. */
  8332. function interpolateNumber(p0, p1, percent) {
  8333. return (p1 - p0) * percent + p0;
  8334. }
  8335. /**
  8336. * @param {string} p0
  8337. * @param {string} p1
  8338. * @param {number} percent
  8339. * @return {string}
  8340. */
  8341. function interpolateString(p0, p1, percent) {
  8342. return percent > 0.5 ? p1 : p0;
  8343. }
  8344. /**
  8345. * @param {Array} p0
  8346. * @param {Array} p1
  8347. * @param {number} percent
  8348. * @param {Array} out
  8349. * @param {number} arrDim
  8350. */
  8351. function interpolateArray(p0, p1, percent, out, arrDim) {
  8352. var len = p0.length;
  8353. if (arrDim == 1) {
  8354. for (var i = 0; i < len; i++) {
  8355. out[i] = interpolateNumber(p0[i], p1[i], percent);
  8356. }
  8357. }
  8358. else {
  8359. var len2 = len && p0[0].length;
  8360. for (var i = 0; i < len; i++) {
  8361. for (var j = 0; j < len2; j++) {
  8362. p0[i] && p1[i] && (out[i][j] = interpolateNumber(
  8363. p0[i][j], p1[i][j], percent
  8364. ));
  8365. }
  8366. }
  8367. }
  8368. }
  8369. // arr0 is source array, arr1 is target array.
  8370. // Do some preprocess to avoid error happened when interpolating from arr0 to arr1
  8371. function fillArr(arr0, arr1, arrDim) {
  8372. var arr0Len = arr0.length;
  8373. var arr1Len = arr1.length;
  8374. if (arr0Len !== arr1Len) {
  8375. // FIXME Not work for TypedArray
  8376. var isPreviousLarger = arr0Len > arr1Len;
  8377. if (isPreviousLarger) {
  8378. // Cut the previous
  8379. arr0.length = arr1Len;
  8380. }
  8381. else {
  8382. // Fill the previous
  8383. for (var i = arr0Len; i < arr1Len; i++) {
  8384. arr0.push(
  8385. arrDim === 1 ? arr1[i] : arraySlice.call(arr1[i])
  8386. );
  8387. }
  8388. }
  8389. }
  8390. // Handling NaN value
  8391. var len2 = arr0[0] && arr0[0].length;
  8392. for (var i = 0; i < arr0.length; i++) {
  8393. if (arrDim === 1) {
  8394. if (isNaN(arr0[i])) {
  8395. arr0[i] = arr1[i];
  8396. }
  8397. }
  8398. else {
  8399. for (var j = 0; j < len2; j++) {
  8400. if (isNaN(arr0[i][j])) {
  8401. arr0[i][j] = arr1[i][j];
  8402. }
  8403. }
  8404. }
  8405. }
  8406. }
  8407. /**
  8408. * @param {Array} arr0
  8409. * @param {Array} arr1
  8410. * @param {number} arrDim
  8411. * @return {boolean}
  8412. */
  8413. function isArraySame(arr0, arr1, arrDim) {
  8414. if (arr0 === arr1) {
  8415. return true;
  8416. }
  8417. var len = arr0.length;
  8418. if (len !== arr1.length) {
  8419. return false;
  8420. }
  8421. if (arrDim === 1) {
  8422. for (var i = 0; i < len; i++) {
  8423. if (arr0[i] !== arr1[i]) {
  8424. return false;
  8425. }
  8426. }
  8427. }
  8428. else {
  8429. var len2 = arr0[0].length;
  8430. for (var i = 0; i < len; i++) {
  8431. for (var j = 0; j < len2; j++) {
  8432. if (arr0[i][j] !== arr1[i][j]) {
  8433. return false;
  8434. }
  8435. }
  8436. }
  8437. }
  8438. return true;
  8439. }
  8440. /**
  8441. * Catmull Rom interpolate array
  8442. * @param {Array} p0
  8443. * @param {Array} p1
  8444. * @param {Array} p2
  8445. * @param {Array} p3
  8446. * @param {number} t
  8447. * @param {number} t2
  8448. * @param {number} t3
  8449. * @param {Array} out
  8450. * @param {number} arrDim
  8451. */
  8452. function catmullRomInterpolateArray(
  8453. p0, p1, p2, p3, t, t2, t3, out, arrDim
  8454. ) {
  8455. var len = p0.length;
  8456. if (arrDim == 1) {
  8457. for (var i = 0; i < len; i++) {
  8458. out[i] = catmullRomInterpolate(
  8459. p0[i], p1[i], p2[i], p3[i], t, t2, t3
  8460. );
  8461. }
  8462. }
  8463. else {
  8464. var len2 = p0[0].length;
  8465. for (var i = 0; i < len; i++) {
  8466. for (var j = 0; j < len2; j++) {
  8467. out[i][j] = catmullRomInterpolate(
  8468. p0[i][j], p1[i][j], p2[i][j], p3[i][j],
  8469. t, t2, t3
  8470. );
  8471. }
  8472. }
  8473. }
  8474. }
  8475. /**
  8476. * Catmull Rom interpolate number
  8477. * @param {number} p0
  8478. * @param {number} p1
  8479. * @param {number} p2
  8480. * @param {number} p3
  8481. * @param {number} t
  8482. * @param {number} t2
  8483. * @param {number} t3
  8484. * @return {number}
  8485. */
  8486. function catmullRomInterpolate(p0, p1, p2, p3, t, t2, t3) {
  8487. var v0 = (p2 - p0) * 0.5;
  8488. var v1 = (p3 - p1) * 0.5;
  8489. return (2 * (p1 - p2) + v0 + v1) * t3
  8490. + (-3 * (p1 - p2) - 2 * v0 - v1) * t2
  8491. + v0 * t + p1;
  8492. }
  8493. function cloneValue(value) {
  8494. if (isArrayLike(value)) {
  8495. var len = value.length;
  8496. if (isArrayLike(value[0])) {
  8497. var ret = [];
  8498. for (var i = 0; i < len; i++) {
  8499. ret.push(arraySlice.call(value[i]));
  8500. }
  8501. return ret;
  8502. }
  8503. return arraySlice.call(value);
  8504. }
  8505. return value;
  8506. }
  8507. function rgba2String(rgba) {
  8508. rgba[0] = Math.floor(rgba[0]);
  8509. rgba[1] = Math.floor(rgba[1]);
  8510. rgba[2] = Math.floor(rgba[2]);
  8511. return 'rgba(' + rgba.join(',') + ')';
  8512. }
  8513. function getArrayDim(keyframes) {
  8514. var lastValue = keyframes[keyframes.length - 1].value;
  8515. return isArrayLike(lastValue && lastValue[0]) ? 2 : 1;
  8516. }
  8517. function createTrackClip (animator, easing, oneTrackDone, keyframes, propName) {
  8518. var getter = animator._getter;
  8519. var setter = animator._setter;
  8520. var useSpline = easing === 'spline';
  8521. var trackLen = keyframes.length;
  8522. if (!trackLen) {
  8523. return;
  8524. }
  8525. // Guess data type
  8526. var firstVal = keyframes[0].value;
  8527. var isValueArray = isArrayLike(firstVal);
  8528. var isValueColor = false;
  8529. var isValueString = false;
  8530. // For vertices morphing
  8531. var arrDim = isValueArray ? getArrayDim(keyframes) : 0;
  8532. var trackMaxTime;
  8533. // Sort keyframe as ascending
  8534. keyframes.sort(function(a, b) {
  8535. return a.time - b.time;
  8536. });
  8537. trackMaxTime = keyframes[trackLen - 1].time;
  8538. // Percents of each keyframe
  8539. var kfPercents = [];
  8540. // Value of each keyframe
  8541. var kfValues = [];
  8542. var prevValue = keyframes[0].value;
  8543. var isAllValueEqual = true;
  8544. for (var i = 0; i < trackLen; i++) {
  8545. kfPercents.push(keyframes[i].time / trackMaxTime);
  8546. // Assume value is a color when it is a string
  8547. var value = keyframes[i].value;
  8548. // Check if value is equal, deep check if value is array
  8549. if (!((isValueArray && isArraySame(value, prevValue, arrDim))
  8550. || (!isValueArray && value === prevValue))) {
  8551. isAllValueEqual = false;
  8552. }
  8553. prevValue = value;
  8554. // Try converting a string to a color array
  8555. if (typeof value == 'string') {
  8556. var colorArray = color.parse(value);
  8557. if (colorArray) {
  8558. value = colorArray;
  8559. isValueColor = true;
  8560. }
  8561. else {
  8562. isValueString = true;
  8563. }
  8564. }
  8565. kfValues.push(value);
  8566. }
  8567. if (isAllValueEqual) {
  8568. return;
  8569. }
  8570. var lastValue = kfValues[trackLen - 1];
  8571. // Polyfill array and NaN value
  8572. for (var i = 0; i < trackLen - 1; i++) {
  8573. if (isValueArray) {
  8574. fillArr(kfValues[i], lastValue, arrDim);
  8575. }
  8576. else {
  8577. if (isNaN(kfValues[i]) && !isNaN(lastValue) && !isValueString && !isValueColor) {
  8578. kfValues[i] = lastValue;
  8579. }
  8580. }
  8581. }
  8582. isValueArray && fillArr(getter(animator._target, propName), lastValue, arrDim);
  8583. // Cache the key of last frame to speed up when
  8584. // animation playback is sequency
  8585. var lastFrame = 0;
  8586. var lastFramePercent = 0;
  8587. var start;
  8588. var w;
  8589. var p0;
  8590. var p1;
  8591. var p2;
  8592. var p3;
  8593. if (isValueColor) {
  8594. var rgba = [0, 0, 0, 0];
  8595. }
  8596. var onframe = function (target, percent) {
  8597. // Find the range keyframes
  8598. // kf1-----kf2---------current--------kf3
  8599. // find kf2 and kf3 and do interpolation
  8600. var frame;
  8601. // In the easing function like elasticOut, percent may less than 0
  8602. if (percent < 0) {
  8603. frame = 0;
  8604. }
  8605. else if (percent < lastFramePercent) {
  8606. // Start from next key
  8607. // PENDING start from lastFrame ?
  8608. start = Math.min(lastFrame + 1, trackLen - 1);
  8609. for (frame = start; frame >= 0; frame--) {
  8610. if (kfPercents[frame] <= percent) {
  8611. break;
  8612. }
  8613. }
  8614. // PENDING really need to do this ?
  8615. frame = Math.min(frame, trackLen - 2);
  8616. }
  8617. else {
  8618. for (frame = lastFrame; frame < trackLen; frame++) {
  8619. if (kfPercents[frame] > percent) {
  8620. break;
  8621. }
  8622. }
  8623. frame = Math.min(frame - 1, trackLen - 2);
  8624. }
  8625. lastFrame = frame;
  8626. lastFramePercent = percent;
  8627. var range = (kfPercents[frame + 1] - kfPercents[frame]);
  8628. if (range === 0) {
  8629. return;
  8630. }
  8631. else {
  8632. w = (percent - kfPercents[frame]) / range;
  8633. }
  8634. if (useSpline) {
  8635. p1 = kfValues[frame];
  8636. p0 = kfValues[frame === 0 ? frame : frame - 1];
  8637. p2 = kfValues[frame > trackLen - 2 ? trackLen - 1 : frame + 1];
  8638. p3 = kfValues[frame > trackLen - 3 ? trackLen - 1 : frame + 2];
  8639. if (isValueArray) {
  8640. catmullRomInterpolateArray(
  8641. p0, p1, p2, p3, w, w * w, w * w * w,
  8642. getter(target, propName),
  8643. arrDim
  8644. );
  8645. }
  8646. else {
  8647. var value;
  8648. if (isValueColor) {
  8649. value = catmullRomInterpolateArray(
  8650. p0, p1, p2, p3, w, w * w, w * w * w,
  8651. rgba, 1
  8652. );
  8653. value = rgba2String(rgba);
  8654. }
  8655. else if (isValueString) {
  8656. // String is step(0.5)
  8657. return interpolateString(p1, p2, w);
  8658. }
  8659. else {
  8660. value = catmullRomInterpolate(
  8661. p0, p1, p2, p3, w, w * w, w * w * w
  8662. );
  8663. }
  8664. setter(
  8665. target,
  8666. propName,
  8667. value
  8668. );
  8669. }
  8670. }
  8671. else {
  8672. if (isValueArray) {
  8673. interpolateArray(
  8674. kfValues[frame], kfValues[frame + 1], w,
  8675. getter(target, propName),
  8676. arrDim
  8677. );
  8678. }
  8679. else {
  8680. var value;
  8681. if (isValueColor) {
  8682. interpolateArray(
  8683. kfValues[frame], kfValues[frame + 1], w,
  8684. rgba, 1
  8685. );
  8686. value = rgba2String(rgba);
  8687. }
  8688. else if (isValueString) {
  8689. // String is step(0.5)
  8690. return interpolateString(kfValues[frame], kfValues[frame + 1], w);
  8691. }
  8692. else {
  8693. value = interpolateNumber(kfValues[frame], kfValues[frame + 1], w);
  8694. }
  8695. setter(
  8696. target,
  8697. propName,
  8698. value
  8699. );
  8700. }
  8701. }
  8702. };
  8703. var clip = new Clip({
  8704. target: animator._target,
  8705. life: trackMaxTime,
  8706. loop: animator._loop,
  8707. delay: animator._delay,
  8708. onframe: onframe,
  8709. ondestroy: oneTrackDone
  8710. });
  8711. if (easing && easing !== 'spline') {
  8712. clip.easing = easing;
  8713. }
  8714. return clip;
  8715. }
  8716. /**
  8717. * @alias module:zrender/animation/Animator
  8718. * @constructor
  8719. * @param {Object} target
  8720. * @param {boolean} loop
  8721. * @param {Function} getter
  8722. * @param {Function} setter
  8723. */
  8724. var Animator = function(target, loop, getter, setter) {
  8725. this._tracks = {};
  8726. this._target = target;
  8727. this._loop = loop || false;
  8728. this._getter = getter || defaultGetter;
  8729. this._setter = setter || defaultSetter;
  8730. this._clipCount = 0;
  8731. this._delay = 0;
  8732. this._doneList = [];
  8733. this._onframeList = [];
  8734. this._clipList = [];
  8735. };
  8736. Animator.prototype = {
  8737. /**
  8738. * 设置动画关键帧
  8739. * @param {number} time 关键帧时间,单位是ms
  8740. * @param {Object} props 关键帧的属性值,key-value表示
  8741. * @return {module:zrender/animation/Animator}
  8742. */
  8743. when: function(time /* ms */, props) {
  8744. var tracks = this._tracks;
  8745. for (var propName in props) {
  8746. if (!props.hasOwnProperty(propName)) {
  8747. continue;
  8748. }
  8749. if (!tracks[propName]) {
  8750. tracks[propName] = [];
  8751. // Invalid value
  8752. var value = this._getter(this._target, propName);
  8753. if (value == null) {
  8754. // zrLog('Invalid property ' + propName);
  8755. continue;
  8756. }
  8757. // If time is 0
  8758. // Then props is given initialize value
  8759. // Else
  8760. // Initialize value from current prop value
  8761. if (time !== 0) {
  8762. tracks[propName].push({
  8763. time: 0,
  8764. value: cloneValue(value)
  8765. });
  8766. }
  8767. }
  8768. tracks[propName].push({
  8769. time: time,
  8770. value: props[propName]
  8771. });
  8772. }
  8773. return this;
  8774. },
  8775. /**
  8776. * 添加动画每一帧的回调函数
  8777. * @param {Function} callback
  8778. * @return {module:zrender/animation/Animator}
  8779. */
  8780. during: function (callback) {
  8781. this._onframeList.push(callback);
  8782. return this;
  8783. },
  8784. pause: function () {
  8785. for (var i = 0; i < this._clipList.length; i++) {
  8786. this._clipList[i].pause();
  8787. }
  8788. this._paused = true;
  8789. },
  8790. resume: function () {
  8791. for (var i = 0; i < this._clipList.length; i++) {
  8792. this._clipList[i].resume();
  8793. }
  8794. this._paused = false;
  8795. },
  8796. isPaused: function () {
  8797. return !!this._paused;
  8798. },
  8799. _doneCallback: function () {
  8800. // Clear all tracks
  8801. this._tracks = {};
  8802. // Clear all clips
  8803. this._clipList.length = 0;
  8804. var doneList = this._doneList;
  8805. var len = doneList.length;
  8806. for (var i = 0; i < len; i++) {
  8807. doneList[i].call(this);
  8808. }
  8809. },
  8810. /**
  8811. * 开始执行动画
  8812. * @param {string|Function} easing
  8813. * 动画缓动函数,详见{@link module:zrender/animation/easing}
  8814. * @return {module:zrender/animation/Animator}
  8815. */
  8816. start: function (easing) {
  8817. var self = this;
  8818. var clipCount = 0;
  8819. var oneTrackDone = function() {
  8820. clipCount--;
  8821. if (!clipCount) {
  8822. self._doneCallback();
  8823. }
  8824. };
  8825. var lastClip;
  8826. for (var propName in this._tracks) {
  8827. if (!this._tracks.hasOwnProperty(propName)) {
  8828. continue;
  8829. }
  8830. var clip = createTrackClip(
  8831. this, easing, oneTrackDone,
  8832. this._tracks[propName], propName
  8833. );
  8834. if (clip) {
  8835. this._clipList.push(clip);
  8836. clipCount++;
  8837. // If start after added to animation
  8838. if (this.animation) {
  8839. this.animation.addClip(clip);
  8840. }
  8841. lastClip = clip;
  8842. }
  8843. }
  8844. // Add during callback on the last clip
  8845. if (lastClip) {
  8846. var oldOnFrame = lastClip.onframe;
  8847. lastClip.onframe = function (target, percent) {
  8848. oldOnFrame(target, percent);
  8849. for (var i = 0; i < self._onframeList.length; i++) {
  8850. self._onframeList[i](target, percent);
  8851. }
  8852. };
  8853. }
  8854. if (!clipCount) {
  8855. this._doneCallback();
  8856. }
  8857. return this;
  8858. },
  8859. /**
  8860. * 停止动画
  8861. * @param {boolean} forwardToLast If move to last frame before stop
  8862. */
  8863. stop: function (forwardToLast) {
  8864. var clipList = this._clipList;
  8865. var animation = this.animation;
  8866. for (var i = 0; i < clipList.length; i++) {
  8867. var clip = clipList[i];
  8868. if (forwardToLast) {
  8869. // Move to last frame before stop
  8870. clip.onframe(this._target, 1);
  8871. }
  8872. animation && animation.removeClip(clip);
  8873. }
  8874. clipList.length = 0;
  8875. },
  8876. /**
  8877. * 设置动画延迟开始的时间
  8878. * @param {number} time 单位ms
  8879. * @return {module:zrender/animation/Animator}
  8880. */
  8881. delay: function (time) {
  8882. this._delay = time;
  8883. return this;
  8884. },
  8885. /**
  8886. * 添加动画结束的回调
  8887. * @param {Function} cb
  8888. * @return {module:zrender/animation/Animator}
  8889. */
  8890. done: function(cb) {
  8891. if (cb) {
  8892. this._doneList.push(cb);
  8893. }
  8894. return this;
  8895. },
  8896. /**
  8897. * @return {Array.<module:zrender/animation/Clip>}
  8898. */
  8899. getClips: function () {
  8900. return this._clipList;
  8901. }
  8902. };
  8903. module.exports = Animator;
  8904. /***/ },
  8905. /* 29 */
  8906. /***/ function(module, exports, __webpack_require__) {
  8907. /**
  8908. * 动画主控制器
  8909. * @config target 动画对象,可以是数组,如果是数组的话会批量分发onframe等事件
  8910. * @config life(1000) 动画时长
  8911. * @config delay(0) 动画延迟时间
  8912. * @config loop(true)
  8913. * @config gap(0) 循环的间隔时间
  8914. * @config onframe
  8915. * @config easing(optional)
  8916. * @config ondestroy(optional)
  8917. * @config onrestart(optional)
  8918. *
  8919. * TODO pause
  8920. */
  8921. var easingFuncs = __webpack_require__(30);
  8922. function Clip(options) {
  8923. this._target = options.target;
  8924. // 生命周期
  8925. this._life = options.life || 1000;
  8926. // 延时
  8927. this._delay = options.delay || 0;
  8928. // 开始时间
  8929. // this._startTime = new Date().getTime() + this._delay;// 单位毫秒
  8930. this._initialized = false;
  8931. // 是否循环
  8932. this.loop = options.loop == null ? false : options.loop;
  8933. this.gap = options.gap || 0;
  8934. this.easing = options.easing || 'Linear';
  8935. this.onframe = options.onframe;
  8936. this.ondestroy = options.ondestroy;
  8937. this.onrestart = options.onrestart;
  8938. this._pausedTime = 0;
  8939. this._paused = false;
  8940. }
  8941. Clip.prototype = {
  8942. constructor: Clip,
  8943. step: function (globalTime, deltaTime) {
  8944. // Set startTime on first step, or _startTime may has milleseconds different between clips
  8945. // PENDING
  8946. if (!this._initialized) {
  8947. this._startTime = globalTime + this._delay;
  8948. this._initialized = true;
  8949. }
  8950. if (this._paused) {
  8951. this._pausedTime += deltaTime;
  8952. return;
  8953. }
  8954. var percent = (globalTime - this._startTime - this._pausedTime) / this._life;
  8955. // 还没开始
  8956. if (percent < 0) {
  8957. return;
  8958. }
  8959. percent = Math.min(percent, 1);
  8960. var easing = this.easing;
  8961. var easingFunc = typeof easing == 'string' ? easingFuncs[easing] : easing;
  8962. var schedule = typeof easingFunc === 'function'
  8963. ? easingFunc(percent)
  8964. : percent;
  8965. this.fire('frame', schedule);
  8966. // 结束
  8967. if (percent == 1) {
  8968. if (this.loop) {
  8969. this.restart (globalTime);
  8970. // 重新开始周期
  8971. // 抛出而不是直接调用事件直到 stage.update 后再统一调用这些事件
  8972. return 'restart';
  8973. }
  8974. // 动画完成将这个控制器标识为待删除
  8975. // 在Animation.update中进行批量删除
  8976. this._needsRemove = true;
  8977. return 'destroy';
  8978. }
  8979. return null;
  8980. },
  8981. restart: function (globalTime) {
  8982. var remainder = (globalTime - this._startTime - this._pausedTime) % this._life;
  8983. this._startTime = globalTime - remainder + this.gap;
  8984. this._pausedTime = 0;
  8985. this._needsRemove = false;
  8986. },
  8987. fire: function (eventType, arg) {
  8988. eventType = 'on' + eventType;
  8989. if (this[eventType]) {
  8990. this[eventType](this._target, arg);
  8991. }
  8992. },
  8993. pause: function () {
  8994. this._paused = true;
  8995. },
  8996. resume: function () {
  8997. this._paused = false;
  8998. }
  8999. };
  9000. module.exports = Clip;
  9001. /***/ },
  9002. /* 30 */
  9003. /***/ function(module, exports) {
  9004. /**
  9005. * 缓动代码来自 https://github.com/sole/tween.js/blob/master/src/Tween.js
  9006. * @see http://sole.github.io/tween.js/examples/03_graphs.html
  9007. * @exports zrender/animation/easing
  9008. */
  9009. var easing = {
  9010. /**
  9011. * @param {number} k
  9012. * @return {number}
  9013. */
  9014. linear: function (k) {
  9015. return k;
  9016. },
  9017. /**
  9018. * @param {number} k
  9019. * @return {number}
  9020. */
  9021. quadraticIn: function (k) {
  9022. return k * k;
  9023. },
  9024. /**
  9025. * @param {number} k
  9026. * @return {number}
  9027. */
  9028. quadraticOut: function (k) {
  9029. return k * (2 - k);
  9030. },
  9031. /**
  9032. * @param {number} k
  9033. * @return {number}
  9034. */
  9035. quadraticInOut: function (k) {
  9036. if ((k *= 2) < 1) {
  9037. return 0.5 * k * k;
  9038. }
  9039. return -0.5 * (--k * (k - 2) - 1);
  9040. },
  9041. // 三次方的缓动(t^3)
  9042. /**
  9043. * @param {number} k
  9044. * @return {number}
  9045. */
  9046. cubicIn: function (k) {
  9047. return k * k * k;
  9048. },
  9049. /**
  9050. * @param {number} k
  9051. * @return {number}
  9052. */
  9053. cubicOut: function (k) {
  9054. return --k * k * k + 1;
  9055. },
  9056. /**
  9057. * @param {number} k
  9058. * @return {number}
  9059. */
  9060. cubicInOut: function (k) {
  9061. if ((k *= 2) < 1) {
  9062. return 0.5 * k * k * k;
  9063. }
  9064. return 0.5 * ((k -= 2) * k * k + 2);
  9065. },
  9066. // 四次方的缓动(t^4)
  9067. /**
  9068. * @param {number} k
  9069. * @return {number}
  9070. */
  9071. quarticIn: function (k) {
  9072. return k * k * k * k;
  9073. },
  9074. /**
  9075. * @param {number} k
  9076. * @return {number}
  9077. */
  9078. quarticOut: function (k) {
  9079. return 1 - (--k * k * k * k);
  9080. },
  9081. /**
  9082. * @param {number} k
  9083. * @return {number}
  9084. */
  9085. quarticInOut: function (k) {
  9086. if ((k *= 2) < 1) {
  9087. return 0.5 * k * k * k * k;
  9088. }
  9089. return -0.5 * ((k -= 2) * k * k * k - 2);
  9090. },
  9091. // 五次方的缓动(t^5)
  9092. /**
  9093. * @param {number} k
  9094. * @return {number}
  9095. */
  9096. quinticIn: function (k) {
  9097. return k * k * k * k * k;
  9098. },
  9099. /**
  9100. * @param {number} k
  9101. * @return {number}
  9102. */
  9103. quinticOut: function (k) {
  9104. return --k * k * k * k * k + 1;
  9105. },
  9106. /**
  9107. * @param {number} k
  9108. * @return {number}
  9109. */
  9110. quinticInOut: function (k) {
  9111. if ((k *= 2) < 1) {
  9112. return 0.5 * k * k * k * k * k;
  9113. }
  9114. return 0.5 * ((k -= 2) * k * k * k * k + 2);
  9115. },
  9116. // 正弦曲线的缓动(sin(t))
  9117. /**
  9118. * @param {number} k
  9119. * @return {number}
  9120. */
  9121. sinusoidalIn: function (k) {
  9122. return 1 - Math.cos(k * Math.PI / 2);
  9123. },
  9124. /**
  9125. * @param {number} k
  9126. * @return {number}
  9127. */
  9128. sinusoidalOut: function (k) {
  9129. return Math.sin(k * Math.PI / 2);
  9130. },
  9131. /**
  9132. * @param {number} k
  9133. * @return {number}
  9134. */
  9135. sinusoidalInOut: function (k) {
  9136. return 0.5 * (1 - Math.cos(Math.PI * k));
  9137. },
  9138. // 指数曲线的缓动(2^t)
  9139. /**
  9140. * @param {number} k
  9141. * @return {number}
  9142. */
  9143. exponentialIn: function (k) {
  9144. return k === 0 ? 0 : Math.pow(1024, k - 1);
  9145. },
  9146. /**
  9147. * @param {number} k
  9148. * @return {number}
  9149. */
  9150. exponentialOut: function (k) {
  9151. return k === 1 ? 1 : 1 - Math.pow(2, -10 * k);
  9152. },
  9153. /**
  9154. * @param {number} k
  9155. * @return {number}
  9156. */
  9157. exponentialInOut: function (k) {
  9158. if (k === 0) {
  9159. return 0;
  9160. }
  9161. if (k === 1) {
  9162. return 1;
  9163. }
  9164. if ((k *= 2) < 1) {
  9165. return 0.5 * Math.pow(1024, k - 1);
  9166. }
  9167. return 0.5 * (-Math.pow(2, -10 * (k - 1)) + 2);
  9168. },
  9169. // 圆形曲线的缓动(sqrt(1-t^2))
  9170. /**
  9171. * @param {number} k
  9172. * @return {number}
  9173. */
  9174. circularIn: function (k) {
  9175. return 1 - Math.sqrt(1 - k * k);
  9176. },
  9177. /**
  9178. * @param {number} k
  9179. * @return {number}
  9180. */
  9181. circularOut: function (k) {
  9182. return Math.sqrt(1 - (--k * k));
  9183. },
  9184. /**
  9185. * @param {number} k
  9186. * @return {number}
  9187. */
  9188. circularInOut: function (k) {
  9189. if ((k *= 2) < 1) {
  9190. return -0.5 * (Math.sqrt(1 - k * k) - 1);
  9191. }
  9192. return 0.5 * (Math.sqrt(1 - (k -= 2) * k) + 1);
  9193. },
  9194. // 创建类似于弹簧在停止前来回振荡的动画
  9195. /**
  9196. * @param {number} k
  9197. * @return {number}
  9198. */
  9199. elasticIn: function (k) {
  9200. var s;
  9201. var a = 0.1;
  9202. var p = 0.4;
  9203. if (k === 0) {
  9204. return 0;
  9205. }
  9206. if (k === 1) {
  9207. return 1;
  9208. }
  9209. if (!a || a < 1) {
  9210. a = 1; s = p / 4;
  9211. }
  9212. else {
  9213. s = p * Math.asin(1 / a) / (2 * Math.PI);
  9214. }
  9215. return -(a * Math.pow(2, 10 * (k -= 1)) *
  9216. Math.sin((k - s) * (2 * Math.PI) / p));
  9217. },
  9218. /**
  9219. * @param {number} k
  9220. * @return {number}
  9221. */
  9222. elasticOut: function (k) {
  9223. var s;
  9224. var a = 0.1;
  9225. var p = 0.4;
  9226. if (k === 0) {
  9227. return 0;
  9228. }
  9229. if (k === 1) {
  9230. return 1;
  9231. }
  9232. if (!a || a < 1) {
  9233. a = 1; s = p / 4;
  9234. }
  9235. else {
  9236. s = p * Math.asin(1 / a) / (2 * Math.PI);
  9237. }
  9238. return (a * Math.pow(2, -10 * k) *
  9239. Math.sin((k - s) * (2 * Math.PI) / p) + 1);
  9240. },
  9241. /**
  9242. * @param {number} k
  9243. * @return {number}
  9244. */
  9245. elasticInOut: function (k) {
  9246. var s;
  9247. var a = 0.1;
  9248. var p = 0.4;
  9249. if (k === 0) {
  9250. return 0;
  9251. }
  9252. if (k === 1) {
  9253. return 1;
  9254. }
  9255. if (!a || a < 1) {
  9256. a = 1; s = p / 4;
  9257. }
  9258. else {
  9259. s = p * Math.asin(1 / a) / (2 * Math.PI);
  9260. }
  9261. if ((k *= 2) < 1) {
  9262. return -0.5 * (a * Math.pow(2, 10 * (k -= 1))
  9263. * Math.sin((k - s) * (2 * Math.PI) / p));
  9264. }
  9265. return a * Math.pow(2, -10 * (k -= 1))
  9266. * Math.sin((k - s) * (2 * Math.PI) / p) * 0.5 + 1;
  9267. },
  9268. // 在某一动画开始沿指示的路径进行动画处理前稍稍收回该动画的移动
  9269. /**
  9270. * @param {number} k
  9271. * @return {number}
  9272. */
  9273. backIn: function (k) {
  9274. var s = 1.70158;
  9275. return k * k * ((s + 1) * k - s);
  9276. },
  9277. /**
  9278. * @param {number} k
  9279. * @return {number}
  9280. */
  9281. backOut: function (k) {
  9282. var s = 1.70158;
  9283. return --k * k * ((s + 1) * k + s) + 1;
  9284. },
  9285. /**
  9286. * @param {number} k
  9287. * @return {number}
  9288. */
  9289. backInOut: function (k) {
  9290. var s = 1.70158 * 1.525;
  9291. if ((k *= 2) < 1) {
  9292. return 0.5 * (k * k * ((s + 1) * k - s));
  9293. }
  9294. return 0.5 * ((k -= 2) * k * ((s + 1) * k + s) + 2);
  9295. },
  9296. // 创建弹跳效果
  9297. /**
  9298. * @param {number} k
  9299. * @return {number}
  9300. */
  9301. bounceIn: function (k) {
  9302. return 1 - easing.bounceOut(1 - k);
  9303. },
  9304. /**
  9305. * @param {number} k
  9306. * @return {number}
  9307. */
  9308. bounceOut: function (k) {
  9309. if (k < (1 / 2.75)) {
  9310. return 7.5625 * k * k;
  9311. }
  9312. else if (k < (2 / 2.75)) {
  9313. return 7.5625 * (k -= (1.5 / 2.75)) * k + 0.75;
  9314. }
  9315. else if (k < (2.5 / 2.75)) {
  9316. return 7.5625 * (k -= (2.25 / 2.75)) * k + 0.9375;
  9317. }
  9318. else {
  9319. return 7.5625 * (k -= (2.625 / 2.75)) * k + 0.984375;
  9320. }
  9321. },
  9322. /**
  9323. * @param {number} k
  9324. * @return {number}
  9325. */
  9326. bounceInOut: function (k) {
  9327. if (k < 0.5) {
  9328. return easing.bounceIn(k * 2) * 0.5;
  9329. }
  9330. return easing.bounceOut(k * 2 - 1) * 0.5 + 0.5;
  9331. }
  9332. };
  9333. module.exports = easing;
  9334. /***/ },
  9335. /* 31 */
  9336. /***/ function(module, exports, __webpack_require__) {
  9337. /**
  9338. * @module zrender/tool/color
  9339. */
  9340. var LRU = __webpack_require__(32);
  9341. var kCSSColorTable = {
  9342. 'transparent': [0,0,0,0], 'aliceblue': [240,248,255,1],
  9343. 'antiquewhite': [250,235,215,1], 'aqua': [0,255,255,1],
  9344. 'aquamarine': [127,255,212,1], 'azure': [240,255,255,1],
  9345. 'beige': [245,245,220,1], 'bisque': [255,228,196,1],
  9346. 'black': [0,0,0,1], 'blanchedalmond': [255,235,205,1],
  9347. 'blue': [0,0,255,1], 'blueviolet': [138,43,226,1],
  9348. 'brown': [165,42,42,1], 'burlywood': [222,184,135,1],
  9349. 'cadetblue': [95,158,160,1], 'chartreuse': [127,255,0,1],
  9350. 'chocolate': [210,105,30,1], 'coral': [255,127,80,1],
  9351. 'cornflowerblue': [100,149,237,1], 'cornsilk': [255,248,220,1],
  9352. 'crimson': [220,20,60,1], 'cyan': [0,255,255,1],
  9353. 'darkblue': [0,0,139,1], 'darkcyan': [0,139,139,1],
  9354. 'darkgoldenrod': [184,134,11,1], 'darkgray': [169,169,169,1],
  9355. 'darkgreen': [0,100,0,1], 'darkgrey': [169,169,169,1],
  9356. 'darkkhaki': [189,183,107,1], 'darkmagenta': [139,0,139,1],
  9357. 'darkolivegreen': [85,107,47,1], 'darkorange': [255,140,0,1],
  9358. 'darkorchid': [153,50,204,1], 'darkred': [139,0,0,1],
  9359. 'darksalmon': [233,150,122,1], 'darkseagreen': [143,188,143,1],
  9360. 'darkslateblue': [72,61,139,1], 'darkslategray': [47,79,79,1],
  9361. 'darkslategrey': [47,79,79,1], 'darkturquoise': [0,206,209,1],
  9362. 'darkviolet': [148,0,211,1], 'deeppink': [255,20,147,1],
  9363. 'deepskyblue': [0,191,255,1], 'dimgray': [105,105,105,1],
  9364. 'dimgrey': [105,105,105,1], 'dodgerblue': [30,144,255,1],
  9365. 'firebrick': [178,34,34,1], 'floralwhite': [255,250,240,1],
  9366. 'forestgreen': [34,139,34,1], 'fuchsia': [255,0,255,1],
  9367. 'gainsboro': [220,220,220,1], 'ghostwhite': [248,248,255,1],
  9368. 'gold': [255,215,0,1], 'goldenrod': [218,165,32,1],
  9369. 'gray': [128,128,128,1], 'green': [0,128,0,1],
  9370. 'greenyellow': [173,255,47,1], 'grey': [128,128,128,1],
  9371. 'honeydew': [240,255,240,1], 'hotpink': [255,105,180,1],
  9372. 'indianred': [205,92,92,1], 'indigo': [75,0,130,1],
  9373. 'ivory': [255,255,240,1], 'khaki': [240,230,140,1],
  9374. 'lavender': [230,230,250,1], 'lavenderblush': [255,240,245,1],
  9375. 'lawngreen': [124,252,0,1], 'lemonchiffon': [255,250,205,1],
  9376. 'lightblue': [173,216,230,1], 'lightcoral': [240,128,128,1],
  9377. 'lightcyan': [224,255,255,1], 'lightgoldenrodyellow': [250,250,210,1],
  9378. 'lightgray': [211,211,211,1], 'lightgreen': [144,238,144,1],
  9379. 'lightgrey': [211,211,211,1], 'lightpink': [255,182,193,1],
  9380. 'lightsalmon': [255,160,122,1], 'lightseagreen': [32,178,170,1],
  9381. 'lightskyblue': [135,206,250,1], 'lightslategray': [119,136,153,1],
  9382. 'lightslategrey': [119,136,153,1], 'lightsteelblue': [176,196,222,1],
  9383. 'lightyellow': [255,255,224,1], 'lime': [0,255,0,1],
  9384. 'limegreen': [50,205,50,1], 'linen': [250,240,230,1],
  9385. 'magenta': [255,0,255,1], 'maroon': [128,0,0,1],
  9386. 'mediumaquamarine': [102,205,170,1], 'mediumblue': [0,0,205,1],
  9387. 'mediumorchid': [186,85,211,1], 'mediumpurple': [147,112,219,1],
  9388. 'mediumseagreen': [60,179,113,1], 'mediumslateblue': [123,104,238,1],
  9389. 'mediumspringgreen': [0,250,154,1], 'mediumturquoise': [72,209,204,1],
  9390. 'mediumvioletred': [199,21,133,1], 'midnightblue': [25,25,112,1],
  9391. 'mintcream': [245,255,250,1], 'mistyrose': [255,228,225,1],
  9392. 'moccasin': [255,228,181,1], 'navajowhite': [255,222,173,1],
  9393. 'navy': [0,0,128,1], 'oldlace': [253,245,230,1],
  9394. 'olive': [128,128,0,1], 'olivedrab': [107,142,35,1],
  9395. 'orange': [255,165,0,1], 'orangered': [255,69,0,1],
  9396. 'orchid': [218,112,214,1], 'palegoldenrod': [238,232,170,1],
  9397. 'palegreen': [152,251,152,1], 'paleturquoise': [175,238,238,1],
  9398. 'palevioletred': [219,112,147,1], 'papayawhip': [255,239,213,1],
  9399. 'peachpuff': [255,218,185,1], 'peru': [205,133,63,1],
  9400. 'pink': [255,192,203,1], 'plum': [221,160,221,1],
  9401. 'powderblue': [176,224,230,1], 'purple': [128,0,128,1],
  9402. 'red': [255,0,0,1], 'rosybrown': [188,143,143,1],
  9403. 'royalblue': [65,105,225,1], 'saddlebrown': [139,69,19,1],
  9404. 'salmon': [250,128,114,1], 'sandybrown': [244,164,96,1],
  9405. 'seagreen': [46,139,87,1], 'seashell': [255,245,238,1],
  9406. 'sienna': [160,82,45,1], 'silver': [192,192,192,1],
  9407. 'skyblue': [135,206,235,1], 'slateblue': [106,90,205,1],
  9408. 'slategray': [112,128,144,1], 'slategrey': [112,128,144,1],
  9409. 'snow': [255,250,250,1], 'springgreen': [0,255,127,1],
  9410. 'steelblue': [70,130,180,1], 'tan': [210,180,140,1],
  9411. 'teal': [0,128,128,1], 'thistle': [216,191,216,1],
  9412. 'tomato': [255,99,71,1], 'turquoise': [64,224,208,1],
  9413. 'violet': [238,130,238,1], 'wheat': [245,222,179,1],
  9414. 'white': [255,255,255,1], 'whitesmoke': [245,245,245,1],
  9415. 'yellow': [255,255,0,1], 'yellowgreen': [154,205,50,1]
  9416. };
  9417. function clampCssByte(i) { // Clamp to integer 0 .. 255.
  9418. i = Math.round(i); // Seems to be what Chrome does (vs truncation).
  9419. return i < 0 ? 0 : i > 255 ? 255 : i;
  9420. }
  9421. function clampCssAngle(i) { // Clamp to integer 0 .. 360.
  9422. i = Math.round(i); // Seems to be what Chrome does (vs truncation).
  9423. return i < 0 ? 0 : i > 360 ? 360 : i;
  9424. }
  9425. function clampCssFloat(f) { // Clamp to float 0.0 .. 1.0.
  9426. return f < 0 ? 0 : f > 1 ? 1 : f;
  9427. }
  9428. function parseCssInt(str) { // int or percentage.
  9429. if (str.length && str.charAt(str.length - 1) === '%') {
  9430. return clampCssByte(parseFloat(str) / 100 * 255);
  9431. }
  9432. return clampCssByte(parseInt(str, 10));
  9433. }
  9434. function parseCssFloat(str) { // float or percentage.
  9435. if (str.length && str.charAt(str.length - 1) === '%') {
  9436. return clampCssFloat(parseFloat(str) / 100);
  9437. }
  9438. return clampCssFloat(parseFloat(str));
  9439. }
  9440. function cssHueToRgb(m1, m2, h) {
  9441. if (h < 0) {
  9442. h += 1;
  9443. }
  9444. else if (h > 1) {
  9445. h -= 1;
  9446. }
  9447. if (h * 6 < 1) {
  9448. return m1 + (m2 - m1) * h * 6;
  9449. }
  9450. if (h * 2 < 1) {
  9451. return m2;
  9452. }
  9453. if (h * 3 < 2) {
  9454. return m1 + (m2 - m1) * (2/3 - h) * 6;
  9455. }
  9456. return m1;
  9457. }
  9458. function lerp(a, b, p) {
  9459. return a + (b - a) * p;
  9460. }
  9461. function setRgba(out, r, g, b, a) {
  9462. out[0] = r; out[1] = g; out[2] = b; out[3] = a;
  9463. return out;
  9464. }
  9465. function copyRgba(out, a) {
  9466. out[0] = a[0]; out[1] = a[1]; out[2] = a[2]; out[3] = a[3];
  9467. return out;
  9468. }
  9469. var colorCache = new LRU(20);
  9470. var lastRemovedArr = null;
  9471. function putToCache(colorStr, rgbaArr) {
  9472. // Reuse removed array
  9473. if (lastRemovedArr) {
  9474. copyRgba(lastRemovedArr, rgbaArr);
  9475. }
  9476. lastRemovedArr = colorCache.put(colorStr, lastRemovedArr || (rgbaArr.slice()));
  9477. }
  9478. /**
  9479. * @param {string} colorStr
  9480. * @param {Array.<number>} out
  9481. * @return {Array.<number>}
  9482. * @memberOf module:zrender/util/color
  9483. */
  9484. function parse(colorStr, rgbaArr) {
  9485. if (!colorStr) {
  9486. return;
  9487. }
  9488. rgbaArr = rgbaArr || [];
  9489. var cached = colorCache.get(colorStr);
  9490. if (cached) {
  9491. return copyRgba(rgbaArr, cached);
  9492. }
  9493. // colorStr may be not string
  9494. colorStr = colorStr + '';
  9495. // Remove all whitespace, not compliant, but should just be more accepting.
  9496. var str = colorStr.replace(/ /g, '').toLowerCase();
  9497. // Color keywords (and transparent) lookup.
  9498. if (str in kCSSColorTable) {
  9499. copyRgba(rgbaArr, kCSSColorTable[str]);
  9500. putToCache(colorStr, rgbaArr);
  9501. return rgbaArr;
  9502. }
  9503. // #abc and #abc123 syntax.
  9504. if (str.charAt(0) === '#') {
  9505. if (str.length === 4) {
  9506. var iv = parseInt(str.substr(1), 16); // TODO(deanm): Stricter parsing.
  9507. if (!(iv >= 0 && iv <= 0xfff)) {
  9508. setRgba(rgbaArr, 0, 0, 0, 1);
  9509. return; // Covers NaN.
  9510. }
  9511. setRgba(rgbaArr,
  9512. ((iv & 0xf00) >> 4) | ((iv & 0xf00) >> 8),
  9513. (iv & 0xf0) | ((iv & 0xf0) >> 4),
  9514. (iv & 0xf) | ((iv & 0xf) << 4),
  9515. 1
  9516. );
  9517. putToCache(colorStr, rgbaArr);
  9518. return rgbaArr;
  9519. }
  9520. else if (str.length === 7) {
  9521. var iv = parseInt(str.substr(1), 16); // TODO(deanm): Stricter parsing.
  9522. if (!(iv >= 0 && iv <= 0xffffff)) {
  9523. setRgba(rgbaArr, 0, 0, 0, 1);
  9524. return; // Covers NaN.
  9525. }
  9526. setRgba(rgbaArr,
  9527. (iv & 0xff0000) >> 16,
  9528. (iv & 0xff00) >> 8,
  9529. iv & 0xff,
  9530. 1
  9531. );
  9532. putToCache(colorStr, rgbaArr);
  9533. return rgbaArr;
  9534. }
  9535. return;
  9536. }
  9537. var op = str.indexOf('('), ep = str.indexOf(')');
  9538. if (op !== -1 && ep + 1 === str.length) {
  9539. var fname = str.substr(0, op);
  9540. var params = str.substr(op + 1, ep - (op + 1)).split(',');
  9541. var alpha = 1; // To allow case fallthrough.
  9542. switch (fname) {
  9543. case 'rgba':
  9544. if (params.length !== 4) {
  9545. setRgba(rgbaArr, 0, 0, 0, 1);
  9546. return;
  9547. }
  9548. alpha = parseCssFloat(params.pop()); // jshint ignore:line
  9549. // Fall through.
  9550. case 'rgb':
  9551. if (params.length !== 3) {
  9552. setRgba(rgbaArr, 0, 0, 0, 1);
  9553. return;
  9554. }
  9555. setRgba(rgbaArr,
  9556. parseCssInt(params[0]),
  9557. parseCssInt(params[1]),
  9558. parseCssInt(params[2]),
  9559. alpha
  9560. );
  9561. putToCache(colorStr, rgbaArr);
  9562. return rgbaArr;
  9563. case 'hsla':
  9564. if (params.length !== 4) {
  9565. setRgba(rgbaArr, 0, 0, 0, 1);
  9566. return;
  9567. }
  9568. params[3] = parseCssFloat(params[3]);
  9569. hsla2rgba(params, rgbaArr);
  9570. putToCache(colorStr, rgbaArr);
  9571. return rgbaArr;
  9572. case 'hsl':
  9573. if (params.length !== 3) {
  9574. setRgba(rgbaArr, 0, 0, 0, 1);
  9575. return;
  9576. }
  9577. hsla2rgba(params, rgbaArr);
  9578. putToCache(colorStr, rgbaArr);
  9579. return rgbaArr;
  9580. default:
  9581. return;
  9582. }
  9583. }
  9584. setRgba(rgbaArr, 0, 0, 0, 1);
  9585. return;
  9586. }
  9587. /**
  9588. * @param {Array.<number>} hsla
  9589. * @param {Array.<number>} rgba
  9590. * @return {Array.<number>} rgba
  9591. */
  9592. function hsla2rgba(hsla, rgba) {
  9593. var h = (((parseFloat(hsla[0]) % 360) + 360) % 360) / 360; // 0 .. 1
  9594. // NOTE(deanm): According to the CSS spec s/l should only be
  9595. // percentages, but we don't bother and let float or percentage.
  9596. var s = parseCssFloat(hsla[1]);
  9597. var l = parseCssFloat(hsla[2]);
  9598. var m2 = l <= 0.5 ? l * (s + 1) : l + s - l * s;
  9599. var m1 = l * 2 - m2;
  9600. rgba = rgba || [];
  9601. setRgba(rgba,
  9602. clampCssByte(cssHueToRgb(m1, m2, h + 1 / 3) * 255),
  9603. clampCssByte(cssHueToRgb(m1, m2, h) * 255),
  9604. clampCssByte(cssHueToRgb(m1, m2, h - 1 / 3) * 255),
  9605. 1
  9606. );
  9607. if (hsla.length === 4) {
  9608. rgba[3] = hsla[3];
  9609. }
  9610. return rgba;
  9611. }
  9612. /**
  9613. * @param {Array.<number>} rgba
  9614. * @return {Array.<number>} hsla
  9615. */
  9616. function rgba2hsla(rgba) {
  9617. if (!rgba) {
  9618. return;
  9619. }
  9620. // RGB from 0 to 255
  9621. var R = rgba[0] / 255;
  9622. var G = rgba[1] / 255;
  9623. var B = rgba[2] / 255;
  9624. var vMin = Math.min(R, G, B); // Min. value of RGB
  9625. var vMax = Math.max(R, G, B); // Max. value of RGB
  9626. var delta = vMax - vMin; // Delta RGB value
  9627. var L = (vMax + vMin) / 2;
  9628. var H;
  9629. var S;
  9630. // HSL results from 0 to 1
  9631. if (delta === 0) {
  9632. H = 0;
  9633. S = 0;
  9634. }
  9635. else {
  9636. if (L < 0.5) {
  9637. S = delta / (vMax + vMin);
  9638. }
  9639. else {
  9640. S = delta / (2 - vMax - vMin);
  9641. }
  9642. var deltaR = (((vMax - R) / 6) + (delta / 2)) / delta;
  9643. var deltaG = (((vMax - G) / 6) + (delta / 2)) / delta;
  9644. var deltaB = (((vMax - B) / 6) + (delta / 2)) / delta;
  9645. if (R === vMax) {
  9646. H = deltaB - deltaG;
  9647. }
  9648. else if (G === vMax) {
  9649. H = (1 / 3) + deltaR - deltaB;
  9650. }
  9651. else if (B === vMax) {
  9652. H = (2 / 3) + deltaG - deltaR;
  9653. }
  9654. if (H < 0) {
  9655. H += 1;
  9656. }
  9657. if (H > 1) {
  9658. H -= 1;
  9659. }
  9660. }
  9661. var hsla = [H * 360, S, L];
  9662. if (rgba[3] != null) {
  9663. hsla.push(rgba[3]);
  9664. }
  9665. return hsla;
  9666. }
  9667. /**
  9668. * @param {string} color
  9669. * @param {number} level
  9670. * @return {string}
  9671. * @memberOf module:zrender/util/color
  9672. */
  9673. function lift(color, level) {
  9674. var colorArr = parse(color);
  9675. if (colorArr) {
  9676. for (var i = 0; i < 3; i++) {
  9677. if (level < 0) {
  9678. colorArr[i] = colorArr[i] * (1 - level) | 0;
  9679. }
  9680. else {
  9681. colorArr[i] = ((255 - colorArr[i]) * level + colorArr[i]) | 0;
  9682. }
  9683. }
  9684. return stringify(colorArr, colorArr.length === 4 ? 'rgba' : 'rgb');
  9685. }
  9686. }
  9687. /**
  9688. * @param {string} color
  9689. * @return {string}
  9690. * @memberOf module:zrender/util/color
  9691. */
  9692. function toHex(color, level) {
  9693. var colorArr = parse(color);
  9694. if (colorArr) {
  9695. return ((1 << 24) + (colorArr[0] << 16) + (colorArr[1] << 8) + (+colorArr[2])).toString(16).slice(1);
  9696. }
  9697. }
  9698. /**
  9699. * Map value to color. Faster than mapToColor methods because color is represented by rgba array.
  9700. * @param {number} normalizedValue A float between 0 and 1.
  9701. * @param {Array.<Array.<number>>} colors List of rgba color array
  9702. * @param {Array.<number>} [out] Mapped gba color array
  9703. * @return {Array.<number>} will be null/undefined if input illegal.
  9704. */
  9705. function fastMapToColor(normalizedValue, colors, out) {
  9706. if (!(colors && colors.length)
  9707. || !(normalizedValue >= 0 && normalizedValue <= 1)
  9708. ) {
  9709. return;
  9710. }
  9711. out = out || [];
  9712. var value = normalizedValue * (colors.length - 1);
  9713. var leftIndex = Math.floor(value);
  9714. var rightIndex = Math.ceil(value);
  9715. var leftColor = colors[leftIndex];
  9716. var rightColor = colors[rightIndex];
  9717. var dv = value - leftIndex;
  9718. out[0] = clampCssByte(lerp(leftColor[0], rightColor[0], dv));
  9719. out[1] = clampCssByte(lerp(leftColor[1], rightColor[1], dv));
  9720. out[2] = clampCssByte(lerp(leftColor[2], rightColor[2], dv));
  9721. out[3] = clampCssFloat(lerp(leftColor[3], rightColor[3], dv));
  9722. return out;
  9723. }
  9724. /**
  9725. * @param {number} normalizedValue A float between 0 and 1.
  9726. * @param {Array.<string>} colors Color list.
  9727. * @param {boolean=} fullOutput Default false.
  9728. * @return {(string|Object)} Result color. If fullOutput,
  9729. * return {color: ..., leftIndex: ..., rightIndex: ..., value: ...},
  9730. * @memberOf module:zrender/util/color
  9731. */
  9732. function mapToColor(normalizedValue, colors, fullOutput) {
  9733. if (!(colors && colors.length)
  9734. || !(normalizedValue >= 0 && normalizedValue <= 1)
  9735. ) {
  9736. return;
  9737. }
  9738. var value = normalizedValue * (colors.length - 1);
  9739. var leftIndex = Math.floor(value);
  9740. var rightIndex = Math.ceil(value);
  9741. var leftColor = parse(colors[leftIndex]);
  9742. var rightColor = parse(colors[rightIndex]);
  9743. var dv = value - leftIndex;
  9744. var color = stringify(
  9745. [
  9746. clampCssByte(lerp(leftColor[0], rightColor[0], dv)),
  9747. clampCssByte(lerp(leftColor[1], rightColor[1], dv)),
  9748. clampCssByte(lerp(leftColor[2], rightColor[2], dv)),
  9749. clampCssFloat(lerp(leftColor[3], rightColor[3], dv))
  9750. ],
  9751. 'rgba'
  9752. );
  9753. return fullOutput
  9754. ? {
  9755. color: color,
  9756. leftIndex: leftIndex,
  9757. rightIndex: rightIndex,
  9758. value: value
  9759. }
  9760. : color;
  9761. }
  9762. /**
  9763. * @param {string} color
  9764. * @param {number=} h 0 ~ 360, ignore when null.
  9765. * @param {number=} s 0 ~ 1, ignore when null.
  9766. * @param {number=} l 0 ~ 1, ignore when null.
  9767. * @return {string} Color string in rgba format.
  9768. * @memberOf module:zrender/util/color
  9769. */
  9770. function modifyHSL(color, h, s, l) {
  9771. color = parse(color);
  9772. if (color) {
  9773. color = rgba2hsla(color);
  9774. h != null && (color[0] = clampCssAngle(h));
  9775. s != null && (color[1] = parseCssFloat(s));
  9776. l != null && (color[2] = parseCssFloat(l));
  9777. return stringify(hsla2rgba(color), 'rgba');
  9778. }
  9779. }
  9780. /**
  9781. * @param {string} color
  9782. * @param {number=} alpha 0 ~ 1
  9783. * @return {string} Color string in rgba format.
  9784. * @memberOf module:zrender/util/color
  9785. */
  9786. function modifyAlpha(color, alpha) {
  9787. color = parse(color);
  9788. if (color && alpha != null) {
  9789. color[3] = clampCssFloat(alpha);
  9790. return stringify(color, 'rgba');
  9791. }
  9792. }
  9793. /**
  9794. * @param {Array.<number>} arrColor like [12,33,44,0.4]
  9795. * @param {string} type 'rgba', 'hsva', ...
  9796. * @return {string} Result color. (If input illegal, return undefined).
  9797. */
  9798. function stringify(arrColor, type) {
  9799. if (!arrColor || !arrColor.length) {
  9800. return;
  9801. }
  9802. var colorStr = arrColor[0] + ',' + arrColor[1] + ',' + arrColor[2];
  9803. if (type === 'rgba' || type === 'hsva' || type === 'hsla') {
  9804. colorStr += ',' + arrColor[3];
  9805. }
  9806. return type + '(' + colorStr + ')';
  9807. }
  9808. module.exports = {
  9809. parse: parse,
  9810. lift: lift,
  9811. toHex: toHex,
  9812. fastMapToColor: fastMapToColor,
  9813. mapToColor: mapToColor,
  9814. modifyHSL: modifyHSL,
  9815. modifyAlpha: modifyAlpha,
  9816. stringify: stringify
  9817. };
  9818. /***/ },
  9819. /* 32 */
  9820. /***/ function(module, exports) {
  9821. // Simple LRU cache use doubly linked list
  9822. // @module zrender/core/LRU
  9823. /**
  9824. * Simple double linked list. Compared with array, it has O(1) remove operation.
  9825. * @constructor
  9826. */
  9827. var LinkedList = function () {
  9828. /**
  9829. * @type {module:zrender/core/LRU~Entry}
  9830. */
  9831. this.head = null;
  9832. /**
  9833. * @type {module:zrender/core/LRU~Entry}
  9834. */
  9835. this.tail = null;
  9836. this._len = 0;
  9837. };
  9838. var linkedListProto = LinkedList.prototype;
  9839. /**
  9840. * Insert a new value at the tail
  9841. * @param {} val
  9842. * @return {module:zrender/core/LRU~Entry}
  9843. */
  9844. linkedListProto.insert = function (val) {
  9845. var entry = new Entry(val);
  9846. this.insertEntry(entry);
  9847. return entry;
  9848. };
  9849. /**
  9850. * Insert an entry at the tail
  9851. * @param {module:zrender/core/LRU~Entry} entry
  9852. */
  9853. linkedListProto.insertEntry = function (entry) {
  9854. if (!this.head) {
  9855. this.head = this.tail = entry;
  9856. }
  9857. else {
  9858. this.tail.next = entry;
  9859. entry.prev = this.tail;
  9860. entry.next = null;
  9861. this.tail = entry;
  9862. }
  9863. this._len++;
  9864. };
  9865. /**
  9866. * Remove entry.
  9867. * @param {module:zrender/core/LRU~Entry} entry
  9868. */
  9869. linkedListProto.remove = function (entry) {
  9870. var prev = entry.prev;
  9871. var next = entry.next;
  9872. if (prev) {
  9873. prev.next = next;
  9874. }
  9875. else {
  9876. // Is head
  9877. this.head = next;
  9878. }
  9879. if (next) {
  9880. next.prev = prev;
  9881. }
  9882. else {
  9883. // Is tail
  9884. this.tail = prev;
  9885. }
  9886. entry.next = entry.prev = null;
  9887. this._len--;
  9888. };
  9889. /**
  9890. * @return {number}
  9891. */
  9892. linkedListProto.len = function () {
  9893. return this._len;
  9894. };
  9895. /**
  9896. * Clear list
  9897. */
  9898. linkedListProto.clear = function () {
  9899. this.head = this.tail = null;
  9900. this._len = 0;
  9901. };
  9902. /**
  9903. * @constructor
  9904. * @param {} val
  9905. */
  9906. var Entry = function (val) {
  9907. /**
  9908. * @type {}
  9909. */
  9910. this.value = val;
  9911. /**
  9912. * @type {module:zrender/core/LRU~Entry}
  9913. */
  9914. this.next;
  9915. /**
  9916. * @type {module:zrender/core/LRU~Entry}
  9917. */
  9918. this.prev;
  9919. };
  9920. /**
  9921. * LRU Cache
  9922. * @constructor
  9923. * @alias module:zrender/core/LRU
  9924. */
  9925. var LRU = function (maxSize) {
  9926. this._list = new LinkedList();
  9927. this._map = {};
  9928. this._maxSize = maxSize || 10;
  9929. this._lastRemovedEntry = null;
  9930. };
  9931. var LRUProto = LRU.prototype;
  9932. /**
  9933. * @param {string} key
  9934. * @param {} value
  9935. * @return {} Removed value
  9936. */
  9937. LRUProto.put = function (key, value) {
  9938. var list = this._list;
  9939. var map = this._map;
  9940. var removed = null;
  9941. if (map[key] == null) {
  9942. var len = list.len();
  9943. // Reuse last removed entry
  9944. var entry = this._lastRemovedEntry;
  9945. if (len >= this._maxSize && len > 0) {
  9946. // Remove the least recently used
  9947. var leastUsedEntry = list.head;
  9948. list.remove(leastUsedEntry);
  9949. delete map[leastUsedEntry.key];
  9950. removed = leastUsedEntry.value;
  9951. this._lastRemovedEntry = leastUsedEntry;
  9952. }
  9953. if (entry) {
  9954. entry.value = value;
  9955. }
  9956. else {
  9957. entry = new Entry(value);
  9958. }
  9959. entry.key = key;
  9960. list.insertEntry(entry);
  9961. map[key] = entry;
  9962. }
  9963. return removed;
  9964. };
  9965. /**
  9966. * @param {string} key
  9967. * @return {}
  9968. */
  9969. LRUProto.get = function (key) {
  9970. var entry = this._map[key];
  9971. var list = this._list;
  9972. if (entry != null) {
  9973. // Put the latest used entry in the tail
  9974. if (entry !== list.tail) {
  9975. list.remove(entry);
  9976. list.insertEntry(entry);
  9977. }
  9978. return entry.value;
  9979. }
  9980. };
  9981. /**
  9982. * Clear the cache
  9983. */
  9984. LRUProto.clear = function () {
  9985. this._list.clear();
  9986. this._map = {};
  9987. };
  9988. module.exports = LRU;
  9989. /***/ },
  9990. /* 33 */
  9991. /***/ function(module, exports, __webpack_require__) {
  9992. var config = __webpack_require__(34);
  9993. /**
  9994. * @exports zrender/tool/log
  9995. * @author Kener (@Kener-林峰, kener.linfeng@gmail.com)
  9996. */
  9997. module.exports = function() {
  9998. if (config.debugMode === 0) {
  9999. return;
  10000. }
  10001. else if (config.debugMode == 1) {
  10002. for (var k in arguments) {
  10003. throw new Error(arguments[k]);
  10004. }
  10005. }
  10006. else if (config.debugMode > 1) {
  10007. for (var k in arguments) {
  10008. console.log(arguments[k]);
  10009. }
  10010. }
  10011. };
  10012. /* for debug
  10013. return function(mes) {
  10014. document.getElementById('wrong-message').innerHTML =
  10015. mes + ' ' + (new Date() - 0)
  10016. + '<br/>'
  10017. + document.getElementById('wrong-message').innerHTML;
  10018. };
  10019. */
  10020. /***/ },
  10021. /* 34 */
  10022. /***/ function(module, exports) {
  10023. var dpr = 1;
  10024. // If in browser environment
  10025. if (typeof window !== 'undefined') {
  10026. dpr = Math.max(window.devicePixelRatio || 1, 1);
  10027. }
  10028. /**
  10029. * config默认配置项
  10030. * @exports zrender/config
  10031. * @author Kener (@Kener-林峰, kener.linfeng@gmail.com)
  10032. */
  10033. var config = {
  10034. /**
  10035. * debug日志选项:catchBrushException为true下有效
  10036. * 0 : 不生成debug数据,发布用
  10037. * 1 : 异常抛出,调试用
  10038. * 2 : 控制台输出,调试用
  10039. */
  10040. debugMode: 0,
  10041. // retina 屏幕优化
  10042. devicePixelRatio: dpr
  10043. };
  10044. module.exports = config;
  10045. /***/ },
  10046. /* 35 */
  10047. /***/ function(module, exports, __webpack_require__) {
  10048. /**
  10049. * Mixin for drawing text in a element bounding rect
  10050. * @module zrender/mixin/RectText
  10051. */
  10052. var textContain = __webpack_require__(8);
  10053. var BoundingRect = __webpack_require__(9);
  10054. var tmpRect = new BoundingRect();
  10055. var RectText = function () {};
  10056. function parsePercent(value, maxValue) {
  10057. if (typeof value === 'string') {
  10058. if (value.lastIndexOf('%') >= 0) {
  10059. return parseFloat(value) / 100 * maxValue;
  10060. }
  10061. return parseFloat(value);
  10062. }
  10063. return value;
  10064. }
  10065. RectText.prototype = {
  10066. constructor: RectText,
  10067. /**
  10068. * Draw text in a rect with specified position.
  10069. * @param {CanvasRenderingContext} ctx
  10070. * @param {Object} rect Displayable rect
  10071. * @return {Object} textRect Alternative precalculated text bounding rect
  10072. */
  10073. drawRectText: function (ctx, rect, textRect) {
  10074. var style = this.style;
  10075. var text = style.text;
  10076. // Convert to string
  10077. text != null && (text += '');
  10078. if (!text) {
  10079. return;
  10080. }
  10081. // FIXME
  10082. ctx.save();
  10083. var x;
  10084. var y;
  10085. var textPosition = style.textPosition;
  10086. var textOffset = style.textOffset;
  10087. var distance = style.textDistance;
  10088. var align = style.textAlign;
  10089. var font = style.textFont || style.font;
  10090. var baseline = style.textBaseline;
  10091. var verticalAlign = style.textVerticalAlign;
  10092. textRect = textRect || textContain.getBoundingRect(text, font, align, baseline);
  10093. // Transform rect to view space
  10094. var transform = this.transform;
  10095. if (!style.textTransform) {
  10096. if (transform) {
  10097. tmpRect.copy(rect);
  10098. tmpRect.applyTransform(transform);
  10099. rect = tmpRect;
  10100. }
  10101. }
  10102. else {
  10103. this.setTransform(ctx);
  10104. }
  10105. // Text position represented by coord
  10106. if (textPosition instanceof Array) {
  10107. // Percent
  10108. x = rect.x + parsePercent(textPosition[0], rect.width);
  10109. y = rect.y + parsePercent(textPosition[1], rect.height);
  10110. align = align || 'left';
  10111. baseline = baseline || 'top';
  10112. if (verticalAlign) {
  10113. switch (verticalAlign) {
  10114. case 'middle':
  10115. y -= textRect.height / 2 - textRect.lineHeight / 2;
  10116. break;
  10117. case 'bottom':
  10118. y -= textRect.height - textRect.lineHeight / 2;
  10119. break;
  10120. default:
  10121. y += textRect.lineHeight / 2;
  10122. }
  10123. // Force bseline to be middle
  10124. baseline = 'middle';
  10125. }
  10126. }
  10127. else {
  10128. var res = textContain.adjustTextPositionOnRect(
  10129. textPosition, rect, textRect, distance
  10130. );
  10131. x = res.x;
  10132. y = res.y;
  10133. // Default align and baseline when has textPosition
  10134. align = align || res.textAlign;
  10135. baseline = baseline || res.textBaseline;
  10136. }
  10137. if (textOffset) {
  10138. x += textOffset[0];
  10139. y += textOffset[1];
  10140. }
  10141. // Use canvas default left textAlign. Giving invalid value will cause state not change
  10142. ctx.textAlign = align || 'left';
  10143. // Use canvas default alphabetic baseline
  10144. ctx.textBaseline = baseline || 'alphabetic';
  10145. var textFill = style.textFill;
  10146. var textStroke = style.textStroke;
  10147. textFill && (ctx.fillStyle = textFill);
  10148. textStroke && (ctx.strokeStyle = textStroke);
  10149. // TODO Invalid font
  10150. ctx.font = font || '12px sans-serif';
  10151. // Text shadow
  10152. // Always set shadowBlur and shadowOffset to avoid leak from displayable
  10153. ctx.shadowBlur = style.textShadowBlur;
  10154. ctx.shadowColor = style.textShadowColor || 'transparent';
  10155. ctx.shadowOffsetX = style.textShadowOffsetX;
  10156. ctx.shadowOffsetY = style.textShadowOffsetY;
  10157. var textLines = text.split('\n');
  10158. if (style.textRotation) {
  10159. transform && ctx.translate(transform[4], transform[5]);
  10160. ctx.rotate(style.textRotation);
  10161. transform && ctx.translate(-transform[4], -transform[5]);
  10162. }
  10163. for (var i = 0; i < textLines.length; i++) {
  10164. // Fill after stroke so the outline will not cover the main part.
  10165. textStroke && ctx.strokeText(textLines[i], x, y);
  10166. textFill && ctx.fillText(textLines[i], x, y);
  10167. y += textRect.lineHeight;
  10168. }
  10169. ctx.restore();
  10170. }
  10171. };
  10172. module.exports = RectText;
  10173. /***/ },
  10174. /* 36 */
  10175. /***/ function(module, exports, __webpack_require__) {
  10176. 'use strict';
  10177. /**
  10178. * Path 代理,可以在`buildPath`中用于替代`ctx`, 会保存每个path操作的命令到pathCommands属性中
  10179. * 可以用于 isInsidePath 判断以及获取boundingRect
  10180. *
  10181. * @module zrender/core/PathProxy
  10182. * @author Yi Shen (http://www.github.com/pissang)
  10183. */
  10184. // TODO getTotalLength, getPointAtLength
  10185. var curve = __webpack_require__(37);
  10186. var vec2 = __webpack_require__(10);
  10187. var bbox = __webpack_require__(38);
  10188. var BoundingRect = __webpack_require__(9);
  10189. var dpr = __webpack_require__(34).devicePixelRatio;
  10190. var CMD = {
  10191. M: 1,
  10192. L: 2,
  10193. C: 3,
  10194. Q: 4,
  10195. A: 5,
  10196. Z: 6,
  10197. // Rect
  10198. R: 7
  10199. };
  10200. // var CMD_MEM_SIZE = {
  10201. // M: 3,
  10202. // L: 3,
  10203. // C: 7,
  10204. // Q: 5,
  10205. // A: 9,
  10206. // R: 5,
  10207. // Z: 1
  10208. // };
  10209. var min = [];
  10210. var max = [];
  10211. var min2 = [];
  10212. var max2 = [];
  10213. var mathMin = Math.min;
  10214. var mathMax = Math.max;
  10215. var mathCos = Math.cos;
  10216. var mathSin = Math.sin;
  10217. var mathSqrt = Math.sqrt;
  10218. var mathAbs = Math.abs;
  10219. var hasTypedArray = typeof Float32Array != 'undefined';
  10220. /**
  10221. * @alias module:zrender/core/PathProxy
  10222. * @constructor
  10223. */
  10224. var PathProxy = function (notSaveData) {
  10225. this._saveData = !(notSaveData || false);
  10226. if (this._saveData) {
  10227. /**
  10228. * Path data. Stored as flat array
  10229. * @type {Array.<Object>}
  10230. */
  10231. this.data = [];
  10232. }
  10233. this._ctx = null;
  10234. };
  10235. /**
  10236. * 快速计算Path包围盒(并不是最小包围盒)
  10237. * @return {Object}
  10238. */
  10239. PathProxy.prototype = {
  10240. constructor: PathProxy,
  10241. _xi: 0,
  10242. _yi: 0,
  10243. _x0: 0,
  10244. _y0: 0,
  10245. // Unit x, Unit y. Provide for avoiding drawing that too short line segment
  10246. _ux: 0,
  10247. _uy: 0,
  10248. _len: 0,
  10249. _lineDash: null,
  10250. _dashOffset: 0,
  10251. _dashIdx: 0,
  10252. _dashSum: 0,
  10253. /**
  10254. * @readOnly
  10255. */
  10256. setScale: function (sx, sy) {
  10257. this._ux = mathAbs(1 / dpr / sx) || 0;
  10258. this._uy = mathAbs(1 / dpr / sy) || 0;
  10259. },
  10260. getContext: function () {
  10261. return this._ctx;
  10262. },
  10263. /**
  10264. * @param {CanvasRenderingContext2D} ctx
  10265. * @return {module:zrender/core/PathProxy}
  10266. */
  10267. beginPath: function (ctx) {
  10268. this._ctx = ctx;
  10269. ctx && ctx.beginPath();
  10270. ctx && (this.dpr = ctx.dpr);
  10271. // Reset
  10272. if (this._saveData) {
  10273. this._len = 0;
  10274. }
  10275. if (this._lineDash) {
  10276. this._lineDash = null;
  10277. this._dashOffset = 0;
  10278. }
  10279. return this;
  10280. },
  10281. /**
  10282. * @param {number} x
  10283. * @param {number} y
  10284. * @return {module:zrender/core/PathProxy}
  10285. */
  10286. moveTo: function (x, y) {
  10287. this.addData(CMD.M, x, y);
  10288. this._ctx && this._ctx.moveTo(x, y);
  10289. // x0, y0, xi, yi 是记录在 _dashedXXXXTo 方法中使用
  10290. // xi, yi 记录当前点, x0, y0 在 closePath 的时候回到起始点。
  10291. // 有可能在 beginPath 之后直接调用 lineTo,这时候 x0, y0 需要
  10292. // 在 lineTo 方法中记录,这里先不考虑这种情况,dashed line 也只在 IE10- 中不支持
  10293. this._x0 = x;
  10294. this._y0 = y;
  10295. this._xi = x;
  10296. this._yi = y;
  10297. return this;
  10298. },
  10299. /**
  10300. * @param {number} x
  10301. * @param {number} y
  10302. * @return {module:zrender/core/PathProxy}
  10303. */
  10304. lineTo: function (x, y) {
  10305. var exceedUnit = mathAbs(x - this._xi) > this._ux
  10306. || mathAbs(y - this._yi) > this._uy
  10307. // Force draw the first segment
  10308. || this._len < 5;
  10309. this.addData(CMD.L, x, y);
  10310. if (this._ctx && exceedUnit) {
  10311. this._needsDash() ? this._dashedLineTo(x, y)
  10312. : this._ctx.lineTo(x, y);
  10313. }
  10314. if (exceedUnit) {
  10315. this._xi = x;
  10316. this._yi = y;
  10317. }
  10318. return this;
  10319. },
  10320. /**
  10321. * @param {number} x1
  10322. * @param {number} y1
  10323. * @param {number} x2
  10324. * @param {number} y2
  10325. * @param {number} x3
  10326. * @param {number} y3
  10327. * @return {module:zrender/core/PathProxy}
  10328. */
  10329. bezierCurveTo: function (x1, y1, x2, y2, x3, y3) {
  10330. this.addData(CMD.C, x1, y1, x2, y2, x3, y3);
  10331. if (this._ctx) {
  10332. this._needsDash() ? this._dashedBezierTo(x1, y1, x2, y2, x3, y3)
  10333. : this._ctx.bezierCurveTo(x1, y1, x2, y2, x3, y3);
  10334. }
  10335. this._xi = x3;
  10336. this._yi = y3;
  10337. return this;
  10338. },
  10339. /**
  10340. * @param {number} x1
  10341. * @param {number} y1
  10342. * @param {number} x2
  10343. * @param {number} y2
  10344. * @return {module:zrender/core/PathProxy}
  10345. */
  10346. quadraticCurveTo: function (x1, y1, x2, y2) {
  10347. this.addData(CMD.Q, x1, y1, x2, y2);
  10348. if (this._ctx) {
  10349. this._needsDash() ? this._dashedQuadraticTo(x1, y1, x2, y2)
  10350. : this._ctx.quadraticCurveTo(x1, y1, x2, y2);
  10351. }
  10352. this._xi = x2;
  10353. this._yi = y2;
  10354. return this;
  10355. },
  10356. /**
  10357. * @param {number} cx
  10358. * @param {number} cy
  10359. * @param {number} r
  10360. * @param {number} startAngle
  10361. * @param {number} endAngle
  10362. * @param {boolean} anticlockwise
  10363. * @return {module:zrender/core/PathProxy}
  10364. */
  10365. arc: function (cx, cy, r, startAngle, endAngle, anticlockwise) {
  10366. this.addData(
  10367. CMD.A, cx, cy, r, r, startAngle, endAngle - startAngle, 0, anticlockwise ? 0 : 1
  10368. );
  10369. this._ctx && this._ctx.arc(cx, cy, r, startAngle, endAngle, anticlockwise);
  10370. this._xi = mathCos(endAngle) * r + cx;
  10371. this._yi = mathSin(endAngle) * r + cx;
  10372. return this;
  10373. },
  10374. // TODO
  10375. arcTo: function (x1, y1, x2, y2, radius) {
  10376. if (this._ctx) {
  10377. this._ctx.arcTo(x1, y1, x2, y2, radius);
  10378. }
  10379. return this;
  10380. },
  10381. // TODO
  10382. rect: function (x, y, w, h) {
  10383. this._ctx && this._ctx.rect(x, y, w, h);
  10384. this.addData(CMD.R, x, y, w, h);
  10385. return this;
  10386. },
  10387. /**
  10388. * @return {module:zrender/core/PathProxy}
  10389. */
  10390. closePath: function () {
  10391. this.addData(CMD.Z);
  10392. var ctx = this._ctx;
  10393. var x0 = this._x0;
  10394. var y0 = this._y0;
  10395. if (ctx) {
  10396. this._needsDash() && this._dashedLineTo(x0, y0);
  10397. ctx.closePath();
  10398. }
  10399. this._xi = x0;
  10400. this._yi = y0;
  10401. return this;
  10402. },
  10403. /**
  10404. * Context 从外部传入,因为有可能是 rebuildPath 完之后再 fill。
  10405. * stroke 同样
  10406. * @param {CanvasRenderingContext2D} ctx
  10407. * @return {module:zrender/core/PathProxy}
  10408. */
  10409. fill: function (ctx) {
  10410. ctx && ctx.fill();
  10411. this.toStatic();
  10412. },
  10413. /**
  10414. * @param {CanvasRenderingContext2D} ctx
  10415. * @return {module:zrender/core/PathProxy}
  10416. */
  10417. stroke: function (ctx) {
  10418. ctx && ctx.stroke();
  10419. this.toStatic();
  10420. },
  10421. /**
  10422. * 必须在其它绘制命令前调用
  10423. * Must be invoked before all other path drawing methods
  10424. * @return {module:zrender/core/PathProxy}
  10425. */
  10426. setLineDash: function (lineDash) {
  10427. if (lineDash instanceof Array) {
  10428. this._lineDash = lineDash;
  10429. this._dashIdx = 0;
  10430. var lineDashSum = 0;
  10431. for (var i = 0; i < lineDash.length; i++) {
  10432. lineDashSum += lineDash[i];
  10433. }
  10434. this._dashSum = lineDashSum;
  10435. }
  10436. return this;
  10437. },
  10438. /**
  10439. * 必须在其它绘制命令前调用
  10440. * Must be invoked before all other path drawing methods
  10441. * @return {module:zrender/core/PathProxy}
  10442. */
  10443. setLineDashOffset: function (offset) {
  10444. this._dashOffset = offset;
  10445. return this;
  10446. },
  10447. /**
  10448. *
  10449. * @return {boolean}
  10450. */
  10451. len: function () {
  10452. return this._len;
  10453. },
  10454. /**
  10455. * 直接设置 Path 数据
  10456. */
  10457. setData: function (data) {
  10458. var len = data.length;
  10459. if (! (this.data && this.data.length == len) && hasTypedArray) {
  10460. this.data = new Float32Array(len);
  10461. }
  10462. for (var i = 0; i < len; i++) {
  10463. this.data[i] = data[i];
  10464. }
  10465. this._len = len;
  10466. },
  10467. /**
  10468. * 添加子路径
  10469. * @param {module:zrender/core/PathProxy|Array.<module:zrender/core/PathProxy>} path
  10470. */
  10471. appendPath: function (path) {
  10472. if (!(path instanceof Array)) {
  10473. path = [path];
  10474. }
  10475. var len = path.length;
  10476. var appendSize = 0;
  10477. var offset = this._len;
  10478. for (var i = 0; i < len; i++) {
  10479. appendSize += path[i].len();
  10480. }
  10481. if (hasTypedArray && (this.data instanceof Float32Array)) {
  10482. this.data = new Float32Array(offset + appendSize);
  10483. }
  10484. for (var i = 0; i < len; i++) {
  10485. var appendPathData = path[i].data;
  10486. for (var k = 0; k < appendPathData.length; k++) {
  10487. this.data[offset++] = appendPathData[k];
  10488. }
  10489. }
  10490. this._len = offset;
  10491. },
  10492. /**
  10493. * 填充 Path 数据。
  10494. * 尽量复用而不申明新的数组。大部分图形重绘的指令数据长度都是不变的。
  10495. */
  10496. addData: function (cmd) {
  10497. if (!this._saveData) {
  10498. return;
  10499. }
  10500. var data = this.data;
  10501. if (this._len + arguments.length > data.length) {
  10502. // 因为之前的数组已经转换成静态的 Float32Array
  10503. // 所以不够用时需要扩展一个新的动态数组
  10504. this._expandData();
  10505. data = this.data;
  10506. }
  10507. for (var i = 0; i < arguments.length; i++) {
  10508. data[this._len++] = arguments[i];
  10509. }
  10510. this._prevCmd = cmd;
  10511. },
  10512. _expandData: function () {
  10513. // Only if data is Float32Array
  10514. if (!(this.data instanceof Array)) {
  10515. var newData = [];
  10516. for (var i = 0; i < this._len; i++) {
  10517. newData[i] = this.data[i];
  10518. }
  10519. this.data = newData;
  10520. }
  10521. },
  10522. /**
  10523. * If needs js implemented dashed line
  10524. * @return {boolean}
  10525. * @private
  10526. */
  10527. _needsDash: function () {
  10528. return this._lineDash;
  10529. },
  10530. _dashedLineTo: function (x1, y1) {
  10531. var dashSum = this._dashSum;
  10532. var offset = this._dashOffset;
  10533. var lineDash = this._lineDash;
  10534. var ctx = this._ctx;
  10535. var x0 = this._xi;
  10536. var y0 = this._yi;
  10537. var dx = x1 - x0;
  10538. var dy = y1 - y0;
  10539. var dist = mathSqrt(dx * dx + dy * dy);
  10540. var x = x0;
  10541. var y = y0;
  10542. var dash;
  10543. var nDash = lineDash.length;
  10544. var idx;
  10545. dx /= dist;
  10546. dy /= dist;
  10547. if (offset < 0) {
  10548. // Convert to positive offset
  10549. offset = dashSum + offset;
  10550. }
  10551. offset %= dashSum;
  10552. x -= offset * dx;
  10553. y -= offset * dy;
  10554. while ((dx > 0 && x <= x1) || (dx < 0 && x >= x1)
  10555. || (dx == 0 && ((dy > 0 && y <= y1) || (dy < 0 && y >= y1)))) {
  10556. idx = this._dashIdx;
  10557. dash = lineDash[idx];
  10558. x += dx * dash;
  10559. y += dy * dash;
  10560. this._dashIdx = (idx + 1) % nDash;
  10561. // Skip positive offset
  10562. if ((dx > 0 && x < x0) || (dx < 0 && x > x0) || (dy > 0 && y < y0) || (dy < 0 && y > y0)) {
  10563. continue;
  10564. }
  10565. ctx[idx % 2 ? 'moveTo' : 'lineTo'](
  10566. dx >= 0 ? mathMin(x, x1) : mathMax(x, x1),
  10567. dy >= 0 ? mathMin(y, y1) : mathMax(y, y1)
  10568. );
  10569. }
  10570. // Offset for next lineTo
  10571. dx = x - x1;
  10572. dy = y - y1;
  10573. this._dashOffset = -mathSqrt(dx * dx + dy * dy);
  10574. },
  10575. // Not accurate dashed line to
  10576. _dashedBezierTo: function (x1, y1, x2, y2, x3, y3) {
  10577. var dashSum = this._dashSum;
  10578. var offset = this._dashOffset;
  10579. var lineDash = this._lineDash;
  10580. var ctx = this._ctx;
  10581. var x0 = this._xi;
  10582. var y0 = this._yi;
  10583. var t;
  10584. var dx;
  10585. var dy;
  10586. var cubicAt = curve.cubicAt;
  10587. var bezierLen = 0;
  10588. var idx = this._dashIdx;
  10589. var nDash = lineDash.length;
  10590. var x;
  10591. var y;
  10592. var tmpLen = 0;
  10593. if (offset < 0) {
  10594. // Convert to positive offset
  10595. offset = dashSum + offset;
  10596. }
  10597. offset %= dashSum;
  10598. // Bezier approx length
  10599. for (t = 0; t < 1; t += 0.1) {
  10600. dx = cubicAt(x0, x1, x2, x3, t + 0.1)
  10601. - cubicAt(x0, x1, x2, x3, t);
  10602. dy = cubicAt(y0, y1, y2, y3, t + 0.1)
  10603. - cubicAt(y0, y1, y2, y3, t);
  10604. bezierLen += mathSqrt(dx * dx + dy * dy);
  10605. }
  10606. // Find idx after add offset
  10607. for (; idx < nDash; idx++) {
  10608. tmpLen += lineDash[idx];
  10609. if (tmpLen > offset) {
  10610. break;
  10611. }
  10612. }
  10613. t = (tmpLen - offset) / bezierLen;
  10614. while (t <= 1) {
  10615. x = cubicAt(x0, x1, x2, x3, t);
  10616. y = cubicAt(y0, y1, y2, y3, t);
  10617. // Use line to approximate dashed bezier
  10618. // Bad result if dash is long
  10619. idx % 2 ? ctx.moveTo(x, y)
  10620. : ctx.lineTo(x, y);
  10621. t += lineDash[idx] / bezierLen;
  10622. idx = (idx + 1) % nDash;
  10623. }
  10624. // Finish the last segment and calculate the new offset
  10625. (idx % 2 !== 0) && ctx.lineTo(x3, y3);
  10626. dx = x3 - x;
  10627. dy = y3 - y;
  10628. this._dashOffset = -mathSqrt(dx * dx + dy * dy);
  10629. },
  10630. _dashedQuadraticTo: function (x1, y1, x2, y2) {
  10631. // Convert quadratic to cubic using degree elevation
  10632. var x3 = x2;
  10633. var y3 = y2;
  10634. x2 = (x2 + 2 * x1) / 3;
  10635. y2 = (y2 + 2 * y1) / 3;
  10636. x1 = (this._xi + 2 * x1) / 3;
  10637. y1 = (this._yi + 2 * y1) / 3;
  10638. this._dashedBezierTo(x1, y1, x2, y2, x3, y3);
  10639. },
  10640. /**
  10641. * 转成静态的 Float32Array 减少堆内存占用
  10642. * Convert dynamic array to static Float32Array
  10643. */
  10644. toStatic: function () {
  10645. var data = this.data;
  10646. if (data instanceof Array) {
  10647. data.length = this._len;
  10648. if (hasTypedArray) {
  10649. this.data = new Float32Array(data);
  10650. }
  10651. }
  10652. },
  10653. /**
  10654. * @return {module:zrender/core/BoundingRect}
  10655. */
  10656. getBoundingRect: function () {
  10657. min[0] = min[1] = min2[0] = min2[1] = Number.MAX_VALUE;
  10658. max[0] = max[1] = max2[0] = max2[1] = -Number.MAX_VALUE;
  10659. var data = this.data;
  10660. var xi = 0;
  10661. var yi = 0;
  10662. var x0 = 0;
  10663. var y0 = 0;
  10664. for (var i = 0; i < data.length;) {
  10665. var cmd = data[i++];
  10666. if (i == 1) {
  10667. // 如果第一个命令是 L, C, Q
  10668. // 则 previous point 同绘制命令的第一个 point
  10669. //
  10670. // 第一个命令为 Arc 的情况下会在后面特殊处理
  10671. xi = data[i];
  10672. yi = data[i + 1];
  10673. x0 = xi;
  10674. y0 = yi;
  10675. }
  10676. switch (cmd) {
  10677. case CMD.M:
  10678. // moveTo 命令重新创建一个新的 subpath, 并且更新新的起点
  10679. // 在 closePath 的时候使用
  10680. x0 = data[i++];
  10681. y0 = data[i++];
  10682. xi = x0;
  10683. yi = y0;
  10684. min2[0] = x0;
  10685. min2[1] = y0;
  10686. max2[0] = x0;
  10687. max2[1] = y0;
  10688. break;
  10689. case CMD.L:
  10690. bbox.fromLine(xi, yi, data[i], data[i + 1], min2, max2);
  10691. xi = data[i++];
  10692. yi = data[i++];
  10693. break;
  10694. case CMD.C:
  10695. bbox.fromCubic(
  10696. xi, yi, data[i++], data[i++], data[i++], data[i++], data[i], data[i + 1],
  10697. min2, max2
  10698. );
  10699. xi = data[i++];
  10700. yi = data[i++];
  10701. break;
  10702. case CMD.Q:
  10703. bbox.fromQuadratic(
  10704. xi, yi, data[i++], data[i++], data[i], data[i + 1],
  10705. min2, max2
  10706. );
  10707. xi = data[i++];
  10708. yi = data[i++];
  10709. break;
  10710. case CMD.A:
  10711. // TODO Arc 判断的开销比较大
  10712. var cx = data[i++];
  10713. var cy = data[i++];
  10714. var rx = data[i++];
  10715. var ry = data[i++];
  10716. var startAngle = data[i++];
  10717. var endAngle = data[i++] + startAngle;
  10718. // TODO Arc 旋转
  10719. var psi = data[i++];
  10720. var anticlockwise = 1 - data[i++];
  10721. if (i == 1) {
  10722. // 直接使用 arc 命令
  10723. // 第一个命令起点还未定义
  10724. x0 = mathCos(startAngle) * rx + cx;
  10725. y0 = mathSin(startAngle) * ry + cy;
  10726. }
  10727. bbox.fromArc(
  10728. cx, cy, rx, ry, startAngle, endAngle,
  10729. anticlockwise, min2, max2
  10730. );
  10731. xi = mathCos(endAngle) * rx + cx;
  10732. yi = mathSin(endAngle) * ry + cy;
  10733. break;
  10734. case CMD.R:
  10735. x0 = xi = data[i++];
  10736. y0 = yi = data[i++];
  10737. var width = data[i++];
  10738. var height = data[i++];
  10739. // Use fromLine
  10740. bbox.fromLine(x0, y0, x0 + width, y0 + height, min2, max2);
  10741. break;
  10742. case CMD.Z:
  10743. xi = x0;
  10744. yi = y0;
  10745. break;
  10746. }
  10747. // Union
  10748. vec2.min(min, min, min2);
  10749. vec2.max(max, max, max2);
  10750. }
  10751. // No data
  10752. if (i === 0) {
  10753. min[0] = min[1] = max[0] = max[1] = 0;
  10754. }
  10755. return new BoundingRect(
  10756. min[0], min[1], max[0] - min[0], max[1] - min[1]
  10757. );
  10758. },
  10759. /**
  10760. * Rebuild path from current data
  10761. * Rebuild path will not consider javascript implemented line dash.
  10762. * @param {CanvasRenderingContext} ctx
  10763. */
  10764. rebuildPath: function (ctx) {
  10765. var d = this.data;
  10766. var x0, y0;
  10767. var xi, yi;
  10768. var x, y;
  10769. var ux = this._ux;
  10770. var uy = this._uy;
  10771. var len = this._len;
  10772. for (var i = 0; i < len;) {
  10773. var cmd = d[i++];
  10774. if (i == 1) {
  10775. // 如果第一个命令是 L, C, Q
  10776. // 则 previous point 同绘制命令的第一个 point
  10777. //
  10778. // 第一个命令为 Arc 的情况下会在后面特殊处理
  10779. xi = d[i];
  10780. yi = d[i + 1];
  10781. x0 = xi;
  10782. y0 = yi;
  10783. }
  10784. switch (cmd) {
  10785. case CMD.M:
  10786. x0 = xi = d[i++];
  10787. y0 = yi = d[i++];
  10788. ctx.moveTo(xi, yi);
  10789. break;
  10790. case CMD.L:
  10791. x = d[i++];
  10792. y = d[i++];
  10793. // Not draw too small seg between
  10794. if (mathAbs(x - xi) > ux || mathAbs(y - yi) > uy || i === len - 1) {
  10795. ctx.lineTo(x, y);
  10796. xi = x;
  10797. yi = y;
  10798. }
  10799. break;
  10800. case CMD.C:
  10801. ctx.bezierCurveTo(
  10802. d[i++], d[i++], d[i++], d[i++], d[i++], d[i++]
  10803. );
  10804. xi = d[i - 2];
  10805. yi = d[i - 1];
  10806. break;
  10807. case CMD.Q:
  10808. ctx.quadraticCurveTo(d[i++], d[i++], d[i++], d[i++]);
  10809. xi = d[i - 2];
  10810. yi = d[i - 1];
  10811. break;
  10812. case CMD.A:
  10813. var cx = d[i++];
  10814. var cy = d[i++];
  10815. var rx = d[i++];
  10816. var ry = d[i++];
  10817. var theta = d[i++];
  10818. var dTheta = d[i++];
  10819. var psi = d[i++];
  10820. var fs = d[i++];
  10821. var r = (rx > ry) ? rx : ry;
  10822. var scaleX = (rx > ry) ? 1 : rx / ry;
  10823. var scaleY = (rx > ry) ? ry / rx : 1;
  10824. var isEllipse = Math.abs(rx - ry) > 1e-3;
  10825. var endAngle = theta + dTheta;
  10826. if (isEllipse) {
  10827. ctx.translate(cx, cy);
  10828. ctx.rotate(psi);
  10829. ctx.scale(scaleX, scaleY);
  10830. ctx.arc(0, 0, r, theta, endAngle, 1 - fs);
  10831. ctx.scale(1 / scaleX, 1 / scaleY);
  10832. ctx.rotate(-psi);
  10833. ctx.translate(-cx, -cy);
  10834. }
  10835. else {
  10836. ctx.arc(cx, cy, r, theta, endAngle, 1 - fs);
  10837. }
  10838. if (i == 1) {
  10839. // 直接使用 arc 命令
  10840. // 第一个命令起点还未定义
  10841. x0 = mathCos(theta) * rx + cx;
  10842. y0 = mathSin(theta) * ry + cy;
  10843. }
  10844. xi = mathCos(endAngle) * rx + cx;
  10845. yi = mathSin(endAngle) * ry + cy;
  10846. break;
  10847. case CMD.R:
  10848. x0 = xi = d[i];
  10849. y0 = yi = d[i + 1];
  10850. ctx.rect(d[i++], d[i++], d[i++], d[i++]);
  10851. break;
  10852. case CMD.Z:
  10853. ctx.closePath();
  10854. xi = x0;
  10855. yi = y0;
  10856. }
  10857. }
  10858. }
  10859. };
  10860. PathProxy.CMD = CMD;
  10861. module.exports = PathProxy;
  10862. /***/ },
  10863. /* 37 */
  10864. /***/ function(module, exports, __webpack_require__) {
  10865. 'use strict';
  10866. /**
  10867. * 曲线辅助模块
  10868. * @module zrender/core/curve
  10869. * @author pissang(https://www.github.com/pissang)
  10870. */
  10871. var vec2 = __webpack_require__(10);
  10872. var v2Create = vec2.create;
  10873. var v2DistSquare = vec2.distSquare;
  10874. var mathPow = Math.pow;
  10875. var mathSqrt = Math.sqrt;
  10876. var EPSILON = 1e-8;
  10877. var EPSILON_NUMERIC = 1e-4;
  10878. var THREE_SQRT = mathSqrt(3);
  10879. var ONE_THIRD = 1 / 3;
  10880. // 临时变量
  10881. var _v0 = v2Create();
  10882. var _v1 = v2Create();
  10883. var _v2 = v2Create();
  10884. // var _v3 = vec2.create();
  10885. function isAroundZero(val) {
  10886. return val > -EPSILON && val < EPSILON;
  10887. }
  10888. function isNotAroundZero(val) {
  10889. return val > EPSILON || val < -EPSILON;
  10890. }
  10891. /**
  10892. * 计算三次贝塞尔值
  10893. * @memberOf module:zrender/core/curve
  10894. * @param {number} p0
  10895. * @param {number} p1
  10896. * @param {number} p2
  10897. * @param {number} p3
  10898. * @param {number} t
  10899. * @return {number}
  10900. */
  10901. function cubicAt(p0, p1, p2, p3, t) {
  10902. var onet = 1 - t;
  10903. return onet * onet * (onet * p0 + 3 * t * p1)
  10904. + t * t * (t * p3 + 3 * onet * p2);
  10905. }
  10906. /**
  10907. * 计算三次贝塞尔导数值
  10908. * @memberOf module:zrender/core/curve
  10909. * @param {number} p0
  10910. * @param {number} p1
  10911. * @param {number} p2
  10912. * @param {number} p3
  10913. * @param {number} t
  10914. * @return {number}
  10915. */
  10916. function cubicDerivativeAt(p0, p1, p2, p3, t) {
  10917. var onet = 1 - t;
  10918. return 3 * (
  10919. ((p1 - p0) * onet + 2 * (p2 - p1) * t) * onet
  10920. + (p3 - p2) * t * t
  10921. );
  10922. }
  10923. /**
  10924. * 计算三次贝塞尔方程根,使用盛金公式
  10925. * @memberOf module:zrender/core/curve
  10926. * @param {number} p0
  10927. * @param {number} p1
  10928. * @param {number} p2
  10929. * @param {number} p3
  10930. * @param {number} val
  10931. * @param {Array.<number>} roots
  10932. * @return {number} 有效根数目
  10933. */
  10934. function cubicRootAt(p0, p1, p2, p3, val, roots) {
  10935. // Evaluate roots of cubic functions
  10936. var a = p3 + 3 * (p1 - p2) - p0;
  10937. var b = 3 * (p2 - p1 * 2 + p0);
  10938. var c = 3 * (p1 - p0);
  10939. var d = p0 - val;
  10940. var A = b * b - 3 * a * c;
  10941. var B = b * c - 9 * a * d;
  10942. var C = c * c - 3 * b * d;
  10943. var n = 0;
  10944. if (isAroundZero(A) && isAroundZero(B)) {
  10945. if (isAroundZero(b)) {
  10946. roots[0] = 0;
  10947. }
  10948. else {
  10949. var t1 = -c / b; //t1, t2, t3, b is not zero
  10950. if (t1 >= 0 && t1 <= 1) {
  10951. roots[n++] = t1;
  10952. }
  10953. }
  10954. }
  10955. else {
  10956. var disc = B * B - 4 * A * C;
  10957. if (isAroundZero(disc)) {
  10958. var K = B / A;
  10959. var t1 = -b / a + K; // t1, a is not zero
  10960. var t2 = -K / 2; // t2, t3
  10961. if (t1 >= 0 && t1 <= 1) {
  10962. roots[n++] = t1;
  10963. }
  10964. if (t2 >= 0 && t2 <= 1) {
  10965. roots[n++] = t2;
  10966. }
  10967. }
  10968. else if (disc > 0) {
  10969. var discSqrt = mathSqrt(disc);
  10970. var Y1 = A * b + 1.5 * a * (-B + discSqrt);
  10971. var Y2 = A * b + 1.5 * a * (-B - discSqrt);
  10972. if (Y1 < 0) {
  10973. Y1 = -mathPow(-Y1, ONE_THIRD);
  10974. }
  10975. else {
  10976. Y1 = mathPow(Y1, ONE_THIRD);
  10977. }
  10978. if (Y2 < 0) {
  10979. Y2 = -mathPow(-Y2, ONE_THIRD);
  10980. }
  10981. else {
  10982. Y2 = mathPow(Y2, ONE_THIRD);
  10983. }
  10984. var t1 = (-b - (Y1 + Y2)) / (3 * a);
  10985. if (t1 >= 0 && t1 <= 1) {
  10986. roots[n++] = t1;
  10987. }
  10988. }
  10989. else {
  10990. var T = (2 * A * b - 3 * a * B) / (2 * mathSqrt(A * A * A));
  10991. var theta = Math.acos(T) / 3;
  10992. var ASqrt = mathSqrt(A);
  10993. var tmp = Math.cos(theta);
  10994. var t1 = (-b - 2 * ASqrt * tmp) / (3 * a);
  10995. var t2 = (-b + ASqrt * (tmp + THREE_SQRT * Math.sin(theta))) / (3 * a);
  10996. var t3 = (-b + ASqrt * (tmp - THREE_SQRT * Math.sin(theta))) / (3 * a);
  10997. if (t1 >= 0 && t1 <= 1) {
  10998. roots[n++] = t1;
  10999. }
  11000. if (t2 >= 0 && t2 <= 1) {
  11001. roots[n++] = t2;
  11002. }
  11003. if (t3 >= 0 && t3 <= 1) {
  11004. roots[n++] = t3;
  11005. }
  11006. }
  11007. }
  11008. return n;
  11009. }
  11010. /**
  11011. * 计算三次贝塞尔方程极限值的位置
  11012. * @memberOf module:zrender/core/curve
  11013. * @param {number} p0
  11014. * @param {number} p1
  11015. * @param {number} p2
  11016. * @param {number} p3
  11017. * @param {Array.<number>} extrema
  11018. * @return {number} 有效数目
  11019. */
  11020. function cubicExtrema(p0, p1, p2, p3, extrema) {
  11021. var b = 6 * p2 - 12 * p1 + 6 * p0;
  11022. var a = 9 * p1 + 3 * p3 - 3 * p0 - 9 * p2;
  11023. var c = 3 * p1 - 3 * p0;
  11024. var n = 0;
  11025. if (isAroundZero(a)) {
  11026. if (isNotAroundZero(b)) {
  11027. var t1 = -c / b;
  11028. if (t1 >= 0 && t1 <=1) {
  11029. extrema[n++] = t1;
  11030. }
  11031. }
  11032. }
  11033. else {
  11034. var disc = b * b - 4 * a * c;
  11035. if (isAroundZero(disc)) {
  11036. extrema[0] = -b / (2 * a);
  11037. }
  11038. else if (disc > 0) {
  11039. var discSqrt = mathSqrt(disc);
  11040. var t1 = (-b + discSqrt) / (2 * a);
  11041. var t2 = (-b - discSqrt) / (2 * a);
  11042. if (t1 >= 0 && t1 <= 1) {
  11043. extrema[n++] = t1;
  11044. }
  11045. if (t2 >= 0 && t2 <= 1) {
  11046. extrema[n++] = t2;
  11047. }
  11048. }
  11049. }
  11050. return n;
  11051. }
  11052. /**
  11053. * 细分三次贝塞尔曲线
  11054. * @memberOf module:zrender/core/curve
  11055. * @param {number} p0
  11056. * @param {number} p1
  11057. * @param {number} p2
  11058. * @param {number} p3
  11059. * @param {number} t
  11060. * @param {Array.<number>} out
  11061. */
  11062. function cubicSubdivide(p0, p1, p2, p3, t, out) {
  11063. var p01 = (p1 - p0) * t + p0;
  11064. var p12 = (p2 - p1) * t + p1;
  11065. var p23 = (p3 - p2) * t + p2;
  11066. var p012 = (p12 - p01) * t + p01;
  11067. var p123 = (p23 - p12) * t + p12;
  11068. var p0123 = (p123 - p012) * t + p012;
  11069. // Seg0
  11070. out[0] = p0;
  11071. out[1] = p01;
  11072. out[2] = p012;
  11073. out[3] = p0123;
  11074. // Seg1
  11075. out[4] = p0123;
  11076. out[5] = p123;
  11077. out[6] = p23;
  11078. out[7] = p3;
  11079. }
  11080. /**
  11081. * 投射点到三次贝塞尔曲线上,返回投射距离。
  11082. * 投射点有可能会有一个或者多个,这里只返回其中距离最短的一个。
  11083. * @param {number} x0
  11084. * @param {number} y0
  11085. * @param {number} x1
  11086. * @param {number} y1
  11087. * @param {number} x2
  11088. * @param {number} y2
  11089. * @param {number} x3
  11090. * @param {number} y3
  11091. * @param {number} x
  11092. * @param {number} y
  11093. * @param {Array.<number>} [out] 投射点
  11094. * @return {number}
  11095. */
  11096. function cubicProjectPoint(
  11097. x0, y0, x1, y1, x2, y2, x3, y3,
  11098. x, y, out
  11099. ) {
  11100. // http://pomax.github.io/bezierinfo/#projections
  11101. var t;
  11102. var interval = 0.005;
  11103. var d = Infinity;
  11104. var prev;
  11105. var next;
  11106. var d1;
  11107. var d2;
  11108. _v0[0] = x;
  11109. _v0[1] = y;
  11110. // 先粗略估计一下可能的最小距离的 t 值
  11111. // PENDING
  11112. for (var _t = 0; _t < 1; _t += 0.05) {
  11113. _v1[0] = cubicAt(x0, x1, x2, x3, _t);
  11114. _v1[1] = cubicAt(y0, y1, y2, y3, _t);
  11115. d1 = v2DistSquare(_v0, _v1);
  11116. if (d1 < d) {
  11117. t = _t;
  11118. d = d1;
  11119. }
  11120. }
  11121. d = Infinity;
  11122. // At most 32 iteration
  11123. for (var i = 0; i < 32; i++) {
  11124. if (interval < EPSILON_NUMERIC) {
  11125. break;
  11126. }
  11127. prev = t - interval;
  11128. next = t + interval;
  11129. // t - interval
  11130. _v1[0] = cubicAt(x0, x1, x2, x3, prev);
  11131. _v1[1] = cubicAt(y0, y1, y2, y3, prev);
  11132. d1 = v2DistSquare(_v1, _v0);
  11133. if (prev >= 0 && d1 < d) {
  11134. t = prev;
  11135. d = d1;
  11136. }
  11137. else {
  11138. // t + interval
  11139. _v2[0] = cubicAt(x0, x1, x2, x3, next);
  11140. _v2[1] = cubicAt(y0, y1, y2, y3, next);
  11141. d2 = v2DistSquare(_v2, _v0);
  11142. if (next <= 1 && d2 < d) {
  11143. t = next;
  11144. d = d2;
  11145. }
  11146. else {
  11147. interval *= 0.5;
  11148. }
  11149. }
  11150. }
  11151. // t
  11152. if (out) {
  11153. out[0] = cubicAt(x0, x1, x2, x3, t);
  11154. out[1] = cubicAt(y0, y1, y2, y3, t);
  11155. }
  11156. // console.log(interval, i);
  11157. return mathSqrt(d);
  11158. }
  11159. /**
  11160. * 计算二次方贝塞尔值
  11161. * @param {number} p0
  11162. * @param {number} p1
  11163. * @param {number} p2
  11164. * @param {number} t
  11165. * @return {number}
  11166. */
  11167. function quadraticAt(p0, p1, p2, t) {
  11168. var onet = 1 - t;
  11169. return onet * (onet * p0 + 2 * t * p1) + t * t * p2;
  11170. }
  11171. /**
  11172. * 计算二次方贝塞尔导数值
  11173. * @param {number} p0
  11174. * @param {number} p1
  11175. * @param {number} p2
  11176. * @param {number} t
  11177. * @return {number}
  11178. */
  11179. function quadraticDerivativeAt(p0, p1, p2, t) {
  11180. return 2 * ((1 - t) * (p1 - p0) + t * (p2 - p1));
  11181. }
  11182. /**
  11183. * 计算二次方贝塞尔方程根
  11184. * @param {number} p0
  11185. * @param {number} p1
  11186. * @param {number} p2
  11187. * @param {number} t
  11188. * @param {Array.<number>} roots
  11189. * @return {number} 有效根数目
  11190. */
  11191. function quadraticRootAt(p0, p1, p2, val, roots) {
  11192. var a = p0 - 2 * p1 + p2;
  11193. var b = 2 * (p1 - p0);
  11194. var c = p0 - val;
  11195. var n = 0;
  11196. if (isAroundZero(a)) {
  11197. if (isNotAroundZero(b)) {
  11198. var t1 = -c / b;
  11199. if (t1 >= 0 && t1 <= 1) {
  11200. roots[n++] = t1;
  11201. }
  11202. }
  11203. }
  11204. else {
  11205. var disc = b * b - 4 * a * c;
  11206. if (isAroundZero(disc)) {
  11207. var t1 = -b / (2 * a);
  11208. if (t1 >= 0 && t1 <= 1) {
  11209. roots[n++] = t1;
  11210. }
  11211. }
  11212. else if (disc > 0) {
  11213. var discSqrt = mathSqrt(disc);
  11214. var t1 = (-b + discSqrt) / (2 * a);
  11215. var t2 = (-b - discSqrt) / (2 * a);
  11216. if (t1 >= 0 && t1 <= 1) {
  11217. roots[n++] = t1;
  11218. }
  11219. if (t2 >= 0 && t2 <= 1) {
  11220. roots[n++] = t2;
  11221. }
  11222. }
  11223. }
  11224. return n;
  11225. }
  11226. /**
  11227. * 计算二次贝塞尔方程极限值
  11228. * @memberOf module:zrender/core/curve
  11229. * @param {number} p0
  11230. * @param {number} p1
  11231. * @param {number} p2
  11232. * @return {number}
  11233. */
  11234. function quadraticExtremum(p0, p1, p2) {
  11235. var divider = p0 + p2 - 2 * p1;
  11236. if (divider === 0) {
  11237. // p1 is center of p0 and p2
  11238. return 0.5;
  11239. }
  11240. else {
  11241. return (p0 - p1) / divider;
  11242. }
  11243. }
  11244. /**
  11245. * 细分二次贝塞尔曲线
  11246. * @memberOf module:zrender/core/curve
  11247. * @param {number} p0
  11248. * @param {number} p1
  11249. * @param {number} p2
  11250. * @param {number} t
  11251. * @param {Array.<number>} out
  11252. */
  11253. function quadraticSubdivide(p0, p1, p2, t, out) {
  11254. var p01 = (p1 - p0) * t + p0;
  11255. var p12 = (p2 - p1) * t + p1;
  11256. var p012 = (p12 - p01) * t + p01;
  11257. // Seg0
  11258. out[0] = p0;
  11259. out[1] = p01;
  11260. out[2] = p012;
  11261. // Seg1
  11262. out[3] = p012;
  11263. out[4] = p12;
  11264. out[5] = p2;
  11265. }
  11266. /**
  11267. * 投射点到二次贝塞尔曲线上,返回投射距离。
  11268. * 投射点有可能会有一个或者多个,这里只返回其中距离最短的一个。
  11269. * @param {number} x0
  11270. * @param {number} y0
  11271. * @param {number} x1
  11272. * @param {number} y1
  11273. * @param {number} x2
  11274. * @param {number} y2
  11275. * @param {number} x
  11276. * @param {number} y
  11277. * @param {Array.<number>} out 投射点
  11278. * @return {number}
  11279. */
  11280. function quadraticProjectPoint(
  11281. x0, y0, x1, y1, x2, y2,
  11282. x, y, out
  11283. ) {
  11284. // http://pomax.github.io/bezierinfo/#projections
  11285. var t;
  11286. var interval = 0.005;
  11287. var d = Infinity;
  11288. _v0[0] = x;
  11289. _v0[1] = y;
  11290. // 先粗略估计一下可能的最小距离的 t 值
  11291. // PENDING
  11292. for (var _t = 0; _t < 1; _t += 0.05) {
  11293. _v1[0] = quadraticAt(x0, x1, x2, _t);
  11294. _v1[1] = quadraticAt(y0, y1, y2, _t);
  11295. var d1 = v2DistSquare(_v0, _v1);
  11296. if (d1 < d) {
  11297. t = _t;
  11298. d = d1;
  11299. }
  11300. }
  11301. d = Infinity;
  11302. // At most 32 iteration
  11303. for (var i = 0; i < 32; i++) {
  11304. if (interval < EPSILON_NUMERIC) {
  11305. break;
  11306. }
  11307. var prev = t - interval;
  11308. var next = t + interval;
  11309. // t - interval
  11310. _v1[0] = quadraticAt(x0, x1, x2, prev);
  11311. _v1[1] = quadraticAt(y0, y1, y2, prev);
  11312. var d1 = v2DistSquare(_v1, _v0);
  11313. if (prev >= 0 && d1 < d) {
  11314. t = prev;
  11315. d = d1;
  11316. }
  11317. else {
  11318. // t + interval
  11319. _v2[0] = quadraticAt(x0, x1, x2, next);
  11320. _v2[1] = quadraticAt(y0, y1, y2, next);
  11321. var d2 = v2DistSquare(_v2, _v0);
  11322. if (next <= 1 && d2 < d) {
  11323. t = next;
  11324. d = d2;
  11325. }
  11326. else {
  11327. interval *= 0.5;
  11328. }
  11329. }
  11330. }
  11331. // t
  11332. if (out) {
  11333. out[0] = quadraticAt(x0, x1, x2, t);
  11334. out[1] = quadraticAt(y0, y1, y2, t);
  11335. }
  11336. // console.log(interval, i);
  11337. return mathSqrt(d);
  11338. }
  11339. module.exports = {
  11340. cubicAt: cubicAt,
  11341. cubicDerivativeAt: cubicDerivativeAt,
  11342. cubicRootAt: cubicRootAt,
  11343. cubicExtrema: cubicExtrema,
  11344. cubicSubdivide: cubicSubdivide,
  11345. cubicProjectPoint: cubicProjectPoint,
  11346. quadraticAt: quadraticAt,
  11347. quadraticDerivativeAt: quadraticDerivativeAt,
  11348. quadraticRootAt: quadraticRootAt,
  11349. quadraticExtremum: quadraticExtremum,
  11350. quadraticSubdivide: quadraticSubdivide,
  11351. quadraticProjectPoint: quadraticProjectPoint
  11352. };
  11353. /***/ },
  11354. /* 38 */
  11355. /***/ function(module, exports, __webpack_require__) {
  11356. /**
  11357. * @author Yi Shen(https://github.com/pissang)
  11358. */
  11359. var vec2 = __webpack_require__(10);
  11360. var curve = __webpack_require__(37);
  11361. var bbox = {};
  11362. var mathMin = Math.min;
  11363. var mathMax = Math.max;
  11364. var mathSin = Math.sin;
  11365. var mathCos = Math.cos;
  11366. var start = vec2.create();
  11367. var end = vec2.create();
  11368. var extremity = vec2.create();
  11369. var PI2 = Math.PI * 2;
  11370. /**
  11371. * 从顶点数组中计算出最小包围盒,写入`min`和`max`中
  11372. * @module zrender/core/bbox
  11373. * @param {Array<Object>} points 顶点数组
  11374. * @param {number} min
  11375. * @param {number} max
  11376. */
  11377. bbox.fromPoints = function(points, min, max) {
  11378. if (points.length === 0) {
  11379. return;
  11380. }
  11381. var p = points[0];
  11382. var left = p[0];
  11383. var right = p[0];
  11384. var top = p[1];
  11385. var bottom = p[1];
  11386. var i;
  11387. for (i = 1; i < points.length; i++) {
  11388. p = points[i];
  11389. left = mathMin(left, p[0]);
  11390. right = mathMax(right, p[0]);
  11391. top = mathMin(top, p[1]);
  11392. bottom = mathMax(bottom, p[1]);
  11393. }
  11394. min[0] = left;
  11395. min[1] = top;
  11396. max[0] = right;
  11397. max[1] = bottom;
  11398. };
  11399. /**
  11400. * @memberOf module:zrender/core/bbox
  11401. * @param {number} x0
  11402. * @param {number} y0
  11403. * @param {number} x1
  11404. * @param {number} y1
  11405. * @param {Array.<number>} min
  11406. * @param {Array.<number>} max
  11407. */
  11408. bbox.fromLine = function (x0, y0, x1, y1, min, max) {
  11409. min[0] = mathMin(x0, x1);
  11410. min[1] = mathMin(y0, y1);
  11411. max[0] = mathMax(x0, x1);
  11412. max[1] = mathMax(y0, y1);
  11413. };
  11414. var xDim = [];
  11415. var yDim = [];
  11416. /**
  11417. * 从三阶贝塞尔曲线(p0, p1, p2, p3)中计算出最小包围盒,写入`min`和`max`中
  11418. * @memberOf module:zrender/core/bbox
  11419. * @param {number} x0
  11420. * @param {number} y0
  11421. * @param {number} x1
  11422. * @param {number} y1
  11423. * @param {number} x2
  11424. * @param {number} y2
  11425. * @param {number} x3
  11426. * @param {number} y3
  11427. * @param {Array.<number>} min
  11428. * @param {Array.<number>} max
  11429. */
  11430. bbox.fromCubic = function(
  11431. x0, y0, x1, y1, x2, y2, x3, y3, min, max
  11432. ) {
  11433. var cubicExtrema = curve.cubicExtrema;
  11434. var cubicAt = curve.cubicAt;
  11435. var i;
  11436. var n = cubicExtrema(x0, x1, x2, x3, xDim);
  11437. min[0] = Infinity;
  11438. min[1] = Infinity;
  11439. max[0] = -Infinity;
  11440. max[1] = -Infinity;
  11441. for (i = 0; i < n; i++) {
  11442. var x = cubicAt(x0, x1, x2, x3, xDim[i]);
  11443. min[0] = mathMin(x, min[0]);
  11444. max[0] = mathMax(x, max[0]);
  11445. }
  11446. n = cubicExtrema(y0, y1, y2, y3, yDim);
  11447. for (i = 0; i < n; i++) {
  11448. var y = cubicAt(y0, y1, y2, y3, yDim[i]);
  11449. min[1] = mathMin(y, min[1]);
  11450. max[1] = mathMax(y, max[1]);
  11451. }
  11452. min[0] = mathMin(x0, min[0]);
  11453. max[0] = mathMax(x0, max[0]);
  11454. min[0] = mathMin(x3, min[0]);
  11455. max[0] = mathMax(x3, max[0]);
  11456. min[1] = mathMin(y0, min[1]);
  11457. max[1] = mathMax(y0, max[1]);
  11458. min[1] = mathMin(y3, min[1]);
  11459. max[1] = mathMax(y3, max[1]);
  11460. };
  11461. /**
  11462. * 从二阶贝塞尔曲线(p0, p1, p2)中计算出最小包围盒,写入`min`和`max`中
  11463. * @memberOf module:zrender/core/bbox
  11464. * @param {number} x0
  11465. * @param {number} y0
  11466. * @param {number} x1
  11467. * @param {number} y1
  11468. * @param {number} x2
  11469. * @param {number} y2
  11470. * @param {Array.<number>} min
  11471. * @param {Array.<number>} max
  11472. */
  11473. bbox.fromQuadratic = function(x0, y0, x1, y1, x2, y2, min, max) {
  11474. var quadraticExtremum = curve.quadraticExtremum;
  11475. var quadraticAt = curve.quadraticAt;
  11476. // Find extremities, where derivative in x dim or y dim is zero
  11477. var tx =
  11478. mathMax(
  11479. mathMin(quadraticExtremum(x0, x1, x2), 1), 0
  11480. );
  11481. var ty =
  11482. mathMax(
  11483. mathMin(quadraticExtremum(y0, y1, y2), 1), 0
  11484. );
  11485. var x = quadraticAt(x0, x1, x2, tx);
  11486. var y = quadraticAt(y0, y1, y2, ty);
  11487. min[0] = mathMin(x0, x2, x);
  11488. min[1] = mathMin(y0, y2, y);
  11489. max[0] = mathMax(x0, x2, x);
  11490. max[1] = mathMax(y0, y2, y);
  11491. };
  11492. /**
  11493. * 从圆弧中计算出最小包围盒,写入`min`和`max`中
  11494. * @method
  11495. * @memberOf module:zrender/core/bbox
  11496. * @param {number} x
  11497. * @param {number} y
  11498. * @param {number} rx
  11499. * @param {number} ry
  11500. * @param {number} startAngle
  11501. * @param {number} endAngle
  11502. * @param {number} anticlockwise
  11503. * @param {Array.<number>} min
  11504. * @param {Array.<number>} max
  11505. */
  11506. bbox.fromArc = function (
  11507. x, y, rx, ry, startAngle, endAngle, anticlockwise, min, max
  11508. ) {
  11509. var vec2Min = vec2.min;
  11510. var vec2Max = vec2.max;
  11511. var diff = Math.abs(startAngle - endAngle);
  11512. if (diff % PI2 < 1e-4 && diff > 1e-4) {
  11513. // Is a circle
  11514. min[0] = x - rx;
  11515. min[1] = y - ry;
  11516. max[0] = x + rx;
  11517. max[1] = y + ry;
  11518. return;
  11519. }
  11520. start[0] = mathCos(startAngle) * rx + x;
  11521. start[1] = mathSin(startAngle) * ry + y;
  11522. end[0] = mathCos(endAngle) * rx + x;
  11523. end[1] = mathSin(endAngle) * ry + y;
  11524. vec2Min(min, start, end);
  11525. vec2Max(max, start, end);
  11526. // Thresh to [0, Math.PI * 2]
  11527. startAngle = startAngle % (PI2);
  11528. if (startAngle < 0) {
  11529. startAngle = startAngle + PI2;
  11530. }
  11531. endAngle = endAngle % (PI2);
  11532. if (endAngle < 0) {
  11533. endAngle = endAngle + PI2;
  11534. }
  11535. if (startAngle > endAngle && !anticlockwise) {
  11536. endAngle += PI2;
  11537. }
  11538. else if (startAngle < endAngle && anticlockwise) {
  11539. startAngle += PI2;
  11540. }
  11541. if (anticlockwise) {
  11542. var tmp = endAngle;
  11543. endAngle = startAngle;
  11544. startAngle = tmp;
  11545. }
  11546. // var number = 0;
  11547. // var step = (anticlockwise ? -Math.PI : Math.PI) / 2;
  11548. for (var angle = 0; angle < endAngle; angle += Math.PI / 2) {
  11549. if (angle > startAngle) {
  11550. extremity[0] = mathCos(angle) * rx + x;
  11551. extremity[1] = mathSin(angle) * ry + y;
  11552. vec2Min(min, extremity, min);
  11553. vec2Max(max, extremity, max);
  11554. }
  11555. }
  11556. };
  11557. module.exports = bbox;
  11558. /***/ },
  11559. /* 39 */
  11560. /***/ function(module, exports, __webpack_require__) {
  11561. 'use strict';
  11562. var CMD = __webpack_require__(36).CMD;
  11563. var line = __webpack_require__(40);
  11564. var cubic = __webpack_require__(41);
  11565. var quadratic = __webpack_require__(42);
  11566. var arc = __webpack_require__(43);
  11567. var normalizeRadian = __webpack_require__(44).normalizeRadian;
  11568. var curve = __webpack_require__(37);
  11569. var windingLine = __webpack_require__(45);
  11570. var containStroke = line.containStroke;
  11571. var PI2 = Math.PI * 2;
  11572. var EPSILON = 1e-4;
  11573. function isAroundEqual(a, b) {
  11574. return Math.abs(a - b) < EPSILON;
  11575. }
  11576. // 临时数组
  11577. var roots = [-1, -1, -1];
  11578. var extrema = [-1, -1];
  11579. function swapExtrema() {
  11580. var tmp = extrema[0];
  11581. extrema[0] = extrema[1];
  11582. extrema[1] = tmp;
  11583. }
  11584. function windingCubic(x0, y0, x1, y1, x2, y2, x3, y3, x, y) {
  11585. // Quick reject
  11586. if (
  11587. (y > y0 && y > y1 && y > y2 && y > y3)
  11588. || (y < y0 && y < y1 && y < y2 && y < y3)
  11589. ) {
  11590. return 0;
  11591. }
  11592. var nRoots = curve.cubicRootAt(y0, y1, y2, y3, y, roots);
  11593. if (nRoots === 0) {
  11594. return 0;
  11595. }
  11596. else {
  11597. var w = 0;
  11598. var nExtrema = -1;
  11599. var y0_, y1_;
  11600. for (var i = 0; i < nRoots; i++) {
  11601. var t = roots[i];
  11602. // Avoid winding error when intersection point is the connect point of two line of polygon
  11603. var unit = (t === 0 || t === 1) ? 0.5 : 1;
  11604. var x_ = curve.cubicAt(x0, x1, x2, x3, t);
  11605. if (x_ < x) { // Quick reject
  11606. continue;
  11607. }
  11608. if (nExtrema < 0) {
  11609. nExtrema = curve.cubicExtrema(y0, y1, y2, y3, extrema);
  11610. if (extrema[1] < extrema[0] && nExtrema > 1) {
  11611. swapExtrema();
  11612. }
  11613. y0_ = curve.cubicAt(y0, y1, y2, y3, extrema[0]);
  11614. if (nExtrema > 1) {
  11615. y1_ = curve.cubicAt(y0, y1, y2, y3, extrema[1]);
  11616. }
  11617. }
  11618. if (nExtrema == 2) {
  11619. // 分成三段单调函数
  11620. if (t < extrema[0]) {
  11621. w += y0_ < y0 ? unit : -unit;
  11622. }
  11623. else if (t < extrema[1]) {
  11624. w += y1_ < y0_ ? unit : -unit;
  11625. }
  11626. else {
  11627. w += y3 < y1_ ? unit : -unit;
  11628. }
  11629. }
  11630. else {
  11631. // 分成两段单调函数
  11632. if (t < extrema[0]) {
  11633. w += y0_ < y0 ? unit : -unit;
  11634. }
  11635. else {
  11636. w += y3 < y0_ ? unit : -unit;
  11637. }
  11638. }
  11639. }
  11640. return w;
  11641. }
  11642. }
  11643. function windingQuadratic(x0, y0, x1, y1, x2, y2, x, y) {
  11644. // Quick reject
  11645. if (
  11646. (y > y0 && y > y1 && y > y2)
  11647. || (y < y0 && y < y1 && y < y2)
  11648. ) {
  11649. return 0;
  11650. }
  11651. var nRoots = curve.quadraticRootAt(y0, y1, y2, y, roots);
  11652. if (nRoots === 0) {
  11653. return 0;
  11654. }
  11655. else {
  11656. var t = curve.quadraticExtremum(y0, y1, y2);
  11657. if (t >= 0 && t <= 1) {
  11658. var w = 0;
  11659. var y_ = curve.quadraticAt(y0, y1, y2, t);
  11660. for (var i = 0; i < nRoots; i++) {
  11661. // Remove one endpoint.
  11662. var unit = (roots[i] === 0 || roots[i] === 1) ? 0.5 : 1;
  11663. var x_ = curve.quadraticAt(x0, x1, x2, roots[i]);
  11664. if (x_ < x) { // Quick reject
  11665. continue;
  11666. }
  11667. if (roots[i] < t) {
  11668. w += y_ < y0 ? unit : -unit;
  11669. }
  11670. else {
  11671. w += y2 < y_ ? unit : -unit;
  11672. }
  11673. }
  11674. return w;
  11675. }
  11676. else {
  11677. // Remove one endpoint.
  11678. var unit = (roots[0] === 0 || roots[0] === 1) ? 0.5 : 1;
  11679. var x_ = curve.quadraticAt(x0, x1, x2, roots[0]);
  11680. if (x_ < x) { // Quick reject
  11681. return 0;
  11682. }
  11683. return y2 < y0 ? unit : -unit;
  11684. }
  11685. }
  11686. }
  11687. // TODO
  11688. // Arc 旋转
  11689. function windingArc(
  11690. cx, cy, r, startAngle, endAngle, anticlockwise, x, y
  11691. ) {
  11692. y -= cy;
  11693. if (y > r || y < -r) {
  11694. return 0;
  11695. }
  11696. var tmp = Math.sqrt(r * r - y * y);
  11697. roots[0] = -tmp;
  11698. roots[1] = tmp;
  11699. var diff = Math.abs(startAngle - endAngle);
  11700. if (diff < 1e-4) {
  11701. return 0;
  11702. }
  11703. if (diff % PI2 < 1e-4) {
  11704. // Is a circle
  11705. startAngle = 0;
  11706. endAngle = PI2;
  11707. var dir = anticlockwise ? 1 : -1;
  11708. if (x >= roots[0] + cx && x <= roots[1] + cx) {
  11709. return dir;
  11710. } else {
  11711. return 0;
  11712. }
  11713. }
  11714. if (anticlockwise) {
  11715. var tmp = startAngle;
  11716. startAngle = normalizeRadian(endAngle);
  11717. endAngle = normalizeRadian(tmp);
  11718. }
  11719. else {
  11720. startAngle = normalizeRadian(startAngle);
  11721. endAngle = normalizeRadian(endAngle);
  11722. }
  11723. if (startAngle > endAngle) {
  11724. endAngle += PI2;
  11725. }
  11726. var w = 0;
  11727. for (var i = 0; i < 2; i++) {
  11728. var x_ = roots[i];
  11729. if (x_ + cx > x) {
  11730. var angle = Math.atan2(y, x_);
  11731. var dir = anticlockwise ? 1 : -1;
  11732. if (angle < 0) {
  11733. angle = PI2 + angle;
  11734. }
  11735. if (
  11736. (angle >= startAngle && angle <= endAngle)
  11737. || (angle + PI2 >= startAngle && angle + PI2 <= endAngle)
  11738. ) {
  11739. if (angle > Math.PI / 2 && angle < Math.PI * 1.5) {
  11740. dir = -dir;
  11741. }
  11742. w += dir;
  11743. }
  11744. }
  11745. }
  11746. return w;
  11747. }
  11748. function containPath(data, lineWidth, isStroke, x, y) {
  11749. var w = 0;
  11750. var xi = 0;
  11751. var yi = 0;
  11752. var x0 = 0;
  11753. var y0 = 0;
  11754. for (var i = 0; i < data.length;) {
  11755. var cmd = data[i++];
  11756. // Begin a new subpath
  11757. if (cmd === CMD.M && i > 1) {
  11758. // Close previous subpath
  11759. if (!isStroke) {
  11760. w += windingLine(xi, yi, x0, y0, x, y);
  11761. }
  11762. // 如果被任何一个 subpath 包含
  11763. // if (w !== 0) {
  11764. // return true;
  11765. // }
  11766. }
  11767. if (i == 1) {
  11768. // 如果第一个命令是 L, C, Q
  11769. // 则 previous point 同绘制命令的第一个 point
  11770. //
  11771. // 第一个命令为 Arc 的情况下会在后面特殊处理
  11772. xi = data[i];
  11773. yi = data[i + 1];
  11774. x0 = xi;
  11775. y0 = yi;
  11776. }
  11777. switch (cmd) {
  11778. case CMD.M:
  11779. // moveTo 命令重新创建一个新的 subpath, 并且更新新的起点
  11780. // 在 closePath 的时候使用
  11781. x0 = data[i++];
  11782. y0 = data[i++];
  11783. xi = x0;
  11784. yi = y0;
  11785. break;
  11786. case CMD.L:
  11787. if (isStroke) {
  11788. if (containStroke(xi, yi, data[i], data[i + 1], lineWidth, x, y)) {
  11789. return true;
  11790. }
  11791. }
  11792. else {
  11793. // NOTE 在第一个命令为 L, C, Q 的时候会计算出 NaN
  11794. w += windingLine(xi, yi, data[i], data[i + 1], x, y) || 0;
  11795. }
  11796. xi = data[i++];
  11797. yi = data[i++];
  11798. break;
  11799. case CMD.C:
  11800. if (isStroke) {
  11801. if (cubic.containStroke(xi, yi,
  11802. data[i++], data[i++], data[i++], data[i++], data[i], data[i + 1],
  11803. lineWidth, x, y
  11804. )) {
  11805. return true;
  11806. }
  11807. }
  11808. else {
  11809. w += windingCubic(
  11810. xi, yi,
  11811. data[i++], data[i++], data[i++], data[i++], data[i], data[i + 1],
  11812. x, y
  11813. ) || 0;
  11814. }
  11815. xi = data[i++];
  11816. yi = data[i++];
  11817. break;
  11818. case CMD.Q:
  11819. if (isStroke) {
  11820. if (quadratic.containStroke(xi, yi,
  11821. data[i++], data[i++], data[i], data[i + 1],
  11822. lineWidth, x, y
  11823. )) {
  11824. return true;
  11825. }
  11826. }
  11827. else {
  11828. w += windingQuadratic(
  11829. xi, yi,
  11830. data[i++], data[i++], data[i], data[i + 1],
  11831. x, y
  11832. ) || 0;
  11833. }
  11834. xi = data[i++];
  11835. yi = data[i++];
  11836. break;
  11837. case CMD.A:
  11838. // TODO Arc 判断的开销比较大
  11839. var cx = data[i++];
  11840. var cy = data[i++];
  11841. var rx = data[i++];
  11842. var ry = data[i++];
  11843. var theta = data[i++];
  11844. var dTheta = data[i++];
  11845. // TODO Arc 旋转
  11846. var psi = data[i++];
  11847. var anticlockwise = 1 - data[i++];
  11848. var x1 = Math.cos(theta) * rx + cx;
  11849. var y1 = Math.sin(theta) * ry + cy;
  11850. // 不是直接使用 arc 命令
  11851. if (i > 1) {
  11852. w += windingLine(xi, yi, x1, y1, x, y);
  11853. }
  11854. else {
  11855. // 第一个命令起点还未定义
  11856. x0 = x1;
  11857. y0 = y1;
  11858. }
  11859. // zr 使用scale来模拟椭圆, 这里也对x做一定的缩放
  11860. var _x = (x - cx) * ry / rx + cx;
  11861. if (isStroke) {
  11862. if (arc.containStroke(
  11863. cx, cy, ry, theta, theta + dTheta, anticlockwise,
  11864. lineWidth, _x, y
  11865. )) {
  11866. return true;
  11867. }
  11868. }
  11869. else {
  11870. w += windingArc(
  11871. cx, cy, ry, theta, theta + dTheta, anticlockwise,
  11872. _x, y
  11873. );
  11874. }
  11875. xi = Math.cos(theta + dTheta) * rx + cx;
  11876. yi = Math.sin(theta + dTheta) * ry + cy;
  11877. break;
  11878. case CMD.R:
  11879. x0 = xi = data[i++];
  11880. y0 = yi = data[i++];
  11881. var width = data[i++];
  11882. var height = data[i++];
  11883. var x1 = x0 + width;
  11884. var y1 = y0 + height;
  11885. if (isStroke) {
  11886. if (containStroke(x0, y0, x1, y0, lineWidth, x, y)
  11887. || containStroke(x1, y0, x1, y1, lineWidth, x, y)
  11888. || containStroke(x1, y1, x0, y1, lineWidth, x, y)
  11889. || containStroke(x0, y1, x0, y0, lineWidth, x, y)
  11890. ) {
  11891. return true;
  11892. }
  11893. }
  11894. else {
  11895. // FIXME Clockwise ?
  11896. w += windingLine(x1, y0, x1, y1, x, y);
  11897. w += windingLine(x0, y1, x0, y0, x, y);
  11898. }
  11899. break;
  11900. case CMD.Z:
  11901. if (isStroke) {
  11902. if (containStroke(
  11903. xi, yi, x0, y0, lineWidth, x, y
  11904. )) {
  11905. return true;
  11906. }
  11907. }
  11908. else {
  11909. // Close a subpath
  11910. w += windingLine(xi, yi, x0, y0, x, y);
  11911. // 如果被任何一个 subpath 包含
  11912. // FIXME subpaths may overlap
  11913. // if (w !== 0) {
  11914. // return true;
  11915. // }
  11916. }
  11917. xi = x0;
  11918. yi = y0;
  11919. break;
  11920. }
  11921. }
  11922. if (!isStroke && !isAroundEqual(yi, y0)) {
  11923. w += windingLine(xi, yi, x0, y0, x, y) || 0;
  11924. }
  11925. return w !== 0;
  11926. }
  11927. module.exports = {
  11928. contain: function (pathData, x, y) {
  11929. return containPath(pathData, 0, false, x, y);
  11930. },
  11931. containStroke: function (pathData, lineWidth, x, y) {
  11932. return containPath(pathData, lineWidth, true, x, y);
  11933. }
  11934. };
  11935. /***/ },
  11936. /* 40 */
  11937. /***/ function(module, exports) {
  11938. module.exports = {
  11939. /**
  11940. * 线段包含判断
  11941. * @param {number} x0
  11942. * @param {number} y0
  11943. * @param {number} x1
  11944. * @param {number} y1
  11945. * @param {number} lineWidth
  11946. * @param {number} x
  11947. * @param {number} y
  11948. * @return {boolean}
  11949. */
  11950. containStroke: function (x0, y0, x1, y1, lineWidth, x, y) {
  11951. if (lineWidth === 0) {
  11952. return false;
  11953. }
  11954. var _l = lineWidth;
  11955. var _a = 0;
  11956. var _b = x0;
  11957. // Quick reject
  11958. if (
  11959. (y > y0 + _l && y > y1 + _l)
  11960. || (y < y0 - _l && y < y1 - _l)
  11961. || (x > x0 + _l && x > x1 + _l)
  11962. || (x < x0 - _l && x < x1 - _l)
  11963. ) {
  11964. return false;
  11965. }
  11966. if (x0 !== x1) {
  11967. _a = (y0 - y1) / (x0 - x1);
  11968. _b = (x0 * y1 - x1 * y0) / (x0 - x1) ;
  11969. }
  11970. else {
  11971. return Math.abs(x - x0) <= _l / 2;
  11972. }
  11973. var tmp = _a * x - y + _b;
  11974. var _s = tmp * tmp / (_a * _a + 1);
  11975. return _s <= _l / 2 * _l / 2;
  11976. }
  11977. };
  11978. /***/ },
  11979. /* 41 */
  11980. /***/ function(module, exports, __webpack_require__) {
  11981. var curve = __webpack_require__(37);
  11982. module.exports = {
  11983. /**
  11984. * 三次贝塞尔曲线描边包含判断
  11985. * @param {number} x0
  11986. * @param {number} y0
  11987. * @param {number} x1
  11988. * @param {number} y1
  11989. * @param {number} x2
  11990. * @param {number} y2
  11991. * @param {number} x3
  11992. * @param {number} y3
  11993. * @param {number} lineWidth
  11994. * @param {number} x
  11995. * @param {number} y
  11996. * @return {boolean}
  11997. */
  11998. containStroke: function(x0, y0, x1, y1, x2, y2, x3, y3, lineWidth, x, y) {
  11999. if (lineWidth === 0) {
  12000. return false;
  12001. }
  12002. var _l = lineWidth;
  12003. // Quick reject
  12004. if (
  12005. (y > y0 + _l && y > y1 + _l && y > y2 + _l && y > y3 + _l)
  12006. || (y < y0 - _l && y < y1 - _l && y < y2 - _l && y < y3 - _l)
  12007. || (x > x0 + _l && x > x1 + _l && x > x2 + _l && x > x3 + _l)
  12008. || (x < x0 - _l && x < x1 - _l && x < x2 - _l && x < x3 - _l)
  12009. ) {
  12010. return false;
  12011. }
  12012. var d = curve.cubicProjectPoint(
  12013. x0, y0, x1, y1, x2, y2, x3, y3,
  12014. x, y, null
  12015. );
  12016. return d <= _l / 2;
  12017. }
  12018. };
  12019. /***/ },
  12020. /* 42 */
  12021. /***/ function(module, exports, __webpack_require__) {
  12022. var curve = __webpack_require__(37);
  12023. module.exports = {
  12024. /**
  12025. * 二次贝塞尔曲线描边包含判断
  12026. * @param {number} x0
  12027. * @param {number} y0
  12028. * @param {number} x1
  12029. * @param {number} y1
  12030. * @param {number} x2
  12031. * @param {number} y2
  12032. * @param {number} lineWidth
  12033. * @param {number} x
  12034. * @param {number} y
  12035. * @return {boolean}
  12036. */
  12037. containStroke: function (x0, y0, x1, y1, x2, y2, lineWidth, x, y) {
  12038. if (lineWidth === 0) {
  12039. return false;
  12040. }
  12041. var _l = lineWidth;
  12042. // Quick reject
  12043. if (
  12044. (y > y0 + _l && y > y1 + _l && y > y2 + _l)
  12045. || (y < y0 - _l && y < y1 - _l && y < y2 - _l)
  12046. || (x > x0 + _l && x > x1 + _l && x > x2 + _l)
  12047. || (x < x0 - _l && x < x1 - _l && x < x2 - _l)
  12048. ) {
  12049. return false;
  12050. }
  12051. var d = curve.quadraticProjectPoint(
  12052. x0, y0, x1, y1, x2, y2,
  12053. x, y, null
  12054. );
  12055. return d <= _l / 2;
  12056. }
  12057. };
  12058. /***/ },
  12059. /* 43 */
  12060. /***/ function(module, exports, __webpack_require__) {
  12061. var normalizeRadian = __webpack_require__(44).normalizeRadian;
  12062. var PI2 = Math.PI * 2;
  12063. module.exports = {
  12064. /**
  12065. * 圆弧描边包含判断
  12066. * @param {number} cx
  12067. * @param {number} cy
  12068. * @param {number} r
  12069. * @param {number} startAngle
  12070. * @param {number} endAngle
  12071. * @param {boolean} anticlockwise
  12072. * @param {number} lineWidth
  12073. * @param {number} x
  12074. * @param {number} y
  12075. * @return {Boolean}
  12076. */
  12077. containStroke: function (
  12078. cx, cy, r, startAngle, endAngle, anticlockwise,
  12079. lineWidth, x, y
  12080. ) {
  12081. if (lineWidth === 0) {
  12082. return false;
  12083. }
  12084. var _l = lineWidth;
  12085. x -= cx;
  12086. y -= cy;
  12087. var d = Math.sqrt(x * x + y * y);
  12088. if ((d - _l > r) || (d + _l < r)) {
  12089. return false;
  12090. }
  12091. if (Math.abs(startAngle - endAngle) % PI2 < 1e-4) {
  12092. // Is a circle
  12093. return true;
  12094. }
  12095. if (anticlockwise) {
  12096. var tmp = startAngle;
  12097. startAngle = normalizeRadian(endAngle);
  12098. endAngle = normalizeRadian(tmp);
  12099. } else {
  12100. startAngle = normalizeRadian(startAngle);
  12101. endAngle = normalizeRadian(endAngle);
  12102. }
  12103. if (startAngle > endAngle) {
  12104. endAngle += PI2;
  12105. }
  12106. var angle = Math.atan2(y, x);
  12107. if (angle < 0) {
  12108. angle += PI2;
  12109. }
  12110. return (angle >= startAngle && angle <= endAngle)
  12111. || (angle + PI2 >= startAngle && angle + PI2 <= endAngle);
  12112. }
  12113. };
  12114. /***/ },
  12115. /* 44 */
  12116. /***/ function(module, exports) {
  12117. var PI2 = Math.PI * 2;
  12118. module.exports = {
  12119. normalizeRadian: function(angle) {
  12120. angle %= PI2;
  12121. if (angle < 0) {
  12122. angle += PI2;
  12123. }
  12124. return angle;
  12125. }
  12126. };
  12127. /***/ },
  12128. /* 45 */
  12129. /***/ function(module, exports) {
  12130. module.exports = function windingLine(x0, y0, x1, y1, x, y) {
  12131. if ((y > y0 && y > y1) || (y < y0 && y < y1)) {
  12132. return 0;
  12133. }
  12134. // Ignore horizontal line
  12135. if (y1 === y0) {
  12136. return 0;
  12137. }
  12138. var dir = y1 < y0 ? 1 : -1;
  12139. var t = (y - y0) / (y1 - y0);
  12140. // Avoid winding error when intersection point is the connect point of two line of polygon
  12141. if (t === 1 || t === 0) {
  12142. dir = y1 < y0 ? 0.5 : -0.5;
  12143. }
  12144. var x_ = t * (x1 - x0) + x0;
  12145. return x_ > x ? dir : 0;
  12146. };
  12147. /***/ },
  12148. /* 46 */
  12149. /***/ function(module, exports) {
  12150. var Pattern = function (image, repeat) {
  12151. // Should do nothing more in this constructor. Because gradient can be
  12152. // declard by `color: {image: ...}`, where this constructor will not be called.
  12153. this.image = image;
  12154. this.repeat = repeat;
  12155. // Can be cloned
  12156. this.type = 'pattern';
  12157. };
  12158. Pattern.prototype.getCanvasPattern = function (ctx) {
  12159. return ctx.createPattern(this.image, this.repeat || 'repeat');
  12160. };
  12161. module.exports = Pattern;
  12162. /***/ },
  12163. /* 47 */
  12164. /***/ function(module, exports, __webpack_require__) {
  12165. var CMD = __webpack_require__(36).CMD;
  12166. var vec2 = __webpack_require__(10);
  12167. var v2ApplyTransform = vec2.applyTransform;
  12168. var points = [[], [], []];
  12169. var mathSqrt = Math.sqrt;
  12170. var mathAtan2 = Math.atan2;
  12171. function transformPath(path, m) {
  12172. var data = path.data;
  12173. var cmd;
  12174. var nPoint;
  12175. var i;
  12176. var j;
  12177. var k;
  12178. var p;
  12179. var M = CMD.M;
  12180. var C = CMD.C;
  12181. var L = CMD.L;
  12182. var R = CMD.R;
  12183. var A = CMD.A;
  12184. var Q = CMD.Q;
  12185. for (i = 0, j = 0; i < data.length;) {
  12186. cmd = data[i++];
  12187. j = i;
  12188. nPoint = 0;
  12189. switch (cmd) {
  12190. case M:
  12191. nPoint = 1;
  12192. break;
  12193. case L:
  12194. nPoint = 1;
  12195. break;
  12196. case C:
  12197. nPoint = 3;
  12198. break;
  12199. case Q:
  12200. nPoint = 2;
  12201. break;
  12202. case A:
  12203. var x = m[4];
  12204. var y = m[5];
  12205. var sx = mathSqrt(m[0] * m[0] + m[1] * m[1]);
  12206. var sy = mathSqrt(m[2] * m[2] + m[3] * m[3]);
  12207. var angle = mathAtan2(-m[1] / sy, m[0] / sx);
  12208. // cx
  12209. data[i] *= sx;
  12210. data[i++] += x;
  12211. // cy
  12212. data[i] *= sy;
  12213. data[i++] += y;
  12214. // Scale rx and ry
  12215. // FIXME Assume psi is 0 here
  12216. data[i++] *= sx;
  12217. data[i++] *= sy;
  12218. // Start angle
  12219. data[i++] += angle;
  12220. // end angle
  12221. data[i++] += angle;
  12222. // FIXME psi
  12223. i += 2;
  12224. j = i;
  12225. break;
  12226. case R:
  12227. // x0, y0
  12228. p[0] = data[i++];
  12229. p[1] = data[i++];
  12230. v2ApplyTransform(p, p, m);
  12231. data[j++] = p[0];
  12232. data[j++] = p[1];
  12233. // x1, y1
  12234. p[0] += data[i++];
  12235. p[1] += data[i++];
  12236. v2ApplyTransform(p, p, m);
  12237. data[j++] = p[0];
  12238. data[j++] = p[1];
  12239. }
  12240. for (k = 0; k < nPoint; k++) {
  12241. var p = points[k];
  12242. p[0] = data[i++];
  12243. p[1] = data[i++];
  12244. v2ApplyTransform(p, p, m);
  12245. // Write back
  12246. data[j++] = p[0];
  12247. data[j++] = p[1];
  12248. }
  12249. }
  12250. }
  12251. module.exports = transformPath;
  12252. /***/ },
  12253. /* 48 */
  12254. /***/ function(module, exports, __webpack_require__) {
  12255. /**
  12256. * Group是一个容器,可以插入子节点,Group的变换也会被应用到子节点上
  12257. * @module zrender/graphic/Group
  12258. * @example
  12259. * var Group = require('zrender/lib/container/Group');
  12260. * var Circle = require('zrender/lib/graphic/shape/Circle');
  12261. * var g = new Group();
  12262. * g.position[0] = 100;
  12263. * g.position[1] = 100;
  12264. * g.add(new Circle({
  12265. * style: {
  12266. * x: 100,
  12267. * y: 100,
  12268. * r: 20,
  12269. * }
  12270. * }));
  12271. * zr.add(g);
  12272. */
  12273. var zrUtil = __webpack_require__(4);
  12274. var Element = __webpack_require__(23);
  12275. var BoundingRect = __webpack_require__(9);
  12276. /**
  12277. * @alias module:zrender/graphic/Group
  12278. * @constructor
  12279. * @extends module:zrender/mixin/Transformable
  12280. * @extends module:zrender/mixin/Eventful
  12281. */
  12282. var Group = function (opts) {
  12283. opts = opts || {};
  12284. Element.call(this, opts);
  12285. for (var key in opts) {
  12286. if (opts.hasOwnProperty(key)) {
  12287. this[key] = opts[key];
  12288. }
  12289. }
  12290. this._children = [];
  12291. this.__storage = null;
  12292. this.__dirty = true;
  12293. };
  12294. Group.prototype = {
  12295. constructor: Group,
  12296. isGroup: true,
  12297. /**
  12298. * @type {string}
  12299. */
  12300. type: 'group',
  12301. /**
  12302. * 所有子孙元素是否响应鼠标事件
  12303. * @name module:/zrender/container/Group#silent
  12304. * @type {boolean}
  12305. * @default false
  12306. */
  12307. silent: false,
  12308. /**
  12309. * @return {Array.<module:zrender/Element>}
  12310. */
  12311. children: function () {
  12312. return this._children.slice();
  12313. },
  12314. /**
  12315. * 获取指定 index 的儿子节点
  12316. * @param {number} idx
  12317. * @return {module:zrender/Element}
  12318. */
  12319. childAt: function (idx) {
  12320. return this._children[idx];
  12321. },
  12322. /**
  12323. * 获取指定名字的儿子节点
  12324. * @param {string} name
  12325. * @return {module:zrender/Element}
  12326. */
  12327. childOfName: function (name) {
  12328. var children = this._children;
  12329. for (var i = 0; i < children.length; i++) {
  12330. if (children[i].name === name) {
  12331. return children[i];
  12332. }
  12333. }
  12334. },
  12335. /**
  12336. * @return {number}
  12337. */
  12338. childCount: function () {
  12339. return this._children.length;
  12340. },
  12341. /**
  12342. * 添加子节点到最后
  12343. * @param {module:zrender/Element} child
  12344. */
  12345. add: function (child) {
  12346. if (child && child !== this && child.parent !== this) {
  12347. this._children.push(child);
  12348. this._doAdd(child);
  12349. }
  12350. return this;
  12351. },
  12352. /**
  12353. * 添加子节点在 nextSibling 之前
  12354. * @param {module:zrender/Element} child
  12355. * @param {module:zrender/Element} nextSibling
  12356. */
  12357. addBefore: function (child, nextSibling) {
  12358. if (child && child !== this && child.parent !== this
  12359. && nextSibling && nextSibling.parent === this) {
  12360. var children = this._children;
  12361. var idx = children.indexOf(nextSibling);
  12362. if (idx >= 0) {
  12363. children.splice(idx, 0, child);
  12364. this._doAdd(child);
  12365. }
  12366. }
  12367. return this;
  12368. },
  12369. _doAdd: function (child) {
  12370. if (child.parent) {
  12371. child.parent.remove(child);
  12372. }
  12373. child.parent = this;
  12374. var storage = this.__storage;
  12375. var zr = this.__zr;
  12376. if (storage && storage !== child.__storage) {
  12377. storage.addToStorage(child);
  12378. if (child instanceof Group) {
  12379. child.addChildrenToStorage(storage);
  12380. }
  12381. }
  12382. zr && zr.refresh();
  12383. },
  12384. /**
  12385. * 移除子节点
  12386. * @param {module:zrender/Element} child
  12387. */
  12388. remove: function (child) {
  12389. var zr = this.__zr;
  12390. var storage = this.__storage;
  12391. var children = this._children;
  12392. var idx = zrUtil.indexOf(children, child);
  12393. if (idx < 0) {
  12394. return this;
  12395. }
  12396. children.splice(idx, 1);
  12397. child.parent = null;
  12398. if (storage) {
  12399. storage.delFromStorage(child);
  12400. if (child instanceof Group) {
  12401. child.delChildrenFromStorage(storage);
  12402. }
  12403. }
  12404. zr && zr.refresh();
  12405. return this;
  12406. },
  12407. /**
  12408. * 移除所有子节点
  12409. */
  12410. removeAll: function () {
  12411. var children = this._children;
  12412. var storage = this.__storage;
  12413. var child;
  12414. var i;
  12415. for (i = 0; i < children.length; i++) {
  12416. child = children[i];
  12417. if (storage) {
  12418. storage.delFromStorage(child);
  12419. if (child instanceof Group) {
  12420. child.delChildrenFromStorage(storage);
  12421. }
  12422. }
  12423. child.parent = null;
  12424. }
  12425. children.length = 0;
  12426. return this;
  12427. },
  12428. /**
  12429. * 遍历所有子节点
  12430. * @param {Function} cb
  12431. * @param {} context
  12432. */
  12433. eachChild: function (cb, context) {
  12434. var children = this._children;
  12435. for (var i = 0; i < children.length; i++) {
  12436. var child = children[i];
  12437. cb.call(context, child, i);
  12438. }
  12439. return this;
  12440. },
  12441. /**
  12442. * 深度优先遍历所有子孙节点
  12443. * @param {Function} cb
  12444. * @param {} context
  12445. */
  12446. traverse: function (cb, context) {
  12447. for (var i = 0; i < this._children.length; i++) {
  12448. var child = this._children[i];
  12449. cb.call(context, child);
  12450. if (child.type === 'group') {
  12451. child.traverse(cb, context);
  12452. }
  12453. }
  12454. return this;
  12455. },
  12456. addChildrenToStorage: function (storage) {
  12457. for (var i = 0; i < this._children.length; i++) {
  12458. var child = this._children[i];
  12459. storage.addToStorage(child);
  12460. if (child instanceof Group) {
  12461. child.addChildrenToStorage(storage);
  12462. }
  12463. }
  12464. },
  12465. delChildrenFromStorage: function (storage) {
  12466. for (var i = 0; i < this._children.length; i++) {
  12467. var child = this._children[i];
  12468. storage.delFromStorage(child);
  12469. if (child instanceof Group) {
  12470. child.delChildrenFromStorage(storage);
  12471. }
  12472. }
  12473. },
  12474. dirty: function () {
  12475. this.__dirty = true;
  12476. this.__zr && this.__zr.refresh();
  12477. return this;
  12478. },
  12479. /**
  12480. * @return {module:zrender/core/BoundingRect}
  12481. */
  12482. getBoundingRect: function (includeChildren) {
  12483. // TODO Caching
  12484. var rect = null;
  12485. var tmpRect = new BoundingRect(0, 0, 0, 0);
  12486. var children = includeChildren || this._children;
  12487. var tmpMat = [];
  12488. for (var i = 0; i < children.length; i++) {
  12489. var child = children[i];
  12490. if (child.ignore || child.invisible) {
  12491. continue;
  12492. }
  12493. var childRect = child.getBoundingRect();
  12494. var transform = child.getLocalTransform(tmpMat);
  12495. // TODO
  12496. // The boundingRect cacluated by transforming original
  12497. // rect may be bigger than the actual bundingRect when rotation
  12498. // is used. (Consider a circle rotated aginst its center, where
  12499. // the actual boundingRect should be the same as that not be
  12500. // rotated.) But we can not find better approach to calculate
  12501. // actual boundingRect yet, considering performance.
  12502. if (transform) {
  12503. tmpRect.copy(childRect);
  12504. tmpRect.applyTransform(transform);
  12505. rect = rect || tmpRect.clone();
  12506. rect.union(tmpRect);
  12507. }
  12508. else {
  12509. rect = rect || childRect.clone();
  12510. rect.union(childRect);
  12511. }
  12512. }
  12513. return rect || tmpRect;
  12514. }
  12515. };
  12516. zrUtil.inherits(Group, Element);
  12517. module.exports = Group;
  12518. /***/ },
  12519. /* 49 */
  12520. /***/ function(module, exports, __webpack_require__) {
  12521. /**
  12522. * Image element
  12523. * @module zrender/graphic/Image
  12524. */
  12525. var Displayable = __webpack_require__(21);
  12526. var BoundingRect = __webpack_require__(9);
  12527. var zrUtil = __webpack_require__(4);
  12528. var LRU = __webpack_require__(32);
  12529. var globalImageCache = new LRU(50);
  12530. /**
  12531. * @alias zrender/graphic/Image
  12532. * @extends module:zrender/graphic/Displayable
  12533. * @constructor
  12534. * @param {Object} opts
  12535. */
  12536. function ZImage(opts) {
  12537. Displayable.call(this, opts);
  12538. }
  12539. ZImage.prototype = {
  12540. constructor: ZImage,
  12541. type: 'image',
  12542. brush: function (ctx, prevEl) {
  12543. var style = this.style;
  12544. var src = style.image;
  12545. var image;
  12546. // Must bind each time
  12547. style.bind(ctx, this, prevEl);
  12548. // style.image is a url string
  12549. if (typeof src === 'string') {
  12550. image = this._image;
  12551. }
  12552. // style.image is an HTMLImageElement or HTMLCanvasElement or Canvas
  12553. else {
  12554. image = src;
  12555. }
  12556. // FIXME Case create many images with src
  12557. if (!image && src) {
  12558. // Try get from global image cache
  12559. var cachedImgObj = globalImageCache.get(src);
  12560. if (!cachedImgObj) {
  12561. // Create a new image
  12562. image = new Image();
  12563. image.onload = function () {
  12564. image.onload = null;
  12565. for (var i = 0; i < cachedImgObj.pending.length; i++) {
  12566. cachedImgObj.pending[i].dirty();
  12567. }
  12568. };
  12569. cachedImgObj = {
  12570. image: image,
  12571. pending: [this]
  12572. };
  12573. image.src = src;
  12574. globalImageCache.put(src, cachedImgObj);
  12575. this._image = image;
  12576. return;
  12577. }
  12578. else {
  12579. image = cachedImgObj.image;
  12580. this._image = image;
  12581. // Image is not complete finish, add to pending list
  12582. if (!image.width || !image.height) {
  12583. cachedImgObj.pending.push(this);
  12584. return;
  12585. }
  12586. }
  12587. }
  12588. if (image) {
  12589. // 图片已经加载完成
  12590. // if (image.nodeName.toUpperCase() == 'IMG') {
  12591. // if (!image.complete) {
  12592. // return;
  12593. // }
  12594. // }
  12595. // Else is canvas
  12596. var x = style.x || 0;
  12597. var y = style.y || 0;
  12598. // 图片加载失败
  12599. if (!image.width || !image.height) {
  12600. return;
  12601. }
  12602. var width = style.width;
  12603. var height = style.height;
  12604. var aspect = image.width / image.height;
  12605. if (width == null && height != null) {
  12606. // Keep image/height ratio
  12607. width = height * aspect;
  12608. }
  12609. else if (height == null && width != null) {
  12610. height = width / aspect;
  12611. }
  12612. else if (width == null && height == null) {
  12613. width = image.width;
  12614. height = image.height;
  12615. }
  12616. // 设置transform
  12617. this.setTransform(ctx);
  12618. if (style.sWidth && style.sHeight) {
  12619. var sx = style.sx || 0;
  12620. var sy = style.sy || 0;
  12621. ctx.drawImage(
  12622. image,
  12623. sx, sy, style.sWidth, style.sHeight,
  12624. x, y, width, height
  12625. );
  12626. }
  12627. else if (style.sx && style.sy) {
  12628. var sx = style.sx;
  12629. var sy = style.sy;
  12630. var sWidth = width - sx;
  12631. var sHeight = height - sy;
  12632. ctx.drawImage(
  12633. image,
  12634. sx, sy, sWidth, sHeight,
  12635. x, y, width, height
  12636. );
  12637. }
  12638. else {
  12639. ctx.drawImage(image, x, y, width, height);
  12640. }
  12641. this.restoreTransform(ctx);
  12642. // Draw rect text
  12643. if (style.text != null) {
  12644. this.drawRectText(ctx, this.getBoundingRect());
  12645. }
  12646. }
  12647. },
  12648. getBoundingRect: function () {
  12649. var style = this.style;
  12650. if (! this._rect) {
  12651. this._rect = new BoundingRect(
  12652. style.x || 0, style.y || 0, style.width || 0, style.height || 0
  12653. );
  12654. }
  12655. return this._rect;
  12656. }
  12657. };
  12658. zrUtil.inherits(ZImage, Displayable);
  12659. module.exports = ZImage;
  12660. /***/ },
  12661. /* 50 */
  12662. /***/ function(module, exports, __webpack_require__) {
  12663. /**
  12664. * Text element
  12665. * @module zrender/graphic/Text
  12666. *
  12667. * TODO Wrapping
  12668. *
  12669. * Text not support gradient
  12670. */
  12671. var Displayable = __webpack_require__(21);
  12672. var zrUtil = __webpack_require__(4);
  12673. var textContain = __webpack_require__(8);
  12674. /**
  12675. * @alias zrender/graphic/Text
  12676. * @extends module:zrender/graphic/Displayable
  12677. * @constructor
  12678. * @param {Object} opts
  12679. */
  12680. var Text = function (opts) {
  12681. Displayable.call(this, opts);
  12682. };
  12683. Text.prototype = {
  12684. constructor: Text,
  12685. type: 'text',
  12686. brush: function (ctx, prevEl) {
  12687. var style = this.style;
  12688. var x = style.x || 0;
  12689. var y = style.y || 0;
  12690. // Convert to string
  12691. var text = style.text;
  12692. // Convert to string
  12693. text != null && (text += '');
  12694. // Always bind style
  12695. style.bind(ctx, this, prevEl);
  12696. if (text) {
  12697. this.setTransform(ctx);
  12698. var textBaseline;
  12699. var textAlign = style.textAlign;
  12700. var font = style.textFont || style.font;
  12701. if (style.textVerticalAlign) {
  12702. var rect = textContain.getBoundingRect(
  12703. text, font, style.textAlign, 'top'
  12704. );
  12705. // Ignore textBaseline
  12706. textBaseline = 'middle';
  12707. switch (style.textVerticalAlign) {
  12708. case 'middle':
  12709. y -= rect.height / 2 - rect.lineHeight / 2;
  12710. break;
  12711. case 'bottom':
  12712. y -= rect.height - rect.lineHeight / 2;
  12713. break;
  12714. default:
  12715. y += rect.lineHeight / 2;
  12716. }
  12717. }
  12718. else {
  12719. textBaseline = style.textBaseline;
  12720. }
  12721. // TODO Invalid font
  12722. ctx.font = font || '12px sans-serif';
  12723. ctx.textAlign = textAlign || 'left';
  12724. // Use canvas default left textAlign. Giving invalid value will cause state not change
  12725. if (ctx.textAlign !== textAlign) {
  12726. ctx.textAlign = 'left';
  12727. }
  12728. // FIXME in text contain default is top
  12729. ctx.textBaseline = textBaseline || 'alphabetic';
  12730. // Use canvas default alphabetic baseline
  12731. if (ctx.textBaseline !== textBaseline) {
  12732. ctx.textBaseline = 'alphabetic';
  12733. }
  12734. var lineHeight = textContain.measureText('国', ctx.font).width;
  12735. var textLines = text.split('\n');
  12736. for (var i = 0; i < textLines.length; i++) {
  12737. // Fill after stroke so the outline will not cover the main part.
  12738. style.hasStroke() && ctx.strokeText(textLines[i], x, y);
  12739. style.hasFill() && ctx.fillText(textLines[i], x, y);
  12740. y += lineHeight;
  12741. }
  12742. this.restoreTransform(ctx);
  12743. }
  12744. },
  12745. getBoundingRect: function () {
  12746. var style = this.style;
  12747. if (!this._rect) {
  12748. var textVerticalAlign = style.textVerticalAlign;
  12749. var rect = textContain.getBoundingRect(
  12750. style.text + '', style.textFont || style.font, style.textAlign,
  12751. textVerticalAlign ? 'top' : style.textBaseline
  12752. );
  12753. switch (textVerticalAlign) {
  12754. case 'middle':
  12755. rect.y -= rect.height / 2;
  12756. break;
  12757. case 'bottom':
  12758. rect.y -= rect.height;
  12759. break;
  12760. }
  12761. rect.x += style.x || 0;
  12762. rect.y += style.y || 0;
  12763. if (style.hasStroke()) {
  12764. var w = style.lineWidth;
  12765. rect.x -= w / 2;
  12766. rect.y -= w / 2;
  12767. rect.width += w;
  12768. rect.height += w;
  12769. }
  12770. this._rect = rect;
  12771. }
  12772. return this._rect;
  12773. }
  12774. };
  12775. zrUtil.inherits(Text, Displayable);
  12776. module.exports = Text;
  12777. /***/ },
  12778. /* 51 */
  12779. /***/ function(module, exports, __webpack_require__) {
  12780. 'use strict';
  12781. /**
  12782. * 圆形
  12783. * @module zrender/shape/Circle
  12784. */
  12785. module.exports = __webpack_require__(20).extend({
  12786. type: 'circle',
  12787. shape: {
  12788. cx: 0,
  12789. cy: 0,
  12790. r: 0
  12791. },
  12792. buildPath : function (ctx, shape, inBundle) {
  12793. // Better stroking in ShapeBundle
  12794. // Always do it may have performence issue ( fill may be 2x more cost)
  12795. if (inBundle) {
  12796. ctx.moveTo(shape.cx + shape.r, shape.cy);
  12797. }
  12798. // else {
  12799. // if (ctx.allocate && !ctx.data.length) {
  12800. // ctx.allocate(ctx.CMD_MEM_SIZE.A);
  12801. // }
  12802. // }
  12803. // Better stroking in ShapeBundle
  12804. // ctx.moveTo(shape.cx + shape.r, shape.cy);
  12805. ctx.arc(shape.cx, shape.cy, shape.r, 0, Math.PI * 2, true);
  12806. }
  12807. });
  12808. /***/ },
  12809. /* 52 */
  12810. /***/ function(module, exports, __webpack_require__) {
  12811. /**
  12812. * 扇形
  12813. * @module zrender/graphic/shape/Sector
  12814. */
  12815. var env = __webpack_require__(2);
  12816. var Path = __webpack_require__(20);
  12817. var shadowTemp = [
  12818. ['shadowBlur', 0],
  12819. ['shadowColor', '#000'],
  12820. ['shadowOffsetX', 0],
  12821. ['shadowOffsetY', 0]
  12822. ];
  12823. module.exports = Path.extend({
  12824. type: 'sector',
  12825. shape: {
  12826. cx: 0,
  12827. cy: 0,
  12828. r0: 0,
  12829. r: 0,
  12830. startAngle: 0,
  12831. endAngle: Math.PI * 2,
  12832. clockwise: true
  12833. },
  12834. brush: (env.browser.ie && env.browser.version >= 11) // version: '11.0'
  12835. // Fix weird bug in some version of IE11 (like 11.0.9600.17801),
  12836. // where exception "unexpected call to method or property access"
  12837. // might be thrown when calling ctx.fill after a path whose area size
  12838. // is zero is drawn and ctx.clip() is called and shadowBlur is set.
  12839. // (e.g.,
  12840. // ctx.moveTo(10, 10);
  12841. // ctx.lineTo(20, 10);
  12842. // ctx.closePath();
  12843. // ctx.clip();
  12844. // ctx.shadowBlur = 10;
  12845. // ...
  12846. // ctx.fill();
  12847. // )
  12848. ? function () {
  12849. var clipPaths = this.__clipPaths;
  12850. var style = this.style;
  12851. var modified;
  12852. if (clipPaths) {
  12853. for (var i = 0; i < clipPaths.length; i++) {
  12854. var shape = clipPaths[i] && clipPaths[i].shape;
  12855. if (shape && shape.startAngle === shape.endAngle) {
  12856. for (var j = 0; j < shadowTemp.length; j++) {
  12857. shadowTemp[j][2] = style[shadowTemp[j][0]];
  12858. style[shadowTemp[j][0]] = shadowTemp[j][1];
  12859. }
  12860. modified = true;
  12861. break;
  12862. }
  12863. }
  12864. }
  12865. Path.prototype.brush.apply(this, arguments);
  12866. if (modified) {
  12867. for (var j = 0; j < shadowTemp.length; j++) {
  12868. style[shadowTemp[j][0]] = shadowTemp[j][2];
  12869. }
  12870. }
  12871. }
  12872. : Path.prototype.brush,
  12873. buildPath: function (ctx, shape) {
  12874. var x = shape.cx;
  12875. var y = shape.cy;
  12876. var r0 = Math.max(shape.r0 || 0, 0);
  12877. var r = Math.max(shape.r, 0);
  12878. var startAngle = shape.startAngle;
  12879. var endAngle = shape.endAngle;
  12880. var clockwise = shape.clockwise;
  12881. var unitX = Math.cos(startAngle);
  12882. var unitY = Math.sin(startAngle);
  12883. ctx.moveTo(unitX * r0 + x, unitY * r0 + y);
  12884. ctx.lineTo(unitX * r + x, unitY * r + y);
  12885. ctx.arc(x, y, r, startAngle, endAngle, !clockwise);
  12886. ctx.lineTo(
  12887. Math.cos(endAngle) * r0 + x,
  12888. Math.sin(endAngle) * r0 + y
  12889. );
  12890. if (r0 !== 0) {
  12891. ctx.arc(x, y, r0, endAngle, startAngle, clockwise);
  12892. }
  12893. ctx.closePath();
  12894. }
  12895. });
  12896. /***/ },
  12897. /* 53 */
  12898. /***/ function(module, exports, __webpack_require__) {
  12899. /**
  12900. * 圆环
  12901. * @module zrender/graphic/shape/Ring
  12902. */
  12903. module.exports = __webpack_require__(20).extend({
  12904. type: 'ring',
  12905. shape: {
  12906. cx: 0,
  12907. cy: 0,
  12908. r: 0,
  12909. r0: 0
  12910. },
  12911. buildPath: function (ctx, shape) {
  12912. var x = shape.cx;
  12913. var y = shape.cy;
  12914. var PI2 = Math.PI * 2;
  12915. ctx.moveTo(x + shape.r, y);
  12916. ctx.arc(x, y, shape.r, 0, PI2, false);
  12917. ctx.moveTo(x + shape.r0, y);
  12918. ctx.arc(x, y, shape.r0, 0, PI2, true);
  12919. }
  12920. });
  12921. /***/ },
  12922. /* 54 */
  12923. /***/ function(module, exports, __webpack_require__) {
  12924. /**
  12925. * 多边形
  12926. * @module zrender/shape/Polygon
  12927. */
  12928. var polyHelper = __webpack_require__(55);
  12929. module.exports = __webpack_require__(20).extend({
  12930. type: 'polygon',
  12931. shape: {
  12932. points: null,
  12933. smooth: false,
  12934. smoothConstraint: null
  12935. },
  12936. buildPath: function (ctx, shape) {
  12937. polyHelper.buildPath(ctx, shape, true);
  12938. }
  12939. });
  12940. /***/ },
  12941. /* 55 */
  12942. /***/ function(module, exports, __webpack_require__) {
  12943. var smoothSpline = __webpack_require__(56);
  12944. var smoothBezier = __webpack_require__(57);
  12945. module.exports = {
  12946. buildPath: function (ctx, shape, closePath) {
  12947. var points = shape.points;
  12948. var smooth = shape.smooth;
  12949. if (points && points.length >= 2) {
  12950. if (smooth && smooth !== 'spline') {
  12951. var controlPoints = smoothBezier(
  12952. points, smooth, closePath, shape.smoothConstraint
  12953. );
  12954. ctx.moveTo(points[0][0], points[0][1]);
  12955. var len = points.length;
  12956. for (var i = 0; i < (closePath ? len : len - 1); i++) {
  12957. var cp1 = controlPoints[i * 2];
  12958. var cp2 = controlPoints[i * 2 + 1];
  12959. var p = points[(i + 1) % len];
  12960. ctx.bezierCurveTo(
  12961. cp1[0], cp1[1], cp2[0], cp2[1], p[0], p[1]
  12962. );
  12963. }
  12964. }
  12965. else {
  12966. if (smooth === 'spline') {
  12967. points = smoothSpline(points, closePath);
  12968. }
  12969. ctx.moveTo(points[0][0], points[0][1]);
  12970. for (var i = 1, l = points.length; i < l; i++) {
  12971. ctx.lineTo(points[i][0], points[i][1]);
  12972. }
  12973. }
  12974. closePath && ctx.closePath();
  12975. }
  12976. }
  12977. };
  12978. /***/ },
  12979. /* 56 */
  12980. /***/ function(module, exports, __webpack_require__) {
  12981. /**
  12982. * Catmull-Rom spline 插值折线
  12983. * @module zrender/shape/util/smoothSpline
  12984. * @author pissang (https://www.github.com/pissang)
  12985. * Kener (@Kener-林峰, kener.linfeng@gmail.com)
  12986. * errorrik (errorrik@gmail.com)
  12987. */
  12988. var vec2 = __webpack_require__(10);
  12989. /**
  12990. * @inner
  12991. */
  12992. function interpolate(p0, p1, p2, p3, t, t2, t3) {
  12993. var v0 = (p2 - p0) * 0.5;
  12994. var v1 = (p3 - p1) * 0.5;
  12995. return (2 * (p1 - p2) + v0 + v1) * t3
  12996. + (-3 * (p1 - p2) - 2 * v0 - v1) * t2
  12997. + v0 * t + p1;
  12998. }
  12999. /**
  13000. * @alias module:zrender/shape/util/smoothSpline
  13001. * @param {Array} points 线段顶点数组
  13002. * @param {boolean} isLoop
  13003. * @return {Array}
  13004. */
  13005. module.exports = function (points, isLoop) {
  13006. var len = points.length;
  13007. var ret = [];
  13008. var distance = 0;
  13009. for (var i = 1; i < len; i++) {
  13010. distance += vec2.distance(points[i - 1], points[i]);
  13011. }
  13012. var segs = distance / 2;
  13013. segs = segs < len ? len : segs;
  13014. for (var i = 0; i < segs; i++) {
  13015. var pos = i / (segs - 1) * (isLoop ? len : len - 1);
  13016. var idx = Math.floor(pos);
  13017. var w = pos - idx;
  13018. var p0;
  13019. var p1 = points[idx % len];
  13020. var p2;
  13021. var p3;
  13022. if (!isLoop) {
  13023. p0 = points[idx === 0 ? idx : idx - 1];
  13024. p2 = points[idx > len - 2 ? len - 1 : idx + 1];
  13025. p3 = points[idx > len - 3 ? len - 1 : idx + 2];
  13026. }
  13027. else {
  13028. p0 = points[(idx - 1 + len) % len];
  13029. p2 = points[(idx + 1) % len];
  13030. p3 = points[(idx + 2) % len];
  13031. }
  13032. var w2 = w * w;
  13033. var w3 = w * w2;
  13034. ret.push([
  13035. interpolate(p0[0], p1[0], p2[0], p3[0], w, w2, w3),
  13036. interpolate(p0[1], p1[1], p2[1], p3[1], w, w2, w3)
  13037. ]);
  13038. }
  13039. return ret;
  13040. };
  13041. /***/ },
  13042. /* 57 */
  13043. /***/ function(module, exports, __webpack_require__) {
  13044. /**
  13045. * 贝塞尔平滑曲线
  13046. * @module zrender/shape/util/smoothBezier
  13047. * @author pissang (https://www.github.com/pissang)
  13048. * Kener (@Kener-林峰, kener.linfeng@gmail.com)
  13049. * errorrik (errorrik@gmail.com)
  13050. */
  13051. var vec2 = __webpack_require__(10);
  13052. var v2Min = vec2.min;
  13053. var v2Max = vec2.max;
  13054. var v2Scale = vec2.scale;
  13055. var v2Distance = vec2.distance;
  13056. var v2Add = vec2.add;
  13057. /**
  13058. * 贝塞尔平滑曲线
  13059. * @alias module:zrender/shape/util/smoothBezier
  13060. * @param {Array} points 线段顶点数组
  13061. * @param {number} smooth 平滑等级, 0-1
  13062. * @param {boolean} isLoop
  13063. * @param {Array} constraint 将计算出来的控制点约束在一个包围盒内
  13064. * 比如 [[0, 0], [100, 100]], 这个包围盒会与
  13065. * 整个折线的包围盒做一个并集用来约束控制点。
  13066. * @param {Array} 计算出来的控制点数组
  13067. */
  13068. module.exports = function (points, smooth, isLoop, constraint) {
  13069. var cps = [];
  13070. var v = [];
  13071. var v1 = [];
  13072. var v2 = [];
  13073. var prevPoint;
  13074. var nextPoint;
  13075. var min, max;
  13076. if (constraint) {
  13077. min = [Infinity, Infinity];
  13078. max = [-Infinity, -Infinity];
  13079. for (var i = 0, len = points.length; i < len; i++) {
  13080. v2Min(min, min, points[i]);
  13081. v2Max(max, max, points[i]);
  13082. }
  13083. // 与指定的包围盒做并集
  13084. v2Min(min, min, constraint[0]);
  13085. v2Max(max, max, constraint[1]);
  13086. }
  13087. for (var i = 0, len = points.length; i < len; i++) {
  13088. var point = points[i];
  13089. if (isLoop) {
  13090. prevPoint = points[i ? i - 1 : len - 1];
  13091. nextPoint = points[(i + 1) % len];
  13092. }
  13093. else {
  13094. if (i === 0 || i === len - 1) {
  13095. cps.push(vec2.clone(points[i]));
  13096. continue;
  13097. }
  13098. else {
  13099. prevPoint = points[i - 1];
  13100. nextPoint = points[i + 1];
  13101. }
  13102. }
  13103. vec2.sub(v, nextPoint, prevPoint);
  13104. // use degree to scale the handle length
  13105. v2Scale(v, v, smooth);
  13106. var d0 = v2Distance(point, prevPoint);
  13107. var d1 = v2Distance(point, nextPoint);
  13108. var sum = d0 + d1;
  13109. if (sum !== 0) {
  13110. d0 /= sum;
  13111. d1 /= sum;
  13112. }
  13113. v2Scale(v1, v, -d0);
  13114. v2Scale(v2, v, d1);
  13115. var cp0 = v2Add([], point, v1);
  13116. var cp1 = v2Add([], point, v2);
  13117. if (constraint) {
  13118. v2Max(cp0, cp0, min);
  13119. v2Min(cp0, cp0, max);
  13120. v2Max(cp1, cp1, min);
  13121. v2Min(cp1, cp1, max);
  13122. }
  13123. cps.push(cp0);
  13124. cps.push(cp1);
  13125. }
  13126. if (isLoop) {
  13127. cps.push(cps.shift());
  13128. }
  13129. return cps;
  13130. };
  13131. /***/ },
  13132. /* 58 */
  13133. /***/ function(module, exports, __webpack_require__) {
  13134. /**
  13135. * @module zrender/graphic/shape/Polyline
  13136. */
  13137. var polyHelper = __webpack_require__(55);
  13138. module.exports = __webpack_require__(20).extend({
  13139. type: 'polyline',
  13140. shape: {
  13141. points: null,
  13142. smooth: false,
  13143. smoothConstraint: null
  13144. },
  13145. style: {
  13146. stroke: '#000',
  13147. fill: null
  13148. },
  13149. buildPath: function (ctx, shape) {
  13150. polyHelper.buildPath(ctx, shape, false);
  13151. }
  13152. });
  13153. /***/ },
  13154. /* 59 */
  13155. /***/ function(module, exports, __webpack_require__) {
  13156. /**
  13157. * 矩形
  13158. * @module zrender/graphic/shape/Rect
  13159. */
  13160. var roundRectHelper = __webpack_require__(60);
  13161. module.exports = __webpack_require__(20).extend({
  13162. type: 'rect',
  13163. shape: {
  13164. // 左上、右上、右下、左下角的半径依次为r1、r2、r3、r4
  13165. // r缩写为1 相当于 [1, 1, 1, 1]
  13166. // r缩写为[1] 相当于 [1, 1, 1, 1]
  13167. // r缩写为[1, 2] 相当于 [1, 2, 1, 2]
  13168. // r缩写为[1, 2, 3] 相当于 [1, 2, 3, 2]
  13169. r: 0,
  13170. x: 0,
  13171. y: 0,
  13172. width: 0,
  13173. height: 0
  13174. },
  13175. buildPath: function (ctx, shape) {
  13176. var x = shape.x;
  13177. var y = shape.y;
  13178. var width = shape.width;
  13179. var height = shape.height;
  13180. if (!shape.r) {
  13181. ctx.rect(x, y, width, height);
  13182. }
  13183. else {
  13184. roundRectHelper.buildPath(ctx, shape);
  13185. }
  13186. ctx.closePath();
  13187. return;
  13188. }
  13189. });
  13190. /***/ },
  13191. /* 60 */
  13192. /***/ function(module, exports) {
  13193. module.exports = {
  13194. buildPath: function (ctx, shape) {
  13195. var x = shape.x;
  13196. var y = shape.y;
  13197. var width = shape.width;
  13198. var height = shape.height;
  13199. var r = shape.r;
  13200. var r1;
  13201. var r2;
  13202. var r3;
  13203. var r4;
  13204. // Convert width and height to positive for better borderRadius
  13205. if (width < 0) {
  13206. x = x + width;
  13207. width = -width;
  13208. }
  13209. if (height < 0) {
  13210. y = y + height;
  13211. height = -height;
  13212. }
  13213. if (typeof r === 'number') {
  13214. r1 = r2 = r3 = r4 = r;
  13215. }
  13216. else if (r instanceof Array) {
  13217. if (r.length === 1) {
  13218. r1 = r2 = r3 = r4 = r[0];
  13219. }
  13220. else if (r.length === 2) {
  13221. r1 = r3 = r[0];
  13222. r2 = r4 = r[1];
  13223. }
  13224. else if (r.length === 3) {
  13225. r1 = r[0];
  13226. r2 = r4 = r[1];
  13227. r3 = r[2];
  13228. }
  13229. else {
  13230. r1 = r[0];
  13231. r2 = r[1];
  13232. r3 = r[2];
  13233. r4 = r[3];
  13234. }
  13235. }
  13236. else {
  13237. r1 = r2 = r3 = r4 = 0;
  13238. }
  13239. var total;
  13240. if (r1 + r2 > width) {
  13241. total = r1 + r2;
  13242. r1 *= width / total;
  13243. r2 *= width / total;
  13244. }
  13245. if (r3 + r4 > width) {
  13246. total = r3 + r4;
  13247. r3 *= width / total;
  13248. r4 *= width / total;
  13249. }
  13250. if (r2 + r3 > height) {
  13251. total = r2 + r3;
  13252. r2 *= height / total;
  13253. r3 *= height / total;
  13254. }
  13255. if (r1 + r4 > height) {
  13256. total = r1 + r4;
  13257. r1 *= height / total;
  13258. r4 *= height / total;
  13259. }
  13260. ctx.moveTo(x + r1, y);
  13261. ctx.lineTo(x + width - r2, y);
  13262. r2 !== 0 && ctx.quadraticCurveTo(
  13263. x + width, y, x + width, y + r2
  13264. );
  13265. ctx.lineTo(x + width, y + height - r3);
  13266. r3 !== 0 && ctx.quadraticCurveTo(
  13267. x + width, y + height, x + width - r3, y + height
  13268. );
  13269. ctx.lineTo(x + r4, y + height);
  13270. r4 !== 0 && ctx.quadraticCurveTo(
  13271. x, y + height, x, y + height - r4
  13272. );
  13273. ctx.lineTo(x, y + r1);
  13274. r1 !== 0 && ctx.quadraticCurveTo(x, y, x + r1, y);
  13275. }
  13276. };
  13277. /***/ },
  13278. /* 61 */
  13279. /***/ function(module, exports, __webpack_require__) {
  13280. /**
  13281. * 直线
  13282. * @module zrender/graphic/shape/Line
  13283. */
  13284. module.exports = __webpack_require__(20).extend({
  13285. type: 'line',
  13286. shape: {
  13287. // Start point
  13288. x1: 0,
  13289. y1: 0,
  13290. // End point
  13291. x2: 0,
  13292. y2: 0,
  13293. percent: 1
  13294. },
  13295. style: {
  13296. stroke: '#000',
  13297. fill: null
  13298. },
  13299. buildPath: function (ctx, shape) {
  13300. var x1 = shape.x1;
  13301. var y1 = shape.y1;
  13302. var x2 = shape.x2;
  13303. var y2 = shape.y2;
  13304. var percent = shape.percent;
  13305. if (percent === 0) {
  13306. return;
  13307. }
  13308. ctx.moveTo(x1, y1);
  13309. if (percent < 1) {
  13310. x2 = x1 * (1 - percent) + x2 * percent;
  13311. y2 = y1 * (1 - percent) + y2 * percent;
  13312. }
  13313. ctx.lineTo(x2, y2);
  13314. },
  13315. /**
  13316. * Get point at percent
  13317. * @param {number} percent
  13318. * @return {Array.<number>}
  13319. */
  13320. pointAt: function (p) {
  13321. var shape = this.shape;
  13322. return [
  13323. shape.x1 * (1 - p) + shape.x2 * p,
  13324. shape.y1 * (1 - p) + shape.y2 * p
  13325. ];
  13326. }
  13327. });
  13328. /***/ },
  13329. /* 62 */
  13330. /***/ function(module, exports, __webpack_require__) {
  13331. 'use strict';
  13332. /**
  13333. * 贝塞尔曲线
  13334. * @module zrender/shape/BezierCurve
  13335. */
  13336. var curveTool = __webpack_require__(37);
  13337. var vec2 = __webpack_require__(10);
  13338. var quadraticSubdivide = curveTool.quadraticSubdivide;
  13339. var cubicSubdivide = curveTool.cubicSubdivide;
  13340. var quadraticAt = curveTool.quadraticAt;
  13341. var cubicAt = curveTool.cubicAt;
  13342. var quadraticDerivativeAt = curveTool.quadraticDerivativeAt;
  13343. var cubicDerivativeAt = curveTool.cubicDerivativeAt;
  13344. var out = [];
  13345. function someVectorAt(shape, t, isTangent) {
  13346. var cpx2 = shape.cpx2;
  13347. var cpy2 = shape.cpy2;
  13348. if (cpx2 === null || cpy2 === null) {
  13349. return [
  13350. (isTangent ? cubicDerivativeAt : cubicAt)(shape.x1, shape.cpx1, shape.cpx2, shape.x2, t),
  13351. (isTangent ? cubicDerivativeAt : cubicAt)(shape.y1, shape.cpy1, shape.cpy2, shape.y2, t)
  13352. ];
  13353. }
  13354. else {
  13355. return [
  13356. (isTangent ? quadraticDerivativeAt : quadraticAt)(shape.x1, shape.cpx1, shape.x2, t),
  13357. (isTangent ? quadraticDerivativeAt : quadraticAt)(shape.y1, shape.cpy1, shape.y2, t)
  13358. ];
  13359. }
  13360. }
  13361. module.exports = __webpack_require__(20).extend({
  13362. type: 'bezier-curve',
  13363. shape: {
  13364. x1: 0,
  13365. y1: 0,
  13366. x2: 0,
  13367. y2: 0,
  13368. cpx1: 0,
  13369. cpy1: 0,
  13370. // cpx2: 0,
  13371. // cpy2: 0
  13372. // Curve show percent, for animating
  13373. percent: 1
  13374. },
  13375. style: {
  13376. stroke: '#000',
  13377. fill: null
  13378. },
  13379. buildPath: function (ctx, shape) {
  13380. var x1 = shape.x1;
  13381. var y1 = shape.y1;
  13382. var x2 = shape.x2;
  13383. var y2 = shape.y2;
  13384. var cpx1 = shape.cpx1;
  13385. var cpy1 = shape.cpy1;
  13386. var cpx2 = shape.cpx2;
  13387. var cpy2 = shape.cpy2;
  13388. var percent = shape.percent;
  13389. if (percent === 0) {
  13390. return;
  13391. }
  13392. ctx.moveTo(x1, y1);
  13393. if (cpx2 == null || cpy2 == null) {
  13394. if (percent < 1) {
  13395. quadraticSubdivide(
  13396. x1, cpx1, x2, percent, out
  13397. );
  13398. cpx1 = out[1];
  13399. x2 = out[2];
  13400. quadraticSubdivide(
  13401. y1, cpy1, y2, percent, out
  13402. );
  13403. cpy1 = out[1];
  13404. y2 = out[2];
  13405. }
  13406. ctx.quadraticCurveTo(
  13407. cpx1, cpy1,
  13408. x2, y2
  13409. );
  13410. }
  13411. else {
  13412. if (percent < 1) {
  13413. cubicSubdivide(
  13414. x1, cpx1, cpx2, x2, percent, out
  13415. );
  13416. cpx1 = out[1];
  13417. cpx2 = out[2];
  13418. x2 = out[3];
  13419. cubicSubdivide(
  13420. y1, cpy1, cpy2, y2, percent, out
  13421. );
  13422. cpy1 = out[1];
  13423. cpy2 = out[2];
  13424. y2 = out[3];
  13425. }
  13426. ctx.bezierCurveTo(
  13427. cpx1, cpy1,
  13428. cpx2, cpy2,
  13429. x2, y2
  13430. );
  13431. }
  13432. },
  13433. /**
  13434. * Get point at percent
  13435. * @param {number} t
  13436. * @return {Array.<number>}
  13437. */
  13438. pointAt: function (t) {
  13439. return someVectorAt(this.shape, t, false);
  13440. },
  13441. /**
  13442. * Get tangent at percent
  13443. * @param {number} t
  13444. * @return {Array.<number>}
  13445. */
  13446. tangentAt: function (t) {
  13447. var p = someVectorAt(this.shape, t, true);
  13448. return vec2.normalize(p, p);
  13449. }
  13450. });
  13451. /***/ },
  13452. /* 63 */
  13453. /***/ function(module, exports, __webpack_require__) {
  13454. /**
  13455. * 圆弧
  13456. * @module zrender/graphic/shape/Arc
  13457. */
  13458. module.exports = __webpack_require__(20).extend({
  13459. type: 'arc',
  13460. shape: {
  13461. cx: 0,
  13462. cy: 0,
  13463. r: 0,
  13464. startAngle: 0,
  13465. endAngle: Math.PI * 2,
  13466. clockwise: true
  13467. },
  13468. style: {
  13469. stroke: '#000',
  13470. fill: null
  13471. },
  13472. buildPath: function (ctx, shape) {
  13473. var x = shape.cx;
  13474. var y = shape.cy;
  13475. var r = Math.max(shape.r, 0);
  13476. var startAngle = shape.startAngle;
  13477. var endAngle = shape.endAngle;
  13478. var clockwise = shape.clockwise;
  13479. var unitX = Math.cos(startAngle);
  13480. var unitY = Math.sin(startAngle);
  13481. ctx.moveTo(unitX * r + x, unitY * r + y);
  13482. ctx.arc(x, y, r, startAngle, endAngle, !clockwise);
  13483. }
  13484. });
  13485. /***/ },
  13486. /* 64 */
  13487. /***/ function(module, exports, __webpack_require__) {
  13488. // CompoundPath to improve performance
  13489. var Path = __webpack_require__(20);
  13490. module.exports = Path.extend({
  13491. type: 'compound',
  13492. shape: {
  13493. paths: null
  13494. },
  13495. _updatePathDirty: function () {
  13496. var dirtyPath = this.__dirtyPath;
  13497. var paths = this.shape.paths;
  13498. for (var i = 0; i < paths.length; i++) {
  13499. // Mark as dirty if any subpath is dirty
  13500. dirtyPath = dirtyPath || paths[i].__dirtyPath;
  13501. }
  13502. this.__dirtyPath = dirtyPath;
  13503. this.__dirty = this.__dirty || dirtyPath;
  13504. },
  13505. beforeBrush: function () {
  13506. this._updatePathDirty();
  13507. var paths = this.shape.paths || [];
  13508. var scale = this.getGlobalScale();
  13509. // Update path scale
  13510. for (var i = 0; i < paths.length; i++) {
  13511. if (!paths[i].path) {
  13512. paths[i].createPathProxy();
  13513. }
  13514. paths[i].path.setScale(scale[0], scale[1]);
  13515. }
  13516. },
  13517. buildPath: function (ctx, shape) {
  13518. var paths = shape.paths || [];
  13519. for (var i = 0; i < paths.length; i++) {
  13520. paths[i].buildPath(ctx, paths[i].shape, true);
  13521. }
  13522. },
  13523. afterBrush: function () {
  13524. var paths = this.shape.paths;
  13525. for (var i = 0; i < paths.length; i++) {
  13526. paths[i].__dirtyPath = false;
  13527. }
  13528. },
  13529. getBoundingRect: function () {
  13530. this._updatePathDirty();
  13531. return Path.prototype.getBoundingRect.call(this);
  13532. }
  13533. });
  13534. /***/ },
  13535. /* 65 */
  13536. /***/ function(module, exports, __webpack_require__) {
  13537. 'use strict';
  13538. var zrUtil = __webpack_require__(4);
  13539. var Gradient = __webpack_require__(66);
  13540. /**
  13541. * x, y, x2, y2 are all percent from 0 to 1
  13542. * @param {number} [x=0]
  13543. * @param {number} [y=0]
  13544. * @param {number} [x2=1]
  13545. * @param {number} [y2=0]
  13546. * @param {Array.<Object>} colorStops
  13547. * @param {boolean} [globalCoord=false]
  13548. */
  13549. var LinearGradient = function (x, y, x2, y2, colorStops, globalCoord) {
  13550. // Should do nothing more in this constructor. Because gradient can be
  13551. // declard by `color: {type: 'linear', colorStops: ...}`, where
  13552. // this constructor will not be called.
  13553. this.x = x == null ? 0 : x;
  13554. this.y = y == null ? 0 : y;
  13555. this.x2 = x2 == null ? 1 : x2;
  13556. this.y2 = y2 == null ? 0 : y2;
  13557. // Can be cloned
  13558. this.type = 'linear';
  13559. // If use global coord
  13560. this.global = globalCoord || false;
  13561. Gradient.call(this, colorStops);
  13562. };
  13563. LinearGradient.prototype = {
  13564. constructor: LinearGradient
  13565. };
  13566. zrUtil.inherits(LinearGradient, Gradient);
  13567. module.exports = LinearGradient;
  13568. /***/ },
  13569. /* 66 */
  13570. /***/ function(module, exports) {
  13571. /**
  13572. * @param {Array.<Object>} colorStops
  13573. */
  13574. var Gradient = function (colorStops) {
  13575. this.colorStops = colorStops || [];
  13576. };
  13577. Gradient.prototype = {
  13578. constructor: Gradient,
  13579. addColorStop: function (offset, color) {
  13580. this.colorStops.push({
  13581. offset: offset,
  13582. color: color
  13583. });
  13584. }
  13585. };
  13586. module.exports = Gradient;
  13587. /***/ },
  13588. /* 67 */
  13589. /***/ function(module, exports, __webpack_require__) {
  13590. 'use strict';
  13591. var zrUtil = __webpack_require__(4);
  13592. var Gradient = __webpack_require__(66);
  13593. /**
  13594. * x, y, r are all percent from 0 to 1
  13595. * @param {number} [x=0.5]
  13596. * @param {number} [y=0.5]
  13597. * @param {number} [r=0.5]
  13598. * @param {Array.<Object>} [colorStops]
  13599. * @param {boolean} [globalCoord=false]
  13600. */
  13601. var RadialGradient = function (x, y, r, colorStops, globalCoord) {
  13602. // Should do nothing more in this constructor. Because gradient can be
  13603. // declard by `color: {type: 'radial', colorStops: ...}`, where
  13604. // this constructor will not be called.
  13605. this.x = x == null ? 0.5 : x;
  13606. this.y = y == null ? 0.5 : y;
  13607. this.r = r == null ? 0.5 : r;
  13608. // Can be cloned
  13609. this.type = 'radial';
  13610. // If use global coord
  13611. this.global = globalCoord || false;
  13612. Gradient.call(this, colorStops);
  13613. };
  13614. RadialGradient.prototype = {
  13615. constructor: RadialGradient
  13616. };
  13617. zrUtil.inherits(RadialGradient, Gradient);
  13618. module.exports = RadialGradient;
  13619. /***/ },
  13620. /* 68 */
  13621. /***/ function(module, exports, __webpack_require__) {
  13622. var getItemStyle = __webpack_require__(15)(
  13623. [
  13624. ['fill', 'color'],
  13625. ['stroke', 'borderColor'],
  13626. ['lineWidth', 'borderWidth'],
  13627. ['opacity'],
  13628. ['shadowBlur'],
  13629. ['shadowOffsetX'],
  13630. ['shadowOffsetY'],
  13631. ['shadowColor'],
  13632. ['textPosition'],
  13633. ['textAlign']
  13634. ]
  13635. );
  13636. module.exports = {
  13637. getItemStyle: function (excludes, includes) {
  13638. var style = getItemStyle.call(this, excludes, includes);
  13639. var lineDash = this.getBorderLineDash();
  13640. lineDash && (style.lineDash = lineDash);
  13641. return style;
  13642. },
  13643. getBorderLineDash: function () {
  13644. var lineType = this.get('borderType');
  13645. return (lineType === 'solid' || lineType == null) ? null
  13646. : (lineType === 'dashed' ? [5, 5] : [1, 1]);
  13647. }
  13648. };
  13649. /***/ },
  13650. /* 69 */
  13651. /***/ function(module, exports, __webpack_require__) {
  13652. /**
  13653. * Component model
  13654. *
  13655. * @module echarts/model/Component
  13656. */
  13657. var Model = __webpack_require__(12);
  13658. var zrUtil = __webpack_require__(4);
  13659. var arrayPush = Array.prototype.push;
  13660. var componentUtil = __webpack_require__(70);
  13661. var clazzUtil = __webpack_require__(13);
  13662. var layout = __webpack_require__(71);
  13663. /**
  13664. * @alias module:echarts/model/Component
  13665. * @constructor
  13666. * @param {Object} option
  13667. * @param {module:echarts/model/Model} parentModel
  13668. * @param {module:echarts/model/Model} ecModel
  13669. */
  13670. var ComponentModel = Model.extend({
  13671. type: 'component',
  13672. /**
  13673. * @readOnly
  13674. * @type {string}
  13675. */
  13676. id: '',
  13677. /**
  13678. * @readOnly
  13679. */
  13680. name: '',
  13681. /**
  13682. * @readOnly
  13683. * @type {string}
  13684. */
  13685. mainType: '',
  13686. /**
  13687. * @readOnly
  13688. * @type {string}
  13689. */
  13690. subType: '',
  13691. /**
  13692. * @readOnly
  13693. * @type {number}
  13694. */
  13695. componentIndex: 0,
  13696. /**
  13697. * @type {Object}
  13698. * @protected
  13699. */
  13700. defaultOption: null,
  13701. /**
  13702. * @type {module:echarts/model/Global}
  13703. * @readOnly
  13704. */
  13705. ecModel: null,
  13706. /**
  13707. * key: componentType
  13708. * value: Component model list, can not be null.
  13709. * @type {Object.<string, Array.<module:echarts/model/Model>>}
  13710. * @readOnly
  13711. */
  13712. dependentModels: [],
  13713. /**
  13714. * @type {string}
  13715. * @readOnly
  13716. */
  13717. uid: null,
  13718. /**
  13719. * Support merge layout params.
  13720. * Only support 'box' now (left/right/top/bottom/width/height).
  13721. * @type {string|Object} Object can be {ignoreSize: true}
  13722. * @readOnly
  13723. */
  13724. layoutMode: null,
  13725. $constructor: function (option, parentModel, ecModel, extraOpt) {
  13726. Model.call(this, option, parentModel, ecModel, extraOpt);
  13727. this.uid = componentUtil.getUID('componentModel');
  13728. },
  13729. init: function (option, parentModel, ecModel, extraOpt) {
  13730. this.mergeDefaultAndTheme(option, ecModel);
  13731. },
  13732. mergeDefaultAndTheme: function (option, ecModel) {
  13733. var layoutMode = this.layoutMode;
  13734. var inputPositionParams = layoutMode
  13735. ? layout.getLayoutParams(option) : {};
  13736. var themeModel = ecModel.getTheme();
  13737. zrUtil.merge(option, themeModel.get(this.mainType));
  13738. zrUtil.merge(option, this.getDefaultOption());
  13739. if (layoutMode) {
  13740. layout.mergeLayoutParam(option, inputPositionParams, layoutMode);
  13741. }
  13742. },
  13743. mergeOption: function (option, extraOpt) {
  13744. zrUtil.merge(this.option, option, true);
  13745. var layoutMode = this.layoutMode;
  13746. if (layoutMode) {
  13747. layout.mergeLayoutParam(this.option, option, layoutMode);
  13748. }
  13749. },
  13750. // Hooker after init or mergeOption
  13751. optionUpdated: function (newCptOption, isInit) {},
  13752. getDefaultOption: function () {
  13753. if (!clazzUtil.hasOwn(this, '__defaultOption')) {
  13754. var optList = [];
  13755. var Class = this.constructor;
  13756. while (Class) {
  13757. var opt = Class.prototype.defaultOption;
  13758. opt && optList.push(opt);
  13759. Class = Class.superClass;
  13760. }
  13761. var defaultOption = {};
  13762. for (var i = optList.length - 1; i >= 0; i--) {
  13763. defaultOption = zrUtil.merge(defaultOption, optList[i], true);
  13764. }
  13765. clazzUtil.set(this, '__defaultOption', defaultOption);
  13766. }
  13767. return clazzUtil.get(this, '__defaultOption');
  13768. },
  13769. getReferringComponents: function (mainType) {
  13770. return this.ecModel.queryComponents({
  13771. mainType: mainType,
  13772. index: this.get(mainType + 'Index', true),
  13773. id: this.get(mainType + 'Id', true)
  13774. });
  13775. }
  13776. });
  13777. // Reset ComponentModel.extend, add preConstruct.
  13778. // clazzUtil.enableClassExtend(
  13779. // ComponentModel,
  13780. // function (option, parentModel, ecModel, extraOpt) {
  13781. // // Set dependentModels, componentIndex, name, id, mainType, subType.
  13782. // zrUtil.extend(this, extraOpt);
  13783. // this.uid = componentUtil.getUID('componentModel');
  13784. // // this.setReadOnly([
  13785. // // 'type', 'id', 'uid', 'name', 'mainType', 'subType',
  13786. // // 'dependentModels', 'componentIndex'
  13787. // // ]);
  13788. // }
  13789. // );
  13790. // Add capability of registerClass, getClass, hasClass, registerSubTypeDefaulter and so on.
  13791. clazzUtil.enableClassManagement(
  13792. ComponentModel, {registerWhenExtend: true}
  13793. );
  13794. componentUtil.enableSubTypeDefaulter(ComponentModel);
  13795. // Add capability of ComponentModel.topologicalTravel.
  13796. componentUtil.enableTopologicalTravel(ComponentModel, getDependencies);
  13797. function getDependencies(componentType) {
  13798. var deps = [];
  13799. zrUtil.each(ComponentModel.getClassesByMainType(componentType), function (Clazz) {
  13800. arrayPush.apply(deps, Clazz.prototype.dependencies || []);
  13801. });
  13802. // Ensure main type
  13803. return zrUtil.map(deps, function (type) {
  13804. return clazzUtil.parseClassType(type).main;
  13805. });
  13806. }
  13807. zrUtil.mixin(ComponentModel, __webpack_require__(72));
  13808. module.exports = ComponentModel;
  13809. /***/ },
  13810. /* 70 */
  13811. /***/ function(module, exports, __webpack_require__) {
  13812. var zrUtil = __webpack_require__(4);
  13813. var clazz = __webpack_require__(13);
  13814. var parseClassType = clazz.parseClassType;
  13815. var base = 0;
  13816. var componentUtil = {};
  13817. var DELIMITER = '_';
  13818. /**
  13819. * @public
  13820. * @param {string} type
  13821. * @return {string}
  13822. */
  13823. componentUtil.getUID = function (type) {
  13824. // Considering the case of crossing js context,
  13825. // use Math.random to make id as unique as possible.
  13826. return [(type || ''), base++, Math.random()].join(DELIMITER);
  13827. };
  13828. /**
  13829. * @inner
  13830. */
  13831. componentUtil.enableSubTypeDefaulter = function (entity) {
  13832. var subTypeDefaulters = {};
  13833. entity.registerSubTypeDefaulter = function (componentType, defaulter) {
  13834. componentType = parseClassType(componentType);
  13835. subTypeDefaulters[componentType.main] = defaulter;
  13836. };
  13837. entity.determineSubType = function (componentType, option) {
  13838. var type = option.type;
  13839. if (!type) {
  13840. var componentTypeMain = parseClassType(componentType).main;
  13841. if (entity.hasSubTypes(componentType) && subTypeDefaulters[componentTypeMain]) {
  13842. type = subTypeDefaulters[componentTypeMain](option);
  13843. }
  13844. }
  13845. return type;
  13846. };
  13847. return entity;
  13848. };
  13849. /**
  13850. * Topological travel on Activity Network (Activity On Vertices).
  13851. * Dependencies is defined in Model.prototype.dependencies, like ['xAxis', 'yAxis'].
  13852. *
  13853. * If 'xAxis' or 'yAxis' is absent in componentTypeList, just ignore it in topology.
  13854. *
  13855. * If there is circle dependencey, Error will be thrown.
  13856. *
  13857. */
  13858. componentUtil.enableTopologicalTravel = function (entity, dependencyGetter) {
  13859. /**
  13860. * @public
  13861. * @param {Array.<string>} targetNameList Target Component type list.
  13862. * Can be ['aa', 'bb', 'aa.xx']
  13863. * @param {Array.<string>} fullNameList By which we can build dependency graph.
  13864. * @param {Function} callback Params: componentType, dependencies.
  13865. * @param {Object} context Scope of callback.
  13866. */
  13867. entity.topologicalTravel = function (targetNameList, fullNameList, callback, context) {
  13868. if (!targetNameList.length) {
  13869. return;
  13870. }
  13871. var result = makeDepndencyGraph(fullNameList);
  13872. var graph = result.graph;
  13873. var stack = result.noEntryList;
  13874. var targetNameSet = {};
  13875. zrUtil.each(targetNameList, function (name) {
  13876. targetNameSet[name] = true;
  13877. });
  13878. while (stack.length) {
  13879. var currComponentType = stack.pop();
  13880. var currVertex = graph[currComponentType];
  13881. var isInTargetNameSet = !!targetNameSet[currComponentType];
  13882. if (isInTargetNameSet) {
  13883. callback.call(context, currComponentType, currVertex.originalDeps.slice());
  13884. delete targetNameSet[currComponentType];
  13885. }
  13886. zrUtil.each(
  13887. currVertex.successor,
  13888. isInTargetNameSet ? removeEdgeAndAdd : removeEdge
  13889. );
  13890. }
  13891. zrUtil.each(targetNameSet, function () {
  13892. throw new Error('Circle dependency may exists');
  13893. });
  13894. function removeEdge(succComponentType) {
  13895. graph[succComponentType].entryCount--;
  13896. if (graph[succComponentType].entryCount === 0) {
  13897. stack.push(succComponentType);
  13898. }
  13899. }
  13900. // Consider this case: legend depends on series, and we call
  13901. // chart.setOption({series: [...]}), where only series is in option.
  13902. // If we do not have 'removeEdgeAndAdd', legendModel.mergeOption will
  13903. // not be called, but only sereis.mergeOption is called. Thus legend
  13904. // have no chance to update its local record about series (like which
  13905. // name of series is available in legend).
  13906. function removeEdgeAndAdd(succComponentType) {
  13907. targetNameSet[succComponentType] = true;
  13908. removeEdge(succComponentType);
  13909. }
  13910. };
  13911. /**
  13912. * DepndencyGraph: {Object}
  13913. * key: conponentType,
  13914. * value: {
  13915. * successor: [conponentTypes...],
  13916. * originalDeps: [conponentTypes...],
  13917. * entryCount: {number}
  13918. * }
  13919. */
  13920. function makeDepndencyGraph(fullNameList) {
  13921. var graph = {};
  13922. var noEntryList = [];
  13923. zrUtil.each(fullNameList, function (name) {
  13924. var thisItem = createDependencyGraphItem(graph, name);
  13925. var originalDeps = thisItem.originalDeps = dependencyGetter(name);
  13926. var availableDeps = getAvailableDependencies(originalDeps, fullNameList);
  13927. thisItem.entryCount = availableDeps.length;
  13928. if (thisItem.entryCount === 0) {
  13929. noEntryList.push(name);
  13930. }
  13931. zrUtil.each(availableDeps, function (dependentName) {
  13932. if (zrUtil.indexOf(thisItem.predecessor, dependentName) < 0) {
  13933. thisItem.predecessor.push(dependentName);
  13934. }
  13935. var thatItem = createDependencyGraphItem(graph, dependentName);
  13936. if (zrUtil.indexOf(thatItem.successor, dependentName) < 0) {
  13937. thatItem.successor.push(name);
  13938. }
  13939. });
  13940. });
  13941. return {graph: graph, noEntryList: noEntryList};
  13942. }
  13943. function createDependencyGraphItem(graph, name) {
  13944. if (!graph[name]) {
  13945. graph[name] = {predecessor: [], successor: []};
  13946. }
  13947. return graph[name];
  13948. }
  13949. function getAvailableDependencies(originalDeps, fullNameList) {
  13950. var availableDeps = [];
  13951. zrUtil.each(originalDeps, function (dep) {
  13952. zrUtil.indexOf(fullNameList, dep) >= 0 && availableDeps.push(dep);
  13953. });
  13954. return availableDeps;
  13955. }
  13956. };
  13957. module.exports = componentUtil;
  13958. /***/ },
  13959. /* 71 */
  13960. /***/ function(module, exports, __webpack_require__) {
  13961. 'use strict';
  13962. // Layout helpers for each component positioning
  13963. var zrUtil = __webpack_require__(4);
  13964. var BoundingRect = __webpack_require__(9);
  13965. var numberUtil = __webpack_require__(7);
  13966. var formatUtil = __webpack_require__(6);
  13967. var parsePercent = numberUtil.parsePercent;
  13968. var each = zrUtil.each;
  13969. var layout = {};
  13970. /**
  13971. * @public
  13972. */
  13973. var LOCATION_PARAMS = layout.LOCATION_PARAMS = [
  13974. 'left', 'right', 'top', 'bottom', 'width', 'height'
  13975. ];
  13976. /**
  13977. * @public
  13978. */
  13979. var HV_NAMES = layout.HV_NAMES = [
  13980. ['width', 'left', 'right'],
  13981. ['height', 'top', 'bottom']
  13982. ];
  13983. function boxLayout(orient, group, gap, maxWidth, maxHeight) {
  13984. var x = 0;
  13985. var y = 0;
  13986. if (maxWidth == null) {
  13987. maxWidth = Infinity;
  13988. }
  13989. if (maxHeight == null) {
  13990. maxHeight = Infinity;
  13991. }
  13992. var currentLineMaxSize = 0;
  13993. group.eachChild(function (child, idx) {
  13994. var position = child.position;
  13995. var rect = child.getBoundingRect();
  13996. var nextChild = group.childAt(idx + 1);
  13997. var nextChildRect = nextChild && nextChild.getBoundingRect();
  13998. var nextX;
  13999. var nextY;
  14000. if (orient === 'horizontal') {
  14001. var moveX = rect.width + (nextChildRect ? (-nextChildRect.x + rect.x) : 0);
  14002. nextX = x + moveX;
  14003. // Wrap when width exceeds maxWidth or meet a `newline` group
  14004. if (nextX > maxWidth || child.newline) {
  14005. x = 0;
  14006. nextX = moveX;
  14007. y += currentLineMaxSize + gap;
  14008. currentLineMaxSize = rect.height;
  14009. }
  14010. else {
  14011. currentLineMaxSize = Math.max(currentLineMaxSize, rect.height);
  14012. }
  14013. }
  14014. else {
  14015. var moveY = rect.height + (nextChildRect ? (-nextChildRect.y + rect.y) : 0);
  14016. nextY = y + moveY;
  14017. // Wrap when width exceeds maxHeight or meet a `newline` group
  14018. if (nextY > maxHeight || child.newline) {
  14019. x += currentLineMaxSize + gap;
  14020. y = 0;
  14021. nextY = moveY;
  14022. currentLineMaxSize = rect.width;
  14023. }
  14024. else {
  14025. currentLineMaxSize = Math.max(currentLineMaxSize, rect.width);
  14026. }
  14027. }
  14028. if (child.newline) {
  14029. return;
  14030. }
  14031. position[0] = x;
  14032. position[1] = y;
  14033. orient === 'horizontal'
  14034. ? (x = nextX + gap)
  14035. : (y = nextY + gap);
  14036. });
  14037. }
  14038. /**
  14039. * VBox or HBox layouting
  14040. * @param {string} orient
  14041. * @param {module:zrender/container/Group} group
  14042. * @param {number} gap
  14043. * @param {number} [width=Infinity]
  14044. * @param {number} [height=Infinity]
  14045. */
  14046. layout.box = boxLayout;
  14047. /**
  14048. * VBox layouting
  14049. * @param {module:zrender/container/Group} group
  14050. * @param {number} gap
  14051. * @param {number} [width=Infinity]
  14052. * @param {number} [height=Infinity]
  14053. */
  14054. layout.vbox = zrUtil.curry(boxLayout, 'vertical');
  14055. /**
  14056. * HBox layouting
  14057. * @param {module:zrender/container/Group} group
  14058. * @param {number} gap
  14059. * @param {number} [width=Infinity]
  14060. * @param {number} [height=Infinity]
  14061. */
  14062. layout.hbox = zrUtil.curry(boxLayout, 'horizontal');
  14063. /**
  14064. * If x or x2 is not specified or 'center' 'left' 'right',
  14065. * the width would be as long as possible.
  14066. * If y or y2 is not specified or 'middle' 'top' 'bottom',
  14067. * the height would be as long as possible.
  14068. *
  14069. * @param {Object} positionInfo
  14070. * @param {number|string} [positionInfo.x]
  14071. * @param {number|string} [positionInfo.y]
  14072. * @param {number|string} [positionInfo.x2]
  14073. * @param {number|string} [positionInfo.y2]
  14074. * @param {Object} containerRect
  14075. * @param {string|number} margin
  14076. * @return {Object} {width, height}
  14077. */
  14078. layout.getAvailableSize = function (positionInfo, containerRect, margin) {
  14079. var containerWidth = containerRect.width;
  14080. var containerHeight = containerRect.height;
  14081. var x = parsePercent(positionInfo.x, containerWidth);
  14082. var y = parsePercent(positionInfo.y, containerHeight);
  14083. var x2 = parsePercent(positionInfo.x2, containerWidth);
  14084. var y2 = parsePercent(positionInfo.y2, containerHeight);
  14085. (isNaN(x) || isNaN(parseFloat(positionInfo.x))) && (x = 0);
  14086. (isNaN(x2) || isNaN(parseFloat(positionInfo.x2))) && (x2 = containerWidth);
  14087. (isNaN(y) || isNaN(parseFloat(positionInfo.y))) && (y = 0);
  14088. (isNaN(y2) || isNaN(parseFloat(positionInfo.y2))) && (y2 = containerHeight);
  14089. margin = formatUtil.normalizeCssArray(margin || 0);
  14090. return {
  14091. width: Math.max(x2 - x - margin[1] - margin[3], 0),
  14092. height: Math.max(y2 - y - margin[0] - margin[2], 0)
  14093. };
  14094. };
  14095. /**
  14096. * Parse position info.
  14097. *
  14098. * @param {Object} positionInfo
  14099. * @param {number|string} [positionInfo.left]
  14100. * @param {number|string} [positionInfo.top]
  14101. * @param {number|string} [positionInfo.right]
  14102. * @param {number|string} [positionInfo.bottom]
  14103. * @param {number|string} [positionInfo.width]
  14104. * @param {number|string} [positionInfo.height]
  14105. * @param {number|string} [positionInfo.aspect] Aspect is width / height
  14106. * @param {Object} containerRect
  14107. * @param {string|number} [margin]
  14108. *
  14109. * @return {module:zrender/core/BoundingRect}
  14110. */
  14111. layout.getLayoutRect = function (
  14112. positionInfo, containerRect, margin
  14113. ) {
  14114. margin = formatUtil.normalizeCssArray(margin || 0);
  14115. var containerWidth = containerRect.width;
  14116. var containerHeight = containerRect.height;
  14117. var left = parsePercent(positionInfo.left, containerWidth);
  14118. var top = parsePercent(positionInfo.top, containerHeight);
  14119. var right = parsePercent(positionInfo.right, containerWidth);
  14120. var bottom = parsePercent(positionInfo.bottom, containerHeight);
  14121. var width = parsePercent(positionInfo.width, containerWidth);
  14122. var height = parsePercent(positionInfo.height, containerHeight);
  14123. var verticalMargin = margin[2] + margin[0];
  14124. var horizontalMargin = margin[1] + margin[3];
  14125. var aspect = positionInfo.aspect;
  14126. // If width is not specified, calculate width from left and right
  14127. if (isNaN(width)) {
  14128. width = containerWidth - right - horizontalMargin - left;
  14129. }
  14130. if (isNaN(height)) {
  14131. height = containerHeight - bottom - verticalMargin - top;
  14132. }
  14133. // If width and height are not given
  14134. // 1. Graph should not exceeds the container
  14135. // 2. Aspect must be keeped
  14136. // 3. Graph should take the space as more as possible
  14137. if (isNaN(width) && isNaN(height)) {
  14138. if (aspect > containerWidth / containerHeight) {
  14139. width = containerWidth * 0.8;
  14140. }
  14141. else {
  14142. height = containerHeight * 0.8;
  14143. }
  14144. }
  14145. if (aspect != null) {
  14146. // Calculate width or height with given aspect
  14147. if (isNaN(width)) {
  14148. width = aspect * height;
  14149. }
  14150. if (isNaN(height)) {
  14151. height = width / aspect;
  14152. }
  14153. }
  14154. // If left is not specified, calculate left from right and width
  14155. if (isNaN(left)) {
  14156. left = containerWidth - right - width - horizontalMargin;
  14157. }
  14158. if (isNaN(top)) {
  14159. top = containerHeight - bottom - height - verticalMargin;
  14160. }
  14161. // Align left and top
  14162. switch (positionInfo.left || positionInfo.right) {
  14163. case 'center':
  14164. left = containerWidth / 2 - width / 2 - margin[3];
  14165. break;
  14166. case 'right':
  14167. left = containerWidth - width - horizontalMargin;
  14168. break;
  14169. }
  14170. switch (positionInfo.top || positionInfo.bottom) {
  14171. case 'middle':
  14172. case 'center':
  14173. top = containerHeight / 2 - height / 2 - margin[0];
  14174. break;
  14175. case 'bottom':
  14176. top = containerHeight - height - verticalMargin;
  14177. break;
  14178. }
  14179. // If something is wrong and left, top, width, height are calculated as NaN
  14180. left = left || 0;
  14181. top = top || 0;
  14182. if (isNaN(width)) {
  14183. // Width may be NaN if only one value is given except width
  14184. width = containerWidth - left - (right || 0);
  14185. }
  14186. if (isNaN(height)) {
  14187. // Height may be NaN if only one value is given except height
  14188. height = containerHeight - top - (bottom || 0);
  14189. }
  14190. var rect = new BoundingRect(left + margin[3], top + margin[0], width, height);
  14191. rect.margin = margin;
  14192. return rect;
  14193. };
  14194. /**
  14195. * Position a zr element in viewport
  14196. * Group position is specified by either
  14197. * {left, top}, {right, bottom}
  14198. * If all properties exists, right and bottom will be igonred.
  14199. *
  14200. * Logic:
  14201. * 1. Scale (against origin point in parent coord)
  14202. * 2. Rotate (against origin point in parent coord)
  14203. * 3. Traslate (with el.position by this method)
  14204. * So this method only fixes the last step 'Traslate', which does not affect
  14205. * scaling and rotating.
  14206. *
  14207. * If be called repeatly with the same input el, the same result will be gotten.
  14208. *
  14209. * @param {module:zrender/Element} el Should have `getBoundingRect` method.
  14210. * @param {Object} positionInfo
  14211. * @param {number|string} [positionInfo.left]
  14212. * @param {number|string} [positionInfo.top]
  14213. * @param {number|string} [positionInfo.right]
  14214. * @param {number|string} [positionInfo.bottom]
  14215. * @param {Object} containerRect
  14216. * @param {string|number} margin
  14217. * @param {Object} [opt]
  14218. * @param {Array.<number>} [opt.hv=[1,1]] Only horizontal or only vertical.
  14219. * @param {Array.<number>} [opt.boundingMode='all']
  14220. * Specify how to calculate boundingRect when locating.
  14221. * 'all': Position the boundingRect that is transformed and uioned
  14222. * both itself and its descendants.
  14223. * This mode simplies confine the elements in the bounding
  14224. * of their container (e.g., using 'right: 0').
  14225. * 'raw': Position the boundingRect that is not transformed and only itself.
  14226. * This mode is useful when you want a element can overflow its
  14227. * container. (Consider a rotated circle needs to be located in a corner.)
  14228. * In this mode positionInfo.width/height can only be number.
  14229. */
  14230. layout.positionElement = function (el, positionInfo, containerRect, margin, opt) {
  14231. var h = !opt || !opt.hv || opt.hv[0];
  14232. var v = !opt || !opt.hv || opt.hv[1];
  14233. var boundingMode = opt && opt.boundingMode || 'all';
  14234. if (!h && !v) {
  14235. return;
  14236. }
  14237. var rect;
  14238. if (boundingMode === 'raw') {
  14239. rect = el.type === 'group'
  14240. ? new BoundingRect(0, 0, +positionInfo.width || 0, +positionInfo.height || 0)
  14241. : el.getBoundingRect();
  14242. }
  14243. else {
  14244. rect = el.getBoundingRect();
  14245. if (el.needLocalTransform()) {
  14246. var transform = el.getLocalTransform();
  14247. // Notice: raw rect may be inner object of el,
  14248. // which should not be modified.
  14249. rect = rect.clone();
  14250. rect.applyTransform(transform);
  14251. }
  14252. }
  14253. positionInfo = layout.getLayoutRect(
  14254. zrUtil.defaults(
  14255. {width: rect.width, height: rect.height},
  14256. positionInfo
  14257. ),
  14258. containerRect,
  14259. margin
  14260. );
  14261. // Because 'tranlate' is the last step in transform
  14262. // (see zrender/core/Transformable#getLocalTransfrom),
  14263. // we can just only modify el.position to get final result.
  14264. var elPos = el.position;
  14265. var dx = h ? positionInfo.x - rect.x : 0;
  14266. var dy = v ? positionInfo.y - rect.y : 0;
  14267. el.attr('position', boundingMode === 'raw' ? [dx, dy] : [elPos[0] + dx, elPos[1] + dy]);
  14268. };
  14269. /**
  14270. * @param {Object} option Contains some of the properties in HV_NAMES.
  14271. * @param {number} hvIdx 0: horizontal; 1: vertical.
  14272. */
  14273. layout.sizeCalculable = function (option, hvIdx) {
  14274. return option[HV_NAMES[hvIdx][0]] != null
  14275. || (option[HV_NAMES[hvIdx][1]] != null && option[HV_NAMES[hvIdx][2]] != null);
  14276. };
  14277. /**
  14278. * Consider Case:
  14279. * When defulat option has {left: 0, width: 100}, and we set {right: 0}
  14280. * through setOption or media query, using normal zrUtil.merge will cause
  14281. * {right: 0} does not take effect.
  14282. *
  14283. * @example
  14284. * ComponentModel.extend({
  14285. * init: function () {
  14286. * ...
  14287. * var inputPositionParams = layout.getLayoutParams(option);
  14288. * this.mergeOption(inputPositionParams);
  14289. * },
  14290. * mergeOption: function (newOption) {
  14291. * newOption && zrUtil.merge(thisOption, newOption, true);
  14292. * layout.mergeLayoutParam(thisOption, newOption);
  14293. * }
  14294. * });
  14295. *
  14296. * @param {Object} targetOption
  14297. * @param {Object} newOption
  14298. * @param {Object|string} [opt]
  14299. * @param {boolean|Array.<boolean>} [opt.ignoreSize=false] Some component must has width and height.
  14300. */
  14301. layout.mergeLayoutParam = function (targetOption, newOption, opt) {
  14302. !zrUtil.isObject(opt) && (opt = {});
  14303. var ignoreSize = opt.ignoreSize;
  14304. !zrUtil.isArray(ignoreSize) && (ignoreSize = [ignoreSize, ignoreSize]);
  14305. var hResult = merge(HV_NAMES[0], 0);
  14306. var vResult = merge(HV_NAMES[1], 1);
  14307. copy(HV_NAMES[0], targetOption, hResult);
  14308. copy(HV_NAMES[1], targetOption, vResult);
  14309. function merge(names, hvIdx) {
  14310. var newParams = {};
  14311. var newValueCount = 0;
  14312. var merged = {};
  14313. var mergedValueCount = 0;
  14314. var enoughParamNumber = 2;
  14315. each(names, function (name) {
  14316. merged[name] = targetOption[name];
  14317. });
  14318. each(names, function (name) {
  14319. // Consider case: newOption.width is null, which is
  14320. // set by user for removing width setting.
  14321. hasProp(newOption, name) && (newParams[name] = merged[name] = newOption[name]);
  14322. hasValue(newParams, name) && newValueCount++;
  14323. hasValue(merged, name) && mergedValueCount++;
  14324. });
  14325. if (ignoreSize[hvIdx]) {
  14326. // Only one of left/right is premitted to exist.
  14327. if (hasValue(newOption, names[1])) {
  14328. merged[names[2]] = null;
  14329. }
  14330. else if (hasValue(newOption, names[2])) {
  14331. merged[names[1]] = null;
  14332. }
  14333. return merged;
  14334. }
  14335. // Case: newOption: {width: ..., right: ...},
  14336. // or targetOption: {right: ...} and newOption: {width: ...},
  14337. // There is no conflict when merged only has params count
  14338. // little than enoughParamNumber.
  14339. if (mergedValueCount === enoughParamNumber || !newValueCount) {
  14340. return merged;
  14341. }
  14342. // Case: newOption: {width: ..., right: ...},
  14343. // Than we can make sure user only want those two, and ignore
  14344. // all origin params in targetOption.
  14345. else if (newValueCount >= enoughParamNumber) {
  14346. return newParams;
  14347. }
  14348. else {
  14349. // Chose another param from targetOption by priority.
  14350. for (var i = 0; i < names.length; i++) {
  14351. var name = names[i];
  14352. if (!hasProp(newParams, name) && hasProp(targetOption, name)) {
  14353. newParams[name] = targetOption[name];
  14354. break;
  14355. }
  14356. }
  14357. return newParams;
  14358. }
  14359. }
  14360. function hasProp(obj, name) {
  14361. return obj.hasOwnProperty(name);
  14362. }
  14363. function hasValue(obj, name) {
  14364. return obj[name] != null && obj[name] !== 'auto';
  14365. }
  14366. function copy(names, target, source) {
  14367. each(names, function (name) {
  14368. target[name] = source[name];
  14369. });
  14370. }
  14371. };
  14372. /**
  14373. * Retrieve 'left', 'right', 'top', 'bottom', 'width', 'height' from object.
  14374. * @param {Object} source
  14375. * @return {Object} Result contains those props.
  14376. */
  14377. layout.getLayoutParams = function (source) {
  14378. return layout.copyLayoutParams({}, source);
  14379. };
  14380. /**
  14381. * Retrieve 'left', 'right', 'top', 'bottom', 'width', 'height' from object.
  14382. * @param {Object} source
  14383. * @return {Object} Result contains those props.
  14384. */
  14385. layout.copyLayoutParams = function (target, source) {
  14386. source && target && each(LOCATION_PARAMS, function (name) {
  14387. source.hasOwnProperty(name) && (target[name] = source[name]);
  14388. });
  14389. return target;
  14390. };
  14391. module.exports = layout;
  14392. /***/ },
  14393. /* 72 */
  14394. /***/ function(module, exports) {
  14395. module.exports = {
  14396. getBoxLayoutParams: function () {
  14397. return {
  14398. left: this.get('left'),
  14399. top: this.get('top'),
  14400. right: this.get('right'),
  14401. bottom: this.get('bottom'),
  14402. width: this.get('width'),
  14403. height: this.get('height')
  14404. };
  14405. }
  14406. };
  14407. /***/ },
  14408. /* 73 */
  14409. /***/ function(module, exports) {
  14410. var platform = '';
  14411. // Navigator not exists in node
  14412. if (typeof navigator !== 'undefined') {
  14413. platform = navigator.platform || '';
  14414. }
  14415. module.exports = {
  14416. // 全图默认背景
  14417. // backgroundColor: 'rgba(0,0,0,0)',
  14418. // https://dribbble.com/shots/1065960-Infographic-Pie-chart-visualization
  14419. // color: ['#5793f3', '#d14a61', '#fd9c35', '#675bba', '#fec42c', '#dd4444', '#d4df5a', '#cd4870'],
  14420. // 浅色
  14421. // color: ['#bcd3bb', '#e88f70', '#edc1a5', '#9dc5c8', '#e1e8c8', '#7b7c68', '#e5b5b5', '#f0b489', '#928ea8', '#bda29a'],
  14422. // color: ['#cc5664', '#9bd6ec', '#ea946e', '#8acaaa', '#f1ec64', '#ee8686', '#a48dc1', '#5da6bc', '#b9dcae'],
  14423. // 深色
  14424. color: ['#c23531','#2f4554', '#61a0a8', '#d48265', '#91c7ae','#749f83', '#ca8622', '#bda29a','#6e7074', '#546570', '#c4ccd3'],
  14425. // 默认需要 Grid 配置项
  14426. // grid: {},
  14427. // 主题,主题
  14428. textStyle: {
  14429. // color: '#000',
  14430. // decoration: 'none',
  14431. // PENDING
  14432. fontFamily: platform.match(/^Win/) ? 'Microsoft YaHei' : 'sans-serif',
  14433. // fontFamily: 'Arial, Verdana, sans-serif',
  14434. fontSize: 12,
  14435. fontStyle: 'normal',
  14436. fontWeight: 'normal'
  14437. },
  14438. // http://blogs.adobe.com/webplatform/2014/02/24/using-blend-modes-in-html-canvas/
  14439. // https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/globalCompositeOperation
  14440. // Default is source-over
  14441. blendMode: null,
  14442. animation: 'auto',
  14443. animationDuration: 1000,
  14444. animationDurationUpdate: 300,
  14445. animationEasing: 'exponentialOut',
  14446. animationEasingUpdate: 'cubicOut',
  14447. animationThreshold: 2000,
  14448. // Configuration for progressive/incremental rendering
  14449. progressiveThreshold: 3000,
  14450. progressive: 400,
  14451. // Threshold of if use single hover layer to optimize.
  14452. // It is recommended that `hoverLayerThreshold` is equivalent to or less than
  14453. // `progressiveThreshold`, otherwise hover will cause restart of progressive,
  14454. // which is unexpected.
  14455. // see example <echarts/test/heatmap-large.html>.
  14456. hoverLayerThreshold: 3000,
  14457. // See: module:echarts/scale/Time
  14458. useUTC: false
  14459. };
  14460. /***/ },
  14461. /* 74 */
  14462. /***/ function(module, exports, __webpack_require__) {
  14463. var classUtil = __webpack_require__(13);
  14464. var set = classUtil.set;
  14465. var get = classUtil.get;
  14466. module.exports = {
  14467. clearColorPalette: function () {
  14468. set(this, 'colorIdx', 0);
  14469. set(this, 'colorNameMap', {});
  14470. },
  14471. getColorFromPalette: function (name, scope) {
  14472. scope = scope || this;
  14473. var colorIdx = get(scope, 'colorIdx') || 0;
  14474. var colorNameMap = get(scope, 'colorNameMap') || set(scope, 'colorNameMap', {});
  14475. // Use `hasOwnProperty` to avoid conflict with Object.prototype.
  14476. if (colorNameMap.hasOwnProperty(name)) {
  14477. return colorNameMap[name];
  14478. }
  14479. var colorPalette = this.get('color', true) || [];
  14480. if (!colorPalette.length) {
  14481. return;
  14482. }
  14483. var color = colorPalette[colorIdx];
  14484. if (name) {
  14485. colorNameMap[name] = color;
  14486. }
  14487. set(scope, 'colorIdx', (colorIdx + 1) % colorPalette.length);
  14488. return color;
  14489. }
  14490. };
  14491. /***/ },
  14492. /* 75 */
  14493. /***/ function(module, exports, __webpack_require__) {
  14494. 'use strict';
  14495. var zrUtil = __webpack_require__(4);
  14496. var echartsAPIList = [
  14497. 'getDom', 'getZr', 'getWidth', 'getHeight', 'getDevicePixelRatio', 'dispatchAction', 'isDisposed',
  14498. 'on', 'off', 'getDataURL', 'getConnectedDataURL', 'getModel', 'getOption',
  14499. 'getViewOfComponentModel', 'getViewOfSeriesModel'
  14500. ];
  14501. // And `getCoordinateSystems` and `getComponentByElement` will be injected in echarts.js
  14502. function ExtensionAPI(chartInstance) {
  14503. zrUtil.each(echartsAPIList, function (name) {
  14504. this[name] = zrUtil.bind(chartInstance[name], chartInstance);
  14505. }, this);
  14506. }
  14507. module.exports = ExtensionAPI;
  14508. /***/ },
  14509. /* 76 */
  14510. /***/ function(module, exports, __webpack_require__) {
  14511. 'use strict';
  14512. var zrUtil = __webpack_require__(4);
  14513. var coordinateSystemCreators = {};
  14514. function CoordinateSystemManager() {
  14515. this._coordinateSystems = [];
  14516. }
  14517. CoordinateSystemManager.prototype = {
  14518. constructor: CoordinateSystemManager,
  14519. create: function (ecModel, api) {
  14520. var coordinateSystems = [];
  14521. zrUtil.each(coordinateSystemCreators, function (creater, type) {
  14522. var list = creater.create(ecModel, api);
  14523. coordinateSystems = coordinateSystems.concat(list || []);
  14524. });
  14525. this._coordinateSystems = coordinateSystems;
  14526. },
  14527. update: function (ecModel, api) {
  14528. zrUtil.each(this._coordinateSystems, function (coordSys) {
  14529. // FIXME MUST have
  14530. coordSys.update && coordSys.update(ecModel, api);
  14531. });
  14532. },
  14533. getCoordinateSystems: function () {
  14534. return this._coordinateSystems.slice();
  14535. }
  14536. };
  14537. CoordinateSystemManager.register = function (type, coordinateSystemCreator) {
  14538. coordinateSystemCreators[type] = coordinateSystemCreator;
  14539. };
  14540. CoordinateSystemManager.get = function (type) {
  14541. return coordinateSystemCreators[type];
  14542. };
  14543. module.exports = CoordinateSystemManager;
  14544. /***/ },
  14545. /* 77 */
  14546. /***/ function(module, exports, __webpack_require__) {
  14547. /**
  14548. * ECharts option manager
  14549. *
  14550. * @module {echarts/model/OptionManager}
  14551. */
  14552. var zrUtil = __webpack_require__(4);
  14553. var modelUtil = __webpack_require__(5);
  14554. var ComponentModel = __webpack_require__(69);
  14555. var each = zrUtil.each;
  14556. var clone = zrUtil.clone;
  14557. var map = zrUtil.map;
  14558. var merge = zrUtil.merge;
  14559. var QUERY_REG = /^(min|max)?(.+)$/;
  14560. /**
  14561. * TERM EXPLANATIONS:
  14562. *
  14563. * [option]:
  14564. *
  14565. * An object that contains definitions of components. For example:
  14566. * var option = {
  14567. * title: {...},
  14568. * legend: {...},
  14569. * visualMap: {...},
  14570. * series: [
  14571. * {data: [...]},
  14572. * {data: [...]},
  14573. * ...
  14574. * ]
  14575. * };
  14576. *
  14577. * [rawOption]:
  14578. *
  14579. * An object input to echarts.setOption. 'rawOption' may be an
  14580. * 'option', or may be an object contains multi-options. For example:
  14581. * var option = {
  14582. * baseOption: {
  14583. * title: {...},
  14584. * legend: {...},
  14585. * series: [
  14586. * {data: [...]},
  14587. * {data: [...]},
  14588. * ...
  14589. * ]
  14590. * },
  14591. * timeline: {...},
  14592. * options: [
  14593. * {title: {...}, series: {data: [...]}},
  14594. * {title: {...}, series: {data: [...]}},
  14595. * ...
  14596. * ],
  14597. * media: [
  14598. * {
  14599. * query: {maxWidth: 320},
  14600. * option: {series: {x: 20}, visualMap: {show: false}}
  14601. * },
  14602. * {
  14603. * query: {minWidth: 320, maxWidth: 720},
  14604. * option: {series: {x: 500}, visualMap: {show: true}}
  14605. * },
  14606. * {
  14607. * option: {series: {x: 1200}, visualMap: {show: true}}
  14608. * }
  14609. * ]
  14610. * };
  14611. *
  14612. * @alias module:echarts/model/OptionManager
  14613. * @param {module:echarts/ExtensionAPI} api
  14614. */
  14615. function OptionManager(api) {
  14616. /**
  14617. * @private
  14618. * @type {module:echarts/ExtensionAPI}
  14619. */
  14620. this._api = api;
  14621. /**
  14622. * @private
  14623. * @type {Array.<number>}
  14624. */
  14625. this._timelineOptions = [];
  14626. /**
  14627. * @private
  14628. * @type {Array.<Object>}
  14629. */
  14630. this._mediaList = [];
  14631. /**
  14632. * @private
  14633. * @type {Object}
  14634. */
  14635. this._mediaDefault;
  14636. /**
  14637. * -1, means default.
  14638. * empty means no media.
  14639. * @private
  14640. * @type {Array.<number>}
  14641. */
  14642. this._currentMediaIndices = [];
  14643. /**
  14644. * @private
  14645. * @type {Object}
  14646. */
  14647. this._optionBackup;
  14648. /**
  14649. * @private
  14650. * @type {Object}
  14651. */
  14652. this._newBaseOption;
  14653. }
  14654. // timeline.notMerge is not supported in ec3. Firstly there is rearly
  14655. // case that notMerge is needed. Secondly supporting 'notMerge' requires
  14656. // rawOption cloned and backuped when timeline changed, which does no
  14657. // good to performance. What's more, that both timeline and setOption
  14658. // method supply 'notMerge' brings complex and some problems.
  14659. // Consider this case:
  14660. // (step1) chart.setOption({timeline: {notMerge: false}, ...}, false);
  14661. // (step2) chart.setOption({timeline: {notMerge: true}, ...}, false);
  14662. OptionManager.prototype = {
  14663. constructor: OptionManager,
  14664. /**
  14665. * @public
  14666. * @param {Object} rawOption Raw option.
  14667. * @param {module:echarts/model/Global} ecModel
  14668. * @param {Array.<Function>} optionPreprocessorFuncs
  14669. * @return {Object} Init option
  14670. */
  14671. setOption: function (rawOption, optionPreprocessorFuncs) {
  14672. rawOption = clone(rawOption, true);
  14673. // FIXME
  14674. // 如果 timeline options 或者 media 中设置了某个属性,而baseOption中没有设置,则进行警告。
  14675. var oldOptionBackup = this._optionBackup;
  14676. var newParsedOption = parseRawOption.call(
  14677. this, rawOption, optionPreprocessorFuncs, !oldOptionBackup
  14678. );
  14679. this._newBaseOption = newParsedOption.baseOption;
  14680. // For setOption at second time (using merge mode);
  14681. if (oldOptionBackup) {
  14682. // Only baseOption can be merged.
  14683. mergeOption(oldOptionBackup.baseOption, newParsedOption.baseOption);
  14684. // For simplicity, timeline options and media options do not support merge,
  14685. // that is, if you `setOption` twice and both has timeline options, the latter
  14686. // timeline opitons will not be merged to the formers, but just substitude them.
  14687. if (newParsedOption.timelineOptions.length) {
  14688. oldOptionBackup.timelineOptions = newParsedOption.timelineOptions;
  14689. }
  14690. if (newParsedOption.mediaList.length) {
  14691. oldOptionBackup.mediaList = newParsedOption.mediaList;
  14692. }
  14693. if (newParsedOption.mediaDefault) {
  14694. oldOptionBackup.mediaDefault = newParsedOption.mediaDefault;
  14695. }
  14696. }
  14697. else {
  14698. this._optionBackup = newParsedOption;
  14699. }
  14700. },
  14701. /**
  14702. * @param {boolean} isRecreate
  14703. * @return {Object}
  14704. */
  14705. mountOption: function (isRecreate) {
  14706. var optionBackup = this._optionBackup;
  14707. // TODO
  14708. // 如果没有reset功能则不clone。
  14709. this._timelineOptions = map(optionBackup.timelineOptions, clone);
  14710. this._mediaList = map(optionBackup.mediaList, clone);
  14711. this._mediaDefault = clone(optionBackup.mediaDefault);
  14712. this._currentMediaIndices = [];
  14713. return clone(isRecreate
  14714. // this._optionBackup.baseOption, which is created at the first `setOption`
  14715. // called, and is merged into every new option by inner method `mergeOption`
  14716. // each time `setOption` called, can be only used in `isRecreate`, because
  14717. // its reliability is under suspicion. In other cases option merge is
  14718. // performed by `model.mergeOption`.
  14719. ? optionBackup.baseOption : this._newBaseOption
  14720. );
  14721. },
  14722. /**
  14723. * @param {module:echarts/model/Global} ecModel
  14724. * @return {Object}
  14725. */
  14726. getTimelineOption: function (ecModel) {
  14727. var option;
  14728. var timelineOptions = this._timelineOptions;
  14729. if (timelineOptions.length) {
  14730. // getTimelineOption can only be called after ecModel inited,
  14731. // so we can get currentIndex from timelineModel.
  14732. var timelineModel = ecModel.getComponent('timeline');
  14733. if (timelineModel) {
  14734. option = clone(
  14735. timelineOptions[timelineModel.getCurrentIndex()],
  14736. true
  14737. );
  14738. }
  14739. }
  14740. return option;
  14741. },
  14742. /**
  14743. * @param {module:echarts/model/Global} ecModel
  14744. * @return {Array.<Object>}
  14745. */
  14746. getMediaOption: function (ecModel) {
  14747. var ecWidth = this._api.getWidth();
  14748. var ecHeight = this._api.getHeight();
  14749. var mediaList = this._mediaList;
  14750. var mediaDefault = this._mediaDefault;
  14751. var indices = [];
  14752. var result = [];
  14753. // No media defined.
  14754. if (!mediaList.length && !mediaDefault) {
  14755. return result;
  14756. }
  14757. // Multi media may be applied, the latter defined media has higher priority.
  14758. for (var i = 0, len = mediaList.length; i < len; i++) {
  14759. if (applyMediaQuery(mediaList[i].query, ecWidth, ecHeight)) {
  14760. indices.push(i);
  14761. }
  14762. }
  14763. // FIXME
  14764. // 是否mediaDefault应该强制用户设置,否则可能修改不能回归。
  14765. if (!indices.length && mediaDefault) {
  14766. indices = [-1];
  14767. }
  14768. if (indices.length && !indicesEquals(indices, this._currentMediaIndices)) {
  14769. result = map(indices, function (index) {
  14770. return clone(
  14771. index === -1 ? mediaDefault.option : mediaList[index].option
  14772. );
  14773. });
  14774. }
  14775. // Otherwise return nothing.
  14776. this._currentMediaIndices = indices;
  14777. return result;
  14778. }
  14779. };
  14780. function parseRawOption(rawOption, optionPreprocessorFuncs, isNew) {
  14781. var timelineOptions = [];
  14782. var mediaList = [];
  14783. var mediaDefault;
  14784. var baseOption;
  14785. // Compatible with ec2.
  14786. var timelineOpt = rawOption.timeline;
  14787. if (rawOption.baseOption) {
  14788. baseOption = rawOption.baseOption;
  14789. }
  14790. // For timeline
  14791. if (timelineOpt || rawOption.options) {
  14792. baseOption = baseOption || {};
  14793. timelineOptions = (rawOption.options || []).slice();
  14794. }
  14795. // For media query
  14796. if (rawOption.media) {
  14797. baseOption = baseOption || {};
  14798. var media = rawOption.media;
  14799. each(media, function (singleMedia) {
  14800. if (singleMedia && singleMedia.option) {
  14801. if (singleMedia.query) {
  14802. mediaList.push(singleMedia);
  14803. }
  14804. else if (!mediaDefault) {
  14805. // Use the first media default.
  14806. mediaDefault = singleMedia;
  14807. }
  14808. }
  14809. });
  14810. }
  14811. // For normal option
  14812. if (!baseOption) {
  14813. baseOption = rawOption;
  14814. }
  14815. // Set timelineOpt to baseOption in ec3,
  14816. // which is convenient for merge option.
  14817. if (!baseOption.timeline) {
  14818. baseOption.timeline = timelineOpt;
  14819. }
  14820. // Preprocess.
  14821. each([baseOption].concat(timelineOptions)
  14822. .concat(zrUtil.map(mediaList, function (media) {
  14823. return media.option;
  14824. })),
  14825. function (option) {
  14826. each(optionPreprocessorFuncs, function (preProcess) {
  14827. preProcess(option, isNew);
  14828. });
  14829. }
  14830. );
  14831. return {
  14832. baseOption: baseOption,
  14833. timelineOptions: timelineOptions,
  14834. mediaDefault: mediaDefault,
  14835. mediaList: mediaList
  14836. };
  14837. }
  14838. /**
  14839. * @see <http://www.w3.org/TR/css3-mediaqueries/#media1>
  14840. * Support: width, height, aspectRatio
  14841. * Can use max or min as prefix.
  14842. */
  14843. function applyMediaQuery(query, ecWidth, ecHeight) {
  14844. var realMap = {
  14845. width: ecWidth,
  14846. height: ecHeight,
  14847. aspectratio: ecWidth / ecHeight // lowser case for convenientce.
  14848. };
  14849. var applicatable = true;
  14850. zrUtil.each(query, function (value, attr) {
  14851. var matched = attr.match(QUERY_REG);
  14852. if (!matched || !matched[1] || !matched[2]) {
  14853. return;
  14854. }
  14855. var operator = matched[1];
  14856. var realAttr = matched[2].toLowerCase();
  14857. if (!compare(realMap[realAttr], value, operator)) {
  14858. applicatable = false;
  14859. }
  14860. });
  14861. return applicatable;
  14862. }
  14863. function compare(real, expect, operator) {
  14864. if (operator === 'min') {
  14865. return real >= expect;
  14866. }
  14867. else if (operator === 'max') {
  14868. return real <= expect;
  14869. }
  14870. else { // Equals
  14871. return real === expect;
  14872. }
  14873. }
  14874. function indicesEquals(indices1, indices2) {
  14875. // indices is always order by asc and has only finite number.
  14876. return indices1.join(',') === indices2.join(',');
  14877. }
  14878. /**
  14879. * Consider case:
  14880. * `chart.setOption(opt1);`
  14881. * Then user do some interaction like dataZoom, dataView changing.
  14882. * `chart.setOption(opt2);`
  14883. * Then user press 'reset button' in toolbox.
  14884. *
  14885. * After doing that all of the interaction effects should be reset, the
  14886. * chart should be the same as the result of invoke
  14887. * `chart.setOption(opt1); chart.setOption(opt2);`.
  14888. *
  14889. * Although it is not able ensure that
  14890. * `chart.setOption(opt1); chart.setOption(opt2);` is equivalents to
  14891. * `chart.setOption(merge(opt1, opt2));` exactly,
  14892. * this might be the only simple way to implement that feature.
  14893. *
  14894. * MEMO: We've considered some other approaches:
  14895. * 1. Each model handle its self restoration but not uniform treatment.
  14896. * (Too complex in logic and error-prone)
  14897. * 2. Use a shadow ecModel. (Performace expensive)
  14898. */
  14899. function mergeOption(oldOption, newOption) {
  14900. newOption = newOption || {};
  14901. each(newOption, function (newCptOpt, mainType) {
  14902. if (newCptOpt == null) {
  14903. return;
  14904. }
  14905. var oldCptOpt = oldOption[mainType];
  14906. if (!ComponentModel.hasClass(mainType)) {
  14907. oldOption[mainType] = merge(oldCptOpt, newCptOpt, true);
  14908. }
  14909. else {
  14910. newCptOpt = modelUtil.normalizeToArray(newCptOpt);
  14911. oldCptOpt = modelUtil.normalizeToArray(oldCptOpt);
  14912. var mapResult = modelUtil.mappingToExists(oldCptOpt, newCptOpt);
  14913. oldOption[mainType] = map(mapResult, function (item) {
  14914. return (item.option && item.exist)
  14915. ? merge(item.exist, item.option, true)
  14916. : (item.exist || item.option);
  14917. });
  14918. }
  14919. });
  14920. }
  14921. module.exports = OptionManager;
  14922. /***/ },
  14923. /* 78 */
  14924. /***/ function(module, exports, __webpack_require__) {
  14925. 'use strict';
  14926. var zrUtil = __webpack_require__(4);
  14927. var formatUtil = __webpack_require__(6);
  14928. var classUtil = __webpack_require__(13);
  14929. var modelUtil = __webpack_require__(5);
  14930. var ComponentModel = __webpack_require__(69);
  14931. var colorPaletteMixin = __webpack_require__(74);
  14932. var env = __webpack_require__(2);
  14933. var layout = __webpack_require__(71);
  14934. var set = classUtil.set;
  14935. var get = classUtil.get;
  14936. var encodeHTML = formatUtil.encodeHTML;
  14937. var addCommas = formatUtil.addCommas;
  14938. var SeriesModel = ComponentModel.extend({
  14939. type: 'series.__base__',
  14940. /**
  14941. * @readOnly
  14942. */
  14943. seriesIndex: 0,
  14944. // coodinateSystem will be injected in the echarts/CoordinateSystem
  14945. coordinateSystem: null,
  14946. /**
  14947. * @type {Object}
  14948. * @protected
  14949. */
  14950. defaultOption: null,
  14951. /**
  14952. * Data provided for legend
  14953. * @type {Function}
  14954. */
  14955. // PENDING
  14956. legendDataProvider: null,
  14957. /**
  14958. * Access path of color for visual
  14959. */
  14960. visualColorAccessPath: 'itemStyle.normal.color',
  14961. /**
  14962. * Support merge layout params.
  14963. * Only support 'box' now (left/right/top/bottom/width/height).
  14964. * @type {string|Object} Object can be {ignoreSize: true}
  14965. * @readOnly
  14966. */
  14967. layoutMode: null,
  14968. init: function (option, parentModel, ecModel, extraOpt) {
  14969. /**
  14970. * @type {number}
  14971. * @readOnly
  14972. */
  14973. this.seriesIndex = this.componentIndex;
  14974. this.mergeDefaultAndTheme(option, ecModel);
  14975. var data = this.getInitialData(option, ecModel);
  14976. if (true) {
  14977. zrUtil.assert(data, 'getInitialData returned invalid data.');
  14978. }
  14979. /**
  14980. * @type {module:echarts/data/List|module:echarts/data/Tree|module:echarts/data/Graph}
  14981. * @private
  14982. */
  14983. set(this, 'dataBeforeProcessed', data);
  14984. // If we reverse the order (make data firstly, and then make
  14985. // dataBeforeProcessed by cloneShallow), cloneShallow will
  14986. // cause data.graph.data !== data when using
  14987. // module:echarts/data/Graph or module:echarts/data/Tree.
  14988. // See module:echarts/data/helper/linkList
  14989. this.restoreData();
  14990. },
  14991. /**
  14992. * Util for merge default and theme to option
  14993. * @param {Object} option
  14994. * @param {module:echarts/model/Global} ecModel
  14995. */
  14996. mergeDefaultAndTheme: function (option, ecModel) {
  14997. var layoutMode = this.layoutMode;
  14998. var inputPositionParams = layoutMode
  14999. ? layout.getLayoutParams(option) : {};
  15000. zrUtil.merge(
  15001. option,
  15002. ecModel.getTheme().get(this.subType)
  15003. );
  15004. zrUtil.merge(option, this.getDefaultOption());
  15005. // Default label emphasis `position` and `show`
  15006. // FIXME Set label in mergeOption
  15007. modelUtil.defaultEmphasis(option.label, modelUtil.LABEL_OPTIONS);
  15008. this.fillDataTextStyle(option.data);
  15009. if (layoutMode) {
  15010. layout.mergeLayoutParam(option, inputPositionParams, layoutMode);
  15011. }
  15012. },
  15013. mergeOption: function (newSeriesOption, ecModel) {
  15014. newSeriesOption = zrUtil.merge(this.option, newSeriesOption, true);
  15015. this.fillDataTextStyle(newSeriesOption.data);
  15016. var layoutMode = this.layoutMode;
  15017. if (layoutMode) {
  15018. layout.mergeLayoutParam(this.option, newSeriesOption, layoutMode);
  15019. }
  15020. var data = this.getInitialData(newSeriesOption, ecModel);
  15021. // TODO Merge data?
  15022. if (data) {
  15023. set(this, 'data', data);
  15024. set(this, 'dataBeforeProcessed', data.cloneShallow());
  15025. }
  15026. },
  15027. fillDataTextStyle: function (data) {
  15028. // Default data label emphasis `position` and `show`
  15029. // FIXME Tree structure data ?
  15030. // FIXME Performance ?
  15031. if (data) {
  15032. for (var i = 0; i < data.length; i++) {
  15033. if (data[i] && data[i].label) {
  15034. modelUtil.defaultEmphasis(data[i].label, modelUtil.LABEL_OPTIONS);
  15035. }
  15036. }
  15037. }
  15038. },
  15039. /**
  15040. * Init a data structure from data related option in series
  15041. * Must be overwritten
  15042. */
  15043. getInitialData: function () {},
  15044. /**
  15045. * @param {string} [dataType]
  15046. * @return {module:echarts/data/List}
  15047. */
  15048. getData: function (dataType) {
  15049. var data = get(this, 'data');
  15050. return dataType == null ? data : data.getLinkedData(dataType);
  15051. },
  15052. /**
  15053. * @param {module:echarts/data/List} data
  15054. */
  15055. setData: function (data) {
  15056. set(this, 'data', data);
  15057. },
  15058. /**
  15059. * Get data before processed
  15060. * @return {module:echarts/data/List}
  15061. */
  15062. getRawData: function () {
  15063. return get(this, 'dataBeforeProcessed');
  15064. },
  15065. /**
  15066. * Coord dimension to data dimension.
  15067. *
  15068. * By default the result is the same as dimensions of series data.
  15069. * But in some series data dimensions are different from coord dimensions (i.e.
  15070. * candlestick and boxplot). Override this method to handle those cases.
  15071. *
  15072. * Coord dimension to data dimension can be one-to-many
  15073. *
  15074. * @param {string} coordDim
  15075. * @return {Array.<string>} dimensions on the axis.
  15076. */
  15077. coordDimToDataDim: function (coordDim) {
  15078. return modelUtil.coordDimToDataDim(this.getData(), coordDim);
  15079. },
  15080. /**
  15081. * Convert data dimension to coord dimension.
  15082. *
  15083. * @param {string|number} dataDim
  15084. * @return {string}
  15085. */
  15086. dataDimToCoordDim: function (dataDim) {
  15087. return modelUtil.dataDimToCoordDim(this.getData(), dataDim);
  15088. },
  15089. /**
  15090. * Get base axis if has coordinate system and has axis.
  15091. * By default use coordSys.getBaseAxis();
  15092. * Can be overrided for some chart.
  15093. * @return {type} description
  15094. */
  15095. getBaseAxis: function () {
  15096. var coordSys = this.coordinateSystem;
  15097. return coordSys && coordSys.getBaseAxis && coordSys.getBaseAxis();
  15098. },
  15099. // FIXME
  15100. /**
  15101. * Default tooltip formatter
  15102. *
  15103. * @param {number} dataIndex
  15104. * @param {boolean} [multipleSeries=false]
  15105. * @param {number} [dataType]
  15106. */
  15107. formatTooltip: function (dataIndex, multipleSeries, dataType) {
  15108. function formatArrayValue(value) {
  15109. var vertially = zrUtil.reduce(value, function (vertially, val, idx) {
  15110. var dimItem = data.getDimensionInfo(idx);
  15111. return vertially |= dimItem.tooltip !== false && dimItem.tooltipName != null;
  15112. }, 0);
  15113. var result = [];
  15114. var tooltipDims = modelUtil.otherDimToDataDim(data, 'tooltip');
  15115. tooltipDims.length
  15116. ? zrUtil.each(tooltipDims, function (dimIdx) {
  15117. setEachItem(data.get(dimIdx, dataIndex), dimIdx);
  15118. })
  15119. // By default, all dims is used on tooltip.
  15120. : zrUtil.each(value, setEachItem);
  15121. function setEachItem(val, dimIdx) {
  15122. var dimInfo = data.getDimensionInfo(dimIdx);
  15123. // If `dimInfo.tooltip` is not set, show tooltip.
  15124. if (!dimInfo || dimInfo.otherDims.tooltip === false) {
  15125. return;
  15126. }
  15127. var dimType = dimInfo.type;
  15128. var valStr = (vertially ? '- ' + (dimInfo.tooltipName || dimInfo.name) + ': ' : '')
  15129. + (dimType === 'ordinal'
  15130. ? val + ''
  15131. : dimType === 'time'
  15132. ? (multipleSeries ? '' : formatUtil.formatTime('yyyy/MM/dd hh:mm:ss', val))
  15133. : addCommas(val)
  15134. );
  15135. valStr && result.push(encodeHTML(valStr));
  15136. }
  15137. return (vertially ? '<br/>' : '') + result.join(vertially ? '<br/>' : ', ');
  15138. }
  15139. var data = get(this, 'data');
  15140. var value = this.getRawValue(dataIndex);
  15141. var formattedValue = zrUtil.isArray(value)
  15142. ? formatArrayValue(value) : encodeHTML(addCommas(value));
  15143. var name = data.getName(dataIndex);
  15144. var color = data.getItemVisual(dataIndex, 'color');
  15145. if (zrUtil.isObject(color) && color.colorStops) {
  15146. color = (color.colorStops[0] || {}).color;
  15147. }
  15148. color = color || 'transparent';
  15149. var colorEl = formatUtil.getTooltipMarker(color);
  15150. var seriesName = this.name;
  15151. // FIXME
  15152. if (seriesName === '\0-') {
  15153. // Not show '-'
  15154. seriesName = '';
  15155. }
  15156. seriesName = seriesName
  15157. ? encodeHTML(seriesName) + (!multipleSeries ? '<br/>' : ': ')
  15158. : '';
  15159. return !multipleSeries
  15160. ? seriesName + colorEl
  15161. + (name
  15162. ? encodeHTML(name) + ': ' + formattedValue
  15163. : formattedValue
  15164. )
  15165. : colorEl + seriesName + formattedValue;
  15166. },
  15167. /**
  15168. * @return {boolean}
  15169. */
  15170. isAnimationEnabled: function () {
  15171. if (env.node) {
  15172. return false;
  15173. }
  15174. var animationEnabled = this.getShallow('animation');
  15175. if (animationEnabled) {
  15176. if (this.getData().count() > this.getShallow('animationThreshold')) {
  15177. animationEnabled = false;
  15178. }
  15179. }
  15180. return animationEnabled;
  15181. },
  15182. restoreData: function () {
  15183. set(this, 'data', get(this, 'dataBeforeProcessed').cloneShallow());
  15184. },
  15185. getColorFromPalette: function (name, scope) {
  15186. var ecModel = this.ecModel;
  15187. // PENDING
  15188. var color = colorPaletteMixin.getColorFromPalette.call(this, name, scope);
  15189. if (!color) {
  15190. color = ecModel.getColorFromPalette(name, scope);
  15191. }
  15192. return color;
  15193. },
  15194. /**
  15195. * Get data indices for show tooltip content. See tooltip.
  15196. * @abstract
  15197. * @param {Array.<string>|string} dim
  15198. * @param {Array.<number>} value
  15199. * @param {module:echarts/coord/single/SingleAxis} baseAxis
  15200. * @return {Object} {dataIndices, nestestValue}.
  15201. */
  15202. getAxisTooltipData: null,
  15203. /**
  15204. * See tooltip.
  15205. * @abstract
  15206. * @param {number} dataIndex
  15207. * @return {Array.<number>} Point of tooltip. null/undefined can be returned.
  15208. */
  15209. getTooltipPosition: null
  15210. });
  15211. zrUtil.mixin(SeriesModel, modelUtil.dataFormatMixin);
  15212. zrUtil.mixin(SeriesModel, colorPaletteMixin);
  15213. module.exports = SeriesModel;
  15214. /***/ },
  15215. /* 79 */
  15216. /***/ function(module, exports, __webpack_require__) {
  15217. var Group = __webpack_require__(48);
  15218. var componentUtil = __webpack_require__(70);
  15219. var clazzUtil = __webpack_require__(13);
  15220. var Component = function () {
  15221. /**
  15222. * @type {module:zrender/container/Group}
  15223. * @readOnly
  15224. */
  15225. this.group = new Group();
  15226. /**
  15227. * @type {string}
  15228. * @readOnly
  15229. */
  15230. this.uid = componentUtil.getUID('viewComponent');
  15231. };
  15232. Component.prototype = {
  15233. constructor: Component,
  15234. init: function (ecModel, api) {},
  15235. render: function (componentModel, ecModel, api, payload) {},
  15236. dispose: function () {}
  15237. };
  15238. var componentProto = Component.prototype;
  15239. componentProto.updateView
  15240. = componentProto.updateLayout
  15241. = componentProto.updateVisual
  15242. = function (seriesModel, ecModel, api, payload) {
  15243. // Do nothing;
  15244. };
  15245. // Enable Component.extend.
  15246. clazzUtil.enableClassExtend(Component);
  15247. // Enable capability of registerClass, getClass, hasClass, registerSubTypeDefaulter and so on.
  15248. clazzUtil.enableClassManagement(Component, {registerWhenExtend: true});
  15249. module.exports = Component;
  15250. /***/ },
  15251. /* 80 */
  15252. /***/ function(module, exports, __webpack_require__) {
  15253. var Group = __webpack_require__(48);
  15254. var componentUtil = __webpack_require__(70);
  15255. var clazzUtil = __webpack_require__(13);
  15256. var modelUtil = __webpack_require__(5);
  15257. var zrUtil = __webpack_require__(4);
  15258. function Chart() {
  15259. /**
  15260. * @type {module:zrender/container/Group}
  15261. * @readOnly
  15262. */
  15263. this.group = new Group();
  15264. /**
  15265. * @type {string}
  15266. * @readOnly
  15267. */
  15268. this.uid = componentUtil.getUID('viewChart');
  15269. }
  15270. Chart.prototype = {
  15271. type: 'chart',
  15272. /**
  15273. * Init the chart
  15274. * @param {module:echarts/model/Global} ecModel
  15275. * @param {module:echarts/ExtensionAPI} api
  15276. */
  15277. init: function (ecModel, api) {},
  15278. /**
  15279. * Render the chart
  15280. * @param {module:echarts/model/Series} seriesModel
  15281. * @param {module:echarts/model/Global} ecModel
  15282. * @param {module:echarts/ExtensionAPI} api
  15283. * @param {Object} payload
  15284. */
  15285. render: function (seriesModel, ecModel, api, payload) {},
  15286. /**
  15287. * Highlight series or specified data item
  15288. * @param {module:echarts/model/Series} seriesModel
  15289. * @param {module:echarts/model/Global} ecModel
  15290. * @param {module:echarts/ExtensionAPI} api
  15291. * @param {Object} payload
  15292. */
  15293. highlight: function (seriesModel, ecModel, api, payload) {
  15294. toggleHighlight(seriesModel.getData(), payload, 'emphasis');
  15295. },
  15296. /**
  15297. * Downplay series or specified data item
  15298. * @param {module:echarts/model/Series} seriesModel
  15299. * @param {module:echarts/model/Global} ecModel
  15300. * @param {module:echarts/ExtensionAPI} api
  15301. * @param {Object} payload
  15302. */
  15303. downplay: function (seriesModel, ecModel, api, payload) {
  15304. toggleHighlight(seriesModel.getData(), payload, 'normal');
  15305. },
  15306. /**
  15307. * Remove self
  15308. * @param {module:echarts/model/Global} ecModel
  15309. * @param {module:echarts/ExtensionAPI} api
  15310. */
  15311. remove: function (ecModel, api) {
  15312. this.group.removeAll();
  15313. },
  15314. /**
  15315. * Dispose self
  15316. * @param {module:echarts/model/Global} ecModel
  15317. * @param {module:echarts/ExtensionAPI} api
  15318. */
  15319. dispose: function () {}
  15320. /**
  15321. * The view contains the given point.
  15322. * @interface
  15323. * @param {Array.<number>} point
  15324. * @return {boolean}
  15325. */
  15326. // containPoint: function () {}
  15327. };
  15328. var chartProto = Chart.prototype;
  15329. chartProto.updateView
  15330. = chartProto.updateLayout
  15331. = chartProto.updateVisual
  15332. = function (seriesModel, ecModel, api, payload) {
  15333. this.render(seriesModel, ecModel, api, payload);
  15334. };
  15335. /**
  15336. * Set state of single element
  15337. * @param {module:zrender/Element} el
  15338. * @param {string} state
  15339. */
  15340. function elSetState(el, state) {
  15341. if (el) {
  15342. el.trigger(state);
  15343. if (el.type === 'group') {
  15344. for (var i = 0; i < el.childCount(); i++) {
  15345. elSetState(el.childAt(i), state);
  15346. }
  15347. }
  15348. }
  15349. }
  15350. /**
  15351. * @param {module:echarts/data/List} data
  15352. * @param {Object} payload
  15353. * @param {string} state 'normal'|'emphasis'
  15354. * @inner
  15355. */
  15356. function toggleHighlight(data, payload, state) {
  15357. var dataIndex = modelUtil.queryDataIndex(data, payload);
  15358. if (dataIndex != null) {
  15359. zrUtil.each(modelUtil.normalizeToArray(dataIndex), function (dataIdx) {
  15360. elSetState(data.getItemGraphicEl(dataIdx), state);
  15361. });
  15362. }
  15363. else {
  15364. data.eachItemGraphicEl(function (el) {
  15365. elSetState(el, state);
  15366. });
  15367. }
  15368. }
  15369. // Enable Chart.extend.
  15370. clazzUtil.enableClassExtend(Chart, ['dispose']);
  15371. // Add capability of registerClass, getClass, hasClass, registerSubTypeDefaulter and so on.
  15372. clazzUtil.enableClassManagement(Chart, {registerWhenExtend: true});
  15373. module.exports = Chart;
  15374. /***/ },
  15375. /* 81 */
  15376. /***/ function(module, exports) {
  15377. var lib = {};
  15378. var ORIGIN_METHOD = '\0__throttleOriginMethod';
  15379. var RATE = '\0__throttleRate';
  15380. var THROTTLE_TYPE = '\0__throttleType';
  15381. /**
  15382. * @public
  15383. * @param {(Function)} fn
  15384. * @param {number} [delay=0] Unit: ms.
  15385. * @param {boolean} [debounce=false]
  15386. * true: If call interval less than `delay`, only the last call works.
  15387. * false: If call interval less than `delay, call works on fixed rate.
  15388. * @return {(Function)} throttled fn.
  15389. */
  15390. lib.throttle = function (fn, delay, debounce) {
  15391. var currCall;
  15392. var lastCall = 0;
  15393. var lastExec = 0;
  15394. var timer = null;
  15395. var diff;
  15396. var scope;
  15397. var args;
  15398. var debounceNextCall;
  15399. delay = delay || 0;
  15400. function exec() {
  15401. lastExec = (new Date()).getTime();
  15402. timer = null;
  15403. fn.apply(scope, args || []);
  15404. }
  15405. var cb = function () {
  15406. currCall = (new Date()).getTime();
  15407. scope = this;
  15408. args = arguments;
  15409. var thisDelay = debounceNextCall || delay;
  15410. var thisDebounce = debounceNextCall || debounce;
  15411. debounceNextCall = null;
  15412. diff = currCall - (thisDebounce ? lastCall : lastExec) - thisDelay;
  15413. clearTimeout(timer);
  15414. if (thisDebounce) {
  15415. timer = setTimeout(exec, thisDelay);
  15416. }
  15417. else {
  15418. if (diff >= 0) {
  15419. exec();
  15420. }
  15421. else {
  15422. timer = setTimeout(exec, -diff);
  15423. }
  15424. }
  15425. lastCall = currCall;
  15426. };
  15427. /**
  15428. * Clear throttle.
  15429. * @public
  15430. */
  15431. cb.clear = function () {
  15432. if (timer) {
  15433. clearTimeout(timer);
  15434. timer = null;
  15435. }
  15436. };
  15437. /**
  15438. * Enable debounce once.
  15439. */
  15440. cb.debounceNextCall = function (debounceDelay) {
  15441. debounceNextCall = debounceDelay;
  15442. };
  15443. return cb;
  15444. };
  15445. /**
  15446. * Create throttle method or update throttle rate.
  15447. *
  15448. * @example
  15449. * ComponentView.prototype.render = function () {
  15450. * ...
  15451. * throttle.createOrUpdate(
  15452. * this,
  15453. * '_dispatchAction',
  15454. * this.model.get('throttle'),
  15455. * 'fixRate'
  15456. * );
  15457. * };
  15458. * ComponentView.prototype.remove = function () {
  15459. * throttle.clear(this, '_dispatchAction');
  15460. * };
  15461. * ComponentView.prototype.dispose = function () {
  15462. * throttle.clear(this, '_dispatchAction');
  15463. * };
  15464. *
  15465. * @public
  15466. * @param {Object} obj
  15467. * @param {string} fnAttr
  15468. * @param {number} [rate]
  15469. * @param {string} [throttleType='fixRate'] 'fixRate' or 'debounce'
  15470. * @return {Function} throttled function.
  15471. */
  15472. lib.createOrUpdate = function (obj, fnAttr, rate, throttleType) {
  15473. var fn = obj[fnAttr];
  15474. if (!fn) {
  15475. return;
  15476. }
  15477. var originFn = fn[ORIGIN_METHOD] || fn;
  15478. var lastThrottleType = fn[THROTTLE_TYPE];
  15479. var lastRate = fn[RATE];
  15480. if (lastRate !== rate || lastThrottleType !== throttleType) {
  15481. if (rate == null || !throttleType) {
  15482. return (obj[fnAttr] = originFn);
  15483. }
  15484. fn = obj[fnAttr] = lib.throttle(
  15485. originFn, rate, throttleType === 'debounce'
  15486. );
  15487. fn[ORIGIN_METHOD] = originFn;
  15488. fn[THROTTLE_TYPE] = throttleType;
  15489. fn[RATE] = rate;
  15490. }
  15491. return fn;
  15492. };
  15493. /**
  15494. * Clear throttle. Example see throttle.createOrUpdate.
  15495. *
  15496. * @public
  15497. * @param {Object} obj
  15498. * @param {string} fnAttr
  15499. */
  15500. lib.clear = function (obj, fnAttr) {
  15501. var fn = obj[fnAttr];
  15502. if (fn && fn[ORIGIN_METHOD]) {
  15503. obj[fnAttr] = fn[ORIGIN_METHOD];
  15504. }
  15505. };
  15506. module.exports = lib;
  15507. /***/ },
  15508. /* 82 */
  15509. /***/ function(module, exports, __webpack_require__) {
  15510. /*!
  15511. * ZRender, a high performance 2d drawing library.
  15512. *
  15513. * Copyright (c) 2013, Baidu Inc.
  15514. * All rights reserved.
  15515. *
  15516. * LICENSE
  15517. * https://github.com/ecomfe/zrender/blob/master/LICENSE.txt
  15518. */
  15519. // Global defines
  15520. var guid = __webpack_require__(24);
  15521. var env = __webpack_require__(2);
  15522. var zrUtil = __webpack_require__(4);
  15523. var Handler = __webpack_require__(83);
  15524. var Storage = __webpack_require__(85);
  15525. var Animation = __webpack_require__(87);
  15526. var HandlerProxy = __webpack_require__(90);
  15527. var useVML = !env.canvasSupported;
  15528. var painterCtors = {
  15529. canvas: __webpack_require__(92)
  15530. };
  15531. var instances = {}; // ZRender实例map索引
  15532. var zrender = {};
  15533. /**
  15534. * @type {string}
  15535. */
  15536. zrender.version = '3.5.1';
  15537. /**
  15538. * Initializing a zrender instance
  15539. * @param {HTMLElement} dom
  15540. * @param {Object} opts
  15541. * @param {string} [opts.renderer='canvas'] 'canvas' or 'svg'
  15542. * @param {number} [opts.devicePixelRatio]
  15543. * @param {number|string} [opts.width] Can be 'auto' (the same as null/undefined)
  15544. * @param {number|string} [opts.height] Can be 'auto' (the same as null/undefined)
  15545. * @return {module:zrender/ZRender}
  15546. */
  15547. zrender.init = function(dom, opts) {
  15548. var zr = new ZRender(guid(), dom, opts);
  15549. instances[zr.id] = zr;
  15550. return zr;
  15551. };
  15552. /**
  15553. * Dispose zrender instance
  15554. * @param {module:zrender/ZRender} zr
  15555. */
  15556. zrender.dispose = function (zr) {
  15557. if (zr) {
  15558. zr.dispose();
  15559. }
  15560. else {
  15561. for (var key in instances) {
  15562. if (instances.hasOwnProperty(key)) {
  15563. instances[key].dispose();
  15564. }
  15565. }
  15566. instances = {};
  15567. }
  15568. return zrender;
  15569. };
  15570. /**
  15571. * Get zrender instance by id
  15572. * @param {string} id zrender instance id
  15573. * @return {module:zrender/ZRender}
  15574. */
  15575. zrender.getInstance = function (id) {
  15576. return instances[id];
  15577. };
  15578. zrender.registerPainter = function (name, Ctor) {
  15579. painterCtors[name] = Ctor;
  15580. };
  15581. function delInstance(id) {
  15582. delete instances[id];
  15583. }
  15584. /**
  15585. * @module zrender/ZRender
  15586. */
  15587. /**
  15588. * @constructor
  15589. * @alias module:zrender/ZRender
  15590. * @param {string} id
  15591. * @param {HTMLDomElement} dom
  15592. * @param {Object} opts
  15593. * @param {string} [opts.renderer='canvas'] 'canvas' or 'svg'
  15594. * @param {number} [opts.devicePixelRatio]
  15595. * @param {number} [opts.width] Can be 'auto' (the same as null/undefined)
  15596. * @param {number} [opts.height] Can be 'auto' (the same as null/undefined)
  15597. */
  15598. var ZRender = function(id, dom, opts) {
  15599. opts = opts || {};
  15600. /**
  15601. * @type {HTMLDomElement}
  15602. */
  15603. this.dom = dom;
  15604. /**
  15605. * @type {string}
  15606. */
  15607. this.id = id;
  15608. var self = this;
  15609. var storage = new Storage();
  15610. var rendererType = opts.renderer;
  15611. // TODO WebGL
  15612. if (useVML) {
  15613. if (!painterCtors.vml) {
  15614. throw new Error('You need to require \'zrender/vml/vml\' to support IE8');
  15615. }
  15616. rendererType = 'vml';
  15617. }
  15618. else if (!rendererType || !painterCtors[rendererType]) {
  15619. rendererType = 'canvas';
  15620. }
  15621. var painter = new painterCtors[rendererType](dom, storage, opts);
  15622. this.storage = storage;
  15623. this.painter = painter;
  15624. var handerProxy = !env.node ? new HandlerProxy(painter.getViewportRoot()) : null;
  15625. this.handler = new Handler(storage, painter, handerProxy, painter.root);
  15626. /**
  15627. * @type {module:zrender/animation/Animation}
  15628. */
  15629. this.animation = new Animation({
  15630. stage: {
  15631. update: zrUtil.bind(this.flush, this)
  15632. }
  15633. });
  15634. this.animation.start();
  15635. /**
  15636. * @type {boolean}
  15637. * @private
  15638. */
  15639. this._needsRefresh;
  15640. // 修改 storage.delFromStorage, 每次删除元素之前删除动画
  15641. // FIXME 有点ugly
  15642. var oldDelFromStorage = storage.delFromStorage;
  15643. var oldAddToStorage = storage.addToStorage;
  15644. storage.delFromStorage = function (el) {
  15645. oldDelFromStorage.call(storage, el);
  15646. el && el.removeSelfFromZr(self);
  15647. };
  15648. storage.addToStorage = function (el) {
  15649. oldAddToStorage.call(storage, el);
  15650. el.addSelfToZr(self);
  15651. };
  15652. };
  15653. ZRender.prototype = {
  15654. constructor: ZRender,
  15655. /**
  15656. * 获取实例唯一标识
  15657. * @return {string}
  15658. */
  15659. getId: function () {
  15660. return this.id;
  15661. },
  15662. /**
  15663. * 添加元素
  15664. * @param {module:zrender/Element} el
  15665. */
  15666. add: function (el) {
  15667. this.storage.addRoot(el);
  15668. this._needsRefresh = true;
  15669. },
  15670. /**
  15671. * 删除元素
  15672. * @param {module:zrender/Element} el
  15673. */
  15674. remove: function (el) {
  15675. this.storage.delRoot(el);
  15676. this._needsRefresh = true;
  15677. },
  15678. /**
  15679. * Change configuration of layer
  15680. * @param {string} zLevel
  15681. * @param {Object} config
  15682. * @param {string} [config.clearColor=0] Clear color
  15683. * @param {string} [config.motionBlur=false] If enable motion blur
  15684. * @param {number} [config.lastFrameAlpha=0.7] Motion blur factor. Larger value cause longer trailer
  15685. */
  15686. configLayer: function (zLevel, config) {
  15687. this.painter.configLayer(zLevel, config);
  15688. this._needsRefresh = true;
  15689. },
  15690. /**
  15691. * Repaint the canvas immediately
  15692. */
  15693. refreshImmediately: function () {
  15694. // Clear needsRefresh ahead to avoid something wrong happens in refresh
  15695. // Or it will cause zrender refreshes again and again.
  15696. this._needsRefresh = false;
  15697. this.painter.refresh();
  15698. /**
  15699. * Avoid trigger zr.refresh in Element#beforeUpdate hook
  15700. */
  15701. this._needsRefresh = false;
  15702. },
  15703. /**
  15704. * Mark and repaint the canvas in the next frame of browser
  15705. */
  15706. refresh: function() {
  15707. this._needsRefresh = true;
  15708. },
  15709. /**
  15710. * Perform all refresh
  15711. */
  15712. flush: function () {
  15713. if (this._needsRefresh) {
  15714. this.refreshImmediately();
  15715. }
  15716. if (this._needsRefreshHover) {
  15717. this.refreshHoverImmediately();
  15718. }
  15719. },
  15720. /**
  15721. * Add element to hover layer
  15722. * @param {module:zrender/Element} el
  15723. * @param {Object} style
  15724. */
  15725. addHover: function (el, style) {
  15726. if (this.painter.addHover) {
  15727. this.painter.addHover(el, style);
  15728. this.refreshHover();
  15729. }
  15730. },
  15731. /**
  15732. * Add element from hover layer
  15733. * @param {module:zrender/Element} el
  15734. */
  15735. removeHover: function (el) {
  15736. if (this.painter.removeHover) {
  15737. this.painter.removeHover(el);
  15738. this.refreshHover();
  15739. }
  15740. },
  15741. /**
  15742. * Clear all hover elements in hover layer
  15743. * @param {module:zrender/Element} el
  15744. */
  15745. clearHover: function () {
  15746. if (this.painter.clearHover) {
  15747. this.painter.clearHover();
  15748. this.refreshHover();
  15749. }
  15750. },
  15751. /**
  15752. * Refresh hover in next frame
  15753. */
  15754. refreshHover: function () {
  15755. this._needsRefreshHover = true;
  15756. },
  15757. /**
  15758. * Refresh hover immediately
  15759. */
  15760. refreshHoverImmediately: function () {
  15761. this._needsRefreshHover = false;
  15762. this.painter.refreshHover && this.painter.refreshHover();
  15763. },
  15764. /**
  15765. * Resize the canvas.
  15766. * Should be invoked when container size is changed
  15767. * @param {Object} [opts]
  15768. * @param {number|string} [opts.width] Can be 'auto' (the same as null/undefined)
  15769. * @param {number|string} [opts.height] Can be 'auto' (the same as null/undefined)
  15770. */
  15771. resize: function(opts) {
  15772. opts = opts || {};
  15773. this.painter.resize(opts.width, opts.height);
  15774. this.handler.resize();
  15775. },
  15776. /**
  15777. * Stop and clear all animation immediately
  15778. */
  15779. clearAnimation: function () {
  15780. this.animation.clear();
  15781. },
  15782. /**
  15783. * Get container width
  15784. */
  15785. getWidth: function() {
  15786. return this.painter.getWidth();
  15787. },
  15788. /**
  15789. * Get container height
  15790. */
  15791. getHeight: function() {
  15792. return this.painter.getHeight();
  15793. },
  15794. /**
  15795. * Export the canvas as Base64 URL
  15796. * @param {string} type
  15797. * @param {string} [backgroundColor='#fff']
  15798. * @return {string} Base64 URL
  15799. */
  15800. // toDataURL: function(type, backgroundColor) {
  15801. // return this.painter.getRenderedCanvas({
  15802. // backgroundColor: backgroundColor
  15803. // }).toDataURL(type);
  15804. // },
  15805. /**
  15806. * Converting a path to image.
  15807. * It has much better performance of drawing image rather than drawing a vector path.
  15808. * @param {module:zrender/graphic/Path} e
  15809. * @param {number} width
  15810. * @param {number} height
  15811. */
  15812. pathToImage: function(e, dpr) {
  15813. return this.painter.pathToImage(e, dpr);
  15814. },
  15815. /**
  15816. * Set default cursor
  15817. * @param {string} [cursorStyle='default'] 例如 crosshair
  15818. */
  15819. setCursorStyle: function (cursorStyle) {
  15820. this.handler.setCursorStyle(cursorStyle);
  15821. },
  15822. /**
  15823. * Find hovered element
  15824. * @param {number} x
  15825. * @param {number} y
  15826. * @return {Object} {target, topTarget}
  15827. */
  15828. findHover: function (x, y) {
  15829. return this.handler.findHover(x, y);
  15830. },
  15831. /**
  15832. * Bind event
  15833. *
  15834. * @param {string} eventName Event name
  15835. * @param {Function} eventHandler Handler function
  15836. * @param {Object} [context] Context object
  15837. */
  15838. on: function(eventName, eventHandler, context) {
  15839. this.handler.on(eventName, eventHandler, context);
  15840. },
  15841. /**
  15842. * Unbind event
  15843. * @param {string} eventName Event name
  15844. * @param {Function} [eventHandler] Handler function
  15845. */
  15846. off: function(eventName, eventHandler) {
  15847. this.handler.off(eventName, eventHandler);
  15848. },
  15849. /**
  15850. * Trigger event manually
  15851. *
  15852. * @param {string} eventName Event name
  15853. * @param {event=} event Event object
  15854. */
  15855. trigger: function (eventName, event) {
  15856. this.handler.trigger(eventName, event);
  15857. },
  15858. /**
  15859. * Clear all objects and the canvas.
  15860. */
  15861. clear: function () {
  15862. this.storage.delRoot();
  15863. this.painter.clear();
  15864. },
  15865. /**
  15866. * Dispose self.
  15867. */
  15868. dispose: function () {
  15869. this.animation.stop();
  15870. this.clear();
  15871. this.storage.dispose();
  15872. this.painter.dispose();
  15873. this.handler.dispose();
  15874. this.animation =
  15875. this.storage =
  15876. this.painter =
  15877. this.handler = null;
  15878. delInstance(this.id);
  15879. }
  15880. };
  15881. module.exports = zrender;
  15882. /***/ },
  15883. /* 83 */
  15884. /***/ function(module, exports, __webpack_require__) {
  15885. 'use strict';
  15886. /**
  15887. * Handler
  15888. * @module zrender/Handler
  15889. * @author Kener (@Kener-林峰, kener.linfeng@gmail.com)
  15890. * errorrik (errorrik@gmail.com)
  15891. * pissang (shenyi.914@gmail.com)
  15892. */
  15893. var util = __webpack_require__(4);
  15894. var Draggable = __webpack_require__(84);
  15895. var Eventful = __webpack_require__(25);
  15896. var SILENT = 'silent';
  15897. function makeEventPacket(eveType, targetInfo, event) {
  15898. return {
  15899. type: eveType,
  15900. event: event,
  15901. // target can only be an element that is not silent.
  15902. target: targetInfo.target,
  15903. // topTarget can be a silent element.
  15904. topTarget: targetInfo.topTarget,
  15905. cancelBubble: false,
  15906. offsetX: event.zrX,
  15907. offsetY: event.zrY,
  15908. gestureEvent: event.gestureEvent,
  15909. pinchX: event.pinchX,
  15910. pinchY: event.pinchY,
  15911. pinchScale: event.pinchScale,
  15912. wheelDelta: event.zrDelta,
  15913. zrByTouch: event.zrByTouch
  15914. };
  15915. }
  15916. function EmptyProxy () {}
  15917. EmptyProxy.prototype.dispose = function () {};
  15918. var handlerNames = [
  15919. 'click', 'dblclick', 'mousewheel', 'mouseout',
  15920. 'mouseup', 'mousedown', 'mousemove', 'contextmenu'
  15921. ];
  15922. /**
  15923. * @alias module:zrender/Handler
  15924. * @constructor
  15925. * @extends module:zrender/mixin/Eventful
  15926. * @param {module:zrender/Storage} storage Storage instance.
  15927. * @param {module:zrender/Painter} painter Painter instance.
  15928. * @param {module:zrender/dom/HandlerProxy} proxy HandlerProxy instance.
  15929. * @param {HTMLElement} painterRoot painter.root (not painter.getViewportRoot()).
  15930. */
  15931. var Handler = function(storage, painter, proxy, painterRoot) {
  15932. Eventful.call(this);
  15933. this.storage = storage;
  15934. this.painter = painter;
  15935. this.painterRoot = painterRoot;
  15936. proxy = proxy || new EmptyProxy();
  15937. /**
  15938. * Proxy of event. can be Dom, WebGLSurface, etc.
  15939. */
  15940. this.proxy = proxy;
  15941. // Attach handler
  15942. proxy.handler = this;
  15943. /**
  15944. * {target, topTarget}
  15945. * @private
  15946. * @type {Object}
  15947. */
  15948. this._hovered = {};
  15949. /**
  15950. * @private
  15951. * @type {Date}
  15952. */
  15953. this._lastTouchMoment;
  15954. /**
  15955. * @private
  15956. * @type {number}
  15957. */
  15958. this._lastX;
  15959. /**
  15960. * @private
  15961. * @type {number}
  15962. */
  15963. this._lastY;
  15964. Draggable.call(this);
  15965. util.each(handlerNames, function (name) {
  15966. proxy.on && proxy.on(name, this[name], this);
  15967. }, this);
  15968. };
  15969. Handler.prototype = {
  15970. constructor: Handler,
  15971. mousemove: function (event) {
  15972. var x = event.zrX;
  15973. var y = event.zrY;
  15974. var lastHovered = this._hovered;
  15975. var hovered = this._hovered = this.findHover(x, y);
  15976. var hoveredTarget = hovered.target;
  15977. var lastHoveredTarget = lastHovered.target;
  15978. var proxy = this.proxy;
  15979. proxy.setCursor && proxy.setCursor(hoveredTarget ? hoveredTarget.cursor : 'default');
  15980. // Mouse out on previous hovered element
  15981. if (lastHoveredTarget && hoveredTarget !== lastHoveredTarget && lastHoveredTarget.__zr) {
  15982. this.dispatchToElement(lastHovered, 'mouseout', event);
  15983. }
  15984. // Mouse moving on one element
  15985. this.dispatchToElement(hovered, 'mousemove', event);
  15986. // Mouse over on a new element
  15987. if (hoveredTarget && hoveredTarget !== lastHoveredTarget) {
  15988. this.dispatchToElement(hovered, 'mouseover', event);
  15989. }
  15990. },
  15991. mouseout: function (event) {
  15992. this.dispatchToElement(this._hovered, 'mouseout', event);
  15993. // There might be some doms created by upper layer application
  15994. // at the same level of painter.getViewportRoot() (e.g., tooltip
  15995. // dom created by echarts), where 'globalout' event should not
  15996. // be triggered when mouse enters these doms. (But 'mouseout'
  15997. // should be triggered at the original hovered element as usual).
  15998. var element = event.toElement || event.relatedTarget;
  15999. var innerDom;
  16000. do {
  16001. element = element && element.parentNode;
  16002. }
  16003. while (element && element.nodeType != 9 && !(
  16004. innerDom = element === this.painterRoot
  16005. ));
  16006. !innerDom && this.trigger('globalout', {event: event});
  16007. },
  16008. /**
  16009. * Resize
  16010. */
  16011. resize: function (event) {
  16012. this._hovered = {};
  16013. },
  16014. /**
  16015. * Dispatch event
  16016. * @param {string} eventName
  16017. * @param {event=} eventArgs
  16018. */
  16019. dispatch: function (eventName, eventArgs) {
  16020. var handler = this[eventName];
  16021. handler && handler.call(this, eventArgs);
  16022. },
  16023. /**
  16024. * Dispose
  16025. */
  16026. dispose: function () {
  16027. this.proxy.dispose();
  16028. this.storage =
  16029. this.proxy =
  16030. this.painter = null;
  16031. },
  16032. /**
  16033. * 设置默认的cursor style
  16034. * @param {string} [cursorStyle='default'] 例如 crosshair
  16035. */
  16036. setCursorStyle: function (cursorStyle) {
  16037. var proxy = this.proxy;
  16038. proxy.setCursor && proxy.setCursor(cursorStyle);
  16039. },
  16040. /**
  16041. * 事件分发代理
  16042. *
  16043. * @private
  16044. * @param {Object} targetInfo {target, topTarget} 目标图形元素
  16045. * @param {string} eventName 事件名称
  16046. * @param {Object} event 事件对象
  16047. */
  16048. dispatchToElement: function (targetInfo, eventName, event) {
  16049. targetInfo = targetInfo || {};
  16050. var eventHandler = 'on' + eventName;
  16051. var eventPacket = makeEventPacket(eventName, targetInfo, event);
  16052. var el = targetInfo.target;
  16053. while (el) {
  16054. el[eventHandler]
  16055. && (eventPacket.cancelBubble = el[eventHandler].call(el, eventPacket));
  16056. el.trigger(eventName, eventPacket);
  16057. el = el.parent;
  16058. if (eventPacket.cancelBubble) {
  16059. break;
  16060. }
  16061. }
  16062. if (!eventPacket.cancelBubble) {
  16063. // 冒泡到顶级 zrender 对象
  16064. this.trigger(eventName, eventPacket);
  16065. // 分发事件到用户自定义层
  16066. // 用户有可能在全局 click 事件中 dispose,所以需要判断下 painter 是否存在
  16067. this.painter && this.painter.eachOtherLayer(function (layer) {
  16068. if (typeof(layer[eventHandler]) == 'function') {
  16069. layer[eventHandler].call(layer, eventPacket);
  16070. }
  16071. if (layer.trigger) {
  16072. layer.trigger(eventName, eventPacket);
  16073. }
  16074. });
  16075. }
  16076. },
  16077. /**
  16078. * @private
  16079. * @param {number} x
  16080. * @param {number} y
  16081. * @param {module:zrender/graphic/Displayable} exclude
  16082. * @return {model:zrender/Element}
  16083. * @method
  16084. */
  16085. findHover: function(x, y, exclude) {
  16086. var list = this.storage.getDisplayList();
  16087. var out = {};
  16088. for (var i = list.length - 1; i >= 0 ; i--) {
  16089. var hoverCheckResult;
  16090. if (list[i] !== exclude
  16091. // getDisplayList may include ignored item in VML mode
  16092. && !list[i].ignore
  16093. && (hoverCheckResult = isHover(list[i], x, y))
  16094. ) {
  16095. !out.topTarget && (out.topTarget = list[i]);
  16096. if (hoverCheckResult !== SILENT) {
  16097. out.target = list[i];
  16098. break;
  16099. }
  16100. }
  16101. }
  16102. return out;
  16103. }
  16104. };
  16105. // Common handlers
  16106. util.each(['click', 'mousedown', 'mouseup', 'mousewheel', 'dblclick', 'contextmenu'], function (name) {
  16107. Handler.prototype[name] = function (event) {
  16108. // Find hover again to avoid click event is dispatched manually. Or click is triggered without mouseover
  16109. var hovered = this.findHover(event.zrX, event.zrY);
  16110. var hoveredTarget = hovered.target;
  16111. if (name === 'mousedown') {
  16112. this._downel = hoveredTarget;
  16113. // In case click triggered before mouseup
  16114. this._upel = hoveredTarget;
  16115. }
  16116. else if (name === 'mosueup') {
  16117. this._upel = hoveredTarget;
  16118. }
  16119. else if (name === 'click') {
  16120. if (this._downel !== this._upel) {
  16121. return;
  16122. }
  16123. }
  16124. this.dispatchToElement(hovered, name, event);
  16125. };
  16126. });
  16127. function isHover(displayable, x, y) {
  16128. if (displayable[displayable.rectHover ? 'rectContain' : 'contain'](x, y)) {
  16129. var el = displayable;
  16130. var isSilent;
  16131. while (el) {
  16132. // If clipped by ancestor.
  16133. // FIXME: If clipPath has neither stroke nor fill,
  16134. // el.clipPath.contain(x, y) will always return false.
  16135. if (el.clipPath && !el.clipPath.contain(x, y)) {
  16136. return false;
  16137. }
  16138. if (el.silent) {
  16139. isSilent = true;
  16140. }
  16141. el = el.parent;
  16142. }
  16143. return isSilent ? SILENT : true;
  16144. }
  16145. return false;
  16146. }
  16147. util.mixin(Handler, Eventful);
  16148. util.mixin(Handler, Draggable);
  16149. module.exports = Handler;
  16150. /***/ },
  16151. /* 84 */
  16152. /***/ function(module, exports) {
  16153. // TODO Draggable for group
  16154. // FIXME Draggable on element which has parent rotation or scale
  16155. function Draggable() {
  16156. this.on('mousedown', this._dragStart, this);
  16157. this.on('mousemove', this._drag, this);
  16158. this.on('mouseup', this._dragEnd, this);
  16159. this.on('globalout', this._dragEnd, this);
  16160. // this._dropTarget = null;
  16161. // this._draggingTarget = null;
  16162. // this._x = 0;
  16163. // this._y = 0;
  16164. }
  16165. Draggable.prototype = {
  16166. constructor: Draggable,
  16167. _dragStart: function (e) {
  16168. var draggingTarget = e.target;
  16169. if (draggingTarget && draggingTarget.draggable) {
  16170. this._draggingTarget = draggingTarget;
  16171. draggingTarget.dragging = true;
  16172. this._x = e.offsetX;
  16173. this._y = e.offsetY;
  16174. this.dispatchToElement(param(draggingTarget, e), 'dragstart', e.event);
  16175. }
  16176. },
  16177. _drag: function (e) {
  16178. var draggingTarget = this._draggingTarget;
  16179. if (draggingTarget) {
  16180. var x = e.offsetX;
  16181. var y = e.offsetY;
  16182. var dx = x - this._x;
  16183. var dy = y - this._y;
  16184. this._x = x;
  16185. this._y = y;
  16186. draggingTarget.drift(dx, dy, e);
  16187. this.dispatchToElement(param(draggingTarget, e), 'drag', e.event);
  16188. var dropTarget = this.findHover(x, y, draggingTarget).target;
  16189. var lastDropTarget = this._dropTarget;
  16190. this._dropTarget = dropTarget;
  16191. if (draggingTarget !== dropTarget) {
  16192. if (lastDropTarget && dropTarget !== lastDropTarget) {
  16193. this.dispatchToElement(param(lastDropTarget, e), 'dragleave', e.event);
  16194. }
  16195. if (dropTarget && dropTarget !== lastDropTarget) {
  16196. this.dispatchToElement(param(dropTarget, e), 'dragenter', e.event);
  16197. }
  16198. }
  16199. }
  16200. },
  16201. _dragEnd: function (e) {
  16202. var draggingTarget = this._draggingTarget;
  16203. if (draggingTarget) {
  16204. draggingTarget.dragging = false;
  16205. }
  16206. this.dispatchToElement(param(draggingTarget, e), 'dragend', e.event);
  16207. if (this._dropTarget) {
  16208. this.dispatchToElement(param(this._dropTarget, e), 'drop', e.event);
  16209. }
  16210. this._draggingTarget = null;
  16211. this._dropTarget = null;
  16212. }
  16213. };
  16214. function param(target, e) {
  16215. return {target: target, topTarget: e && e.topTarget};
  16216. }
  16217. module.exports = Draggable;
  16218. /***/ },
  16219. /* 85 */
  16220. /***/ function(module, exports, __webpack_require__) {
  16221. 'use strict';
  16222. /**
  16223. * Storage内容仓库模块
  16224. * @module zrender/Storage
  16225. * @author Kener (@Kener-林峰, kener.linfeng@gmail.com)
  16226. * @author errorrik (errorrik@gmail.com)
  16227. * @author pissang (https://github.com/pissang/)
  16228. */
  16229. var util = __webpack_require__(4);
  16230. var env = __webpack_require__(2);
  16231. var Group = __webpack_require__(48);
  16232. // Use timsort because in most case elements are partially sorted
  16233. // https://jsfiddle.net/pissang/jr4x7mdm/8/
  16234. var timsort = __webpack_require__(86);
  16235. function shapeCompareFunc(a, b) {
  16236. if (a.zlevel === b.zlevel) {
  16237. if (a.z === b.z) {
  16238. // if (a.z2 === b.z2) {
  16239. // // FIXME Slow has renderidx compare
  16240. // // http://stackoverflow.com/questions/20883421/sorting-in-javascript-should-every-compare-function-have-a-return-0-statement
  16241. // // https://github.com/v8/v8/blob/47cce544a31ed5577ffe2963f67acb4144ee0232/src/js/array.js#L1012
  16242. // return a.__renderidx - b.__renderidx;
  16243. // }
  16244. return a.z2 - b.z2;
  16245. }
  16246. return a.z - b.z;
  16247. }
  16248. return a.zlevel - b.zlevel;
  16249. }
  16250. /**
  16251. * 内容仓库 (M)
  16252. * @alias module:zrender/Storage
  16253. * @constructor
  16254. */
  16255. var Storage = function () {
  16256. this._roots = [];
  16257. this._displayList = [];
  16258. this._displayListLen = 0;
  16259. };
  16260. Storage.prototype = {
  16261. constructor: Storage,
  16262. /**
  16263. * @param {Function} cb
  16264. *
  16265. */
  16266. traverse: function (cb, context) {
  16267. for (var i = 0; i < this._roots.length; i++) {
  16268. this._roots[i].traverse(cb, context);
  16269. }
  16270. },
  16271. /**
  16272. * 返回所有图形的绘制队列
  16273. * @param {boolean} [update=false] 是否在返回前更新该数组
  16274. * @param {boolean} [includeIgnore=false] 是否包含 ignore 的数组, 在 update 为 true 的时候有效
  16275. *
  16276. * 详见{@link module:zrender/graphic/Displayable.prototype.updateDisplayList}
  16277. * @return {Array.<module:zrender/graphic/Displayable>}
  16278. */
  16279. getDisplayList: function (update, includeIgnore) {
  16280. includeIgnore = includeIgnore || false;
  16281. if (update) {
  16282. this.updateDisplayList(includeIgnore);
  16283. }
  16284. return this._displayList;
  16285. },
  16286. /**
  16287. * 更新图形的绘制队列。
  16288. * 每次绘制前都会调用,该方法会先深度优先遍历整个树,更新所有Group和Shape的变换并且把所有可见的Shape保存到数组中,
  16289. * 最后根据绘制的优先级(zlevel > z > 插入顺序)排序得到绘制队列
  16290. * @param {boolean} [includeIgnore=false] 是否包含 ignore 的数组
  16291. */
  16292. updateDisplayList: function (includeIgnore) {
  16293. this._displayListLen = 0;
  16294. var roots = this._roots;
  16295. var displayList = this._displayList;
  16296. for (var i = 0, len = roots.length; i < len; i++) {
  16297. this._updateAndAddDisplayable(roots[i], null, includeIgnore);
  16298. }
  16299. displayList.length = this._displayListLen;
  16300. // for (var i = 0, len = displayList.length; i < len; i++) {
  16301. // displayList[i].__renderidx = i;
  16302. // }
  16303. // displayList.sort(shapeCompareFunc);
  16304. env.canvasSupported && timsort(displayList, shapeCompareFunc);
  16305. },
  16306. _updateAndAddDisplayable: function (el, clipPaths, includeIgnore) {
  16307. if (el.ignore && !includeIgnore) {
  16308. return;
  16309. }
  16310. el.beforeUpdate();
  16311. if (el.__dirty) {
  16312. el.update();
  16313. }
  16314. el.afterUpdate();
  16315. var userSetClipPath = el.clipPath;
  16316. if (userSetClipPath) {
  16317. // FIXME 效率影响
  16318. if (clipPaths) {
  16319. clipPaths = clipPaths.slice();
  16320. }
  16321. else {
  16322. clipPaths = [];
  16323. }
  16324. var currentClipPath = userSetClipPath;
  16325. var parentClipPath = el;
  16326. // Recursively add clip path
  16327. while (currentClipPath) {
  16328. // clipPath 的变换是基于使用这个 clipPath 的元素
  16329. currentClipPath.parent = parentClipPath;
  16330. currentClipPath.updateTransform();
  16331. clipPaths.push(currentClipPath);
  16332. parentClipPath = currentClipPath;
  16333. currentClipPath = currentClipPath.clipPath;
  16334. }
  16335. }
  16336. if (el.isGroup) {
  16337. var children = el._children;
  16338. for (var i = 0; i < children.length; i++) {
  16339. var child = children[i];
  16340. // Force to mark as dirty if group is dirty
  16341. // FIXME __dirtyPath ?
  16342. if (el.__dirty) {
  16343. child.__dirty = true;
  16344. }
  16345. this._updateAndAddDisplayable(child, clipPaths, includeIgnore);
  16346. }
  16347. // Mark group clean here
  16348. el.__dirty = false;
  16349. }
  16350. else {
  16351. el.__clipPaths = clipPaths;
  16352. this._displayList[this._displayListLen++] = el;
  16353. }
  16354. },
  16355. /**
  16356. * 添加图形(Shape)或者组(Group)到根节点
  16357. * @param {module:zrender/Element} el
  16358. */
  16359. addRoot: function (el) {
  16360. if (el.__storage === this) {
  16361. return;
  16362. }
  16363. if (el instanceof Group) {
  16364. el.addChildrenToStorage(this);
  16365. }
  16366. this.addToStorage(el);
  16367. this._roots.push(el);
  16368. },
  16369. /**
  16370. * 删除指定的图形(Shape)或者组(Group)
  16371. * @param {string|Array.<string>} [el] 如果为空清空整个Storage
  16372. */
  16373. delRoot: function (el) {
  16374. if (el == null) {
  16375. // 不指定el清空
  16376. for (var i = 0; i < this._roots.length; i++) {
  16377. var root = this._roots[i];
  16378. if (root instanceof Group) {
  16379. root.delChildrenFromStorage(this);
  16380. }
  16381. }
  16382. this._roots = [];
  16383. this._displayList = [];
  16384. this._displayListLen = 0;
  16385. return;
  16386. }
  16387. if (el instanceof Array) {
  16388. for (var i = 0, l = el.length; i < l; i++) {
  16389. this.delRoot(el[i]);
  16390. }
  16391. return;
  16392. }
  16393. var idx = util.indexOf(this._roots, el);
  16394. if (idx >= 0) {
  16395. this.delFromStorage(el);
  16396. this._roots.splice(idx, 1);
  16397. if (el instanceof Group) {
  16398. el.delChildrenFromStorage(this);
  16399. }
  16400. }
  16401. },
  16402. addToStorage: function (el) {
  16403. el.__storage = this;
  16404. el.dirty(false);
  16405. return this;
  16406. },
  16407. delFromStorage: function (el) {
  16408. if (el) {
  16409. el.__storage = null;
  16410. }
  16411. return this;
  16412. },
  16413. /**
  16414. * 清空并且释放Storage
  16415. */
  16416. dispose: function () {
  16417. this._renderList =
  16418. this._roots = null;
  16419. },
  16420. displayableSortFunc: shapeCompareFunc
  16421. };
  16422. module.exports = Storage;
  16423. /***/ },
  16424. /* 86 */
  16425. /***/ function(module, exports) {
  16426. // https://github.com/mziccard/node-timsort
  16427. var DEFAULT_MIN_MERGE = 32;
  16428. var DEFAULT_MIN_GALLOPING = 7;
  16429. var DEFAULT_TMP_STORAGE_LENGTH = 256;
  16430. function minRunLength(n) {
  16431. var r = 0;
  16432. while (n >= DEFAULT_MIN_MERGE) {
  16433. r |= n & 1;
  16434. n >>= 1;
  16435. }
  16436. return n + r;
  16437. }
  16438. function makeAscendingRun(array, lo, hi, compare) {
  16439. var runHi = lo + 1;
  16440. if (runHi === hi) {
  16441. return 1;
  16442. }
  16443. if (compare(array[runHi++], array[lo]) < 0) {
  16444. while (runHi < hi && compare(array[runHi], array[runHi - 1]) < 0) {
  16445. runHi++;
  16446. }
  16447. reverseRun(array, lo, runHi);
  16448. }
  16449. else {
  16450. while (runHi < hi && compare(array[runHi], array[runHi - 1]) >= 0) {
  16451. runHi++;
  16452. }
  16453. }
  16454. return runHi - lo;
  16455. }
  16456. function reverseRun(array, lo, hi) {
  16457. hi--;
  16458. while (lo < hi) {
  16459. var t = array[lo];
  16460. array[lo++] = array[hi];
  16461. array[hi--] = t;
  16462. }
  16463. }
  16464. function binaryInsertionSort(array, lo, hi, start, compare) {
  16465. if (start === lo) {
  16466. start++;
  16467. }
  16468. for (; start < hi; start++) {
  16469. var pivot = array[start];
  16470. var left = lo;
  16471. var right = start;
  16472. var mid;
  16473. while (left < right) {
  16474. mid = left + right >>> 1;
  16475. if (compare(pivot, array[mid]) < 0) {
  16476. right = mid;
  16477. }
  16478. else {
  16479. left = mid + 1;
  16480. }
  16481. }
  16482. var n = start - left;
  16483. switch (n) {
  16484. case 3:
  16485. array[left + 3] = array[left + 2];
  16486. case 2:
  16487. array[left + 2] = array[left + 1];
  16488. case 1:
  16489. array[left + 1] = array[left];
  16490. break;
  16491. default:
  16492. while (n > 0) {
  16493. array[left + n] = array[left + n - 1];
  16494. n--;
  16495. }
  16496. }
  16497. array[left] = pivot;
  16498. }
  16499. }
  16500. function gallopLeft(value, array, start, length, hint, compare) {
  16501. var lastOffset = 0;
  16502. var maxOffset = 0;
  16503. var offset = 1;
  16504. if (compare(value, array[start + hint]) > 0) {
  16505. maxOffset = length - hint;
  16506. while (offset < maxOffset && compare(value, array[start + hint + offset]) > 0) {
  16507. lastOffset = offset;
  16508. offset = (offset << 1) + 1;
  16509. if (offset <= 0) {
  16510. offset = maxOffset;
  16511. }
  16512. }
  16513. if (offset > maxOffset) {
  16514. offset = maxOffset;
  16515. }
  16516. lastOffset += hint;
  16517. offset += hint;
  16518. }
  16519. else {
  16520. maxOffset = hint + 1;
  16521. while (offset < maxOffset && compare(value, array[start + hint - offset]) <= 0) {
  16522. lastOffset = offset;
  16523. offset = (offset << 1) + 1;
  16524. if (offset <= 0) {
  16525. offset = maxOffset;
  16526. }
  16527. }
  16528. if (offset > maxOffset) {
  16529. offset = maxOffset;
  16530. }
  16531. var tmp = lastOffset;
  16532. lastOffset = hint - offset;
  16533. offset = hint - tmp;
  16534. }
  16535. lastOffset++;
  16536. while (lastOffset < offset) {
  16537. var m = lastOffset + (offset - lastOffset >>> 1);
  16538. if (compare(value, array[start + m]) > 0) {
  16539. lastOffset = m + 1;
  16540. }
  16541. else {
  16542. offset = m;
  16543. }
  16544. }
  16545. return offset;
  16546. }
  16547. function gallopRight(value, array, start, length, hint, compare) {
  16548. var lastOffset = 0;
  16549. var maxOffset = 0;
  16550. var offset = 1;
  16551. if (compare(value, array[start + hint]) < 0) {
  16552. maxOffset = hint + 1;
  16553. while (offset < maxOffset && compare(value, array[start + hint - offset]) < 0) {
  16554. lastOffset = offset;
  16555. offset = (offset << 1) + 1;
  16556. if (offset <= 0) {
  16557. offset = maxOffset;
  16558. }
  16559. }
  16560. if (offset > maxOffset) {
  16561. offset = maxOffset;
  16562. }
  16563. var tmp = lastOffset;
  16564. lastOffset = hint - offset;
  16565. offset = hint - tmp;
  16566. }
  16567. else {
  16568. maxOffset = length - hint;
  16569. while (offset < maxOffset && compare(value, array[start + hint + offset]) >= 0) {
  16570. lastOffset = offset;
  16571. offset = (offset << 1) + 1;
  16572. if (offset <= 0) {
  16573. offset = maxOffset;
  16574. }
  16575. }
  16576. if (offset > maxOffset) {
  16577. offset = maxOffset;
  16578. }
  16579. lastOffset += hint;
  16580. offset += hint;
  16581. }
  16582. lastOffset++;
  16583. while (lastOffset < offset) {
  16584. var m = lastOffset + (offset - lastOffset >>> 1);
  16585. if (compare(value, array[start + m]) < 0) {
  16586. offset = m;
  16587. }
  16588. else {
  16589. lastOffset = m + 1;
  16590. }
  16591. }
  16592. return offset;
  16593. }
  16594. function TimSort(array, compare) {
  16595. var minGallop = DEFAULT_MIN_GALLOPING;
  16596. var length = 0;
  16597. var tmpStorageLength = DEFAULT_TMP_STORAGE_LENGTH;
  16598. var stackLength = 0;
  16599. var runStart;
  16600. var runLength;
  16601. var stackSize = 0;
  16602. length = array.length;
  16603. if (length < 2 * DEFAULT_TMP_STORAGE_LENGTH) {
  16604. tmpStorageLength = length >>> 1;
  16605. }
  16606. var tmp = [];
  16607. stackLength = length < 120 ? 5 : length < 1542 ? 10 : length < 119151 ? 19 : 40;
  16608. runStart = [];
  16609. runLength = [];
  16610. function pushRun(_runStart, _runLength) {
  16611. runStart[stackSize] = _runStart;
  16612. runLength[stackSize] = _runLength;
  16613. stackSize += 1;
  16614. }
  16615. function mergeRuns() {
  16616. while (stackSize > 1) {
  16617. var n = stackSize - 2;
  16618. if (n >= 1 && runLength[n - 1] <= runLength[n] + runLength[n + 1] || n >= 2 && runLength[n - 2] <= runLength[n] + runLength[n - 1]) {
  16619. if (runLength[n - 1] < runLength[n + 1]) {
  16620. n--;
  16621. }
  16622. }
  16623. else if (runLength[n] > runLength[n + 1]) {
  16624. break;
  16625. }
  16626. mergeAt(n);
  16627. }
  16628. }
  16629. function forceMergeRuns() {
  16630. while (stackSize > 1) {
  16631. var n = stackSize - 2;
  16632. if (n > 0 && runLength[n - 1] < runLength[n + 1]) {
  16633. n--;
  16634. }
  16635. mergeAt(n);
  16636. }
  16637. }
  16638. function mergeAt(i) {
  16639. var start1 = runStart[i];
  16640. var length1 = runLength[i];
  16641. var start2 = runStart[i + 1];
  16642. var length2 = runLength[i + 1];
  16643. runLength[i] = length1 + length2;
  16644. if (i === stackSize - 3) {
  16645. runStart[i + 1] = runStart[i + 2];
  16646. runLength[i + 1] = runLength[i + 2];
  16647. }
  16648. stackSize--;
  16649. var k = gallopRight(array[start2], array, start1, length1, 0, compare);
  16650. start1 += k;
  16651. length1 -= k;
  16652. if (length1 === 0) {
  16653. return;
  16654. }
  16655. length2 = gallopLeft(array[start1 + length1 - 1], array, start2, length2, length2 - 1, compare);
  16656. if (length2 === 0) {
  16657. return;
  16658. }
  16659. if (length1 <= length2) {
  16660. mergeLow(start1, length1, start2, length2);
  16661. }
  16662. else {
  16663. mergeHigh(start1, length1, start2, length2);
  16664. }
  16665. }
  16666. function mergeLow(start1, length1, start2, length2) {
  16667. var i = 0;
  16668. for (i = 0; i < length1; i++) {
  16669. tmp[i] = array[start1 + i];
  16670. }
  16671. var cursor1 = 0;
  16672. var cursor2 = start2;
  16673. var dest = start1;
  16674. array[dest++] = array[cursor2++];
  16675. if (--length2 === 0) {
  16676. for (i = 0; i < length1; i++) {
  16677. array[dest + i] = tmp[cursor1 + i];
  16678. }
  16679. return;
  16680. }
  16681. if (length1 === 1) {
  16682. for (i = 0; i < length2; i++) {
  16683. array[dest + i] = array[cursor2 + i];
  16684. }
  16685. array[dest + length2] = tmp[cursor1];
  16686. return;
  16687. }
  16688. var _minGallop = minGallop;
  16689. var count1, count2, exit;
  16690. while (1) {
  16691. count1 = 0;
  16692. count2 = 0;
  16693. exit = false;
  16694. do {
  16695. if (compare(array[cursor2], tmp[cursor1]) < 0) {
  16696. array[dest++] = array[cursor2++];
  16697. count2++;
  16698. count1 = 0;
  16699. if (--length2 === 0) {
  16700. exit = true;
  16701. break;
  16702. }
  16703. }
  16704. else {
  16705. array[dest++] = tmp[cursor1++];
  16706. count1++;
  16707. count2 = 0;
  16708. if (--length1 === 1) {
  16709. exit = true;
  16710. break;
  16711. }
  16712. }
  16713. } while ((count1 | count2) < _minGallop);
  16714. if (exit) {
  16715. break;
  16716. }
  16717. do {
  16718. count1 = gallopRight(array[cursor2], tmp, cursor1, length1, 0, compare);
  16719. if (count1 !== 0) {
  16720. for (i = 0; i < count1; i++) {
  16721. array[dest + i] = tmp[cursor1 + i];
  16722. }
  16723. dest += count1;
  16724. cursor1 += count1;
  16725. length1 -= count1;
  16726. if (length1 <= 1) {
  16727. exit = true;
  16728. break;
  16729. }
  16730. }
  16731. array[dest++] = array[cursor2++];
  16732. if (--length2 === 0) {
  16733. exit = true;
  16734. break;
  16735. }
  16736. count2 = gallopLeft(tmp[cursor1], array, cursor2, length2, 0, compare);
  16737. if (count2 !== 0) {
  16738. for (i = 0; i < count2; i++) {
  16739. array[dest + i] = array[cursor2 + i];
  16740. }
  16741. dest += count2;
  16742. cursor2 += count2;
  16743. length2 -= count2;
  16744. if (length2 === 0) {
  16745. exit = true;
  16746. break;
  16747. }
  16748. }
  16749. array[dest++] = tmp[cursor1++];
  16750. if (--length1 === 1) {
  16751. exit = true;
  16752. break;
  16753. }
  16754. _minGallop--;
  16755. } while (count1 >= DEFAULT_MIN_GALLOPING || count2 >= DEFAULT_MIN_GALLOPING);
  16756. if (exit) {
  16757. break;
  16758. }
  16759. if (_minGallop < 0) {
  16760. _minGallop = 0;
  16761. }
  16762. _minGallop += 2;
  16763. }
  16764. minGallop = _minGallop;
  16765. minGallop < 1 && (minGallop = 1);
  16766. if (length1 === 1) {
  16767. for (i = 0; i < length2; i++) {
  16768. array[dest + i] = array[cursor2 + i];
  16769. }
  16770. array[dest + length2] = tmp[cursor1];
  16771. }
  16772. else if (length1 === 0) {
  16773. throw new Error();
  16774. // throw new Error('mergeLow preconditions were not respected');
  16775. }
  16776. else {
  16777. for (i = 0; i < length1; i++) {
  16778. array[dest + i] = tmp[cursor1 + i];
  16779. }
  16780. }
  16781. }
  16782. function mergeHigh (start1, length1, start2, length2) {
  16783. var i = 0;
  16784. for (i = 0; i < length2; i++) {
  16785. tmp[i] = array[start2 + i];
  16786. }
  16787. var cursor1 = start1 + length1 - 1;
  16788. var cursor2 = length2 - 1;
  16789. var dest = start2 + length2 - 1;
  16790. var customCursor = 0;
  16791. var customDest = 0;
  16792. array[dest--] = array[cursor1--];
  16793. if (--length1 === 0) {
  16794. customCursor = dest - (length2 - 1);
  16795. for (i = 0; i < length2; i++) {
  16796. array[customCursor + i] = tmp[i];
  16797. }
  16798. return;
  16799. }
  16800. if (length2 === 1) {
  16801. dest -= length1;
  16802. cursor1 -= length1;
  16803. customDest = dest + 1;
  16804. customCursor = cursor1 + 1;
  16805. for (i = length1 - 1; i >= 0; i--) {
  16806. array[customDest + i] = array[customCursor + i];
  16807. }
  16808. array[dest] = tmp[cursor2];
  16809. return;
  16810. }
  16811. var _minGallop = minGallop;
  16812. while (true) {
  16813. var count1 = 0;
  16814. var count2 = 0;
  16815. var exit = false;
  16816. do {
  16817. if (compare(tmp[cursor2], array[cursor1]) < 0) {
  16818. array[dest--] = array[cursor1--];
  16819. count1++;
  16820. count2 = 0;
  16821. if (--length1 === 0) {
  16822. exit = true;
  16823. break;
  16824. }
  16825. }
  16826. else {
  16827. array[dest--] = tmp[cursor2--];
  16828. count2++;
  16829. count1 = 0;
  16830. if (--length2 === 1) {
  16831. exit = true;
  16832. break;
  16833. }
  16834. }
  16835. } while ((count1 | count2) < _minGallop);
  16836. if (exit) {
  16837. break;
  16838. }
  16839. do {
  16840. count1 = length1 - gallopRight(tmp[cursor2], array, start1, length1, length1 - 1, compare);
  16841. if (count1 !== 0) {
  16842. dest -= count1;
  16843. cursor1 -= count1;
  16844. length1 -= count1;
  16845. customDest = dest + 1;
  16846. customCursor = cursor1 + 1;
  16847. for (i = count1 - 1; i >= 0; i--) {
  16848. array[customDest + i] = array[customCursor + i];
  16849. }
  16850. if (length1 === 0) {
  16851. exit = true;
  16852. break;
  16853. }
  16854. }
  16855. array[dest--] = tmp[cursor2--];
  16856. if (--length2 === 1) {
  16857. exit = true;
  16858. break;
  16859. }
  16860. count2 = length2 - gallopLeft(array[cursor1], tmp, 0, length2, length2 - 1, compare);
  16861. if (count2 !== 0) {
  16862. dest -= count2;
  16863. cursor2 -= count2;
  16864. length2 -= count2;
  16865. customDest = dest + 1;
  16866. customCursor = cursor2 + 1;
  16867. for (i = 0; i < count2; i++) {
  16868. array[customDest + i] = tmp[customCursor + i];
  16869. }
  16870. if (length2 <= 1) {
  16871. exit = true;
  16872. break;
  16873. }
  16874. }
  16875. array[dest--] = array[cursor1--];
  16876. if (--length1 === 0) {
  16877. exit = true;
  16878. break;
  16879. }
  16880. _minGallop--;
  16881. } while (count1 >= DEFAULT_MIN_GALLOPING || count2 >= DEFAULT_MIN_GALLOPING);
  16882. if (exit) {
  16883. break;
  16884. }
  16885. if (_minGallop < 0) {
  16886. _minGallop = 0;
  16887. }
  16888. _minGallop += 2;
  16889. }
  16890. minGallop = _minGallop;
  16891. if (minGallop < 1) {
  16892. minGallop = 1;
  16893. }
  16894. if (length2 === 1) {
  16895. dest -= length1;
  16896. cursor1 -= length1;
  16897. customDest = dest + 1;
  16898. customCursor = cursor1 + 1;
  16899. for (i = length1 - 1; i >= 0; i--) {
  16900. array[customDest + i] = array[customCursor + i];
  16901. }
  16902. array[dest] = tmp[cursor2];
  16903. }
  16904. else if (length2 === 0) {
  16905. throw new Error();
  16906. // throw new Error('mergeHigh preconditions were not respected');
  16907. }
  16908. else {
  16909. customCursor = dest - (length2 - 1);
  16910. for (i = 0; i < length2; i++) {
  16911. array[customCursor + i] = tmp[i];
  16912. }
  16913. }
  16914. }
  16915. this.mergeRuns = mergeRuns;
  16916. this.forceMergeRuns = forceMergeRuns;
  16917. this.pushRun = pushRun;
  16918. }
  16919. function sort(array, compare, lo, hi) {
  16920. if (!lo) {
  16921. lo = 0;
  16922. }
  16923. if (!hi) {
  16924. hi = array.length;
  16925. }
  16926. var remaining = hi - lo;
  16927. if (remaining < 2) {
  16928. return;
  16929. }
  16930. var runLength = 0;
  16931. if (remaining < DEFAULT_MIN_MERGE) {
  16932. runLength = makeAscendingRun(array, lo, hi, compare);
  16933. binaryInsertionSort(array, lo, hi, lo + runLength, compare);
  16934. return;
  16935. }
  16936. var ts = new TimSort(array, compare);
  16937. var minRun = minRunLength(remaining);
  16938. do {
  16939. runLength = makeAscendingRun(array, lo, hi, compare);
  16940. if (runLength < minRun) {
  16941. var force = remaining;
  16942. if (force > minRun) {
  16943. force = minRun;
  16944. }
  16945. binaryInsertionSort(array, lo, lo + force, lo + runLength, compare);
  16946. runLength = force;
  16947. }
  16948. ts.pushRun(lo, runLength);
  16949. ts.mergeRuns();
  16950. remaining -= runLength;
  16951. lo += runLength;
  16952. } while (remaining !== 0);
  16953. ts.forceMergeRuns();
  16954. }
  16955. module.exports = sort;
  16956. /***/ },
  16957. /* 87 */
  16958. /***/ function(module, exports, __webpack_require__) {
  16959. 'use strict';
  16960. /**
  16961. * 动画主类, 调度和管理所有动画控制器
  16962. *
  16963. * @module zrender/animation/Animation
  16964. * @author pissang(https://github.com/pissang)
  16965. */
  16966. // TODO Additive animation
  16967. // http://iosoteric.com/additive-animations-animatewithduration-in-ios-8/
  16968. // https://developer.apple.com/videos/wwdc2014/#236
  16969. var util = __webpack_require__(4);
  16970. var Dispatcher = __webpack_require__(88).Dispatcher;
  16971. var requestAnimationFrame = __webpack_require__(89);
  16972. var Animator = __webpack_require__(28);
  16973. /**
  16974. * @typedef {Object} IZRenderStage
  16975. * @property {Function} update
  16976. */
  16977. /**
  16978. * @alias module:zrender/animation/Animation
  16979. * @constructor
  16980. * @param {Object} [options]
  16981. * @param {Function} [options.onframe]
  16982. * @param {IZRenderStage} [options.stage]
  16983. * @example
  16984. * var animation = new Animation();
  16985. * var obj = {
  16986. * x: 100,
  16987. * y: 100
  16988. * };
  16989. * animation.animate(node.position)
  16990. * .when(1000, {
  16991. * x: 500,
  16992. * y: 500
  16993. * })
  16994. * .when(2000, {
  16995. * x: 100,
  16996. * y: 100
  16997. * })
  16998. * .start('spline');
  16999. */
  17000. var Animation = function (options) {
  17001. options = options || {};
  17002. this.stage = options.stage || {};
  17003. this.onframe = options.onframe || function() {};
  17004. // private properties
  17005. this._clips = [];
  17006. this._running = false;
  17007. this._time;
  17008. this._pausedTime;
  17009. this._pauseStart;
  17010. this._paused = false;
  17011. Dispatcher.call(this);
  17012. };
  17013. Animation.prototype = {
  17014. constructor: Animation,
  17015. /**
  17016. * 添加 clip
  17017. * @param {module:zrender/animation/Clip} clip
  17018. */
  17019. addClip: function (clip) {
  17020. this._clips.push(clip);
  17021. },
  17022. /**
  17023. * 添加 animator
  17024. * @param {module:zrender/animation/Animator} animator
  17025. */
  17026. addAnimator: function (animator) {
  17027. animator.animation = this;
  17028. var clips = animator.getClips();
  17029. for (var i = 0; i < clips.length; i++) {
  17030. this.addClip(clips[i]);
  17031. }
  17032. },
  17033. /**
  17034. * 删除动画片段
  17035. * @param {module:zrender/animation/Clip} clip
  17036. */
  17037. removeClip: function(clip) {
  17038. var idx = util.indexOf(this._clips, clip);
  17039. if (idx >= 0) {
  17040. this._clips.splice(idx, 1);
  17041. }
  17042. },
  17043. /**
  17044. * 删除动画片段
  17045. * @param {module:zrender/animation/Animator} animator
  17046. */
  17047. removeAnimator: function (animator) {
  17048. var clips = animator.getClips();
  17049. for (var i = 0; i < clips.length; i++) {
  17050. this.removeClip(clips[i]);
  17051. }
  17052. animator.animation = null;
  17053. },
  17054. _update: function() {
  17055. var time = new Date().getTime() - this._pausedTime;
  17056. var delta = time - this._time;
  17057. var clips = this._clips;
  17058. var len = clips.length;
  17059. var deferredEvents = [];
  17060. var deferredClips = [];
  17061. for (var i = 0; i < len; i++) {
  17062. var clip = clips[i];
  17063. var e = clip.step(time, delta);
  17064. // Throw out the events need to be called after
  17065. // stage.update, like destroy
  17066. if (e) {
  17067. deferredEvents.push(e);
  17068. deferredClips.push(clip);
  17069. }
  17070. }
  17071. // Remove the finished clip
  17072. for (var i = 0; i < len;) {
  17073. if (clips[i]._needsRemove) {
  17074. clips[i] = clips[len - 1];
  17075. clips.pop();
  17076. len--;
  17077. }
  17078. else {
  17079. i++;
  17080. }
  17081. }
  17082. len = deferredEvents.length;
  17083. for (var i = 0; i < len; i++) {
  17084. deferredClips[i].fire(deferredEvents[i]);
  17085. }
  17086. this._time = time;
  17087. this.onframe(delta);
  17088. this.trigger('frame', delta);
  17089. if (this.stage.update) {
  17090. this.stage.update();
  17091. }
  17092. },
  17093. _startLoop: function () {
  17094. var self = this;
  17095. this._running = true;
  17096. function step() {
  17097. if (self._running) {
  17098. requestAnimationFrame(step);
  17099. !self._paused && self._update();
  17100. }
  17101. }
  17102. requestAnimationFrame(step);
  17103. },
  17104. /**
  17105. * 开始运行动画
  17106. */
  17107. start: function () {
  17108. this._time = new Date().getTime();
  17109. this._pausedTime = 0;
  17110. this._startLoop();
  17111. },
  17112. /**
  17113. * 停止运行动画
  17114. */
  17115. stop: function () {
  17116. this._running = false;
  17117. },
  17118. /**
  17119. * Pause
  17120. */
  17121. pause: function () {
  17122. if (!this._paused) {
  17123. this._pauseStart = new Date().getTime();
  17124. this._paused = true;
  17125. }
  17126. },
  17127. /**
  17128. * Resume
  17129. */
  17130. resume: function () {
  17131. if (this._paused) {
  17132. this._pausedTime += (new Date().getTime()) - this._pauseStart;
  17133. this._paused = false;
  17134. }
  17135. },
  17136. /**
  17137. * 清除所有动画片段
  17138. */
  17139. clear: function () {
  17140. this._clips = [];
  17141. },
  17142. /**
  17143. * 对一个目标创建一个animator对象,可以指定目标中的属性使用动画
  17144. * @param {Object} target
  17145. * @param {Object} options
  17146. * @param {boolean} [options.loop=false] 是否循环播放动画
  17147. * @param {Function} [options.getter=null]
  17148. * 如果指定getter函数,会通过getter函数取属性值
  17149. * @param {Function} [options.setter=null]
  17150. * 如果指定setter函数,会通过setter函数设置属性值
  17151. * @return {module:zrender/animation/Animation~Animator}
  17152. */
  17153. // TODO Gap
  17154. animate: function (target, options) {
  17155. options = options || {};
  17156. var animator = new Animator(
  17157. target,
  17158. options.loop,
  17159. options.getter,
  17160. options.setter
  17161. );
  17162. this.addAnimator(animator);
  17163. return animator;
  17164. }
  17165. };
  17166. util.mixin(Animation, Dispatcher);
  17167. module.exports = Animation;
  17168. /***/ },
  17169. /* 88 */
  17170. /***/ function(module, exports, __webpack_require__) {
  17171. 'use strict';
  17172. /**
  17173. * 事件辅助类
  17174. * @module zrender/core/event
  17175. * @author Kener (@Kener-林峰, kener.linfeng@gmail.com)
  17176. */
  17177. var Eventful = __webpack_require__(25);
  17178. var env = __webpack_require__(2);
  17179. var isDomLevel2 = (typeof window !== 'undefined') && !!window.addEventListener;
  17180. function getBoundingClientRect(el) {
  17181. // BlackBerry 5, iOS 3 (original iPhone) don't have getBoundingRect
  17182. return el.getBoundingClientRect ? el.getBoundingClientRect() : {left: 0, top: 0};
  17183. }
  17184. // `calculate` is optional, default false
  17185. function clientToLocal(el, e, out, calculate) {
  17186. out = out || {};
  17187. // According to the W3C Working Draft, offsetX and offsetY should be relative
  17188. // to the padding edge of the target element. The only browser using this convention
  17189. // is IE. Webkit uses the border edge, Opera uses the content edge, and FireFox does
  17190. // not support the properties.
  17191. // (see http://www.jacklmoore.com/notes/mouse-position/)
  17192. // In zr painter.dom, padding edge equals to border edge.
  17193. // FIXME
  17194. // When mousemove event triggered on ec tooltip, target is not zr painter.dom, and
  17195. // offsetX/Y is relative to e.target, where the calculation of zrX/Y via offsetX/Y
  17196. // is too complex. So css-transfrom dont support in this case temporarily.
  17197. if (calculate || !env.canvasSupported) {
  17198. defaultGetZrXY(el, e, out);
  17199. }
  17200. // Caution: In FireFox, layerX/layerY Mouse position relative to the closest positioned
  17201. // ancestor element, so we should make sure el is positioned (e.g., not position:static).
  17202. // BTW1, Webkit don't return the same results as FF in non-simple cases (like add
  17203. // zoom-factor, overflow / opacity layers, transforms ...)
  17204. // BTW2, (ev.offsetY || ev.pageY - $(ev.target).offset().top) is not correct in preserve-3d.
  17205. // <https://bugs.jquery.com/ticket/8523#comment:14>
  17206. // BTW3, In ff, offsetX/offsetY is always 0.
  17207. else if (env.browser.firefox && e.layerX != null && e.layerX !== e.offsetX) {
  17208. out.zrX = e.layerX;
  17209. out.zrY = e.layerY;
  17210. }
  17211. // For IE6+, chrome, safari, opera. (When will ff support offsetX?)
  17212. else if (e.offsetX != null) {
  17213. out.zrX = e.offsetX;
  17214. out.zrY = e.offsetY;
  17215. }
  17216. // For some other device, e.g., IOS safari.
  17217. else {
  17218. defaultGetZrXY(el, e, out);
  17219. }
  17220. return out;
  17221. }
  17222. function defaultGetZrXY(el, e, out) {
  17223. // This well-known method below does not support css transform.
  17224. var box = getBoundingClientRect(el);
  17225. out.zrX = e.clientX - box.left;
  17226. out.zrY = e.clientY - box.top;
  17227. }
  17228. /**
  17229. * 如果存在第三方嵌入的一些dom触发的事件,或touch事件,需要转换一下事件坐标.
  17230. * `calculate` is optional, default false.
  17231. */
  17232. function normalizeEvent(el, e, calculate) {
  17233. e = e || window.event;
  17234. if (e.zrX != null) {
  17235. return e;
  17236. }
  17237. var eventType = e.type;
  17238. var isTouch = eventType && eventType.indexOf('touch') >= 0;
  17239. if (!isTouch) {
  17240. clientToLocal(el, e, e, calculate);
  17241. e.zrDelta = (e.wheelDelta) ? e.wheelDelta / 120 : -(e.detail || 0) / 3;
  17242. }
  17243. else {
  17244. var touch = eventType != 'touchend'
  17245. ? e.targetTouches[0]
  17246. : e.changedTouches[0];
  17247. touch && clientToLocal(el, touch, e, calculate);
  17248. }
  17249. return e;
  17250. }
  17251. function addEventListener(el, name, handler) {
  17252. if (isDomLevel2) {
  17253. el.addEventListener(name, handler);
  17254. }
  17255. else {
  17256. el.attachEvent('on' + name, handler);
  17257. }
  17258. }
  17259. function removeEventListener(el, name, handler) {
  17260. if (isDomLevel2) {
  17261. el.removeEventListener(name, handler);
  17262. }
  17263. else {
  17264. el.detachEvent('on' + name, handler);
  17265. }
  17266. }
  17267. /**
  17268. * preventDefault and stopPropagation.
  17269. * Notice: do not do that in zrender. Upper application
  17270. * do that if necessary.
  17271. *
  17272. * @memberOf module:zrender/core/event
  17273. * @method
  17274. * @param {Event} e : event对象
  17275. */
  17276. var stop = isDomLevel2
  17277. ? function (e) {
  17278. e.preventDefault();
  17279. e.stopPropagation();
  17280. e.cancelBubble = true;
  17281. }
  17282. : function (e) {
  17283. e.returnValue = false;
  17284. e.cancelBubble = true;
  17285. };
  17286. module.exports = {
  17287. clientToLocal: clientToLocal,
  17288. normalizeEvent: normalizeEvent,
  17289. addEventListener: addEventListener,
  17290. removeEventListener: removeEventListener,
  17291. stop: stop,
  17292. // 做向上兼容
  17293. Dispatcher: Eventful
  17294. };
  17295. /***/ },
  17296. /* 89 */
  17297. /***/ function(module, exports) {
  17298. module.exports = (typeof window !== 'undefined' &&
  17299. ((window.requestAnimationFrame && window.requestAnimationFrame.bind(window))
  17300. // https://github.com/ecomfe/zrender/issues/189#issuecomment-224919809
  17301. || (window.msRequestAnimationFrame && window.msRequestAnimationFrame.bind(window))
  17302. || window.mozRequestAnimationFrame
  17303. || window.webkitRequestAnimationFrame)
  17304. )
  17305. || function (func) {
  17306. setTimeout(func, 16);
  17307. };
  17308. /***/ },
  17309. /* 90 */
  17310. /***/ function(module, exports, __webpack_require__) {
  17311. var eventTool = __webpack_require__(88);
  17312. var zrUtil = __webpack_require__(4);
  17313. var Eventful = __webpack_require__(25);
  17314. var env = __webpack_require__(2);
  17315. var GestureMgr = __webpack_require__(91);
  17316. var addEventListener = eventTool.addEventListener;
  17317. var removeEventListener = eventTool.removeEventListener;
  17318. var normalizeEvent = eventTool.normalizeEvent;
  17319. var TOUCH_CLICK_DELAY = 300;
  17320. var mouseHandlerNames = [
  17321. 'click', 'dblclick', 'mousewheel', 'mouseout',
  17322. 'mouseup', 'mousedown', 'mousemove', 'contextmenu'
  17323. ];
  17324. var touchHandlerNames = [
  17325. 'touchstart', 'touchend', 'touchmove'
  17326. ];
  17327. var pointerEventNames = {
  17328. pointerdown: 1, pointerup: 1, pointermove: 1, pointerout: 1
  17329. };
  17330. var pointerHandlerNames = zrUtil.map(mouseHandlerNames, function (name) {
  17331. var nm = name.replace('mouse', 'pointer');
  17332. return pointerEventNames[nm] ? nm : name;
  17333. });
  17334. function eventNameFix(name) {
  17335. return (name === 'mousewheel' && env.browser.firefox) ? 'DOMMouseScroll' : name;
  17336. }
  17337. function processGesture(proxy, event, stage) {
  17338. var gestureMgr = proxy._gestureMgr;
  17339. stage === 'start' && gestureMgr.clear();
  17340. var gestureInfo = gestureMgr.recognize(
  17341. event,
  17342. proxy.handler.findHover(event.zrX, event.zrY, null).target,
  17343. proxy.dom
  17344. );
  17345. stage === 'end' && gestureMgr.clear();
  17346. // Do not do any preventDefault here. Upper application do that if necessary.
  17347. if (gestureInfo) {
  17348. var type = gestureInfo.type;
  17349. event.gestureEvent = type;
  17350. proxy.handler.dispatchToElement({target: gestureInfo.target}, type, gestureInfo.event);
  17351. }
  17352. }
  17353. // function onMSGestureChange(proxy, event) {
  17354. // if (event.translationX || event.translationY) {
  17355. // // mousemove is carried by MSGesture to reduce the sensitivity.
  17356. // proxy.handler.dispatchToElement(event.target, 'mousemove', event);
  17357. // }
  17358. // if (event.scale !== 1) {
  17359. // event.pinchX = event.offsetX;
  17360. // event.pinchY = event.offsetY;
  17361. // event.pinchScale = event.scale;
  17362. // proxy.handler.dispatchToElement(event.target, 'pinch', event);
  17363. // }
  17364. // }
  17365. /**
  17366. * Prevent mouse event from being dispatched after Touch Events action
  17367. * @see <https://github.com/deltakosh/handjs/blob/master/src/hand.base.js>
  17368. * 1. Mobile browsers dispatch mouse events 300ms after touchend.
  17369. * 2. Chrome for Android dispatch mousedown for long-touch about 650ms
  17370. * Result: Blocking Mouse Events for 700ms.
  17371. */
  17372. function setTouchTimer(instance) {
  17373. instance._touching = true;
  17374. clearTimeout(instance._touchTimer);
  17375. instance._touchTimer = setTimeout(function () {
  17376. instance._touching = false;
  17377. }, 700);
  17378. }
  17379. var domHandlers = {
  17380. /**
  17381. * Mouse move handler
  17382. * @inner
  17383. * @param {Event} event
  17384. */
  17385. mousemove: function (event) {
  17386. event = normalizeEvent(this.dom, event);
  17387. this.trigger('mousemove', event);
  17388. },
  17389. /**
  17390. * Mouse out handler
  17391. * @inner
  17392. * @param {Event} event
  17393. */
  17394. mouseout: function (event) {
  17395. event = normalizeEvent(this.dom, event);
  17396. var element = event.toElement || event.relatedTarget;
  17397. if (element != this.dom) {
  17398. while (element && element.nodeType != 9) {
  17399. // 忽略包含在root中的dom引起的mouseOut
  17400. if (element === this.dom) {
  17401. return;
  17402. }
  17403. element = element.parentNode;
  17404. }
  17405. }
  17406. this.trigger('mouseout', event);
  17407. },
  17408. /**
  17409. * Touch开始响应函数
  17410. * @inner
  17411. * @param {Event} event
  17412. */
  17413. touchstart: function (event) {
  17414. // Default mouse behaviour should not be disabled here.
  17415. // For example, page may needs to be slided.
  17416. event = normalizeEvent(this.dom, event);
  17417. // Mark touch, which is useful in distinguish touch and
  17418. // mouse event in upper applicatoin.
  17419. event.zrByTouch = true;
  17420. this._lastTouchMoment = new Date();
  17421. processGesture(this, event, 'start');
  17422. // In touch device, trigger `mousemove`(`mouseover`) should
  17423. // be triggered, and must before `mousedown` triggered.
  17424. domHandlers.mousemove.call(this, event);
  17425. domHandlers.mousedown.call(this, event);
  17426. setTouchTimer(this);
  17427. },
  17428. /**
  17429. * Touch移动响应函数
  17430. * @inner
  17431. * @param {Event} event
  17432. */
  17433. touchmove: function (event) {
  17434. event = normalizeEvent(this.dom, event);
  17435. // Mark touch, which is useful in distinguish touch and
  17436. // mouse event in upper applicatoin.
  17437. event.zrByTouch = true;
  17438. processGesture(this, event, 'change');
  17439. // Mouse move should always be triggered no matter whether
  17440. // there is gestrue event, because mouse move and pinch may
  17441. // be used at the same time.
  17442. domHandlers.mousemove.call(this, event);
  17443. setTouchTimer(this);
  17444. },
  17445. /**
  17446. * Touch结束响应函数
  17447. * @inner
  17448. * @param {Event} event
  17449. */
  17450. touchend: function (event) {
  17451. event = normalizeEvent(this.dom, event);
  17452. // Mark touch, which is useful in distinguish touch and
  17453. // mouse event in upper applicatoin.
  17454. event.zrByTouch = true;
  17455. processGesture(this, event, 'end');
  17456. domHandlers.mouseup.call(this, event);
  17457. // Do not trigger `mouseout` here, in spite of `mousemove`(`mouseover`) is
  17458. // triggered in `touchstart`. This seems to be illogical, but by this mechanism,
  17459. // we can conveniently implement "hover style" in both PC and touch device just
  17460. // by listening to `mouseover` to add "hover style" and listening to `mouseout`
  17461. // to remove "hover style" on an element, without any additional code for
  17462. // compatibility. (`mouseout` will not be triggered in `touchend`, so "hover
  17463. // style" will remain for user view)
  17464. // click event should always be triggered no matter whether
  17465. // there is gestrue event. System click can not be prevented.
  17466. if (+new Date() - this._lastTouchMoment < TOUCH_CLICK_DELAY) {
  17467. domHandlers.click.call(this, event);
  17468. }
  17469. setTouchTimer(this);
  17470. },
  17471. pointerdown: function (event) {
  17472. domHandlers.mousedown.call(this, event);
  17473. // if (useMSGuesture(this, event)) {
  17474. // this._msGesture.addPointer(event.pointerId);
  17475. // }
  17476. },
  17477. pointermove: function (event) {
  17478. // FIXME
  17479. // pointermove is so sensitive that it always triggered when
  17480. // tap(click) on touch screen, which affect some judgement in
  17481. // upper application. So, we dont support mousemove on MS touch
  17482. // device yet.
  17483. if (!isPointerFromTouch(event)) {
  17484. domHandlers.mousemove.call(this, event);
  17485. }
  17486. },
  17487. pointerup: function (event) {
  17488. domHandlers.mouseup.call(this, event);
  17489. },
  17490. pointerout: function (event) {
  17491. // pointerout will be triggered when tap on touch screen
  17492. // (IE11+/Edge on MS Surface) after click event triggered,
  17493. // which is inconsistent with the mousout behavior we defined
  17494. // in touchend. So we unify them.
  17495. // (check domHandlers.touchend for detailed explanation)
  17496. if (!isPointerFromTouch(event)) {
  17497. domHandlers.mouseout.call(this, event);
  17498. }
  17499. }
  17500. };
  17501. function isPointerFromTouch(event) {
  17502. var pointerType = event.pointerType;
  17503. return pointerType === 'pen' || pointerType === 'touch';
  17504. }
  17505. // function useMSGuesture(handlerProxy, event) {
  17506. // return isPointerFromTouch(event) && !!handlerProxy._msGesture;
  17507. // }
  17508. // Common handlers
  17509. zrUtil.each(['click', 'mousedown', 'mouseup', 'mousewheel', 'dblclick', 'contextmenu'], function (name) {
  17510. domHandlers[name] = function (event) {
  17511. event = normalizeEvent(this.dom, event);
  17512. this.trigger(name, event);
  17513. };
  17514. });
  17515. /**
  17516. * 为控制类实例初始化dom 事件处理函数
  17517. *
  17518. * @inner
  17519. * @param {module:zrender/Handler} instance 控制类实例
  17520. */
  17521. function initDomHandler(instance) {
  17522. zrUtil.each(touchHandlerNames, function (name) {
  17523. instance._handlers[name] = zrUtil.bind(domHandlers[name], instance);
  17524. });
  17525. zrUtil.each(pointerHandlerNames, function (name) {
  17526. instance._handlers[name] = zrUtil.bind(domHandlers[name], instance);
  17527. });
  17528. zrUtil.each(mouseHandlerNames, function (name) {
  17529. instance._handlers[name] = makeMouseHandler(domHandlers[name], instance);
  17530. });
  17531. function makeMouseHandler(fn, instance) {
  17532. return function () {
  17533. if (instance._touching) {
  17534. return;
  17535. }
  17536. return fn.apply(instance, arguments);
  17537. };
  17538. }
  17539. }
  17540. function HandlerDomProxy(dom) {
  17541. Eventful.call(this);
  17542. this.dom = dom;
  17543. /**
  17544. * @private
  17545. * @type {boolean}
  17546. */
  17547. this._touching = false;
  17548. /**
  17549. * @private
  17550. * @type {number}
  17551. */
  17552. this._touchTimer;
  17553. /**
  17554. * @private
  17555. * @type {module:zrender/core/GestureMgr}
  17556. */
  17557. this._gestureMgr = new GestureMgr();
  17558. this._handlers = {};
  17559. initDomHandler(this);
  17560. if (env.pointerEventsSupported) { // Only IE11+/Edge
  17561. // 1. On devices that both enable touch and mouse (e.g., MS Surface and lenovo X240),
  17562. // IE11+/Edge do not trigger touch event, but trigger pointer event and mouse event
  17563. // at the same time.
  17564. // 2. On MS Surface, it probablely only trigger mousedown but no mouseup when tap on
  17565. // screen, which do not occurs in pointer event.
  17566. // So we use pointer event to both detect touch gesture and mouse behavior.
  17567. mountHandlers(pointerHandlerNames, this);
  17568. // FIXME
  17569. // Note: MS Gesture require CSS touch-action set. But touch-action is not reliable,
  17570. // which does not prevent defuault behavior occasionally (which may cause view port
  17571. // zoomed in but use can not zoom it back). And event.preventDefault() does not work.
  17572. // So we have to not to use MSGesture and not to support touchmove and pinch on MS
  17573. // touch screen. And we only support click behavior on MS touch screen now.
  17574. // MS Gesture Event is only supported on IE11+/Edge and on Windows 8+.
  17575. // We dont support touch on IE on win7.
  17576. // See <https://msdn.microsoft.com/en-us/library/dn433243(v=vs.85).aspx>
  17577. // if (typeof MSGesture === 'function') {
  17578. // (this._msGesture = new MSGesture()).target = dom; // jshint ignore:line
  17579. // dom.addEventListener('MSGestureChange', onMSGestureChange);
  17580. // }
  17581. }
  17582. else {
  17583. if (env.touchEventsSupported) {
  17584. mountHandlers(touchHandlerNames, this);
  17585. // Handler of 'mouseout' event is needed in touch mode, which will be mounted below.
  17586. // addEventListener(root, 'mouseout', this._mouseoutHandler);
  17587. }
  17588. // 1. Considering some devices that both enable touch and mouse event (like on MS Surface
  17589. // and lenovo X240, @see #2350), we make mouse event be always listened, otherwise
  17590. // mouse event can not be handle in those devices.
  17591. // 2. On MS Surface, Chrome will trigger both touch event and mouse event. How to prevent
  17592. // mouseevent after touch event triggered, see `setTouchTimer`.
  17593. mountHandlers(mouseHandlerNames, this);
  17594. }
  17595. function mountHandlers(handlerNames, instance) {
  17596. zrUtil.each(handlerNames, function (name) {
  17597. addEventListener(dom, eventNameFix(name), instance._handlers[name]);
  17598. }, instance);
  17599. }
  17600. }
  17601. var handlerDomProxyProto = HandlerDomProxy.prototype;
  17602. handlerDomProxyProto.dispose = function () {
  17603. var handlerNames = mouseHandlerNames.concat(touchHandlerNames);
  17604. for (var i = 0; i < handlerNames.length; i++) {
  17605. var name = handlerNames[i];
  17606. removeEventListener(this.dom, eventNameFix(name), this._handlers[name]);
  17607. }
  17608. };
  17609. handlerDomProxyProto.setCursor = function (cursorStyle) {
  17610. this.dom.style.cursor = cursorStyle || 'default';
  17611. };
  17612. zrUtil.mixin(HandlerDomProxy, Eventful);
  17613. module.exports = HandlerDomProxy;
  17614. /***/ },
  17615. /* 91 */
  17616. /***/ function(module, exports, __webpack_require__) {
  17617. 'use strict';
  17618. /**
  17619. * Only implements needed gestures for mobile.
  17620. */
  17621. var eventUtil = __webpack_require__(88);
  17622. var GestureMgr = function () {
  17623. /**
  17624. * @private
  17625. * @type {Array.<Object>}
  17626. */
  17627. this._track = [];
  17628. };
  17629. GestureMgr.prototype = {
  17630. constructor: GestureMgr,
  17631. recognize: function (event, target, root) {
  17632. this._doTrack(event, target, root);
  17633. return this._recognize(event);
  17634. },
  17635. clear: function () {
  17636. this._track.length = 0;
  17637. return this;
  17638. },
  17639. _doTrack: function (event, target, root) {
  17640. var touches = event.touches;
  17641. if (!touches) {
  17642. return;
  17643. }
  17644. var trackItem = {
  17645. points: [],
  17646. touches: [],
  17647. target: target,
  17648. event: event
  17649. };
  17650. for (var i = 0, len = touches.length; i < len; i++) {
  17651. var touch = touches[i];
  17652. var pos = eventUtil.clientToLocal(root, touch, {});
  17653. trackItem.points.push([pos.zrX, pos.zrY]);
  17654. trackItem.touches.push(touch);
  17655. }
  17656. this._track.push(trackItem);
  17657. },
  17658. _recognize: function (event) {
  17659. for (var eventName in recognizers) {
  17660. if (recognizers.hasOwnProperty(eventName)) {
  17661. var gestureInfo = recognizers[eventName](this._track, event);
  17662. if (gestureInfo) {
  17663. return gestureInfo;
  17664. }
  17665. }
  17666. }
  17667. }
  17668. };
  17669. function dist(pointPair) {
  17670. var dx = pointPair[1][0] - pointPair[0][0];
  17671. var dy = pointPair[1][1] - pointPair[0][1];
  17672. return Math.sqrt(dx * dx + dy * dy);
  17673. }
  17674. function center(pointPair) {
  17675. return [
  17676. (pointPair[0][0] + pointPair[1][0]) / 2,
  17677. (pointPair[0][1] + pointPair[1][1]) / 2
  17678. ];
  17679. }
  17680. var recognizers = {
  17681. pinch: function (track, event) {
  17682. var trackLen = track.length;
  17683. if (!trackLen) {
  17684. return;
  17685. }
  17686. var pinchEnd = (track[trackLen - 1] || {}).points;
  17687. var pinchPre = (track[trackLen - 2] || {}).points || pinchEnd;
  17688. if (pinchPre
  17689. && pinchPre.length > 1
  17690. && pinchEnd
  17691. && pinchEnd.length > 1
  17692. ) {
  17693. var pinchScale = dist(pinchEnd) / dist(pinchPre);
  17694. !isFinite(pinchScale) && (pinchScale = 1);
  17695. event.pinchScale = pinchScale;
  17696. var pinchCenter = center(pinchEnd);
  17697. event.pinchX = pinchCenter[0];
  17698. event.pinchY = pinchCenter[1];
  17699. return {
  17700. type: 'pinch',
  17701. target: track[0].target,
  17702. event: event
  17703. };
  17704. }
  17705. }
  17706. // Only pinch currently.
  17707. };
  17708. module.exports = GestureMgr;
  17709. /***/ },
  17710. /* 92 */
  17711. /***/ function(module, exports, __webpack_require__) {
  17712. 'use strict';
  17713. /**
  17714. * Default canvas painter
  17715. * @module zrender/Painter
  17716. * @author Kener (@Kener-林峰, kener.linfeng@gmail.com)
  17717. * errorrik (errorrik@gmail.com)
  17718. * pissang (https://www.github.com/pissang)
  17719. */
  17720. var config = __webpack_require__(34);
  17721. var util = __webpack_require__(4);
  17722. var log = __webpack_require__(33);
  17723. var BoundingRect = __webpack_require__(9);
  17724. var timsort = __webpack_require__(86);
  17725. var Layer = __webpack_require__(93);
  17726. var requestAnimationFrame = __webpack_require__(89);
  17727. // PENDIGN
  17728. // Layer exceeds MAX_PROGRESSIVE_LAYER_NUMBER may have some problem when flush directly second time.
  17729. //
  17730. // Maximum progressive layer. When exceeding this number. All elements will be drawed in the last layer.
  17731. var MAX_PROGRESSIVE_LAYER_NUMBER = 5;
  17732. function parseInt10(val) {
  17733. return parseInt(val, 10);
  17734. }
  17735. function isLayerValid(layer) {
  17736. if (!layer) {
  17737. return false;
  17738. }
  17739. if (layer.__builtin__) {
  17740. return true;
  17741. }
  17742. if (typeof(layer.resize) !== 'function'
  17743. || typeof(layer.refresh) !== 'function'
  17744. ) {
  17745. return false;
  17746. }
  17747. return true;
  17748. }
  17749. function preProcessLayer(layer) {
  17750. layer.__unusedCount++;
  17751. }
  17752. function postProcessLayer(layer) {
  17753. if (layer.__unusedCount == 1) {
  17754. layer.clear();
  17755. }
  17756. }
  17757. var tmpRect = new BoundingRect(0, 0, 0, 0);
  17758. var viewRect = new BoundingRect(0, 0, 0, 0);
  17759. function isDisplayableCulled(el, width, height) {
  17760. tmpRect.copy(el.getBoundingRect());
  17761. if (el.transform) {
  17762. tmpRect.applyTransform(el.transform);
  17763. }
  17764. viewRect.width = width;
  17765. viewRect.height = height;
  17766. return !tmpRect.intersect(viewRect);
  17767. }
  17768. function isClipPathChanged(clipPaths, prevClipPaths) {
  17769. if (clipPaths == prevClipPaths) { // Can both be null or undefined
  17770. return false;
  17771. }
  17772. if (!clipPaths || !prevClipPaths || (clipPaths.length !== prevClipPaths.length)) {
  17773. return true;
  17774. }
  17775. for (var i = 0; i < clipPaths.length; i++) {
  17776. if (clipPaths[i] !== prevClipPaths[i]) {
  17777. return true;
  17778. }
  17779. }
  17780. }
  17781. function doClip(clipPaths, ctx) {
  17782. for (var i = 0; i < clipPaths.length; i++) {
  17783. var clipPath = clipPaths[i];
  17784. clipPath.setTransform(ctx);
  17785. ctx.beginPath();
  17786. clipPath.buildPath(ctx, clipPath.shape);
  17787. ctx.clip();
  17788. // Transform back
  17789. clipPath.restoreTransform(ctx);
  17790. }
  17791. }
  17792. function createRoot(width, height) {
  17793. var domRoot = document.createElement('div');
  17794. // domRoot.onselectstart = returnFalse; // 避免页面选中的尴尬
  17795. domRoot.style.cssText = [
  17796. 'position:relative',
  17797. 'overflow:hidden',
  17798. 'width:' + width + 'px',
  17799. 'height:' + height + 'px',
  17800. 'padding:0',
  17801. 'margin:0',
  17802. 'border-width:0'
  17803. ].join(';') + ';';
  17804. return domRoot;
  17805. }
  17806. /**
  17807. * @alias module:zrender/Painter
  17808. * @constructor
  17809. * @param {HTMLElement} root 绘图容器
  17810. * @param {module:zrender/Storage} storage
  17811. * @param {Ojbect} opts
  17812. */
  17813. var Painter = function (root, storage, opts) {
  17814. // In node environment using node-canvas
  17815. var singleCanvas = !root.nodeName // In node ?
  17816. || root.nodeName.toUpperCase() === 'CANVAS';
  17817. this._opts = opts = util.extend({}, opts || {});
  17818. /**
  17819. * @type {number}
  17820. */
  17821. this.dpr = opts.devicePixelRatio || config.devicePixelRatio;
  17822. /**
  17823. * @type {boolean}
  17824. * @private
  17825. */
  17826. this._singleCanvas = singleCanvas;
  17827. /**
  17828. * 绘图容器
  17829. * @type {HTMLElement}
  17830. */
  17831. this.root = root;
  17832. var rootStyle = root.style;
  17833. if (rootStyle) {
  17834. rootStyle['-webkit-tap-highlight-color'] = 'transparent';
  17835. rootStyle['-webkit-user-select'] =
  17836. rootStyle['user-select'] =
  17837. rootStyle['-webkit-touch-callout'] = 'none';
  17838. root.innerHTML = '';
  17839. }
  17840. /**
  17841. * @type {module:zrender/Storage}
  17842. */
  17843. this.storage = storage;
  17844. /**
  17845. * @type {Array.<number>}
  17846. * @private
  17847. */
  17848. var zlevelList = this._zlevelList = [];
  17849. /**
  17850. * @type {Object.<string, module:zrender/Layer>}
  17851. * @private
  17852. */
  17853. var layers = this._layers = {};
  17854. /**
  17855. * @type {Object.<string, Object>}
  17856. * @type {private}
  17857. */
  17858. this._layerConfig = {};
  17859. if (!singleCanvas) {
  17860. this._width = this._getSize(0);
  17861. this._height = this._getSize(1);
  17862. var domRoot = this._domRoot = createRoot(
  17863. this._width, this._height
  17864. );
  17865. root.appendChild(domRoot);
  17866. }
  17867. else {
  17868. if (opts.width != null) {
  17869. root.width = opts.width;
  17870. }
  17871. if (opts.height != null) {
  17872. root.height = opts.height;
  17873. }
  17874. // Use canvas width and height directly
  17875. var width = root.width;
  17876. var height = root.height;
  17877. this._width = width;
  17878. this._height = height;
  17879. // Create layer if only one given canvas
  17880. // Device pixel ratio is fixed to 1 because given canvas has its specified width and height
  17881. var mainLayer = new Layer(root, this, 1);
  17882. mainLayer.initContext();
  17883. // FIXME Use canvas width and height
  17884. // mainLayer.resize(width, height);
  17885. layers[0] = mainLayer;
  17886. zlevelList.push(0);
  17887. this._domRoot = root;
  17888. }
  17889. // Layers for progressive rendering
  17890. this._progressiveLayers = [];
  17891. /**
  17892. * @type {module:zrender/Layer}
  17893. * @private
  17894. */
  17895. this._hoverlayer;
  17896. this._hoverElements = [];
  17897. };
  17898. Painter.prototype = {
  17899. constructor: Painter,
  17900. /**
  17901. * If painter use a single canvas
  17902. * @return {boolean}
  17903. */
  17904. isSingleCanvas: function () {
  17905. return this._singleCanvas;
  17906. },
  17907. /**
  17908. * @return {HTMLDivElement}
  17909. */
  17910. getViewportRoot: function () {
  17911. return this._domRoot;
  17912. },
  17913. /**
  17914. * 刷新
  17915. * @param {boolean} [paintAll=false] 强制绘制所有displayable
  17916. */
  17917. refresh: function (paintAll) {
  17918. var list = this.storage.getDisplayList(true);
  17919. var zlevelList = this._zlevelList;
  17920. this._paintList(list, paintAll);
  17921. // Paint custum layers
  17922. for (var i = 0; i < zlevelList.length; i++) {
  17923. var z = zlevelList[i];
  17924. var layer = this._layers[z];
  17925. if (!layer.__builtin__ && layer.refresh) {
  17926. layer.refresh();
  17927. }
  17928. }
  17929. this.refreshHover();
  17930. if (this._progressiveLayers.length) {
  17931. this._startProgessive();
  17932. }
  17933. return this;
  17934. },
  17935. addHover: function (el, hoverStyle) {
  17936. if (el.__hoverMir) {
  17937. return;
  17938. }
  17939. var elMirror = new el.constructor({
  17940. style: el.style,
  17941. shape: el.shape
  17942. });
  17943. elMirror.__from = el;
  17944. el.__hoverMir = elMirror;
  17945. elMirror.setStyle(hoverStyle);
  17946. this._hoverElements.push(elMirror);
  17947. },
  17948. removeHover: function (el) {
  17949. var elMirror = el.__hoverMir;
  17950. var hoverElements = this._hoverElements;
  17951. var idx = util.indexOf(hoverElements, elMirror);
  17952. if (idx >= 0) {
  17953. hoverElements.splice(idx, 1);
  17954. }
  17955. el.__hoverMir = null;
  17956. },
  17957. clearHover: function (el) {
  17958. var hoverElements = this._hoverElements;
  17959. for (var i = 0; i < hoverElements.length; i++) {
  17960. var from = hoverElements[i].__from;
  17961. if (from) {
  17962. from.__hoverMir = null;
  17963. }
  17964. }
  17965. hoverElements.length = 0;
  17966. },
  17967. refreshHover: function () {
  17968. var hoverElements = this._hoverElements;
  17969. var len = hoverElements.length;
  17970. var hoverLayer = this._hoverlayer;
  17971. hoverLayer && hoverLayer.clear();
  17972. if (!len) {
  17973. return;
  17974. }
  17975. timsort(hoverElements, this.storage.displayableSortFunc);
  17976. // Use a extream large zlevel
  17977. // FIXME?
  17978. if (!hoverLayer) {
  17979. hoverLayer = this._hoverlayer = this.getLayer(1e5);
  17980. }
  17981. var scope = {};
  17982. hoverLayer.ctx.save();
  17983. for (var i = 0; i < len;) {
  17984. var el = hoverElements[i];
  17985. var originalEl = el.__from;
  17986. // Original el is removed
  17987. // PENDING
  17988. if (!(originalEl && originalEl.__zr)) {
  17989. hoverElements.splice(i, 1);
  17990. originalEl.__hoverMir = null;
  17991. len--;
  17992. continue;
  17993. }
  17994. i++;
  17995. // Use transform
  17996. // FIXME style and shape ?
  17997. if (!originalEl.invisible) {
  17998. el.transform = originalEl.transform;
  17999. el.invTransform = originalEl.invTransform;
  18000. el.__clipPaths = originalEl.__clipPaths;
  18001. // el.
  18002. this._doPaintEl(el, hoverLayer, true, scope);
  18003. }
  18004. }
  18005. hoverLayer.ctx.restore();
  18006. },
  18007. _startProgessive: function () {
  18008. var self = this;
  18009. if (!self._furtherProgressive) {
  18010. return;
  18011. }
  18012. // Use a token to stop progress steps triggered by
  18013. // previous zr.refresh calling.
  18014. var token = self._progressiveToken = +new Date();
  18015. self._progress++;
  18016. requestAnimationFrame(step);
  18017. function step() {
  18018. // In case refreshed or disposed
  18019. if (token === self._progressiveToken && self.storage) {
  18020. self._doPaintList(self.storage.getDisplayList());
  18021. if (self._furtherProgressive) {
  18022. self._progress++;
  18023. requestAnimationFrame(step);
  18024. }
  18025. else {
  18026. self._progressiveToken = -1;
  18027. }
  18028. }
  18029. }
  18030. },
  18031. _clearProgressive: function () {
  18032. this._progressiveToken = -1;
  18033. this._progress = 0;
  18034. util.each(this._progressiveLayers, function (layer) {
  18035. layer.__dirty && layer.clear();
  18036. });
  18037. },
  18038. _paintList: function (list, paintAll) {
  18039. if (paintAll == null) {
  18040. paintAll = false;
  18041. }
  18042. this._updateLayerStatus(list);
  18043. this._clearProgressive();
  18044. this.eachBuiltinLayer(preProcessLayer);
  18045. this._doPaintList(list, paintAll);
  18046. this.eachBuiltinLayer(postProcessLayer);
  18047. },
  18048. _doPaintList: function (list, paintAll) {
  18049. var currentLayer;
  18050. var currentZLevel;
  18051. var ctx;
  18052. // var invTransform = [];
  18053. var scope;
  18054. var progressiveLayerIdx = 0;
  18055. var currentProgressiveLayer;
  18056. var width = this._width;
  18057. var height = this._height;
  18058. var layerProgress;
  18059. var frame = this._progress;
  18060. function flushProgressiveLayer(layer) {
  18061. var dpr = ctx.dpr || 1;
  18062. ctx.save();
  18063. ctx.globalAlpha = 1;
  18064. ctx.shadowBlur = 0;
  18065. // Avoid layer don't clear in next progressive frame
  18066. currentLayer.__dirty = true;
  18067. ctx.setTransform(1, 0, 0, 1, 0, 0);
  18068. ctx.drawImage(layer.dom, 0, 0, width * dpr, height * dpr);
  18069. ctx.restore();
  18070. }
  18071. for (var i = 0, l = list.length; i < l; i++) {
  18072. var el = list[i];
  18073. var elZLevel = this._singleCanvas ? 0 : el.zlevel;
  18074. var elFrame = el.__frame;
  18075. // Flush at current context
  18076. // PENDING
  18077. if (elFrame < 0 && currentProgressiveLayer) {
  18078. flushProgressiveLayer(currentProgressiveLayer);
  18079. currentProgressiveLayer = null;
  18080. }
  18081. // Change draw layer
  18082. if (currentZLevel !== elZLevel) {
  18083. if (ctx) {
  18084. ctx.restore();
  18085. }
  18086. // Reset scope
  18087. scope = {};
  18088. // Only 0 zlevel if only has one canvas
  18089. currentZLevel = elZLevel;
  18090. currentLayer = this.getLayer(currentZLevel);
  18091. if (!currentLayer.__builtin__) {
  18092. log(
  18093. 'ZLevel ' + currentZLevel
  18094. + ' has been used by unkown layer ' + currentLayer.id
  18095. );
  18096. }
  18097. ctx = currentLayer.ctx;
  18098. ctx.save();
  18099. // Reset the count
  18100. currentLayer.__unusedCount = 0;
  18101. if (currentLayer.__dirty || paintAll) {
  18102. currentLayer.clear();
  18103. }
  18104. }
  18105. if (!(currentLayer.__dirty || paintAll)) {
  18106. continue;
  18107. }
  18108. if (elFrame >= 0) {
  18109. // Progressive layer changed
  18110. if (!currentProgressiveLayer) {
  18111. currentProgressiveLayer = this._progressiveLayers[
  18112. Math.min(progressiveLayerIdx++, MAX_PROGRESSIVE_LAYER_NUMBER - 1)
  18113. ];
  18114. currentProgressiveLayer.ctx.save();
  18115. currentProgressiveLayer.renderScope = {};
  18116. if (currentProgressiveLayer
  18117. && (currentProgressiveLayer.__progress > currentProgressiveLayer.__maxProgress)
  18118. ) {
  18119. // flushProgressiveLayer(currentProgressiveLayer);
  18120. // Quick jump all progressive elements
  18121. // All progressive element are not dirty, jump over and flush directly
  18122. i = currentProgressiveLayer.__nextIdxNotProg - 1;
  18123. // currentProgressiveLayer = null;
  18124. continue;
  18125. }
  18126. layerProgress = currentProgressiveLayer.__progress;
  18127. if (!currentProgressiveLayer.__dirty) {
  18128. // Keep rendering
  18129. frame = layerProgress;
  18130. }
  18131. currentProgressiveLayer.__progress = frame + 1;
  18132. }
  18133. if (elFrame === frame) {
  18134. this._doPaintEl(el, currentProgressiveLayer, true, currentProgressiveLayer.renderScope);
  18135. }
  18136. }
  18137. else {
  18138. this._doPaintEl(el, currentLayer, paintAll, scope);
  18139. }
  18140. el.__dirty = false;
  18141. }
  18142. if (currentProgressiveLayer) {
  18143. flushProgressiveLayer(currentProgressiveLayer);
  18144. }
  18145. // Restore the lastLayer ctx
  18146. ctx && ctx.restore();
  18147. // If still has clipping state
  18148. // if (scope.prevElClipPaths) {
  18149. // ctx.restore();
  18150. // }
  18151. this._furtherProgressive = false;
  18152. util.each(this._progressiveLayers, function (layer) {
  18153. if (layer.__maxProgress >= layer.__progress) {
  18154. this._furtherProgressive = true;
  18155. }
  18156. }, this);
  18157. },
  18158. _doPaintEl: function (el, currentLayer, forcePaint, scope) {
  18159. var ctx = currentLayer.ctx;
  18160. var m = el.transform;
  18161. if (
  18162. (currentLayer.__dirty || forcePaint)
  18163. // Ignore invisible element
  18164. && !el.invisible
  18165. // Ignore transparent element
  18166. && el.style.opacity !== 0
  18167. // Ignore scale 0 element, in some environment like node-canvas
  18168. // Draw a scale 0 element can cause all following draw wrong
  18169. // And setTransform with scale 0 will cause set back transform failed.
  18170. && !(m && !m[0] && !m[3])
  18171. // Ignore culled element
  18172. && !(el.culling && isDisplayableCulled(el, this._width, this._height))
  18173. ) {
  18174. var clipPaths = el.__clipPaths;
  18175. // Optimize when clipping on group with several elements
  18176. if (scope.prevClipLayer !== currentLayer
  18177. || isClipPathChanged(clipPaths, scope.prevElClipPaths)
  18178. ) {
  18179. // If has previous clipping state, restore from it
  18180. if (scope.prevElClipPaths) {
  18181. scope.prevClipLayer.ctx.restore();
  18182. scope.prevClipLayer = scope.prevElClipPaths = null;
  18183. // Reset prevEl since context has been restored
  18184. scope.prevEl = null;
  18185. }
  18186. // New clipping state
  18187. if (clipPaths) {
  18188. ctx.save();
  18189. doClip(clipPaths, ctx);
  18190. scope.prevClipLayer = currentLayer;
  18191. scope.prevElClipPaths = clipPaths;
  18192. }
  18193. }
  18194. el.beforeBrush && el.beforeBrush(ctx);
  18195. el.brush(ctx, scope.prevEl || null);
  18196. scope.prevEl = el;
  18197. el.afterBrush && el.afterBrush(ctx);
  18198. }
  18199. },
  18200. /**
  18201. * 获取 zlevel 所在层,如果不存在则会创建一个新的层
  18202. * @param {number} zlevel
  18203. * @return {module:zrender/Layer}
  18204. */
  18205. getLayer: function (zlevel) {
  18206. if (this._singleCanvas) {
  18207. return this._layers[0];
  18208. }
  18209. var layer = this._layers[zlevel];
  18210. if (!layer) {
  18211. // Create a new layer
  18212. layer = new Layer('zr_' + zlevel, this, this.dpr);
  18213. layer.__builtin__ = true;
  18214. if (this._layerConfig[zlevel]) {
  18215. util.merge(layer, this._layerConfig[zlevel], true);
  18216. }
  18217. this.insertLayer(zlevel, layer);
  18218. // Context is created after dom inserted to document
  18219. // Or excanvas will get 0px clientWidth and clientHeight
  18220. layer.initContext();
  18221. }
  18222. return layer;
  18223. },
  18224. insertLayer: function (zlevel, layer) {
  18225. var layersMap = this._layers;
  18226. var zlevelList = this._zlevelList;
  18227. var len = zlevelList.length;
  18228. var prevLayer = null;
  18229. var i = -1;
  18230. var domRoot = this._domRoot;
  18231. if (layersMap[zlevel]) {
  18232. log('ZLevel ' + zlevel + ' has been used already');
  18233. return;
  18234. }
  18235. // Check if is a valid layer
  18236. if (!isLayerValid(layer)) {
  18237. log('Layer of zlevel ' + zlevel + ' is not valid');
  18238. return;
  18239. }
  18240. if (len > 0 && zlevel > zlevelList[0]) {
  18241. for (i = 0; i < len - 1; i++) {
  18242. if (
  18243. zlevelList[i] < zlevel
  18244. && zlevelList[i + 1] > zlevel
  18245. ) {
  18246. break;
  18247. }
  18248. }
  18249. prevLayer = layersMap[zlevelList[i]];
  18250. }
  18251. zlevelList.splice(i + 1, 0, zlevel);
  18252. layersMap[zlevel] = layer;
  18253. // Vitual layer will not directly show on the screen.
  18254. // (It can be a WebGL layer and assigned to a ZImage element)
  18255. // But it still under management of zrender.
  18256. if (!layer.virtual) {
  18257. if (prevLayer) {
  18258. var prevDom = prevLayer.dom;
  18259. if (prevDom.nextSibling) {
  18260. domRoot.insertBefore(
  18261. layer.dom,
  18262. prevDom.nextSibling
  18263. );
  18264. }
  18265. else {
  18266. domRoot.appendChild(layer.dom);
  18267. }
  18268. }
  18269. else {
  18270. if (domRoot.firstChild) {
  18271. domRoot.insertBefore(layer.dom, domRoot.firstChild);
  18272. }
  18273. else {
  18274. domRoot.appendChild(layer.dom);
  18275. }
  18276. }
  18277. }
  18278. },
  18279. // Iterate each layer
  18280. eachLayer: function (cb, context) {
  18281. var zlevelList = this._zlevelList;
  18282. var z;
  18283. var i;
  18284. for (i = 0; i < zlevelList.length; i++) {
  18285. z = zlevelList[i];
  18286. cb.call(context, this._layers[z], z);
  18287. }
  18288. },
  18289. // Iterate each buildin layer
  18290. eachBuiltinLayer: function (cb, context) {
  18291. var zlevelList = this._zlevelList;
  18292. var layer;
  18293. var z;
  18294. var i;
  18295. for (i = 0; i < zlevelList.length; i++) {
  18296. z = zlevelList[i];
  18297. layer = this._layers[z];
  18298. if (layer.__builtin__) {
  18299. cb.call(context, layer, z);
  18300. }
  18301. }
  18302. },
  18303. // Iterate each other layer except buildin layer
  18304. eachOtherLayer: function (cb, context) {
  18305. var zlevelList = this._zlevelList;
  18306. var layer;
  18307. var z;
  18308. var i;
  18309. for (i = 0; i < zlevelList.length; i++) {
  18310. z = zlevelList[i];
  18311. layer = this._layers[z];
  18312. if (!layer.__builtin__) {
  18313. cb.call(context, layer, z);
  18314. }
  18315. }
  18316. },
  18317. /**
  18318. * 获取所有已创建的层
  18319. * @param {Array.<module:zrender/Layer>} [prevLayer]
  18320. */
  18321. getLayers: function () {
  18322. return this._layers;
  18323. },
  18324. _updateLayerStatus: function (list) {
  18325. var layers = this._layers;
  18326. var progressiveLayers = this._progressiveLayers;
  18327. var elCountsLastFrame = {};
  18328. var progressiveElCountsLastFrame = {};
  18329. this.eachBuiltinLayer(function (layer, z) {
  18330. elCountsLastFrame[z] = layer.elCount;
  18331. layer.elCount = 0;
  18332. layer.__dirty = false;
  18333. });
  18334. util.each(progressiveLayers, function (layer, idx) {
  18335. progressiveElCountsLastFrame[idx] = layer.elCount;
  18336. layer.elCount = 0;
  18337. layer.__dirty = false;
  18338. });
  18339. var progressiveLayerCount = 0;
  18340. var currentProgressiveLayer;
  18341. var lastProgressiveKey;
  18342. var frameCount = 0;
  18343. for (var i = 0, l = list.length; i < l; i++) {
  18344. var el = list[i];
  18345. var zlevel = this._singleCanvas ? 0 : el.zlevel;
  18346. var layer = layers[zlevel];
  18347. var elProgress = el.progressive;
  18348. if (layer) {
  18349. layer.elCount++;
  18350. layer.__dirty = layer.__dirty || el.__dirty;
  18351. }
  18352. /////// Update progressive
  18353. if (elProgress >= 0) {
  18354. // Fix wrong progressive sequence problem.
  18355. if (lastProgressiveKey !== elProgress) {
  18356. lastProgressiveKey = elProgress;
  18357. frameCount++;
  18358. }
  18359. var elFrame = el.__frame = frameCount - 1;
  18360. if (!currentProgressiveLayer) {
  18361. var idx = Math.min(progressiveLayerCount, MAX_PROGRESSIVE_LAYER_NUMBER - 1);
  18362. currentProgressiveLayer = progressiveLayers[idx];
  18363. if (!currentProgressiveLayer) {
  18364. currentProgressiveLayer = progressiveLayers[idx] = new Layer(
  18365. 'progressive', this, this.dpr
  18366. );
  18367. currentProgressiveLayer.initContext();
  18368. }
  18369. currentProgressiveLayer.__maxProgress = 0;
  18370. }
  18371. currentProgressiveLayer.__dirty = currentProgressiveLayer.__dirty || el.__dirty;
  18372. currentProgressiveLayer.elCount++;
  18373. currentProgressiveLayer.__maxProgress = Math.max(
  18374. currentProgressiveLayer.__maxProgress, elFrame
  18375. );
  18376. if (currentProgressiveLayer.__maxProgress >= currentProgressiveLayer.__progress) {
  18377. // Should keep rendering this layer because progressive rendering is not finished yet
  18378. layer.__dirty = true;
  18379. }
  18380. }
  18381. else {
  18382. el.__frame = -1;
  18383. if (currentProgressiveLayer) {
  18384. currentProgressiveLayer.__nextIdxNotProg = i;
  18385. progressiveLayerCount++;
  18386. currentProgressiveLayer = null;
  18387. }
  18388. }
  18389. }
  18390. if (currentProgressiveLayer) {
  18391. progressiveLayerCount++;
  18392. currentProgressiveLayer.__nextIdxNotProg = i;
  18393. }
  18394. // 层中的元素数量有发生变化
  18395. this.eachBuiltinLayer(function (layer, z) {
  18396. if (elCountsLastFrame[z] !== layer.elCount) {
  18397. layer.__dirty = true;
  18398. }
  18399. });
  18400. progressiveLayers.length = Math.min(progressiveLayerCount, MAX_PROGRESSIVE_LAYER_NUMBER);
  18401. util.each(progressiveLayers, function (layer, idx) {
  18402. if (progressiveElCountsLastFrame[idx] !== layer.elCount) {
  18403. el.__dirty = true;
  18404. }
  18405. if (layer.__dirty) {
  18406. layer.__progress = 0;
  18407. }
  18408. });
  18409. },
  18410. /**
  18411. * 清除hover层外所有内容
  18412. */
  18413. clear: function () {
  18414. this.eachBuiltinLayer(this._clearLayer);
  18415. return this;
  18416. },
  18417. _clearLayer: function (layer) {
  18418. layer.clear();
  18419. },
  18420. /**
  18421. * 修改指定zlevel的绘制参数
  18422. *
  18423. * @param {string} zlevel
  18424. * @param {Object} config 配置对象
  18425. * @param {string} [config.clearColor=0] 每次清空画布的颜色
  18426. * @param {string} [config.motionBlur=false] 是否开启动态模糊
  18427. * @param {number} [config.lastFrameAlpha=0.7]
  18428. * 在开启动态模糊的时候使用,与上一帧混合的alpha值,值越大尾迹越明显
  18429. */
  18430. configLayer: function (zlevel, config) {
  18431. if (config) {
  18432. var layerConfig = this._layerConfig;
  18433. if (!layerConfig[zlevel]) {
  18434. layerConfig[zlevel] = config;
  18435. }
  18436. else {
  18437. util.merge(layerConfig[zlevel], config, true);
  18438. }
  18439. var layer = this._layers[zlevel];
  18440. if (layer) {
  18441. util.merge(layer, layerConfig[zlevel], true);
  18442. }
  18443. }
  18444. },
  18445. /**
  18446. * 删除指定层
  18447. * @param {number} zlevel 层所在的zlevel
  18448. */
  18449. delLayer: function (zlevel) {
  18450. var layers = this._layers;
  18451. var zlevelList = this._zlevelList;
  18452. var layer = layers[zlevel];
  18453. if (!layer) {
  18454. return;
  18455. }
  18456. layer.dom.parentNode.removeChild(layer.dom);
  18457. delete layers[zlevel];
  18458. zlevelList.splice(util.indexOf(zlevelList, zlevel), 1);
  18459. },
  18460. /**
  18461. * 区域大小变化后重绘
  18462. */
  18463. resize: function (width, height) {
  18464. var domRoot = this._domRoot;
  18465. // FIXME Why ?
  18466. domRoot.style.display = 'none';
  18467. // Save input w/h
  18468. var opts = this._opts;
  18469. width != null && (opts.width = width);
  18470. height != null && (opts.height = height);
  18471. width = this._getSize(0);
  18472. height = this._getSize(1);
  18473. domRoot.style.display = '';
  18474. // 优化没有实际改变的resize
  18475. if (this._width != width || height != this._height) {
  18476. domRoot.style.width = width + 'px';
  18477. domRoot.style.height = height + 'px';
  18478. for (var id in this._layers) {
  18479. if (this._layers.hasOwnProperty(id)) {
  18480. this._layers[id].resize(width, height);
  18481. }
  18482. }
  18483. util.each(this._progressiveLayers, function (layer) {
  18484. layer.resize(width, height);
  18485. });
  18486. this.refresh(true);
  18487. }
  18488. this._width = width;
  18489. this._height = height;
  18490. return this;
  18491. },
  18492. /**
  18493. * 清除单独的一个层
  18494. * @param {number} zlevel
  18495. */
  18496. clearLayer: function (zlevel) {
  18497. var layer = this._layers[zlevel];
  18498. if (layer) {
  18499. layer.clear();
  18500. }
  18501. },
  18502. /**
  18503. * 释放
  18504. */
  18505. dispose: function () {
  18506. this.root.innerHTML = '';
  18507. this.root =
  18508. this.storage =
  18509. this._domRoot =
  18510. this._layers = null;
  18511. },
  18512. /**
  18513. * Get canvas which has all thing rendered
  18514. * @param {Object} opts
  18515. * @param {string} [opts.backgroundColor]
  18516. */
  18517. getRenderedCanvas: function (opts) {
  18518. opts = opts || {};
  18519. if (this._singleCanvas) {
  18520. return this._layers[0].dom;
  18521. }
  18522. var imageLayer = new Layer('image', this, opts.pixelRatio || this.dpr);
  18523. imageLayer.initContext();
  18524. imageLayer.clearColor = opts.backgroundColor;
  18525. imageLayer.clear();
  18526. var displayList = this.storage.getDisplayList(true);
  18527. var scope = {};
  18528. var zlevel;
  18529. var self = this;
  18530. function findAndDrawOtherLayer(smaller, larger) {
  18531. var zlevelList = self._zlevelList;
  18532. if (smaller == null) {
  18533. smaller = -Infinity;
  18534. }
  18535. var intermediateLayer;
  18536. for (var i = 0; i < zlevelList.length; i++) {
  18537. var z = zlevelList[i];
  18538. var layer = self._layers[z];
  18539. if (!layer.__builtin__ && z > smaller && z < larger) {
  18540. intermediateLayer = layer;
  18541. break;
  18542. }
  18543. }
  18544. if (intermediateLayer && intermediateLayer.renderToCanvas) {
  18545. imageLayer.ctx.save();
  18546. intermediateLayer.renderToCanvas(imageLayer.ctx);
  18547. imageLayer.ctx.restore();
  18548. }
  18549. }
  18550. for (var i = 0; i < displayList.length; i++) {
  18551. var el = displayList[i];
  18552. if (el.zlevel !== zlevel) {
  18553. findAndDrawOtherLayer(zlevel, el.zlevel);
  18554. zlevel = el.zlevel;
  18555. }
  18556. this._doPaintEl(el, imageLayer, true, scope);
  18557. }
  18558. findAndDrawOtherLayer(zlevel, Infinity);
  18559. return imageLayer.dom;
  18560. },
  18561. /**
  18562. * 获取绘图区域宽度
  18563. */
  18564. getWidth: function () {
  18565. return this._width;
  18566. },
  18567. /**
  18568. * 获取绘图区域高度
  18569. */
  18570. getHeight: function () {
  18571. return this._height;
  18572. },
  18573. _getSize: function (whIdx) {
  18574. var opts = this._opts;
  18575. var wh = ['width', 'height'][whIdx];
  18576. var cwh = ['clientWidth', 'clientHeight'][whIdx];
  18577. var plt = ['paddingLeft', 'paddingTop'][whIdx];
  18578. var prb = ['paddingRight', 'paddingBottom'][whIdx];
  18579. if (opts[wh] != null && opts[wh] !== 'auto') {
  18580. return parseFloat(opts[wh]);
  18581. }
  18582. var root = this.root;
  18583. var stl = document.defaultView.getComputedStyle(root);
  18584. return (
  18585. (root[cwh] || parseInt10(stl[wh]) || parseInt10(root.style[wh]))
  18586. - (parseInt10(stl[plt]) || 0)
  18587. - (parseInt10(stl[prb]) || 0)
  18588. ) | 0;
  18589. },
  18590. pathToImage: function (path, dpr) {
  18591. dpr = dpr || this.dpr;
  18592. var canvas = document.createElement('canvas');
  18593. var ctx = canvas.getContext('2d');
  18594. var rect = path.getBoundingRect();
  18595. var style = path.style;
  18596. var shadowBlurSize = style.shadowBlur;
  18597. var shadowOffsetX = style.shadowOffsetX;
  18598. var shadowOffsetY = style.shadowOffsetY;
  18599. var lineWidth = style.hasStroke() ? style.lineWidth : 0;
  18600. var leftMargin = Math.max(lineWidth / 2, -shadowOffsetX + shadowBlurSize);
  18601. var rightMargin = Math.max(lineWidth / 2, shadowOffsetX + shadowBlurSize);
  18602. var topMargin = Math.max(lineWidth / 2, -shadowOffsetY + shadowBlurSize);
  18603. var bottomMargin = Math.max(lineWidth / 2, shadowOffsetY + shadowBlurSize);
  18604. var width = rect.width + leftMargin + rightMargin;
  18605. var height = rect.height + topMargin + bottomMargin;
  18606. canvas.width = width * dpr;
  18607. canvas.height = height * dpr;
  18608. ctx.scale(dpr, dpr);
  18609. ctx.clearRect(0, 0, width, height);
  18610. ctx.dpr = dpr;
  18611. var pathTransform = {
  18612. position: path.position,
  18613. rotation: path.rotation,
  18614. scale: path.scale
  18615. };
  18616. path.position = [leftMargin - rect.x, topMargin - rect.y];
  18617. path.rotation = 0;
  18618. path.scale = [1, 1];
  18619. path.updateTransform();
  18620. if (path) {
  18621. path.brush(ctx);
  18622. }
  18623. var ImageShape = __webpack_require__(49);
  18624. var imgShape = new ImageShape({
  18625. style: {
  18626. x: 0,
  18627. y: 0,
  18628. image: canvas
  18629. }
  18630. });
  18631. if (pathTransform.position != null) {
  18632. imgShape.position = path.position = pathTransform.position;
  18633. }
  18634. if (pathTransform.rotation != null) {
  18635. imgShape.rotation = path.rotation = pathTransform.rotation;
  18636. }
  18637. if (pathTransform.scale != null) {
  18638. imgShape.scale = path.scale = pathTransform.scale;
  18639. }
  18640. return imgShape;
  18641. }
  18642. };
  18643. module.exports = Painter;
  18644. /***/ },
  18645. /* 93 */
  18646. /***/ function(module, exports, __webpack_require__) {
  18647. /**
  18648. * @module zrender/Layer
  18649. * @author pissang(https://www.github.com/pissang)
  18650. */
  18651. var util = __webpack_require__(4);
  18652. var config = __webpack_require__(34);
  18653. var Style = __webpack_require__(22);
  18654. var Pattern = __webpack_require__(46);
  18655. function returnFalse() {
  18656. return false;
  18657. }
  18658. /**
  18659. * 创建dom
  18660. *
  18661. * @inner
  18662. * @param {string} id dom id 待用
  18663. * @param {string} type dom type,such as canvas, div etc.
  18664. * @param {Painter} painter painter instance
  18665. * @param {number} number
  18666. */
  18667. function createDom(id, type, painter, dpr) {
  18668. var newDom = document.createElement(type);
  18669. var width = painter.getWidth();
  18670. var height = painter.getHeight();
  18671. var newDomStyle = newDom.style;
  18672. // 没append呢,请原谅我这样写,清晰~
  18673. newDomStyle.position = 'absolute';
  18674. newDomStyle.left = 0;
  18675. newDomStyle.top = 0;
  18676. newDomStyle.width = width + 'px';
  18677. newDomStyle.height = height + 'px';
  18678. newDom.width = width * dpr;
  18679. newDom.height = height * dpr;
  18680. // id不作为索引用,避免可能造成的重名,定义为私有属性
  18681. newDom.setAttribute('data-zr-dom-id', id);
  18682. return newDom;
  18683. }
  18684. /**
  18685. * @alias module:zrender/Layer
  18686. * @constructor
  18687. * @extends module:zrender/mixin/Transformable
  18688. * @param {string} id
  18689. * @param {module:zrender/Painter} painter
  18690. * @param {number} [dpr]
  18691. */
  18692. var Layer = function(id, painter, dpr) {
  18693. var dom;
  18694. dpr = dpr || config.devicePixelRatio;
  18695. if (typeof id === 'string') {
  18696. dom = createDom(id, 'canvas', painter, dpr);
  18697. }
  18698. // Not using isDom because in node it will return false
  18699. else if (util.isObject(id)) {
  18700. dom = id;
  18701. id = dom.id;
  18702. }
  18703. this.id = id;
  18704. this.dom = dom;
  18705. var domStyle = dom.style;
  18706. if (domStyle) { // Not in node
  18707. dom.onselectstart = returnFalse; // 避免页面选中的尴尬
  18708. domStyle['-webkit-user-select'] = 'none';
  18709. domStyle['user-select'] = 'none';
  18710. domStyle['-webkit-touch-callout'] = 'none';
  18711. domStyle['-webkit-tap-highlight-color'] = 'rgba(0,0,0,0)';
  18712. domStyle['padding'] = 0;
  18713. domStyle['margin'] = 0;
  18714. domStyle['border-width'] = 0;
  18715. }
  18716. this.domBack = null;
  18717. this.ctxBack = null;
  18718. this.painter = painter;
  18719. this.config = null;
  18720. // Configs
  18721. /**
  18722. * 每次清空画布的颜色
  18723. * @type {string}
  18724. * @default 0
  18725. */
  18726. this.clearColor = 0;
  18727. /**
  18728. * 是否开启动态模糊
  18729. * @type {boolean}
  18730. * @default false
  18731. */
  18732. this.motionBlur = false;
  18733. /**
  18734. * 在开启动态模糊的时候使用,与上一帧混合的alpha值,值越大尾迹越明显
  18735. * @type {number}
  18736. * @default 0.7
  18737. */
  18738. this.lastFrameAlpha = 0.7;
  18739. /**
  18740. * Layer dpr
  18741. * @type {number}
  18742. */
  18743. this.dpr = dpr;
  18744. };
  18745. Layer.prototype = {
  18746. constructor: Layer,
  18747. elCount: 0,
  18748. __dirty: true,
  18749. initContext: function () {
  18750. this.ctx = this.dom.getContext('2d');
  18751. this.ctx.dpr = this.dpr;
  18752. },
  18753. createBackBuffer: function () {
  18754. var dpr = this.dpr;
  18755. this.domBack = createDom('back-' + this.id, 'canvas', this.painter, dpr);
  18756. this.ctxBack = this.domBack.getContext('2d');
  18757. if (dpr != 1) {
  18758. this.ctxBack.scale(dpr, dpr);
  18759. }
  18760. },
  18761. /**
  18762. * @param {number} width
  18763. * @param {number} height
  18764. */
  18765. resize: function (width, height) {
  18766. var dpr = this.dpr;
  18767. var dom = this.dom;
  18768. var domStyle = dom.style;
  18769. var domBack = this.domBack;
  18770. domStyle.width = width + 'px';
  18771. domStyle.height = height + 'px';
  18772. dom.width = width * dpr;
  18773. dom.height = height * dpr;
  18774. if (domBack) {
  18775. domBack.width = width * dpr;
  18776. domBack.height = height * dpr;
  18777. if (dpr != 1) {
  18778. this.ctxBack.scale(dpr, dpr);
  18779. }
  18780. }
  18781. },
  18782. /**
  18783. * 清空该层画布
  18784. * @param {boolean} clearAll Clear all with out motion blur
  18785. */
  18786. clear: function (clearAll) {
  18787. var dom = this.dom;
  18788. var ctx = this.ctx;
  18789. var width = dom.width;
  18790. var height = dom.height;
  18791. var clearColor = this.clearColor;
  18792. var haveMotionBLur = this.motionBlur && !clearAll;
  18793. var lastFrameAlpha = this.lastFrameAlpha;
  18794. var dpr = this.dpr;
  18795. if (haveMotionBLur) {
  18796. if (!this.domBack) {
  18797. this.createBackBuffer();
  18798. }
  18799. this.ctxBack.globalCompositeOperation = 'copy';
  18800. this.ctxBack.drawImage(
  18801. dom, 0, 0,
  18802. width / dpr,
  18803. height / dpr
  18804. );
  18805. }
  18806. ctx.clearRect(0, 0, width, height);
  18807. if (clearColor) {
  18808. var clearColorGradientOrPattern;
  18809. // Gradient
  18810. if (clearColor.colorStops) {
  18811. // Cache canvas gradient
  18812. clearColorGradientOrPattern = clearColor.__canvasGradient || Style.getGradient(ctx, clearColor, {
  18813. x: 0,
  18814. y: 0,
  18815. width: width,
  18816. height: height
  18817. });
  18818. clearColor.__canvasGradient = clearColorGradientOrPattern;
  18819. }
  18820. // Pattern
  18821. else if (clearColor.image) {
  18822. clearColorGradientOrPattern = Pattern.prototype.getCanvasPattern.call(clearColor, ctx);
  18823. }
  18824. ctx.save();
  18825. ctx.fillStyle = clearColorGradientOrPattern || clearColor;
  18826. ctx.fillRect(0, 0, width, height);
  18827. ctx.restore();
  18828. }
  18829. if (haveMotionBLur) {
  18830. var domBack = this.domBack;
  18831. ctx.save();
  18832. ctx.globalAlpha = lastFrameAlpha;
  18833. ctx.drawImage(domBack, 0, 0, width, height);
  18834. ctx.restore();
  18835. }
  18836. }
  18837. };
  18838. module.exports = Layer;
  18839. /***/ },
  18840. /* 94 */
  18841. /***/ function(module, exports, __webpack_require__) {
  18842. var Gradient = __webpack_require__(66);
  18843. module.exports = function (ecModel) {
  18844. function encodeColor(seriesModel) {
  18845. var colorAccessPath = (seriesModel.visualColorAccessPath || 'itemStyle.normal.color').split('.');
  18846. var data = seriesModel.getData();
  18847. var color = seriesModel.get(colorAccessPath) // Set in itemStyle
  18848. || seriesModel.getColorFromPalette(seriesModel.get('name')); // Default color
  18849. // FIXME Set color function or use the platte color
  18850. data.setVisual('color', color);
  18851. // Only visible series has each data be visual encoded
  18852. if (!ecModel.isSeriesFiltered(seriesModel)) {
  18853. if (typeof color === 'function' && !(color instanceof Gradient)) {
  18854. data.each(function (idx) {
  18855. data.setItemVisual(
  18856. idx, 'color', color(seriesModel.getDataParams(idx))
  18857. );
  18858. });
  18859. }
  18860. // itemStyle in each data item
  18861. data.each(function (idx) {
  18862. var itemModel = data.getItemModel(idx);
  18863. var color = itemModel.get(colorAccessPath, true);
  18864. if (color != null) {
  18865. data.setItemVisual(idx, 'color', color);
  18866. }
  18867. });
  18868. }
  18869. }
  18870. ecModel.eachRawSeries(encodeColor);
  18871. };
  18872. /***/ },
  18873. /* 95 */
  18874. /***/ function(module, exports, __webpack_require__) {
  18875. // Compatitable with 2.0
  18876. var zrUtil = __webpack_require__(4);
  18877. var compatStyle = __webpack_require__(96);
  18878. function get(opt, path) {
  18879. path = path.split(',');
  18880. var obj = opt;
  18881. for (var i = 0; i < path.length; i++) {
  18882. obj = obj && obj[path[i]];
  18883. if (obj == null) {
  18884. break;
  18885. }
  18886. }
  18887. return obj;
  18888. }
  18889. function set(opt, path, val, overwrite) {
  18890. path = path.split(',');
  18891. var obj = opt;
  18892. var key;
  18893. for (var i = 0; i < path.length - 1; i++) {
  18894. key = path[i];
  18895. if (obj[key] == null) {
  18896. obj[key] = {};
  18897. }
  18898. obj = obj[key];
  18899. }
  18900. if (overwrite || obj[path[i]] == null) {
  18901. obj[path[i]] = val;
  18902. }
  18903. }
  18904. function compatLayoutProperties(option) {
  18905. each(LAYOUT_PROPERTIES, function (prop) {
  18906. if (prop[0] in option && !(prop[1] in option)) {
  18907. option[prop[1]] = option[prop[0]];
  18908. }
  18909. });
  18910. }
  18911. var LAYOUT_PROPERTIES = [
  18912. ['x', 'left'], ['y', 'top'], ['x2', 'right'], ['y2', 'bottom']
  18913. ];
  18914. var COMPATITABLE_COMPONENTS = [
  18915. 'grid', 'geo', 'parallel', 'legend', 'toolbox', 'title', 'visualMap', 'dataZoom', 'timeline'
  18916. ];
  18917. var COMPATITABLE_SERIES = [
  18918. 'bar', 'boxplot', 'candlestick', 'chord', 'effectScatter',
  18919. 'funnel', 'gauge', 'lines', 'graph', 'heatmap', 'line', 'map', 'parallel',
  18920. 'pie', 'radar', 'sankey', 'scatter', 'treemap'
  18921. ];
  18922. var each = zrUtil.each;
  18923. module.exports = function (option) {
  18924. each(option.series, function (seriesOpt) {
  18925. if (!zrUtil.isObject(seriesOpt)) {
  18926. return;
  18927. }
  18928. var seriesType = seriesOpt.type;
  18929. compatStyle(seriesOpt);
  18930. if (seriesType === 'pie' || seriesType === 'gauge') {
  18931. if (seriesOpt.clockWise != null) {
  18932. seriesOpt.clockwise = seriesOpt.clockWise;
  18933. }
  18934. }
  18935. if (seriesType === 'gauge') {
  18936. var pointerColor = get(seriesOpt, 'pointer.color');
  18937. pointerColor != null
  18938. && set(seriesOpt, 'itemStyle.normal.color', pointerColor);
  18939. }
  18940. for (var i = 0; i < COMPATITABLE_SERIES.length; i++) {
  18941. if (COMPATITABLE_SERIES[i] === seriesOpt.type) {
  18942. compatLayoutProperties(seriesOpt);
  18943. break;
  18944. }
  18945. }
  18946. });
  18947. // dataRange has changed to visualMap
  18948. if (option.dataRange) {
  18949. option.visualMap = option.dataRange;
  18950. }
  18951. each(COMPATITABLE_COMPONENTS, function (componentName) {
  18952. var options = option[componentName];
  18953. if (options) {
  18954. if (!zrUtil.isArray(options)) {
  18955. options = [options];
  18956. }
  18957. each(options, function (option) {
  18958. compatLayoutProperties(option);
  18959. });
  18960. }
  18961. });
  18962. };
  18963. /***/ },
  18964. /* 96 */
  18965. /***/ function(module, exports, __webpack_require__) {
  18966. var zrUtil = __webpack_require__(4);
  18967. var POSSIBLE_STYLES = [
  18968. 'areaStyle', 'lineStyle', 'nodeStyle', 'linkStyle',
  18969. 'chordStyle', 'label', 'labelLine'
  18970. ];
  18971. function compatItemStyle(opt) {
  18972. var itemStyleOpt = opt && opt.itemStyle;
  18973. if (itemStyleOpt) {
  18974. zrUtil.each(POSSIBLE_STYLES, function (styleName) {
  18975. var normalItemStyleOpt = itemStyleOpt.normal;
  18976. var emphasisItemStyleOpt = itemStyleOpt.emphasis;
  18977. if (normalItemStyleOpt && normalItemStyleOpt[styleName]) {
  18978. opt[styleName] = opt[styleName] || {};
  18979. if (!opt[styleName].normal) {
  18980. opt[styleName].normal = normalItemStyleOpt[styleName];
  18981. }
  18982. else {
  18983. zrUtil.merge(opt[styleName].normal, normalItemStyleOpt[styleName]);
  18984. }
  18985. normalItemStyleOpt[styleName] = null;
  18986. }
  18987. if (emphasisItemStyleOpt && emphasisItemStyleOpt[styleName]) {
  18988. opt[styleName] = opt[styleName] || {};
  18989. if (!opt[styleName].emphasis) {
  18990. opt[styleName].emphasis = emphasisItemStyleOpt[styleName];
  18991. }
  18992. else {
  18993. zrUtil.merge(opt[styleName].emphasis, emphasisItemStyleOpt[styleName]);
  18994. }
  18995. emphasisItemStyleOpt[styleName] = null;
  18996. }
  18997. });
  18998. }
  18999. }
  19000. module.exports = function (seriesOpt) {
  19001. if (!seriesOpt) {
  19002. return;
  19003. }
  19004. compatItemStyle(seriesOpt);
  19005. compatItemStyle(seriesOpt.markPoint);
  19006. compatItemStyle(seriesOpt.markLine);
  19007. var data = seriesOpt.data;
  19008. if (data) {
  19009. for (var i = 0; i < data.length; i++) {
  19010. compatItemStyle(data[i]);
  19011. }
  19012. // mark point data
  19013. var markPoint = seriesOpt.markPoint;
  19014. if (markPoint && markPoint.data) {
  19015. var mpData = markPoint.data;
  19016. for (var i = 0; i < mpData.length; i++) {
  19017. compatItemStyle(mpData[i]);
  19018. }
  19019. }
  19020. // mark line data
  19021. var markLine = seriesOpt.markLine;
  19022. if (markLine && markLine.data) {
  19023. var mlData = markLine.data;
  19024. for (var i = 0; i < mlData.length; i++) {
  19025. if (zrUtil.isArray(mlData[i])) {
  19026. compatItemStyle(mlData[i][0]);
  19027. compatItemStyle(mlData[i][1]);
  19028. }
  19029. else {
  19030. compatItemStyle(mlData[i]);
  19031. }
  19032. }
  19033. }
  19034. }
  19035. };
  19036. /***/ },
  19037. /* 97 */
  19038. /***/ function(module, exports, __webpack_require__) {
  19039. var graphic = __webpack_require__(18);
  19040. var zrUtil = __webpack_require__(4);
  19041. var PI = Math.PI;
  19042. /**
  19043. * @param {module:echarts/ExtensionAPI} api
  19044. * @param {Object} [opts]
  19045. * @param {string} [opts.text]
  19046. * @param {string} [opts.color]
  19047. * @param {string} [opts.textColor]
  19048. * @return {module:zrender/Element}
  19049. */
  19050. module.exports = function (api, opts) {
  19051. opts = opts || {};
  19052. zrUtil.defaults(opts, {
  19053. text: 'loading',
  19054. color: '#c23531',
  19055. textColor: '#000',
  19056. maskColor: 'rgba(255, 255, 255, 0.8)',
  19057. zlevel: 0
  19058. });
  19059. var mask = new graphic.Rect({
  19060. style: {
  19061. fill: opts.maskColor
  19062. },
  19063. zlevel: opts.zlevel,
  19064. z: 10000
  19065. });
  19066. var arc = new graphic.Arc({
  19067. shape: {
  19068. startAngle: -PI / 2,
  19069. endAngle: -PI / 2 + 0.1,
  19070. r: 10
  19071. },
  19072. style: {
  19073. stroke: opts.color,
  19074. lineCap: 'round',
  19075. lineWidth: 5
  19076. },
  19077. zlevel: opts.zlevel,
  19078. z: 10001
  19079. });
  19080. var labelRect = new graphic.Rect({
  19081. style: {
  19082. fill: 'none',
  19083. text: opts.text,
  19084. textPosition: 'right',
  19085. textDistance: 10,
  19086. textFill: opts.textColor
  19087. },
  19088. zlevel: opts.zlevel,
  19089. z: 10001
  19090. });
  19091. arc.animateShape(true)
  19092. .when(1000, {
  19093. endAngle: PI * 3 / 2
  19094. })
  19095. .start('circularInOut');
  19096. arc.animateShape(true)
  19097. .when(1000, {
  19098. startAngle: PI * 3 / 2
  19099. })
  19100. .delay(300)
  19101. .start('circularInOut');
  19102. var group = new graphic.Group();
  19103. group.add(arc);
  19104. group.add(labelRect);
  19105. group.add(mask);
  19106. // Inject resize
  19107. group.resize = function () {
  19108. var cx = api.getWidth() / 2;
  19109. var cy = api.getHeight() / 2;
  19110. arc.setShape({
  19111. cx: cx,
  19112. cy: cy
  19113. });
  19114. var r = arc.shape.r;
  19115. labelRect.setShape({
  19116. x: cx - r,
  19117. y: cy - r,
  19118. width: r * 2,
  19119. height: r * 2
  19120. });
  19121. mask.setShape({
  19122. x: 0,
  19123. y: 0,
  19124. width: api.getWidth(),
  19125. height: api.getHeight()
  19126. });
  19127. };
  19128. group.resize();
  19129. return group;
  19130. };
  19131. /***/ },
  19132. /* 98 */
  19133. /***/ function(module, exports, __webpack_require__) {
  19134. /* WEBPACK VAR INJECTION */(function(global) {/**
  19135. * List for data storage
  19136. * @module echarts/data/List
  19137. */
  19138. var UNDEFINED = 'undefined';
  19139. var globalObj = typeof window === 'undefined' ? global : window;
  19140. var Float64Array = typeof globalObj.Float64Array === UNDEFINED
  19141. ? Array : globalObj.Float64Array;
  19142. var Int32Array = typeof globalObj.Int32Array === UNDEFINED
  19143. ? Array : globalObj.Int32Array;
  19144. var dataCtors = {
  19145. 'float': Float64Array,
  19146. 'int': Int32Array,
  19147. // Ordinal data type can be string or int
  19148. 'ordinal': Array,
  19149. 'number': Array,
  19150. 'time': Array
  19151. };
  19152. var Model = __webpack_require__(12);
  19153. var DataDiffer = __webpack_require__(99);
  19154. var zrUtil = __webpack_require__(4);
  19155. var modelUtil = __webpack_require__(5);
  19156. var isObject = zrUtil.isObject;
  19157. var TRANSFERABLE_PROPERTIES = [
  19158. 'stackedOn', 'hasItemOption', '_nameList', '_idList', '_rawData'
  19159. ];
  19160. function transferProperties(a, b) {
  19161. zrUtil.each(TRANSFERABLE_PROPERTIES.concat(b.__wrappedMethods || []), function (propName) {
  19162. if (b.hasOwnProperty(propName)) {
  19163. a[propName] = b[propName];
  19164. }
  19165. });
  19166. a.__wrappedMethods = b.__wrappedMethods;
  19167. }
  19168. function DefaultDataProvider(dataArray) {
  19169. this._array = dataArray || [];
  19170. }
  19171. DefaultDataProvider.prototype.pure = false;
  19172. DefaultDataProvider.prototype.count = function () {
  19173. return this._array.length;
  19174. };
  19175. DefaultDataProvider.prototype.getItem = function (idx) {
  19176. return this._array[idx];
  19177. };
  19178. /**
  19179. * @constructor
  19180. * @alias module:echarts/data/List
  19181. *
  19182. * @param {Array.<string|Object>} dimensions
  19183. * For example, ['someDimName', {name: 'someDimName', type: 'someDimType'}, ...].
  19184. * Dimensions should be concrete names like x, y, z, lng, lat, angle, radius
  19185. * @param {module:echarts/model/Model} hostModel
  19186. */
  19187. var List = function (dimensions, hostModel) {
  19188. dimensions = dimensions || ['x', 'y'];
  19189. var dimensionInfos = {};
  19190. var dimensionNames = [];
  19191. for (var i = 0; i < dimensions.length; i++) {
  19192. var dimensionName;
  19193. var dimensionInfo = {};
  19194. if (typeof dimensions[i] === 'string') {
  19195. dimensionName = dimensions[i];
  19196. dimensionInfo = {
  19197. name: dimensionName,
  19198. coordDim: dimensionName,
  19199. coordDimIndex: 0,
  19200. stackable: false,
  19201. // Type can be 'float', 'int', 'number'
  19202. // Default is number, Precision of float may not enough
  19203. type: 'number'
  19204. };
  19205. }
  19206. else {
  19207. dimensionInfo = dimensions[i];
  19208. dimensionName = dimensionInfo.name;
  19209. dimensionInfo.type = dimensionInfo.type || 'number';
  19210. if (!dimensionInfo.coordDim) {
  19211. dimensionInfo.coordDim = dimensionName;
  19212. dimensionInfo.coordDimIndex = 0;
  19213. }
  19214. }
  19215. dimensionInfo.otherDims = dimensionInfo.otherDims || {};
  19216. dimensionNames.push(dimensionName);
  19217. dimensionInfos[dimensionName] = dimensionInfo;
  19218. }
  19219. /**
  19220. * @readOnly
  19221. * @type {Array.<string>}
  19222. */
  19223. this.dimensions = dimensionNames;
  19224. /**
  19225. * Infomation of each data dimension, like data type.
  19226. * @type {Object}
  19227. */
  19228. this._dimensionInfos = dimensionInfos;
  19229. /**
  19230. * @type {module:echarts/model/Model}
  19231. */
  19232. this.hostModel = hostModel;
  19233. /**
  19234. * @type {module:echarts/model/Model}
  19235. */
  19236. this.dataType;
  19237. /**
  19238. * Indices stores the indices of data subset after filtered.
  19239. * This data subset will be used in chart.
  19240. * @type {Array.<number>}
  19241. * @readOnly
  19242. */
  19243. this.indices = [];
  19244. /**
  19245. * Data storage
  19246. * @type {Object.<key, TypedArray|Array>}
  19247. * @private
  19248. */
  19249. this._storage = {};
  19250. /**
  19251. * @type {Array.<string>}
  19252. */
  19253. this._nameList = [];
  19254. /**
  19255. * @type {Array.<string>}
  19256. */
  19257. this._idList = [];
  19258. /**
  19259. * Models of data option is stored sparse for optimizing memory cost
  19260. * @type {Array.<module:echarts/model/Model>}
  19261. * @private
  19262. */
  19263. this._optionModels = [];
  19264. /**
  19265. * @param {module:echarts/data/List}
  19266. */
  19267. this.stackedOn = null;
  19268. /**
  19269. * Global visual properties after visual coding
  19270. * @type {Object}
  19271. * @private
  19272. */
  19273. this._visual = {};
  19274. /**
  19275. * Globel layout properties.
  19276. * @type {Object}
  19277. * @private
  19278. */
  19279. this._layout = {};
  19280. /**
  19281. * Item visual properties after visual coding
  19282. * @type {Array.<Object>}
  19283. * @private
  19284. */
  19285. this._itemVisuals = [];
  19286. /**
  19287. * Item layout properties after layout
  19288. * @type {Array.<Object>}
  19289. * @private
  19290. */
  19291. this._itemLayouts = [];
  19292. /**
  19293. * Graphic elemnents
  19294. * @type {Array.<module:zrender/Element>}
  19295. * @private
  19296. */
  19297. this._graphicEls = [];
  19298. /**
  19299. * @type {Array.<Array|Object>}
  19300. * @private
  19301. */
  19302. this._rawData;
  19303. /**
  19304. * @type {Object}
  19305. * @private
  19306. */
  19307. this._extent;
  19308. };
  19309. var listProto = List.prototype;
  19310. listProto.type = 'list';
  19311. /**
  19312. * If each data item has it's own option
  19313. * @type {boolean}
  19314. */
  19315. listProto.hasItemOption = true;
  19316. /**
  19317. * Get dimension name
  19318. * @param {string|number} dim
  19319. * Dimension can be concrete names like x, y, z, lng, lat, angle, radius
  19320. * Or a ordinal number. For example getDimensionInfo(0) will return 'x' or 'lng' or 'radius'
  19321. * @return {string} Concrete dim name.
  19322. */
  19323. listProto.getDimension = function (dim) {
  19324. if (!isNaN(dim)) {
  19325. dim = this.dimensions[dim] || dim;
  19326. }
  19327. return dim;
  19328. };
  19329. /**
  19330. * Get type and stackable info of particular dimension
  19331. * @param {string|number} dim
  19332. * Dimension can be concrete names like x, y, z, lng, lat, angle, radius
  19333. * Or a ordinal number. For example getDimensionInfo(0) will return 'x' or 'lng' or 'radius'
  19334. */
  19335. listProto.getDimensionInfo = function (dim) {
  19336. return zrUtil.clone(this._dimensionInfos[this.getDimension(dim)]);
  19337. };
  19338. /**
  19339. * Initialize from data
  19340. * @param {Array.<Object|number|Array>} data
  19341. * @param {Array.<string>} [nameList]
  19342. * @param {Function} [dimValueGetter] (dataItem, dimName, dataIndex, dimIndex) => number
  19343. */
  19344. listProto.initData = function (data, nameList, dimValueGetter) {
  19345. data = data || [];
  19346. var isDataArray = zrUtil.isArray(data);
  19347. if (isDataArray) {
  19348. data = new DefaultDataProvider(data);
  19349. }
  19350. if (true) {
  19351. if (!isDataArray && (typeof data.getItem != 'function' || typeof data.count != 'function')) {
  19352. throw new Error('Inavlid data provider.');
  19353. }
  19354. }
  19355. this._rawData = data;
  19356. // Clear
  19357. var storage = this._storage = {};
  19358. var indices = this.indices = [];
  19359. var dimensions = this.dimensions;
  19360. var dimensionInfoMap = this._dimensionInfos;
  19361. var size = data.count();
  19362. var idList = [];
  19363. var nameRepeatCount = {};
  19364. var nameDimIdx;
  19365. nameList = nameList || [];
  19366. // Init storage
  19367. for (var i = 0; i < dimensions.length; i++) {
  19368. var dimInfo = dimensionInfoMap[dimensions[i]];
  19369. dimInfo.otherDims.itemName === 0 && (nameDimIdx = i);
  19370. var DataCtor = dataCtors[dimInfo.type];
  19371. storage[dimensions[i]] = new DataCtor(size);
  19372. }
  19373. var self = this;
  19374. if (!dimValueGetter) {
  19375. self.hasItemOption = false;
  19376. }
  19377. // Default dim value getter
  19378. dimValueGetter = dimValueGetter || function (dataItem, dimName, dataIndex, dimIndex) {
  19379. var value = modelUtil.getDataItemValue(dataItem);
  19380. // If any dataItem is like { value: 10 }
  19381. if (modelUtil.isDataItemOption(dataItem)) {
  19382. self.hasItemOption = true;
  19383. }
  19384. return modelUtil.converDataValue(
  19385. (value instanceof Array)
  19386. ? value[dimIndex]
  19387. // If value is a single number or something else not array.
  19388. : value,
  19389. dimensionInfoMap[dimName]
  19390. );
  19391. };
  19392. for (var i = 0; i < size; i++) {
  19393. // NOTICE: Try not to write things into dataItem
  19394. var dataItem = data.getItem(i);
  19395. // Each data item is value
  19396. // [1, 2]
  19397. // 2
  19398. // Bar chart, line chart which uses category axis
  19399. // only gives the 'y' value. 'x' value is the indices of cateogry
  19400. // Use a tempValue to normalize the value to be a (x, y) value
  19401. // Store the data by dimensions
  19402. for (var k = 0; k < dimensions.length; k++) {
  19403. var dim = dimensions[k];
  19404. var dimStorage = storage[dim];
  19405. // PENDING NULL is empty or zero
  19406. dimStorage[i] = dimValueGetter(dataItem, dim, i, k);
  19407. }
  19408. indices.push(i);
  19409. }
  19410. // Use the name in option and create id
  19411. for (var i = 0; i < size; i++) {
  19412. var dataItem = data.getItem(i);
  19413. if (!nameList[i] && dataItem) {
  19414. if (dataItem.name != null) {
  19415. nameList[i] = dataItem.name;
  19416. }
  19417. else if (nameDimIdx != null) {
  19418. nameList[i] = storage[dimensions[nameDimIdx]][i];
  19419. }
  19420. }
  19421. var name = nameList[i] || '';
  19422. // Try using the id in option
  19423. var id = dataItem && dataItem.id;
  19424. if (!id && name) {
  19425. // Use name as id and add counter to avoid same name
  19426. nameRepeatCount[name] = nameRepeatCount[name] || 0;
  19427. id = name;
  19428. if (nameRepeatCount[name] > 0) {
  19429. id += '__ec__' + nameRepeatCount[name];
  19430. }
  19431. nameRepeatCount[name]++;
  19432. }
  19433. id && (idList[i] = id);
  19434. }
  19435. this._nameList = nameList;
  19436. this._idList = idList;
  19437. };
  19438. /**
  19439. * @return {number}
  19440. */
  19441. listProto.count = function () {
  19442. return this.indices.length;
  19443. };
  19444. /**
  19445. * Get value. Return NaN if idx is out of range.
  19446. * @param {string} dim Dim must be concrete name.
  19447. * @param {number} idx
  19448. * @param {boolean} stack
  19449. * @return {number}
  19450. */
  19451. listProto.get = function (dim, idx, stack) {
  19452. var storage = this._storage;
  19453. var dataIndex = this.indices[idx];
  19454. // If value not exists
  19455. if (dataIndex == null || !storage[dim]) {
  19456. return NaN;
  19457. }
  19458. var value = storage[dim][dataIndex];
  19459. // FIXME ordinal data type is not stackable
  19460. if (stack) {
  19461. var dimensionInfo = this._dimensionInfos[dim];
  19462. if (dimensionInfo && dimensionInfo.stackable) {
  19463. var stackedOn = this.stackedOn;
  19464. while (stackedOn) {
  19465. // Get no stacked data of stacked on
  19466. var stackedValue = stackedOn.get(dim, idx);
  19467. // Considering positive stack, negative stack and empty data
  19468. if ((value >= 0 && stackedValue > 0) // Positive stack
  19469. || (value <= 0 && stackedValue < 0) // Negative stack
  19470. ) {
  19471. value += stackedValue;
  19472. }
  19473. stackedOn = stackedOn.stackedOn;
  19474. }
  19475. }
  19476. }
  19477. return value;
  19478. };
  19479. /**
  19480. * Get value for multi dimensions.
  19481. * @param {Array.<string>} [dimensions] If ignored, using all dimensions.
  19482. * @param {number} idx
  19483. * @param {boolean} stack
  19484. * @return {number}
  19485. */
  19486. listProto.getValues = function (dimensions, idx, stack) {
  19487. var values = [];
  19488. if (!zrUtil.isArray(dimensions)) {
  19489. stack = idx;
  19490. idx = dimensions;
  19491. dimensions = this.dimensions;
  19492. }
  19493. for (var i = 0, len = dimensions.length; i < len; i++) {
  19494. values.push(this.get(dimensions[i], idx, stack));
  19495. }
  19496. return values;
  19497. };
  19498. /**
  19499. * If value is NaN. Inlcuding '-'
  19500. * @param {string} dim
  19501. * @param {number} idx
  19502. * @return {number}
  19503. */
  19504. listProto.hasValue = function (idx) {
  19505. var dimensions = this.dimensions;
  19506. var dimensionInfos = this._dimensionInfos;
  19507. for (var i = 0, len = dimensions.length; i < len; i++) {
  19508. if (
  19509. // Ordinal type can be string or number
  19510. dimensionInfos[dimensions[i]].type !== 'ordinal'
  19511. && isNaN(this.get(dimensions[i], idx))
  19512. ) {
  19513. return false;
  19514. }
  19515. }
  19516. return true;
  19517. };
  19518. /**
  19519. * Get extent of data in one dimension
  19520. * @param {string} dim
  19521. * @param {boolean} stack
  19522. * @param {Function} filter
  19523. */
  19524. listProto.getDataExtent = function (dim, stack, filter) {
  19525. dim = this.getDimension(dim);
  19526. var dimData = this._storage[dim];
  19527. var dimInfo = this.getDimensionInfo(dim);
  19528. stack = (dimInfo && dimInfo.stackable) && stack;
  19529. var dimExtent = (this._extent || (this._extent = {}))[dim + (!!stack)];
  19530. var value;
  19531. if (dimExtent) {
  19532. return dimExtent;
  19533. }
  19534. // var dimInfo = this._dimensionInfos[dim];
  19535. if (dimData) {
  19536. var min = Infinity;
  19537. var max = -Infinity;
  19538. // var isOrdinal = dimInfo.type === 'ordinal';
  19539. for (var i = 0, len = this.count(); i < len; i++) {
  19540. value = this.get(dim, i, stack);
  19541. // FIXME
  19542. // if (isOrdinal && typeof value === 'string') {
  19543. // value = zrUtil.indexOf(dimData, value);
  19544. // }
  19545. if (!filter || filter(value, dim, i)) {
  19546. value < min && (min = value);
  19547. value > max && (max = value);
  19548. }
  19549. }
  19550. return (this._extent[dim + !!stack] = [min, max]);
  19551. }
  19552. else {
  19553. return [Infinity, -Infinity];
  19554. }
  19555. };
  19556. /**
  19557. * Get sum of data in one dimension
  19558. * @param {string} dim
  19559. * @param {boolean} stack
  19560. */
  19561. listProto.getSum = function (dim, stack) {
  19562. var dimData = this._storage[dim];
  19563. var sum = 0;
  19564. if (dimData) {
  19565. for (var i = 0, len = this.count(); i < len; i++) {
  19566. var value = this.get(dim, i, stack);
  19567. if (!isNaN(value)) {
  19568. sum += value;
  19569. }
  19570. }
  19571. }
  19572. return sum;
  19573. };
  19574. /**
  19575. * Retreive the index with given value
  19576. * @param {number} idx
  19577. * @param {number} value
  19578. * @return {number}
  19579. */
  19580. // FIXME Precision of float value
  19581. listProto.indexOf = function (dim, value) {
  19582. var storage = this._storage;
  19583. var dimData = storage[dim];
  19584. var indices = this.indices;
  19585. if (dimData) {
  19586. for (var i = 0, len = indices.length; i < len; i++) {
  19587. var rawIndex = indices[i];
  19588. if (dimData[rawIndex] === value) {
  19589. return i;
  19590. }
  19591. }
  19592. }
  19593. return -1;
  19594. };
  19595. /**
  19596. * Retreive the index with given name
  19597. * @param {number} idx
  19598. * @param {number} name
  19599. * @return {number}
  19600. */
  19601. listProto.indexOfName = function (name) {
  19602. var indices = this.indices;
  19603. var nameList = this._nameList;
  19604. for (var i = 0, len = indices.length; i < len; i++) {
  19605. var rawIndex = indices[i];
  19606. if (nameList[rawIndex] === name) {
  19607. return i;
  19608. }
  19609. }
  19610. return -1;
  19611. };
  19612. /**
  19613. * Retreive the index with given raw data index
  19614. * @param {number} idx
  19615. * @param {number} name
  19616. * @return {number}
  19617. */
  19618. listProto.indexOfRawIndex = function (rawIndex) {
  19619. // Indices are ascending
  19620. var indices = this.indices;
  19621. // If rawIndex === dataIndex
  19622. var rawDataIndex = indices[rawIndex];
  19623. if (rawDataIndex != null && rawDataIndex === rawIndex) {
  19624. return rawIndex;
  19625. }
  19626. var left = 0;
  19627. var right = indices.length - 1;
  19628. while (left <= right) {
  19629. var mid = (left + right) / 2 | 0;
  19630. if (indices[mid] < rawIndex) {
  19631. left = mid + 1;
  19632. }
  19633. else if (indices[mid] > rawIndex) {
  19634. right = mid - 1;
  19635. }
  19636. else {
  19637. return mid;
  19638. }
  19639. }
  19640. return -1;
  19641. };
  19642. /**
  19643. * Retreive the index of nearest value
  19644. * @param {string} dim
  19645. * @param {number} value
  19646. * @param {boolean} stack If given value is after stacked
  19647. * @param {number} [maxDistance=Infinity]
  19648. * @return {Array.<number>} Considere multiple points has the same value.
  19649. */
  19650. listProto.indicesOfNearest = function (dim, value, stack, maxDistance) {
  19651. var storage = this._storage;
  19652. var dimData = storage[dim];
  19653. var nearestIndices = [];
  19654. if (!dimData) {
  19655. return nearestIndices;
  19656. }
  19657. if (maxDistance == null) {
  19658. maxDistance = Infinity;
  19659. }
  19660. var minDist = Number.MAX_VALUE;
  19661. var minDiff = -1;
  19662. for (var i = 0, len = this.count(); i < len; i++) {
  19663. var diff = value - this.get(dim, i, stack);
  19664. var dist = Math.abs(diff);
  19665. if (diff <= maxDistance && dist <= minDist) {
  19666. // For the case of two data are same on xAxis, which has sequence data.
  19667. // Show the nearest index
  19668. // https://github.com/ecomfe/echarts/issues/2869
  19669. if (dist < minDist || (diff >= 0 && minDiff < 0)) {
  19670. minDist = dist;
  19671. minDiff = diff;
  19672. nearestIndices.length = 0;
  19673. }
  19674. nearestIndices.push(i);
  19675. }
  19676. }
  19677. return nearestIndices;
  19678. };
  19679. /**
  19680. * Get raw data index
  19681. * @param {number} idx
  19682. * @return {number}
  19683. */
  19684. listProto.getRawIndex = function (idx) {
  19685. var rawIdx = this.indices[idx];
  19686. return rawIdx == null ? -1 : rawIdx;
  19687. };
  19688. /**
  19689. * Get raw data item
  19690. * @param {number} idx
  19691. * @return {number}
  19692. */
  19693. listProto.getRawDataItem = function (idx) {
  19694. return this._rawData.getItem(this.getRawIndex(idx));
  19695. };
  19696. /**
  19697. * @param {number} idx
  19698. * @param {boolean} [notDefaultIdx=false]
  19699. * @return {string}
  19700. */
  19701. listProto.getName = function (idx) {
  19702. return this._nameList[this.indices[idx]] || '';
  19703. };
  19704. /**
  19705. * @param {number} idx
  19706. * @param {boolean} [notDefaultIdx=false]
  19707. * @return {string}
  19708. */
  19709. listProto.getId = function (idx) {
  19710. return this._idList[this.indices[idx]] || (this.getRawIndex(idx) + '');
  19711. };
  19712. function normalizeDimensions(dimensions) {
  19713. if (!zrUtil.isArray(dimensions)) {
  19714. dimensions = [dimensions];
  19715. }
  19716. return dimensions;
  19717. }
  19718. /**
  19719. * Data iteration
  19720. * @param {string|Array.<string>}
  19721. * @param {Function} cb
  19722. * @param {boolean} [stack=false]
  19723. * @param {*} [context=this]
  19724. *
  19725. * @example
  19726. * list.each('x', function (x, idx) {});
  19727. * list.each(['x', 'y'], function (x, y, idx) {});
  19728. * list.each(function (idx) {})
  19729. */
  19730. listProto.each = function (dims, cb, stack, context) {
  19731. if (typeof dims === 'function') {
  19732. context = stack;
  19733. stack = cb;
  19734. cb = dims;
  19735. dims = [];
  19736. }
  19737. dims = zrUtil.map(normalizeDimensions(dims), this.getDimension, this);
  19738. var value = [];
  19739. var dimSize = dims.length;
  19740. var indices = this.indices;
  19741. context = context || this;
  19742. for (var i = 0; i < indices.length; i++) {
  19743. // Simple optimization
  19744. switch (dimSize) {
  19745. case 0:
  19746. cb.call(context, i);
  19747. break;
  19748. case 1:
  19749. cb.call(context, this.get(dims[0], i, stack), i);
  19750. break;
  19751. case 2:
  19752. cb.call(context, this.get(dims[0], i, stack), this.get(dims[1], i, stack), i);
  19753. break;
  19754. default:
  19755. for (var k = 0; k < dimSize; k++) {
  19756. value[k] = this.get(dims[k], i, stack);
  19757. }
  19758. // Index
  19759. value[k] = i;
  19760. cb.apply(context, value);
  19761. }
  19762. }
  19763. };
  19764. /**
  19765. * Data filter
  19766. * @param {string|Array.<string>}
  19767. * @param {Function} cb
  19768. * @param {boolean} [stack=false]
  19769. * @param {*} [context=this]
  19770. */
  19771. listProto.filterSelf = function (dimensions, cb, stack, context) {
  19772. if (typeof dimensions === 'function') {
  19773. context = stack;
  19774. stack = cb;
  19775. cb = dimensions;
  19776. dimensions = [];
  19777. }
  19778. dimensions = zrUtil.map(
  19779. normalizeDimensions(dimensions), this.getDimension, this
  19780. );
  19781. var newIndices = [];
  19782. var value = [];
  19783. var dimSize = dimensions.length;
  19784. var indices = this.indices;
  19785. context = context || this;
  19786. for (var i = 0; i < indices.length; i++) {
  19787. var keep;
  19788. // Simple optimization
  19789. if (!dimSize) {
  19790. keep = cb.call(context, i);
  19791. }
  19792. else if (dimSize === 1) {
  19793. keep = cb.call(
  19794. context, this.get(dimensions[0], i, stack), i
  19795. );
  19796. }
  19797. else {
  19798. for (var k = 0; k < dimSize; k++) {
  19799. value[k] = this.get(dimensions[k], i, stack);
  19800. }
  19801. value[k] = i;
  19802. keep = cb.apply(context, value);
  19803. }
  19804. if (keep) {
  19805. newIndices.push(indices[i]);
  19806. }
  19807. }
  19808. this.indices = newIndices;
  19809. // Reset data extent
  19810. this._extent = {};
  19811. return this;
  19812. };
  19813. /**
  19814. * Data mapping to a plain array
  19815. * @param {string|Array.<string>} [dimensions]
  19816. * @param {Function} cb
  19817. * @param {boolean} [stack=false]
  19818. * @param {*} [context=this]
  19819. * @return {Array}
  19820. */
  19821. listProto.mapArray = function (dimensions, cb, stack, context) {
  19822. if (typeof dimensions === 'function') {
  19823. context = stack;
  19824. stack = cb;
  19825. cb = dimensions;
  19826. dimensions = [];
  19827. }
  19828. var result = [];
  19829. this.each(dimensions, function () {
  19830. result.push(cb && cb.apply(this, arguments));
  19831. }, stack, context);
  19832. return result;
  19833. };
  19834. function cloneListForMapAndSample(original, excludeDimensions) {
  19835. var allDimensions = original.dimensions;
  19836. var list = new List(
  19837. zrUtil.map(allDimensions, original.getDimensionInfo, original),
  19838. original.hostModel
  19839. );
  19840. // FIXME If needs stackedOn, value may already been stacked
  19841. transferProperties(list, original);
  19842. var storage = list._storage = {};
  19843. var originalStorage = original._storage;
  19844. // Init storage
  19845. for (var i = 0; i < allDimensions.length; i++) {
  19846. var dim = allDimensions[i];
  19847. var dimStore = originalStorage[dim];
  19848. if (zrUtil.indexOf(excludeDimensions, dim) >= 0) {
  19849. storage[dim] = new dimStore.constructor(
  19850. originalStorage[dim].length
  19851. );
  19852. }
  19853. else {
  19854. // Direct reference for other dimensions
  19855. storage[dim] = originalStorage[dim];
  19856. }
  19857. }
  19858. return list;
  19859. }
  19860. /**
  19861. * Data mapping to a new List with given dimensions
  19862. * @param {string|Array.<string>} dimensions
  19863. * @param {Function} cb
  19864. * @param {boolean} [stack=false]
  19865. * @param {*} [context=this]
  19866. * @return {Array}
  19867. */
  19868. listProto.map = function (dimensions, cb, stack, context) {
  19869. dimensions = zrUtil.map(
  19870. normalizeDimensions(dimensions), this.getDimension, this
  19871. );
  19872. var list = cloneListForMapAndSample(this, dimensions);
  19873. // Following properties are all immutable.
  19874. // So we can reference to the same value
  19875. var indices = list.indices = this.indices;
  19876. var storage = list._storage;
  19877. var tmpRetValue = [];
  19878. this.each(dimensions, function () {
  19879. var idx = arguments[arguments.length - 1];
  19880. var retValue = cb && cb.apply(this, arguments);
  19881. if (retValue != null) {
  19882. // a number
  19883. if (typeof retValue === 'number') {
  19884. tmpRetValue[0] = retValue;
  19885. retValue = tmpRetValue;
  19886. }
  19887. for (var i = 0; i < retValue.length; i++) {
  19888. var dim = dimensions[i];
  19889. var dimStore = storage[dim];
  19890. var rawIdx = indices[idx];
  19891. if (dimStore) {
  19892. dimStore[rawIdx] = retValue[i];
  19893. }
  19894. }
  19895. }
  19896. }, stack, context);
  19897. return list;
  19898. };
  19899. /**
  19900. * Large data down sampling on given dimension
  19901. * @param {string} dimension
  19902. * @param {number} rate
  19903. * @param {Function} sampleValue
  19904. * @param {Function} sampleIndex Sample index for name and id
  19905. */
  19906. listProto.downSample = function (dimension, rate, sampleValue, sampleIndex) {
  19907. var list = cloneListForMapAndSample(this, [dimension]);
  19908. var storage = this._storage;
  19909. var targetStorage = list._storage;
  19910. var originalIndices = this.indices;
  19911. var indices = list.indices = [];
  19912. var frameValues = [];
  19913. var frameIndices = [];
  19914. var frameSize = Math.floor(1 / rate);
  19915. var dimStore = targetStorage[dimension];
  19916. var len = this.count();
  19917. // Copy data from original data
  19918. for (var i = 0; i < storage[dimension].length; i++) {
  19919. targetStorage[dimension][i] = storage[dimension][i];
  19920. }
  19921. for (var i = 0; i < len; i += frameSize) {
  19922. // Last frame
  19923. if (frameSize > len - i) {
  19924. frameSize = len - i;
  19925. frameValues.length = frameSize;
  19926. }
  19927. for (var k = 0; k < frameSize; k++) {
  19928. var idx = originalIndices[i + k];
  19929. frameValues[k] = dimStore[idx];
  19930. frameIndices[k] = idx;
  19931. }
  19932. var value = sampleValue(frameValues);
  19933. var idx = frameIndices[sampleIndex(frameValues, value) || 0];
  19934. // Only write value on the filtered data
  19935. dimStore[idx] = value;
  19936. indices.push(idx);
  19937. }
  19938. return list;
  19939. };
  19940. /**
  19941. * Get model of one data item.
  19942. *
  19943. * @param {number} idx
  19944. */
  19945. // FIXME Model proxy ?
  19946. listProto.getItemModel = function (idx) {
  19947. var hostModel = this.hostModel;
  19948. idx = this.indices[idx];
  19949. return new Model(this._rawData.getItem(idx), hostModel, hostModel && hostModel.ecModel);
  19950. };
  19951. /**
  19952. * Create a data differ
  19953. * @param {module:echarts/data/List} otherList
  19954. * @return {module:echarts/data/DataDiffer}
  19955. */
  19956. listProto.diff = function (otherList) {
  19957. var idList = this._idList;
  19958. var otherIdList = otherList && otherList._idList;
  19959. var val;
  19960. // Use prefix to avoid index to be the same as otherIdList[idx],
  19961. // which will cause weird udpate animation.
  19962. var prefix = 'e\0\0';
  19963. return new DataDiffer(
  19964. otherList ? otherList.indices : [],
  19965. this.indices,
  19966. function (idx) {
  19967. return (val = otherIdList[idx]) != null ? val : prefix + idx;
  19968. },
  19969. function (idx) {
  19970. return (val = idList[idx]) != null ? val : prefix + idx;
  19971. }
  19972. );
  19973. };
  19974. /**
  19975. * Get visual property.
  19976. * @param {string} key
  19977. */
  19978. listProto.getVisual = function (key) {
  19979. var visual = this._visual;
  19980. return visual && visual[key];
  19981. };
  19982. /**
  19983. * Set visual property
  19984. * @param {string|Object} key
  19985. * @param {*} [value]
  19986. *
  19987. * @example
  19988. * setVisual('color', color);
  19989. * setVisual({
  19990. * 'color': color
  19991. * });
  19992. */
  19993. listProto.setVisual = function (key, val) {
  19994. if (isObject(key)) {
  19995. for (var name in key) {
  19996. if (key.hasOwnProperty(name)) {
  19997. this.setVisual(name, key[name]);
  19998. }
  19999. }
  20000. return;
  20001. }
  20002. this._visual = this._visual || {};
  20003. this._visual[key] = val;
  20004. };
  20005. /**
  20006. * Set layout property.
  20007. * @param {string} key
  20008. * @param {*} [val]
  20009. */
  20010. listProto.setLayout = function (key, val) {
  20011. if (isObject(key)) {
  20012. for (var name in key) {
  20013. if (key.hasOwnProperty(name)) {
  20014. this.setLayout(name, key[name]);
  20015. }
  20016. }
  20017. return;
  20018. }
  20019. this._layout[key] = val;
  20020. };
  20021. /**
  20022. * Get layout property.
  20023. * @param {string} key.
  20024. * @return {*}
  20025. */
  20026. listProto.getLayout = function (key) {
  20027. return this._layout[key];
  20028. };
  20029. /**
  20030. * Get layout of single data item
  20031. * @param {number} idx
  20032. */
  20033. listProto.getItemLayout = function (idx) {
  20034. return this._itemLayouts[idx];
  20035. };
  20036. /**
  20037. * Set layout of single data item
  20038. * @param {number} idx
  20039. * @param {Object} layout
  20040. * @param {boolean=} [merge=false]
  20041. */
  20042. listProto.setItemLayout = function (idx, layout, merge) {
  20043. this._itemLayouts[idx] = merge
  20044. ? zrUtil.extend(this._itemLayouts[idx] || {}, layout)
  20045. : layout;
  20046. };
  20047. /**
  20048. * Clear all layout of single data item
  20049. */
  20050. listProto.clearItemLayouts = function () {
  20051. this._itemLayouts.length = 0;
  20052. };
  20053. /**
  20054. * Get visual property of single data item
  20055. * @param {number} idx
  20056. * @param {string} key
  20057. * @param {boolean} [ignoreParent=false]
  20058. */
  20059. listProto.getItemVisual = function (idx, key, ignoreParent) {
  20060. var itemVisual = this._itemVisuals[idx];
  20061. var val = itemVisual && itemVisual[key];
  20062. if (val == null && !ignoreParent) {
  20063. // Use global visual property
  20064. return this.getVisual(key);
  20065. }
  20066. return val;
  20067. };
  20068. /**
  20069. * Set visual property of single data item
  20070. *
  20071. * @param {number} idx
  20072. * @param {string|Object} key
  20073. * @param {*} [value]
  20074. *
  20075. * @example
  20076. * setItemVisual(0, 'color', color);
  20077. * setItemVisual(0, {
  20078. * 'color': color
  20079. * });
  20080. */
  20081. listProto.setItemVisual = function (idx, key, value) {
  20082. var itemVisual = this._itemVisuals[idx] || {};
  20083. this._itemVisuals[idx] = itemVisual;
  20084. if (isObject(key)) {
  20085. for (var name in key) {
  20086. if (key.hasOwnProperty(name)) {
  20087. itemVisual[name] = key[name];
  20088. }
  20089. }
  20090. return;
  20091. }
  20092. itemVisual[key] = value;
  20093. };
  20094. /**
  20095. * Clear itemVisuals and list visual.
  20096. */
  20097. listProto.clearAllVisual = function () {
  20098. this._visual = {};
  20099. this._itemVisuals = [];
  20100. };
  20101. var setItemDataAndSeriesIndex = function (child) {
  20102. child.seriesIndex = this.seriesIndex;
  20103. child.dataIndex = this.dataIndex;
  20104. child.dataType = this.dataType;
  20105. };
  20106. /**
  20107. * Set graphic element relative to data. It can be set as null
  20108. * @param {number} idx
  20109. * @param {module:zrender/Element} [el]
  20110. */
  20111. listProto.setItemGraphicEl = function (idx, el) {
  20112. var hostModel = this.hostModel;
  20113. if (el) {
  20114. // Add data index and series index for indexing the data by element
  20115. // Useful in tooltip
  20116. el.dataIndex = idx;
  20117. el.dataType = this.dataType;
  20118. el.seriesIndex = hostModel && hostModel.seriesIndex;
  20119. if (el.type === 'group') {
  20120. el.traverse(setItemDataAndSeriesIndex, el);
  20121. }
  20122. }
  20123. this._graphicEls[idx] = el;
  20124. };
  20125. /**
  20126. * @param {number} idx
  20127. * @return {module:zrender/Element}
  20128. */
  20129. listProto.getItemGraphicEl = function (idx) {
  20130. return this._graphicEls[idx];
  20131. };
  20132. /**
  20133. * @param {Function} cb
  20134. * @param {*} context
  20135. */
  20136. listProto.eachItemGraphicEl = function (cb, context) {
  20137. zrUtil.each(this._graphicEls, function (el, idx) {
  20138. if (el) {
  20139. cb && cb.call(context, el, idx);
  20140. }
  20141. });
  20142. };
  20143. /**
  20144. * Shallow clone a new list except visual and layout properties, and graph elements.
  20145. * New list only change the indices.
  20146. */
  20147. listProto.cloneShallow = function () {
  20148. var dimensionInfoList = zrUtil.map(this.dimensions, this.getDimensionInfo, this);
  20149. var list = new List(dimensionInfoList, this.hostModel);
  20150. // FIXME
  20151. list._storage = this._storage;
  20152. transferProperties(list, this);
  20153. // Clone will not change the data extent and indices
  20154. list.indices = this.indices.slice();
  20155. if (this._extent) {
  20156. list._extent = zrUtil.extend({}, this._extent);
  20157. }
  20158. return list;
  20159. };
  20160. /**
  20161. * Wrap some method to add more feature
  20162. * @param {string} methodName
  20163. * @param {Function} injectFunction
  20164. */
  20165. listProto.wrapMethod = function (methodName, injectFunction) {
  20166. var originalMethod = this[methodName];
  20167. if (typeof originalMethod !== 'function') {
  20168. return;
  20169. }
  20170. this.__wrappedMethods = this.__wrappedMethods || [];
  20171. this.__wrappedMethods.push(methodName);
  20172. this[methodName] = function () {
  20173. var res = originalMethod.apply(this, arguments);
  20174. return injectFunction.apply(this, [res].concat(zrUtil.slice(arguments)));
  20175. };
  20176. };
  20177. // Methods that create a new list based on this list should be listed here.
  20178. // Notice that those method should `RETURN` the new list.
  20179. listProto.TRANSFERABLE_METHODS = ['cloneShallow', 'downSample', 'map'];
  20180. // Methods that change indices of this list should be listed here.
  20181. listProto.CHANGABLE_METHODS = ['filterSelf'];
  20182. module.exports = List;
  20183. /* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }())))
  20184. /***/ },
  20185. /* 99 */
  20186. /***/ function(module, exports) {
  20187. 'use strict';
  20188. function defaultKeyGetter(item) {
  20189. return item;
  20190. }
  20191. function DataDiffer(oldArr, newArr, oldKeyGetter, newKeyGetter) {
  20192. this._old = oldArr;
  20193. this._new = newArr;
  20194. this._oldKeyGetter = oldKeyGetter || defaultKeyGetter;
  20195. this._newKeyGetter = newKeyGetter || defaultKeyGetter;
  20196. }
  20197. DataDiffer.prototype = {
  20198. constructor: DataDiffer,
  20199. /**
  20200. * Callback function when add a data
  20201. */
  20202. add: function (func) {
  20203. this._add = func;
  20204. return this;
  20205. },
  20206. /**
  20207. * Callback function when update a data
  20208. */
  20209. update: function (func) {
  20210. this._update = func;
  20211. return this;
  20212. },
  20213. /**
  20214. * Callback function when remove a data
  20215. */
  20216. remove: function (func) {
  20217. this._remove = func;
  20218. return this;
  20219. },
  20220. execute: function () {
  20221. var oldArr = this._old;
  20222. var newArr = this._new;
  20223. var oldKeyGetter = this._oldKeyGetter;
  20224. var newKeyGetter = this._newKeyGetter;
  20225. var oldDataIndexMap = {};
  20226. var newDataIndexMap = {};
  20227. var oldDataKeyArr = [];
  20228. var newDataKeyArr = [];
  20229. var i;
  20230. initIndexMap(oldArr, oldDataIndexMap, oldDataKeyArr, oldKeyGetter);
  20231. initIndexMap(newArr, newDataIndexMap, newDataKeyArr, newKeyGetter);
  20232. // Travel by inverted order to make sure order consistency
  20233. // when duplicate keys exists (consider newDataIndex.pop() below).
  20234. // For performance consideration, these code below do not look neat.
  20235. for (i = 0; i < oldArr.length; i++) {
  20236. var key = oldDataKeyArr[i];
  20237. var idx = newDataIndexMap[key];
  20238. // idx can never be empty array here. see 'set null' logic below.
  20239. if (idx != null) {
  20240. // Consider there is duplicate key (for example, use dataItem.name as key).
  20241. // We should make sure every item in newArr and oldArr can be visited.
  20242. var len = idx.length;
  20243. if (len) {
  20244. len === 1 && (newDataIndexMap[key] = null);
  20245. idx = idx.unshift();
  20246. }
  20247. else {
  20248. newDataIndexMap[key] = null;
  20249. }
  20250. this._update && this._update(idx, i);
  20251. }
  20252. else {
  20253. this._remove && this._remove(i);
  20254. }
  20255. }
  20256. for (var i = 0; i < newDataKeyArr.length; i++) {
  20257. var key = newDataKeyArr[i];
  20258. if (newDataIndexMap.hasOwnProperty(key)) {
  20259. var idx = newDataIndexMap[key];
  20260. if (idx == null) {
  20261. continue;
  20262. }
  20263. // idx can never be empty array here. see 'set null' logic above.
  20264. if (!idx.length) {
  20265. this._add && this._add(idx);
  20266. }
  20267. else {
  20268. for (var j = 0, len = idx.length; j < len; j++) {
  20269. this._add && this._add(idx[j]);
  20270. }
  20271. }
  20272. }
  20273. }
  20274. }
  20275. };
  20276. function initIndexMap(arr, map, keyArr, keyGetter) {
  20277. for (var i = 0; i < arr.length; i++) {
  20278. // Add prefix to avoid conflict with Object.prototype.
  20279. var key = '_ec_' + keyGetter(arr[i], i);
  20280. var existence = map[key];
  20281. if (existence == null) {
  20282. keyArr.push(key);
  20283. map[key] = i;
  20284. }
  20285. else {
  20286. if (!existence.length) {
  20287. map[key] = existence = [existence];
  20288. }
  20289. existence.push(i);
  20290. }
  20291. }
  20292. }
  20293. module.exports = DataDiffer;
  20294. /***/ },
  20295. /* 100 */
  20296. /***/ function(module, exports, __webpack_require__) {
  20297. var numberUtil = __webpack_require__(7);
  20298. var linearMap = numberUtil.linearMap;
  20299. var zrUtil = __webpack_require__(4);
  20300. var axisHelper = __webpack_require__(101);
  20301. function fixExtentWithBands(extent, nTick) {
  20302. var size = extent[1] - extent[0];
  20303. var len = nTick;
  20304. var margin = size / len / 2;
  20305. extent[0] += margin;
  20306. extent[1] -= margin;
  20307. }
  20308. var normalizedExtent = [0, 1];
  20309. /**
  20310. * @name module:echarts/coord/CartesianAxis
  20311. * @constructor
  20312. */
  20313. var Axis = function (dim, scale, extent) {
  20314. /**
  20315. * Axis dimension. Such as 'x', 'y', 'z', 'angle', 'radius'
  20316. * @type {string}
  20317. */
  20318. this.dim = dim;
  20319. /**
  20320. * Axis scale
  20321. * @type {module:echarts/coord/scale/*}
  20322. */
  20323. this.scale = scale;
  20324. /**
  20325. * @type {Array.<number>}
  20326. * @private
  20327. */
  20328. this._extent = extent || [0, 0];
  20329. /**
  20330. * @type {boolean}
  20331. */
  20332. this.inverse = false;
  20333. /**
  20334. * Usually true when axis has a ordinal scale
  20335. * @type {boolean}
  20336. */
  20337. this.onBand = false;
  20338. /**
  20339. * @private
  20340. * @type {number}
  20341. */
  20342. this._labelInterval;
  20343. };
  20344. Axis.prototype = {
  20345. constructor: Axis,
  20346. /**
  20347. * If axis extent contain given coord
  20348. * @param {number} coord
  20349. * @return {boolean}
  20350. */
  20351. contain: function (coord) {
  20352. var extent = this._extent;
  20353. var min = Math.min(extent[0], extent[1]);
  20354. var max = Math.max(extent[0], extent[1]);
  20355. return coord >= min && coord <= max;
  20356. },
  20357. /**
  20358. * If axis extent contain given data
  20359. * @param {number} data
  20360. * @return {boolean}
  20361. */
  20362. containData: function (data) {
  20363. return this.contain(this.dataToCoord(data));
  20364. },
  20365. /**
  20366. * Get coord extent.
  20367. * @return {Array.<number>}
  20368. */
  20369. getExtent: function () {
  20370. return this._extent.slice();
  20371. },
  20372. /**
  20373. * Get precision used for formatting
  20374. * @param {Array.<number>} [dataExtent]
  20375. * @return {number}
  20376. */
  20377. getPixelPrecision: function (dataExtent) {
  20378. return numberUtil.getPixelPrecision(
  20379. dataExtent || this.scale.getExtent(),
  20380. this._extent
  20381. );
  20382. },
  20383. /**
  20384. * Set coord extent
  20385. * @param {number} start
  20386. * @param {number} end
  20387. */
  20388. setExtent: function (start, end) {
  20389. var extent = this._extent;
  20390. extent[0] = start;
  20391. extent[1] = end;
  20392. },
  20393. /**
  20394. * Convert data to coord. Data is the rank if it has a ordinal scale
  20395. * @param {number} data
  20396. * @param {boolean} clamp
  20397. * @return {number}
  20398. */
  20399. dataToCoord: function (data, clamp) {
  20400. var extent = this._extent;
  20401. var scale = this.scale;
  20402. data = scale.normalize(data);
  20403. if (this.onBand && scale.type === 'ordinal') {
  20404. extent = extent.slice();
  20405. fixExtentWithBands(extent, scale.count());
  20406. }
  20407. return linearMap(data, normalizedExtent, extent, clamp);
  20408. },
  20409. /**
  20410. * Convert coord to data. Data is the rank if it has a ordinal scale
  20411. * @param {number} coord
  20412. * @param {boolean} clamp
  20413. * @return {number}
  20414. */
  20415. coordToData: function (coord, clamp) {
  20416. var extent = this._extent;
  20417. var scale = this.scale;
  20418. if (this.onBand && scale.type === 'ordinal') {
  20419. extent = extent.slice();
  20420. fixExtentWithBands(extent, scale.count());
  20421. }
  20422. var t = linearMap(coord, extent, normalizedExtent, clamp);
  20423. return this.scale.scale(t);
  20424. },
  20425. /**
  20426. * Convert pixel point to data in axis
  20427. * @param {Array.<number>} point
  20428. * @param {boolean} clamp
  20429. * @return {number} data
  20430. */
  20431. pointToData: function (point, clamp) {
  20432. // Should be implemented in derived class if necessary.
  20433. },
  20434. /**
  20435. * @return {Array.<number>}
  20436. */
  20437. getTicksCoords: function (alignWithLabel) {
  20438. if (this.onBand && !alignWithLabel) {
  20439. var bands = this.getBands();
  20440. var coords = [];
  20441. for (var i = 0; i < bands.length; i++) {
  20442. coords.push(bands[i][0]);
  20443. }
  20444. if (bands[i - 1]) {
  20445. coords.push(bands[i - 1][1]);
  20446. }
  20447. return coords;
  20448. }
  20449. else {
  20450. return zrUtil.map(this.scale.getTicks(), this.dataToCoord, this);
  20451. }
  20452. },
  20453. /**
  20454. * Coords of labels are on the ticks or on the middle of bands
  20455. * @return {Array.<number>}
  20456. */
  20457. getLabelsCoords: function () {
  20458. return zrUtil.map(this.scale.getTicks(), this.dataToCoord, this);
  20459. },
  20460. /**
  20461. * Get bands.
  20462. *
  20463. * If axis has labels [1, 2, 3, 4]. Bands on the axis are
  20464. * |---1---|---2---|---3---|---4---|.
  20465. *
  20466. * @return {Array}
  20467. */
  20468. // FIXME Situation when labels is on ticks
  20469. getBands: function () {
  20470. var extent = this.getExtent();
  20471. var bands = [];
  20472. var len = this.scale.count();
  20473. var start = extent[0];
  20474. var end = extent[1];
  20475. var span = end - start;
  20476. for (var i = 0; i < len; i++) {
  20477. bands.push([
  20478. span * i / len + start,
  20479. span * (i + 1) / len + start
  20480. ]);
  20481. }
  20482. return bands;
  20483. },
  20484. /**
  20485. * Get width of band
  20486. * @return {number}
  20487. */
  20488. getBandWidth: function () {
  20489. var axisExtent = this._extent;
  20490. var dataExtent = this.scale.getExtent();
  20491. var len = dataExtent[1] - dataExtent[0] + (this.onBand ? 1 : 0);
  20492. // Fix #2728, avoid NaN when only one data.
  20493. len === 0 && (len = 1);
  20494. var size = Math.abs(axisExtent[1] - axisExtent[0]);
  20495. return Math.abs(size) / len;
  20496. },
  20497. /**
  20498. * Get interval of the axis label.
  20499. * @return {number}
  20500. */
  20501. getLabelInterval: function () {
  20502. var labelInterval = this._labelInterval;
  20503. if (!labelInterval) {
  20504. var axisModel = this.model;
  20505. var labelModel = axisModel.getModel('axisLabel');
  20506. var interval = labelModel.get('interval');
  20507. if (!(this.type === 'category' && interval === 'auto')) {
  20508. labelInterval = interval === 'auto' ? 0 : interval;
  20509. }
  20510. else if (this.isHorizontal){
  20511. labelInterval = axisHelper.getAxisLabelInterval(
  20512. zrUtil.map(this.scale.getTicks(), this.dataToCoord, this),
  20513. axisModel.getFormattedLabels(),
  20514. labelModel.getModel('textStyle').getFont(),
  20515. this.isHorizontal()
  20516. );
  20517. }
  20518. this._labelInterval = labelInterval;
  20519. }
  20520. return labelInterval;
  20521. }
  20522. };
  20523. module.exports = Axis;
  20524. /***/ },
  20525. /* 101 */
  20526. /***/ function(module, exports, __webpack_require__) {
  20527. var OrdinalScale = __webpack_require__(102);
  20528. var IntervalScale = __webpack_require__(104);
  20529. __webpack_require__(106);
  20530. __webpack_require__(107);
  20531. var Scale = __webpack_require__(103);
  20532. var numberUtil = __webpack_require__(7);
  20533. var zrUtil = __webpack_require__(4);
  20534. var textContain = __webpack_require__(8);
  20535. var axisHelper = {};
  20536. /**
  20537. * Get axis scale extent before niced.
  20538. * Item of returned array can only be number (including Infinity and NaN).
  20539. */
  20540. axisHelper.getScaleExtent = function (scale, model) {
  20541. var scaleType = scale.type;
  20542. var min = model.getMin();
  20543. var max = model.getMax();
  20544. var fixMin = min != null;
  20545. var fixMax = max != null;
  20546. var originalExtent = scale.getExtent();
  20547. var axisDataLen;
  20548. var boundaryGap;
  20549. var span;
  20550. if (scaleType === 'ordinal') {
  20551. axisDataLen = (model.get('data') || []).length;
  20552. }
  20553. else {
  20554. boundaryGap = model.get('boundaryGap');
  20555. if (!zrUtil.isArray(boundaryGap)) {
  20556. boundaryGap = [boundaryGap || 0, boundaryGap || 0];
  20557. }
  20558. if (typeof boundaryGap[0] === 'boolean') {
  20559. if (true) {
  20560. console.warn('Boolean type for boundaryGap is only '
  20561. + 'allowed for ordinal axis. Please use string in '
  20562. + 'percentage instead, e.g., "20%". Currently, '
  20563. + 'boundaryGap is set to be 0.');
  20564. }
  20565. boundaryGap = [0, 0];
  20566. }
  20567. boundaryGap[0] = numberUtil.parsePercent(boundaryGap[0], 1);
  20568. boundaryGap[1] = numberUtil.parsePercent(boundaryGap[1], 1);
  20569. span = (originalExtent[1] - originalExtent[0])
  20570. || Math.abs(originalExtent[0]);
  20571. }
  20572. // Notice: When min/max is not set (that is, when there are null/undefined,
  20573. // which is the most common case), these cases should be ensured:
  20574. // (1) For 'ordinal', show all axis.data.
  20575. // (2) For others:
  20576. // + `boundaryGap` is applied (if min/max set, boundaryGap is
  20577. // disabled).
  20578. // + If `needCrossZero`, min/max should be zero, otherwise, min/max should
  20579. // be the result that originalExtent enlarged by boundaryGap.
  20580. // (3) If no data, it should be ensured that `scale.setBlank` is set.
  20581. // FIXME
  20582. // (1) When min/max is 'dataMin' or 'dataMax', should boundaryGap be able to used?
  20583. // (2) When `needCrossZero` and all data is positive/negative, should it be ensured
  20584. // that the results processed by boundaryGap are positive/negative?
  20585. if (min == null) {
  20586. min = scaleType === 'ordinal'
  20587. ? (axisDataLen ? 0 : NaN)
  20588. : originalExtent[0] - boundaryGap[0] * span;
  20589. }
  20590. if (max == null) {
  20591. max = scaleType === 'ordinal'
  20592. ? (axisDataLen ? axisDataLen - 1 : NaN)
  20593. : originalExtent[1] + boundaryGap[1] * span;
  20594. }
  20595. if (min === 'dataMin') {
  20596. min = originalExtent[0];
  20597. }
  20598. if (max === 'dataMax') {
  20599. max = originalExtent[1];
  20600. }
  20601. (min == null || !isFinite(min)) && (min = NaN);
  20602. (max == null || !isFinite(max)) && (max = NaN);
  20603. scale.setBlank(zrUtil.eqNaN(min) || zrUtil.eqNaN(max));
  20604. // Evaluate if axis needs cross zero
  20605. if (model.getNeedCrossZero()) {
  20606. // Axis is over zero and min is not set
  20607. if (min > 0 && max > 0 && !fixMin) {
  20608. min = 0;
  20609. }
  20610. // Axis is under zero and max is not set
  20611. if (min < 0 && max < 0 && !fixMax) {
  20612. max = 0;
  20613. }
  20614. }
  20615. return [min, max];
  20616. };
  20617. axisHelper.niceScaleExtent = function (scale, model) {
  20618. var extent = axisHelper.getScaleExtent(scale, model);
  20619. var fixMin = model.getMin() != null;
  20620. var fixMax = model.getMax() != null;
  20621. var splitNumber = model.get('splitNumber');
  20622. if (scale.type === 'log') {
  20623. scale.base = model.get('logBase');
  20624. }
  20625. scale.setExtent(extent[0], extent[1]);
  20626. scale.niceExtent({
  20627. splitNumber: splitNumber,
  20628. fixMin: fixMin,
  20629. fixMax: fixMax,
  20630. minInterval: scale.type === 'interval' ? model.get('minInterval') : null
  20631. });
  20632. // If some one specified the min, max. And the default calculated interval
  20633. // is not good enough. He can specify the interval. It is often appeared
  20634. // in angle axis with angle 0 - 360. Interval calculated in interval scale is hard
  20635. // to be 60.
  20636. // FIXME
  20637. var interval = model.get('interval');
  20638. if (interval != null) {
  20639. scale.setInterval && scale.setInterval(interval);
  20640. }
  20641. };
  20642. /**
  20643. * @param {module:echarts/model/Model} model
  20644. * @param {string} [axisType] Default retrieve from model.type
  20645. * @return {module:echarts/scale/*}
  20646. */
  20647. axisHelper.createScaleByModel = function(model, axisType) {
  20648. axisType = axisType || model.get('type');
  20649. if (axisType) {
  20650. switch (axisType) {
  20651. // Buildin scale
  20652. case 'category':
  20653. return new OrdinalScale(
  20654. model.getCategories(), [Infinity, -Infinity]
  20655. );
  20656. case 'value':
  20657. return new IntervalScale();
  20658. // Extended scale, like time and log
  20659. default:
  20660. return (Scale.getClass(axisType) || IntervalScale).create(model);
  20661. }
  20662. }
  20663. };
  20664. /**
  20665. * Check if the axis corss 0
  20666. */
  20667. axisHelper.ifAxisCrossZero = function (axis) {
  20668. var dataExtent = axis.scale.getExtent();
  20669. var min = dataExtent[0];
  20670. var max = dataExtent[1];
  20671. return !((min > 0 && max > 0) || (min < 0 && max < 0));
  20672. };
  20673. /**
  20674. * @param {Array.<number>} tickCoords In axis self coordinate.
  20675. * @param {Array.<string>} labels
  20676. * @param {string} font
  20677. * @param {boolean} isAxisHorizontal
  20678. * @return {number}
  20679. */
  20680. axisHelper.getAxisLabelInterval = function (tickCoords, labels, font, isAxisHorizontal) {
  20681. // FIXME
  20682. // 不同角的axis和label,不只是horizontal和vertical.
  20683. var textSpaceTakenRect;
  20684. var autoLabelInterval = 0;
  20685. var accumulatedLabelInterval = 0;
  20686. var step = 1;
  20687. if (labels.length > 40) {
  20688. // Simple optimization for large amount of labels
  20689. step = Math.floor(labels.length / 40);
  20690. }
  20691. for (var i = 0; i < tickCoords.length; i += step) {
  20692. var tickCoord = tickCoords[i];
  20693. var rect = textContain.getBoundingRect(
  20694. labels[i], font, 'center', 'top'
  20695. );
  20696. rect[isAxisHorizontal ? 'x' : 'y'] += tickCoord;
  20697. // FIXME Magic number 1.5
  20698. rect[isAxisHorizontal ? 'width' : 'height'] *= 1.3;
  20699. if (!textSpaceTakenRect) {
  20700. textSpaceTakenRect = rect.clone();
  20701. }
  20702. // There is no space for current label;
  20703. else if (textSpaceTakenRect.intersect(rect)) {
  20704. accumulatedLabelInterval++;
  20705. autoLabelInterval = Math.max(autoLabelInterval, accumulatedLabelInterval);
  20706. }
  20707. else {
  20708. textSpaceTakenRect.union(rect);
  20709. // Reset
  20710. accumulatedLabelInterval = 0;
  20711. }
  20712. }
  20713. if (autoLabelInterval === 0 && step > 1) {
  20714. return step;
  20715. }
  20716. return (autoLabelInterval + 1) * step - 1;
  20717. };
  20718. /**
  20719. * @param {Object} axis
  20720. * @param {Function} labelFormatter
  20721. * @return {Array.<string>}
  20722. */
  20723. axisHelper.getFormattedLabels = function (axis, labelFormatter) {
  20724. var scale = axis.scale;
  20725. var labels = scale.getTicksLabels();
  20726. var ticks = scale.getTicks();
  20727. if (typeof labelFormatter === 'string') {
  20728. labelFormatter = (function (tpl) {
  20729. return function (val) {
  20730. return tpl.replace('{value}', val != null ? val : '');
  20731. };
  20732. })(labelFormatter);
  20733. // Consider empty array
  20734. return zrUtil.map(labels, labelFormatter);
  20735. }
  20736. else if (typeof labelFormatter === 'function') {
  20737. return zrUtil.map(ticks, function (tick, idx) {
  20738. return labelFormatter(
  20739. axisHelper.getAxisRawValue(axis, tick),
  20740. idx
  20741. );
  20742. }, this);
  20743. }
  20744. else {
  20745. return labels;
  20746. }
  20747. };
  20748. axisHelper.getAxisRawValue = function (axis, value) {
  20749. // In category axis with data zoom, tick is not the original
  20750. // index of axis.data. So tick should not be exposed to user
  20751. // in category axis.
  20752. return axis.type === 'category' ? axis.scale.getLabel(value) : value;
  20753. };
  20754. module.exports = axisHelper;
  20755. /***/ },
  20756. /* 102 */
  20757. /***/ function(module, exports, __webpack_require__) {
  20758. /**
  20759. * Linear continuous scale
  20760. * @module echarts/coord/scale/Ordinal
  20761. *
  20762. * http://en.wikipedia.org/wiki/Level_of_measurement
  20763. */
  20764. // FIXME only one data
  20765. var zrUtil = __webpack_require__(4);
  20766. var Scale = __webpack_require__(103);
  20767. var scaleProto = Scale.prototype;
  20768. var OrdinalScale = Scale.extend({
  20769. type: 'ordinal',
  20770. init: function (data, extent) {
  20771. this._data = data;
  20772. this._extent = extent || [0, data.length - 1];
  20773. },
  20774. parse: function (val) {
  20775. return typeof val === 'string'
  20776. ? zrUtil.indexOf(this._data, val)
  20777. // val might be float.
  20778. : Math.round(val);
  20779. },
  20780. contain: function (rank) {
  20781. rank = this.parse(rank);
  20782. return scaleProto.contain.call(this, rank)
  20783. && this._data[rank] != null;
  20784. },
  20785. /**
  20786. * Normalize given rank or name to linear [0, 1]
  20787. * @param {number|string} [val]
  20788. * @return {number}
  20789. */
  20790. normalize: function (val) {
  20791. return scaleProto.normalize.call(this, this.parse(val));
  20792. },
  20793. scale: function (val) {
  20794. return Math.round(scaleProto.scale.call(this, val));
  20795. },
  20796. /**
  20797. * @return {Array}
  20798. */
  20799. getTicks: function () {
  20800. var ticks = [];
  20801. var extent = this._extent;
  20802. var rank = extent[0];
  20803. while (rank <= extent[1]) {
  20804. ticks.push(rank);
  20805. rank++;
  20806. }
  20807. return ticks;
  20808. },
  20809. /**
  20810. * Get item on rank n
  20811. * @param {number} n
  20812. * @return {string}
  20813. */
  20814. getLabel: function (n) {
  20815. return this._data[n];
  20816. },
  20817. /**
  20818. * @return {number}
  20819. */
  20820. count: function () {
  20821. return this._extent[1] - this._extent[0] + 1;
  20822. },
  20823. /**
  20824. * @override
  20825. */
  20826. unionExtentFromData: function (data, dim) {
  20827. this.unionExtent(data.getDataExtent(dim, false));
  20828. },
  20829. niceTicks: zrUtil.noop,
  20830. niceExtent: zrUtil.noop
  20831. });
  20832. /**
  20833. * @return {module:echarts/scale/Time}
  20834. */
  20835. OrdinalScale.create = function () {
  20836. return new OrdinalScale();
  20837. };
  20838. module.exports = OrdinalScale;
  20839. /***/ },
  20840. /* 103 */
  20841. /***/ function(module, exports, __webpack_require__) {
  20842. /**
  20843. * // Scale class management
  20844. * @module echarts/scale/Scale
  20845. */
  20846. var clazzUtil = __webpack_require__(13);
  20847. /**
  20848. * @param {Object} [setting]
  20849. */
  20850. function Scale(setting) {
  20851. this._setting = setting || {};
  20852. /**
  20853. * Extent
  20854. * @type {Array.<number>}
  20855. * @protected
  20856. */
  20857. this._extent = [Infinity, -Infinity];
  20858. /**
  20859. * Step is calculated in adjustExtent
  20860. * @type {Array.<number>}
  20861. * @protected
  20862. */
  20863. this._interval = 0;
  20864. this.init && this.init.apply(this, arguments);
  20865. }
  20866. var scaleProto = Scale.prototype;
  20867. /**
  20868. * Parse input val to valid inner number.
  20869. * @param {*} val
  20870. * @return {number}
  20871. */
  20872. scaleProto.parse = function (val) {
  20873. // Notice: This would be a trap here, If the implementation
  20874. // of this method depends on extent, and this method is used
  20875. // before extent set (like in dataZoom), it would be wrong.
  20876. // Nevertheless, parse does not depend on extent generally.
  20877. return val;
  20878. };
  20879. scaleProto.getSetting = function (name) {
  20880. return this._setting[name];
  20881. };
  20882. scaleProto.contain = function (val) {
  20883. var extent = this._extent;
  20884. return val >= extent[0] && val <= extent[1];
  20885. };
  20886. /**
  20887. * Normalize value to linear [0, 1], return 0.5 if extent span is 0
  20888. * @param {number} val
  20889. * @return {number}
  20890. */
  20891. scaleProto.normalize = function (val) {
  20892. var extent = this._extent;
  20893. if (extent[1] === extent[0]) {
  20894. return 0.5;
  20895. }
  20896. return (val - extent[0]) / (extent[1] - extent[0]);
  20897. };
  20898. /**
  20899. * Scale normalized value
  20900. * @param {number} val
  20901. * @return {number}
  20902. */
  20903. scaleProto.scale = function (val) {
  20904. var extent = this._extent;
  20905. return val * (extent[1] - extent[0]) + extent[0];
  20906. };
  20907. /**
  20908. * Set extent from data
  20909. * @param {Array.<number>} other
  20910. */
  20911. scaleProto.unionExtent = function (other) {
  20912. var extent = this._extent;
  20913. other[0] < extent[0] && (extent[0] = other[0]);
  20914. other[1] > extent[1] && (extent[1] = other[1]);
  20915. // not setExtent because in log axis it may transformed to power
  20916. // this.setExtent(extent[0], extent[1]);
  20917. };
  20918. /**
  20919. * Set extent from data
  20920. * @param {module:echarts/data/List} data
  20921. * @param {string} dim
  20922. */
  20923. scaleProto.unionExtentFromData = function (data, dim) {
  20924. this.unionExtent(data.getDataExtent(dim, true));
  20925. };
  20926. /**
  20927. * Get extent
  20928. * @return {Array.<number>}
  20929. */
  20930. scaleProto.getExtent = function () {
  20931. return this._extent.slice();
  20932. };
  20933. /**
  20934. * Set extent
  20935. * @param {number} start
  20936. * @param {number} end
  20937. */
  20938. scaleProto.setExtent = function (start, end) {
  20939. var thisExtent = this._extent;
  20940. if (!isNaN(start)) {
  20941. thisExtent[0] = start;
  20942. }
  20943. if (!isNaN(end)) {
  20944. thisExtent[1] = end;
  20945. }
  20946. };
  20947. /**
  20948. * @return {Array.<string>}
  20949. */
  20950. scaleProto.getTicksLabels = function () {
  20951. var labels = [];
  20952. var ticks = this.getTicks();
  20953. for (var i = 0; i < ticks.length; i++) {
  20954. labels.push(this.getLabel(ticks[i]));
  20955. }
  20956. return labels;
  20957. };
  20958. /**
  20959. * When axis extent depends on data and no data exists,
  20960. * axis ticks should not be drawn, which is named 'blank'.
  20961. */
  20962. scaleProto.isBlank = function () {
  20963. return this._isBlank;
  20964. },
  20965. /**
  20966. * When axis extent depends on data and no data exists,
  20967. * axis ticks should not be drawn, which is named 'blank'.
  20968. */
  20969. scaleProto.setBlank = function (isBlank) {
  20970. this._isBlank = isBlank;
  20971. };
  20972. clazzUtil.enableClassExtend(Scale);
  20973. clazzUtil.enableClassManagement(Scale, {
  20974. registerWhenExtend: true
  20975. });
  20976. module.exports = Scale;
  20977. /***/ },
  20978. /* 104 */
  20979. /***/ function(module, exports, __webpack_require__) {
  20980. /**
  20981. * Interval scale
  20982. * @module echarts/scale/Interval
  20983. */
  20984. var numberUtil = __webpack_require__(7);
  20985. var formatUtil = __webpack_require__(6);
  20986. var Scale = __webpack_require__(103);
  20987. var helper = __webpack_require__(105);
  20988. var roundNumber = numberUtil.round;
  20989. /**
  20990. * @alias module:echarts/coord/scale/Interval
  20991. * @constructor
  20992. */
  20993. var IntervalScale = Scale.extend({
  20994. type: 'interval',
  20995. _interval: 0,
  20996. _intervalPrecision: 2,
  20997. setExtent: function (start, end) {
  20998. var thisExtent = this._extent;
  20999. //start,end may be a Number like '25',so...
  21000. if (!isNaN(start)) {
  21001. thisExtent[0] = parseFloat(start);
  21002. }
  21003. if (!isNaN(end)) {
  21004. thisExtent[1] = parseFloat(end);
  21005. }
  21006. },
  21007. unionExtent: function (other) {
  21008. var extent = this._extent;
  21009. other[0] < extent[0] && (extent[0] = other[0]);
  21010. other[1] > extent[1] && (extent[1] = other[1]);
  21011. // unionExtent may called by it's sub classes
  21012. IntervalScale.prototype.setExtent.call(this, extent[0], extent[1]);
  21013. },
  21014. /**
  21015. * Get interval
  21016. */
  21017. getInterval: function () {
  21018. return this._interval;
  21019. },
  21020. /**
  21021. * Set interval
  21022. */
  21023. setInterval: function (interval) {
  21024. this._interval = interval;
  21025. // Dropped auto calculated niceExtent and use user setted extent
  21026. // We assume user wan't to set both interval, min, max to get a better result
  21027. this._niceExtent = this._extent.slice();
  21028. },
  21029. /**
  21030. * @return {Array.<number>}
  21031. */
  21032. getTicks: function () {
  21033. return helper.intervalScaleGetTicks(
  21034. this._interval, this._extent, this._niceExtent, this._intervalPrecision
  21035. );
  21036. },
  21037. /**
  21038. * @return {Array.<string>}
  21039. */
  21040. getTicksLabels: function () {
  21041. var labels = [];
  21042. var ticks = this.getTicks();
  21043. for (var i = 0; i < ticks.length; i++) {
  21044. labels.push(this.getLabel(ticks[i]));
  21045. }
  21046. return labels;
  21047. },
  21048. /**
  21049. * @param {number} data
  21050. * @param {Object} [opt]
  21051. * @param {number|string} [opt.precision] If 'auto', use nice presision.
  21052. * @param {boolean} [opt.pad] returns 1.50 but not 1.5 if precision is 2.
  21053. * @return {string}
  21054. */
  21055. getLabel: function (data, opt) {
  21056. if (data == null) {
  21057. return '';
  21058. }
  21059. var precision = opt && opt.precision;
  21060. if (precision == null) {
  21061. precision = numberUtil.getPrecisionSafe(data) || 0;
  21062. }
  21063. else if (precision === 'auto') {
  21064. // Should be more precise then tick.
  21065. precision = this._intervalPrecision;
  21066. }
  21067. // (1) If `precision` is set, 12.005 should be display as '12.00500'.
  21068. // (2) Use roundNumber (toFixed) to avoid scientific notation like '3.5e-7'.
  21069. data = roundNumber(data, precision, true);
  21070. return formatUtil.addCommas(data);
  21071. },
  21072. /**
  21073. * Update interval and extent of intervals for nice ticks
  21074. *
  21075. * @param {number} [splitNumber = 5] Desired number of ticks
  21076. * @param {number} [minInterval]
  21077. */
  21078. niceTicks: function (splitNumber, minInterval) {
  21079. splitNumber = splitNumber || 5;
  21080. var extent = this._extent;
  21081. var span = extent[1] - extent[0];
  21082. if (!isFinite(span)) {
  21083. return;
  21084. }
  21085. // User may set axis min 0 and data are all negative
  21086. // FIXME If it needs to reverse ?
  21087. if (span < 0) {
  21088. span = -span;
  21089. extent.reverse();
  21090. }
  21091. var result = helper.intervalScaleNiceTicks(extent, splitNumber, minInterval);
  21092. this._intervalPrecision = result.intervalPrecision;
  21093. this._interval = result.interval;
  21094. this._niceExtent = result.niceTickExtent;
  21095. },
  21096. /**
  21097. * Nice extent.
  21098. * @param {Object} opt
  21099. * @param {number} [opt.splitNumber = 5] Given approx tick number
  21100. * @param {boolean} [opt.fixMin=false]
  21101. * @param {boolean} [opt.fixMax=false]
  21102. * @param {boolean} [opt.minInterval=false]
  21103. */
  21104. niceExtent: function (opt) {
  21105. var extent = this._extent;
  21106. // If extent start and end are same, expand them
  21107. if (extent[0] === extent[1]) {
  21108. if (extent[0] !== 0) {
  21109. // Expand extent
  21110. var expandSize = extent[0];
  21111. // In the fowllowing case
  21112. // Axis has been fixed max 100
  21113. // Plus data are all 100 and axis extent are [100, 100].
  21114. // Extend to the both side will cause expanded max is larger than fixed max.
  21115. // So only expand to the smaller side.
  21116. if (!opt.fixMax) {
  21117. extent[1] += expandSize / 2;
  21118. extent[0] -= expandSize / 2;
  21119. }
  21120. else {
  21121. extent[0] -= expandSize / 2;
  21122. }
  21123. }
  21124. else {
  21125. extent[1] = 1;
  21126. }
  21127. }
  21128. var span = extent[1] - extent[0];
  21129. // If there are no data and extent are [Infinity, -Infinity]
  21130. if (!isFinite(span)) {
  21131. extent[0] = 0;
  21132. extent[1] = 1;
  21133. }
  21134. this.niceTicks(opt.splitNumber, opt.minInterval);
  21135. // var extent = this._extent;
  21136. var interval = this._interval;
  21137. if (!opt.fixMin) {
  21138. extent[0] = roundNumber(Math.floor(extent[0] / interval) * interval);
  21139. }
  21140. if (!opt.fixMax) {
  21141. extent[1] = roundNumber(Math.ceil(extent[1] / interval) * interval);
  21142. }
  21143. }
  21144. });
  21145. /**
  21146. * @return {module:echarts/scale/Time}
  21147. */
  21148. IntervalScale.create = function () {
  21149. return new IntervalScale();
  21150. };
  21151. module.exports = IntervalScale;
  21152. /***/ },
  21153. /* 105 */
  21154. /***/ function(module, exports, __webpack_require__) {
  21155. /**
  21156. * For testable.
  21157. */
  21158. var numberUtil = __webpack_require__(7);
  21159. var roundNumber = numberUtil.round;
  21160. var helper = {};
  21161. /**
  21162. * @param {Array.<number>} extent Both extent[0] and extent[1] should be valid number.
  21163. * Should be extent[0] < extent[1].
  21164. * @param {number} splitNumber splitNumber should be >= 1.
  21165. * @param {number} [minInterval]
  21166. * @return {Object} {interval, intervalPrecision, niceTickExtent}
  21167. */
  21168. helper.intervalScaleNiceTicks = function (extent, splitNumber, minInterval) {
  21169. var result = {};
  21170. var span = extent[1] - extent[0];
  21171. var interval = result.interval = numberUtil.nice(span / splitNumber, true);
  21172. if (minInterval != null && interval < minInterval) {
  21173. interval = result.interval = minInterval;
  21174. }
  21175. // Tow more digital for tick.
  21176. var precision = result.intervalPrecision = numberUtil.getPrecisionSafe(interval) + 2;
  21177. // Niced extent inside original extent
  21178. var niceTickExtent = result.niceTickExtent = [
  21179. roundNumber(Math.ceil(extent[0] / interval) * interval, precision),
  21180. roundNumber(Math.floor(extent[1] / interval) * interval, precision)
  21181. ];
  21182. helper.fixExtent(niceTickExtent, extent);
  21183. return result;
  21184. };
  21185. function clamp(niceTickExtent, idx, extent) {
  21186. niceTickExtent[idx] = Math.max(Math.min(niceTickExtent[idx], extent[1]), extent[0]);
  21187. }
  21188. // In some cases (e.g., splitNumber is 1), niceTickExtent may be out of extent.
  21189. helper.fixExtent = function (niceTickExtent, extent) {
  21190. !isFinite(niceTickExtent[0]) && (niceTickExtent[0] = extent[0]);
  21191. !isFinite(niceTickExtent[1]) && (niceTickExtent[1] = extent[1]);
  21192. clamp(niceTickExtent, 0, extent);
  21193. clamp(niceTickExtent, 1, extent);
  21194. if (niceTickExtent[0] > niceTickExtent[1]) {
  21195. niceTickExtent[0] = niceTickExtent[1];
  21196. }
  21197. };
  21198. helper.intervalScaleGetTicks = function (interval, extent, niceTickExtent, intervalPrecision) {
  21199. var ticks = [];
  21200. // If interval is 0, return [];
  21201. if (!interval) {
  21202. return ticks;
  21203. }
  21204. // Consider this case: using dataZoom toolbox, zoom and zoom.
  21205. var safeLimit = 10000;
  21206. if (extent[0] < niceTickExtent[0]) {
  21207. ticks.push(extent[0]);
  21208. }
  21209. var tick = niceTickExtent[0];
  21210. while (tick <= niceTickExtent[1]) {
  21211. ticks.push(tick);
  21212. // Avoid rounding error
  21213. tick = roundNumber(tick + interval, intervalPrecision);
  21214. if (tick === ticks[ticks.length - 1]) {
  21215. // Consider out of safe float point, e.g.,
  21216. // -3711126.9907707 + 2e-10 === -3711126.9907707
  21217. break;
  21218. }
  21219. if (ticks.length > safeLimit) {
  21220. return [];
  21221. }
  21222. }
  21223. // Consider this case: the last item of ticks is smaller
  21224. // than niceTickExtent[1] and niceTickExtent[1] === extent[1].
  21225. if (extent[1] > (ticks.length ? ticks[ticks.length - 1] : niceTickExtent[1])) {
  21226. ticks.push(extent[1]);
  21227. }
  21228. return ticks;
  21229. };
  21230. module.exports = helper;
  21231. /***/ },
  21232. /* 106 */
  21233. /***/ function(module, exports, __webpack_require__) {
  21234. /**
  21235. * Interval scale
  21236. * @module echarts/coord/scale/Time
  21237. */
  21238. // [About UTC and local time zone]:
  21239. // In most cases, `number.parseDate` will treat input data string as local time
  21240. // (except time zone is specified in time string). And `format.formateTime` returns
  21241. // local time by default. option.useUTC is false by default. This design have
  21242. // concidered these common case:
  21243. // (1) Time that is persistent in server is in UTC, but it is needed to be diplayed
  21244. // in local time by default.
  21245. // (2) By default, the input data string (e.g., '2011-01-02') should be displayed
  21246. // as its original time, without any time difference.
  21247. var zrUtil = __webpack_require__(4);
  21248. var numberUtil = __webpack_require__(7);
  21249. var formatUtil = __webpack_require__(6);
  21250. var scaleHelper = __webpack_require__(105);
  21251. var IntervalScale = __webpack_require__(104);
  21252. var intervalScaleProto = IntervalScale.prototype;
  21253. var mathCeil = Math.ceil;
  21254. var mathFloor = Math.floor;
  21255. var ONE_SECOND = 1000;
  21256. var ONE_MINUTE = ONE_SECOND * 60;
  21257. var ONE_HOUR = ONE_MINUTE * 60;
  21258. var ONE_DAY = ONE_HOUR * 24;
  21259. // FIXME 公用?
  21260. var bisect = function (a, x, lo, hi) {
  21261. while (lo < hi) {
  21262. var mid = lo + hi >>> 1;
  21263. if (a[mid][2] < x) {
  21264. lo = mid + 1;
  21265. }
  21266. else {
  21267. hi = mid;
  21268. }
  21269. }
  21270. return lo;
  21271. };
  21272. /**
  21273. * @alias module:echarts/coord/scale/Time
  21274. * @constructor
  21275. */
  21276. var TimeScale = IntervalScale.extend({
  21277. type: 'time',
  21278. /**
  21279. * @override
  21280. */
  21281. getLabel: function (val) {
  21282. var stepLvl = this._stepLvl;
  21283. var date = new Date(val);
  21284. return formatUtil.formatTime(stepLvl[0], date, this.getSetting('useUTC'));
  21285. },
  21286. /**
  21287. * @override
  21288. */
  21289. niceExtent: function (opt) {
  21290. var extent = this._extent;
  21291. // If extent start and end are same, expand them
  21292. if (extent[0] === extent[1]) {
  21293. // Expand extent
  21294. extent[0] -= ONE_DAY;
  21295. extent[1] += ONE_DAY;
  21296. }
  21297. // If there are no data and extent are [Infinity, -Infinity]
  21298. if (extent[1] === -Infinity && extent[0] === Infinity) {
  21299. var d = new Date();
  21300. extent[1] = new Date(d.getFullYear(), d.getMonth(), d.getDate());
  21301. extent[0] = extent[1] - ONE_DAY;
  21302. }
  21303. this.niceTicks(opt.splitNumber);
  21304. // var extent = this._extent;
  21305. var interval = this._interval;
  21306. if (!opt.fixMin) {
  21307. extent[0] = numberUtil.round(mathFloor(extent[0] / interval) * interval);
  21308. }
  21309. if (!opt.fixMax) {
  21310. extent[1] = numberUtil.round(mathCeil(extent[1] / interval) * interval);
  21311. }
  21312. },
  21313. /**
  21314. * @override
  21315. */
  21316. niceTicks: function (approxTickNum) {
  21317. var timezoneOffset = this.getSetting('useUTC')
  21318. ? 0 : numberUtil.getTimezoneOffset() * 60 * 1000;
  21319. approxTickNum = approxTickNum || 10;
  21320. var extent = this._extent;
  21321. var span = extent[1] - extent[0];
  21322. var approxInterval = span / approxTickNum;
  21323. var scaleLevelsLen = scaleLevels.length;
  21324. var idx = bisect(scaleLevels, approxInterval, 0, scaleLevelsLen);
  21325. var level = scaleLevels[Math.min(idx, scaleLevelsLen - 1)];
  21326. var interval = level[2];
  21327. // Same with interval scale if span is much larger than 1 year
  21328. if (level[0] === 'year') {
  21329. var yearSpan = span / interval;
  21330. // From "Nice Numbers for Graph Labels" of Graphic Gems
  21331. // var niceYearSpan = numberUtil.nice(yearSpan, false);
  21332. var yearStep = numberUtil.nice(yearSpan / approxTickNum, true);
  21333. interval *= yearStep;
  21334. }
  21335. var niceExtent = [
  21336. Math.round(mathCeil((extent[0] - timezoneOffset) / interval) * interval + timezoneOffset),
  21337. Math.round(mathFloor((extent[1] - timezoneOffset)/ interval) * interval + timezoneOffset)
  21338. ];
  21339. scaleHelper.fixExtent(niceExtent, extent);
  21340. this._stepLvl = level;
  21341. // Interval will be used in getTicks
  21342. this._interval = interval;
  21343. this._niceExtent = niceExtent;
  21344. },
  21345. parse: function (val) {
  21346. // val might be float.
  21347. return +numberUtil.parseDate(val);
  21348. }
  21349. });
  21350. zrUtil.each(['contain', 'normalize'], function (methodName) {
  21351. TimeScale.prototype[methodName] = function (val) {
  21352. return intervalScaleProto[methodName].call(this, this.parse(val));
  21353. };
  21354. });
  21355. // Steps from d3
  21356. var scaleLevels = [
  21357. // Format step interval
  21358. ['hh:mm:ss', 1, ONE_SECOND], // 1s
  21359. ['hh:mm:ss', 5, ONE_SECOND * 5], // 5s
  21360. ['hh:mm:ss', 10, ONE_SECOND * 10], // 10s
  21361. ['hh:mm:ss', 15, ONE_SECOND * 15], // 15s
  21362. ['hh:mm:ss', 30, ONE_SECOND * 30], // 30s
  21363. ['hh:mm\nMM-dd',1, ONE_MINUTE], // 1m
  21364. ['hh:mm\nMM-dd',5, ONE_MINUTE * 5], // 5m
  21365. ['hh:mm\nMM-dd',10, ONE_MINUTE * 10], // 10m
  21366. ['hh:mm\nMM-dd',15, ONE_MINUTE * 15], // 15m
  21367. ['hh:mm\nMM-dd',30, ONE_MINUTE * 30], // 30m
  21368. ['hh:mm\nMM-dd',1, ONE_HOUR], // 1h
  21369. ['hh:mm\nMM-dd',2, ONE_HOUR * 2], // 2h
  21370. ['hh:mm\nMM-dd',6, ONE_HOUR * 6], // 6h
  21371. ['hh:mm\nMM-dd',12, ONE_HOUR * 12], // 12h
  21372. ['MM-dd\nyyyy', 1, ONE_DAY], // 1d
  21373. ['week', 7, ONE_DAY * 7], // 7d
  21374. ['month', 1, ONE_DAY * 31], // 1M
  21375. ['quarter', 3, ONE_DAY * 380 / 4], // 3M
  21376. ['half-year', 6, ONE_DAY * 380 / 2], // 6M
  21377. ['year', 1, ONE_DAY * 380] // 1Y
  21378. ];
  21379. /**
  21380. * @param {module:echarts/model/Model}
  21381. * @return {module:echarts/scale/Time}
  21382. */
  21383. TimeScale.create = function (model) {
  21384. return new TimeScale({useUTC: model.ecModel.get('useUTC')});
  21385. };
  21386. module.exports = TimeScale;
  21387. /***/ },
  21388. /* 107 */
  21389. /***/ function(module, exports, __webpack_require__) {
  21390. /**
  21391. * Log scale
  21392. * @module echarts/scale/Log
  21393. */
  21394. var zrUtil = __webpack_require__(4);
  21395. var Scale = __webpack_require__(103);
  21396. var numberUtil = __webpack_require__(7);
  21397. // Use some method of IntervalScale
  21398. var IntervalScale = __webpack_require__(104);
  21399. var scaleProto = Scale.prototype;
  21400. var intervalScaleProto = IntervalScale.prototype;
  21401. var getPrecisionSafe = numberUtil.getPrecisionSafe;
  21402. var roundingErrorFix = numberUtil.round;
  21403. var mathFloor = Math.floor;
  21404. var mathCeil = Math.ceil;
  21405. var mathPow = Math.pow;
  21406. var mathLog = Math.log;
  21407. var LogScale = Scale.extend({
  21408. type: 'log',
  21409. base: 10,
  21410. $constructor: function () {
  21411. Scale.apply(this, arguments);
  21412. this._originalScale = new IntervalScale();
  21413. },
  21414. /**
  21415. * @return {Array.<number>}
  21416. */
  21417. getTicks: function () {
  21418. var originalScale = this._originalScale;
  21419. var extent = this._extent;
  21420. var originalExtent = originalScale.getExtent();
  21421. return zrUtil.map(intervalScaleProto.getTicks.call(this), function (val) {
  21422. var powVal = numberUtil.round(mathPow(this.base, val));
  21423. // Fix #4158
  21424. powVal = (val === extent[0] && originalScale.__fixMin)
  21425. ? fixRoundingError(powVal, originalExtent[0])
  21426. : powVal;
  21427. powVal = (val === extent[1] && originalScale.__fixMax)
  21428. ? fixRoundingError(powVal, originalExtent[1])
  21429. : powVal;
  21430. return powVal;
  21431. }, this);
  21432. },
  21433. /**
  21434. * @param {number} val
  21435. * @return {string}
  21436. */
  21437. getLabel: intervalScaleProto.getLabel,
  21438. /**
  21439. * @param {number} val
  21440. * @return {number}
  21441. */
  21442. scale: function (val) {
  21443. val = scaleProto.scale.call(this, val);
  21444. return mathPow(this.base, val);
  21445. },
  21446. /**
  21447. * @param {number} start
  21448. * @param {number} end
  21449. */
  21450. setExtent: function (start, end) {
  21451. var base = this.base;
  21452. start = mathLog(start) / mathLog(base);
  21453. end = mathLog(end) / mathLog(base);
  21454. intervalScaleProto.setExtent.call(this, start, end);
  21455. },
  21456. /**
  21457. * @return {number} end
  21458. */
  21459. getExtent: function () {
  21460. var base = this.base;
  21461. var extent = scaleProto.getExtent.call(this);
  21462. extent[0] = mathPow(base, extent[0]);
  21463. extent[1] = mathPow(base, extent[1]);
  21464. // Fix #4158
  21465. var originalScale = this._originalScale;
  21466. var originalExtent = originalScale.getExtent();
  21467. originalScale.__fixMin && (extent[0] = fixRoundingError(extent[0], originalExtent[0]));
  21468. originalScale.__fixMax && (extent[1] = fixRoundingError(extent[1], originalExtent[1]));
  21469. return extent;
  21470. },
  21471. /**
  21472. * @param {Array.<number>} extent
  21473. */
  21474. unionExtent: function (extent) {
  21475. this._originalScale.unionExtent(extent);
  21476. var base = this.base;
  21477. extent[0] = mathLog(extent[0]) / mathLog(base);
  21478. extent[1] = mathLog(extent[1]) / mathLog(base);
  21479. scaleProto.unionExtent.call(this, extent);
  21480. },
  21481. /**
  21482. * @override
  21483. */
  21484. unionExtentFromData: function (data, dim) {
  21485. this.unionExtent(data.getDataExtent(dim, true, function (val) {
  21486. return val > 0;
  21487. }));
  21488. },
  21489. /**
  21490. * Update interval and extent of intervals for nice ticks
  21491. * @param {number} [approxTickNum = 10] Given approx tick number
  21492. */
  21493. niceTicks: function (approxTickNum) {
  21494. approxTickNum = approxTickNum || 10;
  21495. var extent = this._extent;
  21496. var span = extent[1] - extent[0];
  21497. if (span === Infinity || span <= 0) {
  21498. return;
  21499. }
  21500. var interval = numberUtil.quantity(span);
  21501. var err = approxTickNum / span * interval;
  21502. // Filter ticks to get closer to the desired count.
  21503. if (err <= 0.5) {
  21504. interval *= 10;
  21505. }
  21506. // Interval should be integer
  21507. while (!isNaN(interval) && Math.abs(interval) < 1 && Math.abs(interval) > 0) {
  21508. interval *= 10;
  21509. }
  21510. var niceExtent = [
  21511. numberUtil.round(mathCeil(extent[0] / interval) * interval),
  21512. numberUtil.round(mathFloor(extent[1] / interval) * interval)
  21513. ];
  21514. this._interval = interval;
  21515. this._niceExtent = niceExtent;
  21516. },
  21517. /**
  21518. * Nice extent.
  21519. * @override
  21520. */
  21521. niceExtent: function (opt) {
  21522. intervalScaleProto.niceExtent.call(this, opt);
  21523. var originalScale = this._originalScale;
  21524. originalScale.__fixMin = opt.fixMin;
  21525. originalScale.__fixMax = opt.fixMax;
  21526. }
  21527. });
  21528. zrUtil.each(['contain', 'normalize'], function (methodName) {
  21529. LogScale.prototype[methodName] = function (val) {
  21530. val = mathLog(val) / mathLog(this.base);
  21531. return scaleProto[methodName].call(this, val);
  21532. };
  21533. });
  21534. LogScale.create = function () {
  21535. return new LogScale();
  21536. };
  21537. function fixRoundingError(val, originalVal) {
  21538. return roundingErrorFix(val, getPrecisionSafe(originalVal));
  21539. }
  21540. module.exports = LogScale;
  21541. /***/ },
  21542. /* 108 */
  21543. /***/ function(module, exports, __webpack_require__) {
  21544. var createListFromArray = __webpack_require__(109);
  21545. var symbolUtil = __webpack_require__(111);
  21546. var axisHelper = __webpack_require__(101);
  21547. var axisModelCommonMixin = __webpack_require__(112);
  21548. var Model = __webpack_require__(12);
  21549. var util = __webpack_require__(4);
  21550. module.exports = {
  21551. /**
  21552. * Create a muti dimension List structure from seriesModel.
  21553. * @param {module:echarts/model/Model} seriesModel
  21554. * @return {module:echarts/data/List} list
  21555. */
  21556. createList: function (seriesModel) {
  21557. var data = seriesModel.get('data');
  21558. return createListFromArray(data, seriesModel, seriesModel.ecModel);
  21559. },
  21560. /**
  21561. * @see {module:echarts/data/helper/completeDimensions}
  21562. */
  21563. completeDimensions: __webpack_require__(110),
  21564. /**
  21565. * Create a symbol element with given symbol configuration: shape, x, y, width, height, color
  21566. * @see http://echarts.baidu.com/option.html#series-scatter.symbol
  21567. * @param {string} symbolDesc
  21568. * @param {number} x
  21569. * @param {number} y
  21570. * @param {number} w
  21571. * @param {number} h
  21572. * @param {string} color
  21573. */
  21574. createSymbol: symbolUtil.createSymbol,
  21575. /**
  21576. * Create scale
  21577. * @param {Array.<number>} dataExtent
  21578. * @param {Object|module:echarts/Model} option
  21579. */
  21580. createScale: function (dataExtent, option) {
  21581. var axisModel = option;
  21582. if (!(option instanceof Model)) {
  21583. axisModel = new Model(option);
  21584. util.mixin(axisModel, axisModelCommonMixin);
  21585. }
  21586. var scale = axisHelper.createScaleByModel(axisModel);
  21587. scale.setExtent(dataExtent[0], dataExtent[1]);
  21588. axisHelper.niceScaleExtent(scale, axisModel);
  21589. return scale;
  21590. },
  21591. /**
  21592. * Mixin common methods to axis model,
  21593. *
  21594. * Inlcude methods
  21595. * `getFormattedLabels() => Array.<string>`
  21596. * `getCategories() => Array.<string>`
  21597. * `getMin(origin: boolean) => number`
  21598. * `getMax(origin: boolean) => number`
  21599. * `getNeedCrossZero() => boolean`
  21600. * `setRange(start: number, end: number)`
  21601. * `resetRange()`
  21602. */
  21603. mixinAxisModelCommonMethods: function (Model) {
  21604. util.mixin(Model, axisModelCommonMixin);
  21605. }
  21606. };
  21607. /***/ },
  21608. /* 109 */
  21609. /***/ function(module, exports, __webpack_require__) {
  21610. 'use strict';
  21611. var List = __webpack_require__(98);
  21612. var completeDimensions = __webpack_require__(110);
  21613. var zrUtil = __webpack_require__(4);
  21614. var modelUtil = __webpack_require__(5);
  21615. var CoordinateSystem = __webpack_require__(76);
  21616. var getDataItemValue = modelUtil.getDataItemValue;
  21617. var converDataValue = modelUtil.converDataValue;
  21618. function firstDataNotNull(data) {
  21619. var i = 0;
  21620. while (i < data.length && data[i] == null) {
  21621. i++;
  21622. }
  21623. return data[i];
  21624. }
  21625. function ifNeedCompleteOrdinalData(data) {
  21626. var sampleItem = firstDataNotNull(data);
  21627. return sampleItem != null
  21628. && !zrUtil.isArray(getDataItemValue(sampleItem));
  21629. }
  21630. /**
  21631. * Helper function to create a list from option data
  21632. */
  21633. function createListFromArray(data, seriesModel, ecModel) {
  21634. // If data is undefined
  21635. data = data || [];
  21636. if (true) {
  21637. if (!zrUtil.isArray(data)) {
  21638. throw new Error('Invalid data.');
  21639. }
  21640. }
  21641. var coordSysName = seriesModel.get('coordinateSystem');
  21642. var creator = creators[coordSysName];
  21643. var registeredCoordSys = CoordinateSystem.get(coordSysName);
  21644. var completeDimOpt = {
  21645. encodeDef: seriesModel.get('encode'),
  21646. dimsDef: seriesModel.get('dimensions')
  21647. };
  21648. // FIXME
  21649. var axesInfo = creator && creator(data, seriesModel, ecModel, completeDimOpt);
  21650. var dimensions = axesInfo && axesInfo.dimensions;
  21651. if (!dimensions) {
  21652. // Get dimensions from registered coordinate system
  21653. dimensions = (registeredCoordSys && (
  21654. registeredCoordSys.getDimensionsInfo
  21655. ? registeredCoordSys.getDimensionsInfo()
  21656. : registeredCoordSys.dimensions.slice()
  21657. )) || ['x', 'y'];
  21658. dimensions = completeDimensions(dimensions, data, completeDimOpt);
  21659. }
  21660. var categoryIndex = axesInfo ? axesInfo.categoryIndex : -1;
  21661. var list = new List(dimensions, seriesModel);
  21662. var nameList = createNameList(axesInfo, data);
  21663. var categories = {};
  21664. var dimValueGetter = (categoryIndex >= 0 && ifNeedCompleteOrdinalData(data))
  21665. ? function (itemOpt, dimName, dataIndex, dimIndex) {
  21666. // If any dataItem is like { value: 10 }
  21667. if (modelUtil.isDataItemOption(itemOpt)) {
  21668. list.hasItemOption = true;
  21669. }
  21670. // Use dataIndex as ordinal value in categoryAxis
  21671. return dimIndex === categoryIndex
  21672. ? dataIndex
  21673. : converDataValue(getDataItemValue(itemOpt), dimensions[dimIndex]);
  21674. }
  21675. : function (itemOpt, dimName, dataIndex, dimIndex) {
  21676. var value = getDataItemValue(itemOpt);
  21677. var val = converDataValue(value && value[dimIndex], dimensions[dimIndex]);
  21678. // If any dataItem is like { value: 10 }
  21679. if (modelUtil.isDataItemOption(itemOpt)) {
  21680. list.hasItemOption = true;
  21681. }
  21682. var categoryAxesModels = axesInfo && axesInfo.categoryAxesModels;
  21683. if (categoryAxesModels && categoryAxesModels[dimName]) {
  21684. // If given value is a category string
  21685. if (typeof val === 'string') {
  21686. // Lazy get categories
  21687. categories[dimName] = categories[dimName]
  21688. || categoryAxesModels[dimName].getCategories();
  21689. val = zrUtil.indexOf(categories[dimName], val);
  21690. if (val < 0 && !isNaN(val)) {
  21691. // In case some one write '1', '2' istead of 1, 2
  21692. val = +val;
  21693. }
  21694. }
  21695. }
  21696. return val;
  21697. };
  21698. list.hasItemOption = false;
  21699. list.initData(data, nameList, dimValueGetter);
  21700. return list;
  21701. }
  21702. function isStackable(axisType) {
  21703. return axisType !== 'category' && axisType !== 'time';
  21704. }
  21705. function getDimTypeByAxis(axisType) {
  21706. return axisType === 'category'
  21707. ? 'ordinal'
  21708. : axisType === 'time'
  21709. ? 'time'
  21710. : 'float';
  21711. }
  21712. /**
  21713. * Creaters for each coord system.
  21714. */
  21715. var creators = {
  21716. cartesian2d: function (data, seriesModel, ecModel, completeDimOpt) {
  21717. var axesModels = zrUtil.map(['xAxis', 'yAxis'], function (name) {
  21718. return ecModel.queryComponents({
  21719. mainType: name,
  21720. index: seriesModel.get(name + 'Index'),
  21721. id: seriesModel.get(name + 'Id')
  21722. })[0];
  21723. });
  21724. var xAxisModel = axesModels[0];
  21725. var yAxisModel = axesModels[1];
  21726. if (true) {
  21727. if (!xAxisModel) {
  21728. throw new Error('xAxis "' + zrUtil.retrieve(
  21729. seriesModel.get('xAxisIndex'),
  21730. seriesModel.get('xAxisId'),
  21731. 0
  21732. ) + '" not found');
  21733. }
  21734. if (!yAxisModel) {
  21735. throw new Error('yAxis "' + zrUtil.retrieve(
  21736. seriesModel.get('xAxisIndex'),
  21737. seriesModel.get('yAxisId'),
  21738. 0
  21739. ) + '" not found');
  21740. }
  21741. }
  21742. var xAxisType = xAxisModel.get('type');
  21743. var yAxisType = yAxisModel.get('type');
  21744. var dimensions = [
  21745. {
  21746. name: 'x',
  21747. type: getDimTypeByAxis(xAxisType),
  21748. stackable: isStackable(xAxisType)
  21749. },
  21750. {
  21751. name: 'y',
  21752. // If two category axes
  21753. type: getDimTypeByAxis(yAxisType),
  21754. stackable: isStackable(yAxisType)
  21755. }
  21756. ];
  21757. var isXAxisCateogry = xAxisType === 'category';
  21758. var isYAxisCategory = yAxisType === 'category';
  21759. dimensions = completeDimensions(dimensions, data, completeDimOpt);
  21760. var categoryAxesModels = {};
  21761. if (isXAxisCateogry) {
  21762. categoryAxesModels.x = xAxisModel;
  21763. }
  21764. if (isYAxisCategory) {
  21765. categoryAxesModels.y = yAxisModel;
  21766. }
  21767. return {
  21768. dimensions: dimensions,
  21769. categoryIndex: isXAxisCateogry ? 0 : (isYAxisCategory ? 1 : -1),
  21770. categoryAxesModels: categoryAxesModels
  21771. };
  21772. },
  21773. singleAxis: function (data, seriesModel, ecModel, completeDimOpt) {
  21774. var singleAxisModel = ecModel.queryComponents({
  21775. mainType: 'singleAxis',
  21776. index: seriesModel.get('singleAxisIndex'),
  21777. id: seriesModel.get('singleAxisId')
  21778. })[0];
  21779. if (true) {
  21780. if (!singleAxisModel) {
  21781. throw new Error('singleAxis should be specified.');
  21782. }
  21783. }
  21784. var singleAxisType = singleAxisModel.get('type');
  21785. var isCategory = singleAxisType === 'category';
  21786. var dimensions = [{
  21787. name: 'single',
  21788. type: getDimTypeByAxis(singleAxisType),
  21789. stackable: isStackable(singleAxisType)
  21790. }];
  21791. dimensions = completeDimensions(dimensions, data, completeDimOpt);
  21792. var categoryAxesModels = {};
  21793. if (isCategory) {
  21794. categoryAxesModels.single = singleAxisModel;
  21795. }
  21796. return {
  21797. dimensions: dimensions,
  21798. categoryIndex: isCategory ? 0 : -1,
  21799. categoryAxesModels: categoryAxesModels
  21800. };
  21801. },
  21802. polar: function (data, seriesModel, ecModel, completeDimOpt) {
  21803. var polarModel = ecModel.queryComponents({
  21804. mainType: 'polar',
  21805. index: seriesModel.get('polarIndex'),
  21806. id: seriesModel.get('polarId')
  21807. })[0];
  21808. var angleAxisModel = polarModel.findAxisModel('angleAxis');
  21809. var radiusAxisModel = polarModel.findAxisModel('radiusAxis');
  21810. if (true) {
  21811. if (!angleAxisModel) {
  21812. throw new Error('angleAxis option not found');
  21813. }
  21814. if (!radiusAxisModel) {
  21815. throw new Error('radiusAxis option not found');
  21816. }
  21817. }
  21818. var radiusAxisType = radiusAxisModel.get('type');
  21819. var angleAxisType = angleAxisModel.get('type');
  21820. var dimensions = [
  21821. {
  21822. name: 'radius',
  21823. type: getDimTypeByAxis(radiusAxisType),
  21824. stackable: isStackable(radiusAxisType)
  21825. },
  21826. {
  21827. name: 'angle',
  21828. type: getDimTypeByAxis(angleAxisType),
  21829. stackable: isStackable(angleAxisType)
  21830. }
  21831. ];
  21832. var isAngleAxisCateogry = angleAxisType === 'category';
  21833. var isRadiusAxisCateogry = radiusAxisType === 'category';
  21834. dimensions = completeDimensions(dimensions, data, completeDimOpt);
  21835. var categoryAxesModels = {};
  21836. if (isRadiusAxisCateogry) {
  21837. categoryAxesModels.radius = radiusAxisModel;
  21838. }
  21839. if (isAngleAxisCateogry) {
  21840. categoryAxesModels.angle = angleAxisModel;
  21841. }
  21842. return {
  21843. dimensions: dimensions,
  21844. categoryIndex: isAngleAxisCateogry ? 1 : (isRadiusAxisCateogry ? 0 : -1),
  21845. categoryAxesModels: categoryAxesModels
  21846. };
  21847. },
  21848. geo: function (data, seriesModel, ecModel, completeDimOpt) {
  21849. // TODO Region
  21850. // 多个散点图系列在同一个地区的时候
  21851. return {
  21852. dimensions: completeDimensions([
  21853. {name: 'lng'},
  21854. {name: 'lat'}
  21855. ], data, completeDimOpt)
  21856. };
  21857. }
  21858. };
  21859. function createNameList(result, data) {
  21860. var nameList = [];
  21861. var categoryDim = result && result.dimensions[result.categoryIndex];
  21862. var categoryAxisModel;
  21863. if (categoryDim) {
  21864. categoryAxisModel = result.categoryAxesModels[categoryDim.name];
  21865. }
  21866. if (categoryAxisModel) {
  21867. // FIXME Two category axis
  21868. var categories = categoryAxisModel.getCategories();
  21869. if (categories) {
  21870. var dataLen = data.length;
  21871. // Ordered data is given explicitly like
  21872. // [[3, 0.2], [1, 0.3], [2, 0.15]]
  21873. // or given scatter data,
  21874. // pick the category
  21875. if (zrUtil.isArray(data[0]) && data[0].length > 1) {
  21876. nameList = [];
  21877. for (var i = 0; i < dataLen; i++) {
  21878. nameList[i] = categories[data[i][result.categoryIndex || 0]];
  21879. }
  21880. }
  21881. else {
  21882. nameList = categories.slice(0);
  21883. }
  21884. }
  21885. }
  21886. return nameList;
  21887. }
  21888. module.exports = createListFromArray;
  21889. /***/ },
  21890. /* 110 */
  21891. /***/ function(module, exports, __webpack_require__) {
  21892. /**
  21893. * Complete dimensions by data (guess dimension).
  21894. */
  21895. var zrUtil = __webpack_require__(4);
  21896. var modelUtil = __webpack_require__(5);
  21897. var each = zrUtil.each;
  21898. var isString = zrUtil.isString;
  21899. var defaults = zrUtil.defaults;
  21900. var normalizeToArray = modelUtil.normalizeToArray;
  21901. var OTHER_DIMS = {tooltip: 1, label: 1, itemName: 1};
  21902. /**
  21903. * Complete the dimensions array, by user defined `dimension` and `encode`,
  21904. * and guessing from the data structure.
  21905. * If no 'value' dimension specified, the first no-named dimension will be
  21906. * named as 'value'.
  21907. *
  21908. * @param {Array.<string>} sysDims Necessary dimensions, like ['x', 'y'], which
  21909. * provides not only dim template, but also default order.
  21910. * `name` of each item provides default coord name.
  21911. * [{dimsDef: []}, ...] can be specified to give names.
  21912. * @param {Array} data Data list. [[1, 2, 3], [2, 3, 4]].
  21913. * @param {Object} [opt]
  21914. * @param {Array.<Object|string>} [opt.dimsDef] option.series.dimensions User defined dimensions
  21915. * For example: ['asdf', {name, type}, ...].
  21916. * @param {Object} [opt.encodeDef] option.series.encode {x: 2, y: [3, 1], tooltip: [1, 2], label: 3}
  21917. * @param {string} [opt.extraPrefix] Prefix of name when filling the left dimensions.
  21918. * @param {string} [opt.extraFromZero] If specified, extra dim names will be:
  21919. * extraPrefix + 0, extraPrefix + extraBaseIndex + 1 ...
  21920. * If not specified, extra dim names will be:
  21921. * extraPrefix, extraPrefix + 0, extraPrefix + 1 ...
  21922. * @param {number} [opt.dimCount] If not specified, guess by the first data item.
  21923. * @return {Array.<Object>} [{
  21924. * name: string mandatory,
  21925. * coordDim: string mandatory,
  21926. * coordDimIndex: number mandatory,
  21927. * type: string optional,
  21928. * tooltipName: string optional,
  21929. * otherDims: {
  21930. * tooltip: number optional,
  21931. * label: number optional
  21932. * },
  21933. * isExtraCoord: boolean true or undefined.
  21934. * other props ...
  21935. * }]
  21936. */
  21937. function completeDimensions(sysDims, data, opt) {
  21938. data = data || [];
  21939. opt = opt || {};
  21940. sysDims = (sysDims || []).slice();
  21941. var dimsDef = (opt.dimsDef || []).slice();
  21942. var encodeDef = zrUtil.createHashMap(opt.encodeDef);
  21943. var dataDimNameMap = zrUtil.createHashMap();
  21944. var coordDimNameMap = zrUtil.createHashMap();
  21945. // var valueCandidate;
  21946. var result = [];
  21947. var dimCount = opt.dimCount;
  21948. if (dimCount == null) {
  21949. var value0 = retrieveValue(data[0]);
  21950. dimCount = Math.max(
  21951. zrUtil.isArray(value0) && value0.length || 1,
  21952. sysDims.length,
  21953. dimsDef.length
  21954. );
  21955. each(sysDims, function (sysDimItem) {
  21956. var sysDimItemDimsDef = sysDimItem.dimsDef;
  21957. sysDimItemDimsDef && (dimCount = Math.max(dimCount, sysDimItemDimsDef.length));
  21958. });
  21959. }
  21960. // Apply user defined dims (`name` and `type`) and init result.
  21961. for (var i = 0; i < dimCount; i++) {
  21962. var dimDefItem = isString(dimsDef[i]) ? {name: dimsDef[i]} : (dimsDef[i] || {});
  21963. var userDimName = dimDefItem.name;
  21964. var resultItem = result[i] = {otherDims: {}};
  21965. // Name will be applied later for avoiding duplication.
  21966. if (userDimName != null && dataDimNameMap.get(userDimName) == null) {
  21967. // Only if `series.dimensions` is defined in option, tooltipName
  21968. // will be set, and dimension will be diplayed vertically in
  21969. // tooltip by default.
  21970. resultItem.name = resultItem.tooltipName = userDimName;
  21971. dataDimNameMap.set(userDimName, i);
  21972. }
  21973. dimDefItem.type != null && (resultItem.type = dimDefItem.type);
  21974. }
  21975. // Set `coordDim` and `coordDimIndex` by `encodeDef` and normalize `encodeDef`.
  21976. encodeDef.each(function (dataDims, coordDim) {
  21977. dataDims = encodeDef.set(coordDim, normalizeToArray(dataDims).slice());
  21978. each(dataDims, function (resultDimIdx, coordDimIndex) {
  21979. // The input resultDimIdx can be dim name or index.
  21980. isString(resultDimIdx) && (resultDimIdx = dataDimNameMap.get(resultDimIdx));
  21981. if (resultDimIdx != null && resultDimIdx < dimCount) {
  21982. dataDims[coordDimIndex] = resultDimIdx;
  21983. applyDim(result[resultDimIdx], coordDim, coordDimIndex);
  21984. // coordDim === 'value' && valueCandidate == null && (valueCandidate = resultDimIdx);
  21985. }
  21986. });
  21987. });
  21988. // Apply templetes and default order from `sysDims`.
  21989. var availDimIdx = 0;
  21990. each(sysDims, function (sysDimItem, sysDimIndex) {
  21991. var coordDim;
  21992. var sysDimItem;
  21993. var sysDimItemDimsDef;
  21994. var sysDimItemOtherDims;
  21995. if (isString(sysDimItem)) {
  21996. coordDim = sysDimItem;
  21997. sysDimItem = {};
  21998. }
  21999. else {
  22000. coordDim = sysDimItem.name;
  22001. sysDimItem = zrUtil.clone(sysDimItem);
  22002. // `coordDimIndex` should not be set directly.
  22003. sysDimItemDimsDef = sysDimItem.dimsDef;
  22004. sysDimItemOtherDims = sysDimItem.otherDims;
  22005. sysDimItem.name = sysDimItem.coordDim = sysDimItem.coordDimIndex
  22006. = sysDimItem.dimsDef = sysDimItem.otherDims = null;
  22007. }
  22008. var dataDims = normalizeToArray(encodeDef.get(coordDim));
  22009. // dimensions provides default dim sequences.
  22010. if (!dataDims.length) {
  22011. for (var i = 0; i < (sysDimItemDimsDef && sysDimItemDimsDef.length || 1); i++) {
  22012. while (availDimIdx < result.length && result[availDimIdx].coordDim != null) {
  22013. availDimIdx++;
  22014. }
  22015. availDimIdx < result.length && dataDims.push(availDimIdx++);
  22016. }
  22017. }
  22018. // Apply templates.
  22019. each(dataDims, function (resultDimIdx, coordDimIndex) {
  22020. var resultItem = result[resultDimIdx];
  22021. applyDim(defaults(resultItem, sysDimItem), coordDim, coordDimIndex);
  22022. // coordDim === 'value' && valueCandidate == null && (valueCandidate = resultDimIdx);
  22023. if (resultItem.name == null && sysDimItemDimsDef) {
  22024. resultItem.name = resultItem.tooltipName = sysDimItemDimsDef[coordDimIndex];
  22025. }
  22026. sysDimItemOtherDims && defaults(resultItem.otherDims, sysDimItemOtherDims);
  22027. });
  22028. });
  22029. // Make sure the first extra dim is 'value'.
  22030. var extra = opt.extraPrefix || 'value';
  22031. // Set dim `name` and other `coordDim` and other props.
  22032. for (var resultDimIdx = 0; resultDimIdx < dimCount; resultDimIdx++) {
  22033. var resultItem = result[resultDimIdx] = result[resultDimIdx] || {};
  22034. var coordDim = resultItem.coordDim;
  22035. coordDim == null && (
  22036. resultItem.coordDim = genName(extra, coordDimNameMap, opt.extraFromZero),
  22037. resultItem.coordDimIndex = 0,
  22038. resultItem.isExtraCoord = true
  22039. );
  22040. resultItem.name == null && (resultItem.name = genName(
  22041. // Ensure At least one value dim.
  22042. // (dataDimNameMap.get('value') == null
  22043. // && (valueCandidate == null || valueCandidate === resultDimIdx)
  22044. // // Try to set as 'value' only if coordDim is not set as 'extra'.
  22045. // && coordDim == null
  22046. // )
  22047. // ? 'value'
  22048. // :
  22049. resultItem.coordDim,
  22050. dataDimNameMap
  22051. ));
  22052. resultItem.type == null && guessOrdinal(data, resultDimIdx)
  22053. && (resultItem.type = 'ordinal');
  22054. }
  22055. return result;
  22056. function applyDim(resultItem, coordDim, coordDimIndex) {
  22057. if (OTHER_DIMS[coordDim]) {
  22058. resultItem.otherDims[coordDim] = coordDimIndex;
  22059. }
  22060. else {
  22061. resultItem.coordDim = coordDim;
  22062. resultItem.coordDimIndex = coordDimIndex;
  22063. coordDimNameMap.set(coordDim, true);
  22064. }
  22065. }
  22066. function genName(name, map, fromZero) {
  22067. if (fromZero || map.get(name) != null) {
  22068. var i = 0;
  22069. while (map.get(name + i) != null) {
  22070. i++;
  22071. }
  22072. name += i;
  22073. }
  22074. map.set(name, true);
  22075. return name;
  22076. }
  22077. }
  22078. // The rule should not be complex, otherwise user might not
  22079. // be able to known where the data is wrong.
  22080. var guessOrdinal = completeDimensions.guessOrdinal = function (data, dimIndex) {
  22081. for (var i = 0, len = data.length; i < len; i++) {
  22082. var value = retrieveValue(data[i]);
  22083. if (!zrUtil.isArray(value)) {
  22084. return false;
  22085. }
  22086. var value = value[dimIndex];
  22087. // Consider usage convenience, '1', '2' will be treated as "number".
  22088. if (value != null && isFinite(value)) {
  22089. return false;
  22090. }
  22091. else if (isString(value) && value !== '-') {
  22092. return true;
  22093. }
  22094. }
  22095. return false;
  22096. };
  22097. function retrieveValue(o) {
  22098. return zrUtil.isArray(o) ? o : zrUtil.isObject(o) ? o.value: o;
  22099. }
  22100. module.exports = completeDimensions;
  22101. /***/ },
  22102. /* 111 */
  22103. /***/ function(module, exports, __webpack_require__) {
  22104. 'use strict';
  22105. // Symbol factory
  22106. var graphic = __webpack_require__(18);
  22107. var BoundingRect = __webpack_require__(9);
  22108. /**
  22109. * Triangle shape
  22110. * @inner
  22111. */
  22112. var Triangle = graphic.extendShape({
  22113. type: 'triangle',
  22114. shape: {
  22115. cx: 0,
  22116. cy: 0,
  22117. width: 0,
  22118. height: 0
  22119. },
  22120. buildPath: function (path, shape) {
  22121. var cx = shape.cx;
  22122. var cy = shape.cy;
  22123. var width = shape.width / 2;
  22124. var height = shape.height / 2;
  22125. path.moveTo(cx, cy - height);
  22126. path.lineTo(cx + width, cy + height);
  22127. path.lineTo(cx - width, cy + height);
  22128. path.closePath();
  22129. }
  22130. });
  22131. /**
  22132. * Diamond shape
  22133. * @inner
  22134. */
  22135. var Diamond = graphic.extendShape({
  22136. type: 'diamond',
  22137. shape: {
  22138. cx: 0,
  22139. cy: 0,
  22140. width: 0,
  22141. height: 0
  22142. },
  22143. buildPath: function (path, shape) {
  22144. var cx = shape.cx;
  22145. var cy = shape.cy;
  22146. var width = shape.width / 2;
  22147. var height = shape.height / 2;
  22148. path.moveTo(cx, cy - height);
  22149. path.lineTo(cx + width, cy);
  22150. path.lineTo(cx, cy + height);
  22151. path.lineTo(cx - width, cy);
  22152. path.closePath();
  22153. }
  22154. });
  22155. /**
  22156. * Pin shape
  22157. * @inner
  22158. */
  22159. var Pin = graphic.extendShape({
  22160. type: 'pin',
  22161. shape: {
  22162. // x, y on the cusp
  22163. x: 0,
  22164. y: 0,
  22165. width: 0,
  22166. height: 0
  22167. },
  22168. buildPath: function (path, shape) {
  22169. var x = shape.x;
  22170. var y = shape.y;
  22171. var w = shape.width / 5 * 3;
  22172. // Height must be larger than width
  22173. var h = Math.max(w, shape.height);
  22174. var r = w / 2;
  22175. // Dist on y with tangent point and circle center
  22176. var dy = r * r / (h - r);
  22177. var cy = y - h + r + dy;
  22178. var angle = Math.asin(dy / r);
  22179. // Dist on x with tangent point and circle center
  22180. var dx = Math.cos(angle) * r;
  22181. var tanX = Math.sin(angle);
  22182. var tanY = Math.cos(angle);
  22183. path.arc(
  22184. x, cy, r,
  22185. Math.PI - angle,
  22186. Math.PI * 2 + angle
  22187. );
  22188. var cpLen = r * 0.6;
  22189. var cpLen2 = r * 0.7;
  22190. path.bezierCurveTo(
  22191. x + dx - tanX * cpLen, cy + dy + tanY * cpLen,
  22192. x, y - cpLen2,
  22193. x, y
  22194. );
  22195. path.bezierCurveTo(
  22196. x, y - cpLen2,
  22197. x - dx + tanX * cpLen, cy + dy + tanY * cpLen,
  22198. x - dx, cy + dy
  22199. );
  22200. path.closePath();
  22201. }
  22202. });
  22203. /**
  22204. * Arrow shape
  22205. * @inner
  22206. */
  22207. var Arrow = graphic.extendShape({
  22208. type: 'arrow',
  22209. shape: {
  22210. x: 0,
  22211. y: 0,
  22212. width: 0,
  22213. height: 0
  22214. },
  22215. buildPath: function (ctx, shape) {
  22216. var height = shape.height;
  22217. var width = shape.width;
  22218. var x = shape.x;
  22219. var y = shape.y;
  22220. var dx = width / 3 * 2;
  22221. ctx.moveTo(x, y);
  22222. ctx.lineTo(x + dx, y + height);
  22223. ctx.lineTo(x, y + height / 4 * 3);
  22224. ctx.lineTo(x - dx, y + height);
  22225. ctx.lineTo(x, y);
  22226. ctx.closePath();
  22227. }
  22228. });
  22229. /**
  22230. * Map of path contructors
  22231. * @type {Object.<string, module:zrender/graphic/Path>}
  22232. */
  22233. var symbolCtors = {
  22234. line: graphic.Line,
  22235. rect: graphic.Rect,
  22236. roundRect: graphic.Rect,
  22237. square: graphic.Rect,
  22238. circle: graphic.Circle,
  22239. diamond: Diamond,
  22240. pin: Pin,
  22241. arrow: Arrow,
  22242. triangle: Triangle
  22243. };
  22244. var symbolShapeMakers = {
  22245. line: function (x, y, w, h, shape) {
  22246. // FIXME
  22247. shape.x1 = x;
  22248. shape.y1 = y + h / 2;
  22249. shape.x2 = x + w;
  22250. shape.y2 = y + h / 2;
  22251. },
  22252. rect: function (x, y, w, h, shape) {
  22253. shape.x = x;
  22254. shape.y = y;
  22255. shape.width = w;
  22256. shape.height = h;
  22257. },
  22258. roundRect: function (x, y, w, h, shape) {
  22259. shape.x = x;
  22260. shape.y = y;
  22261. shape.width = w;
  22262. shape.height = h;
  22263. shape.r = Math.min(w, h) / 4;
  22264. },
  22265. square: function (x, y, w, h, shape) {
  22266. var size = Math.min(w, h);
  22267. shape.x = x;
  22268. shape.y = y;
  22269. shape.width = size;
  22270. shape.height = size;
  22271. },
  22272. circle: function (x, y, w, h, shape) {
  22273. // Put circle in the center of square
  22274. shape.cx = x + w / 2;
  22275. shape.cy = y + h / 2;
  22276. shape.r = Math.min(w, h) / 2;
  22277. },
  22278. diamond: function (x, y, w, h, shape) {
  22279. shape.cx = x + w / 2;
  22280. shape.cy = y + h / 2;
  22281. shape.width = w;
  22282. shape.height = h;
  22283. },
  22284. pin: function (x, y, w, h, shape) {
  22285. shape.x = x + w / 2;
  22286. shape.y = y + h / 2;
  22287. shape.width = w;
  22288. shape.height = h;
  22289. },
  22290. arrow: function (x, y, w, h, shape) {
  22291. shape.x = x + w / 2;
  22292. shape.y = y + h / 2;
  22293. shape.width = w;
  22294. shape.height = h;
  22295. },
  22296. triangle: function (x, y, w, h, shape) {
  22297. shape.cx = x + w / 2;
  22298. shape.cy = y + h / 2;
  22299. shape.width = w;
  22300. shape.height = h;
  22301. }
  22302. };
  22303. var symbolBuildProxies = {};
  22304. for (var name in symbolCtors) {
  22305. if (symbolCtors.hasOwnProperty(name)) {
  22306. symbolBuildProxies[name] = new symbolCtors[name]();
  22307. }
  22308. }
  22309. var Symbol = graphic.extendShape({
  22310. type: 'symbol',
  22311. shape: {
  22312. symbolType: '',
  22313. x: 0,
  22314. y: 0,
  22315. width: 0,
  22316. height: 0
  22317. },
  22318. beforeBrush: function () {
  22319. var style = this.style;
  22320. var shape = this.shape;
  22321. // FIXME
  22322. if (shape.symbolType === 'pin' && style.textPosition === 'inside') {
  22323. style.textPosition = ['50%', '40%'];
  22324. style.textAlign = 'center';
  22325. style.textVerticalAlign = 'middle';
  22326. }
  22327. },
  22328. buildPath: function (ctx, shape, inBundle) {
  22329. var symbolType = shape.symbolType;
  22330. var proxySymbol = symbolBuildProxies[symbolType];
  22331. if (shape.symbolType !== 'none') {
  22332. if (!proxySymbol) {
  22333. // Default rect
  22334. symbolType = 'rect';
  22335. proxySymbol = symbolBuildProxies[symbolType];
  22336. }
  22337. symbolShapeMakers[symbolType](
  22338. shape.x, shape.y, shape.width, shape.height, proxySymbol.shape
  22339. );
  22340. proxySymbol.buildPath(ctx, proxySymbol.shape, inBundle);
  22341. }
  22342. }
  22343. });
  22344. // Provide setColor helper method to avoid determine if set the fill or stroke outside
  22345. var symbolPathSetColor = function (color) {
  22346. if (this.type !== 'image') {
  22347. var symbolStyle = this.style;
  22348. var symbolShape = this.shape;
  22349. if (symbolShape && symbolShape.symbolType === 'line') {
  22350. symbolStyle.stroke = color;
  22351. }
  22352. else if (this.__isEmptyBrush) {
  22353. symbolStyle.stroke = color;
  22354. symbolStyle.fill = '#fff';
  22355. }
  22356. else {
  22357. // FIXME 判断图形默认是填充还是描边,使用 onlyStroke ?
  22358. symbolStyle.fill && (symbolStyle.fill = color);
  22359. symbolStyle.stroke && (symbolStyle.stroke = color);
  22360. }
  22361. this.dirty(false);
  22362. }
  22363. };
  22364. var symbolUtil = {
  22365. /**
  22366. * Create a symbol element with given symbol configuration: shape, x, y, width, height, color
  22367. * @param {string} symbolType
  22368. * @param {number} x
  22369. * @param {number} y
  22370. * @param {number} w
  22371. * @param {number} h
  22372. * @param {string} color
  22373. */
  22374. createSymbol: function (symbolType, x, y, w, h, color) {
  22375. // TODO Support image object, DynamicImage.
  22376. var isEmpty = symbolType.indexOf('empty') === 0;
  22377. if (isEmpty) {
  22378. symbolType = symbolType.substr(5, 1).toLowerCase() + symbolType.substr(6);
  22379. }
  22380. var symbolPath;
  22381. if (symbolType.indexOf('image://') === 0) {
  22382. symbolPath = new graphic.Image({
  22383. style: {
  22384. image: symbolType.slice(8),
  22385. x: x,
  22386. y: y,
  22387. width: w,
  22388. height: h
  22389. }
  22390. });
  22391. }
  22392. else if (symbolType.indexOf('path://') === 0) {
  22393. symbolPath = graphic.makePath(symbolType.slice(7), {}, new BoundingRect(x, y, w, h));
  22394. }
  22395. else {
  22396. symbolPath = new Symbol({
  22397. shape: {
  22398. symbolType: symbolType,
  22399. x: x,
  22400. y: y,
  22401. width: w,
  22402. height: h
  22403. }
  22404. });
  22405. }
  22406. symbolPath.__isEmptyBrush = isEmpty;
  22407. symbolPath.setColor = symbolPathSetColor;
  22408. symbolPath.setColor(color);
  22409. return symbolPath;
  22410. }
  22411. };
  22412. module.exports = symbolUtil;
  22413. /***/ },
  22414. /* 112 */
  22415. /***/ function(module, exports, __webpack_require__) {
  22416. var zrUtil = __webpack_require__(4);
  22417. var axisHelper = __webpack_require__(101);
  22418. function getName(obj) {
  22419. if (zrUtil.isObject(obj) && obj.value != null) {
  22420. return obj.value;
  22421. }
  22422. else {
  22423. return obj + '';
  22424. }
  22425. }
  22426. module.exports = {
  22427. /**
  22428. * Format labels
  22429. * @return {Array.<string>}
  22430. */
  22431. getFormattedLabels: function () {
  22432. return axisHelper.getFormattedLabels(
  22433. this.axis,
  22434. this.get('axisLabel.formatter')
  22435. );
  22436. },
  22437. /**
  22438. * Get categories
  22439. */
  22440. getCategories: function () {
  22441. return this.get('type') === 'category'
  22442. && zrUtil.map(this.get('data'), getName);
  22443. },
  22444. /**
  22445. * @param {boolean} origin
  22446. * @return {number|string} min value or 'dataMin' or null/undefined (means auto) or NaN
  22447. */
  22448. getMin: function (origin) {
  22449. var option = this.option;
  22450. var min = (!origin && option.rangeStart != null)
  22451. ? option.rangeStart : option.min;
  22452. if (this.axis && min != null && min !== 'dataMin' && !zrUtil.eqNaN(min)) {
  22453. min = this.axis.scale.parse(min);
  22454. }
  22455. return min;
  22456. },
  22457. /**
  22458. * @param {boolean} origin
  22459. * @return {number|string} max value or 'dataMax' or null/undefined (means auto) or NaN
  22460. */
  22461. getMax: function (origin) {
  22462. var option = this.option;
  22463. var max = (!origin && option.rangeEnd != null)
  22464. ? option.rangeEnd : option.max;
  22465. if (this.axis && max != null && max !== 'dataMax' && !zrUtil.eqNaN(max)) {
  22466. max = this.axis.scale.parse(max);
  22467. }
  22468. return max;
  22469. },
  22470. /**
  22471. * @return {boolean}
  22472. */
  22473. getNeedCrossZero: function () {
  22474. var option = this.option;
  22475. return (option.rangeStart != null || option.rangeEnd != null)
  22476. ? false : !option.scale;
  22477. },
  22478. /**
  22479. * Should be implemented by each axis model if necessary.
  22480. * @return {module:echarts/model/Component} coordinate system model
  22481. */
  22482. getCoordSysModel: zrUtil.noop,
  22483. /**
  22484. * @param {number} rangeStart Can only be finite number or null/undefined or NaN.
  22485. * @param {number} rangeEnd Can only be finite number or null/undefined or NaN.
  22486. */
  22487. setRange: function (rangeStart, rangeEnd) {
  22488. this.option.rangeStart = rangeStart;
  22489. this.option.rangeEnd = rangeEnd;
  22490. },
  22491. /**
  22492. * Reset range
  22493. */
  22494. resetRange: function () {
  22495. // rangeStart and rangeEnd is readonly.
  22496. this.option.rangeStart = this.option.rangeEnd = null;
  22497. }
  22498. };
  22499. /***/ },
  22500. /* 113 */
  22501. /***/ function(module, exports, __webpack_require__) {
  22502. var zrUtil = __webpack_require__(4);
  22503. var echarts = __webpack_require__(1);
  22504. var PRIORITY = echarts.PRIORITY;
  22505. __webpack_require__(114);
  22506. __webpack_require__(115);
  22507. echarts.registerVisual(zrUtil.curry(
  22508. __webpack_require__(121), 'line', 'circle', 'line'
  22509. ));
  22510. echarts.registerLayout(zrUtil.curry(
  22511. __webpack_require__(122), 'line'
  22512. ));
  22513. // Down sample after filter
  22514. echarts.registerProcessor(PRIORITY.PROCESSOR.STATISTIC, zrUtil.curry(
  22515. __webpack_require__(123), 'line'
  22516. ));
  22517. // In case developer forget to include grid component
  22518. __webpack_require__(124);
  22519. /***/ },
  22520. /* 114 */
  22521. /***/ function(module, exports, __webpack_require__) {
  22522. 'use strict';
  22523. var createListFromArray = __webpack_require__(109);
  22524. var SeriesModel = __webpack_require__(78);
  22525. module.exports = SeriesModel.extend({
  22526. type: 'series.line',
  22527. dependencies: ['grid', 'polar'],
  22528. getInitialData: function (option, ecModel) {
  22529. if (true) {
  22530. var coordSys = option.coordinateSystem;
  22531. if (coordSys !== 'polar' && coordSys !== 'cartesian2d') {
  22532. throw new Error('Line not support coordinateSystem besides cartesian and polar');
  22533. }
  22534. }
  22535. return createListFromArray(option.data, this, ecModel);
  22536. },
  22537. defaultOption: {
  22538. zlevel: 0, // 一级层叠
  22539. z: 2, // 二级层叠
  22540. coordinateSystem: 'cartesian2d',
  22541. legendHoverLink: true,
  22542. hoverAnimation: true,
  22543. // stack: null
  22544. // xAxisIndex: 0,
  22545. // yAxisIndex: 0,
  22546. // polarIndex: 0,
  22547. // If clip the overflow value
  22548. clipOverflow: true,
  22549. label: {
  22550. normal: {
  22551. position: 'top'
  22552. }
  22553. },
  22554. // itemStyle: {
  22555. // normal: {},
  22556. // emphasis: {}
  22557. // },
  22558. lineStyle: {
  22559. normal: {
  22560. width: 2,
  22561. type: 'solid'
  22562. }
  22563. },
  22564. // areaStyle: {},
  22565. // false, 'start', 'end', 'middle'
  22566. step: false,
  22567. // Disabled if step is true
  22568. smooth: false,
  22569. smoothMonotone: null,
  22570. // 拐点图形类型
  22571. symbol: 'emptyCircle',
  22572. // 拐点图形大小
  22573. symbolSize: 4,
  22574. // 拐点图形旋转控制
  22575. symbolRotate: null,
  22576. // 是否显示 symbol, 只有在 tooltip hover 的时候显示
  22577. showSymbol: true,
  22578. // 标志图形默认只有主轴显示(随主轴标签间隔隐藏策略)
  22579. showAllSymbol: false,
  22580. // 是否连接断点
  22581. connectNulls: false,
  22582. // 数据过滤,'average', 'max', 'min', 'sum'
  22583. sampling: 'none',
  22584. animationEasing: 'linear',
  22585. // Disable progressive
  22586. progressive: 0,
  22587. hoverLayerThreshold: Infinity
  22588. }
  22589. });
  22590. /***/ },
  22591. /* 115 */
  22592. /***/ function(module, exports, __webpack_require__) {
  22593. 'use strict';
  22594. // FIXME step not support polar
  22595. var zrUtil = __webpack_require__(4);
  22596. var SymbolDraw = __webpack_require__(116);
  22597. var Symbol = __webpack_require__(117);
  22598. var lineAnimationDiff = __webpack_require__(119);
  22599. var graphic = __webpack_require__(18);
  22600. var modelUtil = __webpack_require__(5);
  22601. var polyHelper = __webpack_require__(120);
  22602. var ChartView = __webpack_require__(80);
  22603. function isPointsSame(points1, points2) {
  22604. if (points1.length !== points2.length) {
  22605. return;
  22606. }
  22607. for (var i = 0; i < points1.length; i++) {
  22608. var p1 = points1[i];
  22609. var p2 = points2[i];
  22610. if (p1[0] !== p2[0] || p1[1] !== p2[1]) {
  22611. return;
  22612. }
  22613. }
  22614. return true;
  22615. }
  22616. function getSmooth(smooth) {
  22617. return typeof (smooth) === 'number' ? smooth : (smooth ? 0.3 : 0);
  22618. }
  22619. function getAxisExtentWithGap(axis) {
  22620. var extent = axis.getGlobalExtent();
  22621. if (axis.onBand) {
  22622. // Remove extra 1px to avoid line miter in clipped edge
  22623. var halfBandWidth = axis.getBandWidth() / 2 - 1;
  22624. var dir = extent[1] > extent[0] ? 1 : -1;
  22625. extent[0] += dir * halfBandWidth;
  22626. extent[1] -= dir * halfBandWidth;
  22627. }
  22628. return extent;
  22629. }
  22630. function sign(val) {
  22631. return val >= 0 ? 1 : -1;
  22632. }
  22633. /**
  22634. * @param {module:echarts/coord/cartesian/Cartesian2D|module:echarts/coord/polar/Polar} coordSys
  22635. * @param {module:echarts/data/List} data
  22636. * @param {Array.<Array.<number>>} points
  22637. * @private
  22638. */
  22639. function getStackedOnPoints(coordSys, data) {
  22640. var baseAxis = coordSys.getBaseAxis();
  22641. var valueAxis = coordSys.getOtherAxis(baseAxis);
  22642. var valueStart = baseAxis.onZero
  22643. ? 0 : valueAxis.scale.getExtent()[0];
  22644. var valueDim = valueAxis.dim;
  22645. var baseDataOffset = valueDim === 'x' || valueDim === 'radius' ? 1 : 0;
  22646. return data.mapArray([valueDim], function (val, idx) {
  22647. var stackedOnSameSign;
  22648. var stackedOn = data.stackedOn;
  22649. // Find first stacked value with same sign
  22650. while (stackedOn &&
  22651. sign(stackedOn.get(valueDim, idx)) === sign(val)
  22652. ) {
  22653. stackedOnSameSign = stackedOn;
  22654. break;
  22655. }
  22656. var stackedData = [];
  22657. stackedData[baseDataOffset] = data.get(baseAxis.dim, idx);
  22658. stackedData[1 - baseDataOffset] = stackedOnSameSign
  22659. ? stackedOnSameSign.get(valueDim, idx, true) : valueStart;
  22660. return coordSys.dataToPoint(stackedData);
  22661. }, true);
  22662. }
  22663. function createGridClipShape(cartesian, hasAnimation, seriesModel) {
  22664. var xExtent = getAxisExtentWithGap(cartesian.getAxis('x'));
  22665. var yExtent = getAxisExtentWithGap(cartesian.getAxis('y'));
  22666. var isHorizontal = cartesian.getBaseAxis().isHorizontal();
  22667. var x = Math.min(xExtent[0], xExtent[1]);
  22668. var y = Math.min(yExtent[0], yExtent[1]);
  22669. var width = Math.max(xExtent[0], xExtent[1]) - x;
  22670. var height = Math.max(yExtent[0], yExtent[1]) - y;
  22671. var lineWidth = seriesModel.get('lineStyle.normal.width') || 2;
  22672. // Expand clip shape to avoid clipping when line value exceeds axis
  22673. var expandSize = seriesModel.get('clipOverflow') ? lineWidth / 2 : Math.max(width, height);
  22674. if (isHorizontal) {
  22675. y -= expandSize;
  22676. height += expandSize * 2;
  22677. }
  22678. else {
  22679. x -= expandSize;
  22680. width += expandSize * 2;
  22681. }
  22682. var clipPath = new graphic.Rect({
  22683. shape: {
  22684. x: x,
  22685. y: y,
  22686. width: width,
  22687. height: height
  22688. }
  22689. });
  22690. if (hasAnimation) {
  22691. clipPath.shape[isHorizontal ? 'width' : 'height'] = 0;
  22692. graphic.initProps(clipPath, {
  22693. shape: {
  22694. width: width,
  22695. height: height
  22696. }
  22697. }, seriesModel);
  22698. }
  22699. return clipPath;
  22700. }
  22701. function createPolarClipShape(polar, hasAnimation, seriesModel) {
  22702. var angleAxis = polar.getAngleAxis();
  22703. var radiusAxis = polar.getRadiusAxis();
  22704. var radiusExtent = radiusAxis.getExtent();
  22705. var angleExtent = angleAxis.getExtent();
  22706. var RADIAN = Math.PI / 180;
  22707. var clipPath = new graphic.Sector({
  22708. shape: {
  22709. cx: polar.cx,
  22710. cy: polar.cy,
  22711. r0: radiusExtent[0],
  22712. r: radiusExtent[1],
  22713. startAngle: -angleExtent[0] * RADIAN,
  22714. endAngle: -angleExtent[1] * RADIAN,
  22715. clockwise: angleAxis.inverse
  22716. }
  22717. });
  22718. if (hasAnimation) {
  22719. clipPath.shape.endAngle = -angleExtent[0] * RADIAN;
  22720. graphic.initProps(clipPath, {
  22721. shape: {
  22722. endAngle: -angleExtent[1] * RADIAN
  22723. }
  22724. }, seriesModel);
  22725. }
  22726. return clipPath;
  22727. }
  22728. function createClipShape(coordSys, hasAnimation, seriesModel) {
  22729. return coordSys.type === 'polar'
  22730. ? createPolarClipShape(coordSys, hasAnimation, seriesModel)
  22731. : createGridClipShape(coordSys, hasAnimation, seriesModel);
  22732. }
  22733. function turnPointsIntoStep(points, coordSys, stepTurnAt) {
  22734. var baseAxis = coordSys.getBaseAxis();
  22735. var baseIndex = baseAxis.dim === 'x' || baseAxis.dim === 'radius' ? 0 : 1;
  22736. var stepPoints = [];
  22737. for (var i = 0; i < points.length - 1; i++) {
  22738. var nextPt = points[i + 1];
  22739. var pt = points[i];
  22740. stepPoints.push(pt);
  22741. var stepPt = [];
  22742. switch (stepTurnAt) {
  22743. case 'end':
  22744. stepPt[baseIndex] = nextPt[baseIndex];
  22745. stepPt[1 - baseIndex] = pt[1 - baseIndex];
  22746. // default is start
  22747. stepPoints.push(stepPt);
  22748. break;
  22749. case 'middle':
  22750. // default is start
  22751. var middle = (pt[baseIndex] + nextPt[baseIndex]) / 2;
  22752. var stepPt2 = [];
  22753. stepPt[baseIndex] = stepPt2[baseIndex] = middle;
  22754. stepPt[1 - baseIndex] = pt[1 - baseIndex];
  22755. stepPt2[1 - baseIndex] = nextPt[1 - baseIndex];
  22756. stepPoints.push(stepPt);
  22757. stepPoints.push(stepPt2);
  22758. break;
  22759. default:
  22760. stepPt[baseIndex] = pt[baseIndex];
  22761. stepPt[1 - baseIndex] = nextPt[1 - baseIndex];
  22762. // default is start
  22763. stepPoints.push(stepPt);
  22764. }
  22765. }
  22766. // Last points
  22767. points[i] && stepPoints.push(points[i]);
  22768. return stepPoints;
  22769. }
  22770. function getVisualGradient(data, coordSys) {
  22771. var visualMetaList = data.getVisual('visualMeta');
  22772. if (!visualMetaList || !visualMetaList.length || !data.count()) {
  22773. // When data.count() is 0, gradient range can not be calculated.
  22774. return;
  22775. }
  22776. var visualMeta;
  22777. for (var i = visualMetaList.length - 1; i >= 0; i--) {
  22778. // Can only be x or y
  22779. if (visualMetaList[i].dimension < 2) {
  22780. visualMeta = visualMetaList[i];
  22781. break;
  22782. }
  22783. }
  22784. if (!visualMeta || coordSys.type !== 'cartesian2d') {
  22785. if (true) {
  22786. console.warn('Visual map on line style only support x or y dimension.');
  22787. }
  22788. return;
  22789. }
  22790. // If the area to be rendered is bigger than area defined by LinearGradient,
  22791. // the canvas spec prescribes that the color of the first stop and the last
  22792. // stop should be used. But if two stops are added at offset 0, in effect
  22793. // browsers use the color of the second stop to render area outside
  22794. // LinearGradient. So we can only infinitesimally extend area defined in
  22795. // LinearGradient to render `outerColors`.
  22796. var dimension = visualMeta.dimension;
  22797. var dimName = data.dimensions[dimension];
  22798. var axis = coordSys.getAxis(dimName);
  22799. // dataToCoor mapping may not be linear, but must be monotonic.
  22800. var colorStops = zrUtil.map(visualMeta.stops, function (stop) {
  22801. return {
  22802. coord: axis.toGlobalCoord(axis.dataToCoord(stop.value)),
  22803. color: stop.color
  22804. };
  22805. });
  22806. var stopLen = colorStops.length;
  22807. var outerColors = visualMeta.outerColors.slice();
  22808. if (stopLen && colorStops[0].coord > colorStops[stopLen - 1].coord) {
  22809. colorStops.reverse();
  22810. outerColors.reverse();
  22811. }
  22812. var tinyExtent = 10; // Arbitrary value: 10px
  22813. var minCoord = colorStops[0].coord - tinyExtent;
  22814. var maxCoord = colorStops[stopLen - 1].coord + tinyExtent;
  22815. var coordSpan = maxCoord - minCoord;
  22816. if (coordSpan < 1e-3) {
  22817. return 'transparent';
  22818. }
  22819. zrUtil.each(colorStops, function (stop) {
  22820. stop.offset = (stop.coord - minCoord) / coordSpan;
  22821. });
  22822. colorStops.push({
  22823. offset: stopLen ? colorStops[stopLen - 1].offset : 0.5,
  22824. color: outerColors[1] || 'transparent'
  22825. });
  22826. colorStops.unshift({ // notice colorStops.length have been changed.
  22827. offset: stopLen ? colorStops[0].offset : 0.5,
  22828. color: outerColors[0] || 'transparent'
  22829. });
  22830. // zrUtil.each(colorStops, function (colorStop) {
  22831. // // Make sure each offset has rounded px to avoid not sharp edge
  22832. // colorStop.offset = (Math.round(colorStop.offset * (end - start) + start) - start) / (end - start);
  22833. // });
  22834. var gradient = new graphic.LinearGradient(0, 0, 0, 0, colorStops, true);
  22835. gradient[dimName] = minCoord;
  22836. gradient[dimName + '2'] = maxCoord;
  22837. return gradient;
  22838. }
  22839. module.exports = ChartView.extend({
  22840. type: 'line',
  22841. init: function () {
  22842. var lineGroup = new graphic.Group();
  22843. var symbolDraw = new SymbolDraw();
  22844. this.group.add(symbolDraw.group);
  22845. this._symbolDraw = symbolDraw;
  22846. this._lineGroup = lineGroup;
  22847. },
  22848. render: function (seriesModel, ecModel, api) {
  22849. var coordSys = seriesModel.coordinateSystem;
  22850. var group = this.group;
  22851. var data = seriesModel.getData();
  22852. var lineStyleModel = seriesModel.getModel('lineStyle.normal');
  22853. var areaStyleModel = seriesModel.getModel('areaStyle.normal');
  22854. var points = data.mapArray(data.getItemLayout, true);
  22855. var isCoordSysPolar = coordSys.type === 'polar';
  22856. var prevCoordSys = this._coordSys;
  22857. var symbolDraw = this._symbolDraw;
  22858. var polyline = this._polyline;
  22859. var polygon = this._polygon;
  22860. var lineGroup = this._lineGroup;
  22861. var hasAnimation = seriesModel.get('animation');
  22862. var isAreaChart = !areaStyleModel.isEmpty();
  22863. var stackedOnPoints = getStackedOnPoints(coordSys, data);
  22864. var showSymbol = seriesModel.get('showSymbol');
  22865. var isSymbolIgnore = showSymbol && !isCoordSysPolar && !seriesModel.get('showAllSymbol')
  22866. && this._getSymbolIgnoreFunc(data, coordSys);
  22867. // Remove temporary symbols
  22868. var oldData = this._data;
  22869. oldData && oldData.eachItemGraphicEl(function (el, idx) {
  22870. if (el.__temp) {
  22871. group.remove(el);
  22872. oldData.setItemGraphicEl(idx, null);
  22873. }
  22874. });
  22875. // Remove previous created symbols if showSymbol changed to false
  22876. if (!showSymbol) {
  22877. symbolDraw.remove();
  22878. }
  22879. group.add(lineGroup);
  22880. // FIXME step not support polar
  22881. var step = !isCoordSysPolar && seriesModel.get('step');
  22882. // Initialization animation or coordinate system changed
  22883. if (
  22884. !(polyline && prevCoordSys.type === coordSys.type && step === this._step)
  22885. ) {
  22886. showSymbol && symbolDraw.updateData(data, isSymbolIgnore);
  22887. if (step) {
  22888. // TODO If stacked series is not step
  22889. points = turnPointsIntoStep(points, coordSys, step);
  22890. stackedOnPoints = turnPointsIntoStep(stackedOnPoints, coordSys, step);
  22891. }
  22892. polyline = this._newPolyline(points, coordSys, hasAnimation);
  22893. if (isAreaChart) {
  22894. polygon = this._newPolygon(
  22895. points, stackedOnPoints,
  22896. coordSys, hasAnimation
  22897. );
  22898. }
  22899. lineGroup.setClipPath(createClipShape(coordSys, true, seriesModel));
  22900. }
  22901. else {
  22902. if (isAreaChart && !polygon) {
  22903. // If areaStyle is added
  22904. polygon = this._newPolygon(
  22905. points, stackedOnPoints,
  22906. coordSys, hasAnimation
  22907. );
  22908. }
  22909. else if (polygon && !isAreaChart) {
  22910. // If areaStyle is removed
  22911. lineGroup.remove(polygon);
  22912. polygon = this._polygon = null;
  22913. }
  22914. // Update clipPath
  22915. lineGroup.setClipPath(createClipShape(coordSys, false, seriesModel));
  22916. // Always update, or it is wrong in the case turning on legend
  22917. // because points are not changed
  22918. showSymbol && symbolDraw.updateData(data, isSymbolIgnore);
  22919. // Stop symbol animation and sync with line points
  22920. // FIXME performance?
  22921. data.eachItemGraphicEl(function (el) {
  22922. el.stopAnimation(true);
  22923. });
  22924. // In the case data zoom triggerred refreshing frequently
  22925. // Data may not change if line has a category axis. So it should animate nothing
  22926. if (!isPointsSame(this._stackedOnPoints, stackedOnPoints)
  22927. || !isPointsSame(this._points, points)
  22928. ) {
  22929. if (hasAnimation) {
  22930. this._updateAnimation(
  22931. data, stackedOnPoints, coordSys, api, step
  22932. );
  22933. }
  22934. else {
  22935. // Not do it in update with animation
  22936. if (step) {
  22937. // TODO If stacked series is not step
  22938. points = turnPointsIntoStep(points, coordSys, step);
  22939. stackedOnPoints = turnPointsIntoStep(stackedOnPoints, coordSys, step);
  22940. }
  22941. polyline.setShape({
  22942. points: points
  22943. });
  22944. polygon && polygon.setShape({
  22945. points: points,
  22946. stackedOnPoints: stackedOnPoints
  22947. });
  22948. }
  22949. }
  22950. }
  22951. var visualColor = getVisualGradient(data, coordSys) || data.getVisual('color');
  22952. polyline.useStyle(zrUtil.defaults(
  22953. // Use color in lineStyle first
  22954. lineStyleModel.getLineStyle(),
  22955. {
  22956. fill: 'none',
  22957. stroke: visualColor,
  22958. lineJoin: 'bevel'
  22959. }
  22960. ));
  22961. var smooth = seriesModel.get('smooth');
  22962. smooth = getSmooth(seriesModel.get('smooth'));
  22963. polyline.setShape({
  22964. smooth: smooth,
  22965. smoothMonotone: seriesModel.get('smoothMonotone'),
  22966. connectNulls: seriesModel.get('connectNulls')
  22967. });
  22968. if (polygon) {
  22969. var stackedOn = data.stackedOn;
  22970. var stackedOnSmooth = 0;
  22971. polygon.useStyle(zrUtil.defaults(
  22972. areaStyleModel.getAreaStyle(),
  22973. {
  22974. fill: visualColor,
  22975. opacity: 0.7,
  22976. lineJoin: 'bevel'
  22977. }
  22978. ));
  22979. if (stackedOn) {
  22980. var stackedOnSeries = stackedOn.hostModel;
  22981. stackedOnSmooth = getSmooth(stackedOnSeries.get('smooth'));
  22982. }
  22983. polygon.setShape({
  22984. smooth: smooth,
  22985. stackedOnSmooth: stackedOnSmooth,
  22986. smoothMonotone: seriesModel.get('smoothMonotone'),
  22987. connectNulls: seriesModel.get('connectNulls')
  22988. });
  22989. }
  22990. this._data = data;
  22991. // Save the coordinate system for transition animation when data changed
  22992. this._coordSys = coordSys;
  22993. this._stackedOnPoints = stackedOnPoints;
  22994. this._points = points;
  22995. this._step = step;
  22996. },
  22997. dispose: function () {},
  22998. highlight: function (seriesModel, ecModel, api, payload) {
  22999. var data = seriesModel.getData();
  23000. var dataIndex = modelUtil.queryDataIndex(data, payload);
  23001. if (!(dataIndex instanceof Array) && dataIndex != null && dataIndex >= 0) {
  23002. var symbol = data.getItemGraphicEl(dataIndex);
  23003. if (!symbol) {
  23004. // Create a temporary symbol if it is not exists
  23005. var pt = data.getItemLayout(dataIndex);
  23006. if (!pt) {
  23007. // Null data
  23008. return;
  23009. }
  23010. symbol = new Symbol(data, dataIndex);
  23011. symbol.position = pt;
  23012. symbol.setZ(
  23013. seriesModel.get('zlevel'),
  23014. seriesModel.get('z')
  23015. );
  23016. symbol.ignore = isNaN(pt[0]) || isNaN(pt[1]);
  23017. symbol.__temp = true;
  23018. data.setItemGraphicEl(dataIndex, symbol);
  23019. // Stop scale animation
  23020. symbol.stopSymbolAnimation(true);
  23021. this.group.add(symbol);
  23022. }
  23023. symbol.highlight();
  23024. }
  23025. else {
  23026. // Highlight whole series
  23027. ChartView.prototype.highlight.call(
  23028. this, seriesModel, ecModel, api, payload
  23029. );
  23030. }
  23031. },
  23032. downplay: function (seriesModel, ecModel, api, payload) {
  23033. var data = seriesModel.getData();
  23034. var dataIndex = modelUtil.queryDataIndex(data, payload);
  23035. if (dataIndex != null && dataIndex >= 0) {
  23036. var symbol = data.getItemGraphicEl(dataIndex);
  23037. if (symbol) {
  23038. if (symbol.__temp) {
  23039. data.setItemGraphicEl(dataIndex, null);
  23040. this.group.remove(symbol);
  23041. }
  23042. else {
  23043. symbol.downplay();
  23044. }
  23045. }
  23046. }
  23047. else {
  23048. // FIXME
  23049. // can not downplay completely.
  23050. // Downplay whole series
  23051. ChartView.prototype.downplay.call(
  23052. this, seriesModel, ecModel, api, payload
  23053. );
  23054. }
  23055. },
  23056. /**
  23057. * @param {module:zrender/container/Group} group
  23058. * @param {Array.<Array.<number>>} points
  23059. * @private
  23060. */
  23061. _newPolyline: function (points) {
  23062. var polyline = this._polyline;
  23063. // Remove previous created polyline
  23064. if (polyline) {
  23065. this._lineGroup.remove(polyline);
  23066. }
  23067. polyline = new polyHelper.Polyline({
  23068. shape: {
  23069. points: points
  23070. },
  23071. silent: true,
  23072. z2: 10
  23073. });
  23074. this._lineGroup.add(polyline);
  23075. this._polyline = polyline;
  23076. return polyline;
  23077. },
  23078. /**
  23079. * @param {module:zrender/container/Group} group
  23080. * @param {Array.<Array.<number>>} stackedOnPoints
  23081. * @param {Array.<Array.<number>>} points
  23082. * @private
  23083. */
  23084. _newPolygon: function (points, stackedOnPoints) {
  23085. var polygon = this._polygon;
  23086. // Remove previous created polygon
  23087. if (polygon) {
  23088. this._lineGroup.remove(polygon);
  23089. }
  23090. polygon = new polyHelper.Polygon({
  23091. shape: {
  23092. points: points,
  23093. stackedOnPoints: stackedOnPoints
  23094. },
  23095. silent: true
  23096. });
  23097. this._lineGroup.add(polygon);
  23098. this._polygon = polygon;
  23099. return polygon;
  23100. },
  23101. /**
  23102. * @private
  23103. */
  23104. _getSymbolIgnoreFunc: function (data, coordSys) {
  23105. var categoryAxis = coordSys.getAxesByScale('ordinal')[0];
  23106. // `getLabelInterval` is provided by echarts/component/axis
  23107. if (categoryAxis && categoryAxis.isLabelIgnored) {
  23108. return zrUtil.bind(categoryAxis.isLabelIgnored, categoryAxis);
  23109. }
  23110. },
  23111. /**
  23112. * @private
  23113. */
  23114. // FIXME Two value axis
  23115. _updateAnimation: function (data, stackedOnPoints, coordSys, api, step) {
  23116. var polyline = this._polyline;
  23117. var polygon = this._polygon;
  23118. var seriesModel = data.hostModel;
  23119. var diff = lineAnimationDiff(
  23120. this._data, data,
  23121. this._stackedOnPoints, stackedOnPoints,
  23122. this._coordSys, coordSys
  23123. );
  23124. var current = diff.current;
  23125. var stackedOnCurrent = diff.stackedOnCurrent;
  23126. var next = diff.next;
  23127. var stackedOnNext = diff.stackedOnNext;
  23128. if (step) {
  23129. // TODO If stacked series is not step
  23130. current = turnPointsIntoStep(diff.current, coordSys, step);
  23131. stackedOnCurrent = turnPointsIntoStep(diff.stackedOnCurrent, coordSys, step);
  23132. next = turnPointsIntoStep(diff.next, coordSys, step);
  23133. stackedOnNext = turnPointsIntoStep(diff.stackedOnNext, coordSys, step);
  23134. }
  23135. // `diff.current` is subset of `current` (which should be ensured by
  23136. // turnPointsIntoStep), so points in `__points` can be updated when
  23137. // points in `current` are update during animation.
  23138. polyline.shape.__points = diff.current;
  23139. polyline.shape.points = current;
  23140. graphic.updateProps(polyline, {
  23141. shape: {
  23142. points: next
  23143. }
  23144. }, seriesModel);
  23145. if (polygon) {
  23146. polygon.setShape({
  23147. points: current,
  23148. stackedOnPoints: stackedOnCurrent
  23149. });
  23150. graphic.updateProps(polygon, {
  23151. shape: {
  23152. points: next,
  23153. stackedOnPoints: stackedOnNext
  23154. }
  23155. }, seriesModel);
  23156. }
  23157. var updatedDataInfo = [];
  23158. var diffStatus = diff.status;
  23159. for (var i = 0; i < diffStatus.length; i++) {
  23160. var cmd = diffStatus[i].cmd;
  23161. if (cmd === '=') {
  23162. var el = data.getItemGraphicEl(diffStatus[i].idx1);
  23163. if (el) {
  23164. updatedDataInfo.push({
  23165. el: el,
  23166. ptIdx: i // Index of points
  23167. });
  23168. }
  23169. }
  23170. }
  23171. if (polyline.animators && polyline.animators.length) {
  23172. polyline.animators[0].during(function () {
  23173. for (var i = 0; i < updatedDataInfo.length; i++) {
  23174. var el = updatedDataInfo[i].el;
  23175. el.attr('position', polyline.shape.__points[updatedDataInfo[i].ptIdx]);
  23176. }
  23177. });
  23178. }
  23179. },
  23180. remove: function (ecModel) {
  23181. var group = this.group;
  23182. var oldData = this._data;
  23183. this._lineGroup.removeAll();
  23184. this._symbolDraw.remove(true);
  23185. // Remove temporary created elements when highlighting
  23186. oldData && oldData.eachItemGraphicEl(function (el, idx) {
  23187. if (el.__temp) {
  23188. group.remove(el);
  23189. oldData.setItemGraphicEl(idx, null);
  23190. }
  23191. });
  23192. this._polyline =
  23193. this._polygon =
  23194. this._coordSys =
  23195. this._points =
  23196. this._stackedOnPoints =
  23197. this._data = null;
  23198. }
  23199. });
  23200. /***/ },
  23201. /* 116 */
  23202. /***/ function(module, exports, __webpack_require__) {
  23203. /**
  23204. * @module echarts/chart/helper/SymbolDraw
  23205. */
  23206. var graphic = __webpack_require__(18);
  23207. var Symbol = __webpack_require__(117);
  23208. /**
  23209. * @constructor
  23210. * @alias module:echarts/chart/helper/SymbolDraw
  23211. * @param {module:zrender/graphic/Group} [symbolCtor]
  23212. */
  23213. function SymbolDraw(symbolCtor) {
  23214. this.group = new graphic.Group();
  23215. this._symbolCtor = symbolCtor || Symbol;
  23216. }
  23217. var symbolDrawProto = SymbolDraw.prototype;
  23218. function symbolNeedsDraw(data, idx, isIgnore) {
  23219. var point = data.getItemLayout(idx);
  23220. // Is an object
  23221. // if (point && point.hasOwnProperty('point')) {
  23222. // point = point.point;
  23223. // }
  23224. return point && !isNaN(point[0]) && !isNaN(point[1]) && !(isIgnore && isIgnore(idx))
  23225. && data.getItemVisual(idx, 'symbol') !== 'none';
  23226. }
  23227. /**
  23228. * Update symbols draw by new data
  23229. * @param {module:echarts/data/List} data
  23230. * @param {Array.<boolean>} [isIgnore]
  23231. */
  23232. symbolDrawProto.updateData = function (data, isIgnore) {
  23233. var group = this.group;
  23234. var seriesModel = data.hostModel;
  23235. var oldData = this._data;
  23236. var SymbolCtor = this._symbolCtor;
  23237. var seriesScope = {
  23238. itemStyle: seriesModel.getModel('itemStyle.normal').getItemStyle(['color']),
  23239. hoverItemStyle: seriesModel.getModel('itemStyle.emphasis').getItemStyle(),
  23240. symbolRotate: seriesModel.get('symbolRotate'),
  23241. symbolOffset: seriesModel.get('symbolOffset'),
  23242. hoverAnimation: seriesModel.get('hoverAnimation'),
  23243. labelModel: seriesModel.getModel('label.normal'),
  23244. hoverLabelModel: seriesModel.getModel('label.emphasis')
  23245. };
  23246. data.diff(oldData)
  23247. .add(function (newIdx) {
  23248. var point = data.getItemLayout(newIdx);
  23249. if (symbolNeedsDraw(data, newIdx, isIgnore)) {
  23250. var symbolEl = new SymbolCtor(data, newIdx, seriesScope);
  23251. symbolEl.attr('position', point);
  23252. data.setItemGraphicEl(newIdx, symbolEl);
  23253. group.add(symbolEl);
  23254. }
  23255. })
  23256. .update(function (newIdx, oldIdx) {
  23257. var symbolEl = oldData.getItemGraphicEl(oldIdx);
  23258. var point = data.getItemLayout(newIdx);
  23259. if (!symbolNeedsDraw(data, newIdx, isIgnore)) {
  23260. group.remove(symbolEl);
  23261. return;
  23262. }
  23263. if (!symbolEl) {
  23264. symbolEl = new SymbolCtor(data, newIdx);
  23265. symbolEl.attr('position', point);
  23266. }
  23267. else {
  23268. symbolEl.updateData(data, newIdx, seriesScope);
  23269. graphic.updateProps(symbolEl, {
  23270. position: point
  23271. }, seriesModel);
  23272. }
  23273. // Add back
  23274. group.add(symbolEl);
  23275. data.setItemGraphicEl(newIdx, symbolEl);
  23276. })
  23277. .remove(function (oldIdx) {
  23278. var el = oldData.getItemGraphicEl(oldIdx);
  23279. el && el.fadeOut(function () {
  23280. group.remove(el);
  23281. });
  23282. })
  23283. .execute();
  23284. this._data = data;
  23285. };
  23286. symbolDrawProto.updateLayout = function () {
  23287. var data = this._data;
  23288. if (data) {
  23289. // Not use animation
  23290. data.eachItemGraphicEl(function (el, idx) {
  23291. var point = data.getItemLayout(idx);
  23292. el.attr('position', point);
  23293. });
  23294. }
  23295. };
  23296. symbolDrawProto.remove = function (enableAnimation) {
  23297. var group = this.group;
  23298. var data = this._data;
  23299. if (data) {
  23300. if (enableAnimation) {
  23301. data.eachItemGraphicEl(function (el) {
  23302. el.fadeOut(function () {
  23303. group.remove(el);
  23304. });
  23305. });
  23306. }
  23307. else {
  23308. group.removeAll();
  23309. }
  23310. }
  23311. };
  23312. module.exports = SymbolDraw;
  23313. /***/ },
  23314. /* 117 */
  23315. /***/ function(module, exports, __webpack_require__) {
  23316. /**
  23317. * @module echarts/chart/helper/Symbol
  23318. */
  23319. var zrUtil = __webpack_require__(4);
  23320. var symbolUtil = __webpack_require__(111);
  23321. var graphic = __webpack_require__(18);
  23322. var numberUtil = __webpack_require__(7);
  23323. var labelHelper = __webpack_require__(118);
  23324. function getSymbolSize(data, idx) {
  23325. var symbolSize = data.getItemVisual(idx, 'symbolSize');
  23326. return symbolSize instanceof Array
  23327. ? symbolSize.slice()
  23328. : [+symbolSize, +symbolSize];
  23329. }
  23330. function getScale(symbolSize) {
  23331. return [symbolSize[0] / 2, symbolSize[1] / 2];
  23332. }
  23333. /**
  23334. * @constructor
  23335. * @alias {module:echarts/chart/helper/Symbol}
  23336. * @param {module:echarts/data/List} data
  23337. * @param {number} idx
  23338. * @extends {module:zrender/graphic/Group}
  23339. */
  23340. function Symbol(data, idx, seriesScope) {
  23341. graphic.Group.call(this);
  23342. this.updateData(data, idx, seriesScope);
  23343. }
  23344. var symbolProto = Symbol.prototype;
  23345. function driftSymbol(dx, dy) {
  23346. this.parent.drift(dx, dy);
  23347. }
  23348. symbolProto._createSymbol = function (symbolType, data, idx, symbolSize) {
  23349. // Remove paths created before
  23350. this.removeAll();
  23351. var seriesModel = data.hostModel;
  23352. var color = data.getItemVisual(idx, 'color');
  23353. // var symbolPath = symbolUtil.createSymbol(
  23354. // symbolType, -0.5, -0.5, 1, 1, color
  23355. // );
  23356. // If width/height are set too small (e.g., set to 1) on ios10
  23357. // and macOS Sierra, a circle stroke become a rect, no matter what
  23358. // the scale is set. So we set width/height as 2. See #4150.
  23359. var symbolPath = symbolUtil.createSymbol(
  23360. symbolType, -1, -1, 2, 2, color
  23361. );
  23362. symbolPath.attr({
  23363. z2: 100,
  23364. culling: true,
  23365. scale: [0, 0]
  23366. });
  23367. // Rewrite drift method
  23368. symbolPath.drift = driftSymbol;
  23369. graphic.initProps(symbolPath, {
  23370. scale: getScale(symbolSize)
  23371. }, seriesModel, idx);
  23372. this._symbolType = symbolType;
  23373. this.add(symbolPath);
  23374. };
  23375. /**
  23376. * Stop animation
  23377. * @param {boolean} toLastFrame
  23378. */
  23379. symbolProto.stopSymbolAnimation = function (toLastFrame) {
  23380. this.childAt(0).stopAnimation(toLastFrame);
  23381. };
  23382. /**
  23383. * Get symbol path element
  23384. */
  23385. symbolProto.getSymbolPath = function () {
  23386. return this.childAt(0);
  23387. };
  23388. /**
  23389. * Get scale(aka, current symbol size).
  23390. * Including the change caused by animation
  23391. */
  23392. symbolProto.getScale = function () {
  23393. return this.childAt(0).scale;
  23394. };
  23395. /**
  23396. * Highlight symbol
  23397. */
  23398. symbolProto.highlight = function () {
  23399. this.childAt(0).trigger('emphasis');
  23400. };
  23401. /**
  23402. * Downplay symbol
  23403. */
  23404. symbolProto.downplay = function () {
  23405. this.childAt(0).trigger('normal');
  23406. };
  23407. /**
  23408. * @param {number} zlevel
  23409. * @param {number} z
  23410. */
  23411. symbolProto.setZ = function (zlevel, z) {
  23412. var symbolPath = this.childAt(0);
  23413. symbolPath.zlevel = zlevel;
  23414. symbolPath.z = z;
  23415. };
  23416. symbolProto.setDraggable = function (draggable) {
  23417. var symbolPath = this.childAt(0);
  23418. symbolPath.draggable = draggable;
  23419. symbolPath.cursor = draggable ? 'move' : 'pointer';
  23420. };
  23421. /**
  23422. * Update symbol properties
  23423. * @param {module:echarts/data/List} data
  23424. * @param {number} idx
  23425. */
  23426. symbolProto.updateData = function (data, idx, seriesScope) {
  23427. this.silent = false;
  23428. var symbolType = data.getItemVisual(idx, 'symbol') || 'circle';
  23429. var seriesModel = data.hostModel;
  23430. var symbolSize = getSymbolSize(data, idx);
  23431. if (symbolType !== this._symbolType) {
  23432. this._createSymbol(symbolType, data, idx, symbolSize);
  23433. }
  23434. else {
  23435. var symbolPath = this.childAt(0);
  23436. symbolPath.silent = false;
  23437. graphic.updateProps(symbolPath, {
  23438. scale: getScale(symbolSize)
  23439. }, seriesModel, idx);
  23440. }
  23441. this._updateCommon(data, idx, symbolSize, seriesScope);
  23442. this._seriesModel = seriesModel;
  23443. };
  23444. // Update common properties
  23445. var normalStyleAccessPath = ['itemStyle', 'normal'];
  23446. var emphasisStyleAccessPath = ['itemStyle', 'emphasis'];
  23447. var normalLabelAccessPath = ['label', 'normal'];
  23448. var emphasisLabelAccessPath = ['label', 'emphasis'];
  23449. symbolProto._updateCommon = function (data, idx, symbolSize, seriesScope) {
  23450. var symbolPath = this.childAt(0);
  23451. var seriesModel = data.hostModel;
  23452. var color = data.getItemVisual(idx, 'color');
  23453. // Reset style
  23454. if (symbolPath.type !== 'image') {
  23455. symbolPath.useStyle({
  23456. strokeNoScale: true
  23457. });
  23458. }
  23459. seriesScope = seriesScope || null;
  23460. var itemStyle = seriesScope && seriesScope.itemStyle;
  23461. var hoverItemStyle = seriesScope && seriesScope.hoverItemStyle;
  23462. var symbolRotate = seriesScope && seriesScope.symbolRotate;
  23463. var symbolOffset = seriesScope && seriesScope.symbolOffset;
  23464. var labelModel = seriesScope && seriesScope.labelModel;
  23465. var hoverLabelModel = seriesScope && seriesScope.hoverLabelModel;
  23466. var hoverAnimation = seriesScope && seriesScope.hoverAnimation;
  23467. if (!seriesScope || data.hasItemOption) {
  23468. var itemModel = data.getItemModel(idx);
  23469. // Color must be excluded.
  23470. // Because symbol provide setColor individually to set fill and stroke
  23471. itemStyle = itemModel.getModel(normalStyleAccessPath).getItemStyle(['color']);
  23472. hoverItemStyle = itemModel.getModel(emphasisStyleAccessPath).getItemStyle();
  23473. symbolRotate = itemModel.getShallow('symbolRotate');
  23474. symbolOffset = itemModel.getShallow('symbolOffset');
  23475. labelModel = itemModel.getModel(normalLabelAccessPath);
  23476. hoverLabelModel = itemModel.getModel(emphasisLabelAccessPath);
  23477. hoverAnimation = itemModel.getShallow('hoverAnimation');
  23478. }
  23479. else {
  23480. hoverItemStyle = zrUtil.extend({}, hoverItemStyle);
  23481. }
  23482. var elStyle = symbolPath.style;
  23483. symbolPath.attr('rotation', (symbolRotate || 0) * Math.PI / 180 || 0);
  23484. if (symbolOffset) {
  23485. symbolPath.attr('position', [
  23486. numberUtil.parsePercent(symbolOffset[0], symbolSize[0]),
  23487. numberUtil.parsePercent(symbolOffset[1], symbolSize[1])
  23488. ]);
  23489. }
  23490. // PENDING setColor before setStyle!!!
  23491. symbolPath.setColor(color);
  23492. symbolPath.setStyle(itemStyle);
  23493. var opacity = data.getItemVisual(idx, 'opacity');
  23494. if (opacity != null) {
  23495. elStyle.opacity = opacity;
  23496. }
  23497. var valueDim = labelHelper.findLabelValueDim(data);
  23498. labelHelper.setTextToStyle(
  23499. data, idx, valueDim, elStyle, seriesModel, labelModel, color
  23500. );
  23501. labelHelper.setTextToStyle(
  23502. data, idx, valueDim, hoverItemStyle, seriesModel, hoverLabelModel, color
  23503. );
  23504. symbolPath.off('mouseover')
  23505. .off('mouseout')
  23506. .off('emphasis')
  23507. .off('normal');
  23508. symbolPath.hoverStyle = hoverItemStyle;
  23509. graphic.setHoverStyle(symbolPath);
  23510. var scale = getScale(symbolSize);
  23511. if (hoverAnimation && seriesModel.isAnimationEnabled()) {
  23512. var onEmphasis = function() {
  23513. var ratio = scale[1] / scale[0];
  23514. this.animateTo({
  23515. scale: [
  23516. Math.max(scale[0] * 1.1, scale[0] + 3),
  23517. Math.max(scale[1] * 1.1, scale[1] + 3 * ratio)
  23518. ]
  23519. }, 400, 'elasticOut');
  23520. };
  23521. var onNormal = function() {
  23522. this.animateTo({
  23523. scale: scale
  23524. }, 400, 'elasticOut');
  23525. };
  23526. symbolPath.on('mouseover', onEmphasis)
  23527. .on('mouseout', onNormal)
  23528. .on('emphasis', onEmphasis)
  23529. .on('normal', onNormal);
  23530. }
  23531. };
  23532. symbolProto.fadeOut = function (cb) {
  23533. var symbolPath = this.childAt(0);
  23534. // Avoid mistaken hover when fading out
  23535. this.silent = symbolPath.silent = true;
  23536. // Not show text when animating
  23537. symbolPath.style.text = '';
  23538. graphic.updateProps(symbolPath, {
  23539. scale: [0, 0]
  23540. }, this._seriesModel, this.dataIndex, cb);
  23541. };
  23542. zrUtil.inherits(Symbol, graphic.Group);
  23543. module.exports = Symbol;
  23544. /***/ },
  23545. /* 118 */
  23546. /***/ function(module, exports, __webpack_require__) {
  23547. /**
  23548. * @module echarts/chart/helper/Symbol
  23549. */
  23550. var graphic = __webpack_require__(18);
  23551. var zrUtil = __webpack_require__(4);
  23552. var modelUtil = __webpack_require__(5);
  23553. var helper = {};
  23554. helper.findLabelValueDim = function (data) {
  23555. var valueDim;
  23556. var labelDims = modelUtil.otherDimToDataDim(data, 'label');
  23557. if (labelDims.length) {
  23558. valueDim = labelDims[0];
  23559. }
  23560. else {
  23561. // Get last value dim
  23562. var dimensions = data.dimensions.slice();
  23563. var dataType;
  23564. while (dimensions.length && (
  23565. valueDim = dimensions.pop(),
  23566. dataType = data.getDimensionInfo(valueDim).type,
  23567. dataType === 'ordinal' || dataType === 'time'
  23568. )) {} // jshint ignore:line
  23569. }
  23570. return valueDim;
  23571. };
  23572. helper.setTextToStyle = function (
  23573. data, dataIndex, valueDim, elStyle, seriesModel, labelModel, color
  23574. ) {
  23575. if (valueDim != null && labelModel.getShallow('show')) {
  23576. graphic.setText(elStyle, labelModel, color);
  23577. elStyle.text = zrUtil.retrieve(
  23578. seriesModel.getFormattedLabel(dataIndex, 'normal'),
  23579. data.get(valueDim, dataIndex)
  23580. );
  23581. }
  23582. else {
  23583. elStyle.text = '';
  23584. }
  23585. };
  23586. module.exports = helper;
  23587. /***/ },
  23588. /* 119 */
  23589. /***/ function(module, exports) {
  23590. // var arrayDiff = require('zrender/lib/core/arrayDiff');
  23591. // 'zrender/core/arrayDiff' has been used before, but it did
  23592. // not do well in performance when roam with fixed dataZoom window.
  23593. function sign(val) {
  23594. return val >= 0 ? 1 : -1;
  23595. }
  23596. function getStackedOnPoint(coordSys, data, idx) {
  23597. var baseAxis = coordSys.getBaseAxis();
  23598. var valueAxis = coordSys.getOtherAxis(baseAxis);
  23599. var valueStart = baseAxis.onZero
  23600. ? 0 : valueAxis.scale.getExtent()[0];
  23601. var valueDim = valueAxis.dim;
  23602. var baseDataOffset = valueDim === 'x' || valueDim === 'radius' ? 1 : 0;
  23603. var stackedOnSameSign;
  23604. var stackedOn = data.stackedOn;
  23605. var val = data.get(valueDim, idx);
  23606. // Find first stacked value with same sign
  23607. while (stackedOn &&
  23608. sign(stackedOn.get(valueDim, idx)) === sign(val)
  23609. ) {
  23610. stackedOnSameSign = stackedOn;
  23611. break;
  23612. }
  23613. var stackedData = [];
  23614. stackedData[baseDataOffset] = data.get(baseAxis.dim, idx);
  23615. stackedData[1 - baseDataOffset] = stackedOnSameSign
  23616. ? stackedOnSameSign.get(valueDim, idx, true) : valueStart;
  23617. return coordSys.dataToPoint(stackedData);
  23618. }
  23619. // function convertToIntId(newIdList, oldIdList) {
  23620. // // Generate int id instead of string id.
  23621. // // Compare string maybe slow in score function of arrDiff
  23622. // // Assume id in idList are all unique
  23623. // var idIndicesMap = {};
  23624. // var idx = 0;
  23625. // for (var i = 0; i < newIdList.length; i++) {
  23626. // idIndicesMap[newIdList[i]] = idx;
  23627. // newIdList[i] = idx++;
  23628. // }
  23629. // for (var i = 0; i < oldIdList.length; i++) {
  23630. // var oldId = oldIdList[i];
  23631. // // Same with newIdList
  23632. // if (idIndicesMap[oldId]) {
  23633. // oldIdList[i] = idIndicesMap[oldId];
  23634. // }
  23635. // else {
  23636. // oldIdList[i] = idx++;
  23637. // }
  23638. // }
  23639. // }
  23640. function diffData(oldData, newData) {
  23641. var diffResult = [];
  23642. newData.diff(oldData)
  23643. .add(function (idx) {
  23644. diffResult.push({cmd: '+', idx: idx});
  23645. })
  23646. .update(function (newIdx, oldIdx) {
  23647. diffResult.push({cmd: '=', idx: oldIdx, idx1: newIdx});
  23648. })
  23649. .remove(function (idx) {
  23650. diffResult.push({cmd: '-', idx: idx});
  23651. })
  23652. .execute();
  23653. return diffResult;
  23654. }
  23655. module.exports = function (
  23656. oldData, newData,
  23657. oldStackedOnPoints, newStackedOnPoints,
  23658. oldCoordSys, newCoordSys
  23659. ) {
  23660. var diff = diffData(oldData, newData);
  23661. // var newIdList = newData.mapArray(newData.getId);
  23662. // var oldIdList = oldData.mapArray(oldData.getId);
  23663. // convertToIntId(newIdList, oldIdList);
  23664. // // FIXME One data ?
  23665. // diff = arrayDiff(oldIdList, newIdList);
  23666. var currPoints = [];
  23667. var nextPoints = [];
  23668. // Points for stacking base line
  23669. var currStackedPoints = [];
  23670. var nextStackedPoints = [];
  23671. var status = [];
  23672. var sortedIndices = [];
  23673. var rawIndices = [];
  23674. var dims = newCoordSys.dimensions;
  23675. for (var i = 0; i < diff.length; i++) {
  23676. var diffItem = diff[i];
  23677. var pointAdded = true;
  23678. // FIXME, animation is not so perfect when dataZoom window moves fast
  23679. // Which is in case remvoing or add more than one data in the tail or head
  23680. switch (diffItem.cmd) {
  23681. case '=':
  23682. var currentPt = oldData.getItemLayout(diffItem.idx);
  23683. var nextPt = newData.getItemLayout(diffItem.idx1);
  23684. // If previous data is NaN, use next point directly
  23685. if (isNaN(currentPt[0]) || isNaN(currentPt[1])) {
  23686. currentPt = nextPt.slice();
  23687. }
  23688. currPoints.push(currentPt);
  23689. nextPoints.push(nextPt);
  23690. currStackedPoints.push(oldStackedOnPoints[diffItem.idx]);
  23691. nextStackedPoints.push(newStackedOnPoints[diffItem.idx1]);
  23692. rawIndices.push(newData.getRawIndex(diffItem.idx1));
  23693. break;
  23694. case '+':
  23695. var idx = diffItem.idx;
  23696. currPoints.push(
  23697. oldCoordSys.dataToPoint([
  23698. newData.get(dims[0], idx, true), newData.get(dims[1], idx, true)
  23699. ])
  23700. );
  23701. nextPoints.push(newData.getItemLayout(idx).slice());
  23702. currStackedPoints.push(
  23703. getStackedOnPoint(oldCoordSys, newData, idx)
  23704. );
  23705. nextStackedPoints.push(newStackedOnPoints[idx]);
  23706. rawIndices.push(newData.getRawIndex(idx));
  23707. break;
  23708. case '-':
  23709. var idx = diffItem.idx;
  23710. var rawIndex = oldData.getRawIndex(idx);
  23711. // Data is replaced. In the case of dynamic data queue
  23712. // FIXME FIXME FIXME
  23713. if (rawIndex !== idx) {
  23714. currPoints.push(oldData.getItemLayout(idx));
  23715. nextPoints.push(newCoordSys.dataToPoint([
  23716. oldData.get(dims[0], idx, true), oldData.get(dims[1], idx, true)
  23717. ]));
  23718. currStackedPoints.push(oldStackedOnPoints[idx]);
  23719. nextStackedPoints.push(
  23720. getStackedOnPoint(
  23721. newCoordSys, oldData, idx
  23722. )
  23723. );
  23724. rawIndices.push(rawIndex);
  23725. }
  23726. else {
  23727. pointAdded = false;
  23728. }
  23729. }
  23730. // Original indices
  23731. if (pointAdded) {
  23732. status.push(diffItem);
  23733. sortedIndices.push(sortedIndices.length);
  23734. }
  23735. }
  23736. // Diff result may be crossed if all items are changed
  23737. // Sort by data index
  23738. sortedIndices.sort(function (a, b) {
  23739. return rawIndices[a] - rawIndices[b];
  23740. });
  23741. var sortedCurrPoints = [];
  23742. var sortedNextPoints = [];
  23743. var sortedCurrStackedPoints = [];
  23744. var sortedNextStackedPoints = [];
  23745. var sortedStatus = [];
  23746. for (var i = 0; i < sortedIndices.length; i++) {
  23747. var idx = sortedIndices[i];
  23748. sortedCurrPoints[i] = currPoints[idx];
  23749. sortedNextPoints[i] = nextPoints[idx];
  23750. sortedCurrStackedPoints[i] = currStackedPoints[idx];
  23751. sortedNextStackedPoints[i] = nextStackedPoints[idx];
  23752. sortedStatus[i] = status[idx];
  23753. }
  23754. return {
  23755. current: sortedCurrPoints,
  23756. next: sortedNextPoints,
  23757. stackedOnCurrent: sortedCurrStackedPoints,
  23758. stackedOnNext: sortedNextStackedPoints,
  23759. status: sortedStatus
  23760. };
  23761. };
  23762. /***/ },
  23763. /* 120 */
  23764. /***/ function(module, exports, __webpack_require__) {
  23765. // Poly path support NaN point
  23766. var Path = __webpack_require__(20);
  23767. var vec2 = __webpack_require__(10);
  23768. var vec2Min = vec2.min;
  23769. var vec2Max = vec2.max;
  23770. var scaleAndAdd = vec2.scaleAndAdd;
  23771. var v2Copy = vec2.copy;
  23772. // Temporary variable
  23773. var v = [];
  23774. var cp0 = [];
  23775. var cp1 = [];
  23776. function isPointNull(p) {
  23777. return isNaN(p[0]) || isNaN(p[1]);
  23778. }
  23779. function drawSegment(
  23780. ctx, points, start, segLen, allLen,
  23781. dir, smoothMin, smoothMax, smooth, smoothMonotone, connectNulls
  23782. ) {
  23783. var prevIdx = 0;
  23784. var idx = start;
  23785. for (var k = 0; k < segLen; k++) {
  23786. var p = points[idx];
  23787. if (idx >= allLen || idx < 0) {
  23788. break;
  23789. }
  23790. if (isPointNull(p)) {
  23791. if (connectNulls) {
  23792. idx += dir;
  23793. continue;
  23794. }
  23795. break;
  23796. }
  23797. if (idx === start) {
  23798. ctx[dir > 0 ? 'moveTo' : 'lineTo'](p[0], p[1]);
  23799. v2Copy(cp0, p);
  23800. }
  23801. else {
  23802. if (smooth > 0) {
  23803. var nextIdx = idx + dir;
  23804. var nextP = points[nextIdx];
  23805. if (connectNulls) {
  23806. // Find next point not null
  23807. while (nextP && isPointNull(points[nextIdx])) {
  23808. nextIdx += dir;
  23809. nextP = points[nextIdx];
  23810. }
  23811. }
  23812. var ratioNextSeg = 0.5;
  23813. var prevP = points[prevIdx];
  23814. var nextP = points[nextIdx];
  23815. // Last point
  23816. if (!nextP || isPointNull(nextP)) {
  23817. v2Copy(cp1, p);
  23818. }
  23819. else {
  23820. // If next data is null in not connect case
  23821. if (isPointNull(nextP) && !connectNulls) {
  23822. nextP = p;
  23823. }
  23824. vec2.sub(v, nextP, prevP);
  23825. var lenPrevSeg;
  23826. var lenNextSeg;
  23827. if (smoothMonotone === 'x' || smoothMonotone === 'y') {
  23828. var dim = smoothMonotone === 'x' ? 0 : 1;
  23829. lenPrevSeg = Math.abs(p[dim] - prevP[dim]);
  23830. lenNextSeg = Math.abs(p[dim] - nextP[dim]);
  23831. }
  23832. else {
  23833. lenPrevSeg = vec2.dist(p, prevP);
  23834. lenNextSeg = vec2.dist(p, nextP);
  23835. }
  23836. // Use ratio of seg length
  23837. ratioNextSeg = lenNextSeg / (lenNextSeg + lenPrevSeg);
  23838. scaleAndAdd(cp1, p, v, -smooth * (1 - ratioNextSeg));
  23839. }
  23840. // Smooth constraint
  23841. vec2Min(cp0, cp0, smoothMax);
  23842. vec2Max(cp0, cp0, smoothMin);
  23843. vec2Min(cp1, cp1, smoothMax);
  23844. vec2Max(cp1, cp1, smoothMin);
  23845. ctx.bezierCurveTo(
  23846. cp0[0], cp0[1],
  23847. cp1[0], cp1[1],
  23848. p[0], p[1]
  23849. );
  23850. // cp0 of next segment
  23851. scaleAndAdd(cp0, p, v, smooth * ratioNextSeg);
  23852. }
  23853. else {
  23854. ctx.lineTo(p[0], p[1]);
  23855. }
  23856. }
  23857. prevIdx = idx;
  23858. idx += dir;
  23859. }
  23860. return k;
  23861. }
  23862. function getBoundingBox(points, smoothConstraint) {
  23863. var ptMin = [Infinity, Infinity];
  23864. var ptMax = [-Infinity, -Infinity];
  23865. if (smoothConstraint) {
  23866. for (var i = 0; i < points.length; i++) {
  23867. var pt = points[i];
  23868. if (pt[0] < ptMin[0]) { ptMin[0] = pt[0]; }
  23869. if (pt[1] < ptMin[1]) { ptMin[1] = pt[1]; }
  23870. if (pt[0] > ptMax[0]) { ptMax[0] = pt[0]; }
  23871. if (pt[1] > ptMax[1]) { ptMax[1] = pt[1]; }
  23872. }
  23873. }
  23874. return {
  23875. min: smoothConstraint ? ptMin : ptMax,
  23876. max: smoothConstraint ? ptMax : ptMin
  23877. };
  23878. }
  23879. module.exports = {
  23880. Polyline: Path.extend({
  23881. type: 'ec-polyline',
  23882. shape: {
  23883. points: [],
  23884. smooth: 0,
  23885. smoothConstraint: true,
  23886. smoothMonotone: null,
  23887. connectNulls: false
  23888. },
  23889. style: {
  23890. fill: null,
  23891. stroke: '#000'
  23892. },
  23893. buildPath: function (ctx, shape) {
  23894. var points = shape.points;
  23895. var i = 0;
  23896. var len = points.length;
  23897. var result = getBoundingBox(points, shape.smoothConstraint);
  23898. if (shape.connectNulls) {
  23899. // Must remove first and last null values avoid draw error in polygon
  23900. for (; len > 0; len--) {
  23901. if (!isPointNull(points[len - 1])) {
  23902. break;
  23903. }
  23904. }
  23905. for (; i < len; i++) {
  23906. if (!isPointNull(points[i])) {
  23907. break;
  23908. }
  23909. }
  23910. }
  23911. while (i < len) {
  23912. i += drawSegment(
  23913. ctx, points, i, len, len,
  23914. 1, result.min, result.max, shape.smooth,
  23915. shape.smoothMonotone, shape.connectNulls
  23916. ) + 1;
  23917. }
  23918. }
  23919. }),
  23920. Polygon: Path.extend({
  23921. type: 'ec-polygon',
  23922. shape: {
  23923. points: [],
  23924. // Offset between stacked base points and points
  23925. stackedOnPoints: [],
  23926. smooth: 0,
  23927. stackedOnSmooth: 0,
  23928. smoothConstraint: true,
  23929. smoothMonotone: null,
  23930. connectNulls: false
  23931. },
  23932. buildPath: function (ctx, shape) {
  23933. var points = shape.points;
  23934. var stackedOnPoints = shape.stackedOnPoints;
  23935. var i = 0;
  23936. var len = points.length;
  23937. var smoothMonotone = shape.smoothMonotone;
  23938. var bbox = getBoundingBox(points, shape.smoothConstraint);
  23939. var stackedOnBBox = getBoundingBox(stackedOnPoints, shape.smoothConstraint);
  23940. if (shape.connectNulls) {
  23941. // Must remove first and last null values avoid draw error in polygon
  23942. for (; len > 0; len--) {
  23943. if (!isPointNull(points[len - 1])) {
  23944. break;
  23945. }
  23946. }
  23947. for (; i < len; i++) {
  23948. if (!isPointNull(points[i])) {
  23949. break;
  23950. }
  23951. }
  23952. }
  23953. while (i < len) {
  23954. var k = drawSegment(
  23955. ctx, points, i, len, len,
  23956. 1, bbox.min, bbox.max, shape.smooth,
  23957. smoothMonotone, shape.connectNulls
  23958. );
  23959. drawSegment(
  23960. ctx, stackedOnPoints, i + k - 1, k, len,
  23961. -1, stackedOnBBox.min, stackedOnBBox.max, shape.stackedOnSmooth,
  23962. smoothMonotone, shape.connectNulls
  23963. );
  23964. i += k + 1;
  23965. ctx.closePath();
  23966. }
  23967. }
  23968. })
  23969. };
  23970. /***/ },
  23971. /* 121 */
  23972. /***/ function(module, exports) {
  23973. module.exports = function (seriesType, defaultSymbolType, legendSymbol, ecModel, api) {
  23974. // Encoding visual for all series include which is filtered for legend drawing
  23975. ecModel.eachRawSeriesByType(seriesType, function (seriesModel) {
  23976. var data = seriesModel.getData();
  23977. var symbolType = seriesModel.get('symbol') || defaultSymbolType;
  23978. var symbolSize = seriesModel.get('symbolSize');
  23979. data.setVisual({
  23980. legendSymbol: legendSymbol || symbolType,
  23981. symbol: symbolType,
  23982. symbolSize: symbolSize
  23983. });
  23984. // Only visible series has each data be visual encoded
  23985. if (!ecModel.isSeriesFiltered(seriesModel)) {
  23986. if (typeof symbolSize === 'function') {
  23987. data.each(function (idx) {
  23988. var rawValue = seriesModel.getRawValue(idx);
  23989. // FIXME
  23990. var params = seriesModel.getDataParams(idx);
  23991. data.setItemVisual(idx, 'symbolSize', symbolSize(rawValue, params));
  23992. });
  23993. }
  23994. data.each(function (idx) {
  23995. var itemModel = data.getItemModel(idx);
  23996. var itemSymbolType = itemModel.getShallow('symbol', true);
  23997. var itemSymbolSize = itemModel.getShallow('symbolSize', true);
  23998. // If has item symbol
  23999. if (itemSymbolType != null) {
  24000. data.setItemVisual(idx, 'symbol', itemSymbolType);
  24001. }
  24002. if (itemSymbolSize != null) {
  24003. // PENDING Transform symbolSize ?
  24004. data.setItemVisual(idx, 'symbolSize', itemSymbolSize);
  24005. }
  24006. });
  24007. }
  24008. });
  24009. };
  24010. /***/ },
  24011. /* 122 */
  24012. /***/ function(module, exports) {
  24013. module.exports = function (seriesType, ecModel) {
  24014. ecModel.eachSeriesByType(seriesType, function (seriesModel) {
  24015. var data = seriesModel.getData();
  24016. var coordSys = seriesModel.coordinateSystem;
  24017. if (!coordSys) {
  24018. return;
  24019. }
  24020. var dims = [];
  24021. var coordDims = coordSys.dimensions;
  24022. for (var i = 0; i < coordDims.length; i++) {
  24023. dims.push(seriesModel.coordDimToDataDim(coordSys.dimensions[i])[0]);
  24024. }
  24025. if (dims.length === 1) {
  24026. data.each(dims[0], function (x, idx) {
  24027. // Also {Array.<number>}, not undefined to avoid if...else... statement
  24028. data.setItemLayout(idx, isNaN(x) ? [NaN, NaN] : coordSys.dataToPoint(x));
  24029. });
  24030. }
  24031. else if (dims.length === 2) {
  24032. data.each(dims, function (x, y, idx) {
  24033. // Also {Array.<number>}, not undefined to avoid if...else... statement
  24034. data.setItemLayout(
  24035. idx, (isNaN(x) || isNaN(y)) ? [NaN, NaN] : coordSys.dataToPoint([x, y])
  24036. );
  24037. }, true);
  24038. }
  24039. });
  24040. };
  24041. /***/ },
  24042. /* 123 */
  24043. /***/ function(module, exports) {
  24044. var samplers = {
  24045. average: function (frame) {
  24046. var sum = 0;
  24047. var count = 0;
  24048. for (var i = 0; i < frame.length; i++) {
  24049. if (!isNaN(frame[i])) {
  24050. sum += frame[i];
  24051. count++;
  24052. }
  24053. }
  24054. // Return NaN if count is 0
  24055. return count === 0 ? NaN : sum / count;
  24056. },
  24057. sum: function (frame) {
  24058. var sum = 0;
  24059. for (var i = 0; i < frame.length; i++) {
  24060. // Ignore NaN
  24061. sum += frame[i] || 0;
  24062. }
  24063. return sum;
  24064. },
  24065. max: function (frame) {
  24066. var max = -Infinity;
  24067. for (var i = 0; i < frame.length; i++) {
  24068. frame[i] > max && (max = frame[i]);
  24069. }
  24070. return max;
  24071. },
  24072. min: function (frame) {
  24073. var min = Infinity;
  24074. for (var i = 0; i < frame.length; i++) {
  24075. frame[i] < min && (min = frame[i]);
  24076. }
  24077. return min;
  24078. },
  24079. // TODO
  24080. // Median
  24081. nearest: function (frame) {
  24082. return frame[0];
  24083. }
  24084. };
  24085. var indexSampler = function (frame, value) {
  24086. return Math.round(frame.length / 2);
  24087. };
  24088. module.exports = function (seriesType, ecModel, api) {
  24089. ecModel.eachSeriesByType(seriesType, function (seriesModel) {
  24090. var data = seriesModel.getData();
  24091. var sampling = seriesModel.get('sampling');
  24092. var coordSys = seriesModel.coordinateSystem;
  24093. // Only cartesian2d support down sampling
  24094. if (coordSys.type === 'cartesian2d' && sampling) {
  24095. var baseAxis = coordSys.getBaseAxis();
  24096. var valueAxis = coordSys.getOtherAxis(baseAxis);
  24097. var extent = baseAxis.getExtent();
  24098. // Coordinste system has been resized
  24099. var size = extent[1] - extent[0];
  24100. var rate = Math.round(data.count() / size);
  24101. if (rate > 1) {
  24102. var sampler;
  24103. if (typeof sampling === 'string') {
  24104. sampler = samplers[sampling];
  24105. }
  24106. else if (typeof sampling === 'function') {
  24107. sampler = sampling;
  24108. }
  24109. if (sampler) {
  24110. data = data.downSample(
  24111. valueAxis.dim, 1 / rate, sampler, indexSampler
  24112. );
  24113. seriesModel.setData(data);
  24114. }
  24115. }
  24116. }
  24117. }, this);
  24118. };
  24119. /***/ },
  24120. /* 124 */
  24121. /***/ function(module, exports, __webpack_require__) {
  24122. 'use strict';
  24123. var graphic = __webpack_require__(18);
  24124. var zrUtil = __webpack_require__(4);
  24125. var echarts = __webpack_require__(1);
  24126. __webpack_require__(125);
  24127. __webpack_require__(133);
  24128. // Grid view
  24129. echarts.extendComponentView({
  24130. type: 'grid',
  24131. render: function (gridModel, ecModel) {
  24132. this.group.removeAll();
  24133. if (gridModel.get('show')) {
  24134. this.group.add(new graphic.Rect({
  24135. shape: gridModel.coordinateSystem.getRect(),
  24136. style: zrUtil.defaults({
  24137. fill: gridModel.get('backgroundColor')
  24138. }, gridModel.getItemStyle()),
  24139. silent: true,
  24140. z2: -1
  24141. }));
  24142. }
  24143. }
  24144. });
  24145. echarts.registerPreprocessor(function (option) {
  24146. // Only create grid when need
  24147. if (option.xAxis && option.yAxis && !option.grid) {
  24148. option.grid = {};
  24149. }
  24150. });
  24151. /***/ },
  24152. /* 125 */
  24153. /***/ function(module, exports, __webpack_require__) {
  24154. /**
  24155. * Grid is a region which contains at most 4 cartesian systems
  24156. *
  24157. * TODO Default cartesian
  24158. */
  24159. var factory = exports;
  24160. var layout = __webpack_require__(71);
  24161. var axisHelper = __webpack_require__(101);
  24162. var zrUtil = __webpack_require__(4);
  24163. var Cartesian2D = __webpack_require__(126);
  24164. var Axis2D = __webpack_require__(128);
  24165. var each = zrUtil.each;
  24166. var ifAxisCrossZero = axisHelper.ifAxisCrossZero;
  24167. var niceScaleExtent = axisHelper.niceScaleExtent;
  24168. // 依赖 GridModel, AxisModel 做预处理
  24169. __webpack_require__(129);
  24170. /**
  24171. * Check if the axis is used in the specified grid
  24172. * @inner
  24173. */
  24174. function isAxisUsedInTheGrid(axisModel, gridModel, ecModel) {
  24175. return axisModel.getCoordSysModel() === gridModel;
  24176. }
  24177. function getLabelUnionRect(axis) {
  24178. var axisModel = axis.model;
  24179. var labels = axisModel.getFormattedLabels();
  24180. var textStyleModel = axisModel.getModel('axisLabel.textStyle');
  24181. var rect;
  24182. var step = 1;
  24183. var labelCount = labels.length;
  24184. if (labelCount > 40) {
  24185. // Simple optimization for large amount of labels
  24186. step = Math.ceil(labelCount / 40);
  24187. }
  24188. for (var i = 0; i < labelCount; i += step) {
  24189. if (!axis.isLabelIgnored(i)) {
  24190. var singleRect = textStyleModel.getTextRect(labels[i]);
  24191. // FIXME consider label rotate
  24192. rect ? rect.union(singleRect) : (rect = singleRect);
  24193. }
  24194. }
  24195. return rect;
  24196. }
  24197. function Grid(gridModel, ecModel, api) {
  24198. /**
  24199. * @type {Object.<string, module:echarts/coord/cartesian/Cartesian2D>}
  24200. * @private
  24201. */
  24202. this._coordsMap = {};
  24203. /**
  24204. * @type {Array.<module:echarts/coord/cartesian/Cartesian>}
  24205. * @private
  24206. */
  24207. this._coordsList = [];
  24208. /**
  24209. * @type {Object.<string, module:echarts/coord/cartesian/Axis2D>}
  24210. * @private
  24211. */
  24212. this._axesMap = {};
  24213. /**
  24214. * @type {Array.<module:echarts/coord/cartesian/Axis2D>}
  24215. * @private
  24216. */
  24217. this._axesList = [];
  24218. this._initCartesian(gridModel, ecModel, api);
  24219. this.model = gridModel;
  24220. }
  24221. var gridProto = Grid.prototype;
  24222. gridProto.type = 'grid';
  24223. gridProto.axisPointerEnabled = true;
  24224. gridProto.getRect = function () {
  24225. return this._rect;
  24226. };
  24227. gridProto.update = function (ecModel, api) {
  24228. var axesMap = this._axesMap;
  24229. this._updateScale(ecModel, this.model);
  24230. function ifAxisCanNotOnZero(otherAxisDim) {
  24231. var axes = axesMap[otherAxisDim];
  24232. for (var idx in axes) {
  24233. if (axes.hasOwnProperty(idx)) {
  24234. var axis = axes[idx];
  24235. if (axis && (
  24236. axis.type === 'category' || axis.type === 'time' || !ifAxisCrossZero(axis)
  24237. )) {
  24238. return true;
  24239. }
  24240. }
  24241. }
  24242. return false;
  24243. }
  24244. each(axesMap.x, function (xAxis) {
  24245. niceScaleExtent(xAxis.scale, xAxis.model);
  24246. });
  24247. each(axesMap.y, function (yAxis) {
  24248. niceScaleExtent(yAxis.scale, yAxis.model);
  24249. });
  24250. // Fix configuration
  24251. each(axesMap.x, function (xAxis) {
  24252. // onZero can not be enabled in these two situations
  24253. // 1. When any other axis is a category axis
  24254. // 2. When any other axis not across 0 point
  24255. if (ifAxisCanNotOnZero('y')) {
  24256. xAxis.onZero = false;
  24257. }
  24258. });
  24259. each(axesMap.y, function (yAxis) {
  24260. if (ifAxisCanNotOnZero('x')) {
  24261. yAxis.onZero = false;
  24262. }
  24263. });
  24264. // Resize again if containLabel is enabled
  24265. // FIXME It may cause getting wrong grid size in data processing stage
  24266. this.resize(this.model, api);
  24267. };
  24268. /**
  24269. * Resize the grid
  24270. * @param {module:echarts/coord/cartesian/GridModel} gridModel
  24271. * @param {module:echarts/ExtensionAPI} api
  24272. */
  24273. gridProto.resize = function (gridModel, api, ignoreContainLabel) {
  24274. var gridRect = layout.getLayoutRect(
  24275. gridModel.getBoxLayoutParams(), {
  24276. width: api.getWidth(),
  24277. height: api.getHeight()
  24278. });
  24279. this._rect = gridRect;
  24280. var axesList = this._axesList;
  24281. adjustAxes();
  24282. // Minus label size
  24283. if (!ignoreContainLabel && gridModel.get('containLabel')) {
  24284. each(axesList, function (axis) {
  24285. if (!axis.model.get('axisLabel.inside')) {
  24286. var labelUnionRect = getLabelUnionRect(axis);
  24287. if (labelUnionRect) {
  24288. var dim = axis.isHorizontal() ? 'height' : 'width';
  24289. var margin = axis.model.get('axisLabel.margin');
  24290. gridRect[dim] -= labelUnionRect[dim] + margin;
  24291. if (axis.position === 'top') {
  24292. gridRect.y += labelUnionRect.height + margin;
  24293. }
  24294. else if (axis.position === 'left') {
  24295. gridRect.x += labelUnionRect.width + margin;
  24296. }
  24297. }
  24298. }
  24299. });
  24300. adjustAxes();
  24301. }
  24302. function adjustAxes() {
  24303. each(axesList, function (axis) {
  24304. var isHorizontal = axis.isHorizontal();
  24305. var extent = isHorizontal ? [0, gridRect.width] : [0, gridRect.height];
  24306. var idx = axis.inverse ? 1 : 0;
  24307. axis.setExtent(extent[idx], extent[1 - idx]);
  24308. updateAxisTransfrom(axis, isHorizontal ? gridRect.x : gridRect.y);
  24309. });
  24310. }
  24311. };
  24312. /**
  24313. * @param {string} axisType
  24314. * @param {ndumber} [axisIndex]
  24315. */
  24316. gridProto.getAxis = function (axisType, axisIndex) {
  24317. var axesMapOnDim = this._axesMap[axisType];
  24318. if (axesMapOnDim != null) {
  24319. if (axisIndex == null) {
  24320. // Find first axis
  24321. for (var name in axesMapOnDim) {
  24322. if (axesMapOnDim.hasOwnProperty(name)) {
  24323. return axesMapOnDim[name];
  24324. }
  24325. }
  24326. }
  24327. return axesMapOnDim[axisIndex];
  24328. }
  24329. };
  24330. /**
  24331. * @return {Array.<module:echarts/coord/Axis>}
  24332. */
  24333. gridProto.getAxes = function () {
  24334. return this._axesList.slice();
  24335. };
  24336. /**
  24337. * Usage:
  24338. * grid.getCartesian(xAxisIndex, yAxisIndex);
  24339. * grid.getCartesian(xAxisIndex);
  24340. * grid.getCartesian(null, yAxisIndex);
  24341. * grid.getCartesian({xAxisIndex: ..., yAxisIndex: ...});
  24342. *
  24343. * @param {number|Object} [xAxisIndex]
  24344. * @param {number} [yAxisIndex]
  24345. */
  24346. gridProto.getCartesian = function (xAxisIndex, yAxisIndex) {
  24347. if (xAxisIndex != null && yAxisIndex != null) {
  24348. var key = 'x' + xAxisIndex + 'y' + yAxisIndex;
  24349. return this._coordsMap[key];
  24350. }
  24351. if (zrUtil.isObject(xAxisIndex)) {
  24352. yAxisIndex = xAxisIndex.yAxisIndex;
  24353. xAxisIndex = xAxisIndex.xAxisIndex;
  24354. }
  24355. // When only xAxisIndex or yAxisIndex given, find its first cartesian.
  24356. for (var i = 0, coordList = this._coordsList; i < coordList.length; i++) {
  24357. if (coordList[i].getAxis('x').index === xAxisIndex
  24358. || coordList[i].getAxis('y').index === yAxisIndex
  24359. ) {
  24360. return coordList[i];
  24361. }
  24362. }
  24363. };
  24364. gridProto.getCartesians = function () {
  24365. return this._coordsList.slice();
  24366. };
  24367. /**
  24368. * @implements
  24369. * see {module:echarts/CoodinateSystem}
  24370. */
  24371. gridProto.convertToPixel = function (ecModel, finder, value) {
  24372. var target = this._findConvertTarget(ecModel, finder);
  24373. return target.cartesian
  24374. ? target.cartesian.dataToPoint(value)
  24375. : target.axis
  24376. ? target.axis.toGlobalCoord(target.axis.dataToCoord(value))
  24377. : null;
  24378. };
  24379. /**
  24380. * @implements
  24381. * see {module:echarts/CoodinateSystem}
  24382. */
  24383. gridProto.convertFromPixel = function (ecModel, finder, value) {
  24384. var target = this._findConvertTarget(ecModel, finder);
  24385. return target.cartesian
  24386. ? target.cartesian.pointToData(value)
  24387. : target.axis
  24388. ? target.axis.coordToData(target.axis.toLocalCoord(value))
  24389. : null;
  24390. };
  24391. /**
  24392. * @inner
  24393. */
  24394. gridProto._findConvertTarget = function (ecModel, finder) {
  24395. var seriesModel = finder.seriesModel;
  24396. var xAxisModel = finder.xAxisModel
  24397. || (seriesModel && seriesModel.getReferringComponents('xAxis')[0]);
  24398. var yAxisModel = finder.yAxisModel
  24399. || (seriesModel && seriesModel.getReferringComponents('yAxis')[0]);
  24400. var gridModel = finder.gridModel;
  24401. var coordsList = this._coordsList;
  24402. var cartesian;
  24403. var axis;
  24404. if (seriesModel) {
  24405. cartesian = seriesModel.coordinateSystem;
  24406. zrUtil.indexOf(coordsList, cartesian) < 0 && (cartesian = null);
  24407. }
  24408. else if (xAxisModel && yAxisModel) {
  24409. cartesian = this.getCartesian(xAxisModel.componentIndex, yAxisModel.componentIndex);
  24410. }
  24411. else if (xAxisModel) {
  24412. axis = this.getAxis('x', xAxisModel.componentIndex);
  24413. }
  24414. else if (yAxisModel) {
  24415. axis = this.getAxis('y', yAxisModel.componentIndex);
  24416. }
  24417. // Lowest priority.
  24418. else if (gridModel) {
  24419. var grid = gridModel.coordinateSystem;
  24420. if (grid === this) {
  24421. cartesian = this._coordsList[0];
  24422. }
  24423. }
  24424. return {cartesian: cartesian, axis: axis};
  24425. };
  24426. /**
  24427. * @implements
  24428. * see {module:echarts/CoodinateSystem}
  24429. */
  24430. gridProto.containPoint = function (point) {
  24431. var coord = this._coordsList[0];
  24432. if (coord) {
  24433. return coord.containPoint(point);
  24434. }
  24435. };
  24436. /**
  24437. * Initialize cartesian coordinate systems
  24438. * @private
  24439. */
  24440. gridProto._initCartesian = function (gridModel, ecModel, api) {
  24441. var axisPositionUsed = {
  24442. left: false,
  24443. right: false,
  24444. top: false,
  24445. bottom: false
  24446. };
  24447. var axesMap = {
  24448. x: {},
  24449. y: {}
  24450. };
  24451. var axesCount = {
  24452. x: 0,
  24453. y: 0
  24454. };
  24455. /// Create axis
  24456. ecModel.eachComponent('xAxis', createAxisCreator('x'), this);
  24457. ecModel.eachComponent('yAxis', createAxisCreator('y'), this);
  24458. if (!axesCount.x || !axesCount.y) {
  24459. // Roll back when there no either x or y axis
  24460. this._axesMap = {};
  24461. this._axesList = [];
  24462. return;
  24463. }
  24464. this._axesMap = axesMap;
  24465. /// Create cartesian2d
  24466. each(axesMap.x, function (xAxis, xAxisIndex) {
  24467. each(axesMap.y, function (yAxis, yAxisIndex) {
  24468. var key = 'x' + xAxisIndex + 'y' + yAxisIndex;
  24469. var cartesian = new Cartesian2D(key);
  24470. cartesian.grid = this;
  24471. cartesian.model = gridModel;
  24472. this._coordsMap[key] = cartesian;
  24473. this._coordsList.push(cartesian);
  24474. cartesian.addAxis(xAxis);
  24475. cartesian.addAxis(yAxis);
  24476. }, this);
  24477. }, this);
  24478. function createAxisCreator(axisType) {
  24479. return function (axisModel, idx) {
  24480. if (!isAxisUsedInTheGrid(axisModel, gridModel, ecModel)) {
  24481. return;
  24482. }
  24483. var axisPosition = axisModel.get('position');
  24484. if (axisType === 'x') {
  24485. // Fix position
  24486. if (axisPosition !== 'top' && axisPosition !== 'bottom') {
  24487. // Default bottom of X
  24488. axisPosition = 'bottom';
  24489. if (axisPositionUsed[axisPosition]) {
  24490. axisPosition = axisPosition === 'top' ? 'bottom' : 'top';
  24491. }
  24492. }
  24493. }
  24494. else {
  24495. // Fix position
  24496. if (axisPosition !== 'left' && axisPosition !== 'right') {
  24497. // Default left of Y
  24498. axisPosition = 'left';
  24499. if (axisPositionUsed[axisPosition]) {
  24500. axisPosition = axisPosition === 'left' ? 'right' : 'left';
  24501. }
  24502. }
  24503. }
  24504. axisPositionUsed[axisPosition] = true;
  24505. var axis = new Axis2D(
  24506. axisType, axisHelper.createScaleByModel(axisModel),
  24507. [0, 0],
  24508. axisModel.get('type'),
  24509. axisPosition
  24510. );
  24511. var isCategory = axis.type === 'category';
  24512. axis.onBand = isCategory && axisModel.get('boundaryGap');
  24513. axis.inverse = axisModel.get('inverse');
  24514. axis.onZero = axisModel.get('axisLine.onZero');
  24515. // Inject axis into axisModel
  24516. axisModel.axis = axis;
  24517. // Inject axisModel into axis
  24518. axis.model = axisModel;
  24519. // Inject grid info axis
  24520. axis.grid = this;
  24521. // Index of axis, can be used as key
  24522. axis.index = idx;
  24523. this._axesList.push(axis);
  24524. axesMap[axisType][idx] = axis;
  24525. axesCount[axisType]++;
  24526. };
  24527. }
  24528. };
  24529. /**
  24530. * Update cartesian properties from series
  24531. * @param {module:echarts/model/Option} option
  24532. * @private
  24533. */
  24534. gridProto._updateScale = function (ecModel, gridModel) {
  24535. // Reset scale
  24536. zrUtil.each(this._axesList, function (axis) {
  24537. axis.scale.setExtent(Infinity, -Infinity);
  24538. });
  24539. ecModel.eachSeries(function (seriesModel) {
  24540. if (isCartesian2D(seriesModel)) {
  24541. var axesModels = findAxesModels(seriesModel, ecModel);
  24542. var xAxisModel = axesModels[0];
  24543. var yAxisModel = axesModels[1];
  24544. if (!isAxisUsedInTheGrid(xAxisModel, gridModel, ecModel)
  24545. || !isAxisUsedInTheGrid(yAxisModel, gridModel, ecModel)
  24546. ) {
  24547. return;
  24548. }
  24549. var cartesian = this.getCartesian(
  24550. xAxisModel.componentIndex, yAxisModel.componentIndex
  24551. );
  24552. var data = seriesModel.getData();
  24553. var xAxis = cartesian.getAxis('x');
  24554. var yAxis = cartesian.getAxis('y');
  24555. if (data.type === 'list') {
  24556. unionExtent(data, xAxis, seriesModel);
  24557. unionExtent(data, yAxis, seriesModel);
  24558. }
  24559. }
  24560. }, this);
  24561. function unionExtent(data, axis, seriesModel) {
  24562. each(seriesModel.coordDimToDataDim(axis.dim), function (dim) {
  24563. axis.scale.unionExtentFromData(data, dim);
  24564. });
  24565. }
  24566. };
  24567. /**
  24568. * @param {string} [dim] 'x' or 'y' or 'auto' or null/undefined
  24569. * @return {Object} {baseAxes: [], otherAxes: []}
  24570. */
  24571. gridProto.getTooltipAxes = function (dim) {
  24572. var baseAxes = [];
  24573. var otherAxes = [];
  24574. each(this.getCartesians(), function (cartesian) {
  24575. var baseAxis = (dim != null && dim !== 'auto')
  24576. ? cartesian.getAxis(dim) : cartesian.getBaseAxis();
  24577. var otherAxis = cartesian.getOtherAxis(baseAxis);
  24578. zrUtil.indexOf(baseAxes, baseAxis) < 0 && baseAxes.push(baseAxis);
  24579. zrUtil.indexOf(otherAxes, otherAxis) < 0 && otherAxes.push(otherAxis);
  24580. });
  24581. return {baseAxes: baseAxes, otherAxes: otherAxes};
  24582. };
  24583. /**
  24584. * @inner
  24585. */
  24586. function updateAxisTransfrom(axis, coordBase) {
  24587. var axisExtent = axis.getExtent();
  24588. var axisExtentSum = axisExtent[0] + axisExtent[1];
  24589. // Fast transform
  24590. axis.toGlobalCoord = axis.dim === 'x'
  24591. ? function (coord) {
  24592. return coord + coordBase;
  24593. }
  24594. : function (coord) {
  24595. return axisExtentSum - coord + coordBase;
  24596. };
  24597. axis.toLocalCoord = axis.dim === 'x'
  24598. ? function (coord) {
  24599. return coord - coordBase;
  24600. }
  24601. : function (coord) {
  24602. return axisExtentSum - coord + coordBase;
  24603. };
  24604. }
  24605. var axesTypes = ['xAxis', 'yAxis'];
  24606. /**
  24607. * @inner
  24608. */
  24609. function findAxesModels(seriesModel, ecModel) {
  24610. return zrUtil.map(axesTypes, function (axisType) {
  24611. var axisModel = seriesModel.getReferringComponents(axisType)[0];
  24612. if (true) {
  24613. if (!axisModel) {
  24614. throw new Error(axisType + ' "' + zrUtil.retrieve(
  24615. seriesModel.get(axisType + 'Index'),
  24616. seriesModel.get(axisType + 'Id'),
  24617. 0
  24618. ) + '" not found');
  24619. }
  24620. }
  24621. return axisModel;
  24622. });
  24623. }
  24624. /**
  24625. * @inner
  24626. */
  24627. function isCartesian2D(seriesModel) {
  24628. return seriesModel.get('coordinateSystem') === 'cartesian2d';
  24629. }
  24630. Grid.create = function (ecModel, api) {
  24631. var grids = [];
  24632. ecModel.eachComponent('grid', function (gridModel, idx) {
  24633. var grid = new Grid(gridModel, ecModel, api);
  24634. grid.name = 'grid_' + idx;
  24635. // dataSampling requires axis extent, so resize
  24636. // should be performed in create stage.
  24637. grid.resize(gridModel, api, true);
  24638. gridModel.coordinateSystem = grid;
  24639. grids.push(grid);
  24640. });
  24641. // Inject the coordinateSystems into seriesModel
  24642. ecModel.eachSeries(function (seriesModel) {
  24643. if (!isCartesian2D(seriesModel)) {
  24644. return;
  24645. }
  24646. var axesModels = findAxesModels(seriesModel, ecModel);
  24647. var xAxisModel = axesModels[0];
  24648. var yAxisModel = axesModels[1];
  24649. var gridModel = xAxisModel.getCoordSysModel();
  24650. if (true) {
  24651. if (!gridModel) {
  24652. throw new Error(
  24653. 'Grid "' + zrUtil.retrieve(
  24654. xAxisModel.get('gridIndex'),
  24655. xAxisModel.get('gridId'),
  24656. 0
  24657. ) + '" not found'
  24658. );
  24659. }
  24660. if (xAxisModel.getCoordSysModel() !== yAxisModel.getCoordSysModel()) {
  24661. throw new Error('xAxis and yAxis must use the same grid');
  24662. }
  24663. }
  24664. var grid = gridModel.coordinateSystem;
  24665. seriesModel.coordinateSystem = grid.getCartesian(
  24666. xAxisModel.componentIndex, yAxisModel.componentIndex
  24667. );
  24668. });
  24669. return grids;
  24670. };
  24671. // For deciding which dimensions to use when creating list data
  24672. Grid.dimensions = Grid.prototype.dimensions = Cartesian2D.prototype.dimensions;
  24673. __webpack_require__(76).register('cartesian2d', Grid);
  24674. module.exports = Grid;
  24675. /***/ },
  24676. /* 126 */
  24677. /***/ function(module, exports, __webpack_require__) {
  24678. 'use strict';
  24679. var zrUtil = __webpack_require__(4);
  24680. var Cartesian = __webpack_require__(127);
  24681. function Cartesian2D(name) {
  24682. Cartesian.call(this, name);
  24683. }
  24684. Cartesian2D.prototype = {
  24685. constructor: Cartesian2D,
  24686. type: 'cartesian2d',
  24687. /**
  24688. * @type {Array.<string>}
  24689. * @readOnly
  24690. */
  24691. dimensions: ['x', 'y'],
  24692. /**
  24693. * Base axis will be used on stacking.
  24694. *
  24695. * @return {module:echarts/coord/cartesian/Axis2D}
  24696. */
  24697. getBaseAxis: function () {
  24698. return this.getAxesByScale('ordinal')[0]
  24699. || this.getAxesByScale('time')[0]
  24700. || this.getAxis('x');
  24701. },
  24702. /**
  24703. * If contain point
  24704. * @param {Array.<number>} point
  24705. * @return {boolean}
  24706. */
  24707. containPoint: function (point) {
  24708. var axisX = this.getAxis('x');
  24709. var axisY = this.getAxis('y');
  24710. return axisX.contain(axisX.toLocalCoord(point[0]))
  24711. && axisY.contain(axisY.toLocalCoord(point[1]));
  24712. },
  24713. /**
  24714. * If contain data
  24715. * @param {Array.<number>} data
  24716. * @return {boolean}
  24717. */
  24718. containData: function (data) {
  24719. return this.getAxis('x').containData(data[0])
  24720. && this.getAxis('y').containData(data[1]);
  24721. },
  24722. /**
  24723. * Convert series data to an array of points
  24724. * @param {module:echarts/data/List} data
  24725. * @param {boolean} stack
  24726. * @return {Array}
  24727. * Return array of points. For example:
  24728. * `[[10, 10], [20, 20], [30, 30]]`
  24729. */
  24730. dataToPoints: function (data, stack) {
  24731. return data.mapArray(['x', 'y'], function (x, y) {
  24732. return this.dataToPoint([x, y]);
  24733. }, stack, this);
  24734. },
  24735. /**
  24736. * @param {Array.<number>} data
  24737. * @param {boolean} [clamp=false]
  24738. * @return {Array.<number>}
  24739. */
  24740. dataToPoint: function (data, clamp) {
  24741. var xAxis = this.getAxis('x');
  24742. var yAxis = this.getAxis('y');
  24743. return [
  24744. xAxis.toGlobalCoord(xAxis.dataToCoord(data[0], clamp)),
  24745. yAxis.toGlobalCoord(yAxis.dataToCoord(data[1], clamp))
  24746. ];
  24747. },
  24748. /**
  24749. * @param {Array.<number>} point
  24750. * @param {boolean} [clamp=false]
  24751. * @return {Array.<number>}
  24752. */
  24753. pointToData: function (point, clamp) {
  24754. var xAxis = this.getAxis('x');
  24755. var yAxis = this.getAxis('y');
  24756. return [
  24757. xAxis.coordToData(xAxis.toLocalCoord(point[0]), clamp),
  24758. yAxis.coordToData(yAxis.toLocalCoord(point[1]), clamp)
  24759. ];
  24760. },
  24761. /**
  24762. * Get other axis
  24763. * @param {module:echarts/coord/cartesian/Axis2D} axis
  24764. */
  24765. getOtherAxis: function (axis) {
  24766. return this.getAxis(axis.dim === 'x' ? 'y' : 'x');
  24767. }
  24768. };
  24769. zrUtil.inherits(Cartesian2D, Cartesian);
  24770. module.exports = Cartesian2D;
  24771. /***/ },
  24772. /* 127 */
  24773. /***/ function(module, exports, __webpack_require__) {
  24774. 'use strict';
  24775. /**
  24776. * Cartesian coordinate system
  24777. * @module echarts/coord/Cartesian
  24778. *
  24779. */
  24780. var zrUtil = __webpack_require__(4);
  24781. function dimAxisMapper(dim) {
  24782. return this._axes[dim];
  24783. }
  24784. /**
  24785. * @alias module:echarts/coord/Cartesian
  24786. * @constructor
  24787. */
  24788. var Cartesian = function (name) {
  24789. this._axes = {};
  24790. this._dimList = [];
  24791. /**
  24792. * @type {string}
  24793. */
  24794. this.name = name || '';
  24795. };
  24796. Cartesian.prototype = {
  24797. constructor: Cartesian,
  24798. type: 'cartesian',
  24799. /**
  24800. * Get axis
  24801. * @param {number|string} dim
  24802. * @return {module:echarts/coord/Cartesian~Axis}
  24803. */
  24804. getAxis: function (dim) {
  24805. return this._axes[dim];
  24806. },
  24807. /**
  24808. * Get axes list
  24809. * @return {Array.<module:echarts/coord/Cartesian~Axis>}
  24810. */
  24811. getAxes: function () {
  24812. return zrUtil.map(this._dimList, dimAxisMapper, this);
  24813. },
  24814. /**
  24815. * Get axes list by given scale type
  24816. */
  24817. getAxesByScale: function (scaleType) {
  24818. scaleType = scaleType.toLowerCase();
  24819. return zrUtil.filter(
  24820. this.getAxes(),
  24821. function (axis) {
  24822. return axis.scale.type === scaleType;
  24823. }
  24824. );
  24825. },
  24826. /**
  24827. * Add axis
  24828. * @param {module:echarts/coord/Cartesian.Axis}
  24829. */
  24830. addAxis: function (axis) {
  24831. var dim = axis.dim;
  24832. this._axes[dim] = axis;
  24833. this._dimList.push(dim);
  24834. },
  24835. /**
  24836. * Convert data to coord in nd space
  24837. * @param {Array.<number>|Object.<string, number>} val
  24838. * @return {Array.<number>|Object.<string, number>}
  24839. */
  24840. dataToCoord: function (val) {
  24841. return this._dataCoordConvert(val, 'dataToCoord');
  24842. },
  24843. /**
  24844. * Convert coord in nd space to data
  24845. * @param {Array.<number>|Object.<string, number>} val
  24846. * @return {Array.<number>|Object.<string, number>}
  24847. */
  24848. coordToData: function (val) {
  24849. return this._dataCoordConvert(val, 'coordToData');
  24850. },
  24851. _dataCoordConvert: function (input, method) {
  24852. var dimList = this._dimList;
  24853. var output = input instanceof Array ? [] : {};
  24854. for (var i = 0; i < dimList.length; i++) {
  24855. var dim = dimList[i];
  24856. var axis = this._axes[dim];
  24857. output[dim] = axis[method](input[dim]);
  24858. }
  24859. return output;
  24860. }
  24861. };
  24862. module.exports = Cartesian;
  24863. /***/ },
  24864. /* 128 */
  24865. /***/ function(module, exports, __webpack_require__) {
  24866. var zrUtil = __webpack_require__(4);
  24867. var Axis = __webpack_require__(100);
  24868. /**
  24869. * Extend axis 2d
  24870. * @constructor module:echarts/coord/cartesian/Axis2D
  24871. * @extends {module:echarts/coord/cartesian/Axis}
  24872. * @param {string} dim
  24873. * @param {*} scale
  24874. * @param {Array.<number>} coordExtent
  24875. * @param {string} axisType
  24876. * @param {string} position
  24877. */
  24878. var Axis2D = function (dim, scale, coordExtent, axisType, position) {
  24879. Axis.call(this, dim, scale, coordExtent);
  24880. /**
  24881. * Axis type
  24882. * - 'category'
  24883. * - 'value'
  24884. * - 'time'
  24885. * - 'log'
  24886. * @type {string}
  24887. */
  24888. this.type = axisType || 'value';
  24889. /**
  24890. * Axis position
  24891. * - 'top'
  24892. * - 'bottom'
  24893. * - 'left'
  24894. * - 'right'
  24895. */
  24896. this.position = position || 'bottom';
  24897. };
  24898. Axis2D.prototype = {
  24899. constructor: Axis2D,
  24900. /**
  24901. * Index of axis, can be used as key
  24902. */
  24903. index: 0,
  24904. /**
  24905. * If axis is on the zero position of the other axis
  24906. * @type {boolean}
  24907. */
  24908. onZero: false,
  24909. /**
  24910. * Axis model
  24911. * @param {module:echarts/coord/cartesian/AxisModel}
  24912. */
  24913. model: null,
  24914. isHorizontal: function () {
  24915. var position = this.position;
  24916. return position === 'top' || position === 'bottom';
  24917. },
  24918. /**
  24919. * Each item cooresponds to this.getExtent(), which
  24920. * means globalExtent[0] may greater than globalExtent[1],
  24921. * unless `asc` is input.
  24922. *
  24923. * @param {boolean} [asc]
  24924. * @return {Array.<number>}
  24925. */
  24926. getGlobalExtent: function (asc) {
  24927. var ret = this.getExtent();
  24928. ret[0] = this.toGlobalCoord(ret[0]);
  24929. ret[1] = this.toGlobalCoord(ret[1]);
  24930. asc && ret[0] > ret[1] && ret.reverse();
  24931. return ret;
  24932. },
  24933. getOtherAxis: function () {
  24934. this.grid.getOtherAxis();
  24935. },
  24936. /**
  24937. * If label is ignored.
  24938. * Automatically used when axis is category and label can not be all shown
  24939. * @param {number} idx
  24940. * @return {boolean}
  24941. */
  24942. isLabelIgnored: function (idx) {
  24943. if (this.type === 'category') {
  24944. var labelInterval = this.getLabelInterval();
  24945. return ((typeof labelInterval === 'function')
  24946. && !labelInterval(idx, this.scale.getLabel(idx)))
  24947. || idx % (labelInterval + 1);
  24948. }
  24949. },
  24950. /**
  24951. * @override
  24952. */
  24953. pointToData: function (point, clamp) {
  24954. return this.coordToData(this.toLocalCoord(point[this.dim === 'x' ? 0 : 1]), clamp);
  24955. },
  24956. /**
  24957. * Transform global coord to local coord,
  24958. * i.e. var localCoord = axis.toLocalCoord(80);
  24959. * designate by module:echarts/coord/cartesian/Grid.
  24960. * @type {Function}
  24961. */
  24962. toLocalCoord: null,
  24963. /**
  24964. * Transform global coord to local coord,
  24965. * i.e. var globalCoord = axis.toLocalCoord(40);
  24966. * designate by module:echarts/coord/cartesian/Grid.
  24967. * @type {Function}
  24968. */
  24969. toGlobalCoord: null
  24970. };
  24971. zrUtil.inherits(Axis2D, Axis);
  24972. module.exports = Axis2D;
  24973. /***/ },
  24974. /* 129 */
  24975. /***/ function(module, exports, __webpack_require__) {
  24976. 'use strict';
  24977. // Grid 是在有直角坐标系的时候必须要存在的
  24978. // 所以这里也要被 Cartesian2D 依赖
  24979. __webpack_require__(130);
  24980. var ComponentModel = __webpack_require__(69);
  24981. module.exports = ComponentModel.extend({
  24982. type: 'grid',
  24983. dependencies: ['xAxis', 'yAxis'],
  24984. layoutMode: 'box',
  24985. /**
  24986. * @type {module:echarts/coord/cartesian/Grid}
  24987. */
  24988. coordinateSystem: null,
  24989. defaultOption: {
  24990. show: false,
  24991. zlevel: 0,
  24992. z: 0,
  24993. left: '10%',
  24994. top: 60,
  24995. right: '10%',
  24996. bottom: 60,
  24997. // If grid size contain label
  24998. containLabel: false,
  24999. // width: {totalWidth} - left - right,
  25000. // height: {totalHeight} - top - bottom,
  25001. backgroundColor: 'rgba(0,0,0,0)',
  25002. borderWidth: 1,
  25003. borderColor: '#ccc'
  25004. }
  25005. });
  25006. /***/ },
  25007. /* 130 */
  25008. /***/ function(module, exports, __webpack_require__) {
  25009. 'use strict';
  25010. var ComponentModel = __webpack_require__(69);
  25011. var zrUtil = __webpack_require__(4);
  25012. var axisModelCreator = __webpack_require__(131);
  25013. var AxisModel = ComponentModel.extend({
  25014. type: 'cartesian2dAxis',
  25015. /**
  25016. * @type {module:echarts/coord/cartesian/Axis2D}
  25017. */
  25018. axis: null,
  25019. /**
  25020. * @override
  25021. */
  25022. init: function () {
  25023. AxisModel.superApply(this, 'init', arguments);
  25024. this.resetRange();
  25025. },
  25026. /**
  25027. * @override
  25028. */
  25029. mergeOption: function () {
  25030. AxisModel.superApply(this, 'mergeOption', arguments);
  25031. this.resetRange();
  25032. },
  25033. /**
  25034. * @override
  25035. */
  25036. restoreData: function () {
  25037. AxisModel.superApply(this, 'restoreData', arguments);
  25038. this.resetRange();
  25039. },
  25040. /**
  25041. * @override
  25042. * @return {module:echarts/model/Component}
  25043. */
  25044. getCoordSysModel: function () {
  25045. return this.ecModel.queryComponents({
  25046. mainType: 'grid',
  25047. index: this.option.gridIndex,
  25048. id: this.option.gridId
  25049. })[0];
  25050. }
  25051. });
  25052. function getAxisType(axisDim, option) {
  25053. // Default axis with data is category axis
  25054. return option.type || (option.data ? 'category' : 'value');
  25055. }
  25056. zrUtil.merge(AxisModel.prototype, __webpack_require__(112));
  25057. var extraOption = {
  25058. // gridIndex: 0,
  25059. // gridId: '',
  25060. // Offset is for multiple axis on the same position
  25061. offset: 0
  25062. };
  25063. axisModelCreator('x', AxisModel, getAxisType, extraOption);
  25064. axisModelCreator('y', AxisModel, getAxisType, extraOption);
  25065. module.exports = AxisModel;
  25066. /***/ },
  25067. /* 131 */
  25068. /***/ function(module, exports, __webpack_require__) {
  25069. var axisDefault = __webpack_require__(132);
  25070. var zrUtil = __webpack_require__(4);
  25071. var ComponentModel = __webpack_require__(69);
  25072. var layout = __webpack_require__(71);
  25073. // FIXME axisType is fixed ?
  25074. var AXIS_TYPES = ['value', 'category', 'time', 'log'];
  25075. /**
  25076. * Generate sub axis model class
  25077. * @param {string} axisName 'x' 'y' 'radius' 'angle' 'parallel'
  25078. * @param {module:echarts/model/Component} BaseAxisModelClass
  25079. * @param {Function} axisTypeDefaulter
  25080. * @param {Object} [extraDefaultOption]
  25081. */
  25082. module.exports = function (axisName, BaseAxisModelClass, axisTypeDefaulter, extraDefaultOption) {
  25083. zrUtil.each(AXIS_TYPES, function (axisType) {
  25084. BaseAxisModelClass.extend({
  25085. type: axisName + 'Axis.' + axisType,
  25086. mergeDefaultAndTheme: function (option, ecModel) {
  25087. var layoutMode = this.layoutMode;
  25088. var inputPositionParams = layoutMode
  25089. ? layout.getLayoutParams(option) : {};
  25090. var themeModel = ecModel.getTheme();
  25091. zrUtil.merge(option, themeModel.get(axisType + 'Axis'));
  25092. zrUtil.merge(option, this.getDefaultOption());
  25093. option.type = axisTypeDefaulter(axisName, option);
  25094. if (layoutMode) {
  25095. layout.mergeLayoutParam(option, inputPositionParams, layoutMode);
  25096. }
  25097. },
  25098. defaultOption: zrUtil.mergeAll(
  25099. [
  25100. {},
  25101. axisDefault[axisType + 'Axis'],
  25102. extraDefaultOption
  25103. ],
  25104. true
  25105. )
  25106. });
  25107. });
  25108. ComponentModel.registerSubTypeDefaulter(
  25109. axisName + 'Axis',
  25110. zrUtil.curry(axisTypeDefaulter, axisName)
  25111. );
  25112. };
  25113. /***/ },
  25114. /* 132 */
  25115. /***/ function(module, exports, __webpack_require__) {
  25116. var zrUtil = __webpack_require__(4);
  25117. var defaultOption = {
  25118. show: true,
  25119. zlevel: 0, // 一级层叠
  25120. z: 0, // 二级层叠
  25121. // 反向坐标轴
  25122. inverse: false,
  25123. // 坐标轴名字,默认为空
  25124. name: '',
  25125. // 坐标轴名字位置,支持'start' | 'middle' | 'end'
  25126. nameLocation: 'end',
  25127. // 坐标轴名字旋转,degree。
  25128. nameRotate: null, // Adapt to axis rotate, when nameLocation is 'middle'.
  25129. nameTruncate: {
  25130. maxWidth: null,
  25131. ellipsis: '...',
  25132. placeholder: '.'
  25133. },
  25134. // 坐标轴文字样式,默认取全局样式
  25135. nameTextStyle: {},
  25136. // 文字与轴线距离
  25137. nameGap: 15,
  25138. silent: false, // Default false to support tooltip.
  25139. triggerEvent: false, // Default false to avoid legacy user event listener fail.
  25140. tooltip: {
  25141. show: false
  25142. },
  25143. axisPointer: {},
  25144. // 坐标轴线
  25145. axisLine: {
  25146. // 默认显示,属性show控制显示与否
  25147. show: true,
  25148. onZero: true,
  25149. // 属性lineStyle控制线条样式
  25150. lineStyle: {
  25151. color: '#333',
  25152. width: 1,
  25153. type: 'solid'
  25154. }
  25155. },
  25156. // 坐标轴小标记
  25157. axisTick: {
  25158. // 属性show控制显示与否,默认显示
  25159. show: true,
  25160. // 控制小标记是否在grid里
  25161. inside: false,
  25162. // 属性length控制线长
  25163. length: 5,
  25164. // 属性lineStyle控制线条样式
  25165. lineStyle: {
  25166. width: 1
  25167. }
  25168. },
  25169. // 坐标轴文本标签,详见axis.axisLabel
  25170. axisLabel: {
  25171. show: true,
  25172. // 控制文本标签是否在grid里
  25173. inside: false,
  25174. rotate: 0,
  25175. showMinLabel: null, // true | false | null (auto)
  25176. showMaxLabel: null, // true | false | null (auto)
  25177. margin: 8,
  25178. // formatter: null,
  25179. // 其余属性默认使用全局文本样式,详见TEXTSTYLE
  25180. textStyle: {
  25181. fontSize: 12
  25182. }
  25183. },
  25184. // 分隔线
  25185. splitLine: {
  25186. // 默认显示,属性show控制显示与否
  25187. show: true,
  25188. // 属性lineStyle(详见lineStyle)控制线条样式
  25189. lineStyle: {
  25190. color: ['#ccc'],
  25191. width: 1,
  25192. type: 'solid'
  25193. }
  25194. },
  25195. // 分隔区域
  25196. splitArea: {
  25197. // 默认不显示,属性show控制显示与否
  25198. show: false,
  25199. // 属性areaStyle(详见areaStyle)控制区域样式
  25200. areaStyle: {
  25201. color: ['rgba(250,250,250,0.3)','rgba(200,200,200,0.3)']
  25202. }
  25203. }
  25204. };
  25205. var categoryAxis = zrUtil.merge({
  25206. // 类目起始和结束两端空白策略
  25207. boundaryGap: true,
  25208. // splitArea: {
  25209. // show: false
  25210. // },
  25211. splitLine: {
  25212. show: false
  25213. },
  25214. // 坐标轴小标记
  25215. axisTick: {
  25216. // If tick is align with label when boundaryGap is true
  25217. alignWithLabel: false,
  25218. interval: 'auto'
  25219. },
  25220. // 坐标轴文本标签,详见axis.axisLabel
  25221. axisLabel: {
  25222. interval: 'auto'
  25223. }
  25224. }, defaultOption);
  25225. var valueAxis = zrUtil.merge({
  25226. // 数值起始和结束两端空白策略
  25227. boundaryGap: [0, 0],
  25228. // 最小值, 设置成 'dataMin' 则从数据中计算最小值
  25229. // min: null,
  25230. // 最大值,设置成 'dataMax' 则从数据中计算最大值
  25231. // max: null,
  25232. // Readonly prop, specifies start value of the range when using data zoom.
  25233. // rangeStart: null
  25234. // Readonly prop, specifies end value of the range when using data zoom.
  25235. // rangeEnd: null
  25236. // 脱离0值比例,放大聚焦到最终_min,_max区间
  25237. // scale: false,
  25238. // 分割段数,默认为5
  25239. splitNumber: 5
  25240. // Minimum interval
  25241. // minInterval: null
  25242. }, defaultOption);
  25243. // FIXME
  25244. var timeAxis = zrUtil.defaults({
  25245. scale: true,
  25246. min: 'dataMin',
  25247. max: 'dataMax'
  25248. }, valueAxis);
  25249. var logAxis = zrUtil.defaults({
  25250. scale: true,
  25251. logBase: 10
  25252. }, valueAxis);
  25253. module.exports = {
  25254. categoryAxis: categoryAxis,
  25255. valueAxis: valueAxis,
  25256. timeAxis: timeAxis,
  25257. logAxis: logAxis
  25258. };
  25259. /***/ },
  25260. /* 133 */
  25261. /***/ function(module, exports, __webpack_require__) {
  25262. 'use strict';
  25263. // TODO boundaryGap
  25264. __webpack_require__(130);
  25265. __webpack_require__(134);
  25266. /***/ },
  25267. /* 134 */
  25268. /***/ function(module, exports, __webpack_require__) {
  25269. var zrUtil = __webpack_require__(4);
  25270. var graphic = __webpack_require__(18);
  25271. var AxisBuilder = __webpack_require__(135);
  25272. var AxisView = __webpack_require__(136);
  25273. var cartesianAxisHelper = __webpack_require__(138);
  25274. var ifIgnoreOnTick = AxisBuilder.ifIgnoreOnTick;
  25275. var getInterval = AxisBuilder.getInterval;
  25276. var axisBuilderAttrs = [
  25277. 'axisLine', 'axisLabel', 'axisTick', 'axisName'
  25278. ];
  25279. var selfBuilderAttrs = [
  25280. 'splitArea', 'splitLine'
  25281. ];
  25282. // function getAlignWithLabel(model, axisModel) {
  25283. // var alignWithLabel = model.get('alignWithLabel');
  25284. // if (alignWithLabel === 'auto') {
  25285. // alignWithLabel = axisModel.get('axisTick.alignWithLabel');
  25286. // }
  25287. // return alignWithLabel;
  25288. // }
  25289. var CartesianAxisView = AxisView.extend({
  25290. type: 'cartesianAxis',
  25291. axisPointerClass: 'CartesianAxisPointer',
  25292. /**
  25293. * @override
  25294. */
  25295. render: function (axisModel, ecModel, api, payload) {
  25296. this.group.removeAll();
  25297. var oldAxisGroup = this._axisGroup;
  25298. this._axisGroup = new graphic.Group();
  25299. this.group.add(this._axisGroup);
  25300. if (!axisModel.get('show')) {
  25301. return;
  25302. }
  25303. var gridModel = axisModel.getCoordSysModel();
  25304. var layout = cartesianAxisHelper.layout(gridModel, axisModel);
  25305. var axisBuilder = new AxisBuilder(axisModel, layout);
  25306. zrUtil.each(axisBuilderAttrs, axisBuilder.add, axisBuilder);
  25307. this._axisGroup.add(axisBuilder.getGroup());
  25308. zrUtil.each(selfBuilderAttrs, function (name) {
  25309. if (axisModel.get(name + '.show')) {
  25310. this['_' + name](axisModel, gridModel, layout.labelInterval);
  25311. }
  25312. }, this);
  25313. graphic.groupTransition(oldAxisGroup, this._axisGroup, axisModel);
  25314. CartesianAxisView.superCall(this, 'render', axisModel, ecModel, api, payload);
  25315. },
  25316. /**
  25317. * @param {module:echarts/coord/cartesian/AxisModel} axisModel
  25318. * @param {module:echarts/coord/cartesian/GridModel} gridModel
  25319. * @param {number|Function} labelInterval
  25320. * @private
  25321. */
  25322. _splitLine: function (axisModel, gridModel, labelInterval) {
  25323. var axis = axisModel.axis;
  25324. if (axis.scale.isBlank()) {
  25325. return;
  25326. }
  25327. var splitLineModel = axisModel.getModel('splitLine');
  25328. var lineStyleModel = splitLineModel.getModel('lineStyle');
  25329. var lineColors = lineStyleModel.get('color');
  25330. var lineInterval = getInterval(splitLineModel, labelInterval);
  25331. lineColors = zrUtil.isArray(lineColors) ? lineColors : [lineColors];
  25332. var gridRect = gridModel.coordinateSystem.getRect();
  25333. var isHorizontal = axis.isHorizontal();
  25334. var lineCount = 0;
  25335. var ticksCoords = axis.getTicksCoords(
  25336. // splitLineModel.get('alignWithLabel')
  25337. );
  25338. var ticks = axis.scale.getTicks();
  25339. var p1 = [];
  25340. var p2 = [];
  25341. // Simple optimization
  25342. // Batching the lines if color are the same
  25343. var lineStyle = lineStyleModel.getLineStyle();
  25344. for (var i = 0; i < ticksCoords.length; i++) {
  25345. if (ifIgnoreOnTick(axis, i, lineInterval)) {
  25346. continue;
  25347. }
  25348. var tickCoord = axis.toGlobalCoord(ticksCoords[i]);
  25349. if (isHorizontal) {
  25350. p1[0] = tickCoord;
  25351. p1[1] = gridRect.y;
  25352. p2[0] = tickCoord;
  25353. p2[1] = gridRect.y + gridRect.height;
  25354. }
  25355. else {
  25356. p1[0] = gridRect.x;
  25357. p1[1] = tickCoord;
  25358. p2[0] = gridRect.x + gridRect.width;
  25359. p2[1] = tickCoord;
  25360. }
  25361. var colorIndex = (lineCount++) % lineColors.length;
  25362. this._axisGroup.add(new graphic.Line(graphic.subPixelOptimizeLine({
  25363. anid: 'line_' + ticks[i],
  25364. shape: {
  25365. x1: p1[0],
  25366. y1: p1[1],
  25367. x2: p2[0],
  25368. y2: p2[1]
  25369. },
  25370. style: zrUtil.defaults({
  25371. stroke: lineColors[colorIndex]
  25372. }, lineStyle),
  25373. silent: true
  25374. })));
  25375. }
  25376. },
  25377. /**
  25378. * @param {module:echarts/coord/cartesian/AxisModel} axisModel
  25379. * @param {module:echarts/coord/cartesian/GridModel} gridModel
  25380. * @param {number|Function} labelInterval
  25381. * @private
  25382. */
  25383. _splitArea: function (axisModel, gridModel, labelInterval) {
  25384. var axis = axisModel.axis;
  25385. if (axis.scale.isBlank()) {
  25386. return;
  25387. }
  25388. var splitAreaModel = axisModel.getModel('splitArea');
  25389. var areaStyleModel = splitAreaModel.getModel('areaStyle');
  25390. var areaColors = areaStyleModel.get('color');
  25391. var gridRect = gridModel.coordinateSystem.getRect();
  25392. var ticksCoords = axis.getTicksCoords(
  25393. // splitAreaModel.get('alignWithLabel')
  25394. );
  25395. var ticks = axis.scale.getTicks();
  25396. var prevX = axis.toGlobalCoord(ticksCoords[0]);
  25397. var prevY = axis.toGlobalCoord(ticksCoords[0]);
  25398. var count = 0;
  25399. var areaInterval = getInterval(splitAreaModel, labelInterval);
  25400. var areaStyle = areaStyleModel.getAreaStyle();
  25401. areaColors = zrUtil.isArray(areaColors) ? areaColors : [areaColors];
  25402. for (var i = 1; i < ticksCoords.length; i++) {
  25403. if (ifIgnoreOnTick(axis, i, areaInterval)) {
  25404. continue;
  25405. }
  25406. var tickCoord = axis.toGlobalCoord(ticksCoords[i]);
  25407. var x;
  25408. var y;
  25409. var width;
  25410. var height;
  25411. if (axis.isHorizontal()) {
  25412. x = prevX;
  25413. y = gridRect.y;
  25414. width = tickCoord - x;
  25415. height = gridRect.height;
  25416. }
  25417. else {
  25418. x = gridRect.x;
  25419. y = prevY;
  25420. width = gridRect.width;
  25421. height = tickCoord - y;
  25422. }
  25423. var colorIndex = (count++) % areaColors.length;
  25424. this._axisGroup.add(new graphic.Rect({
  25425. anid: 'area_' + ticks[i],
  25426. shape: {
  25427. x: x,
  25428. y: y,
  25429. width: width,
  25430. height: height
  25431. },
  25432. style: zrUtil.defaults({
  25433. fill: areaColors[colorIndex]
  25434. }, areaStyle),
  25435. silent: true
  25436. }));
  25437. prevX = x + width;
  25438. prevY = y + height;
  25439. }
  25440. }
  25441. });
  25442. CartesianAxisView.extend({
  25443. type: 'xAxis'
  25444. });
  25445. CartesianAxisView.extend({
  25446. type: 'yAxis'
  25447. });
  25448. /***/ },
  25449. /* 135 */
  25450. /***/ function(module, exports, __webpack_require__) {
  25451. var zrUtil = __webpack_require__(4);
  25452. var formatUtil = __webpack_require__(6);
  25453. var graphic = __webpack_require__(18);
  25454. var Model = __webpack_require__(12);
  25455. var numberUtil = __webpack_require__(7);
  25456. var remRadian = numberUtil.remRadian;
  25457. var isRadianAroundZero = numberUtil.isRadianAroundZero;
  25458. var vec2 = __webpack_require__(10);
  25459. var matrix = __webpack_require__(11);
  25460. var v2ApplyTransform = vec2.applyTransform;
  25461. var retrieve = zrUtil.retrieve;
  25462. var PI = Math.PI;
  25463. function makeAxisEventDataBase(axisModel) {
  25464. var eventData = {
  25465. componentType: axisModel.mainType
  25466. };
  25467. eventData[axisModel.mainType + 'Index'] = axisModel.componentIndex;
  25468. return eventData;
  25469. }
  25470. /**
  25471. * A final axis is translated and rotated from a "standard axis".
  25472. * So opt.position and opt.rotation is required.
  25473. *
  25474. * A standard axis is and axis from [0, 0] to [0, axisExtent[1]],
  25475. * for example: (0, 0) ------------> (0, 50)
  25476. *
  25477. * nameDirection or tickDirection or labelDirection is 1 means tick
  25478. * or label is below the standard axis, whereas is -1 means above
  25479. * the standard axis. labelOffset means offset between label and axis,
  25480. * which is useful when 'onZero', where axisLabel is in the grid and
  25481. * label in outside grid.
  25482. *
  25483. * Tips: like always,
  25484. * positive rotation represents anticlockwise, and negative rotation
  25485. * represents clockwise.
  25486. * The direction of position coordinate is the same as the direction
  25487. * of screen coordinate.
  25488. *
  25489. * Do not need to consider axis 'inverse', which is auto processed by
  25490. * axis extent.
  25491. *
  25492. * @param {module:zrender/container/Group} group
  25493. * @param {Object} axisModel
  25494. * @param {Object} opt Standard axis parameters.
  25495. * @param {Array.<number>} opt.position [x, y]
  25496. * @param {number} opt.rotation by radian
  25497. * @param {number} [opt.nameDirection=1] 1 or -1 Used when nameLocation is 'middle'.
  25498. * @param {number} [opt.tickDirection=1] 1 or -1
  25499. * @param {number} [opt.labelDirection=1] 1 or -1
  25500. * @param {number} [opt.labelOffset=0] Usefull when onZero.
  25501. * @param {string} [opt.axisLabelShow] default get from axisModel.
  25502. * @param {string} [opt.axisName] default get from axisModel.
  25503. * @param {number} [opt.axisNameAvailableWidth]
  25504. * @param {number} [opt.labelRotate] by degree, default get from axisModel.
  25505. * @param {number} [opt.labelInterval] Default label interval when label
  25506. * interval from model is null or 'auto'.
  25507. * @param {number} [opt.strokeContainThreshold] Default label interval when label
  25508. * @param {number} [opt.nameTruncateMaxWidth]
  25509. */
  25510. var AxisBuilder = function (axisModel, opt) {
  25511. /**
  25512. * @readOnly
  25513. */
  25514. this.opt = opt;
  25515. /**
  25516. * @readOnly
  25517. */
  25518. this.axisModel = axisModel;
  25519. // Default value
  25520. zrUtil.defaults(
  25521. opt,
  25522. {
  25523. labelOffset: 0,
  25524. nameDirection: 1,
  25525. tickDirection: 1,
  25526. labelDirection: 1,
  25527. silent: true
  25528. }
  25529. );
  25530. /**
  25531. * @readOnly
  25532. */
  25533. this.group = new graphic.Group();
  25534. // FIXME Not use a seperate text group?
  25535. var dumbGroup = new graphic.Group({
  25536. position: opt.position.slice(),
  25537. rotation: opt.rotation
  25538. });
  25539. // this.group.add(dumbGroup);
  25540. // this._dumbGroup = dumbGroup;
  25541. dumbGroup.updateTransform();
  25542. this._transform = dumbGroup.transform;
  25543. this._dumbGroup = dumbGroup;
  25544. };
  25545. AxisBuilder.prototype = {
  25546. constructor: AxisBuilder,
  25547. hasBuilder: function (name) {
  25548. return !!builders[name];
  25549. },
  25550. add: function (name) {
  25551. builders[name].call(this);
  25552. },
  25553. getGroup: function () {
  25554. return this.group;
  25555. }
  25556. };
  25557. var builders = {
  25558. /**
  25559. * @private
  25560. */
  25561. axisLine: function () {
  25562. var opt = this.opt;
  25563. var axisModel = this.axisModel;
  25564. if (!axisModel.get('axisLine.show')) {
  25565. return;
  25566. }
  25567. var extent = this.axisModel.axis.getExtent();
  25568. var matrix = this._transform;
  25569. var pt1 = [extent[0], 0];
  25570. var pt2 = [extent[1], 0];
  25571. if (matrix) {
  25572. v2ApplyTransform(pt1, pt1, matrix);
  25573. v2ApplyTransform(pt2, pt2, matrix);
  25574. }
  25575. this.group.add(new graphic.Line(graphic.subPixelOptimizeLine({
  25576. // Id for animation
  25577. anid: 'line',
  25578. shape: {
  25579. x1: pt1[0],
  25580. y1: pt1[1],
  25581. x2: pt2[0],
  25582. y2: pt2[1]
  25583. },
  25584. style: zrUtil.extend(
  25585. {lineCap: 'round'},
  25586. axisModel.getModel('axisLine.lineStyle').getLineStyle()
  25587. ),
  25588. strokeContainThreshold: opt.strokeContainThreshold || 5,
  25589. silent: true,
  25590. z2: 1
  25591. })));
  25592. },
  25593. /**
  25594. * @private
  25595. */
  25596. axisTick: function () {
  25597. var axisModel = this.axisModel;
  25598. var axis = axisModel.axis;
  25599. if (!axisModel.get('axisTick.show') || axis.scale.isBlank()) {
  25600. return;
  25601. }
  25602. var tickModel = axisModel.getModel('axisTick');
  25603. var opt = this.opt;
  25604. var lineStyleModel = tickModel.getModel('lineStyle');
  25605. var tickLen = tickModel.get('length');
  25606. var tickInterval = getInterval(tickModel, opt.labelInterval);
  25607. var ticksCoords = axis.getTicksCoords(tickModel.get('alignWithLabel'));
  25608. var ticks = axis.scale.getTicks();
  25609. var pt1 = [];
  25610. var pt2 = [];
  25611. var matrix = this._transform;
  25612. for (var i = 0; i < ticksCoords.length; i++) {
  25613. // Only ordinal scale support tick interval
  25614. if (ifIgnoreOnTick(axis, i, tickInterval)) {
  25615. continue;
  25616. }
  25617. var tickCoord = ticksCoords[i];
  25618. pt1[0] = tickCoord;
  25619. pt1[1] = 0;
  25620. pt2[0] = tickCoord;
  25621. pt2[1] = opt.tickDirection * tickLen;
  25622. if (matrix) {
  25623. v2ApplyTransform(pt1, pt1, matrix);
  25624. v2ApplyTransform(pt2, pt2, matrix);
  25625. }
  25626. // Tick line, Not use group transform to have better line draw
  25627. this.group.add(new graphic.Line(graphic.subPixelOptimizeLine({
  25628. // Id for animation
  25629. anid: 'tick_' + ticks[i],
  25630. shape: {
  25631. x1: pt1[0],
  25632. y1: pt1[1],
  25633. x2: pt2[0],
  25634. y2: pt2[1]
  25635. },
  25636. style: zrUtil.defaults(
  25637. lineStyleModel.getLineStyle(),
  25638. {
  25639. stroke: axisModel.get('axisLine.lineStyle.color')
  25640. }
  25641. ),
  25642. z2: 2,
  25643. silent: true
  25644. })));
  25645. }
  25646. },
  25647. /**
  25648. * @param {module:echarts/coord/cartesian/AxisModel} axisModel
  25649. * @param {module:echarts/coord/cartesian/GridModel} gridModel
  25650. * @private
  25651. */
  25652. axisLabel: function () {
  25653. var opt = this.opt;
  25654. var axisModel = this.axisModel;
  25655. var axis = axisModel.axis;
  25656. var show = retrieve(opt.axisLabelShow, axisModel.get('axisLabel.show'));
  25657. if (!show || axis.scale.isBlank()) {
  25658. return;
  25659. }
  25660. var labelModel = axisModel.getModel('axisLabel');
  25661. var textStyleModel = labelModel.getModel('textStyle');
  25662. var labelMargin = labelModel.get('margin');
  25663. var ticks = axis.scale.getTicks();
  25664. var labels = axisModel.getFormattedLabels();
  25665. // Special label rotate.
  25666. var labelRotation = (
  25667. retrieve(opt.labelRotate, labelModel.get('rotate')) || 0
  25668. ) * PI / 180;
  25669. var labelLayout = innerTextLayout(opt.rotation, labelRotation, opt.labelDirection);
  25670. var categoryData = axisModel.get('data');
  25671. var textEls = [];
  25672. var silent = isSilent(axisModel);
  25673. var triggerEvent = axisModel.get('triggerEvent');
  25674. zrUtil.each(ticks, function (tickVal, index) {
  25675. if (ifIgnoreOnTick(axis, index, opt.labelInterval)) {
  25676. return;
  25677. }
  25678. var itemTextStyleModel = textStyleModel;
  25679. if (categoryData && categoryData[tickVal] && categoryData[tickVal].textStyle) {
  25680. itemTextStyleModel = new Model(
  25681. categoryData[tickVal].textStyle, textStyleModel, axisModel.ecModel
  25682. );
  25683. }
  25684. var textColor = itemTextStyleModel.getTextColor()
  25685. || axisModel.get('axisLine.lineStyle.color');
  25686. var tickCoord = axis.dataToCoord(tickVal);
  25687. var pos = [
  25688. tickCoord,
  25689. opt.labelOffset + opt.labelDirection * labelMargin
  25690. ];
  25691. var labelStr = axis.scale.getLabel(tickVal);
  25692. var textEl = new graphic.Text({
  25693. // Id for animation
  25694. anid: 'label_' + tickVal,
  25695. style: {
  25696. text: labels[index],
  25697. textAlign: itemTextStyleModel.get('align', true) || labelLayout.textAlign,
  25698. textVerticalAlign: itemTextStyleModel.get('baseline', true) || labelLayout.textVerticalAlign,
  25699. textFont: itemTextStyleModel.getFont(),
  25700. fill: typeof textColor === 'function'
  25701. ? textColor(
  25702. // (1) In category axis with data zoom, tick is not the original
  25703. // index of axis.data. So tick should not be exposed to user
  25704. // in category axis.
  25705. // (2) Compatible with previous version, which always returns labelStr.
  25706. // But in interval scale labelStr is like '223,445', which maked
  25707. // user repalce ','. So we modify it to return original val but remain
  25708. // it as 'string' to avoid error in replacing.
  25709. axis.type === 'category' ? labelStr : axis.type === 'value' ? tickVal + '' : tickVal,
  25710. index
  25711. )
  25712. : textColor
  25713. },
  25714. position: pos,
  25715. rotation: labelLayout.rotation,
  25716. silent: silent,
  25717. z2: 10
  25718. });
  25719. // Pack data for mouse event
  25720. if (triggerEvent) {
  25721. textEl.eventData = makeAxisEventDataBase(axisModel);
  25722. textEl.eventData.targetType = 'axisLabel';
  25723. textEl.eventData.value = labelStr;
  25724. }
  25725. // FIXME
  25726. this._dumbGroup.add(textEl);
  25727. textEl.updateTransform();
  25728. textEls.push(textEl);
  25729. this.group.add(textEl);
  25730. textEl.decomposeTransform();
  25731. }, this);
  25732. fixMinMaxLabelShow(axisModel, textEls);
  25733. },
  25734. /**
  25735. * @private
  25736. */
  25737. axisName: function () {
  25738. var opt = this.opt;
  25739. var axisModel = this.axisModel;
  25740. var name = retrieve(opt.axisName, axisModel.get('name'));
  25741. if (!name) {
  25742. return;
  25743. }
  25744. var nameLocation = axisModel.get('nameLocation');
  25745. var nameDirection = opt.nameDirection;
  25746. var textStyleModel = axisModel.getModel('nameTextStyle');
  25747. var gap = axisModel.get('nameGap') || 0;
  25748. var extent = this.axisModel.axis.getExtent();
  25749. var gapSignal = extent[0] > extent[1] ? -1 : 1;
  25750. var pos = [
  25751. nameLocation === 'start'
  25752. ? extent[0] - gapSignal * gap
  25753. : nameLocation === 'end'
  25754. ? extent[1] + gapSignal * gap
  25755. : (extent[0] + extent[1]) / 2, // 'middle'
  25756. // Reuse labelOffset.
  25757. nameLocation === 'middle' ? opt.labelOffset + nameDirection * gap : 0
  25758. ];
  25759. var labelLayout;
  25760. var nameRotation = axisModel.get('nameRotate');
  25761. if (nameRotation != null) {
  25762. nameRotation = nameRotation * PI / 180; // To radian.
  25763. }
  25764. var axisNameAvailableWidth;
  25765. if (nameLocation === 'middle') {
  25766. labelLayout = innerTextLayout(
  25767. opt.rotation,
  25768. nameRotation != null ? nameRotation : opt.rotation, // Adapt to axis.
  25769. nameDirection
  25770. );
  25771. }
  25772. else {
  25773. labelLayout = endTextLayout(
  25774. opt, nameLocation, nameRotation || 0, extent
  25775. );
  25776. axisNameAvailableWidth = opt.axisNameAvailableWidth;
  25777. if (axisNameAvailableWidth != null) {
  25778. axisNameAvailableWidth = Math.abs(
  25779. axisNameAvailableWidth / Math.sin(labelLayout.rotation)
  25780. );
  25781. !isFinite(axisNameAvailableWidth) && (axisNameAvailableWidth = null);
  25782. }
  25783. }
  25784. var textFont = textStyleModel.getFont();
  25785. var truncateOpt = axisModel.get('nameTruncate', true) || {};
  25786. var ellipsis = truncateOpt.ellipsis;
  25787. var maxWidth = retrieve(
  25788. opt.nameTruncateMaxWidth, truncateOpt.maxWidth, axisNameAvailableWidth
  25789. );
  25790. var truncatedText = (ellipsis != null && maxWidth != null)
  25791. ? formatUtil.truncateText(
  25792. name, maxWidth, textFont, ellipsis,
  25793. {minChar: 2, placeholder: truncateOpt.placeholder}
  25794. )
  25795. : name;
  25796. var tooltipOpt = axisModel.get('tooltip', true);
  25797. var mainType = axisModel.mainType;
  25798. var formatterParams = {
  25799. componentType: mainType,
  25800. name: name,
  25801. $vars: ['name']
  25802. };
  25803. formatterParams[mainType + 'Index'] = axisModel.componentIndex;
  25804. var textEl = new graphic.Text({
  25805. // Id for animation
  25806. anid: 'name',
  25807. __fullText: name,
  25808. __truncatedText: truncatedText,
  25809. style: {
  25810. text: truncatedText,
  25811. textFont: textFont,
  25812. fill: textStyleModel.getTextColor()
  25813. || axisModel.get('axisLine.lineStyle.color'),
  25814. textAlign: labelLayout.textAlign,
  25815. textVerticalAlign: labelLayout.textVerticalAlign
  25816. },
  25817. position: pos,
  25818. rotation: labelLayout.rotation,
  25819. silent: isSilent(axisModel),
  25820. z2: 1,
  25821. tooltip: (tooltipOpt && tooltipOpt.show)
  25822. ? zrUtil.extend({
  25823. content: name,
  25824. formatter: function () {
  25825. return name;
  25826. },
  25827. formatterParams: formatterParams
  25828. }, tooltipOpt)
  25829. : null
  25830. });
  25831. if (axisModel.get('triggerEvent')) {
  25832. textEl.eventData = makeAxisEventDataBase(axisModel);
  25833. textEl.eventData.targetType = 'axisName';
  25834. textEl.eventData.name = name;
  25835. }
  25836. // FIXME
  25837. this._dumbGroup.add(textEl);
  25838. textEl.updateTransform();
  25839. this.group.add(textEl);
  25840. textEl.decomposeTransform();
  25841. }
  25842. };
  25843. /**
  25844. * @public
  25845. * @static
  25846. * @param {Object} opt
  25847. * @param {number} axisRotation in radian
  25848. * @param {number} textRotation in radian
  25849. * @param {number} direction
  25850. * @return {Object} {
  25851. * rotation, // according to axis
  25852. * textAlign,
  25853. * textVerticalAlign
  25854. * }
  25855. */
  25856. var innerTextLayout = AxisBuilder.innerTextLayout = function (axisRotation, textRotation, direction) {
  25857. var rotationDiff = remRadian(textRotation - axisRotation);
  25858. var textAlign;
  25859. var textVerticalAlign;
  25860. if (isRadianAroundZero(rotationDiff)) { // Label is parallel with axis line.
  25861. textVerticalAlign = direction > 0 ? 'top' : 'bottom';
  25862. textAlign = 'center';
  25863. }
  25864. else if (isRadianAroundZero(rotationDiff - PI)) { // Label is inverse parallel with axis line.
  25865. textVerticalAlign = direction > 0 ? 'bottom' : 'top';
  25866. textAlign = 'center';
  25867. }
  25868. else {
  25869. textVerticalAlign = 'middle';
  25870. if (rotationDiff > 0 && rotationDiff < PI) {
  25871. textAlign = direction > 0 ? 'right' : 'left';
  25872. }
  25873. else {
  25874. textAlign = direction > 0 ? 'left' : 'right';
  25875. }
  25876. }
  25877. return {
  25878. rotation: rotationDiff,
  25879. textAlign: textAlign,
  25880. textVerticalAlign: textVerticalAlign
  25881. };
  25882. };
  25883. function endTextLayout(opt, textPosition, textRotate, extent) {
  25884. var rotationDiff = remRadian(textRotate - opt.rotation);
  25885. var textAlign;
  25886. var textVerticalAlign;
  25887. var inverse = extent[0] > extent[1];
  25888. var onLeft = (textPosition === 'start' && !inverse)
  25889. || (textPosition !== 'start' && inverse);
  25890. if (isRadianAroundZero(rotationDiff - PI / 2)) {
  25891. textVerticalAlign = onLeft ? 'bottom' : 'top';
  25892. textAlign = 'center';
  25893. }
  25894. else if (isRadianAroundZero(rotationDiff - PI * 1.5)) {
  25895. textVerticalAlign = onLeft ? 'top' : 'bottom';
  25896. textAlign = 'center';
  25897. }
  25898. else {
  25899. textVerticalAlign = 'middle';
  25900. if (rotationDiff < PI * 1.5 && rotationDiff > PI / 2) {
  25901. textAlign = onLeft ? 'left' : 'right';
  25902. }
  25903. else {
  25904. textAlign = onLeft ? 'right' : 'left';
  25905. }
  25906. }
  25907. return {
  25908. rotation: rotationDiff,
  25909. textAlign: textAlign,
  25910. textVerticalAlign: textVerticalAlign
  25911. };
  25912. }
  25913. function isSilent(axisModel) {
  25914. var tooltipOpt = axisModel.get('tooltip');
  25915. return axisModel.get('silent')
  25916. // Consider mouse cursor, add these restrictions.
  25917. || !(
  25918. axisModel.get('triggerEvent') || (tooltipOpt && tooltipOpt.show)
  25919. );
  25920. }
  25921. function fixMinMaxLabelShow(axisModel, textEls) {
  25922. // If min or max are user set, we need to check
  25923. // If the tick on min(max) are overlap on their neighbour tick
  25924. // If they are overlapped, we need to hide the min(max) tick label
  25925. var showMinLabel = axisModel.get('axisLabel.showMinLabel');
  25926. var showMaxLabel = axisModel.get('axisLabel.showMaxLabel');
  25927. var firstLabel = textEls[0];
  25928. var nextLabel = textEls[1];
  25929. var lastLabel = textEls[textEls.length - 1];
  25930. var prevLabel = textEls[textEls.length - 2];
  25931. if (showMinLabel === false) {
  25932. firstLabel.ignore = true;
  25933. }
  25934. else if (axisModel.getMin() != null && isTwoLabelOverlapped(firstLabel, nextLabel)) {
  25935. showMinLabel ? (nextLabel.ignore = true) : (firstLabel.ignore = true);
  25936. }
  25937. if (showMaxLabel === false) {
  25938. lastLabel.ignore = true;
  25939. }
  25940. else if (axisModel.getMax() != null && isTwoLabelOverlapped(prevLabel, lastLabel)) {
  25941. showMaxLabel ? (prevLabel.ignore = true) : (lastLabel.ignore = true);
  25942. }
  25943. }
  25944. function isTwoLabelOverlapped(current, next, labelLayout) {
  25945. // current and next has the same rotation.
  25946. var firstRect = current && current.getBoundingRect().clone();
  25947. var nextRect = next && next.getBoundingRect().clone();
  25948. if (!firstRect || !nextRect) {
  25949. return;
  25950. }
  25951. // When checking intersect of two rotated labels, we use mRotationBack
  25952. // to avoid that boundingRect is enlarge when using `boundingRect.applyTransform`.
  25953. var mRotationBack = matrix.identity([]);
  25954. matrix.rotate(mRotationBack, mRotationBack, -current.rotation);
  25955. firstRect.applyTransform(matrix.mul([], mRotationBack, current.getLocalTransform()));
  25956. nextRect.applyTransform(matrix.mul([], mRotationBack, next.getLocalTransform()));
  25957. return firstRect.intersect(nextRect);
  25958. }
  25959. /**
  25960. * @static
  25961. */
  25962. var ifIgnoreOnTick = AxisBuilder.ifIgnoreOnTick = function (axis, i, interval) {
  25963. var rawTick;
  25964. var scale = axis.scale;
  25965. return scale.type === 'ordinal'
  25966. && (
  25967. typeof interval === 'function'
  25968. ? (
  25969. rawTick = scale.getTicks()[i],
  25970. !interval(rawTick, scale.getLabel(rawTick))
  25971. )
  25972. : i % (interval + 1)
  25973. );
  25974. };
  25975. /**
  25976. * @static
  25977. */
  25978. var getInterval = AxisBuilder.getInterval = function (model, labelInterval) {
  25979. var interval = model.get('interval');
  25980. if (interval == null || interval == 'auto') {
  25981. interval = labelInterval;
  25982. }
  25983. return interval;
  25984. };
  25985. module.exports = AxisBuilder;
  25986. /***/ },
  25987. /* 136 */
  25988. /***/ function(module, exports, __webpack_require__) {
  25989. var axisPointerModelHelper = __webpack_require__(137);
  25990. /**
  25991. * Base class of AxisView.
  25992. */
  25993. var AxisView = __webpack_require__(1).extendComponentView({
  25994. type: 'axis',
  25995. /**
  25996. * @private
  25997. */
  25998. _axisPointer: null,
  25999. /**
  26000. * @protected
  26001. * @type {string}
  26002. */
  26003. axisPointerClass: null,
  26004. /**
  26005. * @override
  26006. */
  26007. render: function (axisModel, ecModel, api, payload) {
  26008. // FIXME
  26009. // This process should proformed after coordinate systems updated
  26010. // (axis scale updated), and should be performed each time update.
  26011. // So put it here temporarily, although it is not appropriate to
  26012. // put a model-writing procedure in `view`.
  26013. this.axisPointerClass && axisPointerModelHelper.fixValue(axisModel);
  26014. AxisView.superApply(this, 'render', arguments);
  26015. updateAxisPointer(this, axisModel, ecModel, api, payload, true);
  26016. },
  26017. /**
  26018. * Action handler.
  26019. * @public
  26020. * @param {module:echarts/coord/cartesian/AxisModel} axisModel
  26021. * @param {module:echarts/model/Global} ecModel
  26022. * @param {module:echarts/ExtensionAPI} api
  26023. * @param {Object} payload
  26024. */
  26025. updateAxisPointer: function (axisModel, ecModel, api, payload, force) {
  26026. updateAxisPointer(this, axisModel, ecModel, api, payload, false);
  26027. },
  26028. /**
  26029. * @override
  26030. */
  26031. remove: function (ecModel, api) {
  26032. var axisPointer = this._axisPointer;
  26033. axisPointer && axisPointer.remove(api);
  26034. AxisView.superApply(this, 'remove', arguments);
  26035. },
  26036. /**
  26037. * @override
  26038. */
  26039. dispose: function (ecModel, api) {
  26040. disposeAxisPointer(this, api);
  26041. AxisView.superApply(this, 'dispose', arguments);
  26042. }
  26043. });
  26044. function updateAxisPointer(axisView, axisModel, ecModel, api, payload, forceRender) {
  26045. var Clazz = AxisView.getAxisPointerClass(axisView.axisPointerClass);
  26046. if (!Clazz) {
  26047. return;
  26048. }
  26049. var axisPointerModel = axisPointerModelHelper.getAxisPointerModel(axisModel);
  26050. axisPointerModel
  26051. ? (axisView._axisPointer || (axisView._axisPointer = new Clazz()))
  26052. .render(axisModel, axisPointerModel, api, forceRender)
  26053. : disposeAxisPointer(axisView, api);
  26054. }
  26055. function disposeAxisPointer(axisView, ecModel, api) {
  26056. var axisPointer = axisView._axisPointer;
  26057. axisPointer && axisPointer.dispose(ecModel, api);
  26058. axisView._axisPointer = null;
  26059. }
  26060. var axisPointerClazz = [];
  26061. AxisView.registerAxisPointerClass = function (type, clazz) {
  26062. if (true) {
  26063. if (axisPointerClazz[type]) {
  26064. throw new Error('axisPointer ' + type + ' exists');
  26065. }
  26066. }
  26067. axisPointerClazz[type] = clazz;
  26068. };
  26069. AxisView.getAxisPointerClass = function (type) {
  26070. return type && axisPointerClazz[type];
  26071. };
  26072. module.exports = AxisView;
  26073. /***/ },
  26074. /* 137 */
  26075. /***/ function(module, exports, __webpack_require__) {
  26076. var zrUtil = __webpack_require__(4);
  26077. var Model = __webpack_require__(12);
  26078. var each = zrUtil.each;
  26079. var curry = zrUtil.curry;
  26080. var helper = {};
  26081. // Build axisPointerModel, mergin tooltip.axisPointer model for each axis.
  26082. // allAxesInfo should be updated when setOption performed.
  26083. helper.collect = function (ecModel, api) {
  26084. var result = {
  26085. /**
  26086. * key: makeKey(axis.model)
  26087. * value: {
  26088. * axis,
  26089. * coordSys,
  26090. * axisPointerModel,
  26091. * triggerTooltip,
  26092. * involveSeries,
  26093. * snap,
  26094. * seriesModels,
  26095. * seriesDataCount
  26096. * }
  26097. */
  26098. axesInfo: {},
  26099. seriesInvolved: false,
  26100. /**
  26101. * key: makeKey(coordSys.model)
  26102. * value: Object: key makeKey(axis.model), value: axisInfo
  26103. */
  26104. coordSysAxesInfo: {},
  26105. coordSysMap: {}
  26106. };
  26107. collectAxesInfo(result, ecModel, api);
  26108. // Check seriesInvolved for performance, in case too many series in some chart.
  26109. result.seriesInvolved && collectSeriesInfo(result, ecModel);
  26110. return result;
  26111. };
  26112. function collectAxesInfo(result, ecModel, api) {
  26113. var globalTooltipModel = ecModel.getComponent('tooltip');
  26114. var globalAxisPointerModel = ecModel.getComponent('axisPointer');
  26115. // links can only be set on global.
  26116. var linksOption = globalAxisPointerModel.get('link', true) || [];
  26117. var linkGroups = [];
  26118. // Collect axes info.
  26119. each(api.getCoordinateSystems(), function (coordSys) {
  26120. // Some coordinate system do not support axes, like geo.
  26121. if (!coordSys.axisPointerEnabled) {
  26122. return;
  26123. }
  26124. var coordSysKey = makeKey(coordSys.model);
  26125. var axesInfoInCoordSys = result.coordSysAxesInfo[coordSysKey] = {};
  26126. result.coordSysMap[coordSysKey] = coordSys;
  26127. // Set tooltip (like 'cross') is a convienent way to show axisPointer
  26128. // for user. So we enable seting tooltip on coordSys model.
  26129. var coordSysModel = coordSys.model;
  26130. var baseTooltipModel = coordSysModel.getModel('tooltip', globalTooltipModel);
  26131. each(coordSys.getAxes(), curry(saveTooltipAxisInfo, false, null));
  26132. // If axis tooltip used, choose tooltip axis for each coordSys.
  26133. // Notice this case: coordSys is `grid` but not `cartesian2D` here.
  26134. if (coordSys.getTooltipAxes
  26135. && globalTooltipModel
  26136. // If tooltip.showContent is set as false, tooltip will not
  26137. // show but axisPointer will show as normal.
  26138. && baseTooltipModel.get('show')
  26139. ) {
  26140. // Compatible with previous logic. But series.tooltip.trigger: 'axis'
  26141. // or series.data[n].tooltip.trigger: 'axis' are not support any more.
  26142. var triggerAxis = baseTooltipModel.get('trigger') === 'axis';
  26143. var cross = baseTooltipModel.get('axisPointer.type') === 'cross';
  26144. var tooltipAxes = coordSys.getTooltipAxes(baseTooltipModel.get('axisPointer.axis'));
  26145. if (triggerAxis || cross) {
  26146. each(tooltipAxes.baseAxes, curry(
  26147. saveTooltipAxisInfo, cross ? 'cross' : true, triggerAxis
  26148. ));
  26149. }
  26150. if (cross) {
  26151. each(tooltipAxes.otherAxes, curry(saveTooltipAxisInfo, 'cross', false));
  26152. }
  26153. }
  26154. // fromTooltip: true | false | 'cross'
  26155. // triggerTooltip: true | false | null
  26156. function saveTooltipAxisInfo(fromTooltip, triggerTooltip, axis) {
  26157. var axisPointerModel = axis.model.getModel('axisPointer', globalAxisPointerModel);
  26158. var axisPointerShow = axisPointerModel.get('show');
  26159. if (!axisPointerShow || (
  26160. axisPointerShow === 'auto'
  26161. && !fromTooltip
  26162. && !isHandleTrigger(axisPointerModel)
  26163. )) {
  26164. return;
  26165. }
  26166. if (triggerTooltip == null) {
  26167. triggerTooltip = axisPointerModel.get('triggerTooltip');
  26168. }
  26169. axisPointerModel = fromTooltip
  26170. ? makeAxisPointerModel(
  26171. axis, baseTooltipModel, globalAxisPointerModel, ecModel,
  26172. fromTooltip, triggerTooltip
  26173. )
  26174. : axisPointerModel;
  26175. var snap = axisPointerModel.get('snap');
  26176. var key = makeKey(axis.model);
  26177. var involveSeries = triggerTooltip || snap || axis.type === 'category';
  26178. // If result.axesInfo[key] exist, override it (tooltip has higher priority).
  26179. var axisInfo = result.axesInfo[key] = {
  26180. key: key,
  26181. axis: axis,
  26182. coordSys: coordSys,
  26183. axisPointerModel: axisPointerModel,
  26184. triggerTooltip: triggerTooltip,
  26185. involveSeries: involveSeries,
  26186. snap: snap,
  26187. useHandle: isHandleTrigger(axisPointerModel),
  26188. seriesModels: []
  26189. };
  26190. axesInfoInCoordSys[key] = axisInfo;
  26191. result.seriesInvolved |= involveSeries;
  26192. var groupIndex = getLinkGroupIndex(linksOption, axis);
  26193. if (groupIndex != null) {
  26194. var linkGroup = linkGroups[groupIndex] || (linkGroups[groupIndex] = {axesInfo: {}});
  26195. linkGroup.axesInfo[key] = axisInfo;
  26196. linkGroup.mapper = linksOption[groupIndex].mapper;
  26197. axisInfo.linkGroup = linkGroup;
  26198. }
  26199. }
  26200. });
  26201. }
  26202. function makeAxisPointerModel(
  26203. axis, baseTooltipModel, globalAxisPointerModel, ecModel, fromTooltip, triggerTooltip
  26204. ) {
  26205. var tooltipAxisPointerModel = baseTooltipModel.getModel('axisPointer');
  26206. var volatileOption = {};
  26207. each(
  26208. [
  26209. 'type', 'snap', 'lineStyle', 'shadowStyle', 'label',
  26210. 'animation', 'animationDurationUpdate', 'animationEasingUpdate', 'z'
  26211. ],
  26212. function (field) {
  26213. volatileOption[field] = zrUtil.clone(tooltipAxisPointerModel.get(field));
  26214. }
  26215. );
  26216. // category axis do not auto snap, otherwise some tick that do not
  26217. // has value can not be hovered. value/time/log axis default snap if
  26218. // triggered from tooltip and trigger tooltip.
  26219. volatileOption.snap = axis.type !== 'category' && !!triggerTooltip;
  26220. // Compatibel with previous behavior, tooltip axis do not show label by default.
  26221. // Only these properties can be overrided from tooltip to axisPointer.
  26222. if (tooltipAxisPointerModel.get('type') === 'cross') {
  26223. volatileOption.type = 'line';
  26224. }
  26225. var labelOption = volatileOption.label || (volatileOption.label = {});
  26226. // Follow the convention, do not show label when triggered by tooltip by default.
  26227. labelOption.show == null && (labelOption.show = false);
  26228. if (fromTooltip === 'cross') {
  26229. // When 'cross', both axes show labels.
  26230. labelOption.show = true;
  26231. // If triggerTooltip, this is a base axis, which should better not use cross style
  26232. // (cross style is dashed by default)
  26233. if (!triggerTooltip) {
  26234. var crossStyle = volatileOption.lineStyle = tooltipAxisPointerModel.get('crossStyle');
  26235. crossStyle && zrUtil.defaults(
  26236. labelOption.textStyle || (labelOption.textStyle = {}),
  26237. crossStyle.textStyle
  26238. );
  26239. }
  26240. }
  26241. return axis.model.getModel(
  26242. 'axisPointer',
  26243. new Model(volatileOption, globalAxisPointerModel, ecModel)
  26244. );
  26245. }
  26246. function collectSeriesInfo(result, ecModel) {
  26247. // Prepare data for axis trigger
  26248. ecModel.eachSeries(function (seriesModel) {
  26249. // Notice this case: this coordSys is `cartesian2D` but not `grid`.
  26250. var coordSys = seriesModel.coordinateSystem;
  26251. var seriesTooltipTrigger = seriesModel.get('tooltip.trigger', true);
  26252. if (!coordSys
  26253. || seriesTooltipTrigger === 'none'
  26254. || seriesTooltipTrigger === false
  26255. || seriesTooltipTrigger === 'item'
  26256. || seriesModel.get('axisPointer.show', true) === false
  26257. ) {
  26258. return;
  26259. }
  26260. each(result.coordSysAxesInfo[makeKey(coordSys.model)], function (axisInfo) {
  26261. var axis = axisInfo.axis;
  26262. if (coordSys.getAxis(axis.dim) === axis) {
  26263. axisInfo.seriesModels.push(seriesModel);
  26264. axisInfo.seriesDataCount == null && (axisInfo.seriesDataCount = 0);
  26265. axisInfo.seriesDataCount += seriesModel.getData().count();
  26266. }
  26267. });
  26268. }, this);
  26269. }
  26270. /**
  26271. * For example:
  26272. * {
  26273. * axisPointer: {
  26274. * links: [{
  26275. * xAxisIndex: [2, 4],
  26276. * yAxisIndex: 'all'
  26277. * }, {
  26278. * xAxisId: ['a5', 'a7'],
  26279. * xAxisName: 'xxx'
  26280. * }]
  26281. * }
  26282. * }
  26283. */
  26284. function getLinkGroupIndex(linksOption, axis) {
  26285. var axisModel = axis.model;
  26286. var dim = axis.dim;
  26287. for (var i = 0; i < linksOption.length; i++) {
  26288. var linkOption = linksOption[i] || {};
  26289. if (checkPropInLink(linkOption[dim + 'AxisId'], axisModel.id)
  26290. || checkPropInLink(linkOption[dim + 'AxisIndex'], axisModel.componentIndex)
  26291. || checkPropInLink(linkOption[dim + 'AxisName'], axisModel.name)
  26292. ) {
  26293. return i;
  26294. }
  26295. }
  26296. }
  26297. function checkPropInLink(linkPropValue, axisPropValue) {
  26298. return linkPropValue === 'all'
  26299. || (zrUtil.isArray(linkPropValue) && zrUtil.indexOf(linkPropValue, axisPropValue) >= 0)
  26300. || linkPropValue === axisPropValue;
  26301. }
  26302. helper.fixValue = function (axisModel) {
  26303. var axisInfo = helper.getAxisInfo(axisModel);
  26304. if (!axisInfo) {
  26305. return;
  26306. }
  26307. var axisPointerModel = axisInfo.axisPointerModel;
  26308. var scale = axisInfo.axis.scale;
  26309. var option = axisPointerModel.option;
  26310. var status = axisPointerModel.get('status');
  26311. var value = axisPointerModel.get('value');
  26312. // Parse init value for category and time axis.
  26313. if (value != null) {
  26314. value = scale.parse(value);
  26315. }
  26316. var useHandle = isHandleTrigger(axisPointerModel);
  26317. // If `handle` used, `axisPointer` will always be displayed, so value
  26318. // and status should be initialized.
  26319. if (status == null) {
  26320. option.status = useHandle ? 'show' : 'hide';
  26321. }
  26322. var extent = scale.getExtent().slice();
  26323. extent[0] > extent[1] && extent.reverse();
  26324. if (// Pick a value on axis when initializing.
  26325. value == null
  26326. // If both `handle` and `dataZoom` are used, value may be out of axis extent,
  26327. // where we should re-pick a value to keep `handle` displaying normally.
  26328. || value > extent[1]
  26329. ) {
  26330. // Make handle displayed on the end of the axis when init, which looks better.
  26331. value = extent[1];
  26332. }
  26333. if (value < extent[0]) {
  26334. value = extent[0];
  26335. }
  26336. option.value = value;
  26337. if (useHandle) {
  26338. option.status = axisInfo.axis.scale.isBlank() ? 'hide' : 'show';
  26339. }
  26340. };
  26341. helper.getAxisInfo = function (axisModel) {
  26342. var coordSysAxesInfo = (axisModel.ecModel.getComponent('axisPointer') || {}).coordSysAxesInfo;
  26343. return coordSysAxesInfo && coordSysAxesInfo.axesInfo[makeKey(axisModel)];
  26344. };
  26345. helper.getAxisPointerModel = function (axisModel) {
  26346. var axisInfo = helper.getAxisInfo(axisModel);
  26347. return axisInfo && axisInfo.axisPointerModel;
  26348. };
  26349. function isHandleTrigger(axisPointerModel) {
  26350. return !!axisPointerModel.get('handle.show');
  26351. }
  26352. /**
  26353. * @param {module:echarts/model/Model} model
  26354. * @return {string} unique key
  26355. */
  26356. var makeKey = helper.makeKey = function (model) {
  26357. return model.type + '||' + model.id;
  26358. };
  26359. module.exports = helper;
  26360. /***/ },
  26361. /* 138 */
  26362. /***/ function(module, exports, __webpack_require__) {
  26363. var zrUtil = __webpack_require__(4);
  26364. var helper = {};
  26365. /**
  26366. * @param {Object} opt {labelInside}
  26367. * @return {Object} {
  26368. * position, rotation, labelDirection, labelOffset,
  26369. * tickDirection, labelRotate, labelInterval, z2
  26370. * }
  26371. */
  26372. helper.layout = function (gridModel, axisModel, opt) {
  26373. opt = opt || {};
  26374. var grid = gridModel.coordinateSystem;
  26375. var axis = axisModel.axis;
  26376. var layout = {};
  26377. var rawAxisPosition = axis.position;
  26378. var axisPosition = axis.onZero ? 'onZero' : rawAxisPosition;
  26379. var axisDim = axis.dim;
  26380. // [left, right, top, bottom]
  26381. var rect = grid.getRect();
  26382. var rectBound = [rect.x, rect.x + rect.width, rect.y, rect.y + rect.height];
  26383. var axisOffset = axisModel.get('offset') || 0;
  26384. var posMap = {
  26385. x: { top: rectBound[2] - axisOffset, bottom: rectBound[3] + axisOffset },
  26386. y: { left: rectBound[0] - axisOffset, right: rectBound[1] + axisOffset }
  26387. };
  26388. posMap.x.onZero = Math.max(Math.min(getZero('y'), posMap.x.bottom), posMap.x.top);
  26389. posMap.y.onZero = Math.max(Math.min(getZero('x'), posMap.y.right), posMap.y.left);
  26390. function getZero(dim, val) {
  26391. var theAxis = grid.getAxis(dim);
  26392. return theAxis.toGlobalCoord(theAxis.dataToCoord(0));
  26393. }
  26394. // Axis position
  26395. layout.position = [
  26396. axisDim === 'y' ? posMap.y[axisPosition] : rectBound[0],
  26397. axisDim === 'x' ? posMap.x[axisPosition] : rectBound[3]
  26398. ];
  26399. // Axis rotation
  26400. layout.rotation = Math.PI / 2 * (axisDim === 'x' ? 0 : 1);
  26401. // Tick and label direction, x y is axisDim
  26402. var dirMap = {top: -1, bottom: 1, left: -1, right: 1};
  26403. layout.labelDirection = layout.tickDirection = layout.nameDirection = dirMap[rawAxisPosition];
  26404. layout.labelOffset = axis.onZero ? posMap[axisDim][rawAxisPosition] - posMap[axisDim].onZero : 0;
  26405. if (axisModel.get('axisTick.inside')) {
  26406. layout.tickDirection = -layout.tickDirection;
  26407. }
  26408. if (zrUtil.retrieve(opt.labelInside, axisModel.get('axisLabel.inside'))) {
  26409. layout.labelDirection = -layout.labelDirection;
  26410. }
  26411. // Special label rotation
  26412. var labelRotate = axisModel.get('axisLabel.rotate');
  26413. layout.labelRotate = axisPosition === 'top' ? -labelRotate : labelRotate;
  26414. // label interval when auto mode.
  26415. layout.labelInterval = axis.getLabelInterval();
  26416. // Over splitLine and splitArea
  26417. layout.z2 = 1;
  26418. return layout;
  26419. };
  26420. module.exports = helper;
  26421. /***/ },
  26422. /* 139 */
  26423. /***/ function(module, exports, __webpack_require__) {
  26424. var zrUtil = __webpack_require__(4);
  26425. __webpack_require__(125);
  26426. __webpack_require__(140);
  26427. __webpack_require__(142);
  26428. var barLayoutGrid = __webpack_require__(145);
  26429. var echarts = __webpack_require__(1);
  26430. echarts.registerLayout(zrUtil.curry(barLayoutGrid, 'bar'));
  26431. // Visual coding for legend
  26432. echarts.registerVisual(function (ecModel) {
  26433. ecModel.eachSeriesByType('bar', function (seriesModel) {
  26434. var data = seriesModel.getData();
  26435. data.setVisual('legendSymbol', 'roundRect');
  26436. });
  26437. });
  26438. // In case developer forget to include grid component
  26439. __webpack_require__(124);
  26440. /***/ },
  26441. /* 140 */
  26442. /***/ function(module, exports, __webpack_require__) {
  26443. module.exports = __webpack_require__(141).extend({
  26444. type: 'series.bar',
  26445. dependencies: ['grid', 'polar'],
  26446. brushSelector: 'rect'
  26447. });
  26448. /***/ },
  26449. /* 141 */
  26450. /***/ function(module, exports, __webpack_require__) {
  26451. 'use strict';
  26452. var SeriesModel = __webpack_require__(78);
  26453. var createListFromArray = __webpack_require__(109);
  26454. module.exports = SeriesModel.extend({
  26455. type: 'series.__base_bar__',
  26456. getInitialData: function (option, ecModel) {
  26457. return createListFromArray(option.data, this, ecModel);
  26458. },
  26459. getMarkerPosition: function (value) {
  26460. var coordSys = this.coordinateSystem;
  26461. if (coordSys) {
  26462. // PENDING if clamp ?
  26463. var pt = coordSys.dataToPoint(value, true);
  26464. var data = this.getData();
  26465. var offset = data.getLayout('offset');
  26466. var size = data.getLayout('size');
  26467. var offsetIndex = coordSys.getBaseAxis().isHorizontal() ? 0 : 1;
  26468. pt[offsetIndex] += offset + size / 2;
  26469. return pt;
  26470. }
  26471. return [NaN, NaN];
  26472. },
  26473. defaultOption: {
  26474. zlevel: 0, // 一级层叠
  26475. z: 2, // 二级层叠
  26476. coordinateSystem: 'cartesian2d',
  26477. legendHoverLink: true,
  26478. // stack: null
  26479. // Cartesian coordinate system
  26480. // xAxisIndex: 0,
  26481. // yAxisIndex: 0,
  26482. // 最小高度改为0
  26483. barMinHeight: 0,
  26484. // 最小角度为0,仅对极坐标系下的柱状图有效
  26485. barMinAngle: 0,
  26486. // barMaxWidth: null,
  26487. // 默认自适应
  26488. // barWidth: null,
  26489. // 柱间距离,默认为柱形宽度的30%,可设固定值
  26490. // barGap: '30%',
  26491. // 类目间柱形距离,默认为类目间距的20%,可设固定值
  26492. // barCategoryGap: '20%',
  26493. // label: {
  26494. // normal: {
  26495. // show: false
  26496. // }
  26497. // },
  26498. itemStyle: {
  26499. normal: {
  26500. // color: '各异'
  26501. },
  26502. emphasis: {}
  26503. }
  26504. }
  26505. });
  26506. /***/ },
  26507. /* 142 */
  26508. /***/ function(module, exports, __webpack_require__) {
  26509. 'use strict';
  26510. var zrUtil = __webpack_require__(4);
  26511. var graphic = __webpack_require__(18);
  26512. var helper = __webpack_require__(143);
  26513. var BAR_BORDER_WIDTH_QUERY = ['itemStyle', 'normal', 'barBorderWidth'];
  26514. // FIXME
  26515. // Just for compatible with ec2.
  26516. zrUtil.extend(__webpack_require__(12).prototype, __webpack_require__(144));
  26517. var BarView = __webpack_require__(1).extendChartView({
  26518. type: 'bar',
  26519. render: function (seriesModel, ecModel, api) {
  26520. var coordinateSystemType = seriesModel.get('coordinateSystem');
  26521. if (coordinateSystemType === 'cartesian2d'
  26522. || coordinateSystemType === 'polar'
  26523. ) {
  26524. this._render(seriesModel, ecModel, api);
  26525. }
  26526. else if (true) {
  26527. console.warn('Only cartesian2d and polar supported for bar.');
  26528. }
  26529. return this.group;
  26530. },
  26531. dispose: zrUtil.noop,
  26532. _render: function (seriesModel, ecModel, api) {
  26533. var group = this.group;
  26534. var data = seriesModel.getData();
  26535. var oldData = this._data;
  26536. var coord = seriesModel.coordinateSystem;
  26537. var baseAxis = coord.getBaseAxis();
  26538. var isHorizontalOrRadial;
  26539. if (coord.type === 'cartesian2d') {
  26540. isHorizontalOrRadial = baseAxis.isHorizontal();
  26541. }
  26542. else if (coord.type === 'polar') {
  26543. isHorizontalOrRadial = baseAxis.dim === 'angle';
  26544. }
  26545. var animationModel = seriesModel.isAnimationEnabled() ? seriesModel : null;
  26546. data.diff(oldData)
  26547. .add(function (dataIndex) {
  26548. if (!data.hasValue(dataIndex)) {
  26549. return;
  26550. }
  26551. var itemModel = data.getItemModel(dataIndex);
  26552. var layout = getLayout[coord.type](data, dataIndex, itemModel);
  26553. var el = elementCreator[coord.type](
  26554. data, dataIndex, itemModel, layout, isHorizontalOrRadial, animationModel
  26555. );
  26556. data.setItemGraphicEl(dataIndex, el);
  26557. group.add(el);
  26558. updateStyle(
  26559. el, data, dataIndex, itemModel, layout,
  26560. seriesModel, isHorizontalOrRadial, coord.type === 'polar'
  26561. );
  26562. })
  26563. .update(function (newIndex, oldIndex) {
  26564. var el = oldData.getItemGraphicEl(oldIndex);
  26565. if (!data.hasValue(newIndex)) {
  26566. group.remove(el);
  26567. return;
  26568. }
  26569. var itemModel = data.getItemModel(newIndex);
  26570. var layout = getLayout[coord.type](data, newIndex, itemModel);
  26571. if (el) {
  26572. graphic.updateProps(el, {shape: layout}, animationModel, newIndex);
  26573. }
  26574. else {
  26575. el = elementCreator[coord.type](
  26576. data, newIndex, itemModel, layout, isHorizontalOrRadial, animationModel, true
  26577. );
  26578. }
  26579. data.setItemGraphicEl(newIndex, el);
  26580. // Add back
  26581. group.add(el);
  26582. updateStyle(
  26583. el, data, newIndex, itemModel, layout,
  26584. seriesModel, isHorizontalOrRadial, coord.type === 'polar'
  26585. );
  26586. })
  26587. .remove(function (dataIndex) {
  26588. var el = oldData.getItemGraphicEl(dataIndex);
  26589. if (coord.type === 'cartesian2d') {
  26590. el && removeRect(dataIndex, animationModel, el);
  26591. }
  26592. else {
  26593. el && removeSector(dataIndex, animationModel, el);
  26594. }
  26595. })
  26596. .execute();
  26597. this._data = data;
  26598. },
  26599. remove: function (ecModel, api) {
  26600. var group = this.group;
  26601. var data = this._data;
  26602. if (ecModel.get('animation')) {
  26603. if (data) {
  26604. data.eachItemGraphicEl(function (el) {
  26605. if (el.type === 'sector') {
  26606. removeSector(el.dataIndex, ecModel, el);
  26607. }
  26608. else {
  26609. removeRect(el.dataIndex, ecModel, el);
  26610. }
  26611. });
  26612. }
  26613. }
  26614. else {
  26615. group.removeAll();
  26616. }
  26617. }
  26618. });
  26619. var elementCreator = {
  26620. cartesian2d: function (
  26621. data, dataIndex, itemModel, layout, isHorizontal,
  26622. animationModel, isUpdate
  26623. ) {
  26624. var rect = new graphic.Rect({shape: zrUtil.extend({}, layout)});
  26625. // Animation
  26626. if (animationModel) {
  26627. var rectShape = rect.shape;
  26628. var animateProperty = isHorizontal ? 'height' : 'width';
  26629. var animateTarget = {};
  26630. rectShape[animateProperty] = 0;
  26631. animateTarget[animateProperty] = layout[animateProperty];
  26632. graphic[isUpdate ? 'updateProps' : 'initProps'](rect, {
  26633. shape: animateTarget
  26634. }, animationModel, dataIndex);
  26635. }
  26636. return rect;
  26637. },
  26638. polar: function (
  26639. data, dataIndex, itemModel, layout, isRadial,
  26640. animationModel, isUpdate
  26641. ) {
  26642. var sector = new graphic.Sector({shape: zrUtil.extend({}, layout)});
  26643. // Animation
  26644. if (animationModel) {
  26645. var sectorShape = sector.shape;
  26646. var animateProperty = isRadial ? 'r' : 'endAngle';
  26647. var animateTarget = {};
  26648. sectorShape[animateProperty] = isRadial ? 0 : layout.startAngle;
  26649. animateTarget[animateProperty] = layout[animateProperty];
  26650. graphic[isUpdate ? 'updateProps' : 'initProps'](sector, {
  26651. shape: animateTarget
  26652. }, animationModel, dataIndex);
  26653. }
  26654. return sector;
  26655. }
  26656. };
  26657. function removeRect(dataIndex, animationModel, el) {
  26658. // Not show text when animating
  26659. el.style.text = '';
  26660. graphic.updateProps(el, {
  26661. shape: {
  26662. width: 0
  26663. }
  26664. }, animationModel, dataIndex, function () {
  26665. el.parent && el.parent.remove(el);
  26666. });
  26667. }
  26668. function removeSector(dataIndex, animationModel, el) {
  26669. // Not show text when animating
  26670. el.style.text = '';
  26671. graphic.updateProps(el, {
  26672. shape: {
  26673. r: el.shape.r0
  26674. }
  26675. }, animationModel, dataIndex, function () {
  26676. el.parent && el.parent.remove(el);
  26677. });
  26678. }
  26679. var getLayout = {
  26680. cartesian2d: function (data, dataIndex, itemModel) {
  26681. var layout = data.getItemLayout(dataIndex);
  26682. var fixedLineWidth = getLineWidth(itemModel, layout);
  26683. // fix layout with lineWidth
  26684. var signX = layout.width > 0 ? 1 : -1;
  26685. var signY = layout.height > 0 ? 1 : -1;
  26686. return {
  26687. x: layout.x + signX * fixedLineWidth / 2,
  26688. y: layout.y + signY * fixedLineWidth / 2,
  26689. width: layout.width - signX * fixedLineWidth,
  26690. height: layout.height - signY * fixedLineWidth
  26691. };
  26692. },
  26693. polar: function (data, dataIndex, itemModel) {
  26694. var layout = data.getItemLayout(dataIndex);
  26695. return {
  26696. cx: layout.cx,
  26697. cy: layout.cy,
  26698. r0: layout.r0,
  26699. r: layout.r,
  26700. startAngle: layout.startAngle,
  26701. endAngle: layout.endAngle
  26702. };
  26703. }
  26704. };
  26705. function updateStyle(
  26706. el, data, dataIndex, itemModel, layout, seriesModel, isHorizontal, isPolar
  26707. ) {
  26708. var color = data.getItemVisual(dataIndex, 'color');
  26709. var opacity = data.getItemVisual(dataIndex, 'opacity');
  26710. var itemStyleModel = itemModel.getModel('itemStyle.normal');
  26711. var hoverStyle = itemModel.getModel('itemStyle.emphasis').getBarItemStyle();
  26712. if (!isPolar && isHorizontal) {
  26713. el.setShape('r', itemStyleModel.get('barBorderRadius') || 0);
  26714. }
  26715. el.useStyle(zrUtil.defaults(
  26716. {
  26717. fill: color,
  26718. opacity: opacity
  26719. },
  26720. itemStyleModel.getBarItemStyle()
  26721. ));
  26722. var labelPositionOutside = isHorizontal
  26723. ? (layout.height > 0 ? 'bottom' : 'top')
  26724. : (layout.width > 0 ? 'left' : 'right');
  26725. if (!isPolar) {
  26726. helper.setLabel(
  26727. el.style, hoverStyle, itemModel, color,
  26728. seriesModel, dataIndex, labelPositionOutside
  26729. );
  26730. }
  26731. graphic.setHoverStyle(el, hoverStyle);
  26732. }
  26733. // In case width or height are too small.
  26734. function getLineWidth(itemModel, rawLayout) {
  26735. var lineWidth = itemModel.get(BAR_BORDER_WIDTH_QUERY) || 0;
  26736. return Math.min(lineWidth, Math.abs(rawLayout.width), Math.abs(rawLayout.height));
  26737. }
  26738. module.exports = BarView;
  26739. /***/ },
  26740. /* 143 */
  26741. /***/ function(module, exports, __webpack_require__) {
  26742. var zrUtil = __webpack_require__(4);
  26743. var graphic = __webpack_require__(18);
  26744. var helper = {};
  26745. helper.setLabel = function (
  26746. normalStyle, hoverStyle, itemModel, color, seriesModel, dataIndex, labelPositionOutside
  26747. ) {
  26748. var labelModel = itemModel.getModel('label.normal');
  26749. var hoverLabelModel = itemModel.getModel('label.emphasis');
  26750. if (labelModel.get('show')) {
  26751. setLabel(
  26752. normalStyle, labelModel, color,
  26753. zrUtil.retrieve(
  26754. seriesModel.getFormattedLabel(dataIndex, 'normal'),
  26755. seriesModel.getRawValue(dataIndex)
  26756. ),
  26757. labelPositionOutside
  26758. );
  26759. }
  26760. else {
  26761. normalStyle.text = '';
  26762. }
  26763. if (hoverLabelModel.get('show')) {
  26764. setLabel(
  26765. hoverStyle, hoverLabelModel, color,
  26766. zrUtil.retrieve(
  26767. seriesModel.getFormattedLabel(dataIndex, 'emphasis'),
  26768. seriesModel.getRawValue(dataIndex)
  26769. ),
  26770. labelPositionOutside
  26771. );
  26772. }
  26773. else {
  26774. hoverStyle.text = '';
  26775. }
  26776. };
  26777. function setLabel(style, model, color, labelText, labelPositionOutside) {
  26778. graphic.setText(style, model, color);
  26779. style.text = labelText;
  26780. if (style.textPosition === 'outside') {
  26781. style.textPosition = labelPositionOutside;
  26782. }
  26783. }
  26784. module.exports = helper;
  26785. /***/ },
  26786. /* 144 */
  26787. /***/ function(module, exports, __webpack_require__) {
  26788. var getBarItemStyle = __webpack_require__(15)(
  26789. [
  26790. ['fill', 'color'],
  26791. ['stroke', 'borderColor'],
  26792. ['lineWidth', 'borderWidth'],
  26793. // Compatitable with 2
  26794. ['stroke', 'barBorderColor'],
  26795. ['lineWidth', 'barBorderWidth'],
  26796. ['opacity'],
  26797. ['shadowBlur'],
  26798. ['shadowOffsetX'],
  26799. ['shadowOffsetY'],
  26800. ['shadowColor']
  26801. ]
  26802. );
  26803. module.exports = {
  26804. getBarItemStyle: function (excludes) {
  26805. var style = getBarItemStyle.call(this, excludes);
  26806. if (this.getBorderLineDash) {
  26807. var lineDash = this.getBorderLineDash();
  26808. lineDash && (style.lineDash = lineDash);
  26809. }
  26810. return style;
  26811. }
  26812. };
  26813. /***/ },
  26814. /* 145 */
  26815. /***/ function(module, exports, __webpack_require__) {
  26816. 'use strict';
  26817. var zrUtil = __webpack_require__(4);
  26818. var numberUtil = __webpack_require__(7);
  26819. var parsePercent = numberUtil.parsePercent;
  26820. var STACK_PREFIX = '__ec_stack_';
  26821. function getSeriesStackId(seriesModel) {
  26822. return seriesModel.get('stack') || STACK_PREFIX + seriesModel.seriesIndex;
  26823. }
  26824. function getAxisKey(axis) {
  26825. return axis.dim + axis.index;
  26826. }
  26827. /**
  26828. * @param {Object} opt
  26829. * @param {module:echarts/coord/Axis} opt.axis Only support category axis currently.
  26830. * @param {number} opt.count Positive interger.
  26831. * @param {number} [opt.barWidth]
  26832. * @param {number} [opt.barMaxWidth]
  26833. * @param {number} [opt.barGap]
  26834. * @param {number} [opt.barCategoryGap]
  26835. * @return {Object} {width, offset, offsetCenter} If axis.type is not 'category', return undefined.
  26836. */
  26837. function getLayoutOnAxis(opt, api) {
  26838. var params = [];
  26839. var baseAxis = opt.axis;
  26840. var axisKey = 'axis0';
  26841. if (baseAxis.type !== 'category') {
  26842. return;
  26843. }
  26844. var bandWidth = baseAxis.getBandWidth();
  26845. for (var i = 0; i < opt.count || 0; i++) {
  26846. params.push(zrUtil.defaults({
  26847. bandWidth: bandWidth,
  26848. axisKey: axisKey,
  26849. stackId: STACK_PREFIX + i
  26850. }, opt));
  26851. }
  26852. var widthAndOffsets = doCalBarWidthAndOffset(params, api);
  26853. var result = [];
  26854. for (var i = 0; i < opt.count; i++) {
  26855. var item = widthAndOffsets[axisKey][STACK_PREFIX + i];
  26856. item.offsetCenter = item.offset + item.width / 2;
  26857. result.push(item);
  26858. }
  26859. return result;
  26860. }
  26861. function calBarWidthAndOffset(barSeries, api) {
  26862. var seriesInfoList = zrUtil.map(barSeries, function (seriesModel) {
  26863. var data = seriesModel.getData();
  26864. var cartesian = seriesModel.coordinateSystem;
  26865. var baseAxis = cartesian.getBaseAxis();
  26866. var axisExtent = baseAxis.getExtent();
  26867. var bandWidth = baseAxis.type === 'category'
  26868. ? baseAxis.getBandWidth()
  26869. : (Math.abs(axisExtent[1] - axisExtent[0]) / data.count());
  26870. var barWidth = parsePercent(
  26871. seriesModel.get('barWidth'), bandWidth
  26872. );
  26873. var barMaxWidth = parsePercent(
  26874. seriesModel.get('barMaxWidth'), bandWidth
  26875. );
  26876. var barGap = seriesModel.get('barGap');
  26877. var barCategoryGap = seriesModel.get('barCategoryGap');
  26878. return {
  26879. bandWidth: bandWidth,
  26880. barWidth: barWidth,
  26881. barMaxWidth: barMaxWidth,
  26882. barGap: barGap,
  26883. barCategoryGap: barCategoryGap,
  26884. axisKey: getAxisKey(baseAxis),
  26885. stackId: getSeriesStackId(seriesModel)
  26886. };
  26887. });
  26888. return doCalBarWidthAndOffset(seriesInfoList, api);
  26889. }
  26890. function doCalBarWidthAndOffset(seriesInfoList, api) {
  26891. // Columns info on each category axis. Key is cartesian name
  26892. var columnsMap = {};
  26893. zrUtil.each(seriesInfoList, function (seriesInfo, idx) {
  26894. var axisKey = seriesInfo.axisKey;
  26895. var bandWidth = seriesInfo.bandWidth;
  26896. var columnsOnAxis = columnsMap[axisKey] || {
  26897. bandWidth: bandWidth,
  26898. remainedWidth: bandWidth,
  26899. autoWidthCount: 0,
  26900. categoryGap: '20%',
  26901. gap: '30%',
  26902. stacks: {}
  26903. };
  26904. var stacks = columnsOnAxis.stacks;
  26905. columnsMap[axisKey] = columnsOnAxis;
  26906. var stackId = seriesInfo.stackId;
  26907. if (!stacks[stackId]) {
  26908. columnsOnAxis.autoWidthCount++;
  26909. }
  26910. stacks[stackId] = stacks[stackId] || {
  26911. width: 0,
  26912. maxWidth: 0
  26913. };
  26914. // Caution: In a single coordinate system, these barGrid attributes
  26915. // will be shared by series. Consider that they have default values,
  26916. // only the attributes set on the last series will work.
  26917. // Do not change this fact unless there will be a break change.
  26918. // TODO
  26919. var barWidth = seriesInfo.barWidth;
  26920. if (barWidth && !stacks[stackId].width) {
  26921. barWidth = Math.min(columnsOnAxis.remainedWidth, barWidth);
  26922. stacks[stackId].width = barWidth;
  26923. columnsOnAxis.remainedWidth -= barWidth;
  26924. }
  26925. var barMaxWidth = seriesInfo.barMaxWidth;
  26926. barMaxWidth && (stacks[stackId].maxWidth = barMaxWidth);
  26927. var barGap = seriesInfo.barGap;
  26928. (barGap != null) && (columnsOnAxis.gap = barGap);
  26929. var barCategoryGap = seriesInfo.barCategoryGap;
  26930. (barCategoryGap != null) && (columnsOnAxis.categoryGap = barCategoryGap);
  26931. });
  26932. var result = {};
  26933. zrUtil.each(columnsMap, function (columnsOnAxis, coordSysName) {
  26934. result[coordSysName] = {};
  26935. var stacks = columnsOnAxis.stacks;
  26936. var bandWidth = columnsOnAxis.bandWidth;
  26937. var categoryGap = parsePercent(columnsOnAxis.categoryGap, bandWidth);
  26938. var barGapPercent = parsePercent(columnsOnAxis.gap, 1);
  26939. var remainedWidth = columnsOnAxis.remainedWidth;
  26940. var autoWidthCount = columnsOnAxis.autoWidthCount;
  26941. var autoWidth = (remainedWidth - categoryGap)
  26942. / (autoWidthCount + (autoWidthCount - 1) * barGapPercent);
  26943. autoWidth = Math.max(autoWidth, 0);
  26944. // Find if any auto calculated bar exceeded maxBarWidth
  26945. zrUtil.each(stacks, function (column, stack) {
  26946. var maxWidth = column.maxWidth;
  26947. if (maxWidth && maxWidth < autoWidth) {
  26948. maxWidth = Math.min(maxWidth, remainedWidth);
  26949. if (column.width) {
  26950. maxWidth = Math.min(maxWidth, column.width);
  26951. }
  26952. remainedWidth -= maxWidth;
  26953. column.width = maxWidth;
  26954. autoWidthCount--;
  26955. }
  26956. });
  26957. // Recalculate width again
  26958. autoWidth = (remainedWidth - categoryGap)
  26959. / (autoWidthCount + (autoWidthCount - 1) * barGapPercent);
  26960. autoWidth = Math.max(autoWidth, 0);
  26961. var widthSum = 0;
  26962. var lastColumn;
  26963. zrUtil.each(stacks, function (column, idx) {
  26964. if (!column.width) {
  26965. column.width = autoWidth;
  26966. }
  26967. lastColumn = column;
  26968. widthSum += column.width * (1 + barGapPercent);
  26969. });
  26970. if (lastColumn) {
  26971. widthSum -= lastColumn.width * barGapPercent;
  26972. }
  26973. var offset = -widthSum / 2;
  26974. zrUtil.each(stacks, function (column, stackId) {
  26975. result[coordSysName][stackId] = result[coordSysName][stackId] || {
  26976. offset: offset,
  26977. width: column.width
  26978. };
  26979. offset += column.width * (1 + barGapPercent);
  26980. });
  26981. });
  26982. return result;
  26983. }
  26984. /**
  26985. * @param {string} seriesType
  26986. * @param {module:echarts/model/Global} ecModel
  26987. * @param {module:echarts/ExtensionAPI} api
  26988. */
  26989. function barLayoutGrid(seriesType, ecModel, api) {
  26990. var barWidthAndOffset = calBarWidthAndOffset(
  26991. zrUtil.filter(
  26992. ecModel.getSeriesByType(seriesType),
  26993. function (seriesModel) {
  26994. return !ecModel.isSeriesFiltered(seriesModel)
  26995. && seriesModel.coordinateSystem
  26996. && seriesModel.coordinateSystem.type === 'cartesian2d';
  26997. }
  26998. )
  26999. );
  27000. var lastStackCoords = {};
  27001. var lastStackCoordsOrigin = {};
  27002. ecModel.eachSeriesByType(seriesType, function (seriesModel) {
  27003. // Check series coordinate, do layout for cartesian2d only
  27004. if (seriesModel.coordinateSystem.type !== 'cartesian2d') {
  27005. return;
  27006. }
  27007. var data = seriesModel.getData();
  27008. var cartesian = seriesModel.coordinateSystem;
  27009. var baseAxis = cartesian.getBaseAxis();
  27010. var stackId = getSeriesStackId(seriesModel);
  27011. var columnLayoutInfo = barWidthAndOffset[getAxisKey(baseAxis)][stackId];
  27012. var columnOffset = columnLayoutInfo.offset;
  27013. var columnWidth = columnLayoutInfo.width;
  27014. var valueAxis = cartesian.getOtherAxis(baseAxis);
  27015. var barMinHeight = seriesModel.get('barMinHeight') || 0;
  27016. var valueAxisStart = baseAxis.onZero
  27017. ? valueAxis.toGlobalCoord(valueAxis.dataToCoord(0))
  27018. : valueAxis.getGlobalExtent()[0];
  27019. var coords = cartesian.dataToPoints(data, true);
  27020. lastStackCoords[stackId] = lastStackCoords[stackId] || [];
  27021. lastStackCoordsOrigin[stackId] = lastStackCoordsOrigin[stackId] || []; // Fix #4243
  27022. data.setLayout({
  27023. offset: columnOffset,
  27024. size: columnWidth
  27025. });
  27026. data.each(valueAxis.dim, function (value, idx) {
  27027. if (isNaN(value)) {
  27028. return;
  27029. }
  27030. if (!lastStackCoords[stackId][idx]) {
  27031. lastStackCoords[stackId][idx] = {
  27032. p: valueAxisStart, // Positive stack
  27033. n: valueAxisStart // Negative stack
  27034. };
  27035. lastStackCoordsOrigin[stackId][idx] = {
  27036. p: valueAxisStart, // Positive stack
  27037. n: valueAxisStart // Negative stack
  27038. };
  27039. }
  27040. var sign = value >= 0 ? 'p' : 'n';
  27041. var coord = coords[idx];
  27042. var lastCoord = lastStackCoords[stackId][idx][sign];
  27043. var lastCoordOrigin = lastStackCoordsOrigin[stackId][idx][sign];
  27044. var x;
  27045. var y;
  27046. var width;
  27047. var height;
  27048. if (valueAxis.isHorizontal()) {
  27049. x = lastCoord;
  27050. y = coord[1] + columnOffset;
  27051. width = coord[0] - lastCoordOrigin;
  27052. height = columnWidth;
  27053. lastStackCoordsOrigin[stackId][idx][sign] += width;
  27054. if (Math.abs(width) < barMinHeight) {
  27055. width = (width < 0 ? -1 : 1) * barMinHeight;
  27056. }
  27057. lastStackCoords[stackId][idx][sign] += width;
  27058. }
  27059. else {
  27060. x = coord[0] + columnOffset;
  27061. y = lastCoord;
  27062. width = columnWidth;
  27063. height = coord[1] - lastCoordOrigin;
  27064. lastStackCoordsOrigin[stackId][idx][sign] += height;
  27065. if (Math.abs(height) < barMinHeight) {
  27066. // Include zero to has a positive bar
  27067. height = (height <= 0 ? -1 : 1) * barMinHeight;
  27068. }
  27069. lastStackCoords[stackId][idx][sign] += height;
  27070. }
  27071. data.setItemLayout(idx, {
  27072. x: x,
  27073. y: y,
  27074. width: width,
  27075. height: height
  27076. });
  27077. }, true);
  27078. }, this);
  27079. }
  27080. barLayoutGrid.getLayoutOnAxis = getLayoutOnAxis;
  27081. module.exports = barLayoutGrid;
  27082. /***/ },
  27083. /* 146 */
  27084. /***/ function(module, exports, __webpack_require__) {
  27085. var zrUtil = __webpack_require__(4);
  27086. var echarts = __webpack_require__(1);
  27087. __webpack_require__(147);
  27088. __webpack_require__(149);
  27089. __webpack_require__(150)('pie', [{
  27090. type: 'pieToggleSelect',
  27091. event: 'pieselectchanged',
  27092. method: 'toggleSelected'
  27093. }, {
  27094. type: 'pieSelect',
  27095. event: 'pieselected',
  27096. method: 'select'
  27097. }, {
  27098. type: 'pieUnSelect',
  27099. event: 'pieunselected',
  27100. method: 'unSelect'
  27101. }]);
  27102. echarts.registerVisual(zrUtil.curry(__webpack_require__(151), 'pie'));
  27103. echarts.registerLayout(zrUtil.curry(
  27104. __webpack_require__(152), 'pie'
  27105. ));
  27106. echarts.registerProcessor(zrUtil.curry(__webpack_require__(154), 'pie'));
  27107. /***/ },
  27108. /* 147 */
  27109. /***/ function(module, exports, __webpack_require__) {
  27110. 'use strict';
  27111. var List = __webpack_require__(98);
  27112. var zrUtil = __webpack_require__(4);
  27113. var modelUtil = __webpack_require__(5);
  27114. var completeDimensions = __webpack_require__(110);
  27115. var dataSelectableMixin = __webpack_require__(148);
  27116. var PieSeries = __webpack_require__(1).extendSeriesModel({
  27117. type: 'series.pie',
  27118. // Overwrite
  27119. init: function (option) {
  27120. PieSeries.superApply(this, 'init', arguments);
  27121. // Enable legend selection for each data item
  27122. // Use a function instead of direct access because data reference may changed
  27123. this.legendDataProvider = function () {
  27124. return this.getRawData();
  27125. };
  27126. this.updateSelectedMap(option.data);
  27127. this._defaultLabelLine(option);
  27128. },
  27129. // Overwrite
  27130. mergeOption: function (newOption) {
  27131. PieSeries.superCall(this, 'mergeOption', newOption);
  27132. this.updateSelectedMap(this.option.data);
  27133. },
  27134. getInitialData: function (option, ecModel) {
  27135. var dimensions = completeDimensions(['value'], option.data);
  27136. var list = new List(dimensions, this);
  27137. list.initData(option.data);
  27138. return list;
  27139. },
  27140. // Overwrite
  27141. getDataParams: function (dataIndex) {
  27142. var data = this.getData();
  27143. var params = PieSeries.superCall(this, 'getDataParams', dataIndex);
  27144. var sum = data.getSum('value');
  27145. // FIXME toFixed?
  27146. //
  27147. // Percent is 0 if sum is 0
  27148. params.percent = !sum ? 0 : +(data.get('value', dataIndex) / sum * 100).toFixed(2);
  27149. params.$vars.push('percent');
  27150. return params;
  27151. },
  27152. _defaultLabelLine: function (option) {
  27153. // Extend labelLine emphasis
  27154. modelUtil.defaultEmphasis(option.labelLine, ['show']);
  27155. var labelLineNormalOpt = option.labelLine.normal;
  27156. var labelLineEmphasisOpt = option.labelLine.emphasis;
  27157. // Not show label line if `label.normal.show = false`
  27158. labelLineNormalOpt.show = labelLineNormalOpt.show
  27159. && option.label.normal.show;
  27160. labelLineEmphasisOpt.show = labelLineEmphasisOpt.show
  27161. && option.label.emphasis.show;
  27162. },
  27163. defaultOption: {
  27164. zlevel: 0,
  27165. z: 2,
  27166. legendHoverLink: true,
  27167. hoverAnimation: true,
  27168. // 默认全局居中
  27169. center: ['50%', '50%'],
  27170. radius: [0, '75%'],
  27171. // 默认顺时针
  27172. clockwise: true,
  27173. startAngle: 90,
  27174. // 最小角度改为0
  27175. minAngle: 0,
  27176. // 选中是扇区偏移量
  27177. selectedOffset: 10,
  27178. // If use strategy to avoid label overlapping
  27179. avoidLabelOverlap: true,
  27180. // 选择模式,默认关闭,可选single,multiple
  27181. // selectedMode: false,
  27182. // 南丁格尔玫瑰图模式,'radius'(半径) | 'area'(面积)
  27183. // roseType: null,
  27184. // If still show when all data zero.
  27185. stillShowZeroSum: true,
  27186. label: {
  27187. normal: {
  27188. // If rotate around circle
  27189. rotate: false,
  27190. show: true,
  27191. // 'outer', 'inside', 'center'
  27192. position: 'outer'
  27193. // formatter: 标签文本格式器,同Tooltip.formatter,不支持异步回调
  27194. // textStyle: null // 默认使用全局文本样式,详见TEXTSTYLE
  27195. // distance: 当position为inner时有效,为label位置到圆心的距离与圆半径(环状图为内外半径和)的比例系数
  27196. },
  27197. emphasis: {}
  27198. },
  27199. // Enabled when label.normal.position is 'outer'
  27200. labelLine: {
  27201. normal: {
  27202. show: true,
  27203. // 引导线两段中的第一段长度
  27204. length: 15,
  27205. // 引导线两段中的第二段长度
  27206. length2: 15,
  27207. smooth: false,
  27208. lineStyle: {
  27209. // color: 各异,
  27210. width: 1,
  27211. type: 'solid'
  27212. }
  27213. }
  27214. },
  27215. itemStyle: {
  27216. normal: {
  27217. borderWidth: 1
  27218. },
  27219. emphasis: {}
  27220. },
  27221. // Animation type canbe expansion, scale
  27222. animationType: 'expansion',
  27223. animationEasing: 'cubicOut',
  27224. data: []
  27225. }
  27226. });
  27227. zrUtil.mixin(PieSeries, dataSelectableMixin);
  27228. module.exports = PieSeries;
  27229. /***/ },
  27230. /* 148 */
  27231. /***/ function(module, exports, __webpack_require__) {
  27232. /**
  27233. * Data selectable mixin for chart series.
  27234. * To eanble data select, option of series must have `selectedMode`.
  27235. * And each data item will use `selected` to toggle itself selected status
  27236. *
  27237. * @module echarts/chart/helper/DataSelectable
  27238. */
  27239. var zrUtil = __webpack_require__(4);
  27240. module.exports = {
  27241. updateSelectedMap: function (targetList) {
  27242. this._selectTargetMap = zrUtil.reduce(targetList || [], function (targetMap, target) {
  27243. targetMap.set(target.name, target);
  27244. return targetMap;
  27245. }, zrUtil.createHashMap());
  27246. },
  27247. /**
  27248. * @param {string} name
  27249. */
  27250. // PENGING If selectedMode is null ?
  27251. select: function (name) {
  27252. var targetMap = this._selectTargetMap;
  27253. var target = targetMap.get(name);
  27254. var selectedMode = this.get('selectedMode');
  27255. if (selectedMode === 'single') {
  27256. targetMap.each(function (target) {
  27257. target.selected = false;
  27258. });
  27259. }
  27260. target && (target.selected = true);
  27261. },
  27262. /**
  27263. * @param {string} name
  27264. */
  27265. unSelect: function (name) {
  27266. var target = this._selectTargetMap.get(name);
  27267. // var selectedMode = this.get('selectedMode');
  27268. // selectedMode !== 'single' && target && (target.selected = false);
  27269. target && (target.selected = false);
  27270. },
  27271. /**
  27272. * @param {string} name
  27273. */
  27274. toggleSelected: function (name) {
  27275. var target = this._selectTargetMap.get(name);
  27276. if (target != null) {
  27277. this[target.selected ? 'unSelect' : 'select'](name);
  27278. return target.selected;
  27279. }
  27280. },
  27281. /**
  27282. * @param {string} name
  27283. */
  27284. isSelected: function (name) {
  27285. var target = this._selectTargetMap.get(name);
  27286. return target && target.selected;
  27287. }
  27288. };
  27289. /***/ },
  27290. /* 149 */
  27291. /***/ function(module, exports, __webpack_require__) {
  27292. var graphic = __webpack_require__(18);
  27293. var zrUtil = __webpack_require__(4);
  27294. /**
  27295. * @param {module:echarts/model/Series} seriesModel
  27296. * @param {boolean} hasAnimation
  27297. * @inner
  27298. */
  27299. function updateDataSelected(uid, seriesModel, hasAnimation, api) {
  27300. var data = seriesModel.getData();
  27301. var dataIndex = this.dataIndex;
  27302. var name = data.getName(dataIndex);
  27303. var selectedOffset = seriesModel.get('selectedOffset');
  27304. api.dispatchAction({
  27305. type: 'pieToggleSelect',
  27306. from: uid,
  27307. name: name,
  27308. seriesId: seriesModel.id
  27309. });
  27310. data.each(function (idx) {
  27311. toggleItemSelected(
  27312. data.getItemGraphicEl(idx),
  27313. data.getItemLayout(idx),
  27314. seriesModel.isSelected(data.getName(idx)),
  27315. selectedOffset,
  27316. hasAnimation
  27317. );
  27318. });
  27319. }
  27320. /**
  27321. * @param {module:zrender/graphic/Sector} el
  27322. * @param {Object} layout
  27323. * @param {boolean} isSelected
  27324. * @param {number} selectedOffset
  27325. * @param {boolean} hasAnimation
  27326. * @inner
  27327. */
  27328. function toggleItemSelected(el, layout, isSelected, selectedOffset, hasAnimation) {
  27329. var midAngle = (layout.startAngle + layout.endAngle) / 2;
  27330. var dx = Math.cos(midAngle);
  27331. var dy = Math.sin(midAngle);
  27332. var offset = isSelected ? selectedOffset : 0;
  27333. var position = [dx * offset, dy * offset];
  27334. hasAnimation
  27335. // animateTo will stop revious animation like update transition
  27336. ? el.animate()
  27337. .when(200, {
  27338. position: position
  27339. })
  27340. .start('bounceOut')
  27341. : el.attr('position', position);
  27342. }
  27343. /**
  27344. * Piece of pie including Sector, Label, LabelLine
  27345. * @constructor
  27346. * @extends {module:zrender/graphic/Group}
  27347. */
  27348. function PiePiece(data, idx) {
  27349. graphic.Group.call(this);
  27350. var sector = new graphic.Sector({
  27351. z2: 2
  27352. });
  27353. var polyline = new graphic.Polyline();
  27354. var text = new graphic.Text();
  27355. this.add(sector);
  27356. this.add(polyline);
  27357. this.add(text);
  27358. this.updateData(data, idx, true);
  27359. // Hover to change label and labelLine
  27360. function onEmphasis() {
  27361. polyline.ignore = polyline.hoverIgnore;
  27362. text.ignore = text.hoverIgnore;
  27363. }
  27364. function onNormal() {
  27365. polyline.ignore = polyline.normalIgnore;
  27366. text.ignore = text.normalIgnore;
  27367. }
  27368. this.on('emphasis', onEmphasis)
  27369. .on('normal', onNormal)
  27370. .on('mouseover', onEmphasis)
  27371. .on('mouseout', onNormal);
  27372. }
  27373. var piePieceProto = PiePiece.prototype;
  27374. function getLabelStyle(data, idx, state, labelModel, labelPosition) {
  27375. var textStyleModel = labelModel.getModel('textStyle');
  27376. var isLabelInside = labelPosition === 'inside' || labelPosition === 'inner';
  27377. return {
  27378. fill: textStyleModel.getTextColor()
  27379. || (isLabelInside ? '#fff' : data.getItemVisual(idx, 'color')),
  27380. opacity: data.getItemVisual(idx, 'opacity'),
  27381. textFont: textStyleModel.getFont(),
  27382. text: zrUtil.retrieve(
  27383. data.hostModel.getFormattedLabel(idx, state), data.getName(idx)
  27384. )
  27385. };
  27386. }
  27387. piePieceProto.updateData = function (data, idx, firstCreate) {
  27388. var sector = this.childAt(0);
  27389. var seriesModel = data.hostModel;
  27390. var itemModel = data.getItemModel(idx);
  27391. var layout = data.getItemLayout(idx);
  27392. var sectorShape = zrUtil.extend({}, layout);
  27393. sectorShape.label = null;
  27394. if (firstCreate) {
  27395. sector.setShape(sectorShape);
  27396. var animationType = seriesModel.getShallow('animationType');
  27397. if (animationType === 'scale') {
  27398. sector.shape.r = layout.r0;
  27399. graphic.initProps(sector, {
  27400. shape: {
  27401. r: layout.r
  27402. }
  27403. }, seriesModel, idx);
  27404. }
  27405. // Expansion
  27406. else {
  27407. sector.shape.endAngle = layout.startAngle;
  27408. graphic.updateProps(sector, {
  27409. shape: {
  27410. endAngle: layout.endAngle
  27411. }
  27412. }, seriesModel, idx);
  27413. }
  27414. }
  27415. else {
  27416. graphic.updateProps(sector, {
  27417. shape: sectorShape
  27418. }, seriesModel, idx);
  27419. }
  27420. // Update common style
  27421. var itemStyleModel = itemModel.getModel('itemStyle');
  27422. var visualColor = data.getItemVisual(idx, 'color');
  27423. sector.useStyle(
  27424. zrUtil.defaults(
  27425. {
  27426. lineJoin: 'bevel',
  27427. fill: visualColor
  27428. },
  27429. itemStyleModel.getModel('normal').getItemStyle()
  27430. )
  27431. );
  27432. sector.hoverStyle = itemStyleModel.getModel('emphasis').getItemStyle();
  27433. // Toggle selected
  27434. toggleItemSelected(
  27435. this,
  27436. data.getItemLayout(idx),
  27437. itemModel.get('selected'),
  27438. seriesModel.get('selectedOffset'),
  27439. seriesModel.get('animation')
  27440. );
  27441. function onEmphasis() {
  27442. // Sector may has animation of updating data. Force to move to the last frame
  27443. // Or it may stopped on the wrong shape
  27444. sector.stopAnimation(true);
  27445. sector.animateTo({
  27446. shape: {
  27447. r: layout.r + 10
  27448. }
  27449. }, 300, 'elasticOut');
  27450. }
  27451. function onNormal() {
  27452. sector.stopAnimation(true);
  27453. sector.animateTo({
  27454. shape: {
  27455. r: layout.r
  27456. }
  27457. }, 300, 'elasticOut');
  27458. }
  27459. sector.off('mouseover').off('mouseout').off('emphasis').off('normal');
  27460. if (itemModel.get('hoverAnimation') && seriesModel.isAnimationEnabled()) {
  27461. sector
  27462. .on('mouseover', onEmphasis)
  27463. .on('mouseout', onNormal)
  27464. .on('emphasis', onEmphasis)
  27465. .on('normal', onNormal);
  27466. }
  27467. this._updateLabel(data, idx);
  27468. graphic.setHoverStyle(this);
  27469. };
  27470. piePieceProto._updateLabel = function (data, idx) {
  27471. var labelLine = this.childAt(1);
  27472. var labelText = this.childAt(2);
  27473. var seriesModel = data.hostModel;
  27474. var itemModel = data.getItemModel(idx);
  27475. var layout = data.getItemLayout(idx);
  27476. var labelLayout = layout.label;
  27477. var visualColor = data.getItemVisual(idx, 'color');
  27478. graphic.updateProps(labelLine, {
  27479. shape: {
  27480. points: labelLayout.linePoints || [
  27481. [labelLayout.x, labelLayout.y], [labelLayout.x, labelLayout.y], [labelLayout.x, labelLayout.y]
  27482. ]
  27483. }
  27484. }, seriesModel, idx);
  27485. graphic.updateProps(labelText, {
  27486. style: {
  27487. x: labelLayout.x,
  27488. y: labelLayout.y
  27489. }
  27490. }, seriesModel, idx);
  27491. labelText.attr({
  27492. style: {
  27493. textVerticalAlign: labelLayout.verticalAlign,
  27494. textAlign: labelLayout.textAlign,
  27495. textFont: labelLayout.font
  27496. },
  27497. rotation: labelLayout.rotation,
  27498. origin: [labelLayout.x, labelLayout.y],
  27499. z2: 10
  27500. });
  27501. var labelModel = itemModel.getModel('label.normal');
  27502. var labelHoverModel = itemModel.getModel('label.emphasis');
  27503. var labelLineModel = itemModel.getModel('labelLine.normal');
  27504. var labelLineHoverModel = itemModel.getModel('labelLine.emphasis');
  27505. var labelPosition = labelModel.get('position') || labelHoverModel.get('position');
  27506. labelText.setStyle(getLabelStyle(data, idx, 'normal', labelModel, labelPosition));
  27507. labelText.ignore = labelText.normalIgnore = !labelModel.get('show');
  27508. labelText.hoverIgnore = !labelHoverModel.get('show');
  27509. labelLine.ignore = labelLine.normalIgnore = !labelLineModel.get('show');
  27510. labelLine.hoverIgnore = !labelLineHoverModel.get('show');
  27511. // Default use item visual color
  27512. labelLine.setStyle({
  27513. stroke: visualColor,
  27514. opacity: data.getItemVisual(idx, 'opacity')
  27515. });
  27516. labelLine.setStyle(labelLineModel.getModel('lineStyle').getLineStyle());
  27517. labelText.hoverStyle = getLabelStyle(data, idx, 'emphasis', labelHoverModel, labelPosition);
  27518. labelLine.hoverStyle = labelLineHoverModel.getModel('lineStyle').getLineStyle();
  27519. var smooth = labelLineModel.get('smooth');
  27520. if (smooth && smooth === true) {
  27521. smooth = 0.4;
  27522. }
  27523. labelLine.setShape({
  27524. smooth: smooth
  27525. });
  27526. };
  27527. zrUtil.inherits(PiePiece, graphic.Group);
  27528. // Pie view
  27529. var Pie = __webpack_require__(80).extend({
  27530. type: 'pie',
  27531. init: function () {
  27532. var sectorGroup = new graphic.Group();
  27533. this._sectorGroup = sectorGroup;
  27534. },
  27535. render: function (seriesModel, ecModel, api, payload) {
  27536. if (payload && (payload.from === this.uid)) {
  27537. return;
  27538. }
  27539. var data = seriesModel.getData();
  27540. var oldData = this._data;
  27541. var group = this.group;
  27542. var hasAnimation = ecModel.get('animation');
  27543. var isFirstRender = !oldData;
  27544. var animationType = seriesModel.get('animationType');
  27545. var onSectorClick = zrUtil.curry(
  27546. updateDataSelected, this.uid, seriesModel, hasAnimation, api
  27547. );
  27548. var selectedMode = seriesModel.get('selectedMode');
  27549. data.diff(oldData)
  27550. .add(function (idx) {
  27551. var piePiece = new PiePiece(data, idx);
  27552. // Default expansion animation
  27553. if (isFirstRender && animationType !== 'scale') {
  27554. piePiece.eachChild(function (child) {
  27555. child.stopAnimation(true);
  27556. });
  27557. }
  27558. selectedMode && piePiece.on('click', onSectorClick);
  27559. data.setItemGraphicEl(idx, piePiece);
  27560. group.add(piePiece);
  27561. })
  27562. .update(function (newIdx, oldIdx) {
  27563. var piePiece = oldData.getItemGraphicEl(oldIdx);
  27564. piePiece.updateData(data, newIdx);
  27565. piePiece.off('click');
  27566. selectedMode && piePiece.on('click', onSectorClick);
  27567. group.add(piePiece);
  27568. data.setItemGraphicEl(newIdx, piePiece);
  27569. })
  27570. .remove(function (idx) {
  27571. var piePiece = oldData.getItemGraphicEl(idx);
  27572. group.remove(piePiece);
  27573. })
  27574. .execute();
  27575. if (
  27576. hasAnimation && isFirstRender && data.count() > 0
  27577. // Default expansion animation
  27578. && animationType !== 'scale'
  27579. ) {
  27580. var shape = data.getItemLayout(0);
  27581. var r = Math.max(api.getWidth(), api.getHeight()) / 2;
  27582. var removeClipPath = zrUtil.bind(group.removeClipPath, group);
  27583. group.setClipPath(this._createClipPath(
  27584. shape.cx, shape.cy, r, shape.startAngle, shape.clockwise, removeClipPath, seriesModel
  27585. ));
  27586. }
  27587. this._data = data;
  27588. },
  27589. dispose: function () {},
  27590. _createClipPath: function (
  27591. cx, cy, r, startAngle, clockwise, cb, seriesModel
  27592. ) {
  27593. var clipPath = new graphic.Sector({
  27594. shape: {
  27595. cx: cx,
  27596. cy: cy,
  27597. r0: 0,
  27598. r: r,
  27599. startAngle: startAngle,
  27600. endAngle: startAngle,
  27601. clockwise: clockwise
  27602. }
  27603. });
  27604. graphic.initProps(clipPath, {
  27605. shape: {
  27606. endAngle: startAngle + (clockwise ? 1 : -1) * Math.PI * 2
  27607. }
  27608. }, seriesModel, cb);
  27609. return clipPath;
  27610. },
  27611. /**
  27612. * @implement
  27613. */
  27614. containPoint: function (point, seriesModel) {
  27615. var data = seriesModel.getData();
  27616. var itemLayout = data.getItemLayout(0);
  27617. if (itemLayout) {
  27618. var dx = point[0] - itemLayout.cx;
  27619. var dy = point[1] - itemLayout.cy;
  27620. var radius = Math.sqrt(dx * dx + dy * dy);
  27621. return radius <= itemLayout.r && radius >= itemLayout.r0;
  27622. }
  27623. }
  27624. });
  27625. module.exports = Pie;
  27626. /***/ },
  27627. /* 150 */
  27628. /***/ function(module, exports, __webpack_require__) {
  27629. var echarts = __webpack_require__(1);
  27630. var zrUtil = __webpack_require__(4);
  27631. module.exports = function (seriesType, actionInfos) {
  27632. zrUtil.each(actionInfos, function (actionInfo) {
  27633. actionInfo.update = 'updateView';
  27634. /**
  27635. * @payload
  27636. * @property {string} seriesName
  27637. * @property {string} name
  27638. */
  27639. echarts.registerAction(actionInfo, function (payload, ecModel) {
  27640. var selected = {};
  27641. ecModel.eachComponent(
  27642. {mainType: 'series', subType: seriesType, query: payload},
  27643. function (seriesModel) {
  27644. if (seriesModel[actionInfo.method]) {
  27645. seriesModel[actionInfo.method](payload.name);
  27646. }
  27647. var data = seriesModel.getData();
  27648. // Create selected map
  27649. data.each(function (idx) {
  27650. var name = data.getName(idx);
  27651. selected[name] = seriesModel.isSelected(name) || false;
  27652. });
  27653. }
  27654. );
  27655. return {
  27656. name: payload.name,
  27657. selected: selected
  27658. };
  27659. });
  27660. });
  27661. };
  27662. /***/ },
  27663. /* 151 */
  27664. /***/ function(module, exports) {
  27665. // Pick color from palette for each data item.
  27666. // Applicable for charts that require applying color palette
  27667. // in data level (like pie, funnel, chord).
  27668. module.exports = function (seriesType, ecModel) {
  27669. // Pie and funnel may use diferrent scope
  27670. var paletteScope = {};
  27671. ecModel.eachRawSeriesByType(seriesType, function (seriesModel) {
  27672. var dataAll = seriesModel.getRawData();
  27673. var idxMap = {};
  27674. if (!ecModel.isSeriesFiltered(seriesModel)) {
  27675. var data = seriesModel.getData();
  27676. data.each(function (idx) {
  27677. var rawIdx = data.getRawIndex(idx);
  27678. idxMap[rawIdx] = idx;
  27679. });
  27680. dataAll.each(function (rawIdx) {
  27681. var filteredIdx = idxMap[rawIdx];
  27682. // If series.itemStyle.normal.color is a function. itemVisual may be encoded
  27683. var singleDataColor = filteredIdx != null
  27684. && data.getItemVisual(filteredIdx, 'color', true);
  27685. if (!singleDataColor) {
  27686. // FIXME Performance
  27687. var itemModel = dataAll.getItemModel(rawIdx);
  27688. var color = itemModel.get('itemStyle.normal.color')
  27689. || seriesModel.getColorFromPalette(dataAll.getName(rawIdx), paletteScope);
  27690. // Legend may use the visual info in data before processed
  27691. dataAll.setItemVisual(rawIdx, 'color', color);
  27692. // Data is not filtered
  27693. if (filteredIdx != null) {
  27694. data.setItemVisual(filteredIdx, 'color', color);
  27695. }
  27696. }
  27697. else {
  27698. // Set data all color for legend
  27699. dataAll.setItemVisual(rawIdx, 'color', singleDataColor);
  27700. }
  27701. });
  27702. }
  27703. });
  27704. };
  27705. /***/ },
  27706. /* 152 */
  27707. /***/ function(module, exports, __webpack_require__) {
  27708. var numberUtil = __webpack_require__(7);
  27709. var parsePercent = numberUtil.parsePercent;
  27710. var labelLayout = __webpack_require__(153);
  27711. var zrUtil = __webpack_require__(4);
  27712. var PI2 = Math.PI * 2;
  27713. var RADIAN = Math.PI / 180;
  27714. module.exports = function (seriesType, ecModel, api, payload) {
  27715. ecModel.eachSeriesByType(seriesType, function (seriesModel) {
  27716. var center = seriesModel.get('center');
  27717. var radius = seriesModel.get('radius');
  27718. if (!zrUtil.isArray(radius)) {
  27719. radius = [0, radius];
  27720. }
  27721. if (!zrUtil.isArray(center)) {
  27722. center = [center, center];
  27723. }
  27724. var width = api.getWidth();
  27725. var height = api.getHeight();
  27726. var size = Math.min(width, height);
  27727. var cx = parsePercent(center[0], width);
  27728. var cy = parsePercent(center[1], height);
  27729. var r0 = parsePercent(radius[0], size / 2);
  27730. var r = parsePercent(radius[1], size / 2);
  27731. var data = seriesModel.getData();
  27732. var startAngle = -seriesModel.get('startAngle') * RADIAN;
  27733. var minAngle = seriesModel.get('minAngle') * RADIAN;
  27734. var validDataCount = 0;
  27735. data.each('value', function (value) {
  27736. !isNaN(value) && validDataCount++;
  27737. });
  27738. var sum = data.getSum('value');
  27739. // Sum may be 0
  27740. var unitRadian = Math.PI / (sum || validDataCount) * 2;
  27741. var clockwise = seriesModel.get('clockwise');
  27742. var roseType = seriesModel.get('roseType');
  27743. var stillShowZeroSum = seriesModel.get('stillShowZeroSum');
  27744. // [0...max]
  27745. var extent = data.getDataExtent('value');
  27746. extent[0] = 0;
  27747. // In the case some sector angle is smaller than minAngle
  27748. var restAngle = PI2;
  27749. var valueSumLargerThanMinAngle = 0;
  27750. var currentAngle = startAngle;
  27751. var dir = clockwise ? 1 : -1;
  27752. data.each('value', function (value, idx) {
  27753. var angle;
  27754. if (isNaN(value)) {
  27755. data.setItemLayout(idx, {
  27756. angle: NaN,
  27757. startAngle: NaN,
  27758. endAngle: NaN,
  27759. clockwise: clockwise,
  27760. cx: cx,
  27761. cy: cy,
  27762. r0: r0,
  27763. r: roseType
  27764. ? NaN
  27765. : r
  27766. });
  27767. return;
  27768. }
  27769. // FIXME 兼容 2.0 但是 roseType 是 area 的时候才是这样?
  27770. if (roseType !== 'area') {
  27771. angle = (sum === 0 && stillShowZeroSum)
  27772. ? unitRadian : (value * unitRadian);
  27773. }
  27774. else {
  27775. angle = PI2 / validDataCount;
  27776. }
  27777. if (angle < minAngle) {
  27778. angle = minAngle;
  27779. restAngle -= minAngle;
  27780. }
  27781. else {
  27782. valueSumLargerThanMinAngle += value;
  27783. }
  27784. var endAngle = currentAngle + dir * angle;
  27785. data.setItemLayout(idx, {
  27786. angle: angle,
  27787. startAngle: currentAngle,
  27788. endAngle: endAngle,
  27789. clockwise: clockwise,
  27790. cx: cx,
  27791. cy: cy,
  27792. r0: r0,
  27793. r: roseType
  27794. ? numberUtil.linearMap(value, extent, [r0, r])
  27795. : r
  27796. });
  27797. currentAngle = endAngle;
  27798. }, true);
  27799. // Some sector is constrained by minAngle
  27800. // Rest sectors needs recalculate angle
  27801. if (restAngle < PI2 && validDataCount) {
  27802. // Average the angle if rest angle is not enough after all angles is
  27803. // Constrained by minAngle
  27804. if (restAngle <= 1e-3) {
  27805. var angle = PI2 / validDataCount;
  27806. data.each('value', function (value, idx) {
  27807. if (!isNaN(value)) {
  27808. var layout = data.getItemLayout(idx);
  27809. layout.angle = angle;
  27810. layout.startAngle = startAngle + dir * idx * angle;
  27811. layout.endAngle = startAngle + dir * (idx + 1) * angle;
  27812. }
  27813. });
  27814. }
  27815. else {
  27816. unitRadian = restAngle / valueSumLargerThanMinAngle;
  27817. currentAngle = startAngle;
  27818. data.each('value', function (value, idx) {
  27819. if (!isNaN(value)) {
  27820. var layout = data.getItemLayout(idx);
  27821. var angle = layout.angle === minAngle
  27822. ? minAngle : value * unitRadian;
  27823. layout.startAngle = currentAngle;
  27824. layout.endAngle = currentAngle + dir * angle;
  27825. currentAngle += dir * angle;
  27826. }
  27827. });
  27828. }
  27829. }
  27830. labelLayout(seriesModel, r, width, height);
  27831. });
  27832. };
  27833. /***/ },
  27834. /* 153 */
  27835. /***/ function(module, exports, __webpack_require__) {
  27836. 'use strict';
  27837. // FIXME emphasis label position is not same with normal label position
  27838. var textContain = __webpack_require__(8);
  27839. function adjustSingleSide(list, cx, cy, r, dir, viewWidth, viewHeight) {
  27840. list.sort(function (a, b) {
  27841. return a.y - b.y;
  27842. });
  27843. // 压
  27844. function shiftDown(start, end, delta, dir) {
  27845. for (var j = start; j < end; j++) {
  27846. list[j].y += delta;
  27847. if (j > start
  27848. && j + 1 < end
  27849. && list[j + 1].y > list[j].y + list[j].height
  27850. ) {
  27851. shiftUp(j, delta / 2);
  27852. return;
  27853. }
  27854. }
  27855. shiftUp(end - 1, delta / 2);
  27856. }
  27857. // 弹
  27858. function shiftUp(end, delta) {
  27859. for (var j = end; j >= 0; j--) {
  27860. list[j].y -= delta;
  27861. if (j > 0
  27862. && list[j].y > list[j - 1].y + list[j - 1].height
  27863. ) {
  27864. break;
  27865. }
  27866. }
  27867. }
  27868. function changeX(list, isDownList, cx, cy, r, dir) {
  27869. var lastDeltaX = dir > 0
  27870. ? isDownList // 右侧
  27871. ? Number.MAX_VALUE // 下
  27872. : 0 // 上
  27873. : isDownList // 左侧
  27874. ? Number.MAX_VALUE // 下
  27875. : 0; // 上
  27876. for (var i = 0, l = list.length; i < l; i++) {
  27877. // Not change x for center label
  27878. if (list[i].position === 'center') {
  27879. continue;
  27880. }
  27881. var deltaY = Math.abs(list[i].y - cy);
  27882. var length = list[i].len;
  27883. var length2 = list[i].len2;
  27884. var deltaX = (deltaY < r + length)
  27885. ? Math.sqrt(
  27886. (r + length + length2) * (r + length + length2)
  27887. - deltaY * deltaY
  27888. )
  27889. : Math.abs(list[i].x - cx);
  27890. if (isDownList && deltaX >= lastDeltaX) {
  27891. // 右下,左下
  27892. deltaX = lastDeltaX - 10;
  27893. }
  27894. if (!isDownList && deltaX <= lastDeltaX) {
  27895. // 右上,左上
  27896. deltaX = lastDeltaX + 10;
  27897. }
  27898. list[i].x = cx + deltaX * dir;
  27899. lastDeltaX = deltaX;
  27900. }
  27901. }
  27902. var lastY = 0;
  27903. var delta;
  27904. var len = list.length;
  27905. var upList = [];
  27906. var downList = [];
  27907. for (var i = 0; i < len; i++) {
  27908. delta = list[i].y - lastY;
  27909. if (delta < 0) {
  27910. shiftDown(i, len, -delta, dir);
  27911. }
  27912. lastY = list[i].y + list[i].height;
  27913. }
  27914. if (viewHeight - lastY < 0) {
  27915. shiftUp(len - 1, lastY - viewHeight);
  27916. }
  27917. for (var i = 0; i < len; i++) {
  27918. if (list[i].y >= cy) {
  27919. downList.push(list[i]);
  27920. }
  27921. else {
  27922. upList.push(list[i]);
  27923. }
  27924. }
  27925. changeX(upList, false, cx, cy, r, dir);
  27926. changeX(downList, true, cx, cy, r, dir);
  27927. }
  27928. function avoidOverlap(labelLayoutList, cx, cy, r, viewWidth, viewHeight) {
  27929. var leftList = [];
  27930. var rightList = [];
  27931. for (var i = 0; i < labelLayoutList.length; i++) {
  27932. if (labelLayoutList[i].x < cx) {
  27933. leftList.push(labelLayoutList[i]);
  27934. }
  27935. else {
  27936. rightList.push(labelLayoutList[i]);
  27937. }
  27938. }
  27939. adjustSingleSide(rightList, cx, cy, r, 1, viewWidth, viewHeight);
  27940. adjustSingleSide(leftList, cx, cy, r, -1, viewWidth, viewHeight);
  27941. for (var i = 0; i < labelLayoutList.length; i++) {
  27942. var linePoints = labelLayoutList[i].linePoints;
  27943. if (linePoints) {
  27944. var dist = linePoints[1][0] - linePoints[2][0];
  27945. if (labelLayoutList[i].x < cx) {
  27946. linePoints[2][0] = labelLayoutList[i].x + 3;
  27947. }
  27948. else {
  27949. linePoints[2][0] = labelLayoutList[i].x - 3;
  27950. }
  27951. linePoints[1][1] = linePoints[2][1] = labelLayoutList[i].y;
  27952. linePoints[1][0] = linePoints[2][0] + dist;
  27953. }
  27954. }
  27955. }
  27956. module.exports = function (seriesModel, r, viewWidth, viewHeight) {
  27957. var data = seriesModel.getData();
  27958. var labelLayoutList = [];
  27959. var cx;
  27960. var cy;
  27961. var hasLabelRotate = false;
  27962. data.each(function (idx) {
  27963. var layout = data.getItemLayout(idx);
  27964. var itemModel = data.getItemModel(idx);
  27965. var labelModel = itemModel.getModel('label.normal');
  27966. // Use position in normal or emphasis
  27967. var labelPosition = labelModel.get('position') || itemModel.get('label.emphasis.position');
  27968. var labelLineModel = itemModel.getModel('labelLine.normal');
  27969. var labelLineLen = labelLineModel.get('length');
  27970. var labelLineLen2 = labelLineModel.get('length2');
  27971. var midAngle = (layout.startAngle + layout.endAngle) / 2;
  27972. var dx = Math.cos(midAngle);
  27973. var dy = Math.sin(midAngle);
  27974. var textX;
  27975. var textY;
  27976. var linePoints;
  27977. var textAlign;
  27978. cx = layout.cx;
  27979. cy = layout.cy;
  27980. var isLabelInside = labelPosition === 'inside' || labelPosition === 'inner';
  27981. if (labelPosition === 'center') {
  27982. textX = layout.cx;
  27983. textY = layout.cy;
  27984. textAlign = 'center';
  27985. }
  27986. else {
  27987. var x1 = (isLabelInside ? (layout.r + layout.r0) / 2 * dx : layout.r * dx) + cx;
  27988. var y1 = (isLabelInside ? (layout.r + layout.r0) / 2 * dy : layout.r * dy) + cy;
  27989. textX = x1 + dx * 3;
  27990. textY = y1 + dy * 3;
  27991. if (!isLabelInside) {
  27992. // For roseType
  27993. var x2 = x1 + dx * (labelLineLen + r - layout.r);
  27994. var y2 = y1 + dy * (labelLineLen + r - layout.r);
  27995. var x3 = x2 + ((dx < 0 ? -1 : 1) * labelLineLen2);
  27996. var y3 = y2;
  27997. textX = x3 + (dx < 0 ? -5 : 5);
  27998. textY = y3;
  27999. linePoints = [[x1, y1], [x2, y2], [x3, y3]];
  28000. }
  28001. textAlign = isLabelInside ? 'center' : (dx > 0 ? 'left' : 'right');
  28002. }
  28003. var font = labelModel.getModel('textStyle').getFont();
  28004. var labelRotate = labelModel.get('rotate')
  28005. ? (dx < 0 ? -midAngle + Math.PI : -midAngle) : 0;
  28006. var text = seriesModel.getFormattedLabel(idx, 'normal')
  28007. || data.getName(idx);
  28008. var textRect = textContain.getBoundingRect(
  28009. text, font, textAlign, 'top'
  28010. );
  28011. hasLabelRotate = !!labelRotate;
  28012. layout.label = {
  28013. x: textX,
  28014. y: textY,
  28015. position: labelPosition,
  28016. height: textRect.height,
  28017. len: labelLineLen,
  28018. len2: labelLineLen2,
  28019. linePoints: linePoints,
  28020. textAlign: textAlign,
  28021. verticalAlign: 'middle',
  28022. font: font,
  28023. rotation: labelRotate
  28024. };
  28025. // Not layout the inside label
  28026. if (!isLabelInside) {
  28027. labelLayoutList.push(layout.label);
  28028. }
  28029. });
  28030. if (!hasLabelRotate && seriesModel.get('avoidLabelOverlap')) {
  28031. avoidOverlap(labelLayoutList, cx, cy, r, viewWidth, viewHeight);
  28032. }
  28033. };
  28034. /***/ },
  28035. /* 154 */
  28036. /***/ function(module, exports) {
  28037. module.exports = function (seriesType, ecModel) {
  28038. var legendModels = ecModel.findComponents({
  28039. mainType: 'legend'
  28040. });
  28041. if (!legendModels || !legendModels.length) {
  28042. return;
  28043. }
  28044. ecModel.eachSeriesByType(seriesType, function (series) {
  28045. var data = series.getData();
  28046. data.filterSelf(function (idx) {
  28047. var name = data.getName(idx);
  28048. // If in any legend component the status is not selected.
  28049. for (var i = 0; i < legendModels.length; i++) {
  28050. if (!legendModels[i].isSelected(name)) {
  28051. return false;
  28052. }
  28053. }
  28054. return true;
  28055. }, this);
  28056. }, this);
  28057. };
  28058. /***/ },
  28059. /* 155 */
  28060. /***/ function(module, exports, __webpack_require__) {
  28061. var zrUtil = __webpack_require__(4);
  28062. var echarts = __webpack_require__(1);
  28063. __webpack_require__(156);
  28064. __webpack_require__(157);
  28065. echarts.registerVisual(zrUtil.curry(
  28066. __webpack_require__(121), 'scatter', 'circle', null
  28067. ));
  28068. echarts.registerLayout(zrUtil.curry(
  28069. __webpack_require__(122), 'scatter'
  28070. ));
  28071. // In case developer forget to include grid component
  28072. __webpack_require__(124);
  28073. /***/ },
  28074. /* 156 */
  28075. /***/ function(module, exports, __webpack_require__) {
  28076. 'use strict';
  28077. var createListFromArray = __webpack_require__(109);
  28078. var SeriesModel = __webpack_require__(78);
  28079. module.exports = SeriesModel.extend({
  28080. type: 'series.scatter',
  28081. dependencies: ['grid', 'polar', 'geo', 'singleAxis', 'calendar'],
  28082. getInitialData: function (option, ecModel) {
  28083. return createListFromArray(option.data, this, ecModel);
  28084. },
  28085. brushSelector: 'point',
  28086. defaultOption: {
  28087. coordinateSystem: 'cartesian2d',
  28088. zlevel: 0,
  28089. z: 2,
  28090. legendHoverLink: true,
  28091. hoverAnimation: true,
  28092. // Cartesian coordinate system
  28093. // xAxisIndex: 0,
  28094. // yAxisIndex: 0,
  28095. // Polar coordinate system
  28096. // polarIndex: 0,
  28097. // Geo coordinate system
  28098. // geoIndex: 0,
  28099. // symbol: null, // 图形类型
  28100. symbolSize: 10, // 图形大小,半宽(半径)参数,当图形为方向或菱形则总宽度为symbolSize * 2
  28101. // symbolRotate: null, // 图形旋转控制
  28102. large: false,
  28103. // Available when large is true
  28104. largeThreshold: 2000,
  28105. // label: {
  28106. // normal: {
  28107. // show: false
  28108. // distance: 5,
  28109. // formatter: 标签文本格式器,同Tooltip.formatter,不支持异步回调
  28110. // position: 默认自适应,水平布局为'top',垂直布局为'right',可选为
  28111. // 'inside'|'left'|'right'|'top'|'bottom'
  28112. // textStyle: null // 默认使用全局文本样式,详见TEXTSTYLE
  28113. // }
  28114. // },
  28115. itemStyle: {
  28116. normal: {
  28117. opacity: 0.8
  28118. // color: 各异
  28119. }
  28120. }
  28121. }
  28122. });
  28123. /***/ },
  28124. /* 157 */
  28125. /***/ function(module, exports, __webpack_require__) {
  28126. var SymbolDraw = __webpack_require__(116);
  28127. var LargeSymbolDraw = __webpack_require__(158);
  28128. __webpack_require__(1).extendChartView({
  28129. type: 'scatter',
  28130. init: function () {
  28131. this._normalSymbolDraw = new SymbolDraw();
  28132. this._largeSymbolDraw = new LargeSymbolDraw();
  28133. },
  28134. render: function (seriesModel, ecModel, api) {
  28135. var data = seriesModel.getData();
  28136. var largeSymbolDraw = this._largeSymbolDraw;
  28137. var normalSymbolDraw = this._normalSymbolDraw;
  28138. var group = this.group;
  28139. var symbolDraw = seriesModel.get('large') && data.count() > seriesModel.get('largeThreshold')
  28140. ? largeSymbolDraw : normalSymbolDraw;
  28141. this._symbolDraw = symbolDraw;
  28142. symbolDraw.updateData(data);
  28143. group.add(symbolDraw.group);
  28144. group.remove(
  28145. symbolDraw === largeSymbolDraw
  28146. ? normalSymbolDraw.group : largeSymbolDraw.group
  28147. );
  28148. },
  28149. updateLayout: function (seriesModel) {
  28150. this._symbolDraw.updateLayout(seriesModel);
  28151. },
  28152. remove: function (ecModel, api) {
  28153. this._symbolDraw && this._symbolDraw.remove(api, true);
  28154. },
  28155. dispose: function () {}
  28156. });
  28157. /***/ },
  28158. /* 158 */
  28159. /***/ function(module, exports, __webpack_require__) {
  28160. // TODO Batch by color
  28161. var graphic = __webpack_require__(18);
  28162. var symbolUtil = __webpack_require__(111);
  28163. var LargeSymbolPath = graphic.extendShape({
  28164. shape: {
  28165. points: null,
  28166. sizes: null
  28167. },
  28168. symbolProxy: null,
  28169. buildPath: function (path, shape) {
  28170. var points = shape.points;
  28171. var sizes = shape.sizes;
  28172. var symbolProxy = this.symbolProxy;
  28173. var symbolProxyShape = symbolProxy.shape;
  28174. for (var i = 0; i < points.length; i++) {
  28175. var pt = points[i];
  28176. var size = sizes[i];
  28177. if (size[0] < 4) {
  28178. // Optimize for small symbol
  28179. path.rect(
  28180. pt[0] - size[0] / 2, pt[1] - size[1] / 2,
  28181. size[0], size[1]
  28182. );
  28183. }
  28184. else {
  28185. symbolProxyShape.x = pt[0] - size[0] / 2;
  28186. symbolProxyShape.y = pt[1] - size[1] / 2;
  28187. symbolProxyShape.width = size[0];
  28188. symbolProxyShape.height = size[1];
  28189. symbolProxy.buildPath(path, symbolProxyShape, true);
  28190. }
  28191. }
  28192. },
  28193. findDataIndex: function (x, y) {
  28194. var shape = this.shape;
  28195. var points = shape.points;
  28196. var sizes = shape.sizes;
  28197. // Not consider transform
  28198. // Treat each element as a rect
  28199. // top down traverse
  28200. for (var i = points.length - 1; i >= 0; i--) {
  28201. var pt = points[i];
  28202. var size = sizes[i];
  28203. var x0 = pt[0] - size[0] / 2;
  28204. var y0 = pt[1] - size[1] / 2;
  28205. if (x >= x0 && y >= y0 && x <= x0 + size[0] && y <= y0 + size[1]) {
  28206. // i is dataIndex
  28207. return i;
  28208. }
  28209. }
  28210. return -1;
  28211. }
  28212. });
  28213. function LargeSymbolDraw() {
  28214. this.group = new graphic.Group();
  28215. this._symbolEl = new LargeSymbolPath({
  28216. // rectHover: true,
  28217. // cursor: 'default'
  28218. });
  28219. }
  28220. var largeSymbolProto = LargeSymbolDraw.prototype;
  28221. /**
  28222. * Update symbols draw by new data
  28223. * @param {module:echarts/data/List} data
  28224. */
  28225. largeSymbolProto.updateData = function (data) {
  28226. this.group.removeAll();
  28227. var symbolEl = this._symbolEl;
  28228. var seriesModel = data.hostModel;
  28229. symbolEl.setShape({
  28230. points: data.mapArray(data.getItemLayout),
  28231. sizes: data.mapArray(
  28232. function (idx) {
  28233. var size = data.getItemVisual(idx, 'symbolSize');
  28234. if (!(size instanceof Array)) {
  28235. size = [size, size];
  28236. }
  28237. return size;
  28238. }
  28239. )
  28240. });
  28241. // Create symbolProxy to build path for each data
  28242. symbolEl.symbolProxy = symbolUtil.createSymbol(
  28243. data.getVisual('symbol'), 0, 0, 0, 0
  28244. );
  28245. // Use symbolProxy setColor method
  28246. symbolEl.setColor = symbolEl.symbolProxy.setColor;
  28247. symbolEl.useStyle(
  28248. seriesModel.getModel('itemStyle.normal').getItemStyle(['color'])
  28249. );
  28250. var visualColor = data.getVisual('color');
  28251. if (visualColor) {
  28252. symbolEl.setColor(visualColor);
  28253. }
  28254. // Enable tooltip
  28255. // PENDING May have performance issue when path is extremely large
  28256. symbolEl.seriesIndex = seriesModel.seriesIndex;
  28257. symbolEl.on('mousemove', function (e) {
  28258. symbolEl.dataIndex = null;
  28259. var dataIndex = symbolEl.findDataIndex(e.offsetX, e.offsetY);
  28260. if (dataIndex > 0) {
  28261. // Provide dataIndex for tooltip
  28262. symbolEl.dataIndex = dataIndex;
  28263. }
  28264. });
  28265. // Add back
  28266. this.group.add(symbolEl);
  28267. };
  28268. largeSymbolProto.updateLayout = function (seriesModel) {
  28269. var data = seriesModel.getData();
  28270. this._symbolEl.setShape({
  28271. points: data.mapArray(data.getItemLayout)
  28272. });
  28273. };
  28274. largeSymbolProto.remove = function () {
  28275. this.group.removeAll();
  28276. };
  28277. module.exports = LargeSymbolDraw;
  28278. /***/ },
  28279. /* 159 */
  28280. /***/ function(module, exports, __webpack_require__) {
  28281. var zrUtil = __webpack_require__(4);
  28282. var echarts = __webpack_require__(1);
  28283. // Must use radar component
  28284. __webpack_require__(160);
  28285. __webpack_require__(165);
  28286. __webpack_require__(166);
  28287. echarts.registerVisual(zrUtil.curry(__webpack_require__(151), 'radar'));
  28288. echarts.registerVisual(zrUtil.curry(
  28289. __webpack_require__(121), 'radar', 'circle', null
  28290. ));
  28291. echarts.registerLayout(__webpack_require__(167));
  28292. echarts.registerProcessor(
  28293. zrUtil.curry(__webpack_require__(154), 'radar')
  28294. );
  28295. echarts.registerPreprocessor(__webpack_require__(168));
  28296. /***/ },
  28297. /* 160 */
  28298. /***/ function(module, exports, __webpack_require__) {
  28299. __webpack_require__(161);
  28300. __webpack_require__(163);
  28301. __webpack_require__(164);
  28302. /***/ },
  28303. /* 161 */
  28304. /***/ function(module, exports, __webpack_require__) {
  28305. // TODO clockwise
  28306. var zrUtil = __webpack_require__(4);
  28307. var IndicatorAxis = __webpack_require__(162);
  28308. var IntervalScale = __webpack_require__(104);
  28309. var numberUtil = __webpack_require__(7);
  28310. var axisHelper = __webpack_require__(101);
  28311. function Radar(radarModel, ecModel, api) {
  28312. this._model = radarModel;
  28313. /**
  28314. * Radar dimensions
  28315. * @type {Array.<string>}
  28316. */
  28317. this.dimensions = [];
  28318. this._indicatorAxes = zrUtil.map(radarModel.getIndicatorModels(), function (indicatorModel, idx) {
  28319. var dim = 'indicator_' + idx;
  28320. var indicatorAxis = new IndicatorAxis(dim, new IntervalScale());
  28321. indicatorAxis.name = indicatorModel.get('name');
  28322. // Inject model and axis
  28323. indicatorAxis.model = indicatorModel;
  28324. indicatorModel.axis = indicatorAxis;
  28325. this.dimensions.push(dim);
  28326. return indicatorAxis;
  28327. }, this);
  28328. this.resize(radarModel, api);
  28329. /**
  28330. * @type {number}
  28331. * @readOnly
  28332. */
  28333. this.cx;
  28334. /**
  28335. * @type {number}
  28336. * @readOnly
  28337. */
  28338. this.cy;
  28339. /**
  28340. * @type {number}
  28341. * @readOnly
  28342. */
  28343. this.r;
  28344. /**
  28345. * @type {number}
  28346. * @readOnly
  28347. */
  28348. this.startAngle;
  28349. }
  28350. Radar.prototype.getIndicatorAxes = function () {
  28351. return this._indicatorAxes;
  28352. };
  28353. Radar.prototype.dataToPoint = function (value, indicatorIndex) {
  28354. var indicatorAxis = this._indicatorAxes[indicatorIndex];
  28355. return this.coordToPoint(indicatorAxis.dataToCoord(value), indicatorIndex);
  28356. };
  28357. Radar.prototype.coordToPoint = function (coord, indicatorIndex) {
  28358. var indicatorAxis = this._indicatorAxes[indicatorIndex];
  28359. var angle = indicatorAxis.angle;
  28360. var x = this.cx + coord * Math.cos(angle);
  28361. var y = this.cy - coord * Math.sin(angle);
  28362. return [x, y];
  28363. };
  28364. Radar.prototype.pointToData = function (pt) {
  28365. var dx = pt[0] - this.cx;
  28366. var dy = pt[1] - this.cy;
  28367. var radius = Math.sqrt(dx * dx + dy * dy);
  28368. dx /= radius;
  28369. dy /= radius;
  28370. var radian = Math.atan2(-dy, dx);
  28371. // Find the closest angle
  28372. // FIXME index can calculated directly
  28373. var minRadianDiff = Infinity;
  28374. var closestAxis;
  28375. var closestAxisIdx = -1;
  28376. for (var i = 0; i < this._indicatorAxes.length; i++) {
  28377. var indicatorAxis = this._indicatorAxes[i];
  28378. var diff = Math.abs(radian - indicatorAxis.angle);
  28379. if (diff < minRadianDiff) {
  28380. closestAxis = indicatorAxis;
  28381. closestAxisIdx = i;
  28382. minRadianDiff = diff;
  28383. }
  28384. }
  28385. return [closestAxisIdx, +(closestAxis && closestAxis.coodToData(radius))];
  28386. };
  28387. Radar.prototype.resize = function (radarModel, api) {
  28388. var center = radarModel.get('center');
  28389. var viewWidth = api.getWidth();
  28390. var viewHeight = api.getHeight();
  28391. var viewSize = Math.min(viewWidth, viewHeight) / 2;
  28392. this.cx = numberUtil.parsePercent(center[0], viewWidth);
  28393. this.cy = numberUtil.parsePercent(center[1], viewHeight);
  28394. this.startAngle = radarModel.get('startAngle') * Math.PI / 180;
  28395. this.r = numberUtil.parsePercent(radarModel.get('radius'), viewSize);
  28396. zrUtil.each(this._indicatorAxes, function (indicatorAxis, idx) {
  28397. indicatorAxis.setExtent(0, this.r);
  28398. var angle = (this.startAngle + idx * Math.PI * 2 / this._indicatorAxes.length);
  28399. // Normalize to [-PI, PI]
  28400. angle = Math.atan2(Math.sin(angle), Math.cos(angle));
  28401. indicatorAxis.angle = angle;
  28402. }, this);
  28403. };
  28404. Radar.prototype.update = function (ecModel, api) {
  28405. var indicatorAxes = this._indicatorAxes;
  28406. var radarModel = this._model;
  28407. zrUtil.each(indicatorAxes, function (indicatorAxis) {
  28408. indicatorAxis.scale.setExtent(Infinity, -Infinity);
  28409. });
  28410. ecModel.eachSeriesByType('radar', function (radarSeries, idx) {
  28411. if (radarSeries.get('coordinateSystem') !== 'radar'
  28412. || ecModel.getComponent('radar', radarSeries.get('radarIndex')) !== radarModel
  28413. ) {
  28414. return;
  28415. }
  28416. var data = radarSeries.getData();
  28417. zrUtil.each(indicatorAxes, function (indicatorAxis) {
  28418. indicatorAxis.scale.unionExtentFromData(data, indicatorAxis.dim);
  28419. });
  28420. }, this);
  28421. var splitNumber = radarModel.get('splitNumber');
  28422. function increaseInterval(interval) {
  28423. var exp10 = Math.pow(10, Math.floor(Math.log(interval) / Math.LN10));
  28424. // Increase interval
  28425. var f = interval / exp10;
  28426. if (f === 2) {
  28427. f = 5;
  28428. }
  28429. else { // f is 2 or 5
  28430. f *= 2;
  28431. }
  28432. return f * exp10;
  28433. }
  28434. // Force all the axis fixing the maxSplitNumber.
  28435. zrUtil.each(indicatorAxes, function (indicatorAxis, idx) {
  28436. var rawExtent = axisHelper.getScaleExtent(indicatorAxis.scale, indicatorAxis.model);
  28437. axisHelper.niceScaleExtent(indicatorAxis.scale, indicatorAxis.model);
  28438. var axisModel = indicatorAxis.model;
  28439. var scale = indicatorAxis.scale;
  28440. var fixedMin = axisModel.getMin();
  28441. var fixedMax = axisModel.getMax();
  28442. var interval = scale.getInterval();
  28443. if (fixedMin != null && fixedMax != null) {
  28444. // User set min, max, divide to get new interval
  28445. // FIXME precision
  28446. scale.setInterval(
  28447. (fixedMax - fixedMin) / splitNumber
  28448. );
  28449. }
  28450. else if (fixedMin != null) {
  28451. var max;
  28452. // User set min, expand extent on the other side
  28453. do {
  28454. max = fixedMin + interval * splitNumber;
  28455. scale.setExtent(+fixedMin, max);
  28456. // Interval must been set after extent
  28457. // FIXME
  28458. scale.setInterval(interval);
  28459. interval = increaseInterval(interval);
  28460. } while (max < rawExtent[1] && isFinite(max) && isFinite(rawExtent[1]));
  28461. }
  28462. else if (fixedMax != null) {
  28463. var min;
  28464. // User set min, expand extent on the other side
  28465. do {
  28466. min = fixedMax - interval * splitNumber;
  28467. scale.setExtent(min, +fixedMax);
  28468. scale.setInterval(interval);
  28469. interval = increaseInterval(interval);
  28470. } while (min > rawExtent[0] && isFinite(min) && isFinite(rawExtent[0]));
  28471. }
  28472. else {
  28473. var nicedSplitNumber = scale.getTicks().length - 1;
  28474. if (nicedSplitNumber > splitNumber) {
  28475. interval = increaseInterval(interval);
  28476. }
  28477. // PENDING
  28478. var center = Math.round((rawExtent[0] + rawExtent[1]) / 2 / interval) * interval;
  28479. var halfSplitNumber = Math.round(splitNumber / 2);
  28480. scale.setExtent(
  28481. numberUtil.round(center - halfSplitNumber * interval),
  28482. numberUtil.round(center + (splitNumber - halfSplitNumber) * interval)
  28483. );
  28484. scale.setInterval(interval);
  28485. }
  28486. });
  28487. };
  28488. /**
  28489. * Radar dimensions is based on the data
  28490. * @type {Array}
  28491. */
  28492. Radar.dimensions = [];
  28493. Radar.create = function (ecModel, api) {
  28494. var radarList = [];
  28495. ecModel.eachComponent('radar', function (radarModel) {
  28496. var radar = new Radar(radarModel, ecModel, api);
  28497. radarList.push(radar);
  28498. radarModel.coordinateSystem = radar;
  28499. });
  28500. ecModel.eachSeriesByType('radar', function (radarSeries) {
  28501. if (radarSeries.get('coordinateSystem') === 'radar') {
  28502. // Inject coordinate system
  28503. radarSeries.coordinateSystem = radarList[radarSeries.get('radarIndex') || 0];
  28504. }
  28505. });
  28506. return radarList;
  28507. };
  28508. __webpack_require__(76).register('radar', Radar);
  28509. module.exports = Radar;
  28510. /***/ },
  28511. /* 162 */
  28512. /***/ function(module, exports, __webpack_require__) {
  28513. var zrUtil = __webpack_require__(4);
  28514. var Axis = __webpack_require__(100);
  28515. function IndicatorAxis(dim, scale, radiusExtent) {
  28516. Axis.call(this, dim, scale, radiusExtent);
  28517. /**
  28518. * Axis type
  28519. * - 'category'
  28520. * - 'value'
  28521. * - 'time'
  28522. * - 'log'
  28523. * @type {string}
  28524. */
  28525. this.type = 'value';
  28526. this.angle = 0;
  28527. /**
  28528. * Indicator name
  28529. * @type {string}
  28530. */
  28531. this.name = '';
  28532. /**
  28533. * @type {module:echarts/model/Model}
  28534. */
  28535. this.model;
  28536. }
  28537. zrUtil.inherits(IndicatorAxis, Axis);
  28538. module.exports = IndicatorAxis;
  28539. /***/ },
  28540. /* 163 */
  28541. /***/ function(module, exports, __webpack_require__) {
  28542. var axisDefault = __webpack_require__(132);
  28543. var valueAxisDefault = axisDefault.valueAxis;
  28544. var Model = __webpack_require__(12);
  28545. var zrUtil = __webpack_require__(4);
  28546. var axisModelCommonMixin = __webpack_require__(112);
  28547. function defaultsShow(opt, show) {
  28548. return zrUtil.defaults({
  28549. show: show
  28550. }, opt);
  28551. }
  28552. var RadarModel = __webpack_require__(1).extendComponentModel({
  28553. type: 'radar',
  28554. optionUpdated: function () {
  28555. var boundaryGap = this.get('boundaryGap');
  28556. var splitNumber = this.get('splitNumber');
  28557. var scale = this.get('scale');
  28558. var axisLine = this.get('axisLine');
  28559. var axisTick = this.get('axisTick');
  28560. var axisLabel = this.get('axisLabel');
  28561. var nameTextStyle = this.get('name.textStyle');
  28562. var showName = this.get('name.show');
  28563. var nameFormatter = this.get('name.formatter');
  28564. var nameGap = this.get('nameGap');
  28565. var triggerEvent = this.get('triggerEvent');
  28566. var indicatorModels = zrUtil.map(this.get('indicator') || [], function (indicatorOpt) {
  28567. // PENDING
  28568. if (indicatorOpt.max != null && indicatorOpt.max > 0 && !indicatorOpt.min) {
  28569. indicatorOpt.min = 0;
  28570. }
  28571. else if (indicatorOpt.min != null && indicatorOpt.min < 0 && !indicatorOpt.max) {
  28572. indicatorOpt.max = 0;
  28573. }
  28574. // Use same configuration
  28575. indicatorOpt = zrUtil.merge(zrUtil.clone(indicatorOpt), {
  28576. boundaryGap: boundaryGap,
  28577. splitNumber: splitNumber,
  28578. scale: scale,
  28579. axisLine: axisLine,
  28580. axisTick: axisTick,
  28581. axisLabel: axisLabel,
  28582. // Competitable with 2 and use text
  28583. name: indicatorOpt.text,
  28584. nameLocation: 'end',
  28585. nameGap: nameGap,
  28586. // min: 0,
  28587. nameTextStyle: nameTextStyle,
  28588. triggerEvent: triggerEvent
  28589. }, false);
  28590. if (!showName) {
  28591. indicatorOpt.name = '';
  28592. }
  28593. if (typeof nameFormatter === 'string') {
  28594. var indName = indicatorOpt.name;
  28595. indicatorOpt.name = nameFormatter.replace('{value}', indName != null ? indName : '');
  28596. }
  28597. else if (typeof nameFormatter === 'function') {
  28598. indicatorOpt.name = nameFormatter(
  28599. indicatorOpt.name, indicatorOpt
  28600. );
  28601. }
  28602. var model = zrUtil.extend(
  28603. new Model(indicatorOpt, null, this.ecModel),
  28604. axisModelCommonMixin
  28605. );
  28606. // For triggerEvent.
  28607. model.mainType = 'radar';
  28608. model.componentIndex = this.componentIndex;
  28609. return model;
  28610. }, this);
  28611. this.getIndicatorModels = function () {
  28612. return indicatorModels;
  28613. };
  28614. },
  28615. defaultOption: {
  28616. zlevel: 0,
  28617. z: 0,
  28618. center: ['50%', '50%'],
  28619. radius: '75%',
  28620. startAngle: 90,
  28621. name: {
  28622. show: true
  28623. // formatter: null
  28624. // textStyle: {}
  28625. },
  28626. boundaryGap: [0, 0],
  28627. splitNumber: 5,
  28628. nameGap: 15,
  28629. scale: false,
  28630. // Polygon or circle
  28631. shape: 'polygon',
  28632. axisLine: zrUtil.merge(
  28633. {
  28634. lineStyle: {
  28635. color: '#bbb'
  28636. }
  28637. },
  28638. valueAxisDefault.axisLine
  28639. ),
  28640. axisLabel: defaultsShow(valueAxisDefault.axisLabel, false),
  28641. axisTick: defaultsShow(valueAxisDefault.axisTick, false),
  28642. splitLine: defaultsShow(valueAxisDefault.splitLine, true),
  28643. splitArea: defaultsShow(valueAxisDefault.splitArea, true),
  28644. // {text, min, max}
  28645. indicator: []
  28646. }
  28647. });
  28648. module.exports = RadarModel;
  28649. /***/ },
  28650. /* 164 */
  28651. /***/ function(module, exports, __webpack_require__) {
  28652. var AxisBuilder = __webpack_require__(135);
  28653. var zrUtil = __webpack_require__(4);
  28654. var graphic = __webpack_require__(18);
  28655. var axisBuilderAttrs = [
  28656. 'axisLine', 'axisLabel', 'axisTick', 'axisName'
  28657. ];
  28658. module.exports = __webpack_require__(1).extendComponentView({
  28659. type: 'radar',
  28660. render: function (radarModel, ecModel, api) {
  28661. var group = this.group;
  28662. group.removeAll();
  28663. this._buildAxes(radarModel);
  28664. this._buildSplitLineAndArea(radarModel);
  28665. },
  28666. _buildAxes: function (radarModel) {
  28667. var radar = radarModel.coordinateSystem;
  28668. var indicatorAxes = radar.getIndicatorAxes();
  28669. var axisBuilders = zrUtil.map(indicatorAxes, function (indicatorAxis) {
  28670. var axisBuilder = new AxisBuilder(indicatorAxis.model, {
  28671. position: [radar.cx, radar.cy],
  28672. rotation: indicatorAxis.angle,
  28673. labelDirection: -1,
  28674. tickDirection: -1,
  28675. nameDirection: 1
  28676. });
  28677. return axisBuilder;
  28678. });
  28679. zrUtil.each(axisBuilders, function (axisBuilder) {
  28680. zrUtil.each(axisBuilderAttrs, axisBuilder.add, axisBuilder);
  28681. this.group.add(axisBuilder.getGroup());
  28682. }, this);
  28683. },
  28684. _buildSplitLineAndArea: function (radarModel) {
  28685. var radar = radarModel.coordinateSystem;
  28686. var indicatorAxes = radar.getIndicatorAxes();
  28687. if (!indicatorAxes.length) {
  28688. return;
  28689. }
  28690. var shape = radarModel.get('shape');
  28691. var splitLineModel = radarModel.getModel('splitLine');
  28692. var splitAreaModel = radarModel.getModel('splitArea');
  28693. var lineStyleModel = splitLineModel.getModel('lineStyle');
  28694. var areaStyleModel = splitAreaModel.getModel('areaStyle');
  28695. var showSplitLine = splitLineModel.get('show');
  28696. var showSplitArea = splitAreaModel.get('show');
  28697. var splitLineColors = lineStyleModel.get('color');
  28698. var splitAreaColors = areaStyleModel.get('color');
  28699. splitLineColors = zrUtil.isArray(splitLineColors) ? splitLineColors : [splitLineColors];
  28700. splitAreaColors = zrUtil.isArray(splitAreaColors) ? splitAreaColors : [splitAreaColors];
  28701. var splitLines = [];
  28702. var splitAreas = [];
  28703. function getColorIndex(areaOrLine, areaOrLineColorList, idx) {
  28704. var colorIndex = idx % areaOrLineColorList.length;
  28705. areaOrLine[colorIndex] = areaOrLine[colorIndex] || [];
  28706. return colorIndex;
  28707. }
  28708. if (shape === 'circle') {
  28709. var ticksRadius = indicatorAxes[0].getTicksCoords();
  28710. var cx = radar.cx;
  28711. var cy = radar.cy;
  28712. for (var i = 0; i < ticksRadius.length; i++) {
  28713. if (showSplitLine) {
  28714. var colorIndex = getColorIndex(splitLines, splitLineColors, i);
  28715. splitLines[colorIndex].push(new graphic.Circle({
  28716. shape: {
  28717. cx: cx,
  28718. cy: cy,
  28719. r: ticksRadius[i]
  28720. }
  28721. }));
  28722. }
  28723. if (showSplitArea && i < ticksRadius.length - 1) {
  28724. var colorIndex = getColorIndex(splitAreas, splitAreaColors, i);
  28725. splitAreas[colorIndex].push(new graphic.Ring({
  28726. shape: {
  28727. cx: cx,
  28728. cy: cy,
  28729. r0: ticksRadius[i],
  28730. r: ticksRadius[i + 1]
  28731. }
  28732. }));
  28733. }
  28734. }
  28735. }
  28736. // Polyyon
  28737. else {
  28738. var realSplitNumber = -1;
  28739. var axesTicksPoints = zrUtil.map(indicatorAxes, function (indicatorAxis, idx) {
  28740. var ticksCoords = indicatorAxis.getTicksCoords();
  28741. realSplitNumber = Math.max(ticksCoords.length - 1, realSplitNumber);
  28742. return zrUtil.map(ticksCoords, function (tickCoord) {
  28743. return radar.coordToPoint(tickCoord, idx);
  28744. });
  28745. });
  28746. var prevPoints = [];
  28747. for (var i = 0; i <= realSplitNumber; i++) {
  28748. var points = [];
  28749. for (var j = 0; j < indicatorAxes.length; j++) {
  28750. points.push(axesTicksPoints[j][i]);
  28751. }
  28752. // Close
  28753. if (points[0]) {
  28754. points.push(points[0].slice());
  28755. }
  28756. else {
  28757. if (true) {
  28758. console.error('Can\'t draw value axis ' + i);
  28759. }
  28760. }
  28761. if (showSplitLine) {
  28762. var colorIndex = getColorIndex(splitLines, splitLineColors, i);
  28763. splitLines[colorIndex].push(new graphic.Polyline({
  28764. shape: {
  28765. points: points
  28766. }
  28767. }));
  28768. }
  28769. if (showSplitArea && prevPoints) {
  28770. var colorIndex = getColorIndex(splitAreas, splitAreaColors, i - 1);
  28771. splitAreas[colorIndex].push(new graphic.Polygon({
  28772. shape: {
  28773. points: points.concat(prevPoints)
  28774. }
  28775. }));
  28776. }
  28777. prevPoints = points.slice().reverse();
  28778. }
  28779. }
  28780. var lineStyle = lineStyleModel.getLineStyle();
  28781. var areaStyle = areaStyleModel.getAreaStyle();
  28782. // Add splitArea before splitLine
  28783. zrUtil.each(splitAreas, function (splitAreas, idx) {
  28784. this.group.add(graphic.mergePath(
  28785. splitAreas, {
  28786. style: zrUtil.defaults({
  28787. stroke: 'none',
  28788. fill: splitAreaColors[idx % splitAreaColors.length]
  28789. }, areaStyle),
  28790. silent: true
  28791. }
  28792. ));
  28793. }, this);
  28794. zrUtil.each(splitLines, function (splitLines, idx) {
  28795. this.group.add(graphic.mergePath(
  28796. splitLines, {
  28797. style: zrUtil.defaults({
  28798. fill: 'none',
  28799. stroke: splitLineColors[idx % splitLineColors.length]
  28800. }, lineStyle),
  28801. silent: true
  28802. }
  28803. ));
  28804. }, this);
  28805. }
  28806. });
  28807. /***/ },
  28808. /* 165 */
  28809. /***/ function(module, exports, __webpack_require__) {
  28810. 'use strict';
  28811. var SeriesModel = __webpack_require__(78);
  28812. var List = __webpack_require__(98);
  28813. var completeDimensions = __webpack_require__(110);
  28814. var zrUtil = __webpack_require__(4);
  28815. var encodeHTML = __webpack_require__(6).encodeHTML;
  28816. var RadarSeries = SeriesModel.extend({
  28817. type: 'series.radar',
  28818. dependencies: ['radar'],
  28819. // Overwrite
  28820. init: function (option) {
  28821. RadarSeries.superApply(this, 'init', arguments);
  28822. // Enable legend selection for each data item
  28823. // Use a function instead of direct access because data reference may changed
  28824. this.legendDataProvider = function () {
  28825. return this.getRawData();
  28826. };
  28827. },
  28828. getInitialData: function (option, ecModel) {
  28829. var data = option.data || [];
  28830. var dimensions = completeDimensions(
  28831. [], data, {extraPrefix: 'indicator_', extraFromZero: true}
  28832. );
  28833. var list = new List(dimensions, this);
  28834. list.initData(data);
  28835. return list;
  28836. },
  28837. formatTooltip: function (dataIndex) {
  28838. var value = this.getRawValue(dataIndex);
  28839. var coordSys = this.coordinateSystem;
  28840. var indicatorAxes = coordSys.getIndicatorAxes();
  28841. var name = this.getData().getName(dataIndex);
  28842. return encodeHTML(name === '' ? this.name : name) + '<br/>'
  28843. + zrUtil.map(indicatorAxes, function (axis, idx) {
  28844. return encodeHTML(axis.name + ' : ' + value[idx]);
  28845. }).join('<br />');
  28846. },
  28847. defaultOption: {
  28848. zlevel: 0,
  28849. z: 2,
  28850. coordinateSystem: 'radar',
  28851. legendHoverLink: true,
  28852. radarIndex: 0,
  28853. lineStyle: {
  28854. normal: {
  28855. width: 2,
  28856. type: 'solid'
  28857. }
  28858. },
  28859. label: {
  28860. normal: {
  28861. position: 'top'
  28862. }
  28863. },
  28864. // areaStyle: {
  28865. // },
  28866. // itemStyle: {}
  28867. symbol: 'emptyCircle',
  28868. symbolSize: 4
  28869. // symbolRotate: null
  28870. }
  28871. });
  28872. module.exports = RadarSeries;
  28873. /***/ },
  28874. /* 166 */
  28875. /***/ function(module, exports, __webpack_require__) {
  28876. var graphic = __webpack_require__(18);
  28877. var zrUtil = __webpack_require__(4);
  28878. var symbolUtil = __webpack_require__(111);
  28879. function normalizeSymbolSize(symbolSize) {
  28880. if (!zrUtil.isArray(symbolSize)) {
  28881. symbolSize = [+symbolSize, +symbolSize];
  28882. }
  28883. return symbolSize;
  28884. }
  28885. module.exports = __webpack_require__(1).extendChartView({
  28886. type: 'radar',
  28887. render: function (seriesModel, ecModel, api) {
  28888. var polar = seriesModel.coordinateSystem;
  28889. var group = this.group;
  28890. var data = seriesModel.getData();
  28891. var oldData = this._data;
  28892. function createSymbol(data, idx) {
  28893. var symbolType = data.getItemVisual(idx, 'symbol') || 'circle';
  28894. var color = data.getItemVisual(idx, 'color');
  28895. if (symbolType === 'none') {
  28896. return;
  28897. }
  28898. var symbolPath = symbolUtil.createSymbol(
  28899. symbolType, -0.5, -0.5, 1, 1, color
  28900. );
  28901. symbolPath.attr({
  28902. style: {
  28903. strokeNoScale: true
  28904. },
  28905. z2: 100,
  28906. scale: normalizeSymbolSize(data.getItemVisual(idx, 'symbolSize'))
  28907. });
  28908. return symbolPath;
  28909. }
  28910. function updateSymbols(oldPoints, newPoints, symbolGroup, data, idx, isInit) {
  28911. // Simply rerender all
  28912. symbolGroup.removeAll();
  28913. for (var i = 0; i < newPoints.length - 1; i++) {
  28914. var symbolPath = createSymbol(data, idx);
  28915. if (symbolPath) {
  28916. symbolPath.__dimIdx = i;
  28917. if (oldPoints[i]) {
  28918. symbolPath.attr('position', oldPoints[i]);
  28919. graphic[isInit ? 'initProps' : 'updateProps'](
  28920. symbolPath, {
  28921. position: newPoints[i]
  28922. }, seriesModel, idx
  28923. );
  28924. }
  28925. else {
  28926. symbolPath.attr('position', newPoints[i]);
  28927. }
  28928. symbolGroup.add(symbolPath);
  28929. }
  28930. }
  28931. }
  28932. function getInitialPoints(points) {
  28933. return zrUtil.map(points, function (pt) {
  28934. return [polar.cx, polar.cy];
  28935. });
  28936. }
  28937. data.diff(oldData)
  28938. .add(function (idx) {
  28939. var points = data.getItemLayout(idx);
  28940. if (!points) {
  28941. return;
  28942. }
  28943. var polygon = new graphic.Polygon();
  28944. var polyline = new graphic.Polyline();
  28945. var target = {
  28946. shape: {
  28947. points: points
  28948. }
  28949. };
  28950. polygon.shape.points = getInitialPoints(points);
  28951. polyline.shape.points = getInitialPoints(points);
  28952. graphic.initProps(polygon, target, seriesModel, idx);
  28953. graphic.initProps(polyline, target, seriesModel, idx);
  28954. var itemGroup = new graphic.Group();
  28955. var symbolGroup = new graphic.Group();
  28956. itemGroup.add(polyline);
  28957. itemGroup.add(polygon);
  28958. itemGroup.add(symbolGroup);
  28959. updateSymbols(
  28960. polyline.shape.points, points, symbolGroup, data, idx, true
  28961. );
  28962. data.setItemGraphicEl(idx, itemGroup);
  28963. })
  28964. .update(function (newIdx, oldIdx) {
  28965. var itemGroup = oldData.getItemGraphicEl(oldIdx);
  28966. var polyline = itemGroup.childAt(0);
  28967. var polygon = itemGroup.childAt(1);
  28968. var symbolGroup = itemGroup.childAt(2);
  28969. var target = {
  28970. shape: {
  28971. points: data.getItemLayout(newIdx)
  28972. }
  28973. };
  28974. if (!target.shape.points) {
  28975. return;
  28976. }
  28977. updateSymbols(
  28978. polyline.shape.points, target.shape.points, symbolGroup, data, newIdx, false
  28979. );
  28980. graphic.updateProps(polyline, target, seriesModel);
  28981. graphic.updateProps(polygon, target, seriesModel);
  28982. data.setItemGraphicEl(newIdx, itemGroup);
  28983. })
  28984. .remove(function (idx) {
  28985. group.remove(oldData.getItemGraphicEl(idx));
  28986. })
  28987. .execute();
  28988. data.eachItemGraphicEl(function (itemGroup, idx) {
  28989. var itemModel = data.getItemModel(idx);
  28990. var polyline = itemGroup.childAt(0);
  28991. var polygon = itemGroup.childAt(1);
  28992. var symbolGroup = itemGroup.childAt(2);
  28993. var color = data.getItemVisual(idx, 'color');
  28994. group.add(itemGroup);
  28995. polyline.useStyle(
  28996. zrUtil.defaults(
  28997. itemModel.getModel('lineStyle.normal').getLineStyle(),
  28998. {
  28999. fill: 'none',
  29000. stroke: color
  29001. }
  29002. )
  29003. );
  29004. polyline.hoverStyle = itemModel.getModel('lineStyle.emphasis').getLineStyle();
  29005. var areaStyleModel = itemModel.getModel('areaStyle.normal');
  29006. var hoverAreaStyleModel = itemModel.getModel('areaStyle.emphasis');
  29007. var polygonIgnore = areaStyleModel.isEmpty() && areaStyleModel.parentModel.isEmpty();
  29008. var hoverPolygonIgnore = hoverAreaStyleModel.isEmpty() && hoverAreaStyleModel.parentModel.isEmpty();
  29009. hoverPolygonIgnore = hoverPolygonIgnore && polygonIgnore;
  29010. polygon.ignore = polygonIgnore;
  29011. polygon.useStyle(
  29012. zrUtil.defaults(
  29013. areaStyleModel.getAreaStyle(),
  29014. {
  29015. fill: color,
  29016. opacity: 0.7
  29017. }
  29018. )
  29019. );
  29020. polygon.hoverStyle = hoverAreaStyleModel.getAreaStyle();
  29021. var itemStyle = itemModel.getModel('itemStyle.normal').getItemStyle(['color']);
  29022. var itemHoverStyle = itemModel.getModel('itemStyle.emphasis').getItemStyle();
  29023. var labelModel = itemModel.getModel('label.normal');
  29024. var labelHoverModel = itemModel.getModel('label.emphasis');
  29025. symbolGroup.eachChild(function (symbolPath) {
  29026. symbolPath.setStyle(itemStyle);
  29027. symbolPath.hoverStyle = zrUtil.clone(itemHoverStyle);
  29028. var defaultText = data.get(data.dimensions[symbolPath.__dimIdx], idx);
  29029. graphic.setText(symbolPath.style, labelModel, color);
  29030. symbolPath.setStyle({
  29031. text: labelModel.get('show') ? zrUtil.retrieve(
  29032. seriesModel.getFormattedLabel(
  29033. idx, 'normal', null, symbolPath.__dimIdx
  29034. ),
  29035. defaultText
  29036. ) : ''
  29037. });
  29038. graphic.setText(symbolPath.hoverStyle, labelHoverModel, color);
  29039. symbolPath.hoverStyle.text = labelHoverModel.get('show') ? zrUtil.retrieve(
  29040. seriesModel.getFormattedLabel(
  29041. idx, 'emphasis', null, symbolPath.__dimIdx
  29042. ),
  29043. defaultText
  29044. ) : '';
  29045. });
  29046. function onEmphasis() {
  29047. polygon.attr('ignore', hoverPolygonIgnore);
  29048. }
  29049. function onNormal() {
  29050. polygon.attr('ignore', polygonIgnore);
  29051. }
  29052. itemGroup.off('mouseover').off('mouseout').off('normal').off('emphasis');
  29053. itemGroup.on('emphasis', onEmphasis)
  29054. .on('mouseover', onEmphasis)
  29055. .on('normal', onNormal)
  29056. .on('mouseout', onNormal);
  29057. graphic.setHoverStyle(itemGroup);
  29058. });
  29059. this._data = data;
  29060. },
  29061. remove: function () {
  29062. this.group.removeAll();
  29063. this._data = null;
  29064. },
  29065. dispose: function () {}
  29066. });
  29067. /***/ },
  29068. /* 167 */
  29069. /***/ function(module, exports) {
  29070. module.exports = function (ecModel) {
  29071. ecModel.eachSeriesByType('radar', function (seriesModel) {
  29072. var data = seriesModel.getData();
  29073. var points = [];
  29074. var coordSys = seriesModel.coordinateSystem;
  29075. if (!coordSys) {
  29076. return;
  29077. }
  29078. function pointsConverter(val, idx) {
  29079. points[idx] = points[idx] || [];
  29080. points[idx][i] = coordSys.dataToPoint(val, i);
  29081. }
  29082. for (var i = 0; i < coordSys.getIndicatorAxes().length; i++) {
  29083. var dim = data.dimensions[i];
  29084. data.each(dim, pointsConverter);
  29085. }
  29086. data.each(function (idx) {
  29087. // Close polygon
  29088. points[idx][0] && points[idx].push(points[idx][0].slice());
  29089. data.setItemLayout(idx, points[idx]);
  29090. });
  29091. });
  29092. };
  29093. /***/ },
  29094. /* 168 */
  29095. /***/ function(module, exports, __webpack_require__) {
  29096. // Backward compat for radar chart in 2
  29097. var zrUtil = __webpack_require__(4);
  29098. module.exports = function (option) {
  29099. var polarOptArr = option.polar;
  29100. if (polarOptArr) {
  29101. if (!zrUtil.isArray(polarOptArr)) {
  29102. polarOptArr = [polarOptArr];
  29103. }
  29104. var polarNotRadar = [];
  29105. zrUtil.each(polarOptArr, function (polarOpt, idx) {
  29106. if (polarOpt.indicator) {
  29107. if (polarOpt.type && !polarOpt.shape) {
  29108. polarOpt.shape = polarOpt.type;
  29109. }
  29110. option.radar = option.radar || [];
  29111. if (!zrUtil.isArray(option.radar)) {
  29112. option.radar = [option.radar];
  29113. }
  29114. option.radar.push(polarOpt);
  29115. }
  29116. else {
  29117. polarNotRadar.push(polarOpt);
  29118. }
  29119. });
  29120. option.polar = polarNotRadar;
  29121. }
  29122. zrUtil.each(option.series, function (seriesOpt) {
  29123. if (seriesOpt.type === 'radar' && seriesOpt.polarIndex) {
  29124. seriesOpt.radarIndex = seriesOpt.polarIndex;
  29125. }
  29126. });
  29127. };
  29128. /***/ },
  29129. /* 169 */
  29130. /***/ function(module, exports, __webpack_require__) {
  29131. var echarts = __webpack_require__(1);
  29132. var PRIORITY = echarts.PRIORITY;
  29133. __webpack_require__(170);
  29134. __webpack_require__(180);
  29135. __webpack_require__(186);
  29136. __webpack_require__(171);
  29137. echarts.registerLayout(__webpack_require__(188));
  29138. echarts.registerVisual(__webpack_require__(189));
  29139. echarts.registerProcessor(PRIORITY.PROCESSOR.STATISTIC, __webpack_require__(190));
  29140. echarts.registerPreprocessor(__webpack_require__(191));
  29141. __webpack_require__(150)('map', [{
  29142. type: 'mapToggleSelect',
  29143. event: 'mapselectchanged',
  29144. method: 'toggleSelected'
  29145. }, {
  29146. type: 'mapSelect',
  29147. event: 'mapselected',
  29148. method: 'select'
  29149. }, {
  29150. type: 'mapUnSelect',
  29151. event: 'mapunselected',
  29152. method: 'unSelect'
  29153. }]);
  29154. /***/ },
  29155. /* 170 */
  29156. /***/ function(module, exports, __webpack_require__) {
  29157. var List = __webpack_require__(98);
  29158. var SeriesModel = __webpack_require__(78);
  29159. var zrUtil = __webpack_require__(4);
  29160. var completeDimensions = __webpack_require__(110);
  29161. var formatUtil = __webpack_require__(6);
  29162. var encodeHTML = formatUtil.encodeHTML;
  29163. var addCommas = formatUtil.addCommas;
  29164. var dataSelectableMixin = __webpack_require__(148);
  29165. var geoCreator = __webpack_require__(171);
  29166. var MapSeries = SeriesModel.extend({
  29167. type: 'series.map',
  29168. dependencies: ['geo'],
  29169. layoutMode: 'box',
  29170. /**
  29171. * Only first map series of same mapType will drawMap
  29172. * @type {boolean}
  29173. */
  29174. needsDrawMap: false,
  29175. /**
  29176. * Group of all map series with same mapType
  29177. * @type {boolean}
  29178. */
  29179. seriesGroup: [],
  29180. init: function (option) {
  29181. option = this._fillOption(option, this.getMapType());
  29182. this.option = option;
  29183. MapSeries.superApply(this, 'init', arguments);
  29184. this.updateSelectedMap(option.data);
  29185. },
  29186. getInitialData: function (option) {
  29187. var dimensions = completeDimensions(['value'], option.data || []);
  29188. var list = new List(dimensions, this);
  29189. list.initData(option.data);
  29190. return list;
  29191. },
  29192. mergeOption: function (newOption) {
  29193. if (newOption.data) {
  29194. newOption = this._fillOption(newOption, this.getMapType());
  29195. }
  29196. MapSeries.superCall(this, 'mergeOption', newOption);
  29197. this.updateSelectedMap(this.option.data);
  29198. },
  29199. /**
  29200. * If no host geo model, return null, which means using a
  29201. * inner exclusive geo model.
  29202. */
  29203. getHostGeoModel: function () {
  29204. var geoIndex = this.option.geoIndex;
  29205. return geoIndex != null
  29206. ? this.dependentModels.geo[geoIndex]
  29207. : null;
  29208. },
  29209. getMapType: function () {
  29210. return (this.getHostGeoModel() || this).option.map;
  29211. },
  29212. _fillOption: function (option, mapName) {
  29213. // Shallow clone
  29214. option = zrUtil.extend({}, option);
  29215. option.data = geoCreator.getFilledRegions(option.data, mapName);
  29216. return option;
  29217. },
  29218. getRawValue: function (dataIndex) {
  29219. // Use value stored in data instead because it is calculated from multiple series
  29220. // FIXME Provide all value of multiple series ?
  29221. return this.getData().get('value', dataIndex);
  29222. },
  29223. /**
  29224. * Get model of region
  29225. * @param {string} name
  29226. * @return {module:echarts/model/Model}
  29227. */
  29228. getRegionModel: function (regionName) {
  29229. var data = this.getData();
  29230. return data.getItemModel(data.indexOfName(regionName));
  29231. },
  29232. /**
  29233. * Map tooltip formatter
  29234. *
  29235. * @param {number} dataIndex
  29236. */
  29237. formatTooltip: function (dataIndex) {
  29238. // FIXME orignalData and data is a bit confusing
  29239. var data = this.getData();
  29240. var formattedValue = addCommas(this.getRawValue(dataIndex));
  29241. var name = data.getName(dataIndex);
  29242. var seriesGroup = this.seriesGroup;
  29243. var seriesNames = [];
  29244. for (var i = 0; i < seriesGroup.length; i++) {
  29245. var otherIndex = seriesGroup[i].originalData.indexOfName(name);
  29246. if (!isNaN(seriesGroup[i].originalData.get('value', otherIndex))) {
  29247. seriesNames.push(
  29248. encodeHTML(seriesGroup[i].name)
  29249. );
  29250. }
  29251. }
  29252. return seriesNames.join(', ') + '<br />'
  29253. + encodeHTML(name + ' : ' + formattedValue);
  29254. },
  29255. /**
  29256. * @implement
  29257. */
  29258. getTooltipPosition: function (dataIndex) {
  29259. if (dataIndex != null) {
  29260. var name = this.getData().getName(dataIndex);
  29261. var geo = this.coordinateSystem;
  29262. var region = geo.getRegion(name);
  29263. return region && geo.dataToPoint(region.center);
  29264. }
  29265. },
  29266. setZoom: function (zoom) {
  29267. this.option.zoom = zoom;
  29268. },
  29269. setCenter: function (center) {
  29270. this.option.center = center;
  29271. },
  29272. defaultOption: {
  29273. // 一级层叠
  29274. zlevel: 0,
  29275. // 二级层叠
  29276. z: 2,
  29277. coordinateSystem: 'geo',
  29278. // map should be explicitly specified since ec3.
  29279. map: '',
  29280. // If `geoIndex` is not specified, a exclusive geo will be
  29281. // created. Otherwise use the specified geo component, and
  29282. // `map` and `mapType` are ignored.
  29283. // geoIndex: 0,
  29284. // 'center' | 'left' | 'right' | 'x%' | {number}
  29285. left: 'center',
  29286. // 'center' | 'top' | 'bottom' | 'x%' | {number}
  29287. top: 'center',
  29288. // right
  29289. // bottom
  29290. // width:
  29291. // height
  29292. // Aspect is width / height. Inited to be geoJson bbox aspect
  29293. // This parameter is used for scale this aspect
  29294. aspectScale: 0.75,
  29295. ///// Layout with center and size
  29296. // If you wan't to put map in a fixed size box with right aspect ratio
  29297. // This two properties may more conveninet
  29298. // layoutCenter: [50%, 50%]
  29299. // layoutSize: 100
  29300. // 数值合并方式,默认加和,可选为:
  29301. // 'sum' | 'average' | 'max' | 'min'
  29302. // mapValueCalculation: 'sum',
  29303. // 地图数值计算结果小数精度
  29304. // mapValuePrecision: 0,
  29305. // 显示图例颜色标识(系列标识的小圆点),图例开启时有效
  29306. showLegendSymbol: true,
  29307. // 选择模式,默认关闭,可选single,multiple
  29308. // selectedMode: false,
  29309. dataRangeHoverLink: true,
  29310. // 是否开启缩放及漫游模式
  29311. // roam: false,
  29312. // Define left-top, right-bottom coords to control view
  29313. // For example, [ [180, 90], [-180, -90] ],
  29314. // higher priority than center and zoom
  29315. boundingCoords: null,
  29316. // Default on center of map
  29317. center: null,
  29318. zoom: 1,
  29319. scaleLimit: null,
  29320. label: {
  29321. normal: {
  29322. show: false,
  29323. textStyle: {
  29324. color: '#000'
  29325. }
  29326. },
  29327. emphasis: {
  29328. show: true,
  29329. textStyle: {
  29330. color: 'rgb(100,0,0)'
  29331. }
  29332. }
  29333. },
  29334. // scaleLimit: null,
  29335. itemStyle: {
  29336. normal: {
  29337. // color: 各异,
  29338. borderWidth: 0.5,
  29339. borderColor: '#444',
  29340. areaColor: '#eee'
  29341. },
  29342. // 也是选中样式
  29343. emphasis: {
  29344. areaColor: 'rgba(255,215,0,0.8)'
  29345. }
  29346. }
  29347. }
  29348. });
  29349. zrUtil.mixin(MapSeries, dataSelectableMixin);
  29350. module.exports = MapSeries;
  29351. /***/ },
  29352. /* 171 */
  29353. /***/ function(module, exports, __webpack_require__) {
  29354. var Geo = __webpack_require__(172);
  29355. var layout = __webpack_require__(71);
  29356. var zrUtil = __webpack_require__(4);
  29357. var numberUtil = __webpack_require__(7);
  29358. var mapDataStores = {};
  29359. /**
  29360. * Resize method bound to the geo
  29361. * @param {module:echarts/coord/geo/GeoModel|module:echarts/chart/map/MapModel} geoModel
  29362. * @param {module:echarts/ExtensionAPI} api
  29363. */
  29364. function resizeGeo (geoModel, api) {
  29365. var boundingCoords = geoModel.get('boundingCoords');
  29366. if (boundingCoords != null) {
  29367. var leftTop = boundingCoords[0];
  29368. var rightBottom = boundingCoords[1];
  29369. if (isNaN(leftTop[0]) || isNaN(leftTop[1]) || isNaN(rightBottom[0]) || isNaN(rightBottom[1])) {
  29370. if (true) {
  29371. console.error('Invalid boundingCoords');
  29372. }
  29373. }
  29374. else {
  29375. this.setBoundingRect(leftTop[0], leftTop[1], rightBottom[0] - leftTop[0], rightBottom[1] - leftTop[1]);
  29376. }
  29377. }
  29378. var rect = this.getBoundingRect();
  29379. var boxLayoutOption;
  29380. var center = geoModel.get('layoutCenter');
  29381. var size = geoModel.get('layoutSize');
  29382. var viewWidth = api.getWidth();
  29383. var viewHeight = api.getHeight();
  29384. var aspectScale = geoModel.get('aspectScale') || 0.75;
  29385. var aspect = rect.width / rect.height * aspectScale;
  29386. var useCenterAndSize = false;
  29387. if (center && size) {
  29388. center = [
  29389. numberUtil.parsePercent(center[0], viewWidth),
  29390. numberUtil.parsePercent(center[1], viewHeight)
  29391. ];
  29392. size = numberUtil.parsePercent(size, Math.min(viewWidth, viewHeight));
  29393. if (!isNaN(center[0]) && !isNaN(center[1]) && !isNaN(size)) {
  29394. useCenterAndSize = true;
  29395. }
  29396. else {
  29397. if (true) {
  29398. console.warn('Given layoutCenter or layoutSize data are invalid. Use left/top/width/height instead.');
  29399. }
  29400. }
  29401. }
  29402. var viewRect;
  29403. if (useCenterAndSize) {
  29404. var viewRect = {};
  29405. if (aspect > 1) {
  29406. // Width is same with size
  29407. viewRect.width = size;
  29408. viewRect.height = size / aspect;
  29409. }
  29410. else {
  29411. viewRect.height = size;
  29412. viewRect.width = size * aspect;
  29413. }
  29414. viewRect.y = center[1] - viewRect.height / 2;
  29415. viewRect.x = center[0] - viewRect.width / 2;
  29416. }
  29417. else {
  29418. // Use left/top/width/height
  29419. boxLayoutOption = geoModel.getBoxLayoutParams();
  29420. // 0.75 rate
  29421. boxLayoutOption.aspect = aspect;
  29422. viewRect = layout.getLayoutRect(boxLayoutOption, {
  29423. width: viewWidth,
  29424. height: viewHeight
  29425. });
  29426. }
  29427. this.setViewRect(viewRect.x, viewRect.y, viewRect.width, viewRect.height);
  29428. this.setCenter(geoModel.get('center'));
  29429. this.setZoom(geoModel.get('zoom'));
  29430. }
  29431. /**
  29432. * @param {module:echarts/coord/Geo} geo
  29433. * @param {module:echarts/model/Model} model
  29434. * @inner
  29435. */
  29436. function setGeoCoords(geo, model) {
  29437. zrUtil.each(model.get('geoCoord'), function (geoCoord, name) {
  29438. geo.addGeoCoord(name, geoCoord);
  29439. });
  29440. }
  29441. if (true) {
  29442. var mapNotExistsError = function (name) {
  29443. console.error('Map ' + name + ' not exists. You can download map file on http://echarts.baidu.com/download-map.html');
  29444. };
  29445. }
  29446. var geoCreator = {
  29447. // For deciding which dimensions to use when creating list data
  29448. dimensions: Geo.prototype.dimensions,
  29449. create: function (ecModel, api) {
  29450. var geoList = [];
  29451. // FIXME Create each time may be slow
  29452. ecModel.eachComponent('geo', function (geoModel, idx) {
  29453. var name = geoModel.get('map');
  29454. var mapData = mapDataStores[name];
  29455. if (true) {
  29456. if (!mapData) {
  29457. mapNotExistsError(name);
  29458. }
  29459. }
  29460. var geo = new Geo(
  29461. name + idx, name,
  29462. mapData && mapData.geoJson, mapData && mapData.specialAreas,
  29463. geoModel.get('nameMap')
  29464. );
  29465. geo.zoomLimit = geoModel.get('scaleLimit');
  29466. geoList.push(geo);
  29467. setGeoCoords(geo, geoModel);
  29468. geoModel.coordinateSystem = geo;
  29469. geo.model = geoModel;
  29470. // Inject resize method
  29471. geo.resize = resizeGeo;
  29472. geo.resize(geoModel, api);
  29473. });
  29474. ecModel.eachSeries(function (seriesModel) {
  29475. var coordSys = seriesModel.get('coordinateSystem');
  29476. if (coordSys === 'geo') {
  29477. var geoIndex = seriesModel.get('geoIndex') || 0;
  29478. seriesModel.coordinateSystem = geoList[geoIndex];
  29479. }
  29480. });
  29481. // If has map series
  29482. var mapModelGroupBySeries = {};
  29483. ecModel.eachSeriesByType('map', function (seriesModel) {
  29484. if (!seriesModel.getHostGeoModel()) {
  29485. var mapType = seriesModel.getMapType();
  29486. mapModelGroupBySeries[mapType] = mapModelGroupBySeries[mapType] || [];
  29487. mapModelGroupBySeries[mapType].push(seriesModel);
  29488. }
  29489. });
  29490. zrUtil.each(mapModelGroupBySeries, function (mapSeries, mapType) {
  29491. var mapData = mapDataStores[mapType];
  29492. if (true) {
  29493. if (!mapData) {
  29494. mapNotExistsError(mapSeries[0].get('map'));
  29495. }
  29496. }
  29497. var nameMapList = zrUtil.map(mapSeries, function (singleMapSeries) {
  29498. return singleMapSeries.get('nameMap');
  29499. });
  29500. var geo = new Geo(
  29501. mapType, mapType,
  29502. mapData && mapData.geoJson, mapData && mapData.specialAreas,
  29503. zrUtil.mergeAll(nameMapList)
  29504. );
  29505. geo.zoomLimit = zrUtil.retrieve.apply(null, zrUtil.map(mapSeries, function (singleMapSeries) {
  29506. return singleMapSeries.get('scaleLimit');
  29507. }));
  29508. geoList.push(geo);
  29509. // Inject resize method
  29510. geo.resize = resizeGeo;
  29511. geo.resize(mapSeries[0], api);
  29512. zrUtil.each(mapSeries, function (singleMapSeries) {
  29513. singleMapSeries.coordinateSystem = geo;
  29514. setGeoCoords(geo, singleMapSeries);
  29515. });
  29516. });
  29517. return geoList;
  29518. },
  29519. /**
  29520. * @param {string} mapName
  29521. * @param {Object|string} geoJson
  29522. * @param {Object} [specialAreas]
  29523. *
  29524. * @example
  29525. * $.get('USA.json', function (geoJson) {
  29526. * echarts.registerMap('USA', geoJson);
  29527. * // Or
  29528. * echarts.registerMap('USA', {
  29529. * geoJson: geoJson,
  29530. * specialAreas: {}
  29531. * })
  29532. * });
  29533. */
  29534. registerMap: function (mapName, geoJson, specialAreas) {
  29535. if (geoJson.geoJson && !geoJson.features) {
  29536. specialAreas = geoJson.specialAreas;
  29537. geoJson = geoJson.geoJson;
  29538. }
  29539. if (typeof geoJson === 'string') {
  29540. geoJson = (typeof JSON !== 'undefined' && JSON.parse)
  29541. ? JSON.parse(geoJson) : (new Function('return (' + geoJson + ');'))();
  29542. }
  29543. mapDataStores[mapName] = {
  29544. geoJson: geoJson,
  29545. specialAreas: specialAreas
  29546. };
  29547. },
  29548. /**
  29549. * @param {string} mapName
  29550. * @return {Object}
  29551. */
  29552. getMap: function (mapName) {
  29553. return mapDataStores[mapName];
  29554. },
  29555. /**
  29556. * Fill given regions array
  29557. * @param {Array.<Object>} originRegionArr
  29558. * @param {string} mapName
  29559. * @return {Array}
  29560. */
  29561. getFilledRegions: function (originRegionArr, mapName) {
  29562. // Not use the original
  29563. var regionsArr = (originRegionArr || []).slice();
  29564. var map = geoCreator.getMap(mapName);
  29565. var geoJson = map && map.geoJson;
  29566. if (!geoJson) {
  29567. if (true) {
  29568. mapNotExistsError(mapName);
  29569. }
  29570. return originRegionArr;
  29571. }
  29572. var dataNameMap = zrUtil.createHashMap();
  29573. var features = geoJson.features;
  29574. for (var i = 0; i < regionsArr.length; i++) {
  29575. dataNameMap.set(regionsArr[i].name, regionsArr[i]);
  29576. }
  29577. for (var i = 0; i < features.length; i++) {
  29578. var name = features[i].properties.name;
  29579. if (!dataNameMap.get(name)) {
  29580. regionsArr.push({
  29581. name: name
  29582. });
  29583. }
  29584. }
  29585. return regionsArr;
  29586. }
  29587. };
  29588. // Inject methods into echarts
  29589. var echarts = __webpack_require__(1);
  29590. echarts.registerMap = geoCreator.registerMap;
  29591. echarts.getMap = geoCreator.getMap;
  29592. echarts.parseGeoJSON = __webpack_require__(173);
  29593. // TODO
  29594. echarts.loadMap = function () {};
  29595. echarts.registerCoordinateSystem('geo', geoCreator);
  29596. module.exports = geoCreator;
  29597. /***/ },
  29598. /* 172 */
  29599. /***/ function(module, exports, __webpack_require__) {
  29600. var parseGeoJson = __webpack_require__(173);
  29601. var zrUtil = __webpack_require__(4);
  29602. var BoundingRect = __webpack_require__(9);
  29603. var View = __webpack_require__(176);
  29604. // Geo fix functions
  29605. var geoFixFuncs = [
  29606. __webpack_require__(177),
  29607. __webpack_require__(178),
  29608. __webpack_require__(179)
  29609. ];
  29610. /**
  29611. * [Geo description]
  29612. * @param {string} name Geo name
  29613. * @param {string} map Map type
  29614. * @param {Object} geoJson
  29615. * @param {Object} [specialAreas]
  29616. * Specify the positioned areas by left, top, width, height
  29617. * @param {Object.<string, string>} [nameMap]
  29618. * Specify name alias
  29619. */
  29620. function Geo(name, map, geoJson, specialAreas, nameMap) {
  29621. View.call(this, name);
  29622. /**
  29623. * Map type
  29624. * @type {string}
  29625. */
  29626. this.map = map;
  29627. this._nameCoordMap = zrUtil.createHashMap();
  29628. this.loadGeoJson(geoJson, specialAreas, nameMap);
  29629. }
  29630. Geo.prototype = {
  29631. constructor: Geo,
  29632. type: 'geo',
  29633. /**
  29634. * @param {Array.<string>}
  29635. * @readOnly
  29636. */
  29637. dimensions: ['lng', 'lat'],
  29638. /**
  29639. * If contain given lng,lat coord
  29640. * @param {Array.<number>}
  29641. * @readOnly
  29642. */
  29643. containCoord: function (coord) {
  29644. var regions = this.regions;
  29645. for (var i = 0; i < regions.length; i++) {
  29646. if (regions[i].contain(coord)) {
  29647. return true;
  29648. }
  29649. }
  29650. return false;
  29651. },
  29652. /**
  29653. * @param {Object} geoJson
  29654. * @param {Object} [specialAreas]
  29655. * Specify the positioned areas by left, top, width, height
  29656. * @param {Object.<string, string>} [nameMap]
  29657. * Specify name alias
  29658. */
  29659. loadGeoJson: function (geoJson, specialAreas, nameMap) {
  29660. // https://jsperf.com/try-catch-performance-overhead
  29661. try {
  29662. this.regions = geoJson ? parseGeoJson(geoJson) : [];
  29663. }
  29664. catch (e) {
  29665. throw 'Invalid geoJson format\n' + e.message;
  29666. }
  29667. specialAreas = specialAreas || {};
  29668. nameMap = nameMap || {};
  29669. var regions = this.regions;
  29670. var regionsMap = zrUtil.createHashMap();
  29671. for (var i = 0; i < regions.length; i++) {
  29672. var regionName = regions[i].name;
  29673. // Try use the alias in nameMap
  29674. regionName = nameMap.hasOwnProperty(regionName) ? nameMap[regionName] : regionName;
  29675. regions[i].name = regionName;
  29676. regionsMap.set(regionName, regions[i]);
  29677. // Add geoJson
  29678. this.addGeoCoord(regionName, regions[i].center);
  29679. // Some area like Alaska in USA map needs to be tansformed
  29680. // to look better
  29681. var specialArea = specialAreas[regionName];
  29682. if (specialArea) {
  29683. regions[i].transformTo(
  29684. specialArea.left, specialArea.top, specialArea.width, specialArea.height
  29685. );
  29686. }
  29687. }
  29688. this._regionsMap = regionsMap;
  29689. this._rect = null;
  29690. zrUtil.each(geoFixFuncs, function (fixFunc) {
  29691. fixFunc(this);
  29692. }, this);
  29693. },
  29694. // Overwrite
  29695. transformTo: function (x, y, width, height) {
  29696. var rect = this.getBoundingRect();
  29697. rect = rect.clone();
  29698. // Longitute is inverted
  29699. rect.y = -rect.y - rect.height;
  29700. var viewTransform = this._viewTransform;
  29701. viewTransform.transform = rect.calculateTransform(
  29702. new BoundingRect(x, y, width, height)
  29703. );
  29704. viewTransform.decomposeTransform();
  29705. var scale = viewTransform.scale;
  29706. scale[1] = -scale[1];
  29707. viewTransform.updateTransform();
  29708. this._updateTransform();
  29709. },
  29710. /**
  29711. * @param {string} name
  29712. * @return {module:echarts/coord/geo/Region}
  29713. */
  29714. getRegion: function (name) {
  29715. return this._regionsMap.get(name);
  29716. },
  29717. getRegionByCoord: function (coord) {
  29718. var regions = this.regions;
  29719. for (var i = 0; i < regions.length; i++) {
  29720. if (regions[i].contain(coord)) {
  29721. return regions[i];
  29722. }
  29723. }
  29724. },
  29725. /**
  29726. * Add geoCoord for indexing by name
  29727. * @param {string} name
  29728. * @param {Array.<number>} geoCoord
  29729. */
  29730. addGeoCoord: function (name, geoCoord) {
  29731. this._nameCoordMap.set(name, geoCoord);
  29732. },
  29733. /**
  29734. * Get geoCoord by name
  29735. * @param {string} name
  29736. * @return {Array.<number>}
  29737. */
  29738. getGeoCoord: function (name) {
  29739. return this._nameCoordMap.get(name);
  29740. },
  29741. // Overwrite
  29742. getBoundingRect: function () {
  29743. if (this._rect) {
  29744. return this._rect;
  29745. }
  29746. var rect;
  29747. var regions = this.regions;
  29748. for (var i = 0; i < regions.length; i++) {
  29749. var regionRect = regions[i].getBoundingRect();
  29750. rect = rect || regionRect.clone();
  29751. rect.union(regionRect);
  29752. }
  29753. // FIXME Always return new ?
  29754. return (this._rect = rect || new BoundingRect(0, 0, 0, 0));
  29755. },
  29756. /**
  29757. * Convert series data to a list of points
  29758. * @param {module:echarts/data/List} data
  29759. * @param {boolean} stack
  29760. * @return {Array}
  29761. * Return list of points. For example:
  29762. * `[[10, 10], [20, 20], [30, 30]]`
  29763. */
  29764. dataToPoints: function (data) {
  29765. var item = [];
  29766. return data.mapArray(['lng', 'lat'], function (lon, lat) {
  29767. item[0] = lon;
  29768. item[1] = lat;
  29769. return this.dataToPoint(item);
  29770. }, this);
  29771. },
  29772. /**
  29773. * @param {string|Array.<number>} data
  29774. * @return {Array.<number>}
  29775. */
  29776. dataToPoint: function (data) {
  29777. if (typeof data === 'string') {
  29778. // Map area name to geoCoord
  29779. data = this.getGeoCoord(data);
  29780. }
  29781. if (data) {
  29782. return View.prototype.dataToPoint.call(this, data);
  29783. }
  29784. },
  29785. /**
  29786. * @inheritDoc
  29787. */
  29788. convertToPixel: zrUtil.curry(doConvert, 'dataToPoint'),
  29789. /**
  29790. * @inheritDoc
  29791. */
  29792. convertFromPixel: zrUtil.curry(doConvert, 'pointToData')
  29793. };
  29794. zrUtil.mixin(Geo, View);
  29795. function doConvert(methodName, ecModel, finder, value) {
  29796. var geoModel = finder.geoModel;
  29797. var seriesModel = finder.seriesModel;
  29798. var coordSys = geoModel
  29799. ? geoModel.coordinateSystem
  29800. : seriesModel
  29801. ? (
  29802. seriesModel.coordinateSystem // For map.
  29803. || (seriesModel.getReferringComponents('geo')[0] || {}).coordinateSystem
  29804. )
  29805. : null;
  29806. return coordSys === this ? coordSys[methodName](value) : null;
  29807. }
  29808. module.exports = Geo;
  29809. /***/ },
  29810. /* 173 */
  29811. /***/ function(module, exports, __webpack_require__) {
  29812. /**
  29813. * Parse and decode geo json
  29814. * @module echarts/coord/geo/parseGeoJson
  29815. */
  29816. var zrUtil = __webpack_require__(4);
  29817. var Region = __webpack_require__(174);
  29818. function decode(json) {
  29819. if (!json.UTF8Encoding) {
  29820. return json;
  29821. }
  29822. var encodeScale = json.UTF8Scale;
  29823. if (encodeScale == null) {
  29824. encodeScale = 1024;
  29825. }
  29826. var features = json.features;
  29827. for (var f = 0; f < features.length; f++) {
  29828. var feature = features[f];
  29829. var geometry = feature.geometry;
  29830. var coordinates = geometry.coordinates;
  29831. var encodeOffsets = geometry.encodeOffsets;
  29832. for (var c = 0; c < coordinates.length; c++) {
  29833. var coordinate = coordinates[c];
  29834. if (geometry.type === 'Polygon') {
  29835. coordinates[c] = decodePolygon(
  29836. coordinate,
  29837. encodeOffsets[c],
  29838. encodeScale
  29839. );
  29840. }
  29841. else if (geometry.type === 'MultiPolygon') {
  29842. for (var c2 = 0; c2 < coordinate.length; c2++) {
  29843. var polygon = coordinate[c2];
  29844. coordinate[c2] = decodePolygon(
  29845. polygon,
  29846. encodeOffsets[c][c2],
  29847. encodeScale
  29848. );
  29849. }
  29850. }
  29851. }
  29852. }
  29853. // Has been decoded
  29854. json.UTF8Encoding = false;
  29855. return json;
  29856. }
  29857. function decodePolygon(coordinate, encodeOffsets, encodeScale) {
  29858. var result = [];
  29859. var prevX = encodeOffsets[0];
  29860. var prevY = encodeOffsets[1];
  29861. for (var i = 0; i < coordinate.length; i += 2) {
  29862. var x = coordinate.charCodeAt(i) - 64;
  29863. var y = coordinate.charCodeAt(i + 1) - 64;
  29864. // ZigZag decoding
  29865. x = (x >> 1) ^ (-(x & 1));
  29866. y = (y >> 1) ^ (-(y & 1));
  29867. // Delta deocding
  29868. x += prevX;
  29869. y += prevY;
  29870. prevX = x;
  29871. prevY = y;
  29872. // Dequantize
  29873. result.push([x / encodeScale, y / encodeScale]);
  29874. }
  29875. return result;
  29876. }
  29877. /**
  29878. * @alias module:echarts/coord/geo/parseGeoJson
  29879. * @param {Object} geoJson
  29880. * @return {module:zrender/container/Group}
  29881. */
  29882. module.exports = function (geoJson) {
  29883. decode(geoJson);
  29884. return zrUtil.map(zrUtil.filter(geoJson.features, function (featureObj) {
  29885. // Output of mapshaper may have geometry null
  29886. return featureObj.geometry
  29887. && featureObj.properties
  29888. && featureObj.geometry.coordinates.length > 0;
  29889. }), function (featureObj) {
  29890. var properties = featureObj.properties;
  29891. var geo = featureObj.geometry;
  29892. var coordinates = geo.coordinates;
  29893. var geometries = [];
  29894. if (geo.type === 'Polygon') {
  29895. geometries.push({
  29896. type: 'polygon',
  29897. // According to the GeoJSON specification.
  29898. // First must be exterior, and the rest are all interior(holes).
  29899. exterior: coordinates[0],
  29900. interiors: coordinates.slice(1)
  29901. });
  29902. }
  29903. if (geo.type === 'MultiPolygon') {
  29904. zrUtil.each(coordinates, function (item) {
  29905. if (item[0]) {
  29906. geometries.push({
  29907. type: 'polygon',
  29908. exterior: item[0],
  29909. interiors: item.slice(1)
  29910. });
  29911. }
  29912. });
  29913. }
  29914. var region = new Region(
  29915. properties.name,
  29916. geometries,
  29917. properties.cp
  29918. );
  29919. region.properties = properties;
  29920. return region;
  29921. });
  29922. };
  29923. /***/ },
  29924. /* 174 */
  29925. /***/ function(module, exports, __webpack_require__) {
  29926. /**
  29927. * @module echarts/coord/geo/Region
  29928. */
  29929. var polygonContain = __webpack_require__(175);
  29930. var BoundingRect = __webpack_require__(9);
  29931. var bbox = __webpack_require__(38);
  29932. var vec2 = __webpack_require__(10);
  29933. /**
  29934. * @param {string} name
  29935. * @param {Array} geometries
  29936. * @param {Array.<number>} cp
  29937. */
  29938. function Region(name, geometries, cp) {
  29939. /**
  29940. * @type {string}
  29941. * @readOnly
  29942. */
  29943. this.name = name;
  29944. /**
  29945. * @type {Array.<Array>}
  29946. * @readOnly
  29947. */
  29948. this.geometries = geometries;
  29949. if (!cp) {
  29950. var rect = this.getBoundingRect();
  29951. cp = [
  29952. rect.x + rect.width / 2,
  29953. rect.y + rect.height / 2
  29954. ];
  29955. }
  29956. else {
  29957. cp = [cp[0], cp[1]];
  29958. }
  29959. /**
  29960. * @type {Array.<number>}
  29961. */
  29962. this.center = cp;
  29963. }
  29964. Region.prototype = {
  29965. constructor: Region,
  29966. properties: null,
  29967. /**
  29968. * @return {module:zrender/core/BoundingRect}
  29969. */
  29970. getBoundingRect: function () {
  29971. var rect = this._rect;
  29972. if (rect) {
  29973. return rect;
  29974. }
  29975. var MAX_NUMBER = Number.MAX_VALUE;
  29976. var min = [MAX_NUMBER, MAX_NUMBER];
  29977. var max = [-MAX_NUMBER, -MAX_NUMBER];
  29978. var min2 = [];
  29979. var max2 = [];
  29980. var geometries = this.geometries;
  29981. for (var i = 0; i < geometries.length; i++) {
  29982. // Only support polygon
  29983. if (geometries[i].type !== 'polygon') {
  29984. continue;
  29985. }
  29986. // Doesn't consider hole
  29987. var exterior = geometries[i].exterior;
  29988. bbox.fromPoints(exterior, min2, max2);
  29989. vec2.min(min, min, min2);
  29990. vec2.max(max, max, max2);
  29991. }
  29992. // No data
  29993. if (i === 0) {
  29994. min[0] = min[1] = max[0] = max[1] = 0;
  29995. }
  29996. return (this._rect = new BoundingRect(
  29997. min[0], min[1], max[0] - min[0], max[1] - min[1]
  29998. ));
  29999. },
  30000. /**
  30001. * @param {<Array.<number>} coord
  30002. * @return {boolean}
  30003. */
  30004. contain: function (coord) {
  30005. var rect = this.getBoundingRect();
  30006. var geometries = this.geometries;
  30007. if (!rect.contain(coord[0], coord[1])) {
  30008. return false;
  30009. }
  30010. loopGeo: for (var i = 0, len = geometries.length; i < len; i++) {
  30011. // Only support polygon.
  30012. if (geometries[i].type !== 'polygon') {
  30013. continue;
  30014. }
  30015. var exterior = geometries[i].exterior;
  30016. var interiors = geometries[i].interiors;
  30017. if (polygonContain.contain(exterior, coord[0], coord[1])) {
  30018. // Not in the region if point is in the hole.
  30019. for (var k = 0; k < (interiors ? interiors.length : 0); k++) {
  30020. if (polygonContain.contain(interiors[k])) {
  30021. continue loopGeo;
  30022. }
  30023. }
  30024. return true;
  30025. }
  30026. }
  30027. return false;
  30028. },
  30029. transformTo: function (x, y, width, height) {
  30030. var rect = this.getBoundingRect();
  30031. var aspect = rect.width / rect.height;
  30032. if (!width) {
  30033. width = aspect * height;
  30034. }
  30035. else if (!height) {
  30036. height = width / aspect ;
  30037. }
  30038. var target = new BoundingRect(x, y, width, height);
  30039. var transform = rect.calculateTransform(target);
  30040. var geometries = this.geometries;
  30041. for (var i = 0; i < geometries.length; i++) {
  30042. // Only support polygon.
  30043. if (geometries[i].type !== 'polygon') {
  30044. continue;
  30045. }
  30046. var exterior = geometries[i].exterior;
  30047. var interiors = geometries[i].interiors;
  30048. for (var p = 0; p < exterior.length; p++) {
  30049. vec2.applyTransform(exterior[p], exterior[p], transform);
  30050. }
  30051. for (var h = 0; h < (interiors ? interiors.length : 0); h++) {
  30052. for (var p = 0; p < interiors[h].length; p++) {
  30053. vec2.applyTransform(interiors[h][p], interiors[h][p], transform);
  30054. }
  30055. }
  30056. }
  30057. rect = this._rect;
  30058. rect.copy(target);
  30059. // Update center
  30060. this.center = [
  30061. rect.x + rect.width / 2,
  30062. rect.y + rect.height / 2
  30063. ];
  30064. }
  30065. };
  30066. module.exports = Region;
  30067. /***/ },
  30068. /* 175 */
  30069. /***/ function(module, exports, __webpack_require__) {
  30070. var windingLine = __webpack_require__(45);
  30071. var EPSILON = 1e-8;
  30072. function isAroundEqual(a, b) {
  30073. return Math.abs(a - b) < EPSILON;
  30074. }
  30075. function contain(points, x, y) {
  30076. var w = 0;
  30077. var p = points[0];
  30078. if (!p) {
  30079. return false;
  30080. }
  30081. for (var i = 1; i < points.length; i++) {
  30082. var p2 = points[i];
  30083. w += windingLine(p[0], p[1], p2[0], p2[1], x, y);
  30084. p = p2;
  30085. }
  30086. // Close polygon
  30087. var p0 = points[0];
  30088. if (!isAroundEqual(p[0], p0[0]) || !isAroundEqual(p[1], p0[1])) {
  30089. w += windingLine(p[0], p[1], p0[0], p0[1], x, y);
  30090. }
  30091. return w !== 0;
  30092. }
  30093. module.exports = {
  30094. contain: contain
  30095. };
  30096. /***/ },
  30097. /* 176 */
  30098. /***/ function(module, exports, __webpack_require__) {
  30099. /**
  30100. * Simple view coordinate system
  30101. * Mapping given x, y to transformd view x, y
  30102. */
  30103. var vector = __webpack_require__(10);
  30104. var matrix = __webpack_require__(11);
  30105. var Transformable = __webpack_require__(26);
  30106. var zrUtil = __webpack_require__(4);
  30107. var BoundingRect = __webpack_require__(9);
  30108. var v2ApplyTransform = vector.applyTransform;
  30109. // Dummy transform node
  30110. function TransformDummy() {
  30111. Transformable.call(this);
  30112. }
  30113. zrUtil.mixin(TransformDummy, Transformable);
  30114. function View(name) {
  30115. /**
  30116. * @type {string}
  30117. */
  30118. this.name = name;
  30119. /**
  30120. * @type {Object}
  30121. */
  30122. this.zoomLimit;
  30123. Transformable.call(this);
  30124. this._roamTransform = new TransformDummy();
  30125. this._viewTransform = new TransformDummy();
  30126. this._center;
  30127. this._zoom;
  30128. }
  30129. View.prototype = {
  30130. constructor: View,
  30131. type: 'view',
  30132. /**
  30133. * @param {Array.<string>}
  30134. * @readOnly
  30135. */
  30136. dimensions: ['x', 'y'],
  30137. /**
  30138. * Set bounding rect
  30139. * @param {number} x
  30140. * @param {number} y
  30141. * @param {number} width
  30142. * @param {number} height
  30143. */
  30144. // PENDING to getRect
  30145. setBoundingRect: function (x, y, width, height) {
  30146. this._rect = new BoundingRect(x, y, width, height);
  30147. return this._rect;
  30148. },
  30149. /**
  30150. * @return {module:zrender/core/BoundingRect}
  30151. */
  30152. // PENDING to getRect
  30153. getBoundingRect: function () {
  30154. return this._rect;
  30155. },
  30156. /**
  30157. * @param {number} x
  30158. * @param {number} y
  30159. * @param {number} width
  30160. * @param {number} height
  30161. */
  30162. setViewRect: function (x, y, width, height) {
  30163. this.transformTo(x, y, width, height);
  30164. this._viewRect = new BoundingRect(x, y, width, height);
  30165. },
  30166. /**
  30167. * Transformed to particular position and size
  30168. * @param {number} x
  30169. * @param {number} y
  30170. * @param {number} width
  30171. * @param {number} height
  30172. */
  30173. transformTo: function (x, y, width, height) {
  30174. var rect = this.getBoundingRect();
  30175. var viewTransform = this._viewTransform;
  30176. viewTransform.transform = rect.calculateTransform(
  30177. new BoundingRect(x, y, width, height)
  30178. );
  30179. viewTransform.decomposeTransform();
  30180. this._updateTransform();
  30181. },
  30182. /**
  30183. * Set center of view
  30184. * @param {Array.<number>} [centerCoord]
  30185. */
  30186. setCenter: function (centerCoord) {
  30187. if (!centerCoord) {
  30188. return;
  30189. }
  30190. this._center = centerCoord;
  30191. this._updateCenterAndZoom();
  30192. },
  30193. /**
  30194. * @param {number} zoom
  30195. */
  30196. setZoom: function (zoom) {
  30197. zoom = zoom || 1;
  30198. var zoomLimit = this.zoomLimit;
  30199. if (zoomLimit) {
  30200. if (zoomLimit.max != null) {
  30201. zoom = Math.min(zoomLimit.max, zoom);
  30202. }
  30203. if (zoomLimit.min != null) {
  30204. zoom = Math.max(zoomLimit.min, zoom);
  30205. }
  30206. }
  30207. this._zoom = zoom;
  30208. this._updateCenterAndZoom();
  30209. },
  30210. /**
  30211. * Get default center without roam
  30212. */
  30213. getDefaultCenter: function () {
  30214. // Rect before any transform
  30215. var rawRect = this.getBoundingRect();
  30216. var cx = rawRect.x + rawRect.width / 2;
  30217. var cy = rawRect.y + rawRect.height / 2;
  30218. return [cx, cy];
  30219. },
  30220. getCenter: function () {
  30221. return this._center || this.getDefaultCenter();
  30222. },
  30223. getZoom: function () {
  30224. return this._zoom || 1;
  30225. },
  30226. /**
  30227. * @return {Array.<number}
  30228. */
  30229. getRoamTransform: function () {
  30230. return this._roamTransform;
  30231. },
  30232. _updateCenterAndZoom: function () {
  30233. // Must update after view transform updated
  30234. var viewTransformMatrix = this._viewTransform.getLocalTransform();
  30235. var roamTransform = this._roamTransform;
  30236. var defaultCenter = this.getDefaultCenter();
  30237. var center = this.getCenter();
  30238. var zoom = this.getZoom();
  30239. center = vector.applyTransform([], center, viewTransformMatrix);
  30240. defaultCenter = vector.applyTransform([], defaultCenter, viewTransformMatrix);
  30241. roamTransform.origin = center;
  30242. roamTransform.position = [
  30243. defaultCenter[0] - center[0],
  30244. defaultCenter[1] - center[1]
  30245. ];
  30246. roamTransform.scale = [zoom, zoom];
  30247. this._updateTransform();
  30248. },
  30249. /**
  30250. * Update transform from roam and mapLocation
  30251. * @private
  30252. */
  30253. _updateTransform: function () {
  30254. var roamTransform = this._roamTransform;
  30255. var viewTransform = this._viewTransform;
  30256. viewTransform.parent = roamTransform;
  30257. roamTransform.updateTransform();
  30258. viewTransform.updateTransform();
  30259. viewTransform.transform
  30260. && matrix.copy(this.transform || (this.transform = []), viewTransform.transform);
  30261. if (this.transform) {
  30262. this.invTransform = this.invTransform || [];
  30263. matrix.invert(this.invTransform, this.transform);
  30264. }
  30265. else {
  30266. this.invTransform = null;
  30267. }
  30268. this.decomposeTransform();
  30269. },
  30270. /**
  30271. * @return {module:zrender/core/BoundingRect}
  30272. */
  30273. getViewRect: function () {
  30274. return this._viewRect;
  30275. },
  30276. /**
  30277. * Get view rect after roam transform
  30278. * @return {module:zrender/core/BoundingRect}
  30279. */
  30280. getViewRectAfterRoam: function () {
  30281. var rect = this.getBoundingRect().clone();
  30282. rect.applyTransform(this.transform);
  30283. return rect;
  30284. },
  30285. /**
  30286. * Convert a single (lon, lat) data item to (x, y) point.
  30287. * @param {Array.<number>} data
  30288. * @return {Array.<number>}
  30289. */
  30290. dataToPoint: function (data) {
  30291. var transform = this.transform;
  30292. return transform
  30293. ? v2ApplyTransform([], data, transform)
  30294. : [data[0], data[1]];
  30295. },
  30296. /**
  30297. * Convert a (x, y) point to (lon, lat) data
  30298. * @param {Array.<number>} point
  30299. * @return {Array.<number>}
  30300. */
  30301. pointToData: function (point) {
  30302. var invTransform = this.invTransform;
  30303. return invTransform
  30304. ? v2ApplyTransform([], point, invTransform)
  30305. : [point[0], point[1]];
  30306. },
  30307. /**
  30308. * @implements
  30309. * see {module:echarts/CoodinateSystem}
  30310. */
  30311. convertToPixel: zrUtil.curry(doConvert, 'dataToPoint'),
  30312. /**
  30313. * @implements
  30314. * see {module:echarts/CoodinateSystem}
  30315. */
  30316. convertFromPixel: zrUtil.curry(doConvert, 'pointToData'),
  30317. /**
  30318. * @implements
  30319. * see {module:echarts/CoodinateSystem}
  30320. */
  30321. containPoint: function (point) {
  30322. return this.getViewRectAfterRoam().contain(point[0], point[1]);
  30323. }
  30324. /**
  30325. * @return {number}
  30326. */
  30327. // getScalarScale: function () {
  30328. // // Use determinant square root of transform to mutiply scalar
  30329. // var m = this.transform;
  30330. // var det = Math.sqrt(Math.abs(m[0] * m[3] - m[2] * m[1]));
  30331. // return det;
  30332. // }
  30333. };
  30334. zrUtil.mixin(View, Transformable);
  30335. function doConvert(methodName, ecModel, finder, value) {
  30336. var seriesModel = finder.seriesModel;
  30337. var coordSys = seriesModel ? seriesModel.coordinateSystem : null; // e.g., graph.
  30338. return coordSys === this ? coordSys[methodName](value) : null;
  30339. }
  30340. module.exports = View;
  30341. /***/ },
  30342. /* 177 */
  30343. /***/ function(module, exports, __webpack_require__) {
  30344. // Fix for 南海诸岛
  30345. var Region = __webpack_require__(174);
  30346. var zrUtil = __webpack_require__(4);
  30347. var geoCoord = [126, 25];
  30348. var points = [
  30349. [[0,3.5],[7,11.2],[15,11.9],[30,7],[42,0.7],[52,0.7],
  30350. [56,7.7],[59,0.7],[64,0.7],[64,0],[5,0],[0,3.5]],
  30351. [[13,16.1],[19,14.7],[16,21.7],[11,23.1],[13,16.1]],
  30352. [[12,32.2],[14,38.5],[15,38.5],[13,32.2],[12,32.2]],
  30353. [[16,47.6],[12,53.2],[13,53.2],[18,47.6],[16,47.6]],
  30354. [[6,64.4],[8,70],[9,70],[8,64.4],[6,64.4]],
  30355. [[23,82.6],[29,79.8],[30,79.8],[25,82.6],[23,82.6]],
  30356. [[37,70.7],[43,62.3],[44,62.3],[39,70.7],[37,70.7]],
  30357. [[48,51.1],[51,45.5],[53,45.5],[50,51.1],[48,51.1]],
  30358. [[51,35],[51,28.7],[53,28.7],[53,35],[51,35]],
  30359. [[52,22.4],[55,17.5],[56,17.5],[53,22.4],[52,22.4]],
  30360. [[58,12.6],[62,7],[63,7],[60,12.6],[58,12.6]],
  30361. [[0,3.5],[0,93.1],[64,93.1],[64,0],[63,0],[63,92.4],
  30362. [1,92.4],[1,3.5],[0,3.5]]
  30363. ];
  30364. for (var i = 0; i < points.length; i++) {
  30365. for (var k = 0; k < points[i].length; k++) {
  30366. points[i][k][0] /= 10.5;
  30367. points[i][k][1] /= -10.5 / 0.75;
  30368. points[i][k][0] += geoCoord[0];
  30369. points[i][k][1] += geoCoord[1];
  30370. }
  30371. }
  30372. module.exports = function (geo) {
  30373. if (geo.map === 'china') {
  30374. geo.regions.push(new Region(
  30375. '南海诸岛',
  30376. zrUtil.map(points, function (exterior) {
  30377. return {
  30378. type: 'polygon',
  30379. exterior: exterior
  30380. };
  30381. }), geoCoord
  30382. ));
  30383. }
  30384. };
  30385. /***/ },
  30386. /* 178 */
  30387. /***/ function(module, exports, __webpack_require__) {
  30388. var zrUtil = __webpack_require__(4);
  30389. var coordsOffsetMap = {
  30390. '南海诸岛' : [32, 80],
  30391. // 全国
  30392. '广东': [0, -10],
  30393. '香港': [10, 5],
  30394. '澳门': [-10, 10],
  30395. //'北京': [-10, 0],
  30396. '天津': [5, 5]
  30397. };
  30398. module.exports = function (geo) {
  30399. zrUtil.each(geo.regions, function (region) {
  30400. var coordFix = coordsOffsetMap[region.name];
  30401. if (coordFix) {
  30402. var cp = region.center;
  30403. cp[0] += coordFix[0] / 10.5;
  30404. cp[1] += -coordFix[1] / (10.5 / 0.75);
  30405. }
  30406. });
  30407. };
  30408. /***/ },
  30409. /* 179 */
  30410. /***/ function(module, exports, __webpack_require__) {
  30411. var zrUtil = __webpack_require__(4);
  30412. var geoCoordMap = {
  30413. 'Russia': [100, 60],
  30414. 'United States': [-99, 38],
  30415. 'United States of America': [-99, 38]
  30416. };
  30417. module.exports = function (geo) {
  30418. zrUtil.each(geo.regions, function (region) {
  30419. var geoCoord = geoCoordMap[region.name];
  30420. if (geoCoord) {
  30421. var cp = region.center;
  30422. cp[0] = geoCoord[0];
  30423. cp[1] = geoCoord[1];
  30424. }
  30425. });
  30426. };
  30427. /***/ },
  30428. /* 180 */
  30429. /***/ function(module, exports, __webpack_require__) {
  30430. // var zrUtil = require('zrender/lib/core/util');
  30431. var graphic = __webpack_require__(18);
  30432. var MapDraw = __webpack_require__(181);
  30433. __webpack_require__(1).extendChartView({
  30434. type: 'map',
  30435. render: function (mapModel, ecModel, api, payload) {
  30436. // Not render if it is an toggleSelect action from self
  30437. if (payload && payload.type === 'mapToggleSelect'
  30438. && payload.from === this.uid
  30439. ) {
  30440. return;
  30441. }
  30442. var group = this.group;
  30443. group.removeAll();
  30444. if (mapModel.getHostGeoModel()) {
  30445. return;
  30446. }
  30447. // Not update map if it is an roam action from self
  30448. if (!(payload && payload.type === 'geoRoam'
  30449. && payload.componentType === 'series'
  30450. && payload.seriesId === mapModel.id
  30451. )
  30452. ) {
  30453. if (mapModel.needsDrawMap) {
  30454. var mapDraw = this._mapDraw || new MapDraw(api, true);
  30455. group.add(mapDraw.group);
  30456. mapDraw.draw(mapModel, ecModel, api, this, payload);
  30457. this._mapDraw = mapDraw;
  30458. }
  30459. else {
  30460. // Remove drawed map
  30461. this._mapDraw && this._mapDraw.remove();
  30462. this._mapDraw = null;
  30463. }
  30464. }
  30465. else {
  30466. var mapDraw = this._mapDraw;
  30467. mapDraw && group.add(mapDraw.group);
  30468. }
  30469. mapModel.get('showLegendSymbol') && ecModel.getComponent('legend')
  30470. && this._renderSymbols(mapModel, ecModel, api);
  30471. },
  30472. remove: function () {
  30473. this._mapDraw && this._mapDraw.remove();
  30474. this._mapDraw = null;
  30475. this.group.removeAll();
  30476. },
  30477. dispose: function () {
  30478. this._mapDraw && this._mapDraw.remove();
  30479. this._mapDraw = null;
  30480. },
  30481. _renderSymbols: function (mapModel, ecModel, api) {
  30482. var originalData = mapModel.originalData;
  30483. var group = this.group;
  30484. originalData.each('value', function (value, idx) {
  30485. if (isNaN(value)) {
  30486. return;
  30487. }
  30488. var layout = originalData.getItemLayout(idx);
  30489. if (!layout || !layout.point) {
  30490. // Not exists in map
  30491. return;
  30492. }
  30493. var point = layout.point;
  30494. var offset = layout.offset;
  30495. var circle = new graphic.Circle({
  30496. style: {
  30497. // Because the special of map draw.
  30498. // Which needs statistic of multiple series and draw on one map.
  30499. // And each series also need a symbol with legend color
  30500. //
  30501. // Layout and visual are put one the different data
  30502. fill: mapModel.getData().getVisual('color')
  30503. },
  30504. shape: {
  30505. cx: point[0] + offset * 9,
  30506. cy: point[1],
  30507. r: 3
  30508. },
  30509. silent: true,
  30510. z2: 10
  30511. });
  30512. // First data on the same region
  30513. if (!offset) {
  30514. var fullData = mapModel.mainSeries.getData();
  30515. var name = originalData.getName(idx);
  30516. var labelText = name;
  30517. var fullIndex = fullData.indexOfName(name);
  30518. var itemModel = originalData.getItemModel(idx);
  30519. var labelModel = itemModel.getModel('label.normal');
  30520. var hoverLabelModel = itemModel.getModel('label.emphasis');
  30521. var textStyleModel = labelModel.getModel('textStyle');
  30522. var hoverTextStyleModel = hoverLabelModel.getModel('textStyle');
  30523. var polygonGroups = fullData.getItemGraphicEl(fullIndex);
  30524. circle.setStyle({
  30525. textPosition: 'bottom'
  30526. });
  30527. var onEmphasis = function () {
  30528. circle.setStyle({
  30529. text: hoverLabelModel.get('show') ? labelText : '',
  30530. textFill: hoverTextStyleModel.getTextColor(),
  30531. textFont: hoverTextStyleModel.getFont()
  30532. });
  30533. };
  30534. var onNormal = function () {
  30535. circle.setStyle({
  30536. text: labelModel.get('show') ? labelText : '',
  30537. textFill: textStyleModel.getTextColor(),
  30538. textFont: textStyleModel.getFont()
  30539. });
  30540. };
  30541. polygonGroups.on('mouseover', onEmphasis)
  30542. .on('mouseout', onNormal)
  30543. .on('emphasis', onEmphasis)
  30544. .on('normal', onNormal);
  30545. onNormal();
  30546. }
  30547. group.add(circle);
  30548. });
  30549. }
  30550. });
  30551. /***/ },
  30552. /* 181 */
  30553. /***/ function(module, exports, __webpack_require__) {
  30554. /**
  30555. * @module echarts/component/helper/MapDraw
  30556. */
  30557. var RoamController = __webpack_require__(182);
  30558. var roamHelper = __webpack_require__(184);
  30559. var cursorHelper = __webpack_require__(185);
  30560. var graphic = __webpack_require__(18);
  30561. var zrUtil = __webpack_require__(4);
  30562. function getFixedItemStyle(model, scale) {
  30563. var itemStyle = model.getItemStyle();
  30564. var areaColor = model.get('areaColor');
  30565. // If user want the color not to be changed when hover,
  30566. // they should both set areaColor and color to be null.
  30567. if (areaColor != null) {
  30568. itemStyle.fill = areaColor;
  30569. }
  30570. return itemStyle;
  30571. }
  30572. function updateMapSelectHandler(mapDraw, mapOrGeoModel, group, api, fromView) {
  30573. group.off('click');
  30574. group.off('mousedown');
  30575. if (mapOrGeoModel.get('selectedMode')) {
  30576. group.on('mousedown', function () {
  30577. mapDraw._mouseDownFlag = true;
  30578. });
  30579. group.on('click', function (e) {
  30580. if (!mapDraw._mouseDownFlag) {
  30581. return;
  30582. }
  30583. mapDraw._mouseDownFlag = false;
  30584. var el = e.target;
  30585. while (!el.__regions) {
  30586. el = el.parent;
  30587. }
  30588. if (!el) {
  30589. return;
  30590. }
  30591. var action = {
  30592. type: (mapOrGeoModel.mainType === 'geo' ? 'geo' : 'map') + 'ToggleSelect',
  30593. batch: zrUtil.map(el.__regions, function (region) {
  30594. return {
  30595. name: region.name,
  30596. from: fromView.uid
  30597. };
  30598. })
  30599. };
  30600. action[mapOrGeoModel.mainType + 'Id'] = mapOrGeoModel.id;
  30601. api.dispatchAction(action);
  30602. updateMapSelected(mapOrGeoModel, group);
  30603. });
  30604. }
  30605. }
  30606. function updateMapSelected(mapOrGeoModel, group) {
  30607. // FIXME
  30608. group.eachChild(function (otherRegionEl) {
  30609. zrUtil.each(otherRegionEl.__regions, function (region) {
  30610. otherRegionEl.trigger(mapOrGeoModel.isSelected(region.name) ? 'emphasis' : 'normal');
  30611. });
  30612. });
  30613. }
  30614. /**
  30615. * @alias module:echarts/component/helper/MapDraw
  30616. * @param {module:echarts/ExtensionAPI} api
  30617. * @param {boolean} updateGroup
  30618. */
  30619. function MapDraw(api, updateGroup) {
  30620. var group = new graphic.Group();
  30621. /**
  30622. * @type {module:echarts/component/helper/RoamController}
  30623. * @private
  30624. */
  30625. this._controller = new RoamController(api.getZr());
  30626. /**
  30627. * @type {Object} {target, zoom, zoomLimit}
  30628. * @private
  30629. */
  30630. this._controllerHost = {target: updateGroup ? group : null};
  30631. /**
  30632. * @type {module:zrender/container/Group}
  30633. * @readOnly
  30634. */
  30635. this.group = group;
  30636. /**
  30637. * @type {boolean}
  30638. * @private
  30639. */
  30640. this._updateGroup = updateGroup;
  30641. /**
  30642. * This flag is used to make sure that only one among
  30643. * `pan`, `zoom`, `click` can occurs, otherwise 'selected'
  30644. * action may be triggered when `pan`, which is unexpected.
  30645. * @type {booelan}
  30646. */
  30647. this._mouseDownFlag;
  30648. }
  30649. MapDraw.prototype = {
  30650. constructor: MapDraw,
  30651. draw: function (mapOrGeoModel, ecModel, api, fromView, payload) {
  30652. var isGeo = mapOrGeoModel.mainType === 'geo';
  30653. // map series has data, geo model that controlled by map series
  30654. // has no data, otherwise data exists.
  30655. var data = mapOrGeoModel.getData && mapOrGeoModel.getData();
  30656. isGeo && ecModel.eachComponent({mainType: 'series', subType: 'map'}, function (mapSeries) {
  30657. if (!data && mapSeries.getHostGeoModel() === mapOrGeoModel) {
  30658. data = mapSeries.getData();
  30659. }
  30660. });
  30661. var geo = mapOrGeoModel.coordinateSystem;
  30662. var group = this.group;
  30663. var scale = geo.scale;
  30664. var groupNewProp = {
  30665. position: geo.position,
  30666. scale: scale
  30667. };
  30668. // No animation when first draw or in action
  30669. if (!group.childAt(0) || payload) {
  30670. group.attr(groupNewProp);
  30671. }
  30672. else {
  30673. graphic.updateProps(group, groupNewProp, mapOrGeoModel);
  30674. }
  30675. group.removeAll();
  30676. var itemStyleAccessPath = ['itemStyle', 'normal'];
  30677. var hoverItemStyleAccessPath = ['itemStyle', 'emphasis'];
  30678. var labelAccessPath = ['label', 'normal'];
  30679. var hoverLabelAccessPath = ['label', 'emphasis'];
  30680. var nameMap = zrUtil.createHashMap();
  30681. zrUtil.each(geo.regions, function (region) {
  30682. // Consider in GeoJson properties.name may be duplicated, for example,
  30683. // there is multiple region named "United Kindom" or "France" (so many
  30684. // colonies). And it is not appropriate to merge them in geo, which
  30685. // will make them share the same label and bring trouble in label
  30686. // location calculation.
  30687. var regionGroup = nameMap.get(region.name)
  30688. || nameMap.set(region.name, new graphic.Group());
  30689. var compoundPath = new graphic.CompoundPath({
  30690. shape: {
  30691. paths: []
  30692. }
  30693. });
  30694. regionGroup.add(compoundPath);
  30695. var regionModel = mapOrGeoModel.getRegionModel(region.name) || mapOrGeoModel;
  30696. var itemStyleModel = regionModel.getModel(itemStyleAccessPath);
  30697. var hoverItemStyleModel = regionModel.getModel(hoverItemStyleAccessPath);
  30698. var itemStyle = getFixedItemStyle(itemStyleModel, scale);
  30699. var hoverItemStyle = getFixedItemStyle(hoverItemStyleModel, scale);
  30700. var labelModel = regionModel.getModel(labelAccessPath);
  30701. var hoverLabelModel = regionModel.getModel(hoverLabelAccessPath);
  30702. var dataIdx;
  30703. // Use the itemStyle in data if has data
  30704. if (data) {
  30705. dataIdx = data.indexOfName(region.name);
  30706. // Only visual color of each item will be used. It can be encoded by dataRange
  30707. // But visual color of series is used in symbol drawing
  30708. //
  30709. // Visual color for each series is for the symbol draw
  30710. var visualColor = data.getItemVisual(dataIdx, 'color', true);
  30711. if (visualColor) {
  30712. itemStyle.fill = visualColor;
  30713. }
  30714. }
  30715. var textStyleModel = labelModel.getModel('textStyle');
  30716. var hoverTextStyleModel = hoverLabelModel.getModel('textStyle');
  30717. zrUtil.each(region.geometries, function (geometry) {
  30718. if (geometry.type !== 'polygon') {
  30719. return;
  30720. }
  30721. compoundPath.shape.paths.push(new graphic.Polygon({
  30722. shape: {
  30723. points: geometry.exterior
  30724. }
  30725. }));
  30726. for (var i = 0; i < (geometry.interiors ? geometry.interiors.length : 0); i++) {
  30727. compoundPath.shape.paths.push(new graphic.Polygon({
  30728. shape: {
  30729. points: geometry.interiors[i]
  30730. }
  30731. }));
  30732. }
  30733. });
  30734. compoundPath.setStyle(itemStyle);
  30735. compoundPath.style.strokeNoScale = true;
  30736. compoundPath.culling = true;
  30737. // Label
  30738. var showLabel = labelModel.get('show');
  30739. var hoverShowLabel = hoverLabelModel.get('show');
  30740. var isDataNaN = data && isNaN(data.get('value', dataIdx));
  30741. var itemLayout = data && data.getItemLayout(dataIdx);
  30742. // In the following cases label will be drawn
  30743. // 1. In map series and data value is NaN
  30744. // 2. In geo component
  30745. // 4. Region has no series legendSymbol, which will be add a showLabel flag in mapSymbolLayout
  30746. if (
  30747. (isGeo || isDataNaN && (showLabel || hoverShowLabel))
  30748. || (itemLayout && itemLayout.showLabel)
  30749. ) {
  30750. var query = data ? dataIdx : region.name;
  30751. var formattedStr = mapOrGeoModel.getFormattedLabel(query, 'normal');
  30752. var hoverFormattedStr = mapOrGeoModel.getFormattedLabel(query, 'emphasis');
  30753. var text = new graphic.Text({
  30754. style: {
  30755. text: showLabel ? (formattedStr || region.name) : '',
  30756. fill: textStyleModel.getTextColor(),
  30757. textFont: textStyleModel.getFont(),
  30758. textAlign: 'center',
  30759. textVerticalAlign: 'middle'
  30760. },
  30761. hoverStyle: {
  30762. text: hoverShowLabel ? (hoverFormattedStr || region.name) : '',
  30763. fill: hoverTextStyleModel.getTextColor(),
  30764. textFont: hoverTextStyleModel.getFont()
  30765. },
  30766. position: region.center.slice(),
  30767. scale: [1 / scale[0], 1 / scale[1]],
  30768. z2: 10,
  30769. silent: true
  30770. });
  30771. regionGroup.add(text);
  30772. }
  30773. // setItemGraphicEl, setHoverStyle after all polygons and labels
  30774. // are added to the rigionGroup
  30775. if (data) {
  30776. data.setItemGraphicEl(dataIdx, regionGroup);
  30777. }
  30778. else {
  30779. var regionModel = mapOrGeoModel.getRegionModel(region.name);
  30780. // Package custom mouse event for geo component
  30781. compoundPath.eventData = {
  30782. componentType: 'geo',
  30783. geoIndex: mapOrGeoModel.componentIndex,
  30784. name: region.name,
  30785. region: (regionModel && regionModel.option) || {}
  30786. };
  30787. }
  30788. var groupRegions = regionGroup.__regions || (regionGroup.__regions = []);
  30789. groupRegions.push(region);
  30790. graphic.setHoverStyle(
  30791. regionGroup,
  30792. hoverItemStyle,
  30793. {hoverSilentOnTouch: !!mapOrGeoModel.get('selectedMode')}
  30794. );
  30795. group.add(regionGroup);
  30796. });
  30797. this._updateController(mapOrGeoModel, ecModel, api);
  30798. updateMapSelectHandler(this, mapOrGeoModel, group, api, fromView);
  30799. updateMapSelected(mapOrGeoModel, group);
  30800. },
  30801. remove: function () {
  30802. this.group.removeAll();
  30803. this._controller.dispose();
  30804. this._controllerHost = {};
  30805. },
  30806. _updateController: function (mapOrGeoModel, ecModel, api) {
  30807. var geo = mapOrGeoModel.coordinateSystem;
  30808. var controller = this._controller;
  30809. var controllerHost = this._controllerHost;
  30810. controllerHost.zoomLimit = mapOrGeoModel.get('scaleLimit');
  30811. controllerHost.zoom = geo.getZoom();
  30812. // roamType is will be set default true if it is null
  30813. controller.enable(mapOrGeoModel.get('roam') || false);
  30814. var mainType = mapOrGeoModel.mainType;
  30815. function makeActionBase() {
  30816. var action = {
  30817. type: 'geoRoam',
  30818. componentType: mainType
  30819. };
  30820. action[mainType + 'Id'] = mapOrGeoModel.id;
  30821. return action;
  30822. }
  30823. controller.off('pan').on('pan', function (dx, dy) {
  30824. this._mouseDownFlag = false;
  30825. roamHelper.updateViewOnPan(controllerHost, dx, dy);
  30826. api.dispatchAction(zrUtil.extend(makeActionBase(), {
  30827. dx: dx,
  30828. dy: dy
  30829. }));
  30830. }, this);
  30831. controller.off('zoom').on('zoom', function (zoom, mouseX, mouseY) {
  30832. this._mouseDownFlag = false;
  30833. roamHelper.updateViewOnZoom(controllerHost, zoom, mouseX, mouseY);
  30834. api.dispatchAction(zrUtil.extend(makeActionBase(), {
  30835. zoom: zoom,
  30836. originX: mouseX,
  30837. originY: mouseY
  30838. }));
  30839. if (this._updateGroup) {
  30840. var group = this.group;
  30841. var scale = group.scale;
  30842. group.traverse(function (el) {
  30843. if (el.type === 'text') {
  30844. el.attr('scale', [1 / scale[0], 1 / scale[1]]);
  30845. }
  30846. });
  30847. }
  30848. }, this);
  30849. controller.setPointerChecker(function (e, x, y) {
  30850. return geo.getViewRectAfterRoam().contain(x, y)
  30851. && !cursorHelper.onIrrelevantElement(e, api, mapOrGeoModel);
  30852. });
  30853. }
  30854. };
  30855. module.exports = MapDraw;
  30856. /***/ },
  30857. /* 182 */
  30858. /***/ function(module, exports, __webpack_require__) {
  30859. /**
  30860. * @module echarts/component/helper/RoamController
  30861. */
  30862. var Eventful = __webpack_require__(25);
  30863. var zrUtil = __webpack_require__(4);
  30864. var eventTool = __webpack_require__(88);
  30865. var interactionMutex = __webpack_require__(183);
  30866. /**
  30867. * @alias module:echarts/component/helper/RoamController
  30868. * @constructor
  30869. * @mixin {module:zrender/mixin/Eventful}
  30870. *
  30871. * @param {module:zrender/zrender~ZRender} zr
  30872. */
  30873. function RoamController(zr) {
  30874. /**
  30875. * @type {Function}
  30876. */
  30877. this.pointerChecker;
  30878. /**
  30879. * @type {module:zrender}
  30880. */
  30881. this._zr = zr;
  30882. /**
  30883. * @type {Object}
  30884. */
  30885. this._opt = {};
  30886. // Avoid two roamController bind the same handler
  30887. var bind = zrUtil.bind;
  30888. var mousedownHandler = bind(mousedown, this);
  30889. var mousemoveHandler = bind(mousemove, this);
  30890. var mouseupHandler = bind(mouseup, this);
  30891. var mousewheelHandler = bind(mousewheel, this);
  30892. var pinchHandler = bind(pinch, this);
  30893. Eventful.call(this);
  30894. /**
  30895. * @param {Function} pointerChecker
  30896. * input: x, y
  30897. * output: boolean
  30898. */
  30899. this.setPointerChecker = function (pointerChecker) {
  30900. this.pointerChecker = pointerChecker;
  30901. };
  30902. /**
  30903. * Notice: only enable needed types. For example, if 'zoom'
  30904. * is not needed, 'zoom' should not be enabled, otherwise
  30905. * default mousewheel behaviour (scroll page) will be disabled.
  30906. *
  30907. * @param {boolean|string} [controlType=true] Specify the control type,
  30908. * which can be null/undefined or true/false
  30909. * or 'pan/move' or 'zoom'/'scale'
  30910. * @param {Object} [opt]
  30911. * @param {Object} [opt.zoomOnMouseWheel=true]
  30912. * @param {Object} [opt.moveOnMouseMove=true]
  30913. * @param {Object} [opt.preventDefaultMouseMove=true] When pan.
  30914. */
  30915. this.enable = function (controlType, opt) {
  30916. // Disable previous first
  30917. this.disable();
  30918. this._opt = zrUtil.defaults(zrUtil.clone(opt) || {}, {
  30919. zoomOnMouseWheel: true,
  30920. moveOnMouseMove: true,
  30921. preventDefaultMouseMove: true
  30922. });
  30923. if (controlType == null) {
  30924. controlType = true;
  30925. }
  30926. if (controlType === true || (controlType === 'move' || controlType === 'pan')) {
  30927. zr.on('mousedown', mousedownHandler);
  30928. zr.on('mousemove', mousemoveHandler);
  30929. zr.on('mouseup', mouseupHandler);
  30930. }
  30931. if (controlType === true || (controlType === 'scale' || controlType === 'zoom')) {
  30932. zr.on('mousewheel', mousewheelHandler);
  30933. zr.on('pinch', pinchHandler);
  30934. }
  30935. };
  30936. this.disable = function () {
  30937. zr.off('mousedown', mousedownHandler);
  30938. zr.off('mousemove', mousemoveHandler);
  30939. zr.off('mouseup', mouseupHandler);
  30940. zr.off('mousewheel', mousewheelHandler);
  30941. zr.off('pinch', pinchHandler);
  30942. };
  30943. this.dispose = this.disable;
  30944. this.isDragging = function () {
  30945. return this._dragging;
  30946. };
  30947. this.isPinching = function () {
  30948. return this._pinching;
  30949. };
  30950. }
  30951. zrUtil.mixin(RoamController, Eventful);
  30952. function mousedown(e) {
  30953. if (e.target && e.target.draggable) {
  30954. return;
  30955. }
  30956. var x = e.offsetX;
  30957. var y = e.offsetY;
  30958. // Only check on mosedown, but not mousemove.
  30959. // Mouse can be out of target when mouse moving.
  30960. if (this.pointerChecker && this.pointerChecker(e, x, y)) {
  30961. this._x = x;
  30962. this._y = y;
  30963. this._dragging = true;
  30964. }
  30965. }
  30966. function mousemove(e) {
  30967. if (!checkKeyBinding(this, 'moveOnMouseMove', e) || !this._dragging) {
  30968. return;
  30969. }
  30970. if (e.gestureEvent === 'pinch') {
  30971. return;
  30972. }
  30973. if (interactionMutex.isTaken(this._zr, 'globalPan')) {
  30974. return;
  30975. }
  30976. var x = e.offsetX;
  30977. var y = e.offsetY;
  30978. var oldX = this._x;
  30979. var oldY = this._y;
  30980. var dx = x - oldX;
  30981. var dy = y - oldY;
  30982. this._x = x;
  30983. this._y = y;
  30984. this._opt.preventDefaultMouseMove && eventTool.stop(e.event);
  30985. this.trigger('pan', dx, dy, oldX, oldY, x, y);
  30986. }
  30987. function mouseup(e) {
  30988. this._dragging = false;
  30989. }
  30990. function mousewheel(e) {
  30991. // wheelDelta maybe -0 in chrome mac.
  30992. if (!checkKeyBinding(this, 'zoomOnMouseWheel', e) || e.wheelDelta === 0) {
  30993. return;
  30994. }
  30995. // Convenience:
  30996. // Mac and VM Windows on Mac: scroll up: zoom out.
  30997. // Windows: scroll up: zoom in.
  30998. var zoomDelta = e.wheelDelta > 0 ? 1.1 : 1 / 1.1;
  30999. zoom.call(this, e, zoomDelta, e.offsetX, e.offsetY);
  31000. }
  31001. function pinch(e) {
  31002. if (interactionMutex.isTaken(this._zr, 'globalPan')) {
  31003. return;
  31004. }
  31005. var zoomDelta = e.pinchScale > 1 ? 1.1 : 1 / 1.1;
  31006. zoom.call(this, e, zoomDelta, e.pinchX, e.pinchY);
  31007. }
  31008. function zoom(e, zoomDelta, zoomX, zoomY) {
  31009. if (this.pointerChecker && this.pointerChecker(e, zoomX, zoomY)) {
  31010. // When mouse is out of roamController rect,
  31011. // default befavoius should not be be disabled, otherwise
  31012. // page sliding is disabled, contrary to expectation.
  31013. eventTool.stop(e.event);
  31014. this.trigger('zoom', zoomDelta, zoomX, zoomY);
  31015. }
  31016. }
  31017. function checkKeyBinding(roamController, prop, e) {
  31018. var setting = roamController._opt[prop];
  31019. return setting
  31020. && (!zrUtil.isString(setting) || e.event[setting + 'Key']);
  31021. }
  31022. module.exports = RoamController;
  31023. /***/ },
  31024. /* 183 */
  31025. /***/ function(module, exports, __webpack_require__) {
  31026. var ATTR = '\0_ec_interaction_mutex';
  31027. var interactionMutex = {
  31028. take: function (zr, resourceKey, userKey) {
  31029. var store = getStore(zr);
  31030. store[resourceKey] = userKey;
  31031. },
  31032. release: function (zr, resourceKey, userKey) {
  31033. var store = getStore(zr);
  31034. var uKey = store[resourceKey];
  31035. if (uKey === userKey) {
  31036. store[resourceKey] = null;
  31037. }
  31038. },
  31039. isTaken: function (zr, resourceKey) {
  31040. return !!getStore(zr)[resourceKey];
  31041. }
  31042. };
  31043. function getStore(zr) {
  31044. return zr[ATTR] || (zr[ATTR] = {});
  31045. }
  31046. /**
  31047. * payload: {
  31048. * type: 'takeGlobalCursor',
  31049. * key: 'dataZoomSelect', or 'brush', or ...,
  31050. * If no userKey, release global cursor.
  31051. * }
  31052. */
  31053. __webpack_require__(1).registerAction(
  31054. {type: 'takeGlobalCursor', event: 'globalCursorTaken', update: 'update'},
  31055. function () {}
  31056. );
  31057. module.exports = interactionMutex;
  31058. /***/ },
  31059. /* 184 */
  31060. /***/ function(module, exports) {
  31061. var helper = {};
  31062. /**
  31063. * For geo and graph.
  31064. *
  31065. * @param {Object} controllerHost
  31066. * @param {module:zrender/Element} controllerHost.target
  31067. */
  31068. helper.updateViewOnPan = function (controllerHost, dx, dy) {
  31069. var target = controllerHost.target;
  31070. var pos = target.position;
  31071. pos[0] += dx;
  31072. pos[1] += dy;
  31073. target.dirty();
  31074. };
  31075. /**
  31076. * For geo and graph.
  31077. *
  31078. * @param {Object} controllerHost
  31079. * @param {module:zrender/Element} controllerHost.target
  31080. * @param {number} controllerHost.zoom
  31081. * @param {number} controllerHost.zoomLimit like: {min: 1, max: 2}
  31082. */
  31083. helper.updateViewOnZoom = function (controllerHost, zoomDelta, zoomX, zoomY) {
  31084. var target = controllerHost.target;
  31085. var zoomLimit = controllerHost.zoomLimit;
  31086. var pos = target.position;
  31087. var scale = target.scale;
  31088. var newZoom = controllerHost.zoom = controllerHost.zoom || 1;
  31089. newZoom *= zoomDelta;
  31090. if (zoomLimit) {
  31091. var zoomMin = zoomLimit.min || 0;
  31092. var zoomMax = zoomLimit.max || Infinity;
  31093. newZoom = Math.max(
  31094. Math.min(zoomMax, newZoom),
  31095. zoomMin
  31096. );
  31097. }
  31098. var zoomScale = newZoom / controllerHost.zoom;
  31099. controllerHost.zoom = newZoom;
  31100. // Keep the mouse center when scaling
  31101. pos[0] -= (zoomX - pos[0]) * (zoomScale - 1);
  31102. pos[1] -= (zoomY - pos[1]) * (zoomScale - 1);
  31103. scale[0] *= zoomScale;
  31104. scale[1] *= zoomScale;
  31105. target.dirty();
  31106. };
  31107. module.exports = helper;
  31108. /***/ },
  31109. /* 185 */
  31110. /***/ function(module, exports) {
  31111. var helper = {};
  31112. var IRRELEVANT_EXCLUDES = {'axisPointer': 1, 'tooltip': 1, 'brush': 1};
  31113. /**
  31114. * Avoid that: mouse click on a elements that is over geo or graph,
  31115. * but roam is triggered.
  31116. */
  31117. helper.onIrrelevantElement = function (e, api, targetCoordSysModel) {
  31118. var model = api.getComponentByElement(e.topTarget);
  31119. // If model is axisModel, it works only if it is injected with coordinateSystem.
  31120. var coordSys = model && model.coordinateSystem;
  31121. return model
  31122. && model !== targetCoordSysModel
  31123. && !IRRELEVANT_EXCLUDES[model.mainType]
  31124. && (coordSys && coordSys.model !== targetCoordSysModel);
  31125. };
  31126. module.exports = helper;
  31127. /***/ },
  31128. /* 186 */
  31129. /***/ function(module, exports, __webpack_require__) {
  31130. var zrUtil = __webpack_require__(4);
  31131. var roamHelper = __webpack_require__(187);
  31132. var echarts = __webpack_require__(1);
  31133. /**
  31134. * @payload
  31135. * @property {string} [componentType=series]
  31136. * @property {number} [dx]
  31137. * @property {number} [dy]
  31138. * @property {number} [zoom]
  31139. * @property {number} [originX]
  31140. * @property {number} [originY]
  31141. */
  31142. echarts.registerAction({
  31143. type: 'geoRoam',
  31144. event: 'geoRoam',
  31145. update: 'updateLayout'
  31146. }, function (payload, ecModel) {
  31147. var componentType = payload.componentType || 'series';
  31148. ecModel.eachComponent(
  31149. { mainType: componentType, query: payload },
  31150. function (componentModel) {
  31151. var geo = componentModel.coordinateSystem;
  31152. if (geo.type !== 'geo') {
  31153. return;
  31154. }
  31155. var res = roamHelper.updateCenterAndZoom(
  31156. geo, payload, componentModel.get('scaleLimit')
  31157. );
  31158. componentModel.setCenter
  31159. && componentModel.setCenter(res.center);
  31160. componentModel.setZoom
  31161. && componentModel.setZoom(res.zoom);
  31162. // All map series with same `map` use the same geo coordinate system
  31163. // So the center and zoom must be in sync. Include the series not selected by legend
  31164. if (componentType === 'series') {
  31165. zrUtil.each(componentModel.seriesGroup, function (seriesModel) {
  31166. seriesModel.setCenter(res.center);
  31167. seriesModel.setZoom(res.zoom);
  31168. });
  31169. }
  31170. }
  31171. );
  31172. });
  31173. /***/ },
  31174. /* 187 */
  31175. /***/ function(module, exports) {
  31176. var roamHelper = {};
  31177. /**
  31178. * @param {module:echarts/coord/View} view
  31179. * @param {Object} payload
  31180. * @param {Object} [zoomLimit]
  31181. */
  31182. roamHelper.updateCenterAndZoom = function (
  31183. view, payload, zoomLimit
  31184. ) {
  31185. var previousZoom = view.getZoom();
  31186. var center = view.getCenter();
  31187. var zoom = payload.zoom;
  31188. var point = view.dataToPoint(center);
  31189. if (payload.dx != null && payload.dy != null) {
  31190. point[0] -= payload.dx;
  31191. point[1] -= payload.dy;
  31192. var center = view.pointToData(point);
  31193. view.setCenter(center);
  31194. }
  31195. if (zoom != null) {
  31196. if (zoomLimit) {
  31197. var zoomMin = zoomLimit.min || 0;
  31198. var zoomMax = zoomLimit.max || Infinity;
  31199. zoom = Math.max(
  31200. Math.min(previousZoom * zoom, zoomMax),
  31201. zoomMin
  31202. ) / previousZoom;
  31203. }
  31204. // Zoom on given point(originX, originY)
  31205. view.scale[0] *= zoom;
  31206. view.scale[1] *= zoom;
  31207. var position = view.position;
  31208. var fixX = (payload.originX - position[0]) * (zoom - 1);
  31209. var fixY = (payload.originY - position[1]) * (zoom - 1);
  31210. position[0] -= fixX;
  31211. position[1] -= fixY;
  31212. view.updateTransform();
  31213. // Get the new center
  31214. var center = view.pointToData(point);
  31215. view.setCenter(center);
  31216. view.setZoom(zoom * previousZoom);
  31217. }
  31218. return {
  31219. center: view.getCenter(),
  31220. zoom: view.getZoom()
  31221. };
  31222. };
  31223. module.exports = roamHelper;
  31224. /***/ },
  31225. /* 188 */
  31226. /***/ function(module, exports, __webpack_require__) {
  31227. var zrUtil = __webpack_require__(4);
  31228. module.exports = function (ecModel) {
  31229. var processedMapType = {};
  31230. ecModel.eachSeriesByType('map', function (mapSeries) {
  31231. var mapType = mapSeries.getMapType();
  31232. if (mapSeries.getHostGeoModel() || processedMapType[mapType]) {
  31233. return;
  31234. }
  31235. var mapSymbolOffsets = {};
  31236. zrUtil.each(mapSeries.seriesGroup, function (subMapSeries) {
  31237. var geo = subMapSeries.coordinateSystem;
  31238. var data = subMapSeries.originalData;
  31239. if (subMapSeries.get('showLegendSymbol') && ecModel.getComponent('legend')) {
  31240. data.each('value', function (value, idx) {
  31241. var name = data.getName(idx);
  31242. var region = geo.getRegion(name);
  31243. // If input series.data is [11, 22, '-'/null/undefined, 44],
  31244. // it will be filled with NaN: [11, 22, NaN, 44] and NaN will
  31245. // not be drawn. So here must validate if value is NaN.
  31246. if (!region || isNaN(value)) {
  31247. return;
  31248. }
  31249. var offset = mapSymbolOffsets[name] || 0;
  31250. var point = geo.dataToPoint(region.center);
  31251. mapSymbolOffsets[name] = offset + 1;
  31252. data.setItemLayout(idx, {
  31253. point: point,
  31254. offset: offset
  31255. });
  31256. });
  31257. }
  31258. });
  31259. // Show label of those region not has legendSymbol(which is offset 0)
  31260. var data = mapSeries.getData();
  31261. data.each(function (idx) {
  31262. var name = data.getName(idx);
  31263. var layout = data.getItemLayout(idx) || {};
  31264. layout.showLabel = !mapSymbolOffsets[name];
  31265. data.setItemLayout(idx, layout);
  31266. });
  31267. processedMapType[mapType] = true;
  31268. });
  31269. };
  31270. /***/ },
  31271. /* 189 */
  31272. /***/ function(module, exports) {
  31273. module.exports = function (ecModel) {
  31274. ecModel.eachSeriesByType('map', function (seriesModel) {
  31275. var colorList = seriesModel.get('color');
  31276. var itemStyleModel = seriesModel.getModel('itemStyle.normal');
  31277. var areaColor = itemStyleModel.get('areaColor');
  31278. var color = itemStyleModel.get('color')
  31279. || colorList[seriesModel.seriesIndex % colorList.length];
  31280. seriesModel.getData().setVisual({
  31281. 'areaColor': areaColor,
  31282. 'color': color
  31283. });
  31284. });
  31285. };
  31286. /***/ },
  31287. /* 190 */
  31288. /***/ function(module, exports, __webpack_require__) {
  31289. var zrUtil = __webpack_require__(4);
  31290. // FIXME 公用?
  31291. /**
  31292. * @param {Array.<module:echarts/data/List>} datas
  31293. * @param {string} statisticType 'average' 'sum'
  31294. * @inner
  31295. */
  31296. function dataStatistics(datas, statisticType) {
  31297. var dataNameMap = {};
  31298. var dims = ['value'];
  31299. zrUtil.each(datas, function (data) {
  31300. data.each(dims, function (value, idx) {
  31301. // Add prefix to avoid conflict with Object.prototype.
  31302. var mapKey = 'ec-' + data.getName(idx);
  31303. dataNameMap[mapKey] = dataNameMap[mapKey] || [];
  31304. if (!isNaN(value)) {
  31305. dataNameMap[mapKey].push(value);
  31306. }
  31307. });
  31308. });
  31309. return datas[0].map(dims, function (value, idx) {
  31310. var mapKey = 'ec-' + datas[0].getName(idx);
  31311. var sum = 0;
  31312. var min = Infinity;
  31313. var max = -Infinity;
  31314. var len = dataNameMap[mapKey].length;
  31315. for (var i = 0; i < len; i++) {
  31316. min = Math.min(min, dataNameMap[mapKey][i]);
  31317. max = Math.max(max, dataNameMap[mapKey][i]);
  31318. sum += dataNameMap[mapKey][i];
  31319. }
  31320. var result;
  31321. if (statisticType === 'min') {
  31322. result = min;
  31323. }
  31324. else if (statisticType === 'max') {
  31325. result = max;
  31326. }
  31327. else if (statisticType === 'average') {
  31328. result = sum / len;
  31329. }
  31330. else {
  31331. result = sum;
  31332. }
  31333. return len === 0 ? NaN : result;
  31334. });
  31335. }
  31336. module.exports = function (ecModel) {
  31337. var seriesGroups = {};
  31338. ecModel.eachSeriesByType('map', function (seriesModel) {
  31339. var hostGeoModel = seriesModel.getHostGeoModel();
  31340. var key = hostGeoModel ? 'o' + hostGeoModel.id : 'i' + seriesModel.getMapType();
  31341. (seriesGroups[key] = seriesGroups[key] || []).push(seriesModel);
  31342. });
  31343. zrUtil.each(seriesGroups, function (seriesList, key) {
  31344. var data = dataStatistics(
  31345. zrUtil.map(seriesList, function (seriesModel) {
  31346. return seriesModel.getData();
  31347. }),
  31348. seriesList[0].get('mapValueCalculation')
  31349. );
  31350. for (var i = 0; i < seriesList.length; i++) {
  31351. seriesList[i].originalData = seriesList[i].getData();
  31352. }
  31353. // FIXME Put where?
  31354. for (var i = 0; i < seriesList.length; i++) {
  31355. seriesList[i].seriesGroup = seriesList;
  31356. seriesList[i].needsDrawMap = i === 0 && !seriesList[i].getHostGeoModel();
  31357. seriesList[i].setData(data.cloneShallow());
  31358. seriesList[i].mainSeries = seriesList[0];
  31359. }
  31360. });
  31361. };
  31362. /***/ },
  31363. /* 191 */
  31364. /***/ function(module, exports, __webpack_require__) {
  31365. var zrUtil = __webpack_require__(4);
  31366. module.exports = function (option) {
  31367. // Save geoCoord
  31368. var mapSeries = [];
  31369. zrUtil.each(option.series, function (seriesOpt) {
  31370. if (seriesOpt.type === 'map') {
  31371. mapSeries.push(seriesOpt);
  31372. }
  31373. });
  31374. zrUtil.each(mapSeries, function (seriesOpt) {
  31375. seriesOpt.map = seriesOpt.map || seriesOpt.mapType;
  31376. // Put x, y, width, height, x2, y2 in the top level
  31377. zrUtil.defaults(seriesOpt, seriesOpt.mapLocation);
  31378. });
  31379. };
  31380. /***/ },
  31381. /* 192 */
  31382. /***/ function(module, exports, __webpack_require__) {
  31383. var echarts = __webpack_require__(1);
  31384. __webpack_require__(193);
  31385. __webpack_require__(197);
  31386. __webpack_require__(200);
  31387. echarts.registerVisual(__webpack_require__(201));
  31388. echarts.registerLayout(__webpack_require__(203));
  31389. /***/ },
  31390. /* 193 */
  31391. /***/ function(module, exports, __webpack_require__) {
  31392. var SeriesModel = __webpack_require__(78);
  31393. var Tree = __webpack_require__(194);
  31394. var zrUtil = __webpack_require__(4);
  31395. var Model = __webpack_require__(12);
  31396. var formatUtil = __webpack_require__(6);
  31397. var helper = __webpack_require__(196);
  31398. var encodeHTML = formatUtil.encodeHTML;
  31399. var addCommas = formatUtil.addCommas;
  31400. module.exports = SeriesModel.extend({
  31401. type: 'series.treemap',
  31402. layoutMode: 'box',
  31403. dependencies: ['grid', 'polar'],
  31404. /**
  31405. * @type {module:echarts/data/Tree~Node}
  31406. */
  31407. _viewRoot: null,
  31408. defaultOption: {
  31409. // Disable progressive rendering
  31410. progressive: 0,
  31411. hoverLayerThreshold: Infinity,
  31412. // center: ['50%', '50%'], // not supported in ec3.
  31413. // size: ['80%', '80%'], // deprecated, compatible with ec2.
  31414. left: 'center',
  31415. top: 'middle',
  31416. right: null,
  31417. bottom: null,
  31418. width: '80%',
  31419. height: '80%',
  31420. sort: true, // Can be null or false or true
  31421. // (order by desc default, asc not supported yet (strange effect))
  31422. clipWindow: 'origin', // Size of clipped window when zooming. 'origin' or 'fullscreen'
  31423. squareRatio: 0.5 * (1 + Math.sqrt(5)), // golden ratio
  31424. leafDepth: null, // Nodes on depth from root are regarded as leaves.
  31425. // Count from zero (zero represents only view root).
  31426. drillDownIcon: '▶', // Use html character temporarily because it is complicated
  31427. // to align specialized icon. ▷▶❒❐▼✚
  31428. zoomToNodeRatio: 0.32 * 0.32, // Be effective when using zoomToNode. Specify the proportion of the
  31429. // target node area in the view area.
  31430. roam: true, // true, false, 'scale' or 'zoom', 'move'.
  31431. nodeClick: 'zoomToNode', // Leaf node click behaviour: 'zoomToNode', 'link', false.
  31432. // If leafDepth is set and clicking a node which has children but
  31433. // be on left depth, the behaviour would be changing root. Otherwise
  31434. // use behavious defined above.
  31435. animation: true,
  31436. animationDurationUpdate: 900,
  31437. animationEasing: 'quinticInOut',
  31438. breadcrumb: {
  31439. show: true,
  31440. height: 22,
  31441. left: 'center',
  31442. top: 'bottom',
  31443. // right
  31444. // bottom
  31445. emptyItemWidth: 25, // Width of empty node.
  31446. itemStyle: {
  31447. normal: {
  31448. color: 'rgba(0,0,0,0.7)', //'#5793f3',
  31449. borderColor: 'rgba(255,255,255,0.7)',
  31450. borderWidth: 1,
  31451. shadowColor: 'rgba(150,150,150,1)',
  31452. shadowBlur: 3,
  31453. shadowOffsetX: 0,
  31454. shadowOffsetY: 0,
  31455. textStyle: {
  31456. color: '#fff'
  31457. }
  31458. },
  31459. emphasis: {
  31460. textStyle: {}
  31461. }
  31462. }
  31463. },
  31464. label: {
  31465. normal: {
  31466. show: true,
  31467. position: 'inside', // Can be [5, '5%'] or position stirng like 'insideTopLeft', ...
  31468. textStyle: {
  31469. color: '#fff',
  31470. ellipsis: true
  31471. }
  31472. }
  31473. },
  31474. itemStyle: {
  31475. normal: {
  31476. color: null, // Can be 'none' if not necessary.
  31477. colorAlpha: null, // Can be 'none' if not necessary.
  31478. colorSaturation: null, // Can be 'none' if not necessary.
  31479. borderWidth: 0,
  31480. gapWidth: 0,
  31481. borderColor: '#fff',
  31482. borderColorSaturation: null // If specified, borderColor will be ineffective, and the
  31483. // border color is evaluated by color of current node and
  31484. // borderColorSaturation.
  31485. },
  31486. emphasis: {
  31487. }
  31488. },
  31489. visualDimension: 0, // Can be 0, 1, 2, 3.
  31490. visualMin: null,
  31491. visualMax: null,
  31492. color: [], // + treemapSeries.color should not be modified. Please only modified
  31493. // level[n].color (if necessary).
  31494. // + Specify color list of each level. level[0].color would be global
  31495. // color list if not specified. (see method `setDefault`).
  31496. // + But set as a empty array to forbid fetch color from global palette
  31497. // when using nodeModel.get('color'), otherwise nodes on deep level
  31498. // will always has color palette set and are not able to inherit color
  31499. // from parent node.
  31500. // + TreemapSeries.color can not be set as 'none', otherwise effect
  31501. // legend color fetching (see seriesColor.js).
  31502. colorAlpha: null, // Array. Specify color alpha range of each level, like [0.2, 0.8]
  31503. colorSaturation: null, // Array. Specify color saturation of each level, like [0.2, 0.5]
  31504. colorMappingBy: 'index', // 'value' or 'index' or 'id'.
  31505. visibleMin: 10, // If area less than this threshold (unit: pixel^2), node will not
  31506. // be rendered. Only works when sort is 'asc' or 'desc'.
  31507. childrenVisibleMin: null, // If area of a node less than this threshold (unit: pixel^2),
  31508. // grandchildren will not show.
  31509. // Why grandchildren? If not grandchildren but children,
  31510. // some siblings show children and some not,
  31511. // the appearance may be mess and not consistent,
  31512. levels: [] // Each item: {
  31513. // visibleMin, itemStyle, visualDimension, label
  31514. // }
  31515. // data: {
  31516. // value: [],
  31517. // children: [],
  31518. // link: 'http://xxx.xxx.xxx',
  31519. // target: 'blank' or 'self'
  31520. // }
  31521. },
  31522. /**
  31523. * @override
  31524. */
  31525. getInitialData: function (option, ecModel) {
  31526. var rootName = option.name;
  31527. rootName == null && (rootName = option.name);
  31528. // Create a virtual root.
  31529. var root = {name: rootName, children: option.data};
  31530. completeTreeValue(root);
  31531. var levels = option.levels || [];
  31532. levels = option.levels = setDefault(levels, ecModel);
  31533. // Make sure always a new tree is created when setOption,
  31534. // in TreemapView, we check whether oldTree === newTree
  31535. // to choose mappings approach among old shapes and new shapes.
  31536. return Tree.createTree(root, this, levels).data;
  31537. },
  31538. optionUpdated: function () {
  31539. this.resetViewRoot();
  31540. },
  31541. /**
  31542. * @override
  31543. * @param {number} dataIndex
  31544. * @param {boolean} [mutipleSeries=false]
  31545. */
  31546. formatTooltip: function (dataIndex) {
  31547. var data = this.getData();
  31548. var value = this.getRawValue(dataIndex);
  31549. var formattedValue = zrUtil.isArray(value)
  31550. ? addCommas(value[0]) : addCommas(value);
  31551. var name = data.getName(dataIndex);
  31552. return encodeHTML(name + ': ' + formattedValue);
  31553. },
  31554. /**
  31555. * Add tree path to tooltip param
  31556. *
  31557. * @override
  31558. * @param {number} dataIndex
  31559. * @return {Object}
  31560. */
  31561. getDataParams: function (dataIndex) {
  31562. var params = SeriesModel.prototype.getDataParams.apply(this, arguments);
  31563. var node = this.getData().tree.getNodeByDataIndex(dataIndex);
  31564. params.treePathInfo = helper.wrapTreePathInfo(node, this);
  31565. return params;
  31566. },
  31567. /**
  31568. * @public
  31569. * @param {Object} layoutInfo {
  31570. * x: containerGroup x
  31571. * y: containerGroup y
  31572. * width: containerGroup width
  31573. * height: containerGroup height
  31574. * }
  31575. */
  31576. setLayoutInfo: function (layoutInfo) {
  31577. /**
  31578. * @readOnly
  31579. * @type {Object}
  31580. */
  31581. this.layoutInfo = this.layoutInfo || {};
  31582. zrUtil.extend(this.layoutInfo, layoutInfo);
  31583. },
  31584. /**
  31585. * @param {string} id
  31586. * @return {number} index
  31587. */
  31588. mapIdToIndex: function (id) {
  31589. // A feature is implemented:
  31590. // index is monotone increasing with the sequence of
  31591. // input id at the first time.
  31592. // This feature can make sure that each data item and its
  31593. // mapped color have the same index between data list and
  31594. // color list at the beginning, which is useful for user
  31595. // to adjust data-color mapping.
  31596. /**
  31597. * @private
  31598. * @type {Object}
  31599. */
  31600. var idIndexMap = this._idIndexMap;
  31601. if (!idIndexMap) {
  31602. idIndexMap = this._idIndexMap = zrUtil.createHashMap();
  31603. /**
  31604. * @private
  31605. * @type {number}
  31606. */
  31607. this._idIndexMapCount = 0;
  31608. }
  31609. var index = idIndexMap.get(id);
  31610. if (index == null) {
  31611. idIndexMap.set(id, index = this._idIndexMapCount++);
  31612. }
  31613. return index;
  31614. },
  31615. getViewRoot: function () {
  31616. return this._viewRoot;
  31617. },
  31618. /**
  31619. * @param {module:echarts/data/Tree~Node} [viewRoot]
  31620. */
  31621. resetViewRoot: function (viewRoot) {
  31622. viewRoot
  31623. ? (this._viewRoot = viewRoot)
  31624. : (viewRoot = this._viewRoot);
  31625. var root = this.getData().tree.root;
  31626. if (!viewRoot
  31627. || (viewRoot !== root && !root.contains(viewRoot))
  31628. ) {
  31629. this._viewRoot = root;
  31630. }
  31631. }
  31632. });
  31633. /**
  31634. * @param {Object} dataNode
  31635. */
  31636. function completeTreeValue(dataNode) {
  31637. // Postorder travel tree.
  31638. // If value of none-leaf node is not set,
  31639. // calculate it by suming up the value of all children.
  31640. var sum = 0;
  31641. zrUtil.each(dataNode.children, function (child) {
  31642. completeTreeValue(child);
  31643. var childValue = child.value;
  31644. zrUtil.isArray(childValue) && (childValue = childValue[0]);
  31645. sum += childValue;
  31646. });
  31647. var thisValue = dataNode.value;
  31648. if (zrUtil.isArray(thisValue)) {
  31649. thisValue = thisValue[0];
  31650. }
  31651. if (thisValue == null || isNaN(thisValue)) {
  31652. thisValue = sum;
  31653. }
  31654. // Value should not less than 0.
  31655. if (thisValue < 0) {
  31656. thisValue = 0;
  31657. }
  31658. zrUtil.isArray(dataNode.value)
  31659. ? (dataNode.value[0] = thisValue)
  31660. : (dataNode.value = thisValue);
  31661. }
  31662. /**
  31663. * set default to level configuration
  31664. */
  31665. function setDefault(levels, ecModel) {
  31666. var globalColorList = ecModel.get('color');
  31667. if (!globalColorList) {
  31668. return;
  31669. }
  31670. levels = levels || [];
  31671. var hasColorDefine;
  31672. zrUtil.each(levels, function (levelDefine) {
  31673. var model = new Model(levelDefine);
  31674. var modelColor = model.get('color');
  31675. if (model.get('itemStyle.normal.color')
  31676. || (modelColor && modelColor !== 'none')
  31677. ) {
  31678. hasColorDefine = true;
  31679. }
  31680. });
  31681. if (!hasColorDefine) {
  31682. var level0 = levels[0] || (levels[0] = {});
  31683. level0.color = globalColorList.slice();
  31684. }
  31685. return levels;
  31686. }
  31687. /***/ },
  31688. /* 194 */
  31689. /***/ function(module, exports, __webpack_require__) {
  31690. /**
  31691. * Tree data structure
  31692. *
  31693. * @module echarts/data/Tree
  31694. */
  31695. var zrUtil = __webpack_require__(4);
  31696. var Model = __webpack_require__(12);
  31697. var List = __webpack_require__(98);
  31698. var linkList = __webpack_require__(195);
  31699. var completeDimensions = __webpack_require__(110);
  31700. /**
  31701. * @constructor module:echarts/data/Tree~TreeNode
  31702. * @param {string} name
  31703. * @param {module:echarts/data/Tree} hostTree
  31704. */
  31705. var TreeNode = function (name, hostTree) {
  31706. /**
  31707. * @type {string}
  31708. */
  31709. this.name = name || '';
  31710. /**
  31711. * Depth of node
  31712. *
  31713. * @type {number}
  31714. * @readOnly
  31715. */
  31716. this.depth = 0;
  31717. /**
  31718. * Height of the subtree rooted at this node.
  31719. * @type {number}
  31720. * @readOnly
  31721. */
  31722. this.height = 0;
  31723. /**
  31724. * @type {module:echarts/data/Tree~TreeNode}
  31725. * @readOnly
  31726. */
  31727. this.parentNode = null;
  31728. /**
  31729. * Reference to list item.
  31730. * Do not persistent dataIndex outside,
  31731. * besause it may be changed by list.
  31732. * If dataIndex -1,
  31733. * this node is logical deleted (filtered) in list.
  31734. *
  31735. * @type {Object}
  31736. * @readOnly
  31737. */
  31738. this.dataIndex = -1;
  31739. /**
  31740. * @type {Array.<module:echarts/data/Tree~TreeNode>}
  31741. * @readOnly
  31742. */
  31743. this.children = [];
  31744. /**
  31745. * @type {Array.<module:echarts/data/Tree~TreeNode>}
  31746. * @pubilc
  31747. */
  31748. this.viewChildren = [];
  31749. /**
  31750. * @type {moduel:echarts/data/Tree}
  31751. * @readOnly
  31752. */
  31753. this.hostTree = hostTree;
  31754. };
  31755. TreeNode.prototype = {
  31756. constructor: TreeNode,
  31757. /**
  31758. * The node is removed.
  31759. * @return {boolean} is removed.
  31760. */
  31761. isRemoved: function () {
  31762. return this.dataIndex < 0;
  31763. },
  31764. /**
  31765. * Travel this subtree (include this node).
  31766. * Usage:
  31767. * node.eachNode(function () { ... }); // preorder
  31768. * node.eachNode('preorder', function () { ... }); // preorder
  31769. * node.eachNode('postorder', function () { ... }); // postorder
  31770. * node.eachNode(
  31771. * {order: 'postorder', attr: 'viewChildren'},
  31772. * function () { ... }
  31773. * ); // postorder
  31774. *
  31775. * @param {(Object|string)} options If string, means order.
  31776. * @param {string=} options.order 'preorder' or 'postorder'
  31777. * @param {string=} options.attr 'children' or 'viewChildren'
  31778. * @param {Function} cb If in preorder and return false,
  31779. * its subtree will not be visited.
  31780. * @param {Object} [context]
  31781. */
  31782. eachNode: function (options, cb, context) {
  31783. if (typeof options === 'function') {
  31784. context = cb;
  31785. cb = options;
  31786. options = null;
  31787. }
  31788. options = options || {};
  31789. if (zrUtil.isString(options)) {
  31790. options = {order: options};
  31791. }
  31792. var order = options.order || 'preorder';
  31793. var children = this[options.attr || 'children'];
  31794. var suppressVisitSub;
  31795. order === 'preorder' && (suppressVisitSub = cb.call(context, this));
  31796. for (var i = 0; !suppressVisitSub && i < children.length; i++) {
  31797. children[i].eachNode(options, cb, context);
  31798. }
  31799. order === 'postorder' && cb.call(context, this);
  31800. },
  31801. /**
  31802. * Update depth and height of this subtree.
  31803. *
  31804. * @param {number} depth
  31805. */
  31806. updateDepthAndHeight: function (depth) {
  31807. var height = 0;
  31808. this.depth = depth;
  31809. for (var i = 0; i < this.children.length; i++) {
  31810. var child = this.children[i];
  31811. child.updateDepthAndHeight(depth + 1);
  31812. if (child.height > height) {
  31813. height = child.height;
  31814. }
  31815. }
  31816. this.height = height + 1;
  31817. },
  31818. /**
  31819. * @param {string} id
  31820. * @return {module:echarts/data/Tree~TreeNode}
  31821. */
  31822. getNodeById: function (id) {
  31823. if (this.getId() === id) {
  31824. return this;
  31825. }
  31826. for (var i = 0, children = this.children, len = children.length; i < len; i++) {
  31827. var res = children[i].getNodeById(id);
  31828. if (res) {
  31829. return res;
  31830. }
  31831. }
  31832. },
  31833. /**
  31834. * @param {module:echarts/data/Tree~TreeNode} node
  31835. * @return {boolean}
  31836. */
  31837. contains: function (node) {
  31838. if (node === this) {
  31839. return true;
  31840. }
  31841. for (var i = 0, children = this.children, len = children.length; i < len; i++) {
  31842. var res = children[i].contains(node);
  31843. if (res) {
  31844. return res;
  31845. }
  31846. }
  31847. },
  31848. /**
  31849. * @param {boolean} includeSelf Default false.
  31850. * @return {Array.<module:echarts/data/Tree~TreeNode>} order: [root, child, grandchild, ...]
  31851. */
  31852. getAncestors: function (includeSelf) {
  31853. var ancestors = [];
  31854. var node = includeSelf ? this : this.parentNode;
  31855. while (node) {
  31856. ancestors.push(node);
  31857. node = node.parentNode;
  31858. }
  31859. ancestors.reverse();
  31860. return ancestors;
  31861. },
  31862. /**
  31863. * @param {string|Array=} [dimension='value'] Default 'value'. can be 0, 1, 2, 3
  31864. * @return {number} Value.
  31865. */
  31866. getValue: function (dimension) {
  31867. var data = this.hostTree.data;
  31868. return data.get(data.getDimension(dimension || 'value'), this.dataIndex);
  31869. },
  31870. /**
  31871. * @param {Object} layout
  31872. * @param {boolean=} [merge=false]
  31873. */
  31874. setLayout: function (layout, merge) {
  31875. this.dataIndex >= 0
  31876. && this.hostTree.data.setItemLayout(this.dataIndex, layout, merge);
  31877. },
  31878. /**
  31879. * @return {Object} layout
  31880. */
  31881. getLayout: function () {
  31882. return this.hostTree.data.getItemLayout(this.dataIndex);
  31883. },
  31884. /**
  31885. * @param {string} path
  31886. * @return {module:echarts/model/Model}
  31887. */
  31888. getModel: function (path) {
  31889. if (this.dataIndex < 0) {
  31890. return;
  31891. }
  31892. var hostTree = this.hostTree;
  31893. var itemModel = hostTree.data.getItemModel(this.dataIndex);
  31894. var levelModel = this.getLevelModel();
  31895. return itemModel.getModel(path, (levelModel || hostTree.hostModel).getModel(path));
  31896. },
  31897. /**
  31898. * @return {module:echarts/model/Model}
  31899. */
  31900. getLevelModel: function () {
  31901. return (this.hostTree.levelModels || [])[this.depth];
  31902. },
  31903. /**
  31904. * @example
  31905. * setItemVisual('color', color);
  31906. * setItemVisual({
  31907. * 'color': color
  31908. * });
  31909. */
  31910. setVisual: function (key, value) {
  31911. this.dataIndex >= 0
  31912. && this.hostTree.data.setItemVisual(this.dataIndex, key, value);
  31913. },
  31914. /**
  31915. * Get item visual
  31916. */
  31917. getVisual: function (key, ignoreParent) {
  31918. return this.hostTree.data.getItemVisual(this.dataIndex, key, ignoreParent);
  31919. },
  31920. /**
  31921. * @public
  31922. * @return {number}
  31923. */
  31924. getRawIndex: function () {
  31925. return this.hostTree.data.getRawIndex(this.dataIndex);
  31926. },
  31927. /**
  31928. * @public
  31929. * @return {string}
  31930. */
  31931. getId: function () {
  31932. return this.hostTree.data.getId(this.dataIndex);
  31933. }
  31934. };
  31935. /**
  31936. * @constructor
  31937. * @alias module:echarts/data/Tree
  31938. * @param {module:echarts/model/Model} hostModel
  31939. * @param {Array.<Object>} levelOptions
  31940. */
  31941. function Tree(hostModel, levelOptions) {
  31942. /**
  31943. * @type {module:echarts/data/Tree~TreeNode}
  31944. * @readOnly
  31945. */
  31946. this.root;
  31947. /**
  31948. * @type {module:echarts/data/List}
  31949. * @readOnly
  31950. */
  31951. this.data;
  31952. /**
  31953. * Index of each item is the same as the raw index of coresponding list item.
  31954. * @private
  31955. * @type {Array.<module:echarts/data/Tree~TreeNode}
  31956. */
  31957. this._nodes = [];
  31958. /**
  31959. * @private
  31960. * @readOnly
  31961. * @type {module:echarts/model/Model}
  31962. */
  31963. this.hostModel = hostModel;
  31964. /**
  31965. * @private
  31966. * @readOnly
  31967. * @type {Array.<module:echarts/model/Model}
  31968. */
  31969. this.levelModels = zrUtil.map(levelOptions || [], function (levelDefine) {
  31970. return new Model(levelDefine, hostModel, hostModel.ecModel);
  31971. });
  31972. }
  31973. Tree.prototype = {
  31974. constructor: Tree,
  31975. type: 'tree',
  31976. /**
  31977. * Travel this subtree (include this node).
  31978. * Usage:
  31979. * node.eachNode(function () { ... }); // preorder
  31980. * node.eachNode('preorder', function () { ... }); // preorder
  31981. * node.eachNode('postorder', function () { ... }); // postorder
  31982. * node.eachNode(
  31983. * {order: 'postorder', attr: 'viewChildren'},
  31984. * function () { ... }
  31985. * ); // postorder
  31986. *
  31987. * @param {(Object|string)} options If string, means order.
  31988. * @param {string=} options.order 'preorder' or 'postorder'
  31989. * @param {string=} options.attr 'children' or 'viewChildren'
  31990. * @param {Function} cb
  31991. * @param {Object} [context]
  31992. */
  31993. eachNode: function(options, cb, context) {
  31994. this.root.eachNode(options, cb, context);
  31995. },
  31996. /**
  31997. * @param {number} dataIndex
  31998. * @return {module:echarts/data/Tree~TreeNode}
  31999. */
  32000. getNodeByDataIndex: function (dataIndex) {
  32001. var rawIndex = this.data.getRawIndex(dataIndex);
  32002. return this._nodes[rawIndex];
  32003. },
  32004. /**
  32005. * @param {string} name
  32006. * @return {module:echarts/data/Tree~TreeNode}
  32007. */
  32008. getNodeByName: function (name) {
  32009. return this.root.getNodeByName(name);
  32010. },
  32011. /**
  32012. * Update item available by list,
  32013. * when list has been performed options like 'filterSelf' or 'map'.
  32014. */
  32015. update: function () {
  32016. var data = this.data;
  32017. var nodes = this._nodes;
  32018. for (var i = 0, len = nodes.length; i < len; i++) {
  32019. nodes[i].dataIndex = -1;
  32020. }
  32021. for (var i = 0, len = data.count(); i < len; i++) {
  32022. nodes[data.getRawIndex(i)].dataIndex = i;
  32023. }
  32024. },
  32025. /**
  32026. * Clear all layouts
  32027. */
  32028. clearLayouts: function () {
  32029. this.data.clearItemLayouts();
  32030. }
  32031. };
  32032. /**
  32033. * data node format:
  32034. * {
  32035. * name: ...
  32036. * value: ...
  32037. * children: [
  32038. * {
  32039. * name: ...
  32040. * value: ...
  32041. * children: ...
  32042. * },
  32043. * ...
  32044. * ]
  32045. * }
  32046. *
  32047. * @static
  32048. * @param {Objec} dataRoot Root node.
  32049. * @param {module:echarts/model/Model} hostModel
  32050. * @param {Array.<Object>} levelOptions
  32051. * @return module:echarts/data/Tree
  32052. */
  32053. Tree.createTree = function (dataRoot, hostModel, levelOptions) {
  32054. var tree = new Tree(hostModel, levelOptions);
  32055. var listData = [];
  32056. var dimMax = 1;
  32057. buildHierarchy(dataRoot);
  32058. function buildHierarchy(dataNode, parentNode) {
  32059. var value = dataNode.value;
  32060. dimMax = Math.max(dimMax, zrUtil.isArray(value) ? value.length : 1);
  32061. listData.push(dataNode);
  32062. var node = new TreeNode(dataNode.name, tree);
  32063. parentNode
  32064. ? addChild(node, parentNode)
  32065. : (tree.root = node);
  32066. tree._nodes.push(node);
  32067. var children = dataNode.children;
  32068. if (children) {
  32069. for (var i = 0; i < children.length; i++) {
  32070. buildHierarchy(children[i], node);
  32071. }
  32072. }
  32073. }
  32074. tree.root.updateDepthAndHeight(0);
  32075. var dimensions = completeDimensions([{name: 'value'}], listData, {dimCount: dimMax});
  32076. var list = new List(dimensions, hostModel);
  32077. list.initData(listData);
  32078. linkList({
  32079. mainData: list,
  32080. struct: tree,
  32081. structAttr: 'tree'
  32082. });
  32083. tree.update();
  32084. return tree;
  32085. };
  32086. /**
  32087. * It is needed to consider the mess of 'list', 'hostModel' when creating a TreeNote,
  32088. * so this function is not ready and not necessary to be public.
  32089. *
  32090. * @param {(module:echarts/data/Tree~TreeNode|Object)} child
  32091. */
  32092. function addChild(child, node) {
  32093. var children = node.children;
  32094. if (child.parentNode === node) {
  32095. return;
  32096. }
  32097. children.push(child);
  32098. child.parentNode = node;
  32099. }
  32100. module.exports = Tree;
  32101. /***/ },
  32102. /* 195 */
  32103. /***/ function(module, exports, __webpack_require__) {
  32104. /**
  32105. * Link lists and struct (graph or tree)
  32106. */
  32107. var zrUtil = __webpack_require__(4);
  32108. var each = zrUtil.each;
  32109. var DATAS = '\0__link_datas';
  32110. var MAIN_DATA = '\0__link_mainData';
  32111. // Caution:
  32112. // In most case, either list or its shallow clones (see list.cloneShallow)
  32113. // is active in echarts process. So considering heap memory consumption,
  32114. // we do not clone tree or graph, but share them among list and its shallow clones.
  32115. // But in some rare case, we have to keep old list (like do animation in chart). So
  32116. // please take care that both the old list and the new list share the same tree/graph.
  32117. /**
  32118. * @param {Object} opt
  32119. * @param {module:echarts/data/List} opt.mainData
  32120. * @param {Object} [opt.struct] For example, instance of Graph or Tree.
  32121. * @param {string} [opt.structAttr] designation: list[structAttr] = struct;
  32122. * @param {Object} [opt.datas] {dataType: data},
  32123. * like: {node: nodeList, edge: edgeList}.
  32124. * Should contain mainData.
  32125. * @param {Object} [opt.datasAttr] {dataType: attr},
  32126. * designation: struct[datasAttr[dataType]] = list;
  32127. */
  32128. function linkList(opt) {
  32129. var mainData = opt.mainData;
  32130. var datas = opt.datas;
  32131. if (!datas) {
  32132. datas = {main: mainData};
  32133. opt.datasAttr = {main: 'data'};
  32134. }
  32135. opt.datas = opt.mainData = null;
  32136. linkAll(mainData, datas, opt);
  32137. // Porxy data original methods.
  32138. each(datas, function (data) {
  32139. each(mainData.TRANSFERABLE_METHODS, function (methodName) {
  32140. data.wrapMethod(methodName, zrUtil.curry(transferInjection, opt));
  32141. });
  32142. });
  32143. // Beyond transfer, additional features should be added to `cloneShallow`.
  32144. mainData.wrapMethod('cloneShallow', zrUtil.curry(cloneShallowInjection, opt));
  32145. // Only mainData trigger change, because struct.update may trigger
  32146. // another changable methods, which may bring about dead lock.
  32147. each(mainData.CHANGABLE_METHODS, function (methodName) {
  32148. mainData.wrapMethod(methodName, zrUtil.curry(changeInjection, opt));
  32149. });
  32150. // Make sure datas contains mainData.
  32151. zrUtil.assert(datas[mainData.dataType] === mainData);
  32152. }
  32153. function transferInjection(opt, res) {
  32154. if (isMainData(this)) {
  32155. // Transfer datas to new main data.
  32156. var datas = zrUtil.extend({}, this[DATAS]);
  32157. datas[this.dataType] = res;
  32158. linkAll(res, datas, opt);
  32159. }
  32160. else {
  32161. // Modify the reference in main data to point newData.
  32162. linkSingle(res, this.dataType, this[MAIN_DATA], opt);
  32163. }
  32164. return res;
  32165. }
  32166. function changeInjection(opt, res) {
  32167. opt.struct && opt.struct.update(this);
  32168. return res;
  32169. }
  32170. function cloneShallowInjection(opt, res) {
  32171. // cloneShallow, which brings about some fragilities, may be inappropriate
  32172. // to be exposed as an API. So for implementation simplicity we can make
  32173. // the restriction that cloneShallow of not-mainData should not be invoked
  32174. // outside, but only be invoked here.
  32175. each(res[DATAS], function (data, dataType) {
  32176. data !== res && linkSingle(data.cloneShallow(), dataType, res, opt);
  32177. });
  32178. return res;
  32179. }
  32180. /**
  32181. * Supplement method to List.
  32182. *
  32183. * @public
  32184. * @param {string} [dataType] If not specified, return mainData.
  32185. * @return {module:echarts/data/List}
  32186. */
  32187. function getLinkedData(dataType) {
  32188. var mainData = this[MAIN_DATA];
  32189. return (dataType == null || mainData == null)
  32190. ? mainData
  32191. : mainData[DATAS][dataType];
  32192. }
  32193. function isMainData(data) {
  32194. return data[MAIN_DATA] === data;
  32195. }
  32196. function linkAll(mainData, datas, opt) {
  32197. mainData[DATAS] = {};
  32198. each(datas, function (data, dataType) {
  32199. linkSingle(data, dataType, mainData, opt);
  32200. });
  32201. }
  32202. function linkSingle(data, dataType, mainData, opt) {
  32203. mainData[DATAS][dataType] = data;
  32204. data[MAIN_DATA] = mainData;
  32205. data.dataType = dataType;
  32206. if (opt.struct) {
  32207. data[opt.structAttr] = opt.struct;
  32208. opt.struct[opt.datasAttr[dataType]] = data;
  32209. }
  32210. // Supplement method.
  32211. data.getLinkedData = getLinkedData;
  32212. }
  32213. module.exports = linkList;
  32214. /***/ },
  32215. /* 196 */
  32216. /***/ function(module, exports, __webpack_require__) {
  32217. var zrUtil = __webpack_require__(4);
  32218. var helper = {
  32219. retrieveTargetInfo: function (payload, seriesModel) {
  32220. if (payload
  32221. && (
  32222. payload.type === 'treemapZoomToNode'
  32223. || payload.type === 'treemapRootToNode'
  32224. )
  32225. ) {
  32226. var root = seriesModel.getData().tree.root;
  32227. var targetNode = payload.targetNode;
  32228. if (targetNode && root.contains(targetNode)) {
  32229. return {node: targetNode};
  32230. }
  32231. var targetNodeId = payload.targetNodeId;
  32232. if (targetNodeId != null && (targetNode = root.getNodeById(targetNodeId))) {
  32233. return {node: targetNode};
  32234. }
  32235. }
  32236. },
  32237. // Not includes the given node at the last item.
  32238. getPathToRoot: function (node) {
  32239. var path = [];
  32240. while (node) {
  32241. node = node.parentNode;
  32242. node && path.push(node);
  32243. }
  32244. return path.reverse();
  32245. },
  32246. aboveViewRoot: function (viewRoot, node) {
  32247. var viewPath = helper.getPathToRoot(viewRoot);
  32248. return zrUtil.indexOf(viewPath, node) >= 0;
  32249. },
  32250. // From root to the input node (the input node will be included).
  32251. wrapTreePathInfo: function (node, seriesModel) {
  32252. var treePathInfo = [];
  32253. while (node) {
  32254. var nodeDataIndex = node.dataIndex;
  32255. treePathInfo.push({
  32256. name: node.name,
  32257. dataIndex: nodeDataIndex,
  32258. value: seriesModel.getRawValue(nodeDataIndex)
  32259. });
  32260. node = node.parentNode;
  32261. }
  32262. treePathInfo.reverse();
  32263. return treePathInfo;
  32264. }
  32265. };
  32266. module.exports = helper;
  32267. /***/ },
  32268. /* 197 */
  32269. /***/ function(module, exports, __webpack_require__) {
  32270. var zrUtil = __webpack_require__(4);
  32271. var graphic = __webpack_require__(18);
  32272. var DataDiffer = __webpack_require__(99);
  32273. var helper = __webpack_require__(196);
  32274. var Breadcrumb = __webpack_require__(198);
  32275. var RoamController = __webpack_require__(182);
  32276. var BoundingRect = __webpack_require__(9);
  32277. var matrix = __webpack_require__(11);
  32278. var animationUtil = __webpack_require__(199);
  32279. var bind = zrUtil.bind;
  32280. var Group = graphic.Group;
  32281. var Rect = graphic.Rect;
  32282. var each = zrUtil.each;
  32283. var DRAG_THRESHOLD = 3;
  32284. var PATH_LABEL_NORMAL = ['label', 'normal'];
  32285. var PATH_LABEL_EMPHASIS = ['label', 'emphasis'];
  32286. var Z_BASE = 10; // Should bigger than every z.
  32287. var Z_BG = 1;
  32288. var Z_CONTENT = 2;
  32289. module.exports = __webpack_require__(1).extendChartView({
  32290. type: 'treemap',
  32291. /**
  32292. * @override
  32293. */
  32294. init: function (o, api) {
  32295. /**
  32296. * @private
  32297. * @type {module:zrender/container/Group}
  32298. */
  32299. this._containerGroup;
  32300. /**
  32301. * @private
  32302. * @type {Object.<string, Array.<module:zrender/container/Group>>}
  32303. */
  32304. this._storage = createStorage();
  32305. /**
  32306. * @private
  32307. * @type {module:echarts/data/Tree}
  32308. */
  32309. this._oldTree;
  32310. /**
  32311. * @private
  32312. * @type {module:echarts/chart/treemap/Breadcrumb}
  32313. */
  32314. this._breadcrumb;
  32315. /**
  32316. * @private
  32317. * @type {module:echarts/component/helper/RoamController}
  32318. */
  32319. this._controller;
  32320. /**
  32321. * 'ready', 'animating'
  32322. * @private
  32323. */
  32324. this._state = 'ready';
  32325. /**
  32326. * @private
  32327. * @type {boolean}
  32328. */
  32329. this._mayClick;
  32330. },
  32331. /**
  32332. * @override
  32333. */
  32334. render: function (seriesModel, ecModel, api, payload) {
  32335. var models = ecModel.findComponents({
  32336. mainType: 'series', subType: 'treemap', query: payload
  32337. });
  32338. if (zrUtil.indexOf(models, seriesModel) < 0) {
  32339. return;
  32340. }
  32341. this.seriesModel = seriesModel;
  32342. this.api = api;
  32343. this.ecModel = ecModel;
  32344. var targetInfo = helper.retrieveTargetInfo(payload, seriesModel);
  32345. var payloadType = payload && payload.type;
  32346. var layoutInfo = seriesModel.layoutInfo;
  32347. var isInit = !this._oldTree;
  32348. var thisStorage = this._storage;
  32349. // Mark new root when action is treemapRootToNode.
  32350. var reRoot = (payloadType === 'treemapRootToNode' && targetInfo && thisStorage)
  32351. ? {
  32352. rootNodeGroup: thisStorage.nodeGroup[targetInfo.node.getRawIndex()],
  32353. direction: payload.direction
  32354. }
  32355. : null;
  32356. var containerGroup = this._giveContainerGroup(layoutInfo);
  32357. var renderResult = this._doRender(containerGroup, seriesModel, reRoot);
  32358. (
  32359. !isInit && (
  32360. !payloadType
  32361. || payloadType === 'treemapZoomToNode'
  32362. || payloadType === 'treemapRootToNode'
  32363. )
  32364. )
  32365. ? this._doAnimation(containerGroup, renderResult, seriesModel, reRoot)
  32366. : renderResult.renderFinally();
  32367. this._resetController(api);
  32368. this._renderBreadcrumb(seriesModel, api, targetInfo);
  32369. },
  32370. /**
  32371. * @private
  32372. */
  32373. _giveContainerGroup: function (layoutInfo) {
  32374. var containerGroup = this._containerGroup;
  32375. if (!containerGroup) {
  32376. // FIXME
  32377. // 加一层containerGroup是为了clip,但是现在clip功能并没有实现。
  32378. containerGroup = this._containerGroup = new Group();
  32379. this._initEvents(containerGroup);
  32380. this.group.add(containerGroup);
  32381. }
  32382. containerGroup.attr('position', [layoutInfo.x, layoutInfo.y]);
  32383. return containerGroup;
  32384. },
  32385. /**
  32386. * @private
  32387. */
  32388. _doRender: function (containerGroup, seriesModel, reRoot) {
  32389. var thisTree = seriesModel.getData().tree;
  32390. var oldTree = this._oldTree;
  32391. // Clear last shape records.
  32392. var lastsForAnimation = createStorage();
  32393. var thisStorage = createStorage();
  32394. var oldStorage = this._storage;
  32395. var willInvisibleEls = [];
  32396. var doRenderNode = zrUtil.curry(
  32397. renderNode, seriesModel,
  32398. thisStorage, oldStorage, reRoot,
  32399. lastsForAnimation, willInvisibleEls
  32400. );
  32401. // Notice: when thisTree and oldTree are the same tree (see list.cloneShadow),
  32402. // the oldTree is actually losted, so we can not find all of the old graphic
  32403. // elements from tree. So we use this stragegy: make element storage, move
  32404. // from old storage to new storage, clear old storage.
  32405. dualTravel(
  32406. thisTree.root ? [thisTree.root] : [],
  32407. (oldTree && oldTree.root) ? [oldTree.root] : [],
  32408. containerGroup,
  32409. thisTree === oldTree || !oldTree,
  32410. 0
  32411. );
  32412. // Process all removing.
  32413. var willDeleteEls = clearStorage(oldStorage);
  32414. this._oldTree = thisTree;
  32415. this._storage = thisStorage;
  32416. return {
  32417. lastsForAnimation: lastsForAnimation,
  32418. willDeleteEls: willDeleteEls,
  32419. renderFinally: renderFinally
  32420. };
  32421. function dualTravel(thisViewChildren, oldViewChildren, parentGroup, sameTree, depth) {
  32422. // When 'render' is triggered by action,
  32423. // 'this' and 'old' may be the same tree,
  32424. // we use rawIndex in that case.
  32425. if (sameTree) {
  32426. oldViewChildren = thisViewChildren;
  32427. each(thisViewChildren, function (child, index) {
  32428. !child.isRemoved() && processNode(index, index);
  32429. });
  32430. }
  32431. // Diff hierarchically (diff only in each subtree, but not whole).
  32432. // because, consistency of view is important.
  32433. else {
  32434. (new DataDiffer(oldViewChildren, thisViewChildren, getKey, getKey))
  32435. .add(processNode)
  32436. .update(processNode)
  32437. .remove(zrUtil.curry(processNode, null))
  32438. .execute();
  32439. }
  32440. function getKey(node) {
  32441. // Identify by name or raw index.
  32442. return node.getId();
  32443. }
  32444. function processNode(newIndex, oldIndex) {
  32445. var thisNode = newIndex != null ? thisViewChildren[newIndex] : null;
  32446. var oldNode = oldIndex != null ? oldViewChildren[oldIndex] : null;
  32447. var group = doRenderNode(thisNode, oldNode, parentGroup, depth);
  32448. group && dualTravel(
  32449. thisNode && thisNode.viewChildren || [],
  32450. oldNode && oldNode.viewChildren || [],
  32451. group,
  32452. sameTree,
  32453. depth + 1
  32454. );
  32455. }
  32456. }
  32457. function clearStorage(storage) {
  32458. var willDeleteEls = createStorage();
  32459. storage && each(storage, function (store, storageName) {
  32460. var delEls = willDeleteEls[storageName];
  32461. each(store, function (el) {
  32462. el && (delEls.push(el), el.__tmWillDelete = 1);
  32463. });
  32464. });
  32465. return willDeleteEls;
  32466. }
  32467. function renderFinally() {
  32468. each(willDeleteEls, function (els) {
  32469. each(els, function (el) {
  32470. el.parent && el.parent.remove(el);
  32471. });
  32472. });
  32473. each(willInvisibleEls, function (el) {
  32474. el.invisible = true;
  32475. // Setting invisible is for optimizing, so no need to set dirty,
  32476. // just mark as invisible.
  32477. el.dirty();
  32478. });
  32479. }
  32480. },
  32481. /**
  32482. * @private
  32483. */
  32484. _doAnimation: function (containerGroup, renderResult, seriesModel, reRoot) {
  32485. if (!seriesModel.get('animation')) {
  32486. return;
  32487. }
  32488. var duration = seriesModel.get('animationDurationUpdate');
  32489. var easing = seriesModel.get('animationEasing');
  32490. var animationWrap = animationUtil.createWrap();
  32491. // Make delete animations.
  32492. each(renderResult.willDeleteEls, function (store, storageName) {
  32493. each(store, function (el, rawIndex) {
  32494. if (el.invisible) {
  32495. return;
  32496. }
  32497. var parent = el.parent; // Always has parent, and parent is nodeGroup.
  32498. var target;
  32499. if (reRoot && reRoot.direction === 'drillDown') {
  32500. target = parent === reRoot.rootNodeGroup
  32501. // This is the content element of view root.
  32502. // Only `content` will enter this branch, because
  32503. // `background` and `nodeGroup` will not be deleted.
  32504. ? {
  32505. shape: {
  32506. x: 0,
  32507. y: 0,
  32508. width: parent.__tmNodeWidth,
  32509. height: parent.__tmNodeHeight
  32510. },
  32511. style: {
  32512. opacity: 0
  32513. }
  32514. }
  32515. // Others.
  32516. : {style: {opacity: 0}};
  32517. }
  32518. else {
  32519. var targetX = 0;
  32520. var targetY = 0;
  32521. if (!parent.__tmWillDelete) {
  32522. // Let node animate to right-bottom corner, cooperating with fadeout,
  32523. // which is appropriate for user understanding.
  32524. // Divided by 2 for reRoot rolling up effect.
  32525. targetX = parent.__tmNodeWidth / 2;
  32526. targetY = parent.__tmNodeHeight / 2;
  32527. }
  32528. target = storageName === 'nodeGroup'
  32529. ? {position: [targetX, targetY], style: {opacity: 0}}
  32530. : {
  32531. shape: {x: targetX, y: targetY, width: 0, height: 0},
  32532. style: {opacity: 0}
  32533. };
  32534. }
  32535. target && animationWrap.add(el, target, duration, easing);
  32536. });
  32537. });
  32538. // Make other animations
  32539. each(this._storage, function (store, storageName) {
  32540. each(store, function (el, rawIndex) {
  32541. var last = renderResult.lastsForAnimation[storageName][rawIndex];
  32542. var target = {};
  32543. if (!last) {
  32544. return;
  32545. }
  32546. if (storageName === 'nodeGroup') {
  32547. if (last.old) {
  32548. target.position = el.position.slice();
  32549. el.attr('position', last.old);
  32550. }
  32551. }
  32552. else {
  32553. if (last.old) {
  32554. target.shape = zrUtil.extend({}, el.shape);
  32555. el.setShape(last.old);
  32556. }
  32557. if (last.fadein) {
  32558. el.setStyle('opacity', 0);
  32559. target.style = {opacity: 1};
  32560. }
  32561. // When animation is stopped for succedent animation starting,
  32562. // el.style.opacity might not be 1
  32563. else if (el.style.opacity !== 1) {
  32564. target.style = {opacity: 1};
  32565. }
  32566. }
  32567. animationWrap.add(el, target, duration, easing);
  32568. });
  32569. }, this);
  32570. this._state = 'animating';
  32571. animationWrap
  32572. .done(bind(function () {
  32573. this._state = 'ready';
  32574. renderResult.renderFinally();
  32575. }, this))
  32576. .start();
  32577. },
  32578. /**
  32579. * @private
  32580. */
  32581. _resetController: function (api) {
  32582. var controller = this._controller;
  32583. // Init controller.
  32584. if (!controller) {
  32585. controller = this._controller = new RoamController(api.getZr());
  32586. controller.enable(this.seriesModel.get('roam'));
  32587. controller.on('pan', bind(this._onPan, this));
  32588. controller.on('zoom', bind(this._onZoom, this));
  32589. }
  32590. var rect = new BoundingRect(0, 0, api.getWidth(), api.getHeight());
  32591. controller.setPointerChecker(function (e, x, y) {
  32592. return rect.contain(x, y);
  32593. });
  32594. },
  32595. /**
  32596. * @private
  32597. */
  32598. _clearController: function () {
  32599. var controller = this._controller;
  32600. if (controller) {
  32601. controller.dispose();
  32602. controller = null;
  32603. }
  32604. },
  32605. /**
  32606. * @private
  32607. */
  32608. _onPan: function (dx, dy) {
  32609. this._mayClick = false;
  32610. if (this._state !== 'animating'
  32611. && (Math.abs(dx) > DRAG_THRESHOLD || Math.abs(dy) > DRAG_THRESHOLD)
  32612. ) {
  32613. // These param must not be cached.
  32614. var root = this.seriesModel.getData().tree.root;
  32615. if (!root) {
  32616. return;
  32617. }
  32618. var rootLayout = root.getLayout();
  32619. if (!rootLayout) {
  32620. return;
  32621. }
  32622. this.api.dispatchAction({
  32623. type: 'treemapMove',
  32624. from: this.uid,
  32625. seriesId: this.seriesModel.id,
  32626. rootRect: {
  32627. x: rootLayout.x + dx, y: rootLayout.y + dy,
  32628. width: rootLayout.width, height: rootLayout.height
  32629. }
  32630. });
  32631. }
  32632. },
  32633. /**
  32634. * @private
  32635. */
  32636. _onZoom: function (scale, mouseX, mouseY) {
  32637. this._mayClick = false;
  32638. if (this._state !== 'animating') {
  32639. // These param must not be cached.
  32640. var root = this.seriesModel.getData().tree.root;
  32641. if (!root) {
  32642. return;
  32643. }
  32644. var rootLayout = root.getLayout();
  32645. if (!rootLayout) {
  32646. return;
  32647. }
  32648. var rect = new BoundingRect(
  32649. rootLayout.x, rootLayout.y, rootLayout.width, rootLayout.height
  32650. );
  32651. var layoutInfo = this.seriesModel.layoutInfo;
  32652. // Transform mouse coord from global to containerGroup.
  32653. mouseX -= layoutInfo.x;
  32654. mouseY -= layoutInfo.y;
  32655. // Scale root bounding rect.
  32656. var m = matrix.create();
  32657. matrix.translate(m, m, [-mouseX, -mouseY]);
  32658. matrix.scale(m, m, [scale, scale]);
  32659. matrix.translate(m, m, [mouseX, mouseY]);
  32660. rect.applyTransform(m);
  32661. this.api.dispatchAction({
  32662. type: 'treemapRender',
  32663. from: this.uid,
  32664. seriesId: this.seriesModel.id,
  32665. rootRect: {
  32666. x: rect.x, y: rect.y,
  32667. width: rect.width, height: rect.height
  32668. }
  32669. });
  32670. }
  32671. },
  32672. /**
  32673. * @private
  32674. */
  32675. _initEvents: function (containerGroup) {
  32676. // FIXME
  32677. // 不用click以及silent的原因是,animate时视图设置silent true来避免click生效,
  32678. // 但是animate中,按下鼠标,animate结束后(silent设回为false)松开鼠标,
  32679. // 还是会触发click,期望是不触发。
  32680. // Mousedown occurs when drag start, and mouseup occurs when drag end,
  32681. // click event should not be triggered in that case.
  32682. containerGroup.on('mousedown', function (e) {
  32683. this._state === 'ready' && (this._mayClick = true);
  32684. }, this);
  32685. containerGroup.on('mouseup', function (e) {
  32686. if (this._mayClick) {
  32687. this._mayClick = false;
  32688. this._state === 'ready' && onClick.call(this, e);
  32689. }
  32690. }, this);
  32691. function onClick(e) {
  32692. var nodeClick = this.seriesModel.get('nodeClick', true);
  32693. if (!nodeClick) {
  32694. return;
  32695. }
  32696. var targetInfo = this.findTarget(e.offsetX, e.offsetY);
  32697. if (!targetInfo) {
  32698. return;
  32699. }
  32700. var node = targetInfo.node;
  32701. if (node.getLayout().isLeafRoot) {
  32702. this._rootToNode(targetInfo);
  32703. }
  32704. else {
  32705. if (nodeClick === 'zoomToNode') {
  32706. this._zoomToNode(targetInfo);
  32707. }
  32708. else if (nodeClick === 'link') {
  32709. var itemModel = node.hostTree.data.getItemModel(node.dataIndex);
  32710. var link = itemModel.get('link', true);
  32711. var linkTarget = itemModel.get('target', true) || 'blank';
  32712. link && window.open(link, linkTarget);
  32713. }
  32714. }
  32715. }
  32716. },
  32717. /**
  32718. * @private
  32719. */
  32720. _renderBreadcrumb: function (seriesModel, api, targetInfo) {
  32721. if (!targetInfo) {
  32722. targetInfo = seriesModel.get('leafDepth', true) != null
  32723. ? {node: seriesModel.getViewRoot()}
  32724. // FIXME
  32725. // better way?
  32726. // Find breadcrumb tail on center of containerGroup.
  32727. : this.findTarget(api.getWidth() / 2, api.getHeight() / 2);
  32728. if (!targetInfo) {
  32729. targetInfo = {node: seriesModel.getData().tree.root};
  32730. }
  32731. }
  32732. (this._breadcrumb || (this._breadcrumb = new Breadcrumb(this.group)))
  32733. .render(seriesModel, api, targetInfo.node, bind(onSelect, this));
  32734. function onSelect(node) {
  32735. if (this._state !== 'animating') {
  32736. helper.aboveViewRoot(seriesModel.getViewRoot(), node)
  32737. ? this._rootToNode({node: node})
  32738. : this._zoomToNode({node: node});
  32739. }
  32740. }
  32741. },
  32742. /**
  32743. * @override
  32744. */
  32745. remove: function () {
  32746. this._clearController();
  32747. this._containerGroup && this._containerGroup.removeAll();
  32748. this._storage = createStorage();
  32749. this._state = 'ready';
  32750. this._breadcrumb && this._breadcrumb.remove();
  32751. },
  32752. dispose: function () {
  32753. this._clearController();
  32754. },
  32755. /**
  32756. * @private
  32757. */
  32758. _zoomToNode: function (targetInfo) {
  32759. this.api.dispatchAction({
  32760. type: 'treemapZoomToNode',
  32761. from: this.uid,
  32762. seriesId: this.seriesModel.id,
  32763. targetNode: targetInfo.node
  32764. });
  32765. },
  32766. /**
  32767. * @private
  32768. */
  32769. _rootToNode: function (targetInfo) {
  32770. this.api.dispatchAction({
  32771. type: 'treemapRootToNode',
  32772. from: this.uid,
  32773. seriesId: this.seriesModel.id,
  32774. targetNode: targetInfo.node
  32775. });
  32776. },
  32777. /**
  32778. * @public
  32779. * @param {number} x Global coord x.
  32780. * @param {number} y Global coord y.
  32781. * @return {Object} info If not found, return undefined;
  32782. * @return {number} info.node Target node.
  32783. * @return {number} info.offsetX x refer to target node.
  32784. * @return {number} info.offsetY y refer to target node.
  32785. */
  32786. findTarget: function (x, y) {
  32787. var targetInfo;
  32788. var viewRoot = this.seriesModel.getViewRoot();
  32789. viewRoot.eachNode({attr: 'viewChildren', order: 'preorder'}, function (node) {
  32790. var bgEl = this._storage.background[node.getRawIndex()];
  32791. // If invisible, there might be no element.
  32792. if (bgEl) {
  32793. var point = bgEl.transformCoordToLocal(x, y);
  32794. var shape = bgEl.shape;
  32795. // For performance consideration, dont use 'getBoundingRect'.
  32796. if (shape.x <= point[0]
  32797. && point[0] <= shape.x + shape.width
  32798. && shape.y <= point[1]
  32799. && point[1] <= shape.y + shape.height
  32800. ) {
  32801. targetInfo = {node: node, offsetX: point[0], offsetY: point[1]};
  32802. }
  32803. else {
  32804. return false; // Suppress visit subtree.
  32805. }
  32806. }
  32807. }, this);
  32808. return targetInfo;
  32809. }
  32810. });
  32811. /**
  32812. * @inner
  32813. */
  32814. function createStorage() {
  32815. return {nodeGroup: [], background: [], content: []};
  32816. }
  32817. /**
  32818. * @inner
  32819. * @return Return undefined means do not travel further.
  32820. */
  32821. function renderNode(
  32822. seriesModel, thisStorage, oldStorage, reRoot,
  32823. lastsForAnimation, willInvisibleEls,
  32824. thisNode, oldNode, parentGroup, depth
  32825. ) {
  32826. // Whether under viewRoot.
  32827. if (!thisNode) {
  32828. // Deleting nodes will be performed finally. This method just find
  32829. // element from old storage, or create new element, set them to new
  32830. // storage, and set styles.
  32831. return;
  32832. }
  32833. var thisLayout = thisNode.getLayout();
  32834. if (!thisLayout || !thisLayout.isInView) {
  32835. return;
  32836. }
  32837. var thisWidth = thisLayout.width;
  32838. var thisHeight = thisLayout.height;
  32839. var thisInvisible = thisLayout.invisible;
  32840. var thisRawIndex = thisNode.getRawIndex();
  32841. var oldRawIndex = oldNode && oldNode.getRawIndex();
  32842. // Node group
  32843. var group = giveGraphic('nodeGroup', Group);
  32844. if (!group) {
  32845. return;
  32846. }
  32847. parentGroup.add(group);
  32848. // x,y are not set when el is above view root.
  32849. group.attr('position', [thisLayout.x || 0, thisLayout.y || 0]);
  32850. group.__tmNodeWidth = thisWidth;
  32851. group.__tmNodeHeight = thisHeight;
  32852. if (thisLayout.isAboveViewRoot) {
  32853. return group;
  32854. }
  32855. // Background
  32856. var bg = giveGraphic('background', Rect, depth, Z_BG);
  32857. if (bg) {
  32858. bg.setShape({x: 0, y: 0, width: thisWidth, height: thisHeight});
  32859. updateStyle(bg, function () {
  32860. bg.setStyle('fill', thisNode.getVisual('borderColor', true));
  32861. });
  32862. group.add(bg);
  32863. }
  32864. var thisViewChildren = thisNode.viewChildren;
  32865. // No children, render content.
  32866. if (!thisViewChildren || !thisViewChildren.length) {
  32867. var content = giveGraphic('content', Rect, depth, Z_CONTENT);
  32868. content && renderContent(group);
  32869. }
  32870. return group;
  32871. // ----------------------------
  32872. // | Procedures in renderNode |
  32873. // ----------------------------
  32874. function renderContent(group) {
  32875. // For tooltip.
  32876. content.dataIndex = thisNode.dataIndex;
  32877. content.seriesIndex = seriesModel.seriesIndex;
  32878. var borderWidth = thisLayout.borderWidth;
  32879. var contentWidth = Math.max(thisWidth - 2 * borderWidth, 0);
  32880. var contentHeight = Math.max(thisHeight - 2 * borderWidth, 0);
  32881. content.culling = true;
  32882. content.setShape({
  32883. x: borderWidth,
  32884. y: borderWidth,
  32885. width: contentWidth,
  32886. height: contentHeight
  32887. });
  32888. var visualColor = thisNode.getVisual('color', true);
  32889. updateStyle(content, function () {
  32890. var normalStyle = {fill: visualColor};
  32891. var emphasisStyle = thisNode.getModel('itemStyle.emphasis').getItemStyle();
  32892. prepareText(normalStyle, emphasisStyle, visualColor, contentWidth, contentHeight);
  32893. content.setStyle(normalStyle);
  32894. graphic.setHoverStyle(content, emphasisStyle);
  32895. });
  32896. group.add(content);
  32897. }
  32898. function updateStyle(element, cb) {
  32899. if (!thisInvisible) {
  32900. // If invisible, do not set visual, otherwise the element will
  32901. // change immediately before animation. We think it is OK to
  32902. // remain its origin color when moving out of the view window.
  32903. cb();
  32904. if (!element.__tmWillVisible) {
  32905. element.invisible = false;
  32906. }
  32907. }
  32908. else {
  32909. // Delay invisible setting utill animation finished,
  32910. // avoid element vanish suddenly before animation.
  32911. !element.invisible && willInvisibleEls.push(element);
  32912. }
  32913. }
  32914. function prepareText(normalStyle, emphasisStyle, visualColor, contentWidth, contentHeight) {
  32915. var nodeModel = thisNode.getModel();
  32916. var text = nodeModel.get('name');
  32917. if (thisLayout.isLeafRoot) {
  32918. var iconChar = seriesModel.get('drillDownIcon', true);
  32919. text = iconChar ? iconChar + ' ' + text : text;
  32920. }
  32921. setText(
  32922. text, normalStyle, nodeModel, PATH_LABEL_NORMAL,
  32923. visualColor, contentWidth, contentHeight
  32924. );
  32925. setText(
  32926. text, emphasisStyle, nodeModel, PATH_LABEL_EMPHASIS,
  32927. visualColor, contentWidth, contentHeight
  32928. );
  32929. }
  32930. function setText(text, style, nodeModel, labelPath, visualColor, contentWidth, contentHeight) {
  32931. var labelModel = nodeModel.getModel(labelPath);
  32932. var labelTextStyleModel = labelModel.getModel('textStyle');
  32933. graphic.setText(style, labelModel, visualColor);
  32934. // text.align and text.baseline is not included by graphic.setText,
  32935. // because in most cases the two attributes are not exposed to user,
  32936. // except in treemap.
  32937. style.textAlign = labelTextStyleModel.get('align');
  32938. style.textVerticalAlign = labelTextStyleModel.get('baseline');
  32939. var textRect = labelTextStyleModel.getTextRect(text);
  32940. if (!labelModel.getShallow('show') || textRect.height > contentHeight) {
  32941. style.text = '';
  32942. }
  32943. else if (textRect.width > contentWidth) {
  32944. style.text = labelTextStyleModel.get('ellipsis')
  32945. ? labelTextStyleModel.truncateText(
  32946. text, contentWidth, null, {minChar: 2}
  32947. )
  32948. : '';
  32949. }
  32950. else {
  32951. style.text = text;
  32952. }
  32953. }
  32954. function giveGraphic(storageName, Ctor, depth, z) {
  32955. var element = oldRawIndex != null && oldStorage[storageName][oldRawIndex];
  32956. var lasts = lastsForAnimation[storageName];
  32957. if (element) {
  32958. // Remove from oldStorage
  32959. oldStorage[storageName][oldRawIndex] = null;
  32960. prepareAnimationWhenHasOld(lasts, element, storageName);
  32961. }
  32962. // If invisible and no old element, do not create new element (for optimizing).
  32963. else if (!thisInvisible) {
  32964. element = new Ctor({z: calculateZ(depth, z)});
  32965. element.__tmDepth = depth;
  32966. element.__tmStorageName = storageName;
  32967. prepareAnimationWhenNoOld(lasts, element, storageName);
  32968. }
  32969. // Set to thisStorage
  32970. return (thisStorage[storageName][thisRawIndex] = element);
  32971. }
  32972. function prepareAnimationWhenHasOld(lasts, element, storageName) {
  32973. var lastCfg = lasts[thisRawIndex] = {};
  32974. lastCfg.old = storageName === 'nodeGroup'
  32975. ? element.position.slice()
  32976. : zrUtil.extend({}, element.shape);
  32977. }
  32978. // If a element is new, we need to find the animation start point carefully,
  32979. // otherwise it will looks strange when 'zoomToNode'.
  32980. function prepareAnimationWhenNoOld(lasts, element, storageName) {
  32981. var lastCfg = lasts[thisRawIndex] = {};
  32982. var parentNode = thisNode.parentNode;
  32983. if (parentNode && (!reRoot || reRoot.direction === 'drillDown')) {
  32984. var parentOldX = 0;
  32985. var parentOldY = 0;
  32986. // New nodes appear from right-bottom corner in 'zoomToNode' animation.
  32987. // For convenience, get old bounding rect from background.
  32988. var parentOldBg = lastsForAnimation.background[parentNode.getRawIndex()];
  32989. if (!reRoot && parentOldBg && parentOldBg.old) {
  32990. parentOldX = parentOldBg.old.width;
  32991. parentOldY = parentOldBg.old.height;
  32992. }
  32993. // When no parent old shape found, its parent is new too,
  32994. // so we can just use {x:0, y:0}.
  32995. lastCfg.old = storageName === 'nodeGroup'
  32996. ? [0, parentOldY]
  32997. : {x: parentOldX, y: parentOldY, width: 0, height: 0};
  32998. }
  32999. // Fade in, user can be aware that these nodes are new.
  33000. lastCfg.fadein = storageName !== 'nodeGroup';
  33001. }
  33002. }
  33003. // We can not set all backgroud with the same z, Because the behaviour of
  33004. // drill down and roll up differ background creation sequence from tree
  33005. // hierarchy sequence, which cause that lowser background element overlap
  33006. // upper ones. So we calculate z based on depth.
  33007. // Moreover, we try to shrink down z interval to [0, 1] to avoid that
  33008. // treemap with large z overlaps other components.
  33009. function calculateZ(depth, zInLevel) {
  33010. var zb = depth * Z_BASE + zInLevel;
  33011. return (zb - 1) / zb;
  33012. }
  33013. /***/ },
  33014. /* 198 */
  33015. /***/ function(module, exports, __webpack_require__) {
  33016. var graphic = __webpack_require__(18);
  33017. var layout = __webpack_require__(71);
  33018. var zrUtil = __webpack_require__(4);
  33019. var helper = __webpack_require__(196);
  33020. var TEXT_PADDING = 8;
  33021. var ITEM_GAP = 8;
  33022. var ARRAY_LENGTH = 5;
  33023. function Breadcrumb(containerGroup) {
  33024. /**
  33025. * @private
  33026. * @type {module:zrender/container/Group}
  33027. */
  33028. this.group = new graphic.Group();
  33029. containerGroup.add(this.group);
  33030. }
  33031. Breadcrumb.prototype = {
  33032. constructor: Breadcrumb,
  33033. render: function (seriesModel, api, targetNode, onSelect) {
  33034. var model = seriesModel.getModel('breadcrumb');
  33035. var thisGroup = this.group;
  33036. thisGroup.removeAll();
  33037. if (!model.get('show') || !targetNode) {
  33038. return;
  33039. }
  33040. var normalStyleModel = model.getModel('itemStyle.normal');
  33041. // var emphasisStyleModel = model.getModel('itemStyle.emphasis');
  33042. var textStyleModel = normalStyleModel.getModel('textStyle');
  33043. var layoutParam = {
  33044. pos: {
  33045. left: model.get('left'),
  33046. right: model.get('right'),
  33047. top: model.get('top'),
  33048. bottom: model.get('bottom')
  33049. },
  33050. box: {
  33051. width: api.getWidth(),
  33052. height: api.getHeight()
  33053. },
  33054. emptyItemWidth: model.get('emptyItemWidth'),
  33055. totalWidth: 0,
  33056. renderList: []
  33057. };
  33058. this._prepare(targetNode, layoutParam, textStyleModel);
  33059. this._renderContent(seriesModel, layoutParam, normalStyleModel, textStyleModel, onSelect);
  33060. layout.positionElement(thisGroup, layoutParam.pos, layoutParam.box);
  33061. },
  33062. /**
  33063. * Prepare render list and total width
  33064. * @private
  33065. */
  33066. _prepare: function (targetNode, layoutParam, textStyleModel) {
  33067. for (var node = targetNode; node; node = node.parentNode) {
  33068. var text = node.getModel().get('name');
  33069. var textRect = textStyleModel.getTextRect(text);
  33070. var itemWidth = Math.max(
  33071. textRect.width + TEXT_PADDING * 2,
  33072. layoutParam.emptyItemWidth
  33073. );
  33074. layoutParam.totalWidth += itemWidth + ITEM_GAP;
  33075. layoutParam.renderList.push({node: node, text: text, width: itemWidth});
  33076. }
  33077. },
  33078. /**
  33079. * @private
  33080. */
  33081. _renderContent: function (
  33082. seriesModel, layoutParam, normalStyleModel, textStyleModel, onSelect
  33083. ) {
  33084. // Start rendering.
  33085. var lastX = 0;
  33086. var emptyItemWidth = layoutParam.emptyItemWidth;
  33087. var height = seriesModel.get('breadcrumb.height');
  33088. var availableSize = layout.getAvailableSize(layoutParam.pos, layoutParam.box);
  33089. var totalWidth = layoutParam.totalWidth;
  33090. var renderList = layoutParam.renderList;
  33091. for (var i = renderList.length - 1; i >= 0; i--) {
  33092. var item = renderList[i];
  33093. var itemNode = item.node;
  33094. var itemWidth = item.width;
  33095. var text = item.text;
  33096. // Hdie text and shorten width if necessary.
  33097. if (totalWidth > availableSize.width) {
  33098. totalWidth -= itemWidth - emptyItemWidth;
  33099. itemWidth = emptyItemWidth;
  33100. text = '';
  33101. }
  33102. var el = new graphic.Polygon({
  33103. shape: {
  33104. points: makeItemPoints(
  33105. lastX, 0, itemWidth, height,
  33106. i === renderList.length - 1, i === 0
  33107. )
  33108. },
  33109. style: zrUtil.defaults(
  33110. normalStyleModel.getItemStyle(),
  33111. {
  33112. lineJoin: 'bevel',
  33113. text: text,
  33114. textFill: textStyleModel.getTextColor(),
  33115. textFont: textStyleModel.getFont()
  33116. }
  33117. ),
  33118. z: 10,
  33119. onclick: zrUtil.curry(onSelect, itemNode)
  33120. });
  33121. this.group.add(el);
  33122. packEventData(el, seriesModel, itemNode);
  33123. lastX += itemWidth + ITEM_GAP;
  33124. }
  33125. },
  33126. /**
  33127. * @override
  33128. */
  33129. remove: function () {
  33130. this.group.removeAll();
  33131. }
  33132. };
  33133. function makeItemPoints(x, y, itemWidth, itemHeight, head, tail) {
  33134. var points = [
  33135. [head ? x : x - ARRAY_LENGTH, y],
  33136. [x + itemWidth, y],
  33137. [x + itemWidth, y + itemHeight],
  33138. [head ? x : x - ARRAY_LENGTH, y + itemHeight]
  33139. ];
  33140. !tail && points.splice(2, 0, [x + itemWidth + ARRAY_LENGTH, y + itemHeight / 2]);
  33141. !head && points.push([x, y + itemHeight / 2]);
  33142. return points;
  33143. }
  33144. // Package custom mouse event.
  33145. function packEventData(el, seriesModel, itemNode) {
  33146. el.eventData = {
  33147. componentType: 'series',
  33148. componentSubType: 'treemap',
  33149. seriesIndex: seriesModel.componentIndex,
  33150. seriesName: seriesModel.name,
  33151. seriesType: 'treemap',
  33152. selfType: 'breadcrumb', // Distinguish with click event on treemap node.
  33153. nodeData: {
  33154. dataIndex: itemNode && itemNode.dataIndex,
  33155. name: itemNode && itemNode.name
  33156. },
  33157. treePathInfo: itemNode && helper.wrapTreePathInfo(itemNode, seriesModel)
  33158. };
  33159. }
  33160. module.exports = Breadcrumb;
  33161. /***/ },
  33162. /* 199 */
  33163. /***/ function(module, exports, __webpack_require__) {
  33164. var zrUtil = __webpack_require__(4);
  33165. /**
  33166. * @param {number} [time=500] Time in ms
  33167. * @param {string} [easing='linear']
  33168. * @param {number} [delay=0]
  33169. * @param {Function} [callback]
  33170. *
  33171. * @example
  33172. * // Animate position
  33173. * animation
  33174. * .createWrap()
  33175. * .add(el1, {position: [10, 10]})
  33176. * .add(el2, {shape: {width: 500}, style: {fill: 'red'}}, 400)
  33177. * .done(function () { // done })
  33178. * .start('cubicOut');
  33179. */
  33180. function createWrap() {
  33181. var storage = [];
  33182. var elExistsMap = {};
  33183. var doneCallback;
  33184. return {
  33185. /**
  33186. * Caution: a el can only be added once, otherwise 'done'
  33187. * might not be called. This method checks this (by el.id),
  33188. * suppresses adding and returns false when existing el found.
  33189. *
  33190. * @param {modele:zrender/Element} el
  33191. * @param {Object} target
  33192. * @param {number} [time=500]
  33193. * @param {number} [delay=0]
  33194. * @param {string} [easing='linear']
  33195. * @return {boolean} Whether adding succeeded.
  33196. *
  33197. * @example
  33198. * add(el, target, time, delay, easing);
  33199. * add(el, target, time, easing);
  33200. * add(el, target, time);
  33201. * add(el, target);
  33202. */
  33203. add: function (el, target, time, delay, easing) {
  33204. if (zrUtil.isString(delay)) {
  33205. easing = delay;
  33206. delay = 0;
  33207. }
  33208. if (elExistsMap[el.id]) {
  33209. return false;
  33210. }
  33211. elExistsMap[el.id] = 1;
  33212. storage.push(
  33213. {el: el, target: target, time: time, delay: delay, easing: easing}
  33214. );
  33215. return true;
  33216. },
  33217. /**
  33218. * Only execute when animation finished. Will not execute when any
  33219. * of 'stop' or 'stopAnimation' called.
  33220. *
  33221. * @param {Function} callback
  33222. */
  33223. done: function (callback) {
  33224. doneCallback = callback;
  33225. return this;
  33226. },
  33227. /**
  33228. * Will stop exist animation firstly.
  33229. */
  33230. start: function () {
  33231. var count = storage.length;
  33232. for (var i = 0, len = storage.length; i < len; i++) {
  33233. var item = storage[i];
  33234. item.el.animateTo(item.target, item.time, item.delay, item.easing, done);
  33235. }
  33236. return this;
  33237. function done() {
  33238. count--;
  33239. if (!count) {
  33240. storage.length = 0;
  33241. elExistsMap = {};
  33242. doneCallback && doneCallback();
  33243. }
  33244. }
  33245. }
  33246. };
  33247. }
  33248. module.exports = {createWrap: createWrap};
  33249. /***/ },
  33250. /* 200 */
  33251. /***/ function(module, exports, __webpack_require__) {
  33252. /**
  33253. * @file Treemap action
  33254. */
  33255. var echarts = __webpack_require__(1);
  33256. var helper = __webpack_require__(196);
  33257. var noop = function () {};
  33258. var actionTypes = [
  33259. 'treemapZoomToNode',
  33260. 'treemapRender',
  33261. 'treemapMove'
  33262. ];
  33263. for (var i = 0; i < actionTypes.length; i++) {
  33264. echarts.registerAction({type: actionTypes[i], update: 'updateView'}, noop);
  33265. }
  33266. echarts.registerAction(
  33267. {type: 'treemapRootToNode', update: 'updateView'},
  33268. function (payload, ecModel) {
  33269. ecModel.eachComponent(
  33270. {mainType: 'series', subType: 'treemap', query: payload},
  33271. handleRootToNode
  33272. );
  33273. function handleRootToNode(model, index) {
  33274. var targetInfo = helper.retrieveTargetInfo(payload, model);
  33275. if (targetInfo) {
  33276. var originViewRoot = model.getViewRoot();
  33277. if (originViewRoot) {
  33278. payload.direction = helper.aboveViewRoot(originViewRoot, targetInfo.node)
  33279. ? 'rollUp' : 'drillDown';
  33280. }
  33281. model.resetViewRoot(targetInfo.node);
  33282. }
  33283. }
  33284. }
  33285. );
  33286. /***/ },
  33287. /* 201 */
  33288. /***/ function(module, exports, __webpack_require__) {
  33289. var VisualMapping = __webpack_require__(202);
  33290. var zrColor = __webpack_require__(31);
  33291. var zrUtil = __webpack_require__(4);
  33292. var isArray = zrUtil.isArray;
  33293. var ITEM_STYLE_NORMAL = 'itemStyle.normal';
  33294. module.exports = function (ecModel, api, payload) {
  33295. var condition = {mainType: 'series', subType: 'treemap', query: payload};
  33296. ecModel.eachComponent(condition, function (seriesModel) {
  33297. var tree = seriesModel.getData().tree;
  33298. var root = tree.root;
  33299. var seriesItemStyleModel = seriesModel.getModel(ITEM_STYLE_NORMAL);
  33300. if (root.isRemoved()) {
  33301. return;
  33302. }
  33303. var levelItemStyles = zrUtil.map(tree.levelModels, function (levelModel) {
  33304. return levelModel ? levelModel.get(ITEM_STYLE_NORMAL) : null;
  33305. });
  33306. travelTree(
  33307. root, // Visual should calculate from tree root but not view root.
  33308. {},
  33309. levelItemStyles,
  33310. seriesItemStyleModel,
  33311. seriesModel.getViewRoot().getAncestors(),
  33312. seriesModel
  33313. );
  33314. });
  33315. };
  33316. function travelTree(
  33317. node, designatedVisual, levelItemStyles, seriesItemStyleModel,
  33318. viewRootAncestors, seriesModel
  33319. ) {
  33320. var nodeModel = node.getModel();
  33321. var nodeLayout = node.getLayout();
  33322. // Optimize
  33323. if (!nodeLayout || nodeLayout.invisible || !nodeLayout.isInView) {
  33324. return;
  33325. }
  33326. var nodeItemStyleModel = node.getModel(ITEM_STYLE_NORMAL);
  33327. var levelItemStyle = levelItemStyles[node.depth];
  33328. var visuals = buildVisuals(
  33329. nodeItemStyleModel, designatedVisual, levelItemStyle, seriesItemStyleModel
  33330. );
  33331. // calculate border color
  33332. var borderColor = nodeItemStyleModel.get('borderColor');
  33333. var borderColorSaturation = nodeItemStyleModel.get('borderColorSaturation');
  33334. var thisNodeColor;
  33335. if (borderColorSaturation != null) {
  33336. // For performance, do not always execute 'calculateColor'.
  33337. thisNodeColor = calculateColor(visuals, node);
  33338. borderColor = calculateBorderColor(borderColorSaturation, thisNodeColor);
  33339. }
  33340. node.setVisual('borderColor', borderColor);
  33341. var viewChildren = node.viewChildren;
  33342. if (!viewChildren || !viewChildren.length) {
  33343. thisNodeColor = calculateColor(visuals, node);
  33344. // Apply visual to this node.
  33345. node.setVisual('color', thisNodeColor);
  33346. }
  33347. else {
  33348. var mapping = buildVisualMapping(
  33349. node, nodeModel, nodeLayout, nodeItemStyleModel, visuals, viewChildren
  33350. );
  33351. // Designate visual to children.
  33352. zrUtil.each(viewChildren, function (child, index) {
  33353. // If higher than viewRoot, only ancestors of viewRoot is needed to visit.
  33354. if (child.depth >= viewRootAncestors.length
  33355. || child === viewRootAncestors[child.depth]
  33356. ) {
  33357. var childVisual = mapVisual(
  33358. nodeModel, visuals, child, index, mapping, seriesModel
  33359. );
  33360. travelTree(
  33361. child, childVisual, levelItemStyles, seriesItemStyleModel,
  33362. viewRootAncestors, seriesModel
  33363. );
  33364. }
  33365. });
  33366. }
  33367. }
  33368. function buildVisuals(
  33369. nodeItemStyleModel, designatedVisual, levelItemStyle, seriesItemStyleModel
  33370. ) {
  33371. var visuals = zrUtil.extend({}, designatedVisual);
  33372. zrUtil.each(['color', 'colorAlpha', 'colorSaturation'], function (visualName) {
  33373. // Priority: thisNode > thisLevel > parentNodeDesignated > seriesModel
  33374. var val = nodeItemStyleModel.get(visualName, true); // Ignore parent
  33375. val == null && levelItemStyle && (val = levelItemStyle[visualName]);
  33376. val == null && (val = designatedVisual[visualName]);
  33377. val == null && (val = seriesItemStyleModel.get(visualName));
  33378. val != null && (visuals[visualName] = val);
  33379. });
  33380. return visuals;
  33381. }
  33382. function calculateColor(visuals) {
  33383. var color = getValueVisualDefine(visuals, 'color');
  33384. if (color) {
  33385. var colorAlpha = getValueVisualDefine(visuals, 'colorAlpha');
  33386. var colorSaturation = getValueVisualDefine(visuals, 'colorSaturation');
  33387. if (colorSaturation) {
  33388. color = zrColor.modifyHSL(color, null, null, colorSaturation);
  33389. }
  33390. if (colorAlpha) {
  33391. color = zrColor.modifyAlpha(color, colorAlpha);
  33392. }
  33393. return color;
  33394. }
  33395. }
  33396. function calculateBorderColor(borderColorSaturation, thisNodeColor) {
  33397. return thisNodeColor != null
  33398. ? zrColor.modifyHSL(thisNodeColor, null, null, borderColorSaturation)
  33399. : null;
  33400. }
  33401. function getValueVisualDefine(visuals, name) {
  33402. var value = visuals[name];
  33403. if (value != null && value !== 'none') {
  33404. return value;
  33405. }
  33406. }
  33407. function buildVisualMapping(
  33408. node, nodeModel, nodeLayout, nodeItemStyleModel, visuals, viewChildren
  33409. ) {
  33410. if (!viewChildren || !viewChildren.length) {
  33411. return;
  33412. }
  33413. var rangeVisual = getRangeVisual(nodeModel, 'color')
  33414. || (
  33415. visuals.color != null
  33416. && visuals.color !== 'none'
  33417. && (
  33418. getRangeVisual(nodeModel, 'colorAlpha')
  33419. || getRangeVisual(nodeModel, 'colorSaturation')
  33420. )
  33421. );
  33422. if (!rangeVisual) {
  33423. return;
  33424. }
  33425. var visualMin = nodeModel.get('visualMin');
  33426. var visualMax = nodeModel.get('visualMax');
  33427. var dataExtent = nodeLayout.dataExtent.slice();
  33428. visualMin != null && visualMin < dataExtent[0] && (dataExtent[0] = visualMin);
  33429. visualMax != null && visualMax > dataExtent[1] && (dataExtent[1] = visualMax);
  33430. var colorMappingBy = nodeModel.get('colorMappingBy');
  33431. var opt = {
  33432. type: rangeVisual.name,
  33433. dataExtent: dataExtent,
  33434. visual: rangeVisual.range
  33435. };
  33436. if (opt.type === 'color'
  33437. && (colorMappingBy === 'index' || colorMappingBy === 'id')
  33438. ) {
  33439. opt.mappingMethod = 'category';
  33440. opt.loop = true;
  33441. // categories is ordinal, so do not set opt.categories.
  33442. }
  33443. else {
  33444. opt.mappingMethod = 'linear';
  33445. }
  33446. var mapping = new VisualMapping(opt);
  33447. mapping.__drColorMappingBy = colorMappingBy;
  33448. return mapping;
  33449. }
  33450. // Notice: If we dont have the attribute 'colorRange', but only use
  33451. // attribute 'color' to represent both concepts of 'colorRange' and 'color',
  33452. // (It means 'colorRange' when 'color' is Array, means 'color' when not array),
  33453. // this problem will be encountered:
  33454. // If a level-1 node dont have children, and its siblings has children,
  33455. // and colorRange is set on level-1, then the node can not be colored.
  33456. // So we separate 'colorRange' and 'color' to different attributes.
  33457. function getRangeVisual(nodeModel, name) {
  33458. // 'colorRange', 'colorARange', 'colorSRange'.
  33459. // If not exsits on this node, fetch from levels and series.
  33460. var range = nodeModel.get(name);
  33461. return (isArray(range) && range.length) ? {name: name, range: range} : null;
  33462. }
  33463. function mapVisual(nodeModel, visuals, child, index, mapping, seriesModel) {
  33464. var childVisuals = zrUtil.extend({}, visuals);
  33465. if (mapping) {
  33466. var mappingType = mapping.type;
  33467. var colorMappingBy = mappingType === 'color' && mapping.__drColorMappingBy;
  33468. var value =
  33469. colorMappingBy === 'index'
  33470. ? index
  33471. : colorMappingBy === 'id'
  33472. ? seriesModel.mapIdToIndex(child.getId())
  33473. : child.getValue(nodeModel.get('visualDimension'));
  33474. childVisuals[mappingType] = mapping.mapValueToVisual(value);
  33475. }
  33476. return childVisuals;
  33477. }
  33478. /***/ },
  33479. /* 202 */
  33480. /***/ function(module, exports, __webpack_require__) {
  33481. /**
  33482. * @file Visual mapping.
  33483. */
  33484. var zrUtil = __webpack_require__(4);
  33485. var zrColor = __webpack_require__(31);
  33486. var linearMap = __webpack_require__(7).linearMap;
  33487. var each = zrUtil.each;
  33488. var isObject = zrUtil.isObject;
  33489. var CATEGORY_DEFAULT_VISUAL_INDEX = -1;
  33490. /**
  33491. * @param {Object} option
  33492. * @param {string} [option.type] See visualHandlers.
  33493. * @param {string} [option.mappingMethod] 'linear' or 'piecewise' or 'category' or 'fixed'
  33494. * @param {Array.<number>=} [option.dataExtent] [minExtent, maxExtent],
  33495. * required when mappingMethod is 'linear'
  33496. * @param {Array.<Object>=} [option.pieceList] [
  33497. * {value: someValue},
  33498. * {interval: [min1, max1], visual: {...}},
  33499. * {interval: [min2, max2]}
  33500. * ],
  33501. * required when mappingMethod is 'piecewise'.
  33502. * Visual for only each piece can be specified.
  33503. * @param {Array.<string|Object>=} [option.categories] ['cate1', 'cate2']
  33504. * required when mappingMethod is 'category'.
  33505. * If no option.categories, categories is set
  33506. * as [0, 1, 2, ...].
  33507. * @param {boolean} [option.loop=false] Whether loop mapping when mappingMethod is 'category'.
  33508. * @param {(Array|Object|*)} [option.visual] Visual data.
  33509. * when mappingMethod is 'category',
  33510. * visual data can be array or object
  33511. * (like: {cate1: '#222', none: '#fff'})
  33512. * or primary types (which represents
  33513. * defualt category visual), otherwise visual
  33514. * can be array or primary (which will be
  33515. * normalized to array).
  33516. *
  33517. */
  33518. var VisualMapping = function (option) {
  33519. var mappingMethod = option.mappingMethod;
  33520. var visualType = option.type;
  33521. /**
  33522. * @readOnly
  33523. * @type {Object}
  33524. */
  33525. var thisOption = this.option = zrUtil.clone(option);
  33526. /**
  33527. * @readOnly
  33528. * @type {string}
  33529. */
  33530. this.type = visualType;
  33531. /**
  33532. * @readOnly
  33533. * @type {string}
  33534. */
  33535. this.mappingMethod = mappingMethod;
  33536. /**
  33537. * @private
  33538. * @type {Function}
  33539. */
  33540. this._normalizeData = normalizers[mappingMethod];
  33541. var visualHandler = visualHandlers[visualType];
  33542. /**
  33543. * @public
  33544. * @type {Function}
  33545. */
  33546. this.applyVisual = visualHandler.applyVisual;
  33547. /**
  33548. * @public
  33549. * @type {Function}
  33550. */
  33551. this.getColorMapper = visualHandler.getColorMapper;
  33552. /**
  33553. * @private
  33554. * @type {Function}
  33555. */
  33556. this._doMap = visualHandler._doMap[mappingMethod];
  33557. if (mappingMethod === 'piecewise') {
  33558. normalizeVisualRange(thisOption);
  33559. preprocessForPiecewise(thisOption);
  33560. }
  33561. else if (mappingMethod === 'category') {
  33562. thisOption.categories
  33563. ? preprocessForSpecifiedCategory(thisOption)
  33564. // categories is ordinal when thisOption.categories not specified,
  33565. // which need no more preprocess except normalize visual.
  33566. : normalizeVisualRange(thisOption, true);
  33567. }
  33568. else { // mappingMethod === 'linear' or 'fixed'
  33569. zrUtil.assert(mappingMethod !== 'linear' || thisOption.dataExtent);
  33570. normalizeVisualRange(thisOption);
  33571. }
  33572. };
  33573. VisualMapping.prototype = {
  33574. constructor: VisualMapping,
  33575. mapValueToVisual: function (value) {
  33576. var normalized = this._normalizeData(value);
  33577. return this._doMap(normalized, value);
  33578. },
  33579. getNormalizer: function () {
  33580. return zrUtil.bind(this._normalizeData, this);
  33581. }
  33582. };
  33583. var visualHandlers = VisualMapping.visualHandlers = {
  33584. color: {
  33585. applyVisual: makeApplyVisual('color'),
  33586. /**
  33587. * Create a mapper function
  33588. * @return {Function}
  33589. */
  33590. getColorMapper: function () {
  33591. var thisOption = this.option;
  33592. return zrUtil.bind(
  33593. thisOption.mappingMethod === 'category'
  33594. ? function (value, isNormalized) {
  33595. !isNormalized && (value = this._normalizeData(value));
  33596. return doMapCategory.call(this, value);
  33597. }
  33598. : function (value, isNormalized, out) {
  33599. // If output rgb array
  33600. // which will be much faster and useful in pixel manipulation
  33601. var returnRGBArray = !!out;
  33602. !isNormalized && (value = this._normalizeData(value));
  33603. out = zrColor.fastMapToColor(value, thisOption.parsedVisual, out);
  33604. return returnRGBArray ? out : zrColor.stringify(out, 'rgba');
  33605. },
  33606. this
  33607. );
  33608. },
  33609. _doMap: {
  33610. linear: function (normalized) {
  33611. return zrColor.stringify(
  33612. zrColor.fastMapToColor(normalized, this.option.parsedVisual),
  33613. 'rgba'
  33614. );
  33615. },
  33616. category: doMapCategory,
  33617. piecewise: function (normalized, value) {
  33618. var result = getSpecifiedVisual.call(this, value);
  33619. if (result == null) {
  33620. result = zrColor.stringify(
  33621. zrColor.fastMapToColor(normalized, this.option.parsedVisual),
  33622. 'rgba'
  33623. );
  33624. }
  33625. return result;
  33626. },
  33627. fixed: doMapFixed
  33628. }
  33629. },
  33630. colorHue: makePartialColorVisualHandler(function (color, value) {
  33631. return zrColor.modifyHSL(color, value);
  33632. }),
  33633. colorSaturation: makePartialColorVisualHandler(function (color, value) {
  33634. return zrColor.modifyHSL(color, null, value);
  33635. }),
  33636. colorLightness: makePartialColorVisualHandler(function (color, value) {
  33637. return zrColor.modifyHSL(color, null, null, value);
  33638. }),
  33639. colorAlpha: makePartialColorVisualHandler(function (color, value) {
  33640. return zrColor.modifyAlpha(color, value);
  33641. }),
  33642. opacity: {
  33643. applyVisual: makeApplyVisual('opacity'),
  33644. _doMap: makeDoMap([0, 1])
  33645. },
  33646. symbol: {
  33647. applyVisual: function (value, getter, setter) {
  33648. var symbolCfg = this.mapValueToVisual(value);
  33649. if (zrUtil.isString(symbolCfg)) {
  33650. setter('symbol', symbolCfg);
  33651. }
  33652. else if (isObject(symbolCfg)) {
  33653. for (var name in symbolCfg) {
  33654. if (symbolCfg.hasOwnProperty(name)) {
  33655. setter(name, symbolCfg[name]);
  33656. }
  33657. }
  33658. }
  33659. },
  33660. _doMap: {
  33661. linear: doMapToArray,
  33662. category: doMapCategory,
  33663. piecewise: function (normalized, value) {
  33664. var result = getSpecifiedVisual.call(this, value);
  33665. if (result == null) {
  33666. result = doMapToArray.call(this, normalized);
  33667. }
  33668. return result;
  33669. },
  33670. fixed: doMapFixed
  33671. }
  33672. },
  33673. symbolSize: {
  33674. applyVisual: makeApplyVisual('symbolSize'),
  33675. _doMap: makeDoMap([0, 1])
  33676. }
  33677. };
  33678. function preprocessForPiecewise(thisOption) {
  33679. var pieceList = thisOption.pieceList;
  33680. thisOption.hasSpecialVisual = false;
  33681. zrUtil.each(pieceList, function (piece, index) {
  33682. piece.originIndex = index;
  33683. // piece.visual is "result visual value" but not
  33684. // a visual range, so it does not need to be normalized.
  33685. if (piece.visual != null) {
  33686. thisOption.hasSpecialVisual = true;
  33687. }
  33688. });
  33689. }
  33690. function preprocessForSpecifiedCategory(thisOption) {
  33691. // Hash categories.
  33692. var categories = thisOption.categories;
  33693. var visual = thisOption.visual;
  33694. var categoryMap = thisOption.categoryMap = {};
  33695. each(categories, function (cate, index) {
  33696. categoryMap[cate] = index;
  33697. });
  33698. // Process visual map input.
  33699. if (!zrUtil.isArray(visual)) {
  33700. var visualArr = [];
  33701. if (zrUtil.isObject(visual)) {
  33702. each(visual, function (v, cate) {
  33703. var index = categoryMap[cate];
  33704. visualArr[index != null ? index : CATEGORY_DEFAULT_VISUAL_INDEX] = v;
  33705. });
  33706. }
  33707. else { // Is primary type, represents default visual.
  33708. visualArr[CATEGORY_DEFAULT_VISUAL_INDEX] = visual;
  33709. }
  33710. visual = setVisualToOption(thisOption, visualArr);
  33711. }
  33712. // Remove categories that has no visual,
  33713. // then we can mapping them to CATEGORY_DEFAULT_VISUAL_INDEX.
  33714. for (var i = categories.length - 1; i >= 0; i--) {
  33715. if (visual[i] == null) {
  33716. delete categoryMap[categories[i]];
  33717. categories.pop();
  33718. }
  33719. }
  33720. }
  33721. function normalizeVisualRange(thisOption, isCategory) {
  33722. var visual = thisOption.visual;
  33723. var visualArr = [];
  33724. if (zrUtil.isObject(visual)) {
  33725. each(visual, function (v) {
  33726. visualArr.push(v);
  33727. });
  33728. }
  33729. else if (visual != null) {
  33730. visualArr.push(visual);
  33731. }
  33732. var doNotNeedPair = {color: 1, symbol: 1};
  33733. if (!isCategory
  33734. && visualArr.length === 1
  33735. && !doNotNeedPair.hasOwnProperty(thisOption.type)
  33736. ) {
  33737. // Do not care visualArr.length === 0, which is illegal.
  33738. visualArr[1] = visualArr[0];
  33739. }
  33740. setVisualToOption(thisOption, visualArr);
  33741. }
  33742. function makePartialColorVisualHandler(applyValue) {
  33743. return {
  33744. applyVisual: function (value, getter, setter) {
  33745. value = this.mapValueToVisual(value);
  33746. // Must not be array value
  33747. setter('color', applyValue(getter('color'), value));
  33748. },
  33749. _doMap: makeDoMap([0, 1])
  33750. };
  33751. }
  33752. function doMapToArray(normalized) {
  33753. var visual = this.option.visual;
  33754. return visual[
  33755. Math.round(linearMap(normalized, [0, 1], [0, visual.length - 1], true))
  33756. ] || {};
  33757. }
  33758. function makeApplyVisual(visualType) {
  33759. return function (value, getter, setter) {
  33760. setter(visualType, this.mapValueToVisual(value));
  33761. };
  33762. }
  33763. function doMapCategory(normalized) {
  33764. var visual = this.option.visual;
  33765. return visual[
  33766. (this.option.loop && normalized !== CATEGORY_DEFAULT_VISUAL_INDEX)
  33767. ? normalized % visual.length
  33768. : normalized
  33769. ];
  33770. }
  33771. function doMapFixed() {
  33772. return this.option.visual[0];
  33773. }
  33774. function makeDoMap(sourceExtent) {
  33775. return {
  33776. linear: function (normalized) {
  33777. return linearMap(normalized, sourceExtent, this.option.visual, true);
  33778. },
  33779. category: doMapCategory,
  33780. piecewise: function (normalized, value) {
  33781. var result = getSpecifiedVisual.call(this, value);
  33782. if (result == null) {
  33783. result = linearMap(normalized, sourceExtent, this.option.visual, true);
  33784. }
  33785. return result;
  33786. },
  33787. fixed: doMapFixed
  33788. };
  33789. }
  33790. function getSpecifiedVisual(value) {
  33791. var thisOption = this.option;
  33792. var pieceList = thisOption.pieceList;
  33793. if (thisOption.hasSpecialVisual) {
  33794. var pieceIndex = VisualMapping.findPieceIndex(value, pieceList);
  33795. var piece = pieceList[pieceIndex];
  33796. if (piece && piece.visual) {
  33797. return piece.visual[this.type];
  33798. }
  33799. }
  33800. }
  33801. function setVisualToOption(thisOption, visualArr) {
  33802. thisOption.visual = visualArr;
  33803. if (thisOption.type === 'color') {
  33804. thisOption.parsedVisual = zrUtil.map(visualArr, function (item) {
  33805. return zrColor.parse(item);
  33806. });
  33807. }
  33808. return visualArr;
  33809. }
  33810. /**
  33811. * Normalizers by mapping methods.
  33812. */
  33813. var normalizers = {
  33814. linear: function (value) {
  33815. return linearMap(value, this.option.dataExtent, [0, 1], true);
  33816. },
  33817. piecewise: function (value) {
  33818. var pieceList = this.option.pieceList;
  33819. var pieceIndex = VisualMapping.findPieceIndex(value, pieceList, true);
  33820. if (pieceIndex != null) {
  33821. return linearMap(pieceIndex, [0, pieceList.length - 1], [0, 1], true);
  33822. }
  33823. },
  33824. category: function (value) {
  33825. var index = this.option.categories
  33826. ? this.option.categoryMap[value]
  33827. : value; // ordinal
  33828. return index == null ? CATEGORY_DEFAULT_VISUAL_INDEX : index;
  33829. },
  33830. fixed: zrUtil.noop
  33831. };
  33832. /**
  33833. * List available visual types.
  33834. *
  33835. * @public
  33836. * @return {Array.<string>}
  33837. */
  33838. VisualMapping.listVisualTypes = function () {
  33839. var visualTypes = [];
  33840. zrUtil.each(visualHandlers, function (handler, key) {
  33841. visualTypes.push(key);
  33842. });
  33843. return visualTypes;
  33844. };
  33845. /**
  33846. * @public
  33847. */
  33848. VisualMapping.addVisualHandler = function (name, handler) {
  33849. visualHandlers[name] = handler;
  33850. };
  33851. /**
  33852. * @public
  33853. */
  33854. VisualMapping.isValidType = function (visualType) {
  33855. return visualHandlers.hasOwnProperty(visualType);
  33856. };
  33857. /**
  33858. * Convinent method.
  33859. * Visual can be Object or Array or primary type.
  33860. *
  33861. * @public
  33862. */
  33863. VisualMapping.eachVisual = function (visual, callback, context) {
  33864. if (zrUtil.isObject(visual)) {
  33865. zrUtil.each(visual, callback, context);
  33866. }
  33867. else {
  33868. callback.call(context, visual);
  33869. }
  33870. };
  33871. VisualMapping.mapVisual = function (visual, callback, context) {
  33872. var isPrimary;
  33873. var newVisual = zrUtil.isArray(visual)
  33874. ? []
  33875. : zrUtil.isObject(visual)
  33876. ? {}
  33877. : (isPrimary = true, null);
  33878. VisualMapping.eachVisual(visual, function (v, key) {
  33879. var newVal = callback.call(context, v, key);
  33880. isPrimary ? (newVisual = newVal) : (newVisual[key] = newVal);
  33881. });
  33882. return newVisual;
  33883. };
  33884. /**
  33885. * @public
  33886. * @param {Object} obj
  33887. * @return {Oject} new object containers visual values.
  33888. * If no visuals, return null.
  33889. */
  33890. VisualMapping.retrieveVisuals = function (obj) {
  33891. var ret = {};
  33892. var hasVisual;
  33893. obj && each(visualHandlers, function (h, visualType) {
  33894. if (obj.hasOwnProperty(visualType)) {
  33895. ret[visualType] = obj[visualType];
  33896. hasVisual = true;
  33897. }
  33898. });
  33899. return hasVisual ? ret : null;
  33900. };
  33901. /**
  33902. * Give order to visual types, considering colorSaturation, colorAlpha depends on color.
  33903. *
  33904. * @public
  33905. * @param {(Object|Array)} visualTypes If Object, like: {color: ..., colorSaturation: ...}
  33906. * IF Array, like: ['color', 'symbol', 'colorSaturation']
  33907. * @return {Array.<string>} Sorted visual types.
  33908. */
  33909. VisualMapping.prepareVisualTypes = function (visualTypes) {
  33910. if (isObject(visualTypes)) {
  33911. var types = [];
  33912. each(visualTypes, function (item, type) {
  33913. types.push(type);
  33914. });
  33915. visualTypes = types;
  33916. }
  33917. else if (zrUtil.isArray(visualTypes)) {
  33918. visualTypes = visualTypes.slice();
  33919. }
  33920. else {
  33921. return [];
  33922. }
  33923. visualTypes.sort(function (type1, type2) {
  33924. // color should be front of colorSaturation, colorAlpha, ...
  33925. // symbol and symbolSize do not matter.
  33926. return (type2 === 'color' && type1 !== 'color' && type1.indexOf('color') === 0)
  33927. ? 1 : -1;
  33928. });
  33929. return visualTypes;
  33930. };
  33931. /**
  33932. * 'color', 'colorSaturation', 'colorAlpha', ... are depends on 'color'.
  33933. * Other visuals are only depends on themself.
  33934. *
  33935. * @public
  33936. * @param {string} visualType1
  33937. * @param {string} visualType2
  33938. * @return {boolean}
  33939. */
  33940. VisualMapping.dependsOn = function (visualType1, visualType2) {
  33941. return visualType2 === 'color'
  33942. ? !!(visualType1 && visualType1.indexOf(visualType2) === 0)
  33943. : visualType1 === visualType2;
  33944. };
  33945. /**
  33946. * @param {number} value
  33947. * @param {Array.<Object>} pieceList [{value: ..., interval: [min, max]}, ...]
  33948. * Always from small to big.
  33949. * @param {boolean} [findClosestWhenOutside=false]
  33950. * @return {number} index
  33951. */
  33952. VisualMapping.findPieceIndex = function (value, pieceList, findClosestWhenOutside) {
  33953. var possibleI;
  33954. var abs = Infinity;
  33955. // value has the higher priority.
  33956. for (var i = 0, len = pieceList.length; i < len; i++) {
  33957. var pieceValue = pieceList[i].value;
  33958. if (pieceValue != null) {
  33959. if (pieceValue === value
  33960. // FIXME
  33961. // It is supposed to compare value according to value type of dimension,
  33962. // but currently value type can exactly be string or number.
  33963. // Compromise for numeric-like string (like '12'), especially
  33964. // in the case that visualMap.categories is ['22', '33'].
  33965. || (typeof pieceValue === 'string' && pieceValue === value + '')
  33966. ) {
  33967. return i;
  33968. }
  33969. findClosestWhenOutside && updatePossible(pieceValue, i);
  33970. }
  33971. }
  33972. for (var i = 0, len = pieceList.length; i < len; i++) {
  33973. var piece = pieceList[i];
  33974. var interval = piece.interval;
  33975. var close = piece.close;
  33976. if (interval) {
  33977. if (interval[0] === -Infinity) {
  33978. if (littleThan(close[1], value, interval[1])) {
  33979. return i;
  33980. }
  33981. }
  33982. else if (interval[1] === Infinity) {
  33983. if (littleThan(close[0], interval[0], value)) {
  33984. return i;
  33985. }
  33986. }
  33987. else if (
  33988. littleThan(close[0], interval[0], value)
  33989. && littleThan(close[1], value, interval[1])
  33990. ) {
  33991. return i;
  33992. }
  33993. findClosestWhenOutside && updatePossible(interval[0], i);
  33994. findClosestWhenOutside && updatePossible(interval[1], i);
  33995. }
  33996. }
  33997. if (findClosestWhenOutside) {
  33998. return value === Infinity
  33999. ? pieceList.length - 1
  34000. : value === -Infinity
  34001. ? 0
  34002. : possibleI;
  34003. }
  34004. function updatePossible(val, index) {
  34005. var newAbs = Math.abs(val - value);
  34006. if (newAbs < abs) {
  34007. abs = newAbs;
  34008. possibleI = index;
  34009. }
  34010. }
  34011. };
  34012. function littleThan(close, a, b) {
  34013. return close ? a <= b : a < b;
  34014. }
  34015. module.exports = VisualMapping;
  34016. /***/ },
  34017. /* 203 */
  34018. /***/ function(module, exports, __webpack_require__) {
  34019. var zrUtil = __webpack_require__(4);
  34020. var numberUtil = __webpack_require__(7);
  34021. var layout = __webpack_require__(71);
  34022. var helper = __webpack_require__(196);
  34023. var BoundingRect = __webpack_require__(9);
  34024. var helper = __webpack_require__(196);
  34025. var mathMax = Math.max;
  34026. var mathMin = Math.min;
  34027. var parsePercent = numberUtil.parsePercent;
  34028. var retrieveValue = zrUtil.retrieve;
  34029. var each = zrUtil.each;
  34030. /**
  34031. * @public
  34032. */
  34033. function update(ecModel, api, payload) {
  34034. // Layout result in each node:
  34035. // {x, y, width, height, area, borderWidth}
  34036. var condition = {mainType: 'series', subType: 'treemap', query: payload};
  34037. ecModel.eachComponent(condition, function (seriesModel) {
  34038. var ecWidth = api.getWidth();
  34039. var ecHeight = api.getHeight();
  34040. var seriesOption = seriesModel.option;
  34041. var layoutInfo = layout.getLayoutRect(
  34042. seriesModel.getBoxLayoutParams(),
  34043. {
  34044. width: api.getWidth(),
  34045. height: api.getHeight()
  34046. }
  34047. );
  34048. var size = seriesOption.size || []; // Compatible with ec2.
  34049. var containerWidth = parsePercent(
  34050. retrieveValue(layoutInfo.width, size[0]),
  34051. ecWidth
  34052. );
  34053. var containerHeight = parsePercent(
  34054. retrieveValue(layoutInfo.height, size[1]),
  34055. ecHeight
  34056. );
  34057. // Fetch payload info.
  34058. var payloadType = payload && payload.type;
  34059. var targetInfo = helper.retrieveTargetInfo(payload, seriesModel);
  34060. var rootRect = (payloadType === 'treemapRender' || payloadType === 'treemapMove')
  34061. ? payload.rootRect : null;
  34062. var viewRoot = seriesModel.getViewRoot();
  34063. var viewAbovePath = helper.getPathToRoot(viewRoot);
  34064. if (payloadType !== 'treemapMove') {
  34065. var rootSize = payloadType === 'treemapZoomToNode'
  34066. ? estimateRootSize(
  34067. seriesModel, targetInfo, viewRoot, containerWidth, containerHeight
  34068. )
  34069. : rootRect
  34070. ? [rootRect.width, rootRect.height]
  34071. : [containerWidth, containerHeight];
  34072. var sort = seriesOption.sort;
  34073. if (sort && sort !== 'asc' && sort !== 'desc') {
  34074. sort = 'desc';
  34075. }
  34076. var options = {
  34077. squareRatio: seriesOption.squareRatio,
  34078. sort: sort,
  34079. leafDepth: seriesOption.leafDepth
  34080. };
  34081. // layout should be cleared because using updateView but not update.
  34082. viewRoot.hostTree.clearLayouts();
  34083. // TODO
  34084. // optimize: if out of view clip, do not layout.
  34085. // But take care that if do not render node out of view clip,
  34086. // how to calculate start po
  34087. var viewRootLayout = {
  34088. x: 0, y: 0,
  34089. width: rootSize[0], height: rootSize[1],
  34090. area: rootSize[0] * rootSize[1]
  34091. };
  34092. viewRoot.setLayout(viewRootLayout);
  34093. squarify(viewRoot, options, false, 0);
  34094. // Supplement layout.
  34095. var viewRootLayout = viewRoot.getLayout();
  34096. each(viewAbovePath, function (node, index) {
  34097. var childValue = (viewAbovePath[index + 1] || viewRoot).getValue();
  34098. node.setLayout(zrUtil.extend(
  34099. {dataExtent: [childValue, childValue], borderWidth: 0},
  34100. viewRootLayout
  34101. ));
  34102. });
  34103. }
  34104. var treeRoot = seriesModel.getData().tree.root;
  34105. treeRoot.setLayout(
  34106. calculateRootPosition(layoutInfo, rootRect, targetInfo),
  34107. true
  34108. );
  34109. seriesModel.setLayoutInfo(layoutInfo);
  34110. // FIXME
  34111. // 现在没有clip功能,暂时取ec高宽。
  34112. prunning(
  34113. treeRoot,
  34114. // Transform to base element coordinate system.
  34115. new BoundingRect(-layoutInfo.x, -layoutInfo.y, ecWidth, ecHeight),
  34116. viewAbovePath,
  34117. viewRoot,
  34118. 0
  34119. );
  34120. });
  34121. }
  34122. /**
  34123. * Layout treemap with squarify algorithm.
  34124. * @see https://graphics.ethz.ch/teaching/scivis_common/Literature/squarifiedTreeMaps.pdf
  34125. * @see https://github.com/mbostock/d3/blob/master/src/layout/treemap.js
  34126. *
  34127. * @protected
  34128. * @param {module:echarts/data/Tree~TreeNode} node
  34129. * @param {Object} options
  34130. * @param {string} options.sort 'asc' or 'desc'
  34131. * @param {number} options.squareRatio
  34132. * @param {boolean} hideChildren
  34133. * @param {number} depth
  34134. */
  34135. function squarify(node, options, hideChildren, depth) {
  34136. var width;
  34137. var height;
  34138. if (node.isRemoved()) {
  34139. return;
  34140. }
  34141. var thisLayout = node.getLayout();
  34142. width = thisLayout.width;
  34143. height = thisLayout.height;
  34144. // Considering border and gap
  34145. var itemStyleModel = node.getModel('itemStyle.normal');
  34146. var borderWidth = itemStyleModel.get('borderWidth');
  34147. var halfGapWidth = itemStyleModel.get('gapWidth') / 2;
  34148. var layoutOffset = borderWidth - halfGapWidth;
  34149. var nodeModel = node.getModel();
  34150. node.setLayout({borderWidth: borderWidth}, true);
  34151. width = mathMax(width - 2 * layoutOffset, 0);
  34152. height = mathMax(height - 2 * layoutOffset, 0);
  34153. var totalArea = width * height;
  34154. var viewChildren = initChildren(
  34155. node, nodeModel, totalArea, options, hideChildren, depth
  34156. );
  34157. if (!viewChildren.length) {
  34158. return;
  34159. }
  34160. var rect = {x: layoutOffset, y: layoutOffset, width: width, height: height};
  34161. var rowFixedLength = mathMin(width, height);
  34162. var best = Infinity; // the best row score so far
  34163. var row = [];
  34164. row.area = 0;
  34165. for (var i = 0, len = viewChildren.length; i < len;) {
  34166. var child = viewChildren[i];
  34167. row.push(child);
  34168. row.area += child.getLayout().area;
  34169. var score = worst(row, rowFixedLength, options.squareRatio);
  34170. // continue with this orientation
  34171. if (score <= best) {
  34172. i++;
  34173. best = score;
  34174. }
  34175. // abort, and try a different orientation
  34176. else {
  34177. row.area -= row.pop().getLayout().area;
  34178. position(row, rowFixedLength, rect, halfGapWidth, false);
  34179. rowFixedLength = mathMin(rect.width, rect.height);
  34180. row.length = row.area = 0;
  34181. best = Infinity;
  34182. }
  34183. }
  34184. if (row.length) {
  34185. position(row, rowFixedLength, rect, halfGapWidth, true);
  34186. }
  34187. if (!hideChildren) {
  34188. var childrenVisibleMin = nodeModel.get('childrenVisibleMin');
  34189. if (childrenVisibleMin != null && totalArea < childrenVisibleMin) {
  34190. hideChildren = true;
  34191. }
  34192. }
  34193. for (var i = 0, len = viewChildren.length; i < len; i++) {
  34194. squarify(viewChildren[i], options, hideChildren, depth + 1);
  34195. }
  34196. }
  34197. /**
  34198. * Set area to each child, and calculate data extent for visual coding.
  34199. */
  34200. function initChildren(node, nodeModel, totalArea, options, hideChildren, depth) {
  34201. var viewChildren = node.children || [];
  34202. var orderBy = options.sort;
  34203. orderBy !== 'asc' && orderBy !== 'desc' && (orderBy = null);
  34204. var overLeafDepth = options.leafDepth != null && options.leafDepth <= depth;
  34205. // leafDepth has higher priority.
  34206. if (hideChildren && !overLeafDepth) {
  34207. return (node.viewChildren = []);
  34208. }
  34209. // Sort children, order by desc.
  34210. viewChildren = zrUtil.filter(viewChildren, function (child) {
  34211. return !child.isRemoved();
  34212. });
  34213. sort(viewChildren, orderBy);
  34214. var info = statistic(nodeModel, viewChildren, orderBy);
  34215. if (info.sum === 0) {
  34216. return (node.viewChildren = []);
  34217. }
  34218. info.sum = filterByThreshold(nodeModel, totalArea, info.sum, orderBy, viewChildren);
  34219. if (info.sum === 0) {
  34220. return (node.viewChildren = []);
  34221. }
  34222. // Set area to each child.
  34223. for (var i = 0, len = viewChildren.length; i < len; i++) {
  34224. var area = viewChildren[i].getValue() / info.sum * totalArea;
  34225. // Do not use setLayout({...}, true), because it is needed to clear last layout.
  34226. viewChildren[i].setLayout({area: area});
  34227. }
  34228. if (overLeafDepth) {
  34229. viewChildren.length && node.setLayout({isLeafRoot: true}, true);
  34230. viewChildren.length = 0;
  34231. }
  34232. node.viewChildren = viewChildren;
  34233. node.setLayout({dataExtent: info.dataExtent}, true);
  34234. return viewChildren;
  34235. }
  34236. /**
  34237. * Consider 'visibleMin'. Modify viewChildren and get new sum.
  34238. */
  34239. function filterByThreshold(nodeModel, totalArea, sum, orderBy, orderedChildren) {
  34240. // visibleMin is not supported yet when no option.sort.
  34241. if (!orderBy) {
  34242. return sum;
  34243. }
  34244. var visibleMin = nodeModel.get('visibleMin');
  34245. var len = orderedChildren.length;
  34246. var deletePoint = len;
  34247. // Always travel from little value to big value.
  34248. for (var i = len - 1; i >= 0; i--) {
  34249. var value = orderedChildren[
  34250. orderBy === 'asc' ? len - i - 1 : i
  34251. ].getValue();
  34252. if (value / sum * totalArea < visibleMin) {
  34253. deletePoint = i;
  34254. sum -= value;
  34255. }
  34256. }
  34257. orderBy === 'asc'
  34258. ? orderedChildren.splice(0, len - deletePoint)
  34259. : orderedChildren.splice(deletePoint, len - deletePoint);
  34260. return sum;
  34261. }
  34262. /**
  34263. * Sort
  34264. */
  34265. function sort(viewChildren, orderBy) {
  34266. if (orderBy) {
  34267. viewChildren.sort(function (a, b) {
  34268. var diff = orderBy === 'asc'
  34269. ? a.getValue() - b.getValue() : b.getValue() - a.getValue();
  34270. return diff === 0
  34271. ? (orderBy === 'asc'
  34272. ? a.dataIndex - b.dataIndex : b.dataIndex - a.dataIndex
  34273. )
  34274. : diff;
  34275. });
  34276. }
  34277. return viewChildren;
  34278. }
  34279. /**
  34280. * Statistic
  34281. */
  34282. function statistic(nodeModel, children, orderBy) {
  34283. // Calculate sum.
  34284. var sum = 0;
  34285. for (var i = 0, len = children.length; i < len; i++) {
  34286. sum += children[i].getValue();
  34287. }
  34288. // Statistic data extent for latter visual coding.
  34289. // Notice: data extent should be calculate based on raw children
  34290. // but not filtered view children, otherwise visual mapping will not
  34291. // be stable when zoom (where children is filtered by visibleMin).
  34292. var dimension = nodeModel.get('visualDimension');
  34293. var dataExtent;
  34294. // The same as area dimension.
  34295. if (!children || !children.length) {
  34296. dataExtent = [NaN, NaN];
  34297. }
  34298. else if (dimension === 'value' && orderBy) {
  34299. dataExtent = [
  34300. children[children.length - 1].getValue(),
  34301. children[0].getValue()
  34302. ];
  34303. orderBy === 'asc' && dataExtent.reverse();
  34304. }
  34305. // Other dimension.
  34306. else {
  34307. var dataExtent = [Infinity, -Infinity];
  34308. each(children, function (child) {
  34309. var value = child.getValue(dimension);
  34310. value < dataExtent[0] && (dataExtent[0] = value);
  34311. value > dataExtent[1] && (dataExtent[1] = value);
  34312. });
  34313. }
  34314. return {sum: sum, dataExtent: dataExtent};
  34315. }
  34316. /**
  34317. * Computes the score for the specified row,
  34318. * as the worst aspect ratio.
  34319. */
  34320. function worst(row, rowFixedLength, ratio) {
  34321. var areaMax = 0;
  34322. var areaMin = Infinity;
  34323. for (var i = 0, area, len = row.length; i < len; i++) {
  34324. area = row[i].getLayout().area;
  34325. if (area) {
  34326. area < areaMin && (areaMin = area);
  34327. area > areaMax && (areaMax = area);
  34328. }
  34329. }
  34330. var squareArea = row.area * row.area;
  34331. var f = rowFixedLength * rowFixedLength * ratio;
  34332. return squareArea
  34333. ? mathMax(
  34334. (f * areaMax) / squareArea,
  34335. squareArea / (f * areaMin)
  34336. )
  34337. : Infinity;
  34338. }
  34339. /**
  34340. * Positions the specified row of nodes. Modifies `rect`.
  34341. */
  34342. function position(row, rowFixedLength, rect, halfGapWidth, flush) {
  34343. // When rowFixedLength === rect.width,
  34344. // it is horizontal subdivision,
  34345. // rowFixedLength is the width of the subdivision,
  34346. // rowOtherLength is the height of the subdivision,
  34347. // and nodes will be positioned from left to right.
  34348. // wh[idx0WhenH] means: when horizontal,
  34349. // wh[idx0WhenH] => wh[0] => 'width'.
  34350. // xy[idx1WhenH] => xy[1] => 'y'.
  34351. var idx0WhenH = rowFixedLength === rect.width ? 0 : 1;
  34352. var idx1WhenH = 1 - idx0WhenH;
  34353. var xy = ['x', 'y'];
  34354. var wh = ['width', 'height'];
  34355. var last = rect[xy[idx0WhenH]];
  34356. var rowOtherLength = rowFixedLength
  34357. ? row.area / rowFixedLength : 0;
  34358. if (flush || rowOtherLength > rect[wh[idx1WhenH]]) {
  34359. rowOtherLength = rect[wh[idx1WhenH]]; // over+underflow
  34360. }
  34361. for (var i = 0, rowLen = row.length; i < rowLen; i++) {
  34362. var node = row[i];
  34363. var nodeLayout = {};
  34364. var step = rowOtherLength
  34365. ? node.getLayout().area / rowOtherLength : 0;
  34366. var wh1 = nodeLayout[wh[idx1WhenH]] = mathMax(rowOtherLength - 2 * halfGapWidth, 0);
  34367. // We use Math.max/min to avoid negative width/height when considering gap width.
  34368. var remain = rect[xy[idx0WhenH]] + rect[wh[idx0WhenH]] - last;
  34369. var modWH = (i === rowLen - 1 || remain < step) ? remain : step;
  34370. var wh0 = nodeLayout[wh[idx0WhenH]] = mathMax(modWH - 2 * halfGapWidth, 0);
  34371. nodeLayout[xy[idx1WhenH]] = rect[xy[idx1WhenH]] + mathMin(halfGapWidth, wh1 / 2);
  34372. nodeLayout[xy[idx0WhenH]] = last + mathMin(halfGapWidth, wh0 / 2);
  34373. last += modWH;
  34374. node.setLayout(nodeLayout, true);
  34375. }
  34376. rect[xy[idx1WhenH]] += rowOtherLength;
  34377. rect[wh[idx1WhenH]] -= rowOtherLength;
  34378. }
  34379. // Return [containerWidth, containerHeight] as defualt.
  34380. function estimateRootSize(seriesModel, targetInfo, viewRoot, containerWidth, containerHeight) {
  34381. // If targetInfo.node exists, we zoom to the node,
  34382. // so estimate whold width and heigth by target node.
  34383. var currNode = (targetInfo || {}).node;
  34384. var defaultSize = [containerWidth, containerHeight];
  34385. if (!currNode || currNode === viewRoot) {
  34386. return defaultSize;
  34387. }
  34388. var parent;
  34389. var viewArea = containerWidth * containerHeight;
  34390. var area = viewArea * seriesModel.option.zoomToNodeRatio;
  34391. while (parent = currNode.parentNode) { // jshint ignore:line
  34392. var sum = 0;
  34393. var siblings = parent.children;
  34394. for (var i = 0, len = siblings.length; i < len; i++) {
  34395. sum += siblings[i].getValue();
  34396. }
  34397. var currNodeValue = currNode.getValue();
  34398. if (currNodeValue === 0) {
  34399. return defaultSize;
  34400. }
  34401. area *= sum / currNodeValue;
  34402. var borderWidth = parent.getModel('itemStyle.normal').get('borderWidth');
  34403. if (isFinite(borderWidth)) {
  34404. // Considering border, suppose aspect ratio is 1.
  34405. area += 4 * borderWidth * borderWidth + 4 * borderWidth * Math.pow(area, 0.5);
  34406. }
  34407. area > numberUtil.MAX_SAFE_INTEGER && (area = numberUtil.MAX_SAFE_INTEGER);
  34408. currNode = parent;
  34409. }
  34410. area < viewArea && (area = viewArea);
  34411. var scale = Math.pow(area / viewArea, 0.5);
  34412. return [containerWidth * scale, containerHeight * scale];
  34413. }
  34414. // Root postion base on coord of containerGroup
  34415. function calculateRootPosition(layoutInfo, rootRect, targetInfo) {
  34416. if (rootRect) {
  34417. return {x: rootRect.x, y: rootRect.y};
  34418. }
  34419. var defaultPosition = {x: 0, y: 0};
  34420. if (!targetInfo) {
  34421. return defaultPosition;
  34422. }
  34423. // If targetInfo is fetched by 'retrieveTargetInfo',
  34424. // old tree and new tree are the same tree,
  34425. // so the node still exists and we can visit it.
  34426. var targetNode = targetInfo.node;
  34427. var layout = targetNode.getLayout();
  34428. if (!layout) {
  34429. return defaultPosition;
  34430. }
  34431. // Transform coord from local to container.
  34432. var targetCenter = [layout.width / 2, layout.height / 2];
  34433. var node = targetNode;
  34434. while (node) {
  34435. var nodeLayout = node.getLayout();
  34436. targetCenter[0] += nodeLayout.x;
  34437. targetCenter[1] += nodeLayout.y;
  34438. node = node.parentNode;
  34439. }
  34440. return {
  34441. x: layoutInfo.width / 2 - targetCenter[0],
  34442. y: layoutInfo.height / 2 - targetCenter[1]
  34443. };
  34444. }
  34445. // Mark nodes visible for prunning when visual coding and rendering.
  34446. // Prunning depends on layout and root position, so we have to do it after layout.
  34447. function prunning(node, clipRect, viewAbovePath, viewRoot, depth) {
  34448. var nodeLayout = node.getLayout();
  34449. var nodeInViewAbovePath = viewAbovePath[depth];
  34450. var isAboveViewRoot = nodeInViewAbovePath && nodeInViewAbovePath === node;
  34451. if (
  34452. (nodeInViewAbovePath && !isAboveViewRoot)
  34453. || (depth === viewAbovePath.length && node !== viewRoot)
  34454. ) {
  34455. return;
  34456. }
  34457. node.setLayout({
  34458. // isInView means: viewRoot sub tree + viewAbovePath
  34459. isInView: true,
  34460. // invisible only means: outside view clip so that the node can not
  34461. // see but still layout for animation preparation but not render.
  34462. invisible: !isAboveViewRoot && !clipRect.intersect(nodeLayout),
  34463. isAboveViewRoot: isAboveViewRoot
  34464. }, true);
  34465. // Transform to child coordinate.
  34466. var childClipRect = new BoundingRect(
  34467. clipRect.x - nodeLayout.x,
  34468. clipRect.y - nodeLayout.y,
  34469. clipRect.width,
  34470. clipRect.height
  34471. );
  34472. each(node.viewChildren || [], function (child) {
  34473. prunning(child, childClipRect, viewAbovePath, viewRoot, depth + 1);
  34474. });
  34475. }
  34476. module.exports = update;
  34477. /***/ },
  34478. /* 204 */
  34479. /***/ function(module, exports, __webpack_require__) {
  34480. var echarts = __webpack_require__(1);
  34481. var zrUtil = __webpack_require__(4);
  34482. __webpack_require__(205);
  34483. __webpack_require__(208);
  34484. __webpack_require__(213);
  34485. echarts.registerProcessor(__webpack_require__(214));
  34486. echarts.registerVisual(zrUtil.curry(
  34487. __webpack_require__(121), 'graph', 'circle', null
  34488. ));
  34489. echarts.registerVisual(__webpack_require__(215));
  34490. echarts.registerVisual(__webpack_require__(216));
  34491. echarts.registerLayout(__webpack_require__(217));
  34492. echarts.registerLayout(__webpack_require__(220));
  34493. echarts.registerLayout(__webpack_require__(222));
  34494. // Graph view coordinate system
  34495. echarts.registerCoordinateSystem('graphView', {
  34496. create: __webpack_require__(224)
  34497. });
  34498. /***/ },
  34499. /* 205 */
  34500. /***/ function(module, exports, __webpack_require__) {
  34501. 'use strict';
  34502. var List = __webpack_require__(98);
  34503. var zrUtil = __webpack_require__(4);
  34504. var modelUtil = __webpack_require__(5);
  34505. var Model = __webpack_require__(12);
  34506. var formatUtil = __webpack_require__(6);
  34507. var createGraphFromNodeEdge = __webpack_require__(206);
  34508. var GraphSeries = __webpack_require__(1).extendSeriesModel({
  34509. type: 'series.graph',
  34510. init: function (option) {
  34511. GraphSeries.superApply(this, 'init', arguments);
  34512. // Provide data for legend select
  34513. this.legendDataProvider = function () {
  34514. return this._categoriesData;
  34515. };
  34516. this.fillDataTextStyle(option.edges || option.links);
  34517. this._updateCategoriesData();
  34518. },
  34519. mergeOption: function (option) {
  34520. GraphSeries.superApply(this, 'mergeOption', arguments);
  34521. this.fillDataTextStyle(option.edges || option.links);
  34522. this._updateCategoriesData();
  34523. },
  34524. mergeDefaultAndTheme: function (option) {
  34525. GraphSeries.superApply(this, 'mergeDefaultAndTheme', arguments);
  34526. modelUtil.defaultEmphasis(option.edgeLabel, modelUtil.LABEL_OPTIONS);
  34527. },
  34528. getInitialData: function (option, ecModel) {
  34529. var edges = option.edges || option.links || [];
  34530. var nodes = option.data || option.nodes || [];
  34531. var self = this;
  34532. if (nodes && edges) {
  34533. return createGraphFromNodeEdge(nodes, edges, this, true, beforeLink).data;
  34534. }
  34535. function beforeLink(nodeData, edgeData) {
  34536. // Overwrite nodeData.getItemModel to
  34537. nodeData.wrapMethod('getItemModel', function (model) {
  34538. var categoriesModels = self._categoriesModels;
  34539. var categoryIdx = model.getShallow('category');
  34540. var categoryModel = categoriesModels[categoryIdx];
  34541. if (categoryModel) {
  34542. categoryModel.parentModel = model.parentModel;
  34543. model.parentModel = categoryModel;
  34544. }
  34545. return model;
  34546. });
  34547. var edgeLabelModel = self.getModel('edgeLabel');
  34548. // For option `edgeLabel` can be found by label.xxx.xxx on item mode.
  34549. var fakeSeriesModel = new Model(
  34550. {label: edgeLabelModel.option},
  34551. edgeLabelModel.parentModel,
  34552. ecModel
  34553. );
  34554. edgeData.wrapMethod('getItemModel', function (model) {
  34555. model.customizeGetParent(edgeGetParent);
  34556. return model;
  34557. });
  34558. function edgeGetParent(path) {
  34559. path = this.parsePath(path);
  34560. return (path && path[0] === 'label')
  34561. ? fakeSeriesModel
  34562. : this.parentModel;
  34563. }
  34564. }
  34565. },
  34566. /**
  34567. * @return {module:echarts/data/Graph}
  34568. */
  34569. getGraph: function () {
  34570. return this.getData().graph;
  34571. },
  34572. /**
  34573. * @return {module:echarts/data/List}
  34574. */
  34575. getEdgeData: function () {
  34576. return this.getGraph().edgeData;
  34577. },
  34578. /**
  34579. * @return {module:echarts/data/List}
  34580. */
  34581. getCategoriesData: function () {
  34582. return this._categoriesData;
  34583. },
  34584. /**
  34585. * @override
  34586. */
  34587. formatTooltip: function (dataIndex, multipleSeries, dataType) {
  34588. if (dataType === 'edge') {
  34589. var nodeData = this.getData();
  34590. var params = this.getDataParams(dataIndex, dataType);
  34591. var edge = nodeData.graph.getEdgeByIndex(dataIndex);
  34592. var sourceName = nodeData.getName(edge.node1.dataIndex);
  34593. var targetName = nodeData.getName(edge.node2.dataIndex);
  34594. var html = [];
  34595. sourceName != null && html.push(sourceName);
  34596. targetName != null && html.push(targetName);
  34597. html = formatUtil.encodeHTML(html.join(' > '));
  34598. if (params.value) {
  34599. html += ' : ' + formatUtil.encodeHTML(params.value);
  34600. }
  34601. return html;
  34602. }
  34603. else { // dataType === 'node' or empty
  34604. return GraphSeries.superApply(this, 'formatTooltip', arguments);
  34605. }
  34606. },
  34607. _updateCategoriesData: function () {
  34608. var categories = zrUtil.map(this.option.categories || [], function (category) {
  34609. // Data must has value
  34610. return category.value != null ? category : zrUtil.extend({
  34611. value: 0
  34612. }, category);
  34613. });
  34614. var categoriesData = new List(['value'], this);
  34615. categoriesData.initData(categories);
  34616. this._categoriesData = categoriesData;
  34617. this._categoriesModels = categoriesData.mapArray(function (idx) {
  34618. return categoriesData.getItemModel(idx, true);
  34619. });
  34620. },
  34621. setZoom: function (zoom) {
  34622. this.option.zoom = zoom;
  34623. },
  34624. setCenter: function (center) {
  34625. this.option.center = center;
  34626. },
  34627. isAnimationEnabled: function () {
  34628. return GraphSeries.superCall(this, 'isAnimationEnabled')
  34629. // Not enable animation when do force layout
  34630. && !(this.get('layout') === 'force' && this.get('force.layoutAnimation'));
  34631. },
  34632. defaultOption: {
  34633. zlevel: 0,
  34634. z: 2,
  34635. coordinateSystem: 'view',
  34636. // Default option for all coordinate systems
  34637. // xAxisIndex: 0,
  34638. // yAxisIndex: 0,
  34639. // polarIndex: 0,
  34640. // geoIndex: 0,
  34641. legendHoverLink: true,
  34642. hoverAnimation: true,
  34643. layout: null,
  34644. focusNodeAdjacency: false,
  34645. // Configuration of circular layout
  34646. circular: {
  34647. rotateLabel: false
  34648. },
  34649. // Configuration of force directed layout
  34650. force: {
  34651. initLayout: null,
  34652. // Node repulsion. Can be an array to represent range.
  34653. repulsion: [0, 50],
  34654. gravity: 0.1,
  34655. // Edge length. Can be an array to represent range.
  34656. edgeLength: 30,
  34657. layoutAnimation: true
  34658. },
  34659. left: 'center',
  34660. top: 'center',
  34661. // right: null,
  34662. // bottom: null,
  34663. // width: '80%',
  34664. // height: '80%',
  34665. symbol: 'circle',
  34666. symbolSize: 10,
  34667. edgeSymbol: ['none', 'none'],
  34668. edgeSymbolSize: 10,
  34669. edgeLabel: {
  34670. normal: {
  34671. position: 'middle'
  34672. },
  34673. emphasis: {}
  34674. },
  34675. draggable: false,
  34676. roam: false,
  34677. // Default on center of graph
  34678. center: null,
  34679. zoom: 1,
  34680. // Symbol size scale ratio in roam
  34681. nodeScaleRatio: 0.6,
  34682. // categories: [],
  34683. // data: []
  34684. // Or
  34685. // nodes: []
  34686. //
  34687. // links: []
  34688. // Or
  34689. // edges: []
  34690. label: {
  34691. normal: {
  34692. show: false,
  34693. formatter: '{b}'
  34694. },
  34695. emphasis: {
  34696. show: true
  34697. }
  34698. },
  34699. itemStyle: {
  34700. normal: {},
  34701. emphasis: {}
  34702. },
  34703. lineStyle: {
  34704. normal: {
  34705. color: '#aaa',
  34706. width: 1,
  34707. curveness: 0,
  34708. opacity: 0.5
  34709. },
  34710. emphasis: {}
  34711. }
  34712. }
  34713. });
  34714. module.exports = GraphSeries;
  34715. /***/ },
  34716. /* 206 */
  34717. /***/ function(module, exports, __webpack_require__) {
  34718. var List = __webpack_require__(98);
  34719. var Graph = __webpack_require__(207);
  34720. var linkList = __webpack_require__(195);
  34721. var completeDimensions = __webpack_require__(110);
  34722. var CoordinateSystem = __webpack_require__(76);
  34723. var zrUtil = __webpack_require__(4);
  34724. var createListFromArray = __webpack_require__(109);
  34725. module.exports = function (nodes, edges, hostModel, directed, beforeLink) {
  34726. var graph = new Graph(directed);
  34727. for (var i = 0; i < nodes.length; i++) {
  34728. graph.addNode(zrUtil.retrieve(
  34729. // Id, name, dataIndex
  34730. nodes[i].id, nodes[i].name, i
  34731. ), i);
  34732. }
  34733. var linkNameList = [];
  34734. var validEdges = [];
  34735. var linkCount = 0;
  34736. for (var i = 0; i < edges.length; i++) {
  34737. var link = edges[i];
  34738. var source = link.source;
  34739. var target = link.target;
  34740. // addEdge may fail when source or target not exists
  34741. if (graph.addEdge(source, target, linkCount)) {
  34742. validEdges.push(link);
  34743. linkNameList.push(zrUtil.retrieve(link.id, source + ' > ' + target));
  34744. linkCount++;
  34745. }
  34746. }
  34747. var coordSys = hostModel.get('coordinateSystem');
  34748. var nodeData;
  34749. if (coordSys === 'cartesian2d' || coordSys === 'polar') {
  34750. nodeData = createListFromArray(nodes, hostModel, hostModel.ecModel);
  34751. }
  34752. else {
  34753. // FIXME
  34754. var coordSysCtor = CoordinateSystem.get(coordSys);
  34755. // FIXME
  34756. var dimensionNames = completeDimensions(
  34757. ((coordSysCtor && coordSysCtor.type !== 'view') ? (coordSysCtor.dimensions || []) : []).concat(['value']),
  34758. nodes
  34759. );
  34760. nodeData = new List(dimensionNames, hostModel);
  34761. nodeData.initData(nodes);
  34762. }
  34763. var edgeData = new List(['value'], hostModel);
  34764. edgeData.initData(validEdges, linkNameList);
  34765. beforeLink && beforeLink(nodeData, edgeData);
  34766. linkList({
  34767. mainData: nodeData,
  34768. struct: graph,
  34769. structAttr: 'graph',
  34770. datas: {node: nodeData, edge: edgeData},
  34771. datasAttr: {node: 'data', edge: 'edgeData'}
  34772. });
  34773. // Update dataIndex of nodes and edges because invalid edge may be removed
  34774. graph.update();
  34775. return graph;
  34776. };
  34777. /***/ },
  34778. /* 207 */
  34779. /***/ function(module, exports, __webpack_require__) {
  34780. 'use strict';
  34781. /**
  34782. * Graph data structure
  34783. *
  34784. * @module echarts/data/Graph
  34785. * @author Yi Shen(https://www.github.com/pissang)
  34786. */
  34787. var zrUtil = __webpack_require__(4);
  34788. // id may be function name of Object, add a prefix to avoid this problem.
  34789. function generateNodeKey (id) {
  34790. return '_EC_' + id;
  34791. }
  34792. /**
  34793. * @alias module:echarts/data/Graph
  34794. * @constructor
  34795. * @param {boolean} directed
  34796. */
  34797. var Graph = function(directed) {
  34798. /**
  34799. * 是否是有向图
  34800. * @type {boolean}
  34801. * @private
  34802. */
  34803. this._directed = directed || false;
  34804. /**
  34805. * @type {Array.<module:echarts/data/Graph.Node>}
  34806. * @readOnly
  34807. */
  34808. this.nodes = [];
  34809. /**
  34810. * @type {Array.<module:echarts/data/Graph.Edge>}
  34811. * @readOnly
  34812. */
  34813. this.edges = [];
  34814. /**
  34815. * @type {Object.<string, module:echarts/data/Graph.Node>}
  34816. * @private
  34817. */
  34818. this._nodesMap = {};
  34819. /**
  34820. * @type {Object.<string, module:echarts/data/Graph.Edge>}
  34821. * @private
  34822. */
  34823. this._edgesMap = {};
  34824. /**
  34825. * @type {module:echarts/data/List}
  34826. * @readOnly
  34827. */
  34828. this.data;
  34829. /**
  34830. * @type {module:echarts/data/List}
  34831. * @readOnly
  34832. */
  34833. this.edgeData;
  34834. };
  34835. var graphProto = Graph.prototype;
  34836. /**
  34837. * @type {string}
  34838. */
  34839. graphProto.type = 'graph';
  34840. /**
  34841. * If is directed graph
  34842. * @return {boolean}
  34843. */
  34844. graphProto.isDirected = function () {
  34845. return this._directed;
  34846. };
  34847. /**
  34848. * Add a new node
  34849. * @param {string} id
  34850. * @param {number} [dataIndex]
  34851. */
  34852. graphProto.addNode = function (id, dataIndex) {
  34853. id = id || ('' + dataIndex);
  34854. var nodesMap = this._nodesMap;
  34855. if (nodesMap[generateNodeKey(id)]) {
  34856. return;
  34857. }
  34858. var node = new Node(id, dataIndex);
  34859. node.hostGraph = this;
  34860. this.nodes.push(node);
  34861. nodesMap[generateNodeKey(id)] = node;
  34862. return node;
  34863. };
  34864. /**
  34865. * Get node by data index
  34866. * @param {number} dataIndex
  34867. * @return {module:echarts/data/Graph~Node}
  34868. */
  34869. graphProto.getNodeByIndex = function (dataIndex) {
  34870. var rawIdx = this.data.getRawIndex(dataIndex);
  34871. return this.nodes[rawIdx];
  34872. };
  34873. /**
  34874. * Get node by id
  34875. * @param {string} id
  34876. * @return {module:echarts/data/Graph.Node}
  34877. */
  34878. graphProto.getNodeById = function (id) {
  34879. return this._nodesMap[generateNodeKey(id)];
  34880. };
  34881. /**
  34882. * Add a new edge
  34883. * @param {number|string|module:echarts/data/Graph.Node} n1
  34884. * @param {number|string|module:echarts/data/Graph.Node} n2
  34885. * @param {number} [dataIndex=-1]
  34886. * @return {module:echarts/data/Graph.Edge}
  34887. */
  34888. graphProto.addEdge = function (n1, n2, dataIndex) {
  34889. var nodesMap = this._nodesMap;
  34890. var edgesMap = this._edgesMap;
  34891. // PNEDING
  34892. if (typeof n1 === 'number') {
  34893. n1 = this.nodes[n1];
  34894. }
  34895. if (typeof n2 === 'number') {
  34896. n2 = this.nodes[n2];
  34897. }
  34898. if (!(n1 instanceof Node)) {
  34899. n1 = nodesMap[generateNodeKey(n1)];
  34900. }
  34901. if (!(n2 instanceof Node)) {
  34902. n2 = nodesMap[generateNodeKey(n2)];
  34903. }
  34904. if (!n1 || !n2) {
  34905. return;
  34906. }
  34907. var key = n1.id + '-' + n2.id;
  34908. // PENDING
  34909. if (edgesMap[key]) {
  34910. return;
  34911. }
  34912. var edge = new Edge(n1, n2, dataIndex);
  34913. edge.hostGraph = this;
  34914. if (this._directed) {
  34915. n1.outEdges.push(edge);
  34916. n2.inEdges.push(edge);
  34917. }
  34918. n1.edges.push(edge);
  34919. if (n1 !== n2) {
  34920. n2.edges.push(edge);
  34921. }
  34922. this.edges.push(edge);
  34923. edgesMap[key] = edge;
  34924. return edge;
  34925. };
  34926. /**
  34927. * Get edge by data index
  34928. * @param {number} dataIndex
  34929. * @return {module:echarts/data/Graph~Node}
  34930. */
  34931. graphProto.getEdgeByIndex = function (dataIndex) {
  34932. var rawIdx = this.edgeData.getRawIndex(dataIndex);
  34933. return this.edges[rawIdx];
  34934. };
  34935. /**
  34936. * Get edge by two linked nodes
  34937. * @param {module:echarts/data/Graph.Node|string} n1
  34938. * @param {module:echarts/data/Graph.Node|string} n2
  34939. * @return {module:echarts/data/Graph.Edge}
  34940. */
  34941. graphProto.getEdge = function (n1, n2) {
  34942. if (n1 instanceof Node) {
  34943. n1 = n1.id;
  34944. }
  34945. if (n2 instanceof Node) {
  34946. n2 = n2.id;
  34947. }
  34948. var edgesMap = this._edgesMap;
  34949. if (this._directed) {
  34950. return edgesMap[n1 + '-' + n2];
  34951. } else {
  34952. return edgesMap[n1 + '-' + n2]
  34953. || edgesMap[n2 + '-' + n1];
  34954. }
  34955. };
  34956. /**
  34957. * Iterate all nodes
  34958. * @param {Function} cb
  34959. * @param {*} [context]
  34960. */
  34961. graphProto.eachNode = function (cb, context) {
  34962. var nodes = this.nodes;
  34963. var len = nodes.length;
  34964. for (var i = 0; i < len; i++) {
  34965. if (nodes[i].dataIndex >= 0) {
  34966. cb.call(context, nodes[i], i);
  34967. }
  34968. }
  34969. };
  34970. /**
  34971. * Iterate all edges
  34972. * @param {Function} cb
  34973. * @param {*} [context]
  34974. */
  34975. graphProto.eachEdge = function (cb, context) {
  34976. var edges = this.edges;
  34977. var len = edges.length;
  34978. for (var i = 0; i < len; i++) {
  34979. if (edges[i].dataIndex >= 0
  34980. && edges[i].node1.dataIndex >= 0
  34981. && edges[i].node2.dataIndex >= 0
  34982. ) {
  34983. cb.call(context, edges[i], i);
  34984. }
  34985. }
  34986. };
  34987. /**
  34988. * Breadth first traverse
  34989. * @param {Function} cb
  34990. * @param {module:echarts/data/Graph.Node} startNode
  34991. * @param {string} [direction='none'] 'none'|'in'|'out'
  34992. * @param {*} [context]
  34993. */
  34994. graphProto.breadthFirstTraverse = function (
  34995. cb, startNode, direction, context
  34996. ) {
  34997. if (!(startNode instanceof Node)) {
  34998. startNode = this._nodesMap[generateNodeKey(startNode)];
  34999. }
  35000. if (!startNode) {
  35001. return;
  35002. }
  35003. var edgeType = direction === 'out'
  35004. ? 'outEdges' : (direction === 'in' ? 'inEdges' : 'edges');
  35005. for (var i = 0; i < this.nodes.length; i++) {
  35006. this.nodes[i].__visited = false;
  35007. }
  35008. if (cb.call(context, startNode, null)) {
  35009. return;
  35010. }
  35011. var queue = [startNode];
  35012. while (queue.length) {
  35013. var currentNode = queue.shift();
  35014. var edges = currentNode[edgeType];
  35015. for (var i = 0; i < edges.length; i++) {
  35016. var e = edges[i];
  35017. var otherNode = e.node1 === currentNode
  35018. ? e.node2 : e.node1;
  35019. if (!otherNode.__visited) {
  35020. if (cb.call(context, otherNode, currentNode)) {
  35021. // Stop traversing
  35022. return;
  35023. }
  35024. queue.push(otherNode);
  35025. otherNode.__visited = true;
  35026. }
  35027. }
  35028. }
  35029. };
  35030. // TODO
  35031. // graphProto.depthFirstTraverse = function (
  35032. // cb, startNode, direction, context
  35033. // ) {
  35034. // };
  35035. // Filter update
  35036. graphProto.update = function () {
  35037. var data = this.data;
  35038. var edgeData = this.edgeData;
  35039. var nodes = this.nodes;
  35040. var edges = this.edges;
  35041. for (var i = 0, len = nodes.length; i < len; i++) {
  35042. nodes[i].dataIndex = -1;
  35043. }
  35044. for (var i = 0, len = data.count(); i < len; i++) {
  35045. nodes[data.getRawIndex(i)].dataIndex = i;
  35046. }
  35047. edgeData.filterSelf(function (idx) {
  35048. var edge = edges[edgeData.getRawIndex(idx)];
  35049. return edge.node1.dataIndex >= 0 && edge.node2.dataIndex >= 0;
  35050. });
  35051. // Update edge
  35052. for (var i = 0, len = edges.length; i < len; i++) {
  35053. edges[i].dataIndex = -1;
  35054. }
  35055. for (var i = 0, len = edgeData.count(); i < len; i++) {
  35056. edges[edgeData.getRawIndex(i)].dataIndex = i;
  35057. }
  35058. };
  35059. /**
  35060. * @return {module:echarts/data/Graph}
  35061. */
  35062. graphProto.clone = function () {
  35063. var graph = new Graph(this._directed);
  35064. var nodes = this.nodes;
  35065. var edges = this.edges;
  35066. for (var i = 0; i < nodes.length; i++) {
  35067. graph.addNode(nodes[i].id, nodes[i].dataIndex);
  35068. }
  35069. for (var i = 0; i < edges.length; i++) {
  35070. var e = edges[i];
  35071. graph.addEdge(e.node1.id, e.node2.id, e.dataIndex);
  35072. }
  35073. return graph;
  35074. };
  35075. /**
  35076. * @alias module:echarts/data/Graph.Node
  35077. */
  35078. function Node(id, dataIndex) {
  35079. /**
  35080. * @type {string}
  35081. */
  35082. this.id = id == null ? '' : id;
  35083. /**
  35084. * @type {Array.<module:echarts/data/Graph.Edge>}
  35085. */
  35086. this.inEdges = [];
  35087. /**
  35088. * @type {Array.<module:echarts/data/Graph.Edge>}
  35089. */
  35090. this.outEdges = [];
  35091. /**
  35092. * @type {Array.<module:echarts/data/Graph.Edge>}
  35093. */
  35094. this.edges = [];
  35095. /**
  35096. * @type {module:echarts/data/Graph}
  35097. */
  35098. this.hostGraph;
  35099. /**
  35100. * @type {number}
  35101. */
  35102. this.dataIndex = dataIndex == null ? -1 : dataIndex;
  35103. }
  35104. Node.prototype = {
  35105. constructor: Node,
  35106. /**
  35107. * @return {number}
  35108. */
  35109. degree: function () {
  35110. return this.edges.length;
  35111. },
  35112. /**
  35113. * @return {number}
  35114. */
  35115. inDegree: function () {
  35116. return this.inEdges.length;
  35117. },
  35118. /**
  35119. * @return {number}
  35120. */
  35121. outDegree: function () {
  35122. return this.outEdges.length;
  35123. },
  35124. /**
  35125. * @param {string} [path]
  35126. * @return {module:echarts/model/Model}
  35127. */
  35128. getModel: function (path) {
  35129. if (this.dataIndex < 0) {
  35130. return;
  35131. }
  35132. var graph = this.hostGraph;
  35133. var itemModel = graph.data.getItemModel(this.dataIndex);
  35134. return itemModel.getModel(path);
  35135. }
  35136. };
  35137. /**
  35138. * 图边
  35139. * @alias module:echarts/data/Graph.Edge
  35140. * @param {module:echarts/data/Graph.Node} n1
  35141. * @param {module:echarts/data/Graph.Node} n2
  35142. * @param {number} [dataIndex=-1]
  35143. */
  35144. function Edge(n1, n2, dataIndex) {
  35145. /**
  35146. * 节点1,如果是有向图则为源节点
  35147. * @type {module:echarts/data/Graph.Node}
  35148. */
  35149. this.node1 = n1;
  35150. /**
  35151. * 节点2,如果是有向图则为目标节点
  35152. * @type {module:echarts/data/Graph.Node}
  35153. */
  35154. this.node2 = n2;
  35155. this.dataIndex = dataIndex == null ? -1 : dataIndex;
  35156. }
  35157. /**
  35158. * @param {string} [path]
  35159. * @return {module:echarts/model/Model}
  35160. */
  35161. Edge.prototype.getModel = function (path) {
  35162. if (this.dataIndex < 0) {
  35163. return;
  35164. }
  35165. var graph = this.hostGraph;
  35166. var itemModel = graph.edgeData.getItemModel(this.dataIndex);
  35167. return itemModel.getModel(path);
  35168. };
  35169. var createGraphDataProxyMixin = function (hostName, dataName) {
  35170. return {
  35171. /**
  35172. * @param {string=} [dimension='value'] Default 'value'. can be 'a', 'b', 'c', 'd', 'e'.
  35173. * @return {number}
  35174. */
  35175. getValue: function (dimension) {
  35176. var data = this[hostName][dataName];
  35177. return data.get(data.getDimension(dimension || 'value'), this.dataIndex);
  35178. },
  35179. /**
  35180. * @param {Object|string} key
  35181. * @param {*} [value]
  35182. */
  35183. setVisual: function (key, value) {
  35184. this.dataIndex >= 0
  35185. && this[hostName][dataName].setItemVisual(this.dataIndex, key, value);
  35186. },
  35187. /**
  35188. * @param {string} key
  35189. * @return {boolean}
  35190. */
  35191. getVisual: function (key, ignoreParent) {
  35192. return this[hostName][dataName].getItemVisual(this.dataIndex, key, ignoreParent);
  35193. },
  35194. /**
  35195. * @param {Object} layout
  35196. * @return {boolean} [merge=false]
  35197. */
  35198. setLayout: function (layout, merge) {
  35199. this.dataIndex >= 0
  35200. && this[hostName][dataName].setItemLayout(this.dataIndex, layout, merge);
  35201. },
  35202. /**
  35203. * @return {Object}
  35204. */
  35205. getLayout: function () {
  35206. return this[hostName][dataName].getItemLayout(this.dataIndex);
  35207. },
  35208. /**
  35209. * @return {module:zrender/Element}
  35210. */
  35211. getGraphicEl: function () {
  35212. return this[hostName][dataName].getItemGraphicEl(this.dataIndex);
  35213. },
  35214. /**
  35215. * @return {number}
  35216. */
  35217. getRawIndex: function () {
  35218. return this[hostName][dataName].getRawIndex(this.dataIndex);
  35219. }
  35220. };
  35221. };
  35222. zrUtil.mixin(Node, createGraphDataProxyMixin('hostGraph', 'data'));
  35223. zrUtil.mixin(Edge, createGraphDataProxyMixin('hostGraph', 'edgeData'));
  35224. Graph.Node = Node;
  35225. Graph.Edge = Edge;
  35226. module.exports = Graph;
  35227. /***/ },
  35228. /* 208 */
  35229. /***/ function(module, exports, __webpack_require__) {
  35230. var SymbolDraw = __webpack_require__(116);
  35231. var LineDraw = __webpack_require__(209);
  35232. var RoamController = __webpack_require__(182);
  35233. var roamHelper = __webpack_require__(184);
  35234. var cursorHelper = __webpack_require__(185);
  35235. var graphic = __webpack_require__(18);
  35236. var adjustEdge = __webpack_require__(212);
  35237. var zrUtil = __webpack_require__(4);
  35238. var nodeOpacityPath = ['itemStyle', 'normal', 'opacity'];
  35239. var lineOpacityPath = ['lineStyle', 'normal', 'opacity'];
  35240. function getItemOpacity(item, opacityPath) {
  35241. return item.getVisual('opacity') || item.getModel().get(opacityPath);
  35242. }
  35243. __webpack_require__(1).extendChartView({
  35244. type: 'graph',
  35245. init: function (ecModel, api) {
  35246. var symbolDraw = new SymbolDraw();
  35247. var lineDraw = new LineDraw();
  35248. var group = this.group;
  35249. this._controller = new RoamController(api.getZr());
  35250. this._controllerHost = {target: group};
  35251. group.add(symbolDraw.group);
  35252. group.add(lineDraw.group);
  35253. this._symbolDraw = symbolDraw;
  35254. this._lineDraw = lineDraw;
  35255. this._firstRender = true;
  35256. },
  35257. render: function (seriesModel, ecModel, api) {
  35258. var coordSys = seriesModel.coordinateSystem;
  35259. this._model = seriesModel;
  35260. this._nodeScaleRatio = seriesModel.get('nodeScaleRatio');
  35261. var symbolDraw = this._symbolDraw;
  35262. var lineDraw = this._lineDraw;
  35263. var group = this.group;
  35264. if (coordSys.type === 'view') {
  35265. var groupNewProp = {
  35266. position: coordSys.position,
  35267. scale: coordSys.scale
  35268. };
  35269. if (this._firstRender) {
  35270. group.attr(groupNewProp);
  35271. }
  35272. else {
  35273. graphic.updateProps(group, groupNewProp, seriesModel);
  35274. }
  35275. }
  35276. // Fix edge contact point with node
  35277. adjustEdge(seriesModel.getGraph(), this._getNodeGlobalScale(seriesModel));
  35278. var data = seriesModel.getData();
  35279. symbolDraw.updateData(data);
  35280. var edgeData = seriesModel.getEdgeData();
  35281. lineDraw.updateData(edgeData);
  35282. this._updateNodeAndLinkScale();
  35283. this._updateController(seriesModel, ecModel, api);
  35284. clearTimeout(this._layoutTimeout);
  35285. var forceLayout = seriesModel.forceLayout;
  35286. var layoutAnimation = seriesModel.get('force.layoutAnimation');
  35287. if (forceLayout) {
  35288. this._startForceLayoutIteration(forceLayout, layoutAnimation);
  35289. }
  35290. data.eachItemGraphicEl(function (el, idx) {
  35291. var itemModel = data.getItemModel(idx);
  35292. // Update draggable
  35293. el.off('drag').off('dragend');
  35294. var draggable = data.getItemModel(idx).get('draggable');
  35295. if (draggable) {
  35296. el.on('drag', function () {
  35297. if (forceLayout) {
  35298. forceLayout.warmUp();
  35299. !this._layouting
  35300. && this._startForceLayoutIteration(forceLayout, layoutAnimation);
  35301. forceLayout.setFixed(idx);
  35302. // Write position back to layout
  35303. data.setItemLayout(idx, el.position);
  35304. }
  35305. }, this).on('dragend', function () {
  35306. if (forceLayout) {
  35307. forceLayout.setUnfixed(idx);
  35308. }
  35309. }, this);
  35310. }
  35311. el.setDraggable(draggable && forceLayout);
  35312. el.off('mouseover', el.__focusNodeAdjacency);
  35313. el.off('mouseout', el.__unfocusNodeAdjacency);
  35314. if (itemModel.get('focusNodeAdjacency')) {
  35315. el.on('mouseover', el.__focusNodeAdjacency = function () {
  35316. api.dispatchAction({
  35317. type: 'focusNodeAdjacency',
  35318. seriesId: seriesModel.id,
  35319. dataIndex: el.dataIndex
  35320. });
  35321. });
  35322. el.on('mouseout', el.__unfocusNodeAdjacency = function () {
  35323. api.dispatchAction({
  35324. type: 'unfocusNodeAdjacency',
  35325. seriesId: seriesModel.id
  35326. });
  35327. });
  35328. }
  35329. }, this);
  35330. var circularRotateLabel = seriesModel.get('layout') === 'circular' && seriesModel.get('circular.rotateLabel');
  35331. var cx = data.getLayout('cx');
  35332. var cy = data.getLayout('cy');
  35333. data.eachItemGraphicEl(function (el, idx) {
  35334. var symbolPath = el.getSymbolPath();
  35335. if (circularRotateLabel) {
  35336. var pos = data.getItemLayout(idx);
  35337. var rad = Math.atan2(pos[1] - cy, pos[0] - cx);
  35338. if (rad < 0) {
  35339. rad = Math.PI * 2 + rad;
  35340. }
  35341. var isLeft = pos[0] < cx;
  35342. if (isLeft) {
  35343. rad = rad - Math.PI;
  35344. }
  35345. var textPosition = isLeft ? 'left' : 'right';
  35346. symbolPath.setStyle({
  35347. textRotation: rad,
  35348. textPosition: textPosition
  35349. });
  35350. symbolPath.hoverStyle && (symbolPath.hoverStyle.textPosition = textPosition);
  35351. }
  35352. else {
  35353. symbolPath.setStyle({
  35354. textRotation: 0
  35355. });
  35356. }
  35357. });
  35358. this._firstRender = false;
  35359. },
  35360. dispose: function () {
  35361. this._controller && this._controller.dispose();
  35362. this._controllerHost = {};
  35363. },
  35364. focusNodeAdjacency: function (seriesModel, ecModel, api, payload) {
  35365. var data = this._model.getData();
  35366. var dataIndex = payload.dataIndex;
  35367. var el = data.getItemGraphicEl(dataIndex);
  35368. if (!el) {
  35369. return;
  35370. }
  35371. var graph = data.graph;
  35372. var dataType = el.dataType;
  35373. function fadeOutItem(item, opacityPath) {
  35374. var opacity = getItemOpacity(item, opacityPath);
  35375. var el = item.getGraphicEl();
  35376. if (opacity == null) {
  35377. opacity = 1;
  35378. }
  35379. el.traverse(function (child) {
  35380. child.trigger('normal');
  35381. if (child.type !== 'group') {
  35382. child.setStyle('opacity', opacity * 0.1);
  35383. }
  35384. });
  35385. }
  35386. function fadeInItem(item, opacityPath) {
  35387. var opacity = getItemOpacity(item, opacityPath);
  35388. var el = item.getGraphicEl();
  35389. el.traverse(function (child) {
  35390. child.trigger('emphasis');
  35391. if (child.type !== 'group') {
  35392. child.setStyle('opacity', opacity);
  35393. }
  35394. });
  35395. }
  35396. if (dataIndex !== null && dataType !== 'edge') {
  35397. graph.eachNode(function (node) {
  35398. fadeOutItem(node, nodeOpacityPath);
  35399. });
  35400. graph.eachEdge(function (edge) {
  35401. fadeOutItem(edge, lineOpacityPath);
  35402. });
  35403. var node = graph.getNodeByIndex(dataIndex);
  35404. fadeInItem(node, nodeOpacityPath);
  35405. zrUtil.each(node.edges, function (edge) {
  35406. if (edge.dataIndex < 0) {
  35407. return;
  35408. }
  35409. fadeInItem(edge, lineOpacityPath);
  35410. fadeInItem(edge.node1, nodeOpacityPath);
  35411. fadeInItem(edge.node2, nodeOpacityPath);
  35412. });
  35413. }
  35414. },
  35415. unfocusNodeAdjacency: function (seriesModel, ecModel, api, payload) {
  35416. var graph = this._model.getData().graph;
  35417. graph.eachNode(function (node) {
  35418. var opacity = getItemOpacity(node, nodeOpacityPath);
  35419. node.getGraphicEl().traverse(function (child) {
  35420. child.trigger('normal');
  35421. if (child.type !== 'group') {
  35422. child.setStyle('opacity', opacity);
  35423. }
  35424. });
  35425. });
  35426. graph.eachEdge(function (edge) {
  35427. var opacity = getItemOpacity(edge, lineOpacityPath);
  35428. edge.getGraphicEl().traverse(function (child) {
  35429. child.trigger('normal');
  35430. if (child.type !== 'group') {
  35431. child.setStyle('opacity', opacity);
  35432. }
  35433. });
  35434. });
  35435. },
  35436. _startForceLayoutIteration: function (forceLayout, layoutAnimation) {
  35437. var self = this;
  35438. (function step() {
  35439. forceLayout.step(function (stopped) {
  35440. self.updateLayout(self._model);
  35441. (self._layouting = !stopped) && (
  35442. layoutAnimation
  35443. ? (self._layoutTimeout = setTimeout(step, 16))
  35444. : step()
  35445. );
  35446. });
  35447. })();
  35448. },
  35449. _updateController: function (seriesModel, ecModel, api) {
  35450. var controller = this._controller;
  35451. var controllerHost = this._controllerHost;
  35452. var group = this.group;
  35453. controller.setPointerChecker(function (e, x, y) {
  35454. var rect = group.getBoundingRect();
  35455. rect.applyTransform(group.transform);
  35456. return rect.contain(x, y)
  35457. && !cursorHelper.onIrrelevantElement(e, api, seriesModel);
  35458. });
  35459. if (seriesModel.coordinateSystem.type !== 'view') {
  35460. controller.disable();
  35461. return;
  35462. }
  35463. controller.enable(seriesModel.get('roam'));
  35464. controllerHost.zoomLimit = seriesModel.get('scaleLimit');
  35465. controllerHost.zoom = seriesModel.coordinateSystem.getZoom();
  35466. controller
  35467. .off('pan')
  35468. .off('zoom')
  35469. .on('pan', function (dx, dy) {
  35470. roamHelper.updateViewOnPan(controllerHost, dx, dy);
  35471. api.dispatchAction({
  35472. seriesId: seriesModel.id,
  35473. type: 'graphRoam',
  35474. dx: dx,
  35475. dy: dy
  35476. });
  35477. })
  35478. .on('zoom', function (zoom, mouseX, mouseY) {
  35479. roamHelper.updateViewOnZoom(controllerHost, zoom, mouseX, mouseY);
  35480. api.dispatchAction({
  35481. seriesId: seriesModel.id,
  35482. type: 'graphRoam',
  35483. zoom: zoom,
  35484. originX: mouseX,
  35485. originY: mouseY
  35486. });
  35487. this._updateNodeAndLinkScale();
  35488. adjustEdge(seriesModel.getGraph(), this._getNodeGlobalScale(seriesModel));
  35489. this._lineDraw.updateLayout();
  35490. }, this);
  35491. },
  35492. _updateNodeAndLinkScale: function () {
  35493. var seriesModel = this._model;
  35494. var data = seriesModel.getData();
  35495. var nodeScale = this._getNodeGlobalScale(seriesModel);
  35496. var invScale = [nodeScale, nodeScale];
  35497. data.eachItemGraphicEl(function (el, idx) {
  35498. el.attr('scale', invScale);
  35499. });
  35500. },
  35501. _getNodeGlobalScale: function (seriesModel) {
  35502. var coordSys = seriesModel.coordinateSystem;
  35503. if (coordSys.type !== 'view') {
  35504. return 1;
  35505. }
  35506. var nodeScaleRatio = this._nodeScaleRatio;
  35507. var groupScale = coordSys.scale;
  35508. var groupZoom = (groupScale && groupScale[0]) || 1;
  35509. // Scale node when zoom changes
  35510. var roamZoom = coordSys.getZoom();
  35511. var nodeScale = (roamZoom - 1) * nodeScaleRatio + 1;
  35512. return nodeScale / groupZoom;
  35513. },
  35514. updateLayout: function (seriesModel) {
  35515. adjustEdge(seriesModel.getGraph(), this._getNodeGlobalScale(seriesModel));
  35516. this._symbolDraw.updateLayout();
  35517. this._lineDraw.updateLayout();
  35518. },
  35519. remove: function (ecModel, api) {
  35520. this._symbolDraw && this._symbolDraw.remove();
  35521. this._lineDraw && this._lineDraw.remove();
  35522. }
  35523. });
  35524. /***/ },
  35525. /* 209 */
  35526. /***/ function(module, exports, __webpack_require__) {
  35527. /**
  35528. * @module echarts/chart/helper/LineDraw
  35529. */
  35530. var graphic = __webpack_require__(18);
  35531. var LineGroup = __webpack_require__(210);
  35532. function isPointNaN(pt) {
  35533. return isNaN(pt[0]) || isNaN(pt[1]);
  35534. }
  35535. function lineNeedsDraw(pts) {
  35536. return !isPointNaN(pts[0]) && !isPointNaN(pts[1]);
  35537. }
  35538. /**
  35539. * @alias module:echarts/component/marker/LineDraw
  35540. * @constructor
  35541. */
  35542. function LineDraw(ctor) {
  35543. this._ctor = ctor || LineGroup;
  35544. this.group = new graphic.Group();
  35545. }
  35546. var lineDrawProto = LineDraw.prototype;
  35547. /**
  35548. * @param {module:echarts/data/List} lineData
  35549. */
  35550. lineDrawProto.updateData = function (lineData) {
  35551. var oldLineData = this._lineData;
  35552. var group = this.group;
  35553. var LineCtor = this._ctor;
  35554. var hostModel = lineData.hostModel;
  35555. var seriesScope = {
  35556. lineStyle: hostModel.getModel('lineStyle.normal').getLineStyle(),
  35557. hoverLineStyle: hostModel.getModel('lineStyle.emphasis').getLineStyle(),
  35558. labelModel: hostModel.getModel('label.normal'),
  35559. hoverLabelModel: hostModel.getModel('label.emphasis')
  35560. };
  35561. lineData.diff(oldLineData)
  35562. .add(function (idx) {
  35563. if (!lineNeedsDraw(lineData.getItemLayout(idx))) {
  35564. return;
  35565. }
  35566. var lineGroup = new LineCtor(lineData, idx, seriesScope);
  35567. lineData.setItemGraphicEl(idx, lineGroup);
  35568. group.add(lineGroup);
  35569. })
  35570. .update(function (newIdx, oldIdx) {
  35571. var lineGroup = oldLineData.getItemGraphicEl(oldIdx);
  35572. if (!lineNeedsDraw(lineData.getItemLayout(newIdx))) {
  35573. group.remove(lineGroup);
  35574. return;
  35575. }
  35576. if (!lineGroup) {
  35577. lineGroup = new LineCtor(lineData, newIdx, seriesScope);
  35578. }
  35579. else {
  35580. lineGroup.updateData(lineData, newIdx, seriesScope);
  35581. }
  35582. lineData.setItemGraphicEl(newIdx, lineGroup);
  35583. group.add(lineGroup);
  35584. })
  35585. .remove(function (idx) {
  35586. group.remove(oldLineData.getItemGraphicEl(idx));
  35587. })
  35588. .execute();
  35589. this._lineData = lineData;
  35590. };
  35591. lineDrawProto.updateLayout = function () {
  35592. var lineData = this._lineData;
  35593. lineData.eachItemGraphicEl(function (el, idx) {
  35594. el.updateLayout(lineData, idx);
  35595. }, this);
  35596. };
  35597. lineDrawProto.remove = function () {
  35598. this.group.removeAll();
  35599. };
  35600. module.exports = LineDraw;
  35601. /***/ },
  35602. /* 210 */
  35603. /***/ function(module, exports, __webpack_require__) {
  35604. /**
  35605. * @module echarts/chart/helper/Line
  35606. */
  35607. var symbolUtil = __webpack_require__(111);
  35608. var vector = __webpack_require__(10);
  35609. // var matrix = require('zrender/lib/core/matrix');
  35610. var LinePath = __webpack_require__(211);
  35611. var graphic = __webpack_require__(18);
  35612. var zrUtil = __webpack_require__(4);
  35613. var numberUtil = __webpack_require__(7);
  35614. var SYMBOL_CATEGORIES = ['fromSymbol', 'toSymbol'];
  35615. function makeSymbolTypeKey(symbolCategory) {
  35616. return '_' + symbolCategory + 'Type';
  35617. }
  35618. /**
  35619. * @inner
  35620. */
  35621. function createSymbol(name, lineData, idx) {
  35622. var color = lineData.getItemVisual(idx, 'color');
  35623. var symbolType = lineData.getItemVisual(idx, name);
  35624. var symbolSize = lineData.getItemVisual(idx, name + 'Size');
  35625. if (!symbolType || symbolType === 'none') {
  35626. return;
  35627. }
  35628. if (!zrUtil.isArray(symbolSize)) {
  35629. symbolSize = [symbolSize, symbolSize];
  35630. }
  35631. var symbolPath = symbolUtil.createSymbol(
  35632. symbolType, -symbolSize[0] / 2, -symbolSize[1] / 2,
  35633. symbolSize[0], symbolSize[1], color
  35634. );
  35635. symbolPath.name = name;
  35636. return symbolPath;
  35637. }
  35638. function createLine(points) {
  35639. var line = new LinePath({
  35640. name: 'line'
  35641. });
  35642. setLinePoints(line.shape, points);
  35643. return line;
  35644. }
  35645. function setLinePoints(targetShape, points) {
  35646. var p1 = points[0];
  35647. var p2 = points[1];
  35648. var cp1 = points[2];
  35649. targetShape.x1 = p1[0];
  35650. targetShape.y1 = p1[1];
  35651. targetShape.x2 = p2[0];
  35652. targetShape.y2 = p2[1];
  35653. targetShape.percent = 1;
  35654. if (cp1) {
  35655. targetShape.cpx1 = cp1[0];
  35656. targetShape.cpy1 = cp1[1];
  35657. }
  35658. else {
  35659. targetShape.cpx1 = NaN;
  35660. targetShape.cpy1 = NaN;
  35661. }
  35662. }
  35663. function updateSymbolAndLabelBeforeLineUpdate () {
  35664. var lineGroup = this;
  35665. var symbolFrom = lineGroup.childOfName('fromSymbol');
  35666. var symbolTo = lineGroup.childOfName('toSymbol');
  35667. var label = lineGroup.childOfName('label');
  35668. // Quick reject
  35669. if (!symbolFrom && !symbolTo && label.ignore) {
  35670. return;
  35671. }
  35672. var invScale = 1;
  35673. var parentNode = this.parent;
  35674. while (parentNode) {
  35675. if (parentNode.scale) {
  35676. invScale /= parentNode.scale[0];
  35677. }
  35678. parentNode = parentNode.parent;
  35679. }
  35680. var line = lineGroup.childOfName('line');
  35681. // If line not changed
  35682. // FIXME Parent scale changed
  35683. if (!this.__dirty && !line.__dirty) {
  35684. return;
  35685. }
  35686. var percent = line.shape.percent;
  35687. var fromPos = line.pointAt(0);
  35688. var toPos = line.pointAt(percent);
  35689. var d = vector.sub([], toPos, fromPos);
  35690. vector.normalize(d, d);
  35691. if (symbolFrom) {
  35692. symbolFrom.attr('position', fromPos);
  35693. var tangent = line.tangentAt(0);
  35694. symbolFrom.attr('rotation', Math.PI / 2 - Math.atan2(
  35695. tangent[1], tangent[0]
  35696. ));
  35697. symbolFrom.attr('scale', [invScale * percent, invScale * percent]);
  35698. }
  35699. if (symbolTo) {
  35700. symbolTo.attr('position', toPos);
  35701. var tangent = line.tangentAt(1);
  35702. symbolTo.attr('rotation', -Math.PI / 2 - Math.atan2(
  35703. tangent[1], tangent[0]
  35704. ));
  35705. symbolTo.attr('scale', [invScale * percent, invScale * percent]);
  35706. }
  35707. if (!label.ignore) {
  35708. label.attr('position', toPos);
  35709. var textPosition;
  35710. var textAlign;
  35711. var textVerticalAlign;
  35712. var distance = 5 * invScale;
  35713. // End
  35714. if (label.__position === 'end') {
  35715. textPosition = [d[0] * distance + toPos[0], d[1] * distance + toPos[1]];
  35716. textAlign = d[0] > 0.8 ? 'left' : (d[0] < -0.8 ? 'right' : 'center');
  35717. textVerticalAlign = d[1] > 0.8 ? 'top' : (d[1] < -0.8 ? 'bottom' : 'middle');
  35718. }
  35719. // Middle
  35720. else if (label.__position === 'middle') {
  35721. var halfPercent = percent / 2;
  35722. var tangent = line.tangentAt(halfPercent);
  35723. var n = [tangent[1], -tangent[0]];
  35724. var cp = line.pointAt(halfPercent);
  35725. if (n[1] > 0) {
  35726. n[0] = -n[0];
  35727. n[1] = -n[1];
  35728. }
  35729. textPosition = [cp[0] + n[0] * distance, cp[1] + n[1] * distance];
  35730. textAlign = 'center';
  35731. textVerticalAlign = 'bottom';
  35732. var rotation = -Math.atan2(tangent[1], tangent[0]);
  35733. if (toPos[0] < fromPos[0]) {
  35734. rotation = Math.PI + rotation;
  35735. }
  35736. label.attr('rotation', rotation);
  35737. }
  35738. // Start
  35739. else {
  35740. textPosition = [-d[0] * distance + fromPos[0], -d[1] * distance + fromPos[1]];
  35741. textAlign = d[0] > 0.8 ? 'right' : (d[0] < -0.8 ? 'left' : 'center');
  35742. textVerticalAlign = d[1] > 0.8 ? 'bottom' : (d[1] < -0.8 ? 'top' : 'middle');
  35743. }
  35744. label.attr({
  35745. style: {
  35746. // Use the user specified text align and baseline first
  35747. textVerticalAlign: label.__verticalAlign || textVerticalAlign,
  35748. textAlign: label.__textAlign || textAlign
  35749. },
  35750. position: textPosition,
  35751. scale: [invScale, invScale]
  35752. });
  35753. }
  35754. }
  35755. /**
  35756. * @constructor
  35757. * @extends {module:zrender/graphic/Group}
  35758. * @alias {module:echarts/chart/helper/Line}
  35759. */
  35760. function Line(lineData, idx, seriesScope) {
  35761. graphic.Group.call(this);
  35762. this._createLine(lineData, idx, seriesScope);
  35763. }
  35764. var lineProto = Line.prototype;
  35765. // Update symbol position and rotation
  35766. lineProto.beforeUpdate = updateSymbolAndLabelBeforeLineUpdate;
  35767. lineProto._createLine = function (lineData, idx, seriesScope) {
  35768. var seriesModel = lineData.hostModel;
  35769. var linePoints = lineData.getItemLayout(idx);
  35770. var line = createLine(linePoints);
  35771. line.shape.percent = 0;
  35772. graphic.initProps(line, {
  35773. shape: {
  35774. percent: 1
  35775. }
  35776. }, seriesModel, idx);
  35777. this.add(line);
  35778. var label = new graphic.Text({
  35779. name: 'label'
  35780. });
  35781. this.add(label);
  35782. zrUtil.each(SYMBOL_CATEGORIES, function (symbolCategory) {
  35783. var symbol = createSymbol(symbolCategory, lineData, idx);
  35784. // symbols must added after line to make sure
  35785. // it will be updated after line#update.
  35786. // Or symbol position and rotation update in line#beforeUpdate will be one frame slow
  35787. this.add(symbol);
  35788. this[makeSymbolTypeKey(symbolCategory)] = lineData.getItemVisual(idx, symbolCategory);
  35789. }, this);
  35790. this._updateCommonStl(lineData, idx, seriesScope);
  35791. };
  35792. lineProto.updateData = function (lineData, idx, seriesScope) {
  35793. var seriesModel = lineData.hostModel;
  35794. var line = this.childOfName('line');
  35795. var linePoints = lineData.getItemLayout(idx);
  35796. var target = {
  35797. shape: {}
  35798. };
  35799. setLinePoints(target.shape, linePoints);
  35800. graphic.updateProps(line, target, seriesModel, idx);
  35801. zrUtil.each(SYMBOL_CATEGORIES, function (symbolCategory) {
  35802. var symbolType = lineData.getItemVisual(idx, symbolCategory);
  35803. var key = makeSymbolTypeKey(symbolCategory);
  35804. // Symbol changed
  35805. if (this[key] !== symbolType) {
  35806. this.remove(this.childOfName(symbolCategory));
  35807. var symbol = createSymbol(symbolCategory, lineData, idx);
  35808. this.add(symbol);
  35809. }
  35810. this[key] = symbolType;
  35811. }, this);
  35812. this._updateCommonStl(lineData, idx, seriesScope);
  35813. };
  35814. lineProto._updateCommonStl = function (lineData, idx, seriesScope) {
  35815. var seriesModel = lineData.hostModel;
  35816. var line = this.childOfName('line');
  35817. var lineStyle = seriesScope && seriesScope.lineStyle;
  35818. var hoverLineStyle = seriesScope && seriesScope.hoverLineStyle;
  35819. var labelModel = seriesScope && seriesScope.labelModel;
  35820. var hoverLabelModel = seriesScope && seriesScope.hoverLabelModel;
  35821. // Optimization for large dataset
  35822. if (!seriesScope || lineData.hasItemOption) {
  35823. var itemModel = lineData.getItemModel(idx);
  35824. lineStyle = itemModel.getModel('lineStyle.normal').getLineStyle();
  35825. hoverLineStyle = itemModel.getModel('lineStyle.emphasis').getLineStyle();
  35826. labelModel = itemModel.getModel('label.normal');
  35827. hoverLabelModel = itemModel.getModel('label.emphasis');
  35828. }
  35829. var visualColor = lineData.getItemVisual(idx, 'color');
  35830. var visualOpacity = zrUtil.retrieve(
  35831. lineData.getItemVisual(idx, 'opacity'),
  35832. lineStyle.opacity,
  35833. 1
  35834. );
  35835. line.useStyle(zrUtil.defaults(
  35836. {
  35837. strokeNoScale: true,
  35838. fill: 'none',
  35839. stroke: visualColor,
  35840. opacity: visualOpacity
  35841. },
  35842. lineStyle
  35843. ));
  35844. line.hoverStyle = hoverLineStyle;
  35845. // Update symbol
  35846. zrUtil.each(SYMBOL_CATEGORIES, function (symbolCategory) {
  35847. var symbol = this.childOfName(symbolCategory);
  35848. if (symbol) {
  35849. symbol.setColor(visualColor);
  35850. symbol.setStyle({
  35851. opacity: visualOpacity
  35852. });
  35853. }
  35854. }, this);
  35855. var showLabel = labelModel.getShallow('show');
  35856. var hoverShowLabel = hoverLabelModel.getShallow('show');
  35857. var label = this.childOfName('label');
  35858. var defaultLabelColor;
  35859. var defaultText;
  35860. if (showLabel || hoverShowLabel) {
  35861. var rawVal = seriesModel.getRawValue(idx);
  35862. defaultText = rawVal == null
  35863. ? defaultText = lineData.getName(idx)
  35864. : isFinite(rawVal)
  35865. ? numberUtil.round(rawVal)
  35866. : rawVal;
  35867. defaultLabelColor = visualColor || '#000';
  35868. }
  35869. // label.afterUpdate = lineAfterUpdate;
  35870. if (showLabel) {
  35871. var textStyleModel = labelModel.getModel('textStyle');
  35872. label.setStyle({
  35873. text: zrUtil.retrieve(
  35874. seriesModel.getFormattedLabel(idx, 'normal', lineData.dataType),
  35875. defaultText
  35876. ),
  35877. textFont: textStyleModel.getFont(),
  35878. fill: textStyleModel.getTextColor() || defaultLabelColor
  35879. });
  35880. label.__textAlign = textStyleModel.get('align');
  35881. label.__verticalAlign = textStyleModel.get('baseline');
  35882. label.__position = labelModel.get('position');
  35883. }
  35884. else {
  35885. label.setStyle('text', '');
  35886. }
  35887. if (hoverShowLabel) {
  35888. var textStyleHoverModel = hoverLabelModel.getModel('textStyle');
  35889. label.hoverStyle = {
  35890. text: zrUtil.retrieve(
  35891. seriesModel.getFormattedLabel(idx, 'emphasis', lineData.dataType),
  35892. defaultText
  35893. ),
  35894. textFont: textStyleHoverModel.getFont(),
  35895. fill: textStyleHoverModel.getTextColor() || defaultLabelColor
  35896. };
  35897. }
  35898. else {
  35899. label.hoverStyle = {
  35900. text: ''
  35901. };
  35902. }
  35903. label.ignore = !showLabel && !hoverShowLabel;
  35904. graphic.setHoverStyle(this);
  35905. };
  35906. lineProto.updateLayout = function (lineData, idx) {
  35907. this.setLinePoints(lineData.getItemLayout(idx));
  35908. };
  35909. lineProto.setLinePoints = function (points) {
  35910. var linePath = this.childOfName('line');
  35911. setLinePoints(linePath.shape, points);
  35912. linePath.dirty();
  35913. };
  35914. zrUtil.inherits(Line, graphic.Group);
  35915. module.exports = Line;
  35916. /***/ },
  35917. /* 211 */
  35918. /***/ function(module, exports, __webpack_require__) {
  35919. /**
  35920. * Line path for bezier and straight line draw
  35921. */
  35922. var graphic = __webpack_require__(18);
  35923. var vec2 = __webpack_require__(10);
  35924. var straightLineProto = graphic.Line.prototype;
  35925. var bezierCurveProto = graphic.BezierCurve.prototype;
  35926. function isLine(shape) {
  35927. return isNaN(+shape.cpx1) || isNaN(+shape.cpy1);
  35928. }
  35929. module.exports = graphic.extendShape({
  35930. type: 'ec-line',
  35931. style: {
  35932. stroke: '#000',
  35933. fill: null
  35934. },
  35935. shape: {
  35936. x1: 0,
  35937. y1: 0,
  35938. x2: 0,
  35939. y2: 0,
  35940. percent: 1,
  35941. cpx1: null,
  35942. cpy1: null
  35943. },
  35944. buildPath: function (ctx, shape) {
  35945. (isLine(shape) ? straightLineProto : bezierCurveProto).buildPath(ctx, shape);
  35946. },
  35947. pointAt: function (t) {
  35948. return isLine(this.shape)
  35949. ? straightLineProto.pointAt.call(this, t)
  35950. : bezierCurveProto.pointAt.call(this, t);
  35951. },
  35952. tangentAt: function (t) {
  35953. var shape = this.shape;
  35954. var p = isLine(shape)
  35955. ? [shape.x2 - shape.x1, shape.y2 - shape.y1]
  35956. : bezierCurveProto.tangentAt.call(this, t);
  35957. return vec2.normalize(p, p);
  35958. }
  35959. });
  35960. /***/ },
  35961. /* 212 */
  35962. /***/ function(module, exports, __webpack_require__) {
  35963. var curveTool = __webpack_require__(37);
  35964. var vec2 = __webpack_require__(10);
  35965. var v1 = [];
  35966. var v2 = [];
  35967. var v3 = [];
  35968. var quadraticAt = curveTool.quadraticAt;
  35969. var v2DistSquare = vec2.distSquare;
  35970. var mathAbs = Math.abs;
  35971. function intersectCurveCircle(curvePoints, center, radius) {
  35972. var p0 = curvePoints[0];
  35973. var p1 = curvePoints[1];
  35974. var p2 = curvePoints[2];
  35975. var d = Infinity;
  35976. var t;
  35977. var radiusSquare = radius * radius;
  35978. var interval = 0.1;
  35979. for (var _t = 0.1; _t <= 0.9; _t += 0.1) {
  35980. v1[0] = quadraticAt(p0[0], p1[0], p2[0], _t);
  35981. v1[1] = quadraticAt(p0[1], p1[1], p2[1], _t);
  35982. var diff = mathAbs(v2DistSquare(v1, center) - radiusSquare);
  35983. if (diff < d) {
  35984. d = diff;
  35985. t = _t;
  35986. }
  35987. }
  35988. // Assume the segment is monotone,Find root through Bisection method
  35989. // At most 32 iteration
  35990. for (var i = 0; i < 32; i++) {
  35991. // var prev = t - interval;
  35992. var next = t + interval;
  35993. // v1[0] = quadraticAt(p0[0], p1[0], p2[0], prev);
  35994. // v1[1] = quadraticAt(p0[1], p1[1], p2[1], prev);
  35995. v2[0] = quadraticAt(p0[0], p1[0], p2[0], t);
  35996. v2[1] = quadraticAt(p0[1], p1[1], p2[1], t);
  35997. v3[0] = quadraticAt(p0[0], p1[0], p2[0], next);
  35998. v3[1] = quadraticAt(p0[1], p1[1], p2[1], next);
  35999. var diff = v2DistSquare(v2, center) - radiusSquare;
  36000. if (mathAbs(diff) < 1e-2) {
  36001. break;
  36002. }
  36003. // var prevDiff = v2DistSquare(v1, center) - radiusSquare;
  36004. var nextDiff = v2DistSquare(v3, center) - radiusSquare;
  36005. interval /= 2;
  36006. if (diff < 0) {
  36007. if (nextDiff >= 0) {
  36008. t = t + interval;
  36009. }
  36010. else {
  36011. t = t - interval;
  36012. }
  36013. }
  36014. else {
  36015. if (nextDiff >= 0) {
  36016. t = t - interval;
  36017. }
  36018. else {
  36019. t = t + interval;
  36020. }
  36021. }
  36022. }
  36023. return t;
  36024. }
  36025. // Adjust edge to avoid
  36026. module.exports = function (graph, scale) {
  36027. var tmp0 = [];
  36028. var quadraticSubdivide = curveTool.quadraticSubdivide;
  36029. var pts = [[], [], []];
  36030. var pts2 = [[], []];
  36031. var v = [];
  36032. scale /= 2;
  36033. function getSymbolSize(node) {
  36034. var symbolSize = node.getVisual('symbolSize');
  36035. if (symbolSize instanceof Array) {
  36036. symbolSize = (symbolSize[0] + symbolSize[1]) / 2;
  36037. }
  36038. return symbolSize;
  36039. }
  36040. graph.eachEdge(function (edge, idx) {
  36041. var linePoints = edge.getLayout();
  36042. var fromSymbol = edge.getVisual('fromSymbol');
  36043. var toSymbol = edge.getVisual('toSymbol');
  36044. if (!linePoints.__original) {
  36045. linePoints.__original = [
  36046. vec2.clone(linePoints[0]),
  36047. vec2.clone(linePoints[1])
  36048. ];
  36049. if (linePoints[2]) {
  36050. linePoints.__original.push(vec2.clone(linePoints[2]));
  36051. }
  36052. }
  36053. var originalPoints = linePoints.__original;
  36054. // Quadratic curve
  36055. if (linePoints[2] != null) {
  36056. vec2.copy(pts[0], originalPoints[0]);
  36057. vec2.copy(pts[1], originalPoints[2]);
  36058. vec2.copy(pts[2], originalPoints[1]);
  36059. if (fromSymbol && fromSymbol != 'none') {
  36060. var symbolSize = getSymbolSize(edge.node1);
  36061. var t = intersectCurveCircle(pts, originalPoints[0], symbolSize * scale);
  36062. // Subdivide and get the second
  36063. quadraticSubdivide(pts[0][0], pts[1][0], pts[2][0], t, tmp0);
  36064. pts[0][0] = tmp0[3];
  36065. pts[1][0] = tmp0[4];
  36066. quadraticSubdivide(pts[0][1], pts[1][1], pts[2][1], t, tmp0);
  36067. pts[0][1] = tmp0[3];
  36068. pts[1][1] = tmp0[4];
  36069. }
  36070. if (toSymbol && toSymbol != 'none') {
  36071. var symbolSize = getSymbolSize(edge.node2);
  36072. var t = intersectCurveCircle(pts, originalPoints[1], symbolSize * scale);
  36073. // Subdivide and get the first
  36074. quadraticSubdivide(pts[0][0], pts[1][0], pts[2][0], t, tmp0);
  36075. pts[1][0] = tmp0[1];
  36076. pts[2][0] = tmp0[2];
  36077. quadraticSubdivide(pts[0][1], pts[1][1], pts[2][1], t, tmp0);
  36078. pts[1][1] = tmp0[1];
  36079. pts[2][1] = tmp0[2];
  36080. }
  36081. // Copy back to layout
  36082. vec2.copy(linePoints[0], pts[0]);
  36083. vec2.copy(linePoints[1], pts[2]);
  36084. vec2.copy(linePoints[2], pts[1]);
  36085. }
  36086. // Line
  36087. else {
  36088. vec2.copy(pts2[0], originalPoints[0]);
  36089. vec2.copy(pts2[1], originalPoints[1]);
  36090. vec2.sub(v, pts2[1], pts2[0]);
  36091. vec2.normalize(v, v);
  36092. if (fromSymbol && fromSymbol != 'none') {
  36093. var symbolSize = getSymbolSize(edge.node1);
  36094. vec2.scaleAndAdd(pts2[0], pts2[0], v, symbolSize * scale);
  36095. }
  36096. if (toSymbol && toSymbol != 'none') {
  36097. var symbolSize = getSymbolSize(edge.node2);
  36098. vec2.scaleAndAdd(pts2[1], pts2[1], v, -symbolSize * scale);
  36099. }
  36100. vec2.copy(linePoints[0], pts2[0]);
  36101. vec2.copy(linePoints[1], pts2[1]);
  36102. }
  36103. });
  36104. };
  36105. /***/ },
  36106. /* 213 */
  36107. /***/ function(module, exports, __webpack_require__) {
  36108. var echarts = __webpack_require__(1);
  36109. var roamHelper = __webpack_require__(187);
  36110. var actionInfo = {
  36111. type: 'graphRoam',
  36112. event: 'graphRoam',
  36113. update: 'none'
  36114. };
  36115. /**
  36116. * @payload
  36117. * @property {string} name Series name
  36118. * @property {number} [dx]
  36119. * @property {number} [dy]
  36120. * @property {number} [zoom]
  36121. * @property {number} [originX]
  36122. * @property {number} [originY]
  36123. */
  36124. echarts.registerAction(actionInfo, function (payload, ecModel) {
  36125. ecModel.eachComponent({mainType: 'series', query: payload}, function (seriesModel) {
  36126. var coordSys = seriesModel.coordinateSystem;
  36127. var res = roamHelper.updateCenterAndZoom(coordSys, payload);
  36128. seriesModel.setCenter
  36129. && seriesModel.setCenter(res.center);
  36130. seriesModel.setZoom
  36131. && seriesModel.setZoom(res.zoom);
  36132. });
  36133. });
  36134. /**
  36135. * @payload
  36136. * @property {number} [seriesIndex]
  36137. * @property {string} [seriesId]
  36138. * @property {string} [seriesName]
  36139. * @property {number} [dataIndex]
  36140. */
  36141. echarts.registerAction({
  36142. type: 'focusNodeAdjacency',
  36143. event: 'focusNodeAdjacency',
  36144. update: 'series.graph:focusNodeAdjacency'
  36145. }, function () {});
  36146. /**
  36147. * @payload
  36148. * @property {number} [seriesIndex]
  36149. * @property {string} [seriesId]
  36150. * @property {string} [seriesName]
  36151. */
  36152. echarts.registerAction({
  36153. type: 'unfocusNodeAdjacency',
  36154. event: 'unfocusNodeAdjacency',
  36155. update: 'series.graph:unfocusNodeAdjacency'
  36156. }, function () {});
  36157. /***/ },
  36158. /* 214 */
  36159. /***/ function(module, exports) {
  36160. module.exports = function (ecModel) {
  36161. var legendModels = ecModel.findComponents({
  36162. mainType: 'legend'
  36163. });
  36164. if (!legendModels || !legendModels.length) {
  36165. return;
  36166. }
  36167. ecModel.eachSeriesByType('graph', function (graphSeries) {
  36168. var categoriesData = graphSeries.getCategoriesData();
  36169. var graph = graphSeries.getGraph();
  36170. var data = graph.data;
  36171. var categoryNames = categoriesData.mapArray(categoriesData.getName);
  36172. data.filterSelf(function (idx) {
  36173. var model = data.getItemModel(idx);
  36174. var category = model.getShallow('category');
  36175. if (category != null) {
  36176. if (typeof category === 'number') {
  36177. category = categoryNames[category];
  36178. }
  36179. // If in any legend component the status is not selected.
  36180. for (var i = 0; i < legendModels.length; i++) {
  36181. if (!legendModels[i].isSelected(category)) {
  36182. return false;
  36183. }
  36184. }
  36185. }
  36186. return true;
  36187. });
  36188. }, this);
  36189. };
  36190. /***/ },
  36191. /* 215 */
  36192. /***/ function(module, exports) {
  36193. module.exports = function (ecModel) {
  36194. var paletteScope = {};
  36195. ecModel.eachSeriesByType('graph', function (seriesModel) {
  36196. var categoriesData = seriesModel.getCategoriesData();
  36197. var data = seriesModel.getData();
  36198. var categoryNameIdxMap = {};
  36199. categoriesData.each(function (idx) {
  36200. var name = categoriesData.getName(idx);
  36201. // Add prefix to avoid conflict with Object.prototype.
  36202. categoryNameIdxMap['ec-' + name] = idx;
  36203. var itemModel = categoriesData.getItemModel(idx);
  36204. var color = itemModel.get('itemStyle.normal.color')
  36205. || seriesModel.getColorFromPalette(name, paletteScope);
  36206. categoriesData.setItemVisual(idx, 'color', color);
  36207. });
  36208. // Assign category color to visual
  36209. if (categoriesData.count()) {
  36210. data.each(function (idx) {
  36211. var model = data.getItemModel(idx);
  36212. var category = model.getShallow('category');
  36213. if (category != null) {
  36214. if (typeof category === 'string') {
  36215. category = categoryNameIdxMap['ec-' + category];
  36216. }
  36217. if (!data.getItemVisual(idx, 'color', true)) {
  36218. data.setItemVisual(
  36219. idx, 'color',
  36220. categoriesData.getItemVisual(category, 'color')
  36221. );
  36222. }
  36223. }
  36224. });
  36225. }
  36226. });
  36227. };
  36228. /***/ },
  36229. /* 216 */
  36230. /***/ function(module, exports) {
  36231. function normalize(a) {
  36232. if (!(a instanceof Array)) {
  36233. a = [a, a];
  36234. }
  36235. return a;
  36236. }
  36237. module.exports = function (ecModel) {
  36238. ecModel.eachSeriesByType('graph', function (seriesModel) {
  36239. var graph = seriesModel.getGraph();
  36240. var edgeData = seriesModel.getEdgeData();
  36241. var symbolType = normalize(seriesModel.get('edgeSymbol'));
  36242. var symbolSize = normalize(seriesModel.get('edgeSymbolSize'));
  36243. var colorQuery = 'lineStyle.normal.color'.split('.');
  36244. var opacityQuery = 'lineStyle.normal.opacity'.split('.');
  36245. edgeData.setVisual('fromSymbol', symbolType && symbolType[0]);
  36246. edgeData.setVisual('toSymbol', symbolType && symbolType[1]);
  36247. edgeData.setVisual('fromSymbolSize', symbolSize && symbolSize[0]);
  36248. edgeData.setVisual('toSymbolSize', symbolSize && symbolSize[1]);
  36249. edgeData.setVisual('color', seriesModel.get(colorQuery));
  36250. edgeData.setVisual('opacity', seriesModel.get(opacityQuery));
  36251. edgeData.each(function (idx) {
  36252. var itemModel = edgeData.getItemModel(idx);
  36253. var edge = graph.getEdgeByIndex(idx);
  36254. var symbolType = normalize(itemModel.getShallow('symbol', true));
  36255. var symbolSize = normalize(itemModel.getShallow('symbolSize', true));
  36256. // Edge visual must after node visual
  36257. var color = itemModel.get(colorQuery);
  36258. var opacity = itemModel.get(opacityQuery);
  36259. switch (color) {
  36260. case 'source':
  36261. color = edge.node1.getVisual('color');
  36262. break;
  36263. case 'target':
  36264. color = edge.node2.getVisual('color');
  36265. break;
  36266. }
  36267. symbolType[0] && edge.setVisual('fromSymbol', symbolType[0]);
  36268. symbolType[1] && edge.setVisual('toSymbol', symbolType[1]);
  36269. symbolSize[0] && edge.setVisual('fromSymbolSize', symbolSize[0]);
  36270. symbolSize[1] && edge.setVisual('toSymbolSize', symbolSize[1]);
  36271. edge.setVisual('color', color);
  36272. edge.setVisual('opacity', opacity);
  36273. });
  36274. });
  36275. };
  36276. /***/ },
  36277. /* 217 */
  36278. /***/ function(module, exports, __webpack_require__) {
  36279. var simpleLayoutHelper = __webpack_require__(218);
  36280. var simpleLayoutEdge = __webpack_require__(219);
  36281. module.exports = function (ecModel, api) {
  36282. ecModel.eachSeriesByType('graph', function (seriesModel) {
  36283. var layout = seriesModel.get('layout');
  36284. var coordSys = seriesModel.coordinateSystem;
  36285. if (coordSys && coordSys.type !== 'view') {
  36286. var data = seriesModel.getData();
  36287. var dimensions = coordSys.dimensions;
  36288. data.each(dimensions, function () {
  36289. var hasValue;
  36290. var args = arguments;
  36291. var value = [];
  36292. for (var i = 0; i < dimensions.length; i++) {
  36293. if (!isNaN(args[i])) {
  36294. hasValue = true;
  36295. }
  36296. value.push(args[i]);
  36297. }
  36298. var idx = args[args.length - 1];
  36299. if (hasValue) {
  36300. data.setItemLayout(idx, coordSys.dataToPoint(value));
  36301. }
  36302. else {
  36303. // Also {Array.<number>}, not undefined to avoid if...else... statement
  36304. data.setItemLayout(idx, [NaN, NaN]);
  36305. }
  36306. });
  36307. simpleLayoutEdge(data.graph);
  36308. }
  36309. else if (!layout || layout === 'none') {
  36310. simpleLayoutHelper(seriesModel);
  36311. }
  36312. });
  36313. };
  36314. /***/ },
  36315. /* 218 */
  36316. /***/ function(module, exports, __webpack_require__) {
  36317. var simpleLayoutEdge = __webpack_require__(219);
  36318. module.exports = function (seriesModel) {
  36319. var coordSys = seriesModel.coordinateSystem;
  36320. if (coordSys && coordSys.type !== 'view') {
  36321. return;
  36322. }
  36323. var graph = seriesModel.getGraph();
  36324. graph.eachNode(function (node) {
  36325. var model = node.getModel();
  36326. node.setLayout([+model.get('x'), +model.get('y')]);
  36327. });
  36328. simpleLayoutEdge(graph);
  36329. };
  36330. /***/ },
  36331. /* 219 */
  36332. /***/ function(module, exports, __webpack_require__) {
  36333. var vec2 = __webpack_require__(10);
  36334. module.exports = function (graph) {
  36335. graph.eachEdge(function (edge) {
  36336. var curveness = edge.getModel().get('lineStyle.normal.curveness') || 0;
  36337. var p1 = vec2.clone(edge.node1.getLayout());
  36338. var p2 = vec2.clone(edge.node2.getLayout());
  36339. var points = [p1, p2];
  36340. if (+curveness) {
  36341. points.push([
  36342. (p1[0] + p2[0]) / 2 - (p1[1] - p2[1]) * curveness,
  36343. (p1[1] + p2[1]) / 2 - (p2[0] - p1[0]) * curveness
  36344. ]);
  36345. }
  36346. edge.setLayout(points);
  36347. });
  36348. };
  36349. /***/ },
  36350. /* 220 */
  36351. /***/ function(module, exports, __webpack_require__) {
  36352. var circularLayoutHelper = __webpack_require__(221);
  36353. module.exports = function (ecModel) {
  36354. ecModel.eachSeriesByType('graph', function (seriesModel) {
  36355. if (seriesModel.get('layout') === 'circular') {
  36356. circularLayoutHelper(seriesModel);
  36357. }
  36358. });
  36359. };
  36360. /***/ },
  36361. /* 221 */
  36362. /***/ function(module, exports, __webpack_require__) {
  36363. var vec2 = __webpack_require__(10);
  36364. module.exports = function (seriesModel) {
  36365. var coordSys = seriesModel.coordinateSystem;
  36366. if (coordSys && coordSys.type !== 'view') {
  36367. return;
  36368. }
  36369. var rect = coordSys.getBoundingRect();
  36370. var nodeData = seriesModel.getData();
  36371. var graph = nodeData.graph;
  36372. var angle = 0;
  36373. var sum = nodeData.getSum('value');
  36374. var unitAngle = Math.PI * 2 / (sum || nodeData.count());
  36375. var cx = rect.width / 2 + rect.x;
  36376. var cy = rect.height / 2 + rect.y;
  36377. var r = Math.min(rect.width, rect.height) / 2;
  36378. graph.eachNode(function (node) {
  36379. var value = node.getValue('value');
  36380. angle += unitAngle * (sum ? value : 1) / 2;
  36381. node.setLayout([
  36382. r * Math.cos(angle) + cx,
  36383. r * Math.sin(angle) + cy
  36384. ]);
  36385. angle += unitAngle * (sum ? value : 1) / 2;
  36386. });
  36387. nodeData.setLayout({
  36388. cx: cx,
  36389. cy: cy
  36390. });
  36391. graph.eachEdge(function (edge) {
  36392. var curveness = edge.getModel().get('lineStyle.normal.curveness') || 0;
  36393. var p1 = vec2.clone(edge.node1.getLayout());
  36394. var p2 = vec2.clone(edge.node2.getLayout());
  36395. var cp1;
  36396. var x12 = (p1[0] + p2[0]) / 2;
  36397. var y12 = (p1[1] + p2[1]) / 2;
  36398. if (+curveness) {
  36399. curveness *= 3;
  36400. cp1 = [
  36401. cx * curveness + x12 * (1 - curveness),
  36402. cy * curveness + y12 * (1 - curveness)
  36403. ];
  36404. }
  36405. edge.setLayout([p1, p2, cp1]);
  36406. });
  36407. };
  36408. /***/ },
  36409. /* 222 */
  36410. /***/ function(module, exports, __webpack_require__) {
  36411. var forceHelper = __webpack_require__(223);
  36412. var numberUtil = __webpack_require__(7);
  36413. var simpleLayoutHelper = __webpack_require__(218);
  36414. var circularLayoutHelper = __webpack_require__(221);
  36415. var vec2 = __webpack_require__(10);
  36416. var zrUtil = __webpack_require__(4);
  36417. module.exports = function (ecModel) {
  36418. ecModel.eachSeriesByType('graph', function (graphSeries) {
  36419. var coordSys = graphSeries.coordinateSystem;
  36420. if (coordSys && coordSys.type !== 'view') {
  36421. return;
  36422. }
  36423. if (graphSeries.get('layout') === 'force') {
  36424. var preservedPoints = graphSeries.preservedPoints || {};
  36425. var graph = graphSeries.getGraph();
  36426. var nodeData = graph.data;
  36427. var edgeData = graph.edgeData;
  36428. var forceModel = graphSeries.getModel('force');
  36429. var initLayout = forceModel.get('initLayout');
  36430. if (graphSeries.preservedPoints) {
  36431. nodeData.each(function (idx) {
  36432. var id = nodeData.getId(idx);
  36433. nodeData.setItemLayout(idx, preservedPoints[id] || [NaN, NaN]);
  36434. });
  36435. }
  36436. else if (!initLayout || initLayout === 'none') {
  36437. simpleLayoutHelper(graphSeries);
  36438. }
  36439. else if (initLayout === 'circular') {
  36440. circularLayoutHelper(graphSeries);
  36441. }
  36442. var nodeDataExtent = nodeData.getDataExtent('value');
  36443. var edgeDataExtent = edgeData.getDataExtent('value');
  36444. // var edgeDataExtent = edgeData.getDataExtent('value');
  36445. var repulsion = forceModel.get('repulsion');
  36446. var edgeLength = forceModel.get('edgeLength');
  36447. if (!zrUtil.isArray(repulsion)) {
  36448. repulsion = [repulsion, repulsion];
  36449. }
  36450. if (!zrUtil.isArray(edgeLength)) {
  36451. edgeLength = [edgeLength, edgeLength];
  36452. }
  36453. // Larger value has smaller length
  36454. edgeLength = [edgeLength[1], edgeLength[0]];
  36455. var nodes = nodeData.mapArray('value', function (value, idx) {
  36456. var point = nodeData.getItemLayout(idx);
  36457. // var w = numberUtil.linearMap(value, nodeDataExtent, [0, 50]);
  36458. var rep = numberUtil.linearMap(value, nodeDataExtent, repulsion);
  36459. if (isNaN(rep)) {
  36460. rep = (repulsion[0] + repulsion[1]) / 2;
  36461. }
  36462. return {
  36463. w: rep,
  36464. rep: rep,
  36465. p: (!point || isNaN(point[0]) || isNaN(point[1])) ? null : point
  36466. };
  36467. });
  36468. var edges = edgeData.mapArray('value', function (value, idx) {
  36469. var edge = graph.getEdgeByIndex(idx);
  36470. var d = numberUtil.linearMap(value, edgeDataExtent, edgeLength);
  36471. if (isNaN(d)) {
  36472. d = (edgeLength[0] + edgeLength[1]) / 2;
  36473. }
  36474. return {
  36475. n1: nodes[edge.node1.dataIndex],
  36476. n2: nodes[edge.node2.dataIndex],
  36477. d: d,
  36478. curveness: edge.getModel().get('lineStyle.normal.curveness') || 0
  36479. };
  36480. });
  36481. var coordSys = graphSeries.coordinateSystem;
  36482. var rect = coordSys.getBoundingRect();
  36483. var forceInstance = forceHelper(nodes, edges, {
  36484. rect: rect,
  36485. gravity: forceModel.get('gravity')
  36486. });
  36487. var oldStep = forceInstance.step;
  36488. forceInstance.step = function (cb) {
  36489. for (var i = 0, l = nodes.length; i < l; i++) {
  36490. if (nodes[i].fixed) {
  36491. // Write back to layout instance
  36492. vec2.copy(nodes[i].p, graph.getNodeByIndex(i).getLayout());
  36493. }
  36494. }
  36495. oldStep(function (nodes, edges, stopped) {
  36496. for (var i = 0, l = nodes.length; i < l; i++) {
  36497. if (!nodes[i].fixed) {
  36498. graph.getNodeByIndex(i).setLayout(nodes[i].p);
  36499. }
  36500. preservedPoints[nodeData.getId(i)] = nodes[i].p;
  36501. }
  36502. for (var i = 0, l = edges.length; i < l; i++) {
  36503. var e = edges[i];
  36504. var edge = graph.getEdgeByIndex(i);
  36505. var p1 = e.n1.p;
  36506. var p2 = e.n2.p;
  36507. var points = edge.getLayout();
  36508. points = points ? points.slice() : [];
  36509. points[0] = points[0] || [];
  36510. points[1] = points[1] || [];
  36511. vec2.copy(points[0], p1);
  36512. vec2.copy(points[1], p2);
  36513. if (+e.curveness) {
  36514. points[2] = [
  36515. (p1[0] + p2[0]) / 2 - (p1[1] - p2[1]) * e.curveness,
  36516. (p1[1] + p2[1]) / 2 - (p2[0] - p1[0]) * e.curveness
  36517. ];
  36518. }
  36519. edge.setLayout(points);
  36520. }
  36521. // Update layout
  36522. cb && cb(stopped);
  36523. });
  36524. };
  36525. graphSeries.forceLayout = forceInstance;
  36526. graphSeries.preservedPoints = preservedPoints;
  36527. // Step to get the layout
  36528. forceInstance.step();
  36529. }
  36530. else {
  36531. // Remove prev injected forceLayout instance
  36532. graphSeries.forceLayout = null;
  36533. }
  36534. });
  36535. };
  36536. /***/ },
  36537. /* 223 */
  36538. /***/ function(module, exports, __webpack_require__) {
  36539. var vec2 = __webpack_require__(10);
  36540. var scaleAndAdd = vec2.scaleAndAdd;
  36541. // function adjacentNode(n, e) {
  36542. // return e.n1 === n ? e.n2 : e.n1;
  36543. // }
  36544. module.exports = function (nodes, edges, opts) {
  36545. var rect = opts.rect;
  36546. var width = rect.width;
  36547. var height = rect.height;
  36548. var center = [rect.x + width / 2, rect.y + height / 2];
  36549. // var scale = opts.scale || 1;
  36550. var gravity = opts.gravity == null ? 0.1 : opts.gravity;
  36551. // for (var i = 0; i < edges.length; i++) {
  36552. // var e = edges[i];
  36553. // var n1 = e.n1;
  36554. // var n2 = e.n2;
  36555. // n1.edges = n1.edges || [];
  36556. // n2.edges = n2.edges || [];
  36557. // n1.edges.push(e);
  36558. // n2.edges.push(e);
  36559. // }
  36560. // Init position
  36561. for (var i = 0; i < nodes.length; i++) {
  36562. var n = nodes[i];
  36563. if (!n.p) {
  36564. // Use the position from first adjecent node with defined position
  36565. // Or use a random position
  36566. // From d3
  36567. // if (n.edges) {
  36568. // var j = -1;
  36569. // while (++j < n.edges.length) {
  36570. // var e = n.edges[j];
  36571. // var other = adjacentNode(n, e);
  36572. // if (other.p) {
  36573. // n.p = vec2.clone(other.p);
  36574. // break;
  36575. // }
  36576. // }
  36577. // }
  36578. // if (!n.p) {
  36579. n.p = vec2.create(
  36580. width * (Math.random() - 0.5) + center[0],
  36581. height * (Math.random() - 0.5) + center[1]
  36582. );
  36583. // }
  36584. }
  36585. n.pp = vec2.clone(n.p);
  36586. n.edges = null;
  36587. }
  36588. // Formula in 'Graph Drawing by Force-directed Placement'
  36589. // var k = scale * Math.sqrt(width * height / nodes.length);
  36590. // var k2 = k * k;
  36591. var friction = 0.6;
  36592. return {
  36593. warmUp: function () {
  36594. friction = 0.5;
  36595. },
  36596. setFixed: function (idx) {
  36597. nodes[idx].fixed = true;
  36598. },
  36599. setUnfixed: function (idx) {
  36600. nodes[idx].fixed = false;
  36601. },
  36602. step: function (cb) {
  36603. var v12 = [];
  36604. var nLen = nodes.length;
  36605. for (var i = 0; i < edges.length; i++) {
  36606. var e = edges[i];
  36607. var n1 = e.n1;
  36608. var n2 = e.n2;
  36609. vec2.sub(v12, n2.p, n1.p);
  36610. var d = vec2.len(v12) - e.d;
  36611. var w = n2.w / (n1.w + n2.w);
  36612. vec2.normalize(v12, v12);
  36613. !n1.fixed && scaleAndAdd(n1.p, n1.p, v12, w * d * friction);
  36614. !n2.fixed && scaleAndAdd(n2.p, n2.p, v12, -(1 - w) * d * friction);
  36615. }
  36616. // Gravity
  36617. for (var i = 0; i < nLen; i++) {
  36618. var n = nodes[i];
  36619. if (!n.fixed) {
  36620. vec2.sub(v12, center, n.p);
  36621. // var d = vec2.len(v12);
  36622. // vec2.scale(v12, v12, 1 / d);
  36623. // var gravityFactor = gravity;
  36624. vec2.scaleAndAdd(n.p, n.p, v12, gravity * friction);
  36625. }
  36626. }
  36627. // Repulsive
  36628. // PENDING
  36629. for (var i = 0; i < nLen; i++) {
  36630. var n1 = nodes[i];
  36631. for (var j = i + 1; j < nLen; j++) {
  36632. var n2 = nodes[j];
  36633. vec2.sub(v12, n2.p, n1.p);
  36634. var d = vec2.len(v12);
  36635. if (d === 0) {
  36636. // Random repulse
  36637. vec2.set(v12, Math.random() - 0.5, Math.random() - 0.5);
  36638. d = 1;
  36639. }
  36640. var repFact = (n1.rep + n2.rep) / d / d;
  36641. !n1.fixed && scaleAndAdd(n1.pp, n1.pp, v12, repFact);
  36642. !n2.fixed && scaleAndAdd(n2.pp, n2.pp, v12, -repFact);
  36643. }
  36644. }
  36645. var v = [];
  36646. for (var i = 0; i < nLen; i++) {
  36647. var n = nodes[i];
  36648. if (!n.fixed) {
  36649. vec2.sub(v, n.p, n.pp);
  36650. vec2.scaleAndAdd(n.p, n.p, v, friction);
  36651. vec2.copy(n.pp, n.p);
  36652. }
  36653. }
  36654. friction = friction * 0.992;
  36655. cb && cb(nodes, edges, friction < 0.01);
  36656. }
  36657. };
  36658. };
  36659. /***/ },
  36660. /* 224 */
  36661. /***/ function(module, exports, __webpack_require__) {
  36662. // FIXME Where to create the simple view coordinate system
  36663. var View = __webpack_require__(176);
  36664. var layout = __webpack_require__(71);
  36665. var bbox = __webpack_require__(38);
  36666. function getViewRect(seriesModel, api, aspect) {
  36667. var option = seriesModel.getBoxLayoutParams();
  36668. option.aspect = aspect;
  36669. return layout.getLayoutRect(option, {
  36670. width: api.getWidth(),
  36671. height: api.getHeight()
  36672. });
  36673. }
  36674. module.exports = function (ecModel, api) {
  36675. var viewList = [];
  36676. ecModel.eachSeriesByType('graph', function (seriesModel) {
  36677. var coordSysType = seriesModel.get('coordinateSystem');
  36678. if (!coordSysType || coordSysType === 'view') {
  36679. var data = seriesModel.getData();
  36680. var positions = data.mapArray(function (idx) {
  36681. var itemModel = data.getItemModel(idx);
  36682. return [+itemModel.get('x'), +itemModel.get('y')];
  36683. });
  36684. var min = [];
  36685. var max = [];
  36686. bbox.fromPoints(positions, min, max);
  36687. // If width or height is 0
  36688. if (max[0] - min[0] === 0) {
  36689. max[0] += 1;
  36690. min[0] -= 1;
  36691. }
  36692. if (max[1] - min[1] === 0) {
  36693. max[1] += 1;
  36694. min[1] -= 1;
  36695. }
  36696. var aspect = (max[0] - min[0]) / (max[1] - min[1]);
  36697. // FIXME If get view rect after data processed?
  36698. var viewRect = getViewRect(seriesModel, api, aspect);
  36699. // Position may be NaN, use view rect instead
  36700. if (isNaN(aspect)) {
  36701. min = [viewRect.x, viewRect.y];
  36702. max = [viewRect.x + viewRect.width, viewRect.y + viewRect.height];
  36703. }
  36704. var bbWidth = max[0] - min[0];
  36705. var bbHeight = max[1] - min[1];
  36706. var viewWidth = viewRect.width;
  36707. var viewHeight = viewRect.height;
  36708. var viewCoordSys = seriesModel.coordinateSystem = new View();
  36709. viewCoordSys.zoomLimit = seriesModel.get('scaleLimit');
  36710. viewCoordSys.setBoundingRect(
  36711. min[0], min[1], bbWidth, bbHeight
  36712. );
  36713. viewCoordSys.setViewRect(
  36714. viewRect.x, viewRect.y, viewWidth, viewHeight
  36715. );
  36716. // Update roam info
  36717. viewCoordSys.setCenter(seriesModel.get('center'));
  36718. viewCoordSys.setZoom(seriesModel.get('zoom'));
  36719. viewList.push(viewCoordSys);
  36720. }
  36721. });
  36722. return viewList;
  36723. };
  36724. /***/ },
  36725. /* 225 */
  36726. /***/ function(module, exports, __webpack_require__) {
  36727. __webpack_require__(226);
  36728. __webpack_require__(227);
  36729. /***/ },
  36730. /* 226 */
  36731. /***/ function(module, exports, __webpack_require__) {
  36732. var List = __webpack_require__(98);
  36733. var SeriesModel = __webpack_require__(78);
  36734. var zrUtil = __webpack_require__(4);
  36735. var GaugeSeries = SeriesModel.extend({
  36736. type: 'series.gauge',
  36737. getInitialData: function (option, ecModel) {
  36738. var list = new List(['value'], this);
  36739. var dataOpt = option.data || [];
  36740. if (!zrUtil.isArray(dataOpt)) {
  36741. dataOpt = [dataOpt];
  36742. }
  36743. // Only use the first data item
  36744. list.initData(dataOpt);
  36745. return list;
  36746. },
  36747. defaultOption: {
  36748. zlevel: 0,
  36749. z: 2,
  36750. // 默认全局居中
  36751. center: ['50%', '50%'],
  36752. legendHoverLink: true,
  36753. radius: '75%',
  36754. startAngle: 225,
  36755. endAngle: -45,
  36756. clockwise: true,
  36757. // 最小值
  36758. min: 0,
  36759. // 最大值
  36760. max: 100,
  36761. // 分割段数,默认为10
  36762. splitNumber: 10,
  36763. // 坐标轴线
  36764. axisLine: {
  36765. // 默认显示,属性show控制显示与否
  36766. show: true,
  36767. lineStyle: { // 属性lineStyle控制线条样式
  36768. color: [[0.2, '#91c7ae'], [0.8, '#63869e'], [1, '#c23531']],
  36769. width: 30
  36770. }
  36771. },
  36772. // 分隔线
  36773. splitLine: {
  36774. // 默认显示,属性show控制显示与否
  36775. show: true,
  36776. // 属性length控制线长
  36777. length: 30,
  36778. // 属性lineStyle(详见lineStyle)控制线条样式
  36779. lineStyle: {
  36780. color: '#eee',
  36781. width: 2,
  36782. type: 'solid'
  36783. }
  36784. },
  36785. // 坐标轴小标记
  36786. axisTick: {
  36787. // 属性show控制显示与否,默认不显示
  36788. show: true,
  36789. // 每份split细分多少段
  36790. splitNumber: 5,
  36791. // 属性length控制线长
  36792. length: 8,
  36793. // 属性lineStyle控制线条样式
  36794. lineStyle: {
  36795. color: '#eee',
  36796. width: 1,
  36797. type: 'solid'
  36798. }
  36799. },
  36800. axisLabel: {
  36801. show: true,
  36802. distance: 5,
  36803. // formatter: null,
  36804. textStyle: { // 其余属性默认使用全局文本样式,详见TEXTSTYLE
  36805. color: 'auto'
  36806. }
  36807. },
  36808. pointer: {
  36809. show: true,
  36810. length: '80%',
  36811. width: 8
  36812. },
  36813. itemStyle: {
  36814. normal: {
  36815. color: 'auto'
  36816. }
  36817. },
  36818. title: {
  36819. show: true,
  36820. // x, y,单位px
  36821. offsetCenter: [0, '-40%'],
  36822. // 其余属性默认使用全局文本样式,详见TEXTSTYLE
  36823. textStyle: {
  36824. color: '#333',
  36825. fontSize: 15
  36826. }
  36827. },
  36828. detail: {
  36829. show: true,
  36830. backgroundColor: 'rgba(0,0,0,0)',
  36831. borderWidth: 0,
  36832. borderColor: '#ccc',
  36833. width: 100,
  36834. height: 40,
  36835. // x, y,单位px
  36836. offsetCenter: [0, '40%'],
  36837. // formatter: null,
  36838. // 其余属性默认使用全局文本样式,详见TEXTSTYLE
  36839. textStyle: {
  36840. color: 'auto',
  36841. fontSize: 30
  36842. }
  36843. }
  36844. }
  36845. });
  36846. module.exports = GaugeSeries;
  36847. /***/ },
  36848. /* 227 */
  36849. /***/ function(module, exports, __webpack_require__) {
  36850. var PointerPath = __webpack_require__(228);
  36851. var graphic = __webpack_require__(18);
  36852. var numberUtil = __webpack_require__(7);
  36853. var parsePercent = numberUtil.parsePercent;
  36854. function parsePosition(seriesModel, api) {
  36855. var center = seriesModel.get('center');
  36856. var width = api.getWidth();
  36857. var height = api.getHeight();
  36858. var size = Math.min(width, height);
  36859. var cx = parsePercent(center[0], api.getWidth());
  36860. var cy = parsePercent(center[1], api.getHeight());
  36861. var r = parsePercent(seriesModel.get('radius'), size / 2);
  36862. return {
  36863. cx: cx,
  36864. cy: cy,
  36865. r: r
  36866. };
  36867. }
  36868. function formatLabel(label, labelFormatter) {
  36869. if (labelFormatter) {
  36870. if (typeof labelFormatter === 'string') {
  36871. label = labelFormatter.replace('{value}', label != null ? label : '');
  36872. }
  36873. else if (typeof labelFormatter === 'function') {
  36874. label = labelFormatter(label);
  36875. }
  36876. }
  36877. return label;
  36878. }
  36879. var PI2 = Math.PI * 2;
  36880. var GaugeView = __webpack_require__(80).extend({
  36881. type: 'gauge',
  36882. render: function (seriesModel, ecModel, api) {
  36883. this.group.removeAll();
  36884. var colorList = seriesModel.get('axisLine.lineStyle.color');
  36885. var posInfo = parsePosition(seriesModel, api);
  36886. this._renderMain(
  36887. seriesModel, ecModel, api, colorList, posInfo
  36888. );
  36889. },
  36890. dispose: function () {},
  36891. _renderMain: function (seriesModel, ecModel, api, colorList, posInfo) {
  36892. var group = this.group;
  36893. var axisLineModel = seriesModel.getModel('axisLine');
  36894. var lineStyleModel = axisLineModel.getModel('lineStyle');
  36895. var clockwise = seriesModel.get('clockwise');
  36896. var startAngle = -seriesModel.get('startAngle') / 180 * Math.PI;
  36897. var endAngle = -seriesModel.get('endAngle') / 180 * Math.PI;
  36898. var angleRangeSpan = (endAngle - startAngle) % PI2;
  36899. var prevEndAngle = startAngle;
  36900. var axisLineWidth = lineStyleModel.get('width');
  36901. for (var i = 0; i < colorList.length; i++) {
  36902. // Clamp
  36903. var percent = Math.min(Math.max(colorList[i][0], 0), 1);
  36904. var endAngle = startAngle + angleRangeSpan * percent;
  36905. var sector = new graphic.Sector({
  36906. shape: {
  36907. startAngle: prevEndAngle,
  36908. endAngle: endAngle,
  36909. cx: posInfo.cx,
  36910. cy: posInfo.cy,
  36911. clockwise: clockwise,
  36912. r0: posInfo.r - axisLineWidth,
  36913. r: posInfo.r
  36914. },
  36915. silent: true
  36916. });
  36917. sector.setStyle({
  36918. fill: colorList[i][1]
  36919. });
  36920. sector.setStyle(lineStyleModel.getLineStyle(
  36921. // Because we use sector to simulate arc
  36922. // so the properties for stroking are useless
  36923. ['color', 'borderWidth', 'borderColor']
  36924. ));
  36925. group.add(sector);
  36926. prevEndAngle = endAngle;
  36927. }
  36928. var getColor = function (percent) {
  36929. // Less than 0
  36930. if (percent <= 0) {
  36931. return colorList[0][1];
  36932. }
  36933. for (var i = 0; i < colorList.length; i++) {
  36934. if (colorList[i][0] >= percent
  36935. && (i === 0 ? 0 : colorList[i - 1][0]) < percent
  36936. ) {
  36937. return colorList[i][1];
  36938. }
  36939. }
  36940. // More than 1
  36941. return colorList[i - 1][1];
  36942. };
  36943. if (!clockwise) {
  36944. var tmp = startAngle;
  36945. startAngle = endAngle;
  36946. endAngle = tmp;
  36947. }
  36948. this._renderTicks(
  36949. seriesModel, ecModel, api, getColor, posInfo,
  36950. startAngle, endAngle, clockwise
  36951. );
  36952. this._renderPointer(
  36953. seriesModel, ecModel, api, getColor, posInfo,
  36954. startAngle, endAngle, clockwise
  36955. );
  36956. this._renderTitle(
  36957. seriesModel, ecModel, api, getColor, posInfo
  36958. );
  36959. this._renderDetail(
  36960. seriesModel, ecModel, api, getColor, posInfo
  36961. );
  36962. },
  36963. _renderTicks: function (
  36964. seriesModel, ecModel, api, getColor, posInfo,
  36965. startAngle, endAngle, clockwise
  36966. ) {
  36967. var group = this.group;
  36968. var cx = posInfo.cx;
  36969. var cy = posInfo.cy;
  36970. var r = posInfo.r;
  36971. var minVal = +seriesModel.get('min');
  36972. var maxVal = +seriesModel.get('max');
  36973. var splitLineModel = seriesModel.getModel('splitLine');
  36974. var tickModel = seriesModel.getModel('axisTick');
  36975. var labelModel = seriesModel.getModel('axisLabel');
  36976. var splitNumber = seriesModel.get('splitNumber');
  36977. var subSplitNumber = tickModel.get('splitNumber');
  36978. var splitLineLen = parsePercent(
  36979. splitLineModel.get('length'), r
  36980. );
  36981. var tickLen = parsePercent(
  36982. tickModel.get('length'), r
  36983. );
  36984. var angle = startAngle;
  36985. var step = (endAngle - startAngle) / splitNumber;
  36986. var subStep = step / subSplitNumber;
  36987. var splitLineStyle = splitLineModel.getModel('lineStyle').getLineStyle();
  36988. var tickLineStyle = tickModel.getModel('lineStyle').getLineStyle();
  36989. var textStyleModel = labelModel.getModel('textStyle');
  36990. for (var i = 0; i <= splitNumber; i++) {
  36991. var unitX = Math.cos(angle);
  36992. var unitY = Math.sin(angle);
  36993. // Split line
  36994. if (splitLineModel.get('show')) {
  36995. var splitLine = new graphic.Line({
  36996. shape: {
  36997. x1: unitX * r + cx,
  36998. y1: unitY * r + cy,
  36999. x2: unitX * (r - splitLineLen) + cx,
  37000. y2: unitY * (r - splitLineLen) + cy
  37001. },
  37002. style: splitLineStyle,
  37003. silent: true
  37004. });
  37005. if (splitLineStyle.stroke === 'auto') {
  37006. splitLine.setStyle({
  37007. stroke: getColor(i / splitNumber)
  37008. });
  37009. }
  37010. group.add(splitLine);
  37011. }
  37012. // Label
  37013. if (labelModel.get('show')) {
  37014. var label = formatLabel(
  37015. numberUtil.round(i / splitNumber * (maxVal - minVal) + minVal),
  37016. labelModel.get('formatter')
  37017. );
  37018. var distance = labelModel.get('distance');
  37019. var text = new graphic.Text({
  37020. style: {
  37021. text: label,
  37022. x: unitX * (r - splitLineLen - distance) + cx,
  37023. y: unitY * (r - splitLineLen - distance) + cy,
  37024. fill: textStyleModel.getTextColor(),
  37025. textFont: textStyleModel.getFont(),
  37026. textVerticalAlign: unitY < -0.4 ? 'top' : (unitY > 0.4 ? 'bottom' : 'middle'),
  37027. textAlign: unitX < -0.4 ? 'left' : (unitX > 0.4 ? 'right' : 'center')
  37028. },
  37029. silent: true
  37030. });
  37031. if (text.style.fill === 'auto') {
  37032. text.setStyle({
  37033. fill: getColor(i / splitNumber)
  37034. });
  37035. }
  37036. group.add(text);
  37037. }
  37038. // Axis tick
  37039. if (tickModel.get('show') && i !== splitNumber) {
  37040. for (var j = 0; j <= subSplitNumber; j++) {
  37041. var unitX = Math.cos(angle);
  37042. var unitY = Math.sin(angle);
  37043. var tickLine = new graphic.Line({
  37044. shape: {
  37045. x1: unitX * r + cx,
  37046. y1: unitY * r + cy,
  37047. x2: unitX * (r - tickLen) + cx,
  37048. y2: unitY * (r - tickLen) + cy
  37049. },
  37050. silent: true,
  37051. style: tickLineStyle
  37052. });
  37053. if (tickLineStyle.stroke === 'auto') {
  37054. tickLine.setStyle({
  37055. stroke: getColor((i + j / subSplitNumber) / splitNumber)
  37056. });
  37057. }
  37058. group.add(tickLine);
  37059. angle += subStep;
  37060. }
  37061. angle -= subStep;
  37062. }
  37063. else {
  37064. angle += step;
  37065. }
  37066. }
  37067. },
  37068. _renderPointer: function (
  37069. seriesModel, ecModel, api, getColor, posInfo,
  37070. startAngle, endAngle, clockwise
  37071. ) {
  37072. var group = this.group;
  37073. var oldData = this._data;
  37074. if (!seriesModel.get('pointer.show')) {
  37075. // Remove old element
  37076. oldData && oldData.eachItemGraphicEl(function (el) {
  37077. group.remove(el);
  37078. });
  37079. return;
  37080. }
  37081. var valueExtent = [+seriesModel.get('min'), +seriesModel.get('max')];
  37082. var angleExtent = [startAngle, endAngle];
  37083. var data = seriesModel.getData();
  37084. data.diff(oldData)
  37085. .add(function (idx) {
  37086. var pointer = new PointerPath({
  37087. shape: {
  37088. angle: startAngle
  37089. }
  37090. });
  37091. graphic.initProps(pointer, {
  37092. shape: {
  37093. angle: numberUtil.linearMap(data.get('value', idx), valueExtent, angleExtent, true)
  37094. }
  37095. }, seriesModel);
  37096. group.add(pointer);
  37097. data.setItemGraphicEl(idx, pointer);
  37098. })
  37099. .update(function (newIdx, oldIdx) {
  37100. var pointer = oldData.getItemGraphicEl(oldIdx);
  37101. graphic.updateProps(pointer, {
  37102. shape: {
  37103. angle: numberUtil.linearMap(data.get('value', newIdx), valueExtent, angleExtent, true)
  37104. }
  37105. }, seriesModel);
  37106. group.add(pointer);
  37107. data.setItemGraphicEl(newIdx, pointer);
  37108. })
  37109. .remove(function (idx) {
  37110. var pointer = oldData.getItemGraphicEl(idx);
  37111. group.remove(pointer);
  37112. })
  37113. .execute();
  37114. data.eachItemGraphicEl(function (pointer, idx) {
  37115. var itemModel = data.getItemModel(idx);
  37116. var pointerModel = itemModel.getModel('pointer');
  37117. pointer.setShape({
  37118. x: posInfo.cx,
  37119. y: posInfo.cy,
  37120. width: parsePercent(
  37121. pointerModel.get('width'), posInfo.r
  37122. ),
  37123. r: parsePercent(pointerModel.get('length'), posInfo.r)
  37124. });
  37125. pointer.useStyle(itemModel.getModel('itemStyle.normal').getItemStyle());
  37126. if (pointer.style.fill === 'auto') {
  37127. pointer.setStyle('fill', getColor(
  37128. numberUtil.linearMap(data.get('value', idx), valueExtent, [0, 1], true)
  37129. ));
  37130. }
  37131. graphic.setHoverStyle(
  37132. pointer, itemModel.getModel('itemStyle.emphasis').getItemStyle()
  37133. );
  37134. });
  37135. this._data = data;
  37136. },
  37137. _renderTitle: function (
  37138. seriesModel, ecModel, api, getColor, posInfo
  37139. ) {
  37140. var titleModel = seriesModel.getModel('title');
  37141. if (titleModel.get('show')) {
  37142. var textStyleModel = titleModel.getModel('textStyle');
  37143. var offsetCenter = titleModel.get('offsetCenter');
  37144. var x = posInfo.cx + parsePercent(offsetCenter[0], posInfo.r);
  37145. var y = posInfo.cy + parsePercent(offsetCenter[1], posInfo.r);
  37146. var text = new graphic.Text({
  37147. style: {
  37148. x: x,
  37149. y: y,
  37150. // FIXME First data name ?
  37151. text: seriesModel.getData().getName(0),
  37152. fill: textStyleModel.getTextColor(),
  37153. textFont: textStyleModel.getFont(),
  37154. textAlign: 'center',
  37155. textVerticalAlign: 'middle'
  37156. }
  37157. });
  37158. if (text.style.fill === 'auto') {
  37159. var minVal = +seriesModel.get('min');
  37160. var maxVal = +seriesModel.get('max');
  37161. var value = seriesModel.getData().get('value', 0);
  37162. text.setStyle('fill', getColor(
  37163. numberUtil.linearMap(value, [minVal, maxVal], [0, 1], true)
  37164. ));
  37165. }
  37166. this.group.add(text);
  37167. }
  37168. },
  37169. _renderDetail: function (
  37170. seriesModel, ecModel, api, getColor, posInfo
  37171. ) {
  37172. var detailModel = seriesModel.getModel('detail');
  37173. var minVal = +seriesModel.get('min');
  37174. var maxVal = +seriesModel.get('max');
  37175. if (detailModel.get('show')) {
  37176. var textStyleModel = detailModel.getModel('textStyle');
  37177. var offsetCenter = detailModel.get('offsetCenter');
  37178. var x = posInfo.cx + parsePercent(offsetCenter[0], posInfo.r);
  37179. var y = posInfo.cy + parsePercent(offsetCenter[1], posInfo.r);
  37180. var width = parsePercent(detailModel.get('width'), posInfo.r);
  37181. var height = parsePercent(detailModel.get('height'), posInfo.r);
  37182. var value = seriesModel.getData().get('value', 0);
  37183. var rect = new graphic.Rect({
  37184. shape: {
  37185. x: x - width / 2,
  37186. y: y - height / 2,
  37187. width: width,
  37188. height: height
  37189. },
  37190. style: {
  37191. text: formatLabel(
  37192. // FIXME First data name ?
  37193. value, detailModel.get('formatter')
  37194. ),
  37195. fill: detailModel.get('backgroundColor'),
  37196. textFill: textStyleModel.getTextColor(),
  37197. textFont: textStyleModel.getFont()
  37198. }
  37199. });
  37200. if (rect.style.textFill === 'auto') {
  37201. rect.setStyle('textFill', getColor(
  37202. numberUtil.linearMap(value, [minVal, maxVal], [0, 1], true)
  37203. ));
  37204. }
  37205. rect.setStyle(detailModel.getItemStyle(['color']));
  37206. this.group.add(rect);
  37207. }
  37208. }
  37209. });
  37210. module.exports = GaugeView;
  37211. /***/ },
  37212. /* 228 */
  37213. /***/ function(module, exports, __webpack_require__) {
  37214. module.exports = __webpack_require__(20).extend({
  37215. type: 'echartsGaugePointer',
  37216. shape: {
  37217. angle: 0,
  37218. width: 10,
  37219. r: 10,
  37220. x: 0,
  37221. y: 0
  37222. },
  37223. buildPath: function (ctx, shape) {
  37224. var mathCos = Math.cos;
  37225. var mathSin = Math.sin;
  37226. var r = shape.r;
  37227. var width = shape.width;
  37228. var angle = shape.angle;
  37229. var x = shape.x - mathCos(angle) * width * (width >= r / 3 ? 1 : 2);
  37230. var y = shape.y - mathSin(angle) * width * (width >= r / 3 ? 1 : 2);
  37231. angle = shape.angle - Math.PI / 2;
  37232. ctx.moveTo(x, y);
  37233. ctx.lineTo(
  37234. shape.x + mathCos(angle) * width,
  37235. shape.y + mathSin(angle) * width
  37236. );
  37237. ctx.lineTo(
  37238. shape.x + mathCos(shape.angle) * r,
  37239. shape.y + mathSin(shape.angle) * r
  37240. );
  37241. ctx.lineTo(
  37242. shape.x - mathCos(angle) * width,
  37243. shape.y - mathSin(angle) * width
  37244. );
  37245. ctx.lineTo(x, y);
  37246. return;
  37247. }
  37248. });
  37249. /***/ },
  37250. /* 229 */
  37251. /***/ function(module, exports, __webpack_require__) {
  37252. var zrUtil = __webpack_require__(4);
  37253. var echarts = __webpack_require__(1);
  37254. __webpack_require__(230);
  37255. __webpack_require__(231);
  37256. echarts.registerVisual(zrUtil.curry(__webpack_require__(151), 'funnel'));
  37257. echarts.registerLayout(__webpack_require__(232));
  37258. echarts.registerProcessor(zrUtil.curry(__webpack_require__(154), 'funnel'));
  37259. /***/ },
  37260. /* 230 */
  37261. /***/ function(module, exports, __webpack_require__) {
  37262. 'use strict';
  37263. var List = __webpack_require__(98);
  37264. var modelUtil = __webpack_require__(5);
  37265. var completeDimensions = __webpack_require__(110);
  37266. var FunnelSeries = __webpack_require__(1).extendSeriesModel({
  37267. type: 'series.funnel',
  37268. init: function (option) {
  37269. FunnelSeries.superApply(this, 'init', arguments);
  37270. // Enable legend selection for each data item
  37271. // Use a function instead of direct access because data reference may changed
  37272. this.legendDataProvider = function () {
  37273. return this.getRawData();
  37274. };
  37275. // Extend labelLine emphasis
  37276. this._defaultLabelLine(option);
  37277. },
  37278. getInitialData: function (option, ecModel) {
  37279. var dimensions = completeDimensions(['value'], option.data);
  37280. var list = new List(dimensions, this);
  37281. list.initData(option.data);
  37282. return list;
  37283. },
  37284. _defaultLabelLine: function (option) {
  37285. // Extend labelLine emphasis
  37286. modelUtil.defaultEmphasis(option.labelLine, ['show']);
  37287. var labelLineNormalOpt = option.labelLine.normal;
  37288. var labelLineEmphasisOpt = option.labelLine.emphasis;
  37289. // Not show label line if `label.normal.show = false`
  37290. labelLineNormalOpt.show = labelLineNormalOpt.show
  37291. && option.label.normal.show;
  37292. labelLineEmphasisOpt.show = labelLineEmphasisOpt.show
  37293. && option.label.emphasis.show;
  37294. },
  37295. // Overwrite
  37296. getDataParams: function (dataIndex) {
  37297. var data = this.getData();
  37298. var params = FunnelSeries.superCall(this, 'getDataParams', dataIndex);
  37299. var sum = data.getSum('value');
  37300. // Percent is 0 if sum is 0
  37301. params.percent = !sum ? 0 : +(data.get('value', dataIndex) / sum * 100).toFixed(2);
  37302. params.$vars.push('percent');
  37303. return params;
  37304. },
  37305. defaultOption: {
  37306. zlevel: 0, // 一级层叠
  37307. z: 2, // 二级层叠
  37308. legendHoverLink: true,
  37309. left: 80,
  37310. top: 60,
  37311. right: 80,
  37312. bottom: 60,
  37313. // width: {totalWidth} - left - right,
  37314. // height: {totalHeight} - top - bottom,
  37315. // 默认取数据最小最大值
  37316. // min: 0,
  37317. // max: 100,
  37318. minSize: '0%',
  37319. maxSize: '100%',
  37320. sort: 'descending', // 'ascending', 'descending'
  37321. gap: 0,
  37322. funnelAlign: 'center',
  37323. label: {
  37324. normal: {
  37325. show: true,
  37326. position: 'outer'
  37327. // formatter: 标签文本格式器,同Tooltip.formatter,不支持异步回调
  37328. // textStyle: null // 默认使用全局文本样式,详见TEXTSTYLE
  37329. },
  37330. emphasis: {
  37331. show: true
  37332. }
  37333. },
  37334. labelLine: {
  37335. normal: {
  37336. show: true,
  37337. length: 20,
  37338. lineStyle: {
  37339. // color: 各异,
  37340. width: 1,
  37341. type: 'solid'
  37342. }
  37343. },
  37344. emphasis: {}
  37345. },
  37346. itemStyle: {
  37347. normal: {
  37348. // color: 各异,
  37349. borderColor: '#fff',
  37350. borderWidth: 1
  37351. },
  37352. emphasis: {
  37353. // color: 各异,
  37354. }
  37355. }
  37356. }
  37357. });
  37358. module.exports = FunnelSeries;
  37359. /***/ },
  37360. /* 231 */
  37361. /***/ function(module, exports, __webpack_require__) {
  37362. var graphic = __webpack_require__(18);
  37363. var zrUtil = __webpack_require__(4);
  37364. /**
  37365. * Piece of pie including Sector, Label, LabelLine
  37366. * @constructor
  37367. * @extends {module:zrender/graphic/Group}
  37368. */
  37369. function FunnelPiece(data, idx) {
  37370. graphic.Group.call(this);
  37371. var polygon = new graphic.Polygon();
  37372. var labelLine = new graphic.Polyline();
  37373. var text = new graphic.Text();
  37374. this.add(polygon);
  37375. this.add(labelLine);
  37376. this.add(text);
  37377. this.updateData(data, idx, true);
  37378. // Hover to change label and labelLine
  37379. function onEmphasis() {
  37380. labelLine.ignore = labelLine.hoverIgnore;
  37381. text.ignore = text.hoverIgnore;
  37382. }
  37383. function onNormal() {
  37384. labelLine.ignore = labelLine.normalIgnore;
  37385. text.ignore = text.normalIgnore;
  37386. }
  37387. this.on('emphasis', onEmphasis)
  37388. .on('normal', onNormal)
  37389. .on('mouseover', onEmphasis)
  37390. .on('mouseout', onNormal);
  37391. }
  37392. var funnelPieceProto = FunnelPiece.prototype;
  37393. function getLabelStyle(data, idx, state, labelModel) {
  37394. var textStyleModel = labelModel.getModel('textStyle');
  37395. var position = labelModel.get('position');
  37396. var isLabelInside = position === 'inside' || position === 'inner' || position === 'center';
  37397. return {
  37398. fill: textStyleModel.getTextColor()
  37399. || (isLabelInside ? '#fff' : data.getItemVisual(idx, 'color')),
  37400. textFont: textStyleModel.getFont(),
  37401. text: zrUtil.retrieve(
  37402. data.hostModel.getFormattedLabel(idx, state),
  37403. data.getName(idx)
  37404. )
  37405. };
  37406. }
  37407. var opacityAccessPath = ['itemStyle', 'normal', 'opacity'];
  37408. funnelPieceProto.updateData = function (data, idx, firstCreate) {
  37409. var polygon = this.childAt(0);
  37410. var seriesModel = data.hostModel;
  37411. var itemModel = data.getItemModel(idx);
  37412. var layout = data.getItemLayout(idx);
  37413. var opacity = data.getItemModel(idx).get(opacityAccessPath);
  37414. opacity = opacity == null ? 1 : opacity;
  37415. // Reset style
  37416. polygon.useStyle({});
  37417. if (firstCreate) {
  37418. polygon.setShape({
  37419. points: layout.points
  37420. });
  37421. polygon.setStyle({ opacity : 0 });
  37422. graphic.initProps(polygon, {
  37423. style: {
  37424. opacity: opacity
  37425. }
  37426. }, seriesModel, idx);
  37427. }
  37428. else {
  37429. graphic.updateProps(polygon, {
  37430. style: {
  37431. opacity: opacity
  37432. },
  37433. shape: {
  37434. points: layout.points
  37435. }
  37436. }, seriesModel, idx);
  37437. }
  37438. // Update common style
  37439. var itemStyleModel = itemModel.getModel('itemStyle');
  37440. var visualColor = data.getItemVisual(idx, 'color');
  37441. polygon.setStyle(
  37442. zrUtil.defaults(
  37443. {
  37444. lineJoin: 'round',
  37445. fill: visualColor
  37446. },
  37447. itemStyleModel.getModel('normal').getItemStyle(['opacity'])
  37448. )
  37449. );
  37450. polygon.hoverStyle = itemStyleModel.getModel('emphasis').getItemStyle();
  37451. this._updateLabel(data, idx);
  37452. graphic.setHoverStyle(this);
  37453. };
  37454. funnelPieceProto._updateLabel = function (data, idx) {
  37455. var labelLine = this.childAt(1);
  37456. var labelText = this.childAt(2);
  37457. var seriesModel = data.hostModel;
  37458. var itemModel = data.getItemModel(idx);
  37459. var layout = data.getItemLayout(idx);
  37460. var labelLayout = layout.label;
  37461. var visualColor = data.getItemVisual(idx, 'color');
  37462. graphic.updateProps(labelLine, {
  37463. shape: {
  37464. points: labelLayout.linePoints || labelLayout.linePoints
  37465. }
  37466. }, seriesModel, idx);
  37467. graphic.updateProps(labelText, {
  37468. style: {
  37469. x: labelLayout.x,
  37470. y: labelLayout.y
  37471. }
  37472. }, seriesModel, idx);
  37473. labelText.attr({
  37474. style: {
  37475. textAlign: labelLayout.textAlign,
  37476. textVerticalAlign: labelLayout.verticalAlign,
  37477. textFont: labelLayout.font
  37478. },
  37479. rotation: labelLayout.rotation,
  37480. origin: [labelLayout.x, labelLayout.y],
  37481. z2: 10
  37482. });
  37483. var labelModel = itemModel.getModel('label.normal');
  37484. var labelHoverModel = itemModel.getModel('label.emphasis');
  37485. var labelLineModel = itemModel.getModel('labelLine.normal');
  37486. var labelLineHoverModel = itemModel.getModel('labelLine.emphasis');
  37487. labelText.setStyle(getLabelStyle(data, idx, 'normal', labelModel));
  37488. labelText.ignore = labelText.normalIgnore = !labelModel.get('show');
  37489. labelText.hoverIgnore = !labelHoverModel.get('show');
  37490. labelLine.ignore = labelLine.normalIgnore = !labelLineModel.get('show');
  37491. labelLine.hoverIgnore = !labelLineHoverModel.get('show');
  37492. // Default use item visual color
  37493. labelLine.setStyle({
  37494. stroke: visualColor
  37495. });
  37496. labelLine.setStyle(labelLineModel.getModel('lineStyle').getLineStyle());
  37497. labelText.hoverStyle = getLabelStyle(data, idx, 'emphasis', labelHoverModel);
  37498. labelLine.hoverStyle = labelLineHoverModel.getModel('lineStyle').getLineStyle();
  37499. };
  37500. zrUtil.inherits(FunnelPiece, graphic.Group);
  37501. var Funnel = __webpack_require__(80).extend({
  37502. type: 'funnel',
  37503. render: function (seriesModel, ecModel, api) {
  37504. var data = seriesModel.getData();
  37505. var oldData = this._data;
  37506. var group = this.group;
  37507. data.diff(oldData)
  37508. .add(function (idx) {
  37509. var funnelPiece = new FunnelPiece(data, idx);
  37510. data.setItemGraphicEl(idx, funnelPiece);
  37511. group.add(funnelPiece);
  37512. })
  37513. .update(function (newIdx, oldIdx) {
  37514. var piePiece = oldData.getItemGraphicEl(oldIdx);
  37515. piePiece.updateData(data, newIdx);
  37516. group.add(piePiece);
  37517. data.setItemGraphicEl(newIdx, piePiece);
  37518. })
  37519. .remove(function (idx) {
  37520. var piePiece = oldData.getItemGraphicEl(idx);
  37521. group.remove(piePiece);
  37522. })
  37523. .execute();
  37524. this._data = data;
  37525. },
  37526. remove: function () {
  37527. this.group.removeAll();
  37528. this._data = null;
  37529. },
  37530. dispose: function () {}
  37531. });
  37532. module.exports = Funnel;
  37533. /***/ },
  37534. /* 232 */
  37535. /***/ function(module, exports, __webpack_require__) {
  37536. var layout = __webpack_require__(71);
  37537. var number = __webpack_require__(7);
  37538. var parsePercent = number.parsePercent;
  37539. function getViewRect(seriesModel, api) {
  37540. return layout.getLayoutRect(
  37541. seriesModel.getBoxLayoutParams(), {
  37542. width: api.getWidth(),
  37543. height: api.getHeight()
  37544. }
  37545. );
  37546. }
  37547. function getSortedIndices(data, sort) {
  37548. var valueArr = data.mapArray('value', function (val) {
  37549. return val;
  37550. });
  37551. var indices = [];
  37552. var isAscending = sort === 'ascending';
  37553. for (var i = 0, len = data.count(); i < len; i++) {
  37554. indices[i] = i;
  37555. }
  37556. // Add custom sortable function & none sortable opetion by "options.sort"
  37557. if (typeof sort === 'function') {
  37558. indices.sort(sort);
  37559. } else if (sort !== 'none') {
  37560. indices.sort(function (a, b) {
  37561. return isAscending ? valueArr[a] - valueArr[b] : valueArr[b] - valueArr[a];
  37562. });
  37563. }
  37564. return indices;
  37565. }
  37566. function labelLayout (data) {
  37567. data.each(function (idx) {
  37568. var itemModel = data.getItemModel(idx);
  37569. var labelModel = itemModel.getModel('label.normal');
  37570. var labelPosition = labelModel.get('position');
  37571. var labelLineModel = itemModel.getModel('labelLine.normal');
  37572. var layout = data.getItemLayout(idx);
  37573. var points = layout.points;
  37574. var isLabelInside = labelPosition === 'inner'
  37575. || labelPosition === 'inside' || labelPosition === 'center';
  37576. var textAlign;
  37577. var textX;
  37578. var textY;
  37579. var linePoints;
  37580. if (isLabelInside) {
  37581. textX = (points[0][0] + points[1][0] + points[2][0] + points[3][0]) / 4;
  37582. textY = (points[0][1] + points[1][1] + points[2][1] + points[3][1]) / 4;
  37583. textAlign = 'center';
  37584. linePoints = [
  37585. [textX, textY], [textX, textY]
  37586. ];
  37587. }
  37588. else {
  37589. var x1;
  37590. var y1;
  37591. var x2;
  37592. var labelLineLen = labelLineModel.get('length');
  37593. if (labelPosition === 'left') {
  37594. // Left side
  37595. x1 = (points[3][0] + points[0][0]) / 2;
  37596. y1 = (points[3][1] + points[0][1]) / 2;
  37597. x2 = x1 - labelLineLen;
  37598. textX = x2 - 5;
  37599. textAlign = 'right';
  37600. }
  37601. else {
  37602. // Right side
  37603. x1 = (points[1][0] + points[2][0]) / 2;
  37604. y1 = (points[1][1] + points[2][1]) / 2;
  37605. x2 = x1 + labelLineLen;
  37606. textX = x2 + 5;
  37607. textAlign = 'left';
  37608. }
  37609. var y2 = y1;
  37610. linePoints = [[x1, y1], [x2, y2]];
  37611. textY = y2;
  37612. }
  37613. layout.label = {
  37614. linePoints: linePoints,
  37615. x: textX,
  37616. y: textY,
  37617. verticalAlign: 'middle',
  37618. textAlign: textAlign,
  37619. inside: isLabelInside
  37620. };
  37621. });
  37622. }
  37623. module.exports = function (ecModel, api, payload) {
  37624. ecModel.eachSeriesByType('funnel', function (seriesModel) {
  37625. var data = seriesModel.getData();
  37626. var sort = seriesModel.get('sort');
  37627. var viewRect = getViewRect(seriesModel, api);
  37628. var indices = getSortedIndices(data, sort);
  37629. var sizeExtent = [
  37630. parsePercent(seriesModel.get('minSize'), viewRect.width),
  37631. parsePercent(seriesModel.get('maxSize'), viewRect.width)
  37632. ];
  37633. var dataExtent = data.getDataExtent('value');
  37634. var min = seriesModel.get('min');
  37635. var max = seriesModel.get('max');
  37636. if (min == null) {
  37637. min = Math.min(dataExtent[0], 0);
  37638. }
  37639. if (max == null) {
  37640. max = dataExtent[1];
  37641. }
  37642. var funnelAlign = seriesModel.get('funnelAlign');
  37643. var gap = seriesModel.get('gap');
  37644. var itemHeight = (viewRect.height - gap * (data.count() - 1)) / data.count();
  37645. var y = viewRect.y;
  37646. var getLinePoints = function (idx, offY) {
  37647. // End point index is data.count() and we assign it 0
  37648. var val = data.get('value', idx) || 0;
  37649. var itemWidth = number.linearMap(val, [min, max], sizeExtent, true);
  37650. var x0;
  37651. switch (funnelAlign) {
  37652. case 'left':
  37653. x0 = viewRect.x;
  37654. break;
  37655. case 'center':
  37656. x0 = viewRect.x + (viewRect.width - itemWidth) / 2;
  37657. break;
  37658. case 'right':
  37659. x0 = viewRect.x + viewRect.width - itemWidth;
  37660. break;
  37661. }
  37662. return [
  37663. [x0, offY],
  37664. [x0 + itemWidth, offY]
  37665. ];
  37666. };
  37667. if (sort === 'ascending') {
  37668. // From bottom to top
  37669. itemHeight = -itemHeight;
  37670. gap = -gap;
  37671. y += viewRect.height;
  37672. indices = indices.reverse();
  37673. }
  37674. for (var i = 0; i < indices.length; i++) {
  37675. var idx = indices[i];
  37676. var nextIdx = indices[i + 1];
  37677. var start = getLinePoints(idx, y);
  37678. var end = getLinePoints(nextIdx, y + itemHeight);
  37679. y += itemHeight + gap;
  37680. data.setItemLayout(idx, {
  37681. points: start.concat(end.slice().reverse())
  37682. });
  37683. }
  37684. labelLayout(data);
  37685. });
  37686. };
  37687. /***/ },
  37688. /* 233 */
  37689. /***/ function(module, exports, __webpack_require__) {
  37690. var echarts = __webpack_require__(1);
  37691. __webpack_require__(234);
  37692. __webpack_require__(247);
  37693. __webpack_require__(248);
  37694. echarts.registerVisual(__webpack_require__(249));
  37695. /***/ },
  37696. /* 234 */
  37697. /***/ function(module, exports, __webpack_require__) {
  37698. __webpack_require__(235);
  37699. __webpack_require__(239);
  37700. __webpack_require__(241);
  37701. var echarts = __webpack_require__(1);
  37702. var zrUtil = __webpack_require__(4);
  37703. var throttle = __webpack_require__(81);
  37704. var CLICK_THRESHOLD = 5; // > 4
  37705. // Parallel view
  37706. echarts.extendComponentView({
  37707. type: 'parallel',
  37708. render: function (parallelModel, ecModel, api) {
  37709. this._model = parallelModel;
  37710. this._api = api;
  37711. if (!this._handlers) {
  37712. this._handlers = {};
  37713. zrUtil.each(handlers, function (handler, eventName) {
  37714. api.getZr().on(eventName, this._handlers[eventName] = zrUtil.bind(handler, this));
  37715. }, this);
  37716. }
  37717. throttle.createOrUpdate(
  37718. this,
  37719. '_throttledDispatchExpand',
  37720. parallelModel.get('axisExpandRate'),
  37721. 'fixRate'
  37722. );
  37723. },
  37724. dispose: function (ecModel, api) {
  37725. zrUtil.each(this._handlers, function (handler, eventName) {
  37726. api.getZr().off(eventName, handler);
  37727. });
  37728. this._handlers = null;
  37729. },
  37730. /**
  37731. * @param {Object} [opt] If null, cancle the last action triggering for debounce.
  37732. */
  37733. _throttledDispatchExpand: function (opt) {
  37734. this._dispatchExpand(opt);
  37735. },
  37736. _dispatchExpand: function (opt) {
  37737. opt && this._api.dispatchAction(
  37738. zrUtil.extend({type: 'parallelAxisExpand'}, opt)
  37739. );
  37740. }
  37741. });
  37742. var handlers = {
  37743. mousedown: function (e) {
  37744. if (checkTrigger(this, 'click')) {
  37745. this._mouseDownPoint = [e.offsetX, e.offsetY];
  37746. }
  37747. },
  37748. mouseup: function (e) {
  37749. var mouseDownPoint = this._mouseDownPoint;
  37750. if (checkTrigger(this, 'click') && mouseDownPoint) {
  37751. var point = [e.offsetX, e.offsetY];
  37752. var dist = Math.pow(mouseDownPoint[0] - point[0], 2)
  37753. + Math.pow(mouseDownPoint[1] - point[1], 2);
  37754. if (dist > CLICK_THRESHOLD) {
  37755. return;
  37756. }
  37757. var result = this._model.coordinateSystem.getSlidedAxisExpandWindow(
  37758. [e.offsetX, e.offsetY]
  37759. );
  37760. result.behavior !== 'none' && this._dispatchExpand({
  37761. axisExpandWindow: result.axisExpandWindow
  37762. });
  37763. }
  37764. this._mouseDownPoint = null;
  37765. },
  37766. mousemove: function (e) {
  37767. // Should do nothing when brushing.
  37768. if (this._mouseDownPoint || !checkTrigger(this, 'mousemove')) {
  37769. return;
  37770. }
  37771. var model = this._model;
  37772. var result = model.coordinateSystem.getSlidedAxisExpandWindow(
  37773. [e.offsetX, e.offsetY]
  37774. );
  37775. var behavior = result.behavior;
  37776. behavior === 'jump' && this._throttledDispatchExpand.debounceNextCall(model.get('axisExpandDebounce'));
  37777. this._throttledDispatchExpand(
  37778. behavior === 'none'
  37779. ? null // Cancle the last trigger, in case that mouse slide out of the area quickly.
  37780. : {
  37781. axisExpandWindow: result.axisExpandWindow,
  37782. // Jumping uses animation, and sliding suppresses animation.
  37783. animation: behavior === 'jump' ? null : false
  37784. }
  37785. );
  37786. }
  37787. };
  37788. function checkTrigger(view, triggerOn) {
  37789. var model = view._model;
  37790. return model.get('axisExpandable') && model.get('axisExpandTriggerOn') === triggerOn;
  37791. }
  37792. echarts.registerPreprocessor(
  37793. __webpack_require__(246)
  37794. );
  37795. /***/ },
  37796. /* 235 */
  37797. /***/ function(module, exports, __webpack_require__) {
  37798. /**
  37799. * Parallel coordinate system creater.
  37800. */
  37801. var Parallel = __webpack_require__(236);
  37802. function create(ecModel, api) {
  37803. var coordSysList = [];
  37804. ecModel.eachComponent('parallel', function (parallelModel, idx) {
  37805. var coordSys = new Parallel(parallelModel, ecModel, api);
  37806. coordSys.name = 'parallel_' + idx;
  37807. coordSys.resize(parallelModel, api);
  37808. parallelModel.coordinateSystem = coordSys;
  37809. coordSys.model = parallelModel;
  37810. coordSysList.push(coordSys);
  37811. });
  37812. // Inject the coordinateSystems into seriesModel
  37813. ecModel.eachSeries(function (seriesModel) {
  37814. if (seriesModel.get('coordinateSystem') === 'parallel') {
  37815. var parallelModel = ecModel.queryComponents({
  37816. mainType: 'parallel',
  37817. index: seriesModel.get('parallelIndex'),
  37818. id: seriesModel.get('parallelId')
  37819. })[0];
  37820. seriesModel.coordinateSystem = parallelModel.coordinateSystem;
  37821. }
  37822. });
  37823. return coordSysList;
  37824. }
  37825. __webpack_require__(76).register('parallel', {create: create});
  37826. /***/ },
  37827. /* 236 */
  37828. /***/ function(module, exports, __webpack_require__) {
  37829. /**
  37830. * Parallel Coordinates
  37831. * <https://en.wikipedia.org/wiki/Parallel_coordinates>
  37832. */
  37833. var layoutUtil = __webpack_require__(71);
  37834. var axisHelper = __webpack_require__(101);
  37835. var zrUtil = __webpack_require__(4);
  37836. var ParallelAxis = __webpack_require__(237);
  37837. var graphic = __webpack_require__(18);
  37838. var matrix = __webpack_require__(11);
  37839. var numberUtil = __webpack_require__(7);
  37840. var sliderMove = __webpack_require__(238);
  37841. var each = zrUtil.each;
  37842. var mathMin = Math.min;
  37843. var mathMax = Math.max;
  37844. var mathFloor = Math.floor;
  37845. var mathCeil = Math.ceil;
  37846. var round = numberUtil.round;
  37847. var PI = Math.PI;
  37848. function Parallel(parallelModel, ecModel, api) {
  37849. /**
  37850. * key: dimension
  37851. * @type {Object.<string, module:echarts/coord/parallel/Axis>}
  37852. * @private
  37853. */
  37854. this._axesMap = zrUtil.createHashMap();
  37855. /**
  37856. * key: dimension
  37857. * value: {position: [], rotation, }
  37858. * @type {Object.<string, Object>}
  37859. * @private
  37860. */
  37861. this._axesLayout = {};
  37862. /**
  37863. * Always follow axis order.
  37864. * @type {Array.<string>}
  37865. * @readOnly
  37866. */
  37867. this.dimensions = parallelModel.dimensions;
  37868. /**
  37869. * @type {module:zrender/core/BoundingRect}
  37870. */
  37871. this._rect;
  37872. /**
  37873. * @type {module:echarts/coord/parallel/ParallelModel}
  37874. */
  37875. this._model = parallelModel;
  37876. this._init(parallelModel, ecModel, api);
  37877. }
  37878. Parallel.prototype = {
  37879. type: 'parallel',
  37880. constructor: Parallel,
  37881. /**
  37882. * Initialize cartesian coordinate systems
  37883. * @private
  37884. */
  37885. _init: function (parallelModel, ecModel, api) {
  37886. var dimensions = parallelModel.dimensions;
  37887. var parallelAxisIndex = parallelModel.parallelAxisIndex;
  37888. each(dimensions, function (dim, idx) {
  37889. var axisIndex = parallelAxisIndex[idx];
  37890. var axisModel = ecModel.getComponent('parallelAxis', axisIndex);
  37891. var axis = this._axesMap.set(dim, new ParallelAxis(
  37892. dim,
  37893. axisHelper.createScaleByModel(axisModel),
  37894. [0, 0],
  37895. axisModel.get('type'),
  37896. axisIndex
  37897. ));
  37898. var isCategory = axis.type === 'category';
  37899. axis.onBand = isCategory && axisModel.get('boundaryGap');
  37900. axis.inverse = axisModel.get('inverse');
  37901. // Injection
  37902. axisModel.axis = axis;
  37903. axis.model = axisModel;
  37904. axis.coordinateSystem = axisModel.coordinateSystem = this;
  37905. }, this);
  37906. },
  37907. /**
  37908. * Update axis scale after data processed
  37909. * @param {module:echarts/model/Global} ecModel
  37910. * @param {module:echarts/ExtensionAPI} api
  37911. */
  37912. update: function (ecModel, api) {
  37913. this._updateAxesFromSeries(this._model, ecModel);
  37914. },
  37915. /**
  37916. * @override
  37917. */
  37918. containPoint: function (point) {
  37919. var layoutInfo = this._makeLayoutInfo();
  37920. var axisBase = layoutInfo.axisBase;
  37921. var layoutBase = layoutInfo.layoutBase;
  37922. var pixelDimIndex = layoutInfo.pixelDimIndex;
  37923. var pAxis = point[1 - pixelDimIndex];
  37924. var pLayout = point[pixelDimIndex];
  37925. return pAxis >= axisBase
  37926. && pAxis <= axisBase + layoutInfo.axisLength
  37927. && pLayout >= layoutBase
  37928. && pLayout <= layoutBase + layoutInfo.layoutLength;
  37929. },
  37930. /**
  37931. * Update properties from series
  37932. * @private
  37933. */
  37934. _updateAxesFromSeries: function (parallelModel, ecModel) {
  37935. ecModel.eachSeries(function (seriesModel) {
  37936. if (!parallelModel.contains(seriesModel, ecModel)) {
  37937. return;
  37938. }
  37939. var data = seriesModel.getData();
  37940. each(this.dimensions, function (dim) {
  37941. var axis = this._axesMap.get(dim);
  37942. axis.scale.unionExtentFromData(data, dim);
  37943. axisHelper.niceScaleExtent(axis.scale, axis.model);
  37944. }, this);
  37945. }, this);
  37946. },
  37947. /**
  37948. * Resize the parallel coordinate system.
  37949. * @param {module:echarts/coord/parallel/ParallelModel} parallelModel
  37950. * @param {module:echarts/ExtensionAPI} api
  37951. */
  37952. resize: function (parallelModel, api) {
  37953. this._rect = layoutUtil.getLayoutRect(
  37954. parallelModel.getBoxLayoutParams(),
  37955. {
  37956. width: api.getWidth(),
  37957. height: api.getHeight()
  37958. }
  37959. );
  37960. this._layoutAxes();
  37961. },
  37962. /**
  37963. * @return {module:zrender/core/BoundingRect}
  37964. */
  37965. getRect: function () {
  37966. return this._rect;
  37967. },
  37968. /**
  37969. * @private
  37970. */
  37971. _makeLayoutInfo: function () {
  37972. var parallelModel = this._model;
  37973. var rect = this._rect;
  37974. var xy = ['x', 'y'];
  37975. var wh = ['width', 'height'];
  37976. var layout = parallelModel.get('layout');
  37977. var pixelDimIndex = layout === 'horizontal' ? 0 : 1;
  37978. var layoutLength = rect[wh[pixelDimIndex]];
  37979. var layoutExtent = [0, layoutLength];
  37980. var axisCount = this.dimensions.length;
  37981. var axisExpandWidth = restrict(parallelModel.get('axisExpandWidth'), layoutExtent);
  37982. var axisExpandCount = restrict(parallelModel.get('axisExpandCount') || 0, [0, axisCount]);
  37983. var axisExpandable = parallelModel.get('axisExpandable')
  37984. && axisCount > 3
  37985. && axisCount > axisExpandCount
  37986. && axisExpandCount > 1
  37987. && axisExpandWidth > 0
  37988. && layoutLength > 0;
  37989. // `axisExpandWindow` is According to the coordinates of [0, axisExpandLength],
  37990. // for sake of consider the case that axisCollapseWidth is 0 (when screen is narrow),
  37991. // where collapsed axes should be overlapped.
  37992. var axisExpandWindow = parallelModel.get('axisExpandWindow');
  37993. var winSize;
  37994. if (!axisExpandWindow) {
  37995. winSize = restrict(axisExpandWidth * (axisExpandCount - 1), layoutExtent);
  37996. var axisExpandCenter = parallelModel.get('axisExpandCenter') || mathFloor(axisCount / 2);
  37997. axisExpandWindow = [axisExpandWidth * axisExpandCenter - winSize / 2];
  37998. axisExpandWindow[1] = axisExpandWindow[0] + winSize;
  37999. }
  38000. else {
  38001. winSize = restrict(axisExpandWindow[1] - axisExpandWindow[0], layoutExtent);
  38002. axisExpandWindow[1] = axisExpandWindow[0] + winSize;
  38003. }
  38004. var axisCollapseWidth = (layoutLength - winSize) / (axisCount - axisExpandCount);
  38005. // Avoid axisCollapseWidth is too small.
  38006. axisCollapseWidth < 3 && (axisCollapseWidth = 0);
  38007. // Find the first and last indices > ewin[0] and < ewin[1].
  38008. var winInnerIndices = [
  38009. mathFloor(round(axisExpandWindow[0] / axisExpandWidth, 1)) + 1,
  38010. mathCeil(round(axisExpandWindow[1] / axisExpandWidth, 1)) - 1
  38011. ];
  38012. // Pos in ec coordinates.
  38013. var axisExpandWindow0Pos = axisCollapseWidth / axisExpandWidth * axisExpandWindow[0];
  38014. return {
  38015. layout: layout,
  38016. pixelDimIndex: pixelDimIndex,
  38017. layoutBase: rect[xy[pixelDimIndex]],
  38018. layoutLength: layoutLength,
  38019. axisBase: rect[xy[1 - pixelDimIndex]],
  38020. axisLength: rect[wh[1 - pixelDimIndex]],
  38021. axisExpandable: axisExpandable,
  38022. axisExpandWidth: axisExpandWidth,
  38023. axisCollapseWidth: axisCollapseWidth,
  38024. axisExpandWindow: axisExpandWindow,
  38025. axisCount: axisCount,
  38026. winInnerIndices: winInnerIndices,
  38027. axisExpandWindow0Pos: axisExpandWindow0Pos
  38028. };
  38029. },
  38030. /**
  38031. * @private
  38032. */
  38033. _layoutAxes: function () {
  38034. var rect = this._rect;
  38035. var axes = this._axesMap;
  38036. var dimensions = this.dimensions;
  38037. var layoutInfo = this._makeLayoutInfo();
  38038. var layout = layoutInfo.layout;
  38039. axes.each(function (axis) {
  38040. var axisExtent = [0, layoutInfo.axisLength];
  38041. var idx = axis.inverse ? 1 : 0;
  38042. axis.setExtent(axisExtent[idx], axisExtent[1 - idx]);
  38043. });
  38044. each(dimensions, function (dim, idx) {
  38045. var posInfo = (layoutInfo.axisExpandable
  38046. ? layoutAxisWithExpand : layoutAxisWithoutExpand
  38047. )(idx, layoutInfo);
  38048. var positionTable = {
  38049. horizontal: {
  38050. x: posInfo.position,
  38051. y: layoutInfo.axisLength
  38052. },
  38053. vertical: {
  38054. x: 0,
  38055. y: posInfo.position
  38056. }
  38057. };
  38058. var rotationTable = {
  38059. horizontal: PI / 2,
  38060. vertical: 0
  38061. };
  38062. var position = [
  38063. positionTable[layout].x + rect.x,
  38064. positionTable[layout].y + rect.y
  38065. ];
  38066. var rotation = rotationTable[layout];
  38067. var transform = matrix.create();
  38068. matrix.rotate(transform, transform, rotation);
  38069. matrix.translate(transform, transform, position);
  38070. // TODO
  38071. // tick等排布信息。
  38072. // TODO
  38073. // 根据axis order 更新 dimensions顺序。
  38074. this._axesLayout[dim] = {
  38075. position: position,
  38076. rotation: rotation,
  38077. transform: transform,
  38078. axisNameAvailableWidth: posInfo.axisNameAvailableWidth,
  38079. axisLabelShow: posInfo.axisLabelShow,
  38080. nameTruncateMaxWidth: posInfo.nameTruncateMaxWidth,
  38081. tickDirection: 1,
  38082. labelDirection: 1,
  38083. labelInterval: axes.get(dim).getLabelInterval()
  38084. };
  38085. }, this);
  38086. },
  38087. /**
  38088. * Get axis by dim.
  38089. * @param {string} dim
  38090. * @return {module:echarts/coord/parallel/ParallelAxis} [description]
  38091. */
  38092. getAxis: function (dim) {
  38093. return this._axesMap.get(dim);
  38094. },
  38095. /**
  38096. * Convert a dim value of a single item of series data to Point.
  38097. * @param {*} value
  38098. * @param {string} dim
  38099. * @return {Array}
  38100. */
  38101. dataToPoint: function (value, dim) {
  38102. return this.axisCoordToPoint(
  38103. this._axesMap.get(dim).dataToCoord(value),
  38104. dim
  38105. );
  38106. },
  38107. /**
  38108. * Travel data for one time, get activeState of each data item.
  38109. * @param {module:echarts/data/List} data
  38110. * @param {Functio} cb param: {string} activeState 'active' or 'inactive' or 'normal'
  38111. * {number} dataIndex
  38112. * @param {Object} context
  38113. */
  38114. eachActiveState: function (data, callback, context) {
  38115. var dimensions = this.dimensions;
  38116. var axesMap = this._axesMap;
  38117. var hasActiveSet = this.hasAxisBrushed();
  38118. for (var i = 0, len = data.count(); i < len; i++) {
  38119. var values = data.getValues(dimensions, i);
  38120. var activeState;
  38121. if (!hasActiveSet) {
  38122. activeState = 'normal';
  38123. }
  38124. else {
  38125. activeState = 'active';
  38126. for (var j = 0, lenj = dimensions.length; j < lenj; j++) {
  38127. var dimName = dimensions[j];
  38128. var state = axesMap.get(dimName).model.getActiveState(values[j], j);
  38129. if (state === 'inactive') {
  38130. activeState = 'inactive';
  38131. break;
  38132. }
  38133. }
  38134. }
  38135. callback.call(context, activeState, i);
  38136. }
  38137. },
  38138. /**
  38139. * Whether has any activeSet.
  38140. * @return {boolean}
  38141. */
  38142. hasAxisBrushed: function () {
  38143. var dimensions = this.dimensions;
  38144. var axesMap = this._axesMap;
  38145. var hasActiveSet = false;
  38146. for (var j = 0, lenj = dimensions.length; j < lenj; j++) {
  38147. if (axesMap.get(dimensions[j]).model.getActiveState() !== 'normal') {
  38148. hasActiveSet = true;
  38149. }
  38150. }
  38151. return hasActiveSet;
  38152. },
  38153. /**
  38154. * Convert coords of each axis to Point.
  38155. * Return point. For example: [10, 20]
  38156. * @param {Array.<number>} coords
  38157. * @param {string} dim
  38158. * @return {Array.<number>}
  38159. */
  38160. axisCoordToPoint: function (coord, dim) {
  38161. var axisLayout = this._axesLayout[dim];
  38162. return graphic.applyTransform([coord, 0], axisLayout.transform);
  38163. },
  38164. /**
  38165. * Get axis layout.
  38166. */
  38167. getAxisLayout: function (dim) {
  38168. return zrUtil.clone(this._axesLayout[dim]);
  38169. },
  38170. /**
  38171. * @param {Array.<number>} point
  38172. * @return {Object} {axisExpandWindow, delta, behavior: 'jump' | 'slide' | 'none'}.
  38173. */
  38174. getSlidedAxisExpandWindow: function (point) {
  38175. var layoutInfo = this._makeLayoutInfo();
  38176. var pixelDimIndex = layoutInfo.pixelDimIndex;
  38177. var axisExpandWindow = layoutInfo.axisExpandWindow.slice();
  38178. var winSize = axisExpandWindow[1] - axisExpandWindow[0];
  38179. var extent = [0, layoutInfo.axisExpandWidth * (layoutInfo.axisCount - 1)];
  38180. // Out of the area of coordinate system.
  38181. if (!this.containPoint(point)) {
  38182. return {behavior: 'none', axisExpandWindow: axisExpandWindow};
  38183. }
  38184. // Conver the point from global to expand coordinates.
  38185. var pointCoord = point[pixelDimIndex] - layoutInfo.layoutBase - layoutInfo.axisExpandWindow0Pos;
  38186. // For dragging operation convenience, the window should not be
  38187. // slided when mouse is the center area of the window.
  38188. var delta;
  38189. var behavior = 'slide';
  38190. var axisCollapseWidth = layoutInfo.axisCollapseWidth;
  38191. var triggerArea = this._model.get('axisExpandSlideTriggerArea');
  38192. // But consider touch device, jump is necessary.
  38193. var useJump = triggerArea[0] != null;
  38194. if (axisCollapseWidth) {
  38195. if (useJump && axisCollapseWidth && pointCoord < winSize * triggerArea[0]) {
  38196. behavior = 'jump';
  38197. delta = pointCoord - winSize * triggerArea[2];
  38198. }
  38199. else if (useJump && axisCollapseWidth && pointCoord > winSize * (1 - triggerArea[0])) {
  38200. behavior = 'jump';
  38201. delta = pointCoord - winSize * (1 - triggerArea[2]);
  38202. }
  38203. else {
  38204. (delta = pointCoord - winSize * triggerArea[1]) >= 0
  38205. && (delta = pointCoord - winSize * (1 - triggerArea[1])) <= 0
  38206. && (delta = 0);
  38207. }
  38208. delta *= layoutInfo.axisExpandWidth / axisCollapseWidth;
  38209. delta
  38210. ? sliderMove(delta, axisExpandWindow, extent, 'all')
  38211. // Avoid nonsense triger on mousemove.
  38212. : (behavior = 'none');
  38213. }
  38214. // When screen is too narrow, make it visible and slidable, although it is hard to interact.
  38215. else {
  38216. var winSize = axisExpandWindow[1] - axisExpandWindow[0];
  38217. var pos = extent[1] * pointCoord / winSize;
  38218. axisExpandWindow = [mathMax(0, pos - winSize / 2)];
  38219. axisExpandWindow[1] = mathMin(extent[1], axisExpandWindow[0] + winSize);
  38220. axisExpandWindow[0] = axisExpandWindow[1] - winSize;
  38221. }
  38222. return {
  38223. axisExpandWindow: axisExpandWindow,
  38224. behavior: behavior
  38225. };
  38226. }
  38227. };
  38228. function restrict(len, extent) {
  38229. return mathMin(mathMax(len, extent[0]), extent[1]);
  38230. }
  38231. function layoutAxisWithoutExpand(axisIndex, layoutInfo) {
  38232. var step = layoutInfo.layoutLength / (layoutInfo.axisCount - 1);
  38233. return {
  38234. position: step * axisIndex,
  38235. axisNameAvailableWidth: step,
  38236. axisLabelShow: true
  38237. };
  38238. }
  38239. function layoutAxisWithExpand(axisIndex, layoutInfo) {
  38240. var layoutLength = layoutInfo.layoutLength;
  38241. var axisExpandWidth = layoutInfo.axisExpandWidth;
  38242. var axisCount = layoutInfo.axisCount;
  38243. var axisCollapseWidth = layoutInfo.axisCollapseWidth;
  38244. var winInnerIndices = layoutInfo.winInnerIndices;
  38245. var position;
  38246. var axisNameAvailableWidth = axisCollapseWidth;
  38247. var axisLabelShow = false;
  38248. var nameTruncateMaxWidth;
  38249. if (axisIndex < winInnerIndices[0]) {
  38250. position = axisIndex * axisCollapseWidth;
  38251. nameTruncateMaxWidth = axisCollapseWidth;
  38252. }
  38253. else if (axisIndex <= winInnerIndices[1]) {
  38254. position = layoutInfo.axisExpandWindow0Pos
  38255. + axisIndex * axisExpandWidth - layoutInfo.axisExpandWindow[0];
  38256. axisNameAvailableWidth = axisExpandWidth;
  38257. axisLabelShow = true;
  38258. }
  38259. else {
  38260. position = layoutLength - (axisCount - 1 - axisIndex) * axisCollapseWidth;
  38261. nameTruncateMaxWidth = axisCollapseWidth;
  38262. }
  38263. return {
  38264. position: position,
  38265. axisNameAvailableWidth: axisNameAvailableWidth,
  38266. axisLabelShow: axisLabelShow,
  38267. nameTruncateMaxWidth: nameTruncateMaxWidth
  38268. };
  38269. }
  38270. module.exports = Parallel;
  38271. /***/ },
  38272. /* 237 */
  38273. /***/ function(module, exports, __webpack_require__) {
  38274. var zrUtil = __webpack_require__(4);
  38275. var Axis = __webpack_require__(100);
  38276. /**
  38277. * @constructor module:echarts/coord/parallel/ParallelAxis
  38278. * @extends {module:echarts/coord/Axis}
  38279. * @param {string} dim
  38280. * @param {*} scale
  38281. * @param {Array.<number>} coordExtent
  38282. * @param {string} axisType
  38283. */
  38284. var ParallelAxis = function (dim, scale, coordExtent, axisType, axisIndex) {
  38285. Axis.call(this, dim, scale, coordExtent);
  38286. /**
  38287. * Axis type
  38288. * - 'category'
  38289. * - 'value'
  38290. * - 'time'
  38291. * - 'log'
  38292. * @type {string}
  38293. */
  38294. this.type = axisType || 'value';
  38295. /**
  38296. * @type {number}
  38297. * @readOnly
  38298. */
  38299. this.axisIndex = axisIndex;
  38300. };
  38301. ParallelAxis.prototype = {
  38302. constructor: ParallelAxis,
  38303. /**
  38304. * Axis model
  38305. * @param {module:echarts/coord/parallel/AxisModel}
  38306. */
  38307. model: null
  38308. };
  38309. zrUtil.inherits(ParallelAxis, Axis);
  38310. module.exports = ParallelAxis;
  38311. /***/ },
  38312. /* 238 */
  38313. /***/ function(module, exports) {
  38314. /**
  38315. * Calculate slider move result.
  38316. * Usage:
  38317. * (1) If both handle0 and handle1 are needed to be moved, set minSpan the same as
  38318. * maxSpan and the same as `Math.abs(handleEnd[1] - handleEnds[0])`.
  38319. * (2) If handle0 is forbidden to cross handle1, set minSpan as `0`.
  38320. *
  38321. * @param {number} delta Move length.
  38322. * @param {Array.<number>} handleEnds handleEnds[0] can be bigger then handleEnds[1].
  38323. * handleEnds will be modified in this method.
  38324. * @param {Array.<number>} extent handleEnds is restricted by extent.
  38325. * extent[0] should less or equals than extent[1].
  38326. * @param {number|string} handleIndex Can be 'all', means that both move the two handleEnds,
  38327. * where the input minSpan and maxSpan will not work.
  38328. * @param {number} [minSpan] The range of dataZoom can not be smaller than that.
  38329. * If not set, handle0 and cross handle1. If set as a non-negative
  38330. * number (including `0`), handles will push each other when reaching
  38331. * the minSpan.
  38332. * @param {number} [maxSpan] The range of dataZoom can not be larger than that.
  38333. * @return {Array.<number>} The input handleEnds.
  38334. */
  38335. module.exports = function (delta, handleEnds, extent, handleIndex, minSpan, maxSpan) {
  38336. // Normalize firstly.
  38337. handleEnds[0] = restrict(handleEnds[0], extent);
  38338. handleEnds[1] = restrict(handleEnds[1], extent);
  38339. delta = delta || 0;
  38340. var extentSpan = extent[1] - extent[0];
  38341. // Notice maxSpan and minSpan can be null/undefined.
  38342. if (minSpan != null) {
  38343. minSpan = restrict(minSpan, [0, extentSpan]);
  38344. }
  38345. if (maxSpan != null) {
  38346. maxSpan = Math.max(maxSpan, minSpan != null ? minSpan : 0);
  38347. }
  38348. if (handleIndex === 'all') {
  38349. minSpan = maxSpan = Math.abs(handleEnds[1] - handleEnds[0]);
  38350. handleIndex = 0;
  38351. }
  38352. var originalDistSign = getSpanSign(handleEnds, handleIndex);
  38353. handleEnds[handleIndex] += delta;
  38354. // Restrict in extent.
  38355. var extentMinSpan = minSpan || 0;
  38356. var realExtent = extent.slice();
  38357. originalDistSign.sign < 0 ? (realExtent[0] += extentMinSpan) : (realExtent[1] -= extentMinSpan);
  38358. handleEnds[handleIndex] = restrict(handleEnds[handleIndex], realExtent);
  38359. // Expand span.
  38360. var currDistSign = getSpanSign(handleEnds, handleIndex);
  38361. if (minSpan != null && (
  38362. currDistSign.sign !== originalDistSign.sign || currDistSign.span < minSpan
  38363. )) {
  38364. // If minSpan exists, 'cross' is forbinden.
  38365. handleEnds[1 - handleIndex] = handleEnds[handleIndex] + originalDistSign.sign * minSpan;
  38366. }
  38367. // Shrink span.
  38368. var currDistSign = getSpanSign(handleEnds, handleIndex);
  38369. if (maxSpan != null && currDistSign.span > maxSpan) {
  38370. handleEnds[1 - handleIndex] = handleEnds[handleIndex] + currDistSign.sign * maxSpan;
  38371. }
  38372. return handleEnds;
  38373. };
  38374. function getSpanSign(handleEnds, handleIndex) {
  38375. var dist = handleEnds[handleIndex] - handleEnds[1 - handleIndex];
  38376. // If `handleEnds[0] === handleEnds[1]`, always believe that handleEnd[0]
  38377. // is at left of handleEnds[1] for non-cross case.
  38378. return {span: Math.abs(dist), sign: dist > 0 ? -1 : dist < 0 ? 1 : handleIndex ? -1 : 1};
  38379. }
  38380. function restrict(value, extend) {
  38381. return Math.min(extend[1], Math.max(extend[0], value));
  38382. }
  38383. /***/ },
  38384. /* 239 */
  38385. /***/ function(module, exports, __webpack_require__) {
  38386. var zrUtil = __webpack_require__(4);
  38387. var Component = __webpack_require__(69);
  38388. __webpack_require__(240);
  38389. Component.extend({
  38390. type: 'parallel',
  38391. dependencies: ['parallelAxis'],
  38392. /**
  38393. * @type {module:echarts/coord/parallel/Parallel}
  38394. */
  38395. coordinateSystem: null,
  38396. /**
  38397. * Each item like: 'dim0', 'dim1', 'dim2', ...
  38398. * @type {Array.<string>}
  38399. * @readOnly
  38400. */
  38401. dimensions: null,
  38402. /**
  38403. * Coresponding to dimensions.
  38404. * @type {Array.<number>}
  38405. * @readOnly
  38406. */
  38407. parallelAxisIndex: null,
  38408. layoutMode: 'box',
  38409. defaultOption: {
  38410. zlevel: 0,
  38411. z: 0,
  38412. left: 80,
  38413. top: 60,
  38414. right: 80,
  38415. bottom: 60,
  38416. // width: {totalWidth} - left - right,
  38417. // height: {totalHeight} - top - bottom,
  38418. layout: 'horizontal', // 'horizontal' or 'vertical'
  38419. // FIXME
  38420. // naming?
  38421. axisExpandable: false,
  38422. axisExpandCenter: null,
  38423. axisExpandCount: 0,
  38424. axisExpandWidth: 50, // FIXME '10%' ?
  38425. axisExpandRate: 17,
  38426. axisExpandDebounce: 50,
  38427. // [out, in, jumpTarget]. In percentage. If use [null, 0.05], null means full.
  38428. // Do not doc to user until necessary.
  38429. axisExpandSlideTriggerArea: [-0.15, 0.05, 0.4],
  38430. axisExpandTriggerOn: 'click', // 'mousemove' or 'click'
  38431. parallelAxisDefault: null
  38432. },
  38433. /**
  38434. * @override
  38435. */
  38436. init: function () {
  38437. Component.prototype.init.apply(this, arguments);
  38438. this.mergeOption({});
  38439. },
  38440. /**
  38441. * @override
  38442. */
  38443. mergeOption: function (newOption) {
  38444. var thisOption = this.option;
  38445. newOption && zrUtil.merge(thisOption, newOption, true);
  38446. this._initDimensions();
  38447. },
  38448. /**
  38449. * Whether series or axis is in this coordinate system.
  38450. * @param {module:echarts/model/Series|module:echarts/coord/parallel/AxisModel} model
  38451. * @param {module:echarts/model/Global} ecModel
  38452. */
  38453. contains: function (model, ecModel) {
  38454. var parallelIndex = model.get('parallelIndex');
  38455. return parallelIndex != null
  38456. && ecModel.getComponent('parallel', parallelIndex) === this;
  38457. },
  38458. setAxisExpand: function (opt) {
  38459. zrUtil.each(
  38460. ['axisExpandable', 'axisExpandCenter', 'axisExpandCount', 'axisExpandWidth', 'axisExpandWindow'],
  38461. function (name) {
  38462. if (opt.hasOwnProperty(name)) {
  38463. this.option[name] = opt[name];
  38464. }
  38465. },
  38466. this
  38467. );
  38468. },
  38469. /**
  38470. * @private
  38471. */
  38472. _initDimensions: function () {
  38473. var dimensions = this.dimensions = [];
  38474. var parallelAxisIndex = this.parallelAxisIndex = [];
  38475. var axisModels = zrUtil.filter(this.dependentModels.parallelAxis, function (axisModel) {
  38476. // Can not use this.contains here, because
  38477. // initialization has not been completed yet.
  38478. return axisModel.get('parallelIndex') === this.componentIndex;
  38479. });
  38480. zrUtil.each(axisModels, function (axisModel) {
  38481. dimensions.push('dim' + axisModel.get('dim'));
  38482. parallelAxisIndex.push(axisModel.componentIndex);
  38483. });
  38484. }
  38485. });
  38486. /***/ },
  38487. /* 240 */
  38488. /***/ function(module, exports, __webpack_require__) {
  38489. var ComponentModel = __webpack_require__(69);
  38490. var zrUtil = __webpack_require__(4);
  38491. var makeStyleMapper = __webpack_require__(15);
  38492. var axisModelCreator = __webpack_require__(131);
  38493. var numberUtil = __webpack_require__(7);
  38494. var AxisModel = ComponentModel.extend({
  38495. type: 'baseParallelAxis',
  38496. /**
  38497. * @type {module:echarts/coord/parallel/Axis}
  38498. */
  38499. axis: null,
  38500. /**
  38501. * @type {Array.<Array.<number>}
  38502. * @readOnly
  38503. */
  38504. activeIntervals: [],
  38505. /**
  38506. * @return {Object}
  38507. */
  38508. getAreaSelectStyle: function () {
  38509. return makeStyleMapper(
  38510. [
  38511. ['fill', 'color'],
  38512. ['lineWidth', 'borderWidth'],
  38513. ['stroke', 'borderColor'],
  38514. ['width', 'width'],
  38515. ['opacity', 'opacity']
  38516. ]
  38517. ).call(this.getModel('areaSelectStyle'));
  38518. },
  38519. /**
  38520. * The code of this feature is put on AxisModel but not ParallelAxis,
  38521. * because axisModel can be alive after echarts updating but instance of
  38522. * ParallelAxis having been disposed. this._activeInterval should be kept
  38523. * when action dispatched (i.e. legend click).
  38524. *
  38525. * @param {Array.<Array<number>>} intervals interval.length === 0
  38526. * means set all active.
  38527. * @public
  38528. */
  38529. setActiveIntervals: function (intervals) {
  38530. var activeIntervals = this.activeIntervals = zrUtil.clone(intervals);
  38531. // Normalize
  38532. if (activeIntervals) {
  38533. for (var i = activeIntervals.length - 1; i >= 0; i--) {
  38534. numberUtil.asc(activeIntervals[i]);
  38535. }
  38536. }
  38537. },
  38538. /**
  38539. * @param {number|string} [value] When attempting to detect 'no activeIntervals set',
  38540. * value can not be input.
  38541. * @return {string} 'normal': no activeIntervals set,
  38542. * 'active',
  38543. * 'inactive'.
  38544. * @public
  38545. */
  38546. getActiveState: function (value) {
  38547. var activeIntervals = this.activeIntervals;
  38548. if (!activeIntervals.length) {
  38549. return 'normal';
  38550. }
  38551. if (value == null) {
  38552. return 'inactive';
  38553. }
  38554. for (var i = 0, len = activeIntervals.length; i < len; i++) {
  38555. if (activeIntervals[i][0] <= value && value <= activeIntervals[i][1]) {
  38556. return 'active';
  38557. }
  38558. }
  38559. return 'inactive';
  38560. }
  38561. });
  38562. var defaultOption = {
  38563. type: 'value',
  38564. /**
  38565. * @type {Array.<number>}
  38566. */
  38567. dim: null, // 0, 1, 2, ...
  38568. // parallelIndex: null,
  38569. areaSelectStyle: {
  38570. width: 20,
  38571. borderWidth: 1,
  38572. borderColor: 'rgba(160,197,232)',
  38573. color: 'rgba(160,197,232)',
  38574. opacity: 0.3
  38575. },
  38576. realtime: true, // Whether realtime update view when select.
  38577. z: 10
  38578. };
  38579. zrUtil.merge(AxisModel.prototype, __webpack_require__(112));
  38580. function getAxisType(axisName, option) {
  38581. return option.type || (option.data ? 'category' : 'value');
  38582. }
  38583. axisModelCreator('parallel', AxisModel, getAxisType, defaultOption);
  38584. module.exports = AxisModel;
  38585. /***/ },
  38586. /* 241 */
  38587. /***/ function(module, exports, __webpack_require__) {
  38588. __webpack_require__(235);
  38589. __webpack_require__(242);
  38590. __webpack_require__(243);
  38591. /***/ },
  38592. /* 242 */
  38593. /***/ function(module, exports, __webpack_require__) {
  38594. var echarts = __webpack_require__(1);
  38595. /**
  38596. * @payload
  38597. * @property {string} parallelAxisId
  38598. * @property {Array.<Array.<number>>} intervals
  38599. */
  38600. var actionInfo = {
  38601. type: 'axisAreaSelect',
  38602. event: 'axisAreaSelected',
  38603. update: 'updateVisual'
  38604. };
  38605. echarts.registerAction(actionInfo, function (payload, ecModel) {
  38606. ecModel.eachComponent(
  38607. {mainType: 'parallelAxis', query: payload},
  38608. function (parallelAxisModel) {
  38609. parallelAxisModel.axis.model.setActiveIntervals(payload.intervals);
  38610. }
  38611. );
  38612. });
  38613. /**
  38614. * @payload
  38615. */
  38616. echarts.registerAction('parallelAxisExpand', function (payload, ecModel) {
  38617. ecModel.eachComponent(
  38618. {mainType: 'parallel', query: payload},
  38619. function (parallelModel) {
  38620. parallelModel.setAxisExpand(payload);
  38621. }
  38622. );
  38623. });
  38624. /***/ },
  38625. /* 243 */
  38626. /***/ function(module, exports, __webpack_require__) {
  38627. var zrUtil = __webpack_require__(4);
  38628. var AxisBuilder = __webpack_require__(135);
  38629. var BrushController = __webpack_require__(244);
  38630. var brushHelper = __webpack_require__(245);
  38631. var graphic = __webpack_require__(18);
  38632. var elementList = ['axisLine', 'axisLabel', 'axisTick', 'axisName'];
  38633. var AxisView = __webpack_require__(1).extendComponentView({
  38634. type: 'parallelAxis',
  38635. /**
  38636. * @override
  38637. */
  38638. init: function (ecModel, api) {
  38639. AxisView.superApply(this, 'init', arguments);
  38640. /**
  38641. * @type {module:echarts/component/helper/BrushController}
  38642. */
  38643. (this._brushController = new BrushController(api.getZr()))
  38644. .on('brush', zrUtil.bind(this._onBrush, this));
  38645. },
  38646. /**
  38647. * @override
  38648. */
  38649. render: function (axisModel, ecModel, api, payload) {
  38650. if (fromAxisAreaSelect(axisModel, ecModel, payload)) {
  38651. return;
  38652. }
  38653. this.axisModel = axisModel;
  38654. this.api = api;
  38655. this.group.removeAll();
  38656. var oldAxisGroup = this._axisGroup;
  38657. this._axisGroup = new graphic.Group();
  38658. this.group.add(this._axisGroup);
  38659. if (!axisModel.get('show')) {
  38660. return;
  38661. }
  38662. var coordSysModel = getCoordSysModel(axisModel, ecModel);
  38663. var coordSys = coordSysModel.coordinateSystem;
  38664. var areaSelectStyle = axisModel.getAreaSelectStyle();
  38665. var areaWidth = areaSelectStyle.width;
  38666. var dim = axisModel.axis.dim;
  38667. var axisLayout = coordSys.getAxisLayout(dim);
  38668. var builderOpt = zrUtil.extend(
  38669. {strokeContainThreshold: areaWidth},
  38670. axisLayout
  38671. );
  38672. var axisBuilder = new AxisBuilder(axisModel, builderOpt);
  38673. zrUtil.each(elementList, axisBuilder.add, axisBuilder);
  38674. this._axisGroup.add(axisBuilder.getGroup());
  38675. this._refreshBrushController(
  38676. builderOpt, areaSelectStyle, axisModel, coordSysModel, areaWidth, api
  38677. );
  38678. var animationModel = (payload && payload.animation === false) ? null : axisModel;
  38679. graphic.groupTransition(oldAxisGroup, this._axisGroup, animationModel);
  38680. },
  38681. /**
  38682. * @override
  38683. */
  38684. updateVisual: function (axisModel, ecModel, api, payload) {
  38685. this._brushController && this._brushController
  38686. .updateCovers(getCoverInfoList(axisModel));
  38687. },
  38688. _refreshBrushController: function (
  38689. builderOpt, areaSelectStyle, axisModel, coordSysModel, areaWidth, api
  38690. ) {
  38691. // After filtering, axis may change, select area needs to be update.
  38692. var extent = axisModel.axis.getExtent();
  38693. var extentLen = extent[1] - extent[0];
  38694. var extra = Math.min(30, Math.abs(extentLen) * 0.1); // Arbitrary value.
  38695. // width/height might be negative, which will be
  38696. // normalized in BoundingRect.
  38697. var rect = graphic.BoundingRect.create({
  38698. x: extent[0],
  38699. y: -areaWidth / 2,
  38700. width: extentLen,
  38701. height: areaWidth
  38702. });
  38703. rect.x -= extra;
  38704. rect.width += 2 * extra;
  38705. this._brushController
  38706. .mount({
  38707. enableGlobalPan: true,
  38708. rotation: builderOpt.rotation,
  38709. position: builderOpt.position
  38710. })
  38711. .setPanels([{
  38712. panelId: 'pl',
  38713. clipPath: brushHelper.makeRectPanelClipPath(rect),
  38714. isTargetByCursor: brushHelper.makeRectIsTargetByCursor(rect, api, coordSysModel),
  38715. getLinearBrushOtherExtent: brushHelper.makeLinearBrushOtherExtent(rect, 0)
  38716. }])
  38717. .enableBrush({
  38718. brushType: 'lineX',
  38719. brushStyle: areaSelectStyle,
  38720. removeOnClick: true
  38721. })
  38722. .updateCovers(getCoverInfoList(axisModel));
  38723. },
  38724. _onBrush: function (coverInfoList, opt) {
  38725. // Do not cache these object, because the mey be changed.
  38726. var axisModel = this.axisModel;
  38727. var axis = axisModel.axis;
  38728. var intervals = zrUtil.map(coverInfoList, function (coverInfo) {
  38729. return [
  38730. axis.coordToData(coverInfo.range[0], true),
  38731. axis.coordToData(coverInfo.range[1], true)
  38732. ];
  38733. });
  38734. // If realtime is true, action is not dispatched on drag end, because
  38735. // the drag end emits the same params with the last drag move event,
  38736. // and may have some delay when using touch pad.
  38737. if (!axisModel.option.realtime === opt.isEnd || opt.removeOnClick) { // jshint ignore:line
  38738. this.api.dispatchAction({
  38739. type: 'axisAreaSelect',
  38740. parallelAxisId: axisModel.id,
  38741. intervals: intervals
  38742. });
  38743. }
  38744. },
  38745. /**
  38746. * @override
  38747. */
  38748. dispose: function () {
  38749. this._brushController.dispose();
  38750. }
  38751. });
  38752. function fromAxisAreaSelect(axisModel, ecModel, payload) {
  38753. return payload
  38754. && payload.type === 'axisAreaSelect'
  38755. && ecModel.findComponents(
  38756. {mainType: 'parallelAxis', query: payload}
  38757. )[0] === axisModel;
  38758. }
  38759. function getCoverInfoList(axisModel) {
  38760. var axis = axisModel.axis;
  38761. return zrUtil.map(axisModel.activeIntervals, function (interval) {
  38762. return {
  38763. brushType: 'lineX',
  38764. panelId: 'pl',
  38765. range: [
  38766. axis.dataToCoord(interval[0], true),
  38767. axis.dataToCoord(interval[1], true)
  38768. ]
  38769. };
  38770. });
  38771. }
  38772. function getCoordSysModel(axisModel, ecModel) {
  38773. return ecModel.getComponent(
  38774. 'parallel', axisModel.get('parallelIndex')
  38775. );
  38776. }
  38777. module.exports = AxisView;
  38778. /***/ },
  38779. /* 244 */
  38780. /***/ function(module, exports, __webpack_require__) {
  38781. /**
  38782. * Box selection tool.
  38783. *
  38784. * @module echarts/component/helper/BrushController
  38785. */
  38786. var Eventful = __webpack_require__(25);
  38787. var zrUtil = __webpack_require__(4);
  38788. var graphic = __webpack_require__(18);
  38789. var interactionMutex = __webpack_require__(183);
  38790. var DataDiffer = __webpack_require__(99);
  38791. var curry = zrUtil.curry;
  38792. var each = zrUtil.each;
  38793. var map = zrUtil.map;
  38794. var mathMin = Math.min;
  38795. var mathMax = Math.max;
  38796. var mathPow = Math.pow;
  38797. var COVER_Z = 10000;
  38798. var UNSELECT_THRESHOLD = 6;
  38799. var MIN_RESIZE_LINE_WIDTH = 6;
  38800. var MUTEX_RESOURCE_KEY = 'globalPan';
  38801. var DIRECTION_MAP = {
  38802. w: [0, 0],
  38803. e: [0, 1],
  38804. n: [1, 0],
  38805. s: [1, 1]
  38806. };
  38807. var CURSOR_MAP = {
  38808. w: 'ew',
  38809. e: 'ew',
  38810. n: 'ns',
  38811. s: 'ns',
  38812. ne: 'nesw',
  38813. sw: 'nesw',
  38814. nw: 'nwse',
  38815. se: 'nwse'
  38816. };
  38817. var DEFAULT_BRUSH_OPT = {
  38818. brushStyle: {
  38819. lineWidth: 2,
  38820. stroke: 'rgba(0,0,0,0.3)',
  38821. fill: 'rgba(0,0,0,0.1)'
  38822. },
  38823. transformable: true,
  38824. brushMode: 'single',
  38825. removeOnClick: false
  38826. };
  38827. var baseUID = 0;
  38828. /**
  38829. * @alias module:echarts/component/helper/BrushController
  38830. * @constructor
  38831. * @mixin {module:zrender/mixin/Eventful}
  38832. * @event module:echarts/component/helper/BrushController#brush
  38833. * params:
  38834. * areas: Array.<Array>, coord relates to container group,
  38835. * If no container specified, to global.
  38836. * opt {
  38837. * isEnd: boolean,
  38838. * removeOnClick: boolean
  38839. * }
  38840. *
  38841. * @param {module:zrender/zrender~ZRender} zr
  38842. */
  38843. function BrushController(zr) {
  38844. if (true) {
  38845. zrUtil.assert(zr);
  38846. }
  38847. Eventful.call(this);
  38848. /**
  38849. * @type {module:zrender/zrender~ZRender}
  38850. * @private
  38851. */
  38852. this._zr = zr;
  38853. /**
  38854. * @type {module:zrender/container/Group}
  38855. * @readOnly
  38856. */
  38857. this.group = new graphic.Group();
  38858. /**
  38859. * Only for drawing (after enabledBrush).
  38860. * 'line', 'rect', 'polygon' or false
  38861. * If passing false/null/undefined, disable brush.
  38862. * If passing 'auto', determined by panel.defaultBrushType
  38863. * @private
  38864. * @type {string}
  38865. */
  38866. this._brushType;
  38867. /**
  38868. * Only for drawing (after enabledBrush).
  38869. *
  38870. * @private
  38871. * @type {Object}
  38872. */
  38873. this._brushOption;
  38874. /**
  38875. * @private
  38876. * @type {Object}
  38877. */
  38878. this._panels;
  38879. /**
  38880. * @private
  38881. * @type {Array.<nubmer>}
  38882. */
  38883. this._track = [];
  38884. /**
  38885. * @private
  38886. * @type {boolean}
  38887. */
  38888. this._dragging;
  38889. /**
  38890. * @private
  38891. * @type {Array}
  38892. */
  38893. this._covers = [];
  38894. /**
  38895. * @private
  38896. * @type {moudule:zrender/container/Group}
  38897. */
  38898. this._creatingCover;
  38899. /**
  38900. * `true` means global panel
  38901. * @private
  38902. * @type {module:zrender/container/Group|boolean}
  38903. */
  38904. this._creatingPanel;
  38905. /**
  38906. * @private
  38907. * @type {boolean}
  38908. */
  38909. this._enableGlobalPan;
  38910. /**
  38911. * @private
  38912. * @type {boolean}
  38913. */
  38914. if (true) {
  38915. this._mounted;
  38916. }
  38917. /**
  38918. * @private
  38919. * @type {string}
  38920. */
  38921. this._uid = 'brushController_' + baseUID++;
  38922. /**
  38923. * @private
  38924. * @type {Object}
  38925. */
  38926. this._handlers = {};
  38927. each(mouseHandlers, function (handler, eventName) {
  38928. this._handlers[eventName] = zrUtil.bind(handler, this);
  38929. }, this);
  38930. }
  38931. BrushController.prototype = {
  38932. constructor: BrushController,
  38933. /**
  38934. * If set to null/undefined/false, select disabled.
  38935. * @param {Object} brushOption
  38936. * @param {string|boolean} brushOption.brushType 'line', 'rect', 'polygon' or false
  38937. * If passing false/null/undefined, disable brush.
  38938. * If passing 'auto', determined by panel.defaultBrushType.
  38939. * ('auto' can not be used in global panel)
  38940. * @param {number} [brushOption.brushMode='single'] 'single' or 'multiple'
  38941. * @param {boolean} [brushOption.transformable=true]
  38942. * @param {boolean} [brushOption.removeOnClick=false]
  38943. * @param {Object} [brushOption.brushStyle]
  38944. * @param {number} [brushOption.brushStyle.width]
  38945. * @param {number} [brushOption.brushStyle.lineWidth]
  38946. * @param {string} [brushOption.brushStyle.stroke]
  38947. * @param {string} [brushOption.brushStyle.fill]
  38948. * @param {number} [brushOption.z]
  38949. */
  38950. enableBrush: function (brushOption) {
  38951. if (true) {
  38952. zrUtil.assert(this._mounted);
  38953. }
  38954. this._brushType && doDisableBrush(this);
  38955. brushOption.brushType && doEnableBrush(this, brushOption);
  38956. return this;
  38957. },
  38958. /**
  38959. * @param {Array.<Object>} panelOpts If not pass, it is global brush.
  38960. * Each items: {
  38961. * panelId, // mandatory.
  38962. * clipPath, // mandatory. function.
  38963. * isTargetByCursor, // mandatory. function.
  38964. * defaultBrushType, // optional, only used when brushType is 'auto'.
  38965. * getLinearBrushOtherExtent, // optional. function.
  38966. * }
  38967. */
  38968. setPanels: function (panelOpts) {
  38969. if (panelOpts && panelOpts.length) {
  38970. var panels = this._panels = {};
  38971. zrUtil.each(panelOpts, function (panelOpts) {
  38972. panels[panelOpts.panelId] = zrUtil.clone(panelOpts);
  38973. });
  38974. }
  38975. else {
  38976. this._panels = null;
  38977. }
  38978. return this;
  38979. },
  38980. /**
  38981. * @param {Object} [opt]
  38982. * @return {boolean} [opt.enableGlobalPan=false]
  38983. */
  38984. mount: function (opt) {
  38985. opt = opt || {};
  38986. if (true) {
  38987. this._mounted = true; // should be at first.
  38988. }
  38989. this._enableGlobalPan = opt.enableGlobalPan;
  38990. var thisGroup = this.group;
  38991. this._zr.add(thisGroup);
  38992. thisGroup.attr({
  38993. position: opt.position || [0, 0],
  38994. rotation: opt.rotation || 0,
  38995. scale: opt.scale || [1, 1]
  38996. });
  38997. this._transform = thisGroup.getLocalTransform();
  38998. return this;
  38999. },
  39000. eachCover: function (cb, context) {
  39001. each(this._covers, cb, context);
  39002. },
  39003. /**
  39004. * Update covers.
  39005. * @param {Array.<Object>} brushOptionList Like:
  39006. * [
  39007. * {id: 'xx', brushType: 'line', range: [23, 44], brushStyle, transformable},
  39008. * {id: 'yy', brushType: 'rect', range: [[23, 44], [23, 54]]},
  39009. * ...
  39010. * ]
  39011. * `brushType` is required in each cover info. (can not be 'auto')
  39012. * `id` is not mandatory.
  39013. * `brushStyle`, `transformable` is not mandatory, use DEFAULT_BRUSH_OPT by default.
  39014. * If brushOptionList is null/undefined, all covers removed.
  39015. */
  39016. updateCovers: function (brushOptionList) {
  39017. if (true) {
  39018. zrUtil.assert(this._mounted);
  39019. }
  39020. brushOptionList = zrUtil.map(brushOptionList, function (brushOption) {
  39021. return zrUtil.merge(zrUtil.clone(DEFAULT_BRUSH_OPT), brushOption, true);
  39022. });
  39023. var tmpIdPrefix = '\0-brush-index-';
  39024. var oldCovers = this._covers;
  39025. var newCovers = this._covers = [];
  39026. var controller = this;
  39027. var creatingCover = this._creatingCover;
  39028. (new DataDiffer(oldCovers, brushOptionList, oldGetKey, getKey))
  39029. .add(addOrUpdate)
  39030. .update(addOrUpdate)
  39031. .remove(remove)
  39032. .execute();
  39033. return this;
  39034. function getKey(brushOption, index) {
  39035. return (brushOption.id != null ? brushOption.id : tmpIdPrefix + index)
  39036. + '-' + brushOption.brushType;
  39037. }
  39038. function oldGetKey(cover, index) {
  39039. return getKey(cover.__brushOption, index);
  39040. }
  39041. function addOrUpdate(newIndex, oldIndex) {
  39042. var newBrushOption = brushOptionList[newIndex];
  39043. // Consider setOption in event listener of brushSelect,
  39044. // where updating cover when creating should be forbiden.
  39045. if (oldIndex != null && oldCovers[oldIndex] === creatingCover) {
  39046. newCovers[newIndex] = oldCovers[oldIndex];
  39047. }
  39048. else {
  39049. var cover = newCovers[newIndex] = oldIndex != null
  39050. ? (
  39051. oldCovers[oldIndex].__brushOption = newBrushOption,
  39052. oldCovers[oldIndex]
  39053. )
  39054. : endCreating(controller, createCover(controller, newBrushOption));
  39055. updateCoverAfterCreation(controller, cover);
  39056. }
  39057. }
  39058. function remove(oldIndex) {
  39059. if (oldCovers[oldIndex] !== creatingCover) {
  39060. controller.group.remove(oldCovers[oldIndex]);
  39061. }
  39062. }
  39063. },
  39064. unmount: function () {
  39065. if (true) {
  39066. if (!this._mounted) {
  39067. return;
  39068. }
  39069. }
  39070. this.enableBrush(false);
  39071. // container may 'removeAll' outside.
  39072. clearCovers(this);
  39073. this._zr.remove(this.group);
  39074. if (true) {
  39075. this._mounted = false; // should be at last.
  39076. }
  39077. return this;
  39078. },
  39079. dispose: function () {
  39080. this.unmount();
  39081. this.off();
  39082. }
  39083. };
  39084. zrUtil.mixin(BrushController, Eventful);
  39085. function doEnableBrush(controller, brushOption) {
  39086. var zr = controller._zr;
  39087. // Consider roam, which takes globalPan too.
  39088. if (!controller._enableGlobalPan) {
  39089. interactionMutex.take(zr, MUTEX_RESOURCE_KEY, controller._uid);
  39090. }
  39091. each(controller._handlers, function (handler, eventName) {
  39092. zr.on(eventName, handler);
  39093. });
  39094. controller._brushType = brushOption.brushType;
  39095. controller._brushOption = zrUtil.merge(zrUtil.clone(DEFAULT_BRUSH_OPT), brushOption, true);
  39096. }
  39097. function doDisableBrush(controller) {
  39098. var zr = controller._zr;
  39099. interactionMutex.release(zr, MUTEX_RESOURCE_KEY, controller._uid);
  39100. each(controller._handlers, function (handler, eventName) {
  39101. zr.off(eventName, handler);
  39102. });
  39103. controller._brushType = controller._brushOption = null;
  39104. }
  39105. function createCover(controller, brushOption) {
  39106. var cover = coverRenderers[brushOption.brushType].createCover(controller, brushOption);
  39107. cover.__brushOption = brushOption;
  39108. updateZ(cover, brushOption);
  39109. controller.group.add(cover);
  39110. return cover;
  39111. }
  39112. function endCreating(controller, creatingCover) {
  39113. var coverRenderer = getCoverRenderer(creatingCover);
  39114. if (coverRenderer.endCreating) {
  39115. coverRenderer.endCreating(controller, creatingCover);
  39116. updateZ(creatingCover, creatingCover.__brushOption);
  39117. }
  39118. return creatingCover;
  39119. }
  39120. function updateCoverShape(controller, cover) {
  39121. var brushOption = cover.__brushOption;
  39122. getCoverRenderer(cover).updateCoverShape(
  39123. controller, cover, brushOption.range, brushOption
  39124. );
  39125. }
  39126. function updateZ(cover, brushOption) {
  39127. var z = brushOption.z;
  39128. z == null && (z = COVER_Z);
  39129. cover.traverse(function (el) {
  39130. el.z = z;
  39131. el.z2 = z; // Consider in given container.
  39132. });
  39133. }
  39134. function updateCoverAfterCreation(controller, cover) {
  39135. getCoverRenderer(cover).updateCommon(controller, cover);
  39136. updateCoverShape(controller, cover);
  39137. }
  39138. function getCoverRenderer(cover) {
  39139. return coverRenderers[cover.__brushOption.brushType];
  39140. }
  39141. // return target panel or `true` (means global panel)
  39142. function getPanelByPoint(controller, e, localCursorPoint) {
  39143. var panels = controller._panels;
  39144. if (!panels) {
  39145. return true; // Global panel
  39146. }
  39147. var panel;
  39148. var transform = controller._transform;
  39149. each(panels, function (pn) {
  39150. pn.isTargetByCursor(e, localCursorPoint, transform) && (panel = pn);
  39151. });
  39152. return panel;
  39153. }
  39154. // Return a panel or true
  39155. function getPanelByCover(controller, cover) {
  39156. var panels = controller._panels;
  39157. if (!panels) {
  39158. return true; // Global panel
  39159. }
  39160. var panelId = cover.__brushOption.panelId;
  39161. // User may give cover without coord sys info,
  39162. // which is then treated as global panel.
  39163. return panelId != null ? panels[panelId] : true;
  39164. }
  39165. function clearCovers(controller) {
  39166. var covers = controller._covers;
  39167. var originalLength = covers.length;
  39168. each(covers, function (cover) {
  39169. controller.group.remove(cover);
  39170. }, controller);
  39171. covers.length = 0;
  39172. return !!originalLength;
  39173. }
  39174. function trigger(controller, opt) {
  39175. var areas = map(controller._covers, function (cover) {
  39176. var brushOption = cover.__brushOption;
  39177. var range = zrUtil.clone(brushOption.range);
  39178. return {
  39179. brushType: brushOption.brushType,
  39180. panelId: brushOption.panelId,
  39181. range: range
  39182. };
  39183. });
  39184. controller.trigger('brush', areas, {
  39185. isEnd: !!opt.isEnd,
  39186. removeOnClick: !!opt.removeOnClick
  39187. });
  39188. }
  39189. function shouldShowCover(controller) {
  39190. var track = controller._track;
  39191. if (!track.length) {
  39192. return false;
  39193. }
  39194. var p2 = track[track.length - 1];
  39195. var p1 = track[0];
  39196. var dx = p2[0] - p1[0];
  39197. var dy = p2[1] - p1[1];
  39198. var dist = mathPow(dx * dx + dy * dy, 0.5);
  39199. return dist > UNSELECT_THRESHOLD;
  39200. }
  39201. function getTrackEnds(track) {
  39202. var tail = track.length - 1;
  39203. tail < 0 && (tail = 0);
  39204. return [track[0], track[tail]];
  39205. }
  39206. function createBaseRectCover(doDrift, controller, brushOption, edgeNames) {
  39207. var cover = new graphic.Group();
  39208. cover.add(new graphic.Rect({
  39209. name: 'main',
  39210. style: makeStyle(brushOption),
  39211. silent: true,
  39212. draggable: true,
  39213. cursor: 'move',
  39214. drift: curry(doDrift, controller, cover, 'nswe'),
  39215. ondragend: curry(trigger, controller, {isEnd: true})
  39216. }));
  39217. each(
  39218. edgeNames,
  39219. function (name) {
  39220. cover.add(new graphic.Rect({
  39221. name: name,
  39222. style: {opacity: 0},
  39223. draggable: true,
  39224. silent: true,
  39225. invisible: true,
  39226. drift: curry(doDrift, controller, cover, name),
  39227. ondragend: curry(trigger, controller, {isEnd: true})
  39228. }));
  39229. }
  39230. );
  39231. return cover;
  39232. }
  39233. function updateBaseRect(controller, cover, localRange, brushOption) {
  39234. var lineWidth = brushOption.brushStyle.lineWidth || 0;
  39235. var handleSize = mathMax(lineWidth, MIN_RESIZE_LINE_WIDTH);
  39236. var x = localRange[0][0];
  39237. var y = localRange[1][0];
  39238. var xa = x - lineWidth / 2;
  39239. var ya = y - lineWidth / 2;
  39240. var x2 = localRange[0][1];
  39241. var y2 = localRange[1][1];
  39242. var x2a = x2 - handleSize + lineWidth / 2;
  39243. var y2a = y2 - handleSize + lineWidth / 2;
  39244. var width = x2 - x;
  39245. var height = y2 - y;
  39246. var widtha = width + lineWidth;
  39247. var heighta = height + lineWidth;
  39248. updateRectShape(controller, cover, 'main', x, y, width, height);
  39249. if (brushOption.transformable) {
  39250. updateRectShape(controller, cover, 'w', xa, ya, handleSize, heighta);
  39251. updateRectShape(controller, cover, 'e', x2a, ya, handleSize, heighta);
  39252. updateRectShape(controller, cover, 'n', xa, ya, widtha, handleSize);
  39253. updateRectShape(controller, cover, 's', xa, y2a, widtha, handleSize);
  39254. updateRectShape(controller, cover, 'nw', xa, ya, handleSize, handleSize);
  39255. updateRectShape(controller, cover, 'ne', x2a, ya, handleSize, handleSize);
  39256. updateRectShape(controller, cover, 'sw', xa, y2a, handleSize, handleSize);
  39257. updateRectShape(controller, cover, 'se', x2a, y2a, handleSize, handleSize);
  39258. }
  39259. }
  39260. function updateCommon(controller, cover) {
  39261. var brushOption = cover.__brushOption;
  39262. var transformable = brushOption.transformable;
  39263. var mainEl = cover.childAt(0);
  39264. mainEl.useStyle(makeStyle(brushOption));
  39265. mainEl.attr({
  39266. silent: !transformable,
  39267. cursor: transformable ? 'move' : 'default'
  39268. });
  39269. each(
  39270. ['w', 'e', 'n', 's', 'se', 'sw', 'ne', 'nw'],
  39271. function (name) {
  39272. var el = cover.childOfName(name);
  39273. var globalDir = getGlobalDirection(controller, name);
  39274. el && el.attr({
  39275. silent: !transformable,
  39276. invisible: !transformable,
  39277. cursor: transformable ? CURSOR_MAP[globalDir] + '-resize' : null
  39278. });
  39279. }
  39280. );
  39281. }
  39282. function updateRectShape(controller, cover, name, x, y, w, h) {
  39283. var el = cover.childOfName(name);
  39284. el && el.setShape(pointsToRect(
  39285. clipByPanel(controller, cover, [[x, y], [x + w, y + h]])
  39286. ));
  39287. }
  39288. function makeStyle(brushOption) {
  39289. return zrUtil.defaults({strokeNoScale: true}, brushOption.brushStyle);
  39290. }
  39291. function formatRectRange(x, y, x2, y2) {
  39292. var min = [mathMin(x, x2), mathMin(y, y2)];
  39293. var max = [mathMax(x, x2), mathMax(y, y2)];
  39294. return [
  39295. [min[0], max[0]], // x range
  39296. [min[1], max[1]] // y range
  39297. ];
  39298. }
  39299. function getTransform(controller) {
  39300. return graphic.getTransform(controller.group);
  39301. }
  39302. function getGlobalDirection(controller, localDirection) {
  39303. if (localDirection.length > 1) {
  39304. localDirection = localDirection.split('');
  39305. var globalDir = [
  39306. getGlobalDirection(controller, localDirection[0]),
  39307. getGlobalDirection(controller, localDirection[1])
  39308. ];
  39309. (globalDir[0] === 'e' || globalDir[0] === 'w') && globalDir.reverse();
  39310. return globalDir.join('');
  39311. }
  39312. else {
  39313. var map = {w: 'left', e: 'right', n: 'top', s: 'bottom'};
  39314. var inverseMap = {left: 'w', right: 'e', top: 'n', bottom: 's'};
  39315. var globalDir = graphic.transformDirection(
  39316. map[localDirection], getTransform(controller)
  39317. );
  39318. return inverseMap[globalDir];
  39319. }
  39320. }
  39321. function driftRect(toRectRange, fromRectRange, controller, cover, name, dx, dy, e) {
  39322. var brushOption = cover.__brushOption;
  39323. var rectRange = toRectRange(brushOption.range);
  39324. var localDelta = toLocalDelta(controller, dx, dy);
  39325. each(name.split(''), function (namePart) {
  39326. var ind = DIRECTION_MAP[namePart];
  39327. rectRange[ind[0]][ind[1]] += localDelta[ind[0]];
  39328. });
  39329. brushOption.range = fromRectRange(formatRectRange(
  39330. rectRange[0][0], rectRange[1][0], rectRange[0][1], rectRange[1][1]
  39331. ));
  39332. updateCoverAfterCreation(controller, cover);
  39333. trigger(controller, {isEnd: false});
  39334. }
  39335. function driftPolygon(controller, cover, dx, dy, e) {
  39336. var range = cover.__brushOption.range;
  39337. var localDelta = toLocalDelta(controller, dx, dy);
  39338. each(range, function (point) {
  39339. point[0] += localDelta[0];
  39340. point[1] += localDelta[1];
  39341. });
  39342. updateCoverAfterCreation(controller, cover);
  39343. trigger(controller, {isEnd: false});
  39344. }
  39345. function toLocalDelta(controller, dx, dy) {
  39346. var thisGroup = controller.group;
  39347. var localD = thisGroup.transformCoordToLocal(dx, dy);
  39348. var localZero = thisGroup.transformCoordToLocal(0, 0);
  39349. return [localD[0] - localZero[0], localD[1] - localZero[1]];
  39350. }
  39351. function clipByPanel(controller, cover, data) {
  39352. var panel = getPanelByCover(controller, cover);
  39353. return (panel && panel !== true)
  39354. ? panel.clipPath(data, controller._transform)
  39355. : zrUtil.clone(data);
  39356. }
  39357. function pointsToRect(points) {
  39358. var xmin = mathMin(points[0][0], points[1][0]);
  39359. var ymin = mathMin(points[0][1], points[1][1]);
  39360. var xmax = mathMax(points[0][0], points[1][0]);
  39361. var ymax = mathMax(points[0][1], points[1][1]);
  39362. return {
  39363. x: xmin,
  39364. y: ymin,
  39365. width: xmax - xmin,
  39366. height: ymax - ymin
  39367. };
  39368. }
  39369. function resetCursor(controller, e, localCursorPoint) {
  39370. // Check active
  39371. if (!controller._brushType) {
  39372. return;
  39373. }
  39374. var zr = controller._zr;
  39375. var covers = controller._covers;
  39376. var currPanel = getPanelByPoint(controller, e, localCursorPoint);
  39377. // Check whether in covers.
  39378. if (!controller._dragging) {
  39379. for (var i = 0; i < covers.length; i++) {
  39380. var brushOption = covers[i].__brushOption;
  39381. if (currPanel
  39382. && (currPanel === true || brushOption.panelId === currPanel.panelId)
  39383. && coverRenderers[brushOption.brushType].contain(
  39384. covers[i], localCursorPoint[0], localCursorPoint[1]
  39385. )
  39386. ) {
  39387. // Use cursor style set on cover.
  39388. return;
  39389. }
  39390. }
  39391. }
  39392. currPanel && zr.setCursorStyle('crosshair');
  39393. }
  39394. function preventDefault(e) {
  39395. var rawE = e.event;
  39396. rawE.preventDefault && rawE.preventDefault();
  39397. }
  39398. function mainShapeContain(cover, x, y) {
  39399. return cover.childOfName('main').contain(x, y);
  39400. }
  39401. function updateCoverByMouse(controller, e, localCursorPoint, isEnd) {
  39402. var creatingCover = controller._creatingCover;
  39403. var panel = controller._creatingPanel;
  39404. var thisBrushOption = controller._brushOption;
  39405. var eventParams;
  39406. controller._track.push(localCursorPoint.slice());
  39407. if (shouldShowCover(controller) || creatingCover) {
  39408. if (panel && !creatingCover) {
  39409. thisBrushOption.brushMode === 'single' && clearCovers(controller);
  39410. var brushOption = zrUtil.clone(thisBrushOption);
  39411. brushOption.brushType = determineBrushType(brushOption.brushType, panel);
  39412. brushOption.panelId = panel === true ? null : panel.panelId;
  39413. creatingCover = controller._creatingCover = createCover(controller, brushOption);
  39414. controller._covers.push(creatingCover);
  39415. }
  39416. if (creatingCover) {
  39417. var coverRenderer = coverRenderers[determineBrushType(controller._brushType, panel)];
  39418. var coverBrushOption = creatingCover.__brushOption;
  39419. coverBrushOption.range = coverRenderer.getCreatingRange(
  39420. clipByPanel(controller, creatingCover, controller._track)
  39421. );
  39422. if (isEnd) {
  39423. endCreating(controller, creatingCover);
  39424. coverRenderer.updateCommon(controller, creatingCover);
  39425. }
  39426. updateCoverShape(controller, creatingCover);
  39427. eventParams = {isEnd: isEnd};
  39428. }
  39429. }
  39430. else if (
  39431. isEnd
  39432. && thisBrushOption.brushMode === 'single'
  39433. && thisBrushOption.removeOnClick
  39434. ) {
  39435. // Help user to remove covers easily, only by a tiny drag, in 'single' mode.
  39436. // But a single click do not clear covers, because user may have casual
  39437. // clicks (for example, click on other component and do not expect covers
  39438. // disappear).
  39439. // Only some cover removed, trigger action, but not every click trigger action.
  39440. if (getPanelByPoint(controller, e, localCursorPoint) && clearCovers(controller)) {
  39441. eventParams = {isEnd: isEnd, removeOnClick: true};
  39442. }
  39443. }
  39444. return eventParams;
  39445. }
  39446. function determineBrushType(brushType, panel) {
  39447. if (brushType === 'auto') {
  39448. if (true) {
  39449. zrUtil.assert(
  39450. panel && panel.defaultBrushType,
  39451. 'MUST have defaultBrushType when brushType is "atuo"'
  39452. );
  39453. }
  39454. return panel.defaultBrushType;
  39455. }
  39456. return brushType;
  39457. }
  39458. var mouseHandlers = {
  39459. mousedown: function (e) {
  39460. if (this._dragging) {
  39461. // In case some browser do not support globalOut,
  39462. // and release mose out side the browser.
  39463. handleDragEnd.call(this, e);
  39464. }
  39465. else if (!e.target || !e.target.draggable) {
  39466. preventDefault(e);
  39467. var localCursorPoint = this.group.transformCoordToLocal(e.offsetX, e.offsetY);
  39468. this._creatingCover = null;
  39469. var panel = this._creatingPanel = getPanelByPoint(this, e, localCursorPoint);
  39470. if (panel) {
  39471. this._dragging = true;
  39472. this._track = [localCursorPoint.slice()];
  39473. }
  39474. }
  39475. },
  39476. mousemove: function (e) {
  39477. var localCursorPoint = this.group.transformCoordToLocal(e.offsetX, e.offsetY);
  39478. resetCursor(this, e, localCursorPoint);
  39479. if (this._dragging) {
  39480. preventDefault(e);
  39481. var eventParams = updateCoverByMouse(this, e, localCursorPoint, false);
  39482. eventParams && trigger(this, eventParams);
  39483. }
  39484. },
  39485. mouseup: handleDragEnd //,
  39486. // FIXME
  39487. // in tooltip, globalout should not be triggered.
  39488. // globalout: handleDragEnd
  39489. };
  39490. function handleDragEnd(e) {
  39491. if (this._dragging) {
  39492. preventDefault(e);
  39493. var localCursorPoint = this.group.transformCoordToLocal(e.offsetX, e.offsetY);
  39494. var eventParams = updateCoverByMouse(this, e, localCursorPoint, true);
  39495. this._dragging = false;
  39496. this._track = [];
  39497. this._creatingCover = null;
  39498. // trigger event shoule be at final, after procedure will be nested.
  39499. eventParams && trigger(this, eventParams);
  39500. }
  39501. }
  39502. /**
  39503. * key: brushType
  39504. * @type {Object}
  39505. */
  39506. var coverRenderers = {
  39507. lineX: getLineRenderer(0),
  39508. lineY: getLineRenderer(1),
  39509. rect: {
  39510. createCover: function (controller, brushOption) {
  39511. return createBaseRectCover(
  39512. curry(
  39513. driftRect,
  39514. function (range) {
  39515. return range;
  39516. },
  39517. function (range) {
  39518. return range;
  39519. }
  39520. ),
  39521. controller,
  39522. brushOption,
  39523. ['w', 'e', 'n', 's', 'se', 'sw', 'ne', 'nw']
  39524. );
  39525. },
  39526. getCreatingRange: function (localTrack) {
  39527. var ends = getTrackEnds(localTrack);
  39528. return formatRectRange(ends[1][0], ends[1][1], ends[0][0], ends[0][1]);
  39529. },
  39530. updateCoverShape: function (controller, cover, localRange, brushOption) {
  39531. updateBaseRect(controller, cover, localRange, brushOption);
  39532. },
  39533. updateCommon: updateCommon,
  39534. contain: mainShapeContain
  39535. },
  39536. polygon: {
  39537. createCover: function (controller, brushOption) {
  39538. var cover = new graphic.Group();
  39539. // Do not use graphic.Polygon because graphic.Polyline do not close the
  39540. // border of the shape when drawing, which is a better experience for user.
  39541. cover.add(new graphic.Polyline({
  39542. name: 'main',
  39543. style: makeStyle(brushOption),
  39544. silent: true
  39545. }));
  39546. return cover;
  39547. },
  39548. getCreatingRange: function (localTrack) {
  39549. return localTrack;
  39550. },
  39551. endCreating: function (controller, cover) {
  39552. cover.remove(cover.childAt(0));
  39553. // Use graphic.Polygon close the shape.
  39554. cover.add(new graphic.Polygon({
  39555. name: 'main',
  39556. draggable: true,
  39557. drift: curry(driftPolygon, controller, cover),
  39558. ondragend: curry(trigger, controller, {isEnd: true})
  39559. }));
  39560. },
  39561. updateCoverShape: function (controller, cover, localRange, brushOption) {
  39562. cover.childAt(0).setShape({
  39563. points: clipByPanel(controller, cover, localRange)
  39564. });
  39565. },
  39566. updateCommon: updateCommon,
  39567. contain: mainShapeContain
  39568. }
  39569. };
  39570. function getLineRenderer(xyIndex) {
  39571. return {
  39572. createCover: function (controller, brushOption) {
  39573. return createBaseRectCover(
  39574. curry(
  39575. driftRect,
  39576. function (range) {
  39577. var rectRange = [range, [0, 100]];
  39578. xyIndex && rectRange.reverse();
  39579. return rectRange;
  39580. },
  39581. function (rectRange) {
  39582. return rectRange[xyIndex];
  39583. }
  39584. ),
  39585. controller,
  39586. brushOption,
  39587. [['w', 'e'], ['n', 's']][xyIndex]
  39588. );
  39589. },
  39590. getCreatingRange: function (localTrack) {
  39591. var ends = getTrackEnds(localTrack);
  39592. var min = mathMin(ends[0][xyIndex], ends[1][xyIndex]);
  39593. var max = mathMax(ends[0][xyIndex], ends[1][xyIndex]);
  39594. return [min, max];
  39595. },
  39596. updateCoverShape: function (controller, cover, localRange, brushOption) {
  39597. var otherExtent;
  39598. // If brushWidth not specified, fit the panel.
  39599. var panel = getPanelByCover(controller, cover);
  39600. if (panel !== true && panel.getLinearBrushOtherExtent) {
  39601. otherExtent = panel.getLinearBrushOtherExtent(
  39602. xyIndex, controller._transform
  39603. );
  39604. }
  39605. else {
  39606. var zr = controller._zr;
  39607. otherExtent = [0, [zr.getWidth(), zr.getHeight()][1 - xyIndex]];
  39608. }
  39609. var rectRange = [localRange, otherExtent];
  39610. xyIndex && rectRange.reverse();
  39611. updateBaseRect(controller, cover, rectRange, brushOption);
  39612. },
  39613. updateCommon: updateCommon,
  39614. contain: mainShapeContain
  39615. };
  39616. }
  39617. module.exports = BrushController;
  39618. /***/ },
  39619. /* 245 */
  39620. /***/ function(module, exports, __webpack_require__) {
  39621. var cursorHelper = __webpack_require__(185);
  39622. var BoundingRect = __webpack_require__(9);
  39623. var graphicUtil = __webpack_require__(18);
  39624. var helper = {};
  39625. helper.makeRectPanelClipPath = function (rect) {
  39626. rect = normalizeRect(rect);
  39627. return function (localPoints, transform) {
  39628. return graphicUtil.clipPointsByRect(localPoints, rect);
  39629. };
  39630. };
  39631. helper.makeLinearBrushOtherExtent = function (rect, specifiedXYIndex) {
  39632. rect = normalizeRect(rect);
  39633. return function (xyIndex) {
  39634. var idx = specifiedXYIndex != null ? specifiedXYIndex : xyIndex;
  39635. var brushWidth = idx ? rect.width : rect.height;
  39636. var base = idx ? rect.x : rect.y;
  39637. return [base, base + (brushWidth || 0)];
  39638. };
  39639. };
  39640. helper.makeRectIsTargetByCursor = function (rect, api, targetModel) {
  39641. rect = normalizeRect(rect);
  39642. return function (e, localCursorPoint, transform) {
  39643. return rect.contain(localCursorPoint[0], localCursorPoint[1])
  39644. && !cursorHelper.onIrrelevantElement(e, api, targetModel);
  39645. };
  39646. };
  39647. // Consider width/height is negative.
  39648. function normalizeRect(rect) {
  39649. return BoundingRect.create(rect);
  39650. }
  39651. module.exports = helper;
  39652. /***/ },
  39653. /* 246 */
  39654. /***/ function(module, exports, __webpack_require__) {
  39655. var zrUtil = __webpack_require__(4);
  39656. var modelUtil = __webpack_require__(5);
  39657. module.exports = function (option) {
  39658. createParallelIfNeeded(option);
  39659. mergeAxisOptionFromParallel(option);
  39660. };
  39661. /**
  39662. * Create a parallel coordinate if not exists.
  39663. * @inner
  39664. */
  39665. function createParallelIfNeeded(option) {
  39666. if (option.parallel) {
  39667. return;
  39668. }
  39669. var hasParallelSeries = false;
  39670. zrUtil.each(option.series, function (seriesOpt) {
  39671. if (seriesOpt && seriesOpt.type === 'parallel') {
  39672. hasParallelSeries = true;
  39673. }
  39674. });
  39675. if (hasParallelSeries) {
  39676. option.parallel = [{}];
  39677. }
  39678. }
  39679. /**
  39680. * Merge aixs definition from parallel option (if exists) to axis option.
  39681. * @inner
  39682. */
  39683. function mergeAxisOptionFromParallel(option) {
  39684. var axes = modelUtil.normalizeToArray(option.parallelAxis);
  39685. zrUtil.each(axes, function (axisOption) {
  39686. if (!zrUtil.isObject(axisOption)) {
  39687. return;
  39688. }
  39689. var parallelIndex = axisOption.parallelIndex || 0;
  39690. var parallelOption = modelUtil.normalizeToArray(option.parallel)[parallelIndex];
  39691. if (parallelOption && parallelOption.parallelAxisDefault) {
  39692. zrUtil.merge(axisOption, parallelOption.parallelAxisDefault, false);
  39693. }
  39694. });
  39695. }
  39696. /***/ },
  39697. /* 247 */
  39698. /***/ function(module, exports, __webpack_require__) {
  39699. var List = __webpack_require__(98);
  39700. var zrUtil = __webpack_require__(4);
  39701. var SeriesModel = __webpack_require__(78);
  39702. var completeDimensions = __webpack_require__(110);
  39703. module.exports = SeriesModel.extend({
  39704. type: 'series.parallel',
  39705. dependencies: ['parallel'],
  39706. visualColorAccessPath: 'lineStyle.normal.color',
  39707. getInitialData: function (option, ecModel) {
  39708. var parallelModel = ecModel.getComponent(
  39709. 'parallel', this.get('parallelIndex')
  39710. );
  39711. var parallelAxisIndices = parallelModel.parallelAxisIndex;
  39712. var rawData = option.data;
  39713. var modelDims = parallelModel.dimensions;
  39714. var dataDims = generateDataDims(modelDims, rawData);
  39715. var dataDimsInfo = zrUtil.map(dataDims, function (dim, dimIndex) {
  39716. var modelDimsIndex = zrUtil.indexOf(modelDims, dim);
  39717. var axisModel = modelDimsIndex >= 0 && ecModel.getComponent(
  39718. 'parallelAxis', parallelAxisIndices[modelDimsIndex]
  39719. );
  39720. if (axisModel && axisModel.get('type') === 'category') {
  39721. translateCategoryValue(axisModel, dim, rawData);
  39722. return {name: dim, type: 'ordinal'};
  39723. }
  39724. else if (modelDimsIndex < 0) {
  39725. return completeDimensions.guessOrdinal(rawData, dimIndex)
  39726. ? {name: dim, type: 'ordinal'}
  39727. : dim;
  39728. }
  39729. else {
  39730. return dim;
  39731. }
  39732. });
  39733. var list = new List(dataDimsInfo, this);
  39734. list.initData(rawData);
  39735. // Anication is forbiden in progressive data mode.
  39736. if (this.option.progressive) {
  39737. this.option.animation = false;
  39738. }
  39739. return list;
  39740. },
  39741. /**
  39742. * User can get data raw indices on 'axisAreaSelected' event received.
  39743. *
  39744. * @public
  39745. * @param {string} activeState 'active' or 'inactive' or 'normal'
  39746. * @return {Array.<number>} Raw indices
  39747. */
  39748. getRawIndicesByActiveState: function (activeState) {
  39749. var coordSys = this.coordinateSystem;
  39750. var data = this.getData();
  39751. var indices = [];
  39752. coordSys.eachActiveState(data, function (theActiveState, dataIndex) {
  39753. if (activeState === theActiveState) {
  39754. indices.push(data.getRawIndex(dataIndex));
  39755. }
  39756. });
  39757. return indices;
  39758. },
  39759. defaultOption: {
  39760. zlevel: 0, // 一级层叠
  39761. z: 2, // 二级层叠
  39762. coordinateSystem: 'parallel',
  39763. parallelIndex: 0,
  39764. label: {
  39765. normal: {
  39766. show: false
  39767. },
  39768. emphasis: {
  39769. show: false
  39770. }
  39771. },
  39772. inactiveOpacity: 0.05,
  39773. activeOpacity: 1,
  39774. lineStyle: {
  39775. normal: {
  39776. width: 1,
  39777. opacity: 0.45,
  39778. type: 'solid'
  39779. }
  39780. },
  39781. progressive: false, // 100
  39782. smooth: false,
  39783. animationEasing: 'linear'
  39784. }
  39785. });
  39786. function translateCategoryValue(axisModel, dim, rawData) {
  39787. var axisData = axisModel.get('data');
  39788. var numberDim = convertDimNameToNumber(dim);
  39789. if (axisData && axisData.length) {
  39790. zrUtil.each(rawData, function (dataItem) {
  39791. if (!dataItem) {
  39792. return;
  39793. }
  39794. // FIXME
  39795. // time consuming, should use hash?
  39796. var index = zrUtil.indexOf(axisData, dataItem[numberDim]);
  39797. dataItem[numberDim] = index >= 0 ? index : NaN;
  39798. });
  39799. }
  39800. // FIXME
  39801. // 如果没有设置axis data, 应自动算出,或者提示。
  39802. }
  39803. function convertDimNameToNumber(dimName) {
  39804. return +dimName.replace('dim', '');
  39805. }
  39806. function generateDataDims(modelDims, rawData) {
  39807. // parallelModel.dimension should not be regarded as data
  39808. // dimensions. Consider dimensions = ['dim4', 'dim2', 'dim6'];
  39809. // We detect max dim by parallelModel.dimensions and fist
  39810. // item in rawData arbitrarily.
  39811. var maxDimNum = 0;
  39812. zrUtil.each(modelDims, function (dimName) {
  39813. var numberDim = convertDimNameToNumber(dimName);
  39814. numberDim > maxDimNum && (maxDimNum = numberDim);
  39815. });
  39816. var firstItem = rawData[0];
  39817. if (firstItem && firstItem.length - 1 > maxDimNum) {
  39818. maxDimNum = firstItem.length - 1;
  39819. }
  39820. var dataDims = [];
  39821. for (var i = 0; i <= maxDimNum; i++) {
  39822. dataDims.push('dim' + i);
  39823. }
  39824. return dataDims;
  39825. }
  39826. /***/ },
  39827. /* 248 */
  39828. /***/ function(module, exports, __webpack_require__) {
  39829. var graphic = __webpack_require__(18);
  39830. var zrUtil = __webpack_require__(4);
  39831. var SMOOTH = 0.3;
  39832. var ParallelView = __webpack_require__(80).extend({
  39833. type: 'parallel',
  39834. init: function () {
  39835. /**
  39836. * @type {module:zrender/container/Group}
  39837. * @private
  39838. */
  39839. this._dataGroup = new graphic.Group();
  39840. this.group.add(this._dataGroup);
  39841. /**
  39842. * @type {module:echarts/data/List}
  39843. */
  39844. this._data;
  39845. },
  39846. /**
  39847. * @override
  39848. */
  39849. render: function (seriesModel, ecModel, api, payload) {
  39850. this._renderForNormal(seriesModel, payload);
  39851. // this[
  39852. // seriesModel.option.progressive
  39853. // ? '_renderForProgressive'
  39854. // : '_renderForNormal'
  39855. // ](seriesModel);
  39856. },
  39857. dispose: function () {},
  39858. /**
  39859. * @private
  39860. */
  39861. _renderForNormal: function (seriesModel, payload) {
  39862. var dataGroup = this._dataGroup;
  39863. var data = seriesModel.getData();
  39864. var oldData = this._data;
  39865. var coordSys = seriesModel.coordinateSystem;
  39866. var dimensions = coordSys.dimensions;
  39867. var option = seriesModel.option;
  39868. var smooth = option.smooth ? SMOOTH : null;
  39869. // Consider switch between progressive and not.
  39870. // oldData && oldData.__plProgressive && dataGroup.removeAll();
  39871. data.diff(oldData)
  39872. .add(add)
  39873. .update(update)
  39874. .remove(remove)
  39875. .execute();
  39876. // Update style
  39877. updateElCommon(data, smooth);
  39878. // First create
  39879. if (!this._data) {
  39880. var clipPath = createGridClipShape(
  39881. coordSys, seriesModel, function () {
  39882. // Callback will be invoked immediately if there is no animation
  39883. setTimeout(function () {
  39884. dataGroup.removeClipPath();
  39885. });
  39886. }
  39887. );
  39888. dataGroup.setClipPath(clipPath);
  39889. }
  39890. this._data = data;
  39891. function add(newDataIndex) {
  39892. addEl(data, dataGroup, newDataIndex, dimensions, coordSys, null, smooth);
  39893. }
  39894. function update(newDataIndex, oldDataIndex) {
  39895. var line = oldData.getItemGraphicEl(oldDataIndex);
  39896. var points = createLinePoints(data, newDataIndex, dimensions, coordSys);
  39897. data.setItemGraphicEl(newDataIndex, line);
  39898. var animationModel = (payload && payload.animation === false) ? null : seriesModel;
  39899. graphic.updateProps(line, {shape: {points: points}}, animationModel, newDataIndex);
  39900. }
  39901. function remove(oldDataIndex) {
  39902. var line = oldData.getItemGraphicEl(oldDataIndex);
  39903. dataGroup.remove(line);
  39904. }
  39905. },
  39906. /**
  39907. * @private
  39908. */
  39909. // _renderForProgressive: function (seriesModel) {
  39910. // var dataGroup = this._dataGroup;
  39911. // var data = seriesModel.getData();
  39912. // var oldData = this._data;
  39913. // var coordSys = seriesModel.coordinateSystem;
  39914. // var dimensions = coordSys.dimensions;
  39915. // var option = seriesModel.option;
  39916. // var progressive = option.progressive;
  39917. // var smooth = option.smooth ? SMOOTH : null;
  39918. // // In progressive animation is disabled, so use simple data diff,
  39919. // // which effects performance less.
  39920. // // (Typically performance for data with length 7000+ like:
  39921. // // simpleDiff: 60ms, addEl: 184ms,
  39922. // // in RMBP 2.4GHz intel i7, OSX 10.9 chrome 50.0.2661.102 (64-bit))
  39923. // if (simpleDiff(oldData, data, dimensions)) {
  39924. // dataGroup.removeAll();
  39925. // data.each(function (dataIndex) {
  39926. // addEl(data, dataGroup, dataIndex, dimensions, coordSys);
  39927. // });
  39928. // }
  39929. // updateElCommon(data, progressive, smooth);
  39930. // // Consider switch between progressive and not.
  39931. // data.__plProgressive = true;
  39932. // this._data = data;
  39933. // },
  39934. /**
  39935. * @override
  39936. */
  39937. remove: function () {
  39938. this._dataGroup && this._dataGroup.removeAll();
  39939. this._data = null;
  39940. }
  39941. });
  39942. function createGridClipShape(coordSys, seriesModel, cb) {
  39943. var parallelModel = coordSys.model;
  39944. var rect = coordSys.getRect();
  39945. var rectEl = new graphic.Rect({
  39946. shape: {
  39947. x: rect.x,
  39948. y: rect.y,
  39949. width: rect.width,
  39950. height: rect.height
  39951. }
  39952. });
  39953. var dim = parallelModel.get('layout') === 'horizontal' ? 'width' : 'height';
  39954. rectEl.setShape(dim, 0);
  39955. graphic.initProps(rectEl, {
  39956. shape: {
  39957. width: rect.width,
  39958. height: rect.height
  39959. }
  39960. }, seriesModel, cb);
  39961. return rectEl;
  39962. }
  39963. function createLinePoints(data, dataIndex, dimensions, coordSys) {
  39964. var points = [];
  39965. for (var i = 0; i < dimensions.length; i++) {
  39966. var dimName = dimensions[i];
  39967. var value = data.get(dimName, dataIndex);
  39968. if (!isEmptyValue(value, coordSys.getAxis(dimName).type)) {
  39969. points.push(coordSys.dataToPoint(value, dimName));
  39970. }
  39971. }
  39972. return points;
  39973. }
  39974. function addEl(data, dataGroup, dataIndex, dimensions, coordSys) {
  39975. var points = createLinePoints(data, dataIndex, dimensions, coordSys);
  39976. var line = new graphic.Polyline({
  39977. shape: {points: points},
  39978. silent: true,
  39979. z2: 10
  39980. });
  39981. dataGroup.add(line);
  39982. data.setItemGraphicEl(dataIndex, line);
  39983. }
  39984. function updateElCommon(data, smooth) {
  39985. var seriesStyleModel = data.hostModel.getModel('lineStyle.normal');
  39986. var lineStyle = seriesStyleModel.getLineStyle();
  39987. data.eachItemGraphicEl(function (line, dataIndex) {
  39988. if (data.hasItemOption) {
  39989. var itemModel = data.getItemModel(dataIndex);
  39990. var lineStyleModel = itemModel.getModel('lineStyle.normal', seriesStyleModel);
  39991. lineStyle = lineStyleModel.getLineStyle(['color', 'stroke']);
  39992. }
  39993. line.useStyle(zrUtil.extend(lineStyle, {
  39994. fill: null,
  39995. // lineStyle.color have been set to itemVisual in module:echarts/visual/seriesColor.
  39996. stroke: data.getItemVisual(dataIndex, 'color'),
  39997. // lineStyle.opacity have been set to itemVisual in parallelVisual.
  39998. opacity: data.getItemVisual(dataIndex, 'opacity')
  39999. }));
  40000. line.shape.smooth = smooth;
  40001. });
  40002. }
  40003. // function simpleDiff(oldData, newData, dimensions) {
  40004. // var oldLen;
  40005. // if (!oldData
  40006. // || !oldData.__plProgressive
  40007. // || (oldLen = oldData.count()) !== newData.count()
  40008. // ) {
  40009. // return true;
  40010. // }
  40011. // var dimLen = dimensions.length;
  40012. // for (var i = 0; i < oldLen; i++) {
  40013. // for (var j = 0; j < dimLen; j++) {
  40014. // if (oldData.get(dimensions[j], i) !== newData.get(dimensions[j], i)) {
  40015. // return true;
  40016. // }
  40017. // }
  40018. // }
  40019. // return false;
  40020. // }
  40021. // FIXME
  40022. // 公用方法?
  40023. function isEmptyValue(val, axisType) {
  40024. return axisType === 'category'
  40025. ? val == null
  40026. : (val == null || isNaN(val)); // axisType === 'value'
  40027. }
  40028. module.exports = ParallelView;
  40029. /***/ },
  40030. /* 249 */
  40031. /***/ function(module, exports) {
  40032. var opacityAccessPath = ['lineStyle', 'normal', 'opacity'];
  40033. module.exports = function (ecModel) {
  40034. ecModel.eachSeriesByType('parallel', function (seriesModel) {
  40035. var itemStyleModel = seriesModel.getModel('itemStyle.normal');
  40036. var lineStyleModel = seriesModel.getModel('lineStyle.normal');
  40037. var globalColors = ecModel.get('color');
  40038. var color = lineStyleModel.get('color')
  40039. || itemStyleModel.get('color')
  40040. || globalColors[seriesModel.seriesIndex % globalColors.length];
  40041. var inactiveOpacity = seriesModel.get('inactiveOpacity');
  40042. var activeOpacity = seriesModel.get('activeOpacity');
  40043. var lineStyle = seriesModel.getModel('lineStyle.normal').getLineStyle();
  40044. var coordSys = seriesModel.coordinateSystem;
  40045. var data = seriesModel.getData();
  40046. var opacityMap = {
  40047. normal: lineStyle.opacity,
  40048. active: activeOpacity,
  40049. inactive: inactiveOpacity
  40050. };
  40051. coordSys.eachActiveState(data, function (activeState, dataIndex) {
  40052. var itemModel = data.getItemModel(dataIndex);
  40053. var opacity = opacityMap[activeState];
  40054. if (activeState === 'normal') {
  40055. var itemOpacity = itemModel.get(opacityAccessPath, true);
  40056. itemOpacity != null && (opacity = itemOpacity);
  40057. }
  40058. data.setItemVisual(dataIndex, 'opacity', opacity);
  40059. });
  40060. data.setVisual('color', color);
  40061. });
  40062. };
  40063. /***/ },
  40064. /* 250 */
  40065. /***/ function(module, exports, __webpack_require__) {
  40066. var echarts = __webpack_require__(1);
  40067. __webpack_require__(251);
  40068. __webpack_require__(252);
  40069. echarts.registerLayout(__webpack_require__(253));
  40070. echarts.registerVisual(__webpack_require__(255));
  40071. /***/ },
  40072. /* 251 */
  40073. /***/ function(module, exports, __webpack_require__) {
  40074. /**
  40075. * @file Get initial data and define sankey view's series model
  40076. * @author Deqing Li(annong035@gmail.com)
  40077. */
  40078. var SeriesModel = __webpack_require__(78);
  40079. var createGraphFromNodeEdge = __webpack_require__(206);
  40080. var encodeHTML = __webpack_require__(6).encodeHTML;
  40081. var SankeySeries = SeriesModel.extend({
  40082. type: 'series.sankey',
  40083. layoutInfo: null,
  40084. /**
  40085. * Init a graph data structure from data in option series
  40086. *
  40087. * @param {Object} option the object used to config echarts view
  40088. * @return {module:echarts/data/List} storage initial data
  40089. */
  40090. getInitialData: function (option) {
  40091. var links = option.edges || option.links;
  40092. var nodes = option.data || option.nodes;
  40093. if (nodes && links) {
  40094. var graph = createGraphFromNodeEdge(nodes, links, this, true);
  40095. return graph.data;
  40096. }
  40097. },
  40098. /**
  40099. * Return the graphic data structure
  40100. *
  40101. * @return {module:echarts/data/Graph} graphic data structure
  40102. */
  40103. getGraph: function () {
  40104. return this.getData().graph;
  40105. },
  40106. /**
  40107. * Get edge data of graphic data structure
  40108. *
  40109. * @return {module:echarts/data/List} data structure of list
  40110. */
  40111. getEdgeData: function () {
  40112. return this.getGraph().edgeData;
  40113. },
  40114. /**
  40115. * @override
  40116. */
  40117. formatTooltip: function (dataIndex, multipleSeries, dataType) {
  40118. // dataType === 'node' or empty do not show tooltip by default
  40119. if (dataType === 'edge') {
  40120. var params = this.getDataParams(dataIndex, dataType);
  40121. var rawDataOpt = params.data;
  40122. var html = rawDataOpt.source + ' -- ' + rawDataOpt.target;
  40123. if (params.value) {
  40124. html += ' : ' + params.value;
  40125. }
  40126. return encodeHTML(html);
  40127. }
  40128. return SankeySeries.superCall(this, 'formatTooltip', dataIndex, multipleSeries);
  40129. },
  40130. defaultOption: {
  40131. zlevel: 0,
  40132. z: 2,
  40133. coordinateSystem: 'view',
  40134. layout: null,
  40135. // the position of the whole view
  40136. left: '5%',
  40137. top: '5%',
  40138. right: '20%',
  40139. bottom: '5%',
  40140. // the dx of the node
  40141. nodeWidth: 20,
  40142. // the vertical distance between two nodes
  40143. nodeGap: 8,
  40144. // the number of iterations to change the position of the node
  40145. layoutIterations: 32,
  40146. label: {
  40147. normal: {
  40148. show: true,
  40149. position: 'right',
  40150. textStyle: {
  40151. color: '#000',
  40152. fontSize: 12
  40153. }
  40154. },
  40155. emphasis: {
  40156. show: true
  40157. }
  40158. },
  40159. itemStyle: {
  40160. normal: {
  40161. borderWidth: 1,
  40162. borderColor: '#333'
  40163. }
  40164. },
  40165. lineStyle: {
  40166. normal: {
  40167. color: '#314656',
  40168. opacity: 0.2,
  40169. curveness: 0.5
  40170. },
  40171. emphasis: {
  40172. opacity: 0.6
  40173. }
  40174. },
  40175. animationEasing: 'linear',
  40176. animationDuration: 1000
  40177. }
  40178. });
  40179. module.exports = SankeySeries;
  40180. /***/ },
  40181. /* 252 */
  40182. /***/ function(module, exports, __webpack_require__) {
  40183. /**
  40184. * @file The file used to draw sankey view
  40185. * @author Deqing Li(annong035@gmail.com)
  40186. */
  40187. var graphic = __webpack_require__(18);
  40188. var zrUtil = __webpack_require__(4);
  40189. var SankeyShape = graphic.extendShape({
  40190. shape: {
  40191. x1: 0, y1: 0,
  40192. x2: 0, y2: 0,
  40193. cpx1: 0, cpy1: 0,
  40194. cpx2: 0, cpy2: 0,
  40195. extent: 0
  40196. },
  40197. buildPath: function (ctx, shape) {
  40198. var halfExtent = shape.extent / 2;
  40199. ctx.moveTo(shape.x1, shape.y1 - halfExtent);
  40200. ctx.bezierCurveTo(
  40201. shape.cpx1, shape.cpy1 - halfExtent,
  40202. shape.cpx2, shape.cpy2 - halfExtent,
  40203. shape.x2, shape.y2 - halfExtent
  40204. );
  40205. ctx.lineTo(shape.x2, shape.y2 + halfExtent);
  40206. ctx.bezierCurveTo(
  40207. shape.cpx2, shape.cpy2 + halfExtent,
  40208. shape.cpx1, shape.cpy1 + halfExtent,
  40209. shape.x1, shape.y1 + halfExtent
  40210. );
  40211. ctx.closePath();
  40212. }
  40213. });
  40214. module.exports = __webpack_require__(1).extendChartView({
  40215. type: 'sankey',
  40216. /**
  40217. * @private
  40218. * @type {module:echarts/chart/sankey/SankeySeries}
  40219. */
  40220. _model: null,
  40221. render: function (seriesModel, ecModel, api) {
  40222. var graph = seriesModel.getGraph();
  40223. var group = this.group;
  40224. var layoutInfo = seriesModel.layoutInfo;
  40225. var nodeData = seriesModel.getData();
  40226. var edgeData = seriesModel.getData('edge');
  40227. this._model = seriesModel;
  40228. group.removeAll();
  40229. group.position = [layoutInfo.x, layoutInfo.y];
  40230. // generate a bezire Curve for each edge
  40231. graph.eachEdge(function (edge) {
  40232. var curve = new SankeyShape();
  40233. curve.dataIndex = edge.dataIndex;
  40234. curve.seriesIndex = seriesModel.seriesIndex;
  40235. curve.dataType = 'edge';
  40236. var lineStyleModel = edge.getModel('lineStyle.normal');
  40237. var curvature = lineStyleModel.get('curveness');
  40238. var n1Layout = edge.node1.getLayout();
  40239. var n2Layout = edge.node2.getLayout();
  40240. var edgeLayout = edge.getLayout();
  40241. curve.shape.extent = Math.max(1, edgeLayout.dy);
  40242. var x1 = n1Layout.x + n1Layout.dx;
  40243. var y1 = n1Layout.y + edgeLayout.sy + edgeLayout.dy / 2;
  40244. var x2 = n2Layout.x;
  40245. var y2 = n2Layout.y + edgeLayout.ty + edgeLayout.dy / 2;
  40246. var cpx1 = x1 * (1 - curvature) + x2 * curvature;
  40247. var cpy1 = y1;
  40248. var cpx2 = x1 * curvature + x2 * (1 - curvature);
  40249. var cpy2 = y2;
  40250. curve.setShape({
  40251. x1: x1,
  40252. y1: y1,
  40253. x2: x2,
  40254. y2: y2,
  40255. cpx1: cpx1,
  40256. cpy1: cpy1,
  40257. cpx2: cpx2,
  40258. cpy2: cpy2
  40259. });
  40260. curve.setStyle(lineStyleModel.getItemStyle());
  40261. // Special color, use source node color or target node color
  40262. switch (curve.style.fill) {
  40263. case 'source':
  40264. curve.style.fill = edge.node1.getVisual('color');
  40265. break;
  40266. case 'target':
  40267. curve.style.fill = edge.node2.getVisual('color');
  40268. break;
  40269. }
  40270. graphic.setHoverStyle(curve, edge.getModel('lineStyle.emphasis').getItemStyle());
  40271. group.add(curve);
  40272. edgeData.setItemGraphicEl(edge.dataIndex, curve);
  40273. });
  40274. // generate a rect for each node
  40275. graph.eachNode(function (node) {
  40276. var layout = node.getLayout();
  40277. var itemModel = node.getModel();
  40278. var labelModel = itemModel.getModel('label.normal');
  40279. var textStyleModel = labelModel.getModel('textStyle');
  40280. var labelHoverModel = itemModel.getModel('label.emphasis');
  40281. var textStyleHoverModel = labelHoverModel.getModel('textStyle');
  40282. var rect = new graphic.Rect({
  40283. shape: {
  40284. x: layout.x,
  40285. y: layout.y,
  40286. width: node.getLayout().dx,
  40287. height: node.getLayout().dy
  40288. },
  40289. style: {
  40290. // Get formatted label in label.normal option
  40291. // Use node id if it is not specified
  40292. text: labelModel.get('show')
  40293. ? seriesModel.getFormattedLabel(node.dataIndex, 'normal') || node.id
  40294. // Use empty string to hide the label
  40295. : '',
  40296. textFont: textStyleModel.getFont(),
  40297. textFill: textStyleModel.getTextColor(),
  40298. textPosition: labelModel.get('position')
  40299. }
  40300. });
  40301. rect.setStyle(zrUtil.defaults(
  40302. {
  40303. fill: node.getVisual('color')
  40304. },
  40305. itemModel.getModel('itemStyle.normal').getItemStyle()
  40306. ));
  40307. graphic.setHoverStyle(rect, zrUtil.extend(
  40308. node.getModel('itemStyle.emphasis'),
  40309. {
  40310. text: labelHoverModel.get('show')
  40311. ? seriesModel.getFormattedLabel(node.dataIndex, 'emphasis') || node.id
  40312. : '',
  40313. textFont: textStyleHoverModel.getFont(),
  40314. textFill: textStyleHoverModel.getTextColor(),
  40315. textPosition: labelHoverModel.get('position')
  40316. }
  40317. ));
  40318. group.add(rect);
  40319. nodeData.setItemGraphicEl(node.dataIndex, rect);
  40320. rect.dataType = 'node';
  40321. });
  40322. if (!this._data && seriesModel.get('animation')) {
  40323. group.setClipPath(createGridClipShape(group.getBoundingRect(), seriesModel, function () {
  40324. group.removeClipPath();
  40325. }));
  40326. }
  40327. this._data = seriesModel.getData();
  40328. },
  40329. dispose: function () {}
  40330. });
  40331. // add animation to the view
  40332. function createGridClipShape(rect, seriesModel, cb) {
  40333. var rectEl = new graphic.Rect({
  40334. shape: {
  40335. x: rect.x - 10,
  40336. y: rect.y - 10,
  40337. width: 0,
  40338. height: rect.height + 20
  40339. }
  40340. });
  40341. graphic.initProps(rectEl, {
  40342. shape: {
  40343. width: rect.width + 20,
  40344. height: rect.height + 20
  40345. }
  40346. }, seriesModel, cb);
  40347. return rectEl;
  40348. }
  40349. /***/ },
  40350. /* 253 */
  40351. /***/ function(module, exports, __webpack_require__) {
  40352. /**
  40353. * @file The layout algorithm of sankey view
  40354. * @author Deqing Li(annong035@gmail.com)
  40355. */
  40356. var layout = __webpack_require__(71);
  40357. var nest = __webpack_require__(254);
  40358. var zrUtil = __webpack_require__(4);
  40359. module.exports = function (ecModel, api, payload) {
  40360. ecModel.eachSeriesByType('sankey', function (seriesModel) {
  40361. var nodeWidth = seriesModel.get('nodeWidth');
  40362. var nodeGap = seriesModel.get('nodeGap');
  40363. var layoutInfo = getViewRect(seriesModel, api);
  40364. seriesModel.layoutInfo = layoutInfo;
  40365. var width = layoutInfo.width;
  40366. var height = layoutInfo.height;
  40367. var graph = seriesModel.getGraph();
  40368. var nodes = graph.nodes;
  40369. var edges = graph.edges;
  40370. computeNodeValues(nodes);
  40371. var filteredNodes = zrUtil.filter(nodes, function (node) {
  40372. return node.getLayout().value === 0;
  40373. });
  40374. var iterations = filteredNodes.length !== 0
  40375. ? 0 : seriesModel.get('layoutIterations');
  40376. layoutSankey(nodes, edges, nodeWidth, nodeGap, width, height, iterations);
  40377. });
  40378. };
  40379. /**
  40380. * Get the layout position of the whole view
  40381. *
  40382. * @param {module:echarts/model/Series} seriesModel the model object of sankey series
  40383. * @param {module:echarts/ExtensionAPI} api provide the API list that the developer can call
  40384. * @return {module:zrender/core/BoundingRect} size of rect to draw the sankey view
  40385. */
  40386. function getViewRect(seriesModel, api) {
  40387. return layout.getLayoutRect(
  40388. seriesModel.getBoxLayoutParams(), {
  40389. width: api.getWidth(),
  40390. height: api.getHeight()
  40391. }
  40392. );
  40393. }
  40394. function layoutSankey(nodes, edges, nodeWidth, nodeGap, width, height, iterations) {
  40395. computeNodeBreadths(nodes, nodeWidth, width);
  40396. computeNodeDepths(nodes, edges, height, nodeGap, iterations);
  40397. computeEdgeDepths(nodes);
  40398. }
  40399. /**
  40400. * Compute the value of each node by summing the associated edge's value
  40401. *
  40402. * @param {module:echarts/data/Graph~Node} nodes node of sankey view
  40403. */
  40404. function computeNodeValues(nodes) {
  40405. zrUtil.each(nodes, function (node) {
  40406. var value1 = sum(node.outEdges, getEdgeValue);
  40407. var value2 = sum(node.inEdges, getEdgeValue);
  40408. var value = Math.max(value1, value2);
  40409. node.setLayout({value: value}, true);
  40410. });
  40411. }
  40412. /**
  40413. * Compute the x-position for each node
  40414. *
  40415. * @param {module:echarts/data/Graph~Node} nodes node of sankey view
  40416. * @param {number} nodeWidth the dx of the node
  40417. * @param {number} width the whole width of the area to draw the view
  40418. */
  40419. function computeNodeBreadths(nodes, nodeWidth, width) {
  40420. var remainNodes = nodes;
  40421. var nextNode = null;
  40422. var x = 0;
  40423. var kx = 0;
  40424. while (remainNodes.length) {
  40425. nextNode = [];
  40426. for (var i = 0, len = remainNodes.length; i < len; i++) {
  40427. var node = remainNodes[i];
  40428. node.setLayout({x: x}, true);
  40429. node.setLayout({dx: nodeWidth}, true);
  40430. for (var j = 0, lenj = node.outEdges.length; j < lenj; j++) {
  40431. nextNode.push(node.outEdges[j].node2);
  40432. }
  40433. }
  40434. remainNodes = nextNode;
  40435. ++x;
  40436. }
  40437. moveSinksRight(nodes, x);
  40438. kx = (width - nodeWidth) / (x - 1);
  40439. scaleNodeBreadths(nodes, kx);
  40440. }
  40441. /**
  40442. * All the node without outEgdes are assigned maximum x-position and
  40443. * be aligned in the last column.
  40444. *
  40445. * @param {module:echarts/data/Graph~Node} nodes node of sankey view
  40446. * @param {number} x value (x-1) use to assign to node without outEdges
  40447. * as x-position
  40448. */
  40449. function moveSinksRight(nodes, x) {
  40450. zrUtil.each(nodes, function (node) {
  40451. if (!node.outEdges.length) {
  40452. node.setLayout({x: x - 1}, true);
  40453. }
  40454. });
  40455. }
  40456. /**
  40457. * Scale node x-position to the width
  40458. *
  40459. * @param {module:echarts/data/Graph~Node} nodes node of sankey view
  40460. * @param {number} kx multiple used to scale nodes
  40461. */
  40462. function scaleNodeBreadths(nodes, kx) {
  40463. zrUtil.each(nodes, function (node) {
  40464. var nodeX = node.getLayout().x * kx;
  40465. node.setLayout({x: nodeX}, true);
  40466. });
  40467. }
  40468. /**
  40469. * Using Gauss-Seidel iterations method to compute the node depth(y-position)
  40470. *
  40471. * @param {module:echarts/data/Graph~Node} nodes node of sankey view
  40472. * @param {module:echarts/data/Graph~Edge} edges edge of sankey view
  40473. * @param {number} height the whole height of the area to draw the view
  40474. * @param {numbber} nodeGap the vertical distance between two nodes
  40475. * in the same column.
  40476. * @param {number} iterations the number of iterations for the algorithm
  40477. */
  40478. function computeNodeDepths(nodes, edges, height, nodeGap, iterations) {
  40479. var nodesByBreadth = nest()
  40480. .key(function (d) {
  40481. return d.getLayout().x;
  40482. })
  40483. .sortKeys(ascending)
  40484. .entries(nodes)
  40485. .map(function (d) {
  40486. return d.values;
  40487. });
  40488. initializeNodeDepth(nodes, nodesByBreadth, edges, height, nodeGap);
  40489. resolveCollisions(nodesByBreadth, nodeGap, height);
  40490. for (var alpha = 1; iterations > 0; iterations--) {
  40491. // 0.99 is a experience parameter, ensure that each iterations of
  40492. // changes as small as possible.
  40493. alpha *= 0.99;
  40494. relaxRightToLeft(nodesByBreadth, alpha);
  40495. resolveCollisions(nodesByBreadth, nodeGap, height);
  40496. relaxLeftToRight(nodesByBreadth, alpha);
  40497. resolveCollisions(nodesByBreadth, nodeGap, height);
  40498. }
  40499. }
  40500. /**
  40501. * Compute the original y-position for each node
  40502. *
  40503. * @param {module:echarts/data/Graph~Node} nodes node of sankey view
  40504. * @param {Array.<Array.<module:echarts/data/Graph~Node>>} nodesByBreadth
  40505. * group by the array of all sankey nodes based on the nodes x-position.
  40506. * @param {module:echarts/data/Graph~Edge} edges edge of sankey view
  40507. * @param {number} height the whole height of the area to draw the view
  40508. * @param {number} nodeGap the vertical distance between two nodes
  40509. */
  40510. function initializeNodeDepth(nodes, nodesByBreadth, edges, height, nodeGap) {
  40511. var kyArray = [];
  40512. zrUtil.each(nodesByBreadth, function (nodes) {
  40513. var n = nodes.length;
  40514. var sum = 0;
  40515. zrUtil.each(nodes, function (node) {
  40516. sum += node.getLayout().value;
  40517. });
  40518. var ky = (height - (n - 1) * nodeGap) / sum;
  40519. kyArray.push(ky);
  40520. });
  40521. kyArray.sort(function (a, b) {
  40522. return a - b;
  40523. });
  40524. var ky0 = kyArray[0];
  40525. zrUtil.each(nodesByBreadth, function (nodes) {
  40526. zrUtil.each(nodes, function (node, i) {
  40527. node.setLayout({y: i}, true);
  40528. var nodeDy = node.getLayout().value * ky0;
  40529. node.setLayout({dy: nodeDy}, true);
  40530. });
  40531. });
  40532. zrUtil.each(edges, function (edge) {
  40533. var edgeDy = +edge.getValue() * ky0;
  40534. edge.setLayout({dy: edgeDy}, true);
  40535. });
  40536. }
  40537. /**
  40538. * Resolve the collision of initialized depth (y-position)
  40539. *
  40540. * @param {Array.<Array.<module:echarts/data/Graph~Node>>} nodesByBreadth
  40541. * group by the array of all sankey nodes based on the nodes x-position.
  40542. * @param {number} nodeGap the vertical distance between two nodes
  40543. * @param {number} height the whole height of the area to draw the view
  40544. */
  40545. function resolveCollisions(nodesByBreadth, nodeGap, height) {
  40546. zrUtil.each(nodesByBreadth, function (nodes) {
  40547. var node;
  40548. var dy;
  40549. var y0 = 0;
  40550. var n = nodes.length;
  40551. var i;
  40552. nodes.sort(ascendingDepth);
  40553. for (i = 0; i < n; i++) {
  40554. node = nodes[i];
  40555. dy = y0 - node.getLayout().y;
  40556. if (dy > 0) {
  40557. var nodeY = node.getLayout().y + dy;
  40558. node.setLayout({y: nodeY}, true);
  40559. }
  40560. y0 = node.getLayout().y + node.getLayout().dy + nodeGap;
  40561. }
  40562. // if the bottommost node goes outside the bounds, push it back up
  40563. dy = y0 - nodeGap - height;
  40564. if (dy > 0) {
  40565. var nodeY = node.getLayout().y - dy;
  40566. node.setLayout({y: nodeY}, true);
  40567. y0 = node.getLayout().y;
  40568. for (i = n - 2; i >= 0; --i) {
  40569. node = nodes[i];
  40570. dy = node.getLayout().y + node.getLayout().dy + nodeGap - y0;
  40571. if (dy > 0) {
  40572. nodeY = node.getLayout().y - dy;
  40573. node.setLayout({y: nodeY}, true);
  40574. }
  40575. y0 = node.getLayout().y;
  40576. }
  40577. }
  40578. });
  40579. }
  40580. /**
  40581. * Change the y-position of the nodes, except most the right side nodes
  40582. *
  40583. * @param {Array.<Array.<module:echarts/data/Graph~Node>>} nodesByBreadth
  40584. * group by the array of all sankey nodes based on the node x-position.
  40585. * @param {number} alpha parameter used to adjust the nodes y-position
  40586. */
  40587. function relaxRightToLeft(nodesByBreadth, alpha) {
  40588. zrUtil.each(nodesByBreadth.slice().reverse(), function (nodes) {
  40589. zrUtil.each(nodes, function (node) {
  40590. if (node.outEdges.length) {
  40591. var y = sum(node.outEdges, weightedTarget) / sum(node.outEdges, getEdgeValue);
  40592. var nodeY = node.getLayout().y + (y - center(node)) * alpha;
  40593. node.setLayout({y: nodeY}, true);
  40594. }
  40595. });
  40596. });
  40597. }
  40598. function weightedTarget(edge) {
  40599. return center(edge.node2) * edge.getValue();
  40600. }
  40601. /**
  40602. * Change the y-position of the nodes, except most the left side nodes
  40603. *
  40604. * @param {Array.<Array.<module:echarts/data/Graph~Node>>} nodesByBreadth
  40605. * group by the array of all sankey nodes based on the node x-position.
  40606. * @param {number} alpha parameter used to adjust the nodes y-position
  40607. */
  40608. function relaxLeftToRight(nodesByBreadth, alpha) {
  40609. zrUtil.each(nodesByBreadth, function (nodes) {
  40610. zrUtil.each(nodes, function (node) {
  40611. if (node.inEdges.length) {
  40612. var y = sum(node.inEdges, weightedSource) / sum(node.inEdges, getEdgeValue);
  40613. var nodeY = node.getLayout().y + (y - center(node)) * alpha;
  40614. node.setLayout({y: nodeY}, true);
  40615. }
  40616. });
  40617. });
  40618. }
  40619. function weightedSource(edge) {
  40620. return center(edge.node1) * edge.getValue();
  40621. }
  40622. /**
  40623. * Compute the depth(y-position) of each edge
  40624. *
  40625. * @param {module:echarts/data/Graph~Node} nodes node of sankey view
  40626. */
  40627. function computeEdgeDepths(nodes) {
  40628. zrUtil.each(nodes, function (node) {
  40629. node.outEdges.sort(ascendingTargetDepth);
  40630. node.inEdges.sort(ascendingSourceDepth);
  40631. });
  40632. zrUtil.each(nodes, function (node) {
  40633. var sy = 0;
  40634. var ty = 0;
  40635. zrUtil.each(node.outEdges, function (edge) {
  40636. edge.setLayout({sy: sy}, true);
  40637. sy += edge.getLayout().dy;
  40638. });
  40639. zrUtil.each(node.inEdges, function (edge) {
  40640. edge.setLayout({ty: ty}, true);
  40641. ty += edge.getLayout().dy;
  40642. });
  40643. });
  40644. }
  40645. function ascendingTargetDepth(a, b) {
  40646. return a.node2.getLayout().y - b.node2.getLayout().y;
  40647. }
  40648. function ascendingSourceDepth(a, b) {
  40649. return a.node1.getLayout().y - b.node1.getLayout().y;
  40650. }
  40651. function sum(array, f) {
  40652. var sum = 0;
  40653. var len = array.length;
  40654. var i = -1;
  40655. while (++i < len) {
  40656. var value = +f.call(array, array[i], i);
  40657. if (!isNaN(value)) {
  40658. sum += value;
  40659. }
  40660. }
  40661. return sum;
  40662. }
  40663. function center(node) {
  40664. return node.getLayout().y + node.getLayout().dy / 2;
  40665. }
  40666. function ascendingDepth(a, b) {
  40667. return a.getLayout().y - b.getLayout().y;
  40668. }
  40669. function ascending(a, b) {
  40670. return a < b ? -1 : a > b ? 1 : a === b ? 0 : NaN;
  40671. }
  40672. function getEdgeValue(edge) {
  40673. return edge.getValue();
  40674. }
  40675. /***/ },
  40676. /* 254 */
  40677. /***/ function(module, exports, __webpack_require__) {
  40678. var zrUtil = __webpack_require__(4);
  40679. /**
  40680. * nest helper used to group by the array.
  40681. * can specified the keys and sort the keys.
  40682. */
  40683. function nest() {
  40684. var keysFunction = [];
  40685. var sortKeysFunction = [];
  40686. /**
  40687. * map an Array into the mapObject.
  40688. * @param {Array} array
  40689. * @param {number} depth
  40690. */
  40691. function map(array, depth) {
  40692. if (depth >= keysFunction.length) {
  40693. return array;
  40694. }
  40695. var i = -1;
  40696. var n = array.length;
  40697. var keyFunction = keysFunction[depth++];
  40698. var mapObject = {};
  40699. var valuesByKey = {};
  40700. while (++i < n) {
  40701. var keyValue = keyFunction(array[i]);
  40702. var values = valuesByKey[keyValue];
  40703. if (values) {
  40704. values.push(array[i]);
  40705. }
  40706. else {
  40707. valuesByKey[keyValue] = [array[i]];
  40708. }
  40709. }
  40710. zrUtil.each(valuesByKey, function (value, key) {
  40711. mapObject[key] = map(value, depth);
  40712. });
  40713. return mapObject;
  40714. }
  40715. /**
  40716. * transform the Map Object to multidimensional Array
  40717. * @param {Object} map
  40718. * @param {number} depth
  40719. */
  40720. function entriesMap(mapObject, depth) {
  40721. if (depth >= keysFunction.length) {
  40722. return mapObject;
  40723. }
  40724. var array = [];
  40725. var sortKeyFunction = sortKeysFunction[depth++];
  40726. zrUtil.each(mapObject, function (value, key) {
  40727. array.push({
  40728. key: key, values: entriesMap(value, depth)
  40729. });
  40730. });
  40731. if (sortKeyFunction) {
  40732. return array.sort(function (a, b) {
  40733. return sortKeyFunction(a.key, b.key);
  40734. });
  40735. }
  40736. else {
  40737. return array;
  40738. }
  40739. }
  40740. return {
  40741. /**
  40742. * specified the key to groupby the arrays.
  40743. * users can specified one more keys.
  40744. * @param {Function} d
  40745. */
  40746. key: function (d) {
  40747. keysFunction.push(d);
  40748. return this;
  40749. },
  40750. /**
  40751. * specified the comparator to sort the keys
  40752. * @param {Function} order
  40753. */
  40754. sortKeys: function (order) {
  40755. sortKeysFunction[keysFunction.length - 1] = order;
  40756. return this;
  40757. },
  40758. /**
  40759. * the array to be grouped by.
  40760. * @param {Array} array
  40761. */
  40762. entries: function (array) {
  40763. return entriesMap(map(array, 0), 0);
  40764. }
  40765. };
  40766. }
  40767. module.exports = nest;
  40768. /***/ },
  40769. /* 255 */
  40770. /***/ function(module, exports, __webpack_require__) {
  40771. /**
  40772. * @file Visual encoding for sankey view
  40773. * @author Deqing Li(annong035@gmail.com)
  40774. */
  40775. var VisualMapping = __webpack_require__(202);
  40776. var zrUtil = __webpack_require__(4);
  40777. module.exports = function (ecModel, payload) {
  40778. ecModel.eachSeriesByType('sankey', function (seriesModel) {
  40779. var graph = seriesModel.getGraph();
  40780. var nodes = graph.nodes;
  40781. nodes.sort(function (a, b) {
  40782. return a.getLayout().value - b.getLayout().value;
  40783. });
  40784. var minValue = nodes[0].getLayout().value;
  40785. var maxValue = nodes[nodes.length - 1].getLayout().value;
  40786. zrUtil.each(nodes, function (node) {
  40787. var mapping = new VisualMapping({
  40788. type: 'color',
  40789. mappingMethod: 'linear',
  40790. dataExtent: [minValue, maxValue],
  40791. visual: seriesModel.get('color')
  40792. });
  40793. var mapValueToColor = mapping.mapValueToVisual(node.getLayout().value);
  40794. node.setVisual('color', mapValueToColor);
  40795. // If set itemStyle.normal.color
  40796. var itemModel = node.getModel();
  40797. var customColor = itemModel.get('itemStyle.normal.color');
  40798. if (customColor != null) {
  40799. node.setVisual('color', customColor);
  40800. }
  40801. });
  40802. });
  40803. };
  40804. /***/ },
  40805. /* 256 */
  40806. /***/ function(module, exports, __webpack_require__) {
  40807. var echarts = __webpack_require__(1);
  40808. __webpack_require__(257);
  40809. __webpack_require__(260);
  40810. echarts.registerVisual(__webpack_require__(261));
  40811. echarts.registerLayout(__webpack_require__(262));
  40812. /***/ },
  40813. /* 257 */
  40814. /***/ function(module, exports, __webpack_require__) {
  40815. 'use strict';
  40816. var zrUtil = __webpack_require__(4);
  40817. var SeriesModel = __webpack_require__(78);
  40818. var whiskerBoxCommon = __webpack_require__(258);
  40819. var BoxplotSeries = SeriesModel.extend({
  40820. type: 'series.boxplot',
  40821. dependencies: ['xAxis', 'yAxis', 'grid'],
  40822. // TODO
  40823. // box width represents group size, so dimension should have 'size'.
  40824. /**
  40825. * @see <https://en.wikipedia.org/wiki/Box_plot>
  40826. * The meanings of 'min' and 'max' depend on user,
  40827. * and echarts do not need to know it.
  40828. * @readOnly
  40829. */
  40830. defaultValueDimensions: ['min', 'Q1', 'median', 'Q3', 'max'],
  40831. /**
  40832. * @type {Array.<string>}
  40833. * @readOnly
  40834. */
  40835. dimensions: null,
  40836. /**
  40837. * @override
  40838. */
  40839. defaultOption: {
  40840. zlevel: 0, // 一级层叠
  40841. z: 2, // 二级层叠
  40842. coordinateSystem: 'cartesian2d',
  40843. legendHoverLink: true,
  40844. hoverAnimation: true,
  40845. // xAxisIndex: 0,
  40846. // yAxisIndex: 0,
  40847. layout: null, // 'horizontal' or 'vertical'
  40848. boxWidth: [7, 50], // [min, max] can be percent of band width.
  40849. itemStyle: {
  40850. normal: {
  40851. color: '#fff',
  40852. borderWidth: 1
  40853. },
  40854. emphasis: {
  40855. borderWidth: 2,
  40856. shadowBlur: 5,
  40857. shadowOffsetX: 2,
  40858. shadowOffsetY: 2,
  40859. shadowColor: 'rgba(0,0,0,0.4)'
  40860. }
  40861. },
  40862. animationEasing: 'elasticOut',
  40863. animationDuration: 800
  40864. }
  40865. });
  40866. zrUtil.mixin(BoxplotSeries, whiskerBoxCommon.seriesModelMixin, true);
  40867. module.exports = BoxplotSeries;
  40868. /***/ },
  40869. /* 258 */
  40870. /***/ function(module, exports, __webpack_require__) {
  40871. 'use strict';
  40872. var List = __webpack_require__(98);
  40873. var completeDimensions = __webpack_require__(110);
  40874. var WhiskerBoxDraw = __webpack_require__(259);
  40875. var zrUtil = __webpack_require__(4);
  40876. var seriesModelMixin = {
  40877. /**
  40878. * @private
  40879. * @type {string}
  40880. */
  40881. _baseAxisDim: null,
  40882. /**
  40883. * @override
  40884. */
  40885. getInitialData: function (option, ecModel) {
  40886. // When both types of xAxis and yAxis are 'value', layout is
  40887. // needed to be specified by user. Otherwise, layout can be
  40888. // judged by which axis is category.
  40889. var categories;
  40890. var xAxisModel = ecModel.getComponent('xAxis', this.get('xAxisIndex'));
  40891. var yAxisModel = ecModel.getComponent('yAxis', this.get('yAxisIndex'));
  40892. var xAxisType = xAxisModel.get('type');
  40893. var yAxisType = yAxisModel.get('type');
  40894. var addOrdinal;
  40895. // FIXME
  40896. // 考虑时间轴
  40897. if (xAxisType === 'category') {
  40898. option.layout = 'horizontal';
  40899. categories = xAxisModel.getCategories();
  40900. addOrdinal = true;
  40901. }
  40902. else if (yAxisType === 'category') {
  40903. option.layout = 'vertical';
  40904. categories = yAxisModel.getCategories();
  40905. addOrdinal = true;
  40906. }
  40907. else {
  40908. option.layout = option.layout || 'horizontal';
  40909. }
  40910. var coordDims = ['x', 'y'];
  40911. var baseAxisDimIndex = option.layout === 'horizontal' ? 0 : 1;
  40912. var baseAxisDim = this._baseAxisDim = coordDims[baseAxisDimIndex];
  40913. var otherAxisDim = coordDims[1 - baseAxisDimIndex];
  40914. var data = option.data;
  40915. addOrdinal && zrUtil.each(data, function (item, index) {
  40916. zrUtil.isArray(item) && item.unshift(index);
  40917. });
  40918. var dimensions = [{
  40919. name: baseAxisDim,
  40920. otherDims: {
  40921. tooltip: false
  40922. },
  40923. dimsDef: ['base']
  40924. }, {
  40925. name: otherAxisDim,
  40926. dimsDef: this.defaultValueDimensions.slice()
  40927. }];
  40928. dimensions = completeDimensions(dimensions, data, {
  40929. encodeDef: this.get('encode'),
  40930. dimsDef: this.get('dimensions')
  40931. });
  40932. var list = new List(dimensions, this);
  40933. list.initData(data, categories ? categories.slice() : null);
  40934. return list;
  40935. },
  40936. /**
  40937. * If horizontal, base axis is x, otherwise y.
  40938. * @override
  40939. */
  40940. getBaseAxis: function () {
  40941. var dim = this._baseAxisDim;
  40942. return this.ecModel.getComponent(dim + 'Axis', this.get(dim + 'AxisIndex')).axis;
  40943. }
  40944. };
  40945. var viewMixin = {
  40946. init: function () {
  40947. /**
  40948. * Old data.
  40949. * @private
  40950. * @type {module:echarts/chart/helper/WhiskerBoxDraw}
  40951. */
  40952. var whiskerBoxDraw = this._whiskerBoxDraw = new WhiskerBoxDraw(
  40953. this.getStyleUpdater()
  40954. );
  40955. this.group.add(whiskerBoxDraw.group);
  40956. },
  40957. render: function (seriesModel, ecModel, api) {
  40958. this._whiskerBoxDraw.updateData(seriesModel.getData());
  40959. },
  40960. remove: function (ecModel) {
  40961. this._whiskerBoxDraw.remove();
  40962. }
  40963. };
  40964. module.exports = {
  40965. seriesModelMixin: seriesModelMixin,
  40966. viewMixin: viewMixin
  40967. };
  40968. /***/ },
  40969. /* 259 */
  40970. /***/ function(module, exports, __webpack_require__) {
  40971. /**
  40972. * @module echarts/chart/helper/Symbol
  40973. */
  40974. var zrUtil = __webpack_require__(4);
  40975. var graphic = __webpack_require__(18);
  40976. var Path = __webpack_require__(20);
  40977. var WhiskerPath = Path.extend({
  40978. type: 'whiskerInBox',
  40979. shape: {},
  40980. buildPath: function (ctx, shape) {
  40981. for (var i in shape) {
  40982. if (shape.hasOwnProperty(i) && i.indexOf('ends') === 0) {
  40983. var pts = shape[i];
  40984. ctx.moveTo(pts[0][0], pts[0][1]);
  40985. ctx.lineTo(pts[1][0], pts[1][1]);
  40986. }
  40987. }
  40988. }
  40989. });
  40990. /**
  40991. * @constructor
  40992. * @alias {module:echarts/chart/helper/WhiskerBox}
  40993. * @param {module:echarts/data/List} data
  40994. * @param {number} idx
  40995. * @param {Function} styleUpdater
  40996. * @param {boolean} isInit
  40997. * @extends {module:zrender/graphic/Group}
  40998. */
  40999. function WhiskerBox(data, idx, styleUpdater, isInit) {
  41000. graphic.Group.call(this);
  41001. /**
  41002. * @type {number}
  41003. * @readOnly
  41004. */
  41005. this.bodyIndex;
  41006. /**
  41007. * @type {number}
  41008. * @readOnly
  41009. */
  41010. this.whiskerIndex;
  41011. /**
  41012. * @type {Function}
  41013. */
  41014. this.styleUpdater = styleUpdater;
  41015. this._createContent(data, idx, isInit);
  41016. this.updateData(data, idx, isInit);
  41017. /**
  41018. * Last series model.
  41019. * @type {module:echarts/model/Series}
  41020. */
  41021. this._seriesModel;
  41022. }
  41023. var whiskerBoxProto = WhiskerBox.prototype;
  41024. whiskerBoxProto._createContent = function (data, idx, isInit) {
  41025. var itemLayout = data.getItemLayout(idx);
  41026. var constDim = itemLayout.chartLayout === 'horizontal' ? 1 : 0;
  41027. var count = 0;
  41028. // Whisker element.
  41029. this.add(new graphic.Polygon({
  41030. shape: {
  41031. points: isInit
  41032. ? transInit(itemLayout.bodyEnds, constDim, itemLayout)
  41033. : itemLayout.bodyEnds
  41034. },
  41035. style: {strokeNoScale: true},
  41036. z2: 100
  41037. }));
  41038. this.bodyIndex = count++;
  41039. // Box element.
  41040. var whiskerEnds = zrUtil.map(itemLayout.whiskerEnds, function (ends) {
  41041. return isInit ? transInit(ends, constDim, itemLayout) : ends;
  41042. });
  41043. this.add(new WhiskerPath({
  41044. shape: makeWhiskerEndsShape(whiskerEnds),
  41045. style: {strokeNoScale: true},
  41046. z2: 100
  41047. }));
  41048. this.whiskerIndex = count++;
  41049. };
  41050. function transInit(points, dim, itemLayout) {
  41051. return zrUtil.map(points, function (point) {
  41052. point = point.slice();
  41053. point[dim] = itemLayout.initBaseline;
  41054. return point;
  41055. });
  41056. }
  41057. function makeWhiskerEndsShape(whiskerEnds) {
  41058. // zr animation only support 2-dim array.
  41059. var shape = {};
  41060. zrUtil.each(whiskerEnds, function (ends, i) {
  41061. shape['ends' + i] = ends;
  41062. });
  41063. return shape;
  41064. }
  41065. /**
  41066. * Update symbol properties
  41067. * @param {module:echarts/data/List} data
  41068. * @param {number} idx
  41069. */
  41070. whiskerBoxProto.updateData = function (data, idx, isInit) {
  41071. var seriesModel = this._seriesModel = data.hostModel;
  41072. var itemLayout = data.getItemLayout(idx);
  41073. var updateMethod = graphic[isInit ? 'initProps' : 'updateProps'];
  41074. // this.childAt(this.bodyIndex).stopAnimation(true);
  41075. // this.childAt(this.whiskerIndex).stopAnimation(true);
  41076. updateMethod(
  41077. this.childAt(this.bodyIndex),
  41078. {shape: {points: itemLayout.bodyEnds}},
  41079. seriesModel, idx
  41080. );
  41081. updateMethod(
  41082. this.childAt(this.whiskerIndex),
  41083. {shape: makeWhiskerEndsShape(itemLayout.whiskerEnds)},
  41084. seriesModel, idx
  41085. );
  41086. this.styleUpdater.call(null, this, data, idx);
  41087. };
  41088. zrUtil.inherits(WhiskerBox, graphic.Group);
  41089. /**
  41090. * @constructor
  41091. * @alias module:echarts/chart/helper/WhiskerBoxDraw
  41092. */
  41093. function WhiskerBoxDraw(styleUpdater) {
  41094. this.group = new graphic.Group();
  41095. this.styleUpdater = styleUpdater;
  41096. }
  41097. var whiskerBoxDrawProto = WhiskerBoxDraw.prototype;
  41098. /**
  41099. * Update symbols draw by new data
  41100. * @param {module:echarts/data/List} data
  41101. */
  41102. whiskerBoxDrawProto.updateData = function (data) {
  41103. var group = this.group;
  41104. var oldData = this._data;
  41105. var styleUpdater = this.styleUpdater;
  41106. data.diff(oldData)
  41107. .add(function (newIdx) {
  41108. if (data.hasValue(newIdx)) {
  41109. var symbolEl = new WhiskerBox(data, newIdx, styleUpdater, true);
  41110. data.setItemGraphicEl(newIdx, symbolEl);
  41111. group.add(symbolEl);
  41112. }
  41113. })
  41114. .update(function (newIdx, oldIdx) {
  41115. var symbolEl = oldData.getItemGraphicEl(oldIdx);
  41116. // Empty data
  41117. if (!data.hasValue(newIdx)) {
  41118. group.remove(symbolEl);
  41119. return;
  41120. }
  41121. if (!symbolEl) {
  41122. symbolEl = new WhiskerBox(data, newIdx, styleUpdater);
  41123. }
  41124. else {
  41125. symbolEl.updateData(data, newIdx);
  41126. }
  41127. // Add back
  41128. group.add(symbolEl);
  41129. data.setItemGraphicEl(newIdx, symbolEl);
  41130. })
  41131. .remove(function (oldIdx) {
  41132. var el = oldData.getItemGraphicEl(oldIdx);
  41133. el && group.remove(el);
  41134. })
  41135. .execute();
  41136. this._data = data;
  41137. };
  41138. /**
  41139. * Remove symbols.
  41140. * @param {module:echarts/data/List} data
  41141. */
  41142. whiskerBoxDrawProto.remove = function () {
  41143. var group = this.group;
  41144. var data = this._data;
  41145. this._data = null;
  41146. data && data.eachItemGraphicEl(function (el) {
  41147. el && group.remove(el);
  41148. });
  41149. };
  41150. module.exports = WhiskerBoxDraw;
  41151. /***/ },
  41152. /* 260 */
  41153. /***/ function(module, exports, __webpack_require__) {
  41154. 'use strict';
  41155. var zrUtil = __webpack_require__(4);
  41156. var ChartView = __webpack_require__(80);
  41157. var graphic = __webpack_require__(18);
  41158. var whiskerBoxCommon = __webpack_require__(258);
  41159. var BoxplotView = ChartView.extend({
  41160. type: 'boxplot',
  41161. getStyleUpdater: function () {
  41162. return updateStyle;
  41163. },
  41164. dispose: zrUtil.noop
  41165. });
  41166. zrUtil.mixin(BoxplotView, whiskerBoxCommon.viewMixin, true);
  41167. // Update common properties
  41168. var normalStyleAccessPath = ['itemStyle', 'normal'];
  41169. var emphasisStyleAccessPath = ['itemStyle', 'emphasis'];
  41170. function updateStyle(itemGroup, data, idx) {
  41171. var itemModel = data.getItemModel(idx);
  41172. var normalItemStyleModel = itemModel.getModel(normalStyleAccessPath);
  41173. var borderColor = data.getItemVisual(idx, 'color');
  41174. // Exclude borderColor.
  41175. var itemStyle = normalItemStyleModel.getItemStyle(['borderColor']);
  41176. var whiskerEl = itemGroup.childAt(itemGroup.whiskerIndex);
  41177. whiskerEl.style.set(itemStyle);
  41178. whiskerEl.style.stroke = borderColor;
  41179. whiskerEl.dirty();
  41180. var bodyEl = itemGroup.childAt(itemGroup.bodyIndex);
  41181. bodyEl.style.set(itemStyle);
  41182. bodyEl.style.stroke = borderColor;
  41183. bodyEl.dirty();
  41184. var hoverStyle = itemModel.getModel(emphasisStyleAccessPath).getItemStyle();
  41185. graphic.setHoverStyle(itemGroup, hoverStyle);
  41186. }
  41187. module.exports = BoxplotView;
  41188. /***/ },
  41189. /* 261 */
  41190. /***/ function(module, exports) {
  41191. var borderColorQuery = ['itemStyle', 'normal', 'borderColor'];
  41192. module.exports = function (ecModel, api) {
  41193. var globalColors = ecModel.get('color');
  41194. ecModel.eachRawSeriesByType('boxplot', function (seriesModel) {
  41195. var defaulColor = globalColors[seriesModel.seriesIndex % globalColors.length];
  41196. var data = seriesModel.getData();
  41197. data.setVisual({
  41198. legendSymbol: 'roundRect',
  41199. // Use name 'color' but not 'borderColor' for legend usage and
  41200. // visual coding from other component like dataRange.
  41201. color: seriesModel.get(borderColorQuery) || defaulColor
  41202. });
  41203. // Only visible series has each data be visual encoded
  41204. if (!ecModel.isSeriesFiltered(seriesModel)) {
  41205. data.each(function (idx) {
  41206. var itemModel = data.getItemModel(idx);
  41207. data.setItemVisual(
  41208. idx,
  41209. {color: itemModel.get(borderColorQuery, true)}
  41210. );
  41211. });
  41212. }
  41213. });
  41214. };
  41215. /***/ },
  41216. /* 262 */
  41217. /***/ function(module, exports, __webpack_require__) {
  41218. var zrUtil = __webpack_require__(4);
  41219. var numberUtil = __webpack_require__(7);
  41220. var parsePercent = numberUtil.parsePercent;
  41221. var each = zrUtil.each;
  41222. module.exports = function (ecModel) {
  41223. var groupResult = groupSeriesByAxis(ecModel);
  41224. each(groupResult, function (groupItem) {
  41225. var seriesModels = groupItem.seriesModels;
  41226. if (!seriesModels.length) {
  41227. return;
  41228. }
  41229. calculateBase(groupItem);
  41230. each(seriesModels, function (seriesModel, idx) {
  41231. layoutSingleSeries(
  41232. seriesModel,
  41233. groupItem.boxOffsetList[idx],
  41234. groupItem.boxWidthList[idx]
  41235. );
  41236. });
  41237. });
  41238. };
  41239. /**
  41240. * Group series by axis.
  41241. */
  41242. function groupSeriesByAxis(ecModel) {
  41243. var result = [];
  41244. var axisList = [];
  41245. ecModel.eachSeriesByType('boxplot', function (seriesModel) {
  41246. var baseAxis = seriesModel.getBaseAxis();
  41247. var idx = zrUtil.indexOf(axisList, baseAxis);
  41248. if (idx < 0) {
  41249. idx = axisList.length;
  41250. axisList[idx] = baseAxis;
  41251. result[idx] = {axis: baseAxis, seriesModels: []};
  41252. }
  41253. result[idx].seriesModels.push(seriesModel);
  41254. });
  41255. return result;
  41256. }
  41257. /**
  41258. * Calculate offset and box width for each series.
  41259. */
  41260. function calculateBase(groupItem) {
  41261. var extent;
  41262. var baseAxis = groupItem.axis;
  41263. var seriesModels = groupItem.seriesModels;
  41264. var seriesCount = seriesModels.length;
  41265. var boxWidthList = groupItem.boxWidthList = [];
  41266. var boxOffsetList = groupItem.boxOffsetList = [];
  41267. var boundList = [];
  41268. var bandWidth;
  41269. if (baseAxis.type === 'category') {
  41270. bandWidth = baseAxis.getBandWidth();
  41271. }
  41272. else {
  41273. var maxDataCount = 0;
  41274. each(seriesModels, function (seriesModel) {
  41275. maxDataCount = Math.max(maxDataCount, seriesModel.getData().count());
  41276. });
  41277. extent = baseAxis.getExtent(),
  41278. Math.abs(extent[1] - extent[0]) / maxDataCount;
  41279. }
  41280. each(seriesModels, function (seriesModel) {
  41281. var boxWidthBound = seriesModel.get('boxWidth');
  41282. if (!zrUtil.isArray(boxWidthBound)) {
  41283. boxWidthBound = [boxWidthBound, boxWidthBound];
  41284. }
  41285. boundList.push([
  41286. parsePercent(boxWidthBound[0], bandWidth) || 0,
  41287. parsePercent(boxWidthBound[1], bandWidth) || 0
  41288. ]);
  41289. });
  41290. var availableWidth = bandWidth * 0.8 - 2;
  41291. var boxGap = availableWidth / seriesCount * 0.3;
  41292. var boxWidth = (availableWidth - boxGap * (seriesCount - 1)) / seriesCount;
  41293. var base = boxWidth / 2 - availableWidth / 2;
  41294. each(seriesModels, function (seriesModel, idx) {
  41295. boxOffsetList.push(base);
  41296. base += boxGap + boxWidth;
  41297. boxWidthList.push(
  41298. Math.min(Math.max(boxWidth, boundList[idx][0]), boundList[idx][1])
  41299. );
  41300. });
  41301. }
  41302. /**
  41303. * Calculate points location for each series.
  41304. */
  41305. function layoutSingleSeries(seriesModel, offset, boxWidth) {
  41306. var coordSys = seriesModel.coordinateSystem;
  41307. var data = seriesModel.getData();
  41308. var halfWidth = boxWidth / 2;
  41309. var chartLayout = seriesModel.get('layout');
  41310. var variableDim = chartLayout === 'horizontal' ? 0 : 1;
  41311. var constDim = 1 - variableDim;
  41312. var coordDims = ['x', 'y'];
  41313. var vDims = [];
  41314. var cDim;
  41315. zrUtil.each(data.dimensions, function (dimName) {
  41316. var dimInfo = data.getDimensionInfo(dimName);
  41317. var coordDim = dimInfo.coordDim;
  41318. if (coordDim === coordDims[constDim]) {
  41319. vDims.push(dimName);
  41320. }
  41321. else if (coordDim === coordDims[variableDim]) {
  41322. cDim = dimName;
  41323. }
  41324. });
  41325. if (cDim == null || vDims.length < 5) {
  41326. return;
  41327. }
  41328. data.each([cDim].concat(vDims), function () {
  41329. var args = arguments;
  41330. var axisDimVal = args[0];
  41331. var idx = args[vDims.length + 1];
  41332. var median = getPoint(args[3]);
  41333. var end1 = getPoint(args[1]);
  41334. var end5 = getPoint(args[5]);
  41335. var whiskerEnds = [
  41336. [end1, getPoint(args[2])],
  41337. [end5, getPoint(args[4])]
  41338. ];
  41339. layEndLine(end1);
  41340. layEndLine(end5);
  41341. layEndLine(median);
  41342. var bodyEnds = [];
  41343. addBodyEnd(whiskerEnds[0][1], 0);
  41344. addBodyEnd(whiskerEnds[1][1], 1);
  41345. data.setItemLayout(idx, {
  41346. chartLayout: chartLayout,
  41347. initBaseline: median[constDim],
  41348. median: median,
  41349. bodyEnds: bodyEnds,
  41350. whiskerEnds: whiskerEnds
  41351. });
  41352. function getPoint(val) {
  41353. var p = [];
  41354. p[variableDim] = axisDimVal;
  41355. p[constDim] = val;
  41356. var point;
  41357. if (isNaN(axisDimVal) || isNaN(val)) {
  41358. point = [NaN, NaN];
  41359. }
  41360. else {
  41361. point = coordSys.dataToPoint(p);
  41362. point[variableDim] += offset;
  41363. }
  41364. return point;
  41365. }
  41366. function addBodyEnd(point, start) {
  41367. var point1 = point.slice();
  41368. var point2 = point.slice();
  41369. point1[variableDim] += halfWidth;
  41370. point2[variableDim] -= halfWidth;
  41371. start
  41372. ? bodyEnds.push(point1, point2)
  41373. : bodyEnds.push(point2, point1);
  41374. }
  41375. function layEndLine(endCenter) {
  41376. var line = [endCenter.slice(), endCenter.slice()];
  41377. line[0][variableDim] -= halfWidth;
  41378. line[1][variableDim] += halfWidth;
  41379. whiskerEnds.push(line);
  41380. }
  41381. });
  41382. }
  41383. /***/ },
  41384. /* 263 */
  41385. /***/ function(module, exports, __webpack_require__) {
  41386. var echarts = __webpack_require__(1);
  41387. __webpack_require__(264);
  41388. __webpack_require__(265);
  41389. echarts.registerPreprocessor(
  41390. __webpack_require__(266)
  41391. );
  41392. echarts.registerVisual(__webpack_require__(267));
  41393. echarts.registerLayout(__webpack_require__(268));
  41394. /***/ },
  41395. /* 264 */
  41396. /***/ function(module, exports, __webpack_require__) {
  41397. 'use strict';
  41398. var zrUtil = __webpack_require__(4);
  41399. var SeriesModel = __webpack_require__(78);
  41400. var whiskerBoxCommon = __webpack_require__(258);
  41401. var CandlestickSeries = SeriesModel.extend({
  41402. type: 'series.candlestick',
  41403. dependencies: ['xAxis', 'yAxis', 'grid'],
  41404. /**
  41405. * @readOnly
  41406. */
  41407. defaultValueDimensions: ['open', 'close', 'lowest', 'highest'],
  41408. /**
  41409. * @type {Array.<string>}
  41410. * @readOnly
  41411. */
  41412. dimensions: null,
  41413. /**
  41414. * @override
  41415. */
  41416. defaultOption: {
  41417. zlevel: 0, // 一级层叠
  41418. z: 2, // 二级层叠
  41419. coordinateSystem: 'cartesian2d',
  41420. legendHoverLink: true,
  41421. hoverAnimation: true,
  41422. // xAxisIndex: 0,
  41423. // yAxisIndex: 0,
  41424. layout: null, // 'horizontal' or 'vertical'
  41425. itemStyle: {
  41426. normal: {
  41427. color: '#c23531', // 阳线 positive
  41428. color0: '#314656', // 阴线 negative '#c23531', '#314656'
  41429. borderWidth: 1,
  41430. // FIXME
  41431. // ec2中使用的是lineStyle.color 和 lineStyle.color0
  41432. borderColor: '#c23531',
  41433. borderColor0: '#314656'
  41434. },
  41435. emphasis: {
  41436. borderWidth: 2
  41437. }
  41438. },
  41439. barMaxWidth: null,
  41440. barMinWidth: null,
  41441. barWidth: null,
  41442. animationUpdate: false,
  41443. animationEasing: 'linear',
  41444. animationDuration: 300
  41445. },
  41446. /**
  41447. * Get dimension for shadow in dataZoom
  41448. * @return {string} dimension name
  41449. */
  41450. getShadowDim: function () {
  41451. return 'open';
  41452. },
  41453. brushSelector: function (dataIndex, data, selectors) {
  41454. var itemLayout = data.getItemLayout(dataIndex);
  41455. return selectors.rect(itemLayout.brushRect);
  41456. }
  41457. });
  41458. zrUtil.mixin(CandlestickSeries, whiskerBoxCommon.seriesModelMixin, true);
  41459. module.exports = CandlestickSeries;
  41460. /***/ },
  41461. /* 265 */
  41462. /***/ function(module, exports, __webpack_require__) {
  41463. 'use strict';
  41464. var zrUtil = __webpack_require__(4);
  41465. var ChartView = __webpack_require__(80);
  41466. var graphic = __webpack_require__(18);
  41467. var whiskerBoxCommon = __webpack_require__(258);
  41468. var CandlestickView = ChartView.extend({
  41469. type: 'candlestick',
  41470. getStyleUpdater: function () {
  41471. return updateStyle;
  41472. },
  41473. dispose: zrUtil.noop
  41474. });
  41475. zrUtil.mixin(CandlestickView, whiskerBoxCommon.viewMixin, true);
  41476. // Update common properties
  41477. var normalStyleAccessPath = ['itemStyle', 'normal'];
  41478. var emphasisStyleAccessPath = ['itemStyle', 'emphasis'];
  41479. function updateStyle(itemGroup, data, idx) {
  41480. var itemModel = data.getItemModel(idx);
  41481. var normalItemStyleModel = itemModel.getModel(normalStyleAccessPath);
  41482. var color = data.getItemVisual(idx, 'color');
  41483. var borderColor = data.getItemVisual(idx, 'borderColor') || color;
  41484. // Color must be excluded.
  41485. // Because symbol provide setColor individually to set fill and stroke
  41486. var itemStyle = normalItemStyleModel.getItemStyle(
  41487. ['color', 'color0', 'borderColor', 'borderColor0']
  41488. );
  41489. var whiskerEl = itemGroup.childAt(itemGroup.whiskerIndex);
  41490. whiskerEl.useStyle(itemStyle);
  41491. whiskerEl.style.stroke = borderColor;
  41492. var bodyEl = itemGroup.childAt(itemGroup.bodyIndex);
  41493. bodyEl.useStyle(itemStyle);
  41494. bodyEl.style.fill = color;
  41495. bodyEl.style.stroke = borderColor;
  41496. var hoverStyle = itemModel.getModel(emphasisStyleAccessPath).getItemStyle();
  41497. graphic.setHoverStyle(itemGroup, hoverStyle);
  41498. }
  41499. module.exports = CandlestickView;
  41500. /***/ },
  41501. /* 266 */
  41502. /***/ function(module, exports, __webpack_require__) {
  41503. var zrUtil = __webpack_require__(4);
  41504. module.exports = function (option) {
  41505. if (!option || !zrUtil.isArray(option.series)) {
  41506. return;
  41507. }
  41508. // Translate 'k' to 'candlestick'.
  41509. zrUtil.each(option.series, function (seriesItem) {
  41510. if (zrUtil.isObject(seriesItem) && seriesItem.type === 'k') {
  41511. seriesItem.type = 'candlestick';
  41512. }
  41513. });
  41514. };
  41515. /***/ },
  41516. /* 267 */
  41517. /***/ function(module, exports) {
  41518. var positiveBorderColorQuery = ['itemStyle', 'normal', 'borderColor'];
  41519. var negativeBorderColorQuery = ['itemStyle', 'normal', 'borderColor0'];
  41520. var positiveColorQuery = ['itemStyle', 'normal', 'color'];
  41521. var negativeColorQuery = ['itemStyle', 'normal', 'color0'];
  41522. module.exports = function (ecModel, api) {
  41523. ecModel.eachRawSeriesByType('candlestick', function (seriesModel) {
  41524. var data = seriesModel.getData();
  41525. data.setVisual({
  41526. legendSymbol: 'roundRect'
  41527. });
  41528. // Only visible series has each data be visual encoded
  41529. if (!ecModel.isSeriesFiltered(seriesModel)) {
  41530. data.each(function (idx) {
  41531. var itemModel = data.getItemModel(idx);
  41532. var sign = data.getItemLayout(idx).sign;
  41533. data.setItemVisual(
  41534. idx,
  41535. {
  41536. color: itemModel.get(
  41537. sign > 0 ? positiveColorQuery : negativeColorQuery
  41538. ),
  41539. borderColor: itemModel.get(
  41540. sign > 0 ? positiveBorderColorQuery : negativeBorderColorQuery
  41541. )
  41542. }
  41543. );
  41544. });
  41545. }
  41546. });
  41547. };
  41548. /***/ },
  41549. /* 268 */
  41550. /***/ function(module, exports, __webpack_require__) {
  41551. var zrUtil = __webpack_require__(4);
  41552. var retrieve = __webpack_require__(4).retrieve;
  41553. var parsePercent = __webpack_require__(7).parsePercent;
  41554. module.exports = function (ecModel) {
  41555. ecModel.eachSeriesByType('candlestick', function (seriesModel) {
  41556. var coordSys = seriesModel.coordinateSystem;
  41557. var data = seriesModel.getData();
  41558. var candleWidth = calculateCandleWidth(seriesModel, data);
  41559. var chartLayout = seriesModel.get('layout');
  41560. var variableDim = chartLayout === 'horizontal' ? 0 : 1;
  41561. var constDim = 1 - variableDim;
  41562. var coordDims = ['x', 'y'];
  41563. var vDims = [];
  41564. var cDim;
  41565. zrUtil.each(data.dimensions, function (dimName) {
  41566. var dimInfo = data.getDimensionInfo(dimName);
  41567. var coordDim = dimInfo.coordDim;
  41568. if (coordDim === coordDims[constDim]) {
  41569. vDims.push(dimName);
  41570. }
  41571. else if (coordDim === coordDims[variableDim]) {
  41572. cDim = dimName;
  41573. }
  41574. });
  41575. if (cDim == null || vDims.length < 4) {
  41576. return;
  41577. }
  41578. data.each([cDim].concat(vDims), function () {
  41579. var args = arguments;
  41580. var axisDimVal = args[0];
  41581. var idx = args[vDims.length + 1];
  41582. var openVal = args[1];
  41583. var closeVal = args[2];
  41584. var lowestVal = args[3];
  41585. var highestVal = args[4];
  41586. var ocLow = Math.min(openVal, closeVal);
  41587. var ocHigh = Math.max(openVal, closeVal);
  41588. var ocLowPoint = getPoint(ocLow);
  41589. var ocHighPoint = getPoint(ocHigh);
  41590. var lowestPoint = getPoint(lowestVal);
  41591. var highestPoint = getPoint(highestVal);
  41592. var whiskerEnds = [
  41593. [highestPoint, ocHighPoint],
  41594. [lowestPoint, ocLowPoint]
  41595. ];
  41596. var bodyEnds = [];
  41597. addBodyEnd(ocHighPoint, 0);
  41598. addBodyEnd(ocLowPoint, 1);
  41599. data.setItemLayout(idx, {
  41600. chartLayout: chartLayout,
  41601. sign: openVal > closeVal ? -1 : openVal < closeVal ? 1 : 0,
  41602. initBaseline: openVal > closeVal
  41603. ? ocHighPoint[constDim] : ocLowPoint[constDim], // open point.
  41604. bodyEnds: bodyEnds,
  41605. whiskerEnds: whiskerEnds,
  41606. brushRect: makeBrushRect()
  41607. });
  41608. function getPoint(val) {
  41609. var p = [];
  41610. p[variableDim] = axisDimVal;
  41611. p[constDim] = val;
  41612. return (isNaN(axisDimVal) || isNaN(val))
  41613. ? [NaN, NaN]
  41614. : coordSys.dataToPoint(p);
  41615. }
  41616. function addBodyEnd(point, start) {
  41617. var point1 = point.slice();
  41618. var point2 = point.slice();
  41619. point1[variableDim] += candleWidth / 2;
  41620. point2[variableDim] -= candleWidth / 2;
  41621. start
  41622. ? bodyEnds.push(point1, point2)
  41623. : bodyEnds.push(point2, point1);
  41624. }
  41625. function makeBrushRect() {
  41626. var pmin = getPoint(Math.min(openVal, closeVal, lowestVal, highestVal));
  41627. var pmax = getPoint(Math.max(openVal, closeVal, lowestVal, highestVal));
  41628. pmin[variableDim] -= candleWidth / 2;
  41629. pmax[variableDim] -= candleWidth / 2;
  41630. return {
  41631. x: pmin[0],
  41632. y: pmin[1],
  41633. width: constDim ? candleWidth : pmax[0] - pmin[0],
  41634. height: constDim ? pmax[1] - pmin[1] : candleWidth
  41635. };
  41636. }
  41637. }, true);
  41638. });
  41639. };
  41640. function calculateCandleWidth(seriesModel, data) {
  41641. var baseAxis = seriesModel.getBaseAxis();
  41642. var extent;
  41643. var bandWidth = baseAxis.type === 'category'
  41644. ? baseAxis.getBandWidth()
  41645. : (
  41646. extent = baseAxis.getExtent(),
  41647. Math.abs(extent[1] - extent[0]) / data.count()
  41648. );
  41649. var barMaxWidth = parsePercent(
  41650. retrieve(seriesModel.get('barMaxWidth'), bandWidth),
  41651. bandWidth
  41652. );
  41653. var barMinWidth = parsePercent(
  41654. retrieve(seriesModel.get('barMinWidth'), 1),
  41655. bandWidth
  41656. );
  41657. var barWidth = seriesModel.get('barWidth');
  41658. return barWidth != null
  41659. ? parsePercent(barWidth, bandWidth)
  41660. // Put max outer to ensure bar visible in spite of overlap.
  41661. : Math.max(Math.min(bandWidth / 2, barMaxWidth), barMinWidth);
  41662. }
  41663. /***/ },
  41664. /* 269 */
  41665. /***/ function(module, exports, __webpack_require__) {
  41666. var zrUtil = __webpack_require__(4);
  41667. var echarts = __webpack_require__(1);
  41668. __webpack_require__(270);
  41669. __webpack_require__(271);
  41670. echarts.registerVisual(zrUtil.curry(
  41671. __webpack_require__(121), 'effectScatter', 'circle', null
  41672. ));
  41673. echarts.registerLayout(zrUtil.curry(
  41674. __webpack_require__(122), 'effectScatter'
  41675. ));
  41676. /***/ },
  41677. /* 270 */
  41678. /***/ function(module, exports, __webpack_require__) {
  41679. 'use strict';
  41680. var createListFromArray = __webpack_require__(109);
  41681. var SeriesModel = __webpack_require__(78);
  41682. module.exports = SeriesModel.extend({
  41683. type: 'series.effectScatter',
  41684. dependencies: ['grid', 'polar'],
  41685. getInitialData: function (option, ecModel) {
  41686. var list = createListFromArray(option.data, this, ecModel);
  41687. return list;
  41688. },
  41689. brushSelector: 'point',
  41690. defaultOption: {
  41691. coordinateSystem: 'cartesian2d',
  41692. zlevel: 0,
  41693. z: 2,
  41694. legendHoverLink: true,
  41695. effectType: 'ripple',
  41696. progressive: 0,
  41697. // When to show the effect, option: 'render'|'emphasis'
  41698. showEffectOn: 'render',
  41699. // Ripple effect config
  41700. rippleEffect: {
  41701. period: 4,
  41702. // Scale of ripple
  41703. scale: 2.5,
  41704. // Brush type can be fill or stroke
  41705. brushType: 'fill'
  41706. },
  41707. // Cartesian coordinate system
  41708. // xAxisIndex: 0,
  41709. // yAxisIndex: 0,
  41710. // Polar coordinate system
  41711. // polarIndex: 0,
  41712. // Geo coordinate system
  41713. // geoIndex: 0,
  41714. // symbol: null, // 图形类型
  41715. symbolSize: 10 // 图形大小,半宽(半径)参数,当图形为方向或菱形则总宽度为symbolSize * 2
  41716. // symbolRotate: null, // 图形旋转控制
  41717. // large: false,
  41718. // Available when large is true
  41719. // largeThreshold: 2000,
  41720. // itemStyle: {
  41721. // normal: {
  41722. // opacity: 1
  41723. // }
  41724. // }
  41725. }
  41726. });
  41727. /***/ },
  41728. /* 271 */
  41729. /***/ function(module, exports, __webpack_require__) {
  41730. var SymbolDraw = __webpack_require__(116);
  41731. var EffectSymbol = __webpack_require__(272);
  41732. __webpack_require__(1).extendChartView({
  41733. type: 'effectScatter',
  41734. init: function () {
  41735. this._symbolDraw = new SymbolDraw(EffectSymbol);
  41736. },
  41737. render: function (seriesModel, ecModel, api) {
  41738. var data = seriesModel.getData();
  41739. var effectSymbolDraw = this._symbolDraw;
  41740. effectSymbolDraw.updateData(data);
  41741. this.group.add(effectSymbolDraw.group);
  41742. },
  41743. updateLayout: function () {
  41744. this._symbolDraw.updateLayout();
  41745. },
  41746. remove: function (ecModel, api) {
  41747. this._symbolDraw && this._symbolDraw.remove(api);
  41748. },
  41749. dispose: function () {}
  41750. });
  41751. /***/ },
  41752. /* 272 */
  41753. /***/ function(module, exports, __webpack_require__) {
  41754. /**
  41755. * Symbol with ripple effect
  41756. * @module echarts/chart/helper/EffectSymbol
  41757. */
  41758. var zrUtil = __webpack_require__(4);
  41759. var symbolUtil = __webpack_require__(111);
  41760. var graphic = __webpack_require__(18);
  41761. var numberUtil = __webpack_require__(7);
  41762. var Symbol = __webpack_require__(117);
  41763. var Group = graphic.Group;
  41764. var EFFECT_RIPPLE_NUMBER = 3;
  41765. function normalizeSymbolSize(symbolSize) {
  41766. if (!zrUtil.isArray(symbolSize)) {
  41767. symbolSize = [+symbolSize, +symbolSize];
  41768. }
  41769. return symbolSize;
  41770. }
  41771. function updateRipplePath(rippleGroup, effectCfg) {
  41772. rippleGroup.eachChild(function (ripplePath) {
  41773. ripplePath.attr({
  41774. z: effectCfg.z,
  41775. zlevel: effectCfg.zlevel,
  41776. style: {
  41777. stroke: effectCfg.brushType === 'stroke' ? effectCfg.color : null,
  41778. fill: effectCfg.brushType === 'fill' ? effectCfg.color : null
  41779. }
  41780. });
  41781. });
  41782. }
  41783. /**
  41784. * @constructor
  41785. * @param {module:echarts/data/List} data
  41786. * @param {number} idx
  41787. * @extends {module:zrender/graphic/Group}
  41788. */
  41789. function EffectSymbol(data, idx) {
  41790. Group.call(this);
  41791. var symbol = new Symbol(data, idx);
  41792. var rippleGroup = new Group();
  41793. this.add(symbol);
  41794. this.add(rippleGroup);
  41795. rippleGroup.beforeUpdate = function () {
  41796. this.attr(symbol.getScale());
  41797. };
  41798. this.updateData(data, idx);
  41799. }
  41800. var effectSymbolProto = EffectSymbol.prototype;
  41801. effectSymbolProto.stopEffectAnimation = function () {
  41802. this.childAt(1).removeAll();
  41803. };
  41804. effectSymbolProto.startEffectAnimation = function (effectCfg) {
  41805. var symbolType = effectCfg.symbolType;
  41806. var color = effectCfg.color;
  41807. var rippleGroup = this.childAt(1);
  41808. for (var i = 0; i < EFFECT_RIPPLE_NUMBER; i++) {
  41809. // var ripplePath = symbolUtil.createSymbol(
  41810. // symbolType, -0.5, -0.5, 1, 1, color
  41811. // );
  41812. // If width/height are set too small (e.g., set to 1) on ios10
  41813. // and macOS Sierra, a circle stroke become a rect, no matter what
  41814. // the scale is set. So we set width/height as 2. See #4136.
  41815. var ripplePath = symbolUtil.createSymbol(
  41816. symbolType, -1, -1, 2, 2, color
  41817. );
  41818. ripplePath.attr({
  41819. style: {
  41820. strokeNoScale: true
  41821. },
  41822. z2: 99,
  41823. silent: true,
  41824. scale: [0.5, 0.5]
  41825. });
  41826. var delay = -i / EFFECT_RIPPLE_NUMBER * effectCfg.period + effectCfg.effectOffset;
  41827. // TODO Configurable effectCfg.period
  41828. ripplePath.animate('', true)
  41829. .when(effectCfg.period, {
  41830. scale: [effectCfg.rippleScale / 2, effectCfg.rippleScale / 2]
  41831. })
  41832. .delay(delay)
  41833. .start();
  41834. ripplePath.animateStyle(true)
  41835. .when(effectCfg.period, {
  41836. opacity: 0
  41837. })
  41838. .delay(delay)
  41839. .start();
  41840. rippleGroup.add(ripplePath);
  41841. }
  41842. updateRipplePath(rippleGroup, effectCfg);
  41843. };
  41844. /**
  41845. * Update effect symbol
  41846. */
  41847. effectSymbolProto.updateEffectAnimation = function (effectCfg) {
  41848. var oldEffectCfg = this._effectCfg;
  41849. var rippleGroup = this.childAt(1);
  41850. // Must reinitialize effect if following configuration changed
  41851. var DIFFICULT_PROPS = ['symbolType', 'period', 'rippleScale'];
  41852. for (var i = 0; i < DIFFICULT_PROPS; i++) {
  41853. var propName = DIFFICULT_PROPS[i];
  41854. if (oldEffectCfg[propName] !== effectCfg[propName]) {
  41855. this.stopEffectAnimation();
  41856. this.startEffectAnimation(effectCfg);
  41857. return;
  41858. }
  41859. }
  41860. updateRipplePath(rippleGroup, effectCfg);
  41861. };
  41862. /**
  41863. * Highlight symbol
  41864. */
  41865. effectSymbolProto.highlight = function () {
  41866. this.trigger('emphasis');
  41867. };
  41868. /**
  41869. * Downplay symbol
  41870. */
  41871. effectSymbolProto.downplay = function () {
  41872. this.trigger('normal');
  41873. };
  41874. /**
  41875. * Update symbol properties
  41876. * @param {module:echarts/data/List} data
  41877. * @param {number} idx
  41878. */
  41879. effectSymbolProto.updateData = function (data, idx) {
  41880. var seriesModel = data.hostModel;
  41881. this.childAt(0).updateData(data, idx);
  41882. var rippleGroup = this.childAt(1);
  41883. var itemModel = data.getItemModel(idx);
  41884. var symbolType = data.getItemVisual(idx, 'symbol');
  41885. var symbolSize = normalizeSymbolSize(data.getItemVisual(idx, 'symbolSize'));
  41886. var color = data.getItemVisual(idx, 'color');
  41887. rippleGroup.attr('scale', symbolSize);
  41888. rippleGroup.traverse(function (ripplePath) {
  41889. ripplePath.attr({
  41890. fill: color
  41891. });
  41892. });
  41893. var symbolOffset = itemModel.getShallow('symbolOffset');
  41894. if (symbolOffset) {
  41895. var pos = rippleGroup.position;
  41896. pos[0] = numberUtil.parsePercent(symbolOffset[0], symbolSize[0]);
  41897. pos[1] = numberUtil.parsePercent(symbolOffset[1], symbolSize[1]);
  41898. }
  41899. rippleGroup.rotation = (itemModel.getShallow('symbolRotate') || 0) * Math.PI / 180 || 0;
  41900. var effectCfg = {};
  41901. effectCfg.showEffectOn = seriesModel.get('showEffectOn');
  41902. effectCfg.rippleScale = itemModel.get('rippleEffect.scale');
  41903. effectCfg.brushType = itemModel.get('rippleEffect.brushType');
  41904. effectCfg.period = itemModel.get('rippleEffect.period') * 1000;
  41905. effectCfg.effectOffset = idx / data.count();
  41906. effectCfg.z = itemModel.getShallow('z') || 0;
  41907. effectCfg.zlevel = itemModel.getShallow('zlevel') || 0;
  41908. effectCfg.symbolType = symbolType;
  41909. effectCfg.color = color;
  41910. this.off('mouseover').off('mouseout').off('emphasis').off('normal');
  41911. if (effectCfg.showEffectOn === 'render') {
  41912. this._effectCfg
  41913. ? this.updateEffectAnimation(effectCfg)
  41914. : this.startEffectAnimation(effectCfg);
  41915. this._effectCfg = effectCfg;
  41916. }
  41917. else {
  41918. // Not keep old effect config
  41919. this._effectCfg = null;
  41920. this.stopEffectAnimation();
  41921. var symbol = this.childAt(0);
  41922. var onEmphasis = function () {
  41923. symbol.trigger('emphasis');
  41924. if (effectCfg.showEffectOn !== 'render') {
  41925. this.startEffectAnimation(effectCfg);
  41926. }
  41927. };
  41928. var onNormal = function () {
  41929. symbol.trigger('normal');
  41930. if (effectCfg.showEffectOn !== 'render') {
  41931. this.stopEffectAnimation();
  41932. }
  41933. };
  41934. this.on('mouseover', onEmphasis, this)
  41935. .on('mouseout', onNormal, this)
  41936. .on('emphasis', onEmphasis, this)
  41937. .on('normal', onNormal, this);
  41938. }
  41939. this._effectCfg = effectCfg;
  41940. };
  41941. effectSymbolProto.fadeOut = function (cb) {
  41942. this.off('mouseover').off('mouseout').off('emphasis').off('normal');
  41943. cb && cb();
  41944. };
  41945. zrUtil.inherits(EffectSymbol, Group);
  41946. module.exports = EffectSymbol;
  41947. /***/ },
  41948. /* 273 */
  41949. /***/ function(module, exports, __webpack_require__) {
  41950. __webpack_require__(274);
  41951. __webpack_require__(275);
  41952. var echarts = __webpack_require__(1);
  41953. echarts.registerLayout(
  41954. __webpack_require__(280)
  41955. );
  41956. echarts.registerVisual(
  41957. __webpack_require__(281)
  41958. );
  41959. /***/ },
  41960. /* 274 */
  41961. /***/ function(module, exports, __webpack_require__) {
  41962. 'use strict';
  41963. var SeriesModel = __webpack_require__(78);
  41964. var List = __webpack_require__(98);
  41965. var zrUtil = __webpack_require__(4);
  41966. var formatUtil = __webpack_require__(6);
  41967. var CoordinateSystem = __webpack_require__(76);
  41968. // Convert [ [{coord: []}, {coord: []}] ]
  41969. // to [ { coords: [[]] } ]
  41970. function preprocessOption (seriesOpt) {
  41971. var data = seriesOpt.data;
  41972. if (data && data[0] && data[0][0] && data[0][0].coord) {
  41973. if (true) {
  41974. console.warn('Lines data configuration has been changed to'
  41975. + ' { coords:[[1,2],[2,3]] }');
  41976. }
  41977. seriesOpt.data = zrUtil.map(data, function (itemOpt) {
  41978. var coords = [
  41979. itemOpt[0].coord, itemOpt[1].coord
  41980. ];
  41981. var target = {
  41982. coords: coords
  41983. };
  41984. if (itemOpt[0].name) {
  41985. target.fromName = itemOpt[0].name;
  41986. }
  41987. if (itemOpt[1].name) {
  41988. target.toName = itemOpt[1].name;
  41989. }
  41990. return zrUtil.mergeAll([target, itemOpt[0], itemOpt[1]]);
  41991. });
  41992. }
  41993. }
  41994. var LinesSeries = SeriesModel.extend({
  41995. type: 'series.lines',
  41996. dependencies: ['grid', 'polar'],
  41997. visualColorAccessPath: 'lineStyle.normal.color',
  41998. init: function (option) {
  41999. // Not using preprocessor because mergeOption may not have series.type
  42000. preprocessOption(option);
  42001. LinesSeries.superApply(this, 'init', arguments);
  42002. },
  42003. mergeOption: function (option) {
  42004. preprocessOption(option);
  42005. LinesSeries.superApply(this, 'mergeOption', arguments);
  42006. },
  42007. getInitialData: function (option, ecModel) {
  42008. if (true) {
  42009. var CoordSys = CoordinateSystem.get(option.coordinateSystem);
  42010. if (!CoordSys) {
  42011. throw new Error('Unkown coordinate system ' + option.coordinateSystem);
  42012. }
  42013. }
  42014. var lineData = new List(['value'], this);
  42015. lineData.hasItemOption = false;
  42016. lineData.initData(option.data, [], function (dataItem, dimName, dataIndex, dimIndex) {
  42017. // dataItem is simply coords
  42018. if (dataItem instanceof Array) {
  42019. return NaN;
  42020. }
  42021. else {
  42022. lineData.hasItemOption = true;
  42023. var value = dataItem.value;
  42024. if (value != null) {
  42025. return value instanceof Array ? value[dimIndex] : value;
  42026. }
  42027. }
  42028. });
  42029. return lineData;
  42030. },
  42031. formatTooltip: function (dataIndex) {
  42032. var data = this.getData();
  42033. var itemModel = data.getItemModel(dataIndex);
  42034. var name = itemModel.get('name');
  42035. if (name) {
  42036. return name;
  42037. }
  42038. var fromName = itemModel.get('fromName');
  42039. var toName = itemModel.get('toName');
  42040. var html = [];
  42041. fromName != null && html.push(fromName);
  42042. toName != null && html.push(toName);
  42043. return formatUtil.encodeHTML(html.join(' > '));
  42044. },
  42045. defaultOption: {
  42046. coordinateSystem: 'geo',
  42047. zlevel: 0,
  42048. z: 2,
  42049. legendHoverLink: true,
  42050. hoverAnimation: true,
  42051. // Cartesian coordinate system
  42052. xAxisIndex: 0,
  42053. yAxisIndex: 0,
  42054. symbol: ['none', 'none'],
  42055. symbolSize: [10, 10],
  42056. // Geo coordinate system
  42057. geoIndex: 0,
  42058. effect: {
  42059. show: false,
  42060. period: 4,
  42061. // Animation delay. support callback
  42062. // delay: 0,
  42063. // If move with constant speed px/sec
  42064. // period will be ignored if this property is > 0,
  42065. constantSpeed: 0,
  42066. symbol: 'circle',
  42067. symbolSize: 3,
  42068. loop: true,
  42069. // Length of trail, 0 - 1
  42070. trailLength: 0.2
  42071. // Same with lineStyle.normal.color
  42072. // color
  42073. },
  42074. large: false,
  42075. // Available when large is true
  42076. largeThreshold: 2000,
  42077. // If lines are polyline
  42078. // polyline not support curveness, label, animation
  42079. polyline: false,
  42080. label: {
  42081. normal: {
  42082. show: false,
  42083. position: 'end'
  42084. // distance: 5,
  42085. // formatter: 标签文本格式器,同Tooltip.formatter,不支持异步回调
  42086. }
  42087. },
  42088. lineStyle: {
  42089. normal: {
  42090. opacity: 0.5
  42091. }
  42092. }
  42093. }
  42094. });
  42095. /***/ },
  42096. /* 275 */
  42097. /***/ function(module, exports, __webpack_require__) {
  42098. var LineDraw = __webpack_require__(209);
  42099. var EffectLine = __webpack_require__(276);
  42100. var Line = __webpack_require__(210);
  42101. var Polyline = __webpack_require__(277);
  42102. var EffectPolyline = __webpack_require__(278);
  42103. var LargeLineDraw = __webpack_require__(279);
  42104. __webpack_require__(1).extendChartView({
  42105. type: 'lines',
  42106. init: function () {},
  42107. render: function (seriesModel, ecModel, api) {
  42108. var data = seriesModel.getData();
  42109. var lineDraw = this._lineDraw;
  42110. var hasEffect = seriesModel.get('effect.show');
  42111. var isPolyline = seriesModel.get('polyline');
  42112. var isLarge = seriesModel.get('large') && data.count() >= seriesModel.get('largeThreshold');
  42113. if (true) {
  42114. if (hasEffect && isLarge) {
  42115. console.warn('Large lines not support effect');
  42116. }
  42117. }
  42118. if (hasEffect !== this._hasEffet || isPolyline !== this._isPolyline || isLarge !== this._isLarge) {
  42119. if (lineDraw) {
  42120. lineDraw.remove();
  42121. }
  42122. lineDraw = this._lineDraw = isLarge
  42123. ? new LargeLineDraw()
  42124. : new LineDraw(
  42125. isPolyline
  42126. ? (hasEffect ? EffectPolyline : Polyline)
  42127. : (hasEffect ? EffectLine : Line)
  42128. );
  42129. this._hasEffet = hasEffect;
  42130. this._isPolyline = isPolyline;
  42131. this._isLarge = isLarge;
  42132. }
  42133. var zlevel = seriesModel.get('zlevel');
  42134. var trailLength = seriesModel.get('effect.trailLength');
  42135. var zr = api.getZr();
  42136. // Avoid the drag cause ghost shadow
  42137. // FIXME Better way ?
  42138. zr.painter.getLayer(zlevel).clear(true);
  42139. // Config layer with motion blur
  42140. if (this._lastZlevel != null) {
  42141. zr.configLayer(this._lastZlevel, {
  42142. motionBlur: false
  42143. });
  42144. }
  42145. if (hasEffect && trailLength) {
  42146. if (true) {
  42147. var notInIndividual = false;
  42148. ecModel.eachSeries(function (otherSeriesModel) {
  42149. if (otherSeriesModel !== seriesModel && otherSeriesModel.get('zlevel') === zlevel) {
  42150. notInIndividual = true;
  42151. }
  42152. });
  42153. notInIndividual && console.warn('Lines with trail effect should have an individual zlevel');
  42154. }
  42155. zr.configLayer(zlevel, {
  42156. motionBlur: true,
  42157. lastFrameAlpha: Math.max(Math.min(trailLength / 10 + 0.9, 1), 0)
  42158. });
  42159. }
  42160. this.group.add(lineDraw.group);
  42161. lineDraw.updateData(data);
  42162. this._lastZlevel = zlevel;
  42163. },
  42164. updateLayout: function (seriesModel, ecModel, api) {
  42165. this._lineDraw.updateLayout(seriesModel);
  42166. // Not use motion when dragging or zooming
  42167. var zr = api.getZr();
  42168. zr.painter.getLayer(this._lastZlevel).clear(true);
  42169. },
  42170. remove: function (ecModel, api) {
  42171. this._lineDraw && this._lineDraw.remove(api, true);
  42172. },
  42173. dispose: function () {}
  42174. });
  42175. /***/ },
  42176. /* 276 */
  42177. /***/ function(module, exports, __webpack_require__) {
  42178. /**
  42179. * Provide effect for line
  42180. * @module echarts/chart/helper/EffectLine
  42181. */
  42182. var graphic = __webpack_require__(18);
  42183. var Line = __webpack_require__(210);
  42184. var zrUtil = __webpack_require__(4);
  42185. var symbolUtil = __webpack_require__(111);
  42186. var vec2 = __webpack_require__(10);
  42187. var curveUtil = __webpack_require__(37);
  42188. /**
  42189. * @constructor
  42190. * @extends {module:zrender/graphic/Group}
  42191. * @alias {module:echarts/chart/helper/Line}
  42192. */
  42193. function EffectLine(lineData, idx, seriesScope) {
  42194. graphic.Group.call(this);
  42195. this.add(this.createLine(lineData, idx, seriesScope));
  42196. this._updateEffectSymbol(lineData, idx);
  42197. }
  42198. var effectLineProto = EffectLine.prototype;
  42199. effectLineProto.createLine = function (lineData, idx, seriesScope) {
  42200. return new Line(lineData, idx, seriesScope);
  42201. };
  42202. effectLineProto._updateEffectSymbol = function (lineData, idx) {
  42203. var itemModel = lineData.getItemModel(idx);
  42204. var effectModel = itemModel.getModel('effect');
  42205. var size = effectModel.get('symbolSize');
  42206. var symbolType = effectModel.get('symbol');
  42207. if (!zrUtil.isArray(size)) {
  42208. size = [size, size];
  42209. }
  42210. var color = effectModel.get('color') || lineData.getItemVisual(idx, 'color');
  42211. var symbol = this.childAt(1);
  42212. if (this._symbolType !== symbolType) {
  42213. // Remove previous
  42214. this.remove(symbol);
  42215. symbol = symbolUtil.createSymbol(
  42216. symbolType, -0.5, -0.5, 1, 1, color
  42217. );
  42218. symbol.z2 = 100;
  42219. symbol.culling = true;
  42220. this.add(symbol);
  42221. }
  42222. // Symbol may be removed if loop is false
  42223. if (!symbol) {
  42224. return;
  42225. }
  42226. // Shadow color is same with color in default
  42227. symbol.setStyle('shadowColor', color);
  42228. symbol.setStyle(effectModel.getItemStyle(['color']));
  42229. symbol.attr('scale', size);
  42230. symbol.setColor(color);
  42231. symbol.attr('scale', size);
  42232. this._symbolType = symbolType;
  42233. this._updateEffectAnimation(lineData, effectModel, idx);
  42234. };
  42235. effectLineProto._updateEffectAnimation = function (lineData, effectModel, idx) {
  42236. var symbol = this.childAt(1);
  42237. if (!symbol) {
  42238. return;
  42239. }
  42240. var self = this;
  42241. var points = lineData.getItemLayout(idx);
  42242. var period = effectModel.get('period') * 1000;
  42243. var loop = effectModel.get('loop');
  42244. var constantSpeed = effectModel.get('constantSpeed');
  42245. var delayExpr = zrUtil.retrieve(effectModel.get('delay'), function (idx) {
  42246. return idx / lineData.count() * period / 3;
  42247. });
  42248. var isDelayFunc = typeof delayExpr === 'function';
  42249. // Ignore when updating
  42250. symbol.ignore = true;
  42251. this.updateAnimationPoints(symbol, points);
  42252. if (constantSpeed > 0) {
  42253. period = this.getLineLength(symbol) / constantSpeed * 1000;
  42254. }
  42255. if (period !== this._period || loop !== this._loop) {
  42256. symbol.stopAnimation();
  42257. var delay = delayExpr;
  42258. if (isDelayFunc) {
  42259. delay = delayExpr(idx);
  42260. }
  42261. if (symbol.__t > 0) {
  42262. delay = -period * symbol.__t;
  42263. }
  42264. symbol.__t = 0;
  42265. var animator = symbol.animate('', loop)
  42266. .when(period, {
  42267. __t: 1
  42268. })
  42269. .delay(delay)
  42270. .during(function () {
  42271. self.updateSymbolPosition(symbol);
  42272. });
  42273. if (!loop) {
  42274. animator.done(function () {
  42275. self.remove(symbol);
  42276. });
  42277. }
  42278. animator.start();
  42279. }
  42280. this._period = period;
  42281. this._loop = loop;
  42282. };
  42283. effectLineProto.getLineLength = function (symbol) {
  42284. // Not so accurate
  42285. return (vec2.dist(symbol.__p1, symbol.__cp1)
  42286. + vec2.dist(symbol.__cp1, symbol.__p2));
  42287. };
  42288. effectLineProto.updateAnimationPoints = function (symbol, points) {
  42289. symbol.__p1 = points[0];
  42290. symbol.__p2 = points[1];
  42291. symbol.__cp1 = points[2] || [
  42292. (points[0][0] + points[1][0]) / 2,
  42293. (points[0][1] + points[1][1]) / 2
  42294. ];
  42295. };
  42296. effectLineProto.updateData = function (lineData, idx, seriesScope) {
  42297. this.childAt(0).updateData(lineData, idx, seriesScope);
  42298. this._updateEffectSymbol(lineData, idx);
  42299. };
  42300. effectLineProto.updateSymbolPosition = function (symbol) {
  42301. var p1 = symbol.__p1;
  42302. var p2 = symbol.__p2;
  42303. var cp1 = symbol.__cp1;
  42304. var t = symbol.__t;
  42305. var pos = symbol.position;
  42306. var quadraticAt = curveUtil.quadraticAt;
  42307. var quadraticDerivativeAt = curveUtil.quadraticDerivativeAt;
  42308. pos[0] = quadraticAt(p1[0], cp1[0], p2[0], t);
  42309. pos[1] = quadraticAt(p1[1], cp1[1], p2[1], t);
  42310. // Tangent
  42311. var tx = quadraticDerivativeAt(p1[0], cp1[0], p2[0], t);
  42312. var ty = quadraticDerivativeAt(p1[1], cp1[1], p2[1], t);
  42313. symbol.rotation = -Math.atan2(ty, tx) - Math.PI / 2;
  42314. symbol.ignore = false;
  42315. };
  42316. effectLineProto.updateLayout = function (lineData, idx) {
  42317. this.childAt(0).updateLayout(lineData, idx);
  42318. var effectModel = lineData.getItemModel(idx).getModel('effect');
  42319. this._updateEffectAnimation(lineData, effectModel, idx);
  42320. };
  42321. zrUtil.inherits(EffectLine, graphic.Group);
  42322. module.exports = EffectLine;
  42323. /***/ },
  42324. /* 277 */
  42325. /***/ function(module, exports, __webpack_require__) {
  42326. /**
  42327. * @module echarts/chart/helper/Line
  42328. */
  42329. var graphic = __webpack_require__(18);
  42330. var zrUtil = __webpack_require__(4);
  42331. /**
  42332. * @constructor
  42333. * @extends {module:zrender/graphic/Group}
  42334. * @alias {module:echarts/chart/helper/Polyline}
  42335. */
  42336. function Polyline(lineData, idx, seriesScope) {
  42337. graphic.Group.call(this);
  42338. this._createPolyline(lineData, idx, seriesScope);
  42339. }
  42340. var polylineProto = Polyline.prototype;
  42341. polylineProto._createPolyline = function (lineData, idx, seriesScope) {
  42342. // var seriesModel = lineData.hostModel;
  42343. var points = lineData.getItemLayout(idx);
  42344. var line = new graphic.Polyline({
  42345. shape: {
  42346. points: points
  42347. }
  42348. });
  42349. this.add(line);
  42350. this._updateCommonStl(lineData, idx, seriesScope);
  42351. };
  42352. polylineProto.updateData = function (lineData, idx, seriesScope) {
  42353. var seriesModel = lineData.hostModel;
  42354. var line = this.childAt(0);
  42355. var target = {
  42356. shape: {
  42357. points: lineData.getItemLayout(idx)
  42358. }
  42359. };
  42360. graphic.updateProps(line, target, seriesModel, idx);
  42361. this._updateCommonStl(lineData, idx, seriesScope);
  42362. };
  42363. polylineProto._updateCommonStl = function (lineData, idx, seriesScope) {
  42364. var line = this.childAt(0);
  42365. var itemModel = lineData.getItemModel(idx);
  42366. var visualColor = lineData.getItemVisual(idx, 'color');
  42367. var lineStyle = seriesScope && seriesScope.lineStyle;
  42368. var hoverLineStyle = seriesScope && seriesScope.hoverLineStyle;
  42369. if (!seriesScope || lineData.hasItemOption) {
  42370. lineStyle = itemModel.getModel('lineStyle.normal').getLineStyle();
  42371. hoverLineStyle = itemModel.getModel('lineStyle.emphasis').getLineStyle();
  42372. }
  42373. line.useStyle(zrUtil.defaults(
  42374. {
  42375. strokeNoScale: true,
  42376. fill: 'none',
  42377. stroke: visualColor
  42378. },
  42379. lineStyle
  42380. ));
  42381. line.hoverStyle = hoverLineStyle;
  42382. graphic.setHoverStyle(this);
  42383. };
  42384. polylineProto.updateLayout = function (lineData, idx) {
  42385. var polyline = this.childAt(0);
  42386. polyline.setShape('points', lineData.getItemLayout(idx));
  42387. };
  42388. zrUtil.inherits(Polyline, graphic.Group);
  42389. module.exports = Polyline;
  42390. /***/ },
  42391. /* 278 */
  42392. /***/ function(module, exports, __webpack_require__) {
  42393. /**
  42394. * Provide effect for line
  42395. * @module echarts/chart/helper/EffectLine
  42396. */
  42397. var Polyline = __webpack_require__(277);
  42398. var zrUtil = __webpack_require__(4);
  42399. var EffectLine = __webpack_require__(276);
  42400. var vec2 = __webpack_require__(10);
  42401. /**
  42402. * @constructor
  42403. * @extends {module:echarts/chart/helper/EffectLine}
  42404. * @alias {module:echarts/chart/helper/Polyline}
  42405. */
  42406. function EffectPolyline(lineData, idx, seriesScope) {
  42407. EffectLine.call(this, lineData, idx, seriesScope);
  42408. this._lastFrame = 0;
  42409. this._lastFramePercent = 0;
  42410. }
  42411. var effectPolylineProto = EffectPolyline.prototype;
  42412. // Overwrite
  42413. effectPolylineProto.createLine = function (lineData, idx, seriesScope) {
  42414. return new Polyline(lineData, idx, seriesScope);
  42415. };
  42416. // Overwrite
  42417. effectPolylineProto.updateAnimationPoints = function (symbol, points) {
  42418. this._points = points;
  42419. var accLenArr = [0];
  42420. var len = 0;
  42421. for (var i = 1; i < points.length; i++) {
  42422. var p1 = points[i - 1];
  42423. var p2 = points[i];
  42424. len += vec2.dist(p1, p2);
  42425. accLenArr.push(len);
  42426. }
  42427. if (len === 0) {
  42428. return;
  42429. }
  42430. for (var i = 0; i < accLenArr.length; i++) {
  42431. accLenArr[i] /= len;
  42432. }
  42433. this._offsets = accLenArr;
  42434. this._length = len;
  42435. };
  42436. // Overwrite
  42437. effectPolylineProto.getLineLength = function (symbol) {
  42438. return this._length;
  42439. };
  42440. // Overwrite
  42441. effectPolylineProto.updateSymbolPosition = function (symbol) {
  42442. var t = symbol.__t;
  42443. var points = this._points;
  42444. var offsets = this._offsets;
  42445. var len = points.length;
  42446. if (!offsets) {
  42447. // Has length 0
  42448. return;
  42449. }
  42450. var lastFrame = this._lastFrame;
  42451. var frame;
  42452. if (t < this._lastFramePercent) {
  42453. // Start from the next frame
  42454. // PENDING start from lastFrame ?
  42455. var start = Math.min(lastFrame + 1, len - 1);
  42456. for (frame = start; frame >= 0; frame--) {
  42457. if (offsets[frame] <= t) {
  42458. break;
  42459. }
  42460. }
  42461. // PENDING really need to do this ?
  42462. frame = Math.min(frame, len - 2);
  42463. }
  42464. else {
  42465. for (var frame = lastFrame; frame < len; frame++) {
  42466. if (offsets[frame] > t) {
  42467. break;
  42468. }
  42469. }
  42470. frame = Math.min(frame - 1, len - 2);
  42471. }
  42472. vec2.lerp(
  42473. symbol.position, points[frame], points[frame + 1],
  42474. (t - offsets[frame]) / (offsets[frame + 1] - offsets[frame])
  42475. );
  42476. var tx = points[frame + 1][0] - points[frame][0];
  42477. var ty = points[frame + 1][1] - points[frame][1];
  42478. symbol.rotation = -Math.atan2(ty, tx) - Math.PI / 2;
  42479. this._lastFrame = frame;
  42480. this._lastFramePercent = t;
  42481. symbol.ignore = false;
  42482. };
  42483. zrUtil.inherits(EffectPolyline, EffectLine);
  42484. module.exports = EffectPolyline;
  42485. /***/ },
  42486. /* 279 */
  42487. /***/ function(module, exports, __webpack_require__) {
  42488. // TODO Batch by color
  42489. var graphic = __webpack_require__(18);
  42490. var quadraticContain = __webpack_require__(42);
  42491. var lineContain = __webpack_require__(40);
  42492. var LargeLineShape = graphic.extendShape({
  42493. shape: {
  42494. polyline: false,
  42495. segs: []
  42496. },
  42497. buildPath: function (path, shape) {
  42498. var segs = shape.segs;
  42499. var isPolyline = shape.polyline;
  42500. for (var i = 0; i < segs.length; i++) {
  42501. var seg = segs[i];
  42502. if (isPolyline) {
  42503. path.moveTo(seg[0][0], seg[0][1]);
  42504. for (var j = 1; j < seg.length; j++) {
  42505. path.lineTo(seg[j][0], seg[j][1]);
  42506. }
  42507. }
  42508. else {
  42509. path.moveTo(seg[0][0], seg[0][1]);
  42510. if (seg.length > 2) {
  42511. path.quadraticCurveTo(seg[2][0], seg[2][1], seg[1][0], seg[1][1]);
  42512. }
  42513. else {
  42514. path.lineTo(seg[1][0], seg[1][1]);
  42515. }
  42516. }
  42517. }
  42518. },
  42519. findDataIndex: function (x, y) {
  42520. var shape = this.shape;
  42521. var segs = shape.segs;
  42522. var isPolyline = shape.polyline;
  42523. var lineWidth = Math.max(this.style.lineWidth, 1);
  42524. // Not consider transform
  42525. for (var i = 0; i < segs.length; i++) {
  42526. var seg = segs[i];
  42527. if (isPolyline) {
  42528. for (var j = 1; j < seg.length; j++) {
  42529. if (lineContain.containStroke(
  42530. seg[j - 1][0], seg[j - 1][1], seg[j][0], seg[j][1], lineWidth, x, y
  42531. )) {
  42532. return i;
  42533. }
  42534. }
  42535. }
  42536. else {
  42537. if (seg.length > 2) {
  42538. if (quadraticContain.containStroke(
  42539. seg[0][0], seg[0][1], seg[2][0], seg[2][1], seg[1][0], seg[1][1], lineWidth, x, y
  42540. )) {
  42541. return i;
  42542. }
  42543. }
  42544. else {
  42545. if (lineContain.containStroke(
  42546. seg[0][0], seg[0][1], seg[1][0], seg[1][1], lineWidth, x, y
  42547. )) {
  42548. return i;
  42549. }
  42550. }
  42551. }
  42552. }
  42553. return -1;
  42554. }
  42555. });
  42556. function LargeLineDraw() {
  42557. this.group = new graphic.Group();
  42558. this._lineEl = new LargeLineShape();
  42559. }
  42560. var largeLineProto = LargeLineDraw.prototype;
  42561. /**
  42562. * Update symbols draw by new data
  42563. * @param {module:echarts/data/List} data
  42564. */
  42565. largeLineProto.updateData = function (data) {
  42566. this.group.removeAll();
  42567. var lineEl = this._lineEl;
  42568. var seriesModel = data.hostModel;
  42569. lineEl.setShape({
  42570. segs: data.mapArray(data.getItemLayout),
  42571. polyline: seriesModel.get('polyline')
  42572. });
  42573. lineEl.useStyle(
  42574. seriesModel.getModel('lineStyle.normal').getLineStyle()
  42575. );
  42576. var visualColor = data.getVisual('color');
  42577. if (visualColor) {
  42578. lineEl.setStyle('stroke', visualColor);
  42579. }
  42580. lineEl.setStyle('fill');
  42581. // Enable tooltip
  42582. // PENDING May have performance issue when path is extremely large
  42583. lineEl.seriesIndex = seriesModel.seriesIndex;
  42584. lineEl.on('mousemove', function (e) {
  42585. lineEl.dataIndex = null;
  42586. var dataIndex = lineEl.findDataIndex(e.offsetX, e.offsetY);
  42587. if (dataIndex > 0) {
  42588. // Provide dataIndex for tooltip
  42589. lineEl.dataIndex = dataIndex;
  42590. }
  42591. });
  42592. // Add back
  42593. this.group.add(lineEl);
  42594. };
  42595. largeLineProto.updateLayout = function (seriesModel) {
  42596. var data = seriesModel.getData();
  42597. this._lineEl.setShape({
  42598. segs: data.mapArray(data.getItemLayout)
  42599. });
  42600. };
  42601. largeLineProto.remove = function () {
  42602. this.group.removeAll();
  42603. };
  42604. module.exports = LargeLineDraw;
  42605. /***/ },
  42606. /* 280 */
  42607. /***/ function(module, exports, __webpack_require__) {
  42608. module.exports = function (ecModel) {
  42609. ecModel.eachSeriesByType('lines', function (seriesModel) {
  42610. var coordSys = seriesModel.coordinateSystem;
  42611. var lineData = seriesModel.getData();
  42612. // FIXME Use data dimensions ?
  42613. lineData.each(function (idx) {
  42614. var itemModel = lineData.getItemModel(idx);
  42615. var coords = (itemModel.option instanceof Array) ?
  42616. itemModel.option : itemModel.get('coords');
  42617. if (true) {
  42618. if (!(coords instanceof Array && coords.length > 0 && coords[0] instanceof Array)) {
  42619. throw new Error('Invalid coords ' + JSON.stringify(coords) + '. Lines must have 2d coords array in data item.');
  42620. }
  42621. }
  42622. var pts = [];
  42623. if (seriesModel.get('polyline')) {
  42624. for (var i = 0; i < coords.length; i++) {
  42625. pts.push(coordSys.dataToPoint(coords[i]));
  42626. }
  42627. }
  42628. else {
  42629. pts[0] = coordSys.dataToPoint(coords[0]);
  42630. pts[1] = coordSys.dataToPoint(coords[1]);
  42631. var curveness = itemModel.get('lineStyle.normal.curveness');
  42632. if (+curveness) {
  42633. pts[2] = [
  42634. (pts[0][0] + pts[1][0]) / 2 - (pts[0][1] - pts[1][1]) * curveness,
  42635. (pts[0][1] + pts[1][1]) / 2 - (pts[1][0] - pts[0][0]) * curveness
  42636. ];
  42637. }
  42638. }
  42639. lineData.setItemLayout(idx, pts);
  42640. });
  42641. });
  42642. };
  42643. /***/ },
  42644. /* 281 */
  42645. /***/ function(module, exports) {
  42646. function normalize(a) {
  42647. if (!(a instanceof Array)) {
  42648. a = [a, a];
  42649. }
  42650. return a;
  42651. }
  42652. module.exports = function (ecModel) {
  42653. ecModel.eachSeriesByType('lines', function (seriesModel) {
  42654. var data = seriesModel.getData();
  42655. var symbolType = normalize(seriesModel.get('symbol'));
  42656. var symbolSize = normalize(seriesModel.get('symbolSize'));
  42657. var opacityQuery = 'lineStyle.normal.opacity'.split('.');
  42658. data.setVisual('fromSymbol', symbolType && symbolType[0]);
  42659. data.setVisual('toSymbol', symbolType && symbolType[1]);
  42660. data.setVisual('fromSymbolSize', symbolSize && symbolSize[0]);
  42661. data.setVisual('toSymbolSize', symbolSize && symbolSize[1]);
  42662. data.setVisual('opacity', seriesModel.get(opacityQuery));
  42663. data.each(function (idx) {
  42664. var itemModel = data.getItemModel(idx);
  42665. var symbolType = normalize(itemModel.getShallow('symbol', true));
  42666. var symbolSize = normalize(itemModel.getShallow('symbolSize', true));
  42667. var opacity = itemModel.get(opacityQuery);
  42668. symbolType[0] && data.setItemVisual(idx, 'fromSymbol', symbolType[0]);
  42669. symbolType[1] && data.setItemVisual(idx, 'toSymbol', symbolType[1]);
  42670. symbolSize[0] && data.setItemVisual(idx, 'fromSymbolSize', symbolSize[0]);
  42671. symbolSize[1] && data.setItemVisual(idx, 'toSymbolSize', symbolSize[1]);
  42672. data.setItemVisual(idx, 'opacity', opacity);
  42673. });
  42674. });
  42675. };
  42676. /***/ },
  42677. /* 282 */
  42678. /***/ function(module, exports, __webpack_require__) {
  42679. __webpack_require__(283);
  42680. __webpack_require__(284);
  42681. /***/ },
  42682. /* 283 */
  42683. /***/ function(module, exports, __webpack_require__) {
  42684. var SeriesModel = __webpack_require__(78);
  42685. var createListFromArray = __webpack_require__(109);
  42686. module.exports = SeriesModel.extend({
  42687. type: 'series.heatmap',
  42688. getInitialData: function (option, ecModel) {
  42689. return createListFromArray(option.data, this, ecModel);
  42690. },
  42691. defaultOption: {
  42692. // Cartesian2D or geo
  42693. coordinateSystem: 'cartesian2d',
  42694. zlevel: 0,
  42695. z: 2,
  42696. // Cartesian coordinate system
  42697. // xAxisIndex: 0,
  42698. // yAxisIndex: 0,
  42699. // Geo coordinate system
  42700. geoIndex: 0,
  42701. blurSize: 30,
  42702. pointSize: 20,
  42703. maxOpacity: 1,
  42704. minOpacity: 0
  42705. }
  42706. });
  42707. /***/ },
  42708. /* 284 */
  42709. /***/ function(module, exports, __webpack_require__) {
  42710. var graphic = __webpack_require__(18);
  42711. var HeatmapLayer = __webpack_require__(285);
  42712. var zrUtil = __webpack_require__(4);
  42713. function getIsInPiecewiseRange(dataExtent, pieceList, selected) {
  42714. var dataSpan = dataExtent[1] - dataExtent[0];
  42715. pieceList = zrUtil.map(pieceList, function (piece) {
  42716. return {
  42717. interval: [
  42718. (piece.interval[0] - dataExtent[0]) / dataSpan,
  42719. (piece.interval[1] - dataExtent[0]) / dataSpan
  42720. ]
  42721. };
  42722. });
  42723. var len = pieceList.length;
  42724. var lastIndex = 0;
  42725. return function (val) {
  42726. // Try to find in the location of the last found
  42727. for (var i = lastIndex; i < len; i++) {
  42728. var interval = pieceList[i].interval;
  42729. if (interval[0] <= val && val <= interval[1]) {
  42730. lastIndex = i;
  42731. break;
  42732. }
  42733. }
  42734. if (i === len) { // Not found, back interation
  42735. for (var i = lastIndex - 1; i >= 0; i--) {
  42736. var interval = pieceList[i].interval;
  42737. if (interval[0] <= val && val <= interval[1]) {
  42738. lastIndex = i;
  42739. break;
  42740. }
  42741. }
  42742. }
  42743. return i >= 0 && i < len && selected[i];
  42744. };
  42745. }
  42746. function getIsInContinuousRange(dataExtent, range) {
  42747. var dataSpan = dataExtent[1] - dataExtent[0];
  42748. range = [
  42749. (range[0] - dataExtent[0]) / dataSpan,
  42750. (range[1] - dataExtent[0]) / dataSpan
  42751. ];
  42752. return function (val) {
  42753. return val >= range[0] && val <= range[1];
  42754. };
  42755. }
  42756. function isGeoCoordSys(coordSys) {
  42757. var dimensions = coordSys.dimensions;
  42758. // Not use coorSys.type === 'geo' because coordSys maybe extended
  42759. return dimensions[0] === 'lng' && dimensions[1] === 'lat';
  42760. }
  42761. module.exports = __webpack_require__(1).extendChartView({
  42762. type: 'heatmap',
  42763. render: function (seriesModel, ecModel, api) {
  42764. var visualMapOfThisSeries;
  42765. ecModel.eachComponent('visualMap', function (visualMap) {
  42766. visualMap.eachTargetSeries(function (targetSeries) {
  42767. if (targetSeries === seriesModel) {
  42768. visualMapOfThisSeries = visualMap;
  42769. }
  42770. });
  42771. });
  42772. if (true) {
  42773. if (!visualMapOfThisSeries) {
  42774. throw new Error('Heatmap must use with visualMap');
  42775. }
  42776. }
  42777. this.group.removeAll();
  42778. var coordSys = seriesModel.coordinateSystem;
  42779. if (coordSys.type === 'cartesian2d' || coordSys.type === 'calendar') {
  42780. this._renderOnCartesianAndCalendar(coordSys, seriesModel, api);
  42781. }
  42782. else if (isGeoCoordSys(coordSys)) {
  42783. this._renderOnGeo(
  42784. coordSys, seriesModel, visualMapOfThisSeries, api
  42785. );
  42786. }
  42787. },
  42788. dispose: function () {},
  42789. _renderOnCartesianAndCalendar: function (coordSys, seriesModel, api) {
  42790. if (coordSys.type === 'cartesian2d') {
  42791. var xAxis = coordSys.getAxis('x');
  42792. var yAxis = coordSys.getAxis('y');
  42793. if (true) {
  42794. if (!(xAxis.type === 'category' && yAxis.type === 'category')) {
  42795. throw new Error('Heatmap on cartesian must have two category axes');
  42796. }
  42797. if (!(xAxis.onBand && yAxis.onBand)) {
  42798. throw new Error('Heatmap on cartesian must have two axes with boundaryGap true');
  42799. }
  42800. }
  42801. var width = xAxis.getBandWidth();
  42802. var height = yAxis.getBandWidth();
  42803. }
  42804. var group = this.group;
  42805. var data = seriesModel.getData();
  42806. var itemStyleQuery = 'itemStyle.normal';
  42807. var hoverItemStyleQuery = 'itemStyle.emphasis';
  42808. var labelQuery = 'label.normal';
  42809. var hoverLabelQuery = 'label.emphasis';
  42810. var style = seriesModel.getModel(itemStyleQuery).getItemStyle(['color']);
  42811. var hoverStl = seriesModel.getModel(hoverItemStyleQuery).getItemStyle();
  42812. var labelModel = seriesModel.getModel('label.normal');
  42813. var hoverLabelModel = seriesModel.getModel('label.emphasis');
  42814. var coordSysType = coordSys.type;
  42815. var dataDims = coordSysType === 'cartesian2d'
  42816. ? [
  42817. seriesModel.coordDimToDataDim('x')[0],
  42818. seriesModel.coordDimToDataDim('y')[0],
  42819. seriesModel.coordDimToDataDim('value')[0]
  42820. ]
  42821. : [
  42822. seriesModel.coordDimToDataDim('time')[0],
  42823. seriesModel.coordDimToDataDim('value')[0]
  42824. ];
  42825. data.each(function (idx) {
  42826. var rect;
  42827. if (coordSysType === 'cartesian2d') {
  42828. // Ignore empty data
  42829. if (isNaN(data.get(dataDims[2], idx))) {
  42830. return;
  42831. }
  42832. var point = coordSys.dataToPoint([
  42833. data.get(dataDims[0], idx),
  42834. data.get(dataDims[1], idx)
  42835. ]);
  42836. rect = new graphic.Rect({
  42837. shape: {
  42838. x: point[0] - width / 2,
  42839. y: point[1] - height / 2,
  42840. width: width,
  42841. height: height
  42842. },
  42843. style: {
  42844. fill: data.getItemVisual(idx, 'color'),
  42845. opacity: data.getItemVisual(idx, 'opacity')
  42846. }
  42847. });
  42848. }
  42849. else {
  42850. // Ignore empty data
  42851. if (isNaN(data.get(dataDims[1], idx))) {
  42852. return;
  42853. }
  42854. rect = new graphic.Rect({
  42855. z2: 1,
  42856. shape: coordSys.dataToRect([data.get(dataDims[0], idx)]).contentShape,
  42857. style: {
  42858. fill: data.getItemVisual(idx, 'color'),
  42859. opacity: data.getItemVisual(idx, 'opacity')
  42860. }
  42861. });
  42862. }
  42863. var itemModel = data.getItemModel(idx);
  42864. // Optimization for large datset
  42865. if (data.hasItemOption) {
  42866. style = itemModel.getModel(itemStyleQuery).getItemStyle(['color']);
  42867. hoverStl = itemModel.getModel(hoverItemStyleQuery).getItemStyle();
  42868. labelModel = itemModel.getModel(labelQuery);
  42869. hoverLabelModel = itemModel.getModel(hoverLabelQuery);
  42870. }
  42871. var rawValue = seriesModel.getRawValue(idx);
  42872. var defaultText = '-';
  42873. if (rawValue && rawValue[2] != null) {
  42874. defaultText = rawValue[2];
  42875. }
  42876. if (labelModel.getShallow('show')) {
  42877. graphic.setText(style, labelModel);
  42878. style.text = seriesModel.getFormattedLabel(idx, 'normal') || defaultText;
  42879. }
  42880. if (hoverLabelModel.getShallow('show')) {
  42881. graphic.setText(hoverStl, hoverLabelModel);
  42882. hoverStl.text = seriesModel.getFormattedLabel(idx, 'emphasis') || defaultText;
  42883. }
  42884. rect.setStyle(style);
  42885. graphic.setHoverStyle(rect, data.hasItemOption ? hoverStl : zrUtil.extend({}, hoverStl));
  42886. group.add(rect);
  42887. data.setItemGraphicEl(idx, rect);
  42888. });
  42889. },
  42890. _renderOnGeo: function (geo, seriesModel, visualMapModel, api) {
  42891. var inRangeVisuals = visualMapModel.targetVisuals.inRange;
  42892. var outOfRangeVisuals = visualMapModel.targetVisuals.outOfRange;
  42893. // if (!visualMapping) {
  42894. // throw new Error('Data range must have color visuals');
  42895. // }
  42896. var data = seriesModel.getData();
  42897. var hmLayer = this._hmLayer || (this._hmLayer || new HeatmapLayer());
  42898. hmLayer.blurSize = seriesModel.get('blurSize');
  42899. hmLayer.pointSize = seriesModel.get('pointSize');
  42900. hmLayer.minOpacity = seriesModel.get('minOpacity');
  42901. hmLayer.maxOpacity = seriesModel.get('maxOpacity');
  42902. var rect = geo.getViewRect().clone();
  42903. var roamTransform = geo.getRoamTransform().transform;
  42904. rect.applyTransform(roamTransform);
  42905. // Clamp on viewport
  42906. var x = Math.max(rect.x, 0);
  42907. var y = Math.max(rect.y, 0);
  42908. var x2 = Math.min(rect.width + rect.x, api.getWidth());
  42909. var y2 = Math.min(rect.height + rect.y, api.getHeight());
  42910. var width = x2 - x;
  42911. var height = y2 - y;
  42912. var points = data.mapArray(['lng', 'lat', 'value'], function (lng, lat, value) {
  42913. var pt = geo.dataToPoint([lng, lat]);
  42914. pt[0] -= x;
  42915. pt[1] -= y;
  42916. pt.push(value);
  42917. return pt;
  42918. });
  42919. var dataExtent = visualMapModel.getExtent();
  42920. var isInRange = visualMapModel.type === 'visualMap.continuous'
  42921. ? getIsInContinuousRange(dataExtent, visualMapModel.option.range)
  42922. : getIsInPiecewiseRange(
  42923. dataExtent, visualMapModel.getPieceList(), visualMapModel.option.selected
  42924. );
  42925. hmLayer.update(
  42926. points, width, height,
  42927. inRangeVisuals.color.getNormalizer(),
  42928. {
  42929. inRange: inRangeVisuals.color.getColorMapper(),
  42930. outOfRange: outOfRangeVisuals.color.getColorMapper()
  42931. },
  42932. isInRange
  42933. );
  42934. var img = new graphic.Image({
  42935. style: {
  42936. width: width,
  42937. height: height,
  42938. x: x,
  42939. y: y,
  42940. image: hmLayer.canvas
  42941. },
  42942. silent: true
  42943. });
  42944. this.group.add(img);
  42945. }
  42946. });
  42947. /***/ },
  42948. /* 285 */
  42949. /***/ function(module, exports, __webpack_require__) {
  42950. /**
  42951. * @file defines echarts Heatmap Chart
  42952. * @author Ovilia (me@zhangwenli.com)
  42953. * Inspired by https://github.com/mourner/simpleheat
  42954. *
  42955. * @module
  42956. */
  42957. var GRADIENT_LEVELS = 256;
  42958. var zrUtil = __webpack_require__(4);
  42959. /**
  42960. * Heatmap Chart
  42961. *
  42962. * @class
  42963. */
  42964. function Heatmap() {
  42965. var canvas = zrUtil.createCanvas();
  42966. this.canvas = canvas;
  42967. this.blurSize = 30;
  42968. this.pointSize = 20;
  42969. this.maxOpacity = 1;
  42970. this.minOpacity = 0;
  42971. this._gradientPixels = {};
  42972. }
  42973. Heatmap.prototype = {
  42974. /**
  42975. * Renders Heatmap and returns the rendered canvas
  42976. * @param {Array} data array of data, each has x, y, value
  42977. * @param {number} width canvas width
  42978. * @param {number} height canvas height
  42979. */
  42980. update: function(data, width, height, normalize, colorFunc, isInRange) {
  42981. var brush = this._getBrush();
  42982. var gradientInRange = this._getGradient(data, colorFunc, 'inRange');
  42983. var gradientOutOfRange = this._getGradient(data, colorFunc, 'outOfRange');
  42984. var r = this.pointSize + this.blurSize;
  42985. var canvas = this.canvas;
  42986. var ctx = canvas.getContext('2d');
  42987. var len = data.length;
  42988. canvas.width = width;
  42989. canvas.height = height;
  42990. for (var i = 0; i < len; ++i) {
  42991. var p = data[i];
  42992. var x = p[0];
  42993. var y = p[1];
  42994. var value = p[2];
  42995. // calculate alpha using value
  42996. var alpha = normalize(value);
  42997. // draw with the circle brush with alpha
  42998. ctx.globalAlpha = alpha;
  42999. ctx.drawImage(brush, x - r, y - r);
  43000. }
  43001. // colorize the canvas using alpha value and set with gradient
  43002. var imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
  43003. var pixels = imageData.data;
  43004. var offset = 0;
  43005. var pixelLen = pixels.length;
  43006. var minOpacity = this.minOpacity;
  43007. var maxOpacity = this.maxOpacity;
  43008. var diffOpacity = maxOpacity - minOpacity;
  43009. while(offset < pixelLen) {
  43010. var alpha = pixels[offset + 3] / 256;
  43011. var gradientOffset = Math.floor(alpha * (GRADIENT_LEVELS - 1)) * 4;
  43012. // Simple optimize to ignore the empty data
  43013. if (alpha > 0) {
  43014. var gradient = isInRange(alpha) ? gradientInRange : gradientOutOfRange;
  43015. // Any alpha > 0 will be mapped to [minOpacity, maxOpacity]
  43016. alpha > 0 && (alpha = alpha * diffOpacity + minOpacity);
  43017. pixels[offset++] = gradient[gradientOffset];
  43018. pixels[offset++] = gradient[gradientOffset + 1];
  43019. pixels[offset++] = gradient[gradientOffset + 2];
  43020. pixels[offset++] = gradient[gradientOffset + 3] * alpha * 256;
  43021. }
  43022. else {
  43023. offset += 4;
  43024. }
  43025. }
  43026. ctx.putImageData(imageData, 0, 0);
  43027. return canvas;
  43028. },
  43029. /**
  43030. * get canvas of a black circle brush used for canvas to draw later
  43031. * @private
  43032. * @returns {Object} circle brush canvas
  43033. */
  43034. _getBrush: function() {
  43035. var brushCanvas = this._brushCanvas || (this._brushCanvas = zrUtil.createCanvas());
  43036. // set brush size
  43037. var r = this.pointSize + this.blurSize;
  43038. var d = r * 2;
  43039. brushCanvas.width = d;
  43040. brushCanvas.height = d;
  43041. var ctx = brushCanvas.getContext('2d');
  43042. ctx.clearRect(0, 0, d, d);
  43043. // in order to render shadow without the distinct circle,
  43044. // draw the distinct circle in an invisible place,
  43045. // and use shadowOffset to draw shadow in the center of the canvas
  43046. ctx.shadowOffsetX = d;
  43047. ctx.shadowBlur = this.blurSize;
  43048. // draw the shadow in black, and use alpha and shadow blur to generate
  43049. // color in color map
  43050. ctx.shadowColor = '#000';
  43051. // draw circle in the left to the canvas
  43052. ctx.beginPath();
  43053. ctx.arc(-r, r, this.pointSize, 0, Math.PI * 2, true);
  43054. ctx.closePath();
  43055. ctx.fill();
  43056. return brushCanvas;
  43057. },
  43058. /**
  43059. * get gradient color map
  43060. * @private
  43061. */
  43062. _getGradient: function (data, colorFunc, state) {
  43063. var gradientPixels = this._gradientPixels;
  43064. var pixelsSingleState = gradientPixels[state] || (gradientPixels[state] = new Uint8ClampedArray(256 * 4));
  43065. var color = [0, 0, 0, 0];
  43066. var off = 0;
  43067. for (var i = 0; i < 256; i++) {
  43068. colorFunc[state](i / 255, true, color);
  43069. pixelsSingleState[off++] = color[0];
  43070. pixelsSingleState[off++] = color[1];
  43071. pixelsSingleState[off++] = color[2];
  43072. pixelsSingleState[off++] = color[3];
  43073. }
  43074. return pixelsSingleState;
  43075. }
  43076. };
  43077. module.exports = Heatmap;
  43078. /***/ },
  43079. /* 286 */
  43080. /***/ function(module, exports, __webpack_require__) {
  43081. var zrUtil = __webpack_require__(4);
  43082. __webpack_require__(125);
  43083. __webpack_require__(287);
  43084. __webpack_require__(288);
  43085. var barLayoutGrid = __webpack_require__(145);
  43086. var echarts = __webpack_require__(1);
  43087. echarts.registerLayout(zrUtil.curry(barLayoutGrid, 'pictorialBar'));
  43088. echarts.registerVisual(zrUtil.curry(
  43089. __webpack_require__(121), 'pictorialBar', 'roundRect', null
  43090. ));
  43091. // In case developer forget to include grid component
  43092. __webpack_require__(124);
  43093. /***/ },
  43094. /* 287 */
  43095. /***/ function(module, exports, __webpack_require__) {
  43096. var PictorialBarSeries = __webpack_require__(141).extend({
  43097. type: 'series.pictorialBar',
  43098. dependencies: ['grid'],
  43099. defaultOption: {
  43100. symbol: 'circle', // Customized bar shape
  43101. symbolSize: null, // Can be ['100%', '100%'], null means auto.
  43102. symbolRotate: null,
  43103. symbolPosition: null, // 'start' or 'end' or 'center', null means auto.
  43104. symbolOffset: null,
  43105. symbolMargin: null, // start margin and end margin. Can be a number or a percent string.
  43106. // Auto margin by defualt.
  43107. symbolRepeat: false, // false/null/undefined, means no repeat.
  43108. // Can be true, means auto calculate repeat times and cut by data.
  43109. // Can be a number, specifies repeat times, and do not cut by data.
  43110. // Can be 'fixed', means auto calculate repeat times but do not cut by data.
  43111. symbolRepeatDirection: 'end', // 'end' means from 'start' to 'end'.
  43112. symbolClip: false,
  43113. symbolBoundingData: null,
  43114. symbolPatternSize: 400, // 400 * 400 px
  43115. barGap: '-100%', // In most case, overlap is needed.
  43116. // z can be set in data item, which is z2 actually.
  43117. // Disable progressive
  43118. progressive: 0,
  43119. hoverAnimation: false // Open only when needed.
  43120. },
  43121. getInitialData: function (option) {
  43122. // Disable stack.
  43123. option.stack = null;
  43124. return PictorialBarSeries.superApply(this, 'getInitialData', arguments);
  43125. }
  43126. });
  43127. module.exports = PictorialBarSeries;
  43128. /***/ },
  43129. /* 288 */
  43130. /***/ function(module, exports, __webpack_require__) {
  43131. var zrUtil = __webpack_require__(4);
  43132. var graphic = __webpack_require__(18);
  43133. var symbolUtil = __webpack_require__(111);
  43134. var numberUtil = __webpack_require__(7);
  43135. var helper = __webpack_require__(143);
  43136. var parsePercent = numberUtil.parsePercent;
  43137. var BAR_BORDER_WIDTH_QUERY = ['itemStyle', 'normal', 'borderWidth'];
  43138. // index: +isHorizontal
  43139. var LAYOUT_ATTRS = [
  43140. {xy: 'x', wh: 'width', index: 0, posDesc: ['left', 'right']},
  43141. {xy: 'y', wh: 'height', index: 1, posDesc: ['top', 'bottom']}
  43142. ];
  43143. var pathForLineWidth = new graphic.Circle();
  43144. var BarView = __webpack_require__(1).extendChartView({
  43145. type: 'pictorialBar',
  43146. render: function (seriesModel, ecModel, api) {
  43147. var group = this.group;
  43148. var data = seriesModel.getData();
  43149. var oldData = this._data;
  43150. var cartesian = seriesModel.coordinateSystem;
  43151. var baseAxis = cartesian.getBaseAxis();
  43152. var isHorizontal = !!baseAxis.isHorizontal();
  43153. var coordSysRect = cartesian.grid.getRect();
  43154. var opt = {
  43155. ecSize: {width: api.getWidth(), height: api.getHeight()},
  43156. seriesModel: seriesModel,
  43157. coordSys: cartesian,
  43158. coordSysExtent: [
  43159. [coordSysRect.x, coordSysRect.x + coordSysRect.width],
  43160. [coordSysRect.y, coordSysRect.y + coordSysRect.height]
  43161. ],
  43162. isHorizontal: isHorizontal,
  43163. valueDim: LAYOUT_ATTRS[+isHorizontal],
  43164. categoryDim: LAYOUT_ATTRS[1 - isHorizontal]
  43165. };
  43166. data.diff(oldData)
  43167. .add(function (dataIndex) {
  43168. if (!data.hasValue(dataIndex)) {
  43169. return;
  43170. }
  43171. var itemModel = getItemModel(data, dataIndex);
  43172. var symbolMeta = getSymbolMeta(data, dataIndex, itemModel, opt);
  43173. var bar = createBar(data, opt, symbolMeta);
  43174. data.setItemGraphicEl(dataIndex, bar);
  43175. group.add(bar);
  43176. updateCommon(bar, opt, symbolMeta);
  43177. })
  43178. .update(function (newIndex, oldIndex) {
  43179. var bar = oldData.getItemGraphicEl(oldIndex);
  43180. if (!data.hasValue(newIndex)) {
  43181. group.remove(bar);
  43182. return;
  43183. }
  43184. var itemModel = getItemModel(data, newIndex);
  43185. var symbolMeta = getSymbolMeta(data, newIndex, itemModel, opt);
  43186. var pictorialShapeStr = getShapeStr(data, symbolMeta);
  43187. if (bar && pictorialShapeStr !== bar.__pictorialShapeStr) {
  43188. group.remove(bar);
  43189. data.setItemGraphicEl(newIndex, null);
  43190. bar = null;
  43191. }
  43192. if (bar) {
  43193. updateBar(bar, opt, symbolMeta);
  43194. }
  43195. else {
  43196. bar = createBar(data, opt, symbolMeta, true);
  43197. }
  43198. data.setItemGraphicEl(newIndex, bar);
  43199. bar.__pictorialSymbolMeta = symbolMeta;
  43200. // Add back
  43201. group.add(bar);
  43202. updateCommon(bar, opt, symbolMeta);
  43203. })
  43204. .remove(function (dataIndex) {
  43205. var bar = oldData.getItemGraphicEl(dataIndex);
  43206. bar && removeBar(oldData, dataIndex, bar.__pictorialSymbolMeta.animationModel, bar);
  43207. })
  43208. .execute();
  43209. this._data = data;
  43210. return this.group;
  43211. },
  43212. dispose: zrUtil.noop,
  43213. remove: function (ecModel, api) {
  43214. var group = this.group;
  43215. var data = this._data;
  43216. if (ecModel.get('animation')) {
  43217. if (data) {
  43218. data.eachItemGraphicEl(function (bar) {
  43219. removeBar(data, bar.dataIndex, ecModel, bar);
  43220. });
  43221. }
  43222. }
  43223. else {
  43224. group.removeAll();
  43225. }
  43226. }
  43227. });
  43228. // Set or calculate default value about symbol, and calculate layout info.
  43229. function getSymbolMeta(data, dataIndex, itemModel, opt) {
  43230. var layout = data.getItemLayout(dataIndex);
  43231. var symbolRepeat = itemModel.get('symbolRepeat');
  43232. var symbolClip = itemModel.get('symbolClip');
  43233. var symbolPosition = itemModel.get('symbolPosition') || 'start';
  43234. var symbolRotate = itemModel.get('symbolRotate');
  43235. var rotation = (symbolRotate || 0) * Math.PI / 180 || 0;
  43236. var symbolPatternSize = itemModel.get('symbolPatternSize') || 2;
  43237. var isAnimationEnabled = itemModel.isAnimationEnabled();
  43238. var symbolMeta = {
  43239. dataIndex: dataIndex,
  43240. layout: layout,
  43241. itemModel: itemModel,
  43242. symbolType: data.getItemVisual(dataIndex, 'symbol') || 'circle',
  43243. color: data.getItemVisual(dataIndex, 'color'),
  43244. symbolClip: symbolClip,
  43245. symbolRepeat: symbolRepeat,
  43246. symbolRepeatDirection: itemModel.get('symbolRepeatDirection'),
  43247. symbolPatternSize: symbolPatternSize,
  43248. rotation: rotation,
  43249. animationModel: isAnimationEnabled ? itemModel : null,
  43250. hoverAnimation: isAnimationEnabled && itemModel.get('hoverAnimation'),
  43251. z2: itemModel.getShallow('z', true) || 0
  43252. };
  43253. prepareBarLength(itemModel, symbolRepeat, layout, opt, symbolMeta);
  43254. prepareSymbolSize(
  43255. data, dataIndex, layout, symbolRepeat, symbolClip, symbolMeta.boundingLength,
  43256. symbolMeta.pxSign, symbolPatternSize, opt, symbolMeta
  43257. );
  43258. prepareLineWidth(itemModel, symbolMeta.symbolScale, rotation, opt, symbolMeta);
  43259. var symbolSize = symbolMeta.symbolSize;
  43260. var symbolOffset = itemModel.get('symbolOffset');
  43261. if (zrUtil.isArray(symbolOffset)) {
  43262. symbolOffset = [
  43263. parsePercent(symbolOffset[0], symbolSize[0]),
  43264. parsePercent(symbolOffset[1], symbolSize[1])
  43265. ];
  43266. }
  43267. prepareLayoutInfo(
  43268. itemModel, symbolSize, layout, symbolRepeat, symbolClip, symbolOffset,
  43269. symbolPosition, symbolMeta.valueLineWidth, symbolMeta.boundingLength, symbolMeta.repeatCutLength,
  43270. opt, symbolMeta
  43271. );
  43272. return symbolMeta;
  43273. }
  43274. // bar length can be negative.
  43275. function prepareBarLength(itemModel, symbolRepeat, layout, opt, output) {
  43276. var valueDim = opt.valueDim;
  43277. var symbolBoundingData = itemModel.get('symbolBoundingData');
  43278. var valueAxis = opt.coordSys.getOtherAxis(opt.coordSys.getBaseAxis());
  43279. var zeroPx = valueAxis.toGlobalCoord(valueAxis.dataToCoord(0));
  43280. var boundingLength = output.boundingLength = symbolBoundingData != null
  43281. ? valueAxis.toGlobalCoord(valueAxis.dataToCoord(valueAxis.scale.parse(symbolBoundingData))) - zeroPx
  43282. : symbolRepeat
  43283. ? opt.coordSysExtent[valueDim.index][1 - +(layout[valueDim.wh] <= 0)] - zeroPx
  43284. : layout[valueDim.wh];
  43285. if (symbolRepeat) {
  43286. output.repeatCutLength = layout[valueDim.wh];
  43287. }
  43288. output.pxSign = boundingLength > 0 ? 1 : boundingLength < 0 ? -1 : 0;
  43289. }
  43290. // Support ['100%', '100%']
  43291. function prepareSymbolSize(
  43292. data, dataIndex, layout, symbolRepeat, symbolClip, boundingLength,
  43293. pxSign, symbolPatternSize, opt, output
  43294. ) {
  43295. var valueDim = opt.valueDim;
  43296. var categoryDim = opt.categoryDim;
  43297. var categorySize = Math.abs(layout[categoryDim.wh]);
  43298. var symbolSize = data.getItemVisual(dataIndex, 'symbolSize');
  43299. if (zrUtil.isArray(symbolSize)) {
  43300. symbolSize = symbolSize.slice();
  43301. }
  43302. else {
  43303. if (symbolSize == null) {
  43304. symbolSize = '100%';
  43305. }
  43306. symbolSize = [symbolSize, symbolSize];
  43307. }
  43308. // Note: percentage symbolSize (like '100%') do not consider lineWidth, because it is
  43309. // to complicated to calculate real percent value if considering scaled lineWidth.
  43310. // So the actual size will bigger than layout size if lineWidth is bigger than zero,
  43311. // which can be tolerated in pictorial chart.
  43312. symbolSize[categoryDim.index] = parsePercent(
  43313. symbolSize[categoryDim.index],
  43314. categorySize
  43315. );
  43316. symbolSize[valueDim.index] = parsePercent(
  43317. symbolSize[valueDim.index],
  43318. symbolRepeat ? categorySize : Math.abs(boundingLength)
  43319. );
  43320. output.symbolSize = symbolSize;
  43321. // If x or y is less than zero, show reversed shape.
  43322. var symbolScale = output.symbolScale = [
  43323. symbolSize[0] / symbolPatternSize,
  43324. symbolSize[1] / symbolPatternSize
  43325. ];
  43326. // Follow convention, 'right' and 'top' is the normal scale.
  43327. symbolScale[valueDim.index] *= (opt.isHorizontal ? -1 : 1) * pxSign;
  43328. }
  43329. function prepareLineWidth(itemModel, symbolScale, rotation, opt, output) {
  43330. // In symbols are drawn with scale, so do not need to care about the case that width
  43331. // or height are too small. But symbol use strokeNoScale, where acture lineWidth should
  43332. // be calculated.
  43333. var valueLineWidth = itemModel.get(BAR_BORDER_WIDTH_QUERY) || 0;
  43334. if (valueLineWidth) {
  43335. pathForLineWidth.attr({
  43336. scale: symbolScale.slice(),
  43337. rotation: rotation
  43338. });
  43339. pathForLineWidth.updateTransform();
  43340. valueLineWidth /= pathForLineWidth.getLineScale();
  43341. valueLineWidth *= symbolScale[opt.valueDim.index];
  43342. }
  43343. output.valueLineWidth = valueLineWidth;
  43344. }
  43345. function prepareLayoutInfo(
  43346. itemModel, symbolSize, layout, symbolRepeat, symbolClip, symbolOffset,
  43347. symbolPosition, valueLineWidth, boundingLength, repeatCutLength, opt, output
  43348. ) {
  43349. var categoryDim = opt.categoryDim;
  43350. var valueDim = opt.valueDim;
  43351. var pxSign = output.pxSign;
  43352. var unitLength = Math.max(symbolSize[valueDim.index] + valueLineWidth, 0);
  43353. var pathLen = unitLength;
  43354. // Note: rotation will not effect the layout of symbols, because user may
  43355. // want symbols to rotate on its center, which should not be translated
  43356. // when rotating.
  43357. if (symbolRepeat) {
  43358. var absBoundingLength = Math.abs(boundingLength);
  43359. var symbolMargin = zrUtil.retrieve(itemModel.get('symbolMargin'), '15%') + '';
  43360. var hasEndGap = false;
  43361. if (symbolMargin.lastIndexOf('!') === symbolMargin.length - 1) {
  43362. hasEndGap = true;
  43363. symbolMargin = symbolMargin.slice(0, symbolMargin.length - 1);
  43364. }
  43365. symbolMargin = parsePercent(symbolMargin, symbolSize[valueDim.index]);
  43366. var uLenWithMargin = Math.max(unitLength + symbolMargin * 2, 0);
  43367. // When symbol margin is less than 0, margin at both ends will be subtracted
  43368. // to ensure that all of the symbols will not be overflow the given area.
  43369. var endFix = hasEndGap ? 0 : symbolMargin * 2;
  43370. // Both final repeatTimes and final symbolMargin area calculated based on
  43371. // boundingLength.
  43372. var repeatSpecified = numberUtil.isNumeric(symbolRepeat);
  43373. var repeatTimes = repeatSpecified
  43374. ? symbolRepeat
  43375. : toIntTimes((absBoundingLength + endFix) / uLenWithMargin);
  43376. // Adjust calculate margin, to ensure each symbol is displayed
  43377. // entirely in the given layout area.
  43378. var mDiff = absBoundingLength - repeatTimes * unitLength;
  43379. symbolMargin = mDiff / 2 / (hasEndGap ? repeatTimes : repeatTimes - 1);
  43380. uLenWithMargin = unitLength + symbolMargin * 2;
  43381. endFix = hasEndGap ? 0 : symbolMargin * 2;
  43382. // Update repeatTimes when not all symbol will be shown.
  43383. if (!repeatSpecified && symbolRepeat !== 'fixed') {
  43384. repeatTimes = repeatCutLength
  43385. ? toIntTimes((Math.abs(repeatCutLength) + endFix) / uLenWithMargin)
  43386. : 0;
  43387. }
  43388. pathLen = repeatTimes * uLenWithMargin - endFix;
  43389. output.repeatTimes = repeatTimes;
  43390. output.symbolMargin = symbolMargin;
  43391. }
  43392. var sizeFix = pxSign * (pathLen / 2);
  43393. var pathPosition = output.pathPosition = [];
  43394. pathPosition[categoryDim.index] = layout[categoryDim.wh] / 2;
  43395. pathPosition[valueDim.index] = symbolPosition === 'start'
  43396. ? sizeFix
  43397. : symbolPosition === 'end'
  43398. ? boundingLength - sizeFix
  43399. : boundingLength / 2; // 'center'
  43400. if (symbolOffset) {
  43401. pathPosition[0] += symbolOffset[0];
  43402. pathPosition[1] += symbolOffset[1];
  43403. }
  43404. var bundlePosition = output.bundlePosition = [];
  43405. bundlePosition[categoryDim.index] = layout[categoryDim.xy];
  43406. bundlePosition[valueDim.index] = layout[valueDim.xy];
  43407. var barRectShape = output.barRectShape = zrUtil.extend({}, layout);
  43408. barRectShape[valueDim.wh] = pxSign * Math.max(
  43409. Math.abs(layout[valueDim.wh]), Math.abs(pathPosition[valueDim.index] + sizeFix)
  43410. );
  43411. barRectShape[categoryDim.wh] = layout[categoryDim.wh];
  43412. var clipShape = output.clipShape = {};
  43413. // Consider that symbol may be overflow layout rect.
  43414. clipShape[categoryDim.xy] = -layout[categoryDim.xy];
  43415. clipShape[categoryDim.wh] = opt.ecSize[categoryDim.wh];
  43416. clipShape[valueDim.xy] = 0;
  43417. clipShape[valueDim.wh] = layout[valueDim.wh];
  43418. }
  43419. function createPath(symbolMeta) {
  43420. var symbolPatternSize = symbolMeta.symbolPatternSize;
  43421. var path = symbolUtil.createSymbol(
  43422. // Consider texture img, make a big size.
  43423. symbolMeta.symbolType,
  43424. -symbolPatternSize / 2,
  43425. -symbolPatternSize / 2,
  43426. symbolPatternSize,
  43427. symbolPatternSize,
  43428. symbolMeta.color
  43429. );
  43430. path.attr({
  43431. culling: true
  43432. });
  43433. path.type !== 'image' && path.setStyle({
  43434. strokeNoScale: true
  43435. });
  43436. return path;
  43437. }
  43438. function createOrUpdateRepeatSymbols(bar, opt, symbolMeta, isUpdate) {
  43439. var bundle = bar.__pictorialBundle;
  43440. var symbolSize = symbolMeta.symbolSize;
  43441. var valueLineWidth = symbolMeta.valueLineWidth;
  43442. var pathPosition = symbolMeta.pathPosition;
  43443. var valueDim = opt.valueDim;
  43444. var repeatTimes = symbolMeta.repeatTimes || 0;
  43445. var index = 0;
  43446. var unit = symbolSize[opt.valueDim.index] + valueLineWidth + symbolMeta.symbolMargin * 2;
  43447. eachPath(bar, function (path) {
  43448. path.__pictorialAnimationIndex = index;
  43449. path.__pictorialRepeatTimes = repeatTimes;
  43450. if (index < repeatTimes) {
  43451. updateAttr(path, null, makeTarget(index), symbolMeta, isUpdate);
  43452. }
  43453. else {
  43454. updateAttr(path, null, {scale: [0, 0]}, symbolMeta, isUpdate, function () {
  43455. bundle.remove(path);
  43456. });
  43457. }
  43458. updateHoverAnimation(path, symbolMeta);
  43459. index++;
  43460. });
  43461. for (; index < repeatTimes; index++) {
  43462. var path = createPath(symbolMeta);
  43463. path.__pictorialAnimationIndex = index;
  43464. path.__pictorialRepeatTimes = repeatTimes;
  43465. bundle.add(path);
  43466. var target = makeTarget(index, true);
  43467. updateAttr(
  43468. path,
  43469. {
  43470. position: target.position,
  43471. scale: [0, 0]
  43472. },
  43473. {
  43474. scale: target.scale,
  43475. rotation: target.rotation
  43476. },
  43477. symbolMeta,
  43478. isUpdate
  43479. );
  43480. // FIXME
  43481. // If all emphasis/normal through action.
  43482. path
  43483. .on('mouseover', onMouseOver)
  43484. .on('mouseout', onMouseOut);
  43485. updateHoverAnimation(path, symbolMeta);
  43486. }
  43487. function makeTarget(index) {
  43488. var position = pathPosition.slice();
  43489. // (start && pxSign > 0) || (end && pxSign < 0): i = repeatTimes - index
  43490. // Otherwise: i = index;
  43491. var pxSign = symbolMeta.pxSign;
  43492. var i = index;
  43493. if (symbolMeta.symbolRepeatDirection === 'start' ? pxSign > 0 : pxSign < 0) {
  43494. i = repeatTimes - 1 - index;
  43495. }
  43496. position[valueDim.index] = unit * (i - repeatTimes / 2 + 0.5) + pathPosition[valueDim.index];
  43497. return {
  43498. position: position,
  43499. scale: symbolMeta.symbolScale.slice(),
  43500. rotation: symbolMeta.rotation
  43501. };
  43502. }
  43503. function onMouseOver() {
  43504. eachPath(bar, function (path) {
  43505. path.trigger('emphasis');
  43506. });
  43507. }
  43508. function onMouseOut() {
  43509. eachPath(bar, function (path) {
  43510. path.trigger('normal');
  43511. });
  43512. }
  43513. }
  43514. function createOrUpdateSingleSymbol(bar, opt, symbolMeta, isUpdate) {
  43515. var bundle = bar.__pictorialBundle;
  43516. var mainPath = bar.__pictorialMainPath;
  43517. if (!mainPath) {
  43518. mainPath = bar.__pictorialMainPath = createPath(symbolMeta);
  43519. bundle.add(mainPath);
  43520. updateAttr(
  43521. mainPath,
  43522. {
  43523. position: symbolMeta.pathPosition.slice(),
  43524. scale: [0, 0],
  43525. rotation: symbolMeta.rotation
  43526. },
  43527. {
  43528. scale: symbolMeta.symbolScale.slice()
  43529. },
  43530. symbolMeta,
  43531. isUpdate
  43532. );
  43533. mainPath
  43534. .on('mouseover', onMouseOver)
  43535. .on('mouseout', onMouseOut);
  43536. }
  43537. else {
  43538. updateAttr(
  43539. mainPath,
  43540. null,
  43541. {
  43542. position: symbolMeta.pathPosition.slice(),
  43543. scale: symbolMeta.symbolScale.slice(),
  43544. rotation: symbolMeta.rotation
  43545. },
  43546. symbolMeta,
  43547. isUpdate
  43548. );
  43549. }
  43550. updateHoverAnimation(mainPath, symbolMeta);
  43551. function onMouseOver() {
  43552. this.trigger('emphasis');
  43553. }
  43554. function onMouseOut() {
  43555. this.trigger('normal');
  43556. }
  43557. }
  43558. // bar rect is used for label.
  43559. function createOrUpdateBarRect(bar, symbolMeta, isUpdate) {
  43560. var rectShape = zrUtil.extend({}, symbolMeta.barRectShape);
  43561. var barRect = bar.__pictorialBarRect;
  43562. if (!barRect) {
  43563. barRect = bar.__pictorialBarRect = new graphic.Rect({
  43564. z2: 2,
  43565. shape: rectShape,
  43566. silent: true,
  43567. style: {
  43568. stroke: 'transparent',
  43569. fill: 'transparent',
  43570. lineWidth: 0
  43571. }
  43572. });
  43573. bar.add(barRect);
  43574. }
  43575. else {
  43576. updateAttr(barRect, null, {shape: rectShape}, symbolMeta, isUpdate);
  43577. }
  43578. }
  43579. function createOrUpdateClip(bar, opt, symbolMeta, isUpdate) {
  43580. // If not clip, symbol will be remove and rebuilt.
  43581. if (symbolMeta.symbolClip) {
  43582. var clipPath = bar.__pictorialClipPath;
  43583. var clipShape = zrUtil.extend({}, symbolMeta.clipShape);
  43584. var valueDim = opt.valueDim;
  43585. var animationModel = symbolMeta.animationModel;
  43586. var dataIndex = symbolMeta.dataIndex;
  43587. if (clipPath) {
  43588. graphic.updateProps(
  43589. clipPath, {shape: clipShape}, animationModel, dataIndex
  43590. );
  43591. }
  43592. else {
  43593. clipShape[valueDim.wh] = 0;
  43594. clipPath = new graphic.Rect({shape: clipShape});
  43595. bar.__pictorialBundle.setClipPath(clipPath);
  43596. bar.__pictorialClipPath = clipPath;
  43597. var target = {};
  43598. target[valueDim.wh] = symbolMeta.clipShape[valueDim.wh];
  43599. graphic[isUpdate ? 'updateProps' : 'initProps'](
  43600. clipPath, {shape: target}, animationModel, dataIndex
  43601. );
  43602. }
  43603. }
  43604. }
  43605. function getItemModel(data, dataIndex) {
  43606. var itemModel = data.getItemModel(dataIndex);
  43607. itemModel.getAnimationDelayParams = getAnimationDelayParams;
  43608. itemModel.isAnimationEnabled = isAnimationEnabled;
  43609. return itemModel;
  43610. }
  43611. function getAnimationDelayParams(path) {
  43612. // The order is the same as the z-order, see `symbolRepeatDiretion`.
  43613. return {
  43614. index: path.__pictorialAnimationIndex,
  43615. count: path.__pictorialRepeatTimes
  43616. };
  43617. }
  43618. function isAnimationEnabled() {
  43619. // `animation` prop can be set on itemModel in pictorial bar chart.
  43620. return this.parentModel.isAnimationEnabled() && !!this.getShallow('animation');
  43621. }
  43622. function updateHoverAnimation(path, symbolMeta) {
  43623. path.off('emphasis').off('normal');
  43624. var scale = symbolMeta.symbolScale.slice();
  43625. symbolMeta.hoverAnimation && path
  43626. .on('emphasis', function() {
  43627. this.animateTo({
  43628. scale: [scale[0] * 1.1, scale[1] * 1.1]
  43629. }, 400, 'elasticOut');
  43630. })
  43631. .on('normal', function() {
  43632. this.animateTo({
  43633. scale: scale.slice()
  43634. }, 400, 'elasticOut');
  43635. });
  43636. }
  43637. function createBar(data, opt, symbolMeta, isUpdate) {
  43638. // bar is the main element for each data.
  43639. var bar = new graphic.Group();
  43640. // bundle is used for location and clip.
  43641. var bundle = new graphic.Group();
  43642. bar.add(bundle);
  43643. bar.__pictorialBundle = bundle;
  43644. bundle.attr('position', symbolMeta.bundlePosition.slice());
  43645. if (symbolMeta.symbolRepeat) {
  43646. createOrUpdateRepeatSymbols(bar, opt, symbolMeta);
  43647. }
  43648. else {
  43649. createOrUpdateSingleSymbol(bar, opt, symbolMeta);
  43650. }
  43651. createOrUpdateBarRect(bar, symbolMeta, isUpdate);
  43652. createOrUpdateClip(bar, opt, symbolMeta, isUpdate);
  43653. bar.__pictorialShapeStr = getShapeStr(data, symbolMeta);
  43654. bar.__pictorialSymbolMeta = symbolMeta;
  43655. return bar;
  43656. }
  43657. function updateBar(bar, opt, symbolMeta) {
  43658. var animationModel = symbolMeta.animationModel;
  43659. var dataIndex = symbolMeta.dataIndex;
  43660. var bundle = bar.__pictorialBundle;
  43661. graphic.updateProps(
  43662. bundle, {position: symbolMeta.bundlePosition.slice()}, animationModel, dataIndex
  43663. );
  43664. if (symbolMeta.symbolRepeat) {
  43665. createOrUpdateRepeatSymbols(bar, opt, symbolMeta, true);
  43666. }
  43667. else {
  43668. createOrUpdateSingleSymbol(bar, opt, symbolMeta, true);
  43669. }
  43670. createOrUpdateBarRect(bar, symbolMeta, true);
  43671. createOrUpdateClip(bar, opt, symbolMeta, true);
  43672. }
  43673. function removeBar(data, dataIndex, animationModel, bar) {
  43674. // Not show text when animating
  43675. var labelRect = bar.__pictorialBarRect;
  43676. labelRect && (labelRect.style.text = '');
  43677. var pathes = [];
  43678. eachPath(bar, function (path) {
  43679. pathes.push(path);
  43680. });
  43681. bar.__pictorialMainPath && pathes.push(bar.__pictorialMainPath);
  43682. // I do not find proper remove animation for clip yet.
  43683. bar.__pictorialClipPath && (animationModel = null);
  43684. zrUtil.each(pathes, function (path) {
  43685. graphic.updateProps(
  43686. path, {scale: [0, 0]}, animationModel, dataIndex,
  43687. function () {
  43688. bar.parent && bar.parent.remove(bar);
  43689. }
  43690. );
  43691. });
  43692. data.setItemGraphicEl(dataIndex, null);
  43693. }
  43694. function getShapeStr(data, symbolMeta) {
  43695. return [
  43696. data.getItemVisual(symbolMeta.dataIndex, 'symbol') || 'none',
  43697. !!symbolMeta.symbolRepeat,
  43698. !!symbolMeta.symbolClip
  43699. ].join(':');
  43700. }
  43701. function eachPath(bar, cb, context) {
  43702. // Do not use Group#eachChild, because it do not support remove.
  43703. zrUtil.each(bar.__pictorialBundle.children(), function (el) {
  43704. el !== bar.__pictorialBarRect && cb.call(context, el);
  43705. });
  43706. }
  43707. function updateAttr(el, immediateAttrs, animationAttrs, symbolMeta, isUpdate, cb) {
  43708. immediateAttrs && el.attr(immediateAttrs);
  43709. // when symbolCip used, only clip path has init animation, otherwise it would be weird effect.
  43710. if (symbolMeta.symbolClip && !isUpdate) {
  43711. animationAttrs && el.attr(animationAttrs);
  43712. }
  43713. else {
  43714. animationAttrs && graphic[isUpdate ? 'updateProps' : 'initProps'](
  43715. el, animationAttrs, symbolMeta.animationModel, symbolMeta.dataIndex, cb
  43716. );
  43717. }
  43718. }
  43719. function updateCommon(bar, opt, symbolMeta) {
  43720. var color = symbolMeta.color;
  43721. var dataIndex = symbolMeta.dataIndex;
  43722. var itemModel = symbolMeta.itemModel;
  43723. // Color must be excluded.
  43724. // Because symbol provide setColor individually to set fill and stroke
  43725. var normalStyle = itemModel.getModel('itemStyle.normal').getItemStyle(['color']);
  43726. var hoverStyle = itemModel.getModel('itemStyle.emphasis').getItemStyle();
  43727. eachPath(bar, function (path) {
  43728. // PENDING setColor should be before setStyle!!!
  43729. path.setColor(color);
  43730. path.setStyle(zrUtil.defaults(
  43731. {
  43732. fill: color,
  43733. opacity: symbolMeta.opacity
  43734. },
  43735. normalStyle
  43736. ));
  43737. graphic.setHoverStyle(path, hoverStyle);
  43738. path.z2 = symbolMeta.z2;
  43739. });
  43740. var barRectHoverStyle = {};
  43741. var barPositionOutside = opt.valueDim.posDesc[+(symbolMeta.boundingLength > 0)];
  43742. var barRect = bar.__pictorialBarRect;
  43743. helper.setLabel(
  43744. barRect.style, barRectHoverStyle, itemModel,
  43745. color, opt.seriesModel, dataIndex, barPositionOutside
  43746. );
  43747. graphic.setHoverStyle(barRect, barRectHoverStyle);
  43748. }
  43749. function toIntTimes(times) {
  43750. var roundedTimes = Math.round(times);
  43751. // Escapse accurate error
  43752. return Math.abs(times - roundedTimes) < 1e-4
  43753. ? roundedTimes
  43754. : Math.ceil(times);
  43755. }
  43756. module.exports = BarView;
  43757. /***/ },
  43758. /* 289 */
  43759. /***/ function(module, exports, __webpack_require__) {
  43760. var echarts = __webpack_require__(1);
  43761. var zrUtil = __webpack_require__(4);
  43762. __webpack_require__(290);
  43763. __webpack_require__(307);
  43764. __webpack_require__(308);
  43765. echarts.registerLayout(__webpack_require__(310));
  43766. echarts.registerVisual(__webpack_require__(311));
  43767. echarts.registerProcessor(
  43768. zrUtil.curry(__webpack_require__(154), 'themeRiver')
  43769. );
  43770. /***/ },
  43771. /* 290 */
  43772. /***/ function(module, exports, __webpack_require__) {
  43773. __webpack_require__(291);
  43774. __webpack_require__(294);
  43775. __webpack_require__(296);
  43776. __webpack_require__(297);
  43777. __webpack_require__(306);
  43778. var echarts = __webpack_require__(1);
  43779. echarts.extendComponentView({
  43780. type: 'single'
  43781. });
  43782. /***/ },
  43783. /* 291 */
  43784. /***/ function(module, exports, __webpack_require__) {
  43785. /**
  43786. * Single coordinate system creator.
  43787. */
  43788. var Single = __webpack_require__(292);
  43789. /**
  43790. * Create single coordinate system and inject it into seriesModel.
  43791. *
  43792. * @param {module:echarts/model/Global} ecModel
  43793. * @param {module:echarts/ExtensionAPI} api
  43794. * @return {Array.<module:echarts/coord/single/Single>}
  43795. */
  43796. function create(ecModel, api) {
  43797. var singles = [];
  43798. ecModel.eachComponent('singleAxis', function(axisModel, idx) {
  43799. var single = new Single(axisModel, ecModel, api);
  43800. single.name = 'single_' + idx;
  43801. single.resize(axisModel, api);
  43802. axisModel.coordinateSystem = single;
  43803. singles.push(single);
  43804. });
  43805. ecModel.eachSeries(function (seriesModel) {
  43806. if (seriesModel.get('coordinateSystem') === 'singleAxis') {
  43807. var singleAxisModel = ecModel.queryComponents({
  43808. mainType: 'singleAxis',
  43809. index: seriesModel.get('singleAxisIndex'),
  43810. id: seriesModel.get('singleAxisId')
  43811. })[0];
  43812. seriesModel.coordinateSystem = singleAxisModel && singleAxisModel.coordinateSystem;
  43813. }
  43814. });
  43815. return singles;
  43816. }
  43817. __webpack_require__(76).register('single', {
  43818. create: create,
  43819. dimensions: Single.prototype.dimensions
  43820. });
  43821. /***/ },
  43822. /* 292 */
  43823. /***/ function(module, exports, __webpack_require__) {
  43824. /**
  43825. * Single coordinates system.
  43826. */
  43827. var SingleAxis = __webpack_require__(293);
  43828. var axisHelper = __webpack_require__(101);
  43829. var layout = __webpack_require__(71);
  43830. /**
  43831. * Create a single coordinates system.
  43832. *
  43833. * @param {module:echarts/coord/single/AxisModel} axisModel
  43834. * @param {module:echarts/model/Global} ecModel
  43835. * @param {module:echarts/ExtensionAPI} api
  43836. */
  43837. function Single(axisModel, ecModel, api) {
  43838. /**
  43839. * @type {string}
  43840. * @readOnly
  43841. */
  43842. this.dimension = 'single';
  43843. /**
  43844. * Add it just for draw tooltip.
  43845. *
  43846. * @type {Array.<string>}
  43847. * @readOnly
  43848. */
  43849. this.dimensions = ['single'];
  43850. /**
  43851. * @private
  43852. * @type {module:echarts/coord/single/SingleAxis}.
  43853. */
  43854. this._axis = null;
  43855. /**
  43856. * @private
  43857. * @type {module:zrender/core/BoundingRect}
  43858. */
  43859. this._rect;
  43860. this._init(axisModel, ecModel, api);
  43861. /**
  43862. * @type {module:echarts/coord/single/AxisModel}
  43863. */
  43864. this.model = axisModel;
  43865. }
  43866. Single.prototype = {
  43867. type: 'singleAxis',
  43868. axisPointerEnabled: true,
  43869. constructor: Single,
  43870. /**
  43871. * Initialize single coordinate system.
  43872. *
  43873. * @param {module:echarts/coord/single/AxisModel} axisModel
  43874. * @param {module:echarts/model/Global} ecModel
  43875. * @param {module:echarts/ExtensionAPI} api
  43876. * @private
  43877. */
  43878. _init: function (axisModel, ecModel, api) {
  43879. var dim = this.dimension;
  43880. var axis = new SingleAxis(
  43881. dim,
  43882. axisHelper.createScaleByModel(axisModel),
  43883. [0, 0],
  43884. axisModel.get('type'),
  43885. axisModel.get('position')
  43886. );
  43887. var isCategory = axis.type === 'category';
  43888. axis.onBand = isCategory && axisModel.get('boundaryGap');
  43889. axis.inverse = axisModel.get('inverse');
  43890. axis.orient = axisModel.get('orient');
  43891. axisModel.axis = axis;
  43892. axis.model = axisModel;
  43893. axis.coordinateSystem = this;
  43894. this._axis = axis;
  43895. },
  43896. /**
  43897. * Update axis scale after data processed
  43898. * @param {module:echarts/model/Global} ecModel
  43899. * @param {module:echarts/ExtensionAPI} api
  43900. */
  43901. update: function (ecModel, api) {
  43902. ecModel.eachSeries(function (seriesModel) {
  43903. if (seriesModel.coordinateSystem === this) {
  43904. var data = seriesModel.getData();
  43905. var dim = this.dimension;
  43906. this._axis.scale.unionExtentFromData(
  43907. data, seriesModel.coordDimToDataDim(dim)
  43908. );
  43909. axisHelper.niceScaleExtent(this._axis.scale, this._axis.model);
  43910. }
  43911. }, this);
  43912. },
  43913. /**
  43914. * Resize the single coordinate system.
  43915. *
  43916. * @param {module:echarts/coord/single/AxisModel} axisModel
  43917. * @param {module:echarts/ExtensionAPI} api
  43918. */
  43919. resize: function (axisModel, api) {
  43920. this._rect = layout.getLayoutRect(
  43921. {
  43922. left: axisModel.get('left'),
  43923. top: axisModel.get('top'),
  43924. right: axisModel.get('right'),
  43925. bottom: axisModel.get('bottom'),
  43926. width: axisModel.get('width'),
  43927. height: axisModel.get('height')
  43928. },
  43929. {
  43930. width: api.getWidth(),
  43931. height: api.getHeight()
  43932. }
  43933. );
  43934. this._adjustAxis();
  43935. },
  43936. /**
  43937. * @return {module:zrender/core/BoundingRect}
  43938. */
  43939. getRect: function () {
  43940. return this._rect;
  43941. },
  43942. /**
  43943. * @private
  43944. */
  43945. _adjustAxis: function () {
  43946. var rect = this._rect;
  43947. var axis = this._axis;
  43948. var isHorizontal = axis.isHorizontal();
  43949. var extent = isHorizontal ? [0, rect.width] : [0, rect.height];
  43950. var idx = axis.reverse ? 1 : 0;
  43951. axis.setExtent(extent[idx], extent[1 - idx]);
  43952. this._updateAxisTransform(axis, isHorizontal ? rect.x : rect.y);
  43953. },
  43954. /**
  43955. * @param {module:echarts/coord/single/SingleAxis} axis
  43956. * @param {number} coordBase
  43957. */
  43958. _updateAxisTransform: function (axis, coordBase) {
  43959. var axisExtent = axis.getExtent();
  43960. var extentSum = axisExtent[0] + axisExtent[1];
  43961. var isHorizontal = axis.isHorizontal();
  43962. axis.toGlobalCoord = isHorizontal
  43963. ? function (coord) {
  43964. return coord + coordBase;
  43965. }
  43966. : function (coord) {
  43967. return extentSum - coord + coordBase;
  43968. };
  43969. axis.toLocalCoord = isHorizontal
  43970. ? function (coord) {
  43971. return coord - coordBase;
  43972. }
  43973. : function (coord) {
  43974. return extentSum - coord + coordBase;
  43975. };
  43976. },
  43977. /**
  43978. * Get axis.
  43979. *
  43980. * @return {module:echarts/coord/single/SingleAxis}
  43981. */
  43982. getAxis: function () {
  43983. return this._axis;
  43984. },
  43985. /**
  43986. * Get axis, add it just for draw tooltip.
  43987. *
  43988. * @return {[type]} [description]
  43989. */
  43990. getBaseAxis: function () {
  43991. return this._axis;
  43992. },
  43993. /**
  43994. * @return {Array.<module:echarts/coord/Axis>}
  43995. */
  43996. getAxes: function () {
  43997. return [this._axis];
  43998. },
  43999. /**
  44000. * @return {Object} {baseAxes: [], otherAxes: []}
  44001. */
  44002. getTooltipAxes: function () {
  44003. return {baseAxes: [this.getAxis()]};
  44004. },
  44005. /**
  44006. * If contain point.
  44007. *
  44008. * @param {Array.<number>} point
  44009. * @return {boolean}
  44010. */
  44011. containPoint: function (point) {
  44012. var rect = this.getRect();
  44013. var axis = this.getAxis();
  44014. var orient = axis.orient;
  44015. if (orient === 'horizontal') {
  44016. return axis.contain(axis.toLocalCoord(point[0]))
  44017. && (point[1] >= rect.y && point[1] <= (rect.y + rect.height));
  44018. }
  44019. else {
  44020. return axis.contain(axis.toLocalCoord(point[1]))
  44021. && (point[0] >= rect.y && point[0] <= (rect.y + rect.height));
  44022. }
  44023. },
  44024. /**
  44025. * @param {Array.<number>} point
  44026. * @return {Array.<number>}
  44027. */
  44028. pointToData: function (point) {
  44029. var axis = this.getAxis();
  44030. return [axis.coordToData(axis.toLocalCoord(
  44031. point[axis.orient === 'horizontal' ? 0 : 1]
  44032. ))];
  44033. },
  44034. /**
  44035. * Convert the series data to concrete point.
  44036. *
  44037. * @param {number|Array.<number>} val
  44038. * @return {Array.<number>}
  44039. */
  44040. dataToPoint: function (val) {
  44041. var axis = this.getAxis();
  44042. var rect = this.getRect();
  44043. var pt = [];
  44044. var idx = axis.orient === 'horizontal' ? 0 : 1;
  44045. if (val instanceof Array) {
  44046. val = val[0];
  44047. }
  44048. pt[idx] = axis.toGlobalCoord(axis.dataToCoord(+val));
  44049. pt[1 - idx] = idx === 0 ? (rect.y + rect.height / 2) : (rect.x + rect.width / 2);
  44050. return pt;
  44051. }
  44052. };
  44053. module.exports = Single;
  44054. /***/ },
  44055. /* 293 */
  44056. /***/ function(module, exports, __webpack_require__) {
  44057. var zrUtil = __webpack_require__(4);
  44058. var Axis = __webpack_require__(100);
  44059. /**
  44060. * @constructor module:echarts/coord/single/SingleAxis
  44061. * @extends {module:echarts/coord/Axis}
  44062. * @param {string} dim
  44063. * @param {*} scale
  44064. * @param {Array.<number>} coordExtent
  44065. * @param {string} axisType
  44066. * @param {string} position
  44067. */
  44068. var SingleAxis = function (dim, scale, coordExtent, axisType, position) {
  44069. Axis.call(this, dim, scale, coordExtent);
  44070. /**
  44071. * Axis type
  44072. * - 'category'
  44073. * - 'value'
  44074. * - 'time'
  44075. * - 'log'
  44076. * @type {string}
  44077. */
  44078. this.type = axisType || 'value';
  44079. /**
  44080. * Axis position
  44081. * - 'top'
  44082. * - 'bottom'
  44083. * - 'left'
  44084. * - 'right'
  44085. * @type {string}
  44086. */
  44087. this.position = position || 'bottom';
  44088. /**
  44089. * Axis orient
  44090. * - 'horizontal'
  44091. * - 'vertical'
  44092. * @type {[type]}
  44093. */
  44094. this.orient = null;
  44095. /**
  44096. * @type {number}
  44097. */
  44098. this._labelInterval = null;
  44099. };
  44100. SingleAxis.prototype = {
  44101. constructor: SingleAxis,
  44102. /**
  44103. * Axis model
  44104. * @type {module:echarts/coord/single/AxisModel}
  44105. */
  44106. model: null,
  44107. /**
  44108. * Judge the orient of the axis.
  44109. * @return {boolean}
  44110. */
  44111. isHorizontal: function () {
  44112. var position = this.position;
  44113. return position === 'top' || position === 'bottom';
  44114. },
  44115. /**
  44116. * @override
  44117. */
  44118. pointToData: function (point, clamp) {
  44119. return this.coordinateSystem.pointToData(point, clamp)[0];
  44120. },
  44121. /**
  44122. * Convert the local coord(processed by dataToCoord())
  44123. * to global coord(concrete pixel coord).
  44124. * designated by module:echarts/coord/single/Single.
  44125. * @type {Function}
  44126. */
  44127. toGlobalCoord: null,
  44128. /**
  44129. * Convert the global coord to local coord.
  44130. * designated by module:echarts/coord/single/Single.
  44131. * @type {Function}
  44132. */
  44133. toLocalCoord: null
  44134. };
  44135. zrUtil.inherits(SingleAxis, Axis);
  44136. module.exports = SingleAxis;
  44137. /***/ },
  44138. /* 294 */
  44139. /***/ function(module, exports, __webpack_require__) {
  44140. var AxisBuilder = __webpack_require__(135);
  44141. var zrUtil = __webpack_require__(4);
  44142. var graphic = __webpack_require__(18);
  44143. var singleAxisHelper = __webpack_require__(295);
  44144. var getInterval = AxisBuilder.getInterval;
  44145. var ifIgnoreOnTick = AxisBuilder.ifIgnoreOnTick;
  44146. var axisBuilderAttrs = [
  44147. 'axisLine', 'axisLabel', 'axisTick', 'axisName'
  44148. ];
  44149. var selfBuilderAttr = 'splitLine';
  44150. var SingleAxisView = __webpack_require__(136).extend({
  44151. type: 'singleAxis',
  44152. axisPointerClass: 'SingleAxisPointer',
  44153. render: function (axisModel, ecModel, api, payload) {
  44154. var group = this.group;
  44155. group.removeAll();
  44156. var layout = singleAxisHelper.layout(axisModel);
  44157. var axisBuilder = new AxisBuilder(axisModel, layout);
  44158. zrUtil.each(axisBuilderAttrs, axisBuilder.add, axisBuilder);
  44159. group.add(axisBuilder.getGroup());
  44160. if (axisModel.get(selfBuilderAttr + '.show')) {
  44161. this['_' + selfBuilderAttr](axisModel, layout.labelInterval);
  44162. }
  44163. SingleAxisView.superCall(this, 'render', axisModel, ecModel, api, payload);
  44164. },
  44165. _splitLine: function(axisModel, labelInterval) {
  44166. var axis = axisModel.axis;
  44167. if (axis.scale.isBlank()) {
  44168. return;
  44169. }
  44170. var splitLineModel = axisModel.getModel('splitLine');
  44171. var lineStyleModel = splitLineModel.getModel('lineStyle');
  44172. var lineWidth = lineStyleModel.get('width');
  44173. var lineColors = lineStyleModel.get('color');
  44174. var lineInterval = getInterval(splitLineModel, labelInterval);
  44175. lineColors = lineColors instanceof Array ? lineColors : [lineColors];
  44176. var gridRect = axisModel.coordinateSystem.getRect();
  44177. var isHorizontal = axis.isHorizontal();
  44178. var splitLines = [];
  44179. var lineCount = 0;
  44180. var ticksCoords = axis.getTicksCoords();
  44181. var p1 = [];
  44182. var p2 = [];
  44183. for (var i = 0; i < ticksCoords.length; ++i) {
  44184. if (ifIgnoreOnTick(axis, i, lineInterval)) {
  44185. continue;
  44186. }
  44187. var tickCoord = axis.toGlobalCoord(ticksCoords[i]);
  44188. if (isHorizontal) {
  44189. p1[0] = tickCoord;
  44190. p1[1] = gridRect.y;
  44191. p2[0] = tickCoord;
  44192. p2[1] = gridRect.y + gridRect.height;
  44193. }
  44194. else {
  44195. p1[0] = gridRect.x;
  44196. p1[1] = tickCoord;
  44197. p2[0] = gridRect.x + gridRect.width;
  44198. p2[1] = tickCoord;
  44199. }
  44200. var colorIndex = (lineCount++) % lineColors.length;
  44201. splitLines[colorIndex] = splitLines[colorIndex] || [];
  44202. splitLines[colorIndex].push(new graphic.Line(
  44203. graphic.subPixelOptimizeLine({
  44204. shape: {
  44205. x1: p1[0],
  44206. y1: p1[1],
  44207. x2: p2[0],
  44208. y2: p2[1]
  44209. },
  44210. style: {
  44211. lineWidth: lineWidth
  44212. },
  44213. silent: true
  44214. })));
  44215. }
  44216. for (var i = 0; i < splitLines.length; ++i) {
  44217. this.group.add(graphic.mergePath(splitLines[i], {
  44218. style: {
  44219. stroke: lineColors[i % lineColors.length],
  44220. lineDash: lineStyleModel.getLineDash(lineWidth),
  44221. lineWidth: lineWidth
  44222. },
  44223. silent: true
  44224. }));
  44225. }
  44226. }
  44227. });
  44228. module.exports = SingleAxisView;
  44229. /***/ },
  44230. /* 295 */
  44231. /***/ function(module, exports, __webpack_require__) {
  44232. var zrUtil = __webpack_require__(4);
  44233. var helper = {};
  44234. /**
  44235. * @param {Object} opt {labelInside}
  44236. * @return {Object} {
  44237. * position, rotation, labelDirection, labelOffset,
  44238. * tickDirection, labelRotate, labelInterval, z2
  44239. * }
  44240. */
  44241. helper.layout = function (axisModel, opt) {
  44242. opt = opt || {};
  44243. var single = axisModel.coordinateSystem;
  44244. var axis = axisModel.axis;
  44245. var layout = {};
  44246. var axisPosition = axis.position;
  44247. var orient = axis.orient;
  44248. var rect = single.getRect();
  44249. var rectBound = [rect.x, rect.x + rect.width, rect.y, rect.y + rect.height];
  44250. var positionMap = {
  44251. horizontal: {top: rectBound[2], bottom: rectBound[3]},
  44252. vertical: {left: rectBound[0], right: rectBound[1]}
  44253. };
  44254. layout.position = [
  44255. orient === 'vertical'
  44256. ? positionMap.vertical[axisPosition]
  44257. : rectBound[0],
  44258. orient === 'horizontal'
  44259. ? positionMap.horizontal[axisPosition]
  44260. : rectBound[3]
  44261. ];
  44262. var r = {horizontal: 0, vertical: 1};
  44263. layout.rotation = Math.PI / 2 * r[orient];
  44264. var directionMap = {top: -1, bottom: 1, right: 1, left: -1};
  44265. layout.labelDirection = layout.tickDirection
  44266. = layout.nameDirection
  44267. = directionMap[axisPosition];
  44268. if (axisModel.get('axisTick.inside')) {
  44269. layout.tickDirection = -layout.tickDirection;
  44270. }
  44271. if (zrUtil.retrieve(opt.labelInside, axisModel.get('axisLabel.inside'))) {
  44272. layout.labelDirection = -layout.labelDirection;
  44273. }
  44274. var labelRotation = opt.rotate;
  44275. labelRotation == null && (labelRotation = axisModel.get('axisLabel.rotate'));
  44276. layout.labelRotation = axisPosition === 'top' ? -labelRotation : labelRotation;
  44277. layout.labelInterval = axis.getLabelInterval();
  44278. layout.z2 = 1;
  44279. return layout;
  44280. };
  44281. module.exports = helper;
  44282. /***/ },
  44283. /* 296 */
  44284. /***/ function(module, exports, __webpack_require__) {
  44285. var ComponentModel = __webpack_require__(69);
  44286. var axisModelCreator = __webpack_require__(131);
  44287. var zrUtil = __webpack_require__(4);
  44288. var AxisModel = ComponentModel.extend({
  44289. type: 'singleAxis',
  44290. layoutMode: 'box',
  44291. /**
  44292. * @type {module:echarts/coord/single/SingleAxis}
  44293. */
  44294. axis: null,
  44295. /**
  44296. * @type {module:echarts/coord/single/Single}
  44297. */
  44298. coordinateSystem: null,
  44299. /**
  44300. * @override
  44301. */
  44302. getCoordSysModel: function () {
  44303. return this;
  44304. }
  44305. });
  44306. var defaultOption = {
  44307. left: '5%',
  44308. top: '5%',
  44309. right: '5%',
  44310. bottom: '5%',
  44311. type: 'value',
  44312. position: 'bottom',
  44313. orient: 'horizontal',
  44314. axisLine: {
  44315. show: true,
  44316. lineStyle: {
  44317. width: 2,
  44318. type: 'solid'
  44319. }
  44320. },
  44321. // Single coordinate system and single axis is the,
  44322. // which is used as the parent tooltip model.
  44323. // same model, so we set default tooltip show as true.
  44324. tooltip: {
  44325. show: true
  44326. },
  44327. axisTick: {
  44328. show: true,
  44329. length: 6,
  44330. lineStyle: {
  44331. width: 2
  44332. }
  44333. },
  44334. axisLabel: {
  44335. show: true,
  44336. interval: 'auto'
  44337. },
  44338. splitLine: {
  44339. show: true,
  44340. lineStyle: {
  44341. type: 'dashed',
  44342. opacity: 0.2
  44343. }
  44344. }
  44345. };
  44346. function getAxisType(axisName, option) {
  44347. return option.type || (option.data ? 'category' : 'value');
  44348. }
  44349. zrUtil.merge(AxisModel.prototype, __webpack_require__(112));
  44350. axisModelCreator('single', AxisModel, getAxisType, defaultOption);
  44351. module.exports = AxisModel;
  44352. /***/ },
  44353. /* 297 */
  44354. /***/ function(module, exports, __webpack_require__) {
  44355. var echarts = __webpack_require__(1);
  44356. var axisPointerModelHelper = __webpack_require__(137);
  44357. var axisTrigger = __webpack_require__(298);
  44358. var zrUtil = __webpack_require__(4);
  44359. __webpack_require__(300);
  44360. __webpack_require__(301);
  44361. // CartesianAxisPointer is not supposed to be required here. But consider
  44362. // echarts.simple.js and online build tooltip, which only require gridSimple,
  44363. // CartesianAxisPointer should be able to required somewhere.
  44364. __webpack_require__(303);
  44365. echarts.registerPreprocessor(function (option) {
  44366. // Always has a global axisPointerModel for default setting.
  44367. if (option) {
  44368. (!option.axisPointer || option.axisPointer.length === 0)
  44369. && (option.axisPointer = {});
  44370. var link = option.axisPointer.link;
  44371. // Normalize to array to avoid object mergin. But if link
  44372. // is not set, remain null/undefined, otherwise it will
  44373. // override existent link setting.
  44374. if (link && !zrUtil.isArray(link)) {
  44375. option.axisPointer.link = [link];
  44376. }
  44377. }
  44378. });
  44379. // This process should proformed after coordinate systems created
  44380. // and series data processed. So put it on statistic processing stage.
  44381. echarts.registerProcessor(echarts.PRIORITY.PROCESSOR.STATISTIC, function (ecModel, api) {
  44382. // Build axisPointerModel, mergin tooltip.axisPointer model for each axis.
  44383. // allAxesInfo should be updated when setOption performed.
  44384. ecModel.getComponent('axisPointer').coordSysAxesInfo
  44385. = axisPointerModelHelper.collect(ecModel, api);
  44386. });
  44387. // Broadcast to all views.
  44388. echarts.registerAction({
  44389. type: 'updateAxisPointer',
  44390. event: 'updateAxisPointer',
  44391. update: ':updateAxisPointer'
  44392. }, function (payload, ecModel, api) {
  44393. var outputFinder = axisTrigger(
  44394. ecModel.getComponent('axisPointer').coordSysAxesInfo,
  44395. payload.currTrigger,
  44396. [payload.x, payload.y],
  44397. payload,
  44398. payload.dispatchAction || zrUtil.bind(api.dispatchAction, api),
  44399. ecModel,
  44400. api,
  44401. payload.tooltipOption
  44402. );
  44403. return outputFinder;
  44404. });
  44405. /***/ },
  44406. /* 298 */
  44407. /***/ function(module, exports, __webpack_require__) {
  44408. var zrUtil = __webpack_require__(4);
  44409. var modelUtil = __webpack_require__(5);
  44410. var modelHelper = __webpack_require__(137);
  44411. var findPointFromSeries = __webpack_require__(299);
  44412. var each = zrUtil.each;
  44413. var curry = zrUtil.curry;
  44414. var get = modelUtil.makeGetter();
  44415. /**
  44416. * Basic logic: check all axis, if they do not demand show/highlight,
  44417. * then hide/downplay them.
  44418. *
  44419. * @param {Object} coordSysAxesInfo
  44420. * @param {string} [currTrigger] 'click' | 'mousemove' | 'leave'
  44421. * @param {Array.<number>} [point] x and y, which are mandatory, specify a point to
  44422. * tigger axisPointer and tooltip.
  44423. * @param {Object} [finder] {
  44424. * seriesIndex, dataIndex,
  44425. * axesInfo: [{
  44426. * axisDim: 'x'|'y'|'angle'|..., axisIndex: ..., value: ...
  44427. * }, ...]
  44428. * }
  44429. * These properties, which are optional, restrict target axes.
  44430. * @param {Function} dispatchAction
  44431. * @param {module:echarts/ExtensionAPI} api
  44432. * @param {Object} [tooltipOption]
  44433. * @return {Object} content of event obj for echarts.connect.
  44434. */
  44435. function axisTrigger(
  44436. coordSysAxesInfo, currTrigger, point, finder, dispatchAction,
  44437. ecModel, api, tooltipOption
  44438. ) {
  44439. finder = finder || {};
  44440. if (illegalPoint(point)) {
  44441. // Used in the default behavior of `connection`: use the sample seriesIndex
  44442. // and dataIndex. And also used in the tooltipView trigger.
  44443. point = findPointFromSeries({
  44444. seriesIndex: finder.seriesIndex,
  44445. // Do not use dataIndexInside from other ec instance.
  44446. // FIXME: auto detect it?
  44447. dataIndex: finder.dataIndex
  44448. }, ecModel).point;
  44449. }
  44450. var isIllegalPoint = illegalPoint(point);
  44451. // Axis and value can be specified when calling dispatchAction({type: 'updateAxisPointer'}).
  44452. // Notice: In this case, it is difficult to get the `point` (which is necessary to show
  44453. // tooltip, so if point is not given, we just use the point found by sample seriesIndex
  44454. // and dataIndex.
  44455. var inputAxesInfo = finder.axesInfo;
  44456. var axesInfo = coordSysAxesInfo.axesInfo;
  44457. var shouldHide = currTrigger === 'leave' || illegalPoint(point);
  44458. var outputFinder = {};
  44459. var showValueMap = {};
  44460. var dataByCoordSys = {list: [], map: {}};
  44461. var updaters = {
  44462. showPointer: curry(showPointer, showValueMap),
  44463. showTooltip: curry(showTooltip, dataByCoordSys)
  44464. };
  44465. // Process for triggered axes.
  44466. each(coordSysAxesInfo.coordSysMap, function (coordSys, coordSysKey) {
  44467. // If a point given, it must be contained by the coordinate system.
  44468. var coordSysContainsPoint = isIllegalPoint || coordSys.containPoint(point);
  44469. each(coordSysAxesInfo.coordSysAxesInfo[coordSysKey], function (axisInfo, key) {
  44470. var axis = axisInfo.axis;
  44471. var inputAxisInfo = findInputAxisInfo(inputAxesInfo, axisInfo);
  44472. // If no inputAxesInfo, no axis is restricted.
  44473. if (!shouldHide && coordSysContainsPoint && (!inputAxesInfo || inputAxisInfo)) {
  44474. var val = inputAxisInfo && inputAxisInfo.value;
  44475. if (val == null && !isIllegalPoint) {
  44476. val = axis.pointToData(point);
  44477. }
  44478. val != null && processOnAxis(axisInfo, val, updaters, false, outputFinder);
  44479. }
  44480. });
  44481. });
  44482. // Process for linked axes.
  44483. var linkTriggers = {};
  44484. each(axesInfo, function (tarAxisInfo, tarKey) {
  44485. var linkGroup = tarAxisInfo.linkGroup;
  44486. // If axis has been triggered in the previous stage, it should not be triggered by link.
  44487. if (linkGroup && !showValueMap[tarKey]) {
  44488. each(linkGroup.axesInfo, function (srcAxisInfo, srcKey) {
  44489. var srcValItem = showValueMap[srcKey];
  44490. // If srcValItem exist, source axis is triggered, so link to target axis.
  44491. if (srcAxisInfo !== tarAxisInfo && srcValItem) {
  44492. var val = srcValItem.value;
  44493. linkGroup.mapper && (val = tarAxisInfo.axis.scale.parse(linkGroup.mapper(
  44494. val, makeMapperParam(srcAxisInfo), makeMapperParam(tarAxisInfo)
  44495. )));
  44496. linkTriggers[tarAxisInfo.key] = val;
  44497. }
  44498. });
  44499. }
  44500. });
  44501. each(linkTriggers, function (val, tarKey) {
  44502. processOnAxis(axesInfo[tarKey], val, updaters, true, outputFinder);
  44503. });
  44504. updateModelActually(showValueMap, axesInfo, outputFinder);
  44505. dispatchTooltipActually(dataByCoordSys, point, tooltipOption, dispatchAction);
  44506. dispatchHighDownActually(axesInfo, dispatchAction, api);
  44507. return outputFinder;
  44508. }
  44509. function processOnAxis(axisInfo, newValue, updaters, dontSnap, outputFinder) {
  44510. var axis = axisInfo.axis;
  44511. if (axis.scale.isBlank() || !axis.containData(newValue)) {
  44512. return;
  44513. }
  44514. if (!axisInfo.involveSeries) {
  44515. updaters.showPointer(axisInfo, newValue);
  44516. return;
  44517. }
  44518. // Heavy calculation. So put it after axis.containData checking.
  44519. var payloadInfo = buildPayloadsBySeries(newValue, axisInfo);
  44520. var payloadBatch = payloadInfo.payloadBatch;
  44521. var snapToValue = payloadInfo.snapToValue;
  44522. // Fill content of event obj for echarts.connect.
  44523. // By defualt use the first involved series data as a sample to connect.
  44524. if (payloadBatch[0] && outputFinder.seriesIndex == null) {
  44525. zrUtil.extend(outputFinder, payloadBatch[0]);
  44526. }
  44527. // If no linkSource input, this process is for collecting link
  44528. // target, where snap should not be accepted.
  44529. if (!dontSnap && axisInfo.snap) {
  44530. if (axis.containData(snapToValue) && snapToValue != null) {
  44531. newValue = snapToValue;
  44532. }
  44533. }
  44534. updaters.showPointer(axisInfo, newValue, payloadBatch, outputFinder);
  44535. // Tooltip should always be snapToValue, otherwise there will be
  44536. // incorrect "axis value ~ series value" mapping displayed in tooltip.
  44537. updaters.showTooltip(axisInfo, payloadInfo, snapToValue);
  44538. }
  44539. function buildPayloadsBySeries(value, axisInfo) {
  44540. var axis = axisInfo.axis;
  44541. var dim = axis.dim;
  44542. var snapToValue = value;
  44543. var payloadBatch = [];
  44544. var minDist = Number.MAX_VALUE;
  44545. var minDiff = -1;
  44546. each(axisInfo.seriesModels, function (series, idx) {
  44547. var dataDim = series.coordDimToDataDim(dim);
  44548. var seriesNestestValue;
  44549. var dataIndices;
  44550. if (series.getAxisTooltipData) {
  44551. var result = series.getAxisTooltipData(dataDim, value, axis);
  44552. dataIndices = result.dataIndices;
  44553. seriesNestestValue = result.nestestValue;
  44554. }
  44555. else {
  44556. dataIndices = series.getData().indicesOfNearest(
  44557. dataDim[0],
  44558. value,
  44559. // Add a threshold to avoid find the wrong dataIndex
  44560. // when data length is not same.
  44561. false, axis.type === 'category' ? 0.5 : null
  44562. );
  44563. if (!dataIndices.length) {
  44564. return;
  44565. }
  44566. seriesNestestValue = series.getData().get(dataDim[0], dataIndices[0]);
  44567. }
  44568. if (seriesNestestValue == null || !isFinite(seriesNestestValue)) {
  44569. return;
  44570. }
  44571. var diff = value - seriesNestestValue;
  44572. var dist = Math.abs(diff);
  44573. // Consider category case
  44574. if (dist <= minDist) {
  44575. if (dist < minDist || (diff >= 0 && minDiff < 0)) {
  44576. minDist = dist;
  44577. minDiff = diff;
  44578. snapToValue = seriesNestestValue;
  44579. payloadBatch.length = 0;
  44580. }
  44581. each(dataIndices, function (dataIndex) {
  44582. payloadBatch.push({
  44583. seriesIndex: series.seriesIndex,
  44584. dataIndexInside: dataIndex,
  44585. dataIndex: series.getData().getRawIndex(dataIndex)
  44586. });
  44587. });
  44588. }
  44589. });
  44590. return {
  44591. payloadBatch: payloadBatch,
  44592. snapToValue: snapToValue
  44593. };
  44594. }
  44595. function showPointer(showValueMap, axisInfo, value, payloadBatch) {
  44596. showValueMap[axisInfo.key] = {value: value, payloadBatch: payloadBatch};
  44597. }
  44598. function showTooltip(dataByCoordSys, axisInfo, payloadInfo, value) {
  44599. var payloadBatch = payloadInfo.payloadBatch;
  44600. var axis = axisInfo.axis;
  44601. var axisModel = axis.model;
  44602. var axisPointerModel = axisInfo.axisPointerModel;
  44603. // If no data, do not create anything in dataByCoordSys,
  44604. // whose length will be used to judge whether dispatch action.
  44605. if (!axisInfo.triggerTooltip || !payloadBatch.length) {
  44606. return;
  44607. }
  44608. var coordSysModel = axisInfo.coordSys.model;
  44609. var coordSysKey = modelHelper.makeKey(coordSysModel);
  44610. var coordSysItem = dataByCoordSys.map[coordSysKey];
  44611. if (!coordSysItem) {
  44612. coordSysItem = dataByCoordSys.map[coordSysKey] = {
  44613. coordSysId: coordSysModel.id,
  44614. coordSysIndex: coordSysModel.componentIndex,
  44615. coordSysType: coordSysModel.type,
  44616. coordSysMainType: coordSysModel.mainType,
  44617. dataByAxis: []
  44618. };
  44619. dataByCoordSys.list.push(coordSysItem);
  44620. }
  44621. coordSysItem.dataByAxis.push({
  44622. axisDim: axis.dim,
  44623. axisIndex: axisModel.componentIndex,
  44624. axisType: axisModel.type,
  44625. axisId: axisModel.id,
  44626. value: value,
  44627. // Caustion: viewHelper.getValueLabel is actually on "view stage", which
  44628. // depends that all models have been updated. So it should not be performed
  44629. // here. Considering axisPointerModel used here is volatile, which is hard
  44630. // to be retrieve in TooltipView, we prepare parameters here.
  44631. valueLabelOpt: {
  44632. precision: axisPointerModel.get('label.precision'),
  44633. formatter: axisPointerModel.get('label.formatter')
  44634. },
  44635. seriesDataIndices: payloadBatch.slice()
  44636. });
  44637. }
  44638. function updateModelActually(showValueMap, axesInfo, outputFinder) {
  44639. var outputAxesInfo = outputFinder.axesInfo = [];
  44640. // Basic logic: If no 'show' required, 'hide' this axisPointer.
  44641. each(axesInfo, function (axisInfo, key) {
  44642. var option = axisInfo.axisPointerModel.option;
  44643. var valItem = showValueMap[key];
  44644. if (valItem) {
  44645. !axisInfo.useHandle && (option.status = 'show');
  44646. option.value = valItem.value;
  44647. // For label formatter param and highlight.
  44648. option.seriesDataIndices = (valItem.payloadBatch || []).slice();
  44649. }
  44650. // When always show (e.g., handle used), remain
  44651. // original value and status.
  44652. else {
  44653. // If hide, value still need to be set, consider
  44654. // click legend to toggle axis blank.
  44655. !axisInfo.useHandle && (option.status = 'hide');
  44656. }
  44657. // If status is 'hide', should be no info in payload.
  44658. option.status === 'show' && outputAxesInfo.push({
  44659. axisDim: axisInfo.axis.dim,
  44660. axisIndex: axisInfo.axis.model.componentIndex,
  44661. value: option.value
  44662. });
  44663. });
  44664. }
  44665. function dispatchTooltipActually(dataByCoordSys, point, tooltipOption, dispatchAction) {
  44666. // Basic logic: If no showTip required, hideTip will be dispatched.
  44667. if (illegalPoint(point) || !dataByCoordSys.list.length) {
  44668. dispatchAction({type: 'hideTip'});
  44669. return;
  44670. }
  44671. // In most case only one axis (or event one series is used). It is
  44672. // convinient to fetch payload.seriesIndex and payload.dataIndex
  44673. // dirtectly. So put the first seriesIndex and dataIndex of the first
  44674. // axis on the payload.
  44675. var sampleItem = ((dataByCoordSys.list[0].dataByAxis[0] || {}).seriesDataIndices || [])[0] || {};
  44676. dispatchAction({
  44677. type: 'showTip',
  44678. escapeConnect: true,
  44679. x: point[0],
  44680. y: point[1],
  44681. tooltipOption: tooltipOption,
  44682. dataIndexInside: sampleItem.dataIndexInside,
  44683. dataIndex: sampleItem.dataIndex,
  44684. seriesIndex: sampleItem.seriesIndex,
  44685. dataByCoordSys: dataByCoordSys.list
  44686. });
  44687. }
  44688. function dispatchHighDownActually(axesInfo, dispatchAction, api) {
  44689. // FIXME
  44690. // highlight status modification shoule be a stage of main process?
  44691. // (Consider confilct (e.g., legend and axisPointer) and setOption)
  44692. var zr = api.getZr();
  44693. var highDownKey = 'axisPointerLastHighlights';
  44694. var lastHighlights = get(zr)[highDownKey] || {};
  44695. var newHighlights = get(zr)[highDownKey] = {};
  44696. // Update highlight/downplay status according to axisPointer model.
  44697. // Build hash map and remove duplicate incidentally.
  44698. each(axesInfo, function (axisInfo, key) {
  44699. var option = axisInfo.axisPointerModel.option;
  44700. option.status === 'show' && each(option.seriesDataIndices, function (batchItem) {
  44701. var key = batchItem.seriesIndex + ' | ' + batchItem.dataIndex;
  44702. newHighlights[key] = batchItem;
  44703. });
  44704. });
  44705. // Diff.
  44706. var toHighlight = [];
  44707. var toDownplay = [];
  44708. zrUtil.each(lastHighlights, function (batchItem, key) {
  44709. !newHighlights[key] && toDownplay.push(batchItem);
  44710. });
  44711. zrUtil.each(newHighlights, function (batchItem, key) {
  44712. !lastHighlights[key] && toHighlight.push(batchItem);
  44713. });
  44714. toDownplay.length && api.dispatchAction({
  44715. type: 'downplay', escapeConnect: true, batch: toDownplay
  44716. });
  44717. toHighlight.length && api.dispatchAction({
  44718. type: 'highlight', escapeConnect: true, batch: toHighlight
  44719. });
  44720. }
  44721. function findInputAxisInfo(inputAxesInfo, axisInfo) {
  44722. for (var i = 0; i < (inputAxesInfo || []).length; i++) {
  44723. var inputAxisInfo = inputAxesInfo[i];
  44724. if (axisInfo.axis.dim === inputAxisInfo.axisDim
  44725. && axisInfo.axis.model.componentIndex === inputAxisInfo.axisIndex
  44726. ) {
  44727. return inputAxisInfo;
  44728. }
  44729. }
  44730. }
  44731. function makeMapperParam(axisInfo) {
  44732. var axisModel = axisInfo.axis.model;
  44733. var item = {};
  44734. var dim = item.axisDim = axisInfo.axis.dim;
  44735. item.axisIndex = item[dim + 'AxisIndex'] = axisModel.componentIndex;
  44736. item.axisName = item[dim + 'AxisName'] = axisModel.name;
  44737. item.axisId = item[dim + 'AxisId'] = axisModel.id;
  44738. return item;
  44739. }
  44740. function illegalPoint(point) {
  44741. return !point || point[0] == null || isNaN(point[0]) || point[1] == null || isNaN(point[1]);
  44742. }
  44743. module.exports = axisTrigger;
  44744. /***/ },
  44745. /* 299 */
  44746. /***/ function(module, exports, __webpack_require__) {
  44747. var zrUtil = __webpack_require__(4);
  44748. var modelUtil = __webpack_require__(5);
  44749. /**
  44750. * @param {Object} finder contains {seriesIndex, dataIndex, dataIndexInside}
  44751. * @param {module:echarts/model/Global} ecModel
  44752. * @return {Object} {point: [x, y], el: ...} point Will not be null.
  44753. */
  44754. module.exports = function (finder, ecModel) {
  44755. var point = [];
  44756. var seriesIndex = finder.seriesIndex;
  44757. var seriesModel;
  44758. if (seriesIndex == null || !(
  44759. seriesModel = ecModel.getSeriesByIndex(seriesIndex)
  44760. )) {
  44761. return {point: []};
  44762. }
  44763. var data = seriesModel.getData();
  44764. var dataIndex = modelUtil.queryDataIndex(data, finder);
  44765. if (dataIndex == null || zrUtil.isArray(dataIndex)) {
  44766. return {point: []};
  44767. }
  44768. var el = data.getItemGraphicEl(dataIndex);
  44769. var coordSys = seriesModel.coordinateSystem;
  44770. if (seriesModel.getTooltipPosition) {
  44771. point = seriesModel.getTooltipPosition(dataIndex) || [];
  44772. }
  44773. else if (coordSys && coordSys.dataToPoint) {
  44774. point = coordSys.dataToPoint(
  44775. data.getValues(
  44776. zrUtil.map(coordSys.dimensions, function (dim) {
  44777. return seriesModel.coordDimToDataDim(dim)[0];
  44778. }), dataIndex, true
  44779. )
  44780. ) || [];
  44781. }
  44782. else if (el) {
  44783. // Use graphic bounding rect
  44784. var rect = el.getBoundingRect().clone();
  44785. rect.applyTransform(el.transform);
  44786. point = [
  44787. rect.x + rect.width / 2,
  44788. rect.y + rect.height / 2
  44789. ];
  44790. }
  44791. return {point: point, el: el};
  44792. };
  44793. /***/ },
  44794. /* 300 */
  44795. /***/ function(module, exports, __webpack_require__) {
  44796. var echarts = __webpack_require__(1);
  44797. var AxisPointerModel = echarts.extendComponentModel({
  44798. type: 'axisPointer',
  44799. coordSysAxesInfo: null,
  44800. defaultOption: {
  44801. // 'auto' means that show when triggered by tooltip or handle.
  44802. show: 'auto',
  44803. // 'click' | 'mousemove' | 'none'
  44804. triggerOn: null, // set default in AxisPonterView.js
  44805. zlevel: 0,
  44806. z: 50,
  44807. type: 'line',
  44808. // axispointer triggered by tootip determine snap automatically,
  44809. // see `modelHelper`.
  44810. snap: false,
  44811. triggerTooltip: true,
  44812. value: null,
  44813. status: null, // Init value depends on whether handle is used.
  44814. // [group0, group1, ...]
  44815. // Each group can be: {
  44816. // mapper: function () {},
  44817. // singleTooltip: 'multiple', // 'multiple' or 'single'
  44818. // xAxisId: ...,
  44819. // yAxisName: ...,
  44820. // angleAxisIndex: ...
  44821. // }
  44822. // mapper: can be ignored.
  44823. // input: {axisInfo, value}
  44824. // output: {axisInfo, value}
  44825. link: [],
  44826. // Do not set 'auto' here, otherwise global animation: false
  44827. // will not effect at this axispointer.
  44828. animation: null,
  44829. animationDurationUpdate: 200,
  44830. lineStyle: {
  44831. color: '#aaa',
  44832. width: 1,
  44833. type: 'solid'
  44834. },
  44835. shadowStyle: {
  44836. color: 'rgba(150,150,150,0.3)'
  44837. },
  44838. label: {
  44839. show: true,
  44840. formatter: null, // string | Function
  44841. precision: 'auto', // Or a number like 0, 1, 2 ...
  44842. margin: 3,
  44843. textStyle: {
  44844. color: '#fff'
  44845. },
  44846. padding: [5, 7, 5, 7],
  44847. backgroundColor: 'auto', // default: axis line color
  44848. borderColor: null,
  44849. borderWidth: 0,
  44850. shadowBlur: 3,
  44851. shadowColor: '#aaa'
  44852. // Considering applicability, common style should
  44853. // better not have shadowOffset.
  44854. // shadowOffsetX: 0,
  44855. // shadowOffsetY: 2
  44856. },
  44857. handle: {
  44858. show: false,
  44859. 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
  44860. size: 45,
  44861. // handle margin is from symbol center to axis, which is stable when circular move.
  44862. margin: 50,
  44863. // color: '#1b8bbd'
  44864. // color: '#2f4554'
  44865. color: '#333',
  44866. shadowBlur: 3,
  44867. shadowColor: '#aaa',
  44868. shadowOffsetX: 0,
  44869. shadowOffsetY: 2,
  44870. // For mobile performance
  44871. throttle: 40
  44872. }
  44873. }
  44874. });
  44875. module.exports = AxisPointerModel;
  44876. /***/ },
  44877. /* 301 */
  44878. /***/ function(module, exports, __webpack_require__) {
  44879. var globalListener = __webpack_require__(302);
  44880. var AxisPonterView = __webpack_require__(1).extendComponentView({
  44881. type: 'axisPointer',
  44882. render: function (globalAxisPointerModel, ecModel, api) {
  44883. var globalTooltipModel = ecModel.getComponent('tooltip');
  44884. var triggerOn = globalAxisPointerModel.get('triggerOn')
  44885. || (globalTooltipModel && globalTooltipModel.get('triggerOn') || 'mousemove|click');
  44886. // Register global listener in AxisPointerView to enable
  44887. // AxisPointerView to be independent to Tooltip.
  44888. globalListener.register(
  44889. 'axisPointer',
  44890. api,
  44891. function (currTrigger, e, dispatchAction) {
  44892. // If 'none', it is not controlled by mouse totally.
  44893. if (triggerOn !== 'none'
  44894. && (currTrigger === 'leave' || triggerOn.indexOf(currTrigger) >= 0)
  44895. ) {
  44896. dispatchAction({
  44897. type: 'updateAxisPointer',
  44898. currTrigger: currTrigger,
  44899. x: e && e.offsetX,
  44900. y: e && e.offsetY
  44901. });
  44902. }
  44903. }
  44904. );
  44905. },
  44906. /**
  44907. * @override
  44908. */
  44909. remove: function (ecModel, api) {
  44910. globalListener.disopse(api.getZr(), 'axisPointer');
  44911. AxisPonterView.superApply(this._model, 'remove', arguments);
  44912. },
  44913. /**
  44914. * @override
  44915. */
  44916. dispose: function (ecModel, api) {
  44917. globalListener.unregister('axisPointer', api);
  44918. AxisPonterView.superApply(this._model, 'dispose', arguments);
  44919. }
  44920. });
  44921. /***/ },
  44922. /* 302 */
  44923. /***/ function(module, exports, __webpack_require__) {
  44924. var env = __webpack_require__(2);
  44925. var zrUtil = __webpack_require__(4);
  44926. var get = __webpack_require__(5).makeGetter();
  44927. var each = zrUtil.each;
  44928. var globalListener = {};
  44929. /**
  44930. * @param {string} key
  44931. * @param {module:echarts/ExtensionAPI} api
  44932. * @param {Function} handler
  44933. * param: {string} currTrigger
  44934. * param: {Array.<number>} point
  44935. */
  44936. globalListener.register = function (key, api, handler) {
  44937. if (env.node) {
  44938. return;
  44939. }
  44940. var zr = api.getZr();
  44941. get(zr).records || (get(zr).records = {});
  44942. initGlobalListeners(zr, api);
  44943. var record = get(zr).records[key] || (get(zr).records[key] = {});
  44944. record.handler = handler;
  44945. };
  44946. function initGlobalListeners(zr, api) {
  44947. if (get(zr).initialized) {
  44948. return;
  44949. }
  44950. get(zr).initialized = true;
  44951. useHandler('click', zrUtil.curry(doEnter, 'click'));
  44952. useHandler('mousemove', zrUtil.curry(doEnter, 'mousemove'));
  44953. // useHandler('mouseout', onLeave);
  44954. useHandler('globalout', onLeave);
  44955. function useHandler(eventType, cb) {
  44956. zr.on(eventType, function (e) {
  44957. var dis = makeDispatchAction(api);
  44958. each(get(zr).records, function (record) {
  44959. record && cb(record, e, dis.dispatchAction);
  44960. });
  44961. dispatchTooltipFinally(dis.pendings, api);
  44962. });
  44963. }
  44964. }
  44965. function dispatchTooltipFinally(pendings, api) {
  44966. var showLen = pendings.showTip.length;
  44967. var hideLen = pendings.hideTip.length;
  44968. var actuallyPayload;
  44969. if (showLen) {
  44970. actuallyPayload = pendings.showTip[showLen - 1];
  44971. }
  44972. else if (hideLen) {
  44973. actuallyPayload = pendings.hideTip[hideLen - 1];
  44974. }
  44975. if (actuallyPayload) {
  44976. actuallyPayload.dispatchAction = null;
  44977. api.dispatchAction(actuallyPayload);
  44978. }
  44979. }
  44980. function onLeave(record, e, dispatchAction) {
  44981. record.handler('leave', null, dispatchAction);
  44982. }
  44983. function doEnter(currTrigger, record, e, dispatchAction) {
  44984. record.handler(currTrigger, e, dispatchAction);
  44985. }
  44986. function makeDispatchAction(api) {
  44987. var pendings = {
  44988. showTip: [],
  44989. hideTip: []
  44990. };
  44991. // FIXME
  44992. // better approach?
  44993. // 'showTip' and 'hideTip' can be triggered by axisPointer and tooltip,
  44994. // which may be conflict, (axisPointer call showTip but tooltip call hideTip);
  44995. // So we have to add "final stage" to merge those dispatched actions.
  44996. var dispatchAction = function (payload) {
  44997. var pendingList = pendings[payload.type];
  44998. if (pendingList) {
  44999. pendingList.push(payload);
  45000. }
  45001. else {
  45002. payload.dispatchAction = dispatchAction;
  45003. api.dispatchAction(payload);
  45004. }
  45005. };
  45006. return {
  45007. dispatchAction: dispatchAction,
  45008. pendings: pendings
  45009. };
  45010. }
  45011. /**
  45012. * @param {string} key
  45013. * @param {module:echarts/ExtensionAPI} api
  45014. */
  45015. globalListener.unregister = function (key, api) {
  45016. if (env.node) {
  45017. return;
  45018. }
  45019. var zr = api.getZr();
  45020. var record = (get(zr).records || {})[key];
  45021. if (record) {
  45022. get(zr).records[key] = null;
  45023. }
  45024. };
  45025. module.exports = globalListener;
  45026. /***/ },
  45027. /* 303 */
  45028. /***/ function(module, exports, __webpack_require__) {
  45029. 'use strict';
  45030. var graphic = __webpack_require__(18);
  45031. var BaseAxisPointer = __webpack_require__(304);
  45032. var viewHelper = __webpack_require__(305);
  45033. var cartesianAxisHelper = __webpack_require__(138);
  45034. var AxisView = __webpack_require__(136);
  45035. var CartesianAxisPointer = BaseAxisPointer.extend({
  45036. /**
  45037. * @override
  45038. */
  45039. makeElOption: function (elOption, value, axisModel, axisPointerModel, api) {
  45040. var axis = axisModel.axis;
  45041. var grid = axis.grid;
  45042. var axisPointerType = axisPointerModel.get('type');
  45043. var otherExtent = getCartesian(grid, axis).getOtherAxis(axis).getGlobalExtent();
  45044. var pixelValue = axis.toGlobalCoord(axis.dataToCoord(value, true));
  45045. if (axisPointerType && axisPointerType !== 'none') {
  45046. var elStyle = viewHelper.buildElStyle(axisPointerModel);
  45047. var pointerOption = pointerShapeBuilder[axisPointerType](
  45048. axis, pixelValue, otherExtent, elStyle
  45049. );
  45050. pointerOption.style = elStyle;
  45051. elOption.graphicKey = pointerOption.type;
  45052. elOption.pointer = pointerOption;
  45053. }
  45054. var layoutInfo = cartesianAxisHelper.layout(grid.model, axisModel);
  45055. viewHelper.buildCartesianSingleLabelElOption(
  45056. value, elOption, layoutInfo, axisModel, axisPointerModel, api
  45057. );
  45058. },
  45059. /**
  45060. * @override
  45061. */
  45062. getHandleTransform: function (value, axisModel, axisPointerModel) {
  45063. var layoutInfo = cartesianAxisHelper.layout(axisModel.axis.grid.model, axisModel, {
  45064. labelInside: false
  45065. });
  45066. layoutInfo.labelMargin = axisPointerModel.get('handle.margin');
  45067. return {
  45068. position: viewHelper.getTransformedPosition(axisModel.axis, value, layoutInfo),
  45069. rotation: layoutInfo.rotation + (layoutInfo.labelDirection < 0 ? Math.PI : 0)
  45070. };
  45071. },
  45072. /**
  45073. * @override
  45074. */
  45075. updateHandleTransform: function (transform, delta, axisModel, axisPointerModel) {
  45076. var axis = axisModel.axis;
  45077. var grid = axis.grid;
  45078. var axisExtent = axis.getGlobalExtent(true);
  45079. var otherExtent = getCartesian(grid, axis).getOtherAxis(axis).getGlobalExtent();
  45080. var dimIndex = axis.dim === 'x' ? 0 : 1;
  45081. var currPosition = transform.position;
  45082. currPosition[dimIndex] += delta[dimIndex];
  45083. currPosition[dimIndex] = Math.min(axisExtent[1], currPosition[dimIndex]);
  45084. currPosition[dimIndex] = Math.max(axisExtent[0], currPosition[dimIndex]);
  45085. var cursorOtherValue = (otherExtent[1] + otherExtent[0]) / 2;
  45086. var cursorPoint = [cursorOtherValue, cursorOtherValue];
  45087. cursorPoint[dimIndex] = currPosition[dimIndex];
  45088. // Make tooltip do not overlap axisPointer and in the middle of the grid.
  45089. var tooltipOptions = [{verticalAlign: 'middle'}, {align: 'center'}];
  45090. return {
  45091. position: currPosition,
  45092. rotation: transform.rotation,
  45093. cursorPoint: cursorPoint,
  45094. tooltipOption: tooltipOptions[dimIndex]
  45095. };
  45096. }
  45097. });
  45098. function getCartesian(grid, axis) {
  45099. var opt = {};
  45100. opt[axis.dim + 'AxisIndex'] = axis.index;
  45101. return grid.getCartesian(opt);
  45102. }
  45103. var pointerShapeBuilder = {
  45104. line: function (axis, pixelValue, otherExtent, elStyle) {
  45105. var targetShape = viewHelper.makeLineShape(
  45106. [pixelValue, otherExtent[0]],
  45107. [pixelValue, otherExtent[1]],
  45108. getAxisDimIndex(axis)
  45109. );
  45110. graphic.subPixelOptimizeLine({
  45111. shape: targetShape,
  45112. style: elStyle
  45113. });
  45114. return {
  45115. type: 'Line',
  45116. shape: targetShape
  45117. };
  45118. },
  45119. shadow: function (axis, pixelValue, otherExtent, elStyle) {
  45120. var bandWidth = axis.getBandWidth();
  45121. var span = otherExtent[1] - otherExtent[0];
  45122. return {
  45123. type: 'Rect',
  45124. shape: viewHelper.makeRectShape(
  45125. [pixelValue - bandWidth / 2, otherExtent[0]],
  45126. [bandWidth, span],
  45127. getAxisDimIndex(axis)
  45128. )
  45129. };
  45130. }
  45131. };
  45132. function getAxisDimIndex(axis) {
  45133. return axis.dim === 'x' ? 0 : 1;
  45134. }
  45135. AxisView.registerAxisPointerClass('CartesianAxisPointer', CartesianAxisPointer);
  45136. module.exports = CartesianAxisPointer;
  45137. /***/ },
  45138. /* 304 */
  45139. /***/ function(module, exports, __webpack_require__) {
  45140. 'use strict';
  45141. var zrUtil = __webpack_require__(4);
  45142. var clazzUtil = __webpack_require__(13);
  45143. var graphic = __webpack_require__(18);
  45144. var get = __webpack_require__(5).makeGetter();
  45145. var axisPointerModelHelper = __webpack_require__(137);
  45146. var eventTool = __webpack_require__(88);
  45147. var throttle = __webpack_require__(81);
  45148. var clone = zrUtil.clone;
  45149. var bind = zrUtil.bind;
  45150. /**
  45151. * Base axis pointer class in 2D.
  45152. * Implemenents {module:echarts/component/axis/IAxisPointer}.
  45153. */
  45154. function BaseAxisPointer () {
  45155. }
  45156. BaseAxisPointer.prototype = {
  45157. /**
  45158. * @private
  45159. */
  45160. _group: null,
  45161. /**
  45162. * @private
  45163. */
  45164. _lastGraphicKey: null,
  45165. /**
  45166. * @private
  45167. */
  45168. _handle: null,
  45169. /**
  45170. * @private
  45171. */
  45172. _dragging: false,
  45173. /**
  45174. * @private
  45175. */
  45176. _lastValue: null,
  45177. /**
  45178. * @private
  45179. */
  45180. _lastStatus: null,
  45181. /**
  45182. * @private
  45183. */
  45184. _payloadInfo: null,
  45185. /**
  45186. * In px, arbitrary value. Do not set too small,
  45187. * no animation is ok for most cases.
  45188. * @protected
  45189. */
  45190. animationThreshold: 15,
  45191. /**
  45192. * @implement
  45193. */
  45194. render: function (axisModel, axisPointerModel, api, forceRender) {
  45195. var value = axisPointerModel.get('value');
  45196. var status = axisPointerModel.get('status');
  45197. // Bind them to `this`, not in closure, otherwise they will not
  45198. // be replaced when user calling setOption in not merge mode.
  45199. this._axisModel = axisModel;
  45200. this._axisPointerModel = axisPointerModel;
  45201. this._api = api;
  45202. // Optimize: `render` will be called repeatly during mouse move.
  45203. // So it is power consuming if performing `render` each time,
  45204. // especially on mobile device.
  45205. if (!forceRender
  45206. && this._lastValue === value
  45207. && this._lastStatus === status
  45208. ) {
  45209. return;
  45210. }
  45211. this._lastValue = value;
  45212. this._lastStatus = status;
  45213. var group = this._group;
  45214. var handle = this._handle;
  45215. if (!status || status === 'hide') {
  45216. // Do not clear here, for animation better.
  45217. group && group.hide();
  45218. handle && handle.hide();
  45219. return;
  45220. }
  45221. group && group.show();
  45222. handle && handle.show();
  45223. // Otherwise status is 'show'
  45224. var elOption = {};
  45225. this.makeElOption(elOption, value, axisModel, axisPointerModel, api);
  45226. // Enable change axis pointer type.
  45227. var graphicKey = elOption.graphicKey;
  45228. if (graphicKey !== this._lastGraphicKey) {
  45229. this.clear(api);
  45230. }
  45231. this._lastGraphicKey = graphicKey;
  45232. var moveAnimation = this._moveAnimation =
  45233. this.determineAnimation(axisModel, axisPointerModel);
  45234. if (!group) {
  45235. group = this._group = new graphic.Group();
  45236. this.createPointerEl(group, elOption, axisModel, axisPointerModel);
  45237. this.createLabelEl(group, elOption, axisModel, axisPointerModel);
  45238. api.getZr().add(group);
  45239. }
  45240. else {
  45241. var doUpdateProps = zrUtil.curry(updateProps, axisPointerModel, moveAnimation);
  45242. this.updatePointerEl(group, elOption, doUpdateProps, axisPointerModel);
  45243. this.updateLabelEl(group, elOption, doUpdateProps, axisPointerModel);
  45244. }
  45245. updateMandatoryProps(group, axisPointerModel, true);
  45246. this._renderHandle(value);
  45247. },
  45248. /**
  45249. * @implement
  45250. */
  45251. remove: function (api) {
  45252. this.clear(api);
  45253. },
  45254. /**
  45255. * @implement
  45256. */
  45257. dispose: function (api) {
  45258. this.clear(api);
  45259. },
  45260. /**
  45261. * @protected
  45262. */
  45263. determineAnimation: function (axisModel, axisPointerModel) {
  45264. var animation = axisPointerModel.get('animation');
  45265. var axis = axisModel.axis;
  45266. var isCategoryAxis = axis.type === 'category';
  45267. var useSnap = axisPointerModel.get('snap');
  45268. // Value axis without snap always do not snap.
  45269. if (!useSnap && !isCategoryAxis) {
  45270. return false;
  45271. }
  45272. if (animation === 'auto' || animation == null) {
  45273. var animationThreshold = this.animationThreshold;
  45274. if (isCategoryAxis && axis.getBandWidth() > animationThreshold) {
  45275. return true;
  45276. }
  45277. // It is important to auto animation when snap used. Consider if there is
  45278. // a dataZoom, animation will be disabled when too many points exist, while
  45279. // it will be enabled for better visual effect when little points exist.
  45280. if (useSnap) {
  45281. var seriesDataCount = axisPointerModelHelper.getAxisInfo(axisModel).seriesDataCount;
  45282. var axisExtent = axis.getExtent();
  45283. // Approximate band width
  45284. return Math.abs(axisExtent[0] - axisExtent[1]) / seriesDataCount > animationThreshold;
  45285. }
  45286. return false;
  45287. }
  45288. return animation === true;
  45289. },
  45290. /**
  45291. * add {pointer, label, graphicKey} to elOption
  45292. * @protected
  45293. */
  45294. makeElOption: function (elOption, value, axisModel, axisPointerModel, api) {
  45295. // Shoule be implemenented by sub-class.
  45296. },
  45297. /**
  45298. * @protected
  45299. */
  45300. createPointerEl: function (group, elOption, axisModel, axisPointerModel) {
  45301. var pointerOption = elOption.pointer;
  45302. if (pointerOption) {
  45303. var pointerEl = get(group).pointerEl = new graphic[pointerOption.type](
  45304. clone(elOption.pointer)
  45305. );
  45306. group.add(pointerEl);
  45307. }
  45308. },
  45309. /**
  45310. * @protected
  45311. */
  45312. createLabelEl: function (group, elOption, axisModel, axisPointerModel) {
  45313. if (elOption.label) {
  45314. var labelEl = get(group).labelEl = new graphic.Rect(
  45315. clone(elOption.label)
  45316. );
  45317. group.add(labelEl);
  45318. updateLabelShowHide(labelEl, axisPointerModel);
  45319. }
  45320. },
  45321. /**
  45322. * @protected
  45323. */
  45324. updatePointerEl: function (group, elOption, updateProps) {
  45325. var pointerEl = get(group).pointerEl;
  45326. if (pointerEl) {
  45327. pointerEl.setStyle(elOption.pointer.style);
  45328. updateProps(pointerEl, {shape: elOption.pointer.shape});
  45329. }
  45330. },
  45331. /**
  45332. * @protected
  45333. */
  45334. updateLabelEl: function (group, elOption, updateProps, axisPointerModel) {
  45335. var labelEl = get(group).labelEl;
  45336. if (labelEl) {
  45337. labelEl.setStyle(elOption.label.style);
  45338. updateProps(labelEl, {
  45339. // Consider text length change in vertical axis, animation should
  45340. // be used on shape, otherwise the effect will be weird.
  45341. shape: elOption.label.shape,
  45342. position: elOption.label.position
  45343. });
  45344. updateLabelShowHide(labelEl, axisPointerModel);
  45345. }
  45346. },
  45347. /**
  45348. * @private
  45349. */
  45350. _renderHandle: function (value) {
  45351. if (this._dragging || !this.updateHandleTransform) {
  45352. return;
  45353. }
  45354. var axisPointerModel = this._axisPointerModel;
  45355. var zr = this._api.getZr();
  45356. var handle = this._handle;
  45357. var handleModel = axisPointerModel.getModel('handle');
  45358. var status = axisPointerModel.get('status');
  45359. if (!handleModel.get('show') || !status || status === 'hide') {
  45360. handle && zr.remove(handle);
  45361. this._handle = null;
  45362. return;
  45363. }
  45364. var isInit;
  45365. if (!this._handle) {
  45366. isInit = true;
  45367. handle = this._handle = createIcon(handleModel, {
  45368. onmousemove: function (e) {
  45369. // Fot mobile devicem, prevent screen slider on the button.
  45370. eventTool.stop(e.event);
  45371. },
  45372. onmousedown: bind(this._onHandleDragMove, this, 0, 0),
  45373. drift: bind(this._onHandleDragMove, this),
  45374. ondragend: bind(this._onHandleDragEnd, this)
  45375. });
  45376. zr.add(handle);
  45377. }
  45378. updateMandatoryProps(handle, axisPointerModel, false);
  45379. // update style
  45380. var includeStyles = [
  45381. 'color', 'borderColor', 'borderWidth', 'opacity',
  45382. 'shadowColor', 'shadowBlur', 'shadowOffsetX', 'shadowOffsetY'
  45383. ];
  45384. handle.setStyle(handleModel.getItemStyle(null, includeStyles));
  45385. // update position
  45386. var handleSize = handleModel.get('size');
  45387. if (!zrUtil.isArray(handleSize)) {
  45388. handleSize = [handleSize, handleSize];
  45389. }
  45390. handle.attr('scale', [handleSize[0] / 2, handleSize[1] / 2]);
  45391. throttle.createOrUpdate(
  45392. this,
  45393. '_doDispatchAxisPointer',
  45394. handleModel.get('throttle') || 0,
  45395. 'fixRate'
  45396. );
  45397. this._moveHandleToValue(value, isInit);
  45398. },
  45399. /**
  45400. * @private
  45401. */
  45402. _moveHandleToValue: function (value, isInit) {
  45403. updateProps(
  45404. this._axisPointerModel,
  45405. !isInit && this._moveAnimation,
  45406. this._handle,
  45407. getHandleTransProps(this.getHandleTransform(
  45408. value, this._axisModel, this._axisPointerModel
  45409. ))
  45410. );
  45411. },
  45412. /**
  45413. * @private
  45414. */
  45415. _onHandleDragMove: function (dx, dy) {
  45416. var handle = this._handle;
  45417. if (!handle) {
  45418. return;
  45419. }
  45420. this._dragging = true;
  45421. // Persistent for throttle.
  45422. var trans = this.updateHandleTransform(
  45423. getHandleTransProps(handle),
  45424. [dx, dy],
  45425. this._axisModel,
  45426. this._axisPointerModel
  45427. );
  45428. this._payloadInfo = trans;
  45429. handle.stopAnimation();
  45430. handle.attr(getHandleTransProps(trans));
  45431. get(handle).lastProp = null;
  45432. this._doDispatchAxisPointer();
  45433. },
  45434. /**
  45435. * Throttled method.
  45436. * @private
  45437. */
  45438. _doDispatchAxisPointer: function () {
  45439. var handle = this._handle;
  45440. if (!handle) {
  45441. return;
  45442. }
  45443. var payloadInfo = this._payloadInfo;
  45444. var axisModel = this._axisModel;
  45445. this._api.dispatchAction({
  45446. type: 'updateAxisPointer',
  45447. x: payloadInfo.cursorPoint[0],
  45448. y: payloadInfo.cursorPoint[1],
  45449. tooltipOption: payloadInfo.tooltipOption,
  45450. axesInfo: [{
  45451. axisDim: axisModel.axis.dim,
  45452. axisIndex: axisModel.componentIndex
  45453. }]
  45454. });
  45455. },
  45456. /**
  45457. * @private
  45458. */
  45459. _onHandleDragEnd: function (moveAnimation) {
  45460. this._dragging = false;
  45461. var handle = this._handle;
  45462. if (!handle) {
  45463. return;
  45464. }
  45465. var value = this._axisPointerModel.get('value');
  45466. // Consider snap or categroy axis, handle may be not consistent with
  45467. // axisPointer. So move handle to align the exact value position when
  45468. // drag ended.
  45469. this._moveHandleToValue(value);
  45470. // For the effect: tooltip will be shown when finger holding on handle
  45471. // button, and will be hidden after finger left handle button.
  45472. this._api.dispatchAction({
  45473. type: 'hideTip'
  45474. });
  45475. },
  45476. /**
  45477. * Should be implemenented by sub-class if support `handle`.
  45478. * @protected
  45479. * @param {number} value
  45480. * @param {module:echarts/model/Model} axisModel
  45481. * @param {module:echarts/model/Model} axisPointerModel
  45482. * @return {Object} {position: [x, y], rotation: 0}
  45483. */
  45484. getHandleTransform: null,
  45485. /**
  45486. * * Should be implemenented by sub-class if support `handle`.
  45487. * @protected
  45488. * @param {Object} transform {position, rotation}
  45489. * @param {Array.<number>} delta [dx, dy]
  45490. * @param {module:echarts/model/Model} axisModel
  45491. * @param {module:echarts/model/Model} axisPointerModel
  45492. * @return {Object} {position: [x, y], rotation: 0, cursorPoint: [x, y]}
  45493. */
  45494. updateHandleTransform: null,
  45495. /**
  45496. * @private
  45497. */
  45498. clear: function (api) {
  45499. this._lastValue = null;
  45500. this._lastStatus = null;
  45501. var zr = api.getZr();
  45502. var group = this._group;
  45503. var handle = this._handle;
  45504. if (zr && group) {
  45505. this._lastGraphicKey = null;
  45506. group && zr.remove(group);
  45507. handle && zr.remove(handle);
  45508. this._group = null;
  45509. this._handle = null;
  45510. this._payloadInfo = null;
  45511. }
  45512. },
  45513. /**
  45514. * @protected
  45515. */
  45516. doClear: function () {
  45517. // Implemented by sub-class if necessary.
  45518. },
  45519. /**
  45520. * @protected
  45521. * @param {Array.<number>} xy
  45522. * @param {Array.<number>} wh
  45523. * @param {number} [xDimIndex=0] or 1
  45524. */
  45525. buildLabel: function (xy, wh, xDimIndex) {
  45526. xDimIndex = xDimIndex || 0;
  45527. return {
  45528. x: xy[xDimIndex],
  45529. y: xy[1 - xDimIndex],
  45530. width: wh[xDimIndex],
  45531. height: wh[1 - xDimIndex]
  45532. };
  45533. }
  45534. };
  45535. BaseAxisPointer.prototype.constructor = BaseAxisPointer;
  45536. function updateProps(animationModel, moveAnimation, el, props) {
  45537. // Animation optimize.
  45538. if (!propsEqual(get(el).lastProp, props)) {
  45539. get(el).lastProp = props;
  45540. moveAnimation
  45541. ? graphic.updateProps(el, props, animationModel)
  45542. : (el.stopAnimation(), el.attr(props));
  45543. }
  45544. }
  45545. function propsEqual(lastProps, newProps) {
  45546. if (zrUtil.isObject(lastProps) && zrUtil.isObject(newProps)) {
  45547. var equals = true;
  45548. zrUtil.each(newProps, function (item, key) {
  45549. equals &= propsEqual(lastProps[key], item);
  45550. });
  45551. return !!equals;
  45552. }
  45553. else {
  45554. return lastProps === newProps;
  45555. }
  45556. }
  45557. function updateLabelShowHide(labelEl, axisPointerModel) {
  45558. labelEl[axisPointerModel.get('label.show') ? 'show' : 'hide']();
  45559. }
  45560. function getHandleTransProps(trans) {
  45561. return {
  45562. position: trans.position.slice(),
  45563. rotation: trans.rotation || 0
  45564. };
  45565. }
  45566. function createIcon(handleModel, handlers) {
  45567. var iconStr = handleModel.get('icon');
  45568. var style = {
  45569. x: -1, y: -1, width: 2, height: 2
  45570. };
  45571. var opt = zrUtil.extend({
  45572. style: {
  45573. strokeNoScale: true
  45574. },
  45575. rectHover: true,
  45576. cursor: 'move',
  45577. draggable: true
  45578. }, handlers);
  45579. return iconStr.indexOf('image://') === 0
  45580. ? (
  45581. style.image = iconStr.slice(8),
  45582. opt.style = style,
  45583. new graphic.Image(opt)
  45584. )
  45585. : graphic.makePath(
  45586. iconStr.replace('path://', ''),
  45587. opt,
  45588. style,
  45589. 'center'
  45590. );
  45591. }
  45592. function updateMandatoryProps(group, axisPointerModel, silent) {
  45593. var z = axisPointerModel.get('z');
  45594. var zlevel = axisPointerModel.get('zlevel');
  45595. group && group.traverse(function (el) {
  45596. if (el.type !== 'group') {
  45597. z != null && (el.z = z);
  45598. zlevel != null && (el.zlevel = zlevel);
  45599. el.silent = silent;
  45600. }
  45601. });
  45602. }
  45603. clazzUtil.enableClassExtend(BaseAxisPointer);
  45604. module.exports = BaseAxisPointer;
  45605. /***/ },
  45606. /* 305 */
  45607. /***/ function(module, exports, __webpack_require__) {
  45608. 'use strict';
  45609. var zrUtil = __webpack_require__(4);
  45610. var graphic = __webpack_require__(18);
  45611. var textContain = __webpack_require__(8);
  45612. var formatUtil = __webpack_require__(6);
  45613. var matrix = __webpack_require__(11);
  45614. var axisHelper = __webpack_require__(101);
  45615. var AxisBuilder = __webpack_require__(135);
  45616. var helper = {};
  45617. /**
  45618. * @param {module:echarts/model/Model} axisPointerModel
  45619. */
  45620. helper.buildElStyle = function (axisPointerModel) {
  45621. var axisPointerType = axisPointerModel.get('type');
  45622. var styleModel = axisPointerModel.getModel(axisPointerType + 'Style');
  45623. var style;
  45624. if (axisPointerType === 'line') {
  45625. style = styleModel.getLineStyle();
  45626. style.fill = null;
  45627. }
  45628. else if (axisPointerType === 'shadow') {
  45629. style = styleModel.getAreaStyle();
  45630. style.stroke = null;
  45631. }
  45632. return style;
  45633. };
  45634. /**
  45635. * @param {Function} labelPos {align, verticalAlign, position}
  45636. */
  45637. helper.buildLabelElOption = function (
  45638. elOption, axisModel, axisPointerModel, api, labelPos
  45639. ) {
  45640. var value = axisPointerModel.get('value');
  45641. var text = helper.getValueLabel(
  45642. value, axisModel.axis, axisModel.ecModel,
  45643. axisPointerModel.get('seriesDataIndices'),
  45644. {
  45645. precision: axisPointerModel.get('label.precision'),
  45646. formatter: axisPointerModel.get('label.formatter')
  45647. }
  45648. );
  45649. var labelModel = axisPointerModel.getModel('label');
  45650. var textStyleModel = labelModel.getModel('textStyle');
  45651. var paddings = formatUtil.normalizeCssArray(labelModel.get('padding') || 0);
  45652. var font = textStyleModel.getFont();
  45653. var textRect = textContain.getBoundingRect(
  45654. text, font, labelPos.textAlign, labelPos.textBaseline
  45655. );
  45656. var position = labelPos.position;
  45657. var width = textRect.width + paddings[1] + paddings[3];
  45658. var height = textRect.height + paddings[0] + paddings[2];
  45659. // Adjust by align.
  45660. var align = labelPos.align;
  45661. align === 'right' && (position[0] -= width);
  45662. align === 'center' && (position[0] -= width / 2);
  45663. var verticalAlign = labelPos.verticalAlign;
  45664. verticalAlign === 'bottom' && (position[1] -= height);
  45665. verticalAlign === 'middle' && (position[1] -= height / 2);
  45666. // Not overflow ec container
  45667. confineInContainer(position, width, height, api);
  45668. var bgColor = labelModel.get('backgroundColor');
  45669. if (!bgColor || bgColor === 'auto') {
  45670. bgColor = axisModel.get('axisLine.lineStyle.color');
  45671. }
  45672. elOption.label = {
  45673. shape: {x: 0, y: 0, width: width, height: height, r: labelModel.get('borderRadius')},
  45674. position: position.slice(),
  45675. style: {
  45676. text: text,
  45677. textFont: font,
  45678. textFill: textStyleModel.getTextColor(),
  45679. textPosition: 'inside',
  45680. fill: bgColor,
  45681. stroke: labelModel.get('borderColor') || 'transparent',
  45682. lineWidth: labelModel.get('borderWidth') || 0,
  45683. shadowBlur: labelModel.get('shadowBlur'),
  45684. shadowColor: labelModel.get('shadowColor'),
  45685. shadowOffsetX: labelModel.get('shadowOffsetX'),
  45686. shadowOffsetY: labelModel.get('shadowOffsetY')
  45687. },
  45688. // Lable should be over axisPointer.
  45689. z2: 10
  45690. };
  45691. };
  45692. // Do not overflow ec container
  45693. function confineInContainer(position, width, height, api) {
  45694. var viewWidth = api.getWidth();
  45695. var viewHeight = api.getHeight();
  45696. position[0] = Math.min(position[0] + width, viewWidth) - width;
  45697. position[1] = Math.min(position[1] + height, viewHeight) - height;
  45698. position[0] = Math.max(position[0], 0);
  45699. position[1] = Math.max(position[1], 0);
  45700. }
  45701. /**
  45702. * @param {number} value
  45703. * @param {module:echarts/coord/Axis} axis
  45704. * @param {module:echarts/model/Global} ecModel
  45705. * @param {Object} opt
  45706. * @param {Array.<Object>} seriesDataIndices
  45707. * @param {number|string} opt.precision 'auto' or a number
  45708. * @param {string|Function} opt.formatter label formatter
  45709. */
  45710. helper.getValueLabel = function (value, axis, ecModel, seriesDataIndices, opt) {
  45711. var text = axis.scale.getLabel(
  45712. // If `precision` is set, width can be fixed (like '12.00500'), which
  45713. // helps to debounce when when moving label.
  45714. value, {precision: opt.precision}
  45715. );
  45716. var formatter = opt.formatter;
  45717. if (formatter) {
  45718. var params = {
  45719. value: axisHelper.getAxisRawValue(axis, value),
  45720. seriesData: []
  45721. };
  45722. zrUtil.each(seriesDataIndices, function (idxItem) {
  45723. var series = ecModel.getSeriesByIndex(idxItem.seriesIndex);
  45724. var dataIndex = idxItem.dataIndexInside;
  45725. var dataParams = series && series.getDataParams(dataIndex);
  45726. dataParams && params.seriesData.push(dataParams);
  45727. });
  45728. if (zrUtil.isString(formatter)) {
  45729. text = formatter.replace('{value}', text);
  45730. }
  45731. else if (zrUtil.isFunction(formatter)) {
  45732. text = formatter(params);
  45733. }
  45734. }
  45735. return text;
  45736. };
  45737. /**
  45738. * @param {module:echarts/coord/Axis} axis
  45739. * @param {number} value
  45740. * @param {Object} layoutInfo {
  45741. * rotation, position, labelOffset, labelDirection, labelMargin
  45742. * }
  45743. */
  45744. helper.getTransformedPosition = function (axis, value, layoutInfo) {
  45745. var transform = matrix.create();
  45746. matrix.rotate(transform, transform, layoutInfo.rotation);
  45747. matrix.translate(transform, transform, layoutInfo.position);
  45748. return graphic.applyTransform([
  45749. axis.dataToCoord(value),
  45750. (layoutInfo.labelOffset || 0)
  45751. + (layoutInfo.labelDirection || 1) * (layoutInfo.labelMargin || 0)
  45752. ], transform);
  45753. };
  45754. helper.buildCartesianSingleLabelElOption = function (
  45755. value, elOption, layoutInfo, axisModel, axisPointerModel, api
  45756. ) {
  45757. var textLayout = AxisBuilder.innerTextLayout(
  45758. layoutInfo.rotation, 0, layoutInfo.labelDirection
  45759. );
  45760. layoutInfo.labelMargin = axisPointerModel.get('label.margin');
  45761. helper.buildLabelElOption(elOption, axisModel, axisPointerModel, api, {
  45762. position: helper.getTransformedPosition(axisModel.axis, value, layoutInfo),
  45763. align: textLayout.textAlign,
  45764. verticalAlign: textLayout.textVerticalAlign
  45765. });
  45766. };
  45767. /**
  45768. * @param {Array.<number>} p1
  45769. * @param {Array.<number>} p2
  45770. * @param {number} [xDimIndex=0] or 1
  45771. */
  45772. helper.makeLineShape = function (p1, p2, xDimIndex) {
  45773. xDimIndex = xDimIndex || 0;
  45774. return {
  45775. x1: p1[xDimIndex],
  45776. y1: p1[1 - xDimIndex],
  45777. x2: p2[xDimIndex],
  45778. y2: p2[1 - xDimIndex]
  45779. };
  45780. };
  45781. /**
  45782. * @param {Array.<number>} xy
  45783. * @param {Array.<number>} wh
  45784. * @param {number} [xDimIndex=0] or 1
  45785. */
  45786. helper.makeRectShape = function (xy, wh, xDimIndex) {
  45787. xDimIndex = xDimIndex || 0;
  45788. return {
  45789. x: xy[xDimIndex],
  45790. y: xy[1 - xDimIndex],
  45791. width: wh[xDimIndex],
  45792. height: wh[1 - xDimIndex]
  45793. };
  45794. };
  45795. helper.makeSectorShape = function (cx, cy, r0, r, startAngle, endAngle) {
  45796. return {
  45797. cx: cx,
  45798. cy: cy,
  45799. r0: r0,
  45800. r: r,
  45801. startAngle: startAngle,
  45802. endAngle: endAngle,
  45803. clockwise: true
  45804. };
  45805. };
  45806. module.exports = helper;
  45807. /***/ },
  45808. /* 306 */
  45809. /***/ function(module, exports, __webpack_require__) {
  45810. 'use strict';
  45811. var graphic = __webpack_require__(18);
  45812. var BaseAxisPointer = __webpack_require__(304);
  45813. var viewHelper = __webpack_require__(305);
  45814. var singleAxisHelper = __webpack_require__(295);
  45815. var AxisView = __webpack_require__(136);
  45816. var XY = ['x', 'y'];
  45817. var WH = ['width', 'height'];
  45818. var SingleAxisPointer = BaseAxisPointer.extend({
  45819. /**
  45820. * @override
  45821. */
  45822. makeElOption: function (elOption, value, axisModel, axisPointerModel, api) {
  45823. var axis = axisModel.axis;
  45824. var coordSys = axis.coordinateSystem;
  45825. var otherExtent = getGlobalExtent(coordSys, 1 - getPointDimIndex(axis));
  45826. var pixelValue = coordSys.dataToPoint(value)[0];
  45827. var axisPointerType = axisPointerModel.get('type');
  45828. if (axisPointerType && axisPointerType !== 'none') {
  45829. var elStyle = viewHelper.buildElStyle(axisPointerModel);
  45830. var pointerOption = pointerShapeBuilder[axisPointerType](
  45831. axis, pixelValue, otherExtent, elStyle
  45832. );
  45833. pointerOption.style = elStyle;
  45834. elOption.graphicKey = pointerOption.type;
  45835. elOption.pointer = pointerOption;
  45836. }
  45837. var layoutInfo = singleAxisHelper.layout(axisModel);
  45838. viewHelper.buildCartesianSingleLabelElOption(
  45839. value, elOption, layoutInfo, axisModel, axisPointerModel, api
  45840. );
  45841. },
  45842. /**
  45843. * @override
  45844. */
  45845. getHandleTransform: function (value, axisModel, axisPointerModel) {
  45846. var layoutInfo = singleAxisHelper.layout(axisModel, {labelInside: false});
  45847. layoutInfo.labelMargin = axisPointerModel.get('handle.margin');
  45848. return {
  45849. position: viewHelper.getTransformedPosition(axisModel.axis, value, layoutInfo),
  45850. rotation: layoutInfo.rotation + (layoutInfo.labelDirection < 0 ? Math.PI : 0)
  45851. };
  45852. },
  45853. /**
  45854. * @override
  45855. */
  45856. updateHandleTransform: function (transform, delta, axisModel, axisPointerModel) {
  45857. var axis = axisModel.axis;
  45858. var coordSys = axis.coordinateSystem;
  45859. var dimIndex = getPointDimIndex(axis);
  45860. var axisExtent = getGlobalExtent(coordSys, dimIndex);
  45861. var currPosition = transform.position;
  45862. currPosition[dimIndex] += delta[dimIndex];
  45863. currPosition[dimIndex] = Math.min(axisExtent[1], currPosition[dimIndex]);
  45864. currPosition[dimIndex] = Math.max(axisExtent[0], currPosition[dimIndex]);
  45865. var otherExtent = getGlobalExtent(coordSys, 1 - dimIndex);
  45866. var cursorOtherValue = (otherExtent[1] + otherExtent[0]) / 2;
  45867. var cursorPoint = [cursorOtherValue, cursorOtherValue];
  45868. cursorPoint[dimIndex] = currPosition[dimIndex];
  45869. return {
  45870. position: currPosition,
  45871. rotation: transform.rotation,
  45872. cursorPoint: cursorPoint,
  45873. tooltipOption: {
  45874. verticalAlign: 'middle'
  45875. }
  45876. };
  45877. }
  45878. });
  45879. var pointerShapeBuilder = {
  45880. line: function (axis, pixelValue, otherExtent, elStyle) {
  45881. var targetShape = viewHelper.makeLineShape(
  45882. [pixelValue, otherExtent[0]],
  45883. [pixelValue, otherExtent[1]],
  45884. getPointDimIndex(axis)
  45885. );
  45886. graphic.subPixelOptimizeLine({
  45887. shape: targetShape,
  45888. style: elStyle
  45889. });
  45890. return {
  45891. type: 'Line',
  45892. shape: targetShape
  45893. };
  45894. },
  45895. shadow: function (axis, pixelValue, otherExtent, elStyle) {
  45896. var bandWidth = axis.getBandWidth();
  45897. var span = otherExtent[1] - otherExtent[0];
  45898. return {
  45899. type: 'Rect',
  45900. shape: viewHelper.makeRectShape(
  45901. [pixelValue - bandWidth / 2, otherExtent[0]],
  45902. [bandWidth, span],
  45903. getPointDimIndex(axis)
  45904. )
  45905. };
  45906. }
  45907. };
  45908. function getPointDimIndex(axis) {
  45909. return axis.isHorizontal() ? 0 : 1;
  45910. }
  45911. function getGlobalExtent(coordSys, dimIndex) {
  45912. var rect = coordSys.getRect();
  45913. return [rect[XY[dimIndex]], rect[XY[dimIndex]] + rect[WH[dimIndex]]];
  45914. }
  45915. AxisView.registerAxisPointerClass('SingleAxisPointer', SingleAxisPointer);
  45916. module.exports = SingleAxisPointer;
  45917. /***/ },
  45918. /* 307 */
  45919. /***/ function(module, exports, __webpack_require__) {
  45920. 'use strict';
  45921. /**
  45922. * @file Define the themeRiver view's series model
  45923. * @author Deqing Li(annong035@gmail.com)
  45924. */
  45925. var completeDimensions = __webpack_require__(110);
  45926. var SeriesModel = __webpack_require__(78);
  45927. var List = __webpack_require__(98);
  45928. var zrUtil = __webpack_require__(4);
  45929. var formatUtil = __webpack_require__(6);
  45930. var encodeHTML = formatUtil.encodeHTML;
  45931. var nest = __webpack_require__(254);
  45932. var DATA_NAME_INDEX = 2;
  45933. var ThemeRiverSeries = SeriesModel.extend({
  45934. type: 'series.themeRiver',
  45935. dependencies: ['singleAxis'],
  45936. /**
  45937. * @readOnly
  45938. * @type {module:zrender/core/util#HashMap}
  45939. */
  45940. nameMap: null,
  45941. /**
  45942. * @override
  45943. */
  45944. init: function (option) {
  45945. ThemeRiverSeries.superApply(this, 'init', arguments);
  45946. // Put this function here is for the sake of consistency of code
  45947. // Enable legend selection for each data item
  45948. // Use a function instead of direct access because data reference may changed
  45949. this.legendDataProvider = function () {
  45950. return this.getRawData();
  45951. };
  45952. },
  45953. /**
  45954. * If there is no value of a certain point in the time for some event,set it value to 0.
  45955. *
  45956. * @param {Array} data initial data in the option
  45957. * @return {Array}
  45958. */
  45959. fixData: function (data) {
  45960. var rawDataLength = data.length;
  45961. // grouped data by name
  45962. var dataByName = nest()
  45963. .key(function (dataItem) {
  45964. return dataItem[2];
  45965. })
  45966. .entries(data);
  45967. // data group in each layer
  45968. var layData = zrUtil.map(dataByName, function (d) {
  45969. return {
  45970. name: d.key,
  45971. dataList: d.values
  45972. };
  45973. });
  45974. var layerNum = layData.length;
  45975. var largestLayer = -1;
  45976. var index = -1;
  45977. for (var i = 0; i < layerNum; ++i) {
  45978. var len = layData[i].dataList.length;
  45979. if (len > largestLayer) {
  45980. largestLayer = len;
  45981. index = i;
  45982. }
  45983. }
  45984. for (var k = 0; k < layerNum; ++k) {
  45985. if (k === index) {
  45986. continue;
  45987. }
  45988. var name = layData[k].name;
  45989. for (var j = 0; j < largestLayer; ++j) {
  45990. var timeValue = layData[index].dataList[j][0];
  45991. var length = layData[k].dataList.length;
  45992. var keyIndex = -1;
  45993. for (var l = 0; l < length; ++l) {
  45994. var value = layData[k].dataList[l][0];
  45995. if (value === timeValue) {
  45996. keyIndex = l;
  45997. break;
  45998. }
  45999. }
  46000. if (keyIndex === -1) {
  46001. data[rawDataLength] = [];
  46002. data[rawDataLength][0] = timeValue;
  46003. data[rawDataLength][1] = 0;
  46004. data[rawDataLength][2] = name;
  46005. rawDataLength++;
  46006. }
  46007. }
  46008. }
  46009. return data;
  46010. },
  46011. /**
  46012. * @override
  46013. * @param {Object} option the initial option that user gived
  46014. * @param {module:echarts/model/Model} ecModel the model object for themeRiver option
  46015. * @return {module:echarts/data/List}
  46016. */
  46017. getInitialData: function (option, ecModel) {
  46018. var dimensions = [];
  46019. var singleAxisModel = ecModel.queryComponents({
  46020. mainType: 'singleAxis',
  46021. index: this.get('singleAxisIndex'),
  46022. id: this.get('singleAxisId')
  46023. })[0];
  46024. var axisType = singleAxisModel.get('type');
  46025. dimensions = [
  46026. {
  46027. name: 'time',
  46028. // FIXME common?
  46029. type: axisType === 'category'
  46030. ? 'ordinal'
  46031. : axisType === 'time'
  46032. ? 'time'
  46033. : 'float'
  46034. },
  46035. {
  46036. name: 'value',
  46037. type: 'float'
  46038. },
  46039. {
  46040. name: 'name',
  46041. type: 'ordinal'
  46042. }
  46043. ];
  46044. // filter the data item with the value of label is undefined
  46045. var filterData = zrUtil.filter(option.data, function (dataItem) {
  46046. return dataItem[2] !== undefined;
  46047. });
  46048. var data = this.fixData(filterData || []);
  46049. var nameList = [];
  46050. var nameMap = this.nameMap = zrUtil.createHashMap();
  46051. var count = 0;
  46052. for (var i = 0; i < data.length; ++i) {
  46053. nameList.push(data[i][DATA_NAME_INDEX]);
  46054. if (!nameMap.get(data[i][DATA_NAME_INDEX])) {
  46055. nameMap.set(data[i][DATA_NAME_INDEX], count);
  46056. count++;
  46057. }
  46058. }
  46059. dimensions = completeDimensions(dimensions, data);
  46060. var list = new List(dimensions, this);
  46061. list.initData(data, nameList);
  46062. return list;
  46063. },
  46064. /**
  46065. * Used by single coordinate
  46066. *
  46067. * @param {string} axisDim the dimension for single coordinate
  46068. * @return {Array.<string> } specified dimensions on the axis.
  46069. */
  46070. coordDimToDataDim: function (axisDim) {
  46071. return ['time'];
  46072. },
  46073. /**
  46074. * The raw data is divided into multiple layers and each layer
  46075. * has same name.
  46076. *
  46077. * @return {Array.<Array.<number>>}
  46078. */
  46079. getLayerSeries: function () {
  46080. var data = this.getData();
  46081. var lenCount = data.count();
  46082. var indexArr = [];
  46083. for (var i = 0; i < lenCount; ++i) {
  46084. indexArr[i] = i;
  46085. }
  46086. // data group by name
  46087. var dataByName = nest()
  46088. .key(function (index) {
  46089. return data.get('name', index);
  46090. })
  46091. .entries(indexArr);
  46092. var layerSeries = zrUtil.map(dataByName, function (d) {
  46093. return {
  46094. name: d.key,
  46095. indices: d.values
  46096. };
  46097. });
  46098. for (var j = 0; j < layerSeries.length; ++j) {
  46099. layerSeries[j].indices.sort(comparer);
  46100. }
  46101. function comparer(index1, index2) {
  46102. return data.get('time', index1) - data.get('time', index2);
  46103. }
  46104. return layerSeries;
  46105. },
  46106. /**
  46107. * Get data indices for show tooltip content
  46108. *
  46109. * @param {Array.<string>|string} dim single coordinate dimension
  46110. * @param {number} value axis value
  46111. * @param {module:echarts/coord/single/SingleAxis} baseAxis single Axis used
  46112. * the themeRiver.
  46113. * @return {Object} {dataIndices, nestestValue}
  46114. */
  46115. getAxisTooltipData: function (dim, value, baseAxis) {
  46116. if (!zrUtil.isArray(dim)) {
  46117. dim = dim ? [dim] : [];
  46118. }
  46119. var data = this.getData();
  46120. var layerSeries = this.getLayerSeries();
  46121. var indices = [];
  46122. var layerNum = layerSeries.length;
  46123. var nestestValue;
  46124. for (var i = 0; i < layerNum; ++i) {
  46125. var minDist = Number.MAX_VALUE;
  46126. var nearestIdx = -1;
  46127. var pointNum = layerSeries[i].indices.length;
  46128. for (var j = 0; j < pointNum; ++j) {
  46129. var theValue = data.get(dim[0], layerSeries[i].indices[j]);
  46130. var dist = Math.abs(theValue - value);
  46131. if (dist <= minDist) {
  46132. nestestValue = theValue;
  46133. minDist = dist;
  46134. nearestIdx = layerSeries[i].indices[j];
  46135. }
  46136. }
  46137. indices.push(nearestIdx);
  46138. }
  46139. return {dataIndices: indices, nestestValue: nestestValue};
  46140. },
  46141. /**
  46142. * @override
  46143. * @param {number} dataIndex index of data
  46144. */
  46145. formatTooltip: function (dataIndex) {
  46146. var data = this.getData();
  46147. var htmlName = data.get('name', dataIndex);
  46148. var htmlValue = data.get('value', dataIndex);
  46149. if (isNaN(htmlValue) || htmlValue == null) {
  46150. htmlValue = '-';
  46151. }
  46152. return encodeHTML(htmlName + ' : ' + htmlValue);
  46153. },
  46154. defaultOption: {
  46155. zlevel: 0,
  46156. z: 2,
  46157. coordinateSystem: 'singleAxis',
  46158. // gap in axis's orthogonal orientation
  46159. boundaryGap: ['10%', '10%'],
  46160. // legendHoverLink: true,
  46161. singleAxisIndex: 0,
  46162. animationEasing: 'linear',
  46163. label: {
  46164. normal: {
  46165. margin: 4,
  46166. textAlign: 'right',
  46167. show: true,
  46168. position: 'left',
  46169. textStyle: {
  46170. color: '#000',
  46171. fontSize: 11
  46172. }
  46173. },
  46174. emphasis: {
  46175. show: true
  46176. }
  46177. }
  46178. }
  46179. });
  46180. module.exports = ThemeRiverSeries;
  46181. /***/ },
  46182. /* 308 */
  46183. /***/ function(module, exports, __webpack_require__) {
  46184. /* WEBPACK VAR INJECTION */(function(process) {/**
  46185. * @file The file used to draw themeRiver view
  46186. * @author Deqing Li(annong035@gmail.com)
  46187. */
  46188. var poly = __webpack_require__(120);
  46189. var graphic = __webpack_require__(18);
  46190. var zrUtil = __webpack_require__(4);
  46191. var DataDiffer = __webpack_require__(99);
  46192. module.exports = __webpack_require__(1).extendChartView({
  46193. type: 'themeRiver',
  46194. init: function () {
  46195. this._layers = [];
  46196. },
  46197. render: function (seriesModel, ecModel, api) {
  46198. var data = seriesModel.getData();
  46199. var rawData = seriesModel.getRawData();
  46200. if (!data.count()) {
  46201. return;
  46202. }
  46203. var group = this.group;
  46204. var layerSeries = seriesModel.getLayerSeries();
  46205. var layoutInfo = data.getLayout('layoutInfo');
  46206. var rect = layoutInfo.rect;
  46207. var boundaryGap = layoutInfo.boundaryGap;
  46208. group.attr('position', [0, rect.y + boundaryGap[0]]);
  46209. function keyGetter(item) {
  46210. return item.name;
  46211. }
  46212. var dataDiffer = new DataDiffer(
  46213. this._layersSeries || [], layerSeries,
  46214. keyGetter, keyGetter
  46215. );
  46216. var newLayersGroups = {};
  46217. dataDiffer.add(zrUtil.bind(zrUtil.curry(process, 'add'), this))
  46218. .update(zrUtil.bind(zrUtil.curry(process, 'update'), this))
  46219. .remove(zrUtil.bind(zrUtil.curry(process, 'remove'), this))
  46220. .execute();
  46221. function process(status, idx, oldIdx) {
  46222. var oldLayersGroups = this._layers;
  46223. if (status === 'remove') {
  46224. group.remove(oldLayersGroups[idx]);
  46225. return;
  46226. }
  46227. var points0 = [];
  46228. var points1 = [];
  46229. var color;
  46230. var indices = layerSeries[idx].indices;
  46231. for (var j = 0; j < indices.length; j++) {
  46232. var layout = data.getItemLayout(indices[j]);
  46233. var x = layout.x;
  46234. var y0 = layout.y0;
  46235. var y = layout.y;
  46236. points0.push([x, y0]);
  46237. points1.push([x, y0 + y]);
  46238. color = rawData.getItemVisual(indices[j], 'color');
  46239. }
  46240. var polygon;
  46241. var text;
  46242. var textLayout = data.getItemLayout(indices[0]);
  46243. var itemModel = data.getItemModel(indices[j - 1]);
  46244. var labelModel = itemModel.getModel('label.normal');
  46245. var margin = labelModel.get('margin');
  46246. if (status === 'add') {
  46247. var layerGroup = newLayersGroups[idx] = new graphic.Group();
  46248. polygon = new poly.Polygon({
  46249. shape: {
  46250. points: points0,
  46251. stackedOnPoints: points1,
  46252. smooth: 0.4,
  46253. stackedOnSmooth: 0.4,
  46254. smoothConstraint: false
  46255. },
  46256. z2: 0
  46257. });
  46258. text = new graphic.Text({
  46259. style: {
  46260. x: textLayout.x - margin,
  46261. y: textLayout.y0 + textLayout.y / 2
  46262. }
  46263. });
  46264. layerGroup.add(polygon);
  46265. layerGroup.add(text);
  46266. group.add(layerGroup);
  46267. polygon.setClipPath(createGridClipShape(polygon.getBoundingRect(), seriesModel, function () {
  46268. polygon.removeClipPath();
  46269. }));
  46270. }
  46271. else {
  46272. var layerGroup = oldLayersGroups[oldIdx];
  46273. polygon = layerGroup.childAt(0);
  46274. text = layerGroup.childAt(1);
  46275. group.add(layerGroup);
  46276. newLayersGroups[idx] = layerGroup;
  46277. graphic.updateProps(polygon, {
  46278. shape: {
  46279. points: points0,
  46280. stackedOnPoints: points1
  46281. }
  46282. }, seriesModel);
  46283. graphic.updateProps(text, {
  46284. style: {
  46285. x: textLayout.x - margin,
  46286. y: textLayout.y0 + textLayout.y / 2
  46287. }
  46288. }, seriesModel);
  46289. }
  46290. var hoverItemStyleModel = itemModel.getModel('itemStyle.emphasis');
  46291. var itemStyleModel = itemModel.getModel('itemStyle.normal');
  46292. var textStyleModel = labelModel.getModel('textStyle');
  46293. text.setStyle({
  46294. text: labelModel.get('show')
  46295. ? seriesModel.getFormattedLabel(indices[j - 1], 'normal')
  46296. || data.getName(indices[j - 1])
  46297. : '',
  46298. textFont: textStyleModel.getFont(),
  46299. textAlign: labelModel.get('textAlign'),
  46300. textVerticalAlign: 'middle'
  46301. });
  46302. polygon.setStyle(zrUtil.extend({
  46303. fill: color
  46304. }, itemStyleModel.getItemStyle(['color'])));
  46305. graphic.setHoverStyle(polygon, hoverItemStyleModel.getItemStyle());
  46306. }
  46307. this._layersSeries = layerSeries;
  46308. this._layers = newLayersGroups;
  46309. },
  46310. dispose: function () {}
  46311. });
  46312. // add animation to the view
  46313. function createGridClipShape(rect, seriesModel, cb) {
  46314. var rectEl = new graphic.Rect({
  46315. shape: {
  46316. x: rect.x - 10,
  46317. y: rect.y - 10,
  46318. width: 0,
  46319. height: rect.height + 20
  46320. }
  46321. });
  46322. graphic.initProps(rectEl, {
  46323. shape: {
  46324. width: rect.width + 20,
  46325. height: rect.height + 20
  46326. }
  46327. }, seriesModel, cb);
  46328. return rectEl;
  46329. }
  46330. /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(309)))
  46331. /***/ },
  46332. /* 309 */
  46333. /***/ function(module, exports) {
  46334. // shim for using process in browser
  46335. var process = module.exports = {};
  46336. // cached from whatever global is present so that test runners that stub it
  46337. // don't break things. But we need to wrap it in a try catch in case it is
  46338. // wrapped in strict mode code which doesn't define any globals. It's inside a
  46339. // function because try/catches deoptimize in certain engines.
  46340. var cachedSetTimeout;
  46341. var cachedClearTimeout;
  46342. function defaultSetTimout() {
  46343. throw new Error('setTimeout has not been defined');
  46344. }
  46345. function defaultClearTimeout () {
  46346. throw new Error('clearTimeout has not been defined');
  46347. }
  46348. (function () {
  46349. try {
  46350. if (typeof setTimeout === 'function') {
  46351. cachedSetTimeout = setTimeout;
  46352. } else {
  46353. cachedSetTimeout = defaultSetTimout;
  46354. }
  46355. } catch (e) {
  46356. cachedSetTimeout = defaultSetTimout;
  46357. }
  46358. try {
  46359. if (typeof clearTimeout === 'function') {
  46360. cachedClearTimeout = clearTimeout;
  46361. } else {
  46362. cachedClearTimeout = defaultClearTimeout;
  46363. }
  46364. } catch (e) {
  46365. cachedClearTimeout = defaultClearTimeout;
  46366. }
  46367. } ())
  46368. function runTimeout(fun) {
  46369. if (cachedSetTimeout === setTimeout) {
  46370. //normal enviroments in sane situations
  46371. return setTimeout(fun, 0);
  46372. }
  46373. // if setTimeout wasn't available but was latter defined
  46374. if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
  46375. cachedSetTimeout = setTimeout;
  46376. return setTimeout(fun, 0);
  46377. }
  46378. try {
  46379. // when when somebody has screwed with setTimeout but no I.E. maddness
  46380. return cachedSetTimeout(fun, 0);
  46381. } catch(e){
  46382. try {
  46383. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  46384. return cachedSetTimeout.call(null, fun, 0);
  46385. } catch(e){
  46386. // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
  46387. return cachedSetTimeout.call(this, fun, 0);
  46388. }
  46389. }
  46390. }
  46391. function runClearTimeout(marker) {
  46392. if (cachedClearTimeout === clearTimeout) {
  46393. //normal enviroments in sane situations
  46394. return clearTimeout(marker);
  46395. }
  46396. // if clearTimeout wasn't available but was latter defined
  46397. if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
  46398. cachedClearTimeout = clearTimeout;
  46399. return clearTimeout(marker);
  46400. }
  46401. try {
  46402. // when when somebody has screwed with setTimeout but no I.E. maddness
  46403. return cachedClearTimeout(marker);
  46404. } catch (e){
  46405. try {
  46406. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  46407. return cachedClearTimeout.call(null, marker);
  46408. } catch (e){
  46409. // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
  46410. // Some versions of I.E. have different rules for clearTimeout vs setTimeout
  46411. return cachedClearTimeout.call(this, marker);
  46412. }
  46413. }
  46414. }
  46415. var queue = [];
  46416. var draining = false;
  46417. var currentQueue;
  46418. var queueIndex = -1;
  46419. function cleanUpNextTick() {
  46420. if (!draining || !currentQueue) {
  46421. return;
  46422. }
  46423. draining = false;
  46424. if (currentQueue.length) {
  46425. queue = currentQueue.concat(queue);
  46426. } else {
  46427. queueIndex = -1;
  46428. }
  46429. if (queue.length) {
  46430. drainQueue();
  46431. }
  46432. }
  46433. function drainQueue() {
  46434. if (draining) {
  46435. return;
  46436. }
  46437. var timeout = runTimeout(cleanUpNextTick);
  46438. draining = true;
  46439. var len = queue.length;
  46440. while(len) {
  46441. currentQueue = queue;
  46442. queue = [];
  46443. while (++queueIndex < len) {
  46444. if (currentQueue) {
  46445. currentQueue[queueIndex].run();
  46446. }
  46447. }
  46448. queueIndex = -1;
  46449. len = queue.length;
  46450. }
  46451. currentQueue = null;
  46452. draining = false;
  46453. runClearTimeout(timeout);
  46454. }
  46455. process.nextTick = function (fun) {
  46456. var args = new Array(arguments.length - 1);
  46457. if (arguments.length > 1) {
  46458. for (var i = 1; i < arguments.length; i++) {
  46459. args[i - 1] = arguments[i];
  46460. }
  46461. }
  46462. queue.push(new Item(fun, args));
  46463. if (queue.length === 1 && !draining) {
  46464. runTimeout(drainQueue);
  46465. }
  46466. };
  46467. // v8 likes predictible objects
  46468. function Item(fun, array) {
  46469. this.fun = fun;
  46470. this.array = array;
  46471. }
  46472. Item.prototype.run = function () {
  46473. this.fun.apply(null, this.array);
  46474. };
  46475. process.title = 'browser';
  46476. process.browser = true;
  46477. process.env = {};
  46478. process.argv = [];
  46479. process.version = ''; // empty string to avoid regexp issues
  46480. process.versions = {};
  46481. function noop() {}
  46482. process.on = noop;
  46483. process.addListener = noop;
  46484. process.once = noop;
  46485. process.off = noop;
  46486. process.removeListener = noop;
  46487. process.removeAllListeners = noop;
  46488. process.emit = noop;
  46489. process.binding = function (name) {
  46490. throw new Error('process.binding is not supported');
  46491. };
  46492. process.cwd = function () { return '/' };
  46493. process.chdir = function (dir) {
  46494. throw new Error('process.chdir is not supported');
  46495. };
  46496. process.umask = function() { return 0; };
  46497. /***/ },
  46498. /* 310 */
  46499. /***/ function(module, exports, __webpack_require__) {
  46500. /**
  46501. * @file Using layout algorithm transform the raw data to layout information.
  46502. * @author Deqing Li(annong035@gmail.com)
  46503. */
  46504. var zrUtil = __webpack_require__(4);
  46505. var numberUtil = __webpack_require__(7);
  46506. module.exports = function (ecModel, api) {
  46507. ecModel.eachSeriesByType('themeRiver', function (seriesModel) {
  46508. var data = seriesModel.getData();
  46509. var single = seriesModel.coordinateSystem;
  46510. var layoutInfo = {};
  46511. // use the axis boundingRect for view
  46512. var rect = single.getRect();
  46513. layoutInfo.rect = rect;
  46514. var boundaryGap = seriesModel.get('boundaryGap');
  46515. var axis = single.getAxis();
  46516. layoutInfo.boundaryGap = boundaryGap;
  46517. if (axis.orient === 'horizontal') {
  46518. boundaryGap[0] = numberUtil.parsePercent(boundaryGap[0], rect.height);
  46519. boundaryGap[1] = numberUtil.parsePercent(boundaryGap[1], rect.height);
  46520. var height = rect.height - boundaryGap[0] - boundaryGap[1];
  46521. themeRiverLayout(data, seriesModel, height);
  46522. }
  46523. else {
  46524. boundaryGap[0] = numberUtil.parsePercent(boundaryGap[0], rect.width);
  46525. boundaryGap[1] = numberUtil.parsePercent(boundaryGap[1], rect.width);
  46526. var width = rect.width - boundaryGap[0] - boundaryGap[1];
  46527. themeRiverLayout(data, seriesModel, width);
  46528. }
  46529. data.setLayout('layoutInfo', layoutInfo);
  46530. });
  46531. };
  46532. /**
  46533. * The layout information about themeriver
  46534. *
  46535. * @param {module:echarts/data/List} data data in the series
  46536. * @param {module:echarts/model/Series} seriesModel the model object of themeRiver series
  46537. * @param {number} height value used to compute every series height
  46538. */
  46539. function themeRiverLayout(data, seriesModel, height) {
  46540. if (!data.count()) {
  46541. return;
  46542. }
  46543. var coordSys = seriesModel.coordinateSystem;
  46544. // the data in each layer are organized into a series.
  46545. var layerSeries = seriesModel.getLayerSeries();
  46546. // the points in each layer.
  46547. var layerPoints = zrUtil.map(layerSeries, function (singleLayer) {
  46548. return zrUtil.map(singleLayer.indices, function (idx) {
  46549. var pt = coordSys.dataToPoint(data.get('time', idx));
  46550. pt[1] = data.get('value', idx);
  46551. return pt;
  46552. });
  46553. });
  46554. var base = computeBaseline(layerPoints);
  46555. var baseLine = base.y0;
  46556. var ky = height / base.max;
  46557. // set layout information for each item.
  46558. var n = layerSeries.length;
  46559. var m = layerSeries[0].indices.length;
  46560. var baseY0;
  46561. for (var j = 0; j < m; ++j) {
  46562. baseY0 = baseLine[j] * ky;
  46563. data.setItemLayout(layerSeries[0].indices[j], {
  46564. layerIndex: 0,
  46565. x: layerPoints[0][j][0],
  46566. y0: baseY0,
  46567. y: layerPoints[0][j][1] * ky
  46568. });
  46569. for (var i = 1; i < n; ++i) {
  46570. baseY0 += layerPoints[i - 1][j][1] * ky;
  46571. data.setItemLayout(layerSeries[i].indices[j], {
  46572. layerIndex: i,
  46573. x: layerPoints[i][j][0],
  46574. y0: baseY0,
  46575. y: layerPoints[i][j][1] * ky
  46576. });
  46577. }
  46578. }
  46579. }
  46580. /**
  46581. * Compute the baseLine of the rawdata
  46582. * Inspired by Lee Byron's paper Stacked Graphs - Geometry & Aesthetics
  46583. *
  46584. * @param {Array.<Array>} data the points in each layer
  46585. * @return {Array}
  46586. */
  46587. function computeBaseline(data) {
  46588. var layerNum = data.length;
  46589. var pointNum = data[0].length;
  46590. var sums = [];
  46591. var y0 = [];
  46592. var max = 0;
  46593. var temp;
  46594. var base = {};
  46595. for (var i = 0; i < pointNum; ++i) {
  46596. for (var j = 0, temp = 0; j < layerNum; ++j) {
  46597. temp += data[j][i][1];
  46598. }
  46599. if (temp > max) {
  46600. max = temp;
  46601. }
  46602. sums.push(temp);
  46603. }
  46604. for (var k = 0; k < pointNum; ++k) {
  46605. y0[k] = (max - sums[k]) / 2;
  46606. }
  46607. max = 0;
  46608. for (var l = 0; l < pointNum; ++l) {
  46609. var sum = sums[l] + y0[l];
  46610. if (sum > max) {
  46611. max = sum;
  46612. }
  46613. }
  46614. base.y0 = y0;
  46615. base.max = max;
  46616. return base;
  46617. }
  46618. /***/ },
  46619. /* 311 */
  46620. /***/ function(module, exports) {
  46621. /**
  46622. * @file Visual encoding for themeRiver view
  46623. * @author Deqing Li(annong035@gmail.com)
  46624. */
  46625. module.exports = function (ecModel) {
  46626. ecModel.eachSeriesByType('themeRiver', function (seriesModel) {
  46627. var data = seriesModel.getData();
  46628. var rawData = seriesModel.getRawData();
  46629. var colorList = seriesModel.get('color');
  46630. data.each(function (index) {
  46631. var name = data.getName(index);
  46632. var color = colorList[(seriesModel.nameMap.get(name) - 1) % colorList.length];
  46633. rawData.setItemVisual(index, 'color', color);
  46634. });
  46635. });
  46636. };
  46637. /***/ },
  46638. /* 312 */
  46639. /***/ function(module, exports, __webpack_require__) {
  46640. var echarts = __webpack_require__(1);
  46641. var zrUtil = __webpack_require__(4);
  46642. var graphicUtil = __webpack_require__(18);
  46643. var labelHelper = __webpack_require__(118);
  46644. var createListFromArray = __webpack_require__(109);
  46645. var barGrid = __webpack_require__(145);
  46646. var ITEM_STYLE_NORMAL_PATH = ['itemStyle', 'normal'];
  46647. var ITEM_STYLE_EMPHASIS_PATH = ['itemStyle', 'emphasis'];
  46648. var LABEL_NORMAL = ['label', 'normal'];
  46649. var LABEL_EMPHASIS = ['label', 'emphasis'];
  46650. /**
  46651. * To reduce total package size of each coordinate systems, the modules `prepareCustom`
  46652. * of each coordinate systems are not required by each coordinate systems directly, but
  46653. * required by the module `custom`.
  46654. *
  46655. * prepareInfoForCustomSeries {Function}: optional
  46656. * @return {Object} {coordSys: {...}, api: {
  46657. * coord: function (data, clamp) {}, // return point in global.
  46658. * size: function (dataSize, dataItem) {} // return size of each axis in coordSys.
  46659. * }}
  46660. */
  46661. var prepareCustoms = {
  46662. cartesian2d: __webpack_require__(313),
  46663. geo: __webpack_require__(314),
  46664. singleAxis: __webpack_require__(315),
  46665. polar: __webpack_require__(316),
  46666. calendar: __webpack_require__(317)
  46667. };
  46668. // ------
  46669. // Model
  46670. // ------
  46671. echarts.extendSeriesModel({
  46672. type: 'series.custom',
  46673. dependencies: ['grid', 'polar', 'geo', 'singleAxis', 'calendar'],
  46674. defaultOption: {
  46675. coordinateSystem: 'cartesian2d',
  46676. zlevel: 0,
  46677. z: 2,
  46678. legendHoverLink: true
  46679. // Cartesian coordinate system
  46680. // xAxisIndex: 0,
  46681. // yAxisIndex: 0,
  46682. // Polar coordinate system
  46683. // polarIndex: 0,
  46684. // Geo coordinate system
  46685. // geoIndex: 0,
  46686. // label: {}
  46687. // itemStyle: {}
  46688. },
  46689. getInitialData: function (option, ecModel) {
  46690. return createListFromArray(option.data, this, ecModel);
  46691. }
  46692. });
  46693. // -----
  46694. // View
  46695. // -----
  46696. echarts.extendChartView({
  46697. type: 'custom',
  46698. /**
  46699. * @private
  46700. * @type {module:echarts/data/List}
  46701. */
  46702. _data: null,
  46703. /**
  46704. * @override
  46705. */
  46706. render: function (customSeries, ecModel, api) {
  46707. var oldData = this._data;
  46708. var data = customSeries.getData();
  46709. var group = this.group;
  46710. var renderItem = makeRenderItem(customSeries, data, ecModel, api);
  46711. data.diff(oldData)
  46712. .add(function (newIdx) {
  46713. data.hasValue(newIdx) && createOrUpdate(
  46714. null, newIdx, renderItem(newIdx), customSeries, group, data
  46715. );
  46716. })
  46717. .update(function (newIdx, oldIdx) {
  46718. var el = oldData.getItemGraphicEl(oldIdx);
  46719. data.hasValue(newIdx)
  46720. ? createOrUpdate(
  46721. el, newIdx, renderItem(newIdx), customSeries, group, data
  46722. )
  46723. : (el && group.remove(el));
  46724. })
  46725. .remove(function (oldIdx) {
  46726. var el = oldData.getItemGraphicEl(oldIdx);
  46727. el && group.remove(el);
  46728. })
  46729. .execute();
  46730. this._data = data;
  46731. }
  46732. });
  46733. function createEl(elOption) {
  46734. var graphicType = elOption.type;
  46735. var el;
  46736. if (graphicType === 'path') {
  46737. var shape = elOption.shape;
  46738. el = graphicUtil.makePath(
  46739. shape.pathData,
  46740. null,
  46741. {
  46742. x: shape.x || 0,
  46743. y: shape.y || 0,
  46744. width: shape.width || 0,
  46745. height: shape.height || 0
  46746. },
  46747. 'center'
  46748. );
  46749. el.__customPathData = elOption.pathData;
  46750. }
  46751. else if (graphicType === 'image') {
  46752. el = new graphicUtil.Image({
  46753. });
  46754. el.__customImagePath = elOption.style.image;
  46755. }
  46756. else if (graphicType === 'text') {
  46757. el = new graphicUtil.Text({
  46758. });
  46759. el.__customText = elOption.style.text;
  46760. }
  46761. else {
  46762. var Clz = graphicUtil[graphicType.charAt(0).toUpperCase() + graphicType.slice(1)];
  46763. if (true) {
  46764. zrUtil.assert(Clz, 'graphic type "' + graphicType + '" can not be found.');
  46765. }
  46766. el = new Clz();
  46767. }
  46768. el.__customGraphicType = graphicType;
  46769. return el;
  46770. }
  46771. function updateEl(el, dataIndex, elOption, animatableModel, data, isInit) {
  46772. var targetProps = {};
  46773. var elOptionStyle = elOption.style || {};
  46774. elOption.shape && (targetProps.shape = zrUtil.clone(elOption.shape));
  46775. elOption.position && (targetProps.position = elOption.position.slice());
  46776. elOption.scale && (targetProps.scale = elOption.scale.slice());
  46777. elOption.origin && (targetProps.origin = elOption.origin.slice());
  46778. elOption.rotation && (targetProps.rotation = elOption.rotation);
  46779. if (el.type === 'image' && elOption.style) {
  46780. var targetStyle = targetProps.style = {};
  46781. zrUtil.each(['x', 'y', 'width', 'height'], function (prop) {
  46782. prepareStyleTransition(prop, targetStyle, elOptionStyle, el.style, isInit);
  46783. });
  46784. }
  46785. if (el.type === 'text' && elOption.style) {
  46786. var targetStyle = targetProps.style = {};
  46787. zrUtil.each(['x', 'y'], function (prop) {
  46788. prepareStyleTransition(prop, targetStyle, elOptionStyle, el.style, isInit);
  46789. });
  46790. }
  46791. if (el.type !== 'group') {
  46792. el.useStyle(elOptionStyle);
  46793. // Init animation.
  46794. if (isInit) {
  46795. el.style.opacity = 0;
  46796. var targetOpacity = elOptionStyle.opacity;
  46797. targetOpacity == null && (targetOpacity = 1);
  46798. graphicUtil.initProps(el, {style: {opacity: targetOpacity}}, animatableModel, dataIndex);
  46799. }
  46800. }
  46801. if (isInit) {
  46802. el.attr(targetProps);
  46803. }
  46804. else {
  46805. graphicUtil.updateProps(el, targetProps, animatableModel, dataIndex);
  46806. }
  46807. // z2 must not be null/undefined, otherwise sort error may occur.
  46808. el.attr({z2: elOption.z2 || 0, silent: elOption.silent});
  46809. el.styleEmphasis !== false && graphicUtil.setHoverStyle(el, el.styleEmphasis);
  46810. }
  46811. function prepareStyleTransition(prop, targetStyle, elOptionStyle, oldElStyle, isInit) {
  46812. if (elOptionStyle[prop] != null && !isInit) {
  46813. targetStyle[prop] = elOptionStyle[prop];
  46814. elOptionStyle[prop] = oldElStyle[prop];
  46815. }
  46816. }
  46817. function makeRenderItem(customSeries, data, ecModel, api) {
  46818. var renderItem = customSeries.get('renderItem');
  46819. var coordSys = customSeries.coordinateSystem;
  46820. if (true) {
  46821. zrUtil.assert(renderItem, 'series.render is required.');
  46822. zrUtil.assert(prepareCustoms[coordSys.type], 'This coordSys does not support custom series.');
  46823. }
  46824. var prepareResult = prepareCustoms[coordSys.type](coordSys);
  46825. var userAPI = zrUtil.defaults({
  46826. getWidth: api.getWidth,
  46827. getHeight: api.getHeight,
  46828. getZr: api.getZr,
  46829. getDevicePixelRatio: api.getDevicePixelRatio,
  46830. value: value,
  46831. style: style,
  46832. styleEmphasis: styleEmphasis,
  46833. visual: visual,
  46834. barLayout: barLayout,
  46835. currentSeriesIndices: currentSeriesIndices,
  46836. font: font
  46837. }, prepareResult.api);
  46838. var userParams = {
  46839. context: {},
  46840. seriesId: customSeries.id,
  46841. seriesName: customSeries.name,
  46842. seriesIndex: customSeries.seriesIndex,
  46843. coordSys: prepareResult.coordSys,
  46844. dataInsideLength: data.count(),
  46845. encode: wrapEncodeDef(customSeries.getData())
  46846. };
  46847. // Do not support call `api` asynchronously without dataIndexInside input.
  46848. var currDataIndexInside;
  46849. var currDirty = true;
  46850. var currItemModel;
  46851. var currLabelNormalModel;
  46852. var currLabelEmphasisModel;
  46853. var currLabelValueDim;
  46854. var currVisualColor;
  46855. return function (dataIndexInside) {
  46856. currDataIndexInside = dataIndexInside;
  46857. currDirty = true;
  46858. return renderItem && renderItem(
  46859. zrUtil.defaults({
  46860. dataIndexInside: dataIndexInside,
  46861. dataIndex: data.getRawIndex(dataIndexInside)
  46862. }, userParams),
  46863. userAPI
  46864. ) || {};
  46865. };
  46866. // Do not update cache until api called.
  46867. function updateCache(dataIndexInside) {
  46868. dataIndexInside == null && (dataIndexInside = currDataIndexInside);
  46869. if (currDirty) {
  46870. currItemModel = data.getItemModel(dataIndexInside);
  46871. currLabelNormalModel = currItemModel.getModel(LABEL_NORMAL);
  46872. currLabelEmphasisModel = currItemModel.getModel(LABEL_EMPHASIS);
  46873. currLabelValueDim = labelHelper.findLabelValueDim(data);
  46874. currVisualColor = data.getItemVisual(dataIndexInside, 'color');
  46875. currDirty = false;
  46876. }
  46877. }
  46878. /**
  46879. * @public
  46880. * @param {nubmer|string} dim
  46881. * @param {number} [dataIndexInside=currDataIndexInside]
  46882. * @return {number|string} value
  46883. */
  46884. function value(dim, dataIndexInside) {
  46885. dataIndexInside == null && (dataIndexInside = currDataIndexInside);
  46886. return data.get(data.getDimension(dim || 0), dataIndexInside);
  46887. }
  46888. /**
  46889. * By default, `visual` is applied to style (to support visualMap).
  46890. * `visual.color` is applied at `fill`. If user want apply visual.color on `stroke`,
  46891. * it can be implemented as:
  46892. * `api.style({stroke: api.visual('color'), fill: null})`;
  46893. * @public
  46894. * @param {Object} [extra]
  46895. * @param {number} [dataIndexInside=currDataIndexInside]
  46896. */
  46897. function style(extra, dataIndexInside) {
  46898. dataIndexInside == null && (dataIndexInside = currDataIndexInside);
  46899. updateCache(dataIndexInside);
  46900. var itemStyle = currItemModel.getModel(ITEM_STYLE_NORMAL_PATH).getItemStyle();
  46901. currVisualColor != null && (itemStyle.fill = currVisualColor);
  46902. var opacity = data.getItemVisual(dataIndexInside, 'opacity');
  46903. opacity != null && (itemStyle.opacity = opacity);
  46904. labelHelper.setTextToStyle(
  46905. data, dataIndexInside, currLabelValueDim, itemStyle,
  46906. customSeries, currLabelNormalModel, currVisualColor
  46907. );
  46908. extra && zrUtil.extend(itemStyle, extra);
  46909. return itemStyle;
  46910. }
  46911. /**
  46912. * @public
  46913. * @param {Object} [extra]
  46914. * @param {number} [dataIndexInside=currDataIndexInside]
  46915. */
  46916. function styleEmphasis(extra, dataIndexInside) {
  46917. dataIndexInside == null && (dataIndexInside = currDataIndexInside);
  46918. updateCache(dataIndexInside);
  46919. var itemStyle = currItemModel.getModel(ITEM_STYLE_EMPHASIS_PATH).getItemStyle();
  46920. labelHelper.setTextToStyle(
  46921. data, dataIndexInside, currLabelValueDim, itemStyle,
  46922. customSeries, currLabelEmphasisModel, currVisualColor
  46923. );
  46924. extra && zrUtil.extend(itemStyle, extra);
  46925. return itemStyle;
  46926. }
  46927. /**
  46928. * @public
  46929. * @param {string} visualType
  46930. * @param {number} [dataIndexInside=currDataIndexInside]
  46931. */
  46932. function visual(visualType, dataIndexInside) {
  46933. dataIndexInside == null && (dataIndexInside = currDataIndexInside);
  46934. return data.getItemVisual(dataIndexInside, visualType);
  46935. }
  46936. /**
  46937. * @public
  46938. * @param {number} opt.count Positive interger.
  46939. * @param {number} [opt.barWidth]
  46940. * @param {number} [opt.barMaxWidth]
  46941. * @param {number} [opt.barGap]
  46942. * @param {number} [opt.barCategoryGap]
  46943. * @return {Object} {width, offset, offsetCenter} is not support, return undefined.
  46944. */
  46945. function barLayout(opt) {
  46946. if (coordSys.getBaseAxis) {
  46947. var baseAxis = coordSys.getBaseAxis();
  46948. return barGrid.getLayoutOnAxis(zrUtil.defaults({axis: baseAxis}, opt), api);
  46949. }
  46950. }
  46951. /**
  46952. * @public
  46953. * @return {Array.<number>}
  46954. */
  46955. function currentSeriesIndices() {
  46956. return ecModel.getCurrentSeriesIndices();
  46957. }
  46958. /**
  46959. * @public
  46960. * @param {Object} opt
  46961. * @param {string} [opt.fontStyle]
  46962. * @param {number} [opt.fontWeight]
  46963. * @param {number} [opt.fontSize]
  46964. * @param {string} [opt.fontFamily]
  46965. * @return {string} font string
  46966. */
  46967. function font(opt) {
  46968. return graphicUtil.getFont(opt, ecModel);
  46969. }
  46970. }
  46971. function wrapEncodeDef(data) {
  46972. var encodeDef = {};
  46973. zrUtil.each(data.dimensions, function (dimName, dataDimIndex) {
  46974. var dimInfo = data.getDimensionInfo(dimName);
  46975. if (!dimInfo.isExtraCoord) {
  46976. var coordDim = dimInfo.coordDim;
  46977. var dataDims = encodeDef[coordDim] = encodeDef[coordDim] || [];
  46978. dataDims[dimInfo.coordDimIndex] = dataDimIndex;
  46979. }
  46980. });
  46981. return encodeDef;
  46982. }
  46983. function createOrUpdate(el, dataIndex, elOption, animatableModel, group, data) {
  46984. el = doCreateOrUpdate(el, dataIndex, elOption, animatableModel, group, data);
  46985. el && data.setItemGraphicEl(dataIndex, el);
  46986. }
  46987. function doCreateOrUpdate(el, dataIndex, elOption, animatableModel, group, data) {
  46988. var elOptionType = elOption.type;
  46989. if (el
  46990. && elOptionType !== el.__customGraphicType
  46991. && (elOptionType !== 'path' || elOption.pathData !== el.__customPathData)
  46992. && (elOptionType !== 'image' || elOption.style.image !== el.__customImagePath)
  46993. && (elOptionType !== 'text' || elOption.style.text !== el.__customText)
  46994. ) {
  46995. group.remove(el);
  46996. el = null;
  46997. }
  46998. // `elOption.type` is undefined when `renderItem` returns nothing.
  46999. if (elOptionType == null) {
  47000. return;
  47001. }
  47002. var isInit = !el;
  47003. !el && (el = createEl(elOption));
  47004. updateEl(el, dataIndex, elOption, animatableModel, data, isInit);
  47005. elOptionType === 'group' && zrUtil.each(elOption.children, function (childOption, index) {
  47006. doCreateOrUpdate(el.childAt(index), dataIndex, childOption, animatableModel, el, data);
  47007. });
  47008. group.add(el);
  47009. return el;
  47010. }
  47011. /***/ },
  47012. /* 313 */
  47013. /***/ function(module, exports, __webpack_require__) {
  47014. var zrUtil = __webpack_require__(4);
  47015. function dataToCoordSize(dataSize, dataItem) {
  47016. // dataItem is necessary in log axis.
  47017. dataItem = dataItem || [0, 0];
  47018. return zrUtil.map(['x', 'y'], function (dim, dimIdx) {
  47019. var axis = this.getAxis(dim);
  47020. var val = dataItem[dimIdx];
  47021. var halfSize = dataSize[dimIdx] / 2;
  47022. return axis.type === 'category'
  47023. ? axis.getBandWidth()
  47024. : Math.abs(axis.dataToCoord(val - halfSize) - axis.dataToCoord(val + halfSize));
  47025. }, this);
  47026. }
  47027. function prepareCustom(coordSys) {
  47028. var rect = coordSys.grid.getRect();
  47029. return {
  47030. coordSys: {
  47031. // The name exposed to user is always 'cartesian2d' but not 'grid'.
  47032. type: 'cartesian2d',
  47033. x: rect.x,
  47034. y: rect.y,
  47035. width: rect.width,
  47036. height: rect.height
  47037. },
  47038. api: {
  47039. coord: zrUtil.bind(coordSys.dataToPoint, coordSys),
  47040. size: zrUtil.bind(dataToCoordSize, coordSys)
  47041. }
  47042. };
  47043. }
  47044. module.exports = prepareCustom;
  47045. /***/ },
  47046. /* 314 */
  47047. /***/ function(module, exports, __webpack_require__) {
  47048. var zrUtil = __webpack_require__(4);
  47049. function dataToCoordSize(dataSize, dataItem) {
  47050. dataItem = dataItem || [0, 0];
  47051. return zrUtil.map([0, 1], function (dimIdx) {
  47052. var val = dataItem[dimIdx];
  47053. var halfSize = dataSize[dimIdx] / 2;
  47054. var p1 = [];
  47055. var p2 = [];
  47056. p1[dimIdx] = val - halfSize;
  47057. p2[dimIdx] = val + halfSize;
  47058. p1[1 - dimIdx] = p2[1 - dimIdx] = dataItem[1 - dimIdx];
  47059. return Math.abs(this.dataToPoint(p1)[dimIdx] - this.dataToPoint(p2)[dimIdx]);
  47060. }, this);
  47061. }
  47062. function prepareCustom(coordSys) {
  47063. var rect = coordSys.getBoundingRect();
  47064. return {
  47065. coordSys: {
  47066. type: 'geo',
  47067. x: rect.x,
  47068. y: rect.y,
  47069. width: rect.width,
  47070. height: rect.height
  47071. },
  47072. api: {
  47073. coord: zrUtil.bind(coordSys.dataToPoint, coordSys),
  47074. size: zrUtil.bind(dataToCoordSize, coordSys)
  47075. }
  47076. };
  47077. }
  47078. module.exports = prepareCustom;
  47079. /***/ },
  47080. /* 315 */
  47081. /***/ function(module, exports, __webpack_require__) {
  47082. var zrUtil = __webpack_require__(4);
  47083. function dataToCoordSize(dataSize, dataItem) {
  47084. // dataItem is necessary in log axis.
  47085. var axis = this.getAxis();
  47086. var val = dataItem instanceof Array ? dataItem[0] : dataItem;
  47087. var halfSize = (dataSize instanceof Array ? dataSize[0] : dataSize) / 2;
  47088. return axis.type === 'category'
  47089. ? axis.getBandWidth()
  47090. : Math.abs(axis.dataToCoord(val - halfSize) - axis.dataToCoord(val + halfSize));
  47091. }
  47092. function prepareCustom(coordSys) {
  47093. var rect = coordSys.getRect();
  47094. return {
  47095. coordSys: {
  47096. type: 'singleAxis',
  47097. x: rect.x,
  47098. y: rect.y,
  47099. width: rect.width,
  47100. height: rect.height
  47101. },
  47102. api: {
  47103. coord: zrUtil.bind(coordSys.dataToPoint, coordSys),
  47104. size: zrUtil.bind(dataToCoordSize, coordSys)
  47105. }
  47106. };
  47107. }
  47108. module.exports = prepareCustom;
  47109. /***/ },
  47110. /* 316 */
  47111. /***/ function(module, exports, __webpack_require__) {
  47112. var zrUtil = __webpack_require__(4);
  47113. function dataToCoordSize(dataSize, dataItem) {
  47114. // dataItem is necessary in log axis.
  47115. return zrUtil.map(['Radius', 'Angle'], function (dim, dimIdx) {
  47116. var axis = this['get' + dim + 'Axis']();
  47117. var val = dataItem[dimIdx];
  47118. var halfSize = dataSize[dimIdx] / 2;
  47119. var method = 'dataTo' + dim;
  47120. var result = axis.type === 'category'
  47121. ? axis.getBandWidth()
  47122. : Math.abs(axis[method](val - halfSize) - axis[method](val + halfSize));
  47123. if (dim === 'Angle') {
  47124. result = result * Math.PI / 180;
  47125. }
  47126. return result;
  47127. }, this);
  47128. }
  47129. function prepareCustom(coordSys) {
  47130. var radiusAxis = coordSys.getRadiusAxis();
  47131. var angleAxis = coordSys.getAngleAxis();
  47132. var radius = radiusAxis.getExtent();
  47133. radius[0] > radius[1] && radius.reverse();
  47134. return {
  47135. coordSys: {
  47136. type: 'polar',
  47137. cx: coordSys.cx,
  47138. cy: coordSys.cy,
  47139. r: radius[1],
  47140. r0: radius[0]
  47141. },
  47142. api: {
  47143. coord: zrUtil.bind(function (data) {
  47144. var radius = radiusAxis.dataToRadius(data[0]);
  47145. var angle = angleAxis.dataToAngle(data[1]);
  47146. var coord = coordSys.coordToPoint([radius, angle]);
  47147. coord.push(radius, angle * Math.PI / 180);
  47148. return coord;
  47149. }),
  47150. size: zrUtil.bind(dataToCoordSize, coordSys)
  47151. }
  47152. };
  47153. }
  47154. module.exports = prepareCustom;
  47155. /***/ },
  47156. /* 317 */
  47157. /***/ function(module, exports, __webpack_require__) {
  47158. var zrUtil = __webpack_require__(4);
  47159. function prepareCustom(coordSys) {
  47160. var rect = coordSys.getRect();
  47161. var rangeInfo = coordSys.getRangeInfo();
  47162. return {
  47163. coordSys: {
  47164. type: 'calendar',
  47165. x: rect.x,
  47166. y: rect.y,
  47167. width: rect.width,
  47168. height: rect.height,
  47169. cellWidth: coordSys.getCellWidth(),
  47170. cellHeight: coordSys.getCellHeight(),
  47171. rangeInfo: {
  47172. start: rangeInfo.start,
  47173. end: rangeInfo.end,
  47174. weeks: rangeInfo.weeks,
  47175. dayCount: rangeInfo.allDay
  47176. }
  47177. },
  47178. api: {
  47179. coord: zrUtil.bind(coordSys.dataToPoint, coordSys)
  47180. }
  47181. };
  47182. }
  47183. module.exports = prepareCustom;
  47184. /***/ },
  47185. /* 318 */
  47186. /***/ function(module, exports, __webpack_require__) {
  47187. var echarts = __webpack_require__(1);
  47188. var zrUtil = __webpack_require__(4);
  47189. var modelUtil = __webpack_require__(5);
  47190. var graphicUtil = __webpack_require__(18);
  47191. var layoutUtil = __webpack_require__(71);
  47192. // -------------
  47193. // Preprocessor
  47194. // -------------
  47195. echarts.registerPreprocessor(function (option) {
  47196. var graphicOption = option.graphic;
  47197. // Convert
  47198. // {graphic: [{left: 10, type: 'circle'}, ...]}
  47199. // or
  47200. // {graphic: {left: 10, type: 'circle'}}
  47201. // to
  47202. // {graphic: [{elements: [{left: 10, type: 'circle'}, ...]}]}
  47203. if (zrUtil.isArray(graphicOption)) {
  47204. if (!graphicOption[0] || !graphicOption[0].elements) {
  47205. option.graphic = [{elements: graphicOption}];
  47206. }
  47207. else {
  47208. // Only one graphic instance can be instantiated. (We dont
  47209. // want that too many views are created in echarts._viewMap)
  47210. option.graphic = [option.graphic[0]];
  47211. }
  47212. }
  47213. else if (graphicOption && !graphicOption.elements) {
  47214. option.graphic = [{elements: [graphicOption]}];
  47215. }
  47216. });
  47217. // ------
  47218. // Model
  47219. // ------
  47220. var GraphicModel = echarts.extendComponentModel({
  47221. type: 'graphic',
  47222. defaultOption: {
  47223. // Extra properties for each elements:
  47224. //
  47225. // left/right/top/bottom: (like 12, '22%', 'center', default undefined)
  47226. // If left/rigth is set, shape.x/shape.cx/position will not be used.
  47227. // If top/bottom is set, shape.y/shape.cy/position will not be used.
  47228. // This mechanism is useful when you want to position a group/element
  47229. // against the right side or the center of this container.
  47230. //
  47231. // width/height: (can only be pixel value, default 0)
  47232. // Only be used to specify contianer(group) size, if needed. And
  47233. // can not be percentage value (like '33%'). See the reason in the
  47234. // layout algorithm below.
  47235. //
  47236. // bounding: (enum: 'all' (default) | 'raw')
  47237. // Specify how to calculate boundingRect when locating.
  47238. // 'all': Get uioned and transformed boundingRect
  47239. // from both itself and its descendants.
  47240. // This mode simplies confining a group of elements in the bounding
  47241. // of their ancester container (e.g., using 'right: 0').
  47242. // 'raw': Only use the boundingRect of itself and before transformed.
  47243. // This mode is similar to css behavior, which is useful when you
  47244. // want an element to be able to overflow its container. (Consider
  47245. // a rotated circle needs to be located in a corner.)
  47246. // Note: elements is always behind its ancestors in this elements array.
  47247. elements: [],
  47248. parentId: null
  47249. },
  47250. /**
  47251. * Save el options for the sake of the performance (only update modified graphics).
  47252. * The order is the same as those in option. (ancesters -> descendants)
  47253. *
  47254. * @private
  47255. * @type {Array.<Object>}
  47256. */
  47257. _elOptionsToUpdate: null,
  47258. /**
  47259. * @override
  47260. */
  47261. mergeOption: function (option) {
  47262. // Prevent default merge to elements
  47263. var elements = this.option.elements;
  47264. this.option.elements = null;
  47265. GraphicModel.superApply(this, 'mergeOption', arguments);
  47266. this.option.elements = elements;
  47267. },
  47268. /**
  47269. * @override
  47270. */
  47271. optionUpdated: function (newOption, isInit) {
  47272. var thisOption = this.option;
  47273. var newList = (isInit ? thisOption : newOption).elements;
  47274. var existList = thisOption.elements = isInit ? [] : thisOption.elements;
  47275. var flattenedList = [];
  47276. this._flatten(newList, flattenedList);
  47277. var mappingResult = modelUtil.mappingToExists(existList, flattenedList);
  47278. modelUtil.makeIdAndName(mappingResult);
  47279. // Clear elOptionsToUpdate
  47280. var elOptionsToUpdate = this._elOptionsToUpdate = [];
  47281. zrUtil.each(mappingResult, function (resultItem, index) {
  47282. var newElOption = resultItem.option;
  47283. if (true) {
  47284. zrUtil.assert(
  47285. zrUtil.isObject(newElOption) || resultItem.exist,
  47286. 'Empty graphic option definition'
  47287. );
  47288. }
  47289. if (!newElOption) {
  47290. return;
  47291. }
  47292. elOptionsToUpdate.push(newElOption);
  47293. setKeyInfoToNewElOption(resultItem, newElOption);
  47294. mergeNewElOptionToExist(existList, index, newElOption);
  47295. setLayoutInfoToExist(existList[index], newElOption);
  47296. }, this);
  47297. // Clean
  47298. for (var i = existList.length - 1; i >= 0; i--) {
  47299. if (existList[i] == null) {
  47300. existList.splice(i, 1);
  47301. }
  47302. else {
  47303. // $action should be volatile, otherwise option gotten from
  47304. // `getOption` will contain unexpected $action.
  47305. delete existList[i].$action;
  47306. }
  47307. }
  47308. },
  47309. /**
  47310. * Convert
  47311. * [{
  47312. * type: 'group',
  47313. * id: 'xx',
  47314. * children: [{type: 'circle'}, {type: 'polygon'}]
  47315. * }]
  47316. * to
  47317. * [
  47318. * {type: 'group', id: 'xx'},
  47319. * {type: 'circle', parentId: 'xx'},
  47320. * {type: 'polygon', parentId: 'xx'}
  47321. * ]
  47322. *
  47323. * @private
  47324. * @param {Array.<Object>} optionList option list
  47325. * @param {Array.<Object>} result result of flatten
  47326. * @param {Object} parentOption parent option
  47327. */
  47328. _flatten: function (optionList, result, parentOption) {
  47329. zrUtil.each(optionList, function (option) {
  47330. if (!option) {
  47331. return;
  47332. }
  47333. if (parentOption) {
  47334. option.parentOption = parentOption;
  47335. }
  47336. result.push(option);
  47337. var children = option.children;
  47338. if (option.type === 'group' && children) {
  47339. this._flatten(children, result, option);
  47340. }
  47341. // Deleting for JSON output, and for not affecting group creation.
  47342. delete option.children;
  47343. }, this);
  47344. },
  47345. // FIXME
  47346. // Pass to view using payload? setOption has a payload?
  47347. useElOptionsToUpdate: function () {
  47348. var els = this._elOptionsToUpdate;
  47349. // Clear to avoid render duplicately when zooming.
  47350. this._elOptionsToUpdate = null;
  47351. return els;
  47352. }
  47353. });
  47354. // -----
  47355. // View
  47356. // -----
  47357. echarts.extendComponentView({
  47358. type: 'graphic',
  47359. /**
  47360. * @override
  47361. */
  47362. init: function (ecModel, api) {
  47363. /**
  47364. * @private
  47365. * @type {module:zrender/core/util.HashMap}
  47366. */
  47367. this._elMap = zrUtil.createHashMap();
  47368. /**
  47369. * @private
  47370. * @type {module:echarts/graphic/GraphicModel}
  47371. */
  47372. this._lastGraphicModel;
  47373. },
  47374. /**
  47375. * @override
  47376. */
  47377. render: function (graphicModel, ecModel, api) {
  47378. // Having leveraged between use cases and algorithm complexity, a very
  47379. // simple layout mechanism is used:
  47380. // The size(width/height) can be determined by itself or its parent (not
  47381. // implemented yet), but can not by its children. (Top-down travel)
  47382. // The location(x/y) can be determined by the bounding rect of itself
  47383. // (can including its descendants or not) and the size of its parent.
  47384. // (Bottom-up travel)
  47385. // When `chart.clear()` or `chart.setOption({...}, true)` with the same id,
  47386. // view will be reused.
  47387. if (graphicModel !== this._lastGraphicModel) {
  47388. this._clear();
  47389. }
  47390. this._lastGraphicModel = graphicModel;
  47391. this._updateElements(graphicModel, api);
  47392. this._relocate(graphicModel, api);
  47393. },
  47394. /**
  47395. * Update graphic elements.
  47396. *
  47397. * @private
  47398. * @param {Object} graphicModel graphic model
  47399. * @param {module:echarts/ExtensionAPI} api extension API
  47400. */
  47401. _updateElements: function (graphicModel, api) {
  47402. var elOptionsToUpdate = graphicModel.useElOptionsToUpdate();
  47403. if (!elOptionsToUpdate) {
  47404. return;
  47405. }
  47406. var elMap = this._elMap;
  47407. var rootGroup = this.group;
  47408. // Top-down tranverse to assign graphic settings to each elements.
  47409. zrUtil.each(elOptionsToUpdate, function (elOption) {
  47410. var $action = elOption.$action;
  47411. var id = elOption.id;
  47412. var existEl = elMap.get(id);
  47413. var parentId = elOption.parentId;
  47414. var targetElParent = parentId != null ? elMap.get(parentId) : rootGroup;
  47415. // In top/bottom mode, textVertical should not be used. And textBaseline
  47416. // should not be 'alphabetic', which cause inaccurately locating.
  47417. if (elOption.hv && elOption.hv[1] && elOption.type === 'text') {
  47418. elOption.style = zrUtil.defaults({textBaseline: 'middle'}, elOption.style);
  47419. elOption.style.textVerticalAlign = null;
  47420. }
  47421. // Remove unnecessary props to avoid potential problems.
  47422. var elOptionCleaned = getCleanedElOption(elOption);
  47423. // For simple, do not support parent change, otherwise reorder is needed.
  47424. if (true) {
  47425. existEl && zrUtil.assert(
  47426. targetElParent === existEl.parent,
  47427. 'Changing parent is not supported.'
  47428. );
  47429. }
  47430. if (!$action || $action === 'merge') {
  47431. existEl
  47432. ? existEl.attr(elOptionCleaned)
  47433. : createEl(id, targetElParent, elOptionCleaned, elMap);
  47434. }
  47435. else if ($action === 'replace') {
  47436. removeEl(existEl, elMap);
  47437. createEl(id, targetElParent, elOptionCleaned, elMap);
  47438. }
  47439. else if ($action === 'remove') {
  47440. removeEl(existEl, elMap);
  47441. }
  47442. var el = elMap.get(id);
  47443. if (el) {
  47444. el.__ecGraphicWidth = elOption.width;
  47445. el.__ecGraphicHeight = elOption.height;
  47446. }
  47447. });
  47448. },
  47449. /**
  47450. * Locate graphic elements.
  47451. *
  47452. * @private
  47453. * @param {Object} graphicModel graphic model
  47454. * @param {module:echarts/ExtensionAPI} api extension API
  47455. */
  47456. _relocate: function (graphicModel, api) {
  47457. var elOptions = graphicModel.option.elements;
  47458. var rootGroup = this.group;
  47459. var elMap = this._elMap;
  47460. // Bottom-up tranvese all elements (consider ec resize) to locate elements.
  47461. for (var i = elOptions.length - 1; i >= 0; i--) {
  47462. var elOption = elOptions[i];
  47463. var el = elMap.get(elOption.id);
  47464. if (!el) {
  47465. continue;
  47466. }
  47467. var parentEl = el.parent;
  47468. var containerInfo = parentEl === rootGroup
  47469. ? {
  47470. width: api.getWidth(),
  47471. height: api.getHeight()
  47472. }
  47473. : { // Like 'position:absolut' in css, default 0.
  47474. width: parentEl.__ecGraphicWidth || 0,
  47475. height: parentEl.__ecGraphicHeight || 0
  47476. };
  47477. layoutUtil.positionElement(
  47478. el, elOption, containerInfo, null,
  47479. {hv: elOption.hv, boundingMode: elOption.bounding}
  47480. );
  47481. }
  47482. },
  47483. /**
  47484. * Clear all elements.
  47485. *
  47486. * @private
  47487. */
  47488. _clear: function () {
  47489. var elMap = this._elMap;
  47490. elMap.each(function (el) {
  47491. removeEl(el, elMap);
  47492. });
  47493. this._elMap = zrUtil.createHashMap();
  47494. },
  47495. /**
  47496. * @override
  47497. */
  47498. dispose: function () {
  47499. this._clear();
  47500. }
  47501. });
  47502. function createEl(id, targetElParent, elOption, elMap) {
  47503. var graphicType = elOption.type;
  47504. if (true) {
  47505. zrUtil.assert(graphicType, 'graphic type MUST be set');
  47506. }
  47507. var Clz = graphicUtil[graphicType.charAt(0).toUpperCase() + graphicType.slice(1)];
  47508. if (true) {
  47509. zrUtil.assert(Clz, 'graphic type can not be found');
  47510. }
  47511. var el = new Clz(elOption);
  47512. targetElParent.add(el);
  47513. elMap.set(id, el);
  47514. el.__ecGraphicId = id;
  47515. }
  47516. function removeEl(existEl, elMap) {
  47517. var existElParent = existEl && existEl.parent;
  47518. if (existElParent) {
  47519. existEl.type === 'group' && existEl.traverse(function (el) {
  47520. removeEl(el, elMap);
  47521. });
  47522. elMap.removeKey(existEl.__ecGraphicId);
  47523. existElParent.remove(existEl);
  47524. }
  47525. }
  47526. // Remove unnecessary props to avoid potential problems.
  47527. function getCleanedElOption(elOption) {
  47528. elOption = zrUtil.extend({}, elOption);
  47529. zrUtil.each(
  47530. ['id', 'parentId', '$action', 'hv', 'bounding'].concat(layoutUtil.LOCATION_PARAMS),
  47531. function (name) {
  47532. delete elOption[name];
  47533. }
  47534. );
  47535. return elOption;
  47536. }
  47537. function isSetLoc(obj, props) {
  47538. var isSet;
  47539. zrUtil.each(props, function (prop) {
  47540. obj[prop] != null && obj[prop] !== 'auto' && (isSet = true);
  47541. });
  47542. return isSet;
  47543. }
  47544. function setKeyInfoToNewElOption(resultItem, newElOption) {
  47545. var existElOption = resultItem.exist;
  47546. // Set id and type after id assigned.
  47547. newElOption.id = resultItem.keyInfo.id;
  47548. !newElOption.type && existElOption && (newElOption.type = existElOption.type);
  47549. // Set parent id if not specified
  47550. if (newElOption.parentId == null) {
  47551. var newElParentOption = newElOption.parentOption;
  47552. if (newElParentOption) {
  47553. newElOption.parentId = newElParentOption.id;
  47554. }
  47555. else if (existElOption) {
  47556. newElOption.parentId = existElOption.parentId;
  47557. }
  47558. }
  47559. // Clear
  47560. newElOption.parentOption = null;
  47561. }
  47562. function mergeNewElOptionToExist(existList, index, newElOption) {
  47563. // Update existing options, for `getOption` feature.
  47564. var newElOptCopy = zrUtil.extend({}, newElOption);
  47565. var existElOption = existList[index];
  47566. var $action = newElOption.$action || 'merge';
  47567. if ($action === 'merge') {
  47568. if (existElOption) {
  47569. if (true) {
  47570. var newType = newElOption.type;
  47571. zrUtil.assert(
  47572. !newType || existElOption.type === newType,
  47573. 'Please set $action: "replace" to change `type`'
  47574. );
  47575. }
  47576. // We can ensure that newElOptCopy and existElOption are not
  47577. // the same object, so `merge` will not change newElOptCopy.
  47578. zrUtil.merge(existElOption, newElOptCopy, true);
  47579. // Rigid body, use ignoreSize.
  47580. layoutUtil.mergeLayoutParam(existElOption, newElOptCopy, {ignoreSize: true});
  47581. // Will be used in render.
  47582. layoutUtil.copyLayoutParams(newElOption, existElOption);
  47583. }
  47584. else {
  47585. existList[index] = newElOptCopy;
  47586. }
  47587. }
  47588. else if ($action === 'replace') {
  47589. existList[index] = newElOptCopy;
  47590. }
  47591. else if ($action === 'remove') {
  47592. // null will be cleaned later.
  47593. existElOption && (existList[index] = null);
  47594. }
  47595. }
  47596. function setLayoutInfoToExist(existItem, newElOption) {
  47597. if (!existItem) {
  47598. return;
  47599. }
  47600. existItem.hv = newElOption.hv = [
  47601. // Rigid body, dont care `width`.
  47602. isSetLoc(newElOption, ['left', 'right']),
  47603. // Rigid body, dont care `height`.
  47604. isSetLoc(newElOption, ['top', 'bottom'])
  47605. ];
  47606. // Give default group size. Otherwise layout error may occur.
  47607. if (existItem.type === 'group') {
  47608. existItem.width == null && (existItem.width = newElOption.width = 0);
  47609. existItem.height == null && (existItem.height = newElOption.height = 0);
  47610. }
  47611. }
  47612. /***/ },
  47613. /* 319 */
  47614. /***/ function(module, exports, __webpack_require__) {
  47615. __webpack_require__(124);
  47616. __webpack_require__(303);
  47617. __webpack_require__(297);
  47618. /***/ },
  47619. /* 320 */
  47620. /***/ function(module, exports, __webpack_require__) {
  47621. /**
  47622. * Legend component entry file8
  47623. */
  47624. __webpack_require__(321);
  47625. __webpack_require__(322);
  47626. __webpack_require__(323);
  47627. var echarts = __webpack_require__(1);
  47628. // Series Filter
  47629. echarts.registerProcessor(__webpack_require__(325));
  47630. /***/ },
  47631. /* 321 */
  47632. /***/ function(module, exports, __webpack_require__) {
  47633. 'use strict';
  47634. var zrUtil = __webpack_require__(4);
  47635. var Model = __webpack_require__(12);
  47636. var LegendModel = __webpack_require__(1).extendComponentModel({
  47637. type: 'legend',
  47638. dependencies: ['series'],
  47639. layoutMode: {
  47640. type: 'box',
  47641. ignoreSize: true
  47642. },
  47643. init: function (option, parentModel, ecModel) {
  47644. this.mergeDefaultAndTheme(option, ecModel);
  47645. option.selected = option.selected || {};
  47646. },
  47647. mergeOption: function (option) {
  47648. LegendModel.superCall(this, 'mergeOption', option);
  47649. },
  47650. optionUpdated: function () {
  47651. this._updateData(this.ecModel);
  47652. var legendData = this._data;
  47653. // If selectedMode is single, try to select one
  47654. if (legendData[0] && this.get('selectedMode') === 'single') {
  47655. var hasSelected = false;
  47656. // If has any selected in option.selected
  47657. for (var i = 0; i < legendData.length; i++) {
  47658. var name = legendData[i].get('name');
  47659. if (this.isSelected(name)) {
  47660. // Force to unselect others
  47661. this.select(name);
  47662. hasSelected = true;
  47663. break;
  47664. }
  47665. }
  47666. // Try select the first if selectedMode is single
  47667. !hasSelected && this.select(legendData[0].get('name'));
  47668. }
  47669. },
  47670. _updateData: function (ecModel) {
  47671. var legendData = zrUtil.map(this.get('data') || [], function (dataItem) {
  47672. // Can be string or number
  47673. if (typeof dataItem === 'string' || typeof dataItem === 'number') {
  47674. dataItem = {
  47675. name: dataItem
  47676. };
  47677. }
  47678. return new Model(dataItem, this, this.ecModel);
  47679. }, this);
  47680. this._data = legendData;
  47681. var availableNames = zrUtil.map(ecModel.getSeries(), function (series) {
  47682. return series.name;
  47683. });
  47684. ecModel.eachSeries(function (seriesModel) {
  47685. if (seriesModel.legendDataProvider) {
  47686. var data = seriesModel.legendDataProvider();
  47687. availableNames = availableNames.concat(data.mapArray(data.getName));
  47688. }
  47689. });
  47690. /**
  47691. * @type {Array.<string>}
  47692. * @private
  47693. */
  47694. this._availableNames = availableNames;
  47695. },
  47696. /**
  47697. * @return {Array.<module:echarts/model/Model>}
  47698. */
  47699. getData: function () {
  47700. return this._data;
  47701. },
  47702. /**
  47703. * @param {string} name
  47704. */
  47705. select: function (name) {
  47706. var selected = this.option.selected;
  47707. var selectedMode = this.get('selectedMode');
  47708. if (selectedMode === 'single') {
  47709. var data = this._data;
  47710. zrUtil.each(data, function (dataItem) {
  47711. selected[dataItem.get('name')] = false;
  47712. });
  47713. }
  47714. selected[name] = true;
  47715. },
  47716. /**
  47717. * @param {string} name
  47718. */
  47719. unSelect: function (name) {
  47720. if (this.get('selectedMode') !== 'single') {
  47721. this.option.selected[name] = false;
  47722. }
  47723. },
  47724. /**
  47725. * @param {string} name
  47726. */
  47727. toggleSelected: function (name) {
  47728. var selected = this.option.selected;
  47729. // Default is true
  47730. if (!selected.hasOwnProperty(name)) {
  47731. selected[name] = true;
  47732. }
  47733. this[selected[name] ? 'unSelect' : 'select'](name);
  47734. },
  47735. /**
  47736. * @param {string} name
  47737. */
  47738. isSelected: function (name) {
  47739. var selected = this.option.selected;
  47740. return !(selected.hasOwnProperty(name) && !selected[name])
  47741. && zrUtil.indexOf(this._availableNames, name) >= 0;
  47742. },
  47743. defaultOption: {
  47744. // 一级层叠
  47745. zlevel: 0,
  47746. // 二级层叠
  47747. z: 4,
  47748. show: true,
  47749. // 布局方式,默认为水平布局,可选为:
  47750. // 'horizontal' | 'vertical'
  47751. orient: 'horizontal',
  47752. left: 'center',
  47753. // right: 'center',
  47754. top: 'top',
  47755. // bottom: 'top',
  47756. // 水平对齐
  47757. // 'auto' | 'left' | 'right'
  47758. // 默认为 'auto', 根据 x 的位置判断是左对齐还是右对齐
  47759. align: 'auto',
  47760. backgroundColor: 'rgba(0,0,0,0)',
  47761. // 图例边框颜色
  47762. borderColor: '#ccc',
  47763. // 图例边框线宽,单位px,默认为0(无边框)
  47764. borderWidth: 0,
  47765. // 图例内边距,单位px,默认各方向内边距为5,
  47766. // 接受数组分别设定上右下左边距,同css
  47767. padding: 5,
  47768. // 各个item之间的间隔,单位px,默认为10,
  47769. // 横向布局时为水平间隔,纵向布局时为纵向间隔
  47770. itemGap: 10,
  47771. // 图例图形宽度
  47772. itemWidth: 25,
  47773. // 图例图形高度
  47774. itemHeight: 14,
  47775. // 图例关闭时候的颜色
  47776. inactiveColor: '#ccc',
  47777. textStyle: {
  47778. // 图例文字颜色
  47779. color: '#333'
  47780. },
  47781. // formatter: '',
  47782. // 选择模式,默认开启图例开关
  47783. selectedMode: true,
  47784. // 配置默认选中状态,可配合LEGEND.SELECTED事件做动态数据载入
  47785. // selected: null,
  47786. // 图例内容(详见legend.data,数组中每一项代表一个item
  47787. // data: [],
  47788. // Tooltip 相关配置
  47789. tooltip: {
  47790. show: false
  47791. }
  47792. }
  47793. });
  47794. module.exports = LegendModel;
  47795. /***/ },
  47796. /* 322 */
  47797. /***/ function(module, exports, __webpack_require__) {
  47798. /**
  47799. * @file Legend action
  47800. */
  47801. var echarts = __webpack_require__(1);
  47802. var zrUtil = __webpack_require__(4);
  47803. function legendSelectActionHandler(methodName, payload, ecModel) {
  47804. var selectedMap = {};
  47805. var isToggleSelect = methodName === 'toggleSelected';
  47806. var isSelected;
  47807. // Update all legend components
  47808. ecModel.eachComponent('legend', function (legendModel) {
  47809. if (isToggleSelect && isSelected != null) {
  47810. // Force other legend has same selected status
  47811. // Or the first is toggled to true and other are toggled to false
  47812. // In the case one legend has some item unSelected in option. And if other legend
  47813. // doesn't has the item, they will assume it is selected.
  47814. legendModel[isSelected ? 'select' : 'unSelect'](payload.name);
  47815. }
  47816. else {
  47817. legendModel[methodName](payload.name);
  47818. isSelected = legendModel.isSelected(payload.name);
  47819. }
  47820. var legendData = legendModel.getData();
  47821. zrUtil.each(legendData, function (model) {
  47822. var name = model.get('name');
  47823. // Wrap element
  47824. if (name === '\n' || name === '') {
  47825. return;
  47826. }
  47827. var isItemSelected = legendModel.isSelected(name);
  47828. if (selectedMap.hasOwnProperty(name)) {
  47829. // Unselected if any legend is unselected
  47830. selectedMap[name] = selectedMap[name] && isItemSelected;
  47831. }
  47832. else {
  47833. selectedMap[name] = isItemSelected;
  47834. }
  47835. });
  47836. });
  47837. // Return the event explicitly
  47838. return {
  47839. name: payload.name,
  47840. selected: selectedMap
  47841. };
  47842. }
  47843. /**
  47844. * @event legendToggleSelect
  47845. * @type {Object}
  47846. * @property {string} type 'legendToggleSelect'
  47847. * @property {string} [from]
  47848. * @property {string} name Series name or data item name
  47849. */
  47850. echarts.registerAction(
  47851. 'legendToggleSelect', 'legendselectchanged',
  47852. zrUtil.curry(legendSelectActionHandler, 'toggleSelected')
  47853. );
  47854. /**
  47855. * @event legendSelect
  47856. * @type {Object}
  47857. * @property {string} type 'legendSelect'
  47858. * @property {string} name Series name or data item name
  47859. */
  47860. echarts.registerAction(
  47861. 'legendSelect', 'legendselected',
  47862. zrUtil.curry(legendSelectActionHandler, 'select')
  47863. );
  47864. /**
  47865. * @event legendUnSelect
  47866. * @type {Object}
  47867. * @property {string} type 'legendUnSelect'
  47868. * @property {string} name Series name or data item name
  47869. */
  47870. echarts.registerAction(
  47871. 'legendUnSelect', 'legendunselected',
  47872. zrUtil.curry(legendSelectActionHandler, 'unSelect')
  47873. );
  47874. /***/ },
  47875. /* 323 */
  47876. /***/ function(module, exports, __webpack_require__) {
  47877. var zrUtil = __webpack_require__(4);
  47878. var symbolCreator = __webpack_require__(111);
  47879. var graphic = __webpack_require__(18);
  47880. var listComponentHelper = __webpack_require__(324);
  47881. var curry = zrUtil.curry;
  47882. function dispatchSelectAction(name, api) {
  47883. api.dispatchAction({
  47884. type: 'legendToggleSelect',
  47885. name: name
  47886. });
  47887. }
  47888. function dispatchHighlightAction(seriesModel, dataName, api) {
  47889. // If element hover will move to a hoverLayer.
  47890. var el = api.getZr().storage.getDisplayList()[0];
  47891. if (!(el && el.useHoverLayer)) {
  47892. seriesModel.get('legendHoverLink') && api.dispatchAction({
  47893. type: 'highlight',
  47894. seriesName: seriesModel.name,
  47895. name: dataName
  47896. });
  47897. }
  47898. }
  47899. function dispatchDownplayAction(seriesModel, dataName, api) {
  47900. // If element hover will move to a hoverLayer.
  47901. var el = api.getZr().storage.getDisplayList()[0];
  47902. if (!(el && el.useHoverLayer)) {
  47903. seriesModel.get('legendHoverLink') && api.dispatchAction({
  47904. type: 'downplay',
  47905. seriesName: seriesModel.name,
  47906. name: dataName
  47907. });
  47908. }
  47909. }
  47910. module.exports = __webpack_require__(1).extendComponentView({
  47911. type: 'legend',
  47912. init: function () {
  47913. this._symbolTypeStore = {};
  47914. },
  47915. render: function (legendModel, ecModel, api) {
  47916. var group = this.group;
  47917. group.removeAll();
  47918. if (!legendModel.get('show')) {
  47919. return;
  47920. }
  47921. var selectMode = legendModel.get('selectedMode');
  47922. var itemAlign = legendModel.get('align');
  47923. if (itemAlign === 'auto') {
  47924. itemAlign = (legendModel.get('left') === 'right'
  47925. && legendModel.get('orient') === 'vertical')
  47926. ? 'right' : 'left';
  47927. }
  47928. var legendDrawedMap = zrUtil.createHashMap();
  47929. zrUtil.each(legendModel.getData(), function (itemModel) {
  47930. var name = itemModel.get('name');
  47931. // Use empty string or \n as a newline string
  47932. if (name === '' || name === '\n') {
  47933. group.add(new graphic.Group({
  47934. newline: true
  47935. }));
  47936. return;
  47937. }
  47938. var seriesModel = ecModel.getSeriesByName(name)[0];
  47939. if (legendDrawedMap.get(name)) {
  47940. // Have been drawed
  47941. return;
  47942. }
  47943. // Series legend
  47944. if (seriesModel) {
  47945. var data = seriesModel.getData();
  47946. var color = data.getVisual('color');
  47947. // If color is a callback function
  47948. if (typeof color === 'function') {
  47949. // Use the first data
  47950. color = color(seriesModel.getDataParams(0));
  47951. }
  47952. // Using rect symbol defaultly
  47953. var legendSymbolType = data.getVisual('legendSymbol') || 'roundRect';
  47954. var symbolType = data.getVisual('symbol');
  47955. var itemGroup = this._createItem(
  47956. name, itemModel, legendModel,
  47957. legendSymbolType, symbolType,
  47958. itemAlign, color,
  47959. selectMode
  47960. );
  47961. itemGroup.on('click', curry(dispatchSelectAction, name, api))
  47962. .on('mouseover', curry(dispatchHighlightAction, seriesModel, null, api))
  47963. .on('mouseout', curry(dispatchDownplayAction, seriesModel, null, api));
  47964. legendDrawedMap.set(name, true);
  47965. }
  47966. else {
  47967. // Data legend of pie, funnel
  47968. ecModel.eachRawSeries(function (seriesModel) {
  47969. // In case multiple series has same data name
  47970. if (legendDrawedMap.get(name)) {
  47971. return;
  47972. }
  47973. if (seriesModel.legendDataProvider) {
  47974. var data = seriesModel.legendDataProvider();
  47975. var idx = data.indexOfName(name);
  47976. if (idx < 0) {
  47977. return;
  47978. }
  47979. var color = data.getItemVisual(idx, 'color');
  47980. var legendSymbolType = 'roundRect';
  47981. var itemGroup = this._createItem(
  47982. name, itemModel, legendModel,
  47983. legendSymbolType, null,
  47984. itemAlign, color,
  47985. selectMode
  47986. );
  47987. itemGroup.on('click', curry(dispatchSelectAction, name, api))
  47988. // FIXME Should not specify the series name
  47989. .on('mouseover', curry(dispatchHighlightAction, seriesModel, name, api))
  47990. .on('mouseout', curry(dispatchDownplayAction, seriesModel, name, api));
  47991. legendDrawedMap.set(name, true);
  47992. }
  47993. }, this);
  47994. }
  47995. if (true) {
  47996. if (!legendDrawedMap.get(name)) {
  47997. console.warn(name + ' series not exists. Legend data should be same with series name or data name.');
  47998. }
  47999. }
  48000. }, this);
  48001. listComponentHelper.layout(group, legendModel, api);
  48002. // Render background after group is layout
  48003. // FIXME
  48004. listComponentHelper.addBackground(group, legendModel);
  48005. },
  48006. _createItem: function (
  48007. name, itemModel, legendModel,
  48008. legendSymbolType, symbolType,
  48009. itemAlign, color, selectMode
  48010. ) {
  48011. var itemWidth = legendModel.get('itemWidth');
  48012. var itemHeight = legendModel.get('itemHeight');
  48013. var inactiveColor = legendModel.get('inactiveColor');
  48014. var isSelected = legendModel.isSelected(name);
  48015. var itemGroup = new graphic.Group();
  48016. var textStyleModel = itemModel.getModel('textStyle');
  48017. var itemIcon = itemModel.get('icon');
  48018. var tooltipModel = itemModel.getModel('tooltip');
  48019. var legendGlobalTooltipModel = tooltipModel.parentModel;
  48020. // Use user given icon first
  48021. legendSymbolType = itemIcon || legendSymbolType;
  48022. itemGroup.add(symbolCreator.createSymbol(
  48023. legendSymbolType, 0, 0, itemWidth, itemHeight, isSelected ? color : inactiveColor
  48024. ));
  48025. // Compose symbols
  48026. // PENDING
  48027. if (!itemIcon && symbolType
  48028. // At least show one symbol, can't be all none
  48029. && ((symbolType !== legendSymbolType) || symbolType == 'none')
  48030. ) {
  48031. var size = itemHeight * 0.8;
  48032. if (symbolType === 'none') {
  48033. symbolType = 'circle';
  48034. }
  48035. // Put symbol in the center
  48036. itemGroup.add(symbolCreator.createSymbol(
  48037. symbolType, (itemWidth - size) / 2, (itemHeight - size) / 2, size, size,
  48038. isSelected ? color : inactiveColor
  48039. ));
  48040. }
  48041. // Text
  48042. var textX = itemAlign === 'left' ? itemWidth + 5 : -5;
  48043. var textAlign = itemAlign;
  48044. var formatter = legendModel.get('formatter');
  48045. var content = name;
  48046. if (typeof formatter === 'string' && formatter) {
  48047. content = formatter.replace('{name}', name != null ? name : '');
  48048. }
  48049. else if (typeof formatter === 'function') {
  48050. content = formatter(name);
  48051. }
  48052. var text = new graphic.Text({
  48053. style: {
  48054. text: content,
  48055. x: textX,
  48056. y: itemHeight / 2,
  48057. fill: isSelected ? textStyleModel.getTextColor() : inactiveColor,
  48058. textFont: textStyleModel.getFont(),
  48059. textAlign: textAlign,
  48060. textVerticalAlign: 'middle'
  48061. }
  48062. });
  48063. itemGroup.add(text);
  48064. // Add a invisible rect to increase the area of mouse hover
  48065. var hitRect = new graphic.Rect({
  48066. shape: itemGroup.getBoundingRect(),
  48067. invisible: true,
  48068. tooltip: tooltipModel.get('show') ? zrUtil.extend({
  48069. content: name,
  48070. // Defaul formatter
  48071. formatter: legendGlobalTooltipModel.get('formatter', true) || function () {
  48072. return name;
  48073. },
  48074. formatterParams: {
  48075. componentType: 'legend',
  48076. legendIndex: legendModel.componentIndex,
  48077. name: name,
  48078. $vars: ['name']
  48079. }
  48080. }, tooltipModel.option) : null
  48081. });
  48082. itemGroup.add(hitRect);
  48083. itemGroup.eachChild(function (child) {
  48084. child.silent = true;
  48085. });
  48086. hitRect.silent = !selectMode;
  48087. this.group.add(itemGroup);
  48088. graphic.setHoverStyle(itemGroup);
  48089. return itemGroup;
  48090. }
  48091. });
  48092. /***/ },
  48093. /* 324 */
  48094. /***/ function(module, exports, __webpack_require__) {
  48095. // List layout
  48096. var layout = __webpack_require__(71);
  48097. var formatUtil = __webpack_require__(6);
  48098. var graphic = __webpack_require__(18);
  48099. function positionGroup(group, model, api) {
  48100. layout.positionElement(
  48101. group, model.getBoxLayoutParams(),
  48102. {
  48103. width: api.getWidth(),
  48104. height: api.getHeight()
  48105. },
  48106. model.get('padding')
  48107. );
  48108. }
  48109. module.exports = {
  48110. /**
  48111. * Layout list like component.
  48112. * It will box layout each items in group of component and then position the whole group in the viewport
  48113. * @param {module:zrender/group/Group} group
  48114. * @param {module:echarts/model/Component} componentModel
  48115. * @param {module:echarts/ExtensionAPI}
  48116. */
  48117. layout: function (group, componentModel, api) {
  48118. var rect = layout.getLayoutRect(componentModel.getBoxLayoutParams(), {
  48119. width: api.getWidth(),
  48120. height: api.getHeight()
  48121. }, componentModel.get('padding'));
  48122. layout.box(
  48123. componentModel.get('orient'),
  48124. group,
  48125. componentModel.get('itemGap'),
  48126. rect.width,
  48127. rect.height
  48128. );
  48129. positionGroup(group, componentModel, api);
  48130. },
  48131. addBackground: function (group, componentModel) {
  48132. var padding = formatUtil.normalizeCssArray(
  48133. componentModel.get('padding')
  48134. );
  48135. var boundingRect = group.getBoundingRect();
  48136. var style = componentModel.getItemStyle(['color', 'opacity']);
  48137. style.fill = componentModel.get('backgroundColor');
  48138. var rect = new graphic.Rect({
  48139. shape: {
  48140. x: boundingRect.x - padding[3],
  48141. y: boundingRect.y - padding[0],
  48142. width: boundingRect.width + padding[1] + padding[3],
  48143. height: boundingRect.height + padding[0] + padding[2]
  48144. },
  48145. style: style,
  48146. silent: true,
  48147. z2: -1
  48148. });
  48149. graphic.subPixelOptimizeRect(rect);
  48150. group.add(rect);
  48151. }
  48152. };
  48153. /***/ },
  48154. /* 325 */
  48155. /***/ function(module, exports) {
  48156. module.exports = function (ecModel) {
  48157. var legendModels = ecModel.findComponents({
  48158. mainType: 'legend'
  48159. });
  48160. if (legendModels && legendModels.length) {
  48161. ecModel.filterSeries(function (series) {
  48162. // If in any legend component the status is not selected.
  48163. // Because in legend series is assumed selected when it is not in the legend data.
  48164. for (var i = 0; i < legendModels.length; i++) {
  48165. if (!legendModels[i].isSelected(series.name)) {
  48166. return false;
  48167. }
  48168. }
  48169. return true;
  48170. });
  48171. }
  48172. };
  48173. /***/ },
  48174. /* 326 */
  48175. /***/ function(module, exports, __webpack_require__) {
  48176. // FIXME Better way to pack data in graphic element
  48177. __webpack_require__(297);
  48178. __webpack_require__(327);
  48179. __webpack_require__(328);
  48180. // Show tip action
  48181. /**
  48182. * @action
  48183. * @property {string} type
  48184. * @property {number} seriesIndex
  48185. * @property {number} dataIndex
  48186. * @property {number} [x]
  48187. * @property {number} [y]
  48188. */
  48189. __webpack_require__(1).registerAction(
  48190. {
  48191. type: 'showTip',
  48192. event: 'showTip',
  48193. update: 'tooltip:manuallyShowTip'
  48194. },
  48195. // noop
  48196. function () {}
  48197. );
  48198. // Hide tip action
  48199. __webpack_require__(1).registerAction(
  48200. {
  48201. type: 'hideTip',
  48202. event: 'hideTip',
  48203. update: 'tooltip:manuallyHideTip'
  48204. },
  48205. // noop
  48206. function () {}
  48207. );
  48208. /***/ },
  48209. /* 327 */
  48210. /***/ function(module, exports, __webpack_require__) {
  48211. __webpack_require__(1).extendComponentModel({
  48212. type: 'tooltip',
  48213. dependencies: ['axisPointer'],
  48214. defaultOption: {
  48215. zlevel: 0,
  48216. z: 8,
  48217. show: true,
  48218. // tooltip主体内容
  48219. showContent: true,
  48220. // 'trigger' only works on coordinate system.
  48221. // 'item' | 'axis' | 'none'
  48222. trigger: 'item',
  48223. // 'click' | 'mousemove' | 'none'
  48224. triggerOn: 'mousemove|click',
  48225. alwaysShowContent: false,
  48226. displayMode: 'single', // 'single' | 'multipleByCoordSys'
  48227. // 位置 {Array} | {Function}
  48228. // position: null
  48229. // Consider triggered from axisPointer handle, verticalAlign should be 'middle'
  48230. // align: null,
  48231. // verticalAlign: null,
  48232. // 是否约束 content 在 viewRect 中。默认 false 是为了兼容以前版本。
  48233. confine: false,
  48234. // 内容格式器:{string}(Template) ¦ {Function}
  48235. // formatter: null
  48236. showDelay: 0,
  48237. // 隐藏延迟,单位ms
  48238. hideDelay: 100,
  48239. // 动画变换时间,单位s
  48240. transitionDuration: 0.4,
  48241. enterable: false,
  48242. // 提示背景颜色,默认为透明度为0.7的黑色
  48243. backgroundColor: 'rgba(50,50,50,0.7)',
  48244. // 提示边框颜色
  48245. borderColor: '#333',
  48246. // 提示边框圆角,单位px,默认为4
  48247. borderRadius: 4,
  48248. // 提示边框线宽,单位px,默认为0(无边框)
  48249. borderWidth: 0,
  48250. // 提示内边距,单位px,默认各方向内边距为5,
  48251. // 接受数组分别设定上右下左边距,同css
  48252. padding: 5,
  48253. // Extra css text
  48254. extraCssText: '',
  48255. // 坐标轴指示器,坐标轴触发有效
  48256. axisPointer: {
  48257. // 默认为直线
  48258. // 可选为:'line' | 'shadow' | 'cross'
  48259. type: 'line',
  48260. // type 为 line 的时候有效,指定 tooltip line 所在的轴,可选
  48261. // 可选 'x' | 'y' | 'angle' | 'radius' | 'auto'
  48262. // 默认 'auto',会选择类型为 cateogry 的轴,对于双数值轴,笛卡尔坐标系会默认选择 x 轴
  48263. // 极坐标系会默认选择 angle 轴
  48264. axis: 'auto',
  48265. animation: 'auto',
  48266. animationDurationUpdate: 200,
  48267. animationEasingUpdate: 'exponentialOut',
  48268. crossStyle: {
  48269. color: '#999',
  48270. width: 1,
  48271. type: 'dashed',
  48272. // TODO formatter
  48273. textStyle: {}
  48274. }
  48275. // lineStyle and shadowStyle should not be specified here,
  48276. // otherwise it will always override those styles on option.axisPointer.
  48277. },
  48278. textStyle: {
  48279. color: '#fff',
  48280. fontSize: 14
  48281. }
  48282. }
  48283. });
  48284. /***/ },
  48285. /* 328 */
  48286. /***/ function(module, exports, __webpack_require__) {
  48287. var TooltipContent = __webpack_require__(329);
  48288. var zrUtil = __webpack_require__(4);
  48289. var formatUtil = __webpack_require__(6);
  48290. var numberUtil = __webpack_require__(7);
  48291. var graphic = __webpack_require__(18);
  48292. var findPointFromSeries = __webpack_require__(299);
  48293. var layoutUtil = __webpack_require__(71);
  48294. var env = __webpack_require__(2);
  48295. var Model = __webpack_require__(12);
  48296. var globalListener = __webpack_require__(302);
  48297. var axisHelper = __webpack_require__(101);
  48298. var axisPointerViewHelper = __webpack_require__(305);
  48299. var bind = zrUtil.bind;
  48300. var each = zrUtil.each;
  48301. var parsePercent = numberUtil.parsePercent;
  48302. var proxyRect = new graphic.Rect({
  48303. shape: {x: -1, y: -1, width: 2, height: 2}
  48304. });
  48305. __webpack_require__(1).extendComponentView({
  48306. type: 'tooltip',
  48307. init: function (ecModel, api) {
  48308. if (env.node) {
  48309. return;
  48310. }
  48311. var tooltipContent = new TooltipContent(api.getDom(), api);
  48312. this._tooltipContent = tooltipContent;
  48313. },
  48314. render: function (tooltipModel, ecModel, api) {
  48315. if (env.node) {
  48316. return;
  48317. }
  48318. // Reset
  48319. this.group.removeAll();
  48320. /**
  48321. * @private
  48322. * @type {module:echarts/component/tooltip/TooltipModel}
  48323. */
  48324. this._tooltipModel = tooltipModel;
  48325. /**
  48326. * @private
  48327. * @type {module:echarts/model/Global}
  48328. */
  48329. this._ecModel = ecModel;
  48330. /**
  48331. * @private
  48332. * @type {module:echarts/ExtensionAPI}
  48333. */
  48334. this._api = api;
  48335. /**
  48336. * Should be cleaned when render.
  48337. * @private
  48338. * @type {Array.<Array.<Object>>}
  48339. */
  48340. this._lastDataByCoordSys = null;
  48341. /**
  48342. * @private
  48343. * @type {boolean}
  48344. */
  48345. this._alwaysShowContent = tooltipModel.get('alwaysShowContent');
  48346. var tooltipContent = this._tooltipContent;
  48347. tooltipContent.update();
  48348. tooltipContent.setEnterable(tooltipModel.get('enterable'));
  48349. this._initGlobalListener();
  48350. this._keepShow();
  48351. },
  48352. _initGlobalListener: function () {
  48353. var tooltipModel = this._tooltipModel;
  48354. var triggerOn = tooltipModel.get('triggerOn');
  48355. globalListener.register(
  48356. 'itemTooltip',
  48357. this._api,
  48358. bind(function (currTrigger, e, dispatchAction) {
  48359. // If 'none', it is not controlled by mouse totally.
  48360. if (triggerOn !== 'none') {
  48361. if (triggerOn.indexOf(currTrigger) >= 0) {
  48362. this._tryShow(e, dispatchAction);
  48363. }
  48364. else if (currTrigger === 'leave') {
  48365. this._hide(dispatchAction);
  48366. }
  48367. }
  48368. }, this)
  48369. );
  48370. },
  48371. _keepShow: function () {
  48372. var tooltipModel = this._tooltipModel;
  48373. var ecModel = this._ecModel;
  48374. var api = this._api;
  48375. // Try to keep the tooltip show when refreshing
  48376. if (this._lastX != null
  48377. && this._lastY != null
  48378. // When user is willing to control tooltip totally using API,
  48379. // self.manuallyShowTip({x, y}) might cause tooltip hide,
  48380. // which is not expected.
  48381. && tooltipModel.get('triggerOn') !== 'none'
  48382. ) {
  48383. var self = this;
  48384. clearTimeout(this._refreshUpdateTimeout);
  48385. this._refreshUpdateTimeout = setTimeout(function () {
  48386. // Show tip next tick after other charts are rendered
  48387. // In case highlight action has wrong result
  48388. // FIXME
  48389. self.manuallyShowTip(tooltipModel, ecModel, api, {
  48390. x: self._lastX,
  48391. y: self._lastY
  48392. });
  48393. });
  48394. }
  48395. },
  48396. /**
  48397. * Show tip manually by
  48398. * dispatchAction({
  48399. * type: 'showTip',
  48400. * x: 10,
  48401. * y: 10
  48402. * });
  48403. * Or
  48404. * dispatchAction({
  48405. * type: 'showTip',
  48406. * seriesIndex: 0,
  48407. * dataIndex or dataIndexInside or name
  48408. * });
  48409. *
  48410. * TODO Batch
  48411. */
  48412. manuallyShowTip: function (tooltipModel, ecModel, api, payload) {
  48413. if (payload.from === this.uid || env.node) {
  48414. return;
  48415. }
  48416. var dispatchAction = makeDispatchAction(payload, api);
  48417. // Reset ticket
  48418. this._ticket = '';
  48419. // When triggered from axisPointer.
  48420. var dataByCoordSys = payload.dataByCoordSys;
  48421. if (payload.tooltip && payload.x != null && payload.y != null) {
  48422. var el = proxyRect;
  48423. el.position = [payload.x, payload.y];
  48424. el.update();
  48425. el.tooltip = payload.tooltip;
  48426. // Manually show tooltip while view is not using zrender elements.
  48427. this._tryShow({
  48428. offsetX: payload.x,
  48429. offsetY: payload.y,
  48430. target: el
  48431. }, dispatchAction);
  48432. }
  48433. else if (dataByCoordSys) {
  48434. this._tryShow({
  48435. offsetX: payload.x,
  48436. offsetY: payload.y,
  48437. position: payload.position,
  48438. event: {},
  48439. dataByCoordSys: payload.dataByCoordSys,
  48440. tooltipOption: payload.tooltipOption
  48441. }, dispatchAction);
  48442. }
  48443. else if (payload.seriesIndex != null) {
  48444. if (this._manuallyAxisShowTip(tooltipModel, ecModel, api, payload)) {
  48445. return;
  48446. }
  48447. var pointInfo = findPointFromSeries(payload, ecModel);
  48448. var cx = pointInfo.point[0];
  48449. var cy = pointInfo.point[1];
  48450. if (cx != null && cy != null) {
  48451. this._tryShow({
  48452. offsetX: cx,
  48453. offsetY: cy,
  48454. position: payload.position,
  48455. target: pointInfo.el,
  48456. event: {}
  48457. }, dispatchAction);
  48458. }
  48459. }
  48460. else if (payload.x != null && payload.y != null) {
  48461. // FIXME
  48462. // should wrap dispatchAction like `axisPointer/globalListener` ?
  48463. api.dispatchAction({
  48464. type: 'updateAxisPointer',
  48465. x: payload.x,
  48466. y: payload.y
  48467. });
  48468. this._tryShow({
  48469. offsetX: payload.x,
  48470. offsetY: payload.y,
  48471. position: payload.position,
  48472. target: api.getZr().findHover(payload.x, payload.y).target,
  48473. event: {}
  48474. }, dispatchAction);
  48475. }
  48476. },
  48477. manuallyHideTip: function (tooltipModel, ecModel, api, payload) {
  48478. var tooltipContent = this._tooltipContent;
  48479. if (!this._alwaysShowContent) {
  48480. tooltipContent.hideLater(this._tooltipModel.get('hideDelay'));
  48481. }
  48482. this._lastX = this._lastY = null;
  48483. if (payload.from !== this.uid) {
  48484. this._hide(makeDispatchAction(payload, api));
  48485. }
  48486. },
  48487. // Be compatible with previous design, that is, when tooltip.type is 'axis' and
  48488. // dispatchAction 'showTip' with seriesIndex and dataIndex will trigger axis pointer
  48489. // and tooltip.
  48490. _manuallyAxisShowTip: function (tooltipModel, ecModel, api, payload) {
  48491. var seriesIndex = payload.seriesIndex;
  48492. var dataIndex = payload.dataIndex;
  48493. var coordSysAxesInfo = ecModel.getComponent('axisPointer').coordSysAxesInfo;
  48494. if (seriesIndex == null || dataIndex == null || coordSysAxesInfo == null) {
  48495. return;
  48496. }
  48497. var seriesModel = ecModel.getSeriesByIndex(seriesIndex);
  48498. if (!seriesModel) {
  48499. return;
  48500. }
  48501. var data = seriesModel.getData();
  48502. var tooltipModel = buildTooltipModel([
  48503. data.getItemModel(dataIndex),
  48504. seriesModel,
  48505. (seriesModel.coordinateSystem || {}).model,
  48506. tooltipModel
  48507. ]);
  48508. if (tooltipModel.get('trigger') !== 'axis') {
  48509. return;
  48510. }
  48511. api.dispatchAction({
  48512. type: 'updateAxisPointer',
  48513. seriesIndex: seriesIndex,
  48514. dataIndex: dataIndex
  48515. });
  48516. return true;
  48517. },
  48518. _tryShow: function (e, dispatchAction) {
  48519. var el = e.target;
  48520. var tooltipModel = this._tooltipModel;
  48521. if (!tooltipModel) {
  48522. return;
  48523. }
  48524. // Save mouse x, mouse y. So we can try to keep showing the tip if chart is refreshed
  48525. this._lastX = e.offsetX;
  48526. this._lastY = e.offsetY;
  48527. var dataByCoordSys = e.dataByCoordSys;
  48528. if (dataByCoordSys && dataByCoordSys.length) {
  48529. this._showAxisTooltip(dataByCoordSys, e);
  48530. }
  48531. // Always show item tooltip if mouse is on the element with dataIndex
  48532. else if (el && el.dataIndex != null) {
  48533. this._lastDataByCoordSys = null;
  48534. this._showSeriesItemTooltip(e, el, dispatchAction);
  48535. }
  48536. // Tooltip provided directly. Like legend.
  48537. else if (el && el.tooltip) {
  48538. this._lastDataByCoordSys = null;
  48539. this._showComponentItemTooltip(e, el, dispatchAction);
  48540. }
  48541. else {
  48542. this._lastDataByCoordSys = null;
  48543. this._hide(dispatchAction);
  48544. }
  48545. },
  48546. _showOrMove: function (tooltipModel, cb) {
  48547. // showDelay is used in this case: tooltip.enterable is set
  48548. // as true. User intent to move mouse into tooltip and click
  48549. // something. `showDelay` makes it easyer to enter the content
  48550. // but tooltip do not move immediately.
  48551. var delay = tooltipModel.get('showDelay');
  48552. cb = zrUtil.bind(cb, this);
  48553. clearTimeout(this._showTimout);
  48554. delay > 0
  48555. ? (this._showTimout = setTimeout(cb, delay))
  48556. : cb();
  48557. },
  48558. _showAxisTooltip: function (dataByCoordSys, e) {
  48559. var ecModel = this._ecModel;
  48560. var globalTooltipModel = this._tooltipModel;
  48561. var point = [e.offsetX, e.offsetY];
  48562. var singleDefaultHTML = [];
  48563. var singleParamsList = [];
  48564. var singleTooltipModel = buildTooltipModel([
  48565. e.tooltipOption,
  48566. globalTooltipModel
  48567. ]);
  48568. each(dataByCoordSys, function (itemCoordSys) {
  48569. // var coordParamList = [];
  48570. // var coordDefaultHTML = [];
  48571. // var coordTooltipModel = buildTooltipModel([
  48572. // e.tooltipOption,
  48573. // itemCoordSys.tooltipOption,
  48574. // ecModel.getComponent(itemCoordSys.coordSysMainType, itemCoordSys.coordSysIndex),
  48575. // globalTooltipModel
  48576. // ]);
  48577. // var displayMode = coordTooltipModel.get('displayMode');
  48578. // var paramsList = displayMode === 'single' ? singleParamsList : [];
  48579. each(itemCoordSys.dataByAxis, function (item) {
  48580. var axisModel = ecModel.getComponent(item.axisDim + 'Axis', item.axisIndex);
  48581. var axisValue = item.value;
  48582. var seriesDefaultHTML = [];
  48583. if (!axisModel || axisValue == null) {
  48584. return;
  48585. }
  48586. var valueLabel = axisPointerViewHelper.getValueLabel(
  48587. axisValue, axisModel.axis, ecModel,
  48588. item.seriesDataIndices,
  48589. item.valueLabelOpt
  48590. );
  48591. zrUtil.each(item.seriesDataIndices, function (idxItem) {
  48592. var series = ecModel.getSeriesByIndex(idxItem.seriesIndex);
  48593. var dataIndex = idxItem.dataIndexInside;
  48594. var dataParams = series && series.getDataParams(dataIndex);
  48595. dataParams.axisDim = item.axisDim;
  48596. dataParams.axisIndex = item.axisIndex;
  48597. dataParams.axisType = item.axisType;
  48598. dataParams.axisId = item.axisId;
  48599. dataParams.axisValue = axisHelper.getAxisRawValue(axisModel.axis, axisValue);
  48600. dataParams.axisValueLabel = valueLabel;
  48601. if (dataParams) {
  48602. singleParamsList.push(dataParams);
  48603. seriesDefaultHTML.push(series.formatTooltip(dataIndex, true));
  48604. }
  48605. });
  48606. // Default tooltip content
  48607. // FIXME
  48608. // (1) shold be the first data which has name?
  48609. // (2) themeRiver, firstDataIndex is array, and first line is unnecessary.
  48610. var firstLine = valueLabel;
  48611. singleDefaultHTML.push(
  48612. (firstLine ? formatUtil.encodeHTML(firstLine) + '<br />' : '')
  48613. + seriesDefaultHTML.join('<br />')
  48614. );
  48615. });
  48616. }, this);
  48617. // In most case, the second axis is shown upper than the first one.
  48618. singleDefaultHTML.reverse();
  48619. singleDefaultHTML = singleDefaultHTML.join('<br /><br />');
  48620. var positionExpr = e.position;
  48621. this._showOrMove(singleTooltipModel, function () {
  48622. if (this._updateContentNotChangedOnAxis(dataByCoordSys)) {
  48623. this._updatePosition(
  48624. singleTooltipModel,
  48625. positionExpr,
  48626. point[0], point[1],
  48627. this._tooltipContent,
  48628. singleParamsList
  48629. );
  48630. }
  48631. else {
  48632. this._showTooltipContent(
  48633. singleTooltipModel, singleDefaultHTML, singleParamsList, Math.random(),
  48634. point[0], point[1], positionExpr
  48635. );
  48636. }
  48637. });
  48638. // Do not trigger events here, because this branch only be entered
  48639. // from dispatchAction.
  48640. },
  48641. _showSeriesItemTooltip: function (e, el, dispatchAction) {
  48642. var ecModel = this._ecModel;
  48643. // Use dataModel in element if possible
  48644. // Used when mouseover on a element like markPoint or edge
  48645. // In which case, the data is not main data in series.
  48646. var seriesIndex = el.seriesIndex;
  48647. var seriesModel = ecModel.getSeriesByIndex(seriesIndex);
  48648. // For example, graph link.
  48649. var dataModel = el.dataModel || seriesModel;
  48650. var dataIndex = el.dataIndex;
  48651. var dataType = el.dataType;
  48652. var data = dataModel.getData();
  48653. var tooltipModel = buildTooltipModel([
  48654. data.getItemModel(dataIndex),
  48655. dataModel,
  48656. seriesModel && (seriesModel.coordinateSystem || {}).model,
  48657. this._tooltipModel
  48658. ]);
  48659. var tooltipTrigger = tooltipModel.get('trigger');
  48660. if (tooltipTrigger != null && tooltipTrigger !== 'item') {
  48661. return;
  48662. }
  48663. var params = dataModel.getDataParams(dataIndex, dataType);
  48664. var defaultHtml = dataModel.formatTooltip(dataIndex, false, dataType);
  48665. var asyncTicket = 'item_' + dataModel.name + '_' + dataIndex;
  48666. this._showOrMove(tooltipModel, function () {
  48667. this._showTooltipContent(
  48668. tooltipModel, defaultHtml, params, asyncTicket,
  48669. e.offsetX, e.offsetY, e.position, e.target
  48670. );
  48671. });
  48672. // FIXME
  48673. // duplicated showtip if manuallyShowTip is called from dispatchAction.
  48674. dispatchAction({
  48675. type: 'showTip',
  48676. dataIndexInside: dataIndex,
  48677. dataIndex: data.getRawIndex(dataIndex),
  48678. seriesIndex: seriesIndex,
  48679. from: this.uid
  48680. });
  48681. },
  48682. _showComponentItemTooltip: function (e, el, dispatchAction) {
  48683. var tooltipOpt = el.tooltip;
  48684. if (typeof tooltipOpt === 'string') {
  48685. var content = tooltipOpt;
  48686. tooltipOpt = {
  48687. content: content,
  48688. // Fixed formatter
  48689. formatter: content
  48690. };
  48691. }
  48692. var subTooltipModel = new Model(tooltipOpt, this._tooltipModel, this._ecModel);
  48693. var defaultHtml = subTooltipModel.get('content');
  48694. var asyncTicket = Math.random();
  48695. // Do not check whether `trigger` is 'none' here, because `trigger`
  48696. // only works on cooridinate system. In fact, we have not found case
  48697. // that requires setting `trigger` nothing on component yet.
  48698. this._showOrMove(subTooltipModel, function () {
  48699. this._showTooltipContent(
  48700. subTooltipModel, defaultHtml, subTooltipModel.get('formatterParams') || {},
  48701. asyncTicket, e.offsetX, e.offsetY, e.position, el
  48702. );
  48703. });
  48704. // If not dispatch showTip, tip may be hide triggered by axis.
  48705. dispatchAction({
  48706. type: 'showTip',
  48707. from: this.uid
  48708. });
  48709. },
  48710. _showTooltipContent: function (
  48711. tooltipModel, defaultHtml, params, asyncTicket, x, y, positionExpr, el
  48712. ) {
  48713. // Reset ticket
  48714. this._ticket = '';
  48715. if (!tooltipModel.get('showContent') || !tooltipModel.get('show')) {
  48716. return;
  48717. }
  48718. var tooltipContent = this._tooltipContent;
  48719. var formatter = tooltipModel.get('formatter');
  48720. positionExpr = positionExpr || tooltipModel.get('position');
  48721. var html = defaultHtml;
  48722. if (formatter && typeof formatter === 'string') {
  48723. html = formatUtil.formatTpl(formatter, params, true);
  48724. }
  48725. else if (typeof formatter === 'function') {
  48726. var callback = bind(function (cbTicket, html) {
  48727. if (cbTicket === this._ticket) {
  48728. tooltipContent.setContent(html);
  48729. this._updatePosition(
  48730. tooltipModel, positionExpr, x, y, tooltipContent, params, el
  48731. );
  48732. }
  48733. }, this);
  48734. this._ticket = asyncTicket;
  48735. html = formatter(params, asyncTicket, callback);
  48736. }
  48737. tooltipContent.setContent(html);
  48738. tooltipContent.show(tooltipModel);
  48739. this._updatePosition(
  48740. tooltipModel, positionExpr, x, y, tooltipContent, params, el
  48741. );
  48742. },
  48743. /**
  48744. * @param {string|Function|Array.<number>} positionExpr
  48745. * @param {number} x Mouse x
  48746. * @param {number} y Mouse y
  48747. * @param {boolean} confine Whether confine tooltip content in view rect.
  48748. * @param {Object|<Array.<Object>} params
  48749. * @param {module:zrender/Element} el target element
  48750. * @param {module:echarts/ExtensionAPI} api
  48751. * @return {Array.<number>}
  48752. */
  48753. _updatePosition: function (tooltipModel, positionExpr, x, y, content, params, el) {
  48754. var viewWidth = this._api.getWidth();
  48755. var viewHeight = this._api.getHeight();
  48756. positionExpr = positionExpr || tooltipModel.get('position');
  48757. var contentSize = content.getSize();
  48758. var align = tooltipModel.get('align');
  48759. var vAlign = tooltipModel.get('verticalAlign');
  48760. var rect = el && el.getBoundingRect().clone();
  48761. el && rect.applyTransform(el.transform);
  48762. if (typeof positionExpr === 'function') {
  48763. // Callback of position can be an array or a string specify the position
  48764. positionExpr = positionExpr([x, y], params, content.el, rect, {
  48765. viewSize: [viewWidth, viewHeight],
  48766. contentSize: contentSize.slice()
  48767. });
  48768. }
  48769. if (zrUtil.isArray(positionExpr)) {
  48770. x = parsePercent(positionExpr[0], viewWidth);
  48771. y = parsePercent(positionExpr[1], viewHeight);
  48772. }
  48773. else if (zrUtil.isObject(positionExpr)) {
  48774. positionExpr.width = contentSize[0];
  48775. positionExpr.height = contentSize[1];
  48776. var layoutRect = layoutUtil.getLayoutRect(
  48777. positionExpr, {width: viewWidth, height: viewHeight}
  48778. );
  48779. x = layoutRect.x;
  48780. y = layoutRect.y;
  48781. align = null;
  48782. // When positionExpr is left/top/right/bottom,
  48783. // align and verticalAlign will not work.
  48784. vAlign = null;
  48785. }
  48786. // Specify tooltip position by string 'top' 'bottom' 'left' 'right' around graphic element
  48787. else if (typeof positionExpr === 'string' && el) {
  48788. var pos = calcTooltipPosition(
  48789. positionExpr, rect, contentSize
  48790. );
  48791. x = pos[0];
  48792. y = pos[1];
  48793. }
  48794. else {
  48795. var pos = refixTooltipPosition(
  48796. x, y, content.el, viewWidth, viewHeight, align ? null : 20, vAlign ? null : 20
  48797. );
  48798. x = pos[0];
  48799. y = pos[1];
  48800. }
  48801. align && (x -= isCenterAlign(align) ? contentSize[0] / 2 : align === 'right' ? contentSize[0] : 0);
  48802. vAlign && (y -= isCenterAlign(vAlign) ? contentSize[1] / 2 : vAlign === 'bottom' ? contentSize[1] : 0);
  48803. if (tooltipModel.get('confine')) {
  48804. var pos = confineTooltipPosition(
  48805. x, y, content.el, viewWidth, viewHeight
  48806. );
  48807. x = pos[0];
  48808. y = pos[1];
  48809. }
  48810. content.moveTo(x, y);
  48811. },
  48812. // FIXME
  48813. // Should we remove this but leave this to user?
  48814. _updateContentNotChangedOnAxis: function (dataByCoordSys) {
  48815. var lastCoordSys = this._lastDataByCoordSys;
  48816. var contentNotChanged = !!lastCoordSys
  48817. && lastCoordSys.length === dataByCoordSys.length;
  48818. contentNotChanged && each(lastCoordSys, function (lastItemCoordSys, indexCoordSys) {
  48819. var lastDataByAxis = lastItemCoordSys.dataByAxis || {};
  48820. var thisItemCoordSys = dataByCoordSys[indexCoordSys] || {};
  48821. var thisDataByAxis = thisItemCoordSys.dataByAxis || [];
  48822. contentNotChanged &= lastDataByAxis.length === thisDataByAxis.length;
  48823. contentNotChanged && each(lastDataByAxis, function (lastItem, indexAxis) {
  48824. var thisItem = thisDataByAxis[indexAxis] || {};
  48825. var lastIndices = lastItem.seriesDataIndices || [];
  48826. var newIndices = thisItem.seriesDataIndices || [];
  48827. contentNotChanged &=
  48828. lastItem.value === thisItem.value
  48829. && lastItem.axisType === thisItem.axisType
  48830. && lastItem.axisId === thisItem.axisId
  48831. && lastIndices.length === newIndices.length;
  48832. contentNotChanged && each(lastIndices, function (lastIdxItem, j) {
  48833. var newIdxItem = newIndices[j];
  48834. contentNotChanged &=
  48835. lastIdxItem.seriesIndex === newIdxItem.seriesIndex
  48836. && lastIdxItem.dataIndex === newIdxItem.dataIndex;
  48837. });
  48838. });
  48839. });
  48840. this._lastDataByCoordSys = dataByCoordSys;
  48841. return !!contentNotChanged;
  48842. },
  48843. _hide: function (dispatchAction) {
  48844. // Do not directly hideLater here, because this behavior may be prevented
  48845. // in dispatchAction when showTip is dispatched.
  48846. // FIXME
  48847. // duplicated hideTip if manuallyHideTip is called from dispatchAction.
  48848. this._lastDataByCoordSys = null;
  48849. dispatchAction({
  48850. type: 'hideTip',
  48851. from: this.uid
  48852. });
  48853. },
  48854. dispose: function (ecModel, api) {
  48855. if (env.node) {
  48856. return;
  48857. }
  48858. this._tooltipContent.hide();
  48859. globalListener.unregister('itemTooltip', api);
  48860. }
  48861. });
  48862. /**
  48863. * @param {Array.<Object|module:echarts/model/Model>} modelCascade
  48864. * From top to bottom. (the last one should be globalTooltipModel);
  48865. */
  48866. function buildTooltipModel(modelCascade) {
  48867. var resultModel = modelCascade.pop();
  48868. while (modelCascade.length) {
  48869. var tooltipOpt = modelCascade.pop();
  48870. if (tooltipOpt) {
  48871. if (tooltipOpt instanceof Model) {
  48872. tooltipOpt = tooltipOpt.get('tooltip', true);
  48873. }
  48874. // In each data item tooltip can be simply write:
  48875. // {
  48876. // value: 10,
  48877. // tooltip: 'Something you need to know'
  48878. // }
  48879. if (typeof tooltipOpt === 'string') {
  48880. tooltipOpt = {formatter: tooltipOpt};
  48881. }
  48882. resultModel = new Model(tooltipOpt, resultModel, resultModel.ecModel);
  48883. }
  48884. }
  48885. return resultModel;
  48886. }
  48887. function makeDispatchAction(payload, api) {
  48888. return payload.dispatchAction || zrUtil.bind(api.dispatchAction, api);
  48889. }
  48890. function refixTooltipPosition(x, y, el, viewWidth, viewHeight, gapH, gapV) {
  48891. var width = el.clientWidth;
  48892. var height = el.clientHeight;
  48893. if (gapH != null) {
  48894. if (x + width + gapH > viewWidth) {
  48895. x -= width + gapH;
  48896. }
  48897. else {
  48898. x += gapH;
  48899. }
  48900. }
  48901. if (gapV != null) {
  48902. if (y + height + gapV > viewHeight) {
  48903. y -= height + gapV;
  48904. }
  48905. else {
  48906. y += gapV;
  48907. }
  48908. }
  48909. return [x, y];
  48910. }
  48911. function confineTooltipPosition(x, y, el, viewWidth, viewHeight) {
  48912. var width = el.clientWidth;
  48913. var height = el.clientHeight;
  48914. x = Math.min(x + width, viewWidth) - width;
  48915. y = Math.min(y + height, viewHeight) - height;
  48916. x = Math.max(x, 0);
  48917. y = Math.max(y, 0);
  48918. return [x, y];
  48919. }
  48920. function calcTooltipPosition(position, rect, contentSize) {
  48921. var domWidth = contentSize[0];
  48922. var domHeight = contentSize[1];
  48923. var gap = 5;
  48924. var x = 0;
  48925. var y = 0;
  48926. var rectWidth = rect.width;
  48927. var rectHeight = rect.height;
  48928. switch (position) {
  48929. case 'inside':
  48930. x = rect.x + rectWidth / 2 - domWidth / 2;
  48931. y = rect.y + rectHeight / 2 - domHeight / 2;
  48932. break;
  48933. case 'top':
  48934. x = rect.x + rectWidth / 2 - domWidth / 2;
  48935. y = rect.y - domHeight - gap;
  48936. break;
  48937. case 'bottom':
  48938. x = rect.x + rectWidth / 2 - domWidth / 2;
  48939. y = rect.y + rectHeight + gap;
  48940. break;
  48941. case 'left':
  48942. x = rect.x - domWidth - gap;
  48943. y = rect.y + rectHeight / 2 - domHeight / 2;
  48944. break;
  48945. case 'right':
  48946. x = rect.x + rectWidth + gap;
  48947. y = rect.y + rectHeight / 2 - domHeight / 2;
  48948. }
  48949. return [x, y];
  48950. }
  48951. function isCenterAlign(align) {
  48952. return align === 'center' || align === 'middle';
  48953. }
  48954. /***/ },
  48955. /* 329 */
  48956. /***/ function(module, exports, __webpack_require__) {
  48957. /**
  48958. * @module echarts/component/tooltip/TooltipContent
  48959. */
  48960. var zrUtil = __webpack_require__(4);
  48961. var zrColor = __webpack_require__(31);
  48962. var eventUtil = __webpack_require__(88);
  48963. var formatUtil = __webpack_require__(6);
  48964. var each = zrUtil.each;
  48965. var toCamelCase = formatUtil.toCamelCase;
  48966. var env = __webpack_require__(2);
  48967. var vendors = ['', '-webkit-', '-moz-', '-o-'];
  48968. var gCssText = 'position:absolute;display:block;border-style:solid;white-space:nowrap;z-index:9999999;';
  48969. /**
  48970. * @param {number} duration
  48971. * @return {string}
  48972. * @inner
  48973. */
  48974. function assembleTransition(duration) {
  48975. var transitionCurve = 'cubic-bezier(0.23, 1, 0.32, 1)';
  48976. var transitionText = 'left ' + duration + 's ' + transitionCurve + ','
  48977. + 'top ' + duration + 's ' + transitionCurve;
  48978. return zrUtil.map(vendors, function (vendorPrefix) {
  48979. return vendorPrefix + 'transition:' + transitionText;
  48980. }).join(';');
  48981. }
  48982. /**
  48983. * @param {Object} textStyle
  48984. * @return {string}
  48985. * @inner
  48986. */
  48987. function assembleFont(textStyleModel) {
  48988. var cssText = [];
  48989. var fontSize = textStyleModel.get('fontSize');
  48990. var color = textStyleModel.getTextColor();
  48991. color && cssText.push('color:' + color);
  48992. cssText.push('font:' + textStyleModel.getFont());
  48993. fontSize &&
  48994. cssText.push('line-height:' + Math.round(fontSize * 3 / 2) + 'px');
  48995. each(['decoration', 'align'], function (name) {
  48996. var val = textStyleModel.get(name);
  48997. val && cssText.push('text-' + name + ':' + val);
  48998. });
  48999. return cssText.join(';');
  49000. }
  49001. /**
  49002. * @param {Object} tooltipModel
  49003. * @return {string}
  49004. * @inner
  49005. */
  49006. function assembleCssText(tooltipModel) {
  49007. var cssText = [];
  49008. var transitionDuration = tooltipModel.get('transitionDuration');
  49009. var backgroundColor = tooltipModel.get('backgroundColor');
  49010. var textStyleModel = tooltipModel.getModel('textStyle');
  49011. var padding = tooltipModel.get('padding');
  49012. // Animation transition. Do not animate when transitionDuration is 0.
  49013. transitionDuration &&
  49014. cssText.push(assembleTransition(transitionDuration));
  49015. if (backgroundColor) {
  49016. if (env.canvasSupported) {
  49017. cssText.push('background-Color:' + backgroundColor);
  49018. }
  49019. else {
  49020. // for ie
  49021. cssText.push(
  49022. 'background-Color:#' + zrColor.toHex(backgroundColor)
  49023. );
  49024. cssText.push('filter:alpha(opacity=70)');
  49025. }
  49026. }
  49027. // Border style
  49028. each(['width', 'color', 'radius'], function (name) {
  49029. var borderName = 'border-' + name;
  49030. var camelCase = toCamelCase(borderName);
  49031. var val = tooltipModel.get(camelCase);
  49032. val != null &&
  49033. cssText.push(borderName + ':' + val + (name === 'color' ? '' : 'px'));
  49034. });
  49035. // Text style
  49036. cssText.push(assembleFont(textStyleModel));
  49037. // Padding
  49038. if (padding != null) {
  49039. cssText.push('padding:' + formatUtil.normalizeCssArray(padding).join('px ') + 'px');
  49040. }
  49041. return cssText.join(';') + ';';
  49042. }
  49043. /**
  49044. * @alias module:echarts/component/tooltip/TooltipContent
  49045. * @constructor
  49046. */
  49047. function TooltipContent(container, api) {
  49048. var el = document.createElement('div');
  49049. var zr = this._zr = api.getZr();
  49050. this.el = el;
  49051. this._x = api.getWidth() / 2;
  49052. this._y = api.getHeight() / 2;
  49053. container.appendChild(el);
  49054. this._container = container;
  49055. this._show = false;
  49056. /**
  49057. * @private
  49058. */
  49059. this._hideTimeout;
  49060. var self = this;
  49061. el.onmouseenter = function () {
  49062. // clear the timeout in hideLater and keep showing tooltip
  49063. if (self._enterable) {
  49064. clearTimeout(self._hideTimeout);
  49065. self._show = true;
  49066. }
  49067. self._inContent = true;
  49068. };
  49069. el.onmousemove = function (e) {
  49070. e = e || window.event;
  49071. if (!self._enterable) {
  49072. // Try trigger zrender event to avoid mouse
  49073. // in and out shape too frequently
  49074. var handler = zr.handler;
  49075. eventUtil.normalizeEvent(container, e, true);
  49076. handler.dispatch('mousemove', e);
  49077. }
  49078. };
  49079. el.onmouseleave = function () {
  49080. if (self._enterable) {
  49081. if (self._show) {
  49082. self.hideLater(self._hideDelay);
  49083. }
  49084. }
  49085. self._inContent = false;
  49086. };
  49087. }
  49088. TooltipContent.prototype = {
  49089. constructor: TooltipContent,
  49090. /**
  49091. * @private
  49092. * @type {boolean}
  49093. */
  49094. _enterable: true,
  49095. /**
  49096. * Update when tooltip is rendered
  49097. */
  49098. update: function () {
  49099. // FIXME
  49100. // Move this logic to ec main?
  49101. var container = this._container;
  49102. var stl = container.currentStyle
  49103. || document.defaultView.getComputedStyle(container);
  49104. var domStyle = container.style;
  49105. if (domStyle.position !== 'absolute' && stl.position !== 'absolute') {
  49106. domStyle.position = 'relative';
  49107. }
  49108. // Hide the tooltip
  49109. // PENDING
  49110. // this.hide();
  49111. },
  49112. show: function (tooltipModel) {
  49113. clearTimeout(this._hideTimeout);
  49114. var el = this.el;
  49115. el.style.cssText = gCssText + assembleCssText(tooltipModel)
  49116. // http://stackoverflow.com/questions/21125587/css3-transition-not-working-in-chrome-anymore
  49117. + ';left:' + this._x + 'px;top:' + this._y + 'px;'
  49118. + (tooltipModel.get('extraCssText') || '');
  49119. el.style.display = el.innerHTML ? 'block' : 'none';
  49120. this._show = true;
  49121. },
  49122. setContent: function (content) {
  49123. this.el.innerHTML = content == null ? '' : content;
  49124. },
  49125. setEnterable: function (enterable) {
  49126. this._enterable = enterable;
  49127. },
  49128. getSize: function () {
  49129. var el = this.el;
  49130. return [el.clientWidth, el.clientHeight];
  49131. },
  49132. moveTo: function (x, y) {
  49133. // xy should be based on canvas root. But tooltipContent is
  49134. // the sibling of canvas root. So padding of ec container
  49135. // should be considered here.
  49136. var zr = this._zr;
  49137. var viewportRoot;
  49138. if (zr && zr.painter && (viewportRoot = zr.painter.getViewportRoot())) {
  49139. x += viewportRoot.offsetLeft || 0;
  49140. y += viewportRoot.offsetTop || 0;
  49141. }
  49142. var style = this.el.style;
  49143. style.left = x + 'px';
  49144. style.top = y + 'px';
  49145. this._x = x;
  49146. this._y = y;
  49147. },
  49148. hide: function () {
  49149. this.el.style.display = 'none';
  49150. this._show = false;
  49151. },
  49152. hideLater: function (time) {
  49153. if (this._show && !(this._inContent && this._enterable)) {
  49154. if (time) {
  49155. this._hideDelay = time;
  49156. // Set show false to avoid invoke hideLater mutiple times
  49157. this._show = false;
  49158. this._hideTimeout = setTimeout(zrUtil.bind(this.hide, this), time);
  49159. }
  49160. else {
  49161. this.hide();
  49162. }
  49163. }
  49164. },
  49165. isShow: function () {
  49166. return this._show;
  49167. }
  49168. };
  49169. module.exports = TooltipContent;
  49170. /***/ },
  49171. /* 330 */
  49172. /***/ function(module, exports, __webpack_require__) {
  49173. 'use strict';
  49174. var zrUtil = __webpack_require__(4);
  49175. __webpack_require__(331);
  49176. __webpack_require__(337);
  49177. __webpack_require__(339);
  49178. __webpack_require__(297);
  49179. __webpack_require__(341);
  49180. // For reducing size of echarts.min, barLayoutPolar is required by polar.
  49181. __webpack_require__(1).registerLayout(zrUtil.curry(__webpack_require__(342), 'bar'));
  49182. // Polar view
  49183. __webpack_require__(1).extendComponentView({
  49184. type: 'polar'
  49185. });
  49186. /***/ },
  49187. /* 331 */
  49188. /***/ function(module, exports, __webpack_require__) {
  49189. // TODO Axis scale
  49190. var Polar = __webpack_require__(332);
  49191. var numberUtil = __webpack_require__(7);
  49192. var zrUtil = __webpack_require__(4);
  49193. var axisHelper = __webpack_require__(101);
  49194. var niceScaleExtent = axisHelper.niceScaleExtent;
  49195. // 依赖 PolarModel 做预处理
  49196. __webpack_require__(335);
  49197. /**
  49198. * Resize method bound to the polar
  49199. * @param {module:echarts/coord/polar/PolarModel} polarModel
  49200. * @param {module:echarts/ExtensionAPI} api
  49201. */
  49202. function resizePolar(polarModel, api) {
  49203. var center = polarModel.get('center');
  49204. var radius = polarModel.get('radius');
  49205. var width = api.getWidth();
  49206. var height = api.getHeight();
  49207. var parsePercent = numberUtil.parsePercent;
  49208. this.cx = parsePercent(center[0], width);
  49209. this.cy = parsePercent(center[1], height);
  49210. var radiusAxis = this.getRadiusAxis();
  49211. var size = Math.min(width, height) / 2;
  49212. // var idx = radiusAxis.inverse ? 1 : 0;
  49213. radiusAxis.setExtent(0, parsePercent(radius, size));
  49214. }
  49215. /**
  49216. * Update polar
  49217. */
  49218. function updatePolarScale(ecModel, api) {
  49219. var polar = this;
  49220. var angleAxis = polar.getAngleAxis();
  49221. var radiusAxis = polar.getRadiusAxis();
  49222. // Reset scale
  49223. angleAxis.scale.setExtent(Infinity, -Infinity);
  49224. radiusAxis.scale.setExtent(Infinity, -Infinity);
  49225. ecModel.eachSeries(function (seriesModel) {
  49226. if (seriesModel.coordinateSystem === polar) {
  49227. var data = seriesModel.getData();
  49228. radiusAxis.scale.unionExtentFromData(data, 'radius');
  49229. angleAxis.scale.unionExtentFromData(data, 'angle');
  49230. }
  49231. });
  49232. niceScaleExtent(angleAxis.scale, angleAxis.model);
  49233. niceScaleExtent(radiusAxis.scale, radiusAxis.model);
  49234. // Fix extent of category angle axis
  49235. if (angleAxis.type === 'category' && !angleAxis.onBand) {
  49236. var extent = angleAxis.getExtent();
  49237. var diff = 360 / angleAxis.scale.count();
  49238. angleAxis.inverse ? (extent[1] += diff) : (extent[1] -= diff);
  49239. angleAxis.setExtent(extent[0], extent[1]);
  49240. }
  49241. }
  49242. /**
  49243. * Set common axis properties
  49244. * @param {module:echarts/coord/polar/AngleAxis|module:echarts/coord/polar/RadiusAxis}
  49245. * @param {module:echarts/coord/polar/AxisModel}
  49246. * @inner
  49247. */
  49248. function setAxis(axis, axisModel) {
  49249. axis.type = axisModel.get('type');
  49250. axis.scale = axisHelper.createScaleByModel(axisModel);
  49251. axis.onBand = axisModel.get('boundaryGap') && axis.type === 'category';
  49252. // FIXME Radius axis not support inverse axis
  49253. if (axisModel.mainType === 'angleAxis') {
  49254. var startAngle = axisModel.get('startAngle');
  49255. axis.inverse = axisModel.get('inverse') ^ axisModel.get('clockwise');
  49256. axis.setExtent(startAngle, startAngle + (axis.inverse ? -360 : 360));
  49257. }
  49258. // Inject axis instance
  49259. axisModel.axis = axis;
  49260. axis.model = axisModel;
  49261. }
  49262. var polarCreator = {
  49263. dimensions: Polar.prototype.dimensions,
  49264. create: function (ecModel, api) {
  49265. var polarList = [];
  49266. ecModel.eachComponent('polar', function (polarModel, idx) {
  49267. var polar = new Polar(idx);
  49268. // Inject resize and update method
  49269. polar.resize = resizePolar;
  49270. polar.update = updatePolarScale;
  49271. var radiusAxis = polar.getRadiusAxis();
  49272. var angleAxis = polar.getAngleAxis();
  49273. var radiusAxisModel = polarModel.findAxisModel('radiusAxis');
  49274. var angleAxisModel = polarModel.findAxisModel('angleAxis');
  49275. setAxis(radiusAxis, radiusAxisModel);
  49276. setAxis(angleAxis, angleAxisModel);
  49277. polar.resize(polarModel, api);
  49278. polarList.push(polar);
  49279. polarModel.coordinateSystem = polar;
  49280. polar.model = polarModel;
  49281. });
  49282. // Inject coordinateSystem to series
  49283. ecModel.eachSeries(function (seriesModel) {
  49284. if (seriesModel.get('coordinateSystem') === 'polar') {
  49285. var polarModel = ecModel.queryComponents({
  49286. mainType: 'polar',
  49287. index: seriesModel.get('polarIndex'),
  49288. id: seriesModel.get('polarId')
  49289. })[0];
  49290. if (true) {
  49291. if (!polarModel) {
  49292. throw new Error(
  49293. 'Polar "' + zrUtil.retrieve(
  49294. seriesModel.get('polarIndex'),
  49295. seriesModel.get('polarId'),
  49296. 0
  49297. ) + '" not found'
  49298. );
  49299. }
  49300. }
  49301. seriesModel.coordinateSystem = polarModel.coordinateSystem;
  49302. }
  49303. });
  49304. return polarList;
  49305. }
  49306. };
  49307. __webpack_require__(76).register('polar', polarCreator);
  49308. /***/ },
  49309. /* 332 */
  49310. /***/ function(module, exports, __webpack_require__) {
  49311. 'use strict';
  49312. /**
  49313. * @module echarts/coord/polar/Polar
  49314. */
  49315. var RadiusAxis = __webpack_require__(333);
  49316. var AngleAxis = __webpack_require__(334);
  49317. /**
  49318. * @alias {module:echarts/coord/polar/Polar}
  49319. * @constructor
  49320. * @param {string} name
  49321. */
  49322. var Polar = function (name) {
  49323. /**
  49324. * @type {string}
  49325. */
  49326. this.name = name || '';
  49327. /**
  49328. * x of polar center
  49329. * @type {number}
  49330. */
  49331. this.cx = 0;
  49332. /**
  49333. * y of polar center
  49334. * @type {number}
  49335. */
  49336. this.cy = 0;
  49337. /**
  49338. * @type {module:echarts/coord/polar/RadiusAxis}
  49339. * @private
  49340. */
  49341. this._radiusAxis = new RadiusAxis();
  49342. /**
  49343. * @type {module:echarts/coord/polar/AngleAxis}
  49344. * @private
  49345. */
  49346. this._angleAxis = new AngleAxis();
  49347. this._radiusAxis.polar = this._angleAxis.polar = this;
  49348. };
  49349. Polar.prototype = {
  49350. type: 'polar',
  49351. axisPointerEnabled: true,
  49352. constructor: Polar,
  49353. /**
  49354. * @param {Array.<string>}
  49355. * @readOnly
  49356. */
  49357. dimensions: ['radius', 'angle'],
  49358. /**
  49359. * @type {module:echarts/coord/PolarModel}
  49360. */
  49361. model: null,
  49362. /**
  49363. * If contain coord
  49364. * @param {Array.<number>} point
  49365. * @return {boolean}
  49366. */
  49367. containPoint: function (point) {
  49368. var coord = this.pointToCoord(point);
  49369. return this._radiusAxis.contain(coord[0])
  49370. && this._angleAxis.contain(coord[1]);
  49371. },
  49372. /**
  49373. * If contain data
  49374. * @param {Array.<number>} data
  49375. * @return {boolean}
  49376. */
  49377. containData: function (data) {
  49378. return this._radiusAxis.containData(data[0])
  49379. && this._angleAxis.containData(data[1]);
  49380. },
  49381. /**
  49382. * @param {string} dim
  49383. * @return {module:echarts/coord/polar/AngleAxis|module:echarts/coord/polar/RadiusAxis}
  49384. */
  49385. getAxis: function (dim) {
  49386. return this['_' + dim + 'Axis'];
  49387. },
  49388. /**
  49389. * @return {Array.<module:echarts/coord/Axis>}
  49390. */
  49391. getAxes: function () {
  49392. return [this._radiusAxis, this._angleAxis];
  49393. },
  49394. /**
  49395. * Get axes by type of scale
  49396. * @param {string} scaleType
  49397. * @return {module:echarts/coord/polar/AngleAxis|module:echarts/coord/polar/RadiusAxis}
  49398. */
  49399. getAxesByScale: function (scaleType) {
  49400. var axes = [];
  49401. var angleAxis = this._angleAxis;
  49402. var radiusAxis = this._radiusAxis;
  49403. angleAxis.scale.type === scaleType && axes.push(angleAxis);
  49404. radiusAxis.scale.type === scaleType && axes.push(radiusAxis);
  49405. return axes;
  49406. },
  49407. /**
  49408. * @return {module:echarts/coord/polar/AngleAxis}
  49409. */
  49410. getAngleAxis: function () {
  49411. return this._angleAxis;
  49412. },
  49413. /**
  49414. * @return {module:echarts/coord/polar/RadiusAxis}
  49415. */
  49416. getRadiusAxis: function () {
  49417. return this._radiusAxis;
  49418. },
  49419. /**
  49420. * @param {module:echarts/coord/polar/Axis}
  49421. * @return {module:echarts/coord/polar/Axis}
  49422. */
  49423. getOtherAxis: function (axis) {
  49424. var angleAxis = this._angleAxis;
  49425. return axis === angleAxis ? this._radiusAxis : angleAxis;
  49426. },
  49427. /**
  49428. * Base axis will be used on stacking.
  49429. *
  49430. * @return {module:echarts/coord/polar/Axis}
  49431. */
  49432. getBaseAxis: function () {
  49433. return this.getAxesByScale('ordinal')[0]
  49434. || this.getAxesByScale('time')[0]
  49435. || this.getAngleAxis();
  49436. },
  49437. /**
  49438. * @param {string} [dim] 'radius' or 'angle' or 'auto' or null/undefined
  49439. * @return {Object} {baseAxes: [], otherAxes: []}
  49440. */
  49441. getTooltipAxes: function (dim) {
  49442. var baseAxis = (dim != null && dim !== 'auto')
  49443. ? this.getAxis(dim) : this.getBaseAxis();
  49444. return {
  49445. baseAxes: [baseAxis],
  49446. otherAxes: [this.getOtherAxis(baseAxis)]
  49447. };
  49448. },
  49449. /**
  49450. * Convert series data to a list of (x, y) points
  49451. * @param {module:echarts/data/List} data
  49452. * @return {Array}
  49453. * Return list of coordinates. For example:
  49454. * `[[10, 10], [20, 20], [30, 30]]`
  49455. */
  49456. dataToPoints: function (data) {
  49457. return data.mapArray(this.dimensions, function (radius, angle) {
  49458. return this.dataToPoint([radius, angle]);
  49459. }, true, this);
  49460. },
  49461. /**
  49462. * Convert a single data item to (x, y) point.
  49463. * Parameter data is an array which the first element is radius and the second is angle
  49464. * @param {Array.<number>} data
  49465. * @param {boolean} [clamp=false]
  49466. * @return {Array.<number>}
  49467. */
  49468. dataToPoint: function (data, clamp) {
  49469. return this.coordToPoint([
  49470. this._radiusAxis.dataToRadius(data[0], clamp),
  49471. this._angleAxis.dataToAngle(data[1], clamp)
  49472. ]);
  49473. },
  49474. /**
  49475. * Convert a (x, y) point to data
  49476. * @param {Array.<number>} point
  49477. * @param {boolean} [clamp=false]
  49478. * @return {Array.<number>}
  49479. */
  49480. pointToData: function (point, clamp) {
  49481. var coord = this.pointToCoord(point);
  49482. return [
  49483. this._radiusAxis.radiusToData(coord[0], clamp),
  49484. this._angleAxis.angleToData(coord[1], clamp)
  49485. ];
  49486. },
  49487. /**
  49488. * Convert a (x, y) point to (radius, angle) coord
  49489. * @param {Array.<number>} point
  49490. * @return {Array.<number>}
  49491. */
  49492. pointToCoord: function (point) {
  49493. var dx = point[0] - this.cx;
  49494. var dy = point[1] - this.cy;
  49495. var angleAxis = this.getAngleAxis();
  49496. var extent = angleAxis.getExtent();
  49497. var minAngle = Math.min(extent[0], extent[1]);
  49498. var maxAngle = Math.max(extent[0], extent[1]);
  49499. // Fix fixed extent in polarCreator
  49500. // FIXME
  49501. angleAxis.inverse
  49502. ? (minAngle = maxAngle - 360)
  49503. : (maxAngle = minAngle + 360);
  49504. var radius = Math.sqrt(dx * dx + dy * dy);
  49505. dx /= radius;
  49506. dy /= radius;
  49507. var radian = Math.atan2(-dy, dx) / Math.PI * 180;
  49508. // move to angleExtent
  49509. var dir = radian < minAngle ? 1 : -1;
  49510. while (radian < minAngle || radian > maxAngle) {
  49511. radian += dir * 360;
  49512. }
  49513. return [radius, radian];
  49514. },
  49515. /**
  49516. * Convert a (radius, angle) coord to (x, y) point
  49517. * @param {Array.<number>} coord
  49518. * @return {Array.<number>}
  49519. */
  49520. coordToPoint: function (coord) {
  49521. var radius = coord[0];
  49522. var radian = coord[1] / 180 * Math.PI;
  49523. var x = Math.cos(radian) * radius + this.cx;
  49524. // Inverse the y
  49525. var y = -Math.sin(radian) * radius + this.cy;
  49526. return [x, y];
  49527. }
  49528. };
  49529. module.exports = Polar;
  49530. /***/ },
  49531. /* 333 */
  49532. /***/ function(module, exports, __webpack_require__) {
  49533. 'use strict';
  49534. var zrUtil = __webpack_require__(4);
  49535. var Axis = __webpack_require__(100);
  49536. function RadiusAxis(scale, radiusExtent) {
  49537. Axis.call(this, 'radius', scale, radiusExtent);
  49538. /**
  49539. * Axis type
  49540. * - 'category'
  49541. * - 'value'
  49542. * - 'time'
  49543. * - 'log'
  49544. * @type {string}
  49545. */
  49546. this.type = 'category';
  49547. }
  49548. RadiusAxis.prototype = {
  49549. constructor: RadiusAxis,
  49550. /**
  49551. * @override
  49552. */
  49553. pointToData: function (point, clamp) {
  49554. return this.polar.pointToData(point, clamp)[this.dim === 'radius' ? 0 : 1];
  49555. },
  49556. dataToRadius: Axis.prototype.dataToCoord,
  49557. radiusToData: Axis.prototype.coordToData
  49558. };
  49559. zrUtil.inherits(RadiusAxis, Axis);
  49560. module.exports = RadiusAxis;
  49561. /***/ },
  49562. /* 334 */
  49563. /***/ function(module, exports, __webpack_require__) {
  49564. 'use strict';
  49565. var zrUtil = __webpack_require__(4);
  49566. var Axis = __webpack_require__(100);
  49567. function AngleAxis(scale, angleExtent) {
  49568. angleExtent = angleExtent || [0, 360];
  49569. Axis.call(this, 'angle', scale, angleExtent);
  49570. /**
  49571. * Axis type
  49572. * - 'category'
  49573. * - 'value'
  49574. * - 'time'
  49575. * - 'log'
  49576. * @type {string}
  49577. */
  49578. this.type = 'category';
  49579. }
  49580. AngleAxis.prototype = {
  49581. constructor: AngleAxis,
  49582. /**
  49583. * @override
  49584. */
  49585. pointToData: function (point, clamp) {
  49586. return this.polar.pointToData(point, clamp)[this.dim === 'radius' ? 0 : 1];
  49587. },
  49588. dataToAngle: Axis.prototype.dataToCoord,
  49589. angleToData: Axis.prototype.coordToData
  49590. };
  49591. zrUtil.inherits(AngleAxis, Axis);
  49592. module.exports = AngleAxis;
  49593. /***/ },
  49594. /* 335 */
  49595. /***/ function(module, exports, __webpack_require__) {
  49596. 'use strict';
  49597. __webpack_require__(336);
  49598. __webpack_require__(1).extendComponentModel({
  49599. type: 'polar',
  49600. dependencies: ['polarAxis', 'angleAxis'],
  49601. /**
  49602. * @type {module:echarts/coord/polar/Polar}
  49603. */
  49604. coordinateSystem: null,
  49605. /**
  49606. * @param {string} axisType
  49607. * @return {module:echarts/coord/polar/AxisModel}
  49608. */
  49609. findAxisModel: function (axisType) {
  49610. var foundAxisModel;
  49611. var ecModel = this.ecModel;
  49612. ecModel.eachComponent(axisType, function (axisModel) {
  49613. if (axisModel.getCoordSysModel() === this) {
  49614. foundAxisModel = axisModel;
  49615. }
  49616. }, this);
  49617. return foundAxisModel;
  49618. },
  49619. defaultOption: {
  49620. zlevel: 0,
  49621. z: 0,
  49622. center: ['50%', '50%'],
  49623. radius: '80%'
  49624. }
  49625. });
  49626. /***/ },
  49627. /* 336 */
  49628. /***/ function(module, exports, __webpack_require__) {
  49629. 'use strict';
  49630. var zrUtil = __webpack_require__(4);
  49631. var ComponentModel = __webpack_require__(69);
  49632. var axisModelCreator = __webpack_require__(131);
  49633. var PolarAxisModel = ComponentModel.extend({
  49634. type: 'polarAxis',
  49635. /**
  49636. * @type {module:echarts/coord/polar/AngleAxis|module:echarts/coord/polar/RadiusAxis}
  49637. */
  49638. axis: null,
  49639. /**
  49640. * @override
  49641. */
  49642. getCoordSysModel: function () {
  49643. return this.ecModel.queryComponents({
  49644. mainType: 'polar',
  49645. index: this.option.polarIndex,
  49646. id: this.option.polarId
  49647. })[0];
  49648. }
  49649. });
  49650. zrUtil.merge(PolarAxisModel.prototype, __webpack_require__(112));
  49651. var polarAxisDefaultExtendedOption = {
  49652. angle: {
  49653. // polarIndex: 0,
  49654. // polarId: '',
  49655. startAngle: 90,
  49656. clockwise: true,
  49657. splitNumber: 12,
  49658. axisLabel: {
  49659. rotate: false
  49660. }
  49661. },
  49662. radius: {
  49663. // polarIndex: 0,
  49664. // polarId: '',
  49665. splitNumber: 5
  49666. }
  49667. };
  49668. function getAxisType(axisDim, option) {
  49669. // Default axis with data is category axis
  49670. return option.type || (option.data ? 'category' : 'value');
  49671. }
  49672. axisModelCreator('angle', PolarAxisModel, getAxisType, polarAxisDefaultExtendedOption.angle);
  49673. axisModelCreator('radius', PolarAxisModel, getAxisType, polarAxisDefaultExtendedOption.radius);
  49674. /***/ },
  49675. /* 337 */
  49676. /***/ function(module, exports, __webpack_require__) {
  49677. 'use strict';
  49678. __webpack_require__(331);
  49679. __webpack_require__(338);
  49680. /***/ },
  49681. /* 338 */
  49682. /***/ function(module, exports, __webpack_require__) {
  49683. 'use strict';
  49684. var zrUtil = __webpack_require__(4);
  49685. var graphic = __webpack_require__(18);
  49686. var Model = __webpack_require__(12);
  49687. var elementList = ['axisLine', 'axisLabel', 'axisTick', 'splitLine', 'splitArea'];
  49688. function getAxisLineShape(polar, r0, r, angle) {
  49689. var start = polar.coordToPoint([r0, angle]);
  49690. var end = polar.coordToPoint([r, angle]);
  49691. return {
  49692. x1: start[0],
  49693. y1: start[1],
  49694. x2: end[0],
  49695. y2: end[1]
  49696. };
  49697. }
  49698. __webpack_require__(136).extend({
  49699. type: 'angleAxis',
  49700. axisPointerClass: 'PolarAxisPointer',
  49701. render: function (angleAxisModel, ecModel) {
  49702. this.group.removeAll();
  49703. if (!angleAxisModel.get('show')) {
  49704. return;
  49705. }
  49706. var angleAxis = angleAxisModel.axis;
  49707. var polar = angleAxis.polar;
  49708. var radiusExtent = polar.getRadiusAxis().getExtent();
  49709. var ticksAngles = angleAxis.getTicksCoords();
  49710. if (angleAxis.type !== 'category') {
  49711. // Remove the last tick which will overlap the first tick
  49712. ticksAngles.pop();
  49713. }
  49714. zrUtil.each(elementList, function (name) {
  49715. if (angleAxisModel.get(name +'.show')
  49716. && (!angleAxis.scale.isBlank() || name === 'axisLine')
  49717. ) {
  49718. this['_' + name](angleAxisModel, polar, ticksAngles, radiusExtent);
  49719. }
  49720. }, this);
  49721. },
  49722. /**
  49723. * @private
  49724. */
  49725. _axisLine: function (angleAxisModel, polar, ticksAngles, radiusExtent) {
  49726. var lineStyleModel = angleAxisModel.getModel('axisLine.lineStyle');
  49727. var circle = new graphic.Circle({
  49728. shape: {
  49729. cx: polar.cx,
  49730. cy: polar.cy,
  49731. r: radiusExtent[1]
  49732. },
  49733. style: lineStyleModel.getLineStyle(),
  49734. z2: 1,
  49735. silent: true
  49736. });
  49737. circle.style.fill = null;
  49738. this.group.add(circle);
  49739. },
  49740. /**
  49741. * @private
  49742. */
  49743. _axisTick: function (angleAxisModel, polar, ticksAngles, radiusExtent) {
  49744. var tickModel = angleAxisModel.getModel('axisTick');
  49745. var tickLen = (tickModel.get('inside') ? -1 : 1) * tickModel.get('length');
  49746. var lines = zrUtil.map(ticksAngles, function (tickAngle) {
  49747. return new graphic.Line({
  49748. shape: getAxisLineShape(polar, radiusExtent[1], radiusExtent[1] + tickLen, tickAngle)
  49749. });
  49750. });
  49751. this.group.add(graphic.mergePath(
  49752. lines, {
  49753. style: zrUtil.defaults(
  49754. tickModel.getModel('lineStyle').getLineStyle(),
  49755. {
  49756. stroke: angleAxisModel.get('axisLine.lineStyle.color')
  49757. }
  49758. )
  49759. }
  49760. ));
  49761. },
  49762. /**
  49763. * @private
  49764. */
  49765. _axisLabel: function (angleAxisModel, polar, ticksAngles, radiusExtent) {
  49766. var axis = angleAxisModel.axis;
  49767. var categoryData = angleAxisModel.get('data');
  49768. var labelModel = angleAxisModel.getModel('axisLabel');
  49769. var axisTextStyleModel = labelModel.getModel('textStyle');
  49770. var labels = angleAxisModel.getFormattedLabels();
  49771. var labelMargin = labelModel.get('margin');
  49772. var labelsAngles = axis.getLabelsCoords();
  49773. // Use length of ticksAngles because it may remove the last tick to avoid overlapping
  49774. for (var i = 0; i < ticksAngles.length; i++) {
  49775. var r = radiusExtent[1];
  49776. var p = polar.coordToPoint([r + labelMargin, labelsAngles[i]]);
  49777. var cx = polar.cx;
  49778. var cy = polar.cy;
  49779. var labelTextAlign = Math.abs(p[0] - cx) / r < 0.3
  49780. ? 'center' : (p[0] > cx ? 'left' : 'right');
  49781. var labelTextBaseline = Math.abs(p[1] - cy) / r < 0.3
  49782. ? 'middle' : (p[1] > cy ? 'top' : 'bottom');
  49783. var textStyleModel = axisTextStyleModel;
  49784. if (categoryData && categoryData[i] && categoryData[i].textStyle) {
  49785. textStyleModel = new Model(
  49786. categoryData[i].textStyle, axisTextStyleModel
  49787. );
  49788. }
  49789. this.group.add(new graphic.Text({
  49790. style: {
  49791. x: p[0],
  49792. y: p[1],
  49793. fill: textStyleModel.getTextColor() || angleAxisModel.get('axisLine.lineStyle.color'),
  49794. text: labels[i],
  49795. textAlign: labelTextAlign,
  49796. textVerticalAlign: labelTextBaseline,
  49797. textFont: textStyleModel.getFont()
  49798. },
  49799. silent: true
  49800. }));
  49801. }
  49802. },
  49803. /**
  49804. * @private
  49805. */
  49806. _splitLine: function (angleAxisModel, polar, ticksAngles, radiusExtent) {
  49807. var splitLineModel = angleAxisModel.getModel('splitLine');
  49808. var lineStyleModel = splitLineModel.getModel('lineStyle');
  49809. var lineColors = lineStyleModel.get('color');
  49810. var lineCount = 0;
  49811. lineColors = lineColors instanceof Array ? lineColors : [lineColors];
  49812. var splitLines = [];
  49813. for (var i = 0; i < ticksAngles.length; i++) {
  49814. var colorIndex = (lineCount++) % lineColors.length;
  49815. splitLines[colorIndex] = splitLines[colorIndex] || [];
  49816. splitLines[colorIndex].push(new graphic.Line({
  49817. shape: getAxisLineShape(polar, radiusExtent[0], radiusExtent[1], ticksAngles[i])
  49818. }));
  49819. }
  49820. // Simple optimization
  49821. // Batching the lines if color are the same
  49822. for (var i = 0; i < splitLines.length; i++) {
  49823. this.group.add(graphic.mergePath(splitLines[i], {
  49824. style: zrUtil.defaults({
  49825. stroke: lineColors[i % lineColors.length]
  49826. }, lineStyleModel.getLineStyle()),
  49827. silent: true,
  49828. z: angleAxisModel.get('z')
  49829. }));
  49830. }
  49831. },
  49832. /**
  49833. * @private
  49834. */
  49835. _splitArea: function (angleAxisModel, polar, ticksAngles, radiusExtent) {
  49836. var splitAreaModel = angleAxisModel.getModel('splitArea');
  49837. var areaStyleModel = splitAreaModel.getModel('areaStyle');
  49838. var areaColors = areaStyleModel.get('color');
  49839. var lineCount = 0;
  49840. areaColors = areaColors instanceof Array ? areaColors : [areaColors];
  49841. var splitAreas = [];
  49842. var RADIAN = Math.PI / 180;
  49843. var prevAngle = -ticksAngles[0] * RADIAN;
  49844. var r0 = Math.min(radiusExtent[0], radiusExtent[1]);
  49845. var r1 = Math.max(radiusExtent[0], radiusExtent[1]);
  49846. var clockwise = angleAxisModel.get('clockwise');
  49847. for (var i = 1; i < ticksAngles.length; i++) {
  49848. var colorIndex = (lineCount++) % areaColors.length;
  49849. splitAreas[colorIndex] = splitAreas[colorIndex] || [];
  49850. splitAreas[colorIndex].push(new graphic.Sector({
  49851. shape: {
  49852. cx: polar.cx,
  49853. cy: polar.cy,
  49854. r0: r0,
  49855. r: r1,
  49856. startAngle: prevAngle,
  49857. endAngle: -ticksAngles[i] * RADIAN,
  49858. clockwise: clockwise
  49859. },
  49860. silent: true
  49861. }));
  49862. prevAngle = -ticksAngles[i] * RADIAN;
  49863. }
  49864. // Simple optimization
  49865. // Batching the lines if color are the same
  49866. for (var i = 0; i < splitAreas.length; i++) {
  49867. this.group.add(graphic.mergePath(splitAreas[i], {
  49868. style: zrUtil.defaults({
  49869. fill: areaColors[i % areaColors.length]
  49870. }, areaStyleModel.getAreaStyle()),
  49871. silent: true
  49872. }));
  49873. }
  49874. }
  49875. });
  49876. /***/ },
  49877. /* 339 */
  49878. /***/ function(module, exports, __webpack_require__) {
  49879. __webpack_require__(331);
  49880. __webpack_require__(340);
  49881. /***/ },
  49882. /* 340 */
  49883. /***/ function(module, exports, __webpack_require__) {
  49884. 'use strict';
  49885. var zrUtil = __webpack_require__(4);
  49886. var graphic = __webpack_require__(18);
  49887. var AxisBuilder = __webpack_require__(135);
  49888. var axisBuilderAttrs = [
  49889. 'axisLine', 'axisLabel', 'axisTick', 'axisName'
  49890. ];
  49891. var selfBuilderAttrs = [
  49892. 'splitLine', 'splitArea'
  49893. ];
  49894. __webpack_require__(136).extend({
  49895. type: 'radiusAxis',
  49896. axisPointerClass: 'PolarAxisPointer',
  49897. render: function (radiusAxisModel, ecModel) {
  49898. this.group.removeAll();
  49899. if (!radiusAxisModel.get('show')) {
  49900. return;
  49901. }
  49902. var radiusAxis = radiusAxisModel.axis;
  49903. var polar = radiusAxis.polar;
  49904. var angleAxis = polar.getAngleAxis();
  49905. var ticksCoords = radiusAxis.getTicksCoords();
  49906. var axisAngle = angleAxis.getExtent()[0];
  49907. var radiusExtent = radiusAxis.getExtent();
  49908. var layout = layoutAxis(polar, radiusAxisModel, axisAngle);
  49909. var axisBuilder = new AxisBuilder(radiusAxisModel, layout);
  49910. zrUtil.each(axisBuilderAttrs, axisBuilder.add, axisBuilder);
  49911. this.group.add(axisBuilder.getGroup());
  49912. zrUtil.each(selfBuilderAttrs, function (name) {
  49913. if (radiusAxisModel.get(name +'.show') && !radiusAxis.scale.isBlank()) {
  49914. this['_' + name](radiusAxisModel, polar, axisAngle, radiusExtent, ticksCoords);
  49915. }
  49916. }, this);
  49917. },
  49918. /**
  49919. * @private
  49920. */
  49921. _splitLine: function (radiusAxisModel, polar, axisAngle, radiusExtent, ticksCoords) {
  49922. var splitLineModel = radiusAxisModel.getModel('splitLine');
  49923. var lineStyleModel = splitLineModel.getModel('lineStyle');
  49924. var lineColors = lineStyleModel.get('color');
  49925. var lineCount = 0;
  49926. lineColors = lineColors instanceof Array ? lineColors : [lineColors];
  49927. var splitLines = [];
  49928. for (var i = 0; i < ticksCoords.length; i++) {
  49929. var colorIndex = (lineCount++) % lineColors.length;
  49930. splitLines[colorIndex] = splitLines[colorIndex] || [];
  49931. splitLines[colorIndex].push(new graphic.Circle({
  49932. shape: {
  49933. cx: polar.cx,
  49934. cy: polar.cy,
  49935. r: ticksCoords[i]
  49936. },
  49937. silent: true
  49938. }));
  49939. }
  49940. // Simple optimization
  49941. // Batching the lines if color are the same
  49942. for (var i = 0; i < splitLines.length; i++) {
  49943. this.group.add(graphic.mergePath(splitLines[i], {
  49944. style: zrUtil.defaults({
  49945. stroke: lineColors[i % lineColors.length],
  49946. fill: null
  49947. }, lineStyleModel.getLineStyle()),
  49948. silent: true
  49949. }));
  49950. }
  49951. },
  49952. /**
  49953. * @private
  49954. */
  49955. _splitArea: function (radiusAxisModel, polar, axisAngle, radiusExtent, ticksCoords) {
  49956. var splitAreaModel = radiusAxisModel.getModel('splitArea');
  49957. var areaStyleModel = splitAreaModel.getModel('areaStyle');
  49958. var areaColors = areaStyleModel.get('color');
  49959. var lineCount = 0;
  49960. areaColors = areaColors instanceof Array ? areaColors : [areaColors];
  49961. var splitAreas = [];
  49962. var prevRadius = ticksCoords[0];
  49963. for (var i = 1; i < ticksCoords.length; i++) {
  49964. var colorIndex = (lineCount++) % areaColors.length;
  49965. splitAreas[colorIndex] = splitAreas[colorIndex] || [];
  49966. splitAreas[colorIndex].push(new graphic.Sector({
  49967. shape: {
  49968. cx: polar.cx,
  49969. cy: polar.cy,
  49970. r0: prevRadius,
  49971. r: ticksCoords[i],
  49972. startAngle: 0,
  49973. endAngle: Math.PI * 2
  49974. },
  49975. silent: true
  49976. }));
  49977. prevRadius = ticksCoords[i];
  49978. }
  49979. // Simple optimization
  49980. // Batching the lines if color are the same
  49981. for (var i = 0; i < splitAreas.length; i++) {
  49982. this.group.add(graphic.mergePath(splitAreas[i], {
  49983. style: zrUtil.defaults({
  49984. fill: areaColors[i % areaColors.length]
  49985. }, areaStyleModel.getAreaStyle()),
  49986. silent: true
  49987. }));
  49988. }
  49989. }
  49990. });
  49991. /**
  49992. * @inner
  49993. */
  49994. function layoutAxis(polar, radiusAxisModel, axisAngle) {
  49995. return {
  49996. position: [polar.cx, polar.cy],
  49997. rotation: axisAngle / 180 * Math.PI,
  49998. labelDirection: -1,
  49999. tickDirection: -1,
  50000. nameDirection: 1,
  50001. labelRotate: radiusAxisModel.getModel('axisLabel').get('rotate'),
  50002. // Over splitLine and splitArea
  50003. z2: 1
  50004. };
  50005. }
  50006. /***/ },
  50007. /* 341 */
  50008. /***/ function(module, exports, __webpack_require__) {
  50009. 'use strict';
  50010. var formatUtil = __webpack_require__(6);
  50011. var BaseAxisPointer = __webpack_require__(304);
  50012. var graphic = __webpack_require__(18);
  50013. var viewHelper = __webpack_require__(305);
  50014. var matrix = __webpack_require__(11);
  50015. var AxisBuilder = __webpack_require__(135);
  50016. var AxisView = __webpack_require__(136);
  50017. var PolarAxisPointer = BaseAxisPointer.extend({
  50018. /**
  50019. * @override
  50020. */
  50021. makeElOption: function (elOption, value, axisModel, axisPointerModel, api) {
  50022. var axis = axisModel.axis;
  50023. if (axis.dim === 'angle') {
  50024. this.animationThreshold = Math.PI / 18;
  50025. }
  50026. var polar = axis.polar;
  50027. var otherAxis = polar.getOtherAxis(axis);
  50028. var otherExtent = otherAxis.getExtent();
  50029. var coordValue;
  50030. coordValue = axis['dataTo' + formatUtil.capitalFirst(axis.dim)](value);
  50031. var axisPointerType = axisPointerModel.get('type');
  50032. if (axisPointerType && axisPointerType !== 'none') {
  50033. var elStyle = viewHelper.buildElStyle(axisPointerModel);
  50034. var pointerOption = pointerShapeBuilder[axisPointerType](
  50035. axis, polar, coordValue, otherExtent, elStyle
  50036. );
  50037. pointerOption.style = elStyle;
  50038. elOption.graphicKey = pointerOption.type;
  50039. elOption.pointer = pointerOption;
  50040. }
  50041. var labelMargin = axisPointerModel.get('label.margin');
  50042. var labelPos = getLabelPosition(value, axisModel, axisPointerModel, polar, labelMargin);
  50043. viewHelper.buildLabelElOption(elOption, axisModel, axisPointerModel, api, labelPos);
  50044. }
  50045. // Do not support handle, utill any user requires it.
  50046. });
  50047. function getLabelPosition(value, axisModel, axisPointerModel, polar, labelMargin) {
  50048. var axis = axisModel.axis;
  50049. var coord = axis.dataToCoord(value);
  50050. var axisAngle = polar.getAngleAxis().getExtent()[0];
  50051. axisAngle = axisAngle / 180 * Math.PI;
  50052. var radiusExtent = polar.getRadiusAxis().getExtent();
  50053. var position;
  50054. var align;
  50055. var verticalAlign;
  50056. if (axis.dim === 'radius') {
  50057. var transform = matrix.create();
  50058. matrix.rotate(transform, transform, axisAngle);
  50059. matrix.translate(transform, transform, [polar.cx, polar.cy]);
  50060. position = graphic.applyTransform([coord, -labelMargin], transform);
  50061. var labelRotation = axisModel.getModel('axisLabel').get('rotate') || 0;
  50062. var labelLayout = AxisBuilder.innerTextLayout(
  50063. axisAngle, labelRotation * Math.PI / 180, -1
  50064. );
  50065. align = labelLayout.textAlign;
  50066. verticalAlign = labelLayout.textVerticalAlign;
  50067. }
  50068. else { // angle axis
  50069. var r = radiusExtent[1];
  50070. position = polar.coordToPoint([r + labelMargin, coord]);
  50071. var cx = polar.cx;
  50072. var cy = polar.cy;
  50073. align = Math.abs(position[0] - cx) / r < 0.3
  50074. ? 'center' : (position[0] > cx ? 'left' : 'right');
  50075. verticalAlign = Math.abs(position[1] - cy) / r < 0.3
  50076. ? 'middle' : (position[1] > cy ? 'top' : 'bottom');
  50077. }
  50078. return {
  50079. position: position,
  50080. align: align,
  50081. verticalAlign: verticalAlign
  50082. };
  50083. }
  50084. var pointerShapeBuilder = {
  50085. line: function (axis, polar, coordValue, otherExtent, elStyle) {
  50086. return axis.dim === 'angle'
  50087. ? {
  50088. type: 'Line',
  50089. shape: viewHelper.makeLineShape(
  50090. polar.coordToPoint([otherExtent[0], coordValue]),
  50091. polar.coordToPoint([otherExtent[1], coordValue])
  50092. )
  50093. }
  50094. : {
  50095. type: 'Circle',
  50096. shape: {
  50097. cx: polar.cx,
  50098. cy: polar.cy,
  50099. r: coordValue
  50100. }
  50101. };
  50102. },
  50103. shadow: function (axis, polar, coordValue, otherExtent, elStyle) {
  50104. var bandWidth = axis.getBandWidth();
  50105. var radian = Math.PI / 180;
  50106. return axis.dim === 'angle'
  50107. ? {
  50108. type: 'Sector',
  50109. shape: viewHelper.makeSectorShape(
  50110. polar.cx, polar.cy,
  50111. otherExtent[0], otherExtent[1],
  50112. // In ECharts y is negative if angle is positive
  50113. (-coordValue - bandWidth / 2) * radian,
  50114. (-coordValue + bandWidth / 2) * radian
  50115. )
  50116. }
  50117. : {
  50118. type: 'Sector',
  50119. shape: viewHelper.makeSectorShape(
  50120. polar.cx, polar.cy,
  50121. coordValue - bandWidth / 2,
  50122. coordValue + bandWidth / 2,
  50123. 0, Math.PI * 2
  50124. )
  50125. };
  50126. }
  50127. };
  50128. AxisView.registerAxisPointerClass('PolarAxisPointer', PolarAxisPointer);
  50129. module.exports = PolarAxisPointer;
  50130. /***/ },
  50131. /* 342 */
  50132. /***/ function(module, exports, __webpack_require__) {
  50133. 'use strict';
  50134. var zrUtil = __webpack_require__(4);
  50135. var parsePercent = __webpack_require__(7).parsePercent;
  50136. function getSeriesStackId(seriesModel) {
  50137. return seriesModel.get('stack')
  50138. || '__ec_stack_' + seriesModel.seriesIndex;
  50139. }
  50140. function getAxisKey(axis) {
  50141. return axis.dim;
  50142. }
  50143. /**
  50144. * @param {string} seriesType
  50145. * @param {module:echarts/model/Global} ecModel
  50146. * @param {module:echarts/ExtensionAPI} api
  50147. */
  50148. function barLayoutPolar(seriesType, ecModel, api) {
  50149. var width = api.getWidth();
  50150. var height = api.getHeight();
  50151. var lastStackCoords = {};
  50152. var lastStackCoordsOrigin = {};
  50153. var barWidthAndOffset = calRadialBar(
  50154. zrUtil.filter(
  50155. ecModel.getSeriesByType(seriesType),
  50156. function (seriesModel) {
  50157. return !ecModel.isSeriesFiltered(seriesModel)
  50158. && seriesModel.coordinateSystem
  50159. && seriesModel.coordinateSystem.type === 'polar';
  50160. }
  50161. )
  50162. );
  50163. ecModel.eachSeriesByType(seriesType, function (seriesModel) {
  50164. // Check series coordinate, do layout for polar only
  50165. if (seriesModel.coordinateSystem.type !== 'polar') {
  50166. return;
  50167. }
  50168. var data = seriesModel.getData();
  50169. var polar = seriesModel.coordinateSystem;
  50170. var angleAxis = polar.getAngleAxis();
  50171. var baseAxis = polar.getBaseAxis();
  50172. var stackId = getSeriesStackId(seriesModel);
  50173. var columnLayoutInfo
  50174. = barWidthAndOffset[getAxisKey(baseAxis)][stackId];
  50175. var columnOffset = columnLayoutInfo.offset;
  50176. var columnWidth = columnLayoutInfo.width;
  50177. var valueAxis = polar.getOtherAxis(baseAxis);
  50178. var center = seriesModel.get('center') || ['50%', '50%'];
  50179. var cx = parsePercent(center[0], width);
  50180. var cy = parsePercent(center[1], height);
  50181. var barMinHeight = seriesModel.get('barMinHeight') || 0;
  50182. var barMinAngle = seriesModel.get('barMinAngle') || 0;
  50183. var valueAxisStart = valueAxis.getExtent()[0];
  50184. var valueMax = valueAxis.model.get('max');
  50185. var valueMin = valueAxis.model.get('min');
  50186. var coords = polar.dataToPoints(data);
  50187. lastStackCoords[stackId] = lastStackCoords[stackId] || [];
  50188. lastStackCoordsOrigin[stackId] = lastStackCoordsOrigin[stackId] || []; // Fix #4243
  50189. data.each(valueAxis.dim, function (value, idx) {
  50190. if (isNaN(value)) {
  50191. return;
  50192. }
  50193. if (!lastStackCoords[stackId][idx]) {
  50194. lastStackCoords[stackId][idx] = {
  50195. p: valueAxisStart, // Positive stack
  50196. n: valueAxisStart // Negative stack
  50197. };
  50198. lastStackCoordsOrigin[stackId][idx] = {
  50199. p: valueAxisStart, // Positive stack
  50200. n: valueAxisStart // Negative stack
  50201. };
  50202. }
  50203. var sign = value >= 0 ? 'p' : 'n';
  50204. var coord = polar.pointToCoord(coords[idx]);
  50205. var lastCoordOrigin = lastStackCoordsOrigin[stackId][idx][sign];
  50206. var r0;
  50207. var r;
  50208. var startAngle;
  50209. var endAngle;
  50210. if (valueAxis.dim === 'radius') {
  50211. // radial sector
  50212. r0 = lastCoordOrigin;
  50213. r = coord[0];
  50214. startAngle = (-coord[1] + columnOffset) * Math.PI / 180;
  50215. endAngle = startAngle + columnWidth * Math.PI / 180;
  50216. if (Math.abs(r) < barMinHeight) {
  50217. r = r0 + (r < 0 ? -1 : 1) * barMinHeight;
  50218. }
  50219. lastStackCoordsOrigin[stackId][idx][sign] = r;
  50220. }
  50221. else {
  50222. // tangential sector
  50223. r0 = coord[0] + columnOffset;
  50224. r = r0 + columnWidth;
  50225. // clamp data if min or max is defined for valueAxis
  50226. if (valueMax != null) {
  50227. value = Math.min(value, valueMax);
  50228. }
  50229. if (valueMin != null) {
  50230. value = Math.max(value, valueMin);
  50231. }
  50232. var angle = angleAxis.dataToAngle(value);
  50233. if (Math.abs(angle - lastCoordOrigin) < barMinAngle) {
  50234. angle = lastCoordOrigin - (value < 0 ? -1 : 1)
  50235. * barMinAngle;
  50236. }
  50237. startAngle = -lastCoordOrigin * Math.PI / 180;
  50238. endAngle = -angle * Math.PI / 180;
  50239. // if the previous stack is at the end of the ring,
  50240. // add a round to differentiate it from origin
  50241. var extent = angleAxis.getExtent();
  50242. var stackCoord = angle;
  50243. if (stackCoord === extent[0] && value > 0) {
  50244. stackCoord = extent[1];
  50245. }
  50246. else if (stackCoord === extent[1] && value < 0) {
  50247. stackCoord = extent[0];
  50248. }
  50249. lastStackCoordsOrigin[stackId][idx][sign] = stackCoord;
  50250. }
  50251. data.setItemLayout(idx, {
  50252. cx: cx,
  50253. cy: cy,
  50254. r0: r0,
  50255. r: r,
  50256. startAngle: startAngle,
  50257. endAngle: endAngle
  50258. });
  50259. }, true);
  50260. }, this);
  50261. }
  50262. /**
  50263. * Calculate bar width and offset for radial bar charts
  50264. */
  50265. function calRadialBar(barSeries, api) {
  50266. // Columns info on each category axis. Key is polar name
  50267. var columnsMap = {};
  50268. zrUtil.each(barSeries, function (seriesModel, idx) {
  50269. var data = seriesModel.getData();
  50270. var polar = seriesModel.coordinateSystem;
  50271. var baseAxis = polar.getBaseAxis();
  50272. var axisExtent = baseAxis.getExtent();
  50273. var bandWidth = baseAxis.type === 'category'
  50274. ? baseAxis.getBandWidth()
  50275. : (Math.abs(axisExtent[1] - axisExtent[0]) / data.count());
  50276. var columnsOnAxis = columnsMap[getAxisKey(baseAxis)] || {
  50277. bandWidth: bandWidth,
  50278. remainedWidth: bandWidth,
  50279. autoWidthCount: 0,
  50280. categoryGap: '20%',
  50281. gap: '30%',
  50282. stacks: {}
  50283. };
  50284. var stacks = columnsOnAxis.stacks;
  50285. columnsMap[getAxisKey(baseAxis)] = columnsOnAxis;
  50286. var stackId = getSeriesStackId(seriesModel);
  50287. if (!stacks[stackId]) {
  50288. columnsOnAxis.autoWidthCount++;
  50289. }
  50290. stacks[stackId] = stacks[stackId] || {
  50291. width: 0,
  50292. maxWidth: 0
  50293. };
  50294. var barWidth = parsePercent(
  50295. seriesModel.get('barWidth'),
  50296. bandWidth
  50297. );
  50298. var barMaxWidth = parsePercent(
  50299. seriesModel.get('barMaxWidth'),
  50300. bandWidth
  50301. );
  50302. var barGap = seriesModel.get('barGap');
  50303. var barCategoryGap = seriesModel.get('barCategoryGap');
  50304. if (barWidth && !stacks[stackId].width) {
  50305. barWidth = Math.min(columnsOnAxis.remainedWidth, barWidth);
  50306. stacks[stackId].width = barWidth;
  50307. columnsOnAxis.remainedWidth -= barWidth;
  50308. }
  50309. barMaxWidth && (stacks[stackId].maxWidth = barMaxWidth);
  50310. (barGap != null) && (columnsOnAxis.gap = barGap);
  50311. (barCategoryGap != null) && (columnsOnAxis.categoryGap = barCategoryGap);
  50312. });
  50313. var result = {};
  50314. zrUtil.each(columnsMap, function (columnsOnAxis, coordSysName) {
  50315. result[coordSysName] = {};
  50316. var stacks = columnsOnAxis.stacks;
  50317. var bandWidth = columnsOnAxis.bandWidth;
  50318. var categoryGap = parsePercent(columnsOnAxis.categoryGap, bandWidth);
  50319. var barGapPercent = parsePercent(columnsOnAxis.gap, 1);
  50320. var remainedWidth = columnsOnAxis.remainedWidth;
  50321. var autoWidthCount = columnsOnAxis.autoWidthCount;
  50322. var autoWidth = (remainedWidth - categoryGap)
  50323. / (autoWidthCount + (autoWidthCount - 1) * barGapPercent);
  50324. autoWidth = Math.max(autoWidth, 0);
  50325. // Find if any auto calculated bar exceeded maxBarWidth
  50326. zrUtil.each(stacks, function (column, stack) {
  50327. var maxWidth = column.maxWidth;
  50328. if (maxWidth && maxWidth < autoWidth) {
  50329. maxWidth = Math.min(maxWidth, remainedWidth);
  50330. if (column.width) {
  50331. maxWidth = Math.min(maxWidth, column.width);
  50332. }
  50333. remainedWidth -= maxWidth;
  50334. column.width = maxWidth;
  50335. autoWidthCount--;
  50336. }
  50337. });
  50338. // Recalculate width again
  50339. autoWidth = (remainedWidth - categoryGap)
  50340. / (autoWidthCount + (autoWidthCount - 1) * barGapPercent);
  50341. autoWidth = Math.max(autoWidth, 0);
  50342. var widthSum = 0;
  50343. var lastColumn;
  50344. zrUtil.each(stacks, function (column, idx) {
  50345. if (!column.width) {
  50346. column.width = autoWidth;
  50347. }
  50348. lastColumn = column;
  50349. widthSum += column.width * (1 + barGapPercent);
  50350. });
  50351. if (lastColumn) {
  50352. widthSum -= lastColumn.width * barGapPercent;
  50353. }
  50354. var offset = -widthSum / 2;
  50355. zrUtil.each(stacks, function (column, stackId) {
  50356. result[coordSysName][stackId] = result[coordSysName][stackId] || {
  50357. offset: offset,
  50358. width: column.width
  50359. };
  50360. offset += column.width * (1 + barGapPercent);
  50361. });
  50362. });
  50363. return result;
  50364. }
  50365. module.exports = barLayoutPolar;
  50366. /***/ },
  50367. /* 343 */
  50368. /***/ function(module, exports, __webpack_require__) {
  50369. __webpack_require__(344);
  50370. __webpack_require__(171);
  50371. __webpack_require__(345);
  50372. __webpack_require__(186);
  50373. var echarts = __webpack_require__(1);
  50374. var zrUtil = __webpack_require__(4);
  50375. function makeAction(method, actionInfo) {
  50376. actionInfo.update = 'updateView';
  50377. echarts.registerAction(actionInfo, function (payload, ecModel) {
  50378. var selected = {};
  50379. ecModel.eachComponent(
  50380. { mainType: 'geo', query: payload},
  50381. function (geoModel) {
  50382. geoModel[method](payload.name);
  50383. var geo = geoModel.coordinateSystem;
  50384. zrUtil.each(geo.regions, function (region) {
  50385. selected[region.name] = geoModel.isSelected(region.name) || false;
  50386. });
  50387. }
  50388. );
  50389. return {
  50390. selected: selected,
  50391. name: payload.name
  50392. };
  50393. });
  50394. }
  50395. makeAction('toggleSelected', {
  50396. type: 'geoToggleSelect',
  50397. event: 'geoselectchanged'
  50398. });
  50399. makeAction('select', {
  50400. type: 'geoSelect',
  50401. event: 'geoselected'
  50402. });
  50403. makeAction('unSelect', {
  50404. type: 'geoUnSelect',
  50405. event: 'geounselected'
  50406. });
  50407. /***/ },
  50408. /* 344 */
  50409. /***/ function(module, exports, __webpack_require__) {
  50410. 'use strict';
  50411. var modelUtil = __webpack_require__(5);
  50412. var ComponentModel = __webpack_require__(69);
  50413. var Model = __webpack_require__(12);
  50414. var zrUtil = __webpack_require__(4);
  50415. var selectableMixin = __webpack_require__(148);
  50416. var geoCreator = __webpack_require__(171);
  50417. var GeoModel = ComponentModel.extend({
  50418. type: 'geo',
  50419. /**
  50420. * @type {module:echarts/coord/geo/Geo}
  50421. */
  50422. coordinateSystem: null,
  50423. layoutMode: 'box',
  50424. init: function (option) {
  50425. ComponentModel.prototype.init.apply(this, arguments);
  50426. // Default label emphasis `position` and `show`
  50427. modelUtil.defaultEmphasis(
  50428. option.label, ['position', 'show', 'textStyle', 'distance', 'formatter']
  50429. );
  50430. },
  50431. optionUpdated: function () {
  50432. var option = this.option;
  50433. var self = this;
  50434. option.regions = geoCreator.getFilledRegions(option.regions, option.map);
  50435. this._optionModelMap = zrUtil.reduce(option.regions || [], function (optionModelMap, regionOpt) {
  50436. if (regionOpt.name) {
  50437. optionModelMap.set(regionOpt.name, new Model(regionOpt, self));
  50438. }
  50439. return optionModelMap;
  50440. }, zrUtil.createHashMap());
  50441. this.updateSelectedMap(option.regions);
  50442. },
  50443. defaultOption: {
  50444. zlevel: 0,
  50445. z: 0,
  50446. show: true,
  50447. left: 'center',
  50448. top: 'center',
  50449. // width:,
  50450. // height:,
  50451. // right
  50452. // bottom
  50453. // Aspect is width / height. Inited to be geoJson bbox aspect
  50454. // This parameter is used for scale this aspect
  50455. aspectScale: 0.75,
  50456. ///// Layout with center and size
  50457. // If you wan't to put map in a fixed size box with right aspect ratio
  50458. // This two properties may more conveninet
  50459. // layoutCenter: [50%, 50%]
  50460. // layoutSize: 100
  50461. silent: false,
  50462. // Map type
  50463. map: '',
  50464. // Define left-top, right-bottom coords to control view
  50465. // For example, [ [180, 90], [-180, -90] ]
  50466. boundingCoords: null,
  50467. // Default on center of map
  50468. center: null,
  50469. zoom: 1,
  50470. scaleLimit: null,
  50471. // selectedMode: false
  50472. label: {
  50473. normal: {
  50474. show: false,
  50475. textStyle: {
  50476. color: '#000'
  50477. }
  50478. },
  50479. emphasis: {
  50480. show: true,
  50481. textStyle: {
  50482. color: 'rgb(100,0,0)'
  50483. }
  50484. }
  50485. },
  50486. itemStyle: {
  50487. normal: {
  50488. // color: 各异,
  50489. borderWidth: 0.5,
  50490. borderColor: '#444',
  50491. color: '#eee'
  50492. },
  50493. emphasis: { // 也是选中样式
  50494. color: 'rgba(255,215,0,0.8)'
  50495. }
  50496. },
  50497. regions: []
  50498. },
  50499. /**
  50500. * Get model of region
  50501. * @param {string} name
  50502. * @return {module:echarts/model/Model}
  50503. */
  50504. getRegionModel: function (name) {
  50505. return this._optionModelMap.get(name) || new Model(null, this, this.ecModel);
  50506. },
  50507. /**
  50508. * Format label
  50509. * @param {string} name Region name
  50510. * @param {string} [status='normal'] 'normal' or 'emphasis'
  50511. * @return {string}
  50512. */
  50513. getFormattedLabel: function (name, status) {
  50514. var regionModel = this.getRegionModel(name);
  50515. var formatter = regionModel.get('label.' + status + '.formatter');
  50516. var params = {
  50517. name: name
  50518. };
  50519. if (typeof formatter === 'function') {
  50520. params.status = status;
  50521. return formatter(params);
  50522. }
  50523. else if (typeof formatter === 'string') {
  50524. var serName = params.seriesName;
  50525. return formatter.replace('{a}', serName != null ? serName : '');
  50526. }
  50527. },
  50528. setZoom: function (zoom) {
  50529. this.option.zoom = zoom;
  50530. },
  50531. setCenter: function (center) {
  50532. this.option.center = center;
  50533. }
  50534. });
  50535. zrUtil.mixin(GeoModel, selectableMixin);
  50536. module.exports = GeoModel;
  50537. /***/ },
  50538. /* 345 */
  50539. /***/ function(module, exports, __webpack_require__) {
  50540. 'use strict';
  50541. var MapDraw = __webpack_require__(181);
  50542. module.exports = __webpack_require__(1).extendComponentView({
  50543. type: 'geo',
  50544. init: function (ecModel, api) {
  50545. var mapDraw = new MapDraw(api, true);
  50546. this._mapDraw = mapDraw;
  50547. this.group.add(mapDraw.group);
  50548. },
  50549. render: function (geoModel, ecModel, api, payload) {
  50550. // Not render if it is an toggleSelect action from self
  50551. if (payload && payload.type === 'geoToggleSelect'
  50552. && payload.from === this.uid
  50553. ) {
  50554. return;
  50555. }
  50556. var mapDraw = this._mapDraw;
  50557. if (geoModel.get('show')) {
  50558. mapDraw.draw(geoModel, ecModel, api, this, payload);
  50559. }
  50560. else {
  50561. this._mapDraw.group.removeAll();
  50562. }
  50563. this.group.silent = geoModel.get('silent');
  50564. },
  50565. dispose: function () {
  50566. this._mapDraw && this._mapDraw.remove();
  50567. }
  50568. });
  50569. /***/ },
  50570. /* 346 */
  50571. /***/ function(module, exports, __webpack_require__) {
  50572. /**
  50573. * Brush component entry
  50574. */
  50575. __webpack_require__(1).registerPreprocessor(
  50576. __webpack_require__(347)
  50577. );
  50578. __webpack_require__(348);
  50579. __webpack_require__(352);
  50580. __webpack_require__(353);
  50581. __webpack_require__(354);
  50582. __webpack_require__(355);
  50583. /***/ },
  50584. /* 347 */
  50585. /***/ function(module, exports, __webpack_require__) {
  50586. /**
  50587. * @file brush preprocessor
  50588. */
  50589. var zrUtil = __webpack_require__(4);
  50590. var DEFAULT_TOOLBOX_BTNS = ['rect', 'polygon', 'keep', 'clear'];
  50591. module.exports = function (option, isNew) {
  50592. var brushComponents = option && option.brush;
  50593. if (!zrUtil.isArray(brushComponents)) {
  50594. brushComponents = brushComponents ? [brushComponents] : [];
  50595. }
  50596. if (!brushComponents.length) {
  50597. return;
  50598. }
  50599. var brushComponentSpecifiedBtns = [];
  50600. zrUtil.each(brushComponents, function (brushOpt) {
  50601. var tbs = brushOpt.hasOwnProperty('toolbox')
  50602. ? brushOpt.toolbox : [];
  50603. if (tbs instanceof Array) {
  50604. brushComponentSpecifiedBtns = brushComponentSpecifiedBtns.concat(tbs);
  50605. }
  50606. });
  50607. var toolbox = option && option.toolbox;
  50608. if (zrUtil.isArray(toolbox)) {
  50609. toolbox = toolbox[0];
  50610. }
  50611. if (!toolbox) {
  50612. toolbox = {feature: {}};
  50613. option.toolbox = [toolbox];
  50614. }
  50615. var toolboxFeature = (toolbox.feature || (toolbox.feature = {}));
  50616. var toolboxBrush = toolboxFeature.brush || (toolboxFeature.brush = {});
  50617. var brushTypes = toolboxBrush.type || (toolboxBrush.type = []);
  50618. brushTypes.push.apply(brushTypes, brushComponentSpecifiedBtns);
  50619. removeDuplicate(brushTypes);
  50620. if (isNew && !brushTypes.length) {
  50621. brushTypes.push.apply(brushTypes, DEFAULT_TOOLBOX_BTNS);
  50622. }
  50623. };
  50624. function removeDuplicate(arr) {
  50625. var map = {};
  50626. zrUtil.each(arr, function (val) {
  50627. map[val] = 1;
  50628. });
  50629. arr.length = 0;
  50630. zrUtil.each(map, function (flag, val) {
  50631. arr.push(val);
  50632. });
  50633. }
  50634. /***/ },
  50635. /* 348 */
  50636. /***/ function(module, exports, __webpack_require__) {
  50637. /**
  50638. * @file Brush visual coding.
  50639. */
  50640. var echarts = __webpack_require__(1);
  50641. var visualSolution = __webpack_require__(349);
  50642. var zrUtil = __webpack_require__(4);
  50643. var BoundingRect = __webpack_require__(9);
  50644. var selector = __webpack_require__(350);
  50645. var throttle = __webpack_require__(81);
  50646. var BrushTargetManager = __webpack_require__(351);
  50647. var STATE_LIST = ['inBrush', 'outOfBrush'];
  50648. var DISPATCH_METHOD = '__ecBrushSelect';
  50649. var DISPATCH_FLAG = '__ecInBrushSelectEvent';
  50650. var PRIORITY_BRUSH = echarts.PRIORITY.VISUAL.BRUSH;
  50651. /**
  50652. * Layout for visual, the priority higher than other layout, and before brush visual.
  50653. */
  50654. echarts.registerLayout(PRIORITY_BRUSH, function (ecModel, api, payload) {
  50655. ecModel.eachComponent({mainType: 'brush'}, function (brushModel) {
  50656. payload && payload.type === 'takeGlobalCursor' && brushModel.setBrushOption(
  50657. payload.key === 'brush' ? payload.brushOption : {brushType: false}
  50658. );
  50659. var brushTargetManager = brushModel.brushTargetManager = new BrushTargetManager(brushModel.option, ecModel);
  50660. brushTargetManager.setInputRanges(brushModel.areas, ecModel);
  50661. });
  50662. });
  50663. /**
  50664. * Register the visual encoding if this modules required.
  50665. */
  50666. echarts.registerVisual(PRIORITY_BRUSH, function (ecModel, api, payload) {
  50667. var brushSelected = [];
  50668. var throttleType;
  50669. var throttleDelay;
  50670. ecModel.eachComponent({mainType: 'brush'}, function (brushModel, brushIndex) {
  50671. var thisBrushSelected = {
  50672. brushId: brushModel.id,
  50673. brushIndex: brushIndex,
  50674. brushName: brushModel.name,
  50675. areas: zrUtil.clone(brushModel.areas),
  50676. selected: []
  50677. };
  50678. // Every brush component exists in event params, convenient
  50679. // for user to find by index.
  50680. brushSelected.push(thisBrushSelected);
  50681. var brushOption = brushModel.option;
  50682. var brushLink = brushOption.brushLink;
  50683. var linkedSeriesMap = [];
  50684. var selectedDataIndexForLink = [];
  50685. var rangeInfoBySeries = [];
  50686. var hasBrushExists = 0;
  50687. if (!brushIndex) { // Only the first throttle setting works.
  50688. throttleType = brushOption.throttleType;
  50689. throttleDelay = brushOption.throttleDelay;
  50690. }
  50691. // Add boundingRect and selectors to range.
  50692. var areas = zrUtil.map(brushModel.areas, function (area) {
  50693. return bindSelector(
  50694. zrUtil.defaults(
  50695. {boundingRect: boundingRectBuilders[area.brushType](area)},
  50696. area
  50697. )
  50698. );
  50699. });
  50700. var visualMappings = visualSolution.createVisualMappings(
  50701. brushModel.option, STATE_LIST, function (mappingOption) {
  50702. mappingOption.mappingMethod = 'fixed';
  50703. }
  50704. );
  50705. zrUtil.isArray(brushLink) && zrUtil.each(brushLink, function (seriesIndex) {
  50706. linkedSeriesMap[seriesIndex] = 1;
  50707. });
  50708. function linkOthers(seriesIndex) {
  50709. return brushLink === 'all' || linkedSeriesMap[seriesIndex];
  50710. }
  50711. // If no supported brush or no brush on the series,
  50712. // all visuals should be in original state.
  50713. function brushed(rangeInfoList) {
  50714. return !!rangeInfoList.length;
  50715. }
  50716. /**
  50717. * Logic for each series: (If the logic has to be modified one day, do it carefully!)
  50718. *
  50719. * ( brushed ┬ && ┬hasBrushExist ┬ && linkOthers ) => StepA: ┬record, ┬ StepB: ┬visualByRecord.
  50720. * !brushed┘ ├hasBrushExist ┤ └nothing,┘ ├visualByRecord.
  50721. * └!hasBrushExist┘ └nothing.
  50722. * ( !brushed && ┬hasBrushExist ┬ && linkOthers ) => StepA: nothing, StepB: ┬visualByRecord.
  50723. * └!hasBrushExist┘ └nothing.
  50724. * ( brushed ┬ && !linkOthers ) => StepA: nothing, StepB: ┬visualByCheck.
  50725. * !brushed┘ └nothing.
  50726. * ( !brushed && !linkOthers ) => StepA: nothing, StepB: nothing.
  50727. */
  50728. // Step A
  50729. ecModel.eachSeries(function (seriesModel, seriesIndex) {
  50730. var rangeInfoList = rangeInfoBySeries[seriesIndex] = [];
  50731. seriesModel.subType === 'parallel'
  50732. ? stepAParallel(seriesModel, seriesIndex, rangeInfoList)
  50733. : stepAOthers(seriesModel, seriesIndex, rangeInfoList);
  50734. });
  50735. function stepAParallel(seriesModel, seriesIndex) {
  50736. var coordSys = seriesModel.coordinateSystem;
  50737. hasBrushExists |= coordSys.hasAxisBrushed();
  50738. linkOthers(seriesIndex) && coordSys.eachActiveState(
  50739. seriesModel.getData(),
  50740. function (activeState, dataIndex) {
  50741. activeState === 'active' && (selectedDataIndexForLink[dataIndex] = 1);
  50742. }
  50743. );
  50744. }
  50745. function stepAOthers(seriesModel, seriesIndex, rangeInfoList) {
  50746. var selectorsByBrushType = getSelectorsByBrushType(seriesModel);
  50747. if (!selectorsByBrushType || brushModelNotControll(brushModel, seriesIndex)) {
  50748. return;
  50749. }
  50750. zrUtil.each(areas, function (area) {
  50751. selectorsByBrushType[area.brushType]
  50752. && brushModel.brushTargetManager.controlSeries(area, seriesModel, ecModel)
  50753. && rangeInfoList.push(area);
  50754. hasBrushExists |= brushed(rangeInfoList);
  50755. });
  50756. if (linkOthers(seriesIndex) && brushed(rangeInfoList)) {
  50757. var data = seriesModel.getData();
  50758. data.each(function (dataIndex) {
  50759. if (checkInRange(selectorsByBrushType, rangeInfoList, data, dataIndex)) {
  50760. selectedDataIndexForLink[dataIndex] = 1;
  50761. }
  50762. });
  50763. }
  50764. }
  50765. // Step B
  50766. ecModel.eachSeries(function (seriesModel, seriesIndex) {
  50767. var seriesBrushSelected = {
  50768. seriesId: seriesModel.id,
  50769. seriesIndex: seriesIndex,
  50770. seriesName: seriesModel.name,
  50771. dataIndex: []
  50772. };
  50773. // Every series exists in event params, convenient
  50774. // for user to find series by seriesIndex.
  50775. thisBrushSelected.selected.push(seriesBrushSelected);
  50776. var selectorsByBrushType = getSelectorsByBrushType(seriesModel);
  50777. var rangeInfoList = rangeInfoBySeries[seriesIndex];
  50778. var data = seriesModel.getData();
  50779. var getValueState = linkOthers(seriesIndex)
  50780. ? function (dataIndex) {
  50781. return selectedDataIndexForLink[dataIndex]
  50782. ? (seriesBrushSelected.dataIndex.push(data.getRawIndex(dataIndex)), 'inBrush')
  50783. : 'outOfBrush';
  50784. }
  50785. : function (dataIndex) {
  50786. return checkInRange(selectorsByBrushType, rangeInfoList, data, dataIndex)
  50787. ? (seriesBrushSelected.dataIndex.push(data.getRawIndex(dataIndex)), 'inBrush')
  50788. : 'outOfBrush';
  50789. };
  50790. // If no supported brush or no brush, all visuals are in original state.
  50791. (linkOthers(seriesIndex) ? hasBrushExists : brushed(rangeInfoList))
  50792. && visualSolution.applyVisual(
  50793. STATE_LIST, visualMappings, data, getValueState
  50794. );
  50795. });
  50796. });
  50797. dispatchAction(api, throttleType, throttleDelay, brushSelected, payload);
  50798. });
  50799. function dispatchAction(api, throttleType, throttleDelay, brushSelected, payload) {
  50800. // This event will not be triggered when `setOpion`, otherwise dead lock may
  50801. // triggered when do `setOption` in event listener, which we do not find
  50802. // satisfactory way to solve yet. Some considered resolutions:
  50803. // (a) Diff with prevoius selected data ant only trigger event when changed.
  50804. // But store previous data and diff precisely (i.e., not only by dataIndex, but
  50805. // also detect value changes in selected data) might bring complexity or fragility.
  50806. // (b) Use spectial param like `silent` to suppress event triggering.
  50807. // But such kind of volatile param may be weird in `setOption`.
  50808. if (!payload) {
  50809. return;
  50810. }
  50811. var zr = api.getZr();
  50812. if (zr[DISPATCH_FLAG]) {
  50813. return;
  50814. }
  50815. if (!zr[DISPATCH_METHOD]) {
  50816. zr[DISPATCH_METHOD] = doDispatch;
  50817. }
  50818. var fn = throttle.createOrUpdate(zr, DISPATCH_METHOD, throttleDelay, throttleType);
  50819. fn(api, brushSelected);
  50820. }
  50821. function doDispatch(api, brushSelected) {
  50822. if (!api.isDisposed()) {
  50823. var zr = api.getZr();
  50824. zr[DISPATCH_FLAG] = true;
  50825. api.dispatchAction({
  50826. type: 'brushSelect',
  50827. batch: brushSelected
  50828. });
  50829. zr[DISPATCH_FLAG] = false;
  50830. }
  50831. }
  50832. function checkInRange(selectorsByBrushType, rangeInfoList, data, dataIndex) {
  50833. for (var i = 0, len = rangeInfoList.length; i < len; i++) {
  50834. var area = rangeInfoList[i];
  50835. if (selectorsByBrushType[area.brushType](
  50836. dataIndex, data, area.selectors, area
  50837. )) {
  50838. return true;
  50839. }
  50840. }
  50841. }
  50842. function getSelectorsByBrushType(seriesModel) {
  50843. var brushSelector = seriesModel.brushSelector;
  50844. if (zrUtil.isString(brushSelector)) {
  50845. var sels = [];
  50846. zrUtil.each(selector, function (selectorsByElementType, brushType) {
  50847. sels[brushType] = function (dataIndex, data, selectors, area) {
  50848. var itemLayout = data.getItemLayout(dataIndex);
  50849. return selectorsByElementType[brushSelector](itemLayout, selectors, area);
  50850. };
  50851. });
  50852. return sels;
  50853. }
  50854. else if (zrUtil.isFunction(brushSelector)) {
  50855. var bSelector = {};
  50856. zrUtil.each(selector, function (sel, brushType) {
  50857. bSelector[brushType] = brushSelector;
  50858. });
  50859. return bSelector;
  50860. }
  50861. return brushSelector;
  50862. }
  50863. function brushModelNotControll(brushModel, seriesIndex) {
  50864. var seriesIndices = brushModel.option.seriesIndex;
  50865. return seriesIndices != null
  50866. && seriesIndices !== 'all'
  50867. && (
  50868. zrUtil.isArray(seriesIndices)
  50869. ? zrUtil.indexOf(seriesIndices, seriesIndex) < 0
  50870. : seriesIndex !== seriesIndices
  50871. );
  50872. }
  50873. function bindSelector(area) {
  50874. var selectors = area.selectors = {};
  50875. zrUtil.each(selector[area.brushType], function (selFn, elType) {
  50876. // Do not use function binding or curry for performance.
  50877. selectors[elType] = function (itemLayout) {
  50878. return selFn(itemLayout, selectors, area);
  50879. };
  50880. });
  50881. return area;
  50882. }
  50883. var boundingRectBuilders = {
  50884. lineX: zrUtil.noop,
  50885. lineY: zrUtil.noop,
  50886. rect: function (area) {
  50887. return getBoundingRectFromMinMax(area.range);
  50888. },
  50889. polygon: function (area) {
  50890. var minMax;
  50891. var range = area.range;
  50892. for (var i = 0, len = range.length; i < len; i++) {
  50893. minMax = minMax || [[Infinity, -Infinity], [Infinity, -Infinity]];
  50894. var rg = range[i];
  50895. rg[0] < minMax[0][0] && (minMax[0][0] = rg[0]);
  50896. rg[0] > minMax[0][1] && (minMax[0][1] = rg[0]);
  50897. rg[1] < minMax[1][0] && (minMax[1][0] = rg[1]);
  50898. rg[1] > minMax[1][1] && (minMax[1][1] = rg[1]);
  50899. }
  50900. return minMax && getBoundingRectFromMinMax(minMax);
  50901. }
  50902. };
  50903. function getBoundingRectFromMinMax(minMax) {
  50904. return new BoundingRect(
  50905. minMax[0][0],
  50906. minMax[1][0],
  50907. minMax[0][1] - minMax[0][0],
  50908. minMax[1][1] - minMax[1][0]
  50909. );
  50910. }
  50911. /***/ },
  50912. /* 349 */
  50913. /***/ function(module, exports, __webpack_require__) {
  50914. /**
  50915. * @file Visual solution, for consistent option specification.
  50916. */
  50917. var zrUtil = __webpack_require__(4);
  50918. var VisualMapping = __webpack_require__(202);
  50919. var each = zrUtil.each;
  50920. function hasKeys(obj) {
  50921. if (obj) {
  50922. for (var name in obj){
  50923. if (obj.hasOwnProperty(name)) {
  50924. return true;
  50925. }
  50926. }
  50927. }
  50928. }
  50929. var visualSolution = {
  50930. /**
  50931. * @param {Object} option
  50932. * @param {Array.<string>} stateList
  50933. * @param {Function} [supplementVisualOption]
  50934. * @return {Object} visualMappings <state, <visualType, module:echarts/visual/VisualMapping>>
  50935. */
  50936. createVisualMappings: function (option, stateList, supplementVisualOption) {
  50937. var visualMappings = {};
  50938. each(stateList, function (state) {
  50939. var mappings = visualMappings[state] = createMappings();
  50940. each(option[state], function (visualData, visualType) {
  50941. if (!VisualMapping.isValidType(visualType)) {
  50942. return;
  50943. }
  50944. var mappingOption = {
  50945. type: visualType,
  50946. visual: visualData
  50947. };
  50948. supplementVisualOption && supplementVisualOption(mappingOption, state);
  50949. mappings[visualType] = new VisualMapping(mappingOption);
  50950. // Prepare a alpha for opacity, for some case that opacity
  50951. // is not supported, such as rendering using gradient color.
  50952. if (visualType === 'opacity') {
  50953. mappingOption = zrUtil.clone(mappingOption);
  50954. mappingOption.type = 'colorAlpha';
  50955. mappings.__hidden.__alphaForOpacity = new VisualMapping(mappingOption);
  50956. }
  50957. });
  50958. });
  50959. return visualMappings;
  50960. function createMappings() {
  50961. var Creater = function () {};
  50962. // Make sure hidden fields will not be visited by
  50963. // object iteration (with hasOwnProperty checking).
  50964. Creater.prototype.__hidden = Creater.prototype;
  50965. var obj = new Creater();
  50966. return obj;
  50967. }
  50968. },
  50969. /**
  50970. * @param {Object} thisOption
  50971. * @param {Object} newOption
  50972. * @param {Array.<string>} keys
  50973. */
  50974. replaceVisualOption: function (thisOption, newOption, keys) {
  50975. // Visual attributes merge is not supported, otherwise it
  50976. // brings overcomplicated merge logic. See #2853. So if
  50977. // newOption has anyone of these keys, all of these keys
  50978. // will be reset. Otherwise, all keys remain.
  50979. var has;
  50980. zrUtil.each(keys, function (key) {
  50981. if (newOption.hasOwnProperty(key) && hasKeys(newOption[key])) {
  50982. has = true;
  50983. }
  50984. });
  50985. has && zrUtil.each(keys, function (key) {
  50986. if (newOption.hasOwnProperty(key) && hasKeys(newOption[key])) {
  50987. thisOption[key] = zrUtil.clone(newOption[key]);
  50988. }
  50989. else {
  50990. delete thisOption[key];
  50991. }
  50992. });
  50993. },
  50994. /**
  50995. * @param {Array.<string>} stateList
  50996. * @param {Object} visualMappings <state, Object.<visualType, module:echarts/visual/VisualMapping>>
  50997. * @param {module:echarts/data/List} list
  50998. * @param {Function} getValueState param: valueOrIndex, return: state.
  50999. * @param {object} [scope] Scope for getValueState
  51000. * @param {string} [dimension] Concrete dimension, if used.
  51001. */
  51002. applyVisual: function (stateList, visualMappings, data, getValueState, scope, dimension) {
  51003. var visualTypesMap = {};
  51004. zrUtil.each(stateList, function (state) {
  51005. var visualTypes = VisualMapping.prepareVisualTypes(visualMappings[state]);
  51006. visualTypesMap[state] = visualTypes;
  51007. });
  51008. var dataIndex;
  51009. function getVisual(key) {
  51010. return data.getItemVisual(dataIndex, key);
  51011. }
  51012. function setVisual(key, value) {
  51013. data.setItemVisual(dataIndex, key, value);
  51014. }
  51015. if (dimension == null) {
  51016. data.each(eachItem, true);
  51017. }
  51018. else {
  51019. data.each([dimension], eachItem, true);
  51020. }
  51021. function eachItem(valueOrIndex, index) {
  51022. dataIndex = dimension == null ? valueOrIndex : index;
  51023. var rawDataItem = data.getRawDataItem(dataIndex);
  51024. // Consider performance
  51025. if (rawDataItem && rawDataItem.visualMap === false) {
  51026. return;
  51027. }
  51028. var valueState = getValueState.call(scope, valueOrIndex);
  51029. var mappings = visualMappings[valueState];
  51030. var visualTypes = visualTypesMap[valueState];
  51031. for (var i = 0, len = visualTypes.length; i < len; i++) {
  51032. var type = visualTypes[i];
  51033. mappings[type] && mappings[type].applyVisual(
  51034. valueOrIndex, getVisual, setVisual
  51035. );
  51036. }
  51037. }
  51038. }
  51039. };
  51040. module.exports = visualSolution;
  51041. /***/ },
  51042. /* 350 */
  51043. /***/ function(module, exports, __webpack_require__) {
  51044. var polygonContain = __webpack_require__(175).contain;
  51045. var BoundingRect = __webpack_require__(9);
  51046. // Key of the first level is brushType: `line`, `rect`, `polygon`.
  51047. // Key of the second level is chart element type: `point`, `rect`.
  51048. // See moudule:echarts/component/helper/BrushController
  51049. // function param:
  51050. // {Object} itemLayout fetch from data.getItemLayout(dataIndex)
  51051. // {Object} selectors {point: selector, rect: selector, ...}
  51052. // {Object} area {range: [[], [], ..], boudingRect}
  51053. // function return:
  51054. // {boolean} Whether in the given brush.
  51055. var selector = {
  51056. lineX: getLineSelectors(0),
  51057. lineY: getLineSelectors(1),
  51058. rect: {
  51059. point: function (itemLayout, selectors, area) {
  51060. return area.boundingRect.contain(itemLayout[0], itemLayout[1]);
  51061. },
  51062. rect: function (itemLayout, selectors, area) {
  51063. return area.boundingRect.intersect(itemLayout);
  51064. }
  51065. },
  51066. polygon: {
  51067. point: function (itemLayout, selectors, area) {
  51068. return area.boundingRect.contain(itemLayout[0], itemLayout[1])
  51069. && polygonContain(area.range, itemLayout[0], itemLayout[1]);
  51070. },
  51071. rect: function (itemLayout, selectors, area) {
  51072. var points = area.range;
  51073. if (points.length <= 1) {
  51074. return false;
  51075. }
  51076. var x = itemLayout.x;
  51077. var y = itemLayout.y;
  51078. var width = itemLayout.width;
  51079. var height = itemLayout.height;
  51080. var p = points[0];
  51081. if (polygonContain(points, x, y)
  51082. || polygonContain(points, x + width, y)
  51083. || polygonContain(points, x, y + height)
  51084. || polygonContain(points, x + width, y + height)
  51085. || BoundingRect.create(itemLayout).contain(p[0], p[1])
  51086. || lineIntersectPolygon(x, y, x + width, y, points)
  51087. || lineIntersectPolygon(x, y, x, y + height, points)
  51088. || lineIntersectPolygon(x + width, y, x + width, y + height, points)
  51089. || lineIntersectPolygon(x, y + height, x + width, y + height, points)
  51090. ) {
  51091. return true;
  51092. }
  51093. }
  51094. }
  51095. };
  51096. function getLineSelectors(xyIndex) {
  51097. var xy = ['x', 'y'];
  51098. var wh = ['width', 'height'];
  51099. return {
  51100. point: function (itemLayout, selectors, area) {
  51101. var range = area.range;
  51102. var p = itemLayout[xyIndex];
  51103. return inLineRange(p, range);
  51104. },
  51105. rect: function (itemLayout, selectors, area) {
  51106. var range = area.range;
  51107. var layoutRange = [
  51108. itemLayout[xy[xyIndex]],
  51109. itemLayout[xy[xyIndex]] + itemLayout[wh[xyIndex]]
  51110. ];
  51111. layoutRange[1] < layoutRange[0] && layoutRange.reverse();
  51112. return inLineRange(layoutRange[0], range)
  51113. || inLineRange(layoutRange[1], range)
  51114. || inLineRange(range[0], layoutRange)
  51115. || inLineRange(range[1], layoutRange);
  51116. }
  51117. };
  51118. }
  51119. function inLineRange(p, range) {
  51120. return range[0] <= p && p <= range[1];
  51121. }
  51122. function lineIntersectPolygon(lx, ly, l2x, l2y, points) {
  51123. for (var i = 0, p2 = points[points.length - 1]; i < points.length; i++) {
  51124. var p = points[i];
  51125. if (lineIntersect(lx, ly, l2x, l2y, p[0], p[1], p2[0], p2[1])) {
  51126. return true;
  51127. }
  51128. p2 = p;
  51129. }
  51130. }
  51131. // Code from <http://blog.csdn.net/rickliuxiao/article/details/6259322> with some fix.
  51132. // See <https://en.wikipedia.org/wiki/Line%E2%80%93line_intersection>
  51133. function lineIntersect(a1x, a1y, a2x, a2y, b1x, b1y, b2x, b2y) {
  51134. var delta = determinant(a2x - a1x, b1x - b2x, a2y - a1y, b1y - b2y);
  51135. if (nearZero(delta)) { // parallel
  51136. return false;
  51137. }
  51138. var namenda = determinant(b1x - a1x, b1x - b2x, b1y - a1y, b1y - b2y) / delta;
  51139. if (namenda < 0 || namenda > 1) {
  51140. return false;
  51141. }
  51142. var miu = determinant(a2x - a1x, b1x - a1x, a2y - a1y, b1y - a1y) / delta;
  51143. if (miu < 0 || miu > 1) {
  51144. return false;
  51145. }
  51146. return true;
  51147. }
  51148. function nearZero(val) {
  51149. return val <= (1e-6) && val >= -(1e-6);
  51150. }
  51151. function determinant(v1, v2, v3, v4) {
  51152. return v1 * v4 - v2 * v3;
  51153. }
  51154. module.exports = selector;
  51155. /***/ },
  51156. /* 351 */
  51157. /***/ function(module, exports, __webpack_require__) {
  51158. var zrUtil = __webpack_require__(4);
  51159. var graphic = __webpack_require__(18);
  51160. var modelUtil = __webpack_require__(5);
  51161. var brushHelper = __webpack_require__(245);
  51162. var each = zrUtil.each;
  51163. var indexOf = zrUtil.indexOf;
  51164. var curry = zrUtil.curry;
  51165. var COORD_CONVERTS = ['dataToPoint', 'pointToData'];
  51166. // FIXME
  51167. // how to genarialize to more coordinate systems.
  51168. var INCLUDE_FINDER_MAIN_TYPES = [
  51169. 'grid', 'xAxis', 'yAxis', 'geo', 'graph',
  51170. 'polar', 'radiusAxis', 'angleAxis', 'bmap'
  51171. ];
  51172. /**
  51173. * [option in constructor]:
  51174. * {
  51175. * Index/Id/Name of geo, xAxis, yAxis, grid: See util/model#parseFinder.
  51176. * }
  51177. *
  51178. *
  51179. * [targetInfo]:
  51180. *
  51181. * There can be multiple axes in a single targetInfo. Consider the case
  51182. * of `grid` component, a targetInfo represents a grid which contains one or more
  51183. * cartesian and one or more axes. And consider the case of parallel system,
  51184. * which has multiple axes in a coordinate system.
  51185. * Can be {
  51186. * panelId: ...,
  51187. * coordSys: <a representitive cartesian in grid (first cartesian by default)>,
  51188. * coordSyses: all cartesians.
  51189. * gridModel: <grid component>
  51190. * xAxes: correspond to coordSyses on index
  51191. * yAxes: correspond to coordSyses on index
  51192. * }
  51193. * or {
  51194. * panelId: ...,
  51195. * coordSys: <geo coord sys>
  51196. * coordSyses: [<geo coord sys>]
  51197. * geoModel: <geo component>
  51198. * }
  51199. *
  51200. *
  51201. * [panelOpt]:
  51202. *
  51203. * Make from targetInfo. Input to BrushController.
  51204. * {
  51205. * panelId: ...,
  51206. * rect: ...
  51207. * }
  51208. *
  51209. *
  51210. * [area]:
  51211. *
  51212. * Generated by BrushController or user input.
  51213. * {
  51214. * panelId: Used to locate coordInfo directly. If user inpput, no panelId.
  51215. * brushType: determine how to convert to/from coord('rect' or 'polygon' or 'lineX/Y').
  51216. * Index/Id/Name of geo, xAxis, yAxis, grid: See util/model#parseFinder.
  51217. * range: pixel range.
  51218. * coordRange: representitive coord range (the first one of coordRanges).
  51219. * coordRanges: <Array> coord ranges, used in multiple cartesian in one grid.
  51220. * }
  51221. */
  51222. /**
  51223. * @param {Object} option contains Index/Id/Name of xAxis/yAxis/geo/grid
  51224. * Each can be {number|Array.<number>}. like: {xAxisIndex: [3, 4]}
  51225. * @param {module:echarts/model/Global} ecModel
  51226. * @param {Object} [opt]
  51227. * @param {Array.<string>} [opt.include] include coordinate system types.
  51228. */
  51229. function BrushTargetManager(option, ecModel, opt) {
  51230. /**
  51231. * @private
  51232. * @type {Array.<Object>}
  51233. */
  51234. var targetInfoList = this._targetInfoList = [];
  51235. var info = {};
  51236. var foundCpts = parseFinder(ecModel, option);
  51237. each(targetInfoBuilders, function (builder, type) {
  51238. if (!opt || !opt.include || indexOf(opt.include, type) >= 0) {
  51239. builder(foundCpts, targetInfoList, info);
  51240. }
  51241. });
  51242. }
  51243. var proto = BrushTargetManager.prototype;
  51244. proto.setOutputRanges = function (areas, ecModel) {
  51245. this.matchOutputRanges(areas, ecModel, function (area, coordRange, coordSys) {
  51246. (area.coordRanges || (area.coordRanges = [])).push(coordRange);
  51247. // area.coordRange is the first of area.coordRanges
  51248. if (!area.coordRange) {
  51249. area.coordRange = coordRange;
  51250. // In 'category' axis, coord to pixel is not reversible, so we can not
  51251. // rebuild range by coordRange accrately, which may bring trouble when
  51252. // brushing only one item. So we use __rangeOffset to rebuilding range
  51253. // by coordRange. And this it only used in brush component so it is no
  51254. // need to be adapted to coordRanges.
  51255. var result = coordConvert[area.brushType](0, coordSys, coordRange);
  51256. area.__rangeOffset = {
  51257. offset: diffProcessor[area.brushType](result.values, area.range, [1, 1]),
  51258. xyMinMax: result.xyMinMax
  51259. };
  51260. }
  51261. });
  51262. };
  51263. proto.matchOutputRanges = function (areas, ecModel, cb) {
  51264. each(areas, function (area) {
  51265. var targetInfo = this.findTargetInfo(area, ecModel);
  51266. if (targetInfo && targetInfo !== true) {
  51267. zrUtil.each(
  51268. targetInfo.coordSyses,
  51269. function (coordSys) {
  51270. var result = coordConvert[area.brushType](1, coordSys, area.range);
  51271. cb(area, result.values, coordSys, ecModel);
  51272. }
  51273. );
  51274. }
  51275. }, this);
  51276. };
  51277. proto.setInputRanges = function (areas, ecModel) {
  51278. each(areas, function (area) {
  51279. var targetInfo = this.findTargetInfo(area, ecModel);
  51280. if (true) {
  51281. zrUtil.assert(
  51282. !targetInfo || targetInfo === true || area.coordRange,
  51283. 'coordRange must be specified when coord index specified.'
  51284. );
  51285. zrUtil.assert(
  51286. !targetInfo || targetInfo !== true || area.range,
  51287. 'range must be specified in global brush.'
  51288. );
  51289. }
  51290. area.range = area.range || [];
  51291. // convert coordRange to global range and set panelId.
  51292. if (targetInfo && targetInfo !== true) {
  51293. area.panelId = targetInfo.panelId;
  51294. // (1) area.range shoule always be calculate from coordRange but does
  51295. // not keep its original value, for the sake of the dataZoom scenario,
  51296. // where area.coordRange remains unchanged but area.range may be changed.
  51297. // (2) Only support converting one coordRange to pixel range in brush
  51298. // component. So do not consider `coordRanges`.
  51299. // (3) About __rangeOffset, see comment above.
  51300. var result = coordConvert[area.brushType](0, targetInfo.coordSys, area.coordRange);
  51301. var rangeOffset = area.__rangeOffset;
  51302. area.range = rangeOffset
  51303. ? diffProcessor[area.brushType](
  51304. result.values,
  51305. rangeOffset.offset,
  51306. getScales(result.xyMinMax, rangeOffset.xyMinMax)
  51307. )
  51308. : result.values;
  51309. }
  51310. }, this);
  51311. };
  51312. proto.makePanelOpts = function (api, getDefaultBrushType) {
  51313. return zrUtil.map(this._targetInfoList, function (targetInfo) {
  51314. var rect = targetInfo.getPanelRect();
  51315. return {
  51316. panelId: targetInfo.panelId,
  51317. defaultBrushType: getDefaultBrushType && getDefaultBrushType(targetInfo),
  51318. clipPath: brushHelper.makeRectPanelClipPath(rect),
  51319. isTargetByCursor: brushHelper.makeRectIsTargetByCursor(
  51320. rect, api, targetInfo.coordSysModel
  51321. ),
  51322. getLinearBrushOtherExtent: brushHelper.makeLinearBrushOtherExtent(rect)
  51323. };
  51324. });
  51325. };
  51326. proto.controlSeries = function (area, seriesModel, ecModel) {
  51327. // Check whether area is bound in coord, and series do not belong to that coord.
  51328. // If do not do this check, some brush (like lineX) will controll all axes.
  51329. var targetInfo = this.findTargetInfo(area, ecModel);
  51330. return targetInfo === true || (
  51331. targetInfo && indexOf(targetInfo.coordSyses, seriesModel.coordinateSystem) >= 0
  51332. );
  51333. };
  51334. /**
  51335. * If return Object, a coord found.
  51336. * If reutrn true, global found.
  51337. * Otherwise nothing found.
  51338. *
  51339. * @param {Object} area
  51340. * @param {Array} targetInfoList
  51341. * @return {Obejct|boolean}
  51342. */
  51343. proto.findTargetInfo = function (area, ecModel) {
  51344. var targetInfoList = this._targetInfoList;
  51345. var foundCpts = parseFinder(ecModel, area);
  51346. for (var i = 0; i < targetInfoList.length; i++) {
  51347. var targetInfo = targetInfoList[i];
  51348. var areaPanelId = area.panelId;
  51349. if (areaPanelId) {
  51350. if (targetInfo.panelId === areaPanelId) {
  51351. return targetInfo;
  51352. }
  51353. }
  51354. else {
  51355. for (var i = 0; i < targetInfoMatchers.length; i++) {
  51356. if (targetInfoMatchers[i](foundCpts, targetInfo)) {
  51357. return targetInfo;
  51358. }
  51359. }
  51360. }
  51361. }
  51362. return true;
  51363. };
  51364. function formatMinMax(minMax) {
  51365. minMax[0] > minMax[1] && minMax.reverse();
  51366. return minMax;
  51367. }
  51368. function parseFinder(ecModel, option) {
  51369. return modelUtil.parseFinder(
  51370. ecModel, option, {includeMainTypes: INCLUDE_FINDER_MAIN_TYPES}
  51371. );
  51372. }
  51373. var targetInfoBuilders = {
  51374. grid: function (foundCpts, targetInfoList) {
  51375. var xAxisModels = foundCpts.xAxisModels;
  51376. var yAxisModels = foundCpts.yAxisModels;
  51377. var gridModels = foundCpts.gridModels;
  51378. // Remove duplicated.
  51379. var gridModelMap = zrUtil.createHashMap();
  51380. var xAxesHas = {};
  51381. var yAxesHas = {};
  51382. if (!xAxisModels && !yAxisModels && !gridModels) {
  51383. return;
  51384. }
  51385. each(xAxisModels, function (axisModel) {
  51386. var gridModel = axisModel.axis.grid.model;
  51387. gridModelMap.set(gridModel.id, gridModel);
  51388. xAxesHas[gridModel.id] = true;
  51389. });
  51390. each(yAxisModels, function (axisModel) {
  51391. var gridModel = axisModel.axis.grid.model;
  51392. gridModelMap.set(gridModel.id, gridModel);
  51393. yAxesHas[gridModel.id] = true;
  51394. });
  51395. each(gridModels, function (gridModel) {
  51396. gridModelMap.set(gridModel.id, gridModel);
  51397. xAxesHas[gridModel.id] = true;
  51398. yAxesHas[gridModel.id] = true;
  51399. });
  51400. gridModelMap.each(function (gridModel) {
  51401. var grid = gridModel.coordinateSystem;
  51402. var cartesians = [];
  51403. each(grid.getCartesians(), function (cartesian, index) {
  51404. if (indexOf(xAxisModels, cartesian.getAxis('x').model) >= 0
  51405. || indexOf(yAxisModels, cartesian.getAxis('y').model) >= 0
  51406. ) {
  51407. cartesians.push(cartesian);
  51408. }
  51409. });
  51410. targetInfoList.push({
  51411. panelId: 'grid--' + gridModel.id,
  51412. gridModel: gridModel,
  51413. coordSysModel: gridModel,
  51414. // Use the first one as the representitive coordSys.
  51415. coordSys: cartesians[0],
  51416. coordSyses: cartesians,
  51417. getPanelRect: panelRectBuilder.grid,
  51418. xAxisDeclared: xAxesHas[gridModel.id],
  51419. yAxisDeclared: yAxesHas[gridModel.id]
  51420. });
  51421. });
  51422. },
  51423. geo: function (foundCpts, targetInfoList) {
  51424. each(foundCpts.geoModels, function (geoModel) {
  51425. var coordSys = geoModel.coordinateSystem;
  51426. targetInfoList.push({
  51427. panelId: 'geo--' + geoModel.id,
  51428. geoModel: geoModel,
  51429. coordSysModel: geoModel,
  51430. coordSys: coordSys,
  51431. coordSyses: [coordSys],
  51432. getPanelRect: panelRectBuilder.geo
  51433. });
  51434. });
  51435. }
  51436. };
  51437. var targetInfoMatchers = [
  51438. // grid
  51439. function (foundCpts, targetInfo) {
  51440. var xAxisModel = foundCpts.xAxisModel;
  51441. var yAxisModel = foundCpts.yAxisModel;
  51442. var gridModel = foundCpts.gridModel;
  51443. !gridModel && xAxisModel && (gridModel = xAxisModel.axis.grid.model);
  51444. !gridModel && yAxisModel && (gridModel = yAxisModel.axis.grid.model);
  51445. return gridModel && gridModel === targetInfo.gridModel;
  51446. },
  51447. // geo
  51448. function (foundCpts, targetInfo) {
  51449. var geoModel = foundCpts.geoModel;
  51450. return geoModel && geoModel === targetInfo.geoModel;
  51451. }
  51452. ];
  51453. var panelRectBuilder = {
  51454. grid: function () {
  51455. // grid is not Transformable.
  51456. return this.coordSys.grid.getRect().clone();
  51457. },
  51458. geo: function () {
  51459. var coordSys = this.coordSys;
  51460. var rect = coordSys.getBoundingRect().clone();
  51461. // geo roam and zoom transform
  51462. rect.applyTransform(graphic.getTransform(coordSys));
  51463. return rect;
  51464. }
  51465. };
  51466. var coordConvert = {
  51467. lineX: curry(axisConvert, 0),
  51468. lineY: curry(axisConvert, 1),
  51469. rect: function (to, coordSys, rangeOrCoordRange) {
  51470. var xminymin = coordSys[COORD_CONVERTS[to]]([rangeOrCoordRange[0][0], rangeOrCoordRange[1][0]]);
  51471. var xmaxymax = coordSys[COORD_CONVERTS[to]]([rangeOrCoordRange[0][1], rangeOrCoordRange[1][1]]);
  51472. var values = [
  51473. formatMinMax([xminymin[0], xmaxymax[0]]),
  51474. formatMinMax([xminymin[1], xmaxymax[1]])
  51475. ];
  51476. return {values: values, xyMinMax: values};
  51477. },
  51478. polygon: function (to, coordSys, rangeOrCoordRange) {
  51479. var xyMinMax = [[Infinity, -Infinity], [Infinity, -Infinity]];
  51480. var values = zrUtil.map(rangeOrCoordRange, function (item) {
  51481. var p = coordSys[COORD_CONVERTS[to]](item);
  51482. xyMinMax[0][0] = Math.min(xyMinMax[0][0], p[0]);
  51483. xyMinMax[1][0] = Math.min(xyMinMax[1][0], p[1]);
  51484. xyMinMax[0][1] = Math.max(xyMinMax[0][1], p[0]);
  51485. xyMinMax[1][1] = Math.max(xyMinMax[1][1], p[1]);
  51486. return p;
  51487. });
  51488. return {values: values, xyMinMax: xyMinMax};
  51489. }
  51490. };
  51491. function axisConvert(axisNameIndex, to, coordSys, rangeOrCoordRange) {
  51492. if (true) {
  51493. zrUtil.assert(
  51494. coordSys.type === 'cartesian2d',
  51495. 'lineX/lineY brush is available only in cartesian2d.'
  51496. );
  51497. }
  51498. var axis = coordSys.getAxis(['x', 'y'][axisNameIndex]);
  51499. var values = formatMinMax(zrUtil.map([0, 1], function (i) {
  51500. return to
  51501. ? axis.coordToData(axis.toLocalCoord(rangeOrCoordRange[i]))
  51502. : axis.toGlobalCoord(axis.dataToCoord(rangeOrCoordRange[i]));
  51503. }));
  51504. var xyMinMax = [];
  51505. xyMinMax[axisNameIndex] = values;
  51506. xyMinMax[1 - axisNameIndex] = [NaN, NaN];
  51507. return {values: values, xyMinMax: xyMinMax};
  51508. }
  51509. var diffProcessor = {
  51510. lineX: curry(axisDiffProcessor, 0),
  51511. lineY: curry(axisDiffProcessor, 1),
  51512. rect: function (values, refer, scales) {
  51513. return [
  51514. [values[0][0] - scales[0] * refer[0][0], values[0][1] - scales[0] * refer[0][1]],
  51515. [values[1][0] - scales[1] * refer[1][0], values[1][1] - scales[1] * refer[1][1]]
  51516. ];
  51517. },
  51518. polygon: function (values, refer, scales) {
  51519. return zrUtil.map(values, function (item, idx) {
  51520. return [item[0] - scales[0] * refer[idx][0], item[1] - scales[1] * refer[idx][1]];
  51521. });
  51522. }
  51523. };
  51524. function axisDiffProcessor(axisNameIndex, values, refer, scales) {
  51525. return [
  51526. values[0] - scales[axisNameIndex] * refer[0],
  51527. values[1] - scales[axisNameIndex] * refer[1]
  51528. ];
  51529. }
  51530. // We have to process scale caused by dataZoom manually,
  51531. // although it might be not accurate.
  51532. function getScales(xyMinMaxCurr, xyMinMaxOrigin) {
  51533. var sizeCurr = getSize(xyMinMaxCurr);
  51534. var sizeOrigin = getSize(xyMinMaxOrigin);
  51535. var scales = [sizeCurr[0] / sizeOrigin[0], sizeCurr[1] / sizeOrigin[1]];
  51536. isNaN(scales[0]) && (scales[0] = 1);
  51537. isNaN(scales[1]) && (scales[1] = 1);
  51538. return scales;
  51539. }
  51540. function getSize(xyMinMax) {
  51541. return xyMinMax
  51542. ? [xyMinMax[0][1] - xyMinMax[0][0], xyMinMax[1][1] - xyMinMax[1][0]]
  51543. : [NaN, NaN];
  51544. }
  51545. module.exports = BrushTargetManager;
  51546. /***/ },
  51547. /* 352 */
  51548. /***/ function(module, exports, __webpack_require__) {
  51549. /**
  51550. * @file Brush model
  51551. */
  51552. var echarts = __webpack_require__(1);
  51553. var zrUtil = __webpack_require__(4);
  51554. var visualSolution = __webpack_require__(349);
  51555. var Model = __webpack_require__(12);
  51556. var DEFAULT_OUT_OF_BRUSH_COLOR = ['#ddd'];
  51557. var BrushModel = echarts.extendComponentModel({
  51558. type: 'brush',
  51559. dependencies: ['geo', 'grid', 'xAxis', 'yAxis', 'parallel', 'series'],
  51560. /**
  51561. * @protected
  51562. */
  51563. defaultOption: {
  51564. // inBrush: null,
  51565. // outOfBrush: null,
  51566. toolbox: null, // Default value see preprocessor.
  51567. brushLink: null, // Series indices array, broadcast using dataIndex.
  51568. // or 'all', which means all series. 'none' or null means no series.
  51569. seriesIndex: 'all', // seriesIndex array, specify series controlled by this brush component.
  51570. geoIndex: null, //
  51571. xAxisIndex: null,
  51572. yAxisIndex: null,
  51573. brushType: 'rect', // Default brushType, see BrushController.
  51574. brushMode: 'single', // Default brushMode, 'single' or 'multiple'
  51575. transformable: true, // Default transformable.
  51576. brushStyle: { // Default brushStyle
  51577. borderWidth: 1,
  51578. color: 'rgba(120,140,180,0.3)',
  51579. borderColor: 'rgba(120,140,180,0.8)'
  51580. },
  51581. throttleType: 'fixRate',// Throttle in brushSelected event. 'fixRate' or 'debounce'.
  51582. // If null, no throttle. Valid only in the first brush component
  51583. throttleDelay: 0, // Unit: ms, 0 means every event will be triggered.
  51584. // FIXME
  51585. // 试验效果
  51586. removeOnClick: true,
  51587. z: 10000
  51588. },
  51589. /**
  51590. * @readOnly
  51591. * @type {Array.<Object>}
  51592. */
  51593. areas: [],
  51594. /**
  51595. * Current activated brush type.
  51596. * If null, brush is inactived.
  51597. * see module:echarts/component/helper/BrushController
  51598. * @readOnly
  51599. * @type {string}
  51600. */
  51601. brushType: null,
  51602. /**
  51603. * Current brush opt.
  51604. * see module:echarts/component/helper/BrushController
  51605. * @readOnly
  51606. * @type {Object}
  51607. */
  51608. brushOption: {},
  51609. /**
  51610. * @readOnly
  51611. * @type {Array.<Object>}
  51612. */
  51613. coordInfoList: [],
  51614. optionUpdated: function (newOption, isInit) {
  51615. var thisOption = this.option;
  51616. !isInit && visualSolution.replaceVisualOption(
  51617. thisOption, newOption, ['inBrush', 'outOfBrush']
  51618. );
  51619. thisOption.inBrush = thisOption.inBrush || {};
  51620. // Always give default visual, consider setOption at the second time.
  51621. thisOption.outOfBrush = thisOption.outOfBrush || {color: DEFAULT_OUT_OF_BRUSH_COLOR};
  51622. },
  51623. /**
  51624. * If ranges is null/undefined, range state remain.
  51625. *
  51626. * @param {Array.<Object>} [ranges]
  51627. */
  51628. setAreas: function (areas) {
  51629. if (true) {
  51630. zrUtil.assert(zrUtil.isArray(areas));
  51631. zrUtil.each(areas, function (area) {
  51632. zrUtil.assert(area.brushType, 'Illegal areas');
  51633. });
  51634. }
  51635. // If ranges is null/undefined, range state remain.
  51636. // This helps user to dispatchAction({type: 'brush'}) with no areas
  51637. // set but just want to get the current brush select info from a `brush` event.
  51638. if (!areas) {
  51639. return;
  51640. }
  51641. this.areas = zrUtil.map(areas, function (area) {
  51642. return generateBrushOption(this.option, area);
  51643. }, this);
  51644. },
  51645. /**
  51646. * see module:echarts/component/helper/BrushController
  51647. * @param {Object} brushOption
  51648. */
  51649. setBrushOption: function (brushOption) {
  51650. this.brushOption = generateBrushOption(this.option, brushOption);
  51651. this.brushType = this.brushOption.brushType;
  51652. }
  51653. });
  51654. function generateBrushOption(option, brushOption) {
  51655. return zrUtil.merge(
  51656. {
  51657. brushType: option.brushType,
  51658. brushMode: option.brushMode,
  51659. transformable: option.transformable,
  51660. brushStyle: new Model(option.brushStyle).getItemStyle(),
  51661. removeOnClick: option.removeOnClick,
  51662. z: option.z
  51663. },
  51664. brushOption,
  51665. true
  51666. );
  51667. }
  51668. module.exports = BrushModel;
  51669. /***/ },
  51670. /* 353 */
  51671. /***/ function(module, exports, __webpack_require__) {
  51672. var zrUtil = __webpack_require__(4);
  51673. var BrushController = __webpack_require__(244);
  51674. var echarts = __webpack_require__(1);
  51675. module.exports = echarts.extendComponentView({
  51676. type: 'brush',
  51677. init: function (ecModel, api) {
  51678. /**
  51679. * @readOnly
  51680. * @type {module:echarts/model/Global}
  51681. */
  51682. this.ecModel = ecModel;
  51683. /**
  51684. * @readOnly
  51685. * @type {module:echarts/ExtensionAPI}
  51686. */
  51687. this.api = api;
  51688. /**
  51689. * @readOnly
  51690. * @type {module:echarts/component/brush/BrushModel}
  51691. */
  51692. this.model;
  51693. /**
  51694. * @private
  51695. * @type {module:echarts/component/helper/BrushController}
  51696. */
  51697. (this._brushController = new BrushController(api.getZr()))
  51698. .on('brush', zrUtil.bind(this._onBrush, this))
  51699. .mount();
  51700. },
  51701. /**
  51702. * @override
  51703. */
  51704. render: function (brushModel) {
  51705. this.model = brushModel;
  51706. return updateController.apply(this, arguments);
  51707. },
  51708. /**
  51709. * @override
  51710. */
  51711. updateView: updateController,
  51712. /**
  51713. * @override
  51714. */
  51715. updateLayout: updateController,
  51716. /**
  51717. * @override
  51718. */
  51719. updateVisual: updateController,
  51720. /**
  51721. * @override
  51722. */
  51723. dispose: function () {
  51724. this._brushController.dispose();
  51725. },
  51726. /**
  51727. * @private
  51728. */
  51729. _onBrush: function (areas, opt) {
  51730. var modelId = this.model.id;
  51731. this.model.brushTargetManager.setOutputRanges(areas, this.ecModel);
  51732. // Action is not dispatched on drag end, because the drag end
  51733. // emits the same params with the last drag move event, and
  51734. // may have some delay when using touch pad, which makes
  51735. // animation not smooth (when using debounce).
  51736. (!opt.isEnd || opt.removeOnClick) && this.api.dispatchAction({
  51737. type: 'brush',
  51738. brushId: modelId,
  51739. areas: zrUtil.clone(areas),
  51740. $from: modelId
  51741. });
  51742. }
  51743. });
  51744. function updateController(brushModel, ecModel, api, payload) {
  51745. // Do not update controller when drawing.
  51746. (!payload || payload.$from !== brushModel.id) && this._brushController
  51747. .setPanels(brushModel.brushTargetManager.makePanelOpts(api))
  51748. .enableBrush(brushModel.brushOption)
  51749. .updateCovers(brushModel.areas.slice());
  51750. }
  51751. /***/ },
  51752. /* 354 */
  51753. /***/ function(module, exports, __webpack_require__) {
  51754. /**
  51755. * @file Brush action
  51756. */
  51757. var echarts = __webpack_require__(1);
  51758. /**
  51759. * payload: {
  51760. * brushIndex: number, or,
  51761. * brushId: string, or,
  51762. * brushName: string,
  51763. * globalRanges: Array
  51764. * }
  51765. */
  51766. echarts.registerAction(
  51767. {type: 'brush', event: 'brush', update: 'updateView'},
  51768. function (payload, ecModel) {
  51769. ecModel.eachComponent({mainType: 'brush', query: payload}, function (brushModel) {
  51770. brushModel.setAreas(payload.areas);
  51771. });
  51772. }
  51773. );
  51774. /**
  51775. * payload: {
  51776. * brushComponents: [
  51777. * {
  51778. * brushId,
  51779. * brushIndex,
  51780. * brushName,
  51781. * series: [
  51782. * {
  51783. * seriesId,
  51784. * seriesIndex,
  51785. * seriesName,
  51786. * rawIndices: [21, 34, ...]
  51787. * },
  51788. * ...
  51789. * ]
  51790. * },
  51791. * ...
  51792. * ]
  51793. * }
  51794. */
  51795. echarts.registerAction(
  51796. {type: 'brushSelect', event: 'brushSelected', update: 'none'},
  51797. function () {}
  51798. );
  51799. /***/ },
  51800. /* 355 */
  51801. /***/ function(module, exports, __webpack_require__) {
  51802. 'use strict';
  51803. var featureManager = __webpack_require__(356);
  51804. var zrUtil = __webpack_require__(4);
  51805. function Brush(model, ecModel, api) {
  51806. this.model = model;
  51807. this.ecModel = ecModel;
  51808. this.api = api;
  51809. /**
  51810. * @private
  51811. * @type {string}
  51812. */
  51813. this._brushType;
  51814. /**
  51815. * @private
  51816. * @type {string}
  51817. */
  51818. this._brushMode;
  51819. }
  51820. Brush.defaultOption = {
  51821. show: true,
  51822. type: ['rect', 'polygon', 'lineX', 'lineY', 'keep', 'clear'],
  51823. icon: {
  51824. 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
  51825. 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
  51826. 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
  51827. 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
  51828. 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
  51829. 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
  51830. },
  51831. title: {
  51832. rect: '矩形选择',
  51833. polygon: '圈选',
  51834. lineX: '横向选择',
  51835. lineY: '纵向选择',
  51836. keep: '保持选择',
  51837. clear: '清除选择'
  51838. }
  51839. };
  51840. var proto = Brush.prototype;
  51841. proto.render =
  51842. proto.updateView =
  51843. proto.updateLayout = function (featureModel, ecModel, api) {
  51844. var brushType;
  51845. var brushMode;
  51846. var isBrushed;
  51847. ecModel.eachComponent({mainType: 'brush'}, function (brushModel) {
  51848. brushType = brushModel.brushType;
  51849. brushMode = brushModel.brushOption.brushMode || 'single';
  51850. isBrushed |= brushModel.areas.length;
  51851. });
  51852. this._brushType = brushType;
  51853. this._brushMode = brushMode;
  51854. zrUtil.each(featureModel.get('type', true), function (type) {
  51855. featureModel.setIconStatus(
  51856. type,
  51857. (
  51858. type === 'keep'
  51859. ? brushMode === 'multiple'
  51860. : type === 'clear'
  51861. ? isBrushed
  51862. : type === brushType
  51863. ) ? 'emphasis' : 'normal'
  51864. );
  51865. });
  51866. };
  51867. proto.getIcons = function () {
  51868. var model = this.model;
  51869. var availableIcons = model.get('icon', true);
  51870. var icons = {};
  51871. zrUtil.each(model.get('type', true), function (type) {
  51872. if (availableIcons[type]) {
  51873. icons[type] = availableIcons[type];
  51874. }
  51875. });
  51876. return icons;
  51877. };
  51878. proto.onclick = function (ecModel, api, type) {
  51879. var api = this.api;
  51880. var brushType = this._brushType;
  51881. var brushMode = this._brushMode;
  51882. if (type === 'clear') {
  51883. // Trigger parallel action firstly
  51884. api.dispatchAction({
  51885. type: 'axisAreaSelect',
  51886. intervals: []
  51887. });
  51888. api.dispatchAction({
  51889. type: 'brush',
  51890. command: 'clear',
  51891. // Clear all areas of all brush components.
  51892. areas: []
  51893. });
  51894. }
  51895. else {
  51896. api.dispatchAction({
  51897. type: 'takeGlobalCursor',
  51898. key: 'brush',
  51899. brushOption: {
  51900. brushType: type === 'keep'
  51901. ? brushType
  51902. : (brushType === type ? false : type),
  51903. brushMode: type === 'keep'
  51904. ? (brushMode === 'multiple' ? 'single' : 'multiple')
  51905. : brushMode
  51906. }
  51907. });
  51908. }
  51909. };
  51910. featureManager.register('brush', Brush);
  51911. module.exports = Brush;
  51912. /***/ },
  51913. /* 356 */
  51914. /***/ function(module, exports) {
  51915. 'use strict';
  51916. var features = {};
  51917. module.exports = {
  51918. register: function (name, ctor) {
  51919. features[name] = ctor;
  51920. },
  51921. get: function (name) {
  51922. return features[name];
  51923. }
  51924. };
  51925. /***/ },
  51926. /* 357 */
  51927. /***/ function(module, exports, __webpack_require__) {
  51928. 'use strict';
  51929. /**
  51930. * @file calendar.js
  51931. * @author dxh
  51932. */
  51933. __webpack_require__(358);
  51934. __webpack_require__(359);
  51935. __webpack_require__(360);
  51936. /***/ },
  51937. /* 358 */
  51938. /***/ function(module, exports, __webpack_require__) {
  51939. 'use strict';
  51940. var layout = __webpack_require__(71);
  51941. var numberUtil = __webpack_require__(7);
  51942. var zrUtil = __webpack_require__(4);
  51943. // (24*60*60*1000)
  51944. var ONE_DAY = 86400000;
  51945. /**
  51946. * Calendar
  51947. *
  51948. * @constructor
  51949. *
  51950. * @param {Object} calendarModel calendarModel
  51951. * @param {Object} ecModel ecModel
  51952. * @param {Object} api api
  51953. */
  51954. function Calendar(calendarModel, ecModel, api) {
  51955. this._model = calendarModel;
  51956. }
  51957. Calendar.prototype = {
  51958. constructor: Calendar,
  51959. type: 'calendar',
  51960. dimensions: ['time', 'value'],
  51961. // Required in createListFromData
  51962. getDimensionsInfo: function () {
  51963. return [{name: 'time', type: 'time'}];
  51964. },
  51965. getRangeInfo: function () {
  51966. return this._rangeInfo;
  51967. },
  51968. getModel: function () {
  51969. return this._model;
  51970. },
  51971. getRect: function () {
  51972. return this._rect;
  51973. },
  51974. getCellWidth: function () {
  51975. return this._sw;
  51976. },
  51977. getCellHeight: function () {
  51978. return this._sh;
  51979. },
  51980. getOrient: function () {
  51981. return this._orient;
  51982. },
  51983. /**
  51984. * getFirstDayOfWeek
  51985. *
  51986. * @example
  51987. * 0 : start at Sunday
  51988. * 1 : start at Monday
  51989. *
  51990. * @return {number}
  51991. */
  51992. getFirstDayOfWeek: function () {
  51993. return this._firstDayOfWeek;
  51994. },
  51995. /**
  51996. * get date info
  51997. *
  51998. * @param {string|number} date date
  51999. * @return {Object} info
  52000. */
  52001. getDateInfo: function (date) {
  52002. date = numberUtil.parseDate(date);
  52003. var y = date.getFullYear();
  52004. var m = date.getMonth() + 1;
  52005. m = m < 10 ? '0' + m : m;
  52006. var d = date.getDate();
  52007. d = d < 10 ? '0' + d : d;
  52008. var day = date.getDay();
  52009. day = Math.abs((day + 7 - this.getFirstDayOfWeek()) % 7);
  52010. return {
  52011. y: y,
  52012. m: m,
  52013. d: d,
  52014. day: day,
  52015. time: date.getTime(),
  52016. formatedDate: y + '-' + m + '-' + d,
  52017. date: date
  52018. };
  52019. },
  52020. getNextNDay: function (date, n) {
  52021. n = n || 0;
  52022. if (n === 0) {
  52023. return this.getDateInfo(date);
  52024. }
  52025. var time = this.getDateInfo(date).time;
  52026. return this.getDateInfo(time + ONE_DAY * n);
  52027. },
  52028. update: function (ecModel, api) {
  52029. this._firstDayOfWeek = this._model.getModel('dayLabel').get('firstDay');
  52030. this._orient = this._model.get('orient');
  52031. this._lineWidth = this._model.getModel('itemStyle.normal').getItemStyle().lineWidth || 0;
  52032. this._rangeInfo = this._getRangeInfo(this._initRangeOption());
  52033. var weeks = this._rangeInfo.weeks || 1;
  52034. var whNames = ['width', 'height'];
  52035. var cellSize = this._model.get('cellSize').slice();
  52036. var layoutParams = this._model.getBoxLayoutParams();
  52037. var cellNumbers = this._orient === 'horizontal' ? [weeks, 7] : [7, weeks];
  52038. zrUtil.each([0, 1], function (idx) {
  52039. if (cellSizeSpecified(cellSize, idx)) {
  52040. layoutParams[whNames[idx]] = cellSize[idx] * cellNumbers[idx];
  52041. }
  52042. });
  52043. var whGlobal = {
  52044. width: api.getWidth(),
  52045. height: api.getHeight()
  52046. };
  52047. var calendarRect = this._rect = layout.getLayoutRect(layoutParams, whGlobal);
  52048. zrUtil.each([0, 1], function (idx) {
  52049. if (!cellSizeSpecified(cellSize, idx)) {
  52050. cellSize[idx] = calendarRect[whNames[idx]] / cellNumbers[idx];
  52051. }
  52052. });
  52053. function cellSizeSpecified(cellSize, idx) {
  52054. return cellSize[idx] != null && cellSize[idx] !== 'auto';
  52055. }
  52056. this._sw = cellSize[0];
  52057. this._sh = cellSize[1];
  52058. },
  52059. /**
  52060. * Convert a time data(time, value) item to (x, y) point.
  52061. *
  52062. * @override
  52063. * @param {Array|number} data data
  52064. * @param {boolean} [clamp=true] out of range
  52065. * @return {Array} point
  52066. */
  52067. dataToPoint: function (data, clamp) {
  52068. zrUtil.isArray(data) && (data = data[0]);
  52069. clamp == null && (clamp = true);
  52070. var dayInfo = this.getDateInfo(data);
  52071. var range = this._rangeInfo;
  52072. var date = dayInfo.formatedDate;
  52073. // if not in range return [NaN, NaN]
  52074. if (clamp && !(dayInfo.time >= range.start.time && dayInfo.time <= range.end.time)) {
  52075. return [NaN, NaN];
  52076. }
  52077. var week = dayInfo.day;
  52078. var nthWeek = this._getRangeInfo([range.start.time, date]).weeks;
  52079. if (this._orient === 'vertical') {
  52080. return [
  52081. this._rect.x + week * this._sw + this._sw / 2,
  52082. this._rect.y + (nthWeek - 1) * this._sh + this._sh / 2
  52083. ];
  52084. }
  52085. return [
  52086. this._rect.x + (nthWeek - 1) * this._sw + this._sw / 2,
  52087. this._rect.y + week * this._sh + this._sh / 2
  52088. ];
  52089. },
  52090. /**
  52091. * Convert a (x, y) point to time data
  52092. *
  52093. * @override
  52094. * @param {string} point point
  52095. * @return {string} data
  52096. */
  52097. pointToData: function (point) {
  52098. var date = this.pointToDate(point);
  52099. return date && date.time;
  52100. },
  52101. /**
  52102. * Convert a time date item to (x, y) four point.
  52103. *
  52104. * @param {Array} data date[0] is date
  52105. * @param {boolean} [clamp=true] out of range
  52106. * @return {Object} point
  52107. */
  52108. dataToRect: function (data, clamp) {
  52109. var point = this.dataToPoint(data, clamp);
  52110. return {
  52111. contentShape: {
  52112. x: point[0] - (this._sw - this._lineWidth) / 2,
  52113. y: point[1] - (this._sh - this._lineWidth) / 2,
  52114. width: this._sw - this._lineWidth,
  52115. height: this._sh - this._lineWidth
  52116. },
  52117. center: point,
  52118. tl: [
  52119. point[0] - this._sw / 2,
  52120. point[1] - this._sh / 2
  52121. ],
  52122. tr: [
  52123. point[0] + this._sw / 2,
  52124. point[1] - this._sh / 2
  52125. ],
  52126. br: [
  52127. point[0] + this._sw / 2,
  52128. point[1] + this._sh / 2
  52129. ],
  52130. bl: [
  52131. point[0] - this._sw / 2,
  52132. point[1] + this._sh / 2
  52133. ]
  52134. };
  52135. },
  52136. /**
  52137. * Convert a (x, y) point to time date
  52138. *
  52139. * @param {string} point point
  52140. * @return {Object} date
  52141. */
  52142. pointToDate: function (point) {
  52143. var nthX = Math.floor((point[0] - this._rect.x) / this._sw) + 1;
  52144. var nthY = Math.floor((point[1] - this._rect.y) / this._sh) + 1;
  52145. var range = this._rangeInfo.range;
  52146. if (this._orient === 'vertical') {
  52147. return this._getDateByWeeksAndDay(nthY, nthX - 1, range);
  52148. }
  52149. return this._getDateByWeeksAndDay(nthX, nthY - 1, range);
  52150. },
  52151. /**
  52152. * @inheritDoc
  52153. */
  52154. convertToPixel: zrUtil.curry(doConvert, 'dataToPoint'),
  52155. /**
  52156. * @inheritDoc
  52157. */
  52158. convertFromPixel: zrUtil.curry(doConvert, 'pointToData'),
  52159. /**
  52160. * initRange
  52161. *
  52162. * @private
  52163. * @return {Array} [start, end]
  52164. */
  52165. _initRangeOption: function () {
  52166. var range = this._model.get('range');
  52167. var rg = range;
  52168. if (zrUtil.isArray(rg) && rg.length === 1) {
  52169. rg = rg[0];
  52170. }
  52171. if (/^\d{4}$/.test(rg)) {
  52172. range = [rg + '-01-01', rg + '-12-31'];
  52173. }
  52174. if (/^\d{4}[\/|-]\d{1,2}$/.test(rg)) {
  52175. var start = this.getDateInfo(rg);
  52176. var firstDay = start.date;
  52177. firstDay.setMonth(firstDay.getMonth() + 1);
  52178. var end = this.getNextNDay(firstDay, -1);
  52179. range = [start.formatedDate, end.formatedDate];
  52180. }
  52181. if (/^\d{4}[\/|-]\d{1,2}[\/|-]\d{1,2}$/.test(rg)) {
  52182. range = [rg, rg];
  52183. }
  52184. var tmp = this._getRangeInfo(range);
  52185. if (tmp.start.time > tmp.end.time) {
  52186. range.reverse();
  52187. }
  52188. return range;
  52189. },
  52190. /**
  52191. * range info
  52192. *
  52193. * @private
  52194. * @param {Array} range range ['2017-01-01', '2017-07-08']
  52195. * @return {Object} obj
  52196. */
  52197. _getRangeInfo: function (range) {
  52198. var start = this.getDateInfo(range[0]);
  52199. var end = this.getDateInfo(range[1]);
  52200. var allDay = Math.floor(end.time / ONE_DAY) - Math.floor(start.time / ONE_DAY) + 1;
  52201. var weeks = Math.floor((allDay + start.day + 6) / 7);
  52202. return {
  52203. range: [start.formatedDate, end.formatedDate],
  52204. start: start,
  52205. end: end,
  52206. allDay: allDay,
  52207. weeks: weeks,
  52208. fweek: start.day,
  52209. lweek: end.day
  52210. };
  52211. },
  52212. /**
  52213. * get date by nthWeeks and week day in range
  52214. *
  52215. * @private
  52216. * @param {number} nthWeek the week
  52217. * @param {number} day the week day
  52218. * @param {Array} range [d1, d2]
  52219. * @return {Object}
  52220. */
  52221. _getDateByWeeksAndDay: function (nthWeek, day, range) {
  52222. var rangeInfo = this._getRangeInfo(range);
  52223. if (nthWeek > rangeInfo.weeks
  52224. || (nthWeek === 0 && day < rangeInfo.fweek)
  52225. || (nthWeek === rangeInfo.weeks && day > rangeInfo.lweek)
  52226. ) {
  52227. return false;
  52228. }
  52229. var nthDay = (nthWeek - 1) * 7 - rangeInfo.fweek + day;
  52230. var time = rangeInfo.start.time + nthDay * ONE_DAY;
  52231. return this.getDateInfo(time);
  52232. }
  52233. };
  52234. Calendar.dimensions = Calendar.prototype.dimensions;
  52235. Calendar.getDimensionsInfo = Calendar.prototype.getDimensionsInfo;
  52236. Calendar.create = function (ecModel, api) {
  52237. var calendarList = [];
  52238. ecModel.eachComponent('calendar', function (calendarModel) {
  52239. var calendar = new Calendar(calendarModel, ecModel, api);
  52240. calendarList.push(calendar);
  52241. calendarModel.coordinateSystem = calendar;
  52242. });
  52243. ecModel.eachSeries(function (calendarSeries) {
  52244. if (calendarSeries.get('coordinateSystem') === 'calendar') {
  52245. // Inject coordinate system
  52246. calendarSeries.coordinateSystem = calendarList[calendarSeries.get('calendarIndex') || 0];
  52247. }
  52248. });
  52249. return calendarList;
  52250. };
  52251. function doConvert(methodName, ecModel, finder, value) {
  52252. var calendarModel = finder.calendarModel;
  52253. var seriesModel = finder.seriesModel;
  52254. var coordSys = calendarModel
  52255. ? calendarModel.coordinateSystem
  52256. : seriesModel
  52257. ? seriesModel.coordinateSystem
  52258. : null;
  52259. return coordSys === this ? coordSys[methodName](value) : null;
  52260. }
  52261. __webpack_require__(76).register('calendar', Calendar);
  52262. module.exports = Calendar;
  52263. /***/ },
  52264. /* 359 */
  52265. /***/ function(module, exports, __webpack_require__) {
  52266. 'use strict';
  52267. var ComponentModel = __webpack_require__(69);
  52268. var zrUtil = __webpack_require__(4);
  52269. var layout = __webpack_require__(71);
  52270. var CalendarModel = ComponentModel.extend({
  52271. type: 'calendar',
  52272. /**
  52273. * @type {module:echarts/coord/calendar/Calendar}
  52274. */
  52275. coordinateSystem: null,
  52276. defaultOption: {
  52277. zlevel: 0,
  52278. z: 2,
  52279. left: 80,
  52280. top: 60,
  52281. cellSize: 20,
  52282. // horizontal vertical
  52283. orient: 'horizontal',
  52284. // month separate line style
  52285. splitLine: {
  52286. show: true,
  52287. lineStyle: {
  52288. color: '#000',
  52289. width: 1,
  52290. type: 'solid'
  52291. }
  52292. },
  52293. // rect style temporarily unused emphasis
  52294. itemStyle: {
  52295. normal: {
  52296. color: '#fff',
  52297. borderWidth: 1,
  52298. borderColor: '#ccc'
  52299. }
  52300. },
  52301. // week text style
  52302. dayLabel: {
  52303. show: true,
  52304. // a week first day
  52305. firstDay: 0,
  52306. // start end
  52307. position: 'start',
  52308. margin: '50%', // 50% of cellSize
  52309. nameMap: 'en',
  52310. textStyle: {
  52311. color: '#000'
  52312. }
  52313. },
  52314. // month text style
  52315. monthLabel: {
  52316. show: true,
  52317. // start end
  52318. position: 'start',
  52319. margin: 5,
  52320. // center or left
  52321. align: 'center',
  52322. // cn en []
  52323. nameMap: 'en',
  52324. formatter: null,
  52325. textStyle: {
  52326. color: '#000'
  52327. }
  52328. },
  52329. // year text style
  52330. yearLabel: {
  52331. show: true,
  52332. // top bottom left right
  52333. position: null,
  52334. margin: 30,
  52335. formatter: null,
  52336. textStyle: {
  52337. color: '#ccc',
  52338. fontFamily: 'sans-serif',
  52339. fontWeight: 'bolder',
  52340. fontSize: 20
  52341. }
  52342. }
  52343. },
  52344. /**
  52345. * @override
  52346. */
  52347. init: function (option, parentModel, ecModel, extraOpt) {
  52348. var inputPositionParams = layout.getLayoutParams(option);
  52349. CalendarModel.superApply(this, 'init', arguments);
  52350. mergeAndNormalizeLayoutParams(option, inputPositionParams);
  52351. },
  52352. /**
  52353. * @override
  52354. */
  52355. mergeOption: function (option, extraOpt) {
  52356. CalendarModel.superApply(this, 'mergeOption', arguments);
  52357. mergeAndNormalizeLayoutParams(this.option, option);
  52358. }
  52359. });
  52360. function mergeAndNormalizeLayoutParams(target, raw) {
  52361. // Normalize cellSize
  52362. var cellSize = target.cellSize;
  52363. if (!zrUtil.isArray(cellSize)) {
  52364. cellSize = target.cellSize = [cellSize, cellSize];
  52365. }
  52366. else if (cellSize.length === 1) {
  52367. cellSize[1] = cellSize[0];
  52368. }
  52369. var ignoreSize = zrUtil.map([0, 1], function (hvIdx) {
  52370. // If user have set `width` or both `left` and `right`, cellSize
  52371. // will be automatically set to 'auto', otherwise the default
  52372. // setting of cellSize will make `width` setting not work.
  52373. if (layout.sizeCalculable(raw, hvIdx)) {
  52374. cellSize[hvIdx] = 'auto';
  52375. }
  52376. return cellSize[hvIdx] != null && cellSize[hvIdx] !== 'auto';
  52377. });
  52378. layout.mergeLayoutParam(target, raw, {
  52379. type: 'box', ignoreSize: ignoreSize
  52380. });
  52381. }
  52382. module.exports = CalendarModel;
  52383. /***/ },
  52384. /* 360 */
  52385. /***/ function(module, exports, __webpack_require__) {
  52386. 'use strict';
  52387. var zrUtil = __webpack_require__(4);
  52388. var graphic = __webpack_require__(18);
  52389. var formatUtil = __webpack_require__(6);
  52390. var numberUtil = __webpack_require__(7);
  52391. var MONTH_TEXT = {
  52392. EN: [
  52393. 'Jan', 'Feb', 'Mar',
  52394. 'Apr', 'May', 'Jun',
  52395. 'Jul', 'Aug', 'Sep',
  52396. 'Oct', 'Nov', 'Dec'
  52397. ],
  52398. CN: [
  52399. '一月', '二月', '三月',
  52400. '四月', '五月', '六月',
  52401. '七月', '八月', '九月',
  52402. '十月', '十一月', '十二月'
  52403. ]
  52404. };
  52405. var WEEK_TEXT = {
  52406. EN: ['S', 'M', 'T', 'W', 'T', 'F', 'S'],
  52407. CN: ['日', '一', '二', '三', '四', '五', '六']
  52408. };
  52409. module.exports = __webpack_require__(1).extendComponentView({
  52410. type: 'calendar',
  52411. /**
  52412. * top/left line points
  52413. * @private
  52414. */
  52415. _tlpoints: null,
  52416. /**
  52417. * bottom/right line points
  52418. * @private
  52419. */
  52420. _blpoints: null,
  52421. /**
  52422. * first day of month
  52423. * @private
  52424. */
  52425. _firstDayOfMonth: null,
  52426. /**
  52427. * first day point of month
  52428. * @private
  52429. */
  52430. _firstDayPoints: null,
  52431. render: function (calendarModel, ecModel, api) {
  52432. var group = this.group;
  52433. group.removeAll();
  52434. var coordSys = calendarModel.coordinateSystem;
  52435. // range info
  52436. var rangeData = coordSys.getRangeInfo();
  52437. var orient = coordSys.getOrient();
  52438. this._renderDayRect(calendarModel, rangeData, group);
  52439. // _renderLines must be called prior to following function
  52440. this._renderLines(calendarModel, rangeData, orient, group);
  52441. this._renderYearText(calendarModel, rangeData, orient, group);
  52442. this._renderMonthText(calendarModel, orient, group);
  52443. this._renderWeekText(calendarModel, rangeData, orient, group);
  52444. },
  52445. // render day rect
  52446. _renderDayRect: function (calendarModel, rangeData, group) {
  52447. var coordSys = calendarModel.coordinateSystem;
  52448. var itemRectStyleModel = calendarModel.getModel('itemStyle.normal').getItemStyle();
  52449. var sw = coordSys.getCellWidth();
  52450. var sh = coordSys.getCellHeight();
  52451. for (var i = rangeData.start.time;
  52452. i <= rangeData.end.time;
  52453. i = coordSys.getNextNDay(i, 1).time
  52454. ) {
  52455. var point = coordSys.dataToRect([i], false).tl;
  52456. // every rect
  52457. var rect = new graphic.Rect({
  52458. shape: {
  52459. x: point[0],
  52460. y: point[1],
  52461. width: sw,
  52462. height: sh
  52463. },
  52464. style: itemRectStyleModel
  52465. });
  52466. group.add(rect);
  52467. }
  52468. },
  52469. // render separate line
  52470. _renderLines: function (calendarModel, rangeData, orient, group) {
  52471. var self = this;
  52472. var coordSys = calendarModel.coordinateSystem;
  52473. var lineStyleModel = calendarModel.getModel('splitLine.lineStyle').getLineStyle();
  52474. var show = calendarModel.get('splitLine.show');
  52475. var lineWidth = lineStyleModel.lineWidth;
  52476. this._tlpoints = [];
  52477. this._blpoints = [];
  52478. this._firstDayOfMonth = [];
  52479. this._firstDayPoints = [];
  52480. var firstDay = rangeData.start;
  52481. for (var i = 0; firstDay.time <= rangeData.end.time; i++) {
  52482. addPoints(firstDay.formatedDate);
  52483. if (i === 0) {
  52484. firstDay = coordSys.getDateInfo(rangeData.start.y + '-' + rangeData.start.m);
  52485. }
  52486. var date = firstDay.date;
  52487. date.setMonth(date.getMonth() + 1);
  52488. firstDay = coordSys.getDateInfo(date);
  52489. }
  52490. addPoints(coordSys.getNextNDay(rangeData.end.time, 1).formatedDate);
  52491. function addPoints(date) {
  52492. self._firstDayOfMonth.push(coordSys.getDateInfo(date));
  52493. self._firstDayPoints.push(coordSys.dataToRect([date], false).tl);
  52494. var points = self._getLinePointsOfOneWeek(calendarModel, date, orient);
  52495. self._tlpoints.push(points[0]);
  52496. self._blpoints.push(points[points.length - 1]);
  52497. show && self._drawSplitline(points, lineStyleModel, group);
  52498. }
  52499. // render top/left line
  52500. show && this._drawSplitline(self._getEdgesPoints(self._tlpoints, lineWidth, orient), lineStyleModel, group);
  52501. // render bottom/right line
  52502. show && this._drawSplitline(self._getEdgesPoints(self._blpoints, lineWidth, orient), lineStyleModel, group);
  52503. },
  52504. // get points at both ends
  52505. _getEdgesPoints: function (points, lineWidth, orient) {
  52506. var rs = [points[0].slice(), points[points.length - 1].slice()];
  52507. var idx = orient === 'horizontal' ? 0 : 1;
  52508. // both ends of the line are extend half lineWidth
  52509. rs[0][idx] = rs[0][idx] - lineWidth / 2;
  52510. rs[1][idx] = rs[1][idx] + lineWidth / 2;
  52511. return rs;
  52512. },
  52513. // render split line
  52514. _drawSplitline: function (points, lineStyleModel, group) {
  52515. var poyline = new graphic.Polyline({
  52516. z2: 20,
  52517. shape: {
  52518. points: points
  52519. },
  52520. style: lineStyleModel
  52521. });
  52522. group.add(poyline);
  52523. },
  52524. // render month line of one week points
  52525. _getLinePointsOfOneWeek: function (calendarModel, date, orient) {
  52526. var coordSys = calendarModel.coordinateSystem;
  52527. date = coordSys.getDateInfo(date);
  52528. var points = [];
  52529. for (var i = 0; i < 7; i++) {
  52530. var tmpD = coordSys.getNextNDay(date.time, i);
  52531. var point = coordSys.dataToRect([tmpD.time], false);
  52532. points[2 * tmpD.day] = point.tl;
  52533. points[2 * tmpD.day + 1] = point[orient === 'horizontal' ? 'bl' : 'tr'];
  52534. }
  52535. return points;
  52536. },
  52537. _formatterLabel: function (formatter, params) {
  52538. if (typeof formatter === 'string' && formatter) {
  52539. return formatUtil.formatTplSimple(formatter, params);
  52540. }
  52541. if (typeof formatter === 'function') {
  52542. return formatter(params);
  52543. }
  52544. return params.nameMap;
  52545. },
  52546. _yearTextPositionControl: function (point, orient, position, margin) {
  52547. point = point.slice();
  52548. var aligns = ['center', 'bottom'];
  52549. if (position === 'top') {
  52550. point[1] -= margin;
  52551. }
  52552. if (position === 'bottom') {
  52553. point[1] += margin;
  52554. aligns = ['center', 'top'];
  52555. }
  52556. if (position === 'left') {
  52557. point[0] -= margin;
  52558. }
  52559. if (position === 'right') {
  52560. point[0] += margin;
  52561. aligns = ['center', 'top'];
  52562. }
  52563. var rotate = 0;
  52564. if (position === 'left' || position === 'right') {
  52565. rotate = Math.PI / 2;
  52566. }
  52567. return {
  52568. rotation: rotate,
  52569. origin: point,
  52570. style: {
  52571. x: point[0],
  52572. y: point[1],
  52573. textAlign: aligns[0],
  52574. textVerticalAlign: aligns[1]
  52575. }
  52576. };
  52577. },
  52578. // render year
  52579. _renderYearText: function (calendarModel, rangeData, orient, group) {
  52580. var yearLabel = calendarModel.getModel('yearLabel');
  52581. if (!yearLabel.get('show')) {
  52582. return;
  52583. }
  52584. var yearLabelStyleModel = calendarModel.getModel('yearLabel.textStyle');
  52585. var margin = yearLabel.get('margin');
  52586. var pos = yearLabel.get('position');
  52587. if (!pos) {
  52588. pos = orient !== 'horizontal' ? 'top' : 'left';
  52589. }
  52590. var points = [this._tlpoints[this._tlpoints.length - 1], this._blpoints[0]];
  52591. var xc = (points[0][0] + points[1][0]) / 2;
  52592. var yc = (points[0][1] + points[1][1]) / 2;
  52593. var idx = orient === 'horizontal' ? 0 : 1;
  52594. var posPoints = {
  52595. top: [xc, points[idx][1]],
  52596. bottom: [xc, points[1 - idx][1]],
  52597. left: [points[1 - idx][0], yc],
  52598. right: [points[idx][0], yc]
  52599. };
  52600. var name = rangeData.start.y;
  52601. if (+rangeData.end.y > +rangeData.start.y) {
  52602. name = name + '-' + rangeData.end.y;
  52603. }
  52604. var formatter = yearLabel.get('formatter');
  52605. var params = {
  52606. start: rangeData.start.y,
  52607. end: rangeData.end.y,
  52608. nameMap: name
  52609. };
  52610. var content = this._formatterLabel(formatter, params);
  52611. var yearText = new graphic.Text(
  52612. zrUtil.merge({
  52613. z2: 30,
  52614. style: {
  52615. text: content,
  52616. font: yearLabelStyleModel.getFont(),
  52617. fill: yearLabelStyleModel.getTextColor()
  52618. }
  52619. }, this._yearTextPositionControl(posPoints[pos], orient, pos, margin))
  52620. );
  52621. group.add(yearText);
  52622. },
  52623. _monthTextPositionControl: function (point, isCenter, orient, position, margin) {
  52624. var align = 'left';
  52625. var vAlign = 'top';
  52626. var x = point[0];
  52627. var y = point[1];
  52628. if (orient === 'horizontal') {
  52629. y = y + margin;
  52630. if (isCenter) {
  52631. align = 'center';
  52632. }
  52633. if (position === 'start') {
  52634. vAlign = 'bottom';
  52635. }
  52636. }
  52637. else {
  52638. x = x + margin;
  52639. if (isCenter) {
  52640. vAlign = 'middle';
  52641. }
  52642. if (position === 'start') {
  52643. align = 'right';
  52644. }
  52645. }
  52646. return {
  52647. x: x,
  52648. y: y,
  52649. textAlign: align,
  52650. textVerticalAlign: vAlign
  52651. };
  52652. },
  52653. // render month and year text
  52654. _renderMonthText: function (calendarModel, orient, group) {
  52655. var monthLabel = calendarModel.getModel('monthLabel');
  52656. if (!monthLabel.get('show')) {
  52657. return;
  52658. }
  52659. var monthLabelStyleModel = calendarModel.getModel('monthLabel.textStyle');
  52660. var nameMap = monthLabel.get('nameMap');
  52661. var margin = monthLabel.get('margin');
  52662. var pos = monthLabel.get('position');
  52663. var align = monthLabel.get('align');
  52664. var termPoints = [this._tlpoints, this._blpoints];
  52665. if (zrUtil.isString(nameMap)) {
  52666. nameMap = MONTH_TEXT[nameMap.toUpperCase()] || [];
  52667. }
  52668. var idx = pos === 'start' ? 0 : 1;
  52669. var axis = orient === 'horizontal' ? 0 : 1;
  52670. margin = pos === 'start' ? -margin : margin;
  52671. var isCenter = (align === 'center');
  52672. for (var i = 0; i < termPoints[idx].length - 1; i++) {
  52673. var tmp = termPoints[idx][i].slice();
  52674. var firstDay = this._firstDayOfMonth[i];
  52675. if (isCenter) {
  52676. var firstDayPoints = this._firstDayPoints[i];
  52677. tmp[axis] = (firstDayPoints[axis] + termPoints[0][i + 1][axis]) / 2;
  52678. }
  52679. var formatter = monthLabel.get('formatter');
  52680. var name = nameMap[+firstDay.m - 1];
  52681. var params = {
  52682. yyyy: firstDay.y,
  52683. yy: (firstDay.y + '').slice(2),
  52684. MM: firstDay.m,
  52685. M: +firstDay.m,
  52686. nameMap: name
  52687. };
  52688. var content = this._formatterLabel(formatter, params);
  52689. var monthText = new graphic.Text({
  52690. z2: 30,
  52691. style: zrUtil.extend({
  52692. text: content,
  52693. font: monthLabelStyleModel.getFont(),
  52694. fill: monthLabelStyleModel.getTextColor()
  52695. }, this._monthTextPositionControl(tmp, isCenter, orient, pos, margin))
  52696. });
  52697. group.add(monthText);
  52698. }
  52699. },
  52700. _weekTextPositionControl: function (point, orient, position, margin, cellSize) {
  52701. var align = 'center';
  52702. var vAlign = 'middle';
  52703. var x = point[0];
  52704. var y = point[1];
  52705. var isStart = position === 'start';
  52706. if (orient === 'horizontal') {
  52707. x = x + margin + (isStart ? 1 : -1) * cellSize[0] / 2;
  52708. align = isStart ? 'right' : 'left';
  52709. }
  52710. else {
  52711. y = y + margin + (isStart ? 1 : -1) * cellSize[1] / 2;
  52712. vAlign = isStart ? 'bottom' : 'top';
  52713. }
  52714. return {
  52715. x: x,
  52716. y: y,
  52717. textAlign: align,
  52718. textVerticalAlign: vAlign
  52719. };
  52720. },
  52721. // render weeks
  52722. _renderWeekText: function (calendarModel, rangeData, orient, group) {
  52723. var dayLabel = calendarModel.getModel('dayLabel');
  52724. if (!dayLabel.get('show')) {
  52725. return;
  52726. }
  52727. var coordSys = calendarModel.coordinateSystem;
  52728. var dayLabelStyleModel = calendarModel.getModel('dayLabel.textStyle');
  52729. var pos = dayLabel.get('position');
  52730. var nameMap = dayLabel.get('nameMap');
  52731. var margin = dayLabel.get('margin');
  52732. var firstDayOfWeek = coordSys.getFirstDayOfWeek();
  52733. if (zrUtil.isString(nameMap)) {
  52734. nameMap = WEEK_TEXT[nameMap.toUpperCase()] || [];
  52735. }
  52736. var start = coordSys.getNextNDay(
  52737. rangeData.end.time, (7 - rangeData.lweek)
  52738. ).time;
  52739. var cellSize = [coordSys.getCellWidth(), coordSys.getCellHeight()];
  52740. margin = numberUtil.parsePercent(margin, cellSize[orient === 'horizontal' ? 0 : 1]);
  52741. if (pos === 'start') {
  52742. start = coordSys.getNextNDay(
  52743. rangeData.start.time, -(7 + rangeData.fweek)
  52744. ).time;
  52745. margin = -margin;
  52746. }
  52747. for (var i = 0; i < 7; i++) {
  52748. var tmpD = coordSys.getNextNDay(start, i);
  52749. var point = coordSys.dataToRect([tmpD.time], false).center;
  52750. var day = i;
  52751. day = Math.abs((i + firstDayOfWeek) % 7);
  52752. var weekText = new graphic.Text({
  52753. z2: 30,
  52754. style: zrUtil.extend({
  52755. text: nameMap[day],
  52756. font: dayLabelStyleModel.getFont(),
  52757. fill: dayLabelStyleModel.getTextColor()
  52758. }, this._weekTextPositionControl(point, orient, pos, margin, cellSize))
  52759. });
  52760. group.add(weekText);
  52761. }
  52762. }
  52763. });
  52764. /***/ },
  52765. /* 361 */
  52766. /***/ function(module, exports, __webpack_require__) {
  52767. 'use strict';
  52768. var echarts = __webpack_require__(1);
  52769. var graphic = __webpack_require__(18);
  52770. var layout = __webpack_require__(71);
  52771. // Model
  52772. echarts.extendComponentModel({
  52773. type: 'title',
  52774. layoutMode: {type: 'box', ignoreSize: true},
  52775. defaultOption: {
  52776. // 一级层叠
  52777. zlevel: 0,
  52778. // 二级层叠
  52779. z: 6,
  52780. show: true,
  52781. text: '',
  52782. // 超链接跳转
  52783. // link: null,
  52784. // 仅支持self | blank
  52785. target: 'blank',
  52786. subtext: '',
  52787. // 超链接跳转
  52788. // sublink: null,
  52789. // 仅支持self | blank
  52790. subtarget: 'blank',
  52791. // 'center' ¦ 'left' ¦ 'right'
  52792. // ¦ {number}(x坐标,单位px)
  52793. left: 0,
  52794. // 'top' ¦ 'bottom' ¦ 'center'
  52795. // ¦ {number}(y坐标,单位px)
  52796. top: 0,
  52797. // 水平对齐
  52798. // 'auto' | 'left' | 'right' | 'center'
  52799. // 默认根据 left 的位置判断是左对齐还是右对齐
  52800. // textAlign: null
  52801. //
  52802. // 垂直对齐
  52803. // 'auto' | 'top' | 'bottom' | 'middle'
  52804. // 默认根据 top 位置判断是上对齐还是下对齐
  52805. // textBaseline: null
  52806. backgroundColor: 'rgba(0,0,0,0)',
  52807. // 标题边框颜色
  52808. borderColor: '#ccc',
  52809. // 标题边框线宽,单位px,默认为0(无边框)
  52810. borderWidth: 0,
  52811. // 标题内边距,单位px,默认各方向内边距为5,
  52812. // 接受数组分别设定上右下左边距,同css
  52813. padding: 5,
  52814. // 主副标题纵向间隔,单位px,默认为10,
  52815. itemGap: 10,
  52816. textStyle: {
  52817. fontSize: 18,
  52818. fontWeight: 'bolder',
  52819. color: '#333'
  52820. },
  52821. subtextStyle: {
  52822. color: '#aaa'
  52823. }
  52824. }
  52825. });
  52826. // View
  52827. echarts.extendComponentView({
  52828. type: 'title',
  52829. render: function (titleModel, ecModel, api) {
  52830. this.group.removeAll();
  52831. if (!titleModel.get('show')) {
  52832. return;
  52833. }
  52834. var group = this.group;
  52835. var textStyleModel = titleModel.getModel('textStyle');
  52836. var subtextStyleModel = titleModel.getModel('subtextStyle');
  52837. var textAlign = titleModel.get('textAlign');
  52838. var textBaseline = titleModel.get('textBaseline');
  52839. var textEl = new graphic.Text({
  52840. style: {
  52841. text: titleModel.get('text'),
  52842. textFont: textStyleModel.getFont(),
  52843. fill: textStyleModel.getTextColor()
  52844. },
  52845. z2: 10
  52846. });
  52847. var textRect = textEl.getBoundingRect();
  52848. var subText = titleModel.get('subtext');
  52849. var subTextEl = new graphic.Text({
  52850. style: {
  52851. text: subText,
  52852. textFont: subtextStyleModel.getFont(),
  52853. fill: subtextStyleModel.getTextColor(),
  52854. y: textRect.height + titleModel.get('itemGap'),
  52855. textBaseline: 'top'
  52856. },
  52857. z2: 10
  52858. });
  52859. var link = titleModel.get('link');
  52860. var sublink = titleModel.get('sublink');
  52861. textEl.silent = !link;
  52862. subTextEl.silent = !sublink;
  52863. if (link) {
  52864. textEl.on('click', function () {
  52865. window.open(link, '_' + titleModel.get('target'));
  52866. });
  52867. }
  52868. if (sublink) {
  52869. subTextEl.on('click', function () {
  52870. window.open(sublink, '_' + titleModel.get('subtarget'));
  52871. });
  52872. }
  52873. group.add(textEl);
  52874. subText && group.add(subTextEl);
  52875. // If no subText, but add subTextEl, there will be an empty line.
  52876. var groupRect = group.getBoundingRect();
  52877. var layoutOption = titleModel.getBoxLayoutParams();
  52878. layoutOption.width = groupRect.width;
  52879. layoutOption.height = groupRect.height;
  52880. var layoutRect = layout.getLayoutRect(
  52881. layoutOption, {
  52882. width: api.getWidth(),
  52883. height: api.getHeight()
  52884. }, titleModel.get('padding')
  52885. );
  52886. // Adjust text align based on position
  52887. if (!textAlign) {
  52888. // Align left if title is on the left. center and right is same
  52889. textAlign = titleModel.get('left') || titleModel.get('right');
  52890. if (textAlign === 'middle') {
  52891. textAlign = 'center';
  52892. }
  52893. // Adjust layout by text align
  52894. if (textAlign === 'right') {
  52895. layoutRect.x += layoutRect.width;
  52896. }
  52897. else if (textAlign === 'center') {
  52898. layoutRect.x += layoutRect.width / 2;
  52899. }
  52900. }
  52901. if (!textBaseline) {
  52902. textBaseline = titleModel.get('top') || titleModel.get('bottom');
  52903. if (textBaseline === 'center') {
  52904. textBaseline = 'middle';
  52905. }
  52906. if (textBaseline === 'bottom') {
  52907. layoutRect.y += layoutRect.height;
  52908. }
  52909. else if (textBaseline === 'middle') {
  52910. layoutRect.y += layoutRect.height / 2;
  52911. }
  52912. textBaseline = textBaseline || 'top';
  52913. }
  52914. group.attr('position', [layoutRect.x, layoutRect.y]);
  52915. var alignStyle = {
  52916. textAlign: textAlign,
  52917. textVerticalAlign: textBaseline
  52918. };
  52919. textEl.setStyle(alignStyle);
  52920. subTextEl.setStyle(alignStyle);
  52921. // Render background
  52922. // Get groupRect again because textAlign has been changed
  52923. groupRect = group.getBoundingRect();
  52924. var padding = layoutRect.margin;
  52925. var style = titleModel.getItemStyle(['color', 'opacity']);
  52926. style.fill = titleModel.get('backgroundColor');
  52927. var rect = new graphic.Rect({
  52928. shape: {
  52929. x: groupRect.x - padding[3],
  52930. y: groupRect.y - padding[0],
  52931. width: groupRect.width + padding[1] + padding[3],
  52932. height: groupRect.height + padding[0] + padding[2]
  52933. },
  52934. style: style,
  52935. silent: true
  52936. });
  52937. graphic.subPixelOptimizeRect(rect);
  52938. group.add(rect);
  52939. }
  52940. });
  52941. /***/ },
  52942. /* 362 */
  52943. /***/ function(module, exports, __webpack_require__) {
  52944. /**
  52945. * DataZoom component entry
  52946. */
  52947. __webpack_require__(363);
  52948. __webpack_require__(364);
  52949. __webpack_require__(367);
  52950. __webpack_require__(368);
  52951. __webpack_require__(369);
  52952. __webpack_require__(370);
  52953. __webpack_require__(371);
  52954. __webpack_require__(373);
  52955. __webpack_require__(374);
  52956. /***/ },
  52957. /* 363 */
  52958. /***/ function(module, exports, __webpack_require__) {
  52959. __webpack_require__(69).registerSubTypeDefaulter('dataZoom', function (option) {
  52960. // Default 'slider' when no type specified.
  52961. return 'slider';
  52962. });
  52963. /***/ },
  52964. /* 364 */
  52965. /***/ function(module, exports, __webpack_require__) {
  52966. /**
  52967. * @file Data zoom model
  52968. */
  52969. var zrUtil = __webpack_require__(4);
  52970. var env = __webpack_require__(2);
  52971. var echarts = __webpack_require__(1);
  52972. var modelUtil = __webpack_require__(5);
  52973. var helper = __webpack_require__(365);
  52974. var AxisProxy = __webpack_require__(366);
  52975. var each = zrUtil.each;
  52976. var eachAxisDim = helper.eachAxisDim;
  52977. var DataZoomModel = echarts.extendComponentModel({
  52978. type: 'dataZoom',
  52979. dependencies: [
  52980. 'xAxis', 'yAxis', 'zAxis', 'radiusAxis', 'angleAxis', 'singleAxis', 'series'
  52981. ],
  52982. /**
  52983. * @protected
  52984. */
  52985. defaultOption: {
  52986. zlevel: 0,
  52987. z: 4, // Higher than normal component (z: 2).
  52988. orient: null, // Default auto by axisIndex. Possible value: 'horizontal', 'vertical'.
  52989. xAxisIndex: null, // Default the first horizontal category axis.
  52990. yAxisIndex: null, // Default the first vertical category axis.
  52991. filterMode: 'filter', // Possible values: 'filter' or 'empty' or 'weakFilter'.
  52992. // 'filter': data items which are out of window will be removed. This option is
  52993. // applicable when filtering outliers. For each data item, it will be
  52994. // filtered if one of the relevant dimensions is out of the window.
  52995. // 'weakFilter': data items which are out of window will be removed. This option
  52996. // is applicable when filtering outliers. For each data item, it will be
  52997. // filtered only if all of the relevant dimensions are out of the same
  52998. // side of the window.
  52999. // 'empty': data items which are out of window will be set to empty.
  53000. // This option is applicable when user should not neglect
  53001. // that there are some data items out of window.
  53002. // 'none': Do not filter.
  53003. // Taking line chart as an example, line will be broken in
  53004. // the filtered points when filterModel is set to 'empty', but
  53005. // be connected when set to 'filter'.
  53006. throttle: null, // Dispatch action by the fixed rate, avoid frequency.
  53007. // default 100. Do not throttle when use null/undefined.
  53008. // If animation === true and animationDurationUpdate > 0,
  53009. // default value is 100, otherwise 20.
  53010. start: 0, // Start percent. 0 ~ 100
  53011. end: 100, // End percent. 0 ~ 100
  53012. startValue: null, // Start value. If startValue specified, start is ignored.
  53013. endValue: null, // End value. If endValue specified, end is ignored.
  53014. minSpan: null, // 0 ~ 100
  53015. maxSpan: null, // 0 ~ 100
  53016. minValueSpan: null, // The range of dataZoom can not be smaller than that.
  53017. maxValueSpan: null // The range of dataZoom can not be larger than that.
  53018. },
  53019. /**
  53020. * @override
  53021. */
  53022. init: function (option, parentModel, ecModel) {
  53023. /**
  53024. * key like x_0, y_1
  53025. * @private
  53026. * @type {Object}
  53027. */
  53028. this._dataIntervalByAxis = {};
  53029. /**
  53030. * @private
  53031. */
  53032. this._dataInfo = {};
  53033. /**
  53034. * key like x_0, y_1
  53035. * @private
  53036. */
  53037. this._axisProxies = {};
  53038. /**
  53039. * @readOnly
  53040. */
  53041. this.textStyleModel;
  53042. /**
  53043. * @private
  53044. */
  53045. this._autoThrottle = true;
  53046. /**
  53047. * 'percent' or 'value'
  53048. * @private
  53049. */
  53050. this._rangePropMode = ['percent', 'percent'];
  53051. var rawOption = retrieveRaw(option);
  53052. this.mergeDefaultAndTheme(option, ecModel);
  53053. this.doInit(rawOption);
  53054. },
  53055. /**
  53056. * @override
  53057. */
  53058. mergeOption: function (newOption) {
  53059. var rawOption = retrieveRaw(newOption);
  53060. //FIX #2591
  53061. zrUtil.merge(this.option, newOption, true);
  53062. this.doInit(rawOption);
  53063. },
  53064. /**
  53065. * @protected
  53066. */
  53067. doInit: function (rawOption) {
  53068. var thisOption = this.option;
  53069. // Disable realtime view update if canvas is not supported.
  53070. if (!env.canvasSupported) {
  53071. thisOption.realtime = false;
  53072. }
  53073. this._setDefaultThrottle(rawOption);
  53074. updateRangeUse(this, rawOption);
  53075. each([['start', 'startValue'], ['end', 'endValue']], function (names, index) {
  53076. // start/end has higher priority over startValue/endValue if they
  53077. // both set, but we should make chart.setOption({endValue: 1000})
  53078. // effective, rather than chart.setOption({endValue: 1000, end: null}).
  53079. if (this._rangePropMode[index] === 'value') {
  53080. thisOption[names[0]] = null;
  53081. }
  53082. // Otherwise do nothing and use the merge result.
  53083. }, this);
  53084. this.textStyleModel = this.getModel('textStyle');
  53085. this._resetTarget();
  53086. this._giveAxisProxies();
  53087. },
  53088. /**
  53089. * @private
  53090. */
  53091. _giveAxisProxies: function () {
  53092. var axisProxies = this._axisProxies;
  53093. this.eachTargetAxis(function (dimNames, axisIndex, dataZoomModel, ecModel) {
  53094. var axisModel = this.dependentModels[dimNames.axis][axisIndex];
  53095. // If exists, share axisProxy with other dataZoomModels.
  53096. var axisProxy = axisModel.__dzAxisProxy || (
  53097. // Use the first dataZoomModel as the main model of axisProxy.
  53098. axisModel.__dzAxisProxy = new AxisProxy(
  53099. dimNames.name, axisIndex, this, ecModel
  53100. )
  53101. );
  53102. // FIXME
  53103. // dispose __dzAxisProxy
  53104. axisProxies[dimNames.name + '_' + axisIndex] = axisProxy;
  53105. }, this);
  53106. },
  53107. /**
  53108. * @private
  53109. */
  53110. _resetTarget: function () {
  53111. var thisOption = this.option;
  53112. var autoMode = this._judgeAutoMode();
  53113. eachAxisDim(function (dimNames) {
  53114. var axisIndexName = dimNames.axisIndex;
  53115. thisOption[axisIndexName] = modelUtil.normalizeToArray(
  53116. thisOption[axisIndexName]
  53117. );
  53118. }, this);
  53119. if (autoMode === 'axisIndex') {
  53120. this._autoSetAxisIndex();
  53121. }
  53122. else if (autoMode === 'orient') {
  53123. this._autoSetOrient();
  53124. }
  53125. },
  53126. /**
  53127. * @private
  53128. */
  53129. _judgeAutoMode: function () {
  53130. // Auto set only works for setOption at the first time.
  53131. // The following is user's reponsibility. So using merged
  53132. // option is OK.
  53133. var thisOption = this.option;
  53134. var hasIndexSpecified = false;
  53135. eachAxisDim(function (dimNames) {
  53136. // When user set axisIndex as a empty array, we think that user specify axisIndex
  53137. // but do not want use auto mode. Because empty array may be encountered when
  53138. // some error occured.
  53139. if (thisOption[dimNames.axisIndex] != null) {
  53140. hasIndexSpecified = true;
  53141. }
  53142. }, this);
  53143. var orient = thisOption.orient;
  53144. if (orient == null && hasIndexSpecified) {
  53145. return 'orient';
  53146. }
  53147. else if (!hasIndexSpecified) {
  53148. if (orient == null) {
  53149. thisOption.orient = 'horizontal';
  53150. }
  53151. return 'axisIndex';
  53152. }
  53153. },
  53154. /**
  53155. * @private
  53156. */
  53157. _autoSetAxisIndex: function () {
  53158. var autoAxisIndex = true;
  53159. var orient = this.get('orient', true);
  53160. var thisOption = this.option;
  53161. var dependentModels = this.dependentModels;
  53162. if (autoAxisIndex) {
  53163. // Find axis that parallel to dataZoom as default.
  53164. var dimName = orient === 'vertical' ? 'y' : 'x';
  53165. if (dependentModels[dimName + 'Axis'].length) {
  53166. thisOption[dimName + 'AxisIndex'] = [0];
  53167. autoAxisIndex = false;
  53168. }
  53169. else {
  53170. each(dependentModels.singleAxis, function (singleAxisModel) {
  53171. if (autoAxisIndex && singleAxisModel.get('orient', true) === orient) {
  53172. thisOption.singleAxisIndex = [singleAxisModel.componentIndex];
  53173. autoAxisIndex = false;
  53174. }
  53175. });
  53176. }
  53177. }
  53178. if (autoAxisIndex) {
  53179. // Find the first category axis as default. (consider polar)
  53180. eachAxisDim(function (dimNames) {
  53181. if (!autoAxisIndex) {
  53182. return;
  53183. }
  53184. var axisIndices = [];
  53185. var axisModels = this.dependentModels[dimNames.axis];
  53186. if (axisModels.length && !axisIndices.length) {
  53187. for (var i = 0, len = axisModels.length; i < len; i++) {
  53188. if (axisModels[i].get('type') === 'category') {
  53189. axisIndices.push(i);
  53190. }
  53191. }
  53192. }
  53193. thisOption[dimNames.axisIndex] = axisIndices;
  53194. if (axisIndices.length) {
  53195. autoAxisIndex = false;
  53196. }
  53197. }, this);
  53198. }
  53199. if (autoAxisIndex) {
  53200. // FIXME
  53201. // 这里是兼容ec2的写法(没指定xAxisIndex和yAxisIndex时把scatter和双数值轴折柱纳入dataZoom控制),
  53202. // 但是实际是否需要Grid.js#getScaleByOption来判断(考虑time,log等axis type)?
  53203. // If both dataZoom.xAxisIndex and dataZoom.yAxisIndex is not specified,
  53204. // dataZoom component auto adopts series that reference to
  53205. // both xAxis and yAxis which type is 'value'.
  53206. this.ecModel.eachSeries(function (seriesModel) {
  53207. if (this._isSeriesHasAllAxesTypeOf(seriesModel, 'value')) {
  53208. eachAxisDim(function (dimNames) {
  53209. var axisIndices = thisOption[dimNames.axisIndex];
  53210. var axisIndex = seriesModel.get(dimNames.axisIndex);
  53211. var axisId = seriesModel.get(dimNames.axisId);
  53212. var axisModel = seriesModel.ecModel.queryComponents({
  53213. mainType: dimNames.axis,
  53214. index: axisIndex,
  53215. id: axisId
  53216. })[0];
  53217. if (true) {
  53218. if (!axisModel) {
  53219. throw new Error(
  53220. dimNames.axis + ' "' + zrUtil.retrieve(
  53221. axisIndex,
  53222. axisId,
  53223. 0
  53224. ) + '" not found'
  53225. );
  53226. }
  53227. }
  53228. axisIndex = axisModel.componentIndex;
  53229. if (zrUtil.indexOf(axisIndices, axisIndex) < 0) {
  53230. axisIndices.push(axisIndex);
  53231. }
  53232. });
  53233. }
  53234. }, this);
  53235. }
  53236. },
  53237. /**
  53238. * @private
  53239. */
  53240. _autoSetOrient: function () {
  53241. var dim;
  53242. // Find the first axis
  53243. this.eachTargetAxis(function (dimNames) {
  53244. !dim && (dim = dimNames.name);
  53245. }, this);
  53246. this.option.orient = dim === 'y' ? 'vertical' : 'horizontal';
  53247. },
  53248. /**
  53249. * @private
  53250. */
  53251. _isSeriesHasAllAxesTypeOf: function (seriesModel, axisType) {
  53252. // FIXME
  53253. // 需要series的xAxisIndex和yAxisIndex都首先自动设置上。
  53254. // 例如series.type === scatter时。
  53255. var is = true;
  53256. eachAxisDim(function (dimNames) {
  53257. var seriesAxisIndex = seriesModel.get(dimNames.axisIndex);
  53258. var axisModel = this.dependentModels[dimNames.axis][seriesAxisIndex];
  53259. if (!axisModel || axisModel.get('type') !== axisType) {
  53260. is = false;
  53261. }
  53262. }, this);
  53263. return is;
  53264. },
  53265. /**
  53266. * @private
  53267. */
  53268. _setDefaultThrottle: function (rawOption) {
  53269. // When first time user set throttle, auto throttle ends.
  53270. if (rawOption.hasOwnProperty('throttle')) {
  53271. this._autoThrottle = false;
  53272. }
  53273. if (this._autoThrottle) {
  53274. var globalOption = this.ecModel.option;
  53275. this.option.throttle =
  53276. (globalOption.animation && globalOption.animationDurationUpdate > 0)
  53277. ? 100 : 20;
  53278. }
  53279. },
  53280. /**
  53281. * @public
  53282. */
  53283. getFirstTargetAxisModel: function () {
  53284. var firstAxisModel;
  53285. eachAxisDim(function (dimNames) {
  53286. if (firstAxisModel == null) {
  53287. var indices = this.get(dimNames.axisIndex);
  53288. if (indices.length) {
  53289. firstAxisModel = this.dependentModels[dimNames.axis][indices[0]];
  53290. }
  53291. }
  53292. }, this);
  53293. return firstAxisModel;
  53294. },
  53295. /**
  53296. * @public
  53297. * @param {Function} callback param: axisModel, dimNames, axisIndex, dataZoomModel, ecModel
  53298. */
  53299. eachTargetAxis: function (callback, context) {
  53300. var ecModel = this.ecModel;
  53301. eachAxisDim(function (dimNames) {
  53302. each(
  53303. this.get(dimNames.axisIndex),
  53304. function (axisIndex) {
  53305. callback.call(context, dimNames, axisIndex, this, ecModel);
  53306. },
  53307. this
  53308. );
  53309. }, this);
  53310. },
  53311. /**
  53312. * @param {string} dimName
  53313. * @param {number} axisIndex
  53314. * @return {module:echarts/component/dataZoom/AxisProxy} If not found, return null/undefined.
  53315. */
  53316. getAxisProxy: function (dimName, axisIndex) {
  53317. return this._axisProxies[dimName + '_' + axisIndex];
  53318. },
  53319. /**
  53320. * @param {string} dimName
  53321. * @param {number} axisIndex
  53322. * @return {module:echarts/model/Model} If not found, return null/undefined.
  53323. */
  53324. getAxisModel: function (dimName, axisIndex) {
  53325. var axisProxy = this.getAxisProxy(dimName, axisIndex);
  53326. return axisProxy && axisProxy.getAxisModel();
  53327. },
  53328. /**
  53329. * If not specified, set to undefined.
  53330. *
  53331. * @public
  53332. * @param {Object} opt
  53333. * @param {number} [opt.start]
  53334. * @param {number} [opt.end]
  53335. * @param {number} [opt.startValue]
  53336. * @param {number} [opt.endValue]
  53337. * @param {boolean} [ignoreUpdateRangeUsg=false]
  53338. */
  53339. setRawRange: function (opt, ignoreUpdateRangeUsg) {
  53340. each(['start', 'end', 'startValue', 'endValue'], function (name) {
  53341. // If any of those prop is null/undefined, we should alos set
  53342. // them, because only one pair between start/end and
  53343. // startValue/endValue can work.
  53344. this.option[name] = opt[name];
  53345. }, this);
  53346. !ignoreUpdateRangeUsg && updateRangeUse(this, opt);
  53347. },
  53348. /**
  53349. * @public
  53350. * @return {Array.<number>} [startPercent, endPercent]
  53351. */
  53352. getPercentRange: function () {
  53353. var axisProxy = this.findRepresentativeAxisProxy();
  53354. if (axisProxy) {
  53355. return axisProxy.getDataPercentWindow();
  53356. }
  53357. },
  53358. /**
  53359. * @public
  53360. * For example, chart.getModel().getComponent('dataZoom').getValueRange('y', 0);
  53361. *
  53362. * @param {string} [axisDimName]
  53363. * @param {number} [axisIndex]
  53364. * @return {Array.<number>} [startValue, endValue] value can only be '-' or finite number.
  53365. */
  53366. getValueRange: function (axisDimName, axisIndex) {
  53367. if (axisDimName == null && axisIndex == null) {
  53368. var axisProxy = this.findRepresentativeAxisProxy();
  53369. if (axisProxy) {
  53370. return axisProxy.getDataValueWindow();
  53371. }
  53372. }
  53373. else {
  53374. return this.getAxisProxy(axisDimName, axisIndex).getDataValueWindow();
  53375. }
  53376. },
  53377. /**
  53378. * @public
  53379. * @param {module:echarts/model/Model} [axisModel] If axisModel given, find axisProxy
  53380. * corresponding to the axisModel
  53381. * @return {module:echarts/component/dataZoom/AxisProxy}
  53382. */
  53383. findRepresentativeAxisProxy: function (axisModel) {
  53384. if (axisModel) {
  53385. return axisModel.__dzAxisProxy;
  53386. }
  53387. // Find the first hosted axisProxy
  53388. var axisProxies = this._axisProxies;
  53389. for (var key in axisProxies) {
  53390. if (axisProxies.hasOwnProperty(key) && axisProxies[key].hostedBy(this)) {
  53391. return axisProxies[key];
  53392. }
  53393. }
  53394. // If no hosted axis find not hosted axisProxy.
  53395. // Consider this case: dataZoomModel1 and dataZoomModel2 control the same axis,
  53396. // and the option.start or option.end settings are different. The percentRange
  53397. // should follow axisProxy.
  53398. // (We encounter this problem in toolbox data zoom.)
  53399. for (var key in axisProxies) {
  53400. if (axisProxies.hasOwnProperty(key) && !axisProxies[key].hostedBy(this)) {
  53401. return axisProxies[key];
  53402. }
  53403. }
  53404. },
  53405. /**
  53406. * @return {Array.<string>}
  53407. */
  53408. getRangePropMode: function () {
  53409. return this._rangePropMode.slice();
  53410. }
  53411. });
  53412. function retrieveRaw(option) {
  53413. var ret = {};
  53414. each(
  53415. ['start', 'end', 'startValue', 'endValue', 'throttle'],
  53416. function (name) {
  53417. option.hasOwnProperty(name) && (ret[name] = option[name]);
  53418. }
  53419. );
  53420. return ret;
  53421. }
  53422. function updateRangeUse(dataZoomModel, rawOption) {
  53423. each([['start', 'startValue'], ['end', 'endValue']], function (names, index) {
  53424. var rangePropMode = dataZoomModel._rangePropMode;
  53425. if (rawOption[names[0]] != null) {
  53426. rangePropMode[index] = 'percent';
  53427. }
  53428. else if (rawOption[names[1]] != null) {
  53429. rangePropMode[index] = 'value';
  53430. }
  53431. // else remain its original setting.
  53432. });
  53433. }
  53434. module.exports = DataZoomModel;
  53435. /***/ },
  53436. /* 365 */
  53437. /***/ function(module, exports, __webpack_require__) {
  53438. var formatUtil = __webpack_require__(6);
  53439. var zrUtil = __webpack_require__(4);
  53440. var helper = {};
  53441. var AXIS_DIMS = ['x', 'y', 'z', 'radius', 'angle', 'single'];
  53442. // Supported coords.
  53443. var COORDS = ['cartesian2d', 'polar', 'singleAxis'];
  53444. /**
  53445. * @param {string} coordType
  53446. * @return {boolean}
  53447. */
  53448. helper.isCoordSupported = function (coordType) {
  53449. return zrUtil.indexOf(COORDS, coordType) >= 0;
  53450. };
  53451. /**
  53452. * Create "each" method to iterate names.
  53453. *
  53454. * @pubilc
  53455. * @param {Array.<string>} names
  53456. * @param {Array.<string>=} attrs
  53457. * @return {Function}
  53458. */
  53459. helper.createNameEach = function (names, attrs) {
  53460. names = names.slice();
  53461. var capitalNames = zrUtil.map(names, formatUtil.capitalFirst);
  53462. attrs = (attrs || []).slice();
  53463. var capitalAttrs = zrUtil.map(attrs, formatUtil.capitalFirst);
  53464. return function (callback, context) {
  53465. zrUtil.each(names, function (name, index) {
  53466. var nameObj = {name: name, capital: capitalNames[index]};
  53467. for (var j = 0; j < attrs.length; j++) {
  53468. nameObj[attrs[j]] = name + capitalAttrs[j];
  53469. }
  53470. callback.call(context, nameObj);
  53471. });
  53472. };
  53473. };
  53474. /**
  53475. * Iterate each dimension name.
  53476. *
  53477. * @public
  53478. * @param {Function} callback The parameter is like:
  53479. * {
  53480. * name: 'angle',
  53481. * capital: 'Angle',
  53482. * axis: 'angleAxis',
  53483. * axisIndex: 'angleAixs',
  53484. * index: 'angleIndex'
  53485. * }
  53486. * @param {Object} context
  53487. */
  53488. helper.eachAxisDim = helper.createNameEach(AXIS_DIMS, ['axisIndex', 'axis', 'index', 'id']);
  53489. /**
  53490. * If tow dataZoomModels has the same axis controlled, we say that they are 'linked'.
  53491. * dataZoomModels and 'links' make up one or more graphics.
  53492. * This function finds the graphic where the source dataZoomModel is in.
  53493. *
  53494. * @public
  53495. * @param {Function} forEachNode Node iterator.
  53496. * @param {Function} forEachEdgeType edgeType iterator
  53497. * @param {Function} edgeIdGetter Giving node and edgeType, return an array of edge id.
  53498. * @return {Function} Input: sourceNode, Output: Like {nodes: [], dims: {}}
  53499. */
  53500. helper.createLinkedNodesFinder = function (forEachNode, forEachEdgeType, edgeIdGetter) {
  53501. return function (sourceNode) {
  53502. var result = {
  53503. nodes: [],
  53504. records: {} // key: edgeType.name, value: Object (key: edge id, value: boolean).
  53505. };
  53506. forEachEdgeType(function (edgeType) {
  53507. result.records[edgeType.name] = {};
  53508. });
  53509. if (!sourceNode) {
  53510. return result;
  53511. }
  53512. absorb(sourceNode, result);
  53513. var existsLink;
  53514. do {
  53515. existsLink = false;
  53516. forEachNode(processSingleNode);
  53517. }
  53518. while (existsLink);
  53519. function processSingleNode(node) {
  53520. if (!isNodeAbsorded(node, result) && isLinked(node, result)) {
  53521. absorb(node, result);
  53522. existsLink = true;
  53523. }
  53524. }
  53525. return result;
  53526. };
  53527. function isNodeAbsorded(node, result) {
  53528. return zrUtil.indexOf(result.nodes, node) >= 0;
  53529. }
  53530. function isLinked(node, result) {
  53531. var hasLink = false;
  53532. forEachEdgeType(function (edgeType) {
  53533. zrUtil.each(edgeIdGetter(node, edgeType) || [], function (edgeId) {
  53534. result.records[edgeType.name][edgeId] && (hasLink = true);
  53535. });
  53536. });
  53537. return hasLink;
  53538. }
  53539. function absorb(node, result) {
  53540. result.nodes.push(node);
  53541. forEachEdgeType(function (edgeType) {
  53542. zrUtil.each(edgeIdGetter(node, edgeType) || [], function (edgeId) {
  53543. result.records[edgeType.name][edgeId] = true;
  53544. });
  53545. });
  53546. }
  53547. };
  53548. module.exports = helper;
  53549. /***/ },
  53550. /* 366 */
  53551. /***/ function(module, exports, __webpack_require__) {
  53552. /**
  53553. * @file Axis operator
  53554. */
  53555. var zrUtil = __webpack_require__(4);
  53556. var numberUtil = __webpack_require__(7);
  53557. var helper = __webpack_require__(365);
  53558. var each = zrUtil.each;
  53559. var asc = numberUtil.asc;
  53560. /**
  53561. * Operate single axis.
  53562. * One axis can only operated by one axis operator.
  53563. * Different dataZoomModels may be defined to operate the same axis.
  53564. * (i.e. 'inside' data zoom and 'slider' data zoom components)
  53565. * So dataZoomModels share one axisProxy in that case.
  53566. *
  53567. * @class
  53568. */
  53569. var AxisProxy = function (dimName, axisIndex, dataZoomModel, ecModel) {
  53570. /**
  53571. * @private
  53572. * @type {string}
  53573. */
  53574. this._dimName = dimName;
  53575. /**
  53576. * @private
  53577. */
  53578. this._axisIndex = axisIndex;
  53579. /**
  53580. * @private
  53581. * @type {Array.<number>}
  53582. */
  53583. this._valueWindow;
  53584. /**
  53585. * @private
  53586. * @type {Array.<number>}
  53587. */
  53588. this._percentWindow;
  53589. /**
  53590. * @private
  53591. * @type {Array.<number>}
  53592. */
  53593. this._dataExtent;
  53594. /**
  53595. * {minSpan, maxSpan, minValueSpan, maxValueSpan}
  53596. * @private
  53597. * @type {Object}
  53598. */
  53599. this._minMaxSpan;
  53600. /**
  53601. * @readOnly
  53602. * @type {module: echarts/model/Global}
  53603. */
  53604. this.ecModel = ecModel;
  53605. /**
  53606. * @private
  53607. * @type {module: echarts/component/dataZoom/DataZoomModel}
  53608. */
  53609. this._dataZoomModel = dataZoomModel;
  53610. };
  53611. AxisProxy.prototype = {
  53612. constructor: AxisProxy,
  53613. /**
  53614. * Whether the axisProxy is hosted by dataZoomModel.
  53615. *
  53616. * @public
  53617. * @param {module: echarts/component/dataZoom/DataZoomModel} dataZoomModel
  53618. * @return {boolean}
  53619. */
  53620. hostedBy: function (dataZoomModel) {
  53621. return this._dataZoomModel === dataZoomModel;
  53622. },
  53623. /**
  53624. * @return {Array.<number>} Value can only be NaN or finite value.
  53625. */
  53626. getDataValueWindow: function () {
  53627. return this._valueWindow.slice();
  53628. },
  53629. /**
  53630. * @return {Array.<number>}
  53631. */
  53632. getDataPercentWindow: function () {
  53633. return this._percentWindow.slice();
  53634. },
  53635. /**
  53636. * @public
  53637. * @param {number} axisIndex
  53638. * @return {Array} seriesModels
  53639. */
  53640. getTargetSeriesModels: function () {
  53641. var seriesModels = [];
  53642. var ecModel = this.ecModel;
  53643. ecModel.eachSeries(function (seriesModel) {
  53644. if (helper.isCoordSupported(seriesModel.get('coordinateSystem'))) {
  53645. var dimName = this._dimName;
  53646. var axisModel = ecModel.queryComponents({
  53647. mainType: dimName + 'Axis',
  53648. index: seriesModel.get(dimName + 'AxisIndex'),
  53649. id: seriesModel.get(dimName + 'AxisId')
  53650. })[0];
  53651. if (this._axisIndex === (axisModel && axisModel.componentIndex)) {
  53652. seriesModels.push(seriesModel);
  53653. }
  53654. }
  53655. }, this);
  53656. return seriesModels;
  53657. },
  53658. getAxisModel: function () {
  53659. return this.ecModel.getComponent(this._dimName + 'Axis', this._axisIndex);
  53660. },
  53661. getOtherAxisModel: function () {
  53662. var axisDim = this._dimName;
  53663. var ecModel = this.ecModel;
  53664. var axisModel = this.getAxisModel();
  53665. var isCartesian = axisDim === 'x' || axisDim === 'y';
  53666. var otherAxisDim;
  53667. var coordSysIndexName;
  53668. if (isCartesian) {
  53669. coordSysIndexName = 'gridIndex';
  53670. otherAxisDim = axisDim === 'x' ? 'y' : 'x';
  53671. }
  53672. else {
  53673. coordSysIndexName = 'polarIndex';
  53674. otherAxisDim = axisDim === 'angle' ? 'radius' : 'angle';
  53675. }
  53676. var foundOtherAxisModel;
  53677. ecModel.eachComponent(otherAxisDim + 'Axis', function (otherAxisModel) {
  53678. if ((otherAxisModel.get(coordSysIndexName) || 0)
  53679. === (axisModel.get(coordSysIndexName) || 0)
  53680. ) {
  53681. foundOtherAxisModel = otherAxisModel;
  53682. }
  53683. });
  53684. return foundOtherAxisModel;
  53685. },
  53686. getMinMaxSpan: function () {
  53687. return zrUtil.clone(this._minMaxSpan);
  53688. },
  53689. /**
  53690. * Only calculate by given range and this._dataExtent, do not change anything.
  53691. *
  53692. * @param {Object} opt
  53693. * @param {number} [opt.start]
  53694. * @param {number} [opt.end]
  53695. * @param {number} [opt.startValue]
  53696. * @param {number} [opt.endValue]
  53697. */
  53698. calculateDataWindow: function (opt) {
  53699. var dataExtent = this._dataExtent;
  53700. var axisModel = this.getAxisModel();
  53701. var scale = axisModel.axis.scale;
  53702. var rangePropMode = this._dataZoomModel.getRangePropMode();
  53703. var percentExtent = [0, 100];
  53704. var percentWindow = [
  53705. opt.start,
  53706. opt.end
  53707. ];
  53708. var valueWindow = [];
  53709. each(['startValue', 'endValue'], function (prop) {
  53710. valueWindow.push(opt[prop] != null ? scale.parse(opt[prop]) : null);
  53711. });
  53712. // Normalize bound.
  53713. each([0, 1], function (idx) {
  53714. var boundValue = valueWindow[idx];
  53715. var boundPercent = percentWindow[idx];
  53716. // Notice: dataZoom is based either on `percentProp` ('start', 'end') or
  53717. // on `valueProp` ('startValue', 'endValue'). The former one is suitable
  53718. // for cases that a dataZoom component controls multiple axes with different
  53719. // unit or extent, and the latter one is suitable for accurate zoom by pixel
  53720. // (e.g., in dataZoomSelect). `valueProp` can be calculated from `percentProp`,
  53721. // but it is awkward that `percentProp` can not be obtained from `valueProp`
  53722. // accurately (because all of values that are overflow the `dataExtent` will
  53723. // be calculated to percent '100%'). So we have to use
  53724. // `dataZoom.getRangePropMode()` to mark which prop is used.
  53725. // `rangePropMode` is updated only when setOption or dispatchAction, otherwise
  53726. // it remains its original value.
  53727. if (rangePropMode[idx] === 'percent') {
  53728. if (boundPercent == null) {
  53729. boundPercent = percentExtent[idx];
  53730. }
  53731. // Use scale.parse to math round for category or time axis.
  53732. boundValue = scale.parse(numberUtil.linearMap(
  53733. boundPercent, percentExtent, dataExtent, true
  53734. ));
  53735. }
  53736. else {
  53737. // Calculating `percent` from `value` may be not accurate, because
  53738. // This calculation can not be inversed, because all of values that
  53739. // are overflow the `dataExtent` will be calculated to percent '100%'
  53740. boundPercent = numberUtil.linearMap(
  53741. boundValue, dataExtent, percentExtent, true
  53742. );
  53743. }
  53744. // valueWindow[idx] = round(boundValue);
  53745. // percentWindow[idx] = round(boundPercent);
  53746. valueWindow[idx] = boundValue;
  53747. percentWindow[idx] = boundPercent;
  53748. });
  53749. return {
  53750. valueWindow: asc(valueWindow),
  53751. percentWindow: asc(percentWindow)
  53752. };
  53753. },
  53754. /**
  53755. * Notice: reset should not be called before series.restoreData() called,
  53756. * so it is recommanded to be called in "process stage" but not "model init
  53757. * stage".
  53758. *
  53759. * @param {module: echarts/component/dataZoom/DataZoomModel} dataZoomModel
  53760. */
  53761. reset: function (dataZoomModel) {
  53762. if (dataZoomModel !== this._dataZoomModel) {
  53763. return;
  53764. }
  53765. // Culculate data window and data extent, and record them.
  53766. this._dataExtent = calculateDataExtent(
  53767. this, this._dimName, this.getTargetSeriesModels()
  53768. );
  53769. var dataWindow = this.calculateDataWindow(dataZoomModel.option);
  53770. this._valueWindow = dataWindow.valueWindow;
  53771. this._percentWindow = dataWindow.percentWindow;
  53772. setMinMaxSpan(this);
  53773. // Update axis setting then.
  53774. setAxisModel(this);
  53775. },
  53776. /**
  53777. * @param {module: echarts/component/dataZoom/DataZoomModel} dataZoomModel
  53778. */
  53779. restore: function (dataZoomModel) {
  53780. if (dataZoomModel !== this._dataZoomModel) {
  53781. return;
  53782. }
  53783. this._valueWindow = this._percentWindow = null;
  53784. setAxisModel(this, true);
  53785. },
  53786. /**
  53787. * @param {module: echarts/component/dataZoom/DataZoomModel} dataZoomModel
  53788. */
  53789. filterData: function (dataZoomModel) {
  53790. if (dataZoomModel !== this._dataZoomModel) {
  53791. return;
  53792. }
  53793. var axisDim = this._dimName;
  53794. var seriesModels = this.getTargetSeriesModels();
  53795. var filterMode = dataZoomModel.get('filterMode');
  53796. var valueWindow = this._valueWindow;
  53797. if (filterMode === 'none') {
  53798. return;
  53799. }
  53800. // FIXME
  53801. // Toolbox may has dataZoom injected. And if there are stacked bar chart
  53802. // with NaN data, NaN will be filtered and stack will be wrong.
  53803. // So we need to force the mode to be set empty.
  53804. // In fect, it is not a big deal that do not support filterMode-'filter'
  53805. // when using toolbox#dataZoom, utill tooltip#dataZoom support "single axis
  53806. // selection" some day, which might need "adapt to data extent on the
  53807. // otherAxis", which is disabled by filterMode-'empty'.
  53808. var otherAxisModel = this.getOtherAxisModel();
  53809. if (dataZoomModel.get('$fromToolbox')
  53810. && otherAxisModel
  53811. && otherAxisModel.get('type') === 'category'
  53812. ) {
  53813. filterMode = 'empty';
  53814. }
  53815. // Process series data
  53816. each(seriesModels, function (seriesModel) {
  53817. var seriesData = seriesModel.getData();
  53818. var dataDims = seriesModel.coordDimToDataDim(axisDim);
  53819. if (filterMode === 'weakFilter') {
  53820. seriesData && seriesData.filterSelf(function (dataIndex) {
  53821. var leftOut;
  53822. var rightOut;
  53823. var hasValue;
  53824. for (var i = 0; i < dataDims.length; i++) {
  53825. var value = seriesData.get(dataDims[i], dataIndex);
  53826. var thisHasValue = !isNaN(value);
  53827. var thisLeftOut = value < valueWindow[0];
  53828. var thisRightOut = value > valueWindow[1];
  53829. if (thisHasValue && !thisLeftOut && !thisRightOut) {
  53830. return true;
  53831. }
  53832. thisHasValue && (hasValue = true);
  53833. thisLeftOut && (leftOut = true);
  53834. thisRightOut && (rightOut = true);
  53835. }
  53836. // If both left out and right out, do not filter.
  53837. return hasValue && leftOut && rightOut;
  53838. });
  53839. }
  53840. else {
  53841. seriesData && each(dataDims, function (dim) {
  53842. if (filterMode === 'empty') {
  53843. seriesModel.setData(
  53844. seriesData.map(dim, function (value) {
  53845. return !isInWindow(value) ? NaN : value;
  53846. })
  53847. );
  53848. }
  53849. else {
  53850. seriesData.filterSelf(dim, isInWindow);
  53851. }
  53852. });
  53853. }
  53854. });
  53855. function isInWindow(value) {
  53856. return value >= valueWindow[0] && value <= valueWindow[1];
  53857. }
  53858. }
  53859. };
  53860. function calculateDataExtent(axisProxy, axisDim, seriesModels) {
  53861. var dataExtent = [Infinity, -Infinity];
  53862. each(seriesModels, function (seriesModel) {
  53863. var seriesData = seriesModel.getData();
  53864. if (seriesData) {
  53865. each(seriesModel.coordDimToDataDim(axisDim), function (dim) {
  53866. var seriesExtent = seriesData.getDataExtent(dim);
  53867. seriesExtent[0] < dataExtent[0] && (dataExtent[0] = seriesExtent[0]);
  53868. seriesExtent[1] > dataExtent[1] && (dataExtent[1] = seriesExtent[1]);
  53869. });
  53870. }
  53871. });
  53872. if (dataExtent[1] < dataExtent[0]) {
  53873. dataExtent = [NaN, NaN];
  53874. }
  53875. // It is important to get "consistent" extent when more then one axes is
  53876. // controlled by a `dataZoom`, otherwise those axes will not be synchronized
  53877. // when zooming. But it is difficult to know what is "consistent", considering
  53878. // axes have different type or even different meanings (For example, two
  53879. // time axes are used to compare data of the same date in different years).
  53880. // So basically dataZoom just obtains extent by series.data (in category axis
  53881. // extent can be obtained from axis.data).
  53882. // Nevertheless, user can set min/max/scale on axes to make extent of axes
  53883. // consistent.
  53884. fixExtentByAxis(axisProxy, dataExtent);
  53885. return dataExtent;
  53886. }
  53887. function fixExtentByAxis(axisProxy, dataExtent) {
  53888. var axisModel = axisProxy.getAxisModel();
  53889. var min = axisModel.getMin(true);
  53890. // For category axis, if min/max/scale are not set, extent is determined
  53891. // by axis.data by default.
  53892. var isCategoryAxis = axisModel.get('type') === 'category';
  53893. var axisDataLen = isCategoryAxis && (axisModel.get('data') || []).length;
  53894. if (min != null && min !== 'dataMin') {
  53895. dataExtent[0] = min;
  53896. }
  53897. else if (isCategoryAxis) {
  53898. dataExtent[0] = axisDataLen > 0 ? 0 : NaN;
  53899. }
  53900. var max = axisModel.getMax(true);
  53901. if (max != null && max !== 'dataMax') {
  53902. dataExtent[1] = max;
  53903. }
  53904. else if (isCategoryAxis) {
  53905. dataExtent[1] = axisDataLen > 0 ? axisDataLen - 1 : NaN;
  53906. }
  53907. if (!axisModel.get('scale', true)) {
  53908. dataExtent[0] > 0 && (dataExtent[0] = 0);
  53909. dataExtent[1] < 0 && (dataExtent[1] = 0);
  53910. }
  53911. // For value axis, if min/max/scale are not set, we just use the extent obtained
  53912. // by series data, which may be a little different from the extent calculated by
  53913. // `axisHelper.getScaleExtent`. But the different just affects the experience a
  53914. // little when zooming. So it will not be fixed until some users require it strongly.
  53915. return dataExtent;
  53916. }
  53917. function setAxisModel(axisProxy, isRestore) {
  53918. var axisModel = axisProxy.getAxisModel();
  53919. var percentWindow = axisProxy._percentWindow;
  53920. var valueWindow = axisProxy._valueWindow;
  53921. if (!percentWindow) {
  53922. return;
  53923. }
  53924. // [0, 500]: arbitrary value, guess axis extent.
  53925. var precision = numberUtil.getPixelPrecision(valueWindow, [0, 500]);
  53926. // isRestore or isFull
  53927. var useOrigin = isRestore || (percentWindow[0] === 0 && percentWindow[1] === 100);
  53928. axisModel.setRange(
  53929. useOrigin ? null : +valueWindow[0].toFixed(precision),
  53930. useOrigin ? null : +valueWindow[1].toFixed(precision)
  53931. );
  53932. }
  53933. function setMinMaxSpan(axisProxy) {
  53934. var minMaxSpan = axisProxy._minMaxSpan = {};
  53935. var dataZoomModel = axisProxy._dataZoomModel;
  53936. each(['min', 'max'], function (minMax) {
  53937. minMaxSpan[minMax + 'Span'] = dataZoomModel.get(minMax + 'Span');
  53938. // minValueSpan and maxValueSpan has higher priority than minSpan and maxSpan
  53939. var valueSpan = dataZoomModel.get(minMax + 'ValueSpan');
  53940. if (valueSpan != null) {
  53941. minMaxSpan[minMax + 'ValueSpan'] = valueSpan;
  53942. valueSpan = axisProxy.getAxisModel().axis.scale.parse(valueSpan);
  53943. if (valueSpan != null) {
  53944. minMaxSpan[minMax + 'Span'] = numberUtil.linearMap(
  53945. valueSpan, axisProxy._dataExtent, [0, 100], true
  53946. );
  53947. }
  53948. }
  53949. });
  53950. }
  53951. module.exports = AxisProxy;
  53952. /***/ },
  53953. /* 367 */
  53954. /***/ function(module, exports, __webpack_require__) {
  53955. var ComponentView = __webpack_require__(79);
  53956. module.exports = ComponentView.extend({
  53957. type: 'dataZoom',
  53958. render: function (dataZoomModel, ecModel, api, payload) {
  53959. this.dataZoomModel = dataZoomModel;
  53960. this.ecModel = ecModel;
  53961. this.api = api;
  53962. },
  53963. /**
  53964. * Find the first target coordinate system.
  53965. *
  53966. * @protected
  53967. * @return {Object} {
  53968. * grid: [
  53969. * {model: coord0, axisModels: [axis1, axis3], coordIndex: 1},
  53970. * {model: coord1, axisModels: [axis0, axis2], coordIndex: 0},
  53971. * ...
  53972. * ], // cartesians must not be null/undefined.
  53973. * polar: [
  53974. * {model: coord0, axisModels: [axis4], coordIndex: 0},
  53975. * ...
  53976. * ], // polars must not be null/undefined.
  53977. * singleAxis: [
  53978. * {model: coord0, axisModels: [], coordIndex: 0}
  53979. * ]
  53980. */
  53981. getTargetCoordInfo: function () {
  53982. var dataZoomModel = this.dataZoomModel;
  53983. var ecModel = this.ecModel;
  53984. var coordSysLists = {};
  53985. dataZoomModel.eachTargetAxis(function (dimNames, axisIndex) {
  53986. var axisModel = ecModel.getComponent(dimNames.axis, axisIndex);
  53987. if (axisModel) {
  53988. var coordModel = axisModel.getCoordSysModel();
  53989. coordModel && save(
  53990. coordModel,
  53991. axisModel,
  53992. coordSysLists[coordModel.mainType] || (coordSysLists[coordModel.mainType] = []),
  53993. coordModel.componentIndex
  53994. );
  53995. }
  53996. }, this);
  53997. function save(coordModel, axisModel, store, coordIndex) {
  53998. var item;
  53999. for (var i = 0; i < store.length; i++) {
  54000. if (store[i].model === coordModel) {
  54001. item = store[i];
  54002. break;
  54003. }
  54004. }
  54005. if (!item) {
  54006. store.push(item = {
  54007. model: coordModel, axisModels: [], coordIndex: coordIndex
  54008. });
  54009. }
  54010. item.axisModels.push(axisModel);
  54011. }
  54012. return coordSysLists;
  54013. }
  54014. });
  54015. /***/ },
  54016. /* 368 */
  54017. /***/ function(module, exports, __webpack_require__) {
  54018. /**
  54019. * @file Data zoom model
  54020. */
  54021. var DataZoomModel = __webpack_require__(364);
  54022. var SliderZoomModel = DataZoomModel.extend({
  54023. type: 'dataZoom.slider',
  54024. layoutMode: 'box',
  54025. /**
  54026. * @protected
  54027. */
  54028. defaultOption: {
  54029. show: true,
  54030. // ph => placeholder. Using placehoder here because
  54031. // deault value can only be drived in view stage.
  54032. right: 'ph', // Default align to grid rect.
  54033. top: 'ph', // Default align to grid rect.
  54034. width: 'ph', // Default align to grid rect.
  54035. height: 'ph', // Default align to grid rect.
  54036. left: null, // Default align to grid rect.
  54037. bottom: null, // Default align to grid rect.
  54038. backgroundColor: 'rgba(47,69,84,0)', // Background of slider zoom component.
  54039. // dataBackgroundColor: '#ddd', // Background coor of data shadow and border of box,
  54040. // highest priority, remain for compatibility of
  54041. // previous version, but not recommended any more.
  54042. dataBackground: {
  54043. lineStyle: {
  54044. color: '#2f4554',
  54045. width: 0.5,
  54046. opacity: 0.3
  54047. },
  54048. areaStyle: {
  54049. color: 'rgba(47,69,84,0.3)',
  54050. opacity: 0.3
  54051. }
  54052. },
  54053. borderColor: '#ddd', // border color of the box. For compatibility,
  54054. // if dataBackgroundColor is set, borderColor
  54055. // is ignored.
  54056. fillerColor: 'rgba(167,183,204,0.4)', // Color of selected area.
  54057. // handleColor: 'rgba(89,170,216,0.95)', // Color of handle.
  54058. // 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',
  54059. 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',
  54060. // Percent of the slider height
  54061. handleSize: '100%',
  54062. handleStyle: {
  54063. color: '#a7b7cc'
  54064. },
  54065. labelPrecision: null,
  54066. labelFormatter: null,
  54067. showDetail: true,
  54068. showDataShadow: 'auto', // Default auto decision.
  54069. realtime: true,
  54070. zoomLock: false, // Whether disable zoom.
  54071. textStyle: {
  54072. color: '#333'
  54073. }
  54074. }
  54075. });
  54076. module.exports = SliderZoomModel;
  54077. /***/ },
  54078. /* 369 */
  54079. /***/ function(module, exports, __webpack_require__) {
  54080. var zrUtil = __webpack_require__(4);
  54081. var graphic = __webpack_require__(18);
  54082. var throttle = __webpack_require__(81);
  54083. var DataZoomView = __webpack_require__(367);
  54084. var Rect = graphic.Rect;
  54085. var numberUtil = __webpack_require__(7);
  54086. var linearMap = numberUtil.linearMap;
  54087. var layout = __webpack_require__(71);
  54088. var sliderMove = __webpack_require__(238);
  54089. var eventTool = __webpack_require__(88);
  54090. var asc = numberUtil.asc;
  54091. var bind = zrUtil.bind;
  54092. // var mathMax = Math.max;
  54093. var each = zrUtil.each;
  54094. // Constants
  54095. var DEFAULT_LOCATION_EDGE_GAP = 7;
  54096. var DEFAULT_FRAME_BORDER_WIDTH = 1;
  54097. var DEFAULT_FILLER_SIZE = 100;
  54098. var HORIZONTAL = 'horizontal';
  54099. var VERTICAL = 'vertical';
  54100. var LABEL_GAP = 5;
  54101. var SHOW_DATA_SHADOW_SERIES_TYPE = ['line', 'bar', 'candlestick', 'scatter'];
  54102. var SliderZoomView = DataZoomView.extend({
  54103. type: 'dataZoom.slider',
  54104. init: function (ecModel, api) {
  54105. /**
  54106. * @private
  54107. * @type {Object}
  54108. */
  54109. this._displayables = {};
  54110. /**
  54111. * @private
  54112. * @type {string}
  54113. */
  54114. this._orient;
  54115. /**
  54116. * [0, 100]
  54117. * @private
  54118. */
  54119. this._range;
  54120. /**
  54121. * [coord of the first handle, coord of the second handle]
  54122. * @private
  54123. */
  54124. this._handleEnds;
  54125. /**
  54126. * [length, thick]
  54127. * @private
  54128. * @type {Array.<number>}
  54129. */
  54130. this._size;
  54131. /**
  54132. * @private
  54133. * @type {number}
  54134. */
  54135. this._handleWidth;
  54136. /**
  54137. * @private
  54138. * @type {number}
  54139. */
  54140. this._handleHeight;
  54141. /**
  54142. * @private
  54143. */
  54144. this._location;
  54145. /**
  54146. * @private
  54147. */
  54148. this._dragging;
  54149. /**
  54150. * @private
  54151. */
  54152. this._dataShadowInfo;
  54153. this.api = api;
  54154. },
  54155. /**
  54156. * @override
  54157. */
  54158. render: function (dataZoomModel, ecModel, api, payload) {
  54159. SliderZoomView.superApply(this, 'render', arguments);
  54160. throttle.createOrUpdate(
  54161. this,
  54162. '_dispatchZoomAction',
  54163. this.dataZoomModel.get('throttle'),
  54164. 'fixRate'
  54165. );
  54166. this._orient = dataZoomModel.get('orient');
  54167. if (this.dataZoomModel.get('show') === false) {
  54168. this.group.removeAll();
  54169. return;
  54170. }
  54171. // Notice: this._resetInterval() should not be executed when payload.type
  54172. // is 'dataZoom', origin this._range should be maintained, otherwise 'pan'
  54173. // or 'zoom' info will be missed because of 'throttle' of this.dispatchAction,
  54174. if (!payload || payload.type !== 'dataZoom' || payload.from !== this.uid) {
  54175. this._buildView();
  54176. }
  54177. this._updateView();
  54178. },
  54179. /**
  54180. * @override
  54181. */
  54182. remove: function () {
  54183. SliderZoomView.superApply(this, 'remove', arguments);
  54184. throttle.clear(this, '_dispatchZoomAction');
  54185. },
  54186. /**
  54187. * @override
  54188. */
  54189. dispose: function () {
  54190. SliderZoomView.superApply(this, 'dispose', arguments);
  54191. throttle.clear(this, '_dispatchZoomAction');
  54192. },
  54193. _buildView: function () {
  54194. var thisGroup = this.group;
  54195. thisGroup.removeAll();
  54196. this._resetLocation();
  54197. this._resetInterval();
  54198. var barGroup = this._displayables.barGroup = new graphic.Group();
  54199. this._renderBackground();
  54200. this._renderHandle();
  54201. this._renderDataShadow();
  54202. thisGroup.add(barGroup);
  54203. this._positionGroup();
  54204. },
  54205. /**
  54206. * @private
  54207. */
  54208. _resetLocation: function () {
  54209. var dataZoomModel = this.dataZoomModel;
  54210. var api = this.api;
  54211. // If some of x/y/width/height are not specified,
  54212. // auto-adapt according to target grid.
  54213. var coordRect = this._findCoordRect();
  54214. var ecSize = {width: api.getWidth(), height: api.getHeight()};
  54215. // Default align by coordinate system rect.
  54216. console.log("DEFAULT_FILLER_SIZE =" +DEFAULT_FILLER_SIZE)
  54217. var positionInfo = this._orient === HORIZONTAL
  54218. ? {
  54219. // Why using 'right', because right should be used in vertical,
  54220. // and it is better to be consistent for dealing with position param merge.
  54221. right: ecSize.width - coordRect.x - coordRect.width,
  54222. top: (ecSize.height - DEFAULT_FILLER_SIZE - DEFAULT_LOCATION_EDGE_GAP),
  54223. width: coordRect.width,
  54224. height: DEFAULT_FILLER_SIZE
  54225. }
  54226. : { // vertical
  54227. right: DEFAULT_LOCATION_EDGE_GAP,
  54228. top: coordRect.y,
  54229. width: DEFAULT_FILLER_SIZE,
  54230. height: coordRect.height
  54231. };
  54232. // Do not write back to option and replace value 'ph', because
  54233. // the 'ph' value should be recalculated when resize.
  54234. var layoutParams = layout.getLayoutParams(dataZoomModel.option);
  54235. console.log(dataZoomModel.option)
  54236. // Replace the placeholder value.
  54237. zrUtil.each(['right', 'top', 'width', 'height'], function (name) {
  54238. if (layoutParams[name] === 'ph') {
  54239. layoutParams[name] = positionInfo[name];
  54240. }
  54241. });
  54242. console.log(layoutParams)
  54243. var layoutRect = layout.getLayoutRect(
  54244. layoutParams,
  54245. ecSize,
  54246. dataZoomModel.padding
  54247. );
  54248. console.log(layoutRect.height)
  54249. this._location = {x: layoutRect.x, y: layoutRect.y};
  54250. this._size = [layoutRect.width, layoutRect.height];
  54251. this._orient === VERTICAL && this._size.reverse();
  54252. },
  54253. /**
  54254. * @private
  54255. */
  54256. _positionGroup: function () {
  54257. var thisGroup = this.group;
  54258. var location = this._location;
  54259. var orient = this._orient;
  54260. // Just use the first axis to determine mapping.
  54261. var targetAxisModel = this.dataZoomModel.getFirstTargetAxisModel();
  54262. var inverse = targetAxisModel && targetAxisModel.get('inverse');
  54263. var barGroup = this._displayables.barGroup;
  54264. var otherAxisInverse = (this._dataShadowInfo || {}).otherAxisInverse;
  54265. // Transform barGroup.
  54266. barGroup.attr(
  54267. (orient === HORIZONTAL && !inverse)
  54268. ? {scale: otherAxisInverse ? [1, 1] : [1, -1]}
  54269. : (orient === HORIZONTAL && inverse)
  54270. ? {scale: otherAxisInverse ? [-1, 1] : [-1, -1]}
  54271. : (orient === VERTICAL && !inverse)
  54272. ? {scale: otherAxisInverse ? [1, -1] : [1, 1], rotation: Math.PI / 2}
  54273. // Dont use Math.PI, considering shadow direction.
  54274. : {scale: otherAxisInverse ? [-1, -1] : [-1, 1], rotation: Math.PI / 2}
  54275. );
  54276. // Position barGroup
  54277. var rect = thisGroup.getBoundingRect([barGroup]);
  54278. thisGroup.attr('position', [location.x - rect.x, location.y - rect.y]);
  54279. },
  54280. /**
  54281. * @private
  54282. */
  54283. _getViewExtent: function () {
  54284. return [0, this._size[0]];
  54285. },
  54286. _renderBackground: function () {
  54287. var dataZoomModel = this.dataZoomModel;
  54288. var size = this._size;
  54289. var barGroup = this._displayables.barGroup;
  54290. barGroup.add(new Rect({
  54291. silent: true,
  54292. shape: {
  54293. x: 0, y: 0, width: size[0], height: size[1]
  54294. },
  54295. style: {
  54296. fill: dataZoomModel.get('backgroundColor')
  54297. },
  54298. z2: -40
  54299. }));
  54300. // Click panel, over shadow, below handles.
  54301. barGroup.add(new Rect({
  54302. shape: {
  54303. x: 0, y: 0, width: size[0], height: size[1]
  54304. },
  54305. style: {
  54306. fill: 'transparent'
  54307. },
  54308. z2: 0,
  54309. onclick: zrUtil.bind(this._onClickPanelClick, this)
  54310. }));
  54311. },
  54312. _renderDataShadow: function () {
  54313. var info = this._dataShadowInfo = this._prepareDataShadowInfo();
  54314. if (!info) {
  54315. return;
  54316. }
  54317. var size = this._size;
  54318. var seriesModel = info.series;
  54319. var data = seriesModel.getRawData();
  54320. var otherDim = seriesModel.getShadowDim
  54321. ? seriesModel.getShadowDim() // @see candlestick
  54322. : info.otherDim;
  54323. if (otherDim == null) {
  54324. return;
  54325. }
  54326. var otherDataExtent = data.getDataExtent(otherDim);
  54327. // Nice extent.
  54328. var otherOffset = (otherDataExtent[1] - otherDataExtent[0]) * 0.3;
  54329. otherDataExtent = [
  54330. otherDataExtent[0] - otherOffset,
  54331. otherDataExtent[1] + otherOffset
  54332. ];
  54333. var otherShadowExtent = [0, size[1]];
  54334. var thisShadowExtent = [0, size[0]];
  54335. var areaPoints = [[size[0], 0], [0, 0]];
  54336. var linePoints = [];
  54337. var step = thisShadowExtent[1] / (data.count() - 1);
  54338. var thisCoord = 0;
  54339. // Optimize for large data shadow
  54340. var stride = Math.round(data.count() / size[0]);
  54341. var lastIsEmpty;
  54342. data.each([otherDim], function (value, index) {
  54343. if (stride > 0 && (index % stride)) {
  54344. thisCoord += step;
  54345. return;
  54346. }
  54347. // FIXME
  54348. // Should consider axis.min/axis.max when drawing dataShadow.
  54349. // FIXME
  54350. // 应该使用统一的空判断?还是在list里进行空判断?
  54351. var isEmpty = value == null || isNaN(value) || value === '';
  54352. // See #4235.
  54353. var otherCoord = isEmpty
  54354. ? 0 : linearMap(value, otherDataExtent, otherShadowExtent, true);
  54355. // Attempt to draw data shadow precisely when there are empty value.
  54356. if (isEmpty && !lastIsEmpty && index) {
  54357. areaPoints.push([areaPoints[areaPoints.length - 1][0], 0]);
  54358. linePoints.push([linePoints[linePoints.length - 1][0], 0]);
  54359. }
  54360. else if (!isEmpty && lastIsEmpty) {
  54361. areaPoints.push([thisCoord, 0]);
  54362. linePoints.push([thisCoord, 0]);
  54363. }
  54364. areaPoints.push([thisCoord, otherCoord]);
  54365. linePoints.push([thisCoord, otherCoord]);
  54366. thisCoord += step;
  54367. lastIsEmpty = isEmpty;
  54368. });
  54369. var dataZoomModel = this.dataZoomModel;
  54370. // var dataBackgroundModel = dataZoomModel.getModel('dataBackground');
  54371. this._displayables.barGroup.add(new graphic.Polygon({
  54372. shape: {points: areaPoints},
  54373. style: zrUtil.defaults(
  54374. {fill: dataZoomModel.get('dataBackgroundColor')},
  54375. dataZoomModel.getModel('dataBackground.areaStyle').getAreaStyle()
  54376. ),
  54377. silent: true,
  54378. z2: -20
  54379. }));
  54380. this._displayables.barGroup.add(new graphic.Polyline({
  54381. shape: {points: linePoints},
  54382. style: dataZoomModel.getModel('dataBackground.lineStyle').getLineStyle(),
  54383. silent: true,
  54384. z2: -19
  54385. }));
  54386. },
  54387. _prepareDataShadowInfo: function () {
  54388. var dataZoomModel = this.dataZoomModel;
  54389. var showDataShadow = dataZoomModel.get('showDataShadow');
  54390. if (showDataShadow === false) {
  54391. return;
  54392. }
  54393. // Find a representative series.
  54394. var result;
  54395. var ecModel = this.ecModel;
  54396. dataZoomModel.eachTargetAxis(function (dimNames, axisIndex) {
  54397. var seriesModels = dataZoomModel
  54398. .getAxisProxy(dimNames.name, axisIndex)
  54399. .getTargetSeriesModels();
  54400. zrUtil.each(seriesModels, function (seriesModel) {
  54401. if (result) {
  54402. return;
  54403. }
  54404. if (showDataShadow !== true && zrUtil.indexOf(
  54405. SHOW_DATA_SHADOW_SERIES_TYPE, seriesModel.get('type')
  54406. ) < 0
  54407. ) {
  54408. return;
  54409. }
  54410. var thisAxis = ecModel.getComponent(dimNames.axis, axisIndex).axis;
  54411. var otherDim = getOtherDim(dimNames.name);
  54412. var otherAxisInverse;
  54413. var coordSys = seriesModel.coordinateSystem;
  54414. if (otherDim != null && coordSys.getOtherAxis) {
  54415. otherAxisInverse = coordSys.getOtherAxis(thisAxis).inverse;
  54416. }
  54417. result = {
  54418. thisAxis: thisAxis,
  54419. series: seriesModel,
  54420. thisDim: dimNames.name,
  54421. otherDim: otherDim,
  54422. otherAxisInverse: otherAxisInverse
  54423. };
  54424. }, this);
  54425. }, this);
  54426. return result;
  54427. },
  54428. _renderHandle: function () {
  54429. var displaybles = this._displayables;
  54430. var handles = displaybles.handles = [];
  54431. var handleLabels = displaybles.handleLabels = [];
  54432. var barGroup = this._displayables.barGroup;
  54433. var size = this._size;
  54434. var dataZoomModel = this.dataZoomModel;
  54435. barGroup.add(displaybles.filler = new Rect({
  54436. draggable: true,
  54437. cursor: 'move',
  54438. drift: bind(this._onDragMove, this, 'all'),
  54439. onmousemove: function (e) {
  54440. // Fot mobile devicem, prevent screen slider on the button.
  54441. eventTool.stop(e.event);
  54442. },
  54443. ondragstart: bind(this._showDataInfo, this, true),
  54444. ondragend: bind(this._onDragEnd, this),
  54445. onmouseover: bind(this._showDataInfo, this, true),
  54446. onmouseout: bind(this._showDataInfo, this, false),
  54447. style: {
  54448. fill: dataZoomModel.get('fillerColor'),
  54449. textPosition : 'inside'
  54450. }
  54451. }));
  54452. // Frame border.
  54453. barGroup.add(new Rect(graphic.subPixelOptimizeRect({
  54454. silent: true,
  54455. shape: {
  54456. x: 0,
  54457. y: 0,
  54458. width: size[0],
  54459. height: size[1]
  54460. },
  54461. style: {
  54462. stroke: dataZoomModel.get('dataBackgroundColor')
  54463. || dataZoomModel.get('borderColor'),
  54464. lineWidth: DEFAULT_FRAME_BORDER_WIDTH,
  54465. fill: 'rgba(0,0,0,0)'
  54466. }
  54467. })));
  54468. var iconStr = dataZoomModel.get('handleIcon');
  54469. each([0, 1], function (handleIndex) {
  54470. var iconOpt = {
  54471. style: {
  54472. strokeNoScale: true
  54473. },
  54474. rectHover: true,
  54475. cursor: this._orient === 'vertical' ? 'ns-resize' : 'ew-resize',
  54476. draggable: true,
  54477. drift: bind(this._onDragMove, this, handleIndex),
  54478. onmousemove: function (e) {
  54479. // Fot mobile devicem, prevent screen slider on the button.
  54480. eventTool.stop(e.event);
  54481. },
  54482. ondragend: bind(this._onDragEnd, this),
  54483. onmouseover: bind(this._showDataInfo, this, true),
  54484. onmouseout: bind(this._showDataInfo, this, false)
  54485. };
  54486. var iconStyle = {x: -1, y: 0, width: 2, height: 2};
  54487. var path = iconStr.indexOf('image://') === 0
  54488. ? (
  54489. iconStyle.image = iconStr.slice(8),
  54490. iconOpt.style = iconStyle,
  54491. new graphic.Image(iconOpt)
  54492. )
  54493. : graphic.makePath(
  54494. iconStr.replace('path://', ''),
  54495. iconOpt,
  54496. iconStyle,
  54497. 'center'
  54498. );
  54499. var bRect = path.getBoundingRect();
  54500. this._handleHeight = numberUtil.parsePercent(dataZoomModel.get('handleSize'), this._size[1]);
  54501. this._handleWidth = bRect.width / bRect.height * this._handleHeight;
  54502. path.setStyle(dataZoomModel.getModel('handleStyle').getItemStyle());
  54503. var handleColor = dataZoomModel.get('handleColor');
  54504. // Compatitable with previous version
  54505. if (handleColor != null) {
  54506. path.style.fill = handleColor;
  54507. }
  54508. barGroup.add(handles[handleIndex] = path);
  54509. var textStyleModel = dataZoomModel.textStyleModel;
  54510. this.group.add(
  54511. handleLabels[handleIndex] = new graphic.Text({
  54512. silent: true,
  54513. invisible: true,
  54514. style: {
  54515. x: 0, y: 0, text: '',
  54516. textVerticalAlign: 'middle',
  54517. textAlign: 'center',
  54518. fill: textStyleModel.getTextColor(),
  54519. textFont: textStyleModel.getFont()
  54520. },
  54521. z2: 10
  54522. }));
  54523. }, this);
  54524. },
  54525. /**
  54526. * @private
  54527. */
  54528. _resetInterval: function () {
  54529. var range = this._range = this.dataZoomModel.getPercentRange();
  54530. var viewExtent = this._getViewExtent();
  54531. this._handleEnds = [
  54532. linearMap(range[0], [0, 100], viewExtent, true),
  54533. linearMap(range[1], [0, 100], viewExtent, true)
  54534. ];
  54535. },
  54536. /**
  54537. * @private
  54538. * @param {(number|string)} handleIndex 0 or 1 or 'all'
  54539. * @param {number} delta
  54540. */
  54541. _updateInterval: function (handleIndex, delta) {
  54542. var dataZoomModel = this.dataZoomModel;
  54543. var handleEnds = this._handleEnds;
  54544. var viewExtend = this._getViewExtent();
  54545. var minMaxSpan = dataZoomModel.findRepresentativeAxisProxy().getMinMaxSpan();
  54546. var percentExtent = [0, 100];
  54547. sliderMove(
  54548. delta,
  54549. handleEnds,
  54550. viewExtend,
  54551. dataZoomModel.get('zoomLock') ? 'all' : handleIndex,
  54552. minMaxSpan.minSpan != null
  54553. ? linearMap(minMaxSpan.minSpan, percentExtent, viewExtend, true) : null,
  54554. minMaxSpan.maxSpan != null
  54555. ? linearMap(minMaxSpan.maxSpan, percentExtent, viewExtend, true) : null
  54556. );
  54557. this._range = asc([
  54558. linearMap(handleEnds[0], viewExtend, percentExtent, true),
  54559. linearMap(handleEnds[1], viewExtend, percentExtent, true)
  54560. ]);
  54561. },
  54562. /**
  54563. * @private
  54564. */
  54565. _updateView: function (nonRealtime) {
  54566. var displaybles = this._displayables;
  54567. var handleEnds = this._handleEnds;
  54568. var handleInterval = asc(handleEnds.slice());
  54569. var size = this._size;
  54570. each([0, 1], function (handleIndex) {
  54571. // Handles
  54572. var handle = displaybles.handles[handleIndex];
  54573. var handleHeight = this._handleHeight;
  54574. handle.attr({
  54575. scale: [handleHeight / 2, handleHeight / 2],
  54576. position: [handleEnds[handleIndex], size[1] / 2 - handleHeight / 2]
  54577. });
  54578. }, this);
  54579. // Filler
  54580. displaybles.filler.setShape({
  54581. x: handleInterval[0],
  54582. y: 0,
  54583. width: handleInterval[1] - handleInterval[0],
  54584. height: size[1]
  54585. });
  54586. this._updateDataInfo(nonRealtime);
  54587. },
  54588. /**
  54589. * @private
  54590. */
  54591. _updateDataInfo: function (nonRealtime) {
  54592. var dataZoomModel = this.dataZoomModel;
  54593. var displaybles = this._displayables;
  54594. var handleLabels = displaybles.handleLabels;
  54595. var orient = this._orient;
  54596. var labelTexts = ['', ''];
  54597. // FIXME
  54598. // date型,支持formatter,autoformatter(ec2 date.getAutoFormatter)
  54599. if (dataZoomModel.get('showDetail')) {
  54600. var axisProxy = dataZoomModel.findRepresentativeAxisProxy();
  54601. if (axisProxy) {
  54602. var axis = axisProxy.getAxisModel().axis;
  54603. var range = this._range;
  54604. var dataInterval = nonRealtime
  54605. // See #4434, data and axis are not processed and reset yet in non-realtime mode.
  54606. ? axisProxy.calculateDataWindow({
  54607. start: range[0], end: range[1]
  54608. }).valueWindow
  54609. : axisProxy.getDataValueWindow();
  54610. labelTexts = [
  54611. this._formatLabel(dataInterval[0], axis),
  54612. this._formatLabel(dataInterval[1], axis)
  54613. ];
  54614. }
  54615. }
  54616. var orderedHandleEnds = asc(this._handleEnds.slice());
  54617. setLabel.call(this, 0);
  54618. setLabel.call(this, 1);
  54619. function setLabel(handleIndex) {
  54620. // Label
  54621. // Text should not transform by barGroup.
  54622. // Ignore handlers transform
  54623. var barTransform = graphic.getTransform(
  54624. displaybles.handles[handleIndex].parent, this.group
  54625. );
  54626. var direction = graphic.transformDirection(
  54627. handleIndex === 0 ? 'right' : 'left', barTransform
  54628. );
  54629. var offset = this._handleWidth / 2 + LABEL_GAP;
  54630. var textPoint = graphic.applyTransform(
  54631. [
  54632. orderedHandleEnds[handleIndex] + (handleIndex === 0 ? -offset : offset),
  54633. this._size[1] / 2
  54634. ],
  54635. barTransform
  54636. );
  54637. handleLabels[handleIndex].setStyle({
  54638. x: textPoint[0],
  54639. y: textPoint[1],
  54640. textVerticalAlign: orient === HORIZONTAL ? 'middle' : direction,
  54641. textAlign: orient === HORIZONTAL ? direction : 'center',
  54642. text: labelTexts[handleIndex]
  54643. });
  54644. }
  54645. },
  54646. /**
  54647. * @private
  54648. */
  54649. _formatLabel: function (value, axis) {
  54650. var dataZoomModel = this.dataZoomModel;
  54651. var labelFormatter = dataZoomModel.get('labelFormatter');
  54652. var labelPrecision = dataZoomModel.get('labelPrecision');
  54653. if (labelPrecision == null || labelPrecision === 'auto') {
  54654. labelPrecision = axis.getPixelPrecision();
  54655. }
  54656. var valueStr = (value == null || isNaN(value))
  54657. ? ''
  54658. // FIXME Glue code
  54659. : (axis.type === 'category' || axis.type === 'time')
  54660. ? axis.scale.getLabel(Math.round(value))
  54661. // param of toFixed should less then 20.
  54662. : value.toFixed(Math.min(labelPrecision, 20));
  54663. return zrUtil.isFunction(labelFormatter)
  54664. ? labelFormatter(value, valueStr)
  54665. : zrUtil.isString(labelFormatter)
  54666. ? labelFormatter.replace('{value}', valueStr)
  54667. : valueStr;
  54668. },
  54669. /**
  54670. * @private
  54671. * @param {boolean} showOrHide true: show, false: hide
  54672. */
  54673. _showDataInfo: function (showOrHide) {
  54674. // Always show when drgging.
  54675. showOrHide = this._dragging || showOrHide;
  54676. var handleLabels = this._displayables.handleLabels;
  54677. handleLabels[0].attr('invisible', !showOrHide);
  54678. handleLabels[1].attr('invisible', !showOrHide);
  54679. },
  54680. _onDragMove: function (handleIndex, dx, dy) {
  54681. this._dragging = true;
  54682. // Transform dx, dy to bar coordination.
  54683. var barTransform = this._displayables.barGroup.getLocalTransform();
  54684. var vertex = graphic.applyTransform([dx, dy], barTransform, true);
  54685. this._updateInterval(handleIndex, vertex[0]);
  54686. var realtime = this.dataZoomModel.get('realtime');
  54687. this._updateView(!realtime);
  54688. if (realtime) {
  54689. realtime && this._dispatchZoomAction();
  54690. }
  54691. },
  54692. _onDragEnd: function () {
  54693. this._dragging = false;
  54694. this._showDataInfo(false);
  54695. this._dispatchZoomAction();
  54696. },
  54697. _onClickPanelClick: function (e) {
  54698. var size = this._size;
  54699. var localPoint = this._displayables.barGroup.transformCoordToLocal(e.offsetX, e.offsetY);
  54700. if (localPoint[0] < 0 || localPoint[0] > size[0]
  54701. || localPoint[1] < 0 || localPoint[1] > size[1]
  54702. ) {
  54703. return;
  54704. }
  54705. var handleEnds = this._handleEnds;
  54706. var center = (handleEnds[0] + handleEnds[1]) / 2;
  54707. this._updateInterval('all', localPoint[0] - center);
  54708. this._updateView();
  54709. this._dispatchZoomAction();
  54710. },
  54711. /**
  54712. * This action will be throttled.
  54713. * @private
  54714. */
  54715. _dispatchZoomAction: function () {
  54716. var range = this._range;
  54717. this.api.dispatchAction({
  54718. type: 'dataZoom',
  54719. from: this.uid,
  54720. dataZoomId: this.dataZoomModel.id,
  54721. start: range[0],
  54722. end: range[1]
  54723. });
  54724. },
  54725. /**
  54726. * @private
  54727. */
  54728. _findCoordRect: function () {
  54729. // Find the grid coresponding to the first axis referred by dataZoom.
  54730. var rect;
  54731. each(this.getTargetCoordInfo(), function (coordInfoList) {
  54732. if (!rect && coordInfoList.length) {
  54733. var coordSys = coordInfoList[0].model.coordinateSystem;
  54734. rect = coordSys.getRect && coordSys.getRect();
  54735. }
  54736. });
  54737. if (!rect) {
  54738. var width = this.api.getWidth();
  54739. var height = this.api.getHeight();
  54740. rect = {
  54741. x: width * 0.2,
  54742. y: height * 0.2,
  54743. width: width * 0.6,
  54744. height: height * 0.6
  54745. };
  54746. }
  54747. return rect;
  54748. }
  54749. });
  54750. function getOtherDim(thisDim) {
  54751. // FIXME
  54752. // 这个逻辑和getOtherAxis里一致,但是写在这里是否不好
  54753. var map = {x: 'y', y: 'x', radius: 'angle', angle: 'radius'};
  54754. return map[thisDim];
  54755. }
  54756. module.exports = SliderZoomView;
  54757. /***/ },
  54758. /* 370 */
  54759. /***/ function(module, exports, __webpack_require__) {
  54760. /**
  54761. * @file Data zoom model
  54762. */
  54763. module.exports = __webpack_require__(364).extend({
  54764. type: 'dataZoom.inside',
  54765. /**
  54766. * @protected
  54767. */
  54768. defaultOption: {
  54769. disabled: false, // Whether disable this inside zoom.
  54770. zoomLock: false, // Whether disable zoom but only pan.
  54771. zoomOnMouseWheel: true, // Can be: true / false / 'shift' / 'ctrl' / 'alt'.
  54772. moveOnMouseMove: true, // Can be: true / false / 'shift' / 'ctrl' / 'alt'.
  54773. preventDefaultMouseMove: true
  54774. }
  54775. });
  54776. /***/ },
  54777. /* 371 */
  54778. /***/ function(module, exports, __webpack_require__) {
  54779. var DataZoomView = __webpack_require__(367);
  54780. var zrUtil = __webpack_require__(4);
  54781. var sliderMove = __webpack_require__(238);
  54782. var roams = __webpack_require__(372);
  54783. var bind = zrUtil.bind;
  54784. var InsideZoomView = DataZoomView.extend({
  54785. type: 'dataZoom.inside',
  54786. /**
  54787. * @override
  54788. */
  54789. init: function (ecModel, api) {
  54790. /**
  54791. * 'throttle' is used in this.dispatchAction, so we save range
  54792. * to avoid missing some 'pan' info.
  54793. * @private
  54794. * @type {Array.<number>}
  54795. */
  54796. this._range;
  54797. },
  54798. /**
  54799. * @override
  54800. */
  54801. render: function (dataZoomModel, ecModel, api, payload) {
  54802. InsideZoomView.superApply(this, 'render', arguments);
  54803. // Notice: origin this._range should be maintained, and should not be re-fetched
  54804. // from dataZoomModel when payload.type is 'dataZoom', otherwise 'pan' or 'zoom'
  54805. // info will be missed because of 'throttle' of this.dispatchAction.
  54806. if (roams.shouldRecordRange(payload, dataZoomModel.id)) {
  54807. this._range = dataZoomModel.getPercentRange();
  54808. }
  54809. // Reset controllers.
  54810. zrUtil.each(this.getTargetCoordInfo(), function (coordInfoList, coordSysName) {
  54811. var allCoordIds = zrUtil.map(coordInfoList, function (coordInfo) {
  54812. return roams.generateCoordId(coordInfo.model);
  54813. });
  54814. zrUtil.each(coordInfoList, function (coordInfo) {
  54815. var coordModel = coordInfo.model;
  54816. var dataZoomOption = dataZoomModel.option;
  54817. roams.register(
  54818. api,
  54819. {
  54820. coordId: roams.generateCoordId(coordModel),
  54821. allCoordIds: allCoordIds,
  54822. containsPoint: function (e, x, y) {
  54823. return coordModel.coordinateSystem.containPoint([x, y]);
  54824. },
  54825. dataZoomId: dataZoomModel.id,
  54826. throttleRate: dataZoomModel.get('throttle', true),
  54827. panGetRange: bind(this._onPan, this, coordInfo, coordSysName),
  54828. zoomGetRange: bind(this._onZoom, this, coordInfo, coordSysName),
  54829. zoomLock: dataZoomOption.zoomLock,
  54830. disabled: dataZoomOption.disabled,
  54831. roamControllerOpt: {
  54832. zoomOnMouseWheel: dataZoomOption.zoomOnMouseWheel,
  54833. moveOnMouseMove: dataZoomOption.moveOnMouseMove,
  54834. preventDefaultMouseMove: dataZoomOption.preventDefaultMouseMove
  54835. }
  54836. }
  54837. );
  54838. }, this);
  54839. }, this);
  54840. },
  54841. /**
  54842. * @override
  54843. */
  54844. dispose: function () {
  54845. roams.unregister(this.api, this.dataZoomModel.id);
  54846. InsideZoomView.superApply(this, 'dispose', arguments);
  54847. this._range = null;
  54848. },
  54849. /**
  54850. * @private
  54851. */
  54852. _onPan: function (coordInfo, coordSysName, controller, dx, dy, oldX, oldY, newX, newY) {
  54853. var range = this._range.slice();
  54854. // Calculate transform by the first axis.
  54855. var axisModel = coordInfo.axisModels[0];
  54856. if (!axisModel) {
  54857. return;
  54858. }
  54859. var directionInfo = getDirectionInfo[coordSysName](
  54860. [oldX, oldY], [newX, newY], axisModel, controller, coordInfo
  54861. );
  54862. var percentDelta = directionInfo.signal
  54863. * (range[1] - range[0])
  54864. * directionInfo.pixel / directionInfo.pixelLength;
  54865. sliderMove(percentDelta, range, [0, 100], 'all');
  54866. return (this._range = range);
  54867. },
  54868. /**
  54869. * @private
  54870. */
  54871. _onZoom: function (coordInfo, coordSysName, controller, scale, mouseX, mouseY) {
  54872. var range = this._range.slice();
  54873. // Calculate transform by the first axis.
  54874. var axisModel = coordInfo.axisModels[0];
  54875. if (!axisModel) {
  54876. return;
  54877. }
  54878. var directionInfo = getDirectionInfo[coordSysName](
  54879. null, [mouseX, mouseY], axisModel, controller, coordInfo
  54880. );
  54881. var percentPoint = (directionInfo.pixel - directionInfo.pixelStart) /
  54882. directionInfo.pixelLength * (range[1] - range[0]) + range[0];
  54883. scale = Math.max(1 / scale, 0);
  54884. range[0] = (range[0] - percentPoint) * scale + percentPoint;
  54885. range[1] = (range[1] - percentPoint) * scale + percentPoint;
  54886. // Restrict range.
  54887. var minMaxSpan = this.dataZoomModel.findRepresentativeAxisProxy().getMinMaxSpan();
  54888. sliderMove(0, range, [0, 100], 0, minMaxSpan.minSpan, minMaxSpan.maxSpan);
  54889. return (this._range = range);
  54890. }
  54891. });
  54892. var getDirectionInfo = {
  54893. grid: function (oldPoint, newPoint, axisModel, controller, coordInfo) {
  54894. var axis = axisModel.axis;
  54895. var ret = {};
  54896. var rect = coordInfo.model.coordinateSystem.getRect();
  54897. oldPoint = oldPoint || [0, 0];
  54898. if (axis.dim === 'x') {
  54899. ret.pixel = newPoint[0] - oldPoint[0];
  54900. ret.pixelLength = rect.width;
  54901. ret.pixelStart = rect.x;
  54902. ret.signal = axis.inverse ? 1 : -1;
  54903. }
  54904. else { // axis.dim === 'y'
  54905. ret.pixel = newPoint[1] - oldPoint[1];
  54906. ret.pixelLength = rect.height;
  54907. ret.pixelStart = rect.y;
  54908. ret.signal = axis.inverse ? -1 : 1;
  54909. }
  54910. return ret;
  54911. },
  54912. polar: function (oldPoint, newPoint, axisModel, controller, coordInfo) {
  54913. var axis = axisModel.axis;
  54914. var ret = {};
  54915. var polar = coordInfo.model.coordinateSystem;
  54916. var radiusExtent = polar.getRadiusAxis().getExtent();
  54917. var angleExtent = polar.getAngleAxis().getExtent();
  54918. oldPoint = oldPoint ? polar.pointToCoord(oldPoint) : [0, 0];
  54919. newPoint = polar.pointToCoord(newPoint);
  54920. if (axisModel.mainType === 'radiusAxis') {
  54921. ret.pixel = newPoint[0] - oldPoint[0];
  54922. // ret.pixelLength = Math.abs(radiusExtent[1] - radiusExtent[0]);
  54923. // ret.pixelStart = Math.min(radiusExtent[0], radiusExtent[1]);
  54924. ret.pixelLength = radiusExtent[1] - radiusExtent[0];
  54925. ret.pixelStart = radiusExtent[0];
  54926. ret.signal = axis.inverse ? 1 : -1;
  54927. }
  54928. else { // 'angleAxis'
  54929. ret.pixel = newPoint[1] - oldPoint[1];
  54930. // ret.pixelLength = Math.abs(angleExtent[1] - angleExtent[0]);
  54931. // ret.pixelStart = Math.min(angleExtent[0], angleExtent[1]);
  54932. ret.pixelLength = angleExtent[1] - angleExtent[0];
  54933. ret.pixelStart = angleExtent[0];
  54934. ret.signal = axis.inverse ? -1 : 1;
  54935. }
  54936. return ret;
  54937. },
  54938. singleAxis: function (oldPoint, newPoint, axisModel, controller, coordInfo) {
  54939. var axis = axisModel.axis;
  54940. var rect = coordInfo.model.coordinateSystem.getRect();
  54941. var ret = {};
  54942. oldPoint = oldPoint || [0, 0];
  54943. if (axis.orient === 'horizontal') {
  54944. ret.pixel = newPoint[0] - oldPoint[0];
  54945. ret.pixelLength = rect.width;
  54946. ret.pixelStart = rect.x;
  54947. ret.signal = axis.inverse ? 1 : -1;
  54948. }
  54949. else { // 'vertical'
  54950. ret.pixel = newPoint[1] - oldPoint[1];
  54951. ret.pixelLength = rect.height;
  54952. ret.pixelStart = rect.y;
  54953. ret.signal = axis.inverse ? -1 : 1;
  54954. }
  54955. return ret;
  54956. }
  54957. };
  54958. module.exports = InsideZoomView;
  54959. /***/ },
  54960. /* 372 */
  54961. /***/ function(module, exports, __webpack_require__) {
  54962. /**
  54963. * @file Roam controller manager.
  54964. */
  54965. // Only create one roam controller for each coordinate system.
  54966. // one roam controller might be refered by two inside data zoom
  54967. // components (for example, one for x and one for y). When user
  54968. // pan or zoom, only dispatch one action for those data zoom
  54969. // components.
  54970. var zrUtil = __webpack_require__(4);
  54971. var RoamController = __webpack_require__(182);
  54972. var throttle = __webpack_require__(81);
  54973. var curry = zrUtil.curry;
  54974. var ATTR = '\0_ec_dataZoom_roams';
  54975. var roams = {
  54976. /**
  54977. * @public
  54978. * @param {module:echarts/ExtensionAPI} api
  54979. * @param {Object} dataZoomInfo
  54980. * @param {string} dataZoomInfo.coordId
  54981. * @param {Function} dataZoomInfo.containsPoint
  54982. * @param {Array.<string>} dataZoomInfo.allCoordIds
  54983. * @param {string} dataZoomInfo.dataZoomId
  54984. * @param {number} dataZoomInfo.throttleRate
  54985. * @param {Function} dataZoomInfo.panGetRange
  54986. * @param {Function} dataZoomInfo.zoomGetRange
  54987. * @param {boolean} [dataZoomInfo.zoomLock]
  54988. * @param {boolean} [dataZoomInfo.disabled]
  54989. */
  54990. register: function (api, dataZoomInfo) {
  54991. var store = giveStore(api);
  54992. var theDataZoomId = dataZoomInfo.dataZoomId;
  54993. var theCoordId = dataZoomInfo.coordId;
  54994. // Do clean when a dataZoom changes its target coordnate system.
  54995. // Avoid memory leak, dispose all not-used-registered.
  54996. zrUtil.each(store, function (record, coordId) {
  54997. var dataZoomInfos = record.dataZoomInfos;
  54998. if (dataZoomInfos[theDataZoomId]
  54999. && zrUtil.indexOf(dataZoomInfo.allCoordIds, theCoordId) < 0
  55000. ) {
  55001. delete dataZoomInfos[theDataZoomId];
  55002. record.count--;
  55003. }
  55004. });
  55005. cleanStore(store);
  55006. var record = store[theCoordId];
  55007. // Create if needed.
  55008. if (!record) {
  55009. record = store[theCoordId] = {
  55010. coordId: theCoordId,
  55011. dataZoomInfos: {},
  55012. count: 0
  55013. };
  55014. record.controller = createController(api, record);
  55015. record.dispatchAction = zrUtil.curry(dispatchAction, api);
  55016. }
  55017. record.controller.enable(
  55018. dataZoomInfo.disabled ? false : dataZoomInfo.zoomLock ? 'move' : true,
  55019. dataZoomInfo.roamControllerOpt
  55020. );
  55021. // Consider resize, area should be always updated.
  55022. record.controller.setPointerChecker(dataZoomInfo.containsPoint);
  55023. // Update throttle.
  55024. throttle.createOrUpdate(
  55025. record,
  55026. 'dispatchAction',
  55027. dataZoomInfo.throttleRate,
  55028. 'fixRate'
  55029. );
  55030. // Update reference of dataZoom.
  55031. !(record.dataZoomInfos[theDataZoomId]) && record.count++;
  55032. record.dataZoomInfos[theDataZoomId] = dataZoomInfo;
  55033. },
  55034. /**
  55035. * @public
  55036. * @param {module:echarts/ExtensionAPI} api
  55037. * @param {string} dataZoomId
  55038. */
  55039. unregister: function (api, dataZoomId) {
  55040. var store = giveStore(api);
  55041. zrUtil.each(store, function (record) {
  55042. record.controller.dispose();
  55043. var dataZoomInfos = record.dataZoomInfos;
  55044. if (dataZoomInfos[dataZoomId]) {
  55045. delete dataZoomInfos[dataZoomId];
  55046. record.count--;
  55047. }
  55048. });
  55049. cleanStore(store);
  55050. },
  55051. /**
  55052. * @public
  55053. */
  55054. shouldRecordRange: function (payload, dataZoomId) {
  55055. if (payload && payload.type === 'dataZoom' && payload.batch) {
  55056. for (var i = 0, len = payload.batch.length; i < len; i++) {
  55057. if (payload.batch[i].dataZoomId === dataZoomId) {
  55058. return false;
  55059. }
  55060. }
  55061. }
  55062. return true;
  55063. },
  55064. /**
  55065. * @public
  55066. */
  55067. generateCoordId: function (coordModel) {
  55068. return coordModel.type + '\0_' + coordModel.id;
  55069. }
  55070. };
  55071. /**
  55072. * Key: coordId, value: {dataZoomInfos: [], count, controller}
  55073. * @type {Array.<Object>}
  55074. */
  55075. function giveStore(api) {
  55076. // Mount store on zrender instance, so that we do not
  55077. // need to worry about dispose.
  55078. var zr = api.getZr();
  55079. return zr[ATTR] || (zr[ATTR] = {});
  55080. }
  55081. function createController(api, newRecord) {
  55082. var controller = new RoamController(api.getZr());
  55083. controller.on('pan', curry(onPan, newRecord));
  55084. controller.on('zoom', curry(onZoom, newRecord));
  55085. return controller;
  55086. }
  55087. function cleanStore(store) {
  55088. zrUtil.each(store, function (record, coordId) {
  55089. if (!record.count) {
  55090. record.controller.dispose();
  55091. delete store[coordId];
  55092. }
  55093. });
  55094. }
  55095. function onPan(record, dx, dy, oldX, oldY, newX, newY) {
  55096. wrapAndDispatch(record, function (info) {
  55097. return info.panGetRange(record.controller, dx, dy, oldX, oldY, newX, newY);
  55098. });
  55099. }
  55100. function onZoom(record, scale, mouseX, mouseY) {
  55101. wrapAndDispatch(record, function (info) {
  55102. return info.zoomGetRange(record.controller, scale, mouseX, mouseY);
  55103. });
  55104. }
  55105. function wrapAndDispatch(record, getRange) {
  55106. var batch = [];
  55107. zrUtil.each(record.dataZoomInfos, function (info) {
  55108. var range = getRange(info);
  55109. range && batch.push({
  55110. dataZoomId: info.dataZoomId,
  55111. start: range[0],
  55112. end: range[1]
  55113. });
  55114. });
  55115. record.dispatchAction(batch);
  55116. }
  55117. /**
  55118. * This action will be throttled.
  55119. */
  55120. function dispatchAction(api, batch) {
  55121. api.dispatchAction({
  55122. type: 'dataZoom',
  55123. batch: batch
  55124. });
  55125. }
  55126. module.exports = roams;
  55127. /***/ },
  55128. /* 373 */
  55129. /***/ function(module, exports, __webpack_require__) {
  55130. /**
  55131. * @file Data zoom processor
  55132. */
  55133. var echarts = __webpack_require__(1);
  55134. echarts.registerProcessor(function (ecModel, api) {
  55135. ecModel.eachComponent('dataZoom', function (dataZoomModel) {
  55136. // We calculate window and reset axis here but not in model
  55137. // init stage and not after action dispatch handler, because
  55138. // reset should be called after seriesData.restoreData.
  55139. dataZoomModel.eachTargetAxis(resetSingleAxis);
  55140. // Caution: data zoom filtering is order sensitive when using
  55141. // percent range and no min/max/scale set on axis.
  55142. // For example, we have dataZoom definition:
  55143. // [
  55144. // {xAxisIndex: 0, start: 30, end: 70},
  55145. // {yAxisIndex: 0, start: 20, end: 80}
  55146. // ]
  55147. // In this case, [20, 80] of y-dataZoom should be based on data
  55148. // that have filtered by x-dataZoom using range of [30, 70],
  55149. // but should not be based on full raw data. Thus sliding
  55150. // x-dataZoom will change both ranges of xAxis and yAxis,
  55151. // while sliding y-dataZoom will only change the range of yAxis.
  55152. // So we should filter x-axis after reset x-axis immediately,
  55153. // and then reset y-axis and filter y-axis.
  55154. dataZoomModel.eachTargetAxis(filterSingleAxis);
  55155. });
  55156. ecModel.eachComponent('dataZoom', function (dataZoomModel) {
  55157. // Fullfill all of the range props so that user
  55158. // is able to get them from chart.getOption().
  55159. var axisProxy = dataZoomModel.findRepresentativeAxisProxy();
  55160. var percentRange = axisProxy.getDataPercentWindow();
  55161. var valueRange = axisProxy.getDataValueWindow();
  55162. dataZoomModel.setRawRange({
  55163. start: percentRange[0],
  55164. end: percentRange[1],
  55165. startValue: valueRange[0],
  55166. endValue: valueRange[1]
  55167. }, true);
  55168. });
  55169. });
  55170. function resetSingleAxis(dimNames, axisIndex, dataZoomModel) {
  55171. dataZoomModel.getAxisProxy(dimNames.name, axisIndex).reset(dataZoomModel);
  55172. }
  55173. function filterSingleAxis(dimNames, axisIndex, dataZoomModel) {
  55174. dataZoomModel.getAxisProxy(dimNames.name, axisIndex).filterData(dataZoomModel);
  55175. }
  55176. /***/ },
  55177. /* 374 */
  55178. /***/ function(module, exports, __webpack_require__) {
  55179. /**
  55180. * @file Data zoom action
  55181. */
  55182. var zrUtil = __webpack_require__(4);
  55183. var helper = __webpack_require__(365);
  55184. var echarts = __webpack_require__(1);
  55185. echarts.registerAction('dataZoom', function (payload, ecModel) {
  55186. var linkedNodesFinder = helper.createLinkedNodesFinder(
  55187. zrUtil.bind(ecModel.eachComponent, ecModel, 'dataZoom'),
  55188. helper.eachAxisDim,
  55189. function (model, dimNames) {
  55190. return model.get(dimNames.axisIndex);
  55191. }
  55192. );
  55193. var effectedModels = [];
  55194. ecModel.eachComponent(
  55195. {mainType: 'dataZoom', query: payload},
  55196. function (model, index) {
  55197. effectedModels.push.apply(
  55198. effectedModels, linkedNodesFinder(model).nodes
  55199. );
  55200. }
  55201. );
  55202. zrUtil.each(effectedModels, function (dataZoomModel, index) {
  55203. dataZoomModel.setRawRange({
  55204. start: payload.start,
  55205. end: payload.end,
  55206. startValue: payload.startValue,
  55207. endValue: payload.endValue
  55208. });
  55209. });
  55210. });
  55211. /***/ },
  55212. /* 375 */
  55213. /***/ function(module, exports, __webpack_require__) {
  55214. /**
  55215. * visualMap component entry
  55216. */
  55217. __webpack_require__(376);
  55218. __webpack_require__(387);
  55219. /***/ },
  55220. /* 376 */
  55221. /***/ function(module, exports, __webpack_require__) {
  55222. /**
  55223. * DataZoom component entry
  55224. */
  55225. __webpack_require__(1).registerPreprocessor(
  55226. __webpack_require__(377)
  55227. );
  55228. __webpack_require__(378);
  55229. __webpack_require__(379);
  55230. __webpack_require__(380);
  55231. __webpack_require__(383);
  55232. __webpack_require__(386);
  55233. /***/ },
  55234. /* 377 */
  55235. /***/ function(module, exports, __webpack_require__) {
  55236. /**
  55237. * @file VisualMap preprocessor
  55238. */
  55239. var zrUtil = __webpack_require__(4);
  55240. var each = zrUtil.each;
  55241. module.exports = function (option) {
  55242. var visualMap = option && option.visualMap;
  55243. if (!zrUtil.isArray(visualMap)) {
  55244. visualMap = visualMap ? [visualMap] : [];
  55245. }
  55246. each(visualMap, function (opt) {
  55247. if (!opt) {
  55248. return;
  55249. }
  55250. // rename splitList to pieces
  55251. if (has(opt, 'splitList') && !has(opt, 'pieces')) {
  55252. opt.pieces = opt.splitList;
  55253. delete opt.splitList;
  55254. }
  55255. var pieces = opt.pieces;
  55256. if (pieces && zrUtil.isArray(pieces)) {
  55257. each(pieces, function (piece) {
  55258. if (zrUtil.isObject(piece)) {
  55259. if (has(piece, 'start') && !has(piece, 'min')) {
  55260. piece.min = piece.start;
  55261. }
  55262. if (has(piece, 'end') && !has(piece, 'max')) {
  55263. piece.max = piece.end;
  55264. }
  55265. }
  55266. });
  55267. }
  55268. });
  55269. };
  55270. function has(obj, name) {
  55271. return obj && obj.hasOwnProperty && obj.hasOwnProperty(name);
  55272. }
  55273. /***/ },
  55274. /* 378 */
  55275. /***/ function(module, exports, __webpack_require__) {
  55276. __webpack_require__(69).registerSubTypeDefaulter('visualMap', function (option) {
  55277. // Compatible with ec2, when splitNumber === 0, continuous visualMap will be used.
  55278. return (
  55279. !option.categories
  55280. && (
  55281. !(
  55282. option.pieces
  55283. ? option.pieces.length > 0
  55284. : option.splitNumber > 0
  55285. )
  55286. || option.calculable
  55287. )
  55288. )
  55289. ? 'continuous' : 'piecewise';
  55290. });
  55291. /***/ },
  55292. /* 379 */
  55293. /***/ function(module, exports, __webpack_require__) {
  55294. /**
  55295. * @file Data range visual coding.
  55296. */
  55297. var echarts = __webpack_require__(1);
  55298. var visualSolution = __webpack_require__(349);
  55299. var VisualMapping = __webpack_require__(202);
  55300. var zrUtil = __webpack_require__(4);
  55301. echarts.registerVisual(echarts.PRIORITY.VISUAL.COMPONENT, function (ecModel) {
  55302. ecModel.eachComponent('visualMap', function (visualMapModel) {
  55303. processSingleVisualMap(visualMapModel, ecModel);
  55304. });
  55305. prepareVisualMeta(ecModel);
  55306. });
  55307. function processSingleVisualMap(visualMapModel, ecModel) {
  55308. visualMapModel.eachTargetSeries(function (seriesModel) {
  55309. var data = seriesModel.getData();
  55310. visualSolution.applyVisual(
  55311. visualMapModel.stateList,
  55312. visualMapModel.targetVisuals,
  55313. data,
  55314. visualMapModel.getValueState,
  55315. visualMapModel,
  55316. visualMapModel.getDataDimension(data)
  55317. );
  55318. });
  55319. }
  55320. // Only support color.
  55321. function prepareVisualMeta(ecModel) {
  55322. ecModel.eachSeries(function (seriesModel) {
  55323. var data = seriesModel.getData();
  55324. var visualMetaList = [];
  55325. ecModel.eachComponent('visualMap', function (visualMapModel) {
  55326. if (visualMapModel.isTargetSeries(seriesModel)) {
  55327. var visualMeta = visualMapModel.getVisualMeta(
  55328. zrUtil.bind(getColorVisual, null, seriesModel, visualMapModel)
  55329. ) || {stops: [], outerColors: []};
  55330. visualMeta.dimension = visualMapModel.getDataDimension(data);
  55331. visualMetaList.push(visualMeta);
  55332. }
  55333. });
  55334. // console.log(JSON.stringify(visualMetaList.map(a => a.stops)));
  55335. seriesModel.getData().setVisual('visualMeta', visualMetaList);
  55336. });
  55337. }
  55338. // FIXME
  55339. // performance and export for heatmap?
  55340. // value can be Infinity or -Infinity
  55341. function getColorVisual(seriesModel, visualMapModel, value, valueState) {
  55342. var mappings = visualMapModel.targetVisuals[valueState];
  55343. var visualTypes = VisualMapping.prepareVisualTypes(mappings);
  55344. var resultVisual = {
  55345. color: seriesModel.getData().getVisual('color') // default color.
  55346. };
  55347. for (var i = 0, len = visualTypes.length; i < len; i++) {
  55348. var type = visualTypes[i];
  55349. var mapping = mappings[
  55350. type === 'opacity' ? '__alphaForOpacity' : type
  55351. ];
  55352. mapping && mapping.applyVisual(value, getVisual, setVisual);
  55353. }
  55354. return resultVisual.color;
  55355. function getVisual(key) {
  55356. return resultVisual[key];
  55357. }
  55358. function setVisual(key, value) {
  55359. resultVisual[key] = value;
  55360. }
  55361. }
  55362. /***/ },
  55363. /* 380 */
  55364. /***/ function(module, exports, __webpack_require__) {
  55365. /**
  55366. * @file Data zoom model
  55367. */
  55368. var VisualMapModel = __webpack_require__(381);
  55369. var zrUtil = __webpack_require__(4);
  55370. var numberUtil = __webpack_require__(7);
  55371. // Constant
  55372. var DEFAULT_BAR_BOUND = [20, 140];
  55373. var ContinuousModel = VisualMapModel.extend({
  55374. type: 'visualMap.continuous',
  55375. /**
  55376. * @protected
  55377. */
  55378. defaultOption: {
  55379. align: 'auto', // 'auto', 'left', 'right', 'top', 'bottom'
  55380. calculable: false, // This prop effect default component type determine,
  55381. // See echarts/component/visualMap/typeDefaulter.
  55382. range: null, // selected range. In default case `range` is [min, max]
  55383. // and can auto change along with modification of min max,
  55384. // util use specifid a range.
  55385. realtime: true, // Whether realtime update.
  55386. itemHeight: null, // The length of the range control edge.
  55387. itemWidth: null, // The length of the other side.
  55388. hoverLink: true, // Enable hover highlight.
  55389. hoverLinkDataSize: null,// The size of hovered data.
  55390. hoverLinkOnHandle: true // Whether trigger hoverLink when hover handle.
  55391. },
  55392. /**
  55393. * @override
  55394. */
  55395. optionUpdated: function (newOption, isInit) {
  55396. ContinuousModel.superApply(this, 'optionUpdated', arguments);
  55397. this.resetTargetSeries();
  55398. this.resetExtent();
  55399. this.resetVisual(function (mappingOption) {
  55400. mappingOption.mappingMethod = 'linear';
  55401. mappingOption.dataExtent = this.getExtent();
  55402. });
  55403. this._resetRange();
  55404. },
  55405. /**
  55406. * @protected
  55407. * @override
  55408. */
  55409. resetItemSize: function () {
  55410. ContinuousModel.superApply(this, 'resetItemSize', arguments);
  55411. var itemSize = this.itemSize;
  55412. this._orient === 'horizontal' && itemSize.reverse();
  55413. (itemSize[0] == null || isNaN(itemSize[0])) && (itemSize[0] = DEFAULT_BAR_BOUND[0]);
  55414. (itemSize[1] == null || isNaN(itemSize[1])) && (itemSize[1] = DEFAULT_BAR_BOUND[1]);
  55415. },
  55416. /**
  55417. * @private
  55418. */
  55419. _resetRange: function () {
  55420. var dataExtent = this.getExtent();
  55421. var range = this.option.range;
  55422. if (!range || range.auto) {
  55423. // `range` should always be array (so we dont use other
  55424. // value like 'auto') for user-friend. (consider getOption).
  55425. dataExtent.auto = 1;
  55426. this.option.range = dataExtent;
  55427. }
  55428. else if (zrUtil.isArray(range)) {
  55429. if (range[0] > range[1]) {
  55430. range.reverse();
  55431. }
  55432. range[0] = Math.max(range[0], dataExtent[0]);
  55433. range[1] = Math.min(range[1], dataExtent[1]);
  55434. }
  55435. },
  55436. /**
  55437. * @protected
  55438. * @override
  55439. */
  55440. completeVisualOption: function () {
  55441. VisualMapModel.prototype.completeVisualOption.apply(this, arguments);
  55442. zrUtil.each(this.stateList, function (state) {
  55443. var symbolSize = this.option.controller[state].symbolSize;
  55444. if (symbolSize && symbolSize[0] !== symbolSize[1]) {
  55445. symbolSize[0] = 0; // For good looking.
  55446. }
  55447. }, this);
  55448. },
  55449. /**
  55450. * @override
  55451. */
  55452. setSelected: function (selected) {
  55453. this.option.range = selected.slice();
  55454. this._resetRange();
  55455. },
  55456. /**
  55457. * @public
  55458. */
  55459. getSelected: function () {
  55460. var dataExtent = this.getExtent();
  55461. var dataInterval = numberUtil.asc(
  55462. (this.get('range') || []).slice()
  55463. );
  55464. // Clamp
  55465. dataInterval[0] > dataExtent[1] && (dataInterval[0] = dataExtent[1]);
  55466. dataInterval[1] > dataExtent[1] && (dataInterval[1] = dataExtent[1]);
  55467. dataInterval[0] < dataExtent[0] && (dataInterval[0] = dataExtent[0]);
  55468. dataInterval[1] < dataExtent[0] && (dataInterval[1] = dataExtent[0]);
  55469. return dataInterval;
  55470. },
  55471. /**
  55472. * @override
  55473. */
  55474. getValueState: function (value) {
  55475. var range = this.option.range;
  55476. var dataExtent = this.getExtent();
  55477. // When range[0] === dataExtent[0], any value larger than dataExtent[0] maps to 'inRange'.
  55478. // range[1] is processed likewise.
  55479. return (
  55480. (range[0] <= dataExtent[0] || range[0] <= value)
  55481. && (range[1] >= dataExtent[1] || value <= range[1])
  55482. ) ? 'inRange' : 'outOfRange';
  55483. },
  55484. /**
  55485. * @params {Array.<number>} range target value: range[0] <= value && value <= range[1]
  55486. * @return {Array.<Object>} [{seriesId, dataIndices: <Array.<number>>}, ...]
  55487. */
  55488. findTargetDataIndices: function (range) {
  55489. var result = [];
  55490. this.eachTargetSeries(function (seriesModel) {
  55491. var dataIndices = [];
  55492. var data = seriesModel.getData();
  55493. data.each(this.getDataDimension(data), function (value, dataIndex) {
  55494. range[0] <= value && value <= range[1] && dataIndices.push(dataIndex);
  55495. }, true, this);
  55496. result.push({seriesId: seriesModel.id, dataIndex: dataIndices});
  55497. }, this);
  55498. return result;
  55499. },
  55500. /**
  55501. * @implement
  55502. */
  55503. getVisualMeta: function (getColorVisual) {
  55504. var oVals = getColorStopValues(this, 'outOfRange', this.getExtent());
  55505. var iVals = getColorStopValues(this, 'inRange', this.option.range.slice());
  55506. var stops = [];
  55507. function setStop(value, valueState) {
  55508. stops.push({
  55509. value: value,
  55510. color: getColorVisual(value, valueState)
  55511. });
  55512. }
  55513. // Format to: outOfRange -- inRange -- outOfRange.
  55514. var iIdx = 0;
  55515. var oIdx = 0;
  55516. var iLen = iVals.length;
  55517. var oLen = oVals.length;
  55518. for (; oIdx < oLen && (!iVals.length || oVals[oIdx] <= iVals[0]); oIdx++) {
  55519. // If oVal[oIdx] === iVals[iIdx], oVal[oIdx] should be ignored.
  55520. if (oVals[oIdx] < iVals[iIdx]) {
  55521. setStop(oVals[oIdx], 'outOfRange');
  55522. }
  55523. }
  55524. for (var first = 1; iIdx < iLen; iIdx++, first = 0) {
  55525. // If range is full, value beyond min, max will be clamped.
  55526. // make a singularity
  55527. first && stops.length && setStop(iVals[iIdx], 'outOfRange');
  55528. setStop(iVals[iIdx], 'inRange');
  55529. }
  55530. for (var first = 1; oIdx < oLen; oIdx++) {
  55531. if (!iVals.length || iVals[iVals.length - 1] < oVals[oIdx]) {
  55532. // make a singularity
  55533. if (first) {
  55534. stops.length && setStop(stops[stops.length - 1].value, 'outOfRange');
  55535. first = 0;
  55536. }
  55537. setStop(oVals[oIdx], 'outOfRange');
  55538. }
  55539. }
  55540. var stopsLen = stops.length;
  55541. return {
  55542. stops: stops,
  55543. outerColors: [
  55544. stopsLen ? stops[0].color : 'transparent',
  55545. stopsLen ? stops[stopsLen - 1].color : 'transparent'
  55546. ]
  55547. };
  55548. }
  55549. });
  55550. function getColorStopValues(visualMapModel, valueState, dataExtent) {
  55551. if (dataExtent[0] === dataExtent[1]) {
  55552. return dataExtent.slice();
  55553. }
  55554. // When using colorHue mapping, it is not linear color any more.
  55555. // Moreover, canvas gradient seems not to be accurate linear.
  55556. // FIXME
  55557. // Should be arbitrary value 100? or based on pixel size?
  55558. var count = 200;
  55559. var step = (dataExtent[1] - dataExtent[0]) / count;
  55560. var value = dataExtent[0];
  55561. var stopValues = [];
  55562. for (var i = 0; i <= count && value < dataExtent[1]; i++) {
  55563. stopValues.push(value);
  55564. value += step;
  55565. }
  55566. stopValues.push(dataExtent[1]);
  55567. return stopValues;
  55568. }
  55569. module.exports = ContinuousModel;
  55570. /***/ },
  55571. /* 381 */
  55572. /***/ function(module, exports, __webpack_require__) {
  55573. /**
  55574. * @file Controller visual map model
  55575. */
  55576. var echarts = __webpack_require__(1);
  55577. var zrUtil = __webpack_require__(4);
  55578. var env = __webpack_require__(2);
  55579. var visualDefault = __webpack_require__(382);
  55580. var VisualMapping = __webpack_require__(202);
  55581. var visualSolution = __webpack_require__(349);
  55582. var mapVisual = VisualMapping.mapVisual;
  55583. var modelUtil = __webpack_require__(5);
  55584. var eachVisual = VisualMapping.eachVisual;
  55585. var numberUtil = __webpack_require__(7);
  55586. var isArray = zrUtil.isArray;
  55587. var each = zrUtil.each;
  55588. var asc = numberUtil.asc;
  55589. var linearMap = numberUtil.linearMap;
  55590. var noop = zrUtil.noop;
  55591. var DEFAULT_COLOR = ['#f6efa6', '#d88273', '#bf444c'];
  55592. var VisualMapModel = echarts.extendComponentModel({
  55593. type: 'visualMap',
  55594. dependencies: ['series'],
  55595. /**
  55596. * @readOnly
  55597. * @type {Array.<string>}
  55598. */
  55599. stateList: ['inRange', 'outOfRange'],
  55600. /**
  55601. * @readOnly
  55602. * @type {Array.<string>}
  55603. */
  55604. replacableOptionKeys: [
  55605. 'inRange', 'outOfRange', 'target', 'controller', 'color'
  55606. ],
  55607. /**
  55608. * [lowerBound, upperBound]
  55609. *
  55610. * @readOnly
  55611. * @type {Array.<number>}
  55612. */
  55613. dataBound: [-Infinity, Infinity],
  55614. /**
  55615. * @readOnly
  55616. * @type {string|Object}
  55617. */
  55618. layoutMode: {type: 'box', ignoreSize: true},
  55619. /**
  55620. * @protected
  55621. */
  55622. defaultOption: {
  55623. show: true,
  55624. zlevel: 0,
  55625. z: 4,
  55626. seriesIndex: null, // 所控制的series indices,默认所有有value的series.
  55627. // set min: 0, max: 200, only for campatible with ec2.
  55628. // In fact min max should not have default value.
  55629. min: 0, // min value, must specified if pieces is not specified.
  55630. max: 200, // max value, must specified if pieces is not specified.
  55631. dimension: null,
  55632. inRange: null, // 'color', 'colorHue', 'colorSaturation', 'colorLightness', 'colorAlpha',
  55633. // 'symbol', 'symbolSize'
  55634. outOfRange: null, // 'color', 'colorHue', 'colorSaturation',
  55635. // 'colorLightness', 'colorAlpha',
  55636. // 'symbol', 'symbolSize'
  55637. left: 0, // 'center' ¦ 'left' ¦ 'right' ¦ {number} (px)
  55638. right: null, // The same as left.
  55639. top: null, // 'top' ¦ 'bottom' ¦ 'center' ¦ {number} (px)
  55640. bottom: 0, // The same as top.
  55641. itemWidth: null,
  55642. itemHeight: null,
  55643. inverse: false,
  55644. orient: 'vertical', // 'horizontal' ¦ 'vertical'
  55645. backgroundColor: 'rgba(0,0,0,0)',
  55646. borderColor: '#ccc', // 值域边框颜色
  55647. contentColor: '#5793f3',
  55648. inactiveColor: '#aaa',
  55649. borderWidth: 0, // 值域边框线宽,单位px,默认为0(无边框)
  55650. padding: 5, // 值域内边距,单位px,默认各方向内边距为5,
  55651. // 接受数组分别设定上右下左边距,同css
  55652. textGap: 10, //
  55653. precision: 0, // 小数精度,默认为0,无小数点
  55654. color: null, //颜色(deprecated,兼容ec2,顺序同pieces,不同于inRange/outOfRange)
  55655. formatter: null,
  55656. text: null, // 文本,如['高', '低'],兼容ec2,text[0]对应高值,text[1]对应低值
  55657. textStyle: {
  55658. color: '#333' // 值域文字颜色
  55659. }
  55660. },
  55661. /**
  55662. * @protected
  55663. */
  55664. init: function (option, parentModel, ecModel) {
  55665. /**
  55666. * @private
  55667. * @type {Array.<number>}
  55668. */
  55669. this._dataExtent;
  55670. /**
  55671. * @readOnly
  55672. */
  55673. this.targetVisuals = {};
  55674. /**
  55675. * @readOnly
  55676. */
  55677. this.controllerVisuals = {};
  55678. /**
  55679. * @readOnly
  55680. */
  55681. this.textStyleModel;
  55682. /**
  55683. * [width, height]
  55684. * @readOnly
  55685. * @type {Array.<number>}
  55686. */
  55687. this.itemSize;
  55688. this.mergeDefaultAndTheme(option, ecModel);
  55689. },
  55690. /**
  55691. * @protected
  55692. */
  55693. optionUpdated: function (newOption, isInit) {
  55694. var thisOption = this.option;
  55695. // FIXME
  55696. // necessary?
  55697. // Disable realtime view update if canvas is not supported.
  55698. if (!env.canvasSupported) {
  55699. thisOption.realtime = false;
  55700. }
  55701. !isInit && visualSolution.replaceVisualOption(
  55702. thisOption, newOption, this.replacableOptionKeys
  55703. );
  55704. this.textStyleModel = this.getModel('textStyle');
  55705. this.resetItemSize();
  55706. this.completeVisualOption();
  55707. },
  55708. /**
  55709. * @protected
  55710. */
  55711. resetVisual: function (supplementVisualOption) {
  55712. var stateList = this.stateList;
  55713. supplementVisualOption = zrUtil.bind(supplementVisualOption, this);
  55714. this.controllerVisuals = visualSolution.createVisualMappings(
  55715. this.option.controller, stateList, supplementVisualOption
  55716. );
  55717. this.targetVisuals = visualSolution.createVisualMappings(
  55718. this.option.target, stateList, supplementVisualOption
  55719. );
  55720. },
  55721. /**
  55722. * @protected
  55723. */
  55724. resetTargetSeries: function () {
  55725. var thisOption = this.option;
  55726. var allSeriesIndex = thisOption.seriesIndex == null;
  55727. thisOption.seriesIndex = allSeriesIndex
  55728. ? [] : modelUtil.normalizeToArray(thisOption.seriesIndex);
  55729. allSeriesIndex && this.ecModel.eachSeries(function (seriesModel, index) {
  55730. thisOption.seriesIndex.push(index);
  55731. });
  55732. },
  55733. /**
  55734. * @public
  55735. */
  55736. eachTargetSeries: function (callback, context) {
  55737. zrUtil.each(this.option.seriesIndex, function (seriesIndex) {
  55738. callback.call(context, this.ecModel.getSeriesByIndex(seriesIndex));
  55739. }, this);
  55740. },
  55741. /**
  55742. * @pubilc
  55743. */
  55744. isTargetSeries: function (seriesModel) {
  55745. var is = false;
  55746. this.eachTargetSeries(function (model) {
  55747. model === seriesModel && (is = true);
  55748. });
  55749. return is;
  55750. },
  55751. /**
  55752. * @example
  55753. * this.formatValueText(someVal); // format single numeric value to text.
  55754. * this.formatValueText(someVal, true); // format single category value to text.
  55755. * this.formatValueText([min, max]); // format numeric min-max to text.
  55756. * this.formatValueText([this.dataBound[0], max]); // using data lower bound.
  55757. * this.formatValueText([min, this.dataBound[1]]); // using data upper bound.
  55758. *
  55759. * @param {number|Array.<number>} value Real value, or this.dataBound[0 or 1].
  55760. * @param {boolean} [isCategory=false] Only available when value is number.
  55761. * @param {Array.<string>} edgeSymbols Open-close symbol when value is interval.
  55762. * @return {string}
  55763. * @protected
  55764. */
  55765. formatValueText: function(value, isCategory, edgeSymbols) {
  55766. var option = this.option;
  55767. var precision = option.precision;
  55768. var dataBound = this.dataBound;
  55769. var formatter = option.formatter;
  55770. var isMinMax;
  55771. var textValue;
  55772. edgeSymbols = edgeSymbols || ['<', '>'];
  55773. if (zrUtil.isArray(value)) {
  55774. value = value.slice();
  55775. isMinMax = true;
  55776. }
  55777. textValue = isCategory
  55778. ? value
  55779. : (isMinMax
  55780. ? [toFixed(value[0]), toFixed(value[1])]
  55781. : toFixed(value)
  55782. );
  55783. if (zrUtil.isString(formatter)) {
  55784. return formatter
  55785. .replace('{value}', isMinMax ? textValue[0] : textValue)
  55786. .replace('{value2}', isMinMax ? textValue[1] : textValue);
  55787. }
  55788. else if (zrUtil.isFunction(formatter)) {
  55789. return isMinMax
  55790. ? formatter(value[0], value[1])
  55791. : formatter(value);
  55792. }
  55793. if (isMinMax) {
  55794. if (value[0] === dataBound[0]) {
  55795. return edgeSymbols[0] + ' ' + textValue[1];
  55796. }
  55797. else if (value[1] === dataBound[1]) {
  55798. return edgeSymbols[1] + ' ' + textValue[0];
  55799. }
  55800. else {
  55801. return textValue[0] + ' - ' + textValue[1];
  55802. }
  55803. }
  55804. else { // Format single value (includes category case).
  55805. return textValue;
  55806. }
  55807. function toFixed(val) {
  55808. return val === dataBound[0]
  55809. ? 'min'
  55810. : val === dataBound[1]
  55811. ? 'max'
  55812. : (+val).toFixed(precision);
  55813. }
  55814. },
  55815. /**
  55816. * @protected
  55817. */
  55818. resetExtent: function () {
  55819. var thisOption = this.option;
  55820. // Can not calculate data extent by data here.
  55821. // Because series and data may be modified in processing stage.
  55822. // So we do not support the feature "auto min/max".
  55823. var extent = asc([thisOption.min, thisOption.max]);
  55824. this._dataExtent = extent;
  55825. },
  55826. /**
  55827. * @public
  55828. * @param {module:echarts/data/List} list
  55829. * @return {string} Concrete dimention. If return null/undefined,
  55830. * no dimension used.
  55831. */
  55832. getDataDimension: function (list) {
  55833. var optDim = this.option.dimension;
  55834. return optDim != null
  55835. ? optDim : list.dimensions.length - 1;
  55836. },
  55837. /**
  55838. * @public
  55839. * @override
  55840. */
  55841. getExtent: function () {
  55842. return this._dataExtent.slice();
  55843. },
  55844. /**
  55845. * @protected
  55846. */
  55847. completeVisualOption: function () {
  55848. var thisOption = this.option;
  55849. var base = {inRange: thisOption.inRange, outOfRange: thisOption.outOfRange};
  55850. var target = thisOption.target || (thisOption.target = {});
  55851. var controller = thisOption.controller || (thisOption.controller = {});
  55852. zrUtil.merge(target, base); // Do not override
  55853. zrUtil.merge(controller, base); // Do not override
  55854. var isCategory = this.isCategory();
  55855. completeSingle.call(this, target);
  55856. completeSingle.call(this, controller);
  55857. completeInactive.call(this, target, 'inRange', 'outOfRange');
  55858. // completeInactive.call(this, target, 'outOfRange', 'inRange');
  55859. completeController.call(this, controller);
  55860. function completeSingle(base) {
  55861. // Compatible with ec2 dataRange.color.
  55862. // The mapping order of dataRange.color is: [high value, ..., low value]
  55863. // whereas inRange.color and outOfRange.color is [low value, ..., high value]
  55864. // Notice: ec2 has no inverse.
  55865. if (isArray(thisOption.color)
  55866. // If there has been inRange: {symbol: ...}, adding color is a mistake.
  55867. // So adding color only when no inRange defined.
  55868. && !base.inRange
  55869. ) {
  55870. base.inRange = {color: thisOption.color.slice().reverse()};
  55871. }
  55872. // Compatible with previous logic, always give a defautl color, otherwise
  55873. // simple config with no inRange and outOfRange will not work.
  55874. // Originally we use visualMap.color as the default color, but setOption at
  55875. // the second time the default color will be erased. So we change to use
  55876. // constant DEFAULT_COLOR.
  55877. // If user do not want the defualt color, set inRange: {color: null}.
  55878. base.inRange = base.inRange || {color: DEFAULT_COLOR};
  55879. // If using shortcut like: {inRange: 'symbol'}, complete default value.
  55880. each(this.stateList, function (state) {
  55881. var visualType = base[state];
  55882. if (zrUtil.isString(visualType)) {
  55883. var defa = visualDefault.get(visualType, 'active', isCategory);
  55884. if (defa) {
  55885. base[state] = {};
  55886. base[state][visualType] = defa;
  55887. }
  55888. else {
  55889. // Mark as not specified.
  55890. delete base[state];
  55891. }
  55892. }
  55893. }, this);
  55894. }
  55895. function completeInactive(base, stateExist, stateAbsent) {
  55896. var optExist = base[stateExist];
  55897. var optAbsent = base[stateAbsent];
  55898. if (optExist && !optAbsent) {
  55899. optAbsent = base[stateAbsent] = {};
  55900. each(optExist, function (visualData, visualType) {
  55901. if (!VisualMapping.isValidType(visualType)) {
  55902. return;
  55903. }
  55904. var defa = visualDefault.get(visualType, 'inactive', isCategory);
  55905. if (defa != null) {
  55906. optAbsent[visualType] = defa;
  55907. // Compatibable with ec2:
  55908. // Only inactive color to rgba(0,0,0,0) can not
  55909. // make label transparent, so use opacity also.
  55910. if (visualType === 'color'
  55911. && !optAbsent.hasOwnProperty('opacity')
  55912. && !optAbsent.hasOwnProperty('colorAlpha')
  55913. ) {
  55914. optAbsent.opacity = [0, 0];
  55915. }
  55916. }
  55917. });
  55918. }
  55919. }
  55920. function completeController(controller) {
  55921. var symbolExists = (controller.inRange || {}).symbol
  55922. || (controller.outOfRange || {}).symbol;
  55923. var symbolSizeExists = (controller.inRange || {}).symbolSize
  55924. || (controller.outOfRange || {}).symbolSize;
  55925. var inactiveColor = this.get('inactiveColor');
  55926. each(this.stateList, function (state) {
  55927. var itemSize = this.itemSize;
  55928. var visuals = controller[state];
  55929. // Set inactive color for controller if no other color
  55930. // attr (like colorAlpha) specified.
  55931. if (!visuals) {
  55932. visuals = controller[state] = {
  55933. color: isCategory ? inactiveColor : [inactiveColor]
  55934. };
  55935. }
  55936. // Consistent symbol and symbolSize if not specified.
  55937. if (visuals.symbol == null) {
  55938. visuals.symbol = symbolExists
  55939. && zrUtil.clone(symbolExists)
  55940. || (isCategory ? 'roundRect' : ['roundRect']);
  55941. }
  55942. if (visuals.symbolSize == null) {
  55943. visuals.symbolSize = symbolSizeExists
  55944. && zrUtil.clone(symbolSizeExists)
  55945. || (isCategory ? itemSize[0] : [itemSize[0], itemSize[0]]);
  55946. }
  55947. // Filter square and none.
  55948. visuals.symbol = mapVisual(visuals.symbol, function (symbol) {
  55949. return (symbol === 'none' || symbol === 'square') ? 'roundRect' : symbol;
  55950. });
  55951. // Normalize symbolSize
  55952. var symbolSize = visuals.symbolSize;
  55953. if (symbolSize != null) {
  55954. var max = -Infinity;
  55955. // symbolSize can be object when categories defined.
  55956. eachVisual(symbolSize, function (value) {
  55957. value > max && (max = value);
  55958. });
  55959. visuals.symbolSize = mapVisual(symbolSize, function (value) {
  55960. return linearMap(value, [0, max], [0, itemSize[0]], true);
  55961. });
  55962. }
  55963. }, this);
  55964. }
  55965. },
  55966. /**
  55967. * @protected
  55968. */
  55969. resetItemSize: function () {
  55970. this.itemSize = [
  55971. parseFloat(this.get('itemWidth')),
  55972. parseFloat(this.get('itemHeight'))
  55973. ];
  55974. },
  55975. /**
  55976. * @public
  55977. */
  55978. isCategory: function () {
  55979. return !!this.option.categories;
  55980. },
  55981. /**
  55982. * @public
  55983. * @abstract
  55984. */
  55985. setSelected: noop,
  55986. /**
  55987. * @public
  55988. * @abstract
  55989. * @param {*|module:echarts/data/List} valueOrData
  55990. * @param {number} dataIndex
  55991. * @return {string} state See this.stateList
  55992. */
  55993. getValueState: noop,
  55994. /**
  55995. * FIXME
  55996. * Do not publish to thirt-part-dev temporarily
  55997. * util the interface is stable. (Should it return
  55998. * a function but not visual meta?)
  55999. *
  56000. * @pubilc
  56001. * @abstract
  56002. * @param {Function} getColorVisual
  56003. * params: value, valueState
  56004. * return: color
  56005. * @return {Object} visualMeta
  56006. * should includes {stops, outerColors}
  56007. * outerColor means [colorBeyondMinValue, colorBeyondMaxValue]
  56008. */
  56009. getVisualMeta: noop
  56010. });
  56011. module.exports = VisualMapModel;
  56012. /***/ },
  56013. /* 382 */
  56014. /***/ function(module, exports, __webpack_require__) {
  56015. /**
  56016. * @file Visual mapping.
  56017. */
  56018. var zrUtil = __webpack_require__(4);
  56019. var visualDefault = {
  56020. /**
  56021. * @public
  56022. */
  56023. get: function (visualType, key, isCategory) {
  56024. var value = zrUtil.clone(
  56025. (defaultOption[visualType] || {})[key]
  56026. );
  56027. return isCategory
  56028. ? (zrUtil.isArray(value) ? value[value.length - 1] : value)
  56029. : value;
  56030. }
  56031. };
  56032. var defaultOption = {
  56033. color: {
  56034. active: ['#006edd', '#e0ffff'],
  56035. inactive: ['rgba(0,0,0,0)']
  56036. },
  56037. colorHue: {
  56038. active: [0, 360],
  56039. inactive: [0, 0]
  56040. },
  56041. colorSaturation: {
  56042. active: [0.3, 1],
  56043. inactive: [0, 0]
  56044. },
  56045. colorLightness: {
  56046. active: [0.9, 0.5],
  56047. inactive: [0, 0]
  56048. },
  56049. colorAlpha: {
  56050. active: [0.3, 1],
  56051. inactive: [0, 0]
  56052. },
  56053. opacity: {
  56054. active: [0.3, 1],
  56055. inactive: [0, 0]
  56056. },
  56057. symbol: {
  56058. active: ['circle', 'roundRect', 'diamond'],
  56059. inactive: ['none']
  56060. },
  56061. symbolSize: {
  56062. active: [10, 50],
  56063. inactive: [0, 0]
  56064. }
  56065. };
  56066. module.exports = visualDefault;
  56067. /***/ },
  56068. /* 383 */
  56069. /***/ function(module, exports, __webpack_require__) {
  56070. var VisualMapView = __webpack_require__(384);
  56071. var graphic = __webpack_require__(18);
  56072. var zrUtil = __webpack_require__(4);
  56073. var numberUtil = __webpack_require__(7);
  56074. var sliderMove = __webpack_require__(238);
  56075. var LinearGradient = __webpack_require__(65);
  56076. var helper = __webpack_require__(385);
  56077. var modelUtil = __webpack_require__(5);
  56078. var eventTool = __webpack_require__(88);
  56079. var linearMap = numberUtil.linearMap;
  56080. var each = zrUtil.each;
  56081. var mathMin = Math.min;
  56082. var mathMax = Math.max;
  56083. // Arbitrary value
  56084. var HOVER_LINK_SIZE = 12;
  56085. var HOVER_LINK_OUT = 6;
  56086. // Notice:
  56087. // Any "interval" should be by the order of [low, high].
  56088. // "handle0" (handleIndex === 0) maps to
  56089. // low data value: this._dataInterval[0] and has low coord.
  56090. // "handle1" (handleIndex === 1) maps to
  56091. // high data value: this._dataInterval[1] and has high coord.
  56092. // The logic of transform is implemented in this._createBarGroup.
  56093. var ContinuousView = VisualMapView.extend({
  56094. type: 'visualMap.continuous',
  56095. /**
  56096. * @override
  56097. */
  56098. init: function () {
  56099. ContinuousView.superApply(this, 'init', arguments);
  56100. /**
  56101. * @private
  56102. */
  56103. this._shapes = {};
  56104. /**
  56105. * @private
  56106. */
  56107. this._dataInterval = [];
  56108. /**
  56109. * @private
  56110. */
  56111. this._handleEnds = [];
  56112. /**
  56113. * @private
  56114. */
  56115. this._orient;
  56116. /**
  56117. * @private
  56118. */
  56119. this._useHandle;
  56120. /**
  56121. * @private
  56122. */
  56123. this._hoverLinkDataIndices = [];
  56124. /**
  56125. * @private
  56126. */
  56127. this._dragging;
  56128. /**
  56129. * @private
  56130. */
  56131. this._hovering;
  56132. },
  56133. /**
  56134. * @protected
  56135. * @override
  56136. */
  56137. doRender: function (visualMapModel, ecModel, api, payload) {
  56138. if (!payload || payload.type !== 'selectDataRange' || payload.from !== this.uid) {
  56139. this._buildView();
  56140. }
  56141. },
  56142. /**
  56143. * @private
  56144. */
  56145. _buildView: function () {
  56146. this.group.removeAll();
  56147. var visualMapModel = this.visualMapModel;
  56148. var thisGroup = this.group;
  56149. this._orient = visualMapModel.get('orient');
  56150. this._useHandle = visualMapModel.get('calculable');
  56151. this._resetInterval();
  56152. this._renderBar(thisGroup);
  56153. var dataRangeText = visualMapModel.get('text');
  56154. this._renderEndsText(thisGroup, dataRangeText, 0);
  56155. this._renderEndsText(thisGroup, dataRangeText, 1);
  56156. // Do this for background size calculation.
  56157. this._updateView(true);
  56158. // After updating view, inner shapes is built completely,
  56159. // and then background can be rendered.
  56160. this.renderBackground(thisGroup);
  56161. // Real update view
  56162. this._updateView();
  56163. this._enableHoverLinkToSeries();
  56164. this._enableHoverLinkFromSeries();
  56165. this.positionGroup(thisGroup);
  56166. },
  56167. /**
  56168. * @private
  56169. */
  56170. _renderEndsText: function (group, dataRangeText, endsIndex) {
  56171. if (!dataRangeText) {
  56172. return;
  56173. }
  56174. // Compatible with ec2, text[0] map to high value, text[1] map low value.
  56175. var text = dataRangeText[1 - endsIndex];
  56176. text = text != null ? text + '' : '';
  56177. var visualMapModel = this.visualMapModel;
  56178. var textGap = visualMapModel.get('textGap');
  56179. var itemSize = visualMapModel.itemSize;
  56180. var barGroup = this._shapes.barGroup;
  56181. var position = this._applyTransform(
  56182. [
  56183. itemSize[0] / 2,
  56184. endsIndex === 0 ? -textGap : itemSize[1] + textGap
  56185. ],
  56186. barGroup
  56187. );
  56188. var align = this._applyTransform(
  56189. endsIndex === 0 ? 'bottom' : 'top',
  56190. barGroup
  56191. );
  56192. var orient = this._orient;
  56193. var textStyleModel = this.visualMapModel.textStyleModel;
  56194. this.group.add(new graphic.Text({
  56195. style: {
  56196. x: position[0],
  56197. y: position[1],
  56198. textVerticalAlign: orient === 'horizontal' ? 'middle' : align,
  56199. textAlign: orient === 'horizontal' ? align : 'center',
  56200. text: text,
  56201. textFont: textStyleModel.getFont(),
  56202. fill: textStyleModel.getTextColor()
  56203. }
  56204. }));
  56205. },
  56206. /**
  56207. * @private
  56208. */
  56209. _renderBar: function (targetGroup) {
  56210. var visualMapModel = this.visualMapModel;
  56211. var shapes = this._shapes;
  56212. var itemSize = visualMapModel.itemSize;
  56213. var orient = this._orient;
  56214. var useHandle = this._useHandle;
  56215. var itemAlign = helper.getItemAlign(visualMapModel, this.api, itemSize);
  56216. var barGroup = shapes.barGroup = this._createBarGroup(itemAlign);
  56217. // Bar
  56218. barGroup.add(shapes.outOfRange = createPolygon());
  56219. barGroup.add(shapes.inRange = createPolygon(
  56220. null,
  56221. useHandle ? 'move' : null,
  56222. zrUtil.bind(this._dragHandle, this, 'all', false),
  56223. zrUtil.bind(this._dragHandle, this, 'all', true)
  56224. ));
  56225. var textRect = visualMapModel.textStyleModel.getTextRect('国');
  56226. var textSize = mathMax(textRect.width, textRect.height);
  56227. // Handle
  56228. if (useHandle) {
  56229. shapes.handleThumbs = [];
  56230. shapes.handleLabels = [];
  56231. shapes.handleLabelPoints = [];
  56232. this._createHandle(barGroup, 0, itemSize, textSize, orient, itemAlign);
  56233. this._createHandle(barGroup, 1, itemSize, textSize, orient, itemAlign);
  56234. }
  56235. this._createIndicator(barGroup, itemSize, textSize, orient);
  56236. targetGroup.add(barGroup);
  56237. },
  56238. /**
  56239. * @private
  56240. */
  56241. _createHandle: function (barGroup, handleIndex, itemSize, textSize, orient) {
  56242. var onDrift = zrUtil.bind(this._dragHandle, this, handleIndex, false);
  56243. var onDragEnd = zrUtil.bind(this._dragHandle, this, handleIndex, true);
  56244. var handleThumb = createPolygon(
  56245. createHandlePoints(handleIndex, textSize),
  56246. 'move',
  56247. onDrift,
  56248. onDragEnd
  56249. );
  56250. handleThumb.position[0] = itemSize[0];
  56251. barGroup.add(handleThumb);
  56252. // Text is always horizontal layout but should not be effected by
  56253. // transform (orient/inverse). So label is built separately but not
  56254. // use zrender/graphic/helper/RectText, and is located based on view
  56255. // group (according to handleLabelPoint) but not barGroup.
  56256. var textStyleModel = this.visualMapModel.textStyleModel;
  56257. var handleLabel = new graphic.Text({
  56258. draggable: true,
  56259. drift: onDrift,
  56260. onmousemove: function (e) {
  56261. // Fot mobile devicem, prevent screen slider on the button.
  56262. eventTool.stop(e.event);
  56263. },
  56264. ondragend: onDragEnd,
  56265. style: {
  56266. x: 0, y: 0, text: '',
  56267. textFont: textStyleModel.getFont(),
  56268. fill: textStyleModel.getTextColor()
  56269. }
  56270. });
  56271. this.group.add(handleLabel);
  56272. var handleLabelPoint = [
  56273. orient === 'horizontal'
  56274. ? textSize / 2
  56275. : textSize * 1.5,
  56276. orient === 'horizontal'
  56277. ? (handleIndex === 0 ? -(textSize * 1.5) : (textSize * 1.5))
  56278. : (handleIndex === 0 ? -textSize / 2 : textSize / 2)
  56279. ];
  56280. var shapes = this._shapes;
  56281. shapes.handleThumbs[handleIndex] = handleThumb;
  56282. shapes.handleLabelPoints[handleIndex] = handleLabelPoint;
  56283. shapes.handleLabels[handleIndex] = handleLabel;
  56284. },
  56285. /**
  56286. * @private
  56287. */
  56288. _createIndicator: function (barGroup, itemSize, textSize, orient) {
  56289. var indicator = createPolygon([[0, 0]], 'move');
  56290. indicator.position[0] = itemSize[0];
  56291. indicator.attr({invisible: true, silent: true});
  56292. barGroup.add(indicator);
  56293. var textStyleModel = this.visualMapModel.textStyleModel;
  56294. var indicatorLabel = new graphic.Text({
  56295. silent: true,
  56296. invisible: true,
  56297. style: {
  56298. x: 0, y: 0, text: '',
  56299. textFont: textStyleModel.getFont(),
  56300. fill: textStyleModel.getTextColor()
  56301. }
  56302. });
  56303. this.group.add(indicatorLabel);
  56304. var indicatorLabelPoint = [
  56305. orient === 'horizontal' ? textSize / 2 : HOVER_LINK_OUT + 3,
  56306. 0
  56307. ];
  56308. var shapes = this._shapes;
  56309. shapes.indicator = indicator;
  56310. shapes.indicatorLabel = indicatorLabel;
  56311. shapes.indicatorLabelPoint = indicatorLabelPoint;
  56312. },
  56313. /**
  56314. * @private
  56315. */
  56316. _dragHandle: function (handleIndex, isEnd, dx, dy) {
  56317. if (!this._useHandle) {
  56318. return;
  56319. }
  56320. this._dragging = !isEnd;
  56321. if (!isEnd) {
  56322. // Transform dx, dy to bar coordination.
  56323. var vertex = this._applyTransform([dx, dy], this._shapes.barGroup, true);
  56324. this._updateInterval(handleIndex, vertex[1]);
  56325. // Considering realtime, update view should be executed
  56326. // before dispatch action.
  56327. this._updateView();
  56328. }
  56329. // dragEnd do not dispatch action when realtime.
  56330. if (isEnd === !this.visualMapModel.get('realtime')) { // jshint ignore:line
  56331. this.api.dispatchAction({
  56332. type: 'selectDataRange',
  56333. from: this.uid,
  56334. visualMapId: this.visualMapModel.id,
  56335. selected: this._dataInterval.slice()
  56336. });
  56337. }
  56338. if (isEnd) {
  56339. !this._hovering && this._clearHoverLinkToSeries();
  56340. }
  56341. else if (useHoverLinkOnHandle(this.visualMapModel)) {
  56342. this._doHoverLinkToSeries(this._handleEnds[handleIndex], false);
  56343. }
  56344. },
  56345. /**
  56346. * @private
  56347. */
  56348. _resetInterval: function () {
  56349. var visualMapModel = this.visualMapModel;
  56350. var dataInterval = this._dataInterval = visualMapModel.getSelected();
  56351. var dataExtent = visualMapModel.getExtent();
  56352. var sizeExtent = [0, visualMapModel.itemSize[1]];
  56353. this._handleEnds = [
  56354. linearMap(dataInterval[0], dataExtent, sizeExtent, true),
  56355. linearMap(dataInterval[1], dataExtent, sizeExtent, true)
  56356. ];
  56357. },
  56358. /**
  56359. * @private
  56360. * @param {(number|string)} handleIndex 0 or 1 or 'all'
  56361. * @param {number} dx
  56362. * @param {number} dy
  56363. */
  56364. _updateInterval: function (handleIndex, delta) {
  56365. delta = delta || 0;
  56366. var visualMapModel = this.visualMapModel;
  56367. var handleEnds = this._handleEnds;
  56368. var sizeExtent = [0, visualMapModel.itemSize[1]];
  56369. sliderMove(
  56370. delta,
  56371. handleEnds,
  56372. sizeExtent,
  56373. handleIndex,
  56374. // cross is forbiden
  56375. 0
  56376. );
  56377. var dataExtent = visualMapModel.getExtent();
  56378. // Update data interval.
  56379. this._dataInterval = [
  56380. linearMap(handleEnds[0], sizeExtent, dataExtent, true),
  56381. linearMap(handleEnds[1], sizeExtent, dataExtent, true)
  56382. ];
  56383. },
  56384. /**
  56385. * @private
  56386. */
  56387. _updateView: function (forSketch) {
  56388. var visualMapModel = this.visualMapModel;
  56389. var dataExtent = visualMapModel.getExtent();
  56390. var shapes = this._shapes;
  56391. var outOfRangeHandleEnds = [0, visualMapModel.itemSize[1]];
  56392. var inRangeHandleEnds = forSketch ? outOfRangeHandleEnds : this._handleEnds;
  56393. var visualInRange = this._createBarVisual(
  56394. this._dataInterval, dataExtent, inRangeHandleEnds, 'inRange'
  56395. );
  56396. var visualOutOfRange = this._createBarVisual(
  56397. dataExtent, dataExtent, outOfRangeHandleEnds, 'outOfRange'
  56398. );
  56399. shapes.inRange
  56400. .setStyle({
  56401. fill: visualInRange.barColor,
  56402. opacity: visualInRange.opacity
  56403. })
  56404. .setShape('points', visualInRange.barPoints);
  56405. shapes.outOfRange
  56406. .setStyle({
  56407. fill: visualOutOfRange.barColor,
  56408. opacity: visualOutOfRange.opacity
  56409. })
  56410. .setShape('points', visualOutOfRange.barPoints);
  56411. this._updateHandle(inRangeHandleEnds, visualInRange);
  56412. },
  56413. /**
  56414. * @private
  56415. */
  56416. _createBarVisual: function (dataInterval, dataExtent, handleEnds, forceState) {
  56417. var opts = {
  56418. forceState: forceState,
  56419. convertOpacityToAlpha: true
  56420. };
  56421. var colorStops = this._makeColorGradient(dataInterval, opts);
  56422. var symbolSizes = [
  56423. this.getControllerVisual(dataInterval[0], 'symbolSize', opts),
  56424. this.getControllerVisual(dataInterval[1], 'symbolSize', opts)
  56425. ];
  56426. var barPoints = this._createBarPoints(handleEnds, symbolSizes);
  56427. return {
  56428. barColor: new LinearGradient(0, 0, 0, 1, colorStops),
  56429. barPoints: barPoints,
  56430. handlesColor: [
  56431. colorStops[0].color,
  56432. colorStops[colorStops.length - 1].color
  56433. ]
  56434. };
  56435. },
  56436. /**
  56437. * @private
  56438. */
  56439. _makeColorGradient: function (dataInterval, opts) {
  56440. // Considering colorHue, which is not linear, so we have to sample
  56441. // to calculate gradient color stops, but not only caculate head
  56442. // and tail.
  56443. var sampleNumber = 100; // Arbitrary value.
  56444. var colorStops = [];
  56445. var step = (dataInterval[1] - dataInterval[0]) / sampleNumber;
  56446. colorStops.push({
  56447. color: this.getControllerVisual(dataInterval[0], 'color', opts),
  56448. offset: 0
  56449. });
  56450. for (var i = 1; i < sampleNumber; i++) {
  56451. var currValue = dataInterval[0] + step * i;
  56452. if (currValue > dataInterval[1]) {
  56453. break;
  56454. }
  56455. colorStops.push({
  56456. color: this.getControllerVisual(currValue, 'color', opts),
  56457. offset: i / sampleNumber
  56458. });
  56459. }
  56460. colorStops.push({
  56461. color: this.getControllerVisual(dataInterval[1], 'color', opts),
  56462. offset: 1
  56463. });
  56464. return colorStops;
  56465. },
  56466. /**
  56467. * @private
  56468. */
  56469. _createBarPoints: function (handleEnds, symbolSizes) {
  56470. var itemSize = this.visualMapModel.itemSize;
  56471. return [
  56472. [itemSize[0] - symbolSizes[0], handleEnds[0]],
  56473. [itemSize[0], handleEnds[0]],
  56474. [itemSize[0], handleEnds[1]],
  56475. [itemSize[0] - symbolSizes[1], handleEnds[1]]
  56476. ];
  56477. },
  56478. /**
  56479. * @private
  56480. */
  56481. _createBarGroup: function (itemAlign) {
  56482. var orient = this._orient;
  56483. var inverse = this.visualMapModel.get('inverse');
  56484. return new graphic.Group(
  56485. (orient === 'horizontal' && !inverse)
  56486. ? {scale: itemAlign === 'bottom' ? [1, 1] : [-1, 1], rotation: Math.PI / 2}
  56487. : (orient === 'horizontal' && inverse)
  56488. ? {scale: itemAlign === 'bottom' ? [-1, 1] : [1, 1], rotation: -Math.PI / 2}
  56489. : (orient === 'vertical' && !inverse)
  56490. ? {scale: itemAlign === 'left' ? [1, -1] : [-1, -1]}
  56491. : {scale: itemAlign === 'left' ? [1, 1] : [-1, 1]}
  56492. );
  56493. },
  56494. /**
  56495. * @private
  56496. */
  56497. _updateHandle: function (handleEnds, visualInRange) {
  56498. if (!this._useHandle) {
  56499. return;
  56500. }
  56501. var shapes = this._shapes;
  56502. var visualMapModel = this.visualMapModel;
  56503. var handleThumbs = shapes.handleThumbs;
  56504. var handleLabels = shapes.handleLabels;
  56505. each([0, 1], function (handleIndex) {
  56506. var handleThumb = handleThumbs[handleIndex];
  56507. handleThumb.setStyle('fill', visualInRange.handlesColor[handleIndex]);
  56508. handleThumb.position[1] = handleEnds[handleIndex];
  56509. // Update handle label position.
  56510. var textPoint = graphic.applyTransform(
  56511. shapes.handleLabelPoints[handleIndex],
  56512. graphic.getTransform(handleThumb, this.group)
  56513. );
  56514. handleLabels[handleIndex].setStyle({
  56515. x: textPoint[0],
  56516. y: textPoint[1],
  56517. text: visualMapModel.formatValueText(this._dataInterval[handleIndex]),
  56518. textVerticalAlign: 'middle',
  56519. textAlign: this._applyTransform(
  56520. this._orient === 'horizontal'
  56521. ? (handleIndex === 0 ? 'bottom' : 'top')
  56522. : 'left',
  56523. shapes.barGroup
  56524. )
  56525. });
  56526. }, this);
  56527. },
  56528. /**
  56529. * @private
  56530. * @param {number} cursorValue
  56531. * @param {number} textValue
  56532. * @param {string} [rangeSymbol]
  56533. * @param {number} [halfHoverLinkSize]
  56534. */
  56535. _showIndicator: function (cursorValue, textValue, rangeSymbol, halfHoverLinkSize) {
  56536. var visualMapModel = this.visualMapModel;
  56537. var dataExtent = visualMapModel.getExtent();
  56538. var itemSize = visualMapModel.itemSize;
  56539. var sizeExtent = [0, itemSize[1]];
  56540. var pos = linearMap(cursorValue, dataExtent, sizeExtent, true);
  56541. var shapes = this._shapes;
  56542. var indicator = shapes.indicator;
  56543. if (!indicator) {
  56544. return;
  56545. }
  56546. indicator.position[1] = pos;
  56547. indicator.attr('invisible', false);
  56548. indicator.setShape('points', createIndicatorPoints(
  56549. !!rangeSymbol, halfHoverLinkSize, pos, itemSize[1]
  56550. ));
  56551. var opts = {convertOpacityToAlpha: true};
  56552. var color = this.getControllerVisual(cursorValue, 'color', opts);
  56553. indicator.setStyle('fill', color);
  56554. // Update handle label position.
  56555. var textPoint = graphic.applyTransform(
  56556. shapes.indicatorLabelPoint,
  56557. graphic.getTransform(indicator, this.group)
  56558. );
  56559. var indicatorLabel = shapes.indicatorLabel;
  56560. indicatorLabel.attr('invisible', false);
  56561. var align = this._applyTransform('left', shapes.barGroup);
  56562. var orient = this._orient;
  56563. indicatorLabel.setStyle({
  56564. text: (rangeSymbol ? rangeSymbol : '') + visualMapModel.formatValueText(textValue),
  56565. textVerticalAlign: orient === 'horizontal' ? align : 'middle',
  56566. textAlign: orient === 'horizontal' ? 'center' : align,
  56567. x: textPoint[0],
  56568. y: textPoint[1]
  56569. });
  56570. },
  56571. /**
  56572. * @private
  56573. */
  56574. _enableHoverLinkToSeries: function () {
  56575. var self = this;
  56576. this._shapes.barGroup
  56577. .on('mousemove', function (e) {
  56578. self._hovering = true;
  56579. if (!self._dragging) {
  56580. var itemSize = self.visualMapModel.itemSize;
  56581. var pos = self._applyTransform(
  56582. [e.offsetX, e.offsetY], self._shapes.barGroup, true, true
  56583. );
  56584. // For hover link show when hover handle, which might be
  56585. // below or upper than sizeExtent.
  56586. pos[1] = mathMin(mathMax(0, pos[1]), itemSize[1]);
  56587. self._doHoverLinkToSeries(
  56588. pos[1],
  56589. 0 <= pos[0] && pos[0] <= itemSize[0]
  56590. );
  56591. }
  56592. })
  56593. .on('mouseout', function () {
  56594. // When mouse is out of handle, hoverLink still need
  56595. // to be displayed when realtime is set as false.
  56596. self._hovering = false;
  56597. !self._dragging && self._clearHoverLinkToSeries();
  56598. });
  56599. },
  56600. /**
  56601. * @private
  56602. */
  56603. _enableHoverLinkFromSeries: function () {
  56604. var zr = this.api.getZr();
  56605. if (this.visualMapModel.option.hoverLink) {
  56606. zr.on('mouseover', this._hoverLinkFromSeriesMouseOver, this);
  56607. zr.on('mouseout', this._hideIndicator, this);
  56608. }
  56609. else {
  56610. this._clearHoverLinkFromSeries();
  56611. }
  56612. },
  56613. /**
  56614. * @private
  56615. */
  56616. _doHoverLinkToSeries: function (cursorPos, hoverOnBar) {
  56617. var visualMapModel = this.visualMapModel;
  56618. var itemSize = visualMapModel.itemSize;
  56619. if (!visualMapModel.option.hoverLink) {
  56620. return;
  56621. }
  56622. var sizeExtent = [0, itemSize[1]];
  56623. var dataExtent = visualMapModel.getExtent();
  56624. // For hover link show when hover handle, which might be below or upper than sizeExtent.
  56625. cursorPos = mathMin(mathMax(sizeExtent[0], cursorPos), sizeExtent[1]);
  56626. var halfHoverLinkSize = getHalfHoverLinkSize(visualMapModel, dataExtent, sizeExtent);
  56627. var hoverRange = [cursorPos - halfHoverLinkSize, cursorPos + halfHoverLinkSize];
  56628. var cursorValue = linearMap(cursorPos, sizeExtent, dataExtent, true);
  56629. var valueRange = [
  56630. linearMap(hoverRange[0], sizeExtent, dataExtent, true),
  56631. linearMap(hoverRange[1], sizeExtent, dataExtent, true)
  56632. ];
  56633. // Consider data range is out of visualMap range, see test/visualMap-continuous.html,
  56634. // where china and india has very large population.
  56635. hoverRange[0] < sizeExtent[0] && (valueRange[0] = -Infinity);
  56636. hoverRange[1] > sizeExtent[1] && (valueRange[1] = Infinity);
  56637. // Do not show indicator when mouse is over handle,
  56638. // otherwise labels overlap, especially when dragging.
  56639. if (hoverOnBar) {
  56640. if (valueRange[0] === -Infinity) {
  56641. this._showIndicator(cursorValue, valueRange[1], '< ', halfHoverLinkSize);
  56642. }
  56643. else if (valueRange[1] === Infinity) {
  56644. this._showIndicator(cursorValue, valueRange[0], '> ', halfHoverLinkSize);
  56645. }
  56646. else {
  56647. this._showIndicator(cursorValue, cursorValue, '≈ ', halfHoverLinkSize);
  56648. }
  56649. }
  56650. // When realtime is set as false, handles, which are in barGroup,
  56651. // also trigger hoverLink, which help user to realize where they
  56652. // focus on when dragging. (see test/heatmap-large.html)
  56653. // When realtime is set as true, highlight will not show when hover
  56654. // handle, because the label on handle, which displays a exact value
  56655. // but not range, might mislead users.
  56656. var oldBatch = this._hoverLinkDataIndices;
  56657. var newBatch = [];
  56658. if (hoverOnBar || useHoverLinkOnHandle(visualMapModel)) {
  56659. newBatch = this._hoverLinkDataIndices = visualMapModel.findTargetDataIndices(valueRange);
  56660. }
  56661. var resultBatches = modelUtil.compressBatches(oldBatch, newBatch);
  56662. this._dispatchHighDown('downplay', helper.convertDataIndex(resultBatches[0]));
  56663. this._dispatchHighDown('highlight', helper.convertDataIndex(resultBatches[1]));
  56664. },
  56665. /**
  56666. * @private
  56667. */
  56668. _hoverLinkFromSeriesMouseOver: function (e) {
  56669. var el = e.target;
  56670. var visualMapModel = this.visualMapModel;
  56671. if (!el || el.dataIndex == null) {
  56672. return;
  56673. }
  56674. var dataModel = this.ecModel.getSeriesByIndex(el.seriesIndex);
  56675. if (!visualMapModel.isTargetSeries(dataModel)) {
  56676. return;
  56677. }
  56678. var data = dataModel.getData(el.dataType);
  56679. var dim = data.getDimension(visualMapModel.getDataDimension(data));
  56680. var value = data.get(dim, el.dataIndex, true);
  56681. if (!isNaN(value)) {
  56682. this._showIndicator(value, value);
  56683. }
  56684. },
  56685. /**
  56686. * @private
  56687. */
  56688. _hideIndicator: function () {
  56689. var shapes = this._shapes;
  56690. shapes.indicator && shapes.indicator.attr('invisible', true);
  56691. shapes.indicatorLabel && shapes.indicatorLabel.attr('invisible', true);
  56692. },
  56693. /**
  56694. * @private
  56695. */
  56696. _clearHoverLinkToSeries: function () {
  56697. this._hideIndicator();
  56698. var indices = this._hoverLinkDataIndices;
  56699. this._dispatchHighDown('downplay', helper.convertDataIndex(indices));
  56700. indices.length = 0;
  56701. },
  56702. /**
  56703. * @private
  56704. */
  56705. _clearHoverLinkFromSeries: function () {
  56706. this._hideIndicator();
  56707. var zr = this.api.getZr();
  56708. zr.off('mouseover', this._hoverLinkFromSeriesMouseOver);
  56709. zr.off('mouseout', this._hideIndicator);
  56710. },
  56711. /**
  56712. * @private
  56713. */
  56714. _applyTransform: function (vertex, element, inverse, global) {
  56715. var transform = graphic.getTransform(element, global ? null : this.group);
  56716. return graphic[
  56717. zrUtil.isArray(vertex) ? 'applyTransform' : 'transformDirection'
  56718. ](vertex, transform, inverse);
  56719. },
  56720. /**
  56721. * @private
  56722. */
  56723. _dispatchHighDown: function (type, batch) {
  56724. batch && batch.length && this.api.dispatchAction({
  56725. type: type,
  56726. batch: batch
  56727. });
  56728. },
  56729. /**
  56730. * @override
  56731. */
  56732. dispose: function () {
  56733. this._clearHoverLinkFromSeries();
  56734. this._clearHoverLinkToSeries();
  56735. },
  56736. /**
  56737. * @override
  56738. */
  56739. remove: function () {
  56740. this._clearHoverLinkFromSeries();
  56741. this._clearHoverLinkToSeries();
  56742. }
  56743. });
  56744. function createPolygon(points, cursor, onDrift, onDragEnd) {
  56745. return new graphic.Polygon({
  56746. shape: {points: points},
  56747. draggable: !!onDrift,
  56748. cursor: cursor,
  56749. drift: onDrift,
  56750. onmousemove: function (e) {
  56751. // Fot mobile devicem, prevent screen slider on the button.
  56752. eventTool.stop(e.event);
  56753. },
  56754. ondragend: onDragEnd
  56755. });
  56756. }
  56757. function createHandlePoints(handleIndex, textSize) {
  56758. return handleIndex === 0
  56759. ? [[0, 0], [textSize, 0], [textSize, -textSize]]
  56760. : [[0, 0], [textSize, 0], [textSize, textSize]];
  56761. }
  56762. function createIndicatorPoints(isRange, halfHoverLinkSize, pos, extentMax) {
  56763. return isRange
  56764. ? [ // indicate range
  56765. [0, -mathMin(halfHoverLinkSize, mathMax(pos, 0))],
  56766. [HOVER_LINK_OUT, 0],
  56767. [0, mathMin(halfHoverLinkSize, mathMax(extentMax - pos, 0))]
  56768. ]
  56769. : [ // indicate single value
  56770. [0, 0], [5, -5], [5, 5]
  56771. ];
  56772. }
  56773. function getHalfHoverLinkSize(visualMapModel, dataExtent, sizeExtent) {
  56774. var halfHoverLinkSize = HOVER_LINK_SIZE / 2;
  56775. var hoverLinkDataSize = visualMapModel.get('hoverLinkDataSize');
  56776. if (hoverLinkDataSize) {
  56777. halfHoverLinkSize = linearMap(hoverLinkDataSize, dataExtent, sizeExtent, true) / 2;
  56778. }
  56779. return halfHoverLinkSize;
  56780. }
  56781. function useHoverLinkOnHandle(visualMapModel) {
  56782. return !visualMapModel.get('realtime') && visualMapModel.get('hoverLinkOnHandle');
  56783. }
  56784. module.exports = ContinuousView;
  56785. /***/ },
  56786. /* 384 */
  56787. /***/ function(module, exports, __webpack_require__) {
  56788. var zrUtil = __webpack_require__(4);
  56789. var graphic = __webpack_require__(18);
  56790. var formatUtil = __webpack_require__(6);
  56791. var layout = __webpack_require__(71);
  56792. var echarts = __webpack_require__(1);
  56793. var VisualMapping = __webpack_require__(202);
  56794. module.exports = echarts.extendComponentView({
  56795. type: 'visualMap',
  56796. /**
  56797. * @readOnly
  56798. * @type {Object}
  56799. */
  56800. autoPositionValues: {left: 1, right: 1, top: 1, bottom: 1},
  56801. init: function (ecModel, api) {
  56802. /**
  56803. * @readOnly
  56804. * @type {module:echarts/model/Global}
  56805. */
  56806. this.ecModel = ecModel;
  56807. /**
  56808. * @readOnly
  56809. * @type {module:echarts/ExtensionAPI}
  56810. */
  56811. this.api = api;
  56812. /**
  56813. * @readOnly
  56814. * @type {module:echarts/component/visualMap/visualMapModel}
  56815. */
  56816. this.visualMapModel;
  56817. },
  56818. /**
  56819. * @protected
  56820. */
  56821. render: function (visualMapModel, ecModel, api, payload) {
  56822. this.visualMapModel = visualMapModel;
  56823. if (visualMapModel.get('show') === false) {
  56824. this.group.removeAll();
  56825. return;
  56826. }
  56827. this.doRender.apply(this, arguments);
  56828. },
  56829. /**
  56830. * @protected
  56831. */
  56832. renderBackground: function (group) {
  56833. var visualMapModel = this.visualMapModel;
  56834. var padding = formatUtil.normalizeCssArray(visualMapModel.get('padding') || 0);
  56835. var rect = group.getBoundingRect();
  56836. group.add(new graphic.Rect({
  56837. z2: -1, // Lay background rect on the lowest layer.
  56838. silent: true,
  56839. shape: {
  56840. x: rect.x - padding[3],
  56841. y: rect.y - padding[0],
  56842. width: rect.width + padding[3] + padding[1],
  56843. height: rect.height + padding[0] + padding[2]
  56844. },
  56845. style: {
  56846. fill: visualMapModel.get('backgroundColor'),
  56847. stroke: visualMapModel.get('borderColor'),
  56848. lineWidth: visualMapModel.get('borderWidth')
  56849. }
  56850. }));
  56851. },
  56852. /**
  56853. * @protected
  56854. * @param {number} targetValue can be Infinity or -Infinity
  56855. * @param {string=} visualCluster Only can be 'color' 'opacity' 'symbol' 'symbolSize'
  56856. * @param {Object} [opts]
  56857. * @param {string=} [opts.forceState] Specify state, instead of using getValueState method.
  56858. * @param {string=} [opts.convertOpacityToAlpha=false] For color gradient in controller widget.
  56859. * @return {*} Visual value.
  56860. */
  56861. getControllerVisual: function (targetValue, visualCluster, opts) {
  56862. opts = opts || {};
  56863. var forceState = opts.forceState;
  56864. var visualMapModel = this.visualMapModel;
  56865. var visualObj = {};
  56866. // Default values.
  56867. if (visualCluster === 'symbol') {
  56868. visualObj.symbol = visualMapModel.get('itemSymbol');
  56869. }
  56870. if (visualCluster === 'color') {
  56871. var defaultColor = visualMapModel.get('contentColor');
  56872. visualObj.color = defaultColor;
  56873. }
  56874. function getter(key) {
  56875. return visualObj[key];
  56876. }
  56877. function setter(key, value) {
  56878. visualObj[key] = value;
  56879. }
  56880. var mappings = visualMapModel.controllerVisuals[
  56881. forceState || visualMapModel.getValueState(targetValue)
  56882. ];
  56883. var visualTypes = VisualMapping.prepareVisualTypes(mappings);
  56884. zrUtil.each(visualTypes, function (type) {
  56885. var visualMapping = mappings[type];
  56886. if (opts.convertOpacityToAlpha && type === 'opacity') {
  56887. type = 'colorAlpha';
  56888. visualMapping = mappings.__alphaForOpacity;
  56889. }
  56890. if (VisualMapping.dependsOn(type, visualCluster)) {
  56891. visualMapping && visualMapping.applyVisual(
  56892. targetValue, getter, setter
  56893. );
  56894. }
  56895. });
  56896. return visualObj[visualCluster];
  56897. },
  56898. /**
  56899. * @protected
  56900. */
  56901. positionGroup: function (group) {
  56902. var model = this.visualMapModel;
  56903. var api = this.api;
  56904. layout.positionElement(
  56905. group,
  56906. model.getBoxLayoutParams(),
  56907. {width: api.getWidth(), height: api.getHeight()}
  56908. );
  56909. },
  56910. /**
  56911. * @protected
  56912. * @abstract
  56913. */
  56914. doRender: zrUtil.noop
  56915. });
  56916. /***/ },
  56917. /* 385 */
  56918. /***/ function(module, exports, __webpack_require__) {
  56919. var zrUtil = __webpack_require__(4);
  56920. var layout = __webpack_require__(71);
  56921. var helper = {
  56922. /**
  56923. * @param {module:echarts/component/visualMap/VisualMapModel} visualMapModel\
  56924. * @param {module:echarts/ExtensionAPI} api
  56925. * @param {Array.<number>} itemSize always [short, long]
  56926. * @return {string} 'left' or 'right' or 'top' or 'bottom'
  56927. */
  56928. getItemAlign: function (visualMapModel, api, itemSize) {
  56929. var modelOption = visualMapModel.option;
  56930. var itemAlign = modelOption.align;
  56931. if (itemAlign != null && itemAlign !== 'auto') {
  56932. return itemAlign;
  56933. }
  56934. // Auto decision align.
  56935. var ecSize = {width: api.getWidth(), height: api.getHeight()};
  56936. var realIndex = modelOption.orient === 'horizontal' ? 1 : 0;
  56937. var paramsSet = [
  56938. ['left', 'right', 'width'],
  56939. ['top', 'bottom', 'height']
  56940. ];
  56941. var reals = paramsSet[realIndex];
  56942. var fakeValue = [0, null, 10];
  56943. var layoutInput = {};
  56944. for (var i = 0; i < 3; i++) {
  56945. layoutInput[paramsSet[1 - realIndex][i]] = fakeValue[i];
  56946. layoutInput[reals[i]] = i === 2 ? itemSize[0] : modelOption[reals[i]];
  56947. }
  56948. var rParam = [['x', 'width', 3], ['y', 'height', 0]][realIndex];
  56949. var rect = layout.getLayoutRect(layoutInput, ecSize, modelOption.padding);
  56950. return reals[
  56951. (rect.margin[rParam[2]] || 0) + rect[rParam[0]] + rect[rParam[1]] * 0.5
  56952. < ecSize[rParam[1]] * 0.5 ? 0 : 1
  56953. ];
  56954. },
  56955. /**
  56956. * Prepare dataIndex for outside usage, where dataIndex means rawIndex, and
  56957. * dataIndexInside means filtered index.
  56958. */
  56959. convertDataIndex: function (batch) {
  56960. zrUtil.each(batch || [], function (batchItem) {
  56961. if (batch.dataIndex != null) {
  56962. batch.dataIndexInside = batch.dataIndex;
  56963. batch.dataIndex = null;
  56964. }
  56965. });
  56966. return batch;
  56967. }
  56968. };
  56969. module.exports = helper;
  56970. /***/ },
  56971. /* 386 */
  56972. /***/ function(module, exports, __webpack_require__) {
  56973. /**
  56974. * @file Data range action
  56975. */
  56976. var echarts = __webpack_require__(1);
  56977. var actionInfo = {
  56978. type: 'selectDataRange',
  56979. event: 'dataRangeSelected',
  56980. // FIXME use updateView appears wrong
  56981. update: 'update'
  56982. };
  56983. echarts.registerAction(actionInfo, function (payload, ecModel) {
  56984. ecModel.eachComponent({mainType: 'visualMap', query: payload}, function (model) {
  56985. model.setSelected(payload.selected);
  56986. });
  56987. });
  56988. /***/ },
  56989. /* 387 */
  56990. /***/ function(module, exports, __webpack_require__) {
  56991. /**
  56992. * DataZoom component entry
  56993. */
  56994. __webpack_require__(1).registerPreprocessor(
  56995. __webpack_require__(377)
  56996. );
  56997. __webpack_require__(378);
  56998. __webpack_require__(379);
  56999. __webpack_require__(388);
  57000. __webpack_require__(389);
  57001. __webpack_require__(386);
  57002. /***/ },
  57003. /* 388 */
  57004. /***/ function(module, exports, __webpack_require__) {
  57005. var VisualMapModel = __webpack_require__(381);
  57006. var zrUtil = __webpack_require__(4);
  57007. var VisualMapping = __webpack_require__(202);
  57008. var visualDefault = __webpack_require__(382);
  57009. var reformIntervals = __webpack_require__(7).reformIntervals;
  57010. var PiecewiseModel = VisualMapModel.extend({
  57011. type: 'visualMap.piecewise',
  57012. /**
  57013. * Order Rule:
  57014. *
  57015. * option.categories / option.pieces / option.text / option.selected:
  57016. * If !option.inverse,
  57017. * Order when vertical: ['top', ..., 'bottom'].
  57018. * Order when horizontal: ['left', ..., 'right'].
  57019. * If option.inverse, the meaning of
  57020. * the order should be reversed.
  57021. *
  57022. * this._pieceList:
  57023. * The order is always [low, ..., high].
  57024. *
  57025. * Mapping from location to low-high:
  57026. * If !option.inverse
  57027. * When vertical, top is high.
  57028. * When horizontal, right is high.
  57029. * If option.inverse, reverse.
  57030. */
  57031. /**
  57032. * @protected
  57033. */
  57034. defaultOption: {
  57035. selected: null, // Object. If not specified, means selected.
  57036. // When pieces and splitNumber: {'0': true, '5': true}
  57037. // When categories: {'cate1': false, 'cate3': true}
  57038. // When selected === false, means all unselected.
  57039. minOpen: false, // Whether include values that smaller than `min`.
  57040. maxOpen: false, // Whether include values that bigger than `max`.
  57041. align: 'auto', // 'auto', 'left', 'right'
  57042. itemWidth: 20, // When put the controller vertically, it is the length of
  57043. // horizontal side of each item. Otherwise, vertical side.
  57044. itemHeight: 14, // When put the controller vertically, it is the length of
  57045. // vertical side of each item. Otherwise, horizontal side.
  57046. itemSymbol: 'roundRect',
  57047. pieceList: null, // Each item is Object, with some of those attrs:
  57048. // {min, max, lt, gt, lte, gte, value,
  57049. // color, colorSaturation, colorAlpha, opacity,
  57050. // symbol, symbolSize}, which customize the range or visual
  57051. // coding of the certain piece. Besides, see "Order Rule".
  57052. categories: null, // category names, like: ['some1', 'some2', 'some3'].
  57053. // Attr min/max are ignored when categories set. See "Order Rule"
  57054. splitNumber: 5, // If set to 5, auto split five pieces equally.
  57055. // If set to 0 and component type not set, component type will be
  57056. // determined as "continuous". (It is less reasonable but for ec2
  57057. // compatibility, see echarts/component/visualMap/typeDefaulter)
  57058. selectedMode: 'multiple', // Can be 'multiple' or 'single'.
  57059. itemGap: 10, // The gap between two items, in px.
  57060. hoverLink: true, // Enable hover highlight.
  57061. showLabel: null // By default, when text is used, label will hide (the logic
  57062. // is remained for compatibility reason)
  57063. },
  57064. /**
  57065. * @override
  57066. */
  57067. optionUpdated: function (newOption, isInit) {
  57068. PiecewiseModel.superApply(this, 'optionUpdated', arguments);
  57069. /**
  57070. * The order is always [low, ..., high].
  57071. * [{text: string, interval: Array.<number>}, ...]
  57072. * @private
  57073. * @type {Array.<Object>}
  57074. */
  57075. this._pieceList = [];
  57076. this.resetTargetSeries();
  57077. this.resetExtent();
  57078. /**
  57079. * 'pieces', 'categories', 'splitNumber'
  57080. * @type {string}
  57081. */
  57082. var mode = this._mode = this._determineMode();
  57083. resetMethods[this._mode].call(this);
  57084. this._resetSelected(newOption, isInit);
  57085. var categories = this.option.categories;
  57086. this.resetVisual(function (mappingOption, state) {
  57087. if (mode === 'categories') {
  57088. mappingOption.mappingMethod = 'category';
  57089. mappingOption.categories = zrUtil.clone(categories);
  57090. }
  57091. else {
  57092. mappingOption.dataExtent = this.getExtent();
  57093. mappingOption.mappingMethod = 'piecewise';
  57094. mappingOption.pieceList = zrUtil.map(this._pieceList, function (piece) {
  57095. var piece = zrUtil.clone(piece);
  57096. if (state !== 'inRange') {
  57097. // FIXME
  57098. // outOfRange do not support special visual in pieces.
  57099. piece.visual = null;
  57100. }
  57101. return piece;
  57102. });
  57103. }
  57104. });
  57105. },
  57106. /**
  57107. * @protected
  57108. * @override
  57109. */
  57110. completeVisualOption: function () {
  57111. // Consider this case:
  57112. // visualMap: {
  57113. // pieces: [{symbol: 'circle', lt: 0}, {symbol: 'rect', gte: 0}]
  57114. // }
  57115. // where no inRange/outOfRange set but only pieces. So we should make
  57116. // default inRange/outOfRange for this case, otherwise visuals that only
  57117. // appear in `pieces` will not be taken into account in visual encoding.
  57118. var option = this.option;
  57119. var visualTypesInPieces = {};
  57120. var visualTypes = VisualMapping.listVisualTypes();
  57121. var isCategory = this.isCategory();
  57122. zrUtil.each(option.pieces, function (piece) {
  57123. zrUtil.each(visualTypes, function (visualType) {
  57124. if (piece.hasOwnProperty(visualType)) {
  57125. visualTypesInPieces[visualType] = 1;
  57126. }
  57127. });
  57128. });
  57129. zrUtil.each(visualTypesInPieces, function (v, visualType) {
  57130. var exists = 0;
  57131. zrUtil.each(this.stateList, function (state) {
  57132. exists |= has(option, state, visualType)
  57133. || has(option.target, state, visualType);
  57134. }, this);
  57135. !exists && zrUtil.each(this.stateList, function (state) {
  57136. (option[state] || (option[state] = {}))[visualType] = visualDefault.get(
  57137. visualType, state === 'inRange' ? 'active' : 'inactive', isCategory
  57138. );
  57139. });
  57140. }, this);
  57141. function has(obj, state, visualType) {
  57142. return obj && obj[state] && (
  57143. zrUtil.isObject(obj[state])
  57144. ? obj[state].hasOwnProperty(visualType)
  57145. : obj[state] === visualType // e.g., inRange: 'symbol'
  57146. );
  57147. }
  57148. VisualMapModel.prototype.completeVisualOption.apply(this, arguments);
  57149. },
  57150. _resetSelected: function (newOption, isInit) {
  57151. var thisOption = this.option;
  57152. var pieceList = this._pieceList;
  57153. // Selected do not merge but all override.
  57154. var selected = (isInit ? thisOption : newOption).selected || {};
  57155. thisOption.selected = selected;
  57156. // Consider 'not specified' means true.
  57157. zrUtil.each(pieceList, function (piece, index) {
  57158. var key = this.getSelectedMapKey(piece);
  57159. if (!selected.hasOwnProperty(key)) {
  57160. selected[key] = true;
  57161. }
  57162. }, this);
  57163. if (thisOption.selectedMode === 'single') {
  57164. // Ensure there is only one selected.
  57165. var hasSel = false;
  57166. zrUtil.each(pieceList, function (piece, index) {
  57167. var key = this.getSelectedMapKey(piece);
  57168. if (selected[key]) {
  57169. hasSel
  57170. ? (selected[key] = false)
  57171. : (hasSel = true);
  57172. }
  57173. }, this);
  57174. }
  57175. // thisOption.selectedMode === 'multiple', default: all selected.
  57176. },
  57177. /**
  57178. * @public
  57179. */
  57180. getSelectedMapKey: function (piece) {
  57181. return this._mode === 'categories'
  57182. ? piece.value + '' : piece.index + '';
  57183. },
  57184. /**
  57185. * @public
  57186. */
  57187. getPieceList: function () {
  57188. return this._pieceList;
  57189. },
  57190. /**
  57191. * @private
  57192. * @return {string}
  57193. */
  57194. _determineMode: function () {
  57195. var option = this.option;
  57196. return option.pieces && option.pieces.length > 0
  57197. ? 'pieces'
  57198. : this.option.categories
  57199. ? 'categories'
  57200. : 'splitNumber';
  57201. },
  57202. /**
  57203. * @public
  57204. * @override
  57205. */
  57206. setSelected: function (selected) {
  57207. this.option.selected = zrUtil.clone(selected);
  57208. },
  57209. /**
  57210. * @public
  57211. * @override
  57212. */
  57213. getValueState: function (value) {
  57214. var index = VisualMapping.findPieceIndex(value, this._pieceList);
  57215. return index != null
  57216. ? (this.option.selected[this.getSelectedMapKey(this._pieceList[index])]
  57217. ? 'inRange' : 'outOfRange'
  57218. )
  57219. : 'outOfRange';
  57220. },
  57221. /**
  57222. * @public
  57223. * @params {number} pieceIndex piece index in visualMapModel.getPieceList()
  57224. * @return {Array.<Object>} [{seriesId, dataIndices: <Array.<number>>}, ...]
  57225. */
  57226. findTargetDataIndices: function (pieceIndex) {
  57227. var result = [];
  57228. this.eachTargetSeries(function (seriesModel) {
  57229. var dataIndices = [];
  57230. var data = seriesModel.getData();
  57231. data.each(this.getDataDimension(data), function (value, dataIndex) {
  57232. // Should always base on model pieceList, because it is order sensitive.
  57233. var pIdx = VisualMapping.findPieceIndex(value, this._pieceList);
  57234. pIdx === pieceIndex && dataIndices.push(dataIndex);
  57235. }, true, this);
  57236. result.push({seriesId: seriesModel.id, dataIndex: dataIndices});
  57237. }, this);
  57238. return result;
  57239. },
  57240. /**
  57241. * @private
  57242. * @param {Object} piece piece.value or piece.interval is required.
  57243. * @return {number} Can be Infinity or -Infinity
  57244. */
  57245. getRepresentValue: function (piece) {
  57246. var representValue;
  57247. if (this.isCategory()) {
  57248. representValue = piece.value;
  57249. }
  57250. else {
  57251. if (piece.value != null) {
  57252. representValue = piece.value;
  57253. }
  57254. else {
  57255. var pieceInterval = piece.interval || [];
  57256. representValue = (pieceInterval[0] === -Infinity && pieceInterval[1] === Infinity)
  57257. ? 0
  57258. : (pieceInterval[0] + pieceInterval[1]) / 2;
  57259. }
  57260. }
  57261. return representValue;
  57262. },
  57263. getVisualMeta: function (getColorVisual) {
  57264. // Do not support category. (category axis is ordinal, numerical)
  57265. if (this.isCategory()) {
  57266. return;
  57267. }
  57268. var stops = [];
  57269. var outerColors = [];
  57270. var visualMapModel = this;
  57271. function setStop(interval, valueState) {
  57272. var representValue = visualMapModel.getRepresentValue({interval: interval});
  57273. if (!valueState) {
  57274. valueState = visualMapModel.getValueState(representValue);
  57275. }
  57276. var color = getColorVisual(representValue, valueState);
  57277. if (interval[0] === -Infinity) {
  57278. outerColors[0] = color;
  57279. }
  57280. else if (interval[1] === Infinity) {
  57281. outerColors[1] = color;
  57282. }
  57283. else {
  57284. stops.push(
  57285. {value: interval[0], color: color},
  57286. {value: interval[1], color: color}
  57287. );
  57288. }
  57289. }
  57290. // Suplement
  57291. var pieceList = this._pieceList.slice();
  57292. if (!pieceList.length) {
  57293. pieceList.push({interval: [-Infinity, Infinity]});
  57294. }
  57295. else {
  57296. var edge = pieceList[0].interval[0];
  57297. edge !== -Infinity && pieceList.unshift({interval: [-Infinity, edge]});
  57298. edge = pieceList[pieceList.length - 1].interval[1];
  57299. edge !== Infinity && pieceList.push({interval: [edge, Infinity]});
  57300. }
  57301. var curr = -Infinity;
  57302. zrUtil.each(pieceList, function (piece) {
  57303. var interval = piece.interval;
  57304. if (interval) {
  57305. // Fulfill gap.
  57306. interval[0] > curr && setStop([curr, interval[0]], 'outOfRange');
  57307. setStop(interval.slice());
  57308. curr = interval[1];
  57309. }
  57310. }, this);
  57311. return {stops: stops, outerColors: outerColors};
  57312. }
  57313. });
  57314. /**
  57315. * Key is this._mode
  57316. * @type {Object}
  57317. * @this {module:echarts/component/viusalMap/PiecewiseMode}
  57318. */
  57319. var resetMethods = {
  57320. splitNumber: function () {
  57321. var thisOption = this.option;
  57322. var pieceList = this._pieceList;
  57323. var precision = thisOption.precision;
  57324. var dataExtent = this.getExtent();
  57325. var splitNumber = thisOption.splitNumber;
  57326. splitNumber = Math.max(parseInt(splitNumber, 10), 1);
  57327. thisOption.splitNumber = splitNumber;
  57328. var splitStep = (dataExtent[1] - dataExtent[0]) / splitNumber;
  57329. // Precision auto-adaption
  57330. while (+splitStep.toFixed(precision) !== splitStep && precision < 5) {
  57331. precision++;
  57332. }
  57333. thisOption.precision = precision;
  57334. splitStep = +splitStep.toFixed(precision);
  57335. var index = 0;
  57336. if (thisOption.minOpen) {
  57337. pieceList.push({
  57338. index: index++,
  57339. interval: [-Infinity, dataExtent[0]],
  57340. close: [0, 0]
  57341. });
  57342. }
  57343. for (
  57344. var curr = dataExtent[0], len = index + splitNumber;
  57345. index < len;
  57346. curr += splitStep
  57347. ) {
  57348. var max = index === splitNumber - 1 ? dataExtent[1] : (curr + splitStep);
  57349. pieceList.push({
  57350. index: index++,
  57351. interval: [curr, max],
  57352. close: [1, 1]
  57353. });
  57354. }
  57355. if (thisOption.maxOpen) {
  57356. pieceList.push({
  57357. index: index++,
  57358. interval: [dataExtent[1], Infinity],
  57359. close: [0, 0]
  57360. });
  57361. }
  57362. reformIntervals(pieceList);
  57363. zrUtil.each(pieceList, function (piece) {
  57364. piece.text = this.formatValueText(piece.interval);
  57365. }, this);
  57366. },
  57367. categories: function () {
  57368. var thisOption = this.option;
  57369. zrUtil.each(thisOption.categories, function (cate) {
  57370. // FIXME category模式也使用pieceList,但在visualMapping中不是使用pieceList。
  57371. // 是否改一致。
  57372. this._pieceList.push({
  57373. text: this.formatValueText(cate, true),
  57374. value: cate
  57375. });
  57376. }, this);
  57377. // See "Order Rule".
  57378. normalizeReverse(thisOption, this._pieceList);
  57379. },
  57380. pieces: function () {
  57381. var thisOption = this.option;
  57382. var pieceList = this._pieceList;
  57383. zrUtil.each(thisOption.pieces, function (pieceListItem, index) {
  57384. if (!zrUtil.isObject(pieceListItem)) {
  57385. pieceListItem = {value: pieceListItem};
  57386. }
  57387. var item = {text: '', index: index};
  57388. if (pieceListItem.label != null) {
  57389. item.text = pieceListItem.label;
  57390. }
  57391. if (pieceListItem.hasOwnProperty('value')) {
  57392. var value = item.value = pieceListItem.value;
  57393. item.interval = [value, value];
  57394. item.close = [1, 1];
  57395. }
  57396. else {
  57397. // `min` `max` is legacy option.
  57398. // `lt` `gt` `lte` `gte` is recommanded.
  57399. var interval = item.interval = [];
  57400. var close = item.close = [0, 0];
  57401. var closeList = [1, 0, 1];
  57402. var infinityList = [-Infinity, Infinity];
  57403. var useMinMax = [];
  57404. for (var lg = 0; lg < 2; lg++) {
  57405. var names = [['gte', 'gt', 'min'], ['lte', 'lt', 'max']][lg];
  57406. for (var i = 0; i < 3 && interval[lg] == null; i++) {
  57407. interval[lg] = pieceListItem[names[i]];
  57408. close[lg] = closeList[i];
  57409. useMinMax[lg] = i === 2;
  57410. }
  57411. interval[lg] == null && (interval[lg] = infinityList[lg]);
  57412. }
  57413. useMinMax[0] && interval[1] === Infinity && (close[0] = 0);
  57414. useMinMax[1] && interval[0] === -Infinity && (close[1] = 0);
  57415. if (true) {
  57416. if (interval[0] > interval[1]) {
  57417. console.warn(
  57418. 'Piece ' + index + 'is illegal: ' + interval
  57419. + ' lower bound should not greater then uppper bound.'
  57420. );
  57421. }
  57422. }
  57423. if (interval[0] === interval[1] && close[0] && close[1]) {
  57424. // Consider: [{min: 5, max: 5, visual: {...}}, {min: 0, max: 5}],
  57425. // we use value to lift the priority when min === max
  57426. item.value = interval[0];
  57427. }
  57428. }
  57429. item.visual = VisualMapping.retrieveVisuals(pieceListItem);
  57430. pieceList.push(item);
  57431. }, this);
  57432. // See "Order Rule".
  57433. normalizeReverse(thisOption, pieceList);
  57434. // Only pieces
  57435. reformIntervals(pieceList);
  57436. zrUtil.each(pieceList, function (piece) {
  57437. var close = piece.close;
  57438. var edgeSymbols = [['<', '≤'][close[1]], ['>', '≥'][close[0]]];
  57439. piece.text = piece.text || this.formatValueText(
  57440. piece.value != null ? piece.value : piece.interval,
  57441. false,
  57442. edgeSymbols
  57443. );
  57444. }, this);
  57445. }
  57446. };
  57447. function normalizeReverse(thisOption, pieceList) {
  57448. var inverse = thisOption.inverse;
  57449. if (thisOption.orient === 'vertical' ? !inverse : inverse) {
  57450. pieceList.reverse();
  57451. }
  57452. }
  57453. module.exports = PiecewiseModel;
  57454. /***/ },
  57455. /* 389 */
  57456. /***/ function(module, exports, __webpack_require__) {
  57457. var VisualMapView = __webpack_require__(384);
  57458. var zrUtil = __webpack_require__(4);
  57459. var graphic = __webpack_require__(18);
  57460. var symbolCreators = __webpack_require__(111);
  57461. var layout = __webpack_require__(71);
  57462. var helper = __webpack_require__(385);
  57463. var PiecewiseVisualMapView = VisualMapView.extend({
  57464. type: 'visualMap.piecewise',
  57465. /**
  57466. * @protected
  57467. * @override
  57468. */
  57469. doRender: function () {
  57470. var thisGroup = this.group;
  57471. thisGroup.removeAll();
  57472. var visualMapModel = this.visualMapModel;
  57473. var textGap = visualMapModel.get('textGap');
  57474. var textStyleModel = visualMapModel.textStyleModel;
  57475. var textFont = textStyleModel.getFont();
  57476. var textFill = textStyleModel.getTextColor();
  57477. var itemAlign = this._getItemAlign();
  57478. var itemSize = visualMapModel.itemSize;
  57479. var viewData = this._getViewData();
  57480. var endsText = viewData.endsText;
  57481. var showLabel = zrUtil.retrieve(visualMapModel.get('showLabel', true), !endsText);
  57482. endsText && this._renderEndsText(
  57483. thisGroup, endsText[0], itemSize, showLabel, itemAlign
  57484. );
  57485. zrUtil.each(viewData.viewPieceList, renderItem, this);
  57486. endsText && this._renderEndsText(
  57487. thisGroup, endsText[1], itemSize, showLabel, itemAlign
  57488. );
  57489. layout.box(
  57490. visualMapModel.get('orient'), thisGroup, visualMapModel.get('itemGap')
  57491. );
  57492. this.renderBackground(thisGroup);
  57493. this.positionGroup(thisGroup);
  57494. function renderItem(item) {
  57495. var piece = item.piece;
  57496. var itemGroup = new graphic.Group();
  57497. itemGroup.onclick = zrUtil.bind(this._onItemClick, this, piece);
  57498. this._enableHoverLink(itemGroup, item.indexInModelPieceList);
  57499. var representValue = visualMapModel.getRepresentValue(piece);
  57500. this._createItemSymbol(
  57501. itemGroup, representValue, [0, 0, itemSize[0], itemSize[1]]
  57502. );
  57503. if (showLabel) {
  57504. var visualState = this.visualMapModel.getValueState(representValue);
  57505. itemGroup.add(new graphic.Text({
  57506. style: {
  57507. x: itemAlign === 'right' ? -textGap : itemSize[0] + textGap,
  57508. y: itemSize[1] / 2,
  57509. text: piece.text,
  57510. textVerticalAlign: 'middle',
  57511. textAlign: itemAlign,
  57512. textFont: textFont,
  57513. fill: textFill,
  57514. opacity: visualState === 'outOfRange' ? 0.5 : 1
  57515. }
  57516. }));
  57517. }
  57518. thisGroup.add(itemGroup);
  57519. }
  57520. },
  57521. /**
  57522. * @private
  57523. */
  57524. _enableHoverLink: function (itemGroup, pieceIndex) {
  57525. itemGroup
  57526. .on('mouseover', zrUtil.bind(onHoverLink, this, 'highlight'))
  57527. .on('mouseout', zrUtil.bind(onHoverLink, this, 'downplay'));
  57528. function onHoverLink(method) {
  57529. var visualMapModel = this.visualMapModel;
  57530. visualMapModel.option.hoverLink && this.api.dispatchAction({
  57531. type: method,
  57532. batch: helper.convertDataIndex(
  57533. visualMapModel.findTargetDataIndices(pieceIndex)
  57534. )
  57535. });
  57536. }
  57537. },
  57538. /**
  57539. * @private
  57540. */
  57541. _getItemAlign: function () {
  57542. var visualMapModel = this.visualMapModel;
  57543. var modelOption = visualMapModel.option;
  57544. if (modelOption.orient === 'vertical') {
  57545. return helper.getItemAlign(
  57546. visualMapModel, this.api, visualMapModel.itemSize
  57547. );
  57548. }
  57549. else { // horizontal, most case left unless specifying right.
  57550. var align = modelOption.align;
  57551. if (!align || align === 'auto') {
  57552. align = 'left';
  57553. }
  57554. return align;
  57555. }
  57556. },
  57557. /**
  57558. * @private
  57559. */
  57560. _renderEndsText: function (group, text, itemSize, showLabel, itemAlign) {
  57561. if (!text) {
  57562. return;
  57563. }
  57564. var itemGroup = new graphic.Group();
  57565. var textStyleModel = this.visualMapModel.textStyleModel;
  57566. itemGroup.add(new graphic.Text({
  57567. style: {
  57568. x: showLabel ? (itemAlign === 'right' ? itemSize[0] : 0) : itemSize[0] / 2,
  57569. y: itemSize[1] / 2,
  57570. textVerticalAlign: 'middle',
  57571. textAlign: showLabel ? itemAlign : 'center',
  57572. text: text,
  57573. textFont: textStyleModel.getFont(),
  57574. fill: textStyleModel.getTextColor()
  57575. }
  57576. }));
  57577. group.add(itemGroup);
  57578. },
  57579. /**
  57580. * @private
  57581. * @return {Object} {peiceList, endsText} The order is the same as screen pixel order.
  57582. */
  57583. _getViewData: function () {
  57584. var visualMapModel = this.visualMapModel;
  57585. var viewPieceList = zrUtil.map(visualMapModel.getPieceList(), function (piece, index) {
  57586. return {piece: piece, indexInModelPieceList: index};
  57587. });
  57588. var endsText = visualMapModel.get('text');
  57589. // Consider orient and inverse.
  57590. var orient = visualMapModel.get('orient');
  57591. var inverse = visualMapModel.get('inverse');
  57592. // Order of model pieceList is always [low, ..., high]
  57593. if (orient === 'horizontal' ? inverse : !inverse) {
  57594. viewPieceList.reverse();
  57595. }
  57596. // Origin order of endsText is [high, low]
  57597. else if (endsText) {
  57598. endsText = endsText.slice().reverse();
  57599. }
  57600. return {viewPieceList: viewPieceList, endsText: endsText};
  57601. },
  57602. /**
  57603. * @private
  57604. */
  57605. _createItemSymbol: function (group, representValue, shapeParam) {
  57606. group.add(symbolCreators.createSymbol(
  57607. this.getControllerVisual(representValue, 'symbol'),
  57608. shapeParam[0], shapeParam[1], shapeParam[2], shapeParam[3],
  57609. this.getControllerVisual(representValue, 'color')
  57610. ));
  57611. },
  57612. /**
  57613. * @private
  57614. */
  57615. _onItemClick: function (piece) {
  57616. var visualMapModel = this.visualMapModel;
  57617. var option = visualMapModel.option;
  57618. var selected = zrUtil.clone(option.selected);
  57619. var newKey = visualMapModel.getSelectedMapKey(piece);
  57620. if (option.selectedMode === 'single') {
  57621. selected[newKey] = true;
  57622. zrUtil.each(selected, function (o, key) {
  57623. selected[key] = key === newKey;
  57624. });
  57625. }
  57626. else {
  57627. selected[newKey] = !selected[newKey];
  57628. }
  57629. this.api.dispatchAction({
  57630. type: 'selectDataRange',
  57631. from: this.uid,
  57632. visualMapId: this.visualMapModel.id,
  57633. selected: selected
  57634. });
  57635. }
  57636. });
  57637. module.exports = PiecewiseVisualMapView;
  57638. /***/ },
  57639. /* 390 */
  57640. /***/ function(module, exports, __webpack_require__) {
  57641. // HINT Markpoint can't be used too much
  57642. __webpack_require__(391);
  57643. __webpack_require__(393);
  57644. __webpack_require__(1).registerPreprocessor(function (opt) {
  57645. // Make sure markPoint component is enabled
  57646. opt.markPoint = opt.markPoint || {};
  57647. });
  57648. /***/ },
  57649. /* 391 */
  57650. /***/ function(module, exports, __webpack_require__) {
  57651. module.exports = __webpack_require__(392).extend({
  57652. type: 'markPoint',
  57653. defaultOption: {
  57654. zlevel: 0,
  57655. z: 5,
  57656. symbol: 'pin',
  57657. symbolSize: 50,
  57658. //symbolRotate: 0,
  57659. //symbolOffset: [0, 0]
  57660. tooltip: {
  57661. trigger: 'item'
  57662. },
  57663. label: {
  57664. normal: {
  57665. show: true,
  57666. position: 'inside'
  57667. },
  57668. emphasis: {
  57669. show: true
  57670. }
  57671. },
  57672. itemStyle: {
  57673. normal: {
  57674. borderWidth: 2
  57675. }
  57676. }
  57677. }
  57678. });
  57679. /***/ },
  57680. /* 392 */
  57681. /***/ function(module, exports, __webpack_require__) {
  57682. var modelUtil = __webpack_require__(5);
  57683. var zrUtil = __webpack_require__(4);
  57684. var env = __webpack_require__(2);
  57685. var formatUtil = __webpack_require__(6);
  57686. var addCommas = formatUtil.addCommas;
  57687. var encodeHTML = formatUtil.encodeHTML;
  57688. function fillLabel(opt) {
  57689. modelUtil.defaultEmphasis(
  57690. opt.label,
  57691. modelUtil.LABEL_OPTIONS
  57692. );
  57693. }
  57694. var MarkerModel = __webpack_require__(1).extendComponentModel({
  57695. type: 'marker',
  57696. dependencies: ['series', 'grid', 'polar', 'geo'],
  57697. /**
  57698. * @overrite
  57699. */
  57700. init: function (option, parentModel, ecModel, extraOpt) {
  57701. if (true) {
  57702. if (this.type === 'marker') {
  57703. throw new Error('Marker component is abstract component. Use markLine, markPoint, markArea instead.');
  57704. }
  57705. }
  57706. this.mergeDefaultAndTheme(option, ecModel);
  57707. this.mergeOption(option, ecModel, extraOpt.createdBySelf, true);
  57708. },
  57709. /**
  57710. * @return {boolean}
  57711. */
  57712. isAnimationEnabled: function () {
  57713. if (env.node) {
  57714. return false;
  57715. }
  57716. var hostSeries = this.__hostSeries;
  57717. return this.getShallow('animation') && hostSeries && hostSeries.isAnimationEnabled();
  57718. },
  57719. mergeOption: function (newOpt, ecModel, createdBySelf, isInit) {
  57720. var MarkerModel = this.constructor;
  57721. var modelPropName = this.mainType + 'Model';
  57722. if (!createdBySelf) {
  57723. ecModel.eachSeries(function (seriesModel) {
  57724. var markerOpt = seriesModel.get(this.mainType);
  57725. var markerModel = seriesModel[modelPropName];
  57726. if (!markerOpt || !markerOpt.data) {
  57727. seriesModel[modelPropName] = null;
  57728. return;
  57729. }
  57730. if (!markerModel) {
  57731. if (isInit) {
  57732. // Default label emphasis `position` and `show`
  57733. fillLabel(markerOpt);
  57734. }
  57735. zrUtil.each(markerOpt.data, function (item) {
  57736. // FIXME Overwrite fillLabel method ?
  57737. if (item instanceof Array) {
  57738. fillLabel(item[0]);
  57739. fillLabel(item[1]);
  57740. }
  57741. else {
  57742. fillLabel(item);
  57743. }
  57744. });
  57745. markerModel = new MarkerModel(
  57746. markerOpt, this, ecModel
  57747. );
  57748. zrUtil.extend(markerModel, {
  57749. mainType: this.mainType,
  57750. // Use the same series index and name
  57751. seriesIndex: seriesModel.seriesIndex,
  57752. name: seriesModel.name,
  57753. createdBySelf: true
  57754. });
  57755. markerModel.__hostSeries = seriesModel;
  57756. }
  57757. else {
  57758. markerModel.mergeOption(markerOpt, ecModel, true);
  57759. }
  57760. seriesModel[modelPropName] = markerModel;
  57761. }, this);
  57762. }
  57763. },
  57764. formatTooltip: function (dataIndex) {
  57765. var data = this.getData();
  57766. var value = this.getRawValue(dataIndex);
  57767. var formattedValue = zrUtil.isArray(value)
  57768. ? zrUtil.map(value, addCommas).join(', ') : addCommas(value);
  57769. var name = data.getName(dataIndex);
  57770. var html = encodeHTML(this.name);
  57771. if (value != null || name) {
  57772. html += '<br />';
  57773. }
  57774. if (name) {
  57775. html += encodeHTML(name);
  57776. if (value != null) {
  57777. html += ' : ';
  57778. }
  57779. }
  57780. if (value != null) {
  57781. html += encodeHTML(formattedValue);
  57782. }
  57783. return html;
  57784. },
  57785. getData: function () {
  57786. return this._data;
  57787. },
  57788. setData: function (data) {
  57789. this._data = data;
  57790. }
  57791. });
  57792. zrUtil.mixin(MarkerModel, modelUtil.dataFormatMixin);
  57793. module.exports = MarkerModel;
  57794. /***/ },
  57795. /* 393 */
  57796. /***/ function(module, exports, __webpack_require__) {
  57797. var SymbolDraw = __webpack_require__(116);
  57798. var zrUtil = __webpack_require__(4);
  57799. var numberUtil = __webpack_require__(7);
  57800. var List = __webpack_require__(98);
  57801. var markerHelper = __webpack_require__(394);
  57802. function updateMarkerLayout(mpData, seriesModel, api) {
  57803. var coordSys = seriesModel.coordinateSystem;
  57804. mpData.each(function (idx) {
  57805. var itemModel = mpData.getItemModel(idx);
  57806. var point;
  57807. var xPx = numberUtil.parsePercent(itemModel.get('x'), api.getWidth());
  57808. var yPx = numberUtil.parsePercent(itemModel.get('y'), api.getHeight());
  57809. if (!isNaN(xPx) && !isNaN(yPx)) {
  57810. point = [xPx, yPx];
  57811. }
  57812. // Chart like bar may have there own marker positioning logic
  57813. else if (seriesModel.getMarkerPosition) {
  57814. // Use the getMarkerPoisition
  57815. point = seriesModel.getMarkerPosition(
  57816. mpData.getValues(mpData.dimensions, idx)
  57817. );
  57818. }
  57819. else if (coordSys) {
  57820. var x = mpData.get(coordSys.dimensions[0], idx);
  57821. var y = mpData.get(coordSys.dimensions[1], idx);
  57822. point = coordSys.dataToPoint([x, y]);
  57823. }
  57824. // Use x, y if has any
  57825. if (!isNaN(xPx)) {
  57826. point[0] = xPx;
  57827. }
  57828. if (!isNaN(yPx)) {
  57829. point[1] = yPx;
  57830. }
  57831. mpData.setItemLayout(idx, point);
  57832. });
  57833. }
  57834. __webpack_require__(395).extend({
  57835. type: 'markPoint',
  57836. updateLayout: function (markPointModel, ecModel, api) {
  57837. ecModel.eachSeries(function (seriesModel) {
  57838. var mpModel = seriesModel.markPointModel;
  57839. if (mpModel) {
  57840. updateMarkerLayout(mpModel.getData(), seriesModel, api);
  57841. this.markerGroupMap.get(seriesModel.name).updateLayout(mpModel);
  57842. }
  57843. }, this);
  57844. },
  57845. renderSeries: function (seriesModel, mpModel, ecModel, api) {
  57846. var coordSys = seriesModel.coordinateSystem;
  57847. var seriesName = seriesModel.name;
  57848. var seriesData = seriesModel.getData();
  57849. var symbolDrawMap = this.markerGroupMap;
  57850. var symbolDraw = symbolDrawMap.get(seriesName)
  57851. || symbolDrawMap.set(seriesName, new SymbolDraw());
  57852. var mpData = createList(coordSys, seriesModel, mpModel);
  57853. // FIXME
  57854. mpModel.setData(mpData);
  57855. updateMarkerLayout(mpModel.getData(), seriesModel, api);
  57856. mpData.each(function (idx) {
  57857. var itemModel = mpData.getItemModel(idx);
  57858. var symbolSize = itemModel.getShallow('symbolSize');
  57859. if (typeof symbolSize === 'function') {
  57860. // FIXME 这里不兼容 ECharts 2.x,2.x 貌似参数是整个数据?
  57861. symbolSize = symbolSize(
  57862. mpModel.getRawValue(idx), mpModel.getDataParams(idx)
  57863. );
  57864. }
  57865. mpData.setItemVisual(idx, {
  57866. symbolSize: symbolSize,
  57867. color: itemModel.get('itemStyle.normal.color')
  57868. || seriesData.getVisual('color'),
  57869. symbol: itemModel.getShallow('symbol')
  57870. });
  57871. });
  57872. // TODO Text are wrong
  57873. symbolDraw.updateData(mpData);
  57874. this.group.add(symbolDraw.group);
  57875. // Set host model for tooltip
  57876. // FIXME
  57877. mpData.eachItemGraphicEl(function (el) {
  57878. el.traverse(function (child) {
  57879. child.dataModel = mpModel;
  57880. });
  57881. });
  57882. symbolDraw.__keep = true;
  57883. symbolDraw.group.silent = mpModel.get('silent') || seriesModel.get('silent');
  57884. }
  57885. });
  57886. /**
  57887. * @inner
  57888. * @param {module:echarts/coord/*} [coordSys]
  57889. * @param {module:echarts/model/Series} seriesModel
  57890. * @param {module:echarts/model/Model} mpModel
  57891. */
  57892. function createList(coordSys, seriesModel, mpModel) {
  57893. var coordDimsInfos;
  57894. if (coordSys) {
  57895. coordDimsInfos = zrUtil.map(coordSys && coordSys.dimensions, function (coordDim) {
  57896. var info = seriesModel.getData().getDimensionInfo(
  57897. seriesModel.coordDimToDataDim(coordDim)[0]
  57898. ) || {}; // In map series data don't have lng and lat dimension. Fallback to same with coordSys
  57899. info.name = coordDim;
  57900. return info;
  57901. });
  57902. }
  57903. else {
  57904. coordDimsInfos =[{
  57905. name: 'value',
  57906. type: 'float'
  57907. }];
  57908. }
  57909. var mpData = new List(coordDimsInfos, mpModel);
  57910. var dataOpt = zrUtil.map(mpModel.get('data'), zrUtil.curry(
  57911. markerHelper.dataTransform, seriesModel
  57912. ));
  57913. if (coordSys) {
  57914. dataOpt = zrUtil.filter(
  57915. dataOpt, zrUtil.curry(markerHelper.dataFilter, coordSys)
  57916. );
  57917. }
  57918. mpData.initData(dataOpt, null,
  57919. coordSys ? markerHelper.dimValueGetter : function (item) {
  57920. return item.value;
  57921. }
  57922. );
  57923. return mpData;
  57924. }
  57925. /***/ },
  57926. /* 394 */
  57927. /***/ function(module, exports, __webpack_require__) {
  57928. var zrUtil = __webpack_require__(4);
  57929. var numberUtil = __webpack_require__(7);
  57930. var indexOf = zrUtil.indexOf;
  57931. function hasXOrY(item) {
  57932. return !(isNaN(parseFloat(item.x)) && isNaN(parseFloat(item.y)));
  57933. }
  57934. function hasXAndY(item) {
  57935. return !isNaN(parseFloat(item.x)) && !isNaN(parseFloat(item.y));
  57936. }
  57937. function getPrecision(data, valueAxisDim, dataIndex) {
  57938. var precision = -1;
  57939. do {
  57940. precision = Math.max(
  57941. numberUtil.getPrecision(data.get(
  57942. valueAxisDim, dataIndex
  57943. )),
  57944. precision
  57945. );
  57946. data = data.stackedOn;
  57947. } while (data);
  57948. return precision;
  57949. }
  57950. function markerTypeCalculatorWithExtent(
  57951. mlType, data, otherDataDim, targetDataDim, otherCoordIndex, targetCoordIndex
  57952. ) {
  57953. var coordArr = [];
  57954. var value = numCalculate(data, targetDataDim, mlType);
  57955. var dataIndex = data.indicesOfNearest(targetDataDim, value, true)[0];
  57956. coordArr[otherCoordIndex] = data.get(otherDataDim, dataIndex, true);
  57957. coordArr[targetCoordIndex] = data.get(targetDataDim, dataIndex, true);
  57958. var precision = getPrecision(data, targetDataDim, dataIndex);
  57959. if (precision >= 0) {
  57960. coordArr[targetCoordIndex] = +coordArr[targetCoordIndex].toFixed(precision);
  57961. }
  57962. return coordArr;
  57963. }
  57964. var curry = zrUtil.curry;
  57965. // TODO Specified percent
  57966. var markerTypeCalculator = {
  57967. /**
  57968. * @method
  57969. * @param {module:echarts/data/List} data
  57970. * @param {string} baseAxisDim
  57971. * @param {string} valueAxisDim
  57972. */
  57973. min: curry(markerTypeCalculatorWithExtent, 'min'),
  57974. /**
  57975. * @method
  57976. * @param {module:echarts/data/List} data
  57977. * @param {string} baseAxisDim
  57978. * @param {string} valueAxisDim
  57979. */
  57980. max: curry(markerTypeCalculatorWithExtent, 'max'),
  57981. /**
  57982. * @method
  57983. * @param {module:echarts/data/List} data
  57984. * @param {string} baseAxisDim
  57985. * @param {string} valueAxisDim
  57986. */
  57987. average: curry(markerTypeCalculatorWithExtent, 'average')
  57988. };
  57989. /**
  57990. * Transform markPoint data item to format used in List by do the following
  57991. * 1. Calculate statistic like `max`, `min`, `average`
  57992. * 2. Convert `item.xAxis`, `item.yAxis` to `item.coord` array
  57993. * @param {module:echarts/model/Series} seriesModel
  57994. * @param {module:echarts/coord/*} [coordSys]
  57995. * @param {Object} item
  57996. * @return {Object}
  57997. */
  57998. var dataTransform = function (seriesModel, item) {
  57999. var data = seriesModel.getData();
  58000. var coordSys = seriesModel.coordinateSystem;
  58001. // 1. If not specify the position with pixel directly
  58002. // 2. If `coord` is not a data array. Which uses `xAxis`,
  58003. // `yAxis` to specify the coord on each dimension
  58004. // parseFloat first because item.x and item.y can be percent string like '20%'
  58005. if (item && !hasXAndY(item) && !zrUtil.isArray(item.coord) && coordSys) {
  58006. var dims = coordSys.dimensions;
  58007. var axisInfo = getAxisInfo(item, data, coordSys, seriesModel);
  58008. // Clone the option
  58009. // Transform the properties xAxis, yAxis, radiusAxis, angleAxis, geoCoord to value
  58010. item = zrUtil.clone(item);
  58011. if (item.type
  58012. && markerTypeCalculator[item.type]
  58013. && axisInfo.baseAxis && axisInfo.valueAxis
  58014. ) {
  58015. var otherCoordIndex = indexOf(dims, axisInfo.baseAxis.dim);
  58016. var targetCoordIndex = indexOf(dims, axisInfo.valueAxis.dim);
  58017. item.coord = markerTypeCalculator[item.type](
  58018. data, axisInfo.baseDataDim, axisInfo.valueDataDim,
  58019. otherCoordIndex, targetCoordIndex
  58020. );
  58021. // Force to use the value of calculated value.
  58022. item.value = item.coord[targetCoordIndex];
  58023. }
  58024. else {
  58025. // FIXME Only has one of xAxis and yAxis.
  58026. var coord = [
  58027. item.xAxis != null ? item.xAxis : item.radiusAxis,
  58028. item.yAxis != null ? item.yAxis : item.angleAxis
  58029. ];
  58030. // Each coord support max, min, average
  58031. for (var i = 0; i < 2; i++) {
  58032. if (markerTypeCalculator[coord[i]]) {
  58033. var dataDim = seriesModel.coordDimToDataDim(dims[i])[0];
  58034. coord[i] = numCalculate(data, dataDim, coord[i]);
  58035. }
  58036. }
  58037. item.coord = coord;
  58038. }
  58039. }
  58040. return item;
  58041. };
  58042. var getAxisInfo = function (item, data, coordSys, seriesModel) {
  58043. var ret = {};
  58044. if (item.valueIndex != null || item.valueDim != null) {
  58045. ret.valueDataDim = item.valueIndex != null
  58046. ? data.getDimension(item.valueIndex) : item.valueDim;
  58047. ret.valueAxis = coordSys.getAxis(seriesModel.dataDimToCoordDim(ret.valueDataDim));
  58048. ret.baseAxis = coordSys.getOtherAxis(ret.valueAxis);
  58049. ret.baseDataDim = seriesModel.coordDimToDataDim(ret.baseAxis.dim)[0];
  58050. }
  58051. else {
  58052. ret.baseAxis = seriesModel.getBaseAxis();
  58053. ret.valueAxis = coordSys.getOtherAxis(ret.baseAxis);
  58054. ret.baseDataDim = seriesModel.coordDimToDataDim(ret.baseAxis.dim)[0];
  58055. ret.valueDataDim = seriesModel.coordDimToDataDim(ret.valueAxis.dim)[0];
  58056. }
  58057. return ret;
  58058. };
  58059. /**
  58060. * Filter data which is out of coordinateSystem range
  58061. * [dataFilter description]
  58062. * @param {module:echarts/coord/*} [coordSys]
  58063. * @param {Object} item
  58064. * @return {boolean}
  58065. */
  58066. var dataFilter = function (coordSys, item) {
  58067. // Alwalys return true if there is no coordSys
  58068. return (coordSys && coordSys.containData && item.coord && !hasXOrY(item))
  58069. ? coordSys.containData(item.coord) : true;
  58070. };
  58071. var dimValueGetter = function (item, dimName, dataIndex, dimIndex) {
  58072. // x, y, radius, angle
  58073. if (dimIndex < 2) {
  58074. return item.coord && item.coord[dimIndex];
  58075. }
  58076. return item.value;
  58077. };
  58078. var numCalculate = function (data, valueDataDim, type) {
  58079. if (type === 'average') {
  58080. var sum = 0;
  58081. var count = 0;
  58082. data.each(valueDataDim, function (val, idx) {
  58083. if (!isNaN(val)) {
  58084. sum += val;
  58085. count++;
  58086. }
  58087. }, true);
  58088. return sum / count;
  58089. }
  58090. else {
  58091. return data.getDataExtent(valueDataDim, true)[type === 'max' ? 1 : 0];
  58092. }
  58093. };
  58094. module.exports = {
  58095. dataTransform: dataTransform,
  58096. dataFilter: dataFilter,
  58097. dimValueGetter: dimValueGetter,
  58098. getAxisInfo: getAxisInfo,
  58099. numCalculate: numCalculate
  58100. };
  58101. /***/ },
  58102. /* 395 */
  58103. /***/ function(module, exports, __webpack_require__) {
  58104. var zrUtil = __webpack_require__(4);
  58105. module.exports = __webpack_require__(1).extendComponentView({
  58106. type: 'marker',
  58107. init: function () {
  58108. /**
  58109. * Markline grouped by series
  58110. * @private
  58111. * @type {module:zrender/core/util.HashMap}
  58112. */
  58113. this.markerGroupMap = zrUtil.createHashMap();
  58114. },
  58115. render: function (markerModel, ecModel, api) {
  58116. var markerGroupMap = this.markerGroupMap;
  58117. markerGroupMap.each(function (item) {
  58118. item.__keep = false;
  58119. });
  58120. var markerModelKey = this.type + 'Model';
  58121. ecModel.eachSeries(function (seriesModel) {
  58122. var markerModel = seriesModel[markerModelKey];
  58123. markerModel && this.renderSeries(seriesModel, markerModel, ecModel, api);
  58124. }, this);
  58125. markerGroupMap.each(function (item) {
  58126. !item.__keep && this.group.remove(item.group);
  58127. }, this);
  58128. },
  58129. renderSeries: function () {}
  58130. });
  58131. /***/ },
  58132. /* 396 */
  58133. /***/ function(module, exports, __webpack_require__) {
  58134. __webpack_require__(397);
  58135. __webpack_require__(398);
  58136. __webpack_require__(1).registerPreprocessor(function (opt) {
  58137. // Make sure markLine component is enabled
  58138. opt.markLine = opt.markLine || {};
  58139. });
  58140. /***/ },
  58141. /* 397 */
  58142. /***/ function(module, exports, __webpack_require__) {
  58143. module.exports = __webpack_require__(392).extend({
  58144. type: 'markLine',
  58145. defaultOption: {
  58146. zlevel: 0,
  58147. z: 5,
  58148. symbol: ['circle', 'arrow'],
  58149. symbolSize: [8, 16],
  58150. //symbolRotate: 0,
  58151. precision: 2,
  58152. tooltip: {
  58153. trigger: 'item'
  58154. },
  58155. label: {
  58156. normal: {
  58157. show: true,
  58158. position: 'end'
  58159. },
  58160. emphasis: {
  58161. show: true
  58162. }
  58163. },
  58164. lineStyle: {
  58165. normal: {
  58166. type: 'dashed'
  58167. },
  58168. emphasis: {
  58169. width: 3
  58170. }
  58171. },
  58172. animationEasing: 'linear'
  58173. }
  58174. });
  58175. /***/ },
  58176. /* 398 */
  58177. /***/ function(module, exports, __webpack_require__) {
  58178. var zrUtil = __webpack_require__(4);
  58179. var List = __webpack_require__(98);
  58180. var numberUtil = __webpack_require__(7);
  58181. var markerHelper = __webpack_require__(394);
  58182. var LineDraw = __webpack_require__(209);
  58183. var markLineTransform = function (seriesModel, coordSys, mlModel, item) {
  58184. var data = seriesModel.getData();
  58185. // Special type markLine like 'min', 'max', 'average'
  58186. var mlType = item.type;
  58187. if (!zrUtil.isArray(item)
  58188. && (
  58189. mlType === 'min' || mlType === 'max' || mlType === 'average'
  58190. // In case
  58191. // data: [{
  58192. // yAxis: 10
  58193. // }]
  58194. || (item.xAxis != null || item.yAxis != null)
  58195. )
  58196. ) {
  58197. var valueAxis;
  58198. var valueDataDim;
  58199. var value;
  58200. if (item.yAxis != null || item.xAxis != null) {
  58201. valueDataDim = item.yAxis != null ? 'y' : 'x';
  58202. valueAxis = coordSys.getAxis(valueDataDim);
  58203. value = zrUtil.retrieve(item.yAxis, item.xAxis);
  58204. }
  58205. else {
  58206. var axisInfo = markerHelper.getAxisInfo(item, data, coordSys, seriesModel);
  58207. valueDataDim = axisInfo.valueDataDim;
  58208. valueAxis = axisInfo.valueAxis;
  58209. value = markerHelper.numCalculate(data, valueDataDim, mlType);
  58210. }
  58211. var valueIndex = valueDataDim === 'x' ? 0 : 1;
  58212. var baseIndex = 1 - valueIndex;
  58213. var mlFrom = zrUtil.clone(item);
  58214. var mlTo = {};
  58215. mlFrom.type = null;
  58216. mlFrom.coord = [];
  58217. mlTo.coord = [];
  58218. mlFrom.coord[baseIndex] = -Infinity;
  58219. mlTo.coord[baseIndex] = Infinity;
  58220. var precision = mlModel.get('precision');
  58221. if (precision >= 0 && typeof value === 'number') {
  58222. value = +value.toFixed(precision);
  58223. }
  58224. mlFrom.coord[valueIndex] = mlTo.coord[valueIndex] = value;
  58225. item = [mlFrom, mlTo, { // Extra option for tooltip and label
  58226. type: mlType,
  58227. valueIndex: item.valueIndex,
  58228. // Force to use the value of calculated value.
  58229. value: value
  58230. }];
  58231. }
  58232. item = [
  58233. markerHelper.dataTransform(seriesModel, item[0]),
  58234. markerHelper.dataTransform(seriesModel, item[1]),
  58235. zrUtil.extend({}, item[2])
  58236. ];
  58237. // Avoid line data type is extended by from(to) data type
  58238. item[2].type = item[2].type || '';
  58239. // Merge from option and to option into line option
  58240. zrUtil.merge(item[2], item[0]);
  58241. zrUtil.merge(item[2], item[1]);
  58242. return item;
  58243. };
  58244. function isInifinity(val) {
  58245. return !isNaN(val) && !isFinite(val);
  58246. }
  58247. // If a markLine has one dim
  58248. function ifMarkLineHasOnlyDim(dimIndex, fromCoord, toCoord, coordSys) {
  58249. var otherDimIndex = 1 - dimIndex;
  58250. var dimName = coordSys.dimensions[dimIndex];
  58251. return isInifinity(fromCoord[otherDimIndex]) && isInifinity(toCoord[otherDimIndex])
  58252. && fromCoord[dimIndex] === toCoord[dimIndex] && coordSys.getAxis(dimName).containData(fromCoord[dimIndex]);
  58253. }
  58254. function markLineFilter(coordSys, item) {
  58255. if (coordSys.type === 'cartesian2d') {
  58256. var fromCoord = item[0].coord;
  58257. var toCoord = item[1].coord;
  58258. // In case
  58259. // {
  58260. // markLine: {
  58261. // data: [{ yAxis: 2 }]
  58262. // }
  58263. // }
  58264. if (
  58265. fromCoord && toCoord &&
  58266. (ifMarkLineHasOnlyDim(1, fromCoord, toCoord, coordSys)
  58267. || ifMarkLineHasOnlyDim(0, fromCoord, toCoord, coordSys))
  58268. ) {
  58269. return true;
  58270. }
  58271. }
  58272. return markerHelper.dataFilter(coordSys, item[0])
  58273. && markerHelper.dataFilter(coordSys, item[1]);
  58274. }
  58275. function updateSingleMarkerEndLayout(
  58276. data, idx, isFrom, seriesModel, api
  58277. ) {
  58278. var coordSys = seriesModel.coordinateSystem;
  58279. var itemModel = data.getItemModel(idx);
  58280. var point;
  58281. var xPx = numberUtil.parsePercent(itemModel.get('x'), api.getWidth());
  58282. var yPx = numberUtil.parsePercent(itemModel.get('y'), api.getHeight());
  58283. if (!isNaN(xPx) && !isNaN(yPx)) {
  58284. point = [xPx, yPx];
  58285. }
  58286. else {
  58287. // Chart like bar may have there own marker positioning logic
  58288. if (seriesModel.getMarkerPosition) {
  58289. // Use the getMarkerPoisition
  58290. point = seriesModel.getMarkerPosition(
  58291. data.getValues(data.dimensions, idx)
  58292. );
  58293. }
  58294. else {
  58295. var dims = coordSys.dimensions;
  58296. var x = data.get(dims[0], idx);
  58297. var y = data.get(dims[1], idx);
  58298. point = coordSys.dataToPoint([x, y]);
  58299. }
  58300. // Expand line to the edge of grid if value on one axis is Inifnity
  58301. // In case
  58302. // markLine: {
  58303. // data: [{
  58304. // yAxis: 2
  58305. // // or
  58306. // type: 'average'
  58307. // }]
  58308. // }
  58309. if (coordSys.type === 'cartesian2d') {
  58310. var xAxis = coordSys.getAxis('x');
  58311. var yAxis = coordSys.getAxis('y');
  58312. var dims = coordSys.dimensions;
  58313. if (isInifinity(data.get(dims[0], idx))) {
  58314. point[0] = xAxis.toGlobalCoord(xAxis.getExtent()[isFrom ? 0 : 1]);
  58315. }
  58316. else if (isInifinity(data.get(dims[1], idx))) {
  58317. point[1] = yAxis.toGlobalCoord(yAxis.getExtent()[isFrom ? 0 : 1]);
  58318. }
  58319. }
  58320. // Use x, y if has any
  58321. if (!isNaN(xPx)) {
  58322. point[0] = xPx;
  58323. }
  58324. if (!isNaN(yPx)) {
  58325. point[1] = yPx;
  58326. }
  58327. }
  58328. data.setItemLayout(idx, point);
  58329. }
  58330. __webpack_require__(395).extend({
  58331. type: 'markLine',
  58332. updateLayout: function (markLineModel, ecModel, api) {
  58333. ecModel.eachSeries(function (seriesModel) {
  58334. var mlModel = seriesModel.markLineModel;
  58335. if (mlModel) {
  58336. var mlData = mlModel.getData();
  58337. var fromData = mlModel.__from;
  58338. var toData = mlModel.__to;
  58339. // Update visual and layout of from symbol and to symbol
  58340. fromData.each(function (idx) {
  58341. updateSingleMarkerEndLayout(fromData, idx, true, seriesModel, api);
  58342. updateSingleMarkerEndLayout(toData, idx, false, seriesModel, api);
  58343. });
  58344. // Update layout of line
  58345. mlData.each(function (idx) {
  58346. mlData.setItemLayout(idx, [
  58347. fromData.getItemLayout(idx),
  58348. toData.getItemLayout(idx)
  58349. ]);
  58350. });
  58351. this.markerGroupMap.get(seriesModel.name).updateLayout();
  58352. }
  58353. }, this);
  58354. },
  58355. renderSeries: function (seriesModel, mlModel, ecModel, api) {
  58356. var coordSys = seriesModel.coordinateSystem;
  58357. var seriesName = seriesModel.name;
  58358. var seriesData = seriesModel.getData();
  58359. var lineDrawMap = this.markerGroupMap;
  58360. var lineDraw = lineDrawMap.get(seriesName)
  58361. || lineDrawMap.set(seriesName, new LineDraw());
  58362. this.group.add(lineDraw.group);
  58363. var mlData = createList(coordSys, seriesModel, mlModel);
  58364. var fromData = mlData.from;
  58365. var toData = mlData.to;
  58366. var lineData = mlData.line;
  58367. mlModel.__from = fromData;
  58368. mlModel.__to = toData;
  58369. // Line data for tooltip and formatter
  58370. mlModel.setData(lineData);
  58371. var symbolType = mlModel.get('symbol');
  58372. var symbolSize = mlModel.get('symbolSize');
  58373. if (!zrUtil.isArray(symbolType)) {
  58374. symbolType = [symbolType, symbolType];
  58375. }
  58376. if (typeof symbolSize === 'number') {
  58377. symbolSize = [symbolSize, symbolSize];
  58378. }
  58379. // Update visual and layout of from symbol and to symbol
  58380. mlData.from.each(function (idx) {
  58381. updateDataVisualAndLayout(fromData, idx, true);
  58382. updateDataVisualAndLayout(toData, idx, false);
  58383. });
  58384. // Update visual and layout of line
  58385. lineData.each(function (idx) {
  58386. var lineColor = lineData.getItemModel(idx).get('lineStyle.normal.color');
  58387. lineData.setItemVisual(idx, {
  58388. color: lineColor || fromData.getItemVisual(idx, 'color')
  58389. });
  58390. lineData.setItemLayout(idx, [
  58391. fromData.getItemLayout(idx),
  58392. toData.getItemLayout(idx)
  58393. ]);
  58394. lineData.setItemVisual(idx, {
  58395. 'fromSymbolSize': fromData.getItemVisual(idx, 'symbolSize'),
  58396. 'fromSymbol': fromData.getItemVisual(idx, 'symbol'),
  58397. 'toSymbolSize': toData.getItemVisual(idx, 'symbolSize'),
  58398. 'toSymbol': toData.getItemVisual(idx, 'symbol')
  58399. });
  58400. });
  58401. lineDraw.updateData(lineData);
  58402. // Set host model for tooltip
  58403. // FIXME
  58404. mlData.line.eachItemGraphicEl(function (el, idx) {
  58405. el.traverse(function (child) {
  58406. child.dataModel = mlModel;
  58407. });
  58408. });
  58409. function updateDataVisualAndLayout(data, idx, isFrom) {
  58410. var itemModel = data.getItemModel(idx);
  58411. updateSingleMarkerEndLayout(
  58412. data, idx, isFrom, seriesModel, api
  58413. );
  58414. data.setItemVisual(idx, {
  58415. symbolSize: itemModel.get('symbolSize') || symbolSize[isFrom ? 0 : 1],
  58416. symbol: itemModel.get('symbol', true) || symbolType[isFrom ? 0 : 1],
  58417. color: itemModel.get('itemStyle.normal.color') || seriesData.getVisual('color')
  58418. });
  58419. }
  58420. lineDraw.__keep = true;
  58421. lineDraw.group.silent = mlModel.get('silent') || seriesModel.get('silent');
  58422. }
  58423. });
  58424. /**
  58425. * @inner
  58426. * @param {module:echarts/coord/*} coordSys
  58427. * @param {module:echarts/model/Series} seriesModel
  58428. * @param {module:echarts/model/Model} mpModel
  58429. */
  58430. function createList(coordSys, seriesModel, mlModel) {
  58431. var coordDimsInfos;
  58432. if (coordSys) {
  58433. coordDimsInfos = zrUtil.map(coordSys && coordSys.dimensions, function (coordDim) {
  58434. var info = seriesModel.getData().getDimensionInfo(
  58435. seriesModel.coordDimToDataDim(coordDim)[0]
  58436. ) || {}; // In map series data don't have lng and lat dimension. Fallback to same with coordSys
  58437. info.name = coordDim;
  58438. return info;
  58439. });
  58440. }
  58441. else {
  58442. coordDimsInfos =[{
  58443. name: 'value',
  58444. type: 'float'
  58445. }];
  58446. }
  58447. var fromData = new List(coordDimsInfos, mlModel);
  58448. var toData = new List(coordDimsInfos, mlModel);
  58449. // No dimensions
  58450. var lineData = new List([], mlModel);
  58451. var optData = zrUtil.map(mlModel.get('data'), zrUtil.curry(
  58452. markLineTransform, seriesModel, coordSys, mlModel
  58453. ));
  58454. if (coordSys) {
  58455. optData = zrUtil.filter(
  58456. optData, zrUtil.curry(markLineFilter, coordSys)
  58457. );
  58458. }
  58459. var dimValueGetter = coordSys ? markerHelper.dimValueGetter : function (item) {
  58460. return item.value;
  58461. };
  58462. fromData.initData(
  58463. zrUtil.map(optData, function (item) { return item[0]; }),
  58464. null, dimValueGetter
  58465. );
  58466. toData.initData(
  58467. zrUtil.map(optData, function (item) { return item[1]; }),
  58468. null, dimValueGetter
  58469. );
  58470. lineData.initData(
  58471. zrUtil.map(optData, function (item) { return item[2]; })
  58472. );
  58473. lineData.hasItemOption = true;
  58474. return {
  58475. from: fromData,
  58476. to: toData,
  58477. line: lineData
  58478. };
  58479. }
  58480. /***/ },
  58481. /* 399 */
  58482. /***/ function(module, exports, __webpack_require__) {
  58483. __webpack_require__(400);
  58484. __webpack_require__(401);
  58485. __webpack_require__(1).registerPreprocessor(function (opt) {
  58486. // Make sure markArea component is enabled
  58487. opt.markArea = opt.markArea || {};
  58488. });
  58489. /***/ },
  58490. /* 400 */
  58491. /***/ function(module, exports, __webpack_require__) {
  58492. module.exports = __webpack_require__(392).extend({
  58493. type: 'markArea',
  58494. defaultOption: {
  58495. zlevel: 0,
  58496. // PENDING
  58497. z: 1,
  58498. tooltip: {
  58499. trigger: 'item'
  58500. },
  58501. // markArea should fixed on the coordinate system
  58502. animation: false,
  58503. label: {
  58504. normal: {
  58505. show: true,
  58506. position: 'top'
  58507. },
  58508. emphasis: {
  58509. show: true,
  58510. position: 'top'
  58511. }
  58512. },
  58513. itemStyle: {
  58514. normal: {
  58515. // color and borderColor default to use color from series
  58516. // color: 'auto'
  58517. // borderColor: 'auto'
  58518. borderWidth: 0
  58519. }
  58520. }
  58521. }
  58522. });
  58523. /***/ },
  58524. /* 401 */
  58525. /***/ function(module, exports, __webpack_require__) {
  58526. // TODO Better on polar
  58527. var zrUtil = __webpack_require__(4);
  58528. var List = __webpack_require__(98);
  58529. var numberUtil = __webpack_require__(7);
  58530. var graphic = __webpack_require__(18);
  58531. var colorUtil = __webpack_require__(31);
  58532. var markerHelper = __webpack_require__(394);
  58533. var markAreaTransform = function (seriesModel, coordSys, maModel, item) {
  58534. var lt = markerHelper.dataTransform(seriesModel, item[0]);
  58535. var rb = markerHelper.dataTransform(seriesModel, item[1]);
  58536. var retrieve = zrUtil.retrieve;
  58537. // FIXME make sure lt is less than rb
  58538. var ltCoord = lt.coord;
  58539. var rbCoord = rb.coord;
  58540. ltCoord[0] = retrieve(ltCoord[0], -Infinity);
  58541. ltCoord[1] = retrieve(ltCoord[1], -Infinity);
  58542. rbCoord[0] = retrieve(rbCoord[0], Infinity);
  58543. rbCoord[1] = retrieve(rbCoord[1], Infinity);
  58544. // Merge option into one
  58545. var result = zrUtil.mergeAll([{}, lt, rb]);
  58546. result.coord = [
  58547. lt.coord, rb.coord
  58548. ];
  58549. result.x0 = lt.x;
  58550. result.y0 = lt.y;
  58551. result.x1 = rb.x;
  58552. result.y1 = rb.y;
  58553. return result;
  58554. };
  58555. function isInifinity(val) {
  58556. return !isNaN(val) && !isFinite(val);
  58557. }
  58558. // If a markArea has one dim
  58559. function ifMarkLineHasOnlyDim(dimIndex, fromCoord, toCoord, coordSys) {
  58560. var otherDimIndex = 1 - dimIndex;
  58561. return isInifinity(fromCoord[otherDimIndex]) && isInifinity(toCoord[otherDimIndex]);
  58562. }
  58563. function markAreaFilter(coordSys, item) {
  58564. var fromCoord = item.coord[0];
  58565. var toCoord = item.coord[1];
  58566. if (coordSys.type === 'cartesian2d') {
  58567. // In case
  58568. // {
  58569. // markArea: {
  58570. // data: [{ yAxis: 2 }]
  58571. // }
  58572. // }
  58573. if (
  58574. fromCoord && toCoord &&
  58575. (ifMarkLineHasOnlyDim(1, fromCoord, toCoord, coordSys)
  58576. || ifMarkLineHasOnlyDim(0, fromCoord, toCoord, coordSys))
  58577. ) {
  58578. return true;
  58579. }
  58580. }
  58581. return markerHelper.dataFilter(coordSys, {
  58582. coord: fromCoord,
  58583. x: item.x0,
  58584. y: item.y0
  58585. })
  58586. || markerHelper.dataFilter(coordSys, {
  58587. coord: toCoord,
  58588. x: item.x1,
  58589. y: item.y1
  58590. });
  58591. }
  58592. // dims can be ['x0', 'y0'], ['x1', 'y1'], ['x0', 'y1'], ['x1', 'y0']
  58593. function getSingleMarkerEndPoint(data, idx, dims, seriesModel, api) {
  58594. var coordSys = seriesModel.coordinateSystem;
  58595. var itemModel = data.getItemModel(idx);
  58596. var point;
  58597. var xPx = numberUtil.parsePercent(itemModel.get(dims[0]), api.getWidth());
  58598. var yPx = numberUtil.parsePercent(itemModel.get(dims[1]), api.getHeight());
  58599. if (!isNaN(xPx) && !isNaN(yPx)) {
  58600. point = [xPx, yPx];
  58601. }
  58602. else {
  58603. // Chart like bar may have there own marker positioning logic
  58604. if (seriesModel.getMarkerPosition) {
  58605. // Use the getMarkerPoisition
  58606. point = seriesModel.getMarkerPosition(
  58607. data.getValues(dims, idx)
  58608. );
  58609. }
  58610. else {
  58611. var x = data.get(dims[0], idx);
  58612. var y = data.get(dims[1], idx);
  58613. point = coordSys.dataToPoint([x, y], true);
  58614. }
  58615. if (coordSys.type === 'cartesian2d') {
  58616. var xAxis = coordSys.getAxis('x');
  58617. var yAxis = coordSys.getAxis('y');
  58618. var x = data.get(dims[0], idx);
  58619. var y = data.get(dims[1], idx);
  58620. if (isInifinity(x)) {
  58621. point[0] = xAxis.toGlobalCoord(xAxis.getExtent()[dims[0] === 'x0' ? 0 : 1]);
  58622. }
  58623. else if (isInifinity(y)) {
  58624. point[1] = yAxis.toGlobalCoord(yAxis.getExtent()[dims[1] === 'y0' ? 0 : 1]);
  58625. }
  58626. }
  58627. // Use x, y if has any
  58628. if (!isNaN(xPx)) {
  58629. point[0] = xPx;
  58630. }
  58631. if (!isNaN(yPx)) {
  58632. point[1] = yPx;
  58633. }
  58634. }
  58635. return point;
  58636. }
  58637. var dimPermutations = [['x0', 'y0'], ['x1', 'y0'], ['x1', 'y1'], ['x0', 'y1']];
  58638. __webpack_require__(395).extend({
  58639. type: 'markArea',
  58640. updateLayout: function (markAreaModel, ecModel, api) {
  58641. ecModel.eachSeries(function (seriesModel) {
  58642. var maModel = seriesModel.markAreaModel;
  58643. if (maModel) {
  58644. var areaData = maModel.getData();
  58645. areaData.each(function (idx) {
  58646. var points = zrUtil.map(dimPermutations, function (dim) {
  58647. return getSingleMarkerEndPoint(areaData, idx, dim, seriesModel, api);
  58648. });
  58649. // Layout
  58650. areaData.setItemLayout(idx, points);
  58651. var el = areaData.getItemGraphicEl(idx);
  58652. el.setShape('points', points);
  58653. });
  58654. }
  58655. }, this);
  58656. },
  58657. renderSeries: function (seriesModel, maModel, ecModel, api) {
  58658. var coordSys = seriesModel.coordinateSystem;
  58659. var seriesName = seriesModel.name;
  58660. var seriesData = seriesModel.getData();
  58661. var areaGroupMap = this.markerGroupMap;
  58662. var polygonGroup = areaGroupMap.get(seriesName)
  58663. || areaGroupMap.set(seriesName, {group: new graphic.Group()});
  58664. this.group.add(polygonGroup.group);
  58665. polygonGroup.__keep = true;
  58666. var areaData = createList(coordSys, seriesModel, maModel);
  58667. // Line data for tooltip and formatter
  58668. maModel.setData(areaData);
  58669. // Update visual and layout of line
  58670. areaData.each(function (idx) {
  58671. // Layout
  58672. areaData.setItemLayout(idx, zrUtil.map(dimPermutations, function (dim) {
  58673. return getSingleMarkerEndPoint(areaData, idx, dim, seriesModel, api);
  58674. }));
  58675. // Visual
  58676. areaData.setItemVisual(idx, {
  58677. color: seriesData.getVisual('color')
  58678. });
  58679. });
  58680. areaData.diff(polygonGroup.__data)
  58681. .add(function (idx) {
  58682. var polygon = new graphic.Polygon({
  58683. shape: {
  58684. points: areaData.getItemLayout(idx)
  58685. }
  58686. });
  58687. areaData.setItemGraphicEl(idx, polygon);
  58688. polygonGroup.group.add(polygon);
  58689. })
  58690. .update(function (newIdx, oldIdx) {
  58691. var polygon = polygonGroup.__data.getItemGraphicEl(oldIdx);
  58692. graphic.updateProps(polygon, {
  58693. shape: {
  58694. points: areaData.getItemLayout(newIdx)
  58695. }
  58696. }, maModel, newIdx);
  58697. polygonGroup.group.add(polygon);
  58698. areaData.setItemGraphicEl(newIdx, polygon);
  58699. })
  58700. .remove(function (idx) {
  58701. var polygon = polygonGroup.__data.getItemGraphicEl(idx);
  58702. polygonGroup.group.remove(polygon);
  58703. })
  58704. .execute();
  58705. areaData.eachItemGraphicEl(function (polygon, idx) {
  58706. var itemModel = areaData.getItemModel(idx);
  58707. var labelModel = itemModel.getModel('label.normal');
  58708. var labelHoverModel = itemModel.getModel('label.emphasis');
  58709. var color = areaData.getItemVisual(idx, 'color');
  58710. polygon.useStyle(
  58711. zrUtil.defaults(
  58712. itemModel.getModel('itemStyle.normal').getItemStyle(),
  58713. {
  58714. fill: colorUtil.modifyAlpha(color, 0.4),
  58715. stroke: color
  58716. }
  58717. )
  58718. );
  58719. polygon.hoverStyle = itemModel.getModel('itemStyle.normal').getItemStyle();
  58720. var defaultValue = areaData.getName(idx) || '';
  58721. var textColor = color || polygon.style.fill;
  58722. if (labelModel.getShallow('show')) {
  58723. graphic.setText(polygon.style, labelModel, textColor);
  58724. polygon.style.text = zrUtil.retrieve(
  58725. maModel.getFormattedLabel(idx, 'normal'),
  58726. defaultValue
  58727. );
  58728. }
  58729. else {
  58730. polygon.style.text = '';
  58731. }
  58732. if (labelHoverModel.getShallow('show')) {
  58733. graphic.setText(polygon.hoverStyle, labelHoverModel, textColor);
  58734. polygon.hoverStyle.text = zrUtil.retrieve(
  58735. maModel.getFormattedLabel(idx, 'emphasis'),
  58736. defaultValue
  58737. );
  58738. }
  58739. else {
  58740. polygon.hoverStyle.text = '';
  58741. }
  58742. graphic.setHoverStyle(polygon, {});
  58743. polygon.dataModel = maModel;
  58744. });
  58745. polygonGroup.__data = areaData;
  58746. polygonGroup.group.silent = maModel.get('silent') || seriesModel.get('silent');
  58747. }
  58748. });
  58749. /**
  58750. * @inner
  58751. * @param {module:echarts/coord/*} coordSys
  58752. * @param {module:echarts/model/Series} seriesModel
  58753. * @param {module:echarts/model/Model} mpModel
  58754. */
  58755. function createList(coordSys, seriesModel, maModel) {
  58756. var coordDimsInfos;
  58757. var areaData;
  58758. var dims = ['x0', 'y0', 'x1', 'y1'];
  58759. if (coordSys) {
  58760. coordDimsInfos = zrUtil.map(coordSys && coordSys.dimensions, function (coordDim) {
  58761. var info = seriesModel.getData().getDimensionInfo(
  58762. seriesModel.coordDimToDataDim(coordDim)[0]
  58763. ) || {}; // In map series data don't have lng and lat dimension. Fallback to same with coordSys
  58764. info.name = coordDim;
  58765. return info;
  58766. });
  58767. areaData = new List(zrUtil.map(dims, function (dim, idx) {
  58768. return {
  58769. name: dim,
  58770. type: coordDimsInfos[idx % 2].type
  58771. };
  58772. }), maModel);
  58773. }
  58774. else {
  58775. coordDimsInfos =[{
  58776. name: 'value',
  58777. type: 'float'
  58778. }];
  58779. areaData = new List(coordDimsInfos, maModel);
  58780. }
  58781. var optData = zrUtil.map(maModel.get('data'), zrUtil.curry(
  58782. markAreaTransform, seriesModel, coordSys, maModel
  58783. ));
  58784. if (coordSys) {
  58785. optData = zrUtil.filter(
  58786. optData, zrUtil.curry(markAreaFilter, coordSys)
  58787. );
  58788. }
  58789. var dimValueGetter = coordSys ? function (item, dimName, dataIndex, dimIndex) {
  58790. return item.coord[Math.floor(dimIndex / 2)][dimIndex % 2];
  58791. } : function (item) {
  58792. return item.value;
  58793. };
  58794. areaData.initData(optData, null, dimValueGetter);
  58795. areaData.hasItemOption = true;
  58796. return areaData;
  58797. }
  58798. /***/ },
  58799. /* 402 */
  58800. /***/ function(module, exports, __webpack_require__) {
  58801. /**
  58802. * DataZoom component entry
  58803. */
  58804. var echarts = __webpack_require__(1);
  58805. echarts.registerPreprocessor(__webpack_require__(403));
  58806. __webpack_require__(404);
  58807. __webpack_require__(405);
  58808. __webpack_require__(406);
  58809. __webpack_require__(408);
  58810. /***/ },
  58811. /* 403 */
  58812. /***/ function(module, exports, __webpack_require__) {
  58813. /**
  58814. * @file Timeline preprocessor
  58815. */
  58816. var zrUtil = __webpack_require__(4);
  58817. module.exports = function (option) {
  58818. var timelineOpt = option && option.timeline;
  58819. if (!zrUtil.isArray(timelineOpt)) {
  58820. timelineOpt = timelineOpt ? [timelineOpt] : [];
  58821. }
  58822. zrUtil.each(timelineOpt, function (opt) {
  58823. if (!opt) {
  58824. return;
  58825. }
  58826. compatibleEC2(opt);
  58827. });
  58828. };
  58829. function compatibleEC2(opt) {
  58830. var type = opt.type;
  58831. var ec2Types = {'number': 'value', 'time': 'time'};
  58832. // Compatible with ec2
  58833. if (ec2Types[type]) {
  58834. opt.axisType = ec2Types[type];
  58835. delete opt.type;
  58836. }
  58837. transferItem(opt);
  58838. if (has(opt, 'controlPosition')) {
  58839. var controlStyle = opt.controlStyle || (opt.controlStyle = {});
  58840. if (!has(controlStyle, 'position')) {
  58841. controlStyle.position = opt.controlPosition;
  58842. }
  58843. if (controlStyle.position === 'none' && !has(controlStyle, 'show')) {
  58844. controlStyle.show = false;
  58845. delete controlStyle.position;
  58846. }
  58847. delete opt.controlPosition;
  58848. }
  58849. zrUtil.each(opt.data || [], function (dataItem) {
  58850. if (zrUtil.isObject(dataItem) && !zrUtil.isArray(dataItem)) {
  58851. if (!has(dataItem, 'value') && has(dataItem, 'name')) {
  58852. // In ec2, using name as value.
  58853. dataItem.value = dataItem.name;
  58854. }
  58855. transferItem(dataItem);
  58856. }
  58857. });
  58858. }
  58859. function transferItem(opt) {
  58860. var itemStyle = opt.itemStyle || (opt.itemStyle = {});
  58861. var itemStyleEmphasis = itemStyle.emphasis || (itemStyle.emphasis = {});
  58862. // Transfer label out
  58863. var label = opt.label || (opt.label || {});
  58864. var labelNormal = label.normal || (label.normal = {});
  58865. var excludeLabelAttr = {normal: 1, emphasis: 1};
  58866. zrUtil.each(label, function (value, name) {
  58867. if (!excludeLabelAttr[name] && !has(labelNormal, name)) {
  58868. labelNormal[name] = value;
  58869. }
  58870. });
  58871. if (itemStyleEmphasis.label && !has(label, 'emphasis')) {
  58872. label.emphasis = itemStyleEmphasis.label;
  58873. delete itemStyleEmphasis.label;
  58874. }
  58875. }
  58876. function has(obj, attr) {
  58877. return obj.hasOwnProperty(attr);
  58878. }
  58879. /***/ },
  58880. /* 404 */
  58881. /***/ function(module, exports, __webpack_require__) {
  58882. __webpack_require__(69).registerSubTypeDefaulter('timeline', function () {
  58883. // Only slider now.
  58884. return 'slider';
  58885. });
  58886. /***/ },
  58887. /* 405 */
  58888. /***/ function(module, exports, __webpack_require__) {
  58889. /**
  58890. * @file Timeilne action
  58891. */
  58892. var echarts = __webpack_require__(1);
  58893. var zrUtil = __webpack_require__(4);
  58894. echarts.registerAction(
  58895. {type: 'timelineChange', event: 'timelineChanged', update: 'prepareAndUpdate'},
  58896. function (payload, ecModel) {
  58897. var timelineModel = ecModel.getComponent('timeline');
  58898. if (timelineModel && payload.currentIndex != null) {
  58899. timelineModel.setCurrentIndex(payload.currentIndex);
  58900. if (!timelineModel.get('loop', true) && timelineModel.isIndexMax()) {
  58901. timelineModel.setPlayState(false);
  58902. }
  58903. }
  58904. // Set normalized currentIndex to payload.
  58905. ecModel.resetOption('timeline');
  58906. return zrUtil.defaults({
  58907. currentIndex: timelineModel.option.currentIndex
  58908. }, payload);
  58909. }
  58910. );
  58911. echarts.registerAction(
  58912. {type: 'timelinePlayChange', event: 'timelinePlayChanged', update: 'update'},
  58913. function (payload, ecModel) {
  58914. var timelineModel = ecModel.getComponent('timeline');
  58915. if (timelineModel && payload.playState != null) {
  58916. timelineModel.setPlayState(payload.playState);
  58917. }
  58918. }
  58919. );
  58920. /***/ },
  58921. /* 406 */
  58922. /***/ function(module, exports, __webpack_require__) {
  58923. /**
  58924. * @file Silder timeline model
  58925. */
  58926. var TimelineModel = __webpack_require__(407);
  58927. var zrUtil = __webpack_require__(4);
  58928. var modelUtil = __webpack_require__(5);
  58929. var SliderTimelineModel = TimelineModel.extend({
  58930. type: 'timeline.slider',
  58931. /**
  58932. * @protected
  58933. */
  58934. defaultOption: {
  58935. backgroundColor: 'rgba(0,0,0,0)', // 时间轴背景颜色
  58936. borderColor: '#ccc', // 时间轴边框颜色
  58937. borderWidth: 0, // 时间轴边框线宽,单位px,默认为0(无边框)
  58938. orient: 'horizontal', // 'vertical'
  58939. inverse: false,
  58940. tooltip: { // boolean or Object
  58941. trigger: 'item' // data item may also have tootip attr.
  58942. },
  58943. symbol: 'emptyCircle',
  58944. symbolSize: 10,
  58945. lineStyle: {
  58946. show: true,
  58947. width: 2,
  58948. color: '#304654'
  58949. },
  58950. label: { // 文本标签
  58951. position: 'auto', // auto left right top bottom
  58952. // When using number, label position is not
  58953. // restricted by viewRect.
  58954. // positive: right/bottom, negative: left/top
  58955. normal: {
  58956. show: true,
  58957. interval: 'auto',
  58958. rotate: 0,
  58959. // formatter: null,
  58960. textStyle: { // 其余属性默认使用全局文本样式,详见TEXTSTYLE
  58961. color: '#304654'
  58962. }
  58963. },
  58964. emphasis: {
  58965. show: true,
  58966. textStyle: { // 其余属性默认使用全局文本样式,详见TEXTSTYLE
  58967. color: '#c23531'
  58968. }
  58969. }
  58970. },
  58971. itemStyle: {
  58972. normal: {
  58973. color: '#304654',
  58974. borderWidth: 1
  58975. },
  58976. emphasis: {
  58977. color: '#c23531'
  58978. }
  58979. },
  58980. checkpointStyle: {
  58981. symbol: 'circle',
  58982. symbolSize: 13,
  58983. color: '#c23531',
  58984. borderWidth: 5,
  58985. borderColor: 'rgba(194,53,49, 0.5)',
  58986. animation: true,
  58987. animationDuration: 300,
  58988. animationEasing: 'quinticInOut'
  58989. },
  58990. controlStyle: {
  58991. show: true,
  58992. showPlayBtn: true,
  58993. showPrevBtn: true,
  58994. showNextBtn: true,
  58995. itemSize: 22,
  58996. itemGap: 12,
  58997. position: 'left', // 'left' 'right' 'top' 'bottom'
  58998. 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
  58999. 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
  59000. 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
  59001. 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
  59002. normal: {
  59003. color: '#304654',
  59004. borderColor: '#304654',
  59005. borderWidth: 1
  59006. },
  59007. emphasis: {
  59008. color: '#c23531',
  59009. borderColor: '#c23531',
  59010. borderWidth: 2
  59011. }
  59012. },
  59013. data: []
  59014. }
  59015. });
  59016. zrUtil.mixin(SliderTimelineModel, modelUtil.dataFormatMixin);
  59017. module.exports = SliderTimelineModel;
  59018. /***/ },
  59019. /* 407 */
  59020. /***/ function(module, exports, __webpack_require__) {
  59021. /**
  59022. * @file Timeline model
  59023. */
  59024. var ComponentModel = __webpack_require__(69);
  59025. var List = __webpack_require__(98);
  59026. var zrUtil = __webpack_require__(4);
  59027. var modelUtil = __webpack_require__(5);
  59028. var TimelineModel = ComponentModel.extend({
  59029. type: 'timeline',
  59030. layoutMode: 'box',
  59031. /**
  59032. * @protected
  59033. */
  59034. defaultOption: {
  59035. zlevel: 0, // 一级层叠
  59036. z: 4, // 二级层叠
  59037. show: true,
  59038. axisType: 'time', // 模式是时间类型,支持 value, category
  59039. realtime: true,
  59040. left: '20%',
  59041. top: null,
  59042. right: '20%',
  59043. bottom: 0,
  59044. width: null,
  59045. height: 40,
  59046. padding: 5,
  59047. controlPosition: 'left', // 'left' 'right' 'top' 'bottom' 'none'
  59048. autoPlay: false,
  59049. rewind: false, // 反向播放
  59050. loop: true,
  59051. playInterval: 2000, // 播放时间间隔,单位ms
  59052. currentIndex: 0,
  59053. itemStyle: {
  59054. normal: {},
  59055. emphasis: {}
  59056. },
  59057. label: {
  59058. normal: {
  59059. textStyle: {
  59060. color: '#000'
  59061. }
  59062. },
  59063. emphasis: {}
  59064. },
  59065. data: []
  59066. },
  59067. /**
  59068. * @override
  59069. */
  59070. init: function (option, parentModel, ecModel) {
  59071. /**
  59072. * @private
  59073. * @type {module:echarts/data/List}
  59074. */
  59075. this._data;
  59076. /**
  59077. * @private
  59078. * @type {Array.<string>}
  59079. */
  59080. this._names;
  59081. this.mergeDefaultAndTheme(option, ecModel);
  59082. this._initData();
  59083. },
  59084. /**
  59085. * @override
  59086. */
  59087. mergeOption: function (option) {
  59088. TimelineModel.superApply(this, 'mergeOption', arguments);
  59089. this._initData();
  59090. },
  59091. /**
  59092. * @param {number} [currentIndex]
  59093. */
  59094. setCurrentIndex: function (currentIndex) {
  59095. if (currentIndex == null) {
  59096. currentIndex = this.option.currentIndex;
  59097. }
  59098. var count = this._data.count();
  59099. if (this.option.loop) {
  59100. currentIndex = (currentIndex % count + count) % count;
  59101. }
  59102. else {
  59103. currentIndex >= count && (currentIndex = count - 1);
  59104. currentIndex < 0 && (currentIndex = 0);
  59105. }
  59106. this.option.currentIndex = currentIndex;
  59107. },
  59108. /**
  59109. * @return {number} currentIndex
  59110. */
  59111. getCurrentIndex: function () {
  59112. return this.option.currentIndex;
  59113. },
  59114. /**
  59115. * @return {boolean}
  59116. */
  59117. isIndexMax: function () {
  59118. return this.getCurrentIndex() >= this._data.count() - 1;
  59119. },
  59120. /**
  59121. * @param {boolean} state true: play, false: stop
  59122. */
  59123. setPlayState: function (state) {
  59124. this.option.autoPlay = !!state;
  59125. },
  59126. /**
  59127. * @return {boolean} true: play, false: stop
  59128. */
  59129. getPlayState: function () {
  59130. return !!this.option.autoPlay;
  59131. },
  59132. /**
  59133. * @private
  59134. */
  59135. _initData: function () {
  59136. var thisOption = this.option;
  59137. var dataArr = thisOption.data || [];
  59138. var axisType = thisOption.axisType;
  59139. var names = this._names = [];
  59140. if (axisType === 'category') {
  59141. var idxArr = [];
  59142. zrUtil.each(dataArr, function (item, index) {
  59143. var value = modelUtil.getDataItemValue(item);
  59144. var newItem;
  59145. if (zrUtil.isObject(item)) {
  59146. newItem = zrUtil.clone(item);
  59147. newItem.value = index;
  59148. }
  59149. else {
  59150. newItem = index;
  59151. }
  59152. idxArr.push(newItem);
  59153. if (!zrUtil.isString(value) && (value == null || isNaN(value))) {
  59154. value = '';
  59155. }
  59156. names.push(value + '');
  59157. });
  59158. dataArr = idxArr;
  59159. }
  59160. var dimType = ({category: 'ordinal', time: 'time'})[axisType] || 'number';
  59161. var data = this._data = new List([{name: 'value', type: dimType}], this);
  59162. data.initData(dataArr, names);
  59163. },
  59164. getData: function () {
  59165. return this._data;
  59166. },
  59167. /**
  59168. * @public
  59169. * @return {Array.<string>} categoreis
  59170. */
  59171. getCategories: function () {
  59172. if (this.get('axisType') === 'category') {
  59173. return this._names.slice();
  59174. }
  59175. }
  59176. });
  59177. module.exports = TimelineModel;
  59178. /***/ },
  59179. /* 408 */
  59180. /***/ function(module, exports, __webpack_require__) {
  59181. /**
  59182. * @file Silder timeline view
  59183. */
  59184. var zrUtil = __webpack_require__(4);
  59185. var graphic = __webpack_require__(18);
  59186. var layout = __webpack_require__(71);
  59187. var TimelineView = __webpack_require__(409);
  59188. var TimelineAxis = __webpack_require__(410);
  59189. var symbolUtil = __webpack_require__(111);
  59190. var axisHelper = __webpack_require__(101);
  59191. var BoundingRect = __webpack_require__(9);
  59192. var matrix = __webpack_require__(11);
  59193. var numberUtil = __webpack_require__(7);
  59194. var formatUtil = __webpack_require__(6);
  59195. var encodeHTML = formatUtil.encodeHTML;
  59196. var bind = zrUtil.bind;
  59197. var each = zrUtil.each;
  59198. var PI = Math.PI;
  59199. module.exports = TimelineView.extend({
  59200. type: 'timeline.slider',
  59201. init: function (ecModel, api) {
  59202. this.api = api;
  59203. /**
  59204. * @private
  59205. * @type {module:echarts/component/timeline/TimelineAxis}
  59206. */
  59207. this._axis;
  59208. /**
  59209. * @private
  59210. * @type {module:zrender/core/BoundingRect}
  59211. */
  59212. this._viewRect;
  59213. /**
  59214. * @type {number}
  59215. */
  59216. this._timer;
  59217. /**
  59218. * @type {module:zrender/Element}
  59219. */
  59220. this._currentPointer;
  59221. /**
  59222. * @type {module:zrender/container/Group}
  59223. */
  59224. this._mainGroup;
  59225. /**
  59226. * @type {module:zrender/container/Group}
  59227. */
  59228. this._labelGroup;
  59229. },
  59230. /**
  59231. * @override
  59232. */
  59233. render: function (timelineModel, ecModel, api, payload) {
  59234. this.model = timelineModel;
  59235. this.api = api;
  59236. this.ecModel = ecModel;
  59237. this.group.removeAll();
  59238. if (timelineModel.get('show', true)) {
  59239. var layoutInfo = this._layout(timelineModel, api);
  59240. var mainGroup = this._createGroup('mainGroup');
  59241. var labelGroup = this._createGroup('labelGroup');
  59242. /**
  59243. * @private
  59244. * @type {module:echarts/component/timeline/TimelineAxis}
  59245. */
  59246. var axis = this._axis = this._createAxis(layoutInfo, timelineModel);
  59247. timelineModel.formatTooltip = function (dataIndex) {
  59248. return encodeHTML(axis.scale.getLabel(dataIndex));
  59249. };
  59250. each(
  59251. ['AxisLine', 'AxisTick', 'Control', 'CurrentPointer'],
  59252. function (name) {
  59253. this['_render' + name](layoutInfo, mainGroup, axis, timelineModel);
  59254. },
  59255. this
  59256. );
  59257. this._renderAxisLabel(layoutInfo, labelGroup, axis, timelineModel);
  59258. this._position(layoutInfo, timelineModel);
  59259. }
  59260. this._doPlayStop();
  59261. },
  59262. /**
  59263. * @override
  59264. */
  59265. remove: function () {
  59266. this._clearTimer();
  59267. this.group.removeAll();
  59268. },
  59269. /**
  59270. * @override
  59271. */
  59272. dispose: function () {
  59273. this._clearTimer();
  59274. },
  59275. _layout: function (timelineModel, api) {
  59276. var labelPosOpt = timelineModel.get('label.normal.position');
  59277. var orient = timelineModel.get('orient');
  59278. var viewRect = getViewRect(timelineModel, api);
  59279. // Auto label offset.
  59280. if (labelPosOpt == null || labelPosOpt === 'auto') {
  59281. labelPosOpt = orient === 'horizontal'
  59282. ? ((viewRect.y + viewRect.height / 2) < api.getHeight() / 2 ? '-' : '+')
  59283. : ((viewRect.x + viewRect.width / 2) < api.getWidth() / 2 ? '+' : '-');
  59284. }
  59285. else if (isNaN(labelPosOpt)) {
  59286. labelPosOpt = ({
  59287. horizontal: {top: '-', bottom: '+'},
  59288. vertical: {left: '-', right: '+'}
  59289. })[orient][labelPosOpt];
  59290. }
  59291. // FIXME
  59292. // 暂没有实现用户传入
  59293. // var labelAlign = timelineModel.get('label.normal.textStyle.align');
  59294. // var labelBaseline = timelineModel.get('label.normal.textStyle.baseline');
  59295. var labelAlignMap = {
  59296. horizontal: 'center',
  59297. vertical: (labelPosOpt >= 0 || labelPosOpt === '+') ? 'left' : 'right'
  59298. };
  59299. var labelBaselineMap = {
  59300. horizontal: (labelPosOpt >= 0 || labelPosOpt === '+') ? 'top' : 'bottom',
  59301. vertical: 'middle'
  59302. };
  59303. var rotationMap = {
  59304. horizontal: 0,
  59305. vertical: PI / 2
  59306. };
  59307. // Position
  59308. var mainLength = orient === 'vertical' ? viewRect.height : viewRect.width;
  59309. var controlModel = timelineModel.getModel('controlStyle');
  59310. var showControl = controlModel.get('show');
  59311. var controlSize = showControl ? controlModel.get('itemSize') : 0;
  59312. var controlGap = showControl ? controlModel.get('itemGap') : 0;
  59313. var sizePlusGap = controlSize + controlGap;
  59314. // Special label rotate.
  59315. var labelRotation = timelineModel.get('label.normal.rotate') || 0;
  59316. labelRotation = labelRotation * PI / 180; // To radian.
  59317. var playPosition;
  59318. var prevBtnPosition;
  59319. var nextBtnPosition;
  59320. var axisExtent;
  59321. var controlPosition = controlModel.get('position', true);
  59322. var showControl = controlModel.get('show', true);
  59323. var showPlayBtn = showControl && controlModel.get('showPlayBtn', true);
  59324. var showPrevBtn = showControl && controlModel.get('showPrevBtn', true);
  59325. var showNextBtn = showControl && controlModel.get('showNextBtn', true);
  59326. var xLeft = 0;
  59327. var xRight = mainLength;
  59328. // position[0] means left, position[1] means middle.
  59329. if (controlPosition === 'left' || controlPosition === 'bottom') {
  59330. showPlayBtn && (playPosition = [0, 0], xLeft += sizePlusGap);
  59331. showPrevBtn && (prevBtnPosition = [xLeft, 0], xLeft += sizePlusGap);
  59332. showNextBtn && (nextBtnPosition = [xRight - controlSize, 0], xRight -= sizePlusGap);
  59333. }
  59334. else { // 'top' 'right'
  59335. showPlayBtn && (playPosition = [xRight - controlSize, 0], xRight -= sizePlusGap);
  59336. showPrevBtn && (prevBtnPosition = [0, 0], xLeft += sizePlusGap);
  59337. showNextBtn && (nextBtnPosition = [xRight - controlSize, 0], xRight -= sizePlusGap);
  59338. }
  59339. axisExtent = [xLeft, xRight];
  59340. if (timelineModel.get('inverse')) {
  59341. axisExtent.reverse();
  59342. }
  59343. return {
  59344. viewRect: viewRect,
  59345. mainLength: mainLength,
  59346. orient: orient,
  59347. rotation: rotationMap[orient],
  59348. labelRotation: labelRotation,
  59349. labelPosOpt: labelPosOpt,
  59350. labelAlign: labelAlignMap[orient],
  59351. labelBaseline: labelBaselineMap[orient],
  59352. // Based on mainGroup.
  59353. playPosition: playPosition,
  59354. prevBtnPosition: prevBtnPosition,
  59355. nextBtnPosition: nextBtnPosition,
  59356. axisExtent: axisExtent,
  59357. controlSize: controlSize,
  59358. controlGap: controlGap
  59359. };
  59360. },
  59361. _position: function (layoutInfo, timelineModel) {
  59362. // Position is be called finally, because bounding rect is needed for
  59363. // adapt content to fill viewRect (auto adapt offset).
  59364. // Timeline may be not all in the viewRect when 'offset' is specified
  59365. // as a number, because it is more appropriate that label aligns at
  59366. // 'offset' but not the other edge defined by viewRect.
  59367. var mainGroup = this._mainGroup;
  59368. var labelGroup = this._labelGroup;
  59369. var viewRect = layoutInfo.viewRect;
  59370. if (layoutInfo.orient === 'vertical') {
  59371. // transfrom to horizontal, inverse rotate by left-top point.
  59372. var m = matrix.create();
  59373. var rotateOriginX = viewRect.x;
  59374. var rotateOriginY = viewRect.y + viewRect.height;
  59375. matrix.translate(m, m, [-rotateOriginX, -rotateOriginY]);
  59376. matrix.rotate(m, m, -PI / 2);
  59377. matrix.translate(m, m, [rotateOriginX, rotateOriginY]);
  59378. viewRect = viewRect.clone();
  59379. viewRect.applyTransform(m);
  59380. }
  59381. var viewBound = getBound(viewRect);
  59382. var mainBound = getBound(mainGroup.getBoundingRect());
  59383. var labelBound = getBound(labelGroup.getBoundingRect());
  59384. var mainPosition = mainGroup.position;
  59385. var labelsPosition = labelGroup.position;
  59386. labelsPosition[0] = mainPosition[0] = viewBound[0][0];
  59387. var labelPosOpt = layoutInfo.labelPosOpt;
  59388. if (isNaN(labelPosOpt)) { // '+' or '-'
  59389. var mainBoundIdx = labelPosOpt === '+' ? 0 : 1;
  59390. toBound(mainPosition, mainBound, viewBound, 1, mainBoundIdx);
  59391. toBound(labelsPosition, labelBound, viewBound, 1, 1 - mainBoundIdx);
  59392. }
  59393. else {
  59394. var mainBoundIdx = labelPosOpt >= 0 ? 0 : 1;
  59395. toBound(mainPosition, mainBound, viewBound, 1, mainBoundIdx);
  59396. labelsPosition[1] = mainPosition[1] + labelPosOpt;
  59397. }
  59398. mainGroup.attr('position', mainPosition);
  59399. labelGroup.attr('position', labelsPosition);
  59400. mainGroup.rotation = labelGroup.rotation = layoutInfo.rotation;
  59401. setOrigin(mainGroup);
  59402. setOrigin(labelGroup);
  59403. function setOrigin(targetGroup) {
  59404. var pos = targetGroup.position;
  59405. targetGroup.origin = [
  59406. viewBound[0][0] - pos[0],
  59407. viewBound[1][0] - pos[1]
  59408. ];
  59409. }
  59410. function getBound(rect) {
  59411. // [[xmin, xmax], [ymin, ymax]]
  59412. return [
  59413. [rect.x, rect.x + rect.width],
  59414. [rect.y, rect.y + rect.height]
  59415. ];
  59416. }
  59417. function toBound(fromPos, from, to, dimIdx, boundIdx) {
  59418. fromPos[dimIdx] += to[dimIdx][boundIdx] - from[dimIdx][boundIdx];
  59419. }
  59420. },
  59421. _createAxis: function (layoutInfo, timelineModel) {
  59422. var data = timelineModel.getData();
  59423. var axisType = timelineModel.get('axisType');
  59424. var scale = axisHelper.createScaleByModel(timelineModel, axisType);
  59425. var dataExtent = data.getDataExtent('value');
  59426. scale.setExtent(dataExtent[0], dataExtent[1]);
  59427. this._customizeScale(scale, data);
  59428. scale.niceTicks();
  59429. var axis = new TimelineAxis('value', scale, layoutInfo.axisExtent, axisType);
  59430. axis.model = timelineModel;
  59431. return axis;
  59432. },
  59433. _customizeScale: function (scale, data) {
  59434. scale.getTicks = function () {
  59435. return data.mapArray(['value'], function (value) {
  59436. return value;
  59437. });
  59438. };
  59439. scale.getTicksLabels = function () {
  59440. return zrUtil.map(this.getTicks(), scale.getLabel, scale);
  59441. };
  59442. },
  59443. _createGroup: function (name) {
  59444. var newGroup = this['_' + name] = new graphic.Group();
  59445. this.group.add(newGroup);
  59446. return newGroup;
  59447. },
  59448. _renderAxisLine: function (layoutInfo, group, axis, timelineModel) {
  59449. var axisExtent = axis.getExtent();
  59450. if (!timelineModel.get('lineStyle.show')) {
  59451. return;
  59452. }
  59453. group.add(new graphic.Line({
  59454. shape: {
  59455. x1: axisExtent[0], y1: 0,
  59456. x2: axisExtent[1], y2: 0
  59457. },
  59458. style: zrUtil.extend(
  59459. {lineCap: 'round'},
  59460. timelineModel.getModel('lineStyle').getLineStyle()
  59461. ),
  59462. silent: true,
  59463. z2: 1
  59464. }));
  59465. },
  59466. /**
  59467. * @private
  59468. */
  59469. _renderAxisTick: function (layoutInfo, group, axis, timelineModel) {
  59470. var data = timelineModel.getData();
  59471. var ticks = axis.scale.getTicks();
  59472. each(ticks, function (value, dataIndex) {
  59473. var tickCoord = axis.dataToCoord(value);
  59474. var itemModel = data.getItemModel(dataIndex);
  59475. var itemStyleModel = itemModel.getModel('itemStyle.normal');
  59476. var hoverStyleModel = itemModel.getModel('itemStyle.emphasis');
  59477. var symbolOpt = {
  59478. position: [tickCoord, 0],
  59479. onclick: bind(this._changeTimeline, this, dataIndex)
  59480. };
  59481. var el = giveSymbol(itemModel, itemStyleModel, group, symbolOpt);
  59482. graphic.setHoverStyle(el, hoverStyleModel.getItemStyle());
  59483. if (itemModel.get('tooltip')) {
  59484. el.dataIndex = dataIndex;
  59485. el.dataModel = timelineModel;
  59486. }
  59487. else {
  59488. el.dataIndex = el.dataModel = null;
  59489. }
  59490. }, this);
  59491. },
  59492. /**
  59493. * @private
  59494. */
  59495. _renderAxisLabel: function (layoutInfo, group, axis, timelineModel) {
  59496. var labelModel = timelineModel.getModel('label.normal');
  59497. if (!labelModel.get('show')) {
  59498. return;
  59499. }
  59500. var data = timelineModel.getData();
  59501. var ticks = axis.scale.getTicks();
  59502. var labels = axisHelper.getFormattedLabels(
  59503. axis, labelModel.get('formatter')
  59504. );
  59505. var labelInterval = axis.getLabelInterval();
  59506. each(ticks, function (tick, dataIndex) {
  59507. if (axis.isLabelIgnored(dataIndex, labelInterval)) {
  59508. return;
  59509. }
  59510. var itemModel = data.getItemModel(dataIndex);
  59511. var itemTextStyleModel = itemModel.getModel('label.normal.textStyle');
  59512. var hoverTextStyleModel = itemModel.getModel('label.emphasis.textStyle');
  59513. var tickCoord = axis.dataToCoord(tick);
  59514. var textEl = new graphic.Text({
  59515. style: {
  59516. text: labels[dataIndex],
  59517. textAlign: layoutInfo.labelAlign,
  59518. textVerticalAlign: layoutInfo.labelBaseline,
  59519. textFont: itemTextStyleModel.getFont(),
  59520. fill: itemTextStyleModel.getTextColor()
  59521. },
  59522. position: [tickCoord, 0],
  59523. rotation: layoutInfo.labelRotation - layoutInfo.rotation,
  59524. onclick: bind(this._changeTimeline, this, dataIndex),
  59525. silent: false
  59526. });
  59527. group.add(textEl);
  59528. graphic.setHoverStyle(textEl, hoverTextStyleModel.getItemStyle());
  59529. }, this);
  59530. },
  59531. /**
  59532. * @private
  59533. */
  59534. _renderControl: function (layoutInfo, group, axis, timelineModel) {
  59535. var controlSize = layoutInfo.controlSize;
  59536. var rotation = layoutInfo.rotation;
  59537. var itemStyle = timelineModel.getModel('controlStyle.normal').getItemStyle();
  59538. var hoverStyle = timelineModel.getModel('controlStyle.emphasis').getItemStyle();
  59539. var rect = [0, -controlSize / 2, controlSize, controlSize];
  59540. var playState = timelineModel.getPlayState();
  59541. var inverse = timelineModel.get('inverse', true);
  59542. makeBtn(
  59543. layoutInfo.nextBtnPosition,
  59544. 'controlStyle.nextIcon',
  59545. bind(this._changeTimeline, this, inverse ? '-' : '+')
  59546. );
  59547. makeBtn(
  59548. layoutInfo.prevBtnPosition,
  59549. 'controlStyle.prevIcon',
  59550. bind(this._changeTimeline, this, inverse ? '+' : '-')
  59551. );
  59552. makeBtn(
  59553. layoutInfo.playPosition,
  59554. 'controlStyle.' + (playState ? 'stopIcon' : 'playIcon'),
  59555. bind(this._handlePlayClick, this, !playState),
  59556. true
  59557. );
  59558. function makeBtn(position, iconPath, onclick, willRotate) {
  59559. if (!position) {
  59560. return;
  59561. }
  59562. var opt = {
  59563. position: position,
  59564. origin: [controlSize / 2, 0],
  59565. rotation: willRotate ? -rotation : 0,
  59566. rectHover: true,
  59567. style: itemStyle,
  59568. onclick: onclick
  59569. };
  59570. var btn = makeIcon(timelineModel, iconPath, rect, opt);
  59571. group.add(btn);
  59572. graphic.setHoverStyle(btn, hoverStyle);
  59573. }
  59574. },
  59575. _renderCurrentPointer: function (layoutInfo, group, axis, timelineModel) {
  59576. var data = timelineModel.getData();
  59577. var currentIndex = timelineModel.getCurrentIndex();
  59578. var pointerModel = data.getItemModel(currentIndex).getModel('checkpointStyle');
  59579. var me = this;
  59580. var callback = {
  59581. onCreate: function (pointer) {
  59582. pointer.draggable = true;
  59583. pointer.drift = bind(me._handlePointerDrag, me);
  59584. pointer.ondragend = bind(me._handlePointerDragend, me);
  59585. pointerMoveTo(pointer, currentIndex, axis, timelineModel, true);
  59586. },
  59587. onUpdate: function (pointer) {
  59588. pointerMoveTo(pointer, currentIndex, axis, timelineModel);
  59589. }
  59590. };
  59591. // Reuse when exists, for animation and drag.
  59592. this._currentPointer = giveSymbol(
  59593. pointerModel, pointerModel, this._mainGroup, {}, this._currentPointer, callback
  59594. );
  59595. },
  59596. _handlePlayClick: function (nextState) {
  59597. this._clearTimer();
  59598. this.api.dispatchAction({
  59599. type: 'timelinePlayChange',
  59600. playState: nextState,
  59601. from: this.uid
  59602. });
  59603. },
  59604. _handlePointerDrag: function (dx, dy, e) {
  59605. this._clearTimer();
  59606. this._pointerChangeTimeline([e.offsetX, e.offsetY]);
  59607. },
  59608. _handlePointerDragend: function (e) {
  59609. this._pointerChangeTimeline([e.offsetX, e.offsetY], true);
  59610. },
  59611. _pointerChangeTimeline: function (mousePos, trigger) {
  59612. var toCoord = this._toAxisCoord(mousePos)[0];
  59613. var axis = this._axis;
  59614. var axisExtent = numberUtil.asc(axis.getExtent().slice());
  59615. toCoord > axisExtent[1] && (toCoord = axisExtent[1]);
  59616. toCoord < axisExtent[0] && (toCoord = axisExtent[0]);
  59617. this._currentPointer.position[0] = toCoord;
  59618. this._currentPointer.dirty();
  59619. var targetDataIndex = this._findNearestTick(toCoord);
  59620. var timelineModel = this.model;
  59621. if (trigger || (
  59622. targetDataIndex !== timelineModel.getCurrentIndex()
  59623. && timelineModel.get('realtime')
  59624. )) {
  59625. this._changeTimeline(targetDataIndex);
  59626. }
  59627. },
  59628. _doPlayStop: function () {
  59629. this._clearTimer();
  59630. if (this.model.getPlayState()) {
  59631. this._timer = setTimeout(
  59632. bind(handleFrame, this),
  59633. this.model.get('playInterval')
  59634. );
  59635. }
  59636. function handleFrame() {
  59637. // Do not cache
  59638. var timelineModel = this.model;
  59639. this._changeTimeline(
  59640. timelineModel.getCurrentIndex()
  59641. + (timelineModel.get('rewind', true) ? -1 : 1)
  59642. );
  59643. }
  59644. },
  59645. _toAxisCoord: function (vertex) {
  59646. var trans = this._mainGroup.getLocalTransform();
  59647. return graphic.applyTransform(vertex, trans, true);
  59648. },
  59649. _findNearestTick: function (axisCoord) {
  59650. var data = this.model.getData();
  59651. var dist = Infinity;
  59652. var targetDataIndex;
  59653. var axis = this._axis;
  59654. data.each(['value'], function (value, dataIndex) {
  59655. var coord = axis.dataToCoord(value);
  59656. var d = Math.abs(coord - axisCoord);
  59657. if (d < dist) {
  59658. dist = d;
  59659. targetDataIndex = dataIndex;
  59660. }
  59661. });
  59662. return targetDataIndex;
  59663. },
  59664. _clearTimer: function () {
  59665. if (this._timer) {
  59666. clearTimeout(this._timer);
  59667. this._timer = null;
  59668. }
  59669. },
  59670. _changeTimeline: function (nextIndex) {
  59671. var currentIndex = this.model.getCurrentIndex();
  59672. if (nextIndex === '+') {
  59673. nextIndex = currentIndex + 1;
  59674. }
  59675. else if (nextIndex === '-') {
  59676. nextIndex = currentIndex - 1;
  59677. }
  59678. this.api.dispatchAction({
  59679. type: 'timelineChange',
  59680. currentIndex: nextIndex,
  59681. from: this.uid
  59682. });
  59683. }
  59684. });
  59685. function getViewRect(model, api) {
  59686. return layout.getLayoutRect(
  59687. model.getBoxLayoutParams(),
  59688. {
  59689. width: api.getWidth(),
  59690. height: api.getHeight()
  59691. },
  59692. model.get('padding')
  59693. );
  59694. }
  59695. function makeIcon(timelineModel, objPath, rect, opts) {
  59696. var icon = graphic.makePath(
  59697. timelineModel.get(objPath).replace(/^path:\/\//, ''),
  59698. zrUtil.clone(opts || {}),
  59699. new BoundingRect(rect[0], rect[1], rect[2], rect[3]),
  59700. 'center'
  59701. );
  59702. return icon;
  59703. }
  59704. /**
  59705. * Create symbol or update symbol
  59706. * opt: basic position and event handlers
  59707. */
  59708. function giveSymbol(hostModel, itemStyleModel, group, opt, symbol, callback) {
  59709. var color = itemStyleModel.get('color');
  59710. if (!symbol) {
  59711. var symbolType = hostModel.get('symbol');
  59712. symbol = symbolUtil.createSymbol(symbolType, -1, -1, 2, 2, color);
  59713. symbol.setStyle('strokeNoScale', true);
  59714. group.add(symbol);
  59715. callback && callback.onCreate(symbol);
  59716. }
  59717. else {
  59718. symbol.setColor(color);
  59719. group.add(symbol); // Group may be new, also need to add.
  59720. callback && callback.onUpdate(symbol);
  59721. }
  59722. // Style
  59723. var itemStyle = itemStyleModel.getItemStyle(['color', 'symbol', 'symbolSize']);
  59724. symbol.setStyle(itemStyle);
  59725. // Transform and events.
  59726. opt = zrUtil.merge({
  59727. rectHover: true,
  59728. z2: 100
  59729. }, opt, true);
  59730. var symbolSize = hostModel.get('symbolSize');
  59731. symbolSize = symbolSize instanceof Array
  59732. ? symbolSize.slice()
  59733. : [+symbolSize, +symbolSize];
  59734. symbolSize[0] /= 2;
  59735. symbolSize[1] /= 2;
  59736. opt.scale = symbolSize;
  59737. var symbolOffset = hostModel.get('symbolOffset');
  59738. if (symbolOffset) {
  59739. var pos = opt.position = opt.position || [0, 0];
  59740. pos[0] += numberUtil.parsePercent(symbolOffset[0], symbolSize[0]);
  59741. pos[1] += numberUtil.parsePercent(symbolOffset[1], symbolSize[1]);
  59742. }
  59743. var symbolRotate = hostModel.get('symbolRotate');
  59744. opt.rotation = (symbolRotate || 0) * Math.PI / 180 || 0;
  59745. symbol.attr(opt);
  59746. // FIXME
  59747. // (1) When symbol.style.strokeNoScale is true and updateTransform is not performed,
  59748. // getBoundingRect will return wrong result.
  59749. // (This is supposed to be resolved in zrender, but it is a little difficult to
  59750. // leverage performance and auto updateTransform)
  59751. // (2) All of ancesters of symbol do not scale, so we can just updateTransform symbol.
  59752. symbol.updateTransform();
  59753. return symbol;
  59754. }
  59755. function pointerMoveTo(pointer, dataIndex, axis, timelineModel, noAnimation) {
  59756. if (pointer.dragging) {
  59757. return;
  59758. }
  59759. var pointerModel = timelineModel.getModel('checkpointStyle');
  59760. var toCoord = axis.dataToCoord(timelineModel.getData().get(['value'], dataIndex));
  59761. if (noAnimation || !pointerModel.get('animation', true)) {
  59762. pointer.attr({position: [toCoord, 0]});
  59763. }
  59764. else {
  59765. pointer.stopAnimation(true);
  59766. pointer.animateTo(
  59767. {position: [toCoord, 0]},
  59768. pointerModel.get('animationDuration', true),
  59769. pointerModel.get('animationEasing', true)
  59770. );
  59771. }
  59772. }
  59773. /***/ },
  59774. /* 409 */
  59775. /***/ function(module, exports, __webpack_require__) {
  59776. /**
  59777. * @file Timeline view
  59778. */
  59779. // var zrUtil = require('zrender/lib/core/util');
  59780. // var graphic = require('../../util/graphic');
  59781. var ComponentView = __webpack_require__(79);
  59782. module.exports = ComponentView.extend({
  59783. type: 'timeline'
  59784. });
  59785. /***/ },
  59786. /* 410 */
  59787. /***/ function(module, exports, __webpack_require__) {
  59788. var zrUtil = __webpack_require__(4);
  59789. var Axis = __webpack_require__(100);
  59790. var axisHelper = __webpack_require__(101);
  59791. /**
  59792. * Extend axis 2d
  59793. * @constructor module:echarts/coord/cartesian/Axis2D
  59794. * @extends {module:echarts/coord/cartesian/Axis}
  59795. * @param {string} dim
  59796. * @param {*} scale
  59797. * @param {Array.<number>} coordExtent
  59798. * @param {string} axisType
  59799. * @param {string} position
  59800. */
  59801. var TimelineAxis = function (dim, scale, coordExtent, axisType) {
  59802. Axis.call(this, dim, scale, coordExtent);
  59803. /**
  59804. * Axis type
  59805. * - 'category'
  59806. * - 'value'
  59807. * - 'time'
  59808. * - 'log'
  59809. * @type {string}
  59810. */
  59811. this.type = axisType || 'value';
  59812. /**
  59813. * @private
  59814. * @type {number}
  59815. */
  59816. this._autoLabelInterval;
  59817. /**
  59818. * Axis model
  59819. * @param {module:echarts/component/TimelineModel}
  59820. */
  59821. this.model = null;
  59822. };
  59823. TimelineAxis.prototype = {
  59824. constructor: TimelineAxis,
  59825. /**
  59826. * @public
  59827. * @return {number}
  59828. */
  59829. getLabelInterval: function () {
  59830. var timelineModel = this.model;
  59831. var labelModel = timelineModel.getModel('label.normal');
  59832. var labelInterval = labelModel.get('interval');
  59833. if (labelInterval != null && labelInterval != 'auto') {
  59834. return labelInterval;
  59835. }
  59836. var labelInterval = this._autoLabelInterval;
  59837. if (!labelInterval) {
  59838. labelInterval = this._autoLabelInterval = axisHelper.getAxisLabelInterval(
  59839. zrUtil.map(this.scale.getTicks(), this.dataToCoord, this),
  59840. axisHelper.getFormattedLabels(this, labelModel.get('formatter')),
  59841. labelModel.getModel('textStyle').getFont(),
  59842. timelineModel.get('orient') === 'horizontal'
  59843. );
  59844. }
  59845. return labelInterval;
  59846. },
  59847. /**
  59848. * If label is ignored.
  59849. * Automatically used when axis is category and label can not be all shown
  59850. * @public
  59851. * @param {number} idx
  59852. * @return {boolean}
  59853. */
  59854. isLabelIgnored: function (idx) {
  59855. if (this.type === 'category') {
  59856. var labelInterval = this.getLabelInterval();
  59857. return ((typeof labelInterval === 'function')
  59858. && !labelInterval(idx, this.scale.getLabel(idx)))
  59859. || idx % (labelInterval + 1);
  59860. }
  59861. }
  59862. };
  59863. zrUtil.inherits(TimelineAxis, Axis);
  59864. module.exports = TimelineAxis;
  59865. /***/ },
  59866. /* 411 */
  59867. /***/ function(module, exports, __webpack_require__) {
  59868. __webpack_require__(412);
  59869. __webpack_require__(413);
  59870. __webpack_require__(414);
  59871. __webpack_require__(415);
  59872. __webpack_require__(416);
  59873. __webpack_require__(417);
  59874. __webpack_require__(422);
  59875. /***/ },
  59876. /* 412 */
  59877. /***/ function(module, exports, __webpack_require__) {
  59878. var featureManager = __webpack_require__(356);
  59879. var zrUtil = __webpack_require__(4);
  59880. var ToolboxModel = __webpack_require__(1).extendComponentModel({
  59881. type: 'toolbox',
  59882. layoutMode: {
  59883. type: 'box',
  59884. ignoreSize: true
  59885. },
  59886. mergeDefaultAndTheme: function (option) {
  59887. ToolboxModel.superApply(this, 'mergeDefaultAndTheme', arguments);
  59888. zrUtil.each(this.option.feature, function (featureOpt, featureName) {
  59889. var Feature = featureManager.get(featureName);
  59890. Feature && zrUtil.merge(featureOpt, Feature.defaultOption);
  59891. });
  59892. },
  59893. defaultOption: {
  59894. show: true,
  59895. z: 6,
  59896. zlevel: 0,
  59897. orient: 'horizontal',
  59898. left: 'right',
  59899. top: 'top',
  59900. // right
  59901. // bottom
  59902. backgroundColor: 'transparent',
  59903. borderColor: '#ccc',
  59904. borderWidth: 0,
  59905. padding: 5,
  59906. itemSize: 15,
  59907. itemGap: 8,
  59908. showTitle: true,
  59909. iconStyle: {
  59910. normal: {
  59911. borderColor: '#666',
  59912. color: 'none'
  59913. },
  59914. emphasis: {
  59915. borderColor: '#3E98C5'
  59916. }
  59917. }
  59918. // textStyle: {},
  59919. // feature
  59920. }
  59921. });
  59922. module.exports = ToolboxModel;
  59923. /***/ },
  59924. /* 413 */
  59925. /***/ function(module, exports, __webpack_require__) {
  59926. /* WEBPACK VAR INJECTION */(function(process) {
  59927. var featureManager = __webpack_require__(356);
  59928. var zrUtil = __webpack_require__(4);
  59929. var graphic = __webpack_require__(18);
  59930. var Model = __webpack_require__(12);
  59931. var DataDiffer = __webpack_require__(99);
  59932. var listComponentHelper = __webpack_require__(324);
  59933. var textContain = __webpack_require__(8);
  59934. module.exports = __webpack_require__(1).extendComponentView({
  59935. type: 'toolbox',
  59936. render: function (toolboxModel, ecModel, api, payload) {
  59937. var group = this.group;
  59938. group.removeAll();
  59939. if (!toolboxModel.get('show')) {
  59940. return;
  59941. }
  59942. var itemSize = +toolboxModel.get('itemSize');
  59943. var featureOpts = toolboxModel.get('feature') || {};
  59944. var features = this._features || (this._features = {});
  59945. var featureNames = [];
  59946. zrUtil.each(featureOpts, function (opt, name) {
  59947. featureNames.push(name);
  59948. });
  59949. (new DataDiffer(this._featureNames || [], featureNames))
  59950. .add(process)
  59951. .update(process)
  59952. .remove(zrUtil.curry(process, null))
  59953. .execute();
  59954. // Keep for diff.
  59955. this._featureNames = featureNames;
  59956. function process(newIndex, oldIndex) {
  59957. var featureName = featureNames[newIndex];
  59958. var oldName = featureNames[oldIndex];
  59959. var featureOpt = featureOpts[featureName];
  59960. var featureModel = new Model(featureOpt, toolboxModel, toolboxModel.ecModel);
  59961. var feature;
  59962. if (featureName && !oldName) { // Create
  59963. if (isUserFeatureName(featureName)) {
  59964. feature = {
  59965. model: featureModel,
  59966. onclick: featureModel.option.onclick,
  59967. featureName: featureName
  59968. };
  59969. }
  59970. else {
  59971. var Feature = featureManager.get(featureName);
  59972. if (!Feature) {
  59973. return;
  59974. }
  59975. feature = new Feature(featureModel, ecModel, api);
  59976. }
  59977. features[featureName] = feature;
  59978. }
  59979. else {
  59980. feature = features[oldName];
  59981. // If feature does not exsit.
  59982. if (!feature) {
  59983. return;
  59984. }
  59985. feature.model = featureModel;
  59986. feature.ecModel = ecModel;
  59987. feature.api = api;
  59988. }
  59989. if (!featureName && oldName) {
  59990. feature.dispose && feature.dispose(ecModel, api);
  59991. return;
  59992. }
  59993. if (!featureModel.get('show') || feature.unusable) {
  59994. feature.remove && feature.remove(ecModel, api);
  59995. return;
  59996. }
  59997. createIconPaths(featureModel, feature, featureName);
  59998. featureModel.setIconStatus = function (iconName, status) {
  59999. var option = this.option;
  60000. var iconPaths = this.iconPaths;
  60001. option.iconStatus = option.iconStatus || {};
  60002. option.iconStatus[iconName] = status;
  60003. // FIXME
  60004. iconPaths[iconName] && iconPaths[iconName].trigger(status);
  60005. };
  60006. if (feature.render) {
  60007. feature.render(featureModel, ecModel, api, payload);
  60008. }
  60009. }
  60010. function createIconPaths(featureModel, feature, featureName) {
  60011. var iconStyleModel = featureModel.getModel('iconStyle');
  60012. // If one feature has mutiple icon. they are orginaized as
  60013. // {
  60014. // icon: {
  60015. // foo: '',
  60016. // bar: ''
  60017. // },
  60018. // title: {
  60019. // foo: '',
  60020. // bar: ''
  60021. // }
  60022. // }
  60023. var icons = feature.getIcons ? feature.getIcons() : featureModel.get('icon');
  60024. var titles = featureModel.get('title') || {};
  60025. if (typeof icons === 'string') {
  60026. var icon = icons;
  60027. var title = titles;
  60028. icons = {};
  60029. titles = {};
  60030. icons[featureName] = icon;
  60031. titles[featureName] = title;
  60032. }
  60033. var iconPaths = featureModel.iconPaths = {};
  60034. zrUtil.each(icons, function (icon, iconName) {
  60035. var normalStyle = iconStyleModel.getModel('normal').getItemStyle();
  60036. var hoverStyle = iconStyleModel.getModel('emphasis').getItemStyle();
  60037. var style = {
  60038. x: -itemSize / 2,
  60039. y: -itemSize / 2,
  60040. width: itemSize,
  60041. height: itemSize
  60042. };
  60043. var path = icon.indexOf('image://') === 0
  60044. ? (
  60045. style.image = icon.slice(8),
  60046. new graphic.Image({style: style})
  60047. )
  60048. : graphic.makePath(
  60049. icon.replace('path://', ''),
  60050. {
  60051. style: normalStyle,
  60052. hoverStyle: hoverStyle,
  60053. rectHover: true
  60054. },
  60055. style,
  60056. 'center'
  60057. );
  60058. graphic.setHoverStyle(path);
  60059. if (toolboxModel.get('showTitle')) {
  60060. path.__title = titles[iconName];
  60061. path.on('mouseover', function () {
  60062. // Should not reuse above hoverStyle, which might be modified.
  60063. var hoverStyle = iconStyleModel.getModel('emphasis').getItemStyle();
  60064. path.setStyle({
  60065. text: titles[iconName],
  60066. textPosition: hoverStyle.textPosition || 'bottom',
  60067. textFill: hoverStyle.fill || hoverStyle.stroke || '#000',
  60068. textAlign: hoverStyle.textAlign || 'center'
  60069. });
  60070. })
  60071. .on('mouseout', function () {
  60072. path.setStyle({
  60073. textFill: null
  60074. });
  60075. });
  60076. }
  60077. path.trigger(featureModel.get('iconStatus.' + iconName) || 'normal');
  60078. group.add(path);
  60079. path.on('click', zrUtil.bind(
  60080. feature.onclick, feature, ecModel, api, iconName
  60081. ));
  60082. iconPaths[iconName] = path;
  60083. });
  60084. }
  60085. listComponentHelper.layout(group, toolboxModel, api);
  60086. // Render background after group is layout
  60087. // FIXME
  60088. listComponentHelper.addBackground(group, toolboxModel);
  60089. // Adjust icon title positions to avoid them out of screen
  60090. group.eachChild(function (icon) {
  60091. var titleText = icon.__title;
  60092. var hoverStyle = icon.hoverStyle;
  60093. // May be background element
  60094. if (hoverStyle && titleText) {
  60095. var rect = textContain.getBoundingRect(
  60096. titleText, hoverStyle.font
  60097. );
  60098. var offsetX = icon.position[0] + group.position[0];
  60099. var offsetY = icon.position[1] + group.position[1] + itemSize;
  60100. var needPutOnTop = false;
  60101. if (offsetY + rect.height > api.getHeight()) {
  60102. hoverStyle.textPosition = 'top';
  60103. needPutOnTop = true;
  60104. }
  60105. var topOffset = needPutOnTop ? (-5 - rect.height) : (itemSize + 8);
  60106. if (offsetX + rect.width / 2 > api.getWidth()) {
  60107. hoverStyle.textPosition = ['100%', topOffset];
  60108. hoverStyle.textAlign = 'right';
  60109. }
  60110. else if (offsetX - rect.width / 2 < 0) {
  60111. hoverStyle.textPosition = [0, topOffset];
  60112. hoverStyle.textAlign = 'left';
  60113. }
  60114. }
  60115. });
  60116. },
  60117. updateView: function (toolboxModel, ecModel, api, payload) {
  60118. zrUtil.each(this._features, function (feature) {
  60119. feature.updateView && feature.updateView(feature.model, ecModel, api, payload);
  60120. });
  60121. },
  60122. updateLayout: function (toolboxModel, ecModel, api, payload) {
  60123. zrUtil.each(this._features, function (feature) {
  60124. feature.updateLayout && feature.updateLayout(feature.model, ecModel, api, payload);
  60125. });
  60126. },
  60127. remove: function (ecModel, api) {
  60128. zrUtil.each(this._features, function (feature) {
  60129. feature.remove && feature.remove(ecModel, api);
  60130. });
  60131. this.group.removeAll();
  60132. },
  60133. dispose: function (ecModel, api) {
  60134. zrUtil.each(this._features, function (feature) {
  60135. feature.dispose && feature.dispose(ecModel, api);
  60136. });
  60137. }
  60138. });
  60139. function isUserFeatureName(featureName) {
  60140. return featureName.indexOf('my') === 0;
  60141. }
  60142. /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(309)))
  60143. /***/ },
  60144. /* 414 */
  60145. /***/ function(module, exports, __webpack_require__) {
  60146. var env = __webpack_require__(2);
  60147. function SaveAsImage (model) {
  60148. this.model = model;
  60149. }
  60150. SaveAsImage.defaultOption = {
  60151. show: true,
  60152. 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',
  60153. title: '保存为图片',
  60154. type: 'png',
  60155. // Default use option.backgroundColor
  60156. // backgroundColor: '#fff',
  60157. name: '',
  60158. excludeComponents: ['toolbox'],
  60159. pixelRatio: 1,
  60160. lang: ['右键另存为图片']
  60161. };
  60162. SaveAsImage.prototype.unusable = !env.canvasSupported;
  60163. var proto = SaveAsImage.prototype;
  60164. proto.onclick = function (ecModel, api) {
  60165. var model = this.model;
  60166. var title = model.get('name') || ecModel.get('title.0.text') || 'echarts';
  60167. var $a = document.createElement('a');
  60168. var type = model.get('type', true) || 'png';
  60169. $a.download = title + '.' + type;
  60170. $a.target = '_blank';
  60171. var url = api.getConnectedDataURL({
  60172. type: type,
  60173. backgroundColor: model.get('backgroundColor', true)
  60174. || ecModel.get('backgroundColor') || '#fff',
  60175. excludeComponents: model.get('excludeComponents'),
  60176. pixelRatio: model.get('pixelRatio')
  60177. });
  60178. $a.href = url;
  60179. // Chrome and Firefox
  60180. if (typeof MouseEvent === 'function' && !env.browser.ie && !env.browser.edge) {
  60181. var evt = new MouseEvent('click', {
  60182. view: window,
  60183. bubbles: true,
  60184. cancelable: false
  60185. });
  60186. $a.dispatchEvent(evt);
  60187. }
  60188. // IE
  60189. else {
  60190. var lang = model.get('lang');
  60191. var html = ''
  60192. + '<body style="margin:0;">'
  60193. + '<img src="' + url + '" style="max-width:100%;" title="' + ((lang && lang[0]) || '') + '" />'
  60194. + '</body>';
  60195. var tab = window.open();
  60196. tab.document.write(html);
  60197. }
  60198. };
  60199. __webpack_require__(356).register(
  60200. 'saveAsImage', SaveAsImage
  60201. );
  60202. module.exports = SaveAsImage;
  60203. /***/ },
  60204. /* 415 */
  60205. /***/ function(module, exports, __webpack_require__) {
  60206. 'use strict';
  60207. var zrUtil = __webpack_require__(4);
  60208. function MagicType(model) {
  60209. this.model = model;
  60210. }
  60211. MagicType.defaultOption = {
  60212. show: true,
  60213. type: [],
  60214. // Icon group
  60215. icon: {
  60216. line: 'M4.1,28.9h7.1l9.3-22l7.4,38l9.7-19.7l3,12.8h14.9M4.1,58h51.4',
  60217. bar: 'M6.7,22.9h10V48h-10V22.9zM24.9,13h10v35h-10V13zM43.2,2h10v46h-10V2zM3.1,58h53.7',
  60218. 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
  60219. tiled: 'M2.3,2.2h22.8V25H2.3V2.2z M35,2.2h22.8V25H35V2.2zM2.3,35h22.8v22.8H2.3V35z M35,35h22.8v22.8H35V35z'
  60220. },
  60221. title: {
  60222. line: '切换为折线图',
  60223. bar: '切换为柱状图',
  60224. stack: '切换为堆叠',
  60225. tiled: '切换为平铺'
  60226. },
  60227. option: {},
  60228. seriesIndex: {}
  60229. };
  60230. var proto = MagicType.prototype;
  60231. proto.getIcons = function () {
  60232. var model = this.model;
  60233. var availableIcons = model.get('icon');
  60234. var icons = {};
  60235. zrUtil.each(model.get('type'), function (type) {
  60236. if (availableIcons[type]) {
  60237. icons[type] = availableIcons[type];
  60238. }
  60239. });
  60240. return icons;
  60241. };
  60242. var seriesOptGenreator = {
  60243. 'line': function (seriesType, seriesId, seriesModel, model) {
  60244. if (seriesType === 'bar') {
  60245. return zrUtil.merge({
  60246. id: seriesId,
  60247. type: 'line',
  60248. // Preserve data related option
  60249. data: seriesModel.get('data'),
  60250. stack: seriesModel.get('stack'),
  60251. markPoint: seriesModel.get('markPoint'),
  60252. markLine: seriesModel.get('markLine')
  60253. }, model.get('option.line') || {}, true);
  60254. }
  60255. },
  60256. 'bar': function (seriesType, seriesId, seriesModel, model) {
  60257. if (seriesType === 'line') {
  60258. return zrUtil.merge({
  60259. id: seriesId,
  60260. type: 'bar',
  60261. // Preserve data related option
  60262. data: seriesModel.get('data'),
  60263. stack: seriesModel.get('stack'),
  60264. markPoint: seriesModel.get('markPoint'),
  60265. markLine: seriesModel.get('markLine')
  60266. }, model.get('option.bar') || {}, true);
  60267. }
  60268. },
  60269. 'stack': function (seriesType, seriesId, seriesModel, model) {
  60270. if (seriesType === 'line' || seriesType === 'bar') {
  60271. return zrUtil.merge({
  60272. id: seriesId,
  60273. stack: '__ec_magicType_stack__'
  60274. }, model.get('option.stack') || {}, true);
  60275. }
  60276. },
  60277. 'tiled': function (seriesType, seriesId, seriesModel, model) {
  60278. if (seriesType === 'line' || seriesType === 'bar') {
  60279. return zrUtil.merge({
  60280. id: seriesId,
  60281. stack: ''
  60282. }, model.get('option.tiled') || {}, true);
  60283. }
  60284. }
  60285. };
  60286. var radioTypes = [
  60287. ['line', 'bar'],
  60288. ['stack', 'tiled']
  60289. ];
  60290. proto.onclick = function (ecModel, api, type) {
  60291. var model = this.model;
  60292. var seriesIndex = model.get('seriesIndex.' + type);
  60293. // Not supported magicType
  60294. if (!seriesOptGenreator[type]) {
  60295. return;
  60296. }
  60297. var newOption = {
  60298. series: []
  60299. };
  60300. var generateNewSeriesTypes = function (seriesModel) {
  60301. var seriesType = seriesModel.subType;
  60302. var seriesId = seriesModel.id;
  60303. var newSeriesOpt = seriesOptGenreator[type](
  60304. seriesType, seriesId, seriesModel, model
  60305. );
  60306. if (newSeriesOpt) {
  60307. // PENDING If merge original option?
  60308. zrUtil.defaults(newSeriesOpt, seriesModel.option);
  60309. newOption.series.push(newSeriesOpt);
  60310. }
  60311. // Modify boundaryGap
  60312. var coordSys = seriesModel.coordinateSystem;
  60313. if (coordSys && coordSys.type === 'cartesian2d' && (type === 'line' || type === 'bar')) {
  60314. var categoryAxis = coordSys.getAxesByScale('ordinal')[0];
  60315. if (categoryAxis) {
  60316. var axisDim = categoryAxis.dim;
  60317. var axisType = axisDim + 'Axis';
  60318. var axisModel = ecModel.queryComponents({
  60319. mainType: axisType,
  60320. index: seriesModel.get(name + 'Index'),
  60321. id: seriesModel.get(name + 'Id')
  60322. })[0];
  60323. var axisIndex = axisModel.componentIndex;
  60324. newOption[axisType] = newOption[axisType] || [];
  60325. for (var i = 0; i <= axisIndex; i++) {
  60326. newOption[axisType][axisIndex] = newOption[axisType][axisIndex] || {};
  60327. }
  60328. newOption[axisType][axisIndex].boundaryGap = type === 'bar' ? true : false;
  60329. }
  60330. }
  60331. };
  60332. zrUtil.each(radioTypes, function (radio) {
  60333. if (zrUtil.indexOf(radio, type) >= 0) {
  60334. zrUtil.each(radio, function (item) {
  60335. model.setIconStatus(item, 'normal');
  60336. });
  60337. }
  60338. });
  60339. model.setIconStatus(type, 'emphasis');
  60340. ecModel.eachComponent(
  60341. {
  60342. mainType: 'series',
  60343. query: seriesIndex == null ? null : {
  60344. seriesIndex: seriesIndex
  60345. }
  60346. }, generateNewSeriesTypes
  60347. );
  60348. api.dispatchAction({
  60349. type: 'changeMagicType',
  60350. currentType: type,
  60351. newOption: newOption
  60352. });
  60353. };
  60354. var echarts = __webpack_require__(1);
  60355. echarts.registerAction({
  60356. type: 'changeMagicType',
  60357. event: 'magicTypeChanged',
  60358. update: 'prepareAndUpdate'
  60359. }, function (payload, ecModel) {
  60360. ecModel.mergeOption(payload.newOption);
  60361. });
  60362. __webpack_require__(356).register('magicType', MagicType);
  60363. module.exports = MagicType;
  60364. /***/ },
  60365. /* 416 */
  60366. /***/ function(module, exports, __webpack_require__) {
  60367. /**
  60368. * @module echarts/component/toolbox/feature/DataView
  60369. */
  60370. var zrUtil = __webpack_require__(4);
  60371. var eventTool = __webpack_require__(88);
  60372. var BLOCK_SPLITER = new Array(60).join('-');
  60373. var ITEM_SPLITER = '\t';
  60374. /**
  60375. * Group series into two types
  60376. * 1. on category axis, like line, bar
  60377. * 2. others, like scatter, pie
  60378. * @param {module:echarts/model/Global} ecModel
  60379. * @return {Object}
  60380. * @inner
  60381. */
  60382. function groupSeries(ecModel) {
  60383. var seriesGroupByCategoryAxis = {};
  60384. var otherSeries = [];
  60385. var meta = [];
  60386. ecModel.eachRawSeries(function (seriesModel) {
  60387. var coordSys = seriesModel.coordinateSystem;
  60388. if (coordSys && (coordSys.type === 'cartesian2d' || coordSys.type === 'polar')) {
  60389. var baseAxis = coordSys.getBaseAxis();
  60390. if (baseAxis.type === 'category') {
  60391. var key = baseAxis.dim + '_' + baseAxis.index;
  60392. if (!seriesGroupByCategoryAxis[key]) {
  60393. seriesGroupByCategoryAxis[key] = {
  60394. categoryAxis: baseAxis,
  60395. valueAxis: coordSys.getOtherAxis(baseAxis),
  60396. series: []
  60397. };
  60398. meta.push({
  60399. axisDim: baseAxis.dim,
  60400. axisIndex: baseAxis.index
  60401. });
  60402. }
  60403. seriesGroupByCategoryAxis[key].series.push(seriesModel);
  60404. }
  60405. else {
  60406. otherSeries.push(seriesModel);
  60407. }
  60408. }
  60409. else {
  60410. otherSeries.push(seriesModel);
  60411. }
  60412. });
  60413. return {
  60414. seriesGroupByCategoryAxis: seriesGroupByCategoryAxis,
  60415. other: otherSeries,
  60416. meta: meta
  60417. };
  60418. }
  60419. /**
  60420. * Assemble content of series on cateogory axis
  60421. * @param {Array.<module:echarts/model/Series>} series
  60422. * @return {string}
  60423. * @inner
  60424. */
  60425. function assembleSeriesWithCategoryAxis(series) {
  60426. var tables = [];
  60427. zrUtil.each(series, function (group, key) {
  60428. var categoryAxis = group.categoryAxis;
  60429. var valueAxis = group.valueAxis;
  60430. var valueAxisDim = valueAxis.dim;
  60431. var headers = [' '].concat(zrUtil.map(group.series, function (series) {
  60432. return series.name;
  60433. }));
  60434. var columns = [categoryAxis.model.getCategories()];
  60435. zrUtil.each(group.series, function (series) {
  60436. columns.push(series.getRawData().mapArray(valueAxisDim, function (val) {
  60437. return val;
  60438. }));
  60439. });
  60440. // Assemble table content
  60441. var lines = [headers.join(ITEM_SPLITER)];
  60442. for (var i = 0; i < columns[0].length; i++) {
  60443. var items = [];
  60444. for (var j = 0; j < columns.length; j++) {
  60445. items.push(columns[j][i]);
  60446. }
  60447. lines.push(items.join(ITEM_SPLITER));
  60448. }
  60449. tables.push(lines.join('\n'));
  60450. });
  60451. return tables.join('\n\n' + BLOCK_SPLITER + '\n\n');
  60452. }
  60453. /**
  60454. * Assemble content of other series
  60455. * @param {Array.<module:echarts/model/Series>} series
  60456. * @return {string}
  60457. * @inner
  60458. */
  60459. function assembleOtherSeries(series) {
  60460. return zrUtil.map(series, function (series) {
  60461. var data = series.getRawData();
  60462. var lines = [series.name];
  60463. var vals = [];
  60464. data.each(data.dimensions, function () {
  60465. var argLen = arguments.length;
  60466. var dataIndex = arguments[argLen - 1];
  60467. var name = data.getName(dataIndex);
  60468. for (var i = 0; i < argLen - 1; i++) {
  60469. vals[i] = arguments[i];
  60470. }
  60471. lines.push((name ? (name + ITEM_SPLITER) : '') + vals.join(ITEM_SPLITER));
  60472. });
  60473. return lines.join('\n');
  60474. }).join('\n\n' + BLOCK_SPLITER + '\n\n');
  60475. }
  60476. /**
  60477. * @param {module:echarts/model/Global}
  60478. * @return {string}
  60479. * @inner
  60480. */
  60481. function getContentFromModel(ecModel) {
  60482. var result = groupSeries(ecModel);
  60483. return {
  60484. value: zrUtil.filter([
  60485. assembleSeriesWithCategoryAxis(result.seriesGroupByCategoryAxis),
  60486. assembleOtherSeries(result.other)
  60487. ], function (str) {
  60488. return str.replace(/[\n\t\s]/g, '');
  60489. }).join('\n\n' + BLOCK_SPLITER + '\n\n'),
  60490. meta: result.meta
  60491. };
  60492. }
  60493. function trim(str) {
  60494. return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
  60495. }
  60496. /**
  60497. * If a block is tsv format
  60498. */
  60499. function isTSVFormat(block) {
  60500. // Simple method to find out if a block is tsv format
  60501. var firstLine = block.slice(0, block.indexOf('\n'));
  60502. if (firstLine.indexOf(ITEM_SPLITER) >= 0) {
  60503. return true;
  60504. }
  60505. }
  60506. var itemSplitRegex = new RegExp('[' + ITEM_SPLITER + ']+', 'g');
  60507. /**
  60508. * @param {string} tsv
  60509. * @return {Array.<Object>}
  60510. */
  60511. function parseTSVContents(tsv) {
  60512. var tsvLines = tsv.split(/\n+/g);
  60513. var headers = trim(tsvLines.shift()).split(itemSplitRegex);
  60514. var categories = [];
  60515. var series = zrUtil.map(headers, function (header) {
  60516. return {
  60517. name: header,
  60518. data: []
  60519. };
  60520. });
  60521. for (var i = 0; i < tsvLines.length; i++) {
  60522. var items = trim(tsvLines[i]).split(itemSplitRegex);
  60523. categories.push(items.shift());
  60524. for (var j = 0; j < items.length; j++) {
  60525. series[j] && (series[j].data[i] = items[j]);
  60526. }
  60527. }
  60528. return {
  60529. series: series,
  60530. categories: categories
  60531. };
  60532. }
  60533. /**
  60534. * @param {string} str
  60535. * @return {Array.<Object>}
  60536. * @inner
  60537. */
  60538. function parseListContents(str) {
  60539. var lines = str.split(/\n+/g);
  60540. var seriesName = trim(lines.shift());
  60541. var data = [];
  60542. for (var i = 0; i < lines.length; i++) {
  60543. var items = trim(lines[i]).split(itemSplitRegex);
  60544. var name = '';
  60545. var value;
  60546. var hasName = false;
  60547. if (isNaN(items[0])) { // First item is name
  60548. hasName = true;
  60549. name = items[0];
  60550. items = items.slice(1);
  60551. data[i] = {
  60552. name: name,
  60553. value: []
  60554. };
  60555. value = data[i].value;
  60556. }
  60557. else {
  60558. value = data[i] = [];
  60559. }
  60560. for (var j = 0; j < items.length; j++) {
  60561. value.push(+items[j]);
  60562. }
  60563. if (value.length === 1) {
  60564. hasName ? (data[i].value = value[0]) : (data[i] = value[0]);
  60565. }
  60566. }
  60567. return {
  60568. name: seriesName,
  60569. data: data
  60570. };
  60571. }
  60572. /**
  60573. * @param {string} str
  60574. * @param {Array.<Object>} blockMetaList
  60575. * @return {Object}
  60576. * @inner
  60577. */
  60578. function parseContents(str, blockMetaList) {
  60579. var blocks = str.split(new RegExp('\n*' + BLOCK_SPLITER + '\n*', 'g'));
  60580. var newOption = {
  60581. series: []
  60582. };
  60583. zrUtil.each(blocks, function (block, idx) {
  60584. if (isTSVFormat(block)) {
  60585. var result = parseTSVContents(block);
  60586. var blockMeta = blockMetaList[idx];
  60587. var axisKey = blockMeta.axisDim + 'Axis';
  60588. if (blockMeta) {
  60589. newOption[axisKey] = newOption[axisKey] || [];
  60590. newOption[axisKey][blockMeta.axisIndex] = {
  60591. data: result.categories
  60592. };
  60593. newOption.series = newOption.series.concat(result.series);
  60594. }
  60595. }
  60596. else {
  60597. var result = parseListContents(block);
  60598. newOption.series.push(result);
  60599. }
  60600. });
  60601. return newOption;
  60602. }
  60603. /**
  60604. * @alias {module:echarts/component/toolbox/feature/DataView}
  60605. * @constructor
  60606. * @param {module:echarts/model/Model} model
  60607. */
  60608. function DataView(model) {
  60609. this._dom = null;
  60610. this.model = model;
  60611. }
  60612. DataView.defaultOption = {
  60613. show: true,
  60614. readOnly: false,
  60615. optionToContent: null,
  60616. contentToOption: null,
  60617. 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',
  60618. title: '数据视图',
  60619. lang: ['数据视图', '关闭', '刷新'],
  60620. backgroundColor: '#fff',
  60621. textColor: '#000',
  60622. textareaColor: '#fff',
  60623. textareaBorderColor: '#333',
  60624. buttonColor: '#c23531',
  60625. buttonTextColor: '#fff'
  60626. };
  60627. DataView.prototype.onclick = function (ecModel, api) {
  60628. var container = api.getDom();
  60629. var model = this.model;
  60630. if (this._dom) {
  60631. container.removeChild(this._dom);
  60632. }
  60633. var root = document.createElement('div');
  60634. root.style.cssText = 'position:absolute;left:5px;top:5px;bottom:5px;right:5px;';
  60635. root.style.backgroundColor = model.get('backgroundColor') || '#fff';
  60636. // Create elements
  60637. var header = document.createElement('h4');
  60638. var lang = model.get('lang') || [];
  60639. header.innerHTML = lang[0] || model.get('title');
  60640. header.style.cssText = 'margin: 10px 20px;';
  60641. header.style.color = model.get('textColor');
  60642. var viewMain = document.createElement('div');
  60643. var textarea = document.createElement('textarea');
  60644. viewMain.style.cssText = 'display:block;width:100%;overflow:auto;';
  60645. var optionToContent = model.get('optionToContent');
  60646. var contentToOption = model.get('contentToOption');
  60647. var result = getContentFromModel(ecModel);
  60648. if (typeof optionToContent === 'function') {
  60649. var htmlOrDom = optionToContent(api.getOption());
  60650. if (typeof htmlOrDom === 'string') {
  60651. viewMain.innerHTML = htmlOrDom;
  60652. }
  60653. else if (zrUtil.isDom(htmlOrDom)) {
  60654. viewMain.appendChild(htmlOrDom);
  60655. }
  60656. }
  60657. else {
  60658. // Use default textarea
  60659. viewMain.appendChild(textarea);
  60660. textarea.readOnly = model.get('readOnly');
  60661. textarea.style.cssText = 'width:100%;height:100%;font-family:monospace;font-size:14px;line-height:1.6rem;';
  60662. textarea.style.color = model.get('textColor');
  60663. textarea.style.borderColor = model.get('textareaBorderColor');
  60664. textarea.style.backgroundColor = model.get('textareaColor');
  60665. textarea.value = result.value;
  60666. }
  60667. var blockMetaList = result.meta;
  60668. var buttonContainer = document.createElement('div');
  60669. buttonContainer.style.cssText = 'position:absolute;bottom:0;left:0;right:0;';
  60670. var buttonStyle = 'float:right;margin-right:20px;border:none;'
  60671. + 'cursor:pointer;padding:2px 5px;font-size:12px;border-radius:3px';
  60672. var closeButton = document.createElement('div');
  60673. var refreshButton = document.createElement('div');
  60674. buttonStyle += ';background-color:' + model.get('buttonColor');
  60675. buttonStyle += ';color:' + model.get('buttonTextColor');
  60676. var self = this;
  60677. function close() {
  60678. container.removeChild(root);
  60679. self._dom = null;
  60680. }
  60681. eventTool.addEventListener(closeButton, 'click', close);
  60682. eventTool.addEventListener(refreshButton, 'click', function () {
  60683. var newOption;
  60684. try {
  60685. if (typeof contentToOption === 'function') {
  60686. newOption = contentToOption(viewMain, api.getOption());
  60687. }
  60688. else {
  60689. newOption = parseContents(textarea.value, blockMetaList);
  60690. }
  60691. }
  60692. catch (e) {
  60693. close();
  60694. throw new Error('Data view format error ' + e);
  60695. }
  60696. if (newOption) {
  60697. api.dispatchAction({
  60698. type: 'changeDataView',
  60699. newOption: newOption
  60700. });
  60701. }
  60702. close();
  60703. });
  60704. closeButton.innerHTML = lang[1];
  60705. refreshButton.innerHTML = lang[2];
  60706. refreshButton.style.cssText = buttonStyle;
  60707. closeButton.style.cssText = buttonStyle;
  60708. !model.get('readOnly') && buttonContainer.appendChild(refreshButton);
  60709. buttonContainer.appendChild(closeButton);
  60710. // http://stackoverflow.com/questions/6637341/use-tab-to-indent-in-textarea
  60711. eventTool.addEventListener(textarea, 'keydown', function (e) {
  60712. if ((e.keyCode || e.which) === 9) {
  60713. // get caret position/selection
  60714. var val = this.value;
  60715. var start = this.selectionStart;
  60716. var end = this.selectionEnd;
  60717. // set textarea value to: text before caret + tab + text after caret
  60718. this.value = val.substring(0, start) + ITEM_SPLITER + val.substring(end);
  60719. // put caret at right position again
  60720. this.selectionStart = this.selectionEnd = start + 1;
  60721. // prevent the focus lose
  60722. eventTool.stop(e);
  60723. }
  60724. });
  60725. root.appendChild(header);
  60726. root.appendChild(viewMain);
  60727. root.appendChild(buttonContainer);
  60728. viewMain.style.height = (container.clientHeight - 80) + 'px';
  60729. container.appendChild(root);
  60730. this._dom = root;
  60731. };
  60732. DataView.prototype.remove = function (ecModel, api) {
  60733. this._dom && api.getDom().removeChild(this._dom);
  60734. };
  60735. DataView.prototype.dispose = function (ecModel, api) {
  60736. this.remove(ecModel, api);
  60737. };
  60738. /**
  60739. * @inner
  60740. */
  60741. function tryMergeDataOption(newData, originalData) {
  60742. return zrUtil.map(newData, function (newVal, idx) {
  60743. var original = originalData && originalData[idx];
  60744. if (zrUtil.isObject(original) && !zrUtil.isArray(original)) {
  60745. if (zrUtil.isObject(newVal) && !zrUtil.isArray(newVal)) {
  60746. newVal = newVal.value;
  60747. }
  60748. // Original data has option
  60749. return zrUtil.defaults({
  60750. value: newVal
  60751. }, original);
  60752. }
  60753. else {
  60754. return newVal;
  60755. }
  60756. });
  60757. }
  60758. __webpack_require__(356).register('dataView', DataView);
  60759. __webpack_require__(1).registerAction({
  60760. type: 'changeDataView',
  60761. event: 'dataViewChanged',
  60762. update: 'prepareAndUpdate'
  60763. }, function (payload, ecModel) {
  60764. var newSeriesOptList = [];
  60765. zrUtil.each(payload.newOption.series, function (seriesOpt) {
  60766. var seriesModel = ecModel.getSeriesByName(seriesOpt.name)[0];
  60767. if (!seriesModel) {
  60768. // New created series
  60769. // Geuss the series type
  60770. newSeriesOptList.push(zrUtil.extend({
  60771. // Default is scatter
  60772. type: 'scatter'
  60773. }, seriesOpt));
  60774. }
  60775. else {
  60776. var originalData = seriesModel.get('data');
  60777. newSeriesOptList.push({
  60778. name: seriesOpt.name,
  60779. data: tryMergeDataOption(seriesOpt.data, originalData)
  60780. });
  60781. }
  60782. });
  60783. ecModel.mergeOption(zrUtil.defaults({
  60784. series: newSeriesOptList
  60785. }, payload.newOption));
  60786. });
  60787. module.exports = DataView;
  60788. /***/ },
  60789. /* 417 */
  60790. /***/ function(module, exports, __webpack_require__) {
  60791. 'use strict';
  60792. var zrUtil = __webpack_require__(4);
  60793. var BrushController = __webpack_require__(244);
  60794. var BrushTargetManager = __webpack_require__(351);
  60795. var history = __webpack_require__(418);
  60796. var sliderMove = __webpack_require__(238);
  60797. var each = zrUtil.each;
  60798. // Use dataZoomSelect
  60799. __webpack_require__(419);
  60800. // Spectial component id start with \0ec\0, see echarts/model/Global.js~hasInnerId
  60801. var DATA_ZOOM_ID_BASE = '\0_ec_\0toolbox-dataZoom_';
  60802. function DataZoom(model, ecModel, api) {
  60803. /**
  60804. * @private
  60805. * @type {module:echarts/component/helper/BrushController}
  60806. */
  60807. (this._brushController = new BrushController(api.getZr()))
  60808. .on('brush', zrUtil.bind(this._onBrush, this))
  60809. .mount();
  60810. /**
  60811. * @private
  60812. * @type {boolean}
  60813. */
  60814. this._isZoomActive;
  60815. }
  60816. DataZoom.defaultOption = {
  60817. show: true,
  60818. // Icon group
  60819. icon: {
  60820. zoom: 'M0,13.5h26.9 M13.5,26.9V0 M32.1,13.5H58V58H13.5 V32.1',
  60821. back: 'M22,1.4L9.9,13.5l12.3,12.3 M10.3,13.5H54.9v44.6 H10.3v-26'
  60822. },
  60823. title: {
  60824. zoom: '区域缩放',
  60825. back: '区域缩放还原'
  60826. }
  60827. };
  60828. var proto = DataZoom.prototype;
  60829. proto.render = function (featureModel, ecModel, api, payload) {
  60830. this.model = featureModel;
  60831. this.ecModel = ecModel;
  60832. this.api = api;
  60833. updateZoomBtnStatus(featureModel, ecModel, this, payload, api);
  60834. updateBackBtnStatus(featureModel, ecModel);
  60835. };
  60836. proto.onclick = function (ecModel, api, type) {
  60837. handlers[type].call(this);
  60838. };
  60839. proto.remove = function (ecModel, api) {
  60840. this._brushController.unmount();
  60841. };
  60842. proto.dispose = function (ecModel, api) {
  60843. this._brushController.dispose();
  60844. };
  60845. /**
  60846. * @private
  60847. */
  60848. var handlers = {
  60849. zoom: function () {
  60850. var nextActive = !this._isZoomActive;
  60851. this.api.dispatchAction({
  60852. type: 'takeGlobalCursor',
  60853. key: 'dataZoomSelect',
  60854. dataZoomSelectActive: nextActive
  60855. });
  60856. },
  60857. back: function () {
  60858. this._dispatchZoomAction(history.pop(this.ecModel));
  60859. }
  60860. };
  60861. /**
  60862. * @private
  60863. */
  60864. proto._onBrush = function (areas, opt) {
  60865. if (!opt.isEnd || !areas.length) {
  60866. return;
  60867. }
  60868. var snapshot = {};
  60869. var ecModel = this.ecModel;
  60870. this._brushController.updateCovers([]); // remove cover
  60871. var brushTargetManager = new BrushTargetManager(
  60872. retrieveAxisSetting(this.model.option), ecModel, {include: ['grid']}
  60873. );
  60874. brushTargetManager.matchOutputRanges(areas, ecModel, function (area, coordRange, coordSys) {
  60875. if (coordSys.type !== 'cartesian2d') {
  60876. return;
  60877. }
  60878. var brushType = area.brushType;
  60879. if (brushType === 'rect') {
  60880. setBatch('x', coordSys, coordRange[0]);
  60881. setBatch('y', coordSys, coordRange[1]);
  60882. }
  60883. else {
  60884. setBatch(({lineX: 'x', lineY: 'y'})[brushType], coordSys, coordRange);
  60885. }
  60886. });
  60887. history.push(ecModel, snapshot);
  60888. this._dispatchZoomAction(snapshot);
  60889. function setBatch(dimName, coordSys, minMax) {
  60890. var axis = coordSys.getAxis(dimName);
  60891. var axisModel = axis.model;
  60892. var dataZoomModel = findDataZoom(dimName, axisModel, ecModel);
  60893. // Restrict range.
  60894. var minMaxSpan = dataZoomModel.findRepresentativeAxisProxy(axisModel).getMinMaxSpan();
  60895. if (minMaxSpan.minValueSpan != null || minMaxSpan.maxValueSpan != null) {
  60896. minMax = sliderMove(
  60897. 0, minMax.slice(), axis.scale.getExtent(), 0,
  60898. minMaxSpan.minValueSpan, minMaxSpan.maxValueSpan
  60899. );
  60900. }
  60901. dataZoomModel && (snapshot[dataZoomModel.id] = {
  60902. dataZoomId: dataZoomModel.id,
  60903. startValue: minMax[0],
  60904. endValue: minMax[1]
  60905. });
  60906. }
  60907. function findDataZoom(dimName, axisModel, ecModel) {
  60908. var found;
  60909. ecModel.eachComponent({mainType: 'dataZoom', subType: 'select'}, function (dzModel) {
  60910. var has = dzModel.getAxisModel(dimName, axisModel.componentIndex);
  60911. has && (found = dzModel);
  60912. });
  60913. return found;
  60914. }
  60915. };
  60916. /**
  60917. * @private
  60918. */
  60919. proto._dispatchZoomAction = function (snapshot) {
  60920. var batch = [];
  60921. // Convert from hash map to array.
  60922. each(snapshot, function (batchItem, dataZoomId) {
  60923. batch.push(zrUtil.clone(batchItem));
  60924. });
  60925. batch.length && this.api.dispatchAction({
  60926. type: 'dataZoom',
  60927. from: this.uid,
  60928. batch: batch
  60929. });
  60930. };
  60931. function retrieveAxisSetting(option) {
  60932. var setting = {};
  60933. // Compatible with previous setting: null => all axis, false => no axis.
  60934. zrUtil.each(['xAxisIndex', 'yAxisIndex'], function (name) {
  60935. setting[name] = option[name];
  60936. setting[name] == null && (setting[name] = 'all');
  60937. (setting[name] === false || setting[name] === 'none') && (setting[name] = []);
  60938. });
  60939. return setting;
  60940. }
  60941. function updateBackBtnStatus(featureModel, ecModel) {
  60942. featureModel.setIconStatus(
  60943. 'back',
  60944. history.count(ecModel) > 1 ? 'emphasis' : 'normal'
  60945. );
  60946. }
  60947. function updateZoomBtnStatus(featureModel, ecModel, view, payload, api) {
  60948. var zoomActive = view._isZoomActive;
  60949. if (payload && payload.type === 'takeGlobalCursor') {
  60950. zoomActive = payload.key === 'dataZoomSelect'
  60951. ? payload.dataZoomSelectActive : false;
  60952. }
  60953. view._isZoomActive = zoomActive;
  60954. featureModel.setIconStatus('zoom', zoomActive ? 'emphasis' : 'normal');
  60955. var brushTargetManager = new BrushTargetManager(
  60956. retrieveAxisSetting(featureModel.option), ecModel, {include: ['grid']}
  60957. );
  60958. view._brushController
  60959. .setPanels(brushTargetManager.makePanelOpts(api, function (targetInfo) {
  60960. return (targetInfo.xAxisDeclared && !targetInfo.yAxisDeclared)
  60961. ? 'lineX'
  60962. : (!targetInfo.xAxisDeclared && targetInfo.yAxisDeclared)
  60963. ? 'lineY'
  60964. : 'rect';
  60965. }))
  60966. .enableBrush(
  60967. zoomActive
  60968. ? {
  60969. brushType: 'auto',
  60970. brushStyle: {
  60971. // FIXME user customized?
  60972. lineWidth: 0,
  60973. fill: 'rgba(0,0,0,0.2)'
  60974. }
  60975. }
  60976. : false
  60977. );
  60978. }
  60979. __webpack_require__(356).register('dataZoom', DataZoom);
  60980. // Create special dataZoom option for select
  60981. __webpack_require__(1).registerPreprocessor(function (option) {
  60982. if (!option) {
  60983. return;
  60984. }
  60985. var dataZoomOpts = option.dataZoom || (option.dataZoom = []);
  60986. if (!zrUtil.isArray(dataZoomOpts)) {
  60987. option.dataZoom = dataZoomOpts = [dataZoomOpts];
  60988. }
  60989. var toolboxOpt = option.toolbox;
  60990. if (toolboxOpt) {
  60991. // Assume there is only one toolbox
  60992. if (zrUtil.isArray(toolboxOpt)) {
  60993. toolboxOpt = toolboxOpt[0];
  60994. }
  60995. if (toolboxOpt && toolboxOpt.feature) {
  60996. var dataZoomOpt = toolboxOpt.feature.dataZoom;
  60997. addForAxis('xAxis', dataZoomOpt);
  60998. addForAxis('yAxis', dataZoomOpt);
  60999. }
  61000. }
  61001. function addForAxis(axisName, dataZoomOpt) {
  61002. if (!dataZoomOpt) {
  61003. return;
  61004. }
  61005. // Try not to modify model, because it is not merged yet.
  61006. var axisIndicesName = axisName + 'Index';
  61007. var givenAxisIndices = dataZoomOpt[axisIndicesName];
  61008. if (givenAxisIndices != null
  61009. && givenAxisIndices != 'all'
  61010. && !zrUtil.isArray(givenAxisIndices)
  61011. ) {
  61012. givenAxisIndices = (givenAxisIndices === false || givenAxisIndices === 'none') ? [] : [givenAxisIndices];
  61013. }
  61014. forEachComponent(axisName, function (axisOpt, axisIndex) {
  61015. if (givenAxisIndices != null
  61016. && givenAxisIndices != 'all'
  61017. && zrUtil.indexOf(givenAxisIndices, axisIndex) === -1
  61018. ) {
  61019. return;
  61020. }
  61021. var newOpt = {
  61022. type: 'select',
  61023. $fromToolbox: true,
  61024. // Id for merge mapping.
  61025. id: DATA_ZOOM_ID_BASE + axisName + axisIndex
  61026. };
  61027. // FIXME
  61028. // Only support one axis now.
  61029. newOpt[axisIndicesName] = axisIndex;
  61030. dataZoomOpts.push(newOpt);
  61031. });
  61032. }
  61033. function forEachComponent(mainType, cb) {
  61034. var opts = option[mainType];
  61035. if (!zrUtil.isArray(opts)) {
  61036. opts = opts ? [opts] : [];
  61037. }
  61038. each(opts, cb);
  61039. }
  61040. });
  61041. module.exports = DataZoom;
  61042. /***/ },
  61043. /* 418 */
  61044. /***/ function(module, exports, __webpack_require__) {
  61045. /**
  61046. * @file History manager.
  61047. */
  61048. var zrUtil = __webpack_require__(4);
  61049. var each = zrUtil.each;
  61050. var ATTR = '\0_ec_hist_store';
  61051. var history = {
  61052. /**
  61053. * @public
  61054. * @param {module:echarts/model/Global} ecModel
  61055. * @param {Object} newSnapshot {dataZoomId, batch: [payloadInfo, ...]}
  61056. */
  61057. push: function (ecModel, newSnapshot) {
  61058. var store = giveStore(ecModel);
  61059. // If previous dataZoom can not be found,
  61060. // complete an range with current range.
  61061. each(newSnapshot, function (batchItem, dataZoomId) {
  61062. var i = store.length - 1;
  61063. for (; i >= 0; i--) {
  61064. var snapshot = store[i];
  61065. if (snapshot[dataZoomId]) {
  61066. break;
  61067. }
  61068. }
  61069. if (i < 0) {
  61070. // No origin range set, create one by current range.
  61071. var dataZoomModel = ecModel.queryComponents(
  61072. {mainType: 'dataZoom', subType: 'select', id: dataZoomId}
  61073. )[0];
  61074. if (dataZoomModel) {
  61075. var percentRange = dataZoomModel.getPercentRange();
  61076. store[0][dataZoomId] = {
  61077. dataZoomId: dataZoomId,
  61078. start: percentRange[0],
  61079. end: percentRange[1]
  61080. };
  61081. }
  61082. }
  61083. });
  61084. store.push(newSnapshot);
  61085. },
  61086. /**
  61087. * @public
  61088. * @param {module:echarts/model/Global} ecModel
  61089. * @return {Object} snapshot
  61090. */
  61091. pop: function (ecModel) {
  61092. var store = giveStore(ecModel);
  61093. var head = store[store.length - 1];
  61094. store.length > 1 && store.pop();
  61095. // Find top for all dataZoom.
  61096. var snapshot = {};
  61097. each(head, function (batchItem, dataZoomId) {
  61098. for (var i = store.length - 1; i >= 0; i--) {
  61099. var batchItem = store[i][dataZoomId];
  61100. if (batchItem) {
  61101. snapshot[dataZoomId] = batchItem;
  61102. break;
  61103. }
  61104. }
  61105. });
  61106. return snapshot;
  61107. },
  61108. /**
  61109. * @public
  61110. */
  61111. clear: function (ecModel) {
  61112. ecModel[ATTR] = null;
  61113. },
  61114. /**
  61115. * @public
  61116. * @param {module:echarts/model/Global} ecModel
  61117. * @return {number} records. always >= 1.
  61118. */
  61119. count: function (ecModel) {
  61120. return giveStore(ecModel).length;
  61121. }
  61122. };
  61123. /**
  61124. * [{key: dataZoomId, value: {dataZoomId, range}}, ...]
  61125. * History length of each dataZoom may be different.
  61126. * this._history[0] is used to store origin range.
  61127. * @type {Array.<Object>}
  61128. */
  61129. function giveStore(ecModel) {
  61130. var store = ecModel[ATTR];
  61131. if (!store) {
  61132. store = ecModel[ATTR] = [{}];
  61133. }
  61134. return store;
  61135. }
  61136. module.exports = history;
  61137. /***/ },
  61138. /* 419 */
  61139. /***/ function(module, exports, __webpack_require__) {
  61140. /**
  61141. * DataZoom component entry
  61142. */
  61143. __webpack_require__(363);
  61144. __webpack_require__(364);
  61145. __webpack_require__(367);
  61146. __webpack_require__(420);
  61147. __webpack_require__(421);
  61148. __webpack_require__(373);
  61149. __webpack_require__(374);
  61150. /***/ },
  61151. /* 420 */
  61152. /***/ function(module, exports, __webpack_require__) {
  61153. /**
  61154. * @file Data zoom model
  61155. */
  61156. var DataZoomModel = __webpack_require__(364);
  61157. module.exports = DataZoomModel.extend({
  61158. type: 'dataZoom.select'
  61159. });
  61160. /***/ },
  61161. /* 421 */
  61162. /***/ function(module, exports, __webpack_require__) {
  61163. module.exports = __webpack_require__(367).extend({
  61164. type: 'dataZoom.select'
  61165. });
  61166. /***/ },
  61167. /* 422 */
  61168. /***/ function(module, exports, __webpack_require__) {
  61169. 'use strict';
  61170. var history = __webpack_require__(418);
  61171. function Restore(model) {
  61172. this.model = model;
  61173. }
  61174. Restore.defaultOption = {
  61175. show: true,
  61176. 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',
  61177. title: '还原'
  61178. };
  61179. var proto = Restore.prototype;
  61180. proto.onclick = function (ecModel, api, type) {
  61181. history.clear(ecModel);
  61182. api.dispatchAction({
  61183. type: 'restore',
  61184. from: this.uid
  61185. });
  61186. };
  61187. __webpack_require__(356).register('restore', Restore);
  61188. __webpack_require__(1).registerAction(
  61189. {type: 'restore', event: 'restore', update: 'prepareAndUpdate'},
  61190. function (payload, ecModel) {
  61191. ecModel.resetOption('recreate');
  61192. }
  61193. );
  61194. module.exports = Restore;
  61195. /***/ },
  61196. /* 423 */
  61197. /***/ function(module, exports, __webpack_require__) {
  61198. __webpack_require__(424);
  61199. __webpack_require__(82).registerPainter('vml', __webpack_require__(426));
  61200. /***/ },
  61201. /* 424 */
  61202. /***/ function(module, exports, __webpack_require__) {
  61203. // http://www.w3.org/TR/NOTE-VML
  61204. // TODO Use proxy like svg instead of overwrite brush methods
  61205. if (!__webpack_require__(2).canvasSupported) {
  61206. var vec2 = __webpack_require__(10);
  61207. var BoundingRect = __webpack_require__(9);
  61208. var CMD = __webpack_require__(36).CMD;
  61209. var colorTool = __webpack_require__(31);
  61210. var textContain = __webpack_require__(8);
  61211. var RectText = __webpack_require__(35);
  61212. var Displayable = __webpack_require__(21);
  61213. var ZImage = __webpack_require__(49);
  61214. var Text = __webpack_require__(50);
  61215. var Path = __webpack_require__(20);
  61216. var PathProxy = __webpack_require__(36);
  61217. var Gradient = __webpack_require__(66);
  61218. var vmlCore = __webpack_require__(425);
  61219. var round = Math.round;
  61220. var sqrt = Math.sqrt;
  61221. var abs = Math.abs;
  61222. var cos = Math.cos;
  61223. var sin = Math.sin;
  61224. var mathMax = Math.max;
  61225. var applyTransform = vec2.applyTransform;
  61226. var comma = ',';
  61227. var imageTransformPrefix = 'progid:DXImageTransform.Microsoft';
  61228. var Z = 21600;
  61229. var Z2 = Z / 2;
  61230. var ZLEVEL_BASE = 100000;
  61231. var Z_BASE = 1000;
  61232. var initRootElStyle = function (el) {
  61233. el.style.cssText = 'position:absolute;left:0;top:0;width:1px;height:1px;';
  61234. el.coordsize = Z + ',' + Z;
  61235. el.coordorigin = '0,0';
  61236. };
  61237. var encodeHtmlAttribute = function (s) {
  61238. return String(s).replace(/&/g, '&amp;').replace(/"/g, '&quot;');
  61239. };
  61240. var rgb2Str = function (r, g, b) {
  61241. return 'rgb(' + [r, g, b].join(',') + ')';
  61242. };
  61243. var append = function (parent, child) {
  61244. if (child && parent && child.parentNode !== parent) {
  61245. parent.appendChild(child);
  61246. }
  61247. };
  61248. var remove = function (parent, child) {
  61249. if (child && parent && child.parentNode === parent) {
  61250. parent.removeChild(child);
  61251. }
  61252. };
  61253. var getZIndex = function (zlevel, z, z2) {
  61254. // z 的取值范围为 [0, 1000]
  61255. return (parseFloat(zlevel) || 0) * ZLEVEL_BASE + (parseFloat(z) || 0) * Z_BASE + z2;
  61256. };
  61257. var parsePercent = function (value, maxValue) {
  61258. if (typeof value === 'string') {
  61259. if (value.lastIndexOf('%') >= 0) {
  61260. return parseFloat(value) / 100 * maxValue;
  61261. }
  61262. return parseFloat(value);
  61263. }
  61264. return value;
  61265. };
  61266. /***************************************************
  61267. * PATH
  61268. **************************************************/
  61269. var setColorAndOpacity = function (el, color, opacity) {
  61270. var colorArr = colorTool.parse(color);
  61271. opacity = +opacity;
  61272. if (isNaN(opacity)) {
  61273. opacity = 1;
  61274. }
  61275. if (colorArr) {
  61276. el.color = rgb2Str(colorArr[0], colorArr[1], colorArr[2]);
  61277. el.opacity = opacity * colorArr[3];
  61278. }
  61279. };
  61280. var getColorAndAlpha = function (color) {
  61281. var colorArr = colorTool.parse(color);
  61282. return [
  61283. rgb2Str(colorArr[0], colorArr[1], colorArr[2]),
  61284. colorArr[3]
  61285. ];
  61286. };
  61287. var updateFillNode = function (el, style, zrEl) {
  61288. // TODO pattern
  61289. var fill = style.fill;
  61290. if (fill != null) {
  61291. // Modified from excanvas
  61292. if (fill instanceof Gradient) {
  61293. var gradientType;
  61294. var angle = 0;
  61295. var focus = [0, 0];
  61296. // additional offset
  61297. var shift = 0;
  61298. // scale factor for offset
  61299. var expansion = 1;
  61300. var rect = zrEl.getBoundingRect();
  61301. var rectWidth = rect.width;
  61302. var rectHeight = rect.height;
  61303. if (fill.type === 'linear') {
  61304. gradientType = 'gradient';
  61305. var transform = zrEl.transform;
  61306. var p0 = [fill.x * rectWidth, fill.y * rectHeight];
  61307. var p1 = [fill.x2 * rectWidth, fill.y2 * rectHeight];
  61308. if (transform) {
  61309. applyTransform(p0, p0, transform);
  61310. applyTransform(p1, p1, transform);
  61311. }
  61312. var dx = p1[0] - p0[0];
  61313. var dy = p1[1] - p0[1];
  61314. angle = Math.atan2(dx, dy) * 180 / Math.PI;
  61315. // The angle should be a non-negative number.
  61316. if (angle < 0) {
  61317. angle += 360;
  61318. }
  61319. // Very small angles produce an unexpected result because they are
  61320. // converted to a scientific notation string.
  61321. if (angle < 1e-6) {
  61322. angle = 0;
  61323. }
  61324. }
  61325. else {
  61326. gradientType = 'gradientradial';
  61327. var p0 = [fill.x * rectWidth, fill.y * rectHeight];
  61328. var transform = zrEl.transform;
  61329. var scale = zrEl.scale;
  61330. var width = rectWidth;
  61331. var height = rectHeight;
  61332. focus = [
  61333. // Percent in bounding rect
  61334. (p0[0] - rect.x) / width,
  61335. (p0[1] - rect.y) / height
  61336. ];
  61337. if (transform) {
  61338. applyTransform(p0, p0, transform);
  61339. }
  61340. width /= scale[0] * Z;
  61341. height /= scale[1] * Z;
  61342. var dimension = mathMax(width, height);
  61343. shift = 2 * 0 / dimension;
  61344. expansion = 2 * fill.r / dimension - shift;
  61345. }
  61346. // We need to sort the color stops in ascending order by offset,
  61347. // otherwise IE won't interpret it correctly.
  61348. var stops = fill.colorStops.slice();
  61349. stops.sort(function(cs1, cs2) {
  61350. return cs1.offset - cs2.offset;
  61351. });
  61352. var length = stops.length;
  61353. // Color and alpha list of first and last stop
  61354. var colorAndAlphaList = [];
  61355. var colors = [];
  61356. for (var i = 0; i < length; i++) {
  61357. var stop = stops[i];
  61358. var colorAndAlpha = getColorAndAlpha(stop.color);
  61359. colors.push(stop.offset * expansion + shift + ' ' + colorAndAlpha[0]);
  61360. if (i === 0 || i === length - 1) {
  61361. colorAndAlphaList.push(colorAndAlpha);
  61362. }
  61363. }
  61364. if (length >= 2) {
  61365. var color1 = colorAndAlphaList[0][0];
  61366. var color2 = colorAndAlphaList[1][0];
  61367. var opacity1 = colorAndAlphaList[0][1] * style.opacity;
  61368. var opacity2 = colorAndAlphaList[1][1] * style.opacity;
  61369. el.type = gradientType;
  61370. el.method = 'none';
  61371. el.focus = '100%';
  61372. el.angle = angle;
  61373. el.color = color1;
  61374. el.color2 = color2;
  61375. el.colors = colors.join(',');
  61376. // When colors attribute is used, the meanings of opacity and o:opacity2
  61377. // are reversed.
  61378. el.opacity = opacity2;
  61379. // FIXME g_o_:opacity ?
  61380. el.opacity2 = opacity1;
  61381. }
  61382. if (gradientType === 'radial') {
  61383. el.focusposition = focus.join(',');
  61384. }
  61385. }
  61386. else {
  61387. // FIXME Change from Gradient fill to color fill
  61388. setColorAndOpacity(el, fill, style.opacity);
  61389. }
  61390. }
  61391. };
  61392. var updateStrokeNode = function (el, style) {
  61393. // if (style.lineJoin != null) {
  61394. // el.joinstyle = style.lineJoin;
  61395. // }
  61396. // if (style.miterLimit != null) {
  61397. // el.miterlimit = style.miterLimit * Z;
  61398. // }
  61399. // if (style.lineCap != null) {
  61400. // el.endcap = style.lineCap;
  61401. // }
  61402. if (style.lineDash != null) {
  61403. el.dashstyle = style.lineDash.join(' ');
  61404. }
  61405. if (style.stroke != null && !(style.stroke instanceof Gradient)) {
  61406. setColorAndOpacity(el, style.stroke, style.opacity);
  61407. }
  61408. };
  61409. var updateFillAndStroke = function (vmlEl, type, style, zrEl) {
  61410. var isFill = type == 'fill';
  61411. var el = vmlEl.getElementsByTagName(type)[0];
  61412. // Stroke must have lineWidth
  61413. if (style[type] != null && style[type] !== 'none' && (isFill || (!isFill && style.lineWidth))) {
  61414. vmlEl[isFill ? 'filled' : 'stroked'] = 'true';
  61415. // FIXME Remove before updating, or set `colors` will throw error
  61416. if (style[type] instanceof Gradient) {
  61417. remove(vmlEl, el);
  61418. }
  61419. if (!el) {
  61420. el = vmlCore.createNode(type);
  61421. }
  61422. isFill ? updateFillNode(el, style, zrEl) : updateStrokeNode(el, style);
  61423. append(vmlEl, el);
  61424. }
  61425. else {
  61426. vmlEl[isFill ? 'filled' : 'stroked'] = 'false';
  61427. remove(vmlEl, el);
  61428. }
  61429. };
  61430. var points = [[], [], []];
  61431. var pathDataToString = function (data, m) {
  61432. var M = CMD.M;
  61433. var C = CMD.C;
  61434. var L = CMD.L;
  61435. var A = CMD.A;
  61436. var Q = CMD.Q;
  61437. var str = [];
  61438. var nPoint;
  61439. var cmdStr;
  61440. var cmd;
  61441. var i;
  61442. var xi;
  61443. var yi;
  61444. for (i = 0; i < data.length;) {
  61445. cmd = data[i++];
  61446. cmdStr = '';
  61447. nPoint = 0;
  61448. switch (cmd) {
  61449. case M:
  61450. cmdStr = ' m ';
  61451. nPoint = 1;
  61452. xi = data[i++];
  61453. yi = data[i++];
  61454. points[0][0] = xi;
  61455. points[0][1] = yi;
  61456. break;
  61457. case L:
  61458. cmdStr = ' l ';
  61459. nPoint = 1;
  61460. xi = data[i++];
  61461. yi = data[i++];
  61462. points[0][0] = xi;
  61463. points[0][1] = yi;
  61464. break;
  61465. case Q:
  61466. case C:
  61467. cmdStr = ' c ';
  61468. nPoint = 3;
  61469. var x1 = data[i++];
  61470. var y1 = data[i++];
  61471. var x2 = data[i++];
  61472. var y2 = data[i++];
  61473. var x3;
  61474. var y3;
  61475. if (cmd === Q) {
  61476. // Convert quadratic to cubic using degree elevation
  61477. x3 = x2;
  61478. y3 = y2;
  61479. x2 = (x2 + 2 * x1) / 3;
  61480. y2 = (y2 + 2 * y1) / 3;
  61481. x1 = (xi + 2 * x1) / 3;
  61482. y1 = (yi + 2 * y1) / 3;
  61483. }
  61484. else {
  61485. x3 = data[i++];
  61486. y3 = data[i++];
  61487. }
  61488. points[0][0] = x1;
  61489. points[0][1] = y1;
  61490. points[1][0] = x2;
  61491. points[1][1] = y2;
  61492. points[2][0] = x3;
  61493. points[2][1] = y3;
  61494. xi = x3;
  61495. yi = y3;
  61496. break;
  61497. case A:
  61498. var x = 0;
  61499. var y = 0;
  61500. var sx = 1;
  61501. var sy = 1;
  61502. var angle = 0;
  61503. if (m) {
  61504. // Extract SRT from matrix
  61505. x = m[4];
  61506. y = m[5];
  61507. sx = sqrt(m[0] * m[0] + m[1] * m[1]);
  61508. sy = sqrt(m[2] * m[2] + m[3] * m[3]);
  61509. angle = Math.atan2(-m[1] / sy, m[0] / sx);
  61510. }
  61511. var cx = data[i++];
  61512. var cy = data[i++];
  61513. var rx = data[i++];
  61514. var ry = data[i++];
  61515. var startAngle = data[i++] + angle;
  61516. var endAngle = data[i++] + startAngle + angle;
  61517. // FIXME
  61518. // var psi = data[i++];
  61519. i++;
  61520. var clockwise = data[i++];
  61521. var x0 = cx + cos(startAngle) * rx;
  61522. var y0 = cy + sin(startAngle) * ry;
  61523. var x1 = cx + cos(endAngle) * rx;
  61524. var y1 = cy + sin(endAngle) * ry;
  61525. var type = clockwise ? ' wa ' : ' at ';
  61526. if (Math.abs(x0 - x1) < 1e-4) {
  61527. // IE won't render arches drawn counter clockwise if x0 == x1.
  61528. if (Math.abs(endAngle - startAngle) > 1e-2) {
  61529. // Offset x0 by 1/80 of a pixel. Use something
  61530. // that can be represented in binary
  61531. if (clockwise) {
  61532. x0 += 270 / Z;
  61533. }
  61534. }
  61535. else {
  61536. // Avoid case draw full circle
  61537. if (Math.abs(y0 - cy) < 1e-4) {
  61538. if ((clockwise && x0 < cx) || (!clockwise && x0 > cx)) {
  61539. y1 -= 270 / Z;
  61540. }
  61541. else {
  61542. y1 += 270 / Z;
  61543. }
  61544. }
  61545. else if ((clockwise && y0 < cy) || (!clockwise && y0 > cy)) {
  61546. x1 += 270 / Z;
  61547. }
  61548. else {
  61549. x1 -= 270 / Z;
  61550. }
  61551. }
  61552. }
  61553. str.push(
  61554. type,
  61555. round(((cx - rx) * sx + x) * Z - Z2), comma,
  61556. round(((cy - ry) * sy + y) * Z - Z2), comma,
  61557. round(((cx + rx) * sx + x) * Z - Z2), comma,
  61558. round(((cy + ry) * sy + y) * Z - Z2), comma,
  61559. round((x0 * sx + x) * Z - Z2), comma,
  61560. round((y0 * sy + y) * Z - Z2), comma,
  61561. round((x1 * sx + x) * Z - Z2), comma,
  61562. round((y1 * sy + y) * Z - Z2)
  61563. );
  61564. xi = x1;
  61565. yi = y1;
  61566. break;
  61567. case CMD.R:
  61568. var p0 = points[0];
  61569. var p1 = points[1];
  61570. // x0, y0
  61571. p0[0] = data[i++];
  61572. p0[1] = data[i++];
  61573. // x1, y1
  61574. p1[0] = p0[0] + data[i++];
  61575. p1[1] = p0[1] + data[i++];
  61576. if (m) {
  61577. applyTransform(p0, p0, m);
  61578. applyTransform(p1, p1, m);
  61579. }
  61580. p0[0] = round(p0[0] * Z - Z2);
  61581. p1[0] = round(p1[0] * Z - Z2);
  61582. p0[1] = round(p0[1] * Z - Z2);
  61583. p1[1] = round(p1[1] * Z - Z2);
  61584. str.push(
  61585. // x0, y0
  61586. ' m ', p0[0], comma, p0[1],
  61587. // x1, y0
  61588. ' l ', p1[0], comma, p0[1],
  61589. // x1, y1
  61590. ' l ', p1[0], comma, p1[1],
  61591. // x0, y1
  61592. ' l ', p0[0], comma, p1[1]
  61593. );
  61594. break;
  61595. case CMD.Z:
  61596. // FIXME Update xi, yi
  61597. str.push(' x ');
  61598. }
  61599. if (nPoint > 0) {
  61600. str.push(cmdStr);
  61601. for (var k = 0; k < nPoint; k++) {
  61602. var p = points[k];
  61603. m && applyTransform(p, p, m);
  61604. // 不 round 会非常慢
  61605. str.push(
  61606. round(p[0] * Z - Z2), comma, round(p[1] * Z - Z2),
  61607. k < nPoint - 1 ? comma : ''
  61608. );
  61609. }
  61610. }
  61611. }
  61612. return str.join('');
  61613. };
  61614. // Rewrite the original path method
  61615. Path.prototype.brushVML = function (vmlRoot) {
  61616. var style = this.style;
  61617. var vmlEl = this._vmlEl;
  61618. if (!vmlEl) {
  61619. vmlEl = vmlCore.createNode('shape');
  61620. initRootElStyle(vmlEl);
  61621. this._vmlEl = vmlEl;
  61622. }
  61623. updateFillAndStroke(vmlEl, 'fill', style, this);
  61624. updateFillAndStroke(vmlEl, 'stroke', style, this);
  61625. var m = this.transform;
  61626. var needTransform = m != null;
  61627. var strokeEl = vmlEl.getElementsByTagName('stroke')[0];
  61628. if (strokeEl) {
  61629. var lineWidth = style.lineWidth;
  61630. // Get the line scale.
  61631. // Determinant of this.m_ means how much the area is enlarged by the
  61632. // transformation. So its square root can be used as a scale factor
  61633. // for width.
  61634. if (needTransform && !style.strokeNoScale) {
  61635. var det = m[0] * m[3] - m[1] * m[2];
  61636. lineWidth *= sqrt(abs(det));
  61637. }
  61638. strokeEl.weight = lineWidth + 'px';
  61639. }
  61640. var path = this.path || (this.path = new PathProxy());
  61641. if (this.__dirtyPath) {
  61642. path.beginPath();
  61643. this.buildPath(path, this.shape);
  61644. path.toStatic();
  61645. this.__dirtyPath = false;
  61646. }
  61647. vmlEl.path = pathDataToString(path.data, this.transform);
  61648. vmlEl.style.zIndex = getZIndex(this.zlevel, this.z, this.z2);
  61649. // Append to root
  61650. append(vmlRoot, vmlEl);
  61651. // Text
  61652. if (style.text != null) {
  61653. this.drawRectText(vmlRoot, this.getBoundingRect());
  61654. }
  61655. else {
  61656. this.removeRectText(vmlRoot);
  61657. }
  61658. };
  61659. Path.prototype.onRemove = function (vmlRoot) {
  61660. remove(vmlRoot, this._vmlEl);
  61661. this.removeRectText(vmlRoot);
  61662. };
  61663. Path.prototype.onAdd = function (vmlRoot) {
  61664. append(vmlRoot, this._vmlEl);
  61665. this.appendRectText(vmlRoot);
  61666. };
  61667. /***************************************************
  61668. * IMAGE
  61669. **************************************************/
  61670. var isImage = function (img) {
  61671. // FIXME img instanceof Image 如果 img 是一个字符串的时候,IE8 下会报错
  61672. return (typeof img === 'object') && img.tagName && img.tagName.toUpperCase() === 'IMG';
  61673. // return img instanceof Image;
  61674. };
  61675. // Rewrite the original path method
  61676. ZImage.prototype.brushVML = function (vmlRoot) {
  61677. var style = this.style;
  61678. var image = style.image;
  61679. // Image original width, height
  61680. var ow;
  61681. var oh;
  61682. if (isImage(image)) {
  61683. var src = image.src;
  61684. if (src === this._imageSrc) {
  61685. ow = this._imageWidth;
  61686. oh = this._imageHeight;
  61687. }
  61688. else {
  61689. var imageRuntimeStyle = image.runtimeStyle;
  61690. var oldRuntimeWidth = imageRuntimeStyle.width;
  61691. var oldRuntimeHeight = imageRuntimeStyle.height;
  61692. imageRuntimeStyle.width = 'auto';
  61693. imageRuntimeStyle.height = 'auto';
  61694. // get the original size
  61695. ow = image.width;
  61696. oh = image.height;
  61697. // and remove overides
  61698. imageRuntimeStyle.width = oldRuntimeWidth;
  61699. imageRuntimeStyle.height = oldRuntimeHeight;
  61700. // Caching image original width, height and src
  61701. this._imageSrc = src;
  61702. this._imageWidth = ow;
  61703. this._imageHeight = oh;
  61704. }
  61705. image = src;
  61706. }
  61707. else {
  61708. if (image === this._imageSrc) {
  61709. ow = this._imageWidth;
  61710. oh = this._imageHeight;
  61711. }
  61712. }
  61713. if (!image) {
  61714. return;
  61715. }
  61716. var x = style.x || 0;
  61717. var y = style.y || 0;
  61718. var dw = style.width;
  61719. var dh = style.height;
  61720. var sw = style.sWidth;
  61721. var sh = style.sHeight;
  61722. var sx = style.sx || 0;
  61723. var sy = style.sy || 0;
  61724. var hasCrop = sw && sh;
  61725. var vmlEl = this._vmlEl;
  61726. if (!vmlEl) {
  61727. // FIXME 使用 group 在 left, top 都不是 0 的时候就无法显示了。
  61728. // vmlEl = vmlCore.createNode('group');
  61729. vmlEl = vmlCore.doc.createElement('div');
  61730. initRootElStyle(vmlEl);
  61731. this._vmlEl = vmlEl;
  61732. }
  61733. var vmlElStyle = vmlEl.style;
  61734. var hasRotation = false;
  61735. var m;
  61736. var scaleX = 1;
  61737. var scaleY = 1;
  61738. if (this.transform) {
  61739. m = this.transform;
  61740. scaleX = sqrt(m[0] * m[0] + m[1] * m[1]);
  61741. scaleY = sqrt(m[2] * m[2] + m[3] * m[3]);
  61742. hasRotation = m[1] || m[2];
  61743. }
  61744. if (hasRotation) {
  61745. // If filters are necessary (rotation exists), create them
  61746. // filters are bog-slow, so only create them if abbsolutely necessary
  61747. // The following check doesn't account for skews (which don't exist
  61748. // in the canvas spec (yet) anyway.
  61749. // From excanvas
  61750. var p0 = [x, y];
  61751. var p1 = [x + dw, y];
  61752. var p2 = [x, y + dh];
  61753. var p3 = [x + dw, y + dh];
  61754. applyTransform(p0, p0, m);
  61755. applyTransform(p1, p1, m);
  61756. applyTransform(p2, p2, m);
  61757. applyTransform(p3, p3, m);
  61758. var maxX = mathMax(p0[0], p1[0], p2[0], p3[0]);
  61759. var maxY = mathMax(p0[1], p1[1], p2[1], p3[1]);
  61760. var transformFilter = [];
  61761. transformFilter.push('M11=', m[0] / scaleX, comma,
  61762. 'M12=', m[2] / scaleY, comma,
  61763. 'M21=', m[1] / scaleX, comma,
  61764. 'M22=', m[3] / scaleY, comma,
  61765. 'Dx=', round(x * scaleX + m[4]), comma,
  61766. 'Dy=', round(y * scaleY + m[5]));
  61767. vmlElStyle.padding = '0 ' + round(maxX) + 'px ' + round(maxY) + 'px 0';
  61768. // FIXME DXImageTransform 在 IE11 的兼容模式下不起作用
  61769. vmlElStyle.filter = imageTransformPrefix + '.Matrix('
  61770. + transformFilter.join('') + ', SizingMethod=clip)';
  61771. }
  61772. else {
  61773. if (m) {
  61774. x = x * scaleX + m[4];
  61775. y = y * scaleY + m[5];
  61776. }
  61777. vmlElStyle.filter = '';
  61778. vmlElStyle.left = round(x) + 'px';
  61779. vmlElStyle.top = round(y) + 'px';
  61780. }
  61781. var imageEl = this._imageEl;
  61782. var cropEl = this._cropEl;
  61783. if (!imageEl) {
  61784. imageEl = vmlCore.doc.createElement('div');
  61785. this._imageEl = imageEl;
  61786. }
  61787. var imageELStyle = imageEl.style;
  61788. if (hasCrop) {
  61789. // Needs know image original width and height
  61790. if (! (ow && oh)) {
  61791. var tmpImage = new Image();
  61792. var self = this;
  61793. tmpImage.onload = function () {
  61794. tmpImage.onload = null;
  61795. ow = tmpImage.width;
  61796. oh = tmpImage.height;
  61797. // Adjust image width and height to fit the ratio destinationSize / sourceSize
  61798. imageELStyle.width = round(scaleX * ow * dw / sw) + 'px';
  61799. imageELStyle.height = round(scaleY * oh * dh / sh) + 'px';
  61800. // Caching image original width, height and src
  61801. self._imageWidth = ow;
  61802. self._imageHeight = oh;
  61803. self._imageSrc = image;
  61804. };
  61805. tmpImage.src = image;
  61806. }
  61807. else {
  61808. imageELStyle.width = round(scaleX * ow * dw / sw) + 'px';
  61809. imageELStyle.height = round(scaleY * oh * dh / sh) + 'px';
  61810. }
  61811. if (! cropEl) {
  61812. cropEl = vmlCore.doc.createElement('div');
  61813. cropEl.style.overflow = 'hidden';
  61814. this._cropEl = cropEl;
  61815. }
  61816. var cropElStyle = cropEl.style;
  61817. cropElStyle.width = round((dw + sx * dw / sw) * scaleX);
  61818. cropElStyle.height = round((dh + sy * dh / sh) * scaleY);
  61819. cropElStyle.filter = imageTransformPrefix + '.Matrix(Dx='
  61820. + (-sx * dw / sw * scaleX) + ',Dy=' + (-sy * dh / sh * scaleY) + ')';
  61821. if (! cropEl.parentNode) {
  61822. vmlEl.appendChild(cropEl);
  61823. }
  61824. if (imageEl.parentNode != cropEl) {
  61825. cropEl.appendChild(imageEl);
  61826. }
  61827. }
  61828. else {
  61829. imageELStyle.width = round(scaleX * dw) + 'px';
  61830. imageELStyle.height = round(scaleY * dh) + 'px';
  61831. vmlEl.appendChild(imageEl);
  61832. if (cropEl && cropEl.parentNode) {
  61833. vmlEl.removeChild(cropEl);
  61834. this._cropEl = null;
  61835. }
  61836. }
  61837. var filterStr = '';
  61838. var alpha = style.opacity;
  61839. if (alpha < 1) {
  61840. filterStr += '.Alpha(opacity=' + round(alpha * 100) + ') ';
  61841. }
  61842. filterStr += imageTransformPrefix + '.AlphaImageLoader(src=' + image + ', SizingMethod=scale)';
  61843. imageELStyle.filter = filterStr;
  61844. vmlEl.style.zIndex = getZIndex(this.zlevel, this.z, this.z2);
  61845. // Append to root
  61846. append(vmlRoot, vmlEl);
  61847. // Text
  61848. if (style.text != null) {
  61849. this.drawRectText(vmlRoot, this.getBoundingRect());
  61850. }
  61851. };
  61852. ZImage.prototype.onRemove = function (vmlRoot) {
  61853. remove(vmlRoot, this._vmlEl);
  61854. this._vmlEl = null;
  61855. this._cropEl = null;
  61856. this._imageEl = null;
  61857. this.removeRectText(vmlRoot);
  61858. };
  61859. ZImage.prototype.onAdd = function (vmlRoot) {
  61860. append(vmlRoot, this._vmlEl);
  61861. this.appendRectText(vmlRoot);
  61862. };
  61863. /***************************************************
  61864. * TEXT
  61865. **************************************************/
  61866. var DEFAULT_STYLE_NORMAL = 'normal';
  61867. var fontStyleCache = {};
  61868. var fontStyleCacheCount = 0;
  61869. var MAX_FONT_CACHE_SIZE = 100;
  61870. var fontEl = document.createElement('div');
  61871. var getFontStyle = function (fontString) {
  61872. var fontStyle = fontStyleCache[fontString];
  61873. if (!fontStyle) {
  61874. // Clear cache
  61875. if (fontStyleCacheCount > MAX_FONT_CACHE_SIZE) {
  61876. fontStyleCacheCount = 0;
  61877. fontStyleCache = {};
  61878. }
  61879. var style = fontEl.style;
  61880. var fontFamily;
  61881. try {
  61882. style.font = fontString;
  61883. fontFamily = style.fontFamily.split(',')[0];
  61884. }
  61885. catch (e) {
  61886. }
  61887. fontStyle = {
  61888. style: style.fontStyle || DEFAULT_STYLE_NORMAL,
  61889. variant: style.fontVariant || DEFAULT_STYLE_NORMAL,
  61890. weight: style.fontWeight || DEFAULT_STYLE_NORMAL,
  61891. size: parseFloat(style.fontSize || 12) | 0,
  61892. family: fontFamily || 'Microsoft YaHei'
  61893. };
  61894. fontStyleCache[fontString] = fontStyle;
  61895. fontStyleCacheCount++;
  61896. }
  61897. return fontStyle;
  61898. };
  61899. var textMeasureEl;
  61900. // Overwrite measure text method
  61901. textContain.measureText = function (text, textFont) {
  61902. var doc = vmlCore.doc;
  61903. if (!textMeasureEl) {
  61904. textMeasureEl = doc.createElement('div');
  61905. textMeasureEl.style.cssText = 'position:absolute;top:-20000px;left:0;'
  61906. + 'padding:0;margin:0;border:none;white-space:pre;';
  61907. vmlCore.doc.body.appendChild(textMeasureEl);
  61908. }
  61909. try {
  61910. textMeasureEl.style.font = textFont;
  61911. } catch (ex) {
  61912. // Ignore failures to set to invalid font.
  61913. }
  61914. textMeasureEl.innerHTML = '';
  61915. // Don't use innerHTML or innerText because they allow markup/whitespace.
  61916. textMeasureEl.appendChild(doc.createTextNode(text));
  61917. return {
  61918. width: textMeasureEl.offsetWidth
  61919. };
  61920. };
  61921. var tmpRect = new BoundingRect();
  61922. var drawRectText = function (vmlRoot, rect, textRect, fromTextEl) {
  61923. var style = this.style;
  61924. var text = style.text;
  61925. // Convert to string
  61926. text != null && (text += '');
  61927. if (!text) {
  61928. return;
  61929. }
  61930. var x;
  61931. var y;
  61932. var align = style.textAlign;
  61933. var fontStyle = getFontStyle(style.textFont);
  61934. // FIXME encodeHtmlAttribute ?
  61935. var font = fontStyle.style + ' ' + fontStyle.variant + ' ' + fontStyle.weight + ' '
  61936. + fontStyle.size + 'px "' + fontStyle.family + '"';
  61937. var baseline = style.textBaseline;
  61938. var verticalAlign = style.textVerticalAlign;
  61939. textRect = textRect || textContain.getBoundingRect(text, font, align, baseline);
  61940. // Transform rect to view space
  61941. var m = this.transform;
  61942. // Ignore transform for text in other element
  61943. if (m && !fromTextEl) {
  61944. tmpRect.copy(rect);
  61945. tmpRect.applyTransform(m);
  61946. rect = tmpRect;
  61947. }
  61948. if (!fromTextEl) {
  61949. var textPosition = style.textPosition;
  61950. var distance = style.textDistance;
  61951. // Text position represented by coord
  61952. if (textPosition instanceof Array) {
  61953. x = rect.x + parsePercent(textPosition[0], rect.width);
  61954. y = rect.y + parsePercent(textPosition[1], rect.height);
  61955. align = align || 'left';
  61956. baseline = baseline || 'top';
  61957. }
  61958. else {
  61959. var res = textContain.adjustTextPositionOnRect(
  61960. textPosition, rect, textRect, distance
  61961. );
  61962. x = res.x;
  61963. y = res.y;
  61964. // Default align and baseline when has textPosition
  61965. align = align || res.textAlign;
  61966. baseline = baseline || res.textBaseline;
  61967. }
  61968. }
  61969. else {
  61970. x = rect.x;
  61971. y = rect.y;
  61972. }
  61973. if (verticalAlign) {
  61974. switch (verticalAlign) {
  61975. case 'middle':
  61976. y -= textRect.height / 2;
  61977. break;
  61978. case 'bottom':
  61979. y -= textRect.height;
  61980. break;
  61981. // 'top'
  61982. }
  61983. // Ignore baseline
  61984. baseline = 'top';
  61985. }
  61986. var fontSize = fontStyle.size;
  61987. // 1.75 is an arbitrary number, as there is no info about the text baseline
  61988. switch (baseline) {
  61989. case 'hanging':
  61990. case 'top':
  61991. y += fontSize / 1.75;
  61992. break;
  61993. case 'middle':
  61994. break;
  61995. default:
  61996. // case null:
  61997. // case 'alphabetic':
  61998. // case 'ideographic':
  61999. // case 'bottom':
  62000. y -= fontSize / 2.25;
  62001. break;
  62002. }
  62003. switch (align) {
  62004. case 'left':
  62005. break;
  62006. case 'center':
  62007. x -= textRect.width / 2;
  62008. break;
  62009. case 'right':
  62010. x -= textRect.width;
  62011. break;
  62012. // case 'end':
  62013. // align = elementStyle.direction == 'ltr' ? 'right' : 'left';
  62014. // break;
  62015. // case 'start':
  62016. // align = elementStyle.direction == 'rtl' ? 'right' : 'left';
  62017. // break;
  62018. // default:
  62019. // align = 'left';
  62020. }
  62021. var createNode = vmlCore.createNode;
  62022. var textVmlEl = this._textVmlEl;
  62023. var pathEl;
  62024. var textPathEl;
  62025. var skewEl;
  62026. if (!textVmlEl) {
  62027. textVmlEl = createNode('line');
  62028. pathEl = createNode('path');
  62029. textPathEl = createNode('textpath');
  62030. skewEl = createNode('skew');
  62031. // FIXME Why here is not cammel case
  62032. // Align 'center' seems wrong
  62033. textPathEl.style['v-text-align'] = 'left';
  62034. initRootElStyle(textVmlEl);
  62035. pathEl.textpathok = true;
  62036. textPathEl.on = true;
  62037. textVmlEl.from = '0 0';
  62038. textVmlEl.to = '1000 0.05';
  62039. append(textVmlEl, skewEl);
  62040. append(textVmlEl, pathEl);
  62041. append(textVmlEl, textPathEl);
  62042. this._textVmlEl = textVmlEl;
  62043. }
  62044. else {
  62045. // 这里是在前面 appendChild 保证顺序的前提下
  62046. skewEl = textVmlEl.firstChild;
  62047. pathEl = skewEl.nextSibling;
  62048. textPathEl = pathEl.nextSibling;
  62049. }
  62050. var coords = [x, y];
  62051. var textVmlElStyle = textVmlEl.style;
  62052. // Ignore transform for text in other element
  62053. if (m && fromTextEl) {
  62054. applyTransform(coords, coords, m);
  62055. skewEl.on = true;
  62056. skewEl.matrix = m[0].toFixed(3) + comma + m[2].toFixed(3) + comma +
  62057. m[1].toFixed(3) + comma + m[3].toFixed(3) + ',0,0';
  62058. // Text position
  62059. skewEl.offset = (round(coords[0]) || 0) + ',' + (round(coords[1]) || 0);
  62060. // Left top point as origin
  62061. skewEl.origin = '0 0';
  62062. textVmlElStyle.left = '0px';
  62063. textVmlElStyle.top = '0px';
  62064. }
  62065. else {
  62066. skewEl.on = false;
  62067. textVmlElStyle.left = round(x) + 'px';
  62068. textVmlElStyle.top = round(y) + 'px';
  62069. }
  62070. textPathEl.string = encodeHtmlAttribute(text);
  62071. // TODO
  62072. try {
  62073. textPathEl.style.font = font;
  62074. }
  62075. // Error font format
  62076. catch (e) {}
  62077. updateFillAndStroke(textVmlEl, 'fill', {
  62078. fill: fromTextEl ? style.fill : style.textFill,
  62079. opacity: style.opacity
  62080. }, this);
  62081. updateFillAndStroke(textVmlEl, 'stroke', {
  62082. stroke: fromTextEl ? style.stroke : style.textStroke,
  62083. opacity: style.opacity,
  62084. lineDash: style.lineDash
  62085. }, this);
  62086. textVmlEl.style.zIndex = getZIndex(this.zlevel, this.z, this.z2);
  62087. // Attached to root
  62088. append(vmlRoot, textVmlEl);
  62089. };
  62090. var removeRectText = function (vmlRoot) {
  62091. remove(vmlRoot, this._textVmlEl);
  62092. this._textVmlEl = null;
  62093. };
  62094. var appendRectText = function (vmlRoot) {
  62095. append(vmlRoot, this._textVmlEl);
  62096. };
  62097. var list = [RectText, Displayable, ZImage, Path, Text];
  62098. // In case Displayable has been mixed in RectText
  62099. for (var i = 0; i < list.length; i++) {
  62100. var proto = list[i].prototype;
  62101. proto.drawRectText = drawRectText;
  62102. proto.removeRectText = removeRectText;
  62103. proto.appendRectText = appendRectText;
  62104. }
  62105. Text.prototype.brushVML = function (vmlRoot) {
  62106. var style = this.style;
  62107. if (style.text != null) {
  62108. this.drawRectText(vmlRoot, {
  62109. x: style.x || 0, y: style.y || 0,
  62110. width: 0, height: 0
  62111. }, this.getBoundingRect(), true);
  62112. }
  62113. else {
  62114. this.removeRectText(vmlRoot);
  62115. }
  62116. };
  62117. Text.prototype.onRemove = function (vmlRoot) {
  62118. this.removeRectText(vmlRoot);
  62119. };
  62120. Text.prototype.onAdd = function (vmlRoot) {
  62121. this.appendRectText(vmlRoot);
  62122. };
  62123. }
  62124. /***/ },
  62125. /* 425 */
  62126. /***/ function(module, exports, __webpack_require__) {
  62127. if (!__webpack_require__(2).canvasSupported) {
  62128. var urn = 'urn:schemas-microsoft-com:vml';
  62129. var createNode;
  62130. var win = window;
  62131. var doc = win.document;
  62132. var vmlInited = false;
  62133. try {
  62134. !doc.namespaces.zrvml && doc.namespaces.add('zrvml', urn);
  62135. createNode = function (tagName) {
  62136. return doc.createElement('<zrvml:' + tagName + ' class="zrvml">');
  62137. };
  62138. }
  62139. catch (e) {
  62140. createNode = function (tagName) {
  62141. return doc.createElement('<' + tagName + ' xmlns="' + urn + '" class="zrvml">');
  62142. };
  62143. }
  62144. // From raphael
  62145. var initVML = function () {
  62146. if (vmlInited) {
  62147. return;
  62148. }
  62149. vmlInited = true;
  62150. var styleSheets = doc.styleSheets;
  62151. if (styleSheets.length < 31) {
  62152. doc.createStyleSheet().addRule('.zrvml', 'behavior:url(#default#VML)');
  62153. }
  62154. else {
  62155. // http://msdn.microsoft.com/en-us/library/ms531194%28VS.85%29.aspx
  62156. styleSheets[0].addRule('.zrvml', 'behavior:url(#default#VML)');
  62157. }
  62158. };
  62159. // Not useing return to avoid error when converting to CommonJS module
  62160. module.exports = {
  62161. doc: doc,
  62162. initVML: initVML,
  62163. createNode: createNode
  62164. };
  62165. }
  62166. /***/ },
  62167. /* 426 */
  62168. /***/ function(module, exports, __webpack_require__) {
  62169. /**
  62170. * VML Painter.
  62171. *
  62172. * @module zrender/vml/Painter
  62173. */
  62174. var zrLog = __webpack_require__(33);
  62175. var vmlCore = __webpack_require__(425);
  62176. function parseInt10(val) {
  62177. return parseInt(val, 10);
  62178. }
  62179. /**
  62180. * @alias module:zrender/vml/Painter
  62181. */
  62182. function VMLPainter(root, storage) {
  62183. vmlCore.initVML();
  62184. this.root = root;
  62185. this.storage = storage;
  62186. var vmlViewport = document.createElement('div');
  62187. var vmlRoot = document.createElement('div');
  62188. vmlViewport.style.cssText = 'display:inline-block;overflow:hidden;position:relative;width:300px;height:150px;';
  62189. vmlRoot.style.cssText = 'position:absolute;left:0;top:0;';
  62190. root.appendChild(vmlViewport);
  62191. this._vmlRoot = vmlRoot;
  62192. this._vmlViewport = vmlViewport;
  62193. this.resize();
  62194. // Modify storage
  62195. var oldDelFromStorage = storage.delFromStorage;
  62196. var oldAddToStorage = storage.addToStorage;
  62197. storage.delFromStorage = function (el) {
  62198. oldDelFromStorage.call(storage, el);
  62199. if (el) {
  62200. el.onRemove && el.onRemove(vmlRoot);
  62201. }
  62202. };
  62203. storage.addToStorage = function (el) {
  62204. // Displayable already has a vml node
  62205. el.onAdd && el.onAdd(vmlRoot);
  62206. oldAddToStorage.call(storage, el);
  62207. };
  62208. this._firstPaint = true;
  62209. }
  62210. VMLPainter.prototype = {
  62211. constructor: VMLPainter,
  62212. /**
  62213. * @return {HTMLDivElement}
  62214. */
  62215. getViewportRoot: function () {
  62216. return this._vmlViewport;
  62217. },
  62218. /**
  62219. * 刷新
  62220. */
  62221. refresh: function () {
  62222. var list = this.storage.getDisplayList(true, true);
  62223. this._paintList(list);
  62224. },
  62225. _paintList: function (list) {
  62226. var vmlRoot = this._vmlRoot;
  62227. for (var i = 0; i < list.length; i++) {
  62228. var el = list[i];
  62229. if (el.invisible || el.ignore) {
  62230. if (!el.__alreadyNotVisible) {
  62231. el.onRemove(vmlRoot);
  62232. }
  62233. // Set as already invisible
  62234. el.__alreadyNotVisible = true;
  62235. }
  62236. else {
  62237. if (el.__alreadyNotVisible) {
  62238. el.onAdd(vmlRoot);
  62239. }
  62240. el.__alreadyNotVisible = false;
  62241. if (el.__dirty) {
  62242. el.beforeBrush && el.beforeBrush();
  62243. (el.brushVML || el.brush).call(el, vmlRoot);
  62244. el.afterBrush && el.afterBrush();
  62245. }
  62246. }
  62247. el.__dirty = false;
  62248. }
  62249. if (this._firstPaint) {
  62250. // Detached from document at first time
  62251. // to avoid page refreshing too many times
  62252. // FIXME 如果每次都先 removeChild 可能会导致一些填充和描边的效果改变
  62253. this._vmlViewport.appendChild(vmlRoot);
  62254. this._firstPaint = false;
  62255. }
  62256. },
  62257. resize: function (width, height) {
  62258. var width = width == null ? this._getWidth() : width;
  62259. var height = height == null ? this._getHeight() : height;
  62260. if (this._width != width || this._height != height) {
  62261. this._width = width;
  62262. this._height = height;
  62263. var vmlViewportStyle = this._vmlViewport.style;
  62264. vmlViewportStyle.width = width + 'px';
  62265. vmlViewportStyle.height = height + 'px';
  62266. }
  62267. },
  62268. dispose: function () {
  62269. this.root.innerHTML = '';
  62270. this._vmlRoot =
  62271. this._vmlViewport =
  62272. this.storage = null;
  62273. },
  62274. getWidth: function () {
  62275. return this._width;
  62276. },
  62277. getHeight: function () {
  62278. return this._height;
  62279. },
  62280. clear: function () {
  62281. if (this._vmlViewport) {
  62282. this.root.removeChild(this._vmlViewport);
  62283. }
  62284. },
  62285. _getWidth: function () {
  62286. var root = this.root;
  62287. var stl = root.currentStyle;
  62288. return ((root.clientWidth || parseInt10(stl.width))
  62289. - parseInt10(stl.paddingLeft)
  62290. - parseInt10(stl.paddingRight)) | 0;
  62291. },
  62292. _getHeight: function () {
  62293. var root = this.root;
  62294. var stl = root.currentStyle;
  62295. return ((root.clientHeight || parseInt10(stl.height))
  62296. - parseInt10(stl.paddingTop)
  62297. - parseInt10(stl.paddingBottom)) | 0;
  62298. }
  62299. };
  62300. // Not supported methods
  62301. function createMethodNotSupport(method) {
  62302. return function () {
  62303. zrLog('In IE8.0 VML mode painter not support method "' + method + '"');
  62304. };
  62305. }
  62306. var notSupportedMethods = [
  62307. 'getLayer', 'insertLayer', 'eachLayer', 'eachBuiltinLayer', 'eachOtherLayer', 'getLayers',
  62308. 'modLayer', 'delLayer', 'clearLayer', 'toDataURL', 'pathToImage'
  62309. ];
  62310. for (var i = 0; i < notSupportedMethods.length; i++) {
  62311. var name = notSupportedMethods[i];
  62312. VMLPainter.prototype[name] = createMethodNotSupport(name);
  62313. }
  62314. module.exports = VMLPainter;
  62315. /***/ }
  62316. /******/ ])
  62317. });
  62318. ;